On Fri, Feb 22, 2013 at 4:58 AM, Jakub Jelinek <ja...@redhat.com> wrote: > On Fri, Feb 22, 2013 at 11:53:39AM +0400, Konstantin Serebryany wrote: >> Jakub, thanks again for cleaning up my mess. >> >> Here is a question regarding your fix: >> > -#if ASAN_USE_PREINIT_ARRAY >> > +#if ASAN_USE_PREINIT_ARRAY && !defined (PIC) >> >> The PIC macro is an artifact of the GCC build system and is not >> directly related the the -fPIC flag? >> As I can see, in the gcc build we compile all of asan sources twice: >> w/ and w/o "-fPIC -DPIC". >> If I move the preinit_array to a separate file (asan_preinit.cc), will >> we need to have two builds? >> I think we can just build all objects once with -fPIC and then not >> link asan_preinit.o into libasan.so >> In clang we build the static libasan with -fPIC, it doesn't hurt. >> Anyway, I've just committed >> http://llvm.org/viewvc/llvm-project?rev=175871&view=rev with >> asan_preinit.cc > > Here is corresponding gcc patch to use it. > libasan_preinit.o is installed alongside with libasan.a and libasan.so*, > and linked into executables (but not shared libraries). > > Additionally, I've added __attribute__((constructor)) to __asan_init, > to make it more likely that asan will be initialized properly even when > the executable isn't instrumented. Shared libraries linked with > -fsanitize=address will depend on libasan.so.0, and the dynamic linker first > runs constructors of dependencies before running constructors of the > libraries that have those dependencies (unless there are dependency cycles, > but that > is a user bug). > > 2013-02-22 Jakub Jelinek <ja...@redhat.com> > > PR sanitizer/56393 > * config/gnu-user.h (LIBASAN_EARLY_SPEC): Link in libasan_preinit.o > if not linking a shared library. > > * lib/asan-dg.exp (asan_link_flags): Add > -B${gccpath}/libsanitizer/asan/ to flags. > > * asan/Makefile.am (nodist_toolexeclib_HEADERS): Set to > libasan_preinit.o. > (libasan_preinit.o): Depend on asan_preinit.o. > * asan/Makefile.in: Regenerated. > * asan/asan_preinit.cc: New file, synced from upstream. > * asan/asan_rtl.cc: Remove preinit stuff, synced from upstream. > Add __attribute__((constructor)) to __asan_init. >
We also need this patch. OK to install? Thanks. H.J. -- 2013-02-22 H.J. Lu <hongjiu...@intel.com> * bootstrap-asan.mk (POSTSTAGE1_LDFLAGS): Add -B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/asan/. diff --git a/config/bootstrap-asan.mk b/config/bootstrap-asan.mk index d37a9da..e3f34f5 100644 --- a/config/bootstrap-asan.mk +++ b/config/bootstrap-asan.mk @@ -3,4 +3,5 @@ STAGE2_CFLAGS += -fsanitize=address STAGE3_CFLAGS += -fsanitize=address POSTSTAGE1_LDFLAGS += -fsanitize=address -static-libasan \ + -B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/asan/ \ -B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/asan/.libs