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

Devchandra L Meetei dlmeetei at gmail.com
Wed Jan 9 03:47:37 PST 2013


Did you got compiler-rt?


On Wed, Jan 9, 2013 at 3:53 AM, Martin Martin <
martin at silverliningsystems.com> wrote:

> When trying to use -fsanitize=undefined with shared libraries, I get:
>
> /usr/bin/ld: a.out: hidden symbol `__ubsan_handle_float_cast_overflow' in
> /home/clang/build-cmake/bin/../lib/clang/3.2/lib/linux/libclang_rt.ubsan-x86_64.a(ubsan_handlers.cc.o)
> is referenced by DSO
> /usr/bin/ld: final link failed: Bad value
> clang-3: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> This is with Clang 3.2 compiled from sources using cmake, on Ubuntu 12.10.
>
> I'm compiling my files like this:
>
> clang++ -fPIC -fsanitize=undefined undefined.cpp -c -o undefined.o
> clang++ -shared -Wl,-soname,libfoo.so undefined.o -o libfoo.so
> clang++ -fsanitize=undefined main.cpp -c -o main.o
> clang++ -fsanitize=undefined main.o -L. -lfoo
>
> $ cat undefined.cpp
> int cast(float x) {
>     return int(x);
> }
>
> $ cat main.cpp
> #include <cstdlib>
>
> extern int cast(float x);
>
> int main(int argc, char *argv[])
> {
>     if (argc > 1) {
>         return cast(atof(argv[1]));
>     }
>
>     return 1;
> }
>
> If I don't use shared libraries, but instead like the two .o files
> (without the -fPIC), it works fine, I get:
>
> ./a.out 1e10
> <unknown>: fatal error: value 1e+10 is outside the range of representable
> values of type 'int'
> Illegal instruction (core dumped)
>
>
> Any idea what I'm doing wrong?
>
> Thanks,
> Martin
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>


-- 
Warm Regards
--Dev
OpenPegasus Developer
"It's Always better to try and fail instead of not doing/trying anything"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130109/604c6424/attachment.html>


More information about the cfe-dev mailing list