Skip to content

Commit 7235ac9

Browse files
authored
[LLD][COFF] Check load config size before setting its DependentLoadFlags (#118535)
Merge prepareLoadConfig and checkLoadConfigGuardData to share helper macros.
1 parent 99b862e commit 7235ac9

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;
@@ -2633,14 +2632,6 @@ void Writer::prepareLoadConfig() {
26332632
}
26342633

26352634
template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
2636-
if (ctx.config.dependentLoadFlags)
2637-
loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
2638-
2639-
checkLoadConfigGuardData(loadConfig);
2640-
}
2641-
2642-
template <typename T>
2643-
void Writer::checkLoadConfigGuardData(const T *loadConfig) {
26442635
size_t loadConfigSize = loadConfig->Size;
26452636

26462637
#define RETURN_IF_NOT_CONTAINS(field) \
@@ -2662,6 +2653,11 @@ void Writer::checkLoadConfigGuardData(const T *loadConfig) {
26622653
if (loadConfig->field != s->getVA()) \
26632654
warn(#field " not set correctly in '_load_config_used'");
26642655

2656+
if (ctx.config.dependentLoadFlags) {
2657+
RETURN_IF_NOT_CONTAINS(DependentLoadFlags)
2658+
loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
2659+
}
2660+
26652661
if (ctx.config.guardCF == GuardCFLevel::Off)
26662662
return;
26672663
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)