[PATCH] D140593: In the x86_64 medium code model, emit RIP-relative access to local function instead of position-dependent relocation
Thomas Köppe via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 22 17:29:51 PST 2022
tkoeppe created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
tkoeppe requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently, the medium code model for x86_64 emits position-dependent relocations (R_X86_64_64) for local functions (e.g. https://godbolt.org/z/1W7enxzK6), regardless of PIC or no-PIC mode. (This means generically that code compiled with the medium model cannot be linked into a position-independent executable.)
This patch changes the behaviour to unconditionally emit a RIP-relative access, both in PIC and non-PIC mode. This fixes PIC mode, and is perhaps an improvement in non-PIC mode, too, since it results in a shorter instruction. A 32-bit relocation should suffice since the medium memory model demands that all code fit within 2GiB.
https://reviews.llvm.org/D140593
Files:
llvm/lib/Target/X86/X86ISelLowering.cpp
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -20488,6 +20488,10 @@
return X86ISD::Wrapper;
CodeModel::Model M = getTargetMachine().getCodeModel();
+
+ if (M == CodeModel::Medium && isa_and_nonnull<Function>(GV))
+ return X86ISD::WrapperRIP;
+
if (Subtarget.isPICStyleRIPRel() &&
(M == CodeModel::Small || M == CodeModel::Kernel))
return X86ISD::WrapperRIP;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140593.484992.patch
Type: text/x-patch
Size: 547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221223/854c8607/attachment.bin>
More information about the llvm-commits
mailing list