From ba4721de5c7f98a5bd0184c21e083bb2ce4db7ad Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 29 Jul 2025 23:42:28 +0200 Subject: [PATCH] [LLD][COFF] Move entry thunk offset writing to writeSections (NFC) To make it easier to add entry thunks to other chunk types. --- lld/COFF/Chunks.cpp | 6 ------ lld/COFF/Writer.cpp | 10 +++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 01752cdc6a9da..4ba5d80b581ef 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -422,12 +422,6 @@ void SectionChunk::writeTo(uint8_t *buf) const { applyRelocation(buf + rel.VirtualAddress, rel); } - - // Write the offset to EC entry thunk preceding section contents. The low bit - // is always set, so it's effectively an offset from the last byte of the - // offset. - if (Defined *entryThunk = getEntryThunk()) - write32le(buf - sizeof(uint32_t), entryThunk->getRVA() - rva + 1); } void SectionChunk::applyRelocation(uint8_t *off, diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 076561807af47..62019f19292a1 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -2544,7 +2544,15 @@ void Writer::writeSections() { } parallelForEach(sec->chunks, [&](Chunk *c) { - c->writeTo(secBuf + c->getRVA() - sec->getRVA()); + uint8_t *buf = secBuf + c->getRVA() - sec->getRVA(); + c->writeTo(buf); + + // Write the offset to EC entry thunk preceding section contents. The low + // bit is always set, so it's effectively an offset from the last byte of + // the offset. + if (Defined *entryThunk = c->getEntryThunk()) + write32le(buf - sizeof(uint32_t), + entryThunk->getRVA() - c->getRVA() + 1); }); } }