6

編集:TLDRの場合は、一番下までスキップしてください。私が尋ねる場所:静的ライブラリを使用するように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.aand libclang_rt.ubsan_osx.a(またはLinux では and) ですlibclang_rt.full-x86_64.alibclang_rt.ubsan-x86_64.a

ライブラリを提供するために、次のものをエクスポートします。: これはであり、他のほとんどの関連ツールが期待するものではLIBSありません。LDLIBSmake

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、2 つの問題が発生しているように見えます。/usr/local/...まず、 からに変更することで、パスが解体され/Users/jwalton/...ます。次に、静的ライブラリから動的ライブラリに変更することで、ファイル名が解体されています。

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

別の試みで、次を使用してみました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'

そして、結果からlibプレフィックスと.aサフィックスを削除すると、次のようになります。LIBS

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'

を追加すると、次の-lようになりLIBSます。

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

最後に、-L引数は有効です。

$ 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プロジェクトを構成するにはどうすればよいですか?

おまけ: なぜこんなに簡単なことがこんなに難しくなったのか?

4

3 に答える 3

5

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

于 2013-12-19T14:49:36.530 に答える
3

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 がライブラリ マジックを処理する必要があります。

于 2015-10-19T18:38:53.500 に答える