This is the mail archive of the gcc-patches@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]

[PATCH] fix PR sanitizer/55617 via qsort


   Currently darwin is unable to utilize libasan with constructors due to the lack of
constructor priority support on that target. The asan_finish_file routine inserts an
essential __asan_init into the array of constructors (via the __mod_init_func section).
However the insertion occurs at the end, and due to the lack of priority support for
constructors, these are executed from the front of the array of constructors on program
startup. This causes code any instrumented code that executes before the __asan_init
call to crash. 
   The attached patch uses a va_gc vector of constructor symbol/priority records to
queue this data inside machopic_asm_out_constructor. When the ctors vector is not empty,
the finalize_ctors routine is called in darwin_file_end to sort the queue by priority,
using a qsort stabilized on original position for identical priority, prior to emitting
the constructors. The patch also adds a g++.dg/asan/pr55617.C test case which is
targeted to i?86-*-darwin* and x86_64-*-darwin*.
    The patch reduces the failures observed when running....

make -k check-g++ RUNTESTFLAGS="--target_board=unix'{-fsanitize=address}'"

from 323 to only 85 (which is similar to what linux shows). The cov.C testcase also
fails on gcc trunk with -fsanitize=address when recrafted into a dynamic shared library
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55617#c28. This patch eliminates those
crashes. This problem doesn't extend to when the shared library or module is dlopen'd
(which works in stock gcc trunk and with this patch as well).
    The patch has been bootstrap and regression tested on x86_64-apple-darwin12.
Okay for gcc trunk?
         Jack
ps The issue of inter module priority support remains unresolved (as it is in clang/llvm).
The only solution for both compilers is to reorder the linkage of the modules to insure that the
module with the asan constructor appears first.

Attachment: final_vec_qsort.patch
Description: Text document


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