2013-11-22 12 views
6

EDIT:そのTLDRは、ちょうど下に進んでください。その場所:静的ライブラリを使用するautotoolsプロジェクトを構成するにはどうすればよいですか?静的なlibの設定でClangのサニタイザを使用してautotoolsプロジェクトを設定しますか?

私はいくつかのオープンソースライブラリで作業しています。私はClangのサニタイザでテストスイートを実行しようとしています。 Clangのサニタイザの下で実行するには、(1)いくつかのオプションを指定し、(2)必要に応じてClangのCompiler-RTから静的ライブラリをリンクする必要があります。 :ダイナミックライブラリまたは共有オブジェクトはありません。

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib/clang/3.3/lib/darwin/ 
export CC=/usr/local/bin/clang 
export CXX=/usr/local/bin/clang++ 
export CFLAGS="-g3 -fsanitize=address -fsanitize=undefined" 
export CXXFLAGS="-g3 -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr" 

./configure 

しかし、これはいくつかのアーカイブの警告を生成します(ARが実行されるとき)と未定義のシンボルとリンクエラー(LDが実行されたとき):オプションの設定

は簡単です。メッセージは次のようになります。

libjpeg.a(jmemmgr.o): In function `do_sarray_io': 
/home/jwalton/jpeg-6b/jmemmgr.c:695: undefined reference to 
`__ubsan_handle_type_mismatch' 
/home/jwalton/jpeg-6b/jmemmgr.c:695: undefined reference to 
`__ubsan_handle_type_mismatch' 
/home/jwalton/jpeg-6b/jmemmgr.c:696: undefined reference to 
`__ubsan_handle_type_mismatch' 

私はリンクする必要があるライブラリを知っています。私が使用する消毒剤のために、彼らはlibclang_rt.asan_osx.alibclang_rt.ubsan_osx.a(またはLinux上のlibclang_rt.full-x86_64.alibclang_rt.ubsan-x86_64.a)です。ライブラリを供給する

、私は、次のようにエクスポートします。 :他のほとんどのmake関連のツールで期待どおりにLIBSではなく、LDLIBS

export LIBS="/usr/local/lib/clang/3.3/lib/darwin/libclang_rt.asan_osx.a \ 
      /usr/local/lib/clang/3.3/lib/darwin/libclang_rt.ubsan_osx.a" 

これはのconfigureという問題があった:二つの問題が発生しているよう

configure: error: cannot run C compiled programs. 
If you meant to cross compile, use `--host'. 
... 

config.logを見ると、それが見えます。まず、パスは/usr/local/...から/Users/jwalton/...に変更することで虐殺されています。第二に、ファイル名が動的LIBに静的LIBから変化させることにより、虐殺されている:

configure:3346: ./conftest 
dyld: Library not loaded: /Users/jwalton/clang-llvm/llvm-3.3.src/Release+Asserts/lib/clang/3.3/lib/darwin/libclang_rt.asan_osx_dynamic.dylib 
    Referenced from: /Users/jwalton/libpng-1.6.7/./conftest 
Reason: image not found 

別の試みにおいて、Iは、LDFLAGSを使用してみました:同様のエラーが発生し

export LDFLAGS="-L/usr/local/lib/clang/3.3/lib/darwin/" 
export LIBS="libclang_rt.asan_osx.a libclang_rt.ubsan_osx.a" 

configure: error: in `/Users/jwalton/libpng-1.6.7': 
configure: error: C compiler cannot create executables 

そしてconfig.log

configure:3209: /usr/local/bin/clang -g3 -fsanitize=address -fsanitize=undefined -L/usr/local/lib/clang/3.3/lib/darwin/ conftest.c libclang_rt.asan_osx.a libclang_rt.ubsan_osx.a >&5 
clang: error: no such file or directory: 'libclang_rt.asan_osx.a' 
clang: error: no such file or directory: 'libclang_rt.ubsan_osx.a' 

とでLIBS結果からlib接頭辞と接尾.aをドロップ:最後に、-L引数が有効である

configure:3335: /usr/local/bin/clang -o conftest -g3 -fsanitize=address -fsanitize=undefined 
    -L/usr/local/lib/clang/3.3/lib/darwin/ conftest.c -lclang_rt.asan_osx -lclang_rt.ubsan_osx >&5 
configure:3339: $? = 0 
configure:3346: ./conftest 
dyld: could not load inserted library: /Users/jwalton/libpng-1.6.7/./conftest 

./configure: line 3348: 38224 Trace/BPT trap: 5  ./conftest$ac_cv_exeext 

configure:3209: /usr/local/bin/clang -g3 -fsanitize=address -fsanitize=undefined -L/usr/local/lib/clang/3.3/lib/darwin/ conftest.c clang_rt.asan_osx clang_rt.ubsan_osx >&5 
clang: error: no such file or directory: 'clang_rt.asan_osx' 
clang: error: no such file or directory: 'clang_rt.ubsan_osx' 

