]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/binutils-tumbl.git/commitdiff
Don't generate empty reloc sections
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 13 Apr 2012 02:52:33 +0000 (02:52 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 13 Apr 2012 02:52:33 +0000 (02:52 +0000)
binutils/

PR binutils/13947
* objcopy.c (copy_object): Call copy_relocations_in_section
before copy_section.
(skip_section): New.
(copy_relocations_in_section): Likewise.
(copy_section): Use skip_section.  Don't copy relocations here.

binutils/testsuite/

PR binutils/13947
* binutils-all/i386/compressed-1b.d: Remove empty REL section.
* binutils-all/i386/compressed-1c.d: Likewise.

* binutils-all/x86-64/compressed-1b.d: Remove empty RELA
section.
* binutils-all/x86-64/compressed-1c.d: Likewise.

binutils/ChangeLog
binutils/objcopy.c
binutils/testsuite/ChangeLog
binutils/testsuite/binutils-all/i386/compressed-1b.d
binutils/testsuite/binutils-all/i386/compressed-1c.d
binutils/testsuite/binutils-all/x86-64/compressed-1b.d
binutils/testsuite/binutils-all/x86-64/compressed-1c.d

index 5c0492c075a71ab42a6b68458de42747b5c66cef..7b6c2191f746d23ef10016b717ec26b37ef7991c 100644 (file)
@@ -1,3 +1,12 @@
+2012-04-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/13947
+       * objcopy.c (copy_object): Call copy_relocations_in_section
+       before copy_section.
+       (skip_section): New.
+       (copy_relocations_in_section): Likewise.
+       (copy_section): Use skip_section.  Don't copy relocations here.
+
 2012-04-11  Ryan Mansfield  <rmansfield@qnx.com>
 
         * objdump.c (dump_bfd): If defaulting to dwarf call
index 230d3e564807eed2cc32d36df4482e48be9dc02b..a48ac4338d5368589da344a98140b658a58f3e77 100644 (file)
@@ -459,6 +459,7 @@ extern bfd_boolean S3Forced;
 /* Forward declarations.  */
 static void setup_section (bfd *, asection *, void *);
 static void setup_bfd_headers (bfd *, bfd *);
+static void copy_relocations_in_section (bfd *, asection *, void *);
 static void copy_section (bfd *, asection *, void *);
 static void get_sections (bfd *, asection *, void *);
 static int compare_section_lma (const void *, const void *);
@@ -1885,6 +1886,9 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
   bfd_set_symtab (obfd, osympp, symcount);
 
+  /* This has to happen before section positions are set.  */
+  bfd_map_over_sections (ibfd, copy_relocations_in_section, obfd);
+
   /* This has to happen after the symbol table has been set.  */
   bfd_map_over_sections (ibfd, copy_section, obfd);
 
@@ -2588,44 +2592,56 @@ loser:
   bfd_nonfatal_message (NULL, obfd, osection, err);
 }
 
-/* Copy the data of input section ISECTION of IBFD
-   to an output section with the same name in OBFD.
-   If stripping then don't copy any relocation info.  */
+/* Return TRUE if input section ISECTION should be skipped.  */
 
