summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-09 22:34:36 +0800
committerruki <[email protected]>2025-12-09 22:34:36 +0800
commit5931e48282914758fd7c4eeaf9ca05a16521692b (patch)
treef06ffda22f2675a3e08979503b4bff1de0e08e0f
parent102507b96dab0403592c07c8760644f08ed66dff (diff)
fix compile error
-rw-r--r--core/src/xmake/binutils/elf/prefix.h2
-rw-r--r--xmake/core/base/binutils.lua13
-rw-r--r--xmake/modules/utils/binary/bin2obj.lua14
3 files changed, 20 insertions, 9 deletions
diff --git a/core/src/xmake/binutils/elf/prefix.h b/core/src/xmake/binutils/elf/prefix.h
index d79fe3e11..bd3cc9129 100644
--- a/core/src/xmake/binutils/elf/prefix.h
+++ b/core/src/xmake/binutils/elf/prefix.h
@@ -278,7 +278,7 @@ static __tb_inline__ tb_bool_t xm_binutils_elf_is_64bit(tb_char_t const *arch) {
* @param offset the string offset
* @return the string (static buffer, valid until next call)
*/
-static __tb_inline__ tb_bool_t xm_binutils_elf_read_string(tb_stream_ref_t istream, tb_uint32_t strtab_offset, tb_uint32_t offset, tb_char_t *name, tb_size_t name_size) {
+static __tb_inline__ tb_bool_t xm_binutils_elf_read_string(tb_stream_ref_t istream, tb_uint64_t strtab_offset, tb_uint32_t offset, tb_char_t *name, tb_size_t name_size) {
tb_assert_and_check_return_val(istream && name && name_size > 0, tb_false);
tb_hize_t saved_pos = tb_stream_offset(istream);
diff --git a/xmake/core/base/binutils.lua b/xmake/core/base/binutils.lua
index 995f0d0a7..77b17dc92 100644
--- a/xmake/core/base/binutils.lua
+++ b/xmake/core/base/binutils.lua
@@ -21,6 +21,9 @@
-- define module
local binutils = binutils or {}
+-- load modules
+local os = require("base/os")
+
-- save original interfaces
binutils._bin2c = binutils._bin2c or binutils.bin2c
binutils._bin2coff = binutils._bin2coff or binutils.bin2coff
@@ -55,7 +58,15 @@ function binutils.bin2obj(binaryfile, outputfile, opt)
opt = opt or {}
local format = opt.format
if not format then
- return nil, "bin2obj: format is required (coff, elf, or macho)"
+ -- auto-detect format based on host platform
+ local host = os.host()
+ if host == "windows" or host == "mingw" or host == "msys" or host == "cygwin" then
+ format = "coff"
+ elseif host == "macosx" or host == "iphoneos" or host == "watchos" or host == "appletvos" then
+ format = "macho"
+ else
+ format = "elf"
+ end
end
format = format:lower()
diff --git a/xmake/modules/utils/binary/bin2obj.lua b/xmake/modules/utils/binary/bin2obj.lua
index 7870e2544..95e705ca6 100644
--- a/xmake/modules/utils/binary/bin2obj.lua
+++ b/xmake/modules/utils/binary/bin2obj.lua
@@ -47,17 +47,17 @@ function _do_bin2obj(binarypath, outputpath, opt)
local basename = filename:gsub("%.", "_")
opt.basename = basename
- -- get format (default: coff)
- local format = opt.format or "coff"
- format = format:lower()
-
-- validate format
- if format ~= "coff" and format ~= "elf" and format ~= "macho" then
- raise("bin2obj: unsupported format '%s' (supported: coff, elf, macho)", format)
+ local format = opt.format
+ if format then
+ format = format:lower()
+ if format ~= "coff" and format ~= "elf" and format ~= "macho" then
+ raise("bin2obj: unsupported format '%s' (supported: coff, elf, macho)", format)
+ end
end
-- trace
- print("converting binary file %s to %s object file %s ..", binarypath, format, outputpath)
+ print("converting binary file %s to %s object file %s ..", binarypath, format or "coff", outputpath)
-- do conversion
binutils.bin2obj(binarypath, outputpath, opt)