public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] objcopy: Allow making symbol global and weak on same invocation
Date: Sun, 30 Jun 2024 22:23:31 +0000 (GMT)	[thread overview]
Message-ID: <20240630222331.83D54382DB13@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ebe3f6d0f18505e3f6a1800d3a3ee4b3403d726f

commit ebe3f6d0f18505e3f6a1800d3a3ee4b3403d726f
Author: Marcus Nilsson <brainbomb@gmail.com>
Date:   Sat Jun 29 23:01:56 2024 +0200

    objcopy: Allow making symbol global and weak on same invocation
    
    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.

Diff:
---
 binutils/objcopy.c                          | 31 +++++++++++++++--------------
 binutils/testsuite/binutils-all/symbols-5.d |  8 ++++++++
 binutils/testsuite/binutils-all/symbols-5.s |  3 +++
 3 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 26f9d4a0f26..f54ae734198 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -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
index 00000000000..ffaa950fc5b
--- /dev/null
+++ b/binutils/testsuite/binutils-all/symbols-5.d
@@ -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
index 00000000000..aa01b9e4a60
--- /dev/null
+++ b/binutils/testsuite/binutils-all/symbols-5.s
@@ -0,0 +1,3 @@
+ .text
+foo:
+ .word 0x0

                 reply	other threads:[~2024-06-30 22:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240630222331.83D54382DB13@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=binutils-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).