summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-reader-logging.cc10
-rw-r--r--src/binary-reader-logging.h5
-rw-r--r--src/binary-reader-nop.h8
-rw-r--r--src/binary-reader-objdump.cc9
-rw-r--r--src/binary-reader.cc19
-rw-r--r--src/binary-reader.h6
-rw-r--r--src/binary.h1
-rw-r--r--test/binary/target-features-section.txt28
8 files changed, 85 insertions, 1 deletions
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index fb3d3840..1776a9ba 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -584,6 +584,12 @@ Result BinaryReaderLogging::OnReloc(RelocType type,
return reader_->OnReloc(type, offset, index, addend);
}
+Result BinaryReaderLogging::OnFeature(uint8_t prefix, string_view name) {
+ LOGF("OnFeature(prefix: '%c', name: '" PRIstringview "')\n", prefix,
+ WABT_PRINTF_STRING_VIEW_ARG(name));
+ return reader_->OnFeature(prefix, name);
+}
+
Result BinaryReaderLogging::OnDataSymbol(Index index,
uint32_t flags,
string_view name,
@@ -902,6 +908,10 @@ DEFINE_INDEX(OnDylinkExportCount)
DEFINE_INDEX(OnDylinkImportCount)
DEFINE_END(EndDylinkSection)
+DEFINE_BEGIN(BeginTargetFeaturesSection)
+DEFINE_INDEX(OnFeatureCount)
+DEFINE_END(EndTargetFeaturesSection)
+
DEFINE_BEGIN(BeginLinkingSection)
DEFINE_INDEX(OnSymbolCount)
DEFINE_INDEX(OnSegmentInfoCount)
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index e15801b5..1c3117db 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -332,6 +332,11 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnDylinkExport(string_view name, uint32_t flags) override;
Result EndDylinkSection() override;
+ Result BeginTargetFeaturesSection(Offset size) override;
+ Result OnFeatureCount(Index count) override;
+ Result OnFeature(uint8_t prefix, string_view name) override;
+ Result EndTargetFeaturesSection() override;
+
Result BeginLinkingSection(Offset size) override;
Result OnSymbolCount(Index count) override;
Result OnDataSymbol(Index index,
diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h
index d7c46d31..5e5151a9 100644
--- a/src/binary-reader-nop.h
+++ b/src/binary-reader-nop.h
@@ -477,6 +477,14 @@ class BinaryReaderNop : public BinaryReaderDelegate {
}
Result EndDylinkSection() override { return Result::Ok; }
+ /* target_features section */
+ Result BeginTargetFeaturesSection(Offset size) override { return Result::Ok; }
+ Result OnFeatureCount(Index count) override { return Result::Ok; }
+ Result OnFeature(uint8_t prefix, string_view name) override {
+ return Result::Ok;
+ }
+ Result EndTargetFeaturesSection() override { return Result::Ok; }
+
/* Linking section */
Result BeginLinkingSection(Offset size) override { return Result::Ok; }
Result OnSymbolCount(Index count) override { return Result::Ok; }
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index 7cca4505..9b451c9b 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -986,6 +986,8 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Index index,
uint32_t addend) override;
+ Result OnFeature(uint8_t prefix, string_view name) override;
+
Result OnSymbolCount(Index count) override;
Result OnDataSymbol(Index index,
uint32_t flags,
@@ -1022,7 +1024,6 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnComdatCount(Index count) override;
Result OnComdatBegin(string_view name, uint32_t flags, Index count) override;
Result OnComdatEntry(ComdatType kind, Index index) override;
- Result EndLinkingSection() override { return Result::Ok; }
Result OnTagCount(Index count) override;
Result OnTagType(Index index, Index sig_index) override;
@@ -1842,6 +1843,12 @@ Result BinaryReaderObjdump::OnReloc(RelocType type,
return Result::Ok;
}
+Result BinaryReaderObjdump::OnFeature(uint8_t prefix, string_view name) {
+ PrintDetails(" - [%c] " PRIstringview "\n", prefix,
+ WABT_PRINTF_STRING_VIEW_ARG(name));
+ return Result::Ok;
+}
+
Result BinaryReaderObjdump::OnSymbolCount(Index count) {
PrintDetails(" - symbol table [count=%d]\n", count);
return Result::Ok;
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index d8dcce70..3f42b8f2 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -132,6 +132,7 @@ class BinaryReader {
Result ReadRelocSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadDylinkSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadDylink0Section(Offset section_size) WABT_WARN_UNUSED;
+ Result ReadTargetFeaturesSections(Offset section_size) WABT_WARN_UNUSED;
Result ReadLinkingSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadCustomSection(Index section_index,
Offset section_size) WABT_WARN_UNUSED;
@@ -2057,6 +2058,22 @@ Result BinaryReader::ReadDylinkSection(Offset section_size) {
return Result::Ok;
}
+Result BinaryReader::ReadTargetFeaturesSections(Offset section_size) {
+ CALLBACK(BeginTargetFeaturesSection, section_size);
+ uint32_t count;
+ CHECK_RESULT(ReadU32Leb128(&count, "sym count"));
+ CALLBACK(OnFeatureCount, count);
+ while (count--) {
+ uint8_t prefix;
+ string_view name;
+ CHECK_RESULT(ReadU8(&prefix, "prefix"));
+ CHECK_RESULT(ReadStr(&name, "feature name"));
+ CALLBACK(OnFeature, prefix, name);
+ }
+ CALLBACK0(EndTargetFeaturesSection);
+ return Result::Ok;
+}
+
Result BinaryReader::ReadLinkingSection(Offset section_size) {
CALLBACK(BeginLinkingSection, section_size);
uint32_t version;
@@ -2236,6 +2253,8 @@ Result BinaryReader::ReadCustomSection(Index section_index,
} else if (section_name.rfind(WABT_BINARY_SECTION_RELOC, 0) == 0) {
// Reloc sections always begin with "reloc."
CHECK_RESULT(ReadRelocSection(section_size));
+ } else if (section_name == WABT_BINARY_SECTION_TARGET_FEATURES) {
+ CHECK_RESULT(ReadTargetFeaturesSections(section_size));
} else if (section_name == WABT_BINARY_SECTION_LINKING) {
CHECK_RESULT(ReadLinkingSection(section_size));
} else {
diff --git a/src/binary-reader.h b/src/binary-reader.h
index ce090622..98cfa62d 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -405,6 +405,12 @@ class BinaryReaderDelegate {
virtual Result OnDylinkNeeded(string_view so_name) = 0;
virtual Result EndDylinkSection() = 0;
+ /* target_features section */
+ virtual Result BeginTargetFeaturesSection(Offset size) = 0;
+ virtual Result OnFeatureCount(Index count) = 0;
+ virtual Result OnFeature(uint8_t prefix, string_view name) = 0;
+ virtual Result EndTargetFeaturesSection() = 0;
+
/* Linking section */
virtual Result BeginLinkingSection(Offset size) = 0;
virtual Result OnSymbolCount(Index count) = 0;
diff --git a/src/binary.h b/src/binary.h
index c6757820..72322cb0 100644
--- a/src/binary.h
+++ b/src/binary.h
@@ -31,6 +31,7 @@
#define WABT_BINARY_SECTION_NAME "name"
#define WABT_BINARY_SECTION_RELOC "reloc"
#define WABT_BINARY_SECTION_LINKING "linking"
+#define WABT_BINARY_SECTION_TARGET_FEATURES "target_features"
#define WABT_BINARY_SECTION_DYLINK "dylink"
#define WABT_BINARY_SECTION_DYLINK0 "dylink.0"
diff --git a/test/binary/target-features-section.txt b/test/binary/target-features-section.txt
new file mode 100644
index 00000000..3a39ab48
--- /dev/null
+++ b/test/binary/target-features-section.txt
@@ -0,0 +1,28 @@
+;;; TOOL: run-objdump-gen-wasm
+;;; ARGS: -x
+magic
+version
+section("target_features") {
+ count[3]
+ prefix['-']
+ str("foo")
+ prefix['+']
+ str("bar")
+ prefix['=']
+ str("baz")
+}
+(;; STDOUT ;;;
+
+target-features-section.wasm: file format wasm 0x1
+
+Section Details:
+
+Custom:
+ - name: "target_features"
+ - [-] foo
+ - [+] bar
+ - [=] baz
+
+Code Disassembly:
+
+;;; STDOUT ;;)