[llvm-dev] Where does the LLVM implement the Ubsan's instrumentations?

Vedant Kumar via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 25 11:56:37 PDT 2017

> On Jul 22, 2017, at 6:06 AM, Shi, Steven <steven.shi at intel.com> wrote:
> > You might try compiling with '-fsanitize=undefined -fno-sanitize-
> > Ubsan doesn't provide an option of using callbacks to implement its
> > instrumentation. If the no-recovery mode won't work for you, it's pretty
> > simply to write a custom ubsan runtime that fits in a single object file. That's
> > what I ended up doing to sanitize our kernel (xnu), so I can offer help if you
> > decide to go down that path.
> Vedant,
> Thank you. I'm OK to write customized runtime libs for Ubsan. In fact, I did in this way when I enable the Asan in my firmware. My problem is how to correctly implement the UBsan C++ runtime lib with pure C functions in my firmware. You know, the UBsan define the runtime interface in C++, which is different from the Asan extern "C" ones.

The UBSan runtime uses `extern "C"' too, though this may not be apparent due to the use of macros to generate the handler declarations. The full ubsan interface is listed in the ubsan_interface.inc file.

> Many UBsan RT lib input parameters type are mixed with C++ Class. I'm not sure how to correctly parse the C++ class with C structure. E.g. Many UBsan RT functions use the Class SourceLocation to pass the source location info. How should I parse or map the class SourceLocation layout to a C structure?

It isn't necessary to change the definition of SourceLocation, since it's only used by the runtime. The handler functions accept pointers to SourceLocation objects, so as long as the runtime's definition matches the structures the compiler emits, things work. The only thing to note about SourceLocation is that you'll need to use __sync_lock_test_and_set in the acquire() method.

> llvm\projects\compiler-rt\lib\ubsan\ubsan_value.h
> class SourceLocation {
>   const char *Filename;
>   u32 Line;
>   u32 Column;
> public:
>   SourceLocation() : Filename(), Line(), Column() {}
>   SourceLocation(const char *Filename, unsigned Line, unsigned Column)
>     : Filename(Filename), Lin
> .... .... 
> }
> I’d like to take a look at your XNU Ubsan runtime lib code, and if you have open-sourced them, please show me their links. Thank you!

This is in a slightly grey area, and I'd have to ask around to make sure it's fine for me to post the source somewhere.


> Thanks
> Steven

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170725/a60b3946/attachment.html>

More information about the llvm-dev mailing list