[PATCH] LoongArch: gas: Try to avoid R_LARCH_ALIGN associate with a symbol

mengqinggang mengqinggang@loongson.cn
Mon Feb 5 09:32:31 GMT 2024


The R_LARCH_ALIGN need to associated with a symbol if .align has the first
and third expressions. If R_LARCH_ALIGN associate with a symbol, the addend can
represent the first and third expression of .align.

For '.align 3', the addend of R_LARCH_ALIGN only need to represent the alignment
and R_LARCH_ALIGN not need to associate with a symbol.
---
 gas/config/tc-loongarch.c                 | 23 +++++++++++++++--------
 gas/testsuite/gas/loongarch/relax_align.d | 16 ++++++++--------
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index 91f5f1d0681..831a463879b 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1746,14 +1746,21 @@ loongarch_frag_align_code (int n, int max)
 
   nops = frag_more (worst_case_bytes);
 
-  s = symbol_find (".Lla-relax-align");
-  if (s == NULL)
-    s = (symbolS *)local_symbol_make (".Lla-relax-align", now_seg,
-				      &zero_address_frag, 0);
-
-  ex.X_add_symbol = s;
-  ex.X_op = O_symbol;
-  ex.X_add_number = (max << 8) | n;
+  if (max)
+    {
+      s = symbol_find (".Lla-relax-align");
+      if (s == NULL)
+	s = (symbolS *)local_symbol_make (".Lla-relax-align", now_seg,
+					  &zero_address_frag, 0);
+      ex.X_add_symbol = s;
+      ex.X_op = O_symbol;
+      ex.X_add_number = (max << 8) | n;
+    }
+  else
+    {
+      ex.X_op = O_constant;
+      ex.X_add_number = worst_case_bytes;
+    }
 
   loongarch_make_nops (nops, worst_case_bytes);
 
diff --git a/gas/testsuite/gas/loongarch/relax_align.d b/gas/testsuite/gas/loongarch/relax_align.d
index 2cc6c86d38a..e86d0d592b6 100644
--- a/gas/testsuite/gas/loongarch/relax_align.d
+++ b/gas/testsuite/gas/loongarch/relax_align.d
@@ -1,4 +1,4 @@
-#as: --no-warn
+#as:
 #objdump: -dr
 #skip: loongarch32-*-*
 
@@ -14,20 +14,20 @@ Disassembly of section .text:
 [ 	]+4:[ 	]+02c00084[ 	]+addi.d[ 	]+\$a0, \$a0, 0
 [ 	]+4: R_LARCH_PCALA_LO12[ 	]+L1
 [ 	]+4: R_LARCH_RELAX[ 	]+\*ABS\*
-[ 	]+8:[ 	]+03400000[ 	]+nop.*
-[ 	]+8: R_LARCH_ALIGN[ 	]+.Lla-relax-align\+0x4
-[ 	]+c:[ 	]+03400000[ 	]+nop.*
-[ 	]+10:[ 	]+03400000[ 	]+nop.*
+[ 	]+8:[ 	]+03400000[ 	]+nop
+[ 	]+8: R_LARCH_ALIGN[ 	]+\*ABS\*\+0xc
+[ 	]+c:[ 	]+03400000[ 	]+nop
+[ 	]+10:[ 	]+03400000[ 	]+nop
 [ 	]+14:[ 	]+1a000004[ 	]+pcalau12i[ 	]+\$a0, 0
 [ 	]+14: R_LARCH_PCALA_HI20[ 	]+L1
 [ 	]+14: R_LARCH_RELAX[ 	]+\*ABS\*
 [ 	]+18:[ 	]+02c00084[ 	]+addi.d[ 	]+\$a0, \$a0, 0
 [ 	]+18: R_LARCH_PCALA_LO12[ 	]+L1
 [ 	]+18: R_LARCH_RELAX[ 	]+\*ABS\*
-[ 	]+1c:[ 	]+03400000[ 	]+nop.*
+[ 	]+1c:[ 	]+03400000[ 	]+nop
 [ 	]+1c: R_LARCH_ALIGN[ 	]+.Lla-relax-align\+0x404
-[ 	]+20:[ 	]+03400000[ 	]+nop.*
-[ 	]+24:[ 	]+03400000[ 	]+nop.*
+[ 	]+20:[ 	]+03400000[ 	]+nop
+[ 	]+24:[ 	]+03400000[ 	]+nop
 [ 	]+28:[ 	]+1a000004[ 	]+pcalau12i[ 	]+\$a0, 0
 [ 	]+28: R_LARCH_PCALA_HI20[ 	]+L1
 [ 	]+28: R_LARCH_RELAX[ 	]+\*ABS\*
-- 
2.36.0



More information about the Binutils mailing list