]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: gas: Try to avoid R_LARCH_ALIGN associate with a symbol
authormengqinggang <mengqinggang@loongson.cn>
Mon, 5 Feb 2024 08:16:52 +0000 (16:16 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Fri, 23 Feb 2024 07:40:34 +0000 (15:40 +0800)
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.

For '.align x, , y', R_LARCH_ALIGN need to associate with a symbol if 0 < y <
2^x - 4.

gas/config/tc-loongarch.c
gas/testsuite/gas/loongarch/relax_align.d
gas/testsuite/gas/loongarch/relax_align.s

index 91f5f1d068139deec931d50aac3e2e8212be2d6f..de92366eda4d6f4398778910ca1b2cf30bb27dfc 100644 (file)
@@ -1746,14 +1746,25 @@ 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 <= 0, ignore max.
+     If max >= worst_case_bytes, max has no effect.
+     Similar to gas/write.c relax_segment function rs_align_code case:
+     if (fragP->fr_subtype != 0 && offset > fragP->fr_subtype).  */
+  if (max > 0 && (bfd_vma) max < 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;
+    }
+  else
+    {
+      ex.X_op = O_constant;
+      ex.X_add_number = worst_case_bytes;
+    }
 
   loongarch_make_nops (nops, worst_case_bytes);
 
index 2cc6c86d38aad9736451be8a4a7763357f631ef3..fc1fd032611503122db18c0e166118e94d5dd1fd 100644 (file)
@@ -1,4 +1,4 @@
-#as: --no-warn
+#as:
 #objdump: -dr
 #skip: loongarch32-*-*
 
@@ -8,29 +8,39 @@
 Disassembly of section .text:
 
 [      ]*0000000000000000 <.Lla-relax-align>:
-[      ]+0:[   ]+1a000004[     ]+pcalau12i[    ]+\$a0, 0
-[      ]+0: R_LARCH_PCALA_HI20[        ]+L1
-[      ]+0: R_LARCH_RELAX[     ]+\*ABS\*
-[      ]+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.*
-[      ]+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: R_LARCH_ALIGN[    ]+.Lla-relax-align\+0x404
-[      ]+20:[  ]+03400000[     ]+nop.*
-[      ]+24:[  ]+03400000[     ]+nop.*
-[      ]+28:[  ]+1a000004[     ]+pcalau12i[    ]+\$a0, 0
-[      ]+28: R_LARCH_PCALA_HI20[       ]+L1
-[      ]+28: R_LARCH_RELAX[    ]+\*ABS\*
-[      ]+2c:[  ]+02c00084[     ]+addi.d[       ]+\$a0, \$a0, 0
-[      ]+2c: R_LARCH_PCALA_LO12[       ]+L1
-[      ]+2c: R_LARCH_RELAX[    ]+\*ABS\*
+[      ]+0:[   ]+4c000020[     ]+ret
+[      ]+4:[   ]+03400000[     ]+nop
+[      ]+4: R_LARCH_ALIGN[     ]+\*ABS\*\+0xc
+[      ]+8:[   ]+03400000[     ]+nop
+[      ]+c:[   ]+03400000[     ]+nop
+[      ]+10:[  ]+4c000020[     ]+ret
+[      ]+14:[  ]+03400000[     ]+nop
+[      ]+14: R_LARCH_ALIGN[    ]+\*ABS\*\+0xc
+[      ]+18:[  ]+03400000[     ]+nop
+[      ]+1c:[  ]+03400000[     ]+nop
+[      ]+20:[  ]+4c000020[     ]+ret
+[      ]+24:[  ]+03400000[     ]+nop
+[      ]+24: R_LARCH_ALIGN[    ]+.Lla-relax-align\+0x104
+[      ]+28:[  ]+03400000[     ]+nop
+[      ]+2c:[  ]+03400000[     ]+nop
+[      ]+30:[  ]+4c000020[     ]+ret
+[      ]+34:[  ]+03400000[     ]+nop
+[      ]+34: R_LARCH_ALIGN[    ]+.Lla-relax-align\+0xb04
+[      ]+38:[  ]+03400000[     ]+nop
+[      ]+3c:[  ]+03400000[     ]+nop
+[      ]+40:[  ]+4c000020[     ]+ret
+[      ]+44:[  ]+03400000[     ]+nop
+[      ]+44: R_LARCH_ALIGN[    ]+\*ABS\*\+0xc
+[      ]+48:[  ]+03400000[     ]+nop
+[      ]+4c:[  ]+03400000[     ]+nop
+[      ]+50:[  ]+4c000020[     ]+ret
+[      ]+54:[  ]+03400000[     ]+nop
+[      ]+54: R_LARCH_ALIGN[    ]+\*ABS\*\+0xc
+[      ]+58:[  ]+03400000[     ]+nop
+[      ]+5c:[  ]+03400000[     ]+nop
+[      ]+60:[  ]+4c000020[     ]+ret
+[      ]+64:[  ]+03400000[     ]+nop
+[      ]+64: R_LARCH_ALIGN[    ]+\*ABS\*\+0xc
+[      ]+68:[  ]+03400000[     ]+nop
+[      ]+6c:[  ]+03400000[     ]+nop
+[      ]+70:[  ]+4c000020[     ]+ret
index c0177c88fc10521f1c4d5abff5d5c1b856aa0fa6..4f4867fb209c7411a378ba81863988337eb00196 100644 (file)
@@ -1,7 +1,19 @@
+# If max < -0x80000000, max becomes a positive number because type conversion
+# (bfd_signed_vma -> unsigned int).
   .text
 .L1:
-  la.local $a0, L1
+  ret
   .align 4
-  la.local $a0, L1
-  .align 4, , 4
-  la.local $a0, L1
+  ret
+  .align 4, , 0
+  ret
+  .align 4, , 1
+  ret
+  .align 4, , 11
+  ret
+  .align 4, , 12
+  ret
+  .align 4, , -1
+  ret
+  .align 4, , -0x80000000
+  ret