From 008285a797c969ab1a5addac9b44f93a0063c4f3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 21 Dec 2023 16:49:29 +0000 Subject: Don't assume relocatable section is CODE --- .../wasm/structure/binary/WasmBinaryWriter.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java index c8fc458b..14393722 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java @@ -118,11 +118,14 @@ public class WasmBinaryWriter { WasmRelocatableIndex index ) throws IOException { // TODO: handle custom sections? - var isRelocatable = currentSection - .map(c -> c == WasmSectionId.CODE || c == WasmSectionId.DATA) - .orElse(false); - - if (isRelocatable) { + var relocatableSectionName = currentSection + .flatMap(c -> switch (c) { + case CODE -> Optional.of("CODE"); + case DATA -> Optional.of("DATA"); + default -> Optional.empty(); + }); + + if (relocatableSectionName.isPresent()) { var value = unrelocatedIndex.orElse(0); var sectionContentsOffset = writer.position() - sectionContentsStart; if (relocationType.isSigned()) { @@ -132,8 +135,10 @@ public class WasmBinaryWriter { } if (!relocationSections.containsKey(sectionIndex)) { - // TODO: don't assume CODE - relocationSections.put(sectionIndex, WasmRelocationSection.empty(sectionIndex, "CODE")); + relocationSections.put(sectionIndex, WasmRelocationSection.empty( + sectionIndex, + relocatableSectionName.get() + )); } relocationSections.get(sectionIndex).addEntry(new WasmRelocationEntry( relocationType, -- cgit v1.2.3