Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save loicmolinari/356725c4a0ece43c66301cd83fcd0271 to your computer and use it in GitHub Desktop.

Select an option

Save loicmolinari/356725c4a0ece43c66301cd83fcd0271 to your computer and use it in GitHub Desktop.
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 3155c206..7ffc2c6d 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -809,13 +809,17 @@ void BinaryWriter::WriteLinkingSection() {
}
}
stream_->WriteU8Enum(sym.type, "symbol type");
- WriteU32Leb128(stream_, is_defined ? 0 : WABT_SYMBOL_FLAG_UNDEFINED,
+ WriteU32Leb128(stream_, is_defined ?
+ WABT_SYMBOL_FLAG_HIDDEN : WABT_SYMBOL_FLAG_UNDEFINED,
"symbol flags");
WriteU32Leb128(stream_, sym.element_index, "element index");
if (is_defined) {
if (sym.type == SymbolType::Function) {
- WriteStr(stream_, module_->funcs[sym.element_index]->name,
- "function name", PrintChars::Yes);
+ string_view name =
+ static_cast<string_view>(module_->funcs[sym.element_index]->name);
+ assert(name.front() == '$');
+ name.remove_prefix(1);
+ WriteStr(stream_, name, "function name", PrintChars::Yes);
} else if (sym.type == SymbolType::Global) {
WriteStr(stream_, module_->globals[sym.element_index]->name,
"global name", PrintChars::Yes);
@@ -1162,6 +1166,13 @@ Result BinaryWriter::WriteModule() {
}
if (options_.relocatable) {
+ Index num_funcs = module_->funcs.size() - module_->num_func_imports;
+ if (num_funcs) {
+ for (size_t i = 0; i < num_funcs; ++i) {
+ GetSymbolIndex(RelocType::FuncIndexLEB, i + module_->num_func_imports);
+ }
+ }
+
WriteLinkingSection();
for (RelocSection& section : reloc_sections_) {
WriteRelocSection(&section);
diff --git a/src/common.h b/src/common.h
index 476431c9..36e4773e 100644
--- a/src/common.h
+++ b/src/common.h
@@ -259,6 +259,7 @@ enum class SymbolType {
};
#define WABT_SYMBOL_FLAG_UNDEFINED 0x10
+#define WABT_SYMBOL_FLAG_HIDDEN 0x4
#define WABT_SYMBOL_MASK_VISIBILITY 0x4
#define WABT_SYMBOL_MASK_BINDING 0x3
#define WASM_SYMBOL_EXPLICIT_NAME 0x40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment