[LLD][COFF] Set __guard_flags to CF_INSTRUMENTED if any object is instrumented (#115374)
This commit is contained in:
@@ -1217,8 +1217,7 @@ void Writer::createMiscChunks() {
|
||||
createSEHTable();
|
||||
|
||||
// Create /guard:cf tables if requested.
|
||||
if (config->guardCF != GuardCFLevel::Off)
|
||||
createGuardCFTables();
|
||||
createGuardCFTables();
|
||||
|
||||
if (isArm64EC(config->machine))
|
||||
createECChunks();
|
||||
@@ -1979,6 +1978,20 @@ void Writer::markSymbolsWithRelocations(ObjFile *file,
|
||||
void Writer::createGuardCFTables() {
|
||||
Configuration *config = &ctx.config;
|
||||
|
||||
if (config->guardCF == GuardCFLevel::Off) {
|
||||
// MSVC marks the entire image as instrumented if any input object was built
|
||||
// with /guard:cf.
|
||||
for (ObjFile *file : ctx.objFileInstances) {
|
||||
if (file->hasGuardCF()) {
|
||||
Symbol *flagSym = ctx.symtab.findUnderscore("__guard_flags");
|
||||
cast<DefinedAbsolute>(flagSym)->setVA(
|
||||
uint32_t(GuardFlags::CF_INSTRUMENTED));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SymbolRVASet addressTakenSyms;
|
||||
SymbolRVASet giatsRVASet;
|
||||
std::vector<Symbol *> giatsSymbols;
|
||||
|
||||
22
lld/test/COFF/cfguard-off-instrumented.s
Normal file
22
lld/test/COFF/cfguard-off-instrumented.s
Normal file
@@ -0,0 +1,22 @@
|
||||
// Verify that __guard_flags is set to CF_INSTRUMENTED if CF guard is disabled,
|
||||
// but the input object was built with CF guard.
|
||||
|
||||
// REQUIRES: x86
|
||||
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
|
||||
// RUN: lld-link -out:%t1.dll %t.obj -dll -noentry
|
||||
// RUN: lld-link -out:%t2.dll %t.obj -dll -noentry -guard:no
|
||||
|
||||
// RUN: llvm-readobj --hex-dump=.test %t1.dll | FileCheck %s
|
||||
// RUN: llvm-readobj --hex-dump=.test %t2.dll | FileCheck %s
|
||||
// CHECK: 0x180001000 00010000
|
||||
|
||||
.def @feat.00;
|
||||
.scl 3;
|
||||
.type 0;
|
||||
.endef
|
||||
.globl @feat.00
|
||||
@feat.00 = 0x800
|
||||
|
||||
.section .test, "r"
|
||||
.long __guard_flags
|
||||
Reference in New Issue
Block a user