Patchwork r196201 - in /trunk: gcc/ChangeLog gcc/config/i...

login
register
mail settings
Submitter H.J. Lu
Date Feb. 22, 2013, 10:42 p.m.
Message ID <CAMe9rOpixSR5DRcoP5Bhg63df-3sx9trH4ppiBnRy3oYdo5VMA@mail.gmail.com>
Download mbox | patch
Permalink /patch/222690/
State New
Headers show

Comments

H.J. Lu - Feb. 22, 2013, 10:42 p.m.
On Fri, Feb 22, 2013 at 4:58 AM, Jakub Jelinek <jakub@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  <jakub@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.lu@intel.com>

	* bootstrap-asan.mk (POSTSTAGE1_LDFLAGS): Add
	-B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/asan/.
Jakub Jelinek - Feb. 24, 2013, 6:20 p.m.
On Fri, Feb 22, 2013 at 02:42:44PM -0800, H.J. Lu wrote:
> 2013-02-22  H.J. Lu  <hongjiu.lu@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

Ok.

	Jakub
Toon Moene - Feb. 26, 2013, 7:03 p.m.
On 02/24/2013 07:20 PM, Jakub Jelinek wrote:

> On Fri, Feb 22, 2013 at 02:42:44PM -0800, H.J. Lu wrote:
>> 2013-02-22  H.J. Lu<hongjiu.lu@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
>
> Ok.
>
> 	Jakub

After this went in, I got further now:

http://gcc.gnu.org/ml/gcc-testresults/2013-02/msg02974.html

than before:

http://gcc.gnu.org/ml/gcc-testresults/2013-02/msg02749.html

Patch

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