public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Yet another unnecessary powerpc section
@ 2005-03-21 15:42 Alan Modra
  2005-03-22  8:16 ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-03-21 15:42 UTC (permalink / raw)
  To: binutils

This change removes another section that appears in powerpc-linux object
files whether needed or not.  It's a little controversial to remove
symbols provided in the linker script, but I couldn't find any use of
them in a search through a reasonably large source base.  The possible
need to reinstate them is why I separated this change out from the
previous ones..

bfd/
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Make htab->sbss
	SEC_LINKER_CREATED.  Attach to dynobj.
	(ppc_elf_size_dynamic_sections): Strip htab->sbss if zero size.
ld/
	* scripttempl/elf.sc (SBSS): Don't provide sbss start and end syms.
ld/testsuite/
	* ld-powerpc/tlsexe32.r: Update.
	* ld-powerpc/tlsso32.d: Update.
	* ld-powerpc/tlsso32.g: Update.
	* ld-powerpc/tlsso32.r: Update.

Applied mainline.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.143
diff -u -p -r1.143 elf32-ppc.c
--- bfd/elf32-ppc.c	21 Mar 2005 13:23:13 -0000	1.143
+++ bfd/elf32-ppc.c	21 Mar 2005 13:30:02 -0000
@@ -2381,11 +2381,14 @@ ppc_elf_add_symbol_hook (bfd *abfd,
       htab = ppc_elf_hash_table (info);
       if (htab->sbss == NULL)
 	{
-	  flagword flags = SEC_IS_COMMON;
+	  flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
 
-	  htab->sbss = bfd_make_section_anyway (abfd, ".sbss");
+	  if (!htab->elf.dynobj)
+	    htab->elf.dynobj = abfd;
+
+	  htab->sbss = bfd_make_section_anyway (htab->elf.dynobj, ".sbss");
 	  if (htab->sbss == NULL
-	      || ! bfd_set_section_flags (abfd, htab->sbss, flags))
+	      || ! bfd_set_section_flags (htab->elf.dynobj, htab->sbss, flags))
 	    return FALSE;
 	}
 
