[llvm] c33598d - [JITLink] Make sure MachO/x86-64 handles 32-bit signed addends correctly.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 22:46:20 PST 2019
Author: Lang Hames
Date: 2019-11-27T22:46:07-08:00
New Revision: c33598d5e547cddcd0b2a8e647570a759e01e02b
URL: https://github.com/llvm/llvm-project/commit/c33598d5e547cddcd0b2a8e647570a759e01e02b
DIFF: https://github.com/llvm/llvm-project/commit/c33598d5e547cddcd0b2a8e647570a759e01e02b.diff
LOG: [JITLink] Make sure MachO/x86-64 handles 32-bit signed addends correctly.
These need to be sign extended when loading into Edge addends.
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
index 9dbfb6556e31..69ec72aae292 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
@@ -252,7 +252,7 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder {
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 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder {
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 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder {
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
diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
index c97b1ecce6d6..5fabc6db1218 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
@@ -40,6 +40,17 @@ test_gotld:
movq external_data at 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 at 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
More information about the llvm-commits
mailing list