summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-07 14:19:46 +0800
committerruki <[email protected]>2025-12-07 17:16:00 +0800
commit832de3edc75ba2bb1e6ea4f26ee39513f35d4bd4 (patch)
treec4d473bd9d269d2fd559a97e262685565038eeea /xmake/modules
parentb18cf3e29067c0b9159880bf2028eb5555176841 (diff)
add bin2elf
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/utils/bin2obj.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/xmake/modules/private/utils/bin2obj.lua b/xmake/modules/private/utils/bin2obj.lua
index 9b8dfa4c2..caa8b2e22 100644
--- a/xmake/modules/private/utils/bin2obj.lua
+++ b/xmake/modules/private/utils/bin2obj.lua
@@ -63,7 +63,32 @@ function _do_bin2obj_coff(binarypath, outputpath, opt)
end
function _do_bin2obj_elf(binarypath, outputpath, opt)
- raise("bin2obj: ELF format not yet implemented")
+ -- get symbol prefix
+ local symbol_prefix = opt.symbol_prefix or "_binary_"
+
+ -- get architecture (default: x86_64)
+ local arch = opt.arch or "x86_64"
+
+ -- get zeroend (default: false)
+ local zeroend = opt.zeroend or false
+
+ -- get filename from binary path (with extension, dots replaced with underscores)
+ local filename = path.filename(binarypath)
+ -- replace dots with underscores for symbol name (e.g., data.bin -> data_bin)
+ local basename = filename:gsub("%.", "_")
+
+ -- trace
+ print("converting binary file %s to ELF object file %s ..", binarypath, outputpath)
+
+ -- do dump
+ if utils.bin2elf then
+ utils.bin2elf(binarypath, outputpath, symbol_prefix, arch, basename, zeroend)
+ else
+ raise("bin2obj: utils.bin2elf not available (C implementation not compiled)")
+ end
+
+ -- trace
+ cprint("${bright}%s generated!", outputpath)
end
function _do_bin2obj_macho(binarypath, outputpath, opt)