@@ -4053,7 +4058,8 @@ ppc_elf_size_dynamic_sections (bfd *outp
 	continue;
 
       if (s == htab->plt
-	  || s == htab->got)
+	  || s == htab->got
+	  || s == htab->sbss)
 	{
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
@@ -4099,6 +4105,9 @@ ppc_elf_size_dynamic_sections (bfd *outp
 	  continue;
 	}
 
+      if (s == htab->sbss)
+	continue;
+
       /* Allocate memory for the section contents.  */
       s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
       if (s->contents == NULL)
Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.51
diff -u -p -r1.51 elf.sc
--- ld/scripttempl/elf.sc	17 Mar 2005 22:51:09 -0000	1.51
+++ ld/scripttempl/elf.sc	21 Mar 2005 13:30:21 -0000
@@ -118,14 +118,10 @@ STACKNOTE="/DISCARD/ : { *(.note.GNU-sta
 if test -z "${NO_SMALL_DATA}"; then
   SBSS=".sbss         ${RELOCATING-0} :
   {
-    ${RELOCATING+PROVIDE (__sbss_start = .);}
-    ${RELOCATING+PROVIDE (___sbss_start = .);}
     ${CREATE_SHLIB+*(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)}
     *(.dynsbss)
     *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
     *(.scommon)
-    ${RELOCATING+PROVIDE (__sbss_end = .);}
-    ${RELOCATING+PROVIDE (___sbss_end = .);}
   }"
   SBSS2=".sbss2        ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
   SDATA="/* We want the small data sections together, so single-instruction offsets
Index: ld/testsuite/ld-powerpc/tlsexe32.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexe32.r,v
retrieving revision 1.7
diff -u -p -r1.7 tlsexe32.r
--- ld/testsuite/ld-powerpc/tlsexe32.r	16 Mar 2005 21:52:47 -0000	1.7
+++ ld/testsuite/ld-powerpc/tlsexe32.r	21 Mar 2005 13:30:21 -0000
@@ -5,7 +5,7 @@
 #readelf: -WSsrl
 #target: powerpc*-*-*
 
-There are 18 section headers.*
+There are 16 section headers.*
 
 Section Headers:
  +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
@@ -17,16 +17,14 @@ Section Headers:
  +\[ 5\] \.rela\.dyn +.*
  +\[ 6\] \.rela\.plt +.*
  +\[ 7\] \.text +PROGBITS +01800244 000244 000070 00 +AX +0 +0 +1
- +\[ 8\] \.sdata2 +PROGBITS +.*
- +\[ 9\] \.tdata +PROGBITS +018102b4 0002b4 00001c 00 WAT +0 +0 +4
- +\[10\] \.tbss +NOBITS +018102d0 0002d0 00001c 00 WAT +0 +0 +4
- +\[11\] \.dynamic +DYNAMIC +018102d0 0002d0 0000a0 08 +WA +4 +0 +4
- +\[12\] \.got +PROGBITS +01810370 000370 00001c 04 WAX +0 +0 +4
- +\[13\] \.sdata +PROGBITS +0181038c 00038c 000000 00 +WA +0 +0 +4
- +\[14\] \.plt +NOBITS +.*
- +\[15\] \.shstrtab +STRTAB +.*
- +\[16\] \.symtab +SYMTAB +.*
- +\[17\] \.strtab +STRTAB +.*
+ +\[ 8\] \.tdata +PROGBITS +018102b4 0002b4 00001c 00 WAT +0 +0 +4
+ +\[ 9\] \.tbss +NOBITS +018102d0 0002d0 00001c 00 WAT +0 +0 +4
+ +\[10\] \.dynamic +DYNAMIC +018102d0 0002d0 0000a0 08 +WA +4 +0 +4
+ +\[11\] \.got +PROGBITS +01810370 000370 00001c 04 WAX +0 +0 +4
+ +\[12\] \.plt +NOBITS +.*
+ +\[13\] \.shstrtab +STRTAB +.*
+ +\[14\] \.symtab +SYMTAB +.*
+ +\[15\] \.strtab +STRTAB +.*
 #...
 
 Elf file type is EXEC \(Executable file\)
@@ -63,59 +61,55 @@ Relocation section '\.rela\.plt' at offs
 
 Symbol table '\.dynsym' contains 9 entries:
  +Num: +Value +Size Type +Bind +Vis +Ndx Name
- +0: 00000000 +0 NOTYPE +LOCAL +DEFAULT +UND 
- +1: 018102d0 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
- +2: 00000000 +0 TLS +GLOBAL DEFAULT +UND gd
- +3: 018103d4 +0 FUNC +GLOBAL DEFAULT +UND __tls_get_addr
- +4: 00000000 +0 TLS +GLOBAL DEFAULT +UND ld
- +5: 018103e0 +0 NOTYPE +GLOBAL DEFAULT +ABS __end
- +6: 0181038c +0 NOTYPE +GLOBAL DEFAULT +ABS __bss_start
- +7: 0181038c +0 NOTYPE +GLOBAL DEFAULT +ABS _edata
- +8: 018103e0 +0 NOTYPE +GLOBAL DEFAULT +ABS _end
+.*: 00000000 +0 NOTYPE +LOCAL +DEFAULT +UND 
+.*: 018102d0 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+.*: 00000000 +0 TLS +GLOBAL DEFAULT +UND gd
+.*: 018103d4 +0 FUNC +GLOBAL DEFAULT +UND __tls_get_addr
+.*: 00000000 +0 TLS +GLOBAL DEFAULT +UND ld
+.*: 018103e0 +0 NOTYPE +GLOBAL DEFAULT +ABS __end
+.*: 0181038c +0 NOTYPE +GLOBAL DEFAULT +ABS __bss_start
+.*: 0181038c +0 NOTYPE +GLOBAL DEFAULT +ABS _edata
+.*: 018103e0 +0 NOTYPE +GLOBAL DEFAULT +ABS _end
 
-Symbol table '\.symtab' contains 44 entries:
+Symbol table '\.symtab' contains 40 entries:
  +Num: +Value +Size Type +Bind +Vis +Ndx Name
- +[0-9]+: 00000000 +0 NOTYPE +LOCAL +DEFAULT +UND 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +1 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +2 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +3 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +4 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +5 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +6 
- +[0-9]+: 01800244 +0 SECTION LOCAL +DEFAULT +7 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +8 
- +[0-9]+: 018102b4 +0 SECTION LOCAL +DEFAULT +9 
- +[0-9]+: 018102d0 +0 SECTION LOCAL +DEFAULT +10 
- +[0-9]+: 018102d0 +0 SECTION LOCAL +DEFAULT +11 
- +[0-9]+: 01810370 +0 SECTION LOCAL +DEFAULT +12 
- +[0-9]+: 0181038c +0 SECTION LOCAL +DEFAULT +13 
- +[0-9]+: 0181038c +0 SECTION LOCAL +DEFAULT +14 
- +[0-9]+: 00000000 +0 SECTION LOCAL +DEFAULT +15 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +16 
- +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +17 
- +[0-9]+: 00000000 +0 TLS +LOCAL +DEFAULT +9 gd4
- +[0-9]+: 00000004 +0 TLS +LOCAL +DEFAULT +9 ld4
- +[0-9]+: 00000008 +0 TLS +LOCAL +DEFAULT +9 ld5
- +[0-9]+: 0000000c +0 TLS +LOCAL +DEFAULT +9 ld6
- +[0-9]+: 00000010 +0 TLS +LOCAL +DEFAULT +9 ie4
- +[0-9]+: 00000014 +0 TLS +LOCAL +DEFAULT +9 le4
- +[0-9]+: 00000018 +0 TLS +LOCAL +DEFAULT +9 le5
- +[0-9]+: 018102d0 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
- +[0-9]+: 00000000 +0 TLS +GLOBAL DEFAULT +UND gd
- +[0-9]+: 00000030 +0 TLS +GLOBAL DEFAULT +10 le0
- +[0-9]+: [0-9a-f]+ +0 FUNC +GLOBAL DEFAULT +UND __tls_get_addr
- +[0-9]+: 00000020 +0 TLS +GLOBAL DEFAULT +10 ld0
- +[0-9]+: 00000034 +0 TLS +GLOBAL DEFAULT +10 le1
- +[0-9]+: 00000000 +0 TLS +GLOBAL DEFAULT +UND ld
- +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +7 _start
- +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __end
- +[0-9]+: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +13 _SDA_BASE_
- +[0-9]+: 00000028 +0 TLS +GLOBAL DEFAULT +10 ld2
- +[0-9]+: 00000024 +0 TLS +GLOBAL DEFAULT +10 ld1
- +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __bss_start
- +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _edata
- +[0-9]+: 01810374 +0 OBJECT +GLOBAL +HIDDEN +12 _GLOBAL_OFFSET_TABLE_
- +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _end
- +[0-9]+: 0000001c +0 TLS +GLOBAL DEFAULT +10 gd0
- +[0-9]+: 0000002c +0 TLS +GLOBAL DEFAULT +10 ie0
- +[0-9]+: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +8 _SDA2_BASE_
+.*: 00000000 +0 NOTYPE +LOCAL +DEFAULT +UND 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +1 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +2 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +3 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +4 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +5 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +6 
+.*: 01800244 +0 SECTION LOCAL +DEFAULT +7 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +8 
+.*: 018102d0 +0 SECTION LOCAL +DEFAULT +9 
+.*: 018102d0 +0 SECTION LOCAL +DEFAULT +10 
+.*: 01810370 +0 SECTION LOCAL +DEFAULT +11 
+.*: 0181038c +0 SECTION LOCAL +DEFAULT +12 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +13 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +14 
+.*: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +15 
+.*: 00000000 +0 TLS +LOCAL +DEFAULT +8 gd4
+.*: 00000004 +0 TLS +LOCAL +DEFAULT +8 ld4
+.*: 00000008 +0 TLS +LOCAL +DEFAULT +8 ld5
+.*: 0000000c +0 TLS +LOCAL +DEFAULT +8 ld6
+.*: 00000010 +0 TLS +LOCAL +DEFAULT +8 ie4
+.*: 00000014 +0 TLS +LOCAL +DEFAULT +8 le4
+.*: 00000018 +0 TLS +LOCAL +DEFAULT +8 le5
+.*: 018102d0 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+.*: 00000000 +0 TLS +GLOBAL DEFAULT +UND gd
+.*: 00000030 +0 TLS +GLOBAL DEFAULT +9 le0
+.*: [0-9a-f]+ +0 FUNC +GLOBAL DEFAULT +UND __tls_get_addr
+.*: 00000020 +0 TLS +GLOBAL DEFAULT +9 ld0
+.*: 00000034 +0 TLS +GLOBAL DEFAULT +9 le1
+.*: 00000000 +0 TLS +GLOBAL DEFAULT +UND ld
+.*: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +7 _start
+.*: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __end
+.*: 00000028 +0 TLS +GLOBAL DEFAULT +9 ld2
+.*: 00000024 +0 TLS +GLOBAL DEFAULT +9 ld1
+.*: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __bss_start
+.*: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _edata
+.*: 01810374 +0 OBJECT +GLOBAL +HIDDEN +11 _GLOBAL_OFFSET_TABLE_
+.*: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _end
+.*: 0000001c +0 TLS +GLOBAL DEFAULT +9 gd0
+.*: 0000002c +0 TLS +GLOBAL DEFAULT +9 ie0
Index: ld/testsuite/ld-powerpc/tlsso32.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso32.d,v
retrieving revision 1.8
diff -u -p -r1.8 tlsso32.d
--- ld/testsuite/ld-powerpc/tlsso32.d	16 Mar 2005 02:41:28 -0000	1.8
+++ ld/testsuite/ld-powerpc/tlsso32.d	21 Mar 2005 13:30:21 -0000
@@ -41,5 +41,5 @@ Disassembly of section \.got:
 
 .* <\.got>:
 .*:	4e 80 00 21 	blrl
-.*:	00 01 04 e4 	.*
+.*:	00 01 04 90 	.*
 	\.\.\.
Index: ld/testsuite/ld-powerpc/tlsso32.g
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso32.g,v
retrieving revision 1.4
diff -u -p -r1.4 tlsso32.g
--- ld/testsuite/ld-powerpc/tlsso32.g	16 Mar 2005 02:41:28 -0000	1.4
+++ ld/testsuite/ld-powerpc/tlsso32.g	21 Mar 2005 13:30:21 -0000
@@ -7,7 +7,7 @@
 .*: +file format elf32-powerpc
 
 Contents of section \.got:
-.* 4e800021 000104e4 00000000 00000000  .*
+.* 4e800021 00010490 00000000 00000000  .*
 .* 00000000 00000000 00000000 00000000  .*
 .* 00000000 00000000 00000000 00000000  .*
 .* 00000000                             .*
Index: ld/testsuite/ld-powerpc/tlsso32.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso32.r,v
retrieving revision 1.9
diff -u -p -r1.9 tlsso32.r
--- ld/testsuite/ld-powerpc/tlsso32.r	16 Mar 2005 21:52:47 -0000	1.9
+++ ld/testsuite/ld-powerpc/tlsso32.r	21 Mar 2005 13:30:21 -0000
@@ -4,7 +4,7 @@
 #readelf: -WSsrl
 #target: powerpc*-*-*
 
-There are 17 section headers.*
+There are 15 section headers.*
 
 Section Headers:
  +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
@@ -14,19 +14,15 @@ Section Headers:
  +\[ 3\] \.dynstr +.*
  +\[ 4\] \.rela\.dyn +.*
  +\[ 5\] \.rela\.plt +.*
- +\[ 6\] \.text +PROGBITS +0+458 0+458 0+70 0+ +AX +0 +0 +1
- +\[ 7\] \.tdata +PROGBITS +0+104c8 0+4c8 0+1c 0+ WAT +0 +0 +4
- +\[ 8\] \.tbss +NOBITS +0+104e4 0+4e4 0+1c 0+ WAT +0 +0 +4
- +\[ 9\] \.dynamic +DYNAMIC +0+104e4 0+4e4 0+a0 08 +WA +3 +0 +4
- +\[10\] \.data +PROGBITS +0+10584 0+584 0+ 0+ +WA +0 +0 +1
- +\[11\] \.got +PROGBITS +0+10584 0+584 0+34 04 WAX +0 +0 +4
- +\[12\] \.sdata +.*
- +\[13\] \.sbss +.*
- +\[14\] \.plt +.*
- +\[15\] \.bss +.*
- +\[16\] \.shstrtab +.*
- +\[17\] \.symtab +.*
- +\[18\] \.strtab +.*
+ +\[ 6\] \.text +PROGBITS +0+404 0+404 0+70 0+ +AX +0 +0 +1
+ +\[ 7\] \.tdata +PROGBITS +0+10474 0+474 0+1c 0+ WAT +0 +0 +4
+ +\[ 8\] \.tbss +NOBITS +0+10490 0+490 0+1c 0+ WAT +0 +0 +4
+ +\[ 9\] \.dynamic +DYNAMIC +0+10490 0+490 0+a0 08 +WA +3 +0 +4
+ +\[10\] \.got +PROGBITS +0+10530 0+530 0+34 04 WAX +0 +0 +4
+ +\[11\] \.plt +.*
+ +\[12\] \.shstrtab +.*
+ +\[13\] \.symtab +.*
+ +\[14\] \.strtab +.*
 #...
 
 Elf file type is DYN \(Shared object file\)
@@ -35,10 +31,10 @@ There are 4 program headers.*
 
 Program Headers:
  +Type +Offset +VirtAddr +PhysAddr +FileSiz MemSiz +Flg Align
- +LOAD +0x0+ 0x0+ 0x0+ 0x0+4c8 0x0+4c8 R E 0x10000
- +LOAD +0x0+4c8 0x0+104c8 0x0+104c8 0x0+f0 0x0+144 RWE 0x10000
- +DYNAMIC +0x0+4e4 0x0+104e4 0x0+104e4 0x0+a0 0x0+a0 RW +0x4
- +TLS +0x0+4c8 0x0+104c8 0x0+104c8 0x0+1c 0x0+38 R +0x4
+ +LOAD +0x0+ 0x0+ 0x0+ 0x0+474 0x0+474 R E 0x10000
+ +LOAD +0x0+474 0x0+10474 0x0+10474 0x0+f0 0x0+144 RWE 0x10000
+ +DYNAMIC +0x0+490 0x0+10490 0x0+10490 0x0+a0 0x0+a0 RW +0x4
+ +TLS +0x0+474 0x0+10474 0x0+10474 0x0+1c 0x0+38 R +0x4
 
  Section to Segment mapping:
  +Segment Sections\.\.\.
@@ -49,40 +45,39 @@ Program Headers:
 
 Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 18 entries:
  Offset +Info +Type +Sym\. Value +Symbol's Name \+ Addend
-0+45c +0+b0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
-0+464 +0+b0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
-0+49c +0+b0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
-0+4a4 +0+b0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
-0+48e +0+a45 R_PPC_TPREL16 +0+30 +le0 \+ 0
-0+492 +0+d48 R_PPC_TPREL16_HA +0+34 +le1 \+ 0
-0+496 +0+d46 R_PPC_TPREL16_LO +0+34 +le1 \+ 0
-0+4be +0+245 R_PPC_TPREL16 +0+104c8 +\.tdata \+ 104dc
-0+4c2 +0+248 R_PPC_TPREL16_HA +0+104c8 +\.tdata \+ 104e0
-0+4c6 +0+246 R_PPC_TPREL16_LO +0+104c8 +\.tdata \+ 104e0
-0+10594 +0+44 R_PPC_DTPMOD32 +0+
-0+1059c +0+44 R_PPC_DTPMOD32 +0+
-0+105a0 +0+4e R_PPC_DTPREL32 +0+
-0+105a4 +0+944 R_PPC_DTPMOD32 +0+ +gd \+ 0
-0+105a8 +0+94e R_PPC_DTPREL32 +0+ +gd \+ 0
-0+105ac +0+1744 R_PPC_DTPMOD32 +0+1c +gd0 \+ 0
-0+105b0 +0+174e R_PPC_DTPREL32 +0+1c +gd0 \+ 0
-0+105b4 +0+1849 R_PPC_TPREL32 +0+2c +ie0 \+ 0
+0+408 +0+a0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
+0+410 +0+a0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
+0+448 +0+a0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
+0+450 +0+a0a R_PPC_REL24 +0+ +__tls_get_addr \+ 0
+0+43a +0+945 R_PPC_TPREL16 +0+30 +le0 \+ 0
+0+43e +0+c48 R_PPC_TPREL16_HA +0+34 +le1 \+ 0
+0+442 +0+c46 R_PPC_TPREL16_LO +0+34 +le1 \+ 0
+0+46a +0+245 R_PPC_TPREL16 +0+10474 +\.tdata \+ 10488
+0+46e +0+248 R_PPC_TPREL16_HA +0+10474 +\.tdata \+ 1048c
+0+472 +0+246 R_PPC_TPREL16_LO +0+10474 +\.tdata \+ 1048c
+0+10540 +0+44 R_PPC_DTPMOD32 +0+
+0+10548 +0+44 R_PPC_DTPMOD32 +0+
+0+1054c +0+4e R_PPC_DTPREL32 +0+
+0+10550 +0+844 R_PPC_DTPMOD32 +0+ +gd \+ 0
+0+10554 +0+84e R_PPC_DTPREL32 +0+ +gd \+ 0
+0+10558 +0+1544 R_PPC_DTPMOD32 +0+1c +gd0 \+ 0
+0+1055c +0+154e R_PPC_DTPREL32 +0+1c +gd0 \+ 0
+0+10560 +0+1649 R_PPC_TPREL32 +0+2c +ie0 \+ 0
 
 Relocation section '\.rela\.plt' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset +Info +Type +Sym\. Value +Symbol's Name \+ Addend
-0+10600 +0+b15 R_PPC_JMP_SLOT +0+ +__tls_get_addr \+ 0
+0+105ac +0+a15 R_PPC_JMP_SLOT +0+ +__tls_get_addr \+ 0
 
-Symbol table '\.dynsym' contains 26 entries:
+Symbol table '\.dynsym' contains 23 entries:
  +Num: +Value +Size Type +Bind +Vis +Ndx Name
  +[0-9]+: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND 
- +[0-9]+: 0+458 +0 SECTION LOCAL +DEFAULT +6 
- +[0-9]+: 0+104c8 +0 SECTION LOCAL +DEFAULT +7 
- +[0-9]+: 0+104e4 +0 SECTION LOCAL +DEFAULT +8 
- +[0-9]+: 0+10584 +0 SECTION LOCAL +DEFAULT +10 
- +[0-9]+: 0+105b8 +0 SECTION LOCAL +DEFAULT +12 
- +[0-9]+: 0+105b8 +0 SECTION LOCAL +DEFAULT +13 
- +[0-9]+: 0+1060c +0 SECTION LOCAL +DEFAULT +15 
- +[0-9]+: 0+104e4 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+ +[0-9]+: 0+404 +0 SECTION LOCAL +DEFAULT +6 
+ +[0-9]+: 0+10474 +0 SECTION LOCAL +DEFAULT +7 
+ +[0-9]+: 0+10490 +0 SECTION LOCAL +DEFAULT +8 
+ +[0-9]+: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND 
+ +[0-9]+: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND 
+ +[0-9]+: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND 
+ +[0-9]+: 0+10490 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
  +[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND gd
  +[0-9]+: 0+30 +0 TLS +GLOBAL DEFAULT +8 le0
  +[0-9]+: 0+ +0 NOTYPE +GLOBAL DEFAULT +UND __tls_get_addr
@@ -91,7 +86,6 @@ Symbol table '\.dynsym' contains 26 entr
  +[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND ld
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +6 _start
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __end
- +[0-9]+: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +12 _SDA_BASE_
  +[0-9]+: 0+28 +0 TLS +GLOBAL DEFAULT +8 ld2
  +[0-9]+: 0+24 +0 TLS +GLOBAL DEFAULT +8 ld1
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __bss_start
@@ -99,9 +93,8 @@ Symbol table '\.dynsym' contains 26 entr
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _end
  +[0-9]+: 0+1c +0 TLS +GLOBAL DEFAULT +8 gd0
  +[0-9]+: 0+2c +0 TLS +GLOBAL DEFAULT +8 ie0
- +[0-9]+: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +12 _SDA2_BASE_
 
-Symbol table '\.symtab' contains 45 entries:
+Symbol table '\.symtab' contains 39 entries:
  +Num: +Value +Size Type +Bind +Vis +Ndx Name
  +[0-9]+: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND 
  +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +1 
@@ -109,19 +102,15 @@ Symbol table '\.symtab' contains 45 entr
  +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +3 
  +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +4 
  +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +5 
- +[0-9]+: 0+458 +0 SECTION LOCAL +DEFAULT +6 
- +[0-9]+: 0+104c8 +0 SECTION LOCAL +DEFAULT +7 
- +[0-9]+: 0+104e4 +0 SECTION LOCAL +DEFAULT +8 
+ +[0-9]+: 0+404 +0 SECTION LOCAL +DEFAULT +6 
+ +[0-9]+: 0+10474 +0 SECTION LOCAL +DEFAULT +7 
+ +[0-9]+: 0+10490 +0 SECTION LOCAL +DEFAULT +8 
  +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +9 
- +[0-9]+: 0+10584 +0 SECTION LOCAL +DEFAULT +10 
+ +[0-9]+: 0+10530 +0 SECTION LOCAL +DEFAULT +10 
  +[0-9]+: [0-9a-f]+ +0 SECTION LOCAL +DEFAULT +11 
- +[0-9]+: 0+105b8 +0 SECTION LOCAL +DEFAULT +12 
- +[0-9]+: 0+105b8 +0 SECTION LOCAL +DEFAULT +13 
- +[0-9]+: 0+105b8 +0 SECTION LOCAL +DEFAULT +14 
- +[0-9]+: 0+1060c +0 SECTION LOCAL +DEFAULT +15 
- +[0-9]+: 0+ +0 SECTION LOCAL +DEFAULT +16 
- +[0-9]+: 0+ +0 SECTION LOCAL +DEFAULT +17 
- +[0-9]+: 0+ +0 SECTION LOCAL +DEFAULT +18 
+ +[0-9]+: 0+ +0 SECTION LOCAL +DEFAULT +12 
+ +[0-9]+: 0+ +0 SECTION LOCAL +DEFAULT +13 
+ +[0-9]+: 0+ +0 SECTION LOCAL +DEFAULT +14 
  +[0-9]+: 0+ +0 TLS +LOCAL +DEFAULT +7 gd4
  +[0-9]+: 0+4 +0 TLS +LOCAL +DEFAULT +7 ld4
  +[0-9]+: 0+8 +0 TLS +LOCAL +DEFAULT +7 ld5
@@ -129,8 +118,8 @@ Symbol table '\.symtab' contains 45 entr
  +[0-9]+: 0+10 +0 TLS +LOCAL +DEFAULT +7 ie4
  +[0-9]+: 0+14 +0 TLS +LOCAL +DEFAULT +7 le4
  +[0-9]+: 0+18 +0 TLS +LOCAL +DEFAULT +7 le5
- +[0-9]+: 0+10588 +0 OBJECT +LOCAL +HIDDEN +ABS _GLOBAL_OFFSET_TABLE_
- +[0-9]+: 0+104e4 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+ +[0-9]+: 0+10534 +0 OBJECT +LOCAL +HIDDEN +ABS _GLOBAL_OFFSET_TABLE_
+ +[0-9]+: 0+10490 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
  +[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND gd
  +[0-9]+: 0+30 +0 TLS +GLOBAL DEFAULT +8 le0
  +[0-9]+: 0+ +0 NOTYPE +GLOBAL DEFAULT +UND __tls_get_addr
@@ -139,7 +128,6 @@ Symbol table '\.symtab' contains 45 entr
  +[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND ld
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +6 _start
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __end
- +[0-9]+: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +12 _SDA_BASE_
  +[0-9]+: 0+28 +0 TLS +GLOBAL DEFAULT +8 ld2
  +[0-9]+: 0+24 +0 TLS +GLOBAL DEFAULT +8 ld1
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS __bss_start
@@ -147,4 +135,3 @@ Symbol table '\.symtab' contains 45 entr
  +[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _end
  +[0-9]+: 0+1c +0 TLS +GLOBAL DEFAULT +8 gd0
  +[0-9]+: 0+2c +0 TLS +GLOBAL DEFAULT +8 ie0
- +[0-9]+: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +11 _SDA2_BASE_

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: Yet another unnecessary powerpc section
  2005-03-21 15:42 Yet another unnecessary powerpc section Alan Modra
@ 2005-03-22  8:16 ` Alan Modra
  2005-03-22 11:48   ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-03-22  8:16 UTC (permalink / raw)
  To: binutils

On Tue, Mar 22, 2005 at 12:30:03AM +1030, Alan Modra wrote:
> 	* scripttempl/elf.sc (SBSS): Don't provide sbss start and end syms.

Sigh.  It appears my search through source wasn't comprehensive enough.
libgloss uses __sbss_start and __sbss_end.

	 * elf32-ppc.c (set_linker_sym): New function, extracted from..
	 (ppc_elf_set_sdata_syms): ..here.  Expand comment.  Set .sbss
	 start and end syms.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.144
diff -u -p -r1.144 elf32-ppc.c
--- bfd/elf32-ppc.c	21 Mar 2005 13:56:47 -0000	1.144
+++ bfd/elf32-ppc.c	22 Mar 2005 03:06:16 -0000
@@ -4570,22 +4570,46 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set _SDA_BASE_ and _SDA2_BASE.  */
+/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
+
+static void
+set_linker_sym (struct ppc_elf_link_hash_table *htab,
+		const char *sym_name,
+		bfd_vma val)
+{
+  struct elf_link_hash_entry *h;
+  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
+  if (h != NULL && h->root.type == bfd_link_hash_undefined)
+    {
+      h->root.type = bfd_link_hash_defined;
+      h->root.u.def.section = bfd_abs_section_ptr;
+      h->root.u.def.value = val;
+      h->def_regular = 1;
+      h->type = STT_OBJECT;
+      h->other = STV_HIDDEN;
+    }
+}
+
+/* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
+   set here rather than via PROVIDE in the default linker script,
+   because using PROVIDE inside an output section statement results in
+   unnecessary output sections.  Using PROVIDE outside an output section
+   statement runs the risk of section alignment affecting where the
+   section starts.  */
 
 bfd_boolean
 ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
 {
   struct ppc_elf_link_hash_table *htab;
   unsigned i;
+  asection *s;
+  bfd_vma val;
 
   htab = ppc_elf_hash_table (info);
 
   for (i = 0; i < 2; i++)
     {
       elf_linker_section_t *lsect = &htab->sdata[i];
-      asection *s;
-      bfd_vma val;
-      struct elf_link_hash_entry *h;
 
       s = lsect->section;
       if (s != NULL)
@@ -4600,18 +4624,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
 	val = s->vma + 32768;
       lsect->sym_val = val;
 
-      h = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
-				FALSE, FALSE, FALSE);
-      if (h != NULL && h->root.type == bfd_link_hash_undefined)
-	{
-	  h->root.type = bfd_link_hash_defined;
-	  h->root.u.def.section = bfd_abs_section_ptr;
-	  h->root.u.def.value = val;
-	  h->def_regular = 1;
-	  h->type = STT_OBJECT;
-	  h->other = STV_HIDDEN;
-	}
+      set_linker_sym (htab, lsect->sym_name, val);
     }
+
+  s = bfd_get_section_by_name (obfd, ".sbss");
+  val = 0;
+  if (s != NULL)
+    val = s->vma;
+  set_linker_sym (htab, "__sbss_start", val);
+  set_linker_sym (htab, "___sbss_start", val);
+  if (s != NULL)
+    val += s->size;
+  set_linker_sym (htab, "__sbss_end", val);
+  set_linker_sym (htab, "___sbss_end", val);
   return TRUE;
 }
 \f

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: Yet another unnecessary powerpc section
  2005-03-22  8:16 ` Alan Modra
@ 2005-03-22 11:48   ` H. J. Lu
  2005-03-22 12:06     ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-03-22 11:48 UTC (permalink / raw)
  To: binutils

On Tue, Mar 22, 2005 at 01:46:17PM +1030, Alan Modra wrote:
> On Tue, Mar 22, 2005 at 12:30:03AM +1030, Alan Modra wrote:
> > 	* scripttempl/elf.sc (SBSS): Don't provide sbss start and end syms.
> 
> Sigh.  It appears my search through source wasn't comprehensive enough.
> libgloss uses __sbss_start and __sbss_end.
> 
> 	 * elf32-ppc.c (set_linker_sym): New function, extracted from..
> 	 (ppc_elf_set_sdata_syms): ..here.  Expand comment.  Set .sbss
> 	 start and end syms.
> 
> +/* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
> +   set here rather than via PROVIDE in the default linker script,
> +   because using PROVIDE inside an output section statement results in
> +   unnecessary output sections.  Using PROVIDE outside an output section
> +   statement runs the risk of section alignment affecting where the
> +   section starts.  */
>  

We had the same problem with __XXX_array_start/__XXX_array_end. I am
running into the same problem for a different issue. Can we can make
this a generic ELF function:

void bfd_elf_provide_symbol (struct bfd_link_info *,
			     const char *sym_name,
			     asection *sec,
			     bfd_vma val);

It will define a hidden data symbol NAME defined in SEC with value VAL
if it is undefined.


H.J.

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

* Re: Yet another unnecessary powerpc section
  2005-03-22 11:48   ` H. J. Lu
@ 2005-03-22 12:06     ` Alan Modra
  2005-03-22 17:37       ` PATCH: Add _bfd_elf_provide_symbol H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-03-22 12:06 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Mon, Mar 21, 2005 at 08:18:55PM -0800, H. J. Lu wrote:
> On Tue, Mar 22, 2005 at 01:46:17PM +1030, Alan Modra wrote:
> > On Tue, Mar 22, 2005 at 12:30:03AM +1030, Alan Modra wrote:
> > > 	* scripttempl/elf.sc (SBSS): Don't provide sbss start and end syms.
> > 
> > Sigh.  It appears my search through source wasn't comprehensive enough.
> > libgloss uses __sbss_start and __sbss_end.
> > 
> > 	 * elf32-ppc.c (set_linker_sym): New function, extracted from..
> > 	 (ppc_elf_set_sdata_syms): ..here.  Expand comment.  Set .sbss
> > 	 start and end syms.
> > 
> > +/* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
> > +   set here rather than via PROVIDE in the default linker script,
> > +   because using PROVIDE inside an output section statement results in
> > +   unnecessary output sections.  Using PROVIDE outside an output section
> > +   statement runs the risk of section alignment affecting where the
> > +   section starts.  */
> >  
> 
> We had the same problem with __XXX_array_start/__XXX_array_end. I am
> running into the same problem for a different issue. Can we can make
> this a generic ELF function:
> 
> void bfd_elf_provide_symbol (struct bfd_link_info *,
> 			     const char *sym_name,
> 			     asection *sec,
> 			     bfd_vma val);
> 
> It will define a hidden data symbol NAME defined in SEC with value VAL
> if it is undefined.

If you need it, go ahead and steal it.  :)  The function probably ought
to start with '_' to indicate that it's not part of the public bfd
interface.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* PATCH: Add _bfd_elf_provide_symbol
  2005-03-22 12:06     ` Alan Modra
@ 2005-03-22 17:37       ` H. J. Lu
  2005-03-23  4:19         ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-03-22 17:37 UTC (permalink / raw)
  To: binutils

On Tue, Mar 22, 2005 at 03:33:14PM +1030, Alan Modra wrote:
> > 
> > We had the same problem with __XXX_array_start/__XXX_array_end. I am
> > running into the same problem for a different issue. Can we can make
> > this a generic ELF function:
> > 
> > void bfd_elf_provide_symbol (struct bfd_link_info *,
> > 			     const char *sym_name,
> > 			     asection *sec,
> > 			     bfd_vma val);
> > 
> > It will define a hidden data symbol NAME defined in SEC with value VAL
> > if it is undefined.
> 
> If you need it, go ahead and steal it.  :)  The function probably ought
> to start with '_' to indicate that it's not part of the public bfd
> interface.
> 

Here is the patch. I call it from gld${EMULATION_NAME}_finish and
it works for me. Is this the best place to do it?


H.J.
----
bfd/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* bfd-in.h (_bfd_elf_provide_symbol): New.
	* bfd-in2.h: Regenerated.

	* elf32-ppc.c (set_linker_sym): Moved to elflink.c.
	(ppc_elf_set_sdata_syms): Call _bfd_elf_provide_symbol instead
	of set_linker_sym.

	* elflink.c (_bfd_elf_provide_symbol): New. Moved and renamed
	from elf32-ppc.c.

ld/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_finish): Provide
	__preinit_array_start, __preinit_array_end, __init_array_start,
	__init_array_end, __fini_array_start and __fini_array_end.

	* scripttempl/elf.sc: Don't provide __preinit_array_start,
	__preinit_array_end, __init_array_start, __init_array_end,
	__fini_array_start nor __fini_array_end.

--- binutils/bfd/bfd-in.h.provide	2005-02-21 11:10:29.000000000 -0800
+++ binutils/bfd/bfd-in.h	2005-03-22 08:05:03.000000000 -0800
@@ -694,6 +694,9 @@ extern int bfd_get_sign_extend_vma
 extern struct bfd_section *_bfd_elf_tls_setup
   (bfd *, struct bfd_link_info *);
 
+extern void _bfd_elf_provide_symbol
+  (struct bfd_link_info *, const char *, bfd_vma);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
--- binutils/bfd/elf32-ppc.c.provide	2005-03-22 07:14:43.000000000 -0800
+++ binutils/bfd/elf32-ppc.c	2005-03-22 07:35:13.000000000 -0800
@@ -4545,26 +4545,6 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
-
-static void
-set_linker_sym (struct ppc_elf_link_hash_table *htab,
-		const char *sym_name,
-		bfd_vma val)
-{
-  struct elf_link_hash_entry *h;
-  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
-  if (h != NULL && h->root.type == bfd_link_hash_undefined)
-    {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN;
-    }
-}
-
 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
    set here rather than via PROVIDE in the default linker script,
    because using PROVIDE inside an output section statement results in
@@ -4599,19 +4579,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
 	val = s->vma + 32768;
       lsect->sym_val = val;
 
-      set_linker_sym (htab, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
   val = 0;
   if (s != NULL)
     val = s->vma;
-  set_linker_sym (htab, "__sbss_start", val);
-  set_linker_sym (htab, "___sbss_start", val);
+  _bfd_elf_provide_symbol (info, "__sbss_start", val);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val);
   if (s != NULL)
     val += s->size;
-  set_linker_sym (htab, "__sbss_end", val);
-  set_linker_sym (htab, "___sbss_end", val);
+  _bfd_elf_provide_symbol (info, "__sbss_end", val);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val);
   return TRUE;
 }
 \f
--- binutils/bfd/elflink.c.provide	2005-03-22 07:14:45.000000000 -0800
+++ binutils/bfd/elflink.c	2005-03-22 07:34:13.000000000 -0800
@@ -9754,3 +9754,23 @@ _bfd_elf_section_already_linked (bfd *ab
   /* This is the first section with this name.  Record it.  */
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
+
+/* Set NAME to VAL if the symbol exists and is undefined.  */
+
+void
+_bfd_elf_provide_symbol (struct bfd_link_info *info, const char *name,
+			 bfd_vma val)
+{
+  struct elf_link_hash_entry *h;
+  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE,
+			    FALSE);
+  if (h != NULL && h->root.type == bfd_link_hash_undefined)
+    {
+      h->root.type = bfd_link_hash_defined;
+      h->root.u.def.section = bfd_abs_section_ptr;
+      h->root.u.def.value = val;
+      h->def_regular = 1;
+      h->type = STT_OBJECT;
+      h->other = STV_HIDDEN;
+    }
+}
--- binutils/ld/emultempl/elf32.em.provide	2005-03-22 07:15:14.000000000 -0800
+++ binutils/ld/emultempl/elf32.em	2005-03-22 09:03:36.783703101 -0800
@@ -1430,6 +1430,9 @@ cat >>e${EMULATION_NAME}.c <<EOF
 static void
 gld${EMULATION_NAME}_finish (void)
 {
+  asection *s;
+  bfd_vma start, end;
+
   if (bfd_elf_discard_info (output_bfd, &link_info))
     {
       lang_reset_memory_regions ();
@@ -1454,8 +1457,6 @@ gld${EMULATION_NAME}_finish (void)
 	   os != NULL;
 	   os = os->next)
 	{
-	  asection *s;
-
 	  if (os == abs_output_section || os->constraint == -1)
 	    continue;
 	  s = os->bfd_section;
@@ -1473,6 +1474,63 @@ gld${EMULATION_NAME}_finish (void)
 	    }
 	}
     }
