[lld] [lld][ELF] Add range extension thunks for x86-64 (PR #180266)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 7 11:23:41 PST 2026
================
@@ -613,6 +614,45 @@ class PPC64PDLongBranchThunk final : public PPC64LongBranchThunk {
}
};
+// Base class for x86-64 thunks.
+//
+// An x86-64 thunk may be either short or long. A short thunk is simply a
+// jmp rel32 instruction (5 bytes), and it may be used when the distance from
+// the thunk to the target is less than 2GiB. Long thunks can branch to any
+// 64-bit virtual address and are implemented in derived classes. This class
+// tries to create a short thunk if the target is in range, otherwise it
+// creates a long thunk.
+class X86_64Thunk : public Thunk {
+public:
+ X86_64Thunk(Ctx &ctx, Symbol &dest, int64_t addend)
+ : Thunk(ctx, dest, addend) {}
+ bool getMayUseShortThunk();
+ void writeTo(uint8_t *buf) override;
+
+private:
+ bool mayUseShortThunk = true;
+ virtual void writeLong(uint8_t *buf) = 0;
+};
+
+// x86-64 long range thunk using absolute address.
----------------
MaskRay wrote:
I am not sure how useful this will be. The majority of large executables should use `-pie` and the absolute address thunk isn't very useful. It might come with shorter code sequence but the extra complexity needs to justify itself.
https://github.com/llvm/llvm-project/pull/180266
More information about the llvm-commits
mailing list