diff options
| author | ruki <[email protected]> | 2026-02-12 00:41:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-12 00:41:49 +0800 |
| commit | 120bb0b0cf4a046638dca0d408a5bff604d91c9f (patch) | |
| tree | 5efbe1ec971ed7ad0415a226c8f99ee1ede511c8 /core/src | |
| parent | 790140eab69420769d87040a72b12f2642a43979 (diff) | |
improve binutils.format to support wasm
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/binutils/format.c | 10 | ||||
| -rw-r--r-- | core/src/xmake/binutils/prefix.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/core/src/xmake/binutils/format.c b/core/src/xmake/binutils/format.c index dd7e836f3..956340b0a 100644 --- a/core/src/xmake/binutils/format.c +++ b/core/src/xmake/binutils/format.c @@ -91,6 +91,10 @@ static __tb_inline__ tb_bool_t xm_binutils_format_is_ape(tb_byte_t const* first8 first8[4] == 'p' && first8[5] == 'D'; } +static __tb_inline__ tb_bool_t xm_binutils_format_is_wasm(tb_byte_t const* first8) { + return first8[0] == 0x00 && first8[1] == 0x61 && first8[2] == 0x73 && first8[3] == 0x6d; +} + static __tb_inline__ tb_bool_t xm_binutils_format_is_elf(tb_byte_t const* first8) { return first8[0] == 0x7f && first8[1] == 'E' && first8[2] == 'L' && first8[3] == 'F'; } @@ -164,6 +168,11 @@ tb_int_t xm_binutils_format_detect(tb_stream_ref_t istream) { break; } + if (xm_binutils_format_is_wasm(p)) { + format = XM_BINUTILS_FORMAT_WASM; + break; + } + if (xm_binutils_format_is_elf(p)) { format = XM_BINUTILS_FORMAT_ELF; break; @@ -237,6 +246,7 @@ tb_int_t xm_binutils_format(lua_State *lua) { case XM_BINUTILS_FORMAT_PE: lua_pushliteral(lua, "pe"); break; case XM_BINUTILS_FORMAT_SHEBANG: lua_pushliteral(lua, "shebang"); break; case XM_BINUTILS_FORMAT_APE: lua_pushliteral(lua, "ape"); break; + case XM_BINUTILS_FORMAT_WASM: lua_pushliteral(lua, "wasm"); break; default: lua_pushliteral(lua, "unknown"); break; } diff --git a/core/src/xmake/binutils/prefix.h b/core/src/xmake/binutils/prefix.h index b3ffd8c27..608424958 100644 --- a/core/src/xmake/binutils/prefix.h +++ b/core/src/xmake/binutils/prefix.h @@ -36,6 +36,7 @@ #define XM_BINUTILS_FORMAT_PE 5 #define XM_BINUTILS_FORMAT_SHEBANG 6 #define XM_BINUTILS_FORMAT_APE 7 +#define XM_BINUTILS_FORMAT_WASM 8 #define XM_BINUTILS_FORMAT_UNKNOWN 0 // COFF machine types (for format detection) |
