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

Will Dietz willdtz at gmail.com
Wed Jan 9 13:32:11 PST 2013


The attached patch should fix the issue for you.

Richard, okay to commit?

~Will

On Wed, Jan 9, 2013 at 6:02 AM, Martin Martin
<martin at silverliningsystems.com> wrote:
> Yes, otherwise it wouldn't work when statically linked.
>
>
> On Wed, Jan 9, 2013 at 6:47 AM, Devchandra L Meetei <dlmeetei at gmail.com>
> wrote:
>>
>> 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"
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ubsan-Give-entry-methods-default-not-hidden-visibili.patch
Type: application/octet-stream
Size: 2875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130109/9a048d03/attachment.obj>


More information about the cfe-dev mailing list