Skip to content

Commit 1129678

Browse files
committed
[JITLink] Fixed a signedness bug when processing X86_64_RELOC_SUBTRACTOR.
Subtractor relocation addends are signed, so we need to read them via signed int pointers. Accidentally treating 32-bit addends as unsigned leads to out-of-range errors when we try to add very large (>INT32_MAX) bogus addends. llvm-svn: 360392
1 parent 76ea748 commit 1129678

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ class MachOAtomGraphBuilder_x86_64 : public MachOAtomGraphBuilder {
157157
// Read the current fixup value.
158158
uint64_t FixupValue = 0;
159159
if (SubRI.r_length == 3)
160-
FixupValue = *(const ulittle64_t *)FixupContent;
160+
FixupValue = *(const little64_t *)FixupContent;
161161
else
162-
FixupValue = *(const ulittle32_t *)FixupContent;
162+
FixupValue = *(const little32_t *)FixupContent;
163163

164164
// Find 'ToAtom' using symbol number or address, depending on whether the
165165
// paired UNSIGNED relocation is extern.

llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,32 +180,32 @@ anon_minuend_long1:
180180
# Both forms "A: .quad A - B + C" and "A: .quad B - A + C" are tested.
181181
#
182182
# Check "A: .quad B - A + C".
183-
# jitlink-check: *{8}subtrahend_quad2 = (named_data - subtrahend_quad2 + 2)
183+
# jitlink-check: *{8}subtrahend_quad2 = (named_data - subtrahend_quad2 - 2)
184184
.globl subtrahend_quad2
185185
.p2align 3
186186
subtrahend_quad2:
187-
.quad named_data - subtrahend_quad2 + 2
187+
.quad named_data - subtrahend_quad2 - 2
188188

189189
# Check "A: .long B - A + C".
190-
# jitlink-check: *{4}subtrahend_long2 = (named_data - subtrahend_long2 + 2)[31:0]
190+
# jitlink-check: *{4}subtrahend_long2 = (named_data - subtrahend_long2 - 2)[31:0]
191191
.globl subtrahend_long2
192192
.p2align 2
193193
subtrahend_long2:
194-
.long named_data - subtrahend_long2 + 2
194+
.long named_data - subtrahend_long2 - 2
195195

196196
# Check "A: .quad A - B + C".
197-
# jitlink-check: *{8}minuend_quad3 = (minuend_quad3 - named_data + 2)
197+
# jitlink-check: *{8}minuend_quad3 = (minuend_quad3 - named_data - 2)
198198
.globl minuend_quad3
199199
.p2align 3
200200
minuend_quad3:
201-
.quad minuend_quad3 - named_data + 2
201+
.quad minuend_quad3 - named_data - 2
202202

203203
# Check "A: .long B - A + C".
204-
# jitlink-check: *{4}minuend_long3 = (minuend_long3 - named_data + 2)[31:0]
204+
# jitlink-check: *{4}minuend_long3 = (minuend_long3 - named_data - 2)[31:0]
205205
.globl minuend_long3
206206
.p2align 2
207207
minuend_long3:
208-
.long minuend_long3 - named_data + 2
208+
.long minuend_long3 - named_data - 2
209209

210210
# Check X86_64_RELOC_SUBTRACTOR handling for exprs of the form
211211
# "A: .quad/long B - C + D", where 'B' or 'C' is at a fixed offset from 'A'

0 commit comments

Comments
 (0)