-static void
-copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
+static bfd_boolean
+skip_section (bfd *ibfd, sec_ptr isection)
 {
-  bfd *obfd = (bfd *) obfdarg;
-  struct section_list *p;
-  arelent **relpp;
-  long relcount;
   sec_ptr osection;
   bfd_size_type size;
-  long relsize;
   flagword flags;
 
   /* If we have already failed earlier on,
      do not keep on generating complaints now.  */
   if (status != 0)
-    return;
+    return TRUE;
+
+  if (extract_symbol)
+    return TRUE;
 
   if (is_strip_section (ibfd, isection))
-    return;
+    return TRUE;
 
   flags = bfd_get_section_flags (ibfd, isection);
   if ((flags & SEC_GROUP) != 0)
-    return;
+    return TRUE;
 
   osection = isection->output_section;
   size = bfd_get_section_size (isection);
 
   if (size == 0 || osection == 0)
-    return;
+    return TRUE;
 
-  if (extract_symbol)
+  return FALSE;
+}
+
+/* Copy relocations in input section ISECTION of IBFD to an output
+   section with the same name in OBFDARG.  If stripping then don't
+   copy any relocation info.  */
+
+static void
+copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
+{
+  bfd *obfd = (bfd *) obfdarg;
+  long relsize;
+  arelent **relpp;
+  long relcount;
+  sec_ptr osection;
+
+  if (skip_section (ibfd, isection))
     return;
 
-  p = find_section_list (bfd_get_section_name (ibfd, isection), FALSE);
+  osection = isection->output_section;
 
   /* Core files do not need to be relocated.  */
   if (bfd_get_format (obfd) == bfd_core)
@@ -2682,8 +2698,31 @@ copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
 
       bfd_set_reloc (obfd, osection, relcount == 0 ? NULL : relpp, relcount);
       if (relcount == 0)
-       free (relpp);
+       {
+         osection->flags &= ~SEC_RELOC;
+         free (relpp);
+       }
     }
