Skip to content

Commit 92ab85c

Browse files
committed
[CodeGen][clang] Use module metadata to mark hotpatchable modules
1 parent 23302a2 commit 92ab85c

File tree

6 files changed

+50
-10
lines changed

6 files changed

+50
-10
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
467467
Options.LoopAlignment = CodeGenOpts.LoopAlignment;
468468
Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
469469
Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
470-
Options.Hotpatch = CodeGenOpts.HotPatch;
471470
Options.JMCInstrument = CodeGenOpts.JMCInstrument;
472471
Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
473472

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,10 @@ void CodeGenModule::Release() {
11361136
// Function ID tables for EH Continuation Guard.
11371137
getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
11381138
}
1139+
if (CodeGenOpts.HotPatch) {
1140+
// Note if we are compiling with /hotpatch.
1141+
getModule().addModuleFlag(llvm::Module::Warning, "ms-hotpatch", 1);
1142+
}
11391143
if (Context.getLangOpts().Kernel) {
11401144
// Note if we are compiling with /kernel.
11411145
getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);

clang/test/CodeGen/patchable-function-entry.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ void f(void) {}
3939
// HOTPATCH: attributes #1 = { {{.*}} "patchable-function"="prologue-short-redirect"
4040
// HOTPATCH: attributes #2 = { {{.*}} "patchable-function"="prologue-short-redirect"
4141
// HOTPATCH: attributes #3 = { {{.*}} "patchable-function"="prologue-short-redirect"
42+
// HOTPATCH: !{{.}} = !{i32 2, !"ms-hotpatch", i32 1}

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ class TargetOptions {
137137
EmitCallSiteInfo(false), SupportsDebugEntryValues(false),
138138
EnableDebugEntryValues(false), ValueTrackingVariableLocations(false),
139139
ForceDwarfFrameSection(false), XRayFunctionIndex(true),
140-
DebugStrictDwarf(false), Hotpatch(false),
141-
PPCGenScalarMASSEntries(false), JMCInstrument(false),
142-
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
143-
VerifyArgABICompliance(true),
140+
DebugStrictDwarf(false), PPCGenScalarMASSEntries(false),
141+
JMCInstrument(false), EnableCFIFixup(false), MisExpect(false),
142+
XCOFFReadOnlyPointers(false), VerifyArgABICompliance(true),
144143
FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
145144

146145
/// DisableFramePointerElim - This returns true if frame pointer elimination
@@ -347,9 +346,6 @@ class TargetOptions {
347346
/// By default, it is set to false.
348347
unsigned DebugStrictDwarf : 1;
349348

350-
/// Emit the hotpatch flag in CodeView debug.
351-
unsigned Hotpatch : 1;
352-
353349
/// Enables scalar MASS conversions
354350
unsigned PPCGenScalarMASSEntries : 1;
355351

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ void CodeViewDebug::emitCompilerInformation() {
886886
}
887887
using ArchType = llvm::Triple::ArchType;
888888
ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
889-
if (CompilerInfoAsm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
890-
Arch == ArchType::aarch64) {
889+
if (Arch == ArchType::thumb || Arch == ArchType::aarch64 ||
890+
MMI->getModule()->getModuleFlag("ms-hotpatch")) {
891891
Flags |= static_cast<uint32_t>(CompileSym3Flags::HotPatch);
892892
}
893893

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llc -filetype=obj -o - %s | llvm-readobj --codeview - | FileCheck %s
2+
3+
; ModuleID = 'a.c'
4+
source_filename = "a.c"
5+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
6+
target triple = "x86_64-unknown-windows-msvc19.33.0"
7+
8+
; Function Attrs: noinline nounwind optnone uwtable
9+
define dso_local void @test() #0 !dbg !10 {
10+
entry:
11+
ret void, !dbg !13
12+
}
13+
14+
attributes #0 = { noinline nounwind optnone uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "patchable-function"="prologue-short-redirect" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
15+
16+
!llvm.dbg.cu = !{!0}
17+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
18+
!llvm.ident = !{!9}
19+
20+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
21+
!1 = !DIFile(filename: "a.c", directory: "/tmp", checksumkind: CSK_MD5, checksum: "c59e1f6192de3124537b024248301dd1")
22+
!2 = !{i32 2, !"CodeView", i32 1}
23+
!3 = !{i32 2, !"ms-hotpatch", i32 1}
24+
!4 = !{i32 2, !"Debug Info Version", i32 3}
25+
!5 = !{i32 1, !"wchar_size", i32 2}
26+
!6 = !{i32 8, !"PIC Level", i32 2}
27+
!7 = !{i32 7, !"uwtable", i32 2}
28+
!8 = !{i32 1, !"MaxTLSAlign", i32 65536}
29+
!9 = !{!"clang version 21.0.0git"}
30+
!10 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
31+
!11 = !DISubroutineType(types: !12)
32+
!12 = !{null}
33+
!13 = !DILocation(line: 1, scope: !10)
34+
35+
; CHECK: Compile3Sym {
36+
; CHECK-NEXT: Kind: S_COMPILE3 (0x113C)
37+
; CHECK-NEXT: Language: C (0x0)
38+
; CHECK-NEXT: Flags [ (0x4000)
39+
; CHECK-NEXT: HotPatch (0x4000)
40+
; CHECK-NEXT: ]

0 commit comments

Comments
 (0)