aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCObjectFileInfo.cpp
diff options
context:
space:
mode:
authorDaniel Paoliello <danpao@microsoft.com>2025-05-20 14:48:41 -0700
committerGitHub <noreply@github.com>2025-05-20 14:48:41 -0700
commita414877a7a5f000d01370acb1162eb1dea87f48c (patch)
treeee19822c85edd3291c3a8476b9ff7936badabd25 /llvm/lib/MC/MCObjectFileInfo.cpp
parenta690852b290fc9c843933f95d1c8ebb6d7b97adb (diff)
downloadllvm-a414877a7a5f000d01370acb1162eb1dea87f48c.zip
llvm-a414877a7a5f000d01370acb1162eb1dea87f48c.tar.gz
llvm-a414877a7a5f000d01370acb1162eb1dea87f48c.tar.bz2
[x64][win] Add compiler support for x64 import call optimization (equivalent to MSVC /d2guardretpoline) (#126631)
This is the x64 equivalent of #121516 Since import call optimization was originally [added to x64 Windows to implement a more efficient retpoline mitigation](https://techcommunity.microsoft.com/blog/windowsosplatform/mitigating-spectre-variant-2-with-retpoline-on-windows/295618) the section and constant names relating to this all mention "retpoline" and we need to mark indirect calls, control-flow guard calls and jumps for jump tables in the section alongside calls to imported functions. As with the AArch64 feature, this emits a new section into the obj which is used by the MSVC linker to generate the Dynamic Value Relocation Table and the section itself does not appear in the final binary. The Windows Loader requires a specific sequence of instructions be emitted when this feature is enabled: * Indirect calls/jumps must have the function pointer to jump to in `rax`. * Calls to imported functions must use the `rex` prefix and be followed by a 5-byte nop. * Indirect calls must be followed by a 3-byte nop.
Diffstat (limited to 'llvm/lib/MC/MCObjectFileInfo.cpp')
-rw-r--r--llvm/lib/MC/MCObjectFileInfo.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index ab7552c..9ad56aa 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -599,6 +599,11 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
if (T.getArch() == Triple::aarch64) {
ImportCallSection =
Ctx->getCOFFSection(".impcall", COFF::IMAGE_SCN_LNK_INFO);
+ } else if (T.getArch() == Triple::x86_64) {
+ // Import Call Optimization on x64 leverages the same metadata as the
+ // retpoline mitigation, hence the unusual section name.
+ ImportCallSection =
+ Ctx->getCOFFSection(".retplne", COFF::IMAGE_SCN_LNK_INFO);
}
// Debug info.