diff options
author | Jacek Caban <jacek@codeweavers.com> | 2023-12-02 13:09:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-02 13:09:51 +0100 |
commit | 708158529b82007a34d623ba6f52d641c43b3416 (patch) | |
tree | 574262623806e2eb0ea885f8901265a37299726a /lld/COFF | |
parent | e9c6f3f5e7e23b23de4eeaa182ebfcb7d2188495 (diff) | |
download | llvm-708158529b82007a34d623ba6f52d641c43b3416.zip llvm-708158529b82007a34d623ba6f52d641c43b3416.tar.gz llvm-708158529b82007a34d623ba6f52d641c43b3416.tar.bz2 |
[lld][COFF][NFC] Store pdata range as ChunkRange. (#74024)
Diffstat (limited to 'lld/COFF')
-rw-r--r-- | lld/COFF/Writer.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 6dbfa8e..3490ff1 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -197,6 +197,10 @@ public: } }; +struct ChunkRange { + Chunk *first = nullptr, *last; +}; + // The writer writes a SymbolTable result to a file. class Writer { public: @@ -247,7 +251,7 @@ private: void writeBuildId(); void writePEChecksum(); void sortSections(); - template <typename T> void sortExceptionTable(Chunk *first, Chunk *last); + template <typename T> void sortExceptionTable(ChunkRange &exceptionTable); void sortExceptionTables(); void sortCRTSectionChunks(std::vector<Chunk *> &chunks); void addSyntheticIdata(); @@ -311,7 +315,7 @@ private: OutputSection *ctorsSec; OutputSection *dtorsSec; - // The first and last .pdata sections in the output file. + // The range of .pdata sections in the output file. // // We need to keep track of the location of .pdata in whichever section it // gets merged into so that we can sort its contents and emit a correct data @@ -320,8 +324,7 @@ private: // are entirely linker-generated we can keep track of their locations using // the chunks that the linker creates. All .pdata chunks come from input // files, so we need to keep track of them separately. - Chunk *firstPdata = nullptr; - Chunk *lastPdata; + ChunkRange pdata; COFFLinkerContext &ctx; }; @@ -1408,8 +1411,8 @@ void Writer::createSymbolAndStringTable() { void Writer::mergeSections() { llvm::TimeTraceScope timeScope("Merge sections"); if (!pdataSec->chunks.empty()) { - firstPdata = pdataSec->chunks.front(); - lastPdata = pdataSec->chunks.back(); + pdata.first = pdataSec->chunks.front(); + pdata.last = pdataSec->chunks.back(); } for (auto &p : ctx.config.merge) { @@ -1665,10 +1668,10 @@ template <typename PEHeaderTy> void Writer::writeHeader() { dir[RESOURCE_TABLE].RelativeVirtualAddress = rsrcSec->getRVA(); dir[RESOURCE_TABLE].Size = rsrcSec->getVirtualSize(); } - if (firstPdata) { - dir[EXCEPTION_TABLE].RelativeVirtualAddress = firstPdata->getRVA(); + if (pdata.first) { + dir[EXCEPTION_TABLE].RelativeVirtualAddress = pdata.first->getRVA(); dir[EXCEPTION_TABLE].Size = - lastPdata->getRVA() + lastPdata->getSize() - firstPdata->getRVA(); + pdata.last->getRVA() + pdata.last->getSize() - pdata.first->getRVA(); } if (relocSec->getVirtualSize()) { dir[BASE_RELOCATION_TABLE].RelativeVirtualAddress = relocSec->getRVA(); @@ -2166,15 +2169,18 @@ void Writer::writeBuildId() { // Sort .pdata section contents according to PE/COFF spec 5.5. template <typename T> -void Writer::sortExceptionTable(Chunk *first, Chunk *last) { +void Writer::sortExceptionTable(ChunkRange &exceptionTable) { + if (!exceptionTable.first) + return; + // We assume .pdata contains function table entries only. auto bufAddr = [&](Chunk *c) { OutputSection *os = ctx.getOutputSection(c); return buffer->getBufferStart() + os->getFileOff() + c->getRVA() - os->getRVA(); }; - uint8_t *begin = bufAddr(first); - uint8_t *end = bufAddr(last) + last->getSize(); + uint8_t *begin = bufAddr(exceptionTable.first); + uint8_t *end = bufAddr(exceptionTable.last) + exceptionTable.last->getSize(); if ((end - begin) % sizeof(T) != 0) { fatal("unexpected .pdata size: " + Twine(end - begin) + " is not a multiple of " + Twine(sizeof(T))); @@ -2198,16 +2204,14 @@ void Writer::sortExceptionTables() { switch (ctx.config.machine) { case AMD64: - if (firstPdata) - sortExceptionTable<EntryX64>(firstPdata, lastPdata); + sortExceptionTable<EntryX64>(pdata); break; case ARMNT: case ARM64: - if (firstPdata) - sortExceptionTable<EntryArm>(firstPdata, lastPdata); + sortExceptionTable<EntryArm>(pdata); break; default: - if (firstPdata) + if (pdata.first) lld::errs() << "warning: don't know how to handle .pdata.\n"; break; } |