llvm.org GIT mirror llvm / 99deb0b
[RuntimeDyld][MachO] Properly handle thumb to thumb calls within a section. Previously thumb bits were only checked for external relocations (thumb to arm code and vice-versa). This patch adds detection for thumb callees in the same section asthe (also thumb) caller. The MachO/Thumb test case is updated to cover this, and redundant checks (handled by the MachO/ARM test) are removed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331838 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 2 years ago
2 changed file(s) with 64 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
4444 if (Flags.getTargetFlags() & ARMJITSymbolFlags::Thumb)
4545 Addr |= 0x1;
4646 return Addr;
47 }
48
49 bool isAddrTargetThumb(unsigned SectionID, uint64_t Offset) {
50 auto TargetObjAddr = Sections[SectionID].getObjAddress() + Offset;
51 for (auto &KV : GlobalSymbolTable) {
52 auto &Entry = KV.second;
53 auto SymbolObjAddr =
54 Sections[Entry.getSectionID()].getObjAddress() + Entry.getOffset();
55 if (TargetObjAddr == SymbolObjAddr)
56 return (Entry.getFlags().getTargetFlags() & ARMJITSymbolFlags::Thumb);
57 }
58 return false;
4759 }
4860
4961 Expected decodeAddend(const RelocationEntry &RE) const {
160172 // the value as being a thumb stub: we don't want to mix it up with an ARM
161173 // stub targeting the same function.
162174 if (RE.RelType == MachO::ARM_THUMB_RELOC_BR22)
163 Value.IsStubThumb = TargetIsLocalThumbFunc;
175 Value.IsStubThumb = true;
164176
165177 if (RE.IsPCRel)
166178 makeValueAddendPCRel(Value, RelI,
167179 (RE.RelType == MachO::ARM_THUMB_RELOC_BR22) ? 4 : 8);
180
181 // If this is a non-external branch target check whether Value points to a
182 // thumb func.
183 if (!Value.SymbolName && (RelType == MachO::ARM_RELOC_BR24 ||
184 RelType == MachO::ARM_THUMB_RELOC_BR22))
185 RE.IsTargetThumbFunc = isAddrTargetThumb(Value.SectionID, Value.Offset);
168186
169187 if (RE.RelType == MachO::ARM_RELOC_BR24 ||
170188 RE.RelType == MachO::ARM_THUMB_RELOC_BR22)
44 .section __TEXT,__text,regular,pure_instructions
55 .syntax unified
66
7 # Add 'aaa' to the common symbols to make sure 'baz' isn't at the start of the
8 # section. This ensures that we test VANILLA relocation addends correctly.
9 .comm aaa, 4, 2
10 .comm baz, 4, 2
11
12
13 .globl bar
7 .globl thumb_caller_thumb_callee
148 .p2align 1
15 .code 16 @ @bar
16 .thumb_func bar
17
18 bar:
19 # Check lower 16-bits of section difference relocation
20 # rtdyld-check: decode_operand(insn1, 1) = (foo-(nextPC+8))[15:0]
21 insn1:
22 movw r0, :lower16:(foo-(nextPC+8))
23 # Check upper 16-bits of section difference relocation
24 # rtdyld-check: decode_operand(insn2, 2) = (foo-(nextPC+8))[31:16]
25 insn2:
26 movt r0, :upper16:(foo-(nextPC+8))
27 nextPC:
9 .code 16
10 .thumb_func thumb_caller_thumb_callee
11 thumb_caller_thumb_callee:
2812 nop
2913
30 # Check stub generation for external symbols by referencing a common symbol, 'baz'.
31 # Check both the content of the stub, and the reference to the stub.
32 # Stub should contain '0xf000f8df' (ldr.w pc, [pc]), followed by the target.
14 .globl arm_caller_thumb_callee
15 .p2align 1
16 .code 16
17 .thumb_func arm_caller_thumb_callee
18 arm_caller_thumb_callee:
19 nop
20
21 .globl thumb_caller_arm_callee
22 .p2align 1
23 .code 32
24 thumb_caller_arm_callee:
25 nop
26
27 .globl thumb_caller
28 .p2align 1
29 .code 16
30 .thumb_func thumb_caller
31 thumb_caller:
32 nop
33
34 # Check that stubs for thumb callers use thumb code (not arm), and that thumb
35 # callees have the low bit set on their addresses.
3336 #
34 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, baz)) = 0xf000f8df
35 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, baz) + 4) = baz
37 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, thumb_caller_thumb_callee)) = 0xf000f8df
38 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, thumb_caller_thumb_callee) + 4) = (thumb_caller_thumb_callee | 0x1)
39 bl thumb_caller_thumb_callee
40
41 # Check that arm callees do not have the low bit set on their addresses.
3642 #
37 # rtdyld-check: decode_operand(insn3, 0) = stub_addr(MachO_Thumb.o, __text, baz) - (insn3 + 4)
38 insn3:
39 bl baz
43 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, thumb_caller_arm_callee)) = 0xf000f8df
44 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, thumb_caller_arm_callee) + 4) = thumb_caller_arm_callee
45 bl thumb_caller_arm_callee
4046
41 # Check stub generation for internal symbols by referencing 'bar'.
42 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, bar) + 4) = bar & 0xfffffffffffffffe
43 insn4:
44 bl bar
47 .globl arm_caller
48 .p2align 2
49 .code 32
50 arm_caller:
51 nop
4552
46 .section __DATA,__data
47 .align 2
48 foo:
49 .long 0
53 # Check that stubs for arm callers use arm code (not thumb), and that thumb
54 # callees have the low bit set on their addresses.
55 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, arm_caller_thumb_callee)) = 0xe51ff004
56 # rtdyld-check: *{4}(stub_addr(MachO_Thumb.o, __text, arm_caller_thumb_callee) + 4) = (arm_caller_thumb_callee | 0x1)
57 bl arm_caller_thumb_callee
58 nop
5059
5160 .subsections_via_symbols