diff options
Diffstat (limited to 'core/src/xmake')
| -rw-r--r-- | core/src/xmake/binutils/elf/rpath.c | 30 | ||||
| -rw-r--r-- | core/src/xmake/binutils/rpath.c | 22 |
2 files changed, 34 insertions, 18 deletions
diff --git a/core/src/xmake/binutils/elf/rpath.c b/core/src/xmake/binutils/elf/rpath.c index b238ad42f..539c8a018 100644 --- a/core/src/xmake/binutils/elf/rpath.c +++ b/core/src/xmake/binutils/elf/rpath.c @@ -204,17 +204,33 @@ tb_bool_t xm_binutils_elf_rpath_clean(tb_stream_ref_t istream, tb_hize_t base_of if (!tb_stream_seek(istream, base_offset)) break; if (!tb_stream_bread(istream, ident, sizeof(ident))) break; - // build ELF context and cleanup rpath entries + /* build ELF context to locate the .dynamic section + * + * @note we only need dynamic_offset/dynamic_size here (strtab is not used + * when removing entries by tag), so we do not require get_context to fully succeed. + */ xm_elf_context_t ctx; + tb_memset(&ctx, 0, sizeof(ctx)); if (ident[XM_ELF_EI_CLASS] == XM_ELF_CLASS32) { - if (xm_binutils_elf_get_context_32(istream, base_offset, &ctx)) { - if (xm_binutils_elf_rpath_clean_impl(istream, base_offset, &ctx)) ok = tb_true; - } + xm_binutils_elf_get_context_32(istream, base_offset, &ctx); } else if (ident[XM_ELF_EI_CLASS] == XM_ELF_CLASS64) { - if (xm_binutils_elf_get_context_64(istream, base_offset, &ctx)) { - if (xm_binutils_elf_rpath_clean_impl(istream, base_offset, &ctx)) ok = tb_true; - } + xm_binutils_elf_get_context_64(istream, base_offset, &ctx); + } else { + break; } + + /* no .dynamic section? e.g. a fully static executable (-static), + * there is no rpath/runpath to clean, so just treat it as a no-op success. + * + * @see https://github.com/xmake-io/xmake/issues/7595 + */ + if (ctx.dynamic_offset == 0 || ctx.dynamic_size == 0) { + ok = tb_true; + break; + } + + // remove DT_RPATH/DT_RUNPATH entries + ok = xm_binutils_elf_rpath_clean_impl(istream, base_offset, &ctx); } while (0); return ok; } diff --git a/core/src/xmake/binutils/rpath.c b/core/src/xmake/binutils/rpath.c index c720141c2..b3b7f5c3a 100644 --- a/core/src/xmake/binutils/rpath.c +++ b/core/src/xmake/binutils/rpath.c @@ -61,7 +61,7 @@ tb_int_t xm_binutils_rpath_list(lua_State *lua) { tb_stream_ref_t istream = tb_stream_init_from_file(binaryfile, TB_FILE_MODE_RO); if (!istream) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_list: open %s failed", binaryfile); + lua_pushfstring(lua, "open %s failed", binaryfile); return 2; } @@ -69,7 +69,7 @@ tb_int_t xm_binutils_rpath_list(lua_State *lua) { do { if (!tb_stream_open(istream)) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_list: open %s failed", binaryfile); + lua_pushfstring(lua, "open %s failed", binaryfile); break; } @@ -77,7 +77,7 @@ tb_int_t xm_binutils_rpath_list(lua_State *lua) { tb_int_t format = xm_binutils_format_detect(istream); if (format < 0) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_list: cannot detect file format"); + lua_pushfstring(lua, "cannot detect file format"); break; } @@ -89,14 +89,14 @@ tb_int_t xm_binutils_rpath_list(lua_State *lua) { if (!xm_binutils_elf_rpath_list(istream, 0, lua)) { lua_pop(lua, 1); // pop table lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_list: failed to parse ELF"); + lua_pushfstring(lua, "failed to parse ELF"); break; } } else if (format == XM_BINUTILS_FORMAT_MACHO) { if (!xm_binutils_macho_rpath_list(istream, 0, lua)) { lua_pop(lua, 1); // pop table lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_list: failed to parse Mach-O"); + lua_pushfstring(lua, "failed to parse Mach-O"); break; } } else { @@ -129,7 +129,7 @@ tb_int_t xm_binutils_rpath_clean(lua_State *lua) { 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_clean: open %s failed", binaryfile); + lua_pushfstring(lua, "open %s failed", binaryfile); return 2; } @@ -137,7 +137,7 @@ tb_int_t xm_binutils_rpath_clean(lua_State *lua) { do { if (!tb_stream_open(istream)) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_clean: open %s failed", binaryfile); + lua_pushfstring(lua, "open %s failed", binaryfile); break; } @@ -145,7 +145,7 @@ tb_int_t xm_binutils_rpath_clean(lua_State *lua) { tb_int_t format = xm_binutils_format_detect(istream); if (format < 0) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_clean: cannot detect file format"); + lua_pushfstring(lua, "cannot detect file format"); break; } @@ -153,18 +153,18 @@ tb_int_t xm_binutils_rpath_clean(lua_State *lua) { if (format == XM_BINUTILS_FORMAT_ELF) { if (!xm_binutils_elf_rpath_clean(istream, 0)) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_clean: failed to clean ELF"); + lua_pushfstring(lua, "failed to clean ELF"); break; } } else if (format == XM_BINUTILS_FORMAT_MACHO) { if (!xm_binutils_macho_rpath_clean(istream, 0)) { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_clean: failed to clean Mach-O"); + lua_pushfstring(lua, "failed to clean Mach-O"); break; } } else { lua_pushboolean(lua, tb_false); - lua_pushfstring(lua, "rpath_clean: format not supported"); + lua_pushfstring(lua, "format not supported"); break; } |
