This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -fsanitize=undefined in a freestanding environment
- From: "Zdenek Sojka" <zsojka at seznam dot cz>
- To: "Zdenek Sojka" <zsojka at seznam dot cz>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 18 May 2016 12:13:36 +0200 (CEST)
- Subject: Re: -fsanitize=undefined in a freestanding environment
- Authentication-results: sourceware.org; auth=none
- References: <6t7 dot 2odq dot 3{zgb5bN{ss dot 1NF1ZZ at seznam dot cz>
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