Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ class Writer {

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;
Expand Down Expand Up @@ -2631,14 +2630,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) \
Expand All @@ -2660,6 +2651,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)
Expand Down
12 changes: 12 additions & 0 deletions lld/test/COFF/deploadflag-cfg-short.s
Original file line number Diff line number Diff line change
@@ -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
Loading