[lld] [LLD][COFF] Simplify creation of .edata chunks (NFC) (PR #123651)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 09:24:20 PST 2025


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

Since commit dadc6f2488684, only the constructor of the `EdataContents` class is used. Replace it with a function and skip the call when using a custom `.edata` section.

>From 7d469e4a48a9440a679e12da5924a92aa9d67d51 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Wed, 25 Dec 2024 23:56:19 +0100
Subject: [PATCH] [LLD][COFF] Simplify creation of .edata chunks (NFC)

Since commit dadc6f2488684, only the constructor of the EdataContents class is used.
Replace it with a function and skip the call when using a custom .edata section.
---
 lld/COFF/DLL.cpp    |  2 +-
 lld/COFF/DLL.h      | 16 ++--------------
 lld/COFF/Writer.cpp |  7 ++++---
 3 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp
index 875ada9d605394..3e9f3f47183863 100644
--- a/lld/COFF/DLL.cpp
+++ b/lld/COFF/DLL.cpp
@@ -920,7 +920,7 @@ Chunk *DelayLoadContents::newThunkChunk(DefinedImportData *s,
   }
 }
 
-EdataContents::EdataContents(COFFLinkerContext &ctx) : ctx(ctx) {
+void createEdataChunks(COFFLinkerContext &ctx, std::vector<Chunk *> &chunks) {
   unsigned baseOrdinal = 1 << 16, maxOrdinal = 0;
   for (Export &e : ctx.config.exports) {
     baseOrdinal = std::min(baseOrdinal, (unsigned)e.ordinal);
diff --git a/lld/COFF/DLL.h b/lld/COFF/DLL.h
index f7d2b57a20a020..901c974069b47b 100644
--- a/lld/COFF/DLL.h
+++ b/lld/COFF/DLL.h
@@ -77,20 +77,8 @@ class DelayLoadContents {
   COFFLinkerContext &ctx;
 };
 
-// Windows-specific.
-// EdataContents creates all chunks for the DLL export table.
-class EdataContents {
-public:
-  EdataContents(COFFLinkerContext &ctx);
-  std::vector<Chunk *> chunks;
-
-  uint64_t getRVA() { return chunks[0]->getRVA(); }
-  uint64_t getSize() {
-    return chunks.back()->getRVA() + chunks.back()->getSize() - getRVA();
-  }
-
-  COFFLinkerContext &ctx;
-};
+// Create all chunks for the DLL export table.
+void createEdataChunks(COFFLinkerContext &ctx, std::vector<Chunk *> &chunks);
 
 } // namespace lld::coff
 
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 536c1eef5e49c8..d8f45852bd311e 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -210,7 +210,7 @@ struct ChunkRange {
 class Writer {
 public:
   Writer(COFFLinkerContext &c)
-      : buffer(c.e.outputBuffer), delayIdata(c), edata(c), ctx(c) {}
+      : buffer(c.e.outputBuffer), delayIdata(c), ctx(c) {}
   void run();
 
 private:
@@ -298,7 +298,6 @@ class Writer {
   Chunk *iatStart = nullptr;
   uint64_t iatSize = 0;
   DelayLoadContents delayIdata;
-  EdataContents edata;
   bool setNoSEHCharacteristic = false;
   uint32_t tlsAlignment = 0;
 
@@ -1325,7 +1324,9 @@ void Writer::createExportTable() {
     if (ctx.config.hadExplicitExports)
       Warn(ctx) << "literal .edata sections override exports";
   } else if (!ctx.config.exports.empty()) {
-    for (Chunk *c : edata.chunks)
+    std::vector<Chunk *> edataChunks;
+    createEdataChunks(ctx, edataChunks);
+    for (Chunk *c : edataChunks)
       edataSec->addChunk(c);
   }
   if (!edataSec->chunks.empty()) {



More information about the llvm-commits mailing list