[binutils-gdb] gas: don't fail due to local register symbols

Jan Beulich jbeulich@sourceware.org
Mon Apr 20 06:39:59 GMT 2026


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

commit e8086b69f6db02845769fb60895b652e670362f3
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Apr 20 08:36:54 2026 +0200

    gas: don't fail due to local register symbols
    
    The diagnostic text as well as its origin are pretty clear: This is about
    global symbols. This is further supported by S_IS_LOCAL() returning true
    for symbols in reg_section. Add the missing check, adjusting the testcase
    that was introduced back at the time (where the sole diagnostic originally
    issued was therefore wrong, while other diagnostics were missing, but got
    added thanks to work done elsewhere). Further drop the bogus trailing .equ
    in another testcase, which were apparently put there to avoid tripping
    this or some other undue check (albeit no error surfaced there already
    before the change here).
    
    While there also fully eliminate the redundant "sname": There's "name"
    already, getting set up a little earlier.

Diff:
---
 gas/testsuite/gas/i386/equ.s         |  3 ---
 gas/testsuite/gas/i386/inval-equ-2.l |  7 +++++--
 gas/testsuite/gas/i386/inval-equ-2.s |  3 +++
 gas/write.c                          | 18 ++++++++----------
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/gas/testsuite/gas/i386/equ.s b/gas/testsuite/gas/i386/equ.s
index c7c4e604f03..30401ca9c1e 100644
--- a/gas/testsuite/gas/i386/equ.s
+++ b/gas/testsuite/gas/i386/equ.s
@@ -59,6 +59,3 @@ _start:
  .if s == x
  .err
  .endif
-
- .equ r, -3
- .equ s, -3
diff --git a/gas/testsuite/gas/i386/inval-equ-2.l b/gas/testsuite/gas/i386/inval-equ-2.l
index 839bc8d3523..d4c7f171417 100644
--- a/gas/testsuite/gas/i386/inval-equ-2.l
+++ b/gas/testsuite/gas/i386/inval-equ-2.l
@@ -18,10 +18,13 @@ GAS LISTING .*
 [ 	]*6[ 	]+\.globl  bar2
 [ 	]*7[ 	]+\.set    bar3,\(%eax\+1\)
 [ 	]*8[ 	]+\?\?\?\? A1...... 		mov bar3,%eax
+[ 	]*8[ 	]+..
+[ 	]*9[ 	]+\.globl  bar4
+[ 	]*10[ 	]+\.set    bar4,\(%eax\+1\)
+[ 	]*11[ 	]+\?\?\?\? 90       		nop
 .*  Error: invalid .* relocation against register
 .*  Error: invalid .* relocation against register
 .*  Error: invalid .* relocation against register
 .*  Error: can't make global register symbol `bar1'
 .*  Error: can't make global register symbol `bar2'
-.*  Error: can't make global register symbol `bar3'
-[ 	]*8[ 	]+..
+.*  Error: can't make global register symbol `bar4'
diff --git a/gas/testsuite/gas/i386/inval-equ-2.s b/gas/testsuite/gas/i386/inval-equ-2.s
index 90caa25df37..afc13eb86e8 100644
--- a/gas/testsuite/gas/i386/inval-equ-2.s
+++ b/gas/testsuite/gas/i386/inval-equ-2.s
@@ -6,3 +6,6 @@
 	.globl  bar2
 	.set    bar3,(%eax+1)
 	mov bar3,%eax
+	.globl  bar4
+	.set    bar4,(%eax+1)
+	nop
diff --git a/gas/write.c b/gas/write.c
index 9d0777051dd..9bb47857936 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -2396,24 +2396,22 @@ write_object_file (void)
 	  if (symbol_equated_reloc_p (symp)
 	      || S_IS_WEAKREFR (symp))
 	    {
-	      const char *sname = S_GET_NAME (symp);
-
 	      if (S_IS_COMMON (symp)
-		  && !TC_FAKE_LABEL (sname)
+		  && !TC_FAKE_LABEL (name)
 		  && !S_IS_WEAKREFR (symp))
 		{
 		  expressionS *e = symbol_get_value_expression (symp);
 
 		  as_bad (_("`%s' can't be equated to common symbol `%s'"),
-			  sname, S_GET_NAME (e->X_add_symbol));
+			  name, S_GET_NAME (e->X_add_symbol));
 		}
-	      if (S_GET_SEGMENT (symp) == reg_section)
-		{
+
+	      if (S_GET_SEGMENT (symp) == reg_section
+		  && S_IS_EXTERNAL (symp)
 		  /* Report error only if we know the symbol name.  */
-		  if (S_GET_NAME (symp) != reg_section->name)
-		    as_bad (_("can't make global register symbol `%s'"),
-			    sname);
-		}
+		  && name != reg_section->name)
+		as_bad (_("can't make global register symbol `%s'"), name);
+
 	      symbol_remove (symp, &symbol_rootP, &symbol_lastP);
 	      continue;
 	    }


More information about the Binutils-cvs mailing list