From 293d5193af009401b98836cc042d55117ca53694 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sat, 3 Feb 2024 11:03:48 +0000 Subject: [PATCH] On OpenBSD we always want IBT-compatible PLT entries. Currently we use repoline PLT entries that were changed to include the necessary endbr64 instructions. But with -Wl,-znoretpolineplt we would still emit non-BIT PLT entries under certain circumstances. Fix this. ok deraadt@, guenther@ --- gnu/llvm/lld/ELF/Arch/X86_64.cpp | 5 +++++ gnu/llvm/lld/ELF/SyntheticSections.cpp | 4 ++++ gnu/llvm/lld/ELF/Writer.cpp | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/gnu/llvm/lld/ELF/Arch/X86_64.cpp b/gnu/llvm/lld/ELF/Arch/X86_64.cpp index a44c2fe0b53..a74bf8825af 100644 --- a/gnu/llvm/lld/ELF/Arch/X86_64.cpp +++ b/gnu/llvm/lld/ELF/Arch/X86_64.cpp @@ -1186,6 +1186,10 @@ static TargetInfo *getTargetInfo() { return &t; } +#ifdef __OpenBSD__ + static IntelIBT t; + return &t; +#else if (config->andFeatures & GNU_PROPERTY_X86_FEATURE_1_IBT) { static IntelIBT t; return &t; @@ -1193,6 +1197,7 @@ static TargetInfo *getTargetInfo() { static X86_64 t; return &t; +#endif } TargetInfo *elf::getX86_64TargetInfo() { return getTargetInfo(); } diff --git a/gnu/llvm/lld/ELF/SyntheticSections.cpp b/gnu/llvm/lld/ELF/SyntheticSections.cpp index e7c437bc765..b73b326504f 100644 --- a/gnu/llvm/lld/ELF/SyntheticSections.cpp +++ b/gnu/llvm/lld/ELF/SyntheticSections.cpp @@ -2500,6 +2500,10 @@ PltSection::PltSection() if ((config->emachine == EM_386 || config->emachine == EM_X86_64) && (config->andFeatures & GNU_PROPERTY_X86_FEATURE_1_IBT)) name = ".plt.sec"; +#ifdef __OpenBSD__ + else if (config->emachine == EM_X86_64) + name = ".plt.sec"; +#endif // The PLT needs to be writable on SPARC as the dynamic linker will // modify the instructions in the PLT entries. diff --git a/gnu/llvm/lld/ELF/Writer.cpp b/gnu/llvm/lld/ELF/Writer.cpp index 3bba1b62db4..eb4643d3c5f 100644 --- a/gnu/llvm/lld/ELF/Writer.cpp +++ b/gnu/llvm/lld/ELF/Writer.cpp @@ -489,6 +489,12 @@ template void elf::createSyntheticSections() { in.ibtPlt = std::make_unique(); add(*in.ibtPlt); } +#ifdef __OpenBSD__ + else if (config->emachine == EM_X86_64) { + in.ibtPlt = std::make_unique(); + add(*in.ibtPlt); + } +#endif if (config->emachine == EM_PPC) in.plt = std::make_unique(); -- 2.20.1