[llvm] 1f3d452 - [JITLink][AArch64] Use R-X permissions for the GOT.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 11 23:09:20 PST 2022
Author: Lang Hames
Date: 2022-01-12T18:03:58+11:00
New Revision: 1f3d4525d87e9cd69c18098449a21ed0199fc459
URL: https://github.com/llvm/llvm-project/commit/1f3d4525d87e9cd69c18098449a21ed0199fc459
DIFF: https://github.com/llvm/llvm-project/commit/1f3d4525d87e9cd69c18098449a21ed0199fc459.diff
LOG: [JITLink][AArch64] Use R-X permissions for the GOT.
This consistent with ld64's treatment of the GOT, but the main aim here is a
short-term workaround for a bad interaction between stub code sequences and
memory layout: Stubs use LDRLiteral19 relocations to reference the GOT, but
BasicLayout currently puts RW- segments between R-- and R-X segments -- a large
RW- segment (or a large R-- for that matter) can cause the relocation to fail
with an out-of-range error.
Putting the GOT in R-X fixes this efficiently in practice. A more robust fix
will be to use a longer code sequence to materialize the GOT pointer and then
rewrite the stub to use a shorter sequence where possible.
Added:
llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_stub_to_got_distance_stress_test.s
Modified:
llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
index 844e76ab05425..45e70af642906 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
@@ -475,7 +475,7 @@ class PerGraphGOTAndPLTStubsBuilder_MachO_arm64
private:
Section &getGOTSection() {
if (!GOTSection)
- GOTSection = &G.createSection("$__GOT", MemProt::Read);
+ GOTSection = &G.createSection("$__GOT", MemProt::Read | MemProt::Exec);
return *GOTSection;
}
diff --git a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_stub_to_got_distance_stress_test.s b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_stub_to_got_distance_stress_test.s
new file mode 100644
index 0000000000000..d9a8cae9d5005
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_stub_to_got_distance_stress_test.s
@@ -0,0 +1,17 @@
+# RUN: llvm-mc -triple=arm64-apple-darwin19 -filetype=obj -o %t.o %s
+# RUN: llvm-jitlink -noexec -phony-externals %t.o
+#
+# Use RW- empty space sufficient to push the R-- and R-X segments more than
+# 2^20 bytes apart. This will cause the LDRLiteral19 relocations from the STUB
+# section to the GOT to overflow if not handled correctly.
+
+ .section __TEXT,__text,regular,pure_instructions
+ .ios_version_min 7, 0 sdk_version 16, 0
+ .globl _main
+ .p2align 2
+_main:
+ b _foo
+
+ .comm _empty_space,2097152,0
+
+.subsections_via_symbols
More information about the llvm-commits
mailing list