とで-lLIBSに結果を追加

$ ls /usr/local/lib/clang/3.3/lib/darwin/ 
libclang_rt.10.4.a   libclang_rt.ios.a 
libclang_rt.asan_osx.a   libclang_rt.osx.a 
libclang_rt.asan_osx_dynamic.dylib libclang_rt.profile_ios.a 
libclang_rt.cc_kext.a   libclang_rt.profile_osx.a 
libclang_rt.cc_kext_ios5.a  libclang_rt.ubsan_osx.a 
libclang_rt.eprintf.a 

すべての背景:静的ライブラリを使用するautotoolsプロジェクトを設定するにはどうすればよいですか?

ボーナスポイント:どうしてそんなに簡単にできないのですか?

答えて

1

GNU libtoolの出荷バージョンでは、-fsanitize = ...引数をリンカーに渡しません。あなたが具体的にhttp://savannah.gnu.org/patch/?8775からパッチでのlibtoolを更新する必要があります。

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in 
index 0c40da0..b99b0cd 100644 
--- a/build-aux/ltmain.in 
+++ b/build-aux/ltmain.in 
@@ -5362,10 +5362,11 @@ func_mode_link() 
     # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization 
     # -specs=*    GCC specs files 
     # -stdlib=*   select c++ std lib with clang 
+  # -fsanitize=*   Clang memory and address sanitizer 
     -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ 
     -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ 
     -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ 
-  -specs=*) 
+  -specs=*|-fsanitize=*) 
     func_quote_for_eval "$arg" 
    arg=$func_quote_for_eval_result 
     func_append compile_command " $arg" 

静的ライブラリを受け入れるようにlibtoolを取得するためとして、あなただけのコマンドラインで静的ライブラリへの完全なパスを含めることができるはず、または-L/usr/local/lib/clang/3.3/lib/darwin/ -lclang_rt.ubsan_osxのようなオプションを使用できます。しかし、libtoolがリンクするために-fsanitize = ...を使用するように指示すると、cfeはあなたにライブラリのマジックを配慮しなければなりません。

+0

ああ、完璧です。どうもありがとうございました。私はこれらの変更を行うつもりはないが、Autotoolsの問題と消毒剤の解決策を明確に示している。彼らはおそらく "sanitzer"もチェックしておくべきでしょう。例えば、私は 'CXXFLAGS'に対して以下を使用します:' -fsanitize = undefined -fno-sanitize = vptr'。 – jww

+0

MacPortsを使用している場合は、libtoolポートをインストールするだけです。すでにパッチがあります。あなたのプロジェクトで 'autoreconf'や' glibtoolize'を再実行して新しいバージョンを手に入れる必要がありますが、それは助けになるはずです。 –

5

-fsanitizeフラグもLDFLAGSに追加する必要があります。

+1

少し注意してください:私がしたとき、静的にリンクすることを明示的に指摘していたとしても、«libubsan»は動的にリンクされていました。この解決策は、LDFLAGSで '-fsanitize'を使用するのではなく、静的ライブラリ' libubsan.a'にフルパスを追加することでした。 –

+1

@ Hi-Angel GCCでは、標準的な解決策は '-static-libubsan'を使うことです。 – yugr

0

未定義のシンボルの問題については、C++オブジェクトをリンクする場合、clangの代わりにclang++を使用する必要があります。 automakeはあなたがCのオブジェクトのセットをリンクしたいと思ったので(それはlibtoolのを結ぶことを理解していないような場合、代わりに打ち鳴らすの凶悪libtool使用打ち鳴らす++で

/bin/bash libtool --tag=CC --mode=link clang-3.6 ... -fsanitize=undefined -o freeswitch ... 
libtool: link: clang-3.6 ... -fsanitize=undefined -o .libs/freeswitch ./.libs/libfreeswitch.so ... 
./.libs/libfreeswitch.so: undefined reference to `__ubsan_vptr_type_cache' 
./.libs/libfreeswitch.so: undefined reference to `__ubsan_handle_dynamic_type_cache_miss' 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

:そうしないと次のようなエラーを取得することができますC++を使用してアーカイブ(libfreeswitch.la)(--tag=CCに注意してください)C++リンカが必要であることを意味する。また、https://lists.debian.org/debian-mentors/2003/06/msg00004.htmlを参照してください。

、この問題を回避するhttps://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.htmlで指示に従うと、(本当/ダミー)を追加するにはあなたにC++ソースあなたのソース:Makefile.am

SUBDIRS = sub1 sub2 … 
lib_LTLIBRARIES = libtop.la 
libtop_la_SOURCES = 
# Dummy C++ source to cause C++ linking. 
nodist_EXTRA_libtop_la_SOURCES = dummy.cxx 
libtop_la_LIBADD = \ 
    sub1/libsub1.la \ 
    sub2/libsub2.la \ 
    …