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
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
: 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