[LLD][COFF] Check load config size before setting its DependentLoadFlags (#118535)

Merge prepareLoadConfig and checkLoadConfigGuardData to share helper
macros.
This commit is contained in:
Jacek Caban
2024-12-04 15:36:41 +01:00
committed by GitHub
parent 99b862efba
commit 7235ac9051
2 changed files with 17 additions and 9 deletions

View File

@@ -277,7 +277,6 @@ private:
void prepareLoadConfig();
template <typename T> void prepareLoadConfig(T *loadConfig);
template <typename T> void checkLoadConfigGuardData(const T *loadConfig);
std::unique_ptr<FileOutputBuffer> &buffer;
std::map<PartialSectionKey, PartialSection *> partialSections;
@@ -2633,14 +2632,6 @@ void Writer::prepareLoadConfig() {
}
template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
if (ctx.config.dependentLoadFlags)
loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
checkLoadConfigGuardData(loadConfig);
}
template <typename T>
void Writer::checkLoadConfigGuardData(const T *loadConfig) {
size_t loadConfigSize = loadConfig->Size;
#define RETURN_IF_NOT_CONTAINS(field) \
@@ -2662,6 +2653,11 @@ void Writer::checkLoadConfigGuardData(const T *loadConfig) {
if (loadConfig->field != s->getVA()) \
warn(#field " not set correctly in '_load_config_used'");
if (ctx.config.dependentLoadFlags) {
RETURN_IF_NOT_CONTAINS(DependentLoadFlags)
loadConfig->DependentLoadFlags = ctx.config.dependentLoadFlags;
}
if (ctx.config.guardCF == GuardCFLevel::Off)
return;
RETURN_IF_NOT_CONTAINS(GuardFlags)

View File

@@ -0,0 +1,12 @@
# REQUIRES: x86
# RUN: llvm-mc -triple x86_64-windows-msvc -filetype=obj %s -o %t.obj
# RUN: lld-link %t.obj -out:%t.dll -dll -noentry -nodefaultlib -dependentloadflag:0x800 2>&1 | FileCheck %s
# CHECK: lld-link: warning: '_load_config_used' structure too small to include DependentLoadFlags
.section .rdata,"dr"
.balign 8
.globl _load_config_used
_load_config_used:
.long 0x4c
.fill 0x48, 1, 0