public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Issues with ld -shared --build-id
@ 2007-07-24 20:56 Jakub Jelinek
  2007-07-24 23:10 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2007-07-24 20:56 UTC (permalink / raw)
  To: Roland McGrath; +Cc: binutils

Hi!

ld -shared --build-id creates bad DSOs:

  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .note.gnu.build-i NOTE            00000000 001000 000024 00   A  0   0  4
  [ 2] .gnu.hash         GNU_HASH        000000d4 0010d4 000040 04   A  3   0  4
  [ 3] .dynsym           DYNSYM          00000114 001114 0000b0 10   A  4   1  4
  [ 4] .dynstr           STRTAB          000001c4 0011c4 000071 00   A  0   0  1
  [ 5] .gnu.version      VERSYM          00000236 001236 000016 02   A  3   0  2
  [ 6] .gnu.version_r    VERNEED         0000024c 00124c 000020 00   A  4   1  4

note that the SHT_NOTE section has sh_addr 0 rather than 0xd4 (SIZE_OF_HEADERS),
sh_offset 0x1000 rather than 0 and there is quite a big gap between end of
.note.gnu.build-id section and .gnu.hash section.
In addition to being inefficient, e.g. ldconfig doesn't like such libraries.

The issue seems to be in gld*place_orphan, notes are placed on .interp hold,
but unlike executables shared libraries don't have .interp in their linker scripts.
As there aren't even any sections with similar flags like the .note section,
they end up being places right after the *ABS* section, but that's unfortunately
before the . = 0 + SIZE_OF_HEADERS; dot adjustment in the linker script.

The following patch cures this for me (and if we generate --build-id often,
it is probably a good idea anyway to put it there), but perhaps we should
do something with the orphan placement code as well.

2007-07-24  Jakub Jelinek  <jakub@redhat.com>

	* scripttempl/elf.sc: Add .note.gnu.build-id.

--- ld/scripttempl/elf.sc.jj	2007-07-24 10:07:02.000000000 +0200
+++ ld/scripttempl/elf.sc	2007-07-24 21:44:35.000000000 +0200
@@ -267,6 +267,7 @@ SECTIONS
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
   ${INITIAL_READONLY_SECTIONS}
+  .note.gnu.build-id : { *(.note.gnu.build-id) }
   ${TEXT_DYNAMIC+${DYNAMIC}}
   .hash         ${RELOCATING-0} : { *(.hash) }
   .gnu.hash     ${RELOCATING-0} : { *(.gnu.hash) }

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Issues with ld -shared --build-id
  2007-07-24 20:56 [PATCH] Issues with ld -shared --build-id Jakub Jelinek
@ 2007-07-24 23:10 ` Alan Modra
  2007-07-24 23:36   ` Roland McGrath
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2007-07-24 23:10 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, binutils

On Tue, Jul 24, 2007 at 10:22:24PM +0200, Jakub Jelinek wrote:
> 	* scripttempl/elf.sc: Add .note.gnu.build-id.

OK, thanks!

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Issues with ld -shared --build-id
  2007-07-24 23:10 ` Alan Modra
@ 2007-07-24 23:36   ` Roland McGrath
  2007-07-29 16:27     ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Roland McGrath @ 2007-07-24 23:36 UTC (permalink / raw)
  To: Alan Modra; +Cc: Jakub Jelinek, binutils

IIUC the proper orphans placing would put it (SHT_NOTE,SHF_ALLOC) there
anyway.  So it seems best to fix the orphans code and leave out the special
case.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Issues with ld -shared --build-id
  2007-07-24 23:36   ` Roland McGrath
@ 2007-07-29 16:27     ` Alan Modra
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2007-07-29 16:27 UTC (permalink / raw)
  To: binutils; +Cc: Roland McGrath, Jakub Jelinek

On Tue, Jul 24, 2007 at 04:10:47PM -0700, Roland McGrath wrote:
> IIUC the proper orphans placing would put it (SHT_NOTE,SHF_ALLOC) there
> anyway.

This ldlang.c patch fixes the problem Jakub reported, with orphan note
sections being placed before the initial "dot" assignment in a linker
script.  The elf32.em patch improves placement of orphan reloc
sections.

ld/
	* ldlang.c (lang_insert_orphan): When searching through linker
	script to place an orphan, don't stop on statements that appear
	outside of SECTIONS.
	* emultempl/elf32.em (output_rel_find): Prefer read-only alloc
	sections over read/write alloc sections.
ld/testsuite/
	* ld-elf/weak-dyn-1.rd: Adjust.

Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.267
diff -u -p -r1.267 ldlang.c
--- ld/ldlang.c	13 Jul 2007 07:34:25 -0000	1.267
+++ ld/ldlang.c	29 Jul 2007 02:52:28 -0000
@@ -1654,13 +1654,14 @@ lang_insert_orphan (asection *s,
 		    case lang_output_section_statement_enum:
 		      if (assign != NULL)
 			where = assign;
+		      break;
 		    case lang_input_statement_enum:
 		    case lang_address_statement_enum:
 		    case lang_target_statement_enum:
 		    case lang_output_statement_enum:
 		    case lang_group_statement_enum:
 		    case lang_afile_asection_pair_statement_enum:
-		      break;
+		      continue;
 		    }
 		  break;
 		}
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.183
diff -u -p -r1.183 elf32.em
--- ld/emultempl/elf32.em	19 Jul 2007 19:56:10 -0000	1.183
+++ ld/emultempl/elf32.em	29 Jul 2007 02:52:30 -0000
@@ -1567,6 +1567,7 @@ output_rel_find (asection *sec, int isdy
   lang_output_section_statement_type *lookup;
   lang_output_section_statement_type *last = NULL;
   lang_output_section_statement_type *last_alloc = NULL;
+  lang_output_section_statement_type *last_ro_alloc = NULL;
   lang_output_section_statement_type *last_rel = NULL;
   lang_output_section_statement_type *last_rel_alloc = NULL;
   int rela = sec->name[4] == 'a';
@@ -1601,7 +1602,11 @@ output_rel_find (asection *sec, int isdy
       last = lookup;
       if (lookup->bfd_section != NULL
 	  && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
-	last_alloc = lookup;
+	{
+	  last_alloc = lookup;
+	  if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
+	    last_ro_alloc = lookup;
+	}
     }
 
   if (last_rel_alloc)
@@ -1610,6 +1615,9 @@ output_rel_find (asection *sec, int isdy
   if (last_rel)
     return last_rel;
 
+  if (last_ro_alloc)
+    return last_ro_alloc;
+
   if (last_alloc)
     return last_alloc;
 
Index: ld/testsuite/ld-elf/weak-dyn-1.rd
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/weak-dyn-1.rd,v
retrieving revision 1.1
diff -u -p -r1.1 weak-dyn-1.rd
--- ld/testsuite/ld-elf/weak-dyn-1.rd	23 Jul 2007 09:56:19 -0000	1.1
+++ ld/testsuite/ld-elf/weak-dyn-1.rd	29 Jul 2007 08:17:42 -0000
@@ -1,3 +1,3 @@
 #...
-0+800000 .* foo.*
+.* foo.*
 #pass


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-07-29 12:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-24 20:56 [PATCH] Issues with ld -shared --build-id Jakub Jelinek
2007-07-24 23:10 ` Alan Modra
2007-07-24 23:36   ` Roland McGrath
2007-07-29 16:27     ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).