From 7d469e4a48a9440a679e12da5924a92aa9d67d51 Mon Sep 17 00:00:00 2001 From: Jacek Caban 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 875ada9d60539..3e9f3f4718386 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 &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 f7d2b57a20a02..901c974069b47 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 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 &chunks); } // namespace lld::coff diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 536c1eef5e49c..d8f45852bd311 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 edataChunks; + createEdataChunks(ctx, edataChunks); + for (Chunk *c : edataChunks) edataSec->addChunk(c); } if (!edataSec->chunks.empty()) {