Skip to content

Commit 924d511

Browse files
committed
Fixes for reviews.
1 parent 30cb382 commit 924d511

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

lld/ELF/Arch/LoongArch.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -790,23 +790,23 @@ static void relaxPCHi20Lo12(Ctx &ctx, const InputSection &sec, size_t i,
790790
(ctx.arg.isPic && !cast<Defined>(*rHi20.sym).section)))
791791
return;
792792

793-
uint64_t symBase = 0;
793+
uint64_t dest = 0;
794794
if (rHi20.expr == RE_LOONGARCH_PLT_PAGE_PC)
795-
symBase = rHi20.sym->getPltVA(ctx);
795+
dest = rHi20.sym->getPltVA(ctx);
796796
else if (rHi20.expr == RE_LOONGARCH_PAGE_PC ||
797797
rHi20.expr == RE_LOONGARCH_GOT_PAGE_PC)
798-
symBase = rHi20.sym->getVA(ctx);
798+
dest = rHi20.sym->getVA(ctx);
799799
else {
800800
Err(ctx) << getErrorLoc(ctx, (const uint8_t *)loc) << "unknown expr ("
801801
<< rHi20.expr << ") against symbol " << rHi20.sym
802802
<< "in relaxPCHi20Lo12";
803803
return;
804804
}
805-
const uint64_t symLocal = symBase + rHi20.addend;
805+
dest += rHi20.addend;
806806

807-
const int64_t distance = symLocal - loc;
808-
// Check if the distance aligns 4 bytes or exceeds the range of pcaddi.
809-
if ((distance & 0x3) != 0 || !isInt<22>(distance))
807+
const int64_t displace = dest - loc;
808+
// Check if the displace aligns 4 bytes or exceeds the range of pcaddi.
809+
if ((displace & 0x3) != 0 || !isInt<22>(displace))
810810
return;
811811

812812
// Note: If we can ensure that the .o files generated by LLVM only contain

lld/test/ELF/loongarch-relax-align.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# RUN: llvm-mc --filetype=obj --triple=loongarch32 --mattr=+relax %s -o %t.32.o
44
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.64.o
5-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 --relax %t.32.o -o %t.32
6-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 --relax %t.64.o -o %t.64
5+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.32.o -o %t.32
6+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o -o %t.64
77
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 --no-relax %t.32.o -o %t.32n
88
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 --no-relax %t.64.o -o %t.64n
99
# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck --check-prefixes=RELAX,NOOLD %s
@@ -13,13 +13,13 @@
1313

1414
## Test the R_LARCH_ALIGN without symbol index.
1515
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.o64.o --defsym=old=1
16-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 --relax %t.o64.o -o %t.o64
16+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o -o %t.o64
1717
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 --no-relax %t.o64.o -o %t.o64n
1818
# RUN: llvm-objdump -td --no-show-raw-insn %t.o64 | FileCheck --check-prefixes=RELAX,OLD %s
1919
# RUN: llvm-objdump -td --no-show-raw-insn %t.o64n | FileCheck --check-prefixes=NORELAX,OLD %s
2020

2121
## -r keeps section contents unchanged.
22-
# RUN: ld.lld -r --relax %t.64.o -o %t.64.r
22+
# RUN: ld.lld -r %t.64.o -o %t.64.r
2323
# RUN: llvm-objdump -dr --no-show-raw-insn %t.64.r | FileCheck %s --check-prefix=CHECKR
2424

2525
# NOOLD: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol

lld/test/ELF/loongarch-relax-emit-relocs.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
# RUN: llvm-mc --filetype=obj --triple=loongarch32 --mattr=+relax %s -o %t.32.o
55
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.64.o
6-
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs --relax %t.32.o -o %t.32
7-
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs --relax %t.64.o -o %t.64
6+
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs %t.32.o -o %t.32
7+
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs %t.64.o -o %t.64
88
# RUN: llvm-objdump -dr %t.32 | FileCheck %s --check-prefix=RELAX
99
# RUN: llvm-objdump -dr %t.64 | FileCheck %s --check-prefix=RELAX
1010

1111
## -r should keep original relocations.
12-
# RUN: ld.lld --relax -r %t.64.o -o %t.64.r
12+
# RUN: ld.lld -r %t.64.o -o %t.64.r
1313
# RUN: llvm-objdump -dr %t.64.r | FileCheck %s --check-prefix=CHECKR
1414

1515
## --no-relax should keep original relocations.

lld/test/ELF/loongarch-relax-pc-hi20-lo12-got-symbols.s

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,45 @@
99
# RUN: llvm-mc --filetype=obj --triple=loongarch32 -mattr=+relax abs.s -o abs.32.o
1010
# RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax abs.s -o abs.64.o
1111

12-
# RUN: ld.lld --shared --relax -Tlinker.t symbols.32.o abs.32.o -o symbols.32.so
13-
# RUN: ld.lld --shared --relax -Tlinker.t symbols.64.o abs.64.o -o symbols.64.so
12+
# RUN: ld.lld --shared -Tlinker.t symbols.32.o abs.32.o -o symbols.32.so
13+
# RUN: ld.lld --shared -Tlinker.t symbols.64.o abs.64.o -o symbols.64.so
1414
# RUN: llvm-objdump -d --no-show-raw-insn symbols.32.so | FileCheck --check-prefixes=LIB %s
1515
# RUN: llvm-objdump -d --no-show-raw-insn symbols.64.so | FileCheck --check-prefixes=LIB %s
1616

17-
# RUN: ld.lld --relax -Tlinker.t -z undefs symbols.32.o abs.32.o -o symbols.32
18-
# RUN: ld.lld --relax -Tlinker.t -z undefs symbols.64.o abs.64.o -o symbols.64
17+
# RUN: ld.lld -Tlinker.t -z undefs symbols.32.o abs.32.o -o symbols.32
18+
# RUN: ld.lld -Tlinker.t -z undefs symbols.64.o abs.64.o -o symbols.64
1919
# RUN: llvm-objdump -d --no-show-raw-insn symbols.32 | FileCheck --check-prefixes=EXE %s
2020
# RUN: llvm-objdump -d --no-show-raw-insn symbols.64 | FileCheck --check-prefixes=EXE %s
2121

2222

2323
## Symbol 'hidden_sym' is nonpreemptible, the relaxation should be applied.
24-
LIB: pcaddi $a0, {{[0-9]+}}
24+
LIB: pcaddi $a0, [[#]]
2525
## Symbol 'global_sym' is preemptible, no relaxations should be applied.
2626
LIB-NEXT: pcalau12i $a1, 4
27-
LIB-NEXT: ld.{{[wd]}} $a1, $a1, {{[0-9]+}}
27+
LIB-NEXT: ld.{{[wd]}} $a1, $a1, [[#]]
2828
## Symbol 'undefined_sym' is undefined, no relaxations should be applied.
2929
LIB-NEXT: pcalau12i $a2, 4
30-
LIB-NEXT: ld.{{[wd]}} $a2, $a2, {{[0-9]+}}
30+
LIB-NEXT: ld.{{[wd]}} $a2, $a2, [[#]]
3131
## Symbol 'ifunc_sym' is STT_GNU_IFUNC, no relaxations should be applied.
3232
LIB-NEXT: pcalau12i $a3, 4
33-
LIB-NEXT: ld.{{[wd]}} $a3, $a3, {{[0-9]+}}
33+
LIB-NEXT: ld.{{[wd]}} $a3, $a3, [[#]]
3434
## Symbol 'abs_sym' is absolute, no relaxations should be applied.
3535
LIB-NEXT: pcalau12i $a4, 4
36-
LIB-NEXT: ld.{{[wd]}} $a4, $a4, {{[0-9]+}}
36+
LIB-NEXT: ld.{{[wd]}} $a4, $a4, [[#]]
3737

3838

3939
## Symbol 'hidden_sym' is nonpreemptible, the relaxation should be applied.
40-
EXE: pcaddi $a0, {{[0-9]+}}
40+
EXE: pcaddi $a0, [[#]]
4141
## Symbol 'global_sym' is nonpreemptible, the relaxation should be applied.
42-
EXE-NEXT: pcaddi $a1, {{[0-9]+}}
42+
EXE-NEXT: pcaddi $a1, [[#]]
4343
## Symbol 'undefined_sym' is undefined, no relaxations should be applied.
4444
EXE-NEXT: pcalau12i $a2, 4
45-
EXE-NEXT: ld.{{[wd]}} $a2, $a2, {{[0-9]+}}
45+
EXE-NEXT: ld.{{[wd]}} $a2, $a2, [[#]]
4646
## Symbol 'ifunc_sym' is STT_GNU_IFUNC, no relaxations should be applied.
4747
EXE-NEXT: pcalau12i $a3, 4
48-
EXE-NEXT: ld.{{[wd]}} $a3, $a3, {{[0-9]+}}
48+
EXE-NEXT: ld.{{[wd]}} $a3, $a3, [[#]]
4949
## Symbol 'abs_sym' is absolute, relaxations may be applied in -no-pie mode.
50-
EXE-NEXT: pcaddi $a4, -{{[0-9]+}}
50+
EXE-NEXT: pcaddi $a4, -[[#]]
5151

5252

5353
## The linker script ensures that .rodata and .text are near (>4M) so that

lld/test/ELF/loongarch-relax-pc-hi20-lo12.s

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
# RUN: llvm-mc --filetype=obj --triple=loongarch32 -mattr=+relax %s -o %t.32.o
44
# RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax %s -o %t.64.o
55

6-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 --relax %t.32.o -o %t.32
7-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 --relax %t.64.o -o %t.64
6+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 %t.32.o -o %t.32
7+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 %t.64.o -o %t.64
88
# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck --check-prefixes=RELAX %s
99
# RUN: llvm-objdump -td --no-show-raw-insn %t.64 | FileCheck --check-prefixes=RELAX %s
1010

11-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 --relax %t.32.o -shared -o %t.32s
12-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 --relax %t.64.o -shared -o %t.64s
11+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 %t.32.o -shared -o %t.32s
12+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x14000 %t.64.o -shared -o %t.64s
1313
# RUN: llvm-objdump -td --no-show-raw-insn %t.32s | FileCheck --check-prefixes=RELAX %s
1414
# RUN: llvm-objdump -td --no-show-raw-insn %t.64s | FileCheck --check-prefixes=RELAX %s
1515

16-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x410000 --relax %t.32.o -o %t.32o
17-
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x410000 --relax %t.64.o -o %t.64o
16+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x410000 %t.32.o -o %t.32o
17+
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.data=0x410000 %t.64.o -o %t.64o
1818
# RUN: llvm-objdump -td --no-show-raw-insn %t.32o | FileCheck --check-prefixes=NORELAX32 %s
1919
# RUN: llvm-objdump -td --no-show-raw-insn %t.64o | FileCheck --check-prefixes=NORELAX64 %s
2020

0 commit comments

Comments
 (0)