[all-commits] [llvm/llvm-project] 97a58b: [aarch64][x86][win] Add compiler support for MSVC'...

Daniel Paoliello via All-commits all-commits at lists.llvm.org
Fri May 9 14:57:00 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 97a58b04c6813d8cab1bfb47ce5023895b016319
      https://github.com/llvm/llvm-project/commit/97a58b04c6813d8cab1bfb47ce5023895b016319
  Author: Daniel Paoliello <danpao at microsoft.com>
  Date:   2025-05-09 (Fri, 09 May 2025)

  Changed paths:
    M clang/include/clang/Basic/CodeGenOptions.h
    M clang/include/clang/Driver/Options.td
    M clang/lib/CodeGen/CGCall.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    A clang/test/CodeGen/loader-replaceable-function.cpp
    M clang/test/Driver/cl-options.c
    M llvm/include/llvm/CodeGen/AsmPrinter.h
    M llvm/include/llvm/IR/Attributes.td
    M llvm/include/llvm/IR/Mangler.h
    M llvm/lib/Analysis/InlineCost.cpp
    M llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    M llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
    M llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
    M llvm/lib/Target/X86/X86AsmPrinter.cpp
    A llvm/test/CodeGen/AArch64/win-loader-replaceable-function.ll
    A llvm/test/CodeGen/X86/win-loader-replaceable-function.ll
    M llvm/test/Transforms/Inline/attributes.ll

  Log Message:
  -----------
  [aarch64][x86][win] Add compiler support for MSVC's /funcoverride flag (Windows kernel loader replaceable functions) (#125320)

Adds support for MSVC's undocumented `/funcoverride` flag, which marks
functions as being replaceable by the Windows kernel loader. This is
used to allow functions to be upgraded depending on the capabilities of
the current processor (e.g., the kernel can be built with the naive
implementation of a function, but that function can be replaced at boot
with one that uses SIMD instructions if the processor supports them).

For each marked function we need to generate:
* An undefined symbol named `<name>_$fo$`.
* A defined symbol `<name>_$fo_default$` that points to the `.data`
section (anywhere in the data section, it is assumed to be zero sized).
* An `/ALTERNATENAME` linker directive that points from `<name>_$fo$` to
`<name>_$fo_default$`.

This is used by the MSVC linker to generate the appropriate metadata in
the Dynamic Value Relocation Table.

Marked function must never be inlined (otherwise those inline sites
can't be replaced).

Note that I've chosen to implement this in AsmPrinter as there was no
way to create a `GlobalVariable` for `<name>_$fo$` that would result in
a symbol being emitted (as nothing consumes it and it has no
initializer). I tried to have `llvm.used` and `llvm.compiler.used` point
to it, but this didn't help.

Within LLVM I referred to this feature as "loader replaceable" as
"function override" already has a different meaning to C++ developers...

I also took the opportunity to extract the feature symbol generation
code used by both AArch64 and X86 into a common function in AsmPrinter.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list