
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.
18 lines
593 B
C++
18 lines
593 B
C++
// RUN: %clang_cc1 -triple=x86_64-pc-windows-msvc -loader-replaceable-function=override_me -loader-replaceable-function="?override_me_cpp@@YAXXZ" -emit-llvm -o - %s | FileCheck %s
|
|
|
|
// CHECK: define dso_local void @override_me() #0
|
|
extern "C" void override_me() {}
|
|
|
|
// CHECK: define dso_local void @"?override_me_cpp@@YAXXZ"() #0
|
|
void override_me_cpp() {}
|
|
|
|
// CHECK: define dso_local void @dont_override_me() #1
|
|
extern "C" void dont_override_me() {}
|
|
|
|
// CHECK: attributes #0 = {
|
|
// CHECK-SAME: loader-replaceable
|
|
|
|
// CHECK: attributes #1 = {
|
|
// CHECK-NOT: loader-replaceable
|
|
// CHECK-SAME: }
|