This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -fsanitize=undefined in a freestanding environment


Hello,

> 
> I would like to use asan in a freestanding environment. According to link errors, it should be enough to provide functions like:
> __ubsan_handle_type_mismatch
> __ubsan_handle_out_of_bounds
> __ubsan_handle_sub_overflow
> __ubsan_handle_add_overflow
> 
> etc.
> 
> Is there such an implementation somewhere? Or is it even possible to configure GCC to build the asan for a generic "elf" target? (just adding --enable-> libsanitizer to configure does "nothing")


In the meantime I've implemented dummy handlers:

#define DASAN(func) \
ÂÂÂ extern void func(void *p); \
ÂÂÂ void func(void *p) \
ÂÂÂ { \
ÂÂÂÂÂÂÂ printf("\n"#func ":Â %p ptr: %p\n", __builtin_return_address(0)), p); \
/*ÂÂÂÂÂÂÂ while(1);*/ \
ÂÂÂ }


DASAN(__ubsan_handle_type_mismatch)
DASAN(__ubsan_handle_out_of_bounds)
DASAN(__ubsan_handle_sub_overflow)
DASAN(__ubsan_handle_add_overflow)
DASAN(__ubsan_handle_shift_out_of_bounds)
DASAN(__ubsan_handle_divrem_overflow)
DASAN(__ubsan_handle_negate_overflow)
DASAN(__ubsan_handle_mul_overflow)


which does the job "well enough".

Note the function prototypes are wrong, they should match https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libsanitizer/ubsan/ubsan_handlers.cc#l74 & friends.

Best regards,
Zdenek Sojka


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]