+
+  /* Provide
+
+     __preinit_array_start
+     __preinit_array_end
+     __init_array_start
+     __init_array_end
+     __fini_array_start
+     __fini_array_end
+
+     They are set here rather than via PROVIDE in the linker script,
+     because using PROVIDE inside an output section statement results
+     in unnecessary output sections.  Using PROVIDE outside an output
+     section statement runs the risk of section alignment affecting
+     where the section starts.  */
+
+  s = bfd_get_section_by_name (output_bfd, ".preinit_array");
+  if (s != NULL)
+    {
+      start = s->vma;
+      end = start + s->size;
+    }
+  else
+    {
+      start = 0;
+      end = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, "__preinit_array_start", start);
+  _bfd_elf_provide_symbol (&link_info, "__preinit_array_end", end);
+
+  s = bfd_get_section_by_name (output_bfd, ".init_array");
+  if (s != NULL)
+    {
+      start = s->vma;
+      end = start + s->size;
+    }
+  else
+    {
+      start = 0;
+      end = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, "__init_array_start", start);
+  _bfd_elf_provide_symbol (&link_info, "__init_array_end", end);
+
+  s = bfd_get_section_by_name (output_bfd, ".fini_array");
+  if (s != NULL)
+    {
+      start = s->vma;
+      end = start + s->size;
+    }
+  else
+    {
+      start = 0;
+      end = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, "__fini_array_start", start);
+  _bfd_elf_provide_symbol (&link_info, "__fini_array_end", end);
 }
 EOF
 fi
