Support objcopy --remove-section=.relaFOO
authorAlan Modra <amodra@gmail.com>
Wed, 12 Sep 2018 05:27:48 +0000 (14:57 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 17 Sep 2018 14:01:18 +0000 (23:31 +0930)
* objcopy.c (handle_remove_section_option): Don't require a dot
after .rela and .rel to handle a possible relocation section.
* testsuite/binutils-all/remove-relocs-07.s,
* testsuite/binutils-all/remove-relocs-07.d,
* testsuite/binutils-all/remove-relocs-08.d: New tests.
* testsuite/binutils-all/remove-relocs-01.d,
* testsuite/binutils-all/remove-relocs-04.d,
* testsuite/binutils-all/remove-relocs-05.d,
* testsuite/binutils-all/remove-relocs-06.d: Exclude mips64-openbsd.

binutils/ChangeLog
binutils/objcopy.c
binutils/testsuite/binutils-all/remove-relocs-01.d
binutils/testsuite/binutils-all/remove-relocs-04.d
binutils/testsuite/binutils-all/remove-relocs-05.d
binutils/testsuite/binutils-all/remove-relocs-06.d
binutils/testsuite/binutils-all/remove-relocs-07.d [new file with mode: 0644]
binutils/testsuite/binutils-all/remove-relocs-07.s [new file with mode: 0644]
binutils/testsuite/binutils-all/remove-relocs-08.d [new file with mode: 0644]

index ee6defcbf8dd3a1e796d840df14c108d422e0c47..5207db81931775e569ac7c286fe8a657d1343472 100644 (file)
@@ -1,3 +1,15 @@
+2018-09-17  Alan Modra  <amodra@gmail.com>
+
+       * objcopy.c (handle_remove_section_option): Don't require a dot
+       after .rela and .rel to handle a possible relocation section.
+       * testsuite/binutils-all/remove-relocs-07.s,
+       * testsuite/binutils-all/remove-relocs-07.d,
+       * testsuite/binutils-all/remove-relocs-08.d: New tests.
+       * testsuite/binutils-all/remove-relocs-01.d,
+       * testsuite/binutils-all/remove-relocs-04.d,
+       * testsuite/binutils-all/remove-relocs-05.d,
+       * testsuite/binutils-all/remove-relocs-06.d: Exclude mips64-openbsd.
+
 2018-09-17  Alan Modra  <amodra@gmail.com>
 
        * testsuite/lib/binutils-common.exp (is_som_format): New proc.
index 8e06cd284f5a72dfed52ff73ff70b3457b326a86..2e40b42da318e5bcfbbb04567d2816b43068016a 100644 (file)
@@ -3943,18 +3943,21 @@ discard_relocations (bfd *ibfd ATTRIBUTE_UNUSED, asection *isection)
 
 /* Wrapper for dealing with --remove-section (-R) command line arguments.
    A special case is detected here, if the user asks to remove a relocation
-   section (one starting with ".rela." or ".rel.") then this removal must
+   section (one starting with ".rela" or ".rel") then this removal must
    be done using a different technique in a relocatable object.  */
 
 static void
 handle_remove_section_option (const char *section_pattern)
 {
-  if (strncmp (section_pattern, ".rela.", 6) == 0)
-    handle_remove_relocations_option (section_pattern + 5);
-  else if (strncmp (section_pattern, ".rel.", 5) == 0)
-    handle_remove_relocations_option (section_pattern + 4);
-
   find_section_list (section_pattern, TRUE, SECTION_CONTEXT_REMOVE);
+  if (strncmp (section_pattern, ".rel", 4) == 0)
+    {
+      section_pattern += 4;
+      if (*section_pattern == 'a')
+       section_pattern++;
+      if (*section_pattern)
+       handle_remove_relocations_option (section_pattern);
+    }
   sections_removed = TRUE;
 }
 
index 9cd0bfeb63ffa1c46a15624f9ac07f65f4e514c7..702747bc3f3c5c0aa48919cdb4f77db0bb27ed7f 100644 (file)
@@ -2,6 +2,7 @@
 #source: remove-relocs-01.s
 #objcopy: --remove-relocations=.data.relocs.01
 #readelf: -r
+#notarget: "mips64*-*-openbsd*"
 
 Relocation section '\.rela?\.data\.relocs\.02' at offset 0x[0-9a-f]+ contains 3 entries:
 .*
index 99f5a6146eb92875962668ccd2a0944a432d426a..1b8eab39a1a3c892839711a5150200f5a53071a0 100644 (file)
@@ -2,6 +2,7 @@
 #source: remove-relocs-01.s
 #objcopy: --remove-relocations=.data.relocs.0\[12\]
 #readelf: -r
+#notarget: "mips64*-*-openbsd*"
 
 Relocation section '\.rela?\.data\.relocs\.03' at offset 0x[0-9a-f]+ contains 3 entries:
 .*
index e2166c93d91d98f1874194c6519f86f8acd981b5..a429182d258f5a7afe2daa4ea6d207b13d5c5285 100644 (file)
@@ -2,6 +2,7 @@
 #source: remove-relocs-01.s
 #objcopy: --remove-section=.rela.data.relocs.01 --remove-section=.rel.data.relocs.01
 #readelf: -r
+#notarget: "mips64*-*-openbsd*"
 
 Relocation section '\.rela?\.data\.relocs\.02' at offset 0x[0-9a-f]+ contains 3 entries:
 .*
index 09fed58bb096639fd968687180ddde303b8fb114..5214bc7297ab6b8ceec9068f7548b52c7ffa7619 100644 (file)
@@ -2,6 +2,7 @@
 #source: remove-relocs-01.s
 #objcopy: --remove-relocations=.data.relocs.* --remove-relocations=!.data.relocs.02
 #readelf: -r
+#notarget: "mips64*-*-openbsd*"
 
 Relocation section '\.rela?\.data\.relocs\.02' at offset 0x[0-9a-f]+ contains 3 entries:
 .*
diff --git a/binutils/testsuite/binutils-all/remove-relocs-07.d b/binutils/testsuite/binutils-all/remove-relocs-07.d
new file mode 100644 (file)
index 0000000..c69df8d
--- /dev/null
@@ -0,0 +1,6 @@
+#PROG: objcopy
+#source: remove-relocs-07.s
+#objcopy: --remove-relocations=FOO
+#readelf: -r
+
+There are no relocations in this file\.
diff --git a/binutils/testsuite/binutils-all/remove-relocs-07.s b/binutils/testsuite/binutils-all/remove-relocs-07.s
new file mode 100644 (file)
index 0000000..1e95375
--- /dev/null
@@ -0,0 +1,2 @@
+       .section "FOO","aw",%progbits
+       .dc.a x
diff --git a/binutils/testsuite/binutils-all/remove-relocs-08.d b/binutils/testsuite/binutils-all/remove-relocs-08.d
new file mode 100644 (file)
index 0000000..f54462d
--- /dev/null
@@ -0,0 +1,6 @@
+#PROG: objcopy
+#source: remove-relocs-07.s
+#objcopy: --remove-section=.relFOO --remove-section=.relaFOO
+#readelf: -r
+
+There are no relocations in this file\.