This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix place_orphan; add .rela.opd to default ppc64 linker script


Hi!

cat > test.c <<EOF
extern int bar, baz, f1 (void), f2 (void);
int f3 (void) { return f1 () + 3; }
int f4 (void) { return f2 () + 4; }
EOF
gcc -shared -O2 -fpic -nostdlib -o test.so test.c
results in:
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .hash             HASH            00000000000000e8 0000e8 0000b4 04   A  2   0  8
  [ 2] .dynsym           DYNSYM          00000000000001a0 0001a0 000270 18   A  3  10  8
  [ 3] .dynstr           STRTAB          0000000000000410 000410 000030 00   A  0   0  1
  [ 4] .rela.plt         RELA            00000000000004a0 0004a0 000030 18   A  2   c  8
  [ 5] .text             PROGBITS        00000000000004d0 0004d0 0000f8 00  AX  0   0  4
  [ 6] .data             PROGBITS        00000000000105c8 0005c8 000000 00  WA  0   0  1
  [ 7] .branch_lt        PROGBITS        00000000000105c8 0005c8 000000 00  WA  0   0  8
  [ 8] .opd              PROGBITS        00000000000105c8 0005c8 000030 00  WA  0   0  8
  [ 9] .dynamic          DYNAMIC         00000000000105f8 0005f8 000130 10  WA  3   0  8
  [10] .got              PROGBITS        0000000000010728 000728 000008 08  WA  0   0  8
  [11] .sbss             NOBITS          0000000000010730 000730 000000 00   W  0   0  1
  [12] .plt              NOBITS          0000000000010730 000730 000048 18  WA  0   0  8
  [13] .bss              NOBITS          0000000000010778 000730 000000 00  WA  0   0  1
  [14] .comment          PROGBITS        0000000000000000 000730 000030 00      0   0  1
  [15] .rela.dyn         RELA            0000000000000440 000440 000060 18   A  2   0  8
  [16] .shstrtab         STRTAB          0000000000000000 000760 000083 00      0   0  1
  [17] .symtab           SYMTAB          0000000000000000 000ca8 000300 18     18  16  8
  [18] .strtab           STRTAB          0000000000000000 000fa8 00004c 00      0   0  1
(see .rela.dyn placement). Although this is not invalid, it makes such libraries
e.g. not prelinkable and is ugly.
The following patch fixes it (well, either hunk of the patch does, but I think both
should be done).
Ok to commit?

2003-08-05  Jakub Jelinek  <jakub@redhat.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): If secname
	is in the linker script but os->bfd_section is NULL, use
	output_prev_sec_find to place it on the right place in the section
	list.
	* emulparams/elf64ppc.sh (OTHER_GOT_RELOC_SECTIONS): Add .rela.opd.

--- binutils/ld/emulparams/elf64ppc.sh.jj	2003-07-28 10:24:45.000000000 -0400
+++ binutils/ld/emulparams/elf64ppc.sh	2003-08-05 08:35:58.000000000 -0400
@@ -28,7 +28,8 @@ else
   .toc		0 : { *(.toc) }"
 fi
 OTHER_GOT_RELOC_SECTIONS="
-  .rela.toc	${RELOCATING-0} : { *(.rela.toc) }"
+  .rela.toc	${RELOCATING-0} : { *(.rela.toc) }
+  .rela.opd	${RELOCATING-0} : { *(.rela.opd) }"
 OTHER_READWRITE_SECTIONS="
   .toc1		${RELOCATING-0}${RELOCATING+ALIGN(8)} : { *(.toc1) }
   .opd		${RELOCATING-0}${RELOCATING+ALIGN(8)} : { KEEP (*(.opd)) }"
--- binutils/ld/emultempl/elf32.em.jj	2003-08-05 06:59:49.000000000 -0400
+++ binutils/ld/emultempl/elf32.em	2003-08-05 08:27:23.000000000 -0400
@@ -1138,7 +1138,27 @@ gld${EMULATION_NAME}_place_orphan (lang_
 	{
 	  /* We already have an output section statement with this
 	     name, and its bfd section, if any, has compatible flags.  */
-	  lang_add_section (&os->children, s, os, file);
+	  if (os->bfd_section != NULL)
+	    lang_add_section (&os->children, s, os, file);
+	  else
+	    {
+	      asection *prev_section = output_prev_sec_find (os);
+	      lang_add_section (&os->children, s, os, file);
+	      if (prev_section != NULL)
+		{
+		  asection *snew = os->bfd_section, **pps;
+
+		  /* Unlink the section.  */
+		  for (pps = &output_bfd->sections; *pps != snew;
+		       pps = &(*pps)->next)
+		    ;
+		  bfd_section_list_remove (output_bfd, pps);
+
+		  /* Now tack it on to the "os" section list.  */
+		  bfd_section_list_insert (output_bfd, &prev_section->next,
+					   snew);
+		}
+	    }
 	  return TRUE;
 	}
     }

	Jakub


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