forked from OSchip/llvm-project
[JITLink] Make sure MachO/x86-64 handles 32-bit signed addends correctly.
These need to be sign extended when loading into Edge addends.
This commit is contained in:
parent
825debe847
commit
c33598d5e5
|
@ -252,7 +252,7 @@ private:
|
|||
TargetSymbol = TargetSymbolOrErr->GraphSymbol;
|
||||
else
|
||||
return TargetSymbolOrErr.takeError();
|
||||
Addend = *(const ulittle32_t *)FixupContent;
|
||||
Addend = *(const little32_t *)FixupContent;
|
||||
break;
|
||||
case Pointer32:
|
||||
if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
|
||||
|
@ -284,12 +284,12 @@ private:
|
|||
TargetSymbol = TargetSymbolOrErr->GraphSymbol;
|
||||
else
|
||||
return TargetSymbolOrErr.takeError();
|
||||
Addend = *(const ulittle32_t *)FixupContent +
|
||||
Addend = *(const little32_t *)FixupContent +
|
||||
(1 << (*Kind - PCRel32Minus1));
|
||||
break;
|
||||
case PCRel32Anon: {
|
||||
JITTargetAddress TargetAddress =
|
||||
FixupAddress + 4 + *(const ulittle32_t *)FixupContent;
|
||||
FixupAddress + 4 + *(const little32_t *)FixupContent;
|
||||
if (auto TargetSymbolOrErr = findSymbolByAddress(TargetAddress))
|
||||
TargetSymbol = &*TargetSymbolOrErr;
|
||||
else
|
||||
|
@ -303,7 +303,7 @@ private:
|
|||
JITTargetAddress Delta =
|
||||
static_cast<JITTargetAddress>(1ULL << (*Kind - PCRel32Minus1Anon));
|
||||
JITTargetAddress TargetAddress =
|
||||
FixupAddress + 4 + Delta + *(const ulittle32_t *)FixupContent;
|
||||
FixupAddress + 4 + Delta + *(const little32_t *)FixupContent;
|
||||
if (auto TargetSymbolOrErr = findSymbolByAddress(TargetAddress))
|
||||
TargetSymbol = &*TargetSymbolOrErr;
|
||||
else
|
||||
|
|
|
@ -40,6 +40,17 @@ test_gotld:
|
|||
movq external_data@GOTPCREL(%rip), %rax
|
||||
retq
|
||||
|
||||
|
||||
# Check X86_64_RELOC_GOTPCREL handling with cmp instructions, which have
|
||||
# negative addends.
|
||||
#
|
||||
# jitlink-check: decode_operand(test_gotcmpq, 3) = got_addr(macho_reloc.o, external_data) - next_pc(test_gotcmpq)
|
||||
.globl test_gotcmpq
|
||||
.align 4, 0x90
|
||||
test_gotcmpq:
|
||||
cmpq $0, external_data@GOTPCREL(%rip)
|
||||
retq
|
||||
|
||||
# Check that calls to external functions trigger the generation of stubs and GOT
|
||||
# entries.
|
||||
#
|
||||
|
@ -118,16 +129,16 @@ Lanon_data:
|
|||
# anonymous.
|
||||
#
|
||||
# Note: +8 offset in expression below to accounts for sizeof(Lanon_data).
|
||||
# jitlink-check: *{8}(section_addr(macho_reloc.o, __data) + 8) = (section_addr(macho_reloc.o, __data) + 8) - named_data + 2
|
||||
# jitlink-check: *{8}(section_addr(macho_reloc.o, __data) + 8) = (section_addr(macho_reloc.o, __data) + 8) - named_data - 2
|
||||
.p2align 3
|
||||
Lanon_minuend_quad:
|
||||
.quad Lanon_minuend_quad - named_data + 2
|
||||
.quad Lanon_minuend_quad - named_data - 2
|
||||
|
||||
# Note: +16 offset in expression below to accounts for sizeof(Lanon_data) + sizeof(Lanon_minuend_long).
|
||||
# jitlink-check: *{4}(section_addr(macho_reloc.o, __data) + 16) = ((section_addr(macho_reloc.o, __data) + 16) - named_data + 2)[31:0]
|
||||
# jitlink-check: *{4}(section_addr(macho_reloc.o, __data) + 16) = ((section_addr(macho_reloc.o, __data) + 16) - named_data - 2)[31:0]
|
||||
.p2align 2
|
||||
Lanon_minuend_long:
|
||||
.long Lanon_minuend_long - named_data + 2
|
||||
.long Lanon_minuend_long - named_data - 2
|
||||
|
||||
# Named quad storage target (first named atom in __data).
|
||||
.globl named_data
|
||||
|
@ -221,11 +232,11 @@ minuend_long3:
|
|||
# (i.e. is part of an alt_entry chain that includes 'A').
|
||||
#
|
||||
# Check "A: .long B - C + D" where 'B' is an alt_entry for 'A'.
|
||||
# jitlink-check: *{4}subtractor_with_alt_entry_minuend_long = (subtractor_with_alt_entry_minuend_long_B - named_data + 2)[31:0]
|
||||
# jitlink-check: *{4}subtractor_with_alt_entry_minuend_long = (subtractor_with_alt_entry_minuend_long_B - named_data - 2)[31:0]
|
||||
.globl subtractor_with_alt_entry_minuend_long
|
||||
.p2align 2
|
||||
subtractor_with_alt_entry_minuend_long:
|
||||
.long subtractor_with_alt_entry_minuend_long_B - named_data + 2
|
||||
.long subtractor_with_alt_entry_minuend_long_B - named_data - 2
|
||||
|
||||
.globl subtractor_with_alt_entry_minuend_long_B
|
||||
.p2align 2
|
||||
|
@ -234,11 +245,11 @@ subtractor_with_alt_entry_minuend_long_B:
|
|||
.long 0
|
||||
|
||||
# Check "A: .quad B - C + D" where 'B' is an alt_entry for 'A'.
|
||||
# jitlink-check: *{8}subtractor_with_alt_entry_minuend_quad = (subtractor_with_alt_entry_minuend_quad_B - named_data + 2)
|
||||
# jitlink-check: *{8}subtractor_with_alt_entry_minuend_quad = (subtractor_with_alt_entry_minuend_quad_B - named_data - 2)
|
||||
.globl subtractor_with_alt_entry_minuend_quad
|
||||
.p2align 3
|
||||
subtractor_with_alt_entry_minuend_quad:
|
||||
.quad subtractor_with_alt_entry_minuend_quad_B - named_data + 2
|
||||
.quad subtractor_with_alt_entry_minuend_quad_B - named_data - 2
|
||||
|
||||
.globl subtractor_with_alt_entry_minuend_quad_B
|
||||
.p2align 3
|
||||
|
@ -247,11 +258,11 @@ subtractor_with_alt_entry_minuend_quad_B:
|
|||
.quad 0
|
||||
|
||||
# Check "A: .long B - C + D" where 'C' is an alt_entry for 'A'.
|
||||
# jitlink-check: *{4}subtractor_with_alt_entry_subtrahend_long = (named_data - subtractor_with_alt_entry_subtrahend_long_B + 2)[31:0]
|
||||
# jitlink-check: *{4}subtractor_with_alt_entry_subtrahend_long = (named_data - subtractor_with_alt_entry_subtrahend_long_B - 2)[31:0]
|
||||
.globl subtractor_with_alt_entry_subtrahend_long
|
||||
.p2align 2
|
||||
subtractor_with_alt_entry_subtrahend_long:
|
||||
.long named_data - subtractor_with_alt_entry_subtrahend_long_B + 2
|
||||
.long named_data - subtractor_with_alt_entry_subtrahend_long_B - 2
|
||||
|
||||
.globl subtractor_with_alt_entry_subtrahend_long_B
|
||||
.p2align 2
|
||||
|
@ -260,11 +271,11 @@ subtractor_with_alt_entry_subtrahend_long_B:
|
|||
.long 0
|
||||
|
||||
# Check "A: .quad B - C + D" where 'B' is an alt_entry for 'A'.
|
||||
# jitlink-check: *{8}subtractor_with_alt_entry_subtrahend_quad = (named_data - subtractor_with_alt_entry_subtrahend_quad_B + 2)
|
||||
# jitlink-check: *{8}subtractor_with_alt_entry_subtrahend_quad = (named_data - subtractor_with_alt_entry_subtrahend_quad_B - 2)
|
||||
.globl subtractor_with_alt_entry_subtrahend_quad
|
||||
.p2align 3
|
||||
subtractor_with_alt_entry_subtrahend_quad:
|
||||
.quad named_data - subtractor_with_alt_entry_subtrahend_quad_B + 2
|
||||
.quad named_data - subtractor_with_alt_entry_subtrahend_quad_B - 2
|
||||
|
||||
.globl subtractor_with_alt_entry_subtrahend_quad_B
|
||||
.p2align 3
|
||||
|
|
Loading…
Reference in New Issue