--- binutils/ld/scripttempl/elf.sc.provide	2005-03-21 13:13:41.000000000 -0800
+++ binutils/ld/scripttempl/elf.sc	2005-03-22 07:36:29.000000000 -0800
@@ -333,22 +333,9 @@ cat <<EOF
   .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
   .tbss		${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
   .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
   .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
 
   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-03-22 17:37       ` PATCH: Add _bfd_elf_provide_symbol H. J. Lu
@ 2005-03-23  4:19         ` H. J. Lu
  2005-03-23  5:37           ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-03-23  4:19 UTC (permalink / raw)
  To: binutils

On Tue, Mar 22, 2005 at 09:07:58AM -0800, H. J. Lu wrote:
> On Tue, Mar 22, 2005 at 03:33:14PM +1030, Alan Modra wrote:
> > > 
> > > We had the same problem with __XXX_array_start/__XXX_array_end. I am
> > > running into the same problem for a different issue. Can we can make
> > > this a generic ELF function:
> > > 
> > > void bfd_elf_provide_symbol (struct bfd_link_info *,
> > > 			     const char *sym_name,
> > > 			     asection *sec,
> > > 			     bfd_vma val);
> > > 
> > > It will define a hidden data symbol NAME defined in SEC with value VAL
> > > if it is undefined.
> > 
> > If you need it, go ahead and steal it.  :)  The function probably ought
> > to start with '_' to indicate that it's not part of the public bfd
> > interface.
> > 
> 
> Here is the patch. I call it from gld${EMULATION_NAME}_finish and
> it works for me. Is this the best place to do it?
> 
> 

Here is an updated patch. We don't need those symbols for ld -r.


H.J.
----
bfd/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* bfd-in.h (_bfd_elf_provide_symbol): New.
	* bfd-in2.h: Regenerated.

	* elf32-ppc.c (set_linker_sym): Moved to elflink.c.
	(ppc_elf_set_sdata_syms): Call _bfd_elf_provide_symbol instead
	of set_linker_sym.

	* elflink.c (_bfd_elf_provide_symbol): New. Moved and renamed
	from elf32-ppc.c.

ld/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_array_symbols): New
	(gld${EMULATION_NAME}_finish): Call
	gld${EMULATION_NAME}_provide_array_symbols to provide
	__preinit_array_start, __preinit_array_end, __init_array_start,
	__init_array_end, __fini_array_start and __fini_array_end.

	* scripttempl/elf.sc: Don't provide __preinit_array_start,
	__preinit_array_end, __init_array_start, __init_array_end,
	__fini_array_start nor __fini_array_end.

--- binutils/bfd/bfd-in.h.provide	2005-02-21 11:10:29.000000000 -0800
+++ binutils/bfd/bfd-in.h	2005-03-22 08:05:03.000000000 -0800
@@ -694,6 +694,9 @@ extern int bfd_get_sign_extend_vma
 extern struct bfd_section *_bfd_elf_tls_setup
   (bfd *, struct bfd_link_info *);
 
+extern void _bfd_elf_provide_symbol
+  (struct bfd_link_info *, const char *, bfd_vma);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
--- binutils/bfd/elf32-ppc.c.provide	2005-03-22 07:14:43.000000000 -0800
+++ binutils/bfd/elf32-ppc.c	2005-03-22 07:35:13.000000000 -0800
@@ -4545,26 +4545,6 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
-
-static void
-set_linker_sym (struct ppc_elf_link_hash_table *htab,
-		const char *sym_name,
-		bfd_vma val)
-{
-  struct elf_link_hash_entry *h;
-  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
-  if (h != NULL && h->root.type == bfd_link_hash_undefined)
-    {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN;
-    }
-}
-
 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
    set here rather than via PROVIDE in the default linker script,
    because using PROVIDE inside an output section statement results in
@@ -4599,19 +4579,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
 	val = s->vma + 32768;
       lsect->sym_val = val;
 
-      set_linker_sym (htab, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
   val = 0;
   if (s != NULL)
     val = s->vma;
-  set_linker_sym (htab, "__sbss_start", val);
-  set_linker_sym (htab, "___sbss_start", val);
+  _bfd_elf_provide_symbol (info, "__sbss_start", val);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val);
   if (s != NULL)
     val += s->size;
-  set_linker_sym (htab, "__sbss_end", val);
-  set_linker_sym (htab, "___sbss_end", val);
+  _bfd_elf_provide_symbol (info, "__sbss_end", val);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val);
   return TRUE;
 }
 \f
--- binutils/bfd/elflink.c.provide	2005-03-22 07:14:45.000000000 -0800
+++ binutils/bfd/elflink.c	2005-03-22 07:34:13.000000000 -0800
@@ -9754,3 +9754,23 @@ _bfd_elf_section_already_linked (bfd *ab
   /* This is the first section with this name.  Record it.  */
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
+
+/* Set NAME to VAL if the symbol exists and is undefined.  */
+
+void
+_bfd_elf_provide_symbol (struct bfd_link_info *info, const char *name,
+			 bfd_vma val)
+{
+  struct elf_link_hash_entry *h;
+  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE,
+			    FALSE);
+  if (h != NULL && h->root.type == bfd_link_hash_undefined)
+    {
+      h->root.type = bfd_link_hash_defined;
+      h->root.u.def.section = bfd_abs_section_ptr;
+      h->root.u.def.value = val;
+      h->def_regular = 1;
+      h->type = STT_OBJECT;
+      h->other = STV_HIDDEN;
+    }
+}
--- binutils/ld/emultempl/elf32.em.provide	2005-03-22 07:15:14.000000000 -0800
+++ binutils/ld/emultempl/elf32.em	2005-03-22 12:41:42.558505370 -0800
@@ -1428,6 +1428,29 @@ if test x"$LDEMUL_FINISH" != xgld"$EMULA
 cat >>e${EMULATION_NAME}.c <<EOF
 
 static void
+gld${EMULATION_NAME}_provide_array_symbols (const char *sec,
+					    const char *start,
+					    const char *end)
+{
+  asection *s;
+  bfd_vma start_val, end_val;
+
+  s = bfd_get_section_by_name (output_bfd, sec);
+  if (s != NULL)
+    {
+      start_val = s->vma;
+      end_val = start_val + s->size;
+    }
+  else
+    {
+      start_val = 0;
+      end_val = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, start, start_val);
+  _bfd_elf_provide_symbol (&link_info, end, end_val);
+}
+
+static void
 gld${EMULATION_NAME}_finish (void)
 {
   if (bfd_elf_discard_info (output_bfd, &link_info))
@@ -1472,6 +1495,31 @@ gld${EMULATION_NAME}_finish (void)
 		  }
 	    }
 	}
+
+      /* Provide
+
+	 __preinit_array_start
+	 __preinit_array_end
+	 __init_array_start
+	 __init_array_end
+	 __fini_array_start
+	 __fini_array_end
+
+	 They are set here rather than via PROVIDE in the linker
+	 script, because using PROVIDE inside an output section
+	 statement results in unnecessary output sections.  Using
+	 PROVIDE outside an output section statement runs the risk of
+	 section alignment affecting where the section starts.  */
+
+      gld${EMULATION_NAME}_provide_array_symbols
+	(".preinit_array", "__preinit_array_start",
+	 "__preinit_array_end");
+      gld${EMULATION_NAME}_provide_array_symbols
+	(".init_array", "__init_array_start",
+	 "__init_array_end");
+      gld${EMULATION_NAME}_provide_array_symbols
+	(".fini_array", "__fini_array_start",
+	 "__fini_array_end");
     }
 }
 EOF
--- binutils/ld/scripttempl/elf.sc.provide	2005-03-21 13:13:41.000000000 -0800
+++ binutils/ld/scripttempl/elf.sc	2005-03-22 07:36:29.000000000 -0800
@@ -333,22 +333,9 @@ cat <<EOF
   .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
   .tbss		${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
   .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
   .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
 
   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-03-23  4:19         ` H. J. Lu
@ 2005-03-23  5:37           ` H. J. Lu
  2005-03-23  9:28             ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-03-23  5:37 UTC (permalink / raw)
  To: binutils

On Tue, Mar 22, 2005 at 12:49:03PM -0800, H. J. Lu wrote:
> On Tue, Mar 22, 2005 at 09:07:58AM -0800, H. J. Lu wrote:
> > On Tue, Mar 22, 2005 at 03:33:14PM +1030, Alan Modra wrote:
> > > > 
> > > > We had the same problem with __XXX_array_start/__XXX_array_end. I am
> > > > running into the same problem for a different issue. Can we can make
> > > > this a generic ELF function:
> > > > 
> > > > void bfd_elf_provide_symbol (struct bfd_link_info *,
> > > > 			     const char *sym_name,
> > > > 			     asection *sec,
> > > > 			     bfd_vma val);
> > > > 
> > > > It will define a hidden data symbol NAME defined in SEC with value VAL
> > > > if it is undefined.
> > > 
> > > If you need it, go ahead and steal it.  :)  The function probably ought
> > > to start with '_' to indicate that it's not part of the public bfd
> > > interface.
> > > 
> > 
> > Here is the patch. I call it from gld${EMULATION_NAME}_finish and
> > it works for me. Is this the best place to do it?
> > 
> > 
> 
> Here is an updated patch. We don't need those symbols for ld -r.
> 
> 

