objcopy --weaken-symbol: apply to STB_GNU_UNIQUE symbols
authorFangrui Song <i@maskray.me>
Wed, 16 Mar 2022 16:38:37 +0000 (09:38 -0700)
committerFangrui Song <i@maskray.me>
Wed, 16 Mar 2022 16:40:13 +0000 (09:40 -0700)
    PR binutils/28926
    * objcopy.c (filter_symbols): Apply weaken to STB_GNU_UNIQUE symbols
    * NEWS: Mention feature.
    * testsuite/binutils-all/objcopy.exp (objcopy_test_symbol_manipulation): New test.
    * testsuite/binutils-all/weaken-gnu-unique.s: New.

binutils/ChangeLog
binutils/NEWS
binutils/objcopy.c
binutils/testsuite/binutils-all/objcopy.exp
binutils/testsuite/binutils-all/weaken-gnu-unique.d [new file with mode: 0644]

index 127ee5c50d1d52e8be912fa37cc1c89e9e7f71cc..f84323953d6d2e7db9d5dbfb849b39a0924b9eaa 100644 (file)
@@ -1,3 +1,11 @@
+2022-03-16  Fangrui Song  <maskray@google.com>
+
+       PR binutils/28926
+       * objcopy.c (filter_symbols): Apply weaken to STB_GNU_UNIQUE symbols
+       * NEWS: Mention feature.
+       * testsuite/binutils-all/objcopy.exp (objcopy_test_symbol_manipulation): New test.
+       * testsuite/binutils-all/weaken-gnu-unique.s: New.
+
 2022-03-16  Martin Storsjö  <martin@martin.st>
 
        PR 28885
index 3c447083e2e4a587a74a99cb28ac5943623566a1..7e3c005f25c9719252617391cec71a86b3ced6d6 100644 (file)
@@ -2,6 +2,8 @@
 
 * Add an option to objdump and readelf to prevent attempts to access debuginfod
   servers when following links.
+* objcopy --weaken, --weaken-symbol, and --weaken-symbols now make ELF
+  STB_GNU_UNIQUE symbols weak.
 
 Changes in 2.38:
 
index d53aa5c6000f093b84a47c17b302365ab635526b..aaa5aa9b2afe7614a73b42a54fe5d87e7e853a5b 100644 (file)
@@ -1681,11 +1681,11 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
 
       if (keep)
        {
-         if (((flags & BSF_GLOBAL) != 0
+         if (((flags & (BSF_GLOBAL | BSF_GNU_UNIQUE))
               || undefined)
              && (weaken || is_specified_symbol (name, weaken_specific_htab)))
            {
-             sym->flags &= ~ BSF_GLOBAL;
+             sym->flags &= ~ (BSF_GLOBAL | BSF_GNU_UNIQUE);
              sym->flags |= BSF_WEAK;
            }
 
index 32c76a11f3b3dbfd1a4da5a2d78e7325d3e36af1..9a5dad5384e1bad95f6d273fcbb6fec6d6ade2eb 100644 (file)
@@ -1144,6 +1144,10 @@ proc objcopy_test_symbol_manipulation {} {
         verbose [file rootname $t]
         run_dump_test [file rootname $t]
     }
+
+    if { [supports_gnu_unique] } {
+       run_dump_test "weaken-gnu-unique"
+    }
 }
 
 proc objcopy_test_elf_common_symbols {} {
diff --git a/binutils/testsuite/binutils-all/weaken-gnu-unique.d b/binutils/testsuite/binutils-all/weaken-gnu-unique.d
new file mode 100644 (file)
index 0000000..b0e60c4
--- /dev/null
@@ -0,0 +1,8 @@
+#name: weaken STB_GNU_UNIQUE symbols
+#PROG: objcopy
+#objcopy: -W foo
+#source: unique.s
+#readelf: -s
+
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9]+ +OBJECT +WEAK +DEFAULT +[1-9] foo