[lld][COFF] Fix bug causing assertion in Chunk::setAlignment

Reinstate use of FakeSection class to avoid constructing SectionChunk
from unintialised coff_section in FakeSectionChunk constructor.

Issue was caused by commit 5a58b19f9c93f3ac51bcde318508131ae78aa10c,
"[LLD] Remove global state in lld/COFF".
This commit is contained in:
Andrew Ng 2023-01-10 14:03:48 +00:00
parent 264976d98e
commit 85a2f29fd4
3 changed files with 15 additions and 5 deletions

View File

@ -19,8 +19,10 @@
namespace lld::coff {
COFFLinkerContext::COFFLinkerContext()
: driver(*this), symtab(*this),
ltoTextSectionChunk(llvm::COFF::IMAGE_SCN_MEM_EXECUTE),
ltoDataSectionChunk(llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA),
ltoTextSection(llvm::COFF::IMAGE_SCN_MEM_EXECUTE),
ltoDataSection(llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA),
ltoTextSectionChunk(&ltoTextSection.section),
ltoDataSectionChunk(&ltoDataSection.section),
rootTimer("Total Linking Time"),
inputFileTimer("Input File Reading", rootTimer),
ltoTimer("LTO", rootTimer), gcTimer("GC", rootTimer),

View File

@ -56,6 +56,8 @@ public:
}
// Fake sections for parsing bitcode files.
FakeSection ltoTextSection;
FakeSection ltoDataSection;
FakeSectionChunk ltoTextSectionChunk;
FakeSectionChunk ltoDataSectionChunk;

View File

@ -715,18 +715,24 @@ void applyArm64Addr(uint8_t *off, uint64_t s, uint64_t p, int shift);
void applyArm64Imm(uint8_t *off, uint64_t imm, uint32_t rangeLimit);
void applyArm64Branch26(uint8_t *off, int64_t v);
// Convenience class for initializing a coff_section with specific flags.
class FakeSection {
public:
FakeSection(int c) { section.Characteristics = c; }
coff_section section;
};
// Convenience class for initializing a SectionChunk with specific flags.
class FakeSectionChunk {
public:
FakeSectionChunk(int c) : chunk(nullptr, &section) {
section.Characteristics = c;
FakeSectionChunk(const coff_section *section) : chunk(nullptr, section) {
// Comdats from LTO files can't be fully treated as regular comdats
// at this point; we don't know what size or contents they are going to
// have, so we can't do proper checking of such aspects of them.
chunk.selection = llvm::COFF::IMAGE_COMDAT_SELECT_ANY;
}
coff_section section;
SectionChunk chunk;
};