[lld] 7235ac9 - [LLD][COFF] Check load config size before setting its DependentLoadFlags (#118535)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 06:36:45 PST 2024
Author: Jacek Caban
Date: 2024-12-04T15:36:41+01:00
New Revision: 7235ac90517b61f8a5b5bd4e6a55437c094d6156
URL: https://github.com/llvm/llvm-project/commit/7235ac90517b61f8a5b5bd4e6a55437c094d6156
DIFF: https://github.com/llvm/llvm-project/commit/7235ac90517b61f8a5b5bd4e6a55437c094d6156.diff
LOG: [LLD][COFF] Check load config size before setting its DependentLoadFlags (#118535)
Merge prepareLoadConfig and checkLoadConfigGuardData to share helper
macros.
Added:
lld/test/COFF/deploadflag-cfg-short.s
Modified:
lld/COFF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 3ec8e42f97c8e9..34f4839396df12 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -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;
@@ -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)
diff --git a/lld/test/COFF/deploadflag-cfg-short.s b/lld/test/COFF/deploadflag-cfg-short.s
new file mode 100644
index 00000000000000..9cc5248044d8a3
--- /dev/null
+++ b/lld/test/COFF/deploadflag-cfg-short.s
@@ -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
More information about the llvm-commits
mailing list