aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/WasmObjectWriter.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2020-12-04 13:45:42 -0800
committerDerek Schuff <dschuff@chromium.org>2020-12-07 12:12:44 -0800
commit0a391060f16dc3e10bcb0b02036073021c414006 (patch)
treee614e3665e5cda86cc772eaebc2cd5183a31584a /llvm/lib/MC/WasmObjectWriter.cpp
parent5fe1a49f961d7e6a064addf6373288d5e3697e68 (diff)
downloadllvm-0a391060f16dc3e10bcb0b02036073021c414006.zip
llvm-0a391060f16dc3e10bcb0b02036073021c414006.tar.gz
llvm-0a391060f16dc3e10bcb0b02036073021c414006.tar.bz2
[WebAssembly] Add Object and ObjectWriter support for wasm COMDAT sections
Allow sections to be placed into COMDAT groups, in addtion to functions and data segments. Also make section symbols unnamed, which allows sections with identical names (section names are independent of their section symbols, but previously we gave the symbols the same name as their sections, which results in collisions when sections are identically-named). Differential Revision: https://reviews.llvm.org/D92691
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp22
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);