Skip to content

Commit f840fe7

Browse files
committed
[LLD][COFF] Check load config size before setting its DependentLoadFlags
Merge prepareLoadConfig and checkLoadConfigGuardData to share helper macros.
1 parent 5024926 commit f840fe7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lld/COFF/Writer.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ class Writer {
277277

278278
void prepareLoadConfig();
279279
template <typename T> void prepareLoadConfig(T *loadConfig);
280-
template <typename T> void checkLoadConfigGuardData(const T *loadConfig);
281280

282281
std::unique_ptr<FileOutputBuffer> &buffer;
283282
std::map<PartialSectionKey, PartialSection *> partialSections;
@@ -2631,14 +2630,6 @@ void Writer::prepareLoadConfig() {
26312630
}
26322631

26332632
template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
2634-
if (ctx.config.dependentLoadFlags)
2635-
loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
2636-
2637-
checkLoadConfigGuardData(loadConfig);
2638-
}
2639-
2640-
template <typename T>
2641-
void Writer::checkLoadConfigGuardData(const T *loadConfig) {
26422633
size_t loadConfigSize = loadConfig->Size;
26432634

26442635
#define RETURN_IF_NOT_CONTAINS(field) \
@@ -2660,6 +2651,11 @@ void Writer::checkLoadConfigGuardData(const T *loadConfig) {
26602651
if (loadConfig->field != s->getVA()) \
26612652
warn(#field " not set correctly in '_load_config_used'");
26622653

2654+
if (ctx.config.dependentLoadFlags) {
2655+
RETURN_IF_NOT_CONTAINS(DependentLoadFlags)
2656+
loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
2657+
}
2658+
26632659
if (ctx.config.guardCF == GuardCFLevel::Off)
26642660
return;
26652661
RETURN_IF_NOT_CONTAINS(GuardFlags)

lld/test/COFF/deploadflag-cfg-short.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -triple x86_64-windows-msvc -filetype=obj %s -o %t.obj
4+
# RUN: lld-link %t.obj -out:%t.dll -dll -noentry -nodefaultlib -dependentloadflag:0x800 2>&1 | FileCheck %s
5+
# CHECK: lld-link: warning: '_load_config_used' structure too small to include DependentLoadFlags
6+
7+
.section .rdata,"dr"
8+
.balign 8
9+
.globl _load_config_used
10+
_load_config_used:
11+
.long 0x4c
12+
.fill 0x48, 1, 0

0 commit comments

Comments
 (0)