[cfe-dev] recent change broke -fcatch-undefined-behavior

Richard Smith richard at metafoo.co.uk
Mon Oct 15 23:55:51 PDT 2012


On Mon, Oct 15, 2012 at 11:51 PM, Jean-Daniel Dupas
<devlists at shadowlab.org>wrote:

>
> Le 16 oct. 2012 à 08:42, Alexey Samsonov <samsonov at google.com> a écrit :
>
>
>
> On Tue, Oct 16, 2012 at 1:46 AM, Jean-Daniel Dupas <devlists at shadowlab.org
> > wrote:
>
>>
>> Le 15 oct. 2012 à 23:32, Jean-Daniel Dupas <devlists at shadowlab.org> a
>> écrit :
>>
>>
>> Le 15 oct. 2012 à 21:31, "Sean McBride" <sean at rogue-research.com> a
>> écrit :
>>
>> On Mon, 15 Oct 2012 12:21:17 -0700, David Blaikie said:
>>
>> I see that there have been recent changes wrt -fcatch-undefined-
>>
>> behavior, and within the last week or so something changed such that my
>> own build of clang (built with CMake on OS X) is unable to build simple
>> programs that use -fcatch-undefined-behavior, I get link errors like:
>>
>>
>> "___ubsan_handle_divrem_overflow", referenced from:
>>    _main in test-OSZvjm.o
>> "___ubsan_handle_type_mismatch", referenced from:
>>    _main in test-OSZvjm.o
>>
>> Any ideas why?
>>
>>
>> This is a new feature. Instead of generating traps, -fcatch-undefined-
>> behavior generates library calls that make it easier to find what is
>> wrong (each undefined behavior calls a different function).
>>
>> This functions are provided by the ubsan library that is part of
>> compiler-rt. But I'm not sure the integration to the Makefile build
>> system is done yet.
>>
>>
>> You mean with the CMake build system?
>>
>>
>> Generally "Makefile build system" describes the configure+make build
>> system (at least when it's discussed here).
>>
>> Perhaps if I build using autotools it will work?  Or do you mean it
>>
>> works nowhere yet?
>>
>> I believe the implication is that it works with the CMake build
>> system. But you will need to checkout the compiler-rt LLVM project
>> into llvm/projects to build it along with clang. (& I assume you'll
>> need to install compiler-rt alongside clang as well, but hopefully the
>> install target does that)
>>
>>
>> As I said in my original post, I am using CMake (not autotools aka
>> configure+make).  I do have llvm/projects.
>>
>> My full little 'build everything' script is:
>>
>> ------------
>> (cd ~/llvm/llvm/; svn up)
>> (cd ~/llvm/llvm/tools/clang; svn up)
>> (cd ~/llvm/llvm/projects/compiler-rt; svn up)
>>
>> mkdir -p ~/llvm/llvm-rel-bin
>> rm -rf ~/llvm/llvm-rel-bin/*
>>
>> mkdir -p ~/llvm/llvm-rel-install
>> rm -rf ~/llvm/llvm-rel-install/*
>>
>> cd ~/llvm/llvm-rel-bin
>> CC="$(xcrun --find cc)" CXX="$(xcrun --find c++)" cmake
>> -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF
>> -DCMAKE_INSTALL_PREFIX=~/llvm/llvm-rel-install ../llvm
>> make -j16 install
>>
>>
>> Yep, it looks like the driver integration for the darwin toolchain is
>> missing too.
>>
>> The ubsan library should probably be append to the link flags somewhere
>> in Toolchains.cpp:DarwinClang::AddLinkRuntimeLibArgs(), but I don't see it
>> anywhere.
>>
>>
>> Digging a little further, I found this in ubsan_value.h.
>>
>> // For now, only support linux. Other platforms should be easy to add, and
>> // probably work as-is.
>> #if !defined(__linux__)
>> #error "UBSan not supported for this platform!"
>> #endif
>>
>
> Yes, as I can see ubsan runtime library is currently supported only in
> CMake build and is built on Linux only.
>
>
> That's unfortunate that clang try to emit function calls on platforms that
> does not support it.
>

Right now, we could just emit calls to @llvm.trap on unsupported platforms,
but some of the remaining checks actually need runtime library support. I
would prefer to get the runtime working on more platforms, rather than
working around its absence.


> That said, do you need patches for darwin/make integration, or are you
> already working on it (or planning to do it after usban is done on linux) ?
>

Patches to support Darwin are very much welcome. I don't have a Darwin
machine, so I've not added this support myself.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121015/86262fb3/attachment.html>


More information about the cfe-dev mailing list