[PATCH] --eh-frame-hdr had no effect on certain executables

Jan Beulich jbeulich@novell.com
Mon Nov 20 16:49:00 GMT 2006


This patch rearranges things so that executables not participating in dynamic
linking can still get an .eh_frame_hdr section. This is particularly intended
for the Linux kernel. The changed execution flow made it necessary to adjust
a few test cases, which previously depended on linker internals.

bfd/
2006-11-20  Jan Beulich  <jbeulich@novell.com>

	* elflink.c (_bfd_elf_link_create_dynamic_sections): Move creation of
	.eh_frame_hdr sectioin from here ...
	(elf_link_add_object_symbols): ... to here.
	(bfd_elf_size_dynamic_sections): Call _bfd_elf_maybe_strip_eh_frame_hdr
	a little earlier.

include/
2006-11-20  Jan Beulich  <jbeulich@novell.com>

	* bfdlink.h (struct bfd_link_info): New field can_place_orphan.

ld/
2006-11-20  Jan Beulich  <jbeulich@novell.com>

	* ldemul.h (ldemul_can_place_orphan): Declare.
	* ldemul.c (ldemul_can_place_orphan): New.
	* ldmain.c (main): Initialize link_info.can_place_orphan.

ld/testsuite/
2006-11-20  Jan Beulich  <jbeulich@novell.com>

	* ld-elf/eh-frame-hdr.d: New.
	* ld-elf/eh-frame-hdr.s: New.
	* ld-elf/symbol2w.s: Move Foo into a non-removed section.
	* ld-elf/warn2.d: Don't depend on the exact section number Foo ends up
	in.
	* ld-ia64/tlsbin.dd, ld-ia64/tlsbin.sd: Don't depend on exact linkage
	table layout.

--- /home/jbeulich/src/binutils/mainline/2006-11-14/bfd/elflink.c	2006-11-13 15:21:56.000000000 +0100
+++ 2006-11-14/bfd/elflink.c	2006-11-20 12:28:41.000000000 +0100
@@ -185,16 +185,6 @@ _bfd_elf_link_create_dynamic_sections (b
 	return FALSE;
     }
 
-  if (! info->traditional_format)
-    {
-      s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
-				       flags | SEC_READONLY);
-      if (s == NULL
-	  || ! bfd_set_section_alignment (abfd, s, 2))
-	return FALSE;
-      elf_hash_table (info)->eh_info.hdr_sec = s;
-    }
-
   /* Create sections to hold version informations.  These are removed
      if they are not needed.  */
   s = bfd_make_section_with_flags (abfd, ".gnu.version_d",
@@ -3294,14 +3284,31 @@ elf_link_add_object_symbols (bfd *abfd, 
 	 sections immediately.  We need to attach them to something,
 	 so we attach them to this BFD, provided it is the right
 	 format.  FIXME: If there are no input BFD's of the same
-	 format as the output, we can't make a shared library.  */
-      if (info->shared
-	  && is_elf_hash_table (htab)
-	  && htab->root.creator == abfd->xvec
-	  && !htab->dynamic_sections_created)
+	 format as the output, we can't make a shared library.
+	 Also create the .eh_frame_hdr section here, as its presence
+	 is not tied to the presence of any dynamic sections.  */
+      if (is_elf_hash_table (htab))
 	{
-	  if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
+	  if (info->shared
+	      && htab->root.creator == abfd->xvec
+	      && ! htab->dynamic_sections_created
+	      && ! _bfd_elf_link_create_dynamic_sections (abfd, info))
 	    goto error_return;
+	  if (info->can_place_orphan
+	      && ! info->traditional_format
+	      && ! info->relocatable
+	      && ! htab->eh_info.hdr_sec)
+	    {
+	      asection *s;
+
+	      s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
+					       bed->dynamic_sec_flags
+					       | SEC_READONLY);
+	      if (s == NULL
+		 || ! bfd_set_section_alignment (abfd, s, 2))
+		goto error_return;
+	      htab->eh_info.hdr_sec = s;
+	    }
 	}
     }
   else if (!is_elf_hash_table (htab))
