This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

Avoid GCC 4.7 optimization in elf/soinit.c


We recently got a bug report and analysis showed that gcc 4.7 optimized 
__libc_fini and __libc_global_ctors to empty functions since it checked the 
size of __CTOR_LIST__ and does not know that glibc changes the size at link 
time.

Bug report is:
https://bugzilla.novell.com/show_bug.cgi?id=717671

I'm appending a patch that fixes the problem,

Andreas

2011-09-27  Richard Guenther  <rguenther@suse.de>

	* elf/soinit.c (__libc_global_ctors): Avoid GCC 4.7 optimization.
	(__libc_fini): Likewise.

diff --git a/elf/soinit.c b/elf/soinit.c
index 7139830..56c19dd 100644
--- a/elf/soinit.c
+++ b/elf/soinit.c
@@ -25,8 +25,13 @@ run_hooks (void (*const list[]) (void))
 void
 __libc_global_ctors (void)
 {
+  /* GCC 4.7 is able to figure out that the list contains only one
+     entry and thus optimized the call to run_hooks away. The following
+     lines disallow this optimization.  */
+  void (**tem)();
+  asm ("" : "=r" (tem) : "0" (__CTOR_LIST__));
   /* Call constructor functions.  */
-  run_hooks (__CTOR_LIST__);
+  run_hooks (tem);
 }
 
 
@@ -35,8 +40,13 @@ __libc_global_ctors (void)
 void
 __libc_fini (void)
 {
+  /* GCC 4.7 is able to figure out that the list contains only one
+     entry and thus optimized the call to run_hooks away. The following
+     lines disallow this optimization.  */
+  void (**tem)();
+  asm ("" : "=r" (tem) : "0" (__DTOR_LIST__));
   /* Call destructor functions.  */
-  run_hooks (__DTOR_LIST__);
+  run_hooks (tem);
 }
 
 void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))

-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126
diff --git a/elf/soinit.c b/elf/soinit.c
index 7139830..56c19dd 100644
--- a/elf/soinit.c
+++ b/elf/soinit.c
@@ -25,8 +25,13 @@ run_hooks (void (*const list[]) (void))
 void
 __libc_global_ctors (void)
 {
+  /* GCC 4.7 is able to figure out that the list contains only one
+     entry and thus optimized the call to run_hooks away. The following
+     lines disallow this optimization.  */
+  void (**tem)();
+  asm ("" : "=r" (tem) : "0" (__CTOR_LIST__));
   /* Call constructor functions.  */
-  run_hooks (__CTOR_LIST__);
+  run_hooks (tem);
 }
 
 
@@ -35,8 +40,13 @@ __libc_global_ctors (void)
 void
 __libc_fini (void)
 {
+  /* GCC 4.7 is able to figure out that the list contains only one
+     entry and thus optimized the call to run_hooks away. The following
+     lines disallow this optimization.  */
+  void (**tem)();
+  asm ("" : "=r" (tem) : "0" (__DTOR_LIST__));
   /* Call destructor functions.  */
-  run_hooks (__DTOR_LIST__);
+  run_hooks (tem);
 }
 
 void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))

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