Hi,Is there anyway to build a shared object with asan support and load this in a non-asan executable?
The third party executable has support for loading shared objects to provide extra functionality but it is not built with asan; this results in an undefined symbol error.A similar thread previously addressed this point with regard to python and the conclusion was to rebuild python with asan. Unfortunately this is not an option; is there any work around?
--Thanks,Mark
You received this message because you are subscribed to the Google Groups "address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to address-saniti...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You can build asan.so from LLVM tree like this:cd lvm/projects/compiler-rt/libclang -o asan.so -DASAN_USE_PREINIT_ARRAY=0 -fno-exceptions -fno-rtti -I. -O2 -fPIC -shared asan/*.cc sanitizer_common/*.cc interception/*.cc lsan/lsan_common.cc lsan/lsan_common_linux.cc
Cool! My comments below.
> Smaller disk usage
How about "Smaller memory footprint"?
> __asan_init is not called from preinit_array and so there is a risk that an instrumented code will get called before __asan_init
1) Should probably decribe symptoms here (call to NULL).
2) Can we add a check to REAL() to produce a nice diagnostic message
in this case?
3) We once discussed making __asan_init a constructor to solve this
problem (discussion and patch available here:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58937).
> the binary is linked against incompatible DSO version
Nice one. I wonder whether we can catch this in preloaded libasan
(e.g. search for all older __asan_init_vXXX using dlsym at start).
Can you add other bugs as well?
>> There are some bugs specific to using asan as a shared library, e.g.
Some proposal from me:
* could you add a note about spurious "failed to intercept" warnings?
(see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58680 for reference)
BTW should we acronimize as ASAN or ASan?
>> 2) Can we add a check to REAL() to produce a nice diagnostic messageI don't think that REAL() currently checks anything:
>> in this case?
>
> There are a few such checks.
~/llvm/trunk/projects/compiler-rt/lib$ grep NULL interception/* -l
interception/interception_win.cc
We seem to rely on callers to make sure that these variables are
properly initialized.
Are you sure? I don't see any ctors in compiler-rt trunk:
>> 3) We once discussed making __asan_init a constructor to solve this
>> problem (discussion and patch available here:
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58937).
>
>
> __asan_init is a constructor, but there could be other constructors that run
> before it.
~/llvm/trunk/projects/compiler-rt/lib/asan$ grep constructor * | grep
-v TestCases
asan_thread.cc: // On Android, libc constructor is called _after_
asan_init, and cleans up
asan_thread.h: // NOTE: There is no AsanThread constructor. It is allocated
Added to Cons section in wiki.
>> Some proposal from me:
>> * could you add a note about spurious "failed to intercept" warnings?
>> (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58680 for reference)
>
> Hm? What about that? How would you phrase it?
>> I don't think that REAL() currently checks anything:That's what I meant to say - instead or relying on interceptors (I'm
>
> REAL doesn't check anything. Some interceptors do the checks
pretty sure we missed something out or may miss in future), just check
it directly in REAL().
Is this one coming from asan_preinit? What about unsanitized
>> Are you sure? I don't see any ctors in compiler-rt trunk:
>
> The compiler eimits a CTOR function that call __asan_init
executable with preloaded ASan runtime? My proposal was to add ctor
directly to ASan runtime.
Well, debug output is the first thing people will check when something
> First, debug output concerns only developers, not (most) users.
goes wrong with ASan DSO will stop working for them so I think it
makes sense to give some hints.
Not really, it's the idiosyncrasy of Linux ld.so which resolves
> Second, what does this output mean?
> I suspect that this means the same thing as with -static-libstdc++ -- asan
> failed to intercept one of the functions is wants to intercept.
intercepted symbols to PLT entries in main executable instead of ASan
interceptors. These warnings are really spurious and misleading
(please refer to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58680 for
more details).
Here is one example which currently works by pure luck:
INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act,
struct sigaction *oldact) {
if (!AsanInterceptsSignal(signum) ||
common_flags()->allow_user_segv_handler) {
return REAL(sigaction)(signum, act, oldact);
}
Note the lack of ENSURE_ASAN_INITED - this may easily result in call
to NULL function if we preload libasan to unsanitized executable which
calls signal() at start of main. The only reason why it manages to
work is because libstdc++ calls __cxa_atexit at start and this calls
ENSURE_ASAN_INITED. But relying on __cxa_atexit is surely messy.
Having an __attribute__((constructor)) for __asan_init would clean all
this stuff up.
Well, I'll keep hoping then)
> Ah. Now I remember this. Yes, we may want to improve the warning to handle
> the PLT case.
> No idea how, and the change would need to be testable in LLVM tree, which in
> turn requires that
> we build and support asan-dso in llvm tree as a non-default alternative to
> the static run-time.
> We may eventually get to it, but no promises.