[llvm] f7a5715 - [JITLink][MachO] Fix handling of non-extern UNSIGNED pair of SUBTRACTOR relocs.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 19 10:48:22 PDT 2020
Author: Lang Hames
Date: 2020-07-19T10:22:55-07:00
New Revision: f7a571537a14da83e5701864471b99b61cdcca54
URL: https://github.com/llvm/llvm-project/commit/f7a571537a14da83e5701864471b99b61cdcca54
DIFF: https://github.com/llvm/llvm-project/commit/f7a571537a14da83e5701864471b99b61cdcca54.diff
LOG: [JITLink][MachO] Fix handling of non-extern UNSIGNED pair of SUBTRACTOR relocs.
When processing a MachO SUBTRACTOR/UNSIGNED pair, if the UNSIGNED target
is non-extern then check the r_symbolnum field of the relocation to find
the targeted section and use the section's address to find 'ToSymbol'.
Previously 'ToSymbol' was found by loading the initial value stored at
the fixup location and treating this as an address to search for. This
is incorrect, however: the initial value includes the addend and will
point to the wrong block if the addend is less than zero or greater than
the block size.
rdar://65756694
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
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_arm64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
index 463845a5b8cb..28adf9b3fb71 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
@@ -148,10 +148,11 @@ class MachOLinkGraphBuilder_arm64 : public MachOLinkGraphBuilder {
else
return ToSymbolOrErr.takeError();
} else {
- if (auto ToSymbolOrErr = findSymbolByAddress(FixupValue))
- ToSymbol = &*ToSymbolOrErr;
- else
- return ToSymbolOrErr.takeError();
+ auto ToSymbolSec = findSectionByIndex(UnsignedRI.r_symbolnum - 1);
+ if (!ToSymbolSec)
+ return ToSymbolSec.takeError();
+ ToSymbol = getSymbolByAddress(ToSymbolSec->Address);
+ assert(ToSymbol && "No symbol for section");
FixupValue -= ToSymbol->getAddress();
}
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
index a91bc3b6033c..54d725eac144 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
@@ -150,10 +150,11 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder {
else
return ToSymbolOrErr.takeError();
} else {
- if (auto ToSymbolOrErr = findSymbolByAddress(FixupValue))
- ToSymbol = &*ToSymbolOrErr;
- else
- return ToSymbolOrErr.takeError();
+ auto ToSymbolSec = findSectionByIndex(UnsignedRI.r_symbolnum - 1);
+ if (!ToSymbolSec)
+ return ToSymbolSec.takeError();
+ ToSymbol = getSymbolByAddress(ToSymbolSec->Address);
+ assert(ToSymbol && "No symbol for section");
FixupValue -= ToSymbol->getAddress();
}
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 6d9c26484f8f..dd3cc455bd34 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_relocations.s
@@ -193,19 +193,19 @@ anon_func_addr_quad:
# X86_64_RELOC_SUBTRACTOR Quad/Long in named storage with anonymous minuend
#
-# jitlink-check: *{8}anon_minuend_quad1 = section_addr(macho_reloc.o, __data) - anon_minuend_quad1 + 2
+# jitlink-check: *{8}anon_minuend_quad1 = section_addr(macho_reloc.o, __data) - anon_minuend_quad1 - 2
# Only the form "B: .quad LA - B + C" is tested. The form "B: .quad B - LA + C" is
# invalid because the subtrahend can not be local.
.globl anon_minuend_quad1
.p2align 3
anon_minuend_quad1:
- .quad Lanon_data - anon_minuend_quad1 + 2
+ .quad Lanon_data - anon_minuend_quad1 - 2
-# jitlink-check: *{4}anon_minuend_long1 = (section_addr(macho_reloc.o, __data) - anon_minuend_long1 + 2)[31:0]
+# jitlink-check: *{4}anon_minuend_long1 = (section_addr(macho_reloc.o, __data) - anon_minuend_long1 - 2)[31:0]
.globl anon_minuend_long1
.p2align 2
anon_minuend_long1:
- .long Lanon_data - anon_minuend_long1 + 2
+ .long Lanon_data - anon_minuend_long1 - 2
# Check X86_64_RELOC_SUBTRACTOR Quad/Long in named storage with minuend and subtrahend.
# Both forms "A: .quad A - B + C" and "A: .quad B - A + C" are tested.
More information about the llvm-commits
mailing list