
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.
41 lines
1.3 KiB
LLVM
41 lines
1.3 KiB
LLVM
; RUN: llc -mtriple=aarch64-pc-windows-msvc < %s | FileCheck %s
|
|
|
|
define dso_local i32 @override_me1() "loader-replaceable" {
|
|
entry:
|
|
ret i32 1
|
|
}
|
|
|
|
define dso_local i32 @override_me2() "loader-replaceable" {
|
|
entry:
|
|
ret i32 2
|
|
}
|
|
|
|
define dso_local i32 @dont_override_me() {
|
|
entry:
|
|
ret i32 3
|
|
}
|
|
|
|
; CHECK: .section .drectve,"yni"
|
|
; CHECK-NEXT: .def override_me1_$fo$;
|
|
; CHECK-NEXT: .scl 2;
|
|
; CHECK-NEXT: .type 0;
|
|
; CHECK-NEXT: .endef
|
|
; CHECK-NEXT: .def override_me1_$fo_default$;
|
|
; CHECK-NEXT: .scl 2;
|
|
; CHECK-NEXT: .type 0;
|
|
; CHECK-NEXT: .endef
|
|
; CHECK-NEXT: .ascii " /ALTERNATENAME:override_me1_$fo$=override_me1_$fo_default$"
|
|
; CHECK-NEXT: .def override_me2_$fo$;
|
|
; CHECK-NEXT: .scl 2;
|
|
; CHECK-NEXT: .type 0;
|
|
; CHECK-NEXT: .endef
|
|
; CHECK-NEXT: .def override_me2_$fo_default$;
|
|
; CHECK-NEXT: .scl 2;
|
|
; CHECK-NEXT: .type 0;
|
|
; CHECK-NEXT: .endef
|
|
; CHECK-NEXT: .ascii " /ALTERNATENAME:override_me2_$fo$=override_me2_$fo_default$"
|
|
; CHECK-NEXT: .data
|
|
; CHECK-NEXT: override_me1_$fo_default$:
|
|
; CHECK-NEXT: override_me2_$fo_default$:
|
|
; CHECK-NEXT: .zero 1
|