llvm.org GIT mirror llvm / 13e7624
[MC][ARM] Add range checking for Thumb2 resolved fixups. When the branch target of a Thumb2 unconditional or conditonal branch is resolved at assembly time, no range checking is performed on the result leading to incorrect immediates. This change adds a range check: +- 16 Megabytes for unconditional branches, +- 1 Megabyte for the conditional branch. Differential Revision: https://reviews.llvm.org/D46306 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333997 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Smith 1 year, 11 months ago
2 changed file(s) with 106 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
486486 return 0xffffff & ((Value - 8) >> 2);
487487 case ARM::fixup_t2_uncondbranch: {
488488 Value = Value - 4;
489 if (!isInt<25>(Value)) {
490 Ctx.reportError(Fixup.getLoc(), "Relocation out of range");
491 return 0;
492 }
493
489494 Value >>= 1; // Low bit is not encoded.
490495
491496 uint32_t out = 0;
505510 }
506511 case ARM::fixup_t2_condbranch: {
507512 Value = Value - 4;
513 if (!isInt<21>(Value)) {
514 Ctx.reportError(Fixup.getLoc(), "Relocation out of range");
515 return 0;
516 }
517
508518 Value >>= 1; // Low bit is not encoded.
509519
510520 uint64_t out = 0;
0 @ RUN: not llvm-mc %s -triple thumbv7-linux-gnueabi -filetype=obj -o /dev/null 2>&1 | FileCheck %s
1
2 // Thumb2 unconditional branch has a range of +- 16 Megabytes. The
3 // conditional branch has a range of +- 1 Megabyte. We should give
4 // an error message if we evaluate the expression at assembly
5 // time and it is out of range.
6
7 .syntax unified
8 .thumb
9 b.w end
10 .space 0xfffffe
11 end:
12 b.w end2
13 .space 0xfffffe
14 .global end2
15 end2:
16
17 // branch to arm function uses relocation
18 b.w end3
19 .space 0x1000000
20 .global end3
21 .type end3, %function
22 .arm
23 end3: bx lr
24 .thumb
25
26 // branch to thumb function is resolved at assembly time
27 // CHECK-NOT: error
28 // CHECK: [[@LINE+2]]:{{[0-9]}}: error: Relocation out of range
29 // CHECK-LABEL: b.w end4
30 b.w end4
31 .space 0x1000000
32 .thumb_func
33 end4:
34
35 beq.w end5
36 .space 0xffffc
37 end5:
38
39 // conditional branch to arm function uses relocation
40 beq.w end6
41 .arm
42 .type end6, %function
43 .space 0x100000
44 end6: bx lr
45 .thumb
46
47 // conditional branch to thumb function resolved at assembly time
48 // CHECK-NOT: error
49 // CHECK: [[@LINE+2]]:{{[0-9]}}: error: Relocation out of range
50 // CHECK-LABEL: beq.w end7
51 beq.w end7
52 .space 0x100000
53 end7:
54
55 start:
56 .space 0xfffffc
57 b.w start
58
59 .arm
60 .global start2
61 .type start2, %function
62 start2:
63 .space 0x1000000
64 .thumb
65 // branch to arm function uses relocation
66 b.w start2
67
68 start3:
69 .space 0x1000000
70 // branch to thumb function resolved at assembly time
71 // CHECK-NOT: error
72 // CHECK: [[@LINE+2]]:{{[0-9]}}: error: Relocation out of range
73 // CHECK-LABEL: b.w start3
74 b.w start3
75
76 start4:
77 .space 0xffffc
78 b.w start4
79
80 .arm
81 .global start5
82 .type start5, %function
83 start5:
84 .space 0x100000
85 .thumb
86 // conditional branch to arm function uses relocation
87 beq.w start5
88
89 start6:
90 .space 0x100000
91 // branch to thumb function resolved at assembly time
92 // CHECK-NOT: error
93 // CHECK: [[@LINE+2]]:{{[0-9]}}: error: Relocation out of range
94 // CHECK-LABEL: beq.w start6
95 beq.w start6