diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binary-reader-logging.cc | 2 | ||||
-rw-r--r-- | src/binary-reader-logging.h | 2 | ||||
-rw-r--r-- | src/binary-reader-nop.h | 4 | ||||
-rw-r--r-- | src/binary-reader-objdump.cc | 12 | ||||
-rw-r--r-- | src/binary-reader.cc | 12 | ||||
-rw-r--r-- | src/binary-reader.h | 2 | ||||
-rw-r--r-- | src/binary-writer.cc | 1 | ||||
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/tools/wasm-link.cc | 34 |
9 files changed, 67 insertions, 4 deletions
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc index 9a2d4e9a..2d0ada8f 100644 --- a/src/binary-reader-logging.cc +++ b/src/binary-reader-logging.cc @@ -602,6 +602,8 @@ DEFINE_INDEX_INDEX(OnInitExprGetGlobalExpr, "index", "global_index") DEFINE_BEGIN(BeginLinkingSection) DEFINE_INDEX(OnSymbolInfoCount) DEFINE_INDEX(OnStackGlobal) +DEFINE_INDEX(OnDataSize) +DEFINE_INDEX(OnDataAlignment) DEFINE_END(EndLinkingSection) DEFINE_BEGIN(BeginExceptionSection); diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h index 6256bff2..6726ed07 100644 --- a/src/binary-reader-logging.h +++ b/src/binary-reader-logging.h @@ -235,6 +235,8 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result OnStackGlobal(Index stack_global) override; Result OnSymbolInfo(string_view name, uint32_t flags) override; Result OnSymbolInfoCount(Index count) override; + Result OnDataSize(uint32_t data_size) override; + Result OnDataAlignment(uint32_t data_alignment) override; Result EndLinkingSection() override; Result BeginExceptionSection(Offset size) override; diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h index 2faa18cf..2fa57bbd 100644 --- a/src/binary-reader-nop.h +++ b/src/binary-reader-nop.h @@ -332,6 +332,10 @@ class BinaryReaderNop : public BinaryReaderDelegate { Result OnSymbolInfo(string_view name, uint32_t flags) override { return Result::Ok; } + Result OnDataSize(uint32_t data_size) override { return Result::Ok; } + Result OnDataAlignment(uint32_t data_alignment) override { + return Result::Ok; + } Result EndLinkingSection() override { return Result::Ok; } /* InitExpr - used by elem, data and global sections; these functions are diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 5fe39adb..9baf3938 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -547,6 +547,8 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase { Result OnStackGlobal(Index stack_global) override; Result OnSymbolInfoCount(Index count) override; Result OnSymbolInfo(string_view name, uint32_t flags) override; + Result OnDataSize(uint32_t data_size) override; + Result OnDataAlignment(uint32_t data_alignment) override; Result OnExceptionCount(Index count) override; Result OnExceptionType(Index index, TypeVector& sig) override; @@ -1110,6 +1112,16 @@ Result BinaryReaderObjdump::OnExceptionType( return Result::Ok; } +Result BinaryReaderObjdump::OnDataSize(uint32_t data_size) { + PrintDetails(" - data size : %d\n", data_size); + return Result::Ok; +} + +Result BinaryReaderObjdump::OnDataAlignment(uint32_t data_alignment) { + PrintDetails(" - data align: %d\n", data_alignment); + return Result::Ok; +} + } // end anonymous namespace Result ReadBinaryObjdump(const uint8_t* data, diff --git a/src/binary-reader.cc b/src/binary-reader.cc index c484ae4d..a48cadcd 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -1264,6 +1264,18 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) { } break; } + case LinkingEntryType::DataSize: { + uint32_t data_size; + CHECK_RESULT(ReadU32Leb128(&data_size, "data size")); + CALLBACK(OnDataSize, data_size); + break; + } + case LinkingEntryType::DataAlignment: { + uint32_t data_alignment; + CHECK_RESULT(ReadU32Leb128(&data_alignment, "data alignment")); + CALLBACK(OnDataAlignment, data_alignment); + break; + } default: /* unknown subsection, skip it */ state_.offset = subsection_end; diff --git a/src/binary-reader.h b/src/binary-reader.h index b96ecb8a..0494ffd3 100644 --- a/src/binary-reader.h +++ b/src/binary-reader.h @@ -283,6 +283,8 @@ class BinaryReaderDelegate { virtual Result OnStackGlobal(Index stack_global) = 0; virtual Result OnSymbolInfoCount(Index count) = 0; virtual Result OnSymbolInfo(string_view name, uint32_t flags) = 0; + virtual Result OnDataSize(uint32_t data_size) = 0; + virtual Result OnDataAlignment(uint32_t data_alignment) = 0; virtual Result EndLinkingSection() = 0; /* Exception section */ diff --git a/src/binary-writer.cc b/src/binary-writer.cc index 7be8ecb8..8627e377 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -1033,7 +1033,6 @@ Result BinaryWriter::WriteModule(const Module* module) { } } - return stream_.result(); } diff --git a/src/common.h b/src/common.h index 2b14c242..76722cba 100644 --- a/src/common.h +++ b/src/common.h @@ -225,6 +225,8 @@ struct Reloc { enum class LinkingEntryType { StackPointer = 1, SymbolInfo = 2, + DataSize = 3, + DataAlignment = 4, }; enum class SymbolBinding { diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc index f00b9603..b8758f85 100644 --- a/src/tools/wasm-link.cc +++ b/src/tools/wasm-link.cc @@ -218,6 +218,7 @@ class Linker { void WriteDataSegment(const DataSegment& segment, Address offset); void WriteDataSection(const SectionPtrVector& sections, Index total_count); void WriteNamesSection(); + void WriteLinkingSection(uint32_t data_size, uint32_t data_alignment); void WriteRelocSection(BinarySection section_code, const SectionPtrVector& sections); bool WriteCombinedSection(BinarySection section_code, @@ -484,6 +485,30 @@ void Linker::WriteNamesSection() { FixupSize(fixup_section); } +void Linker::WriteLinkingSection(uint32_t data_size, uint32_t data_alignment) { + stream_.WriteU8Enum(BinarySection::Custom, "section code"); + auto fixup = WriteUnknownSize(); + + WriteStr(&stream_, "linking", "linking section name"); + + { + WriteU32Leb128Enum(&stream_, LinkingEntryType::DataSize, "subsection code"); + auto fixup_subsection = WriteUnknownSize(); + WriteU32Leb128(&stream_, data_size, "data size"); + FixupSize(fixup_subsection); + } + + { + WriteU32Leb128Enum(&stream_, LinkingEntryType::DataAlignment, + "subsection code"); + auto fixup_subsection = WriteUnknownSize(); + WriteU32Leb128(&stream_, data_alignment, "data alignment"); + FixupSize(fixup_subsection); + } + + FixupSize(fixup); +} + void Linker::WriteRelocSection(BinarySection section_code, const SectionPtrVector& sections) { Index total_relocs = 0; @@ -723,9 +748,12 @@ void Linker::WriteBinary() { WriteNamesSection(); - // Generate a new set of reloction sections. - for (size_t i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) { - WriteRelocSection(static_cast<BinarySection>(i), sections[i]); + /* Generate a new set of reloction sections */ + if (s_relocatable) { + WriteLinkingSection(0, 0); + for (size_t i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) { + WriteRelocSection(static_cast<BinarySection>(i), sections[i]); + } } } |