+}
+
+/* Copy the data of input section ISECTION of IBFD
+   to an output section with the same name in OBFD.  */
+
+static void
+copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
+{
+  bfd *obfd = (bfd *) obfdarg;
+  struct section_list *p;
+  sec_ptr osection;
+  bfd_size_type size;
+
+  if (skip_section (ibfd, isection))
+    return;
+
+  osection = isection->output_section;
+  size = bfd_get_section_size (isection);
+
+  p = find_section_list (bfd_get_section_name (ibfd, isection), FALSE);
 
   if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
       && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
index db44b9209dd6d3fefc1835dde21c33337b88c9df..797272d0e749b7fb7680baae11f2558c3736532e 100644 (file)
@@ -1,3 +1,13 @@
+2012-04-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/13947
+       * binutils-all/i386/compressed-1b.d: Remove empty REL section.
+       * binutils-all/i386/compressed-1c.d: Likewise.
+
+       * binutils-all/x86-64/compressed-1b.d: Remove empty RELA
+       section.
+       * binutils-all/x86-64/compressed-1c.d: Likewise.
+
 2012-04-03  Roland McGrath  <mcgrathr@google.com>
 
        * lib/binutils-common.exp (is_elf_format): Consider *-*-nacl* to
index 1e13f6bc598f2ed4024570106533fdf20af744b2..d7ffe21d8874b714a225d5123919f5ad00916ece 100644 (file)
@@ -5,15 +5,14 @@
 #readelf: -S --wide
 #name: strip on uncompressed debug sections
 
-There are 6 section headers, starting at offset 0x7c:
+There are 5 section headers, starting at offset 0x78:
 
 Section Headers:
   \[Nr\] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
   \[ 0\]                   NULL            00000000 000000 000000 00      0   0  0
   \[ 1\] .text             PROGBITS        00000000 000040 00001b 00  AX  0   0 16
-  \[ 2\] .rel.text         REL             00000000 00016c 000000 08      0   1  4
-  \[ 3\] .data             PROGBITS        00000000 00005c 000000 00  WA  0   0  4
-  \[ 4\] .bss              NOBITS          00000000 00005c 000000 00  WA  0   0  4
-  \[ 5\] .shstrtab         STRTAB          00000000 00005c 000020 00      0   0  1
+  \[ 2\] .data             PROGBITS        00000000 00005c 000000 00  WA  0   0  4
+  \[ 3\] .bss              NOBITS          00000000 00005c 000000 00  WA  0   0  4
+  \[ 4\] .shstrtab         STRTAB          00000000 00005c 00001c 00      0   0  1
 Key to Flags:
 #...
index 1e7467a1692686279a97914d5e4b093d6f313d91..3db18fe31c35e1c92cf568fc107adbe8d69966c1 100644 (file)
@@ -5,15 +5,14 @@
 #readelf: -S --wide
 #name: strip on compressed debug sections
 
-There are 6 section headers, starting at offset 0x7c:
+There are 5 section headers, starting at offset 0x78:
 
 Section Headers:
   \[Nr\] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
   \[ 0\]                   NULL            00000000 000000 000000 00      0   0  0
   \[ 1\] .text             PROGBITS        00000000 000040 00001b 00  AX  0   0 16
-  \[ 2\] .rel.text         REL             00000000 00016c 000000 08      0   1  4
-  \[ 3\] .data             PROGBITS        00000000 00005c 000000 00  WA  0   0  4
-  \[ 4\] .bss              NOBITS          00000000 00005c 000000 00  WA  0   0  4
-  \[ 5\] .shstrtab         STRTAB          00000000 00005c 000020 00      0   0  1
+  \[ 2\] .data             PROGBITS        00000000 00005c 000000 00  WA  0   0  4
+  \[ 3\] .bss              NOBITS          00000000 00005c 000000 00  WA  0   0  4
+  \[ 4\] .shstrtab         STRTAB          00000000 00005c 00001c 00      0   0  1
 Key to Flags:
 #...
index 39a8f59ce697e40aa6b84dae46f724ceb5e4444a..078ccb6c6e8e063e09e1535cc4ad2af5d83faaf8 100644 (file)
@@ -5,15 +5,14 @@
 #readelf: -S --wide
 #name: strip on uncompressed debug sections
 
-There are 6 section headers, starting at offset 0x80:
+There are 5 section headers, starting at offset 0x78:
 
 Section Headers:
   \[Nr\] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
   \[ 0\]                   NULL            0000000000000000 000000 000000 00      0   0  0
   \[ 1\] .text             PROGBITS        0000000000000000 000040 000015 00  AX  0   0 16
-  \[ 2\] .rela.text        RELA            0000000000000000 000200 000000 18      0   1  8
-  \[ 3\] .data             PROGBITS        0000000000000000 000058 000000 00  WA  0   0  4
-  \[ 4\] .bss              NOBITS          0000000000000000 000058 000000 00  WA  0   0  4
-  \[ 5\] .shstrtab         STRTAB          0000000000000000 000058 000021 00      0   0  1
+  \[ 2\] .data             PROGBITS        0000000000000000 000058 000000 00  WA  0   0  4
+  \[ 3\] .bss              NOBITS          0000000000000000 000058 000000 00  WA  0   0  4
+  \[ 4\] .shstrtab         STRTAB          0000000000000000 000058 00001c 00      0   0  1
 Key to Flags:
 #...
index 33adfc10cf68dbf8497bed96db38c003cc7a0225..90a3c2d7ffdadb5b43e1b5344b7146e61f2a5c6d 100644 (file)
@@ -5,15 +5,14 @@
 #readelf: -S --wide
 #name: strip on compressed debug sections
 
-There are 6 section headers, starting at offset 0x80:
+There are 5 section headers, starting at offset 0x78:
 
 Section Headers:
   \[Nr\] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
   \[ 0\]                   NULL            0000000000000000 000000 000000 00      0   0  0
   \[ 1\] .text             PROGBITS        0000000000000000 000040 000015 00  AX  0   0 16
-  \[ 2\] .rela.text        RELA            0000000000000000 000200 000000 18      0   1  8
-  \[ 3\] .data             PROGBITS        0000000000000000 000058 000000 00  WA  0   0  4
-  \[ 4\] .bss              NOBITS          0000000000000000 000058 000000 00  WA  0   0  4
-  \[ 5\] .shstrtab         STRTAB          0000000000000000 000058 000021 00      0   0  1
+  \[ 2\] .data             PROGBITS        0000000000000000 000058 000000 00  WA  0   0  4
+  \[ 3\] .bss              NOBITS          0000000000000000 000058 000000 00  WA  0   0  4
+  \[ 4\] .shstrtab         STRTAB          0000000000000000 000058 00001c 00      0   0  1
 Key to Flags:
 #...