This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: r196201 - in /trunk: gcc/ChangeLog gcc/config/i...
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Konstantin Serebryany <konstantin dot s dot serebryany at gmail dot com>
- Cc: "Zamyatin, Igor" <igor dot zamyatin at intel dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Dodji Seketeli <dodji at redhat dot com>, Dmitry Vyukov <dvyukov at google dot com>
- Date: Thu, 21 Feb 2013 14:21:36 +0100
- Subject: Re: r196201 - in /trunk: gcc/ChangeLog gcc/config/i...
- References: <20130221105711.23596.qmail@sourceware.org> <CAGQ9bdwfaS=fPfurN+fJOgg-2s4-c23A9z97aQtVK71PjfMfQg@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Feb 21, 2013 at 05:15:51PM +0400, Konstantin Serebryany wrote:
> This commit breaks the build if the BFD linker is used (I have gold on
> my box, so I missed it).
>
> Short repro:
> % cat preinit.cc
> void foo() {}
> __attribute__((section(".preinit_array"))) void (*xxx)(void) = foo;
> % g++ preinit.cc -shared # gold
> % sudo apt-get remove binutils-gold
> ...
> % g++ preinit.cc -shared # bfd
> /usr/bin/ld: /tmp/cc4GVflE.o: .preinit_array section is not allowed in DSO
> /usr/bin/ld: failed to set dynamic section sizes: Nonrepresentable
> section on output
> collect2: ld returned 1 exit status
> %
>
> Can we stop building the asan-rt as DSO and leave only the static
> variant (as in clang)?
No, IMNSHO it is desirable to support also that.
Here is a different fix, so libasan.so will not have .preinit_array, but
libasan.a will have it. Ideally, that hunk should go into a separate
source file (asan_preinit.cc ?), be just compiled into an object file,
rather than shared library and the compiler driver should include it
explicitly in the link.
The used attribute is there because, as it isn't (or shouldn't) be exported
out of the library, if libasan was built with LTO, it could very well be
optimized away.
2013-02-21 Jakub Jelinek <jakub@redhat.com>
* asan/asan_rtl.cc (__asan_preinit): Don't add if PIC macro is
defined. Add used attribute.
--- libsanitizer/asan/asan_rtl.cc.jj 2013-02-21 14:10:41.000000000 +0100
+++ libsanitizer/asan/asan_rtl.cc 2013-02-21 14:16:28.985547506 +0100
@@ -520,11 +520,11 @@ void __asan_init() {
}
}
-#if ASAN_USE_PREINIT_ARRAY
+#if ASAN_USE_PREINIT_ARRAY && !defined (PIC)
// On Linux, we force __asan_init to be called before anyone else
// by placing it into .preinit_array section.
// FIXME: do we have anything like this on Mac?
- __attribute__((section(".preinit_array")))
+ __attribute__((section(".preinit_array"), used))
void (*__asan_preinit)(void) =__asan_init;
#elif defined(_WIN32) && defined(_DLL)
// On Windows, when using dynamic CRT (/MD), we can put a pointer
Jakub