diff options
| author | ruki <[email protected]> | 2025-12-21 21:10:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-21 21:10:02 +0800 |
| commit | 2b56c8ee2256fe007d9be131cf1cb9e1126fcf26 (patch) | |
| tree | bca4813aec296ad20515d558d69ae2365966211e /core/src/xmake/binutils/rpath.c | |
| parent | b6f59585662d051459b6660d397a9b41941738da (diff) | |
only add rpath_clean
Diffstat (limited to 'core/src/xmake/binutils/rpath.c')
| -rw-r--r-- | core/src/xmake/binutils/rpath.c | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/core/src/xmake/binutils/rpath.c b/core/src/xmake/binutils/rpath.c index 9cb8c4a3b..d67b88923 100644 --- a/core/src/xmake/binutils/rpath.c +++ b/core/src/xmake/binutils/rpath.c @@ -38,11 +38,7 @@ tb_bool_t xm_binutils_elf_rpath_list(tb_stream_ref_t istream, tb_hize_t base_offset, lua_State *lua); tb_bool_t xm_binutils_macho_rpath_list(tb_stream_ref_t istream, tb_hize_t base_offset, lua_State *lua); -tb_bool_t xm_binutils_elf_rpath_insert(tb_stream_ref_t istream, tb_hize_t base_offset, tb_char_t const* rpath); -tb_bool_t xm_binutils_macho_rpath_insert(tb_stream_ref_t istream, tb_hize_t base_offset, tb_char_t const* rpath); -tb_bool_t xm_binutils_elf_rpath_remove(tb_stream_ref_t istream, tb_hize_t base_offset, tb_char_t const* rpath); -tb_bool_t xm_binutils_macho_rpath_remove(tb_stream_ref_t istream, tb_hize_t base_offset, tb_char_t const* rpath); tb_bool_t xm_binutils_elf_rpath_clean(tb_stream_ref_t istream, tb_hize_t base_offset); tb_bool_t xm_binutils_macho_rpath_clean(tb_stream_ref_t istream, tb_hize_t base_offset); @@ -119,136 +115,6 @@ tb_int_t xm_binutils_rpath_list(lua_State *lua) { return ok ? 1 : 2; } -/* insert rpath to binary file - * - * @param lua the lua state - * @return 1 on success, 2 on failure - */ -tb_int_t xm_binutils_rpath_insert(lua_State *lua) { - tb_assert_and_check_return_val(lua, 0); - - // get arguments - tb_char_t const *binaryfile = luaL_checkstring(lua, 1); - tb_char_t const *rpath = luaL_checkstring(lua, 2); - tb_check_return_val(binaryfile && rpath, 0); - - // open file - tb_stream_ref_t istream = tb_stream_init_from_file(binaryfile, TB_FILE_MODE_RW); - if (!istream) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_insert: open %s failed", binaryfile); - return 2; - } - - tb_bool_t ok = tb_false; - do { - if (!tb_stream_open(istream)) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_insert: open %s failed", binaryfile); - break; - } - - // detect format - tb_int_t format = xm_binutils_detect_format(istream); - if (format < 0) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_insert: cannot detect file format"); - break; - } - - // insert rpath - if (format == XM_BINUTILS_FORMAT_ELF) { - if (!xm_binutils_elf_rpath_insert(istream, 0, rpath)) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_insert: failed to insert to ELF"); - break; - } - } else if (format == XM_BINUTILS_FORMAT_MACHO) { - if (!xm_binutils_macho_rpath_insert(istream, 0, rpath)) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_insert: failed to insert to Mach-O"); - break; - } - } else { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_insert: format not supported"); - break; - } - - lua_pushboolean(lua, tb_true); - ok = tb_true; - - } while (0); - - if (istream) tb_stream_exit(istream); - return ok ? 1 : 2; -} - -/* remove rpath from binary file - * - * @param lua the lua state - * @return 1 on success, 2 on failure - */ -tb_int_t xm_binutils_rpath_remove(lua_State *lua) { - tb_assert_and_check_return_val(lua, 0); - - // get arguments - tb_char_t const *binaryfile = luaL_checkstring(lua, 1); - tb_char_t const *rpath = luaL_checkstring(lua, 2); - tb_check_return_val(binaryfile && rpath, 0); - - // open file - tb_stream_ref_t istream = tb_stream_init_from_file(binaryfile, TB_FILE_MODE_RW); - if (!istream) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_remove: open %s failed", binaryfile); - return 2; - } - - tb_bool_t ok = tb_false; - do { - if (!tb_stream_open(istream)) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_remove: open %s failed", binaryfile); - break; - } - - // detect format - tb_int_t format = xm_binutils_detect_format(istream); - if (format < 0) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_remove: cannot detect file format"); - break; - } - - // remove rpath - if (format == XM_BINUTILS_FORMAT_ELF) { - if (!xm_binutils_elf_rpath_remove(istream, 0, rpath)) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_remove: failed to remove from ELF"); - break; - } - } else if (format == XM_BINUTILS_FORMAT_MACHO) { - if (!xm_binutils_macho_rpath_remove(istream, 0, rpath)) { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_remove: failed to remove from Mach-O"); - break; - } - } else { - lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_remove: format not supported"); - break; - } - - lua_pushboolean(lua, tb_true); - ok = tb_true; - - } while (0); - - if (istream) tb_stream_exit(istream); - return ok ? 1 : 2; -} - /* clean all rpaths from binary file * * @param lua the lua state |
