[cfe-dev] -fsanitize=undefined and shared libraries

Will Dietz willdtz at gmail.com
Sun Jan 27 16:56:41 PST 2013


See: http://llvm.org/bugs/show_bug.cgi?id=14469 , which I can
reproduce locally using -fsanitize=integer -m32 and by multiplying two
64bit integers together.

The issue is we emit overflow intrinsics that aren't neatly supported
on the platform and so a call to the supporting runtime is emitted
instead.  Unfortunately libgcc doesn't implement __mulodi4
(compiler-rt does) resulting in the undefined reference you're seeing.

Unfortunately I don't know a good way to convince clang that
compiler-rt is available and to use that instead of libgcc, and it
seems Motsak in the bug report has the same question.  As a kludge of
a workaround, you can manually add the libclang_rt library for your
architecture to your linker invocation (like:
/path/to/libclang_rt.i386.a), which I've used myself to get around
this issue in the past.

Perhaps someone more familiar with the issue can comment on the
challenges in resolving the linked bug?

Hope this helps,

~Will

On Sun, Jan 27, 2013 at 4:22 PM, zapadinsky <zapadinsky at gmail.com> wrote:
> Sorry for bringing this thread up again...
> I've updated clang and compiler-rt to current trunk. Now I have this error
> trying to link against libMyLib.so which was linked with -fsanitize=integer
> switch:
>
> clang++ -fsanitize=integer ... -lMyLib -o ...
> /.../libMyLib.so: undefined reference to `__mulodi4'
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> I'm trying to localize the problem but have no big progress for now. It is
> not reproduced on a simple shared lib project. Any ideas? Without -fsanitize
> all works fine
>
>
>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/fsanitize-undefined-and-shared-libraries-tp4029561p4030098.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list