Here is an upated patch. _bfd_elf_provide_symbol should presever
st_other. Also it needs to set forced_local to 1. Otherwise, we will
get global hidden symbols. We don't need those array symbols for
shared libraries.


H.J.
----
bfd/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* bfd-in.h (_bfd_elf_provide_symbol): New.
	* bfd-in2.h: Regenerated.

	* elf32-ppc.c (set_linker_sym): Moved to elflink.c.
	(ppc_elf_set_sdata_syms): Call _bfd_elf_provide_symbol instead
	of set_linker_sym.

	* elflink.c (_bfd_elf_provide_symbol): New. Moved and renamed
	from elf32-ppc.c.

ld/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_array_symbols): New
	(gld${EMULATION_NAME}_finish): Call
	gld${EMULATION_NAME}_provide_array_symbols to provide
	__preinit_array_start, __preinit_array_end, __init_array_start,
	__init_array_end, __fini_array_start and __fini_array_end.

	* scripttempl/elf.sc: Don't provide __preinit_array_start,
	__preinit_array_end, __init_array_start, __init_array_end,
	__fini_array_start nor __fini_array_end.

--- binutils/bfd/bfd-in.h.provide	2005-02-21 11:10:29.000000000 -0800
+++ binutils/bfd/bfd-in.h	2005-03-22 12:52:00.000000000 -0800
@@ -694,6 +694,9 @@ extern int bfd_get_sign_extend_vma
 extern struct bfd_section *_bfd_elf_tls_setup
   (bfd *, struct bfd_link_info *);
 
+extern void _bfd_elf_provide_symbol
+  (struct bfd_link_info *, const char *, bfd_vma);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
--- binutils/bfd/elf32-ppc.c.provide	2005-03-22 07:14:43.000000000 -0800
+++ binutils/bfd/elf32-ppc.c	2005-03-22 12:52:00.000000000 -0800
@@ -4545,26 +4545,6 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
-
-static void
-set_linker_sym (struct ppc_elf_link_hash_table *htab,
-		const char *sym_name,
-		bfd_vma val)
-{
-  struct elf_link_hash_entry *h;
-  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
-  if (h != NULL && h->root.type == bfd_link_hash_undefined)
-    {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN;
-    }
-}
-
 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
    set here rather than via PROVIDE in the default linker script,
    because using PROVIDE inside an output section statement results in
@@ -4599,19 +4579,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
 	val = s->vma + 32768;
       lsect->sym_val = val;
 
-      set_linker_sym (htab, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
   val = 0;
   if (s != NULL)
     val = s->vma;
-  set_linker_sym (htab, "__sbss_start", val);
-  set_linker_sym (htab, "___sbss_start", val);
+  _bfd_elf_provide_symbol (info, "__sbss_start", val);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val);
   if (s != NULL)
     val += s->size;
-  set_linker_sym (htab, "__sbss_end", val);
-  set_linker_sym (htab, "___sbss_end", val);
+  _bfd_elf_provide_symbol (info, "__sbss_end", val);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val);
   return TRUE;
 }
 \f
--- binutils/bfd/elflink.c.provide	2005-03-22 07:14:45.000000000 -0800
+++ binutils/bfd/elflink.c	2005-03-22 14:31:19.054207031 -0800
@@ -9754,3 +9754,24 @@ _bfd_elf_section_already_linked (bfd *ab
   /* This is the first section with this name.  Record it.  */
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
+
+/* Set NAME to VAL if the symbol exists and is undefined.  */
+
+void
+_bfd_elf_provide_symbol (struct bfd_link_info *info, const char *name,
+			 bfd_vma val)
+{
+  struct elf_link_hash_entry *h;
+  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE,
+			    FALSE);
+  if (h != NULL && h->root.type == bfd_link_hash_undefined)
+    {
+      h->root.type = bfd_link_hash_defined;
+      h->root.u.def.section = bfd_abs_section_ptr;
+      h->root.u.def.value = val;
+      h->def_regular = 1;
+      h->type = STT_OBJECT;
+      h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
+      h->forced_local = 1;
+    }
+}
--- binutils/ld/emultempl/elf32.em.provide	2005-03-22 07:15:14.000000000 -0800
+++ binutils/ld/emultempl/elf32.em	2005-03-22 14:43:13.316089374 -0800
@@ -1428,6 +1428,29 @@ if test x"$LDEMUL_FINISH" != xgld"$EMULA
 cat >>e${EMULATION_NAME}.c <<EOF
 
 static void
+gld${EMULATION_NAME}_provide_array_symbols (const char *sec,
+					    const char *start,
+					    const char *end)
+{
+  asection *s;
+  bfd_vma start_val, end_val;
+
+  s = bfd_get_section_by_name (output_bfd, sec);
+  if (s != NULL)
+    {
+      start_val = s->vma;
+      end_val = start_val + s->size;
+    }
+  else
+    {
+      start_val = 0;
+      end_val = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, start, start_val);
+  _bfd_elf_provide_symbol (&link_info, end, end_val);
+}
+
+static void
 gld${EMULATION_NAME}_finish (void)
 {
   if (bfd_elf_discard_info (output_bfd, &link_info))
@@ -1472,6 +1495,34 @@ gld${EMULATION_NAME}_finish (void)
 		  }
 	    }
 	}
+
+      /* If not building shared library, provide
+
+	 __preinit_array_start
+	 __preinit_array_end
+	 __init_array_start
+	 __init_array_end
+	 __fini_array_start
+	 __fini_array_end
+
+	 They are set here rather than via PROVIDE in the linker
+	 script, because using PROVIDE inside an output section
+	 statement results in unnecessary output sections.  Using
+	 PROVIDE outside an output section statement runs the risk of
+	 section alignment affecting where the section starts.  */
+
+      if (!link_info.shared)
+	{
+	  gld${EMULATION_NAME}_provide_array_symbols
+	    (".preinit_array", "__preinit_array_start",
+	     "__preinit_array_end");
+	  gld${EMULATION_NAME}_provide_array_symbols
+	    (".init_array", "__init_array_start",
+	     "__init_array_end");
+	  gld${EMULATION_NAME}_provide_array_symbols
+	    (".fini_array", "__fini_array_start",
+	     "__fini_array_end");
+	}
     }
 }
 EOF
--- binutils/ld/scripttempl/elf.sc.provide	2005-03-21 13:13:41.000000000 -0800
+++ binutils/ld/scripttempl/elf.sc	2005-03-22 12:52:00.000000000 -0800
@@ -333,22 +333,9 @@ cat <<EOF
   .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
   .tbss		${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
   .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
   .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
 
   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-03-23  5:37           ` H. J. Lu
@ 2005-03-23  9:28             ` Alan Modra
  2005-03-23  9:31               ` Daniel Jacobowitz
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-03-23  9:28 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Tue, Mar 22, 2005 at 02:44:22PM -0800, H. J. Lu wrote:
> Here is an upated patch. _bfd_elf_provide_symbol should presever
> st_other. Also it needs to set forced_local to 1. Otherwise, we will
> get global hidden symbols. We don't need those array symbols for
> shared libraries.

Looks good.  OK for mainline, and the branch too unless Daniel
disagrees.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-03-23  9:28             ` Alan Modra
@ 2005-03-23  9:31               ` Daniel Jacobowitz
  2005-03-23  9:33                 ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Daniel Jacobowitz @ 2005-03-23  9:31 UTC (permalink / raw)
  To: H. J. Lu, binutils

On Wed, Mar 23, 2005 at 12:34:57PM +1030, Alan Modra wrote:
> On Tue, Mar 22, 2005 at 02:44:22PM -0800, H. J. Lu wrote:
> > Here is an upated patch. _bfd_elf_provide_symbol should presever
> > st_other. Also it needs to set forced_local to 1. Otherwise, we will
> > get global hidden symbols. We don't need those array symbols for
> > shared libraries.
> 
> Looks good.  OK for mainline, and the branch too unless Daniel
> disagrees.

That's fine.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-03-23  9:31               ` Daniel Jacobowitz
@ 2005-03-23  9:33                 ` H. J. Lu
  2005-04-25  4:53                   ` Michael Matz
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-03-23  9:33 UTC (permalink / raw)
  To: binutils

On Tue, Mar 22, 2005 at 09:11:09PM -0500, Daniel Jacobowitz wrote:
> On Wed, Mar 23, 2005 at 12:34:57PM +1030, Alan Modra wrote:
> > On Tue, Mar 22, 2005 at 02:44:22PM -0800, H. J. Lu wrote:
> > > Here is an upated patch. _bfd_elf_provide_symbol should presever
> > > st_other. Also it needs to set forced_local to 1. Otherwise, we will
> > > get global hidden symbols. We don't need those array symbols for
> > > shared libraries.
> > 
> > Looks good.  OK for mainline, and the branch too unless Daniel
> > disagrees.
> 
> That's fine.

This is the patch I checked in. I changed

gld${EMULATION_NAME}_provide_array_symbols

to

gld${EMULATION_NAME}_provide_bound_symbols

since it can be used to provide section start/end symbols.

It won't apply to 2.16 since it depends on some other changes in
mainline.


H.J.
----
bfd/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* bfd-in.h (_bfd_elf_provide_symbol): New.
	* bfd-in2.h: Regenerated.

	* elf32-ppc.c (set_linker_sym): Moved to elflink.c.
	(ppc_elf_set_sdata_syms): Call _bfd_elf_provide_symbol instead
	of set_linker_sym.

	* elflink.c (_bfd_elf_provide_symbol): New. Moved and renamed
	from elf32-ppc.c.

ld/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols): New
	(gld${EMULATION_NAME}_finish): Call
	gld${EMULATION_NAME}_provide_bound_symbols to provide
	__preinit_array_start, __preinit_array_end, __init_array_start,
	__init_array_end, __fini_array_start and __fini_array_end.

	* scripttempl/elf.sc: Don't provide __preinit_array_start,
	__preinit_array_end, __init_array_start, __init_array_end,
	__fini_array_start nor __fini_array_end.

--- binutils/bfd/bfd-in.h.provide	2005-02-21 11:10:29.000000000 -0800
+++ binutils/bfd/bfd-in.h	2005-03-22 12:52:00.000000000 -0800
@@ -694,6 +694,9 @@ extern int bfd_get_sign_extend_vma
 extern struct bfd_section *_bfd_elf_tls_setup
   (bfd *, struct bfd_link_info *);
 
+extern void _bfd_elf_provide_symbol
+  (struct bfd_link_info *, const char *, bfd_vma);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
--- binutils/bfd/elf32-ppc.c.provide	2005-03-22 07:14:43.000000000 -0800
+++ binutils/bfd/elf32-ppc.c	2005-03-22 12:52:00.000000000 -0800
@@ -4545,26 +4545,6 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
-
-static void
-set_linker_sym (struct ppc_elf_link_hash_table *htab,
-		const char *sym_name,
-		bfd_vma val)
-{
-  struct elf_link_hash_entry *h;
-  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
-  if (h != NULL && h->root.type == bfd_link_hash_undefined)
-    {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN;
-    }
-}
-
 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
    set here rather than via PROVIDE in the default linker script,
    because using PROVIDE inside an output section statement results in
@@ -4599,19 +4579,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
 	val = s->vma + 32768;
       lsect->sym_val = val;
 
-      set_linker_sym (htab, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
   val = 0;
   if (s != NULL)
     val = s->vma;
-  set_linker_sym (htab, "__sbss_start", val);
-  set_linker_sym (htab, "___sbss_start", val);
+  _bfd_elf_provide_symbol (info, "__sbss_start", val);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val);
   if (s != NULL)
     val += s->size;
-  set_linker_sym (htab, "__sbss_end", val);
-  set_linker_sym (htab, "___sbss_end", val);
+  _bfd_elf_provide_symbol (info, "__sbss_end", val);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val);
   return TRUE;
 }
 \f
