Author: David Majnemer Date: 2022-08-25T14:17:26Z New Revision: bd28bd59a3693b6abc12231f2140e02760c0ada0
URL: https://github.com/llvm/llvm-project/commit/bd28bd59a3693b6abc12231f2140e02760c0ada0 DIFF: https://github.com/llvm/llvm-project/commit/bd28bd59a3693b6abc12231f2140e02760c0ada0.diff LOG: [clang-cl] /kernel should toggle bit 30 in @feat.00 The linker is supposed to detect when an object with /kernel is linked with another object which is not compiled with /kernel. The linker detects this by checking bit 30 in @feat.00. Added: Modified: clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGen/cfguardtable.c llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp llvm/lib/Target/X86/X86AsmPrinter.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6238a289978d..9df197056664 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -697,6 +697,10 @@ void CodeGenModule::Release() { // Function ID tables for EH Continuation Guard. getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1); } + if (Context.getLangOpts().Kernel) { + // Note if we are compiling with /kernel. + getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1); + } if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) { // We don't support LTO with 2 with diff erent StrictVTablePointers // FIXME: we could support it by stripping all the information introduced diff --git a/clang/test/CodeGen/cfguardtable.c b/clang/test/CodeGen/cfguardtable.c index a92e1f6c610c..fe65d2a81c23 100644 --- a/clang/test/CodeGen/cfguardtable.c +++ b/clang/test/CodeGen/cfguardtable.c @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -cfguard-no-checks -emit-llvm %s -o - | FileCheck %s -check-prefix=CFGUARDNOCHECKS // RUN: %clang_cc1 -cfguard -emit-llvm %s -o - | FileCheck %s -check-prefix=CFGUARD // RUN: %clang_cc1 -ehcontguard -emit-llvm %s -o - | FileCheck %s -check-prefix=EHCONTGUARD +// RUN: %clang_cc1 -fms-kernel -emit-llvm %s -o - | FileCheck %s -check-prefix=MS-KERNEL void f(void) {} @@ -8,3 +9,4 @@ void f(void) {} // CFGUARDNOCHECKS: !"cfguard", i32 1} // CFGUARD: !"cfguard", i32 2} // EHCONTGUARD: !"ehcontguard", i32 1} +// MS-KERNEL: !"ms-kernel", i32 1} diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index 32d2f7945646..df2fce5621ad 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -219,6 +219,10 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { Feat00Flags |= 0x4000; // Object also has EHCont. } + if (M.getModuleFlag("ms-kernel")) { + Feat00Flags |= 0x40000000; // Object is compiled with /kernel. + } + OutStreamer->emitSymbolAttribute(S, MCSA_Global); OutStreamer->emitAssignment( S, MCConstantExpr::create(Feat00Flags, MMI->getContext())); diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp index 834b626dbb15..3e0f2a41ee74 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -818,6 +818,10 @@ void X86AsmPrinter::emitStartOfAsmFile(Module &M) { Feat00Flags |= 0x4000; // Object also has EHCont. } + if (M.getModuleFlag("ms-kernel")) { + Feat00Flags |= 0x40000000; // Object is compiled with /kernel. + } + OutStreamer->emitSymbolAttribute(S, MCSA_Global); OutStreamer->emitAssignment( S, MCConstantExpr::create(Feat00Flags, MMI->getContext())); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits