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 | |
| parent | 790140eab69420769d87040a72b12f2642a43979 (diff) | |
improve binutils.format to support wasm
| -rw-r--r-- | core/src/xmake/binutils/format.c | 10 | ||||
| -rw-r--r-- | core/src/xmake/binutils/prefix.h | 1 | ||||
| -rw-r--r-- | tests/modules/binutils/test.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/binutils.lua | 2 |
4 files changed, 15 insertions, 2 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) diff --git a/tests/modules/binutils/test.lua b/tests/modules/binutils/test.lua index bbb466144..b26e2b337 100644 --- a/tests/modules/binutils/test.lua +++ b/tests/modules/binutils/test.lua @@ -44,6 +44,10 @@ function test_format(t) io.writefile(ar, "!<arch>\n") t:are_equal(binutils.format(ar), "ar") + local wasmso = path.join(tempdir, "libfoo.so") + io.writefile(wasmso, string.char(0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)) + t:are_equal(binutils.format(wasmso), "wasm") + local elf = path.join(tempdir, "a.elf") io.writefile(elf, string.char(0x7f, string.byte("E"), string.byte("L"), string.byte("F"), 0, 0, 0, 0)) t:are_equal(binutils.format(elf), "elf") diff --git a/xmake/core/sandbox/modules/import/core/base/binutils.lua b/xmake/core/sandbox/modules/import/core/base/binutils.lua index 0fc2b6796..a3b9428b6 100644 --- a/xmake/core/sandbox/modules/import/core/base/binutils.lua +++ b/xmake/core/sandbox/modules/import/core/base/binutils.lua @@ -82,8 +82,6 @@ function sandbox_core_base_binutils.rpath_list(binaryfile) end end --- insert rpath to binary file (auto-detect format: ELF or Mach-O) - -- clean rpaths from binary file (auto-detect format: ELF or Mach-O) function sandbox_core_base_binutils.rpath_clean(binaryfile) local ok, errors = binutils.rpath_clean(binaryfile) |