@@ -5281,6 +5288,9 @@ bfd_elf_size_dynamic_sections (bfd *outp
       && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
     return FALSE;
 
+  if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
+    return FALSE;
+
   dynobj = elf_hash_table (info)->dynobj;
 
   /* If there were no dynamic objects in the link, there is nothing to
@@ -5288,9 +5298,6 @@ bfd_elf_size_dynamic_sections (bfd *outp
   if (dynobj == NULL)
     return TRUE;
 
-  if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
-    return FALSE;
-
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       struct elf_info_failed eif;
--- /home/jbeulich/src/binutils/mainline/2006-11-14/include/bfdlink.h	2006-11-13 15:22:06.000000000 +0100
+++ 2006-11-14/include/bfdlink.h	2006-11-20 12:33:51.000000000 +0100
@@ -340,6 +340,9 @@ struct bfd_link_info
      caching ELF symbol buffer.  */
   unsigned int reduce_memory_overheads: 1;
 
+  /* TRUE if there is a place_orphan backend function.  */
+  unsigned int can_place_orphan: 1;
+
   /* What to do with unresolved symbols in an object file.
      When producing executables the default is GENERATE_ERROR.
      When producing shared libraries the default is IGNORE.  The
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/ldemul.c	2005-11-17 08:25:36.000000000 +0100
+++ 2006-11-14/ld/ldemul.c	2006-11-20 12:26:32.000000000 +0100
@@ -121,6 +121,12 @@ ldemul_open_dynamic_archive (const char 
 }
 
 bfd_boolean
+ldemul_can_place_orphan (void)
+{
+  return ld_emulation->place_orphan != NULL;
+}
+
+bfd_boolean
 ldemul_place_orphan (asection *s)
 {
   if (ld_emulation->place_orphan)
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/ldemul.h	2005-11-17 08:25:36.000000000 +0100
+++ 2006-11-14/ld/ldemul.h	2006-11-20 12:25:34.000000000 +0100
@@ -53,6 +53,8 @@ extern void ldemul_set_symbols
   (void);
 extern void ldemul_create_output_section_statements
   (void);
+extern bfd_boolean ldemul_can_place_orphan
+  (void);
 extern bfd_boolean ldemul_place_orphan
   (asection *);
 extern bfd_boolean ldemul_parse_args
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/ldmain.c	2006-11-13 15:22:07.000000000 +0100
+++ 2006-11-14/ld/ldmain.c	2006-11-20 12:39:57.000000000 +0100
@@ -320,6 +320,7 @@ main (int argc, char **argv)
   link_info.print_gc_sections = FALSE;
   link_info.dynamic = NULL;
   link_info.reduce_memory_overheads = FALSE;
+  link_info.can_place_orphan = FALSE;
 
   config.maxpagesize = 0;
   config.commonpagesize = 0;
@@ -334,6 +335,7 @@ main (int argc, char **argv)
   emulation = get_emulation (argc, argv);
   ldemul_choose_mode (emulation);
   default_target = ldemul_choose_target (argc, argv);
+  link_info.can_place_orphan = ldemul_can_place_orphan ();
   lang_init ();
   ldemul_before_parse ();
   lang_has_input_file = FALSE;
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/testsuite/ld-elf/eh-frame-hdr.d	1970-01-01 01:00:00.000000000
+0100
+++ 2006-11-14/ld/testsuite/ld-elf/eh-frame-hdr.d	2006-11-20 10:11:18.000000000 +0100
@@ -0,0 +1,17 @@
+#source: eh-frame-hdr.s
+#ld: -e _start --eh-frame-hdr
+#objdump: -hw
+#target: alpha*-*-*
+#target: arm*-*-*
+#target: i?86-*-*
+#target: m68k-*-*
+#target: mips*-*-*
+#target: powerpc*-*-*
+#target: s390*-*-*
+#target: sh*-*-*
+#xfail: sh*l*-*-*
+#target: sparc*-*-*
+#target: x86_64-*-*
+#...
+  [0-9] .eh_frame_hdr 0*[12][048c] .*
+#pass
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/testsuite/ld-elf/eh-frame-hdr.s	1970-01-01 01:00:00.000000000
+0100
+++ 2006-11-14/ld/testsuite/ld-elf/eh-frame-hdr.s	2006-11-16 16:25:06.000000000 +0100
@@ -0,0 +1,6 @@
+	.text
+	.global _start
+_start:
+	.cfi_startproc
+	.skip 16
+	.cfi_endproc
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/testsuite/ld-elf/symbol2w.s	2006-11-08 11:21:12.000000000
+0100
+++ 2006-11-14/ld/testsuite/ld-elf/symbol2w.s	2006-11-20 10:35:50.000000000 +0100
@@ -1,4 +1,6 @@
         .section        .gnu.warning,"a",%progbits
+        .string "function 'Foo' used"
+        .data
 	.global Foo
         .type   Foo, %object
         .size   Foo, 20
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/testsuite/ld-elf/warn2.d	2006-11-06 11:39:17.000000000
+0100
+++ 2006-11-14/ld/testsuite/ld-elf/warn2.d	2006-11-20 10:38:25.000000000 +0100
@@ -11,5 +11,5 @@
 # construct and that the symbol still appears as expected.
 
 #...
-[ 	]+[0-9]+:[ 	]+[0-9a-f]+[ 	]+20[ 	]+OBJECT[	 ]+GLOBAL DEFAULT[ 	]+1 Foo
+[ 	]+[0-9]+:[ 	]+[0-9a-f]+[ 	]+20[ 	]+OBJECT[	 ]+GLOBAL DEFAULT[ 	]+[1-9] Foo
 #pass
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/testsuite/ld-ia64/tlsbin.dd	2005-08-18 08:52:00.000000000
+0200
+++ 2006-11-14/ld/testsuite/ld-ia64/tlsbin.dd	2006-11-17 12:16:38.000000000 +0100
@@ -13,25 +13,25 @@ Disassembly of section .text:
 40+1000:	10 10 15 06 80 05[ 	]+\[MIB\][ 	]+alloc r34=ar.pfs,5,3,0
 40+1006:	10 02 00 62 00 00[ 	]+mov r33=b0
 40+100c:	00 00 00 20[ 	]+nop.b 0x0
-40+1010:	0d 70 80 02 00 24[ 	]+\[MFI\][ 	]+addl r14=32,r1
+40+1010:	0d 70 .0 0. 00 24[ 	]+\[MFI\][ 	]+addl r14=(24|32|40|48|56|64),r1
 40+1016:	00 00 00 02 00 e0[ 	]+nop.f 0x0
-40+101c:	81 0a 00 90[ 	]+addl r15=40,r1;;
+40+101c:	.1 0. 00 90[ 	]+addl r15=(24|32|40|48|56|64),r1;;
 40+1020:	19 18 01 1c 18 10[ 	]+\[MMB\][ 	]+ld8 r35=\[r14\]
 40+1026:	40 02 3c 30 20 00[ 	]+ld8 r36=\[r15\]
 40+102c:	[0-9a-f 	]+br.call.sptk.many b0=[0-9a-f]+ <.*>;;
-40+1030:	0d 70 c0 02 00 24[ 	]+\[MFI\][ 	]+addl r14=48,r1
+40+1030:	0d 70 .0 0. 00 24[ 	]+\[MFI\][ 	]+addl r14=(24|32|40|48|56|64),r1
 40+1036:	00 00 00 02 00 e0[ 	]+nop.f 0x0
-40+103c:	01 0c 00 90[ 	]+addl r15=64,r1;;
+40+103c:	.1 0. 00 90[ 	]+addl r15=(24|32|40|48|56|64),r1;;
 40+1040:	19 18 01 1c 18 10[ 	]+\[MMB\][ 	]+ld8 r35=\[r14\]
 40+1046:	40 02 3c 30 20 00[ 	]+ld8 r36=\[r15\]
 40+104c:	[0-9a-f 	]+br.call.sptk.many b0=[0-9a-f]+ <.*>;;
-40+1050:	0d 70 c0 02 00 24[ 	]+\[MFI\][ 	]+addl r14=48,r1
+40+1050:	0d 70 .0 0. 00 24[ 	]+\[MFI\][ 	]+addl r14=(24|32|40|48|56|64),r1
 40+1056:	00 00 00 02 00 80[ 	]+nop.f 0x0
 40+105c:	14 02 00 90[ 	]+mov r36=33;;
 40+1060:	1d 18 01 1c 18 10[ 	]+\[MFB\][ 	]+ld8 r35=\[r14\]
 40+1066:	00 00 00 02 00 00[ 	]+nop.f 0x0
 40+106c:	[0-9a-f 	]+br.call.sptk.many b0=[0-9a-f]+ <.*>;;
-40+1070:	0d 70 c0 02 00 24[ 	]+\[MFI\][ 	]+addl r14=48,r1
+40+1070:	0d 70 .0 0. 00 24[ 	]+\[MFI\][ 	]+addl r14=(24|32|40|48|56|64),r1
 40+1076:	00 00 00 02 00 80[ 	]+nop.f 0x0
 40+107c:	04 00 00 84[ 	]+mov r36=r0;;
 40+1080:	1d 18 01 1c 18 10[ 	]+\[MFB\][ 	]+ld8 r35=\[r14\]
@@ -51,11 +51,11 @@ Disassembly of section .text:
 40+10cc:	08 00 84 00[ 	]+br.ret.sptk.many b0;;
 
 40+10d0 <_start>:
-40+10d0:	0b 70 60 02 00 24[ 	]+\[MMI\][ 	]+addl r14=24,r1;;
+40+10d0:	0b 70 .0 0. 00 24[ 	]+\[MMI\][ 	]+addl r14=(24|32|40|48|56|64),r1;;
 40+10d6:	e0 00 38 30 20 00[ 	]+ld8 r14=\[r14\]
 40+10dc:	00 00 04 00[ 	]+nop.i 0x0;;
 40+10e0:	0b 70 38 1a 00 20[ 	]+\[MMI\][ 	]+add r14=r14,r13;;
-40+10e6:	e0 c0 05 00 48 00[ 	]+addl r14=56,r1
+40+10e6:	e0 .0 0. 00 48 00[ 	]+addl r14=(24|32|40|48|56|64),r1
 40+10ec:	00 00 04 00[ 	]+nop.i 0x0;;
 40+10f0:	0b 70 00 1c 18 10[ 	]+\[MMI\][ 	]+ld8 r14=\[r14\];;
 40+10f6:	e0 70 34 00 40 00[ 	]+add r14=r14,r13
--- /home/jbeulich/src/binutils/mainline/2006-11-14/ld/testsuite/ld-ia64/tlsbin.sd	2005-07-18 08:04:02.000000000
+0200
+++ 2006-11-14/ld/testsuite/ld-ia64/tlsbin.sd	2006-11-17 12:19:26.000000000 +0100
@@ -11,5 +11,5 @@ Contents of section .got:
  (60+)?1318 0+ 0+ 0+ 0+  .*
  (60+)?1328 0+ 0+ 0+ 0+  .*
  (60+)?1338 0+ 0+ 0+ 0+  .*
- (60+)?1348 01000000 0+ 90000000 0+  .*
- (60+)?1358 24000000 0+  .*
+ (60+)?1348 (00|01|24|90)000000 0+ (00|01|24|90)000000 0+  .*
+ (60+)?1358 (00|01|24|90)000000 0+  .*




More information about the Binutils mailing list