Skip to content

Commit e1385c4

Browse files
committed
[lld] Always mark ARM64EC modules as instrumented.
FIXME: The test doesn't seem to work on MSVC, but it's observed in real-world images, needs more investigation.
1 parent d76da39 commit e1385c4

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lld/COFF/Writer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,7 @@ void Writer::createMiscChunks() {
12131213
createSEHTable();
12141214

12151215
// Create /guard:cf tables if requested.
1216-
if (config->guardCF != GuardCFLevel::Off)
1217-
createGuardCFTables();
1216+
createGuardCFTables();
12181217

12191218
if (isArm64EC(config->machine))
12201219
createECChunks();
@@ -1973,6 +1972,15 @@ void Writer::markSymbolsWithRelocations(ObjFile *file,
19731972
void Writer::createGuardCFTables() {
19741973
Configuration *config = &ctx.config;
19751974

1975+
if (config->guardCF == GuardCFLevel::Off) {
1976+
if (isArm64EC(config->machine)) {
1977+
Symbol *flagSym = ctx.symtab.findUnderscore("__guard_flags");
1978+
cast<DefinedAbsolute>(flagSym)->setVA(
1979+
uint32_t(GuardFlags::CF_INSTRUMENTED));
1980+
}
1981+
return;
1982+
}
1983+
19761984
SymbolRVASet addressTakenSyms;
19771985
SymbolRVASet giatsRVASet;
19781986
std::vector<Symbol *> giatsSymbols;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ARM64EC code is always instrumented, check that CF_INSTRUMENTED flag is set even with -guard:no argument.
2+
3+
// REQUIRES: aarch64
4+
5+
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.obj
6+
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o %t-loadconfig.obj
7+
8+
// RUN: lld-link -out:%t1.dll -machine:arm64ec %t.obj %t-loadconfig.obj -dll -noentry
9+
// RUN: lld-link -out:%t2.dll -machine:arm64ec %t.obj %t-loadconfig.obj -dll -noentry -guard:no
10+
11+
// RUN: llvm-readobj --coff-load-config %t1.dll | FileCheck %s
12+
// RUN: llvm-readobj --coff-load-config %t2.dll | FileCheck %s
13+
// CHECK: GuardFlags [ (0x100)
14+
// CHECK-NEXT: CF_INSTRUMENTED (0x100)
15+
// CHECK-NEXT: ]
16+
17+
// RUN: llvm-readobj --hex-dump=.test %t1.dll | FileCheck --check-prefix=SYM %s
18+
// RUN: llvm-readobj --hex-dump=.test %t2.dll | FileCheck --check-prefix=SYM %s
19+
// SYM: 0x180003000 00010000
20+
21+
.section .test, "r"
22+
.word __guard_flags

0 commit comments

Comments
 (0)