llvm.org GIT mirror llvm / 559201d
[WebAssembly] Update dylink section parsing This updates the format of the dylink section in accordance with recent "spec" change: https://github.com/WebAssembly/tool-conventions/pull/77 Differential Revision: https://reviews.llvm.org/D55609 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348989 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Clegg 8 months ago
8 changed file(s) with 20 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3939 uint32_t MemoryAlignment; // P2 alignment of memory
4040 uint32_t TableSize; // Table size in elements
4141 uint32_t TableAlignment; // P2 alignment of table
42 std::vector Needed; // Shared library depenedencies
4243 };
4344
4445 struct WasmExport {
200200 Triple::ArchType getArch() const override;
201201 SubtargetFeatures getFeatures() const override;
202202 bool isRelocatableObject() const override;
203 bool isSharedObject() const;
203204
204205 struct ReadContext {
205206 const uint8_t *Start;
270271 std::vector DebugNames;
271272 uint32_t StartFunction = -1;
272273 bool HasLinkingSection = false;
274 bool HasDylinkSection = false;
273275 wasm::WasmLinkingData LinkingData;
274276 uint32_t NumImportedGlobals = 0;
275277 uint32_t NumImportedFunctions = 0;
194194 uint32_t MemoryAlignment;
195195 uint32_t TableSize;
196196 uint32_t TableAlignment;
197 std::vector Needed;
197198 };
198199
199200 struct NameSection : CustomSection {
318318 DylinkInfo.MemoryAlignment = readVaruint32(Ctx);
319319 DylinkInfo.TableSize = readVaruint32(Ctx);
320320 DylinkInfo.TableAlignment = readVaruint32(Ctx);
321 uint32_t Count = readVaruint32(Ctx);
322 while (Count--) {
323 DylinkInfo.Needed.push_back(readString(Ctx));
324 }
321325 if (Ctx.Ptr != Ctx.End)
322326 return make_error("dylink section ended prematurely",
323327 object_error::parse_failed);
14041408
14051409 bool WasmObjectFile::isRelocatableObject() const { return HasLinkingSection; }
14061410
1411 bool WasmObjectFile::isSharedObject() const { return HasDylinkSection; }
1412
14071413 const WasmSection &WasmObjectFile::getWasmSection(DataRefImpl Ref) const {
14081414 assert(Ref.d.a < Sections.size());
14091415 return Sections[Ref.d.a];
5454 IO.mapRequired("MemoryAlignment", Section.MemoryAlignment);
5555 IO.mapRequired("TableSize", Section.TableSize);
5656 IO.mapRequired("TableAlignment", Section.TableAlignment);
57 IO.mapRequired("Needed", Section.Needed);
5758 }
5859
5960 static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {
99 MemoryAlignment: 2
1010 TableSize: 1
1111 TableAlignment: 0
12 Needed: [ libfoo.so, libbar.so ]
1213 ...
1314 # CHECK: --- !WASM
1415 # CHECK: FileHeader:
2021 # CHECK: MemoryAlignment: 2
2122 # CHECK: TableSize: 1
2223 # CHECK: TableAlignment: 0
24 # CHECK: Needed:
25 # CHECK: - libfoo.so
26 # CHECK: - libbar.so
2327 # CHECK: ...
5959 DylinkSec->MemoryAlignment = Info.MemoryAlignment;
6060 DylinkSec->TableSize = Info.TableSize;
6161 DylinkSec->TableAlignment = Info.TableAlignment;
62 DylinkSec->Needed = Info.Needed;
6263 CustomSec = std::move(DylinkSec);
6364 } else if (WasmSec.Name == "name") {
6465 std::unique_ptr NameSec =
139139 encodeULEB128(Section.MemoryAlignment, OS);
140140 encodeULEB128(Section.TableSize, OS);
141141 encodeULEB128(Section.TableAlignment, OS);
142 encodeULEB128(Section.Needed.size(), OS);
143 for (StringRef Needed : Section.Needed) {
144 writeStringRef(Needed, OS);
145 }
142146 return 0;
143147 }
144148