編集: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.a
and libclang_rt.ubsan_osx.a
(またはLinux では and) ですlibclang_rt.full-x86_64.a
。libclang_rt.ubsan-x86_64.a
ライブラリを提供するために、次のものをエクスポートします。注: これはであり、他のほとんどの関連ツールが期待するものではLIBS
ありません。LDLIBS
make
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プロジェクトを構成するにはどうすればよいですか?
おまけ: なぜこんなに簡単なことがこんなに難しくなったのか?