[binutils-gdb] gas: consolidate . latching

Jan Beulich jbeulich@sourceware.org
Fri Jan 10 07:45:25 GMT 2025


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

commit 3f4bbf3c060e888299c4cc14eff52059921bed93
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Jan 10 08:43:02 2025 +0100

    gas: consolidate . latching
    
    ... by purging dot_{frag,value}. Right now these two and dot_symbol are
    updated independently, which can't be quite right. Centralize .-related
    information in dot_symbol, updating it also where previously
    dot_{frag,value} were updated. Since S_GET_VALUE() can't be used to
    retrieve what used to be dot_value, introduce a new helper to fetch both
    frag and offset.

Diff:
---
 gas/config/tc-ppc.c | 10 ++++++----
 gas/expr.c          |  5 +----
 gas/read.c          |  3 +--
 gas/symbols.c       | 17 +++++++++++++++++
 gas/symbols.h       |  1 +
 gas/write.c         | 10 ++--------
 gas/write.h         |  2 --
 7 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index d1de57e882c..9c3adb39950 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -4082,12 +4082,14 @@ md_assemble (char *str)
 	 a label attached to the instruction.  By "attached" we mean
 	 on the same source line as the instruction and without any
 	 intervening semicolons.  */
-      dot_value = frag_now_fix ();
-      dot_frag = frag_now;
+      symbol_set_value_now (&dot_symbol);
       for (l = insn_labels; l != NULL; l = l->next)
 	{
-	  symbol_set_frag (l->label, dot_frag);
-	  S_SET_VALUE (l->label, dot_value);
+	  addressT value;
+
+	  symbol_set_frag (l->label,
+			   symbol_get_frag_and_value (&dot_symbol, &value));
+	  S_SET_VALUE (l->label, value);
 	}
     }
 
diff --git a/gas/expr.c b/gas/expr.c
index ccd89253ac1..66513198911 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -1849,10 +1849,7 @@ expr (int rankarg,		/* Larger # is higher rank.  */
 
   /* Save the value of dot for the fixup code.  */
   if (rank == 0)
-    {
-      dot_value = frag_now_fix ();
-      dot_frag = frag_now;
-    }
+    symbol_set_value_now (&dot_symbol);
 
   retval = operand (resultP, mode);
 
diff --git a/gas/read.c b/gas/read.c
index c51536f44f9..03c19ee0824 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -4483,8 +4483,7 @@ emit_expr_with_reloc (expressionS *exp,
     return;
 
   frag_grow (nbytes);
-  dot_value = frag_now_fix ();
-  dot_frag = frag_now;
+  symbol_set_value_now (&dot_symbol);
 
 #ifndef NO_LISTING
 #ifdef OBJ_ELF
diff --git a/gas/symbols.c b/gas/symbols.c
index e6f3d85a75d..37a1e2b8215 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -2814,6 +2814,23 @@ symbol_get_frag (const symbolS *s)
   return s->frag;
 }
 
+/* Return the frag of a symbol and the symbol's offset into that frag.  */
+
+fragS *symbol_get_frag_and_value (const symbolS *s, addressT *value)
+{
+  if (s->flags.local_symbol)
+    {
+      const struct local_symbol *locsym = (const struct local_symbol *) s;
+
+      *value = locsym->value;
+      return locsym->frag;
+    }
+
+  gas_assert (s->x->value.X_op == O_constant);
+  *value = s->x->value.X_add_number;
+  return s->frag;
+}
+
 /* Mark a symbol as having been used.  */
 
 void
diff --git a/gas/symbols.h b/gas/symbols.h
index df6acfffc48..465a1ab17c2 100644
--- a/gas/symbols.h
+++ b/gas/symbols.h
@@ -189,6 +189,7 @@ extern offsetT *symbol_X_add_number (const symbolS *);
 extern void symbol_set_value_now (symbolS *);
 extern void symbol_set_frag (symbolS *, fragS *);
 extern fragS *symbol_get_frag (const symbolS *);
+extern fragS *symbol_get_frag_and_value (const symbolS *, addressT *);
 extern void symbol_mark_used (symbolS *);
 extern void symbol_clear_used (symbolS *);
 extern int symbol_used_p (const symbolS *);
diff --git a/gas/write.c b/gas/write.c
index c52a16947e5..e8231603961 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -110,12 +110,6 @@ int symbol_table_frozen;
 
 symbolS *abs_section_sym;
 
-/* Remember the value of dot when parsing expressions.  */
-addressT dot_value;
-
-/* The frag that dot_value is based from.  */
-fragS *dot_frag;
-
 /* Relocs generated by ".reloc" pseudo.  */
 struct reloc_list* reloc_list;
 
@@ -162,8 +156,8 @@ fix_new_internal (fragS *frag,		/* Which frag?  */
   fixP->fx_addsy = add_symbol;
   fixP->fx_subsy = sub_symbol;
   fixP->fx_offset = offset;
-  fixP->fx_dot_value = dot_value;
-  fixP->fx_dot_frag = dot_frag;
+  fixP->fx_dot_frag = symbol_get_frag_and_value (&dot_symbol,
+						 &fixP->fx_dot_value);
   fixP->fx_pcrel = pcrel;
   fixP->fx_r_type = r_type;
   fixP->fx_pcrel_adjust = 0;
diff --git a/gas/write.h b/gas/write.h
index 3cd82504568..eb6ac642a10 100644
--- a/gas/write.h
+++ b/gas/write.h
@@ -170,8 +170,6 @@ struct reloc_list
 
 extern int finalize_syms;
 extern symbolS *abs_section_sym;
-extern addressT dot_value;
-extern fragS *dot_frag;
 extern struct reloc_list* reloc_list;
 
 extern void append (char **, char *, unsigned long);


More information about the Binutils-cvs mailing list