--- binutils/bfd/elflink.c.provide	2005-03-22 07:14:45.000000000 -0800
+++ binutils/bfd/elflink.c	2005-03-22 14:31:19.054207031 -0800
@@ -9754,3 +9754,24 @@ _bfd_elf_section_already_linked (bfd *ab
   /* This is the first section with this name.  Record it.  */
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
+
+/* Set NAME to VAL if the symbol exists and is undefined.  */
+
+void
+_bfd_elf_provide_symbol (struct bfd_link_info *info, const char *name,
+			 bfd_vma val)
+{
+  struct elf_link_hash_entry *h;
+  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE,
+			    FALSE);
+  if (h != NULL && h->root.type == bfd_link_hash_undefined)
+    {
+      h->root.type = bfd_link_hash_defined;
+      h->root.u.def.section = bfd_abs_section_ptr;
+      h->root.u.def.value = val;
+      h->def_regular = 1;
+      h->type = STT_OBJECT;
+      h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
+      h->forced_local = 1;
+    }
+}
--- binutils/ld/emultempl/elf32.em.provide	2005-03-22 07:15:14.000000000 -0800
+++ binutils/ld/emultempl/elf32.em	2005-03-22 14:43:13.316089374 -0800
@@ -1428,6 +1428,29 @@ if test x"$LDEMUL_FINISH" != xgld"$EMULA
 cat >>e${EMULATION_NAME}.c <<EOF
 
 static void
+gld${EMULATION_NAME}_provide_bound_symbols (const char *sec,
+					    const char *start,
+					    const char *end)
+{
+  asection *s;
+  bfd_vma start_val, end_val;
+
+  s = bfd_get_section_by_name (output_bfd, sec);
+  if (s != NULL)
+    {
+      start_val = s->vma;
+      end_val = start_val + s->size;
+    }
+  else
+    {
+      start_val = 0;
+      end_val = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, start, start_val);
+  _bfd_elf_provide_symbol (&link_info, end, end_val);
+}
+
+static void
 gld${EMULATION_NAME}_finish (void)
 {
   if (bfd_elf_discard_info (output_bfd, &link_info))
@@ -1472,6 +1495,34 @@ gld${EMULATION_NAME}_finish (void)
 		  }
 	    }
 	}
+
+      /* If not building shared library, provide
+
+	 __preinit_array_start
+	 __preinit_array_end
+	 __init_array_start
+	 __init_array_end
+	 __fini_array_start
+	 __fini_array_end
+
+	 They are set here rather than via PROVIDE in the linker
+	 script, because using PROVIDE inside an output section
+	 statement results in unnecessary output sections.  Using
+	 PROVIDE outside an output section statement runs the risk of
+	 section alignment affecting where the section starts.  */
+
+      if (!link_info.shared)
+	{
+	  gld${EMULATION_NAME}_provide_bound_symbols
+	    (".preinit_array", "__preinit_array_start",
+	     "__preinit_array_end");
+	  gld${EMULATION_NAME}_provide_bound_symbols
+	    (".init_array", "__init_array_start",
+	     "__init_array_end");
+	  gld${EMULATION_NAME}_provide_bound_symbols
+	    (".fini_array", "__fini_array_start",
+	     "__fini_array_end");
+	}
     }
 }
 EOF
--- binutils/ld/scripttempl/elf.sc.provide	2005-03-21 13:13:41.000000000 -0800
+++ binutils/ld/scripttempl/elf.sc	2005-03-22 12:52:00.000000000 -0800
@@ -333,22 +333,9 @@ cat <<EOF
   .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
   .tbss		${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
   .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
   .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
 
   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-03-23  9:33                 ` H. J. Lu
@ 2005-04-25  4:53                   ` Michael Matz
  2005-04-25 14:55                     ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Matz @ 2005-04-25  4:53 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

Hi HJ,

On Tue, 22 Mar 2005, H. J. Lu wrote:

> On Tue, Mar 22, 2005 at 09:11:09PM -0500, Daniel Jacobowitz wrote:
> > On Wed, Mar 23, 2005 at 12:34:57PM +1030, Alan Modra wrote:
> > > On Tue, Mar 22, 2005 at 02:44:22PM -0800, H. J. Lu wrote:
> > > > Here is an upated patch. _bfd_elf_provide_symbol should presever
> > > > st_other. Also it needs to set forced_local to 1. Otherwise, we will
> > > > get global hidden symbols. We don't need those array symbols for
> > > > shared libraries.
> > > 
> > > Looks good.  OK for mainline, and the branch too unless Daniel
> > > disagrees.
> > 
> > That's fine.
> 
> since it can be used to provide section start/end symbols.
> 
> It won't apply to 2.16 since it depends on some other changes in
> mainline.

This patch introduces a regression for linking code with older glibcs on 
alpha, due to this error message:

/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_fini':
/usr/src/packages/BUILD/glibc-2.3/csu/elf-init.c:76: relocation truncated 
to fit: GPRELHIGH against symbol `__fini_array_start' defined in *ABS* 
section in <none>

The elf-init.oS has a GPRELHIGH reloc against the __fini_array_start
symbol.  This reloc is complain_overflow_signed.  As it is GP relative the
content of current GP is subtracted from the value of that symbol.  Your
patch defines the value of that symbol to be zero if the section is not
there.  Before your patch the ldscript defined it to be something after
.tbss independent if the .fini_array section was there or not.

So if this section is not there the final value of the relocation with
your patch will be "0 - gp".  This all is mappeg beyond the 32 bit border,
so bit 32 is set.  Hence the negative amount of that doesn't fit into 32
bit, resulting in the above error message.  Before your patch the symbols
value was in reach of 32 bit signed offsets of GP.

I'm not 100% sure what the best alternative would be.  I think simplest 
would be to define it to the start of .got, like in the below patch.  It 
works for me on alpha, but I don't know if that's a sane approach, or if 
.got is available everywhere (I guess with static executables it's not).


Ciao,
Michael.
-- 
--- ld/emultempl/elf32.em.mm	2005-04-25 04:49:34.000000000 +0000
+++ ld/emultempl/elf32.em	2005-04-25 04:50:46.000000000 +0000
@@ -1541,8 +1541,9 @@ gld${EMULATION_NAME}_provide_bound_symbo
     }
   else
     {
-      start_val = 0;
-      end_val = 0;
+      s = bfd_get_section_by_name (output_bfd, ".got");
+      start_val = s ? s->vma : 0;
+      end_val = start_val;
     }
   _bfd_elf_provide_symbol (&link_info, start, start_val);
   _bfd_elf_provide_symbol (&link_info, end, end_val);

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-04-25  4:53                   ` Michael Matz
@ 2005-04-25 14:55                     ` H. J. Lu
  2005-04-25 15:17                       ` Michael Matz
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-04-25 14:55 UTC (permalink / raw)
  To: Michael Matz; +Cc: binutils

On Mon, Apr 25, 2005 at 06:53:47AM +0200, Michael Matz wrote:
> Hi HJ,
> 
> On Tue, 22 Mar 2005, H. J. Lu wrote:
> 
> > On Tue, Mar 22, 2005 at 09:11:09PM -0500, Daniel Jacobowitz wrote:
> > > On Wed, Mar 23, 2005 at 12:34:57PM +1030, Alan Modra wrote:
> > > > On Tue, Mar 22, 2005 at 02:44:22PM -0800, H. J. Lu wrote:
> > > > > Here is an upated patch. _bfd_elf_provide_symbol should presever
> > > > > st_other. Also it needs to set forced_local to 1. Otherwise, we will
> > > > > get global hidden symbols. We don't need those array symbols for
> > > > > shared libraries.
> > > > 
> > > > Looks good.  OK for mainline, and the branch too unless Daniel
> > > > disagrees.
> > > 
> > > That's fine.
> > 
> > since it can be used to provide section start/end symbols.
> > 
> > It won't apply to 2.16 since it depends on some other changes in
> > mainline.
> 
> This patch introduces a regression for linking code with older glibcs on 
> alpha, due to this error message:

Did you say it only happens with the older glibc? What does the new
glibc do on alpha?

> I'm not 100% sure what the best alternative would be.  I think simplest 
> would be to define it to the start of .got, like in the below patch.  It 
> works for me on alpha, but I don't know if that's a sane approach, or if 
> .got is available everywhere (I guess with static executables it's not).
> 

Do you have a simple testcase for alpha which I can run on Linux/i386? 


H.J.

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

* Re: PATCH: Add _bfd_elf_provide_symbol
  2005-04-25 14:55                     ` H. J. Lu
@ 2005-04-25 15:17                       ` Michael Matz
  2005-04-25 17:31                         ` PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol) H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Matz @ 2005-04-25 15:17 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2799 bytes --]

Hi HJ,

On Mon, 25 Apr 2005, H. J. Lu wrote:

> > This patch introduces a regression for linking code with older glibcs on 
> > alpha, due to this error message:
> 
> Did you say it only happens with the older glibc?

Well, it's from last year:
% ll /usr/lib/libc_nonshared.a
-rw-r--r--  1 root root 50344 Apr 23  2004 /usr/lib/libc_nonshared.a
and is a 2.3.3 glibc.

so not that old.  The problem is the elf-init.oS member of that archive, 
which contains references to __fini_array_end and friends.  In current 
glibc CVS I still see the same references to those symbols in the source 
code (although it's obsolete one can't simply remove those functions, and 
anyway it would be too late for the above glibcs).  In particular we are 
talking about these relocations:

% objdump -r elf-init.oS | grep array
0000000000000008 GPRELHIGH         __fini_array_start
000000000000000c GPRELHIGH         __fini_array_end
0000000000000014 GPRELLOW          __fini_array_start
0000000000000018 GPRELLOW          __fini_array_end
00000000000000cc GPRELHIGH         __init_array_start
00000000000000d0 GPRELHIGH         __init_array_end
00000000000000d4 GPRELLOW          __init_array_start
00000000000000d8 GPRELLOW          __init_array_end

It should be noted that the alpha ld maps the executable start to beyond 
32 bit (as already mentioned in the last mail):
PROVIDE (__executable_start = 0x120000000); . = 0x120000000 + SIZEOF_HEADERS;

So, the difference between the symvalue 0 and GP is too large to fit into
signed 32 bit, which it must if GPRELHIGH/LOW relocations are used.

The libc_nonshared.a archive is linked into all executables so no 
executables can be produced anymore with the new binutils, as soon as they 
are installed one can't even build a new glibc (but I doubt this would 
change the error).  I had to hack the linker script to provide these 
symbols, and to make a gcc wrapper adding -Wl,-T,/elf-hack.x to link 
commands to be able to bootstrap this system again ;-)

> > I'm not 100% sure what the best alternative would be.  I think
> > simplest would be to define it to the start of .got, like in the below
> > patch.  It works for me on alpha, but I don't know if that's a sane
> > approach, or if .got is available everywhere (I guess with static
> > executables it's not).
> > 
> 
> Do you have a simple testcase for alpha which I can run on Linux/i386?

I've packed together the elf-init.oS file from the system, a small c file 
providing some symbols needed from that .oS, and this file precompiled for 
alpha.  So you should be able to reproduce the problem with:

% ld elf-init.oS a.o

with a cross linker.  This will of course not create a functioning 
executable, but will demonstrate the linking error.  With my patch this 
works.  Hope this helps.


Ciao,
Michael.

[-- Attachment #2: Type: APPLICATION/x-gunzip, Size: 2222 bytes --]

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

* PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-04-25 15:17                       ` Michael Matz
@ 2005-04-25 17:31                         ` H. J. Lu
  2005-04-25 17:46                           ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-04-25 17:31 UTC (permalink / raw)
  To: Michael Matz; +Cc: binutils

On Mon, Apr 25, 2005 at 05:17:24PM +0200, Michael Matz wrote:
> > Do you have a simple testcase for alpha which I can run on Linux/i386?
> 
> I've packed together the elf-init.oS file from the system, a small c file 
> providing some symbols needed from that .oS, and this file precompiled for 
> alpha.  So you should be able to reproduce the problem with:
> 
> % ld elf-init.oS a.o
> 
> with a cross linker.  This will of course not create a functioning 
> executable, but will demonstrate the linking error.  With my patch this 
> works.  Hope this helps.
> 

How about this patch?


H.J.
----
2005-04-25  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols):
	Use the first SEC_ALLOC section which isn't SEC_CODE or the
	last SEC_CODE section if the section doesn't exist.

--- ld/emultempl/elf32.em.alpha	2005-04-25 09:24:59.000000000 -0700
+++ ld/emultempl/elf32.em	2005-04-25 10:19:53.000000000 -0700
@@ -1463,8 +1463,22 @@ gld${EMULATION_NAME}_provide_bound_symbo
     }
   else
     {
+      /* We have to choose those values very carefully.  Some targets,
+	 like alpha, may have relocation overflow with 0.  We use the
+	 first SEC_ALLOC section which isn't SEC_CODE or the last
+	 SEC_CODE section.   */
       start_val = 0;
       end_val = 0;
+      for (s = output_bfd->sections; s != NULL; s = s->next)
+	{
+	  if ((s->flags & SEC_ALLOC) != 0)
+	    {
+	      start_val = s->vma;
+	      end_val = start_val + s->size;
+	      if ((s->flags & SEC_CODE) == 0)
+		break;
+	    }
+	}
     }
   _bfd_elf_provide_symbol (&link_info, start, start_val);
   _bfd_elf_provide_symbol (&link_info, end, end_val);

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-04-25 17:31                         ` PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol) H. J. Lu
@ 2005-04-25 17:46                           ` H. J. Lu
  2005-04-26 12:01                             ` Michael Matz
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-04-25 17:46 UTC (permalink / raw)
  To: Michael Matz; +Cc: binutils

On Mon, Apr 25, 2005 at 10:27:36AM -0700, H. J. Lu wrote:
> On Mon, Apr 25, 2005 at 05:17:24PM +0200, Michael Matz wrote:
> > > Do you have a simple testcase for alpha which I can run on Linux/i386?
> > 
> > I've packed together the elf-init.oS file from the system, a small c file 
> > providing some symbols needed from that .oS, and this file precompiled for 
> > alpha.  So you should be able to reproduce the problem with:
> > 
> > % ld elf-init.oS a.o
> > 
> > with a cross linker.  This will of course not create a functioning 
> > executable, but will demonstrate the linking error.  With my patch this 
> > works.  Hope this helps.
> > 
> 
> How about this patch?
> 
> 

Wrong patch. This is the updated one.


H.J.
----
2005-04-25  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols):
	Use the first SEC_ALLOC section which isn't SEC_CODE or the
	last SEC_CODE section if the section doesn't exist.

