diff options
author | mengqinggang <mengqinggang@loongson.cn> | 2024-02-05 16:16:52 +0800 |
---|---|---|
committer | liuzhensong <liuzhensong@loongson.cn> | 2024-02-23 15:40:34 +0800 |
commit | c429c4459865284a0059cbabdde0449eb7df0774 (patch) | |
tree | 906de2ed770ca3d5ca7a2189dd44127302ac52ff /gas | |
parent | 97f2a34ed1d255ea301f858b31c0fbe75da1c4f6 (diff) | |
download | gdb-c429c4459865284a0059cbabdde0449eb7df0774.zip gdb-c429c4459865284a0059cbabdde0449eb7df0774.tar.gz gdb-c429c4459865284a0059cbabdde0449eb7df0774.tar.bz2 |
LoongArch: gas: Try to avoid R_LARCH_ALIGN associate with a symbol
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.
Diffstat (limited to 'gas')
-rw-r--r-- | gas/config/tc-loongarch.c | 27 | ||||
-rw-r--r-- | gas/testsuite/gas/loongarch/relax_align.d | 64 | ||||
-rw-r--r-- | gas/testsuite/gas/loongarch/relax_align.s | 20 |
3 files changed, 72 insertions, 39 deletions
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 91f5f1d..de92366 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -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); diff --git a/gas/testsuite/gas/loongarch/relax_align.d b/gas/testsuite/gas/loongarch/relax_align.d index 2cc6c86..fc1fd03 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-*-* @@ -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 diff --git a/gas/testsuite/gas/loongarch/relax_align.s b/gas/testsuite/gas/loongarch/relax_align.s index c0177c8..4f4867f 100644 --- a/gas/testsuite/gas/loongarch/relax_align.s +++ b/gas/testsuite/gas/loongarch/relax_align.s @@ -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 |