summaryrefslogtreecommitdiff
path: root/src/binary-reader-objdump.c
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2017-01-20 11:43:38 -0800
committerGitHub <noreply@github.com>2017-01-20 11:43:38 -0800
commit4a139e085cfc2e04776530ab714aa2cf4f01b56d (patch)
treed9e8d638a5d0e930c0c49e197453bd30a42868e7 /src/binary-reader-objdump.c
parent86d121eb85f4e75fb0207bd5a13891e3d4de7ee9 (diff)
downloadwabt-4a139e085cfc2e04776530ab714aa2cf4f01b56d.tar.gz
wabt-4a139e085cfc2e04776530ab714aa2cf4f01b56d.tar.bz2
wabt-4a139e085cfc2e04776530ab714aa2cf4f01b56d.zip
Add symbol resolution to wasm-link (#271)
Symbols exported by one module can now be consumed by another module at link time. Imports that can be resolved at link time are removed the output. Any unresolved imported remaining in the output binary are considered and error unless the -r flag is passed. Also split binary reading logic out of wasm-link.c into its own binary-reader-linker file.
Diffstat (limited to 'src/binary-reader-objdump.c')
-rw-r--r--src/binary-reader-objdump.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/binary-reader-objdump.c b/src/binary-reader-objdump.c
index 0c67e39b..cdc8f88d 100644
--- a/src/binary-reader-objdump.c
+++ b/src/binary-reader-objdump.c
@@ -23,9 +23,14 @@
#include "binary-reader.h"
#include "literal.h"
+#include "vector.h"
+
+typedef uint32_t Uint32;
+WASM_DEFINE_VECTOR(uint32, Uint32);
typedef struct Context {
const WasmObjdumpOptions* options;
+ WasmAllocator* allocator;
WasmStream* out_stream;
const uint8_t* data;
size_t size;
@@ -37,11 +42,13 @@ typedef struct Context {
WasmBool header_printed;
int section_found;
+ uint32_t section_starts[WASM_NUM_BINARY_SECTIONS];
+ WasmBinarySection reloc_section;
+
WasmStringSlice import_module_name;
WasmStringSlice import_field_name;
} Context;
-
static WasmBool should_print_details(Context* ctx) {
if (ctx->options->mode != WASM_DUMP_DETAILS)
return WASM_FALSE;
@@ -97,8 +104,10 @@ static WasmResult do_begin_section(Context* ctx,
static WasmResult begin_section(WasmBinaryReaderContext* ctx,
WasmBinarySection type,
uint32_t size) {
- return do_begin_section(ctx->user_data, wasm_get_section_name(type),
- ctx->offset, size);
+ Context* context = ctx->user_data;
+ context->section_starts[type] = ctx->offset;
+ return do_begin_section(context, wasm_get_section_name(type), ctx->offset,
+ size);
}
static WasmResult begin_custom_section(WasmBinaryReaderContext* ctx,
@@ -565,12 +574,24 @@ static WasmResult on_local_name(uint32_t func_index,
return WASM_OK;
}
+WasmResult on_reloc_count(uint32_t count,
+ WasmBinarySection section_code,
+ WasmStringSlice section_name,
+ void* user_data) {
+ Context* ctx = user_data;
+ ctx->reloc_section = section_code;
+ print_details(user_data, " - section: %s\n",
+ wasm_get_section_name(section_code));
+ return WASM_OK;
+}
+
WasmResult on_reloc(WasmRelocType type,
- uint32_t section,
uint32_t offset,
void* user_data) {
- print_details(user_data, " - %-20s section=%d offset=%#x\n",
- wasm_get_reloc_type_name(type), section, offset);
+ Context* ctx = user_data;
+ uint32_t total_offset = ctx->section_starts[ctx->reloc_section] + offset;
+ print_details(user_data, " - %-18s offset=%#x (%#x)\n",
+ wasm_get_reloc_type_name(type), total_offset, offset);
return WASM_OK;
}
@@ -665,6 +686,7 @@ static WasmBinaryReader s_binary_reader = {
.on_function_name = on_function_name,
.on_local_name = on_local_name,
+ .on_reloc_count = on_reloc_count,
.on_reloc = on_reloc,
.on_init_expr_i32_const_expr = on_init_expr_i32_const_expr,
@@ -683,6 +705,7 @@ WasmResult wasm_read_binary_objdump(struct WasmAllocator* allocator,
reader = s_binary_reader;
Context context;
WASM_ZERO_MEMORY(context);
+ context.allocator = allocator;
context.header_printed = WASM_FALSE;
context.print_details = WASM_FALSE;
context.section_found = WASM_FALSE;