--- ld/emultempl/elf32.em.alpha	2005-04-25 09:24:59.000000000 -0700
+++ ld/emultempl/elf32.em	2005-04-25 10:41:25.000000000 -0700
@@ -1463,8 +1463,21 @@ gld${EMULATION_NAME}_provide_bound_symbo
     }
   else
     {
+      /* We have to choose those values very carefully.  Some targets,
+	 like alpha, may have relocation overflow with 0.  We use the
+	 first SEC_ALLOC section which isn't SEC_CODE or the last
+	 SEC_CODE section.   */
       start_val = 0;
-      end_val = 0;
+      for (s = output_bfd->sections; s != NULL; s = s->next)
+	{
+	  if ((s->flags & SEC_ALLOC) != 0)
+	    {
+	      start_val = s->vma;
+	      if ((s->flags & SEC_CODE) == 0)
+		break;
+	    }
+	}
+      end_val = start_val;
     }
   _bfd_elf_provide_symbol (&link_info, start, start_val);
   _bfd_elf_provide_symbol (&link_info, end, end_val);

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-04-25 17:46                           ` H. J. Lu
@ 2005-04-26 12:01                             ` Michael Matz
  2005-04-26 13:47                               ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Matz @ 2005-04-26 12:01 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

Hi,

On Mon, 25 Apr 2005, H. J. Lu wrote:

> > How about this patch?
> 
> Wrong patch. This is the updated one.

