diff options
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 211f0de..77df4ac 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -1421,6 +1421,16 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, continue; } + // Custom sections can also belong to COMDAT groups. In this case the + // decriptor's "index" field is the section index (in the final object + // file), but that is not known until after layout, so it must be fixed up + // later + if (const MCSymbolWasm *C = Section.getGroup()) { + Comdats[C->getName()].emplace_back( + WasmComdatEntry{wasm::WASM_COMDAT_SECTION, + static_cast<uint32_t>(CustomSections.size())}); + } + CustomSections.emplace_back(Name, &Section); } } @@ -1799,9 +1809,17 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, DataSectionIndex = writeDataSection(Layout); } - for (auto &CustomSection : CustomSections) { - writeCustomSection(CustomSection, Asm, Layout); + // The Sections in the COMDAT list have placeholder indices (their index among + // custom sections, rather than among all sections). Fix them up here. + for (auto &Group : Comdats) { + for (auto &Entry : Group.second) { + if (Entry.Kind == wasm::WASM_COMDAT_SECTION) { + Entry.Index += SectionCount; + } + } } + for (auto &CustomSection : CustomSections) + writeCustomSection(CustomSection, Asm, Layout); if (Mode != DwoMode::DwoOnly) { writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats); |