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.a
とlibclang_rt.ubsan_osx.a
(またはLinux上のlibclang_rt.full-x86_64.a
とlibclang_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'
とで-l
LIBS
に結果を追加
$ 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プロジェクトを設定するにはどうすればよいですか?
ボーナスポイント:どうしてそんなに簡単にできないのですか?
ああ、完璧です。どうもありがとうございました。私はこれらの変更を行うつもりはないが、Autotoolsの問題と消毒剤の解決策を明確に示している。彼らはおそらく "sanitzer"もチェックしておくべきでしょう。例えば、私は 'CXXFLAGS'に対して以下を使用します:' -fsanitize = undefined -fno-sanitize = vptr'。 – jww
MacPortsを使用している場合は、libtoolポートをインストールするだけです。すでにパッチがあります。あなたのプロジェクトで 'autoreconf'や' glibtoolize'を再実行して新しいバージョンを手に入れる必要がありますが、それは助けになるはずです。 –