Fixes the problem for me.  Btw. why did you chose the first non-code alloc 
section for this (I'm just curious)?  This will be .interp in practice 
most often.


Ciao,
Michael.

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-04-26 12:01                             ` Michael Matz
@ 2005-04-26 13:47                               ` H. J. Lu
  2005-04-27 19:35                                 ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-04-26 13:47 UTC (permalink / raw)
  To: Michael Matz; +Cc: binutils

On Tue, Apr 26, 2005 at 02:01:43PM +0200, Michael Matz wrote:
> Hi,
> 
> On Mon, 25 Apr 2005, H. J. Lu wrote:
> 
> > > How about this patch?
> > 
> > Wrong patch. This is the updated one.
> 
> Fixes the problem for me.  Btw. why did you chose the first non-code alloc 
> section for this (I'm just curious)?  This will be .interp in practice 
> most often.
> 

I just happen to pick it. I have no preference.


H.J.

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-04-26 13:47                               ` H. J. Lu
@ 2005-04-27 19:35                                 ` H. J. Lu
  2005-05-03  1:27                                   ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-04-27 19:35 UTC (permalink / raw)
  To: Michael Matz; +Cc: binutils

On Tue, Apr 26, 2005 at 06:46:59AM -0700, H. J. Lu wrote:
> On Tue, Apr 26, 2005 at 02:01:43PM +0200, Michael Matz wrote:
> > Hi,
> > 
> > On Mon, 25 Apr 2005, H. J. Lu wrote:
> > 
> > > > How about this patch?
> > > 
> > > Wrong patch. This is the updated one.
> > 
> > Fixes the problem for me.  Btw. why did you chose the first non-code alloc 
> > section for this (I'm just curious)?  This will be .interp in practice 
> > most often.
> > 
> 
> I just happen to pick it. I have no preference.
> 
> 

I am going to check in this patch to fix alpha as an obvious fix by
the end of the day.


H.J.
----
2005-04-27  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols):
	Use the first SEC_ALLOC section which isn't SEC_READONLY or the
	last SEC_ALLOC section if such a section doesn't exist.

--- ld/emultempl/elf32.em.provide	2005-04-11 09:10:51.000000000 -0700
+++ ld/emultempl/elf32.em	2005-04-27 11:15:15.000000000 -0700
@@ -1457,8 +1457,21 @@ gld${EMULATION_NAME}_provide_bound_symbo
     }
   else
     {
+      /* We have to choose those values very carefully.  Some targets,
+	 like alpha, may have relocation overflow with 0.  We use the
+	 first SEC_ALLOC section which isn't SEC_READONLY or the last
+	 SEC_ALLOC section.   */
       start_val = 0;
-      end_val = 0;
+      for (s = output_bfd->sections; s != NULL; s = s->next)
+	{
+	  if ((s->flags & SEC_ALLOC) != 0)
+	    {
+	      start_val = s->vma;
+	      if ((s->flags & SEC_READONLY) == 0)
+		break;
+	    }
+	}
+      end_val = start_val;
     }
   _bfd_elf_provide_symbol (&link_info, start, start_val);
   _bfd_elf_provide_symbol (&link_info, end, end_val);

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-04-27 19:35                                 ` H. J. Lu
@ 2005-05-03  1:27                                   ` Alan Modra
  2005-05-03  1:35                                     ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-05-03  1:27 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Michael Matz, binutils

On Wed, Apr 27, 2005 at 11:18:40AM -0700, H. J. Lu wrote:
> --- ld/emultempl/elf32.em.provide	2005-04-11 09:10:51.000000000 -0700
> +++ ld/emultempl/elf32.em	2005-04-27 11:15:15.000000000 -0700
> @@ -1457,8 +1457,21 @@ gld${EMULATION_NAME}_provide_bound_symbo
>      }
>    else
>      {
> +      /* We have to choose those values very carefully.  Some targets,
> +	 like alpha, may have relocation overflow with 0.  We use the
> +	 first SEC_ALLOC section which isn't SEC_READONLY or the last
> +	 SEC_ALLOC section.   */
>        start_val = 0;
> -      end_val = 0;
> +      for (s = output_bfd->sections; s != NULL; s = s->next)
> +	{
> +	  if ((s->flags & SEC_ALLOC) != 0)
> +	    {
> +	      start_val = s->vma;
> +	      if ((s->flags & SEC_READONLY) == 0)
> +		break;
> +	    }
> +	}
> +      end_val = start_val;

I think this is a rather horrible hack.  Can't you do this some way that
avoids the potentially slow section list traversal?  How about defining
__init_fini_array in the linker script, and using its value instead?
(Default to zero if __init_fini_array isn't defined.)

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-05-03  1:27                                   ` Alan Modra
@ 2005-05-03  1:35                                     ` H. J. Lu
  2005-05-03  5:31                                       ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-05-03  1:35 UTC (permalink / raw)
  To: Michael Matz, binutils

On Tue, May 03, 2005 at 10:57:16AM +0930, Alan Modra wrote:
> On Wed, Apr 27, 2005 at 11:18:40AM -0700, H. J. Lu wrote:
> > --- ld/emultempl/elf32.em.provide	2005-04-11 09:10:51.000000000 -0700
> > +++ ld/emultempl/elf32.em	2005-04-27 11:15:15.000000000 -0700
> > @@ -1457,8 +1457,21 @@ gld${EMULATION_NAME}_provide_bound_symbo
> >      }
> >    else
> >      {
> > +      /* We have to choose those values very carefully.  Some targets,
> > +	 like alpha, may have relocation overflow with 0.  We use the
> > +	 first SEC_ALLOC section which isn't SEC_READONLY or the last
> > +	 SEC_ALLOC section.   */
> >        start_val = 0;
> > -      end_val = 0;
> > +      for (s = output_bfd->sections; s != NULL; s = s->next)
> > +	{
> > +	  if ((s->flags & SEC_ALLOC) != 0)
> > +	    {
> > +	      start_val = s->vma;
> > +	      if ((s->flags & SEC_READONLY) == 0)
> > +		break;
> > +	    }
> > +	}
> > +      end_val = start_val;
> 
> I think this is a rather horrible hack.  Can't you do this some way that
> avoids the potentially slow section list traversal?  How about defining
> __init_fini_array in the linker script, and using its value instead?
> (Default to zero if __init_fini_array isn't defined.)

That function is used to avoid __init_fini_array in the linker script. 
I think alpha may even work with the first SEC_ALLOC section, which
will be very likely among the first few sections.


H.J.

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-05-03  1:35                                     ` H. J. Lu
@ 2005-05-03  5:31                                       ` Alan Modra
  2005-05-03 21:40                                         ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-05-03  5:31 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Michael Matz, binutils

On Mon, May 02, 2005 at 06:35:28PM -0700, H. J. Lu wrote:
> > I think this is a rather horrible hack.  Can't you do this some way that
> > avoids the potentially slow section list traversal?  How about defining
> > __init_fini_array in the linker script, and using its value instead?
> > (Default to zero if __init_fini_array isn't defined.)
> 
> That function is used to avoid __init_fini_array in the linker script. 

No, it's to avoid a symbol defined inside an output section.  I'm
suggesting a symbol defined like

  __init_fini_array = .;
  .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
  .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
  .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-05-03  5:31                                       ` Alan Modra
@ 2005-05-03 21:40                                         ` H. J. Lu
  2005-05-04  6:18                                           ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-05-03 21:40 UTC (permalink / raw)
  To: Michael Matz, binutils

On Tue, May 03, 2005 at 03:01:08PM +0930, Alan Modra wrote:
> On Mon, May 02, 2005 at 06:35:28PM -0700, H. J. Lu wrote:
> > > I think this is a rather horrible hack.  Can't you do this some way that
> > > avoids the potentially slow section list traversal?  How about defining
> > > __init_fini_array in the linker script, and using its value instead?
> > > (Default to zero if __init_fini_array isn't defined.)
> > 
> > That function is used to avoid __init_fini_array in the linker script. 
> 
> No, it's to avoid a symbol defined inside an output section.  I'm
> suggesting a symbol defined like
> 
>   __init_fini_array = .;
>   .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
>   .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
>   .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }
> 


How about this patch?


H.J.
----
bfd/

2005-05-03  H.J. Lu  <hongjiu.lu@intel.com>

	* bfd-in.h (_bfd_elf_provide_section_bound_symbols): New.
	* bfd-in2.h: Regenerated.

	* elflink.c (bfd_elf_set_symbol): New.
	(_bfd_elf_provide_symbol): Call it.
	(_bfd_elf_provide_section_bound_symbols): New.

ld/

2005-05-03  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols):
	Call _bfd_elf_provide_section_bound_symbols.

--- binutils/bfd/bfd-in.h.pp	2005-05-03 14:10:31.000000000 -0700
+++ binutils/bfd/bfd-in.h	2005-05-03 14:16:21.000000000 -0700
@@ -697,6 +697,9 @@ extern struct bfd_section *_bfd_elf_tls_
 extern void _bfd_elf_provide_symbol
   (struct bfd_link_info *, const char *, bfd_vma);
 
+extern void _bfd_elf_provide_section_bound_symbols
+  (struct bfd_link_info *, struct bfd_section *sec, const char *, const char *);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
--- binutils/bfd/elflink.c.pp	2005-05-03 14:19:55.000000000 -0700
+++ binutils/bfd/elflink.c	2005-05-03 14:15:40.000000000 -0700
@@ -9913,6 +9913,18 @@ _bfd_elf_section_already_linked (bfd *ab
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
 
+static void
+bfd_elf_set_symbol (struct elf_link_hash_entry *h, bfd_vma val)
+{
+  h->root.type = bfd_link_hash_defined;
+  h->root.u.def.section = bfd_abs_section_ptr;
+  h->root.u.def.value = val;
+  h->def_regular = 1;
+  h->type = STT_OBJECT;
+  h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
+  h->forced_local = 1;
+}
+
 /* Set NAME to VAL if the symbol exists and is undefined.  */
 
 void
@@ -9925,13 +9937,58 @@ _bfd_elf_provide_symbol (struct bfd_link
 			    FALSE);
   if (h != NULL && (h->root.type == bfd_link_hash_undefined
 	            || h->root.type == bfd_link_hash_undefweak))
+    bfd_elf_set_symbol (h, val);
+}
+
+/* Set START and END to boundaries of SEC if they exist and are
+   undefined.  */
+
+void
+_bfd_elf_provide_section_bound_symbols (struct bfd_link_info *info,
+					asection *sec,
+					const char *start,
+					const char *end)
+{
+  struct elf_link_hash_entry *hs, *he;
+  bfd_vma start_val, end_val;
+  bfd_boolean do_start, do_end;
+
+  /* Check if we need them or not first.  */
+  hs = elf_link_hash_lookup (elf_hash_table (info), start, FALSE,
+			     FALSE, FALSE);
+  do_start = (hs != NULL
+	      && (hs->root.type == bfd_link_hash_undefined
+		  || hs->root.type == bfd_link_hash_undefweak));
+
+  he = elf_link_hash_lookup (elf_hash_table (info), end, FALSE,
+			     FALSE, FALSE);
+  do_end = (he != NULL
+	    && (he->root.type == bfd_link_hash_undefined
+		|| he->root.type == bfd_link_hash_undefweak));
+
+  if (!do_start && !do_end)
+    return;
+
+  if (sec != NULL)
     {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
-      h->forced_local = 1;
+      start_val = sec->vma;
+      end_val = start_val + sec->size;
     }
+  else
+    {
+      /* We have to choose those values very carefully.  Some targets,
+	 like alpha, may have relocation overflow with 0. "_edata"
+	 should be defined in all cases.  */
+      struct elf_link_hash_entry *h
+	= elf_link_hash_lookup (elf_hash_table (info), "_edata",
+				FALSE, FALSE, FALSE);
+      BFD_ASSERT (h != NULL && h->root.type == bfd_link_hash_defined);
+      start_val = end_val = h->root.u.def.value;
+    }
+
+  if (do_start)
+    bfd_elf_set_symbol (hs, start_val);
+
+  if (do_end)
+    bfd_elf_set_symbol (he, end_val);
 }
--- binutils/ld/emultempl/elf32.em.pp	2005-05-03 12:51:22.000000000 -0700
+++ binutils/ld/emultempl/elf32.em	2005-05-03 14:07:20.000000000 -0700
@@ -1452,35 +1452,8 @@ gld${EMULATION_NAME}_provide_bound_symbo
 					    const char *start,
 					    const char *end)
 {
-  asection *s;
-  bfd_vma start_val, end_val;
-
-  s = bfd_get_section_by_name (output_bfd, sec);
-  if (s != NULL)
-    {
-      start_val = s->vma;
-      end_val = start_val + s->size;
-    }
-  else
-    {
-      /* We have to choose those values very carefully.  Some targets,
-	 like alpha, may have relocation overflow with 0.  We use the
-	 first SEC_ALLOC section which isn't SEC_READONLY or the last
-	 SEC_ALLOC section.   */
-      start_val = 0;
-      for (s = output_bfd->sections; s != NULL; s = s->next)
-	{
-	  if ((s->flags & SEC_ALLOC) != 0)
-	    {
-	      start_val = s->vma;
-	      if ((s->flags & SEC_READONLY) == 0)
-		break;
-	    }
-	}
-      end_val = start_val;
-    }
-  _bfd_elf_provide_symbol (&link_info, start, start_val);
-  _bfd_elf_provide_symbol (&link_info, end, end_val);
+  asection *s = bfd_get_section_by_name (output_bfd, sec);
+  _bfd_elf_provide_section_bound_symbols (&link_info, s, start, end);
 }
 
 /* If not building a shared library, provide

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-05-03 21:40                                         ` H. J. Lu
@ 2005-05-04  6:18                                           ` Alan Modra
  2005-05-04  6:50                                             ` H. J. Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Alan Modra @ 2005-05-04  6:18 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Michael Matz, binutils

On Tue, May 03, 2005 at 02:24:50PM -0700, H. J. Lu wrote:
> +      /* We have to choose those values very carefully.  Some targets,
> +	 like alpha, may have relocation overflow with 0. "_edata"
> +	 should be defined in all cases.  */
> +      struct elf_link_hash_entry *h
> +	= elf_link_hash_lookup (elf_hash_table (info), "_edata",
> +				FALSE, FALSE, FALSE);
> +      BFD_ASSERT (h != NULL && h->root.type == bfd_link_hash_defined);
> +      start_val = end_val = h->root.u.def.value;

You are going to hit this assert if linking with a non-standard link
script.  "_edata" may well not be defined.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-05-04  6:18                                           ` Alan Modra
@ 2005-05-04  6:50                                             ` H. J. Lu
  2005-05-04 10:17                                               ` Alan Modra
  0 siblings, 1 reply; 25+ messages in thread
From: H. J. Lu @ 2005-05-04  6:50 UTC (permalink / raw)
  To: Michael Matz, binutils

On Wed, May 04, 2005 at 03:47:53PM +0930, Alan Modra wrote:
> On Tue, May 03, 2005 at 02:24:50PM -0700, H. J. Lu wrote:
> > +      /* We have to choose those values very carefully.  Some targets,
> > +	 like alpha, may have relocation overflow with 0. "_edata"
> > +	 should be defined in all cases.  */
> > +      struct elf_link_hash_entry *h
> > +	= elf_link_hash_lookup (elf_hash_table (info), "_edata",
> > +				FALSE, FALSE, FALSE);
> > +      BFD_ASSERT (h != NULL && h->root.type == bfd_link_hash_defined);
> > +      start_val = end_val = h->root.u.def.value;
> 
> You are going to hit this assert if linking with a non-standard link
> script.  "_edata" may well not be defined.
> 

It is OK as long as they don't reference those *_start/*_end symbols.

How about this one? If non-standard link script is used, users have to
know what they are doing.


H.J.
----
bfd/

2005-05-03  H.J. Lu  <hongjiu.lu@intel.com>

	* bfd-in.h (_bfd_elf_provide_section_bound_symbols): New.
	* bfd-in2.h: Regenerated.

	* elflink.c (bfd_elf_set_symbol): New.
	(_bfd_elf_provide_symbol): Call it.
	(_bfd_elf_provide_section_bound_symbols): New.

ld/

2005-05-03  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols):
	Call _bfd_elf_provide_section_bound_symbols.

--- binutils/bfd/bfd-in.h.pp	2005-05-03 14:10:31.000000000 -0700
+++ binutils/bfd/bfd-in.h	2005-05-03 14:16:21.000000000 -0700
@@ -697,6 +697,9 @@ extern struct bfd_section *_bfd_elf_tls_
 extern void _bfd_elf_provide_symbol
   (struct bfd_link_info *, const char *, bfd_vma);
 
+extern void _bfd_elf_provide_section_bound_symbols
+  (struct bfd_link_info *, struct bfd_section *sec, const char *, const char *);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
--- binutils/bfd/elflink.c.pp	2005-05-03 14:19:55.000000000 -0700
+++ binutils/bfd/elflink.c	2005-05-03 23:19:54.000000000 -0700
@@ -9913,6 +9913,18 @@ _bfd_elf_section_already_linked (bfd *ab
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
 
+static void
+bfd_elf_set_symbol (struct elf_link_hash_entry *h, bfd_vma val)
+{
+  h->root.type = bfd_link_hash_defined;
+  h->root.u.def.section = bfd_abs_section_ptr;
+  h->root.u.def.value = val;
+  h->def_regular = 1;
+  h->type = STT_OBJECT;
+  h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
+  h->forced_local = 1;
+}
+
 /* Set NAME to VAL if the symbol exists and is undefined.  */
 
 void
@@ -9925,13 +9937,61 @@ _bfd_elf_provide_symbol (struct bfd_link
 			    FALSE);
   if (h != NULL && (h->root.type == bfd_link_hash_undefined
 	            || h->root.type == bfd_link_hash_undefweak))
+    bfd_elf_set_symbol (h, val);
+}
+
+/* Set START and END to boundaries of SEC if they exist and are
+   undefined.  */
+
+void
+_bfd_elf_provide_section_bound_symbols (struct bfd_link_info *info,
+					asection *sec,
+					const char *start,
+					const char *end)
+{
+  struct elf_link_hash_entry *hs, *he;
+  bfd_vma start_val, end_val;
+  bfd_boolean do_start, do_end;
+
+  /* Check if we need them or not first.  */
+  hs = elf_link_hash_lookup (elf_hash_table (info), start, FALSE,
+			     FALSE, FALSE);
+  do_start = (hs != NULL
+	      && (hs->root.type == bfd_link_hash_undefined
+		  || hs->root.type == bfd_link_hash_undefweak));
+
+  he = elf_link_hash_lookup (elf_hash_table (info), end, FALSE,
+			     FALSE, FALSE);
+  do_end = (he != NULL
+	    && (he->root.type == bfd_link_hash_undefined
+		|| he->root.type == bfd_link_hash_undefweak));
+
+  if (!do_start && !do_end)
+    return;
+
+  if (sec != NULL)
     {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
-      h->forced_local = 1;
+      start_val = sec->vma;
+      end_val = start_val + sec->size;
     }
+  else
+    {
+      /* We have to choose those values very carefully.  Some targets,
+	 like alpha, may have relocation overflow with 0. "_edata"
+	 should be defined in all cases.  */
+      struct elf_link_hash_entry *h
+	= elf_link_hash_lookup (elf_hash_table (info), "_edata",
+				FALSE, FALSE, FALSE);
+      if (h != NULL && h->root.type == bfd_link_hash_defined)
+	start_val = h->root.u.def.value;
+      else
+	start_val = 0;
+      end_val = start_val;
+    }
+
+  if (do_start)
+    bfd_elf_set_symbol (hs, start_val);
+
+  if (do_end)
+    bfd_elf_set_symbol (he, end_val);
 }
--- binutils/ld/emultempl/elf32.em.pp	2005-05-03 12:51:22.000000000 -0700
+++ binutils/ld/emultempl/elf32.em	2005-05-03 14:07:20.000000000 -0700
@@ -1452,35 +1452,8 @@ gld${EMULATION_NAME}_provide_bound_symbo
 					    const char *start,
 					    const char *end)
 {
-  asection *s;
-  bfd_vma start_val, end_val;
-
-  s = bfd_get_section_by_name (output_bfd, sec);
-  if (s != NULL)
-    {
-      start_val = s->vma;
-      end_val = start_val + s->size;
-    }
-  else
-    {
-      /* We have to choose those values very carefully.  Some targets,
-	 like alpha, may have relocation overflow with 0.  We use the
-	 first SEC_ALLOC section which isn't SEC_READONLY or the last
-	 SEC_ALLOC section.   */
-      start_val = 0;
-      for (s = output_bfd->sections; s != NULL; s = s->next)
-	{
-	  if ((s->flags & SEC_ALLOC) != 0)
-	    {
-	      start_val = s->vma;
-	      if ((s->flags & SEC_READONLY) == 0)
-		break;
-	    }
-	}
-      end_val = start_val;
-    }
-  _bfd_elf_provide_symbol (&link_info, start, start_val);
-  _bfd_elf_provide_symbol (&link_info, end, end_val);
+  asection *s = bfd_get_section_by_name (output_bfd, sec);
+  _bfd_elf_provide_section_bound_symbols (&link_info, s, start, end);
 }
 
 /* If not building a shared library, provide

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

* Re: PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)
  2005-05-04  6:50                                             ` H. J. Lu
@ 2005-05-04 10:17                                               ` Alan Modra
  0 siblings, 0 replies; 25+ messages in thread
From: Alan Modra @ 2005-05-04 10:17 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Michael Matz, binutils

On Tue, May 03, 2005 at 11:24:21PM -0700, H. J. Lu wrote:
> How about this one? If non-standard link script is used, users have to
> know what they are doing.

OK.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

end of thread, other threads:[~2005-05-04  8:06 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-21 15:42 Yet another unnecessary powerpc section Alan Modra
2005-03-22  8:16 ` Alan Modra
2005-03-22 11:48   ` H. J. Lu
2005-03-22 12:06     ` Alan Modra
2005-03-22 17:37       ` PATCH: Add _bfd_elf_provide_symbol H. J. Lu
2005-03-23  4:19         ` H. J. Lu
2005-03-23  5:37           ` H. J. Lu
2005-03-23  9:28             ` Alan Modra
2005-03-23  9:31               ` Daniel Jacobowitz
2005-03-23  9:33                 ` H. J. Lu
2005-04-25  4:53                   ` Michael Matz
2005-04-25 14:55                     ` H. J. Lu
2005-04-25 15:17                       ` Michael Matz
2005-04-25 17:31                         ` PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol) H. J. Lu
2005-04-25 17:46                           ` H. J. Lu
2005-04-26 12:01                             ` Michael Matz
2005-04-26 13:47                               ` H. J. Lu
2005-04-27 19:35                                 ` H. J. Lu
2005-05-03  1:27                                   ` Alan Modra
2005-05-03  1:35                                     ` H. J. Lu
2005-05-03  5:31                                       ` Alan Modra
2005-05-03 21:40                                         ` H. J. Lu
2005-05-04  6:18                                           ` Alan Modra
2005-05-04  6:50                                             ` H. J. Lu
2005-05-04 10:17                                               ` 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).