]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objcopy: Allow making symbol global and weak on same invocation
authorMarcus Nilsson <brainbomb@gmail.com>
Sat, 29 Jun 2024 21:01:56 +0000 (23:01 +0200)
committerAlan Modra <amodra@gmail.com>
Sun, 30 Jun 2024 21:49:47 +0000 (07:19 +0930)
Previously objcopy had to be run twice in order to make a local symbol
weak, first once to globalize it, and once again to mark it as weak.

* objcopy.c (filter_symbols): Weaken symbols after making
local/global changes.
* testsuite/binutils-all/symbols-5.d,
* testsuite/binutils-all/symbols-5.s: New test.

binutils/objcopy.c
binutils/testsuite/binutils-all/symbols-5.d [new file with mode: 0644]
binutils/testsuite/binutils-all/symbols-5.s [new file with mode: 0644]

index 26f9d4a0f262f5b437172cb31e9ad5a5b4ea14ce..f54ae734198a437c00c85dd31bb87abfd9699d5c 100644 (file)
@@ -1730,14 +1730,6 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
 
       if (keep)
        {
-         if (((flags & (BSF_GLOBAL | BSF_GNU_UNIQUE))
-              || undefined)
-             && (weaken || is_specified_symbol (name, weaken_specific_htab)))
-           {
-             sym->flags &= ~ (BSF_GLOBAL | BSF_GNU_UNIQUE);
-             sym->flags |= BSF_WEAK;
-           }
-
          if (!undefined
              && (flags & (BSF_GLOBAL | BSF_WEAK))
              && (is_specified_symbol (name, localize_specific_htab)
@@ -1745,18 +1737,27 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
                      && ! is_specified_symbol (name, keepglobal_specific_htab))
                  || (localize_hidden && is_hidden_symbol (sym))))
            {
-             sym->flags &= ~ (BSF_GLOBAL | BSF_WEAK);
-             sym->flags |= BSF_LOCAL;
+             flags &= ~(BSF_GLOBAL | BSF_WEAK);
+             flags |= BSF_LOCAL;
            }
 
-         if (!undefined
-             && (flags & BSF_LOCAL)
-             && is_specified_symbol (name, globalize_specific_htab))
+         else if (!undefined
+                  && (flags & BSF_LOCAL)
+                  && is_specified_symbol (name, globalize_specific_htab))
+           {
+             flags &= ~BSF_LOCAL;
+             flags |= BSF_GLOBAL;
+           }
+
+         if (((flags & (BSF_GLOBAL | BSF_GNU_UNIQUE))
+              || undefined)
+             && (weaken || is_specified_symbol (name, weaken_specific_htab)))
            {
-             sym->flags &= ~ BSF_LOCAL;
-             sym->flags |= BSF_GLOBAL;
+             flags &= ~(BSF_GLOBAL | BSF_GNU_UNIQUE);
+             flags |= BSF_WEAK;
            }
 
+         sym->flags = flags;
          to[dst_count++] = sym;
        }
     }
diff --git a/binutils/testsuite/binutils-all/symbols-5.d b/binutils/testsuite/binutils-all/symbols-5.d
new file mode 100644 (file)
index 0000000..ffaa950
--- /dev/null
@@ -0,0 +1,8 @@
+#name: globalize and weaken 'foo'
+#PROG: objcopy
+#objcopy: --globalize-symbol foo -W foo
+#source: symbols-5.s
+#nm: -n
+
+#...
+0+ [VW] foo
diff --git a/binutils/testsuite/binutils-all/symbols-5.s b/binutils/testsuite/binutils-all/symbols-5.s
new file mode 100644 (file)
index 0000000..aa01b9e
--- /dev/null
@@ -0,0 +1,3 @@
+ .text
+foo:
+ .word 0x0