[v2,3/3] gas: consolidate . latching

Message ID 19b57e8a-1295-4d7e-ab70-fa8a082868fc@suse.com
State New
Headers
Series gas: dot handling |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich Dec. 19, 2024, 10:09 a.m. UTC
  ... 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.
---
v2: New.
  

Patch

--- 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);
 	}
     }
 
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -1849,10 +1849,7 @@  expr (int rankarg,		/* Larger # is highe
 
   /* 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);
 
--- 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
--- 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
   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;
--- 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);
--- 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
--- a/gas/symbols.h
+++ b/gas/symbols.h
@@ -189,6 +189,7 @@  extern offsetT *symbol_X_add_number (con
 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 *);