[1/2] gas: make fix_new_exp()'s "exp" parameter const

Message ID 79fa6785-c0b9-44af-8dde-dfd9360da449@suse.com
State New
Headers
Series x86/gas: far direct branch plus fix_new_exp() simplification |

Checks

Context Check Description
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_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich Oct. 14, 2024, 6:38 a.m. UTC
  This really should be only an input; in particular it looks bogus that
O_add expressions are even altered. That altering and the recursion are
even pointless: Once expanding what the inner call would do (with
O_symbol) it becomes clear that this is no different than the default
case. Simplify the code accordingly, retaining the comment.
---
Question of course is whether any caller has grown a dependency on O_add
expressions being converted to O_symbol ones. Pretty wide testing
suggests no.

The simplification really ought to have happened when 00a69b895a5f
replaced the as_bad() in the default case, post-dating 4acf8c78e659
which introduced the special O_add handling.
  

Patch

--- a/gas/write.c
+++ b/gas/write.c
@@ -238,7 +238,7 @@  fixS *
 fix_new_exp (fragS *frag,		/* Which frag?  */
 	     unsigned long where,	/* Where in that frag?  */
 	     unsigned long size,	/* 1, 2, or 4 usually.  */
-	     expressionS *exp,		/* Expression.  */
+	     const expressionS *exp,	/* Expression.  */
 	     int pcrel,			/* TRUE if PC-relative relocation.  */
 	     RELOC_ENUM r_type		/* Relocation type.  */)
 {
@@ -255,20 +255,6 @@  fix_new_exp (fragS *frag,		/* Which frag
       as_bad (_("register value used as expression"));
       break;
 
-    case O_add:
-      /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
-	 the difference expression cannot immediately be reduced.  */
-      {
-	symbolS *stmp = make_expr_symbol (exp);
-
-	exp->X_op = O_symbol;
-	exp->X_op_symbol = 0;
-	exp->X_add_symbol = stmp;
-	exp->X_add_number = 0;
-
-	return fix_new_exp (frag, where, size, exp, pcrel, r_type);
-      }
-
     case O_symbol_rva:
       add = exp->X_add_symbol;
       off = exp->X_add_number;
@@ -290,6 +276,8 @@  fix_new_exp (fragS *frag,		/* Which frag
       off = exp->X_add_number;
       break;
 
+    case O_add: /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
+		   the difference expression cannot immediately be reduced.  */
     default:
       add = make_expr_symbol (exp);
       break;
--- a/gas/write.h
+++ b/gas/write.h
@@ -188,7 +188,7 @@  extern fixS *fix_new (fragS *, unsigned
 extern fixS *fix_at_start (fragS *, unsigned long, symbolS *,
 			   offsetT, int, bfd_reloc_code_real_type);
 extern fixS *fix_new_exp (fragS *, unsigned long, unsigned long,
-			  expressionS *, int, bfd_reloc_code_real_type);
+			  const expressionS *, int, bfd_reloc_code_real_type);
 extern void write_print_statistics (FILE *);
 extern void as_bad_subtract (fixS *);