[LLD][COFF] Check load config size before setting its DependentLoadFlags (#118535)
Merge prepareLoadConfig and checkLoadConfigGuardData to share helper macros.
This commit is contained in:
@@ -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)
|
||||
|
||||
12
lld/test/COFF/deploadflag-cfg-short.s
Normal file
12
lld/test/COFF/deploadflag-cfg-short.s
Normal 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
|
||||
Reference in New Issue
Block a user