llvm.org GIT mirror llvm / be2c0a2
[RISCV][MC] Find matching pcrel_hi fixup in more cases. If a symbol points to the end of a fragment, instead of searching for fixups in that fragment, search in the next fragment. Fixes spurious assembler error with subtarget change next to "la" pseudo-instruction, or expanded equivalent. Alternate proposal to fix the problem discussed in https://reviews.llvm.org/D58759. Testcase by Ana Pazos. Differential Revision: https://reviews.llvm.org/D58943 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355946 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Friedman 1 year, 8 months ago
2 changed file(s) with 63 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
4848 if (!AUIPCSRE)
4949 return nullptr;
5050
51 const auto *DF =
52 dyn_cast_or_null(AUIPCSRE->findAssociatedFragment());
51 const MCSymbol *AUIPCSymbol = &AUIPCSRE->getSymbol();
52 const auto *DF = dyn_cast_or_null(AUIPCSymbol->getFragment());
53
5354 if (!DF)
5455 return nullptr;
5556
56 const MCSymbol *AUIPCSymbol = &AUIPCSRE->getSymbol();
57 uint64_t Offset = AUIPCSymbol->getOffset();
58 if (DF->getContents().size() == Offset) {
59 DF = dyn_cast_or_null(DF->getNextNode());
60 if (!DF)
61 return nullptr;
62 Offset = 0;
63 }
64
5765 for (const MCFixup &F : DF->getFixups()) {
58 if (F.getOffset() != AUIPCSymbol->getOffset())
66 if (F.getOffset() != Offset)
5967 continue;
6068
6169 switch ((unsigned)F.getKind()) {
0 # RUN: llvm-mc %s -triple=riscv32 | FileCheck -check-prefix=ASM %s
1 # RUN: llvm-mc %s -triple=riscv64 | FileCheck -check-prefix=ASM %s
2 # RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
3 # RUN: | llvm-objdump -d -riscv-no-aliases - | FileCheck -check-prefix=DISASM %s
4 # RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
5 # RUN: | llvm-objdump -d -riscv-no-aliases - | FileCheck -check-prefix=DISASM %s
6
7 # Checks change of options does not cause error: could not find corresponding %pcrel_hi
8 # when assembling pseudoinstruction and its extended form.
9
10 .option push
11 .option norelax
12 la a0, a_symbol
13 .option pop
14 la a1, another_symbol
15
16 # ASM: .Lpcrel_hi0:
17 # ASM: auipc a0, %pcrel_hi(a_symbol)
18 # ASM: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
19 # ASM: .Lpcrel_hi1:
20 # ASM: auipc a1, %pcrel_hi(another_symbol)
21 # ASM: addi a1, a1, %pcrel_lo(.Lpcrel_hi1)
22
23 # DISASM: .Lpcrel_hi0:
24 # DISASM: auipc a0, 0
25 # DISASM: addi a0, a0, 0
26 # DISASM:.Lpcrel_hi1:
27 # DISASM: auipc a1, 0
28 # DISASM: addi a1, a1, 0
29
30 .option push
31 .option norelax
32 1:auipc a0, %pcrel_hi(a_symbol)
33 addi a0, a0, %pcrel_lo(1b)
34 .option pop
35 2:auipc a1, %pcrel_hi(another_symbol)
36 addi a1, a1, %pcrel_lo(2b)
37
38 # ASM: .Ltmp0:
39 # ASM: auipc a0, %pcrel_hi(a_symbol)
40 # ASM: addi a0, a0, %pcrel_lo(.Ltmp0)
41 # ASM: .Ltmp1:
42 # ASM: auipc a1, %pcrel_hi(another_symbol)
43 # ASM: addi a1, a1, %pcrel_lo(.Ltmp1)
44
45 # DISASM: .Ltmp0:
46 # DISASM: auipc a0, 0
47 # DISASM: addi a0, a0, 0
48 # DISASM: .Ltmp1:
49 # DISASM: auipc a1, 0
50 # DISASM: addi a1, a1, 0