[cfe-dev] -fsanitize=undefined and shared libraries
Martin Martin
martin at silverliningsystems.com
Tue Jan 8 14:23:18 PST 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130108/84b96c53/attachment.html>
More information about the cfe-dev
mailing list