[lld] [LLD][COFF] Skip sections marked as IMAGE_SCN_LNK_INFO in the output image (PR #122752)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 09:38:34 PST 2025


https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/122752

Fixes #106275.

>From 9e425c92f04030b9e95c2bf2f85f3f1221c976da Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Mon, 13 Jan 2025 18:18:49 +0100
Subject: [PATCH] [LLD][COFF] Skip sections marked as IMAGE_SCN_LNK_INFO in the
 output image

Fixes #106275.
---
 lld/COFF/InputFiles.cpp  |  2 +-
 lld/test/COFF/info-sec.s | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 lld/test/COFF/info-sec.s

diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index a94c984cfd4870..e7891d3e67f3e4 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -355,7 +355,7 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber,
     MergeChunk::addSection(symtab.ctx, c);
   else if (name == ".rsrc" || name.starts_with(".rsrc$"))
     resourceChunks.push_back(c);
-  else
+  else if (!(sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_INFO))
     chunks.push_back(c);
 
   return c;
diff --git a/lld/test/COFF/info-sec.s b/lld/test/COFF/info-sec.s
new file mode 100644
index 00000000000000..bdc2e4711b4040
--- /dev/null
+++ b/lld/test/COFF/info-sec.s
@@ -0,0 +1,10 @@
+// REQUIRES: x86
+// Check that sections marked as IMAGE_SCN_LNK_INFO are excluded from the output.
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
+// RUN: lld-link -machine:amd64 -dll -noentry %t.obj -out:%t.dll
+// RUN: llvm-readobj --headers %t.dll | FileCheck %s
+// CHECK-NOT: Name: .test
+
+        .section .test,"i"
+        .long 1



More information about the llvm-commits mailing list