llvm.org GIT mirror llvm / 8af3f96
ARM: do not relax Thumb1 -> Thumb2 if only Thumb1 is available. After recognising that a certain narrow instruction might need a relocation to be represented, we used to unconditionally relax it to a Thumb2 instruction to permit this. Unfortunately, some CPUs (e.g. v6m) don't even have most Thumb2 instructions, so we end up emitting a completely invalid instruction. Theoretically, ELF does have relocations for these situations; but they are fairly unusable with such short ranges and the ABI document even says they're documented "for completeness". So an error is probably better there too. rdar://20391953 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234195 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 5 years ago
8 changed file(s) with 65 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
152152 }
153153 } // end anonymous namespace
154154
155 static unsigned getRelaxedOpcode(unsigned Op) {
155 unsigned ARMAsmBackend::getRelaxedOpcode(unsigned Op) const {
156 bool HasThumb2 = STI->getFeatureBits() & ARM::FeatureThumb2;
157
156158 switch (Op) {
157159 default:
158160 return Op;
159161 case ARM::tBcc:
160 return ARM::t2Bcc;
162 return HasThumb2 ? ARM::t2Bcc : Op;
161163 case ARM::tLDRpci:
162 return ARM::t2LDRpci;
164 return HasThumb2 ? ARM::t2LDRpci : Op;
163165 case ARM::tADR:
164 return ARM::t2ADR;
166 return HasThumb2 ? ARM::t2ADR : Op;
165167 case ARM::tB:
166 return ARM::t2B;
168 return HasThumb2 ? ARM::t2B : Op;
167169 case ARM::tCBZ:
168170 return ARM::tHINT;
169171 case ARM::tCBNZ:
4646 void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
4747 uint64_t Value, bool IsPCRel) const override;
4848
49 unsigned getRelaxedOpcode(unsigned Op) const;
50
4951 bool mayNeedRelaxation(const MCInst &Inst) const override;
5052
5153 bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
8080 unsigned Type = 0;
8181 if (IsPCRel) {
8282 switch ((unsigned)Fixup.getKind()) {
83 default: llvm_unreachable("Unimplemented");
83 default:
84 report_fatal_error("unsupported relocation on symbol");
85 return ELF::R_ARM_NONE;
8486 case FK_Data_4:
8587 switch (Modifier) {
8688 default: llvm_unreachable("Unsupported Modifier");
146148 }
147149 } else {
148150 switch ((unsigned)Fixup.getKind()) {
149 default: llvm_unreachable("invalid fixup kind!");
151 default:
152 report_fatal_error("unsupported relocation on symbol");
153 return ELF::R_ARM_NONE;
150154 case FK_Data_1:
151155 switch (Modifier) {
152156 default: llvm_unreachable("unsupported Modifier");
8787 case ARM::fixup_arm_ldst_pcrel_12:
8888 case ARM::fixup_arm_pcrel_10:
8989 case ARM::fixup_arm_adr_pcrel_12:
90 case ARM::fixup_arm_thumb_br:
9091 return false;
9192
9293 // Handle 24-bit branch kinds.
9899 RelocType = unsigned(MachO::ARM_RELOC_BR24);
99100 // Report as 'long', even though that is not quite accurate.
100101 Log2Size = llvm::Log2_32(4);
101 return true;
102
103 // Handle Thumb branches.
104 case ARM::fixup_arm_thumb_br:
105 RelocType = unsigned(MachO::ARM_THUMB_RELOC_BR22);
106 Log2Size = llvm::Log2_32(2);
107102 return true;
108103
109104 case ARM::fixup_t2_uncondbranch:
0 @ RUN: not llvm-mc -triple thumbv6m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
1 @ RUN: not llvm-mc -triple thumbv7m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
2 @ RUN: not llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
3
4 .global func1
5 _func1:
6 adr r0, _func2
7 @ CHECK-ERROR: unsupported relocation on symbol
8
0 @ RUN: not llvm-mc -triple thumbv6m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
1 @ RUN: not llvm-mc -triple thumbv7m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
2 @ RUN: llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o %t %s
3 @ RUN: llvm-objdump -d -r -triple thumbv7m-none-eabi %t | FileCheck --check-prefix=CHECK-ELF %s
4
5 .global func1
6 _func1:
7 bne _func2
8 @ CHECK-ERROR: unsupported relocation on symbol
9
10 @ CHECK-ELF: 7f f4 fe af bne.w #-4
11 @ CHECK-ELF-NEXT: R_ARM_THM_JUMP24 _func2
0 @ RUN: not llvm-mc -triple thumbv6m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
1 @ RUN: llvm-mc -triple thumbv7m-none-macho -filetype=obj -o %t %s
2 @ RUN: llvm-objdump -d -r -triple thumbv7m-none-macho %t | FileCheck --check-prefix=CHECK-MACHO %s
3 @ RUN: llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o %t %s
4 @ RUN: llvm-objdump -d -r -triple thumbv7m-none-eabi %t | FileCheck --check-prefix=CHECK-ELF %s
5
6 .global func1
7 _func1:
8 @ There is no MachO relocation for Thumb1's unconditional branch, so
9 @ this is unrepresentable. FIXME: I think ELF could represent this.
10 b _func2
11
12 @ CHECK-ERROR: unsupported relocation on symbol
13
14 @ CHECK-MACHO: ff f7 fe bf b.w #-4
15 @ CHECK-MACHO-NEXT: ARM_THUMB_RELOC_BR22
16
17 @ CHECK-ELF: ff f7 fe bf b.w #-4
18 @ CHECK-ELF-NEXT: R_ARM_THM_JUMP24 _func2
0 @ RUN: not llvm-mc -triple thumbv6m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
1 @ RUN: not llvm-mc -triple thumbv7m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
2 @ RUN: not llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
3
4 .global func1
5 _func1:
6 ldr r0, _func2
7 @ CHECK-ERROR: unsupported relocation on symbol
8