summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-19 13:48:46 +0800
committerGitHub <[email protected]>2025-12-19 13:48:46 +0800
commit5df20ea1dafb3c19e95b8bcd2df6cbbbf03fde81 (patch)
treed7554bec8522d1be9eb6e7e45953b1d8010bf522 /xmake
parentbbe585b9b8927d71f79f8c723110224e31348381 (diff)
parent68be1c62a74322993a6b21f74476a716cb3a6963 (diff)
Merge pull request #7149 from xmake-io/rpath
Add rpath in binutils
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/binutils.lua10
-rw-r--r--xmake/core/sandbox/modules/import/core/base/binutils.lua10
-rw-r--r--xmake/modules/utils/binary/rpath.lua8
3 files changed, 27 insertions, 1 deletions
diff --git a/xmake/core/base/binutils.lua b/xmake/core/base/binutils.lua
index af71e8ae7..5bed5de21 100644
--- a/xmake/core/base/binutils.lua
+++ b/xmake/core/base/binutils.lua
@@ -31,6 +31,7 @@ binutils._bin2macho = binutils._bin2macho or binutils.bin2macho
binutils._bin2elf = binutils._bin2elf or binutils.bin2elf
binutils._readsyms = binutils._readsyms or binutils.readsyms
binutils._deplibs = binutils._deplibs or binutils.deplibs
+binutils._rpath_list = binutils._rpath_list or binutils.rpath_list
binutils._extractlib = binutils._extractlib or binutils.extractlib
-- generate c/c++ code from the binary file
@@ -111,6 +112,15 @@ function binutils.deplibs(binaryfile)
end
end
+-- get rpath list from binary file (auto-detect format: ELF or Mach-O)
+function binutils.rpath_list(binaryfile)
+ if binutils._rpath_list then
+ return binutils._rpath_list(binaryfile)
+ else
+ return nil, "binutils: internal rpath_list not supported!"
+ end
+end
+
-- extract static library to directory
-- Supports AR format (.a) and MSVC lib format (.lib)
-- @param libraryfile the static library file path (.a or .lib)
diff --git a/xmake/core/sandbox/modules/import/core/base/binutils.lua b/xmake/core/sandbox/modules/import/core/base/binutils.lua
index 11f432340..b7b8a1792 100644
--- a/xmake/core/sandbox/modules/import/core/base/binutils.lua
+++ b/xmake/core/sandbox/modules/import/core/base/binutils.lua
@@ -62,6 +62,16 @@ function sandbox_core_base_binutils.deplibs(binaryfile)
end
end
+-- get rpath list from binary file (auto-detect format: ELF or Mach-O)
+function sandbox_core_base_binutils.rpath_list(binaryfile)
+ local rpaths, errors = binutils.rpath_list(binaryfile)
+ if rpaths then
+ return rpaths
+ else
+ raise("rpath_list: %s", errors or "unknown errors")
+ end
+end
+
-- extract static library to directory
function sandbox_core_base_binutils.extractlib(libraryfile, outputdir, opt)
local ok, errors = binutils.extractlib(libraryfile, outputdir, opt)
diff --git a/xmake/modules/utils/binary/rpath.lua b/xmake/modules/utils/binary/rpath.lua
index 271ef8939..6152d4d14 100644
--- a/xmake/modules/utils/binary/rpath.lua
+++ b/xmake/modules/utils/binary/rpath.lua
@@ -20,6 +20,7 @@
-- imports
import("core.base.option")
+import("core.base.binutils")
import("lib.detect.find_tool")
function _replace_rpath_vars(rpath, opt)
@@ -34,6 +35,10 @@ function _replace_rpath_vars(rpath, opt)
return rpath
end
+function _get_rpath_list_by_binutils(binaryfile, opt)
+ return binutils.rpath_list(binaryfile)
+end
+
function _get_rpath_list_by_objdump(binaryfile, opt)
local list
local plat = opt.plat or os.host()
@@ -296,7 +301,8 @@ function list(binaryfile, opt)
local ops = {
_get_rpath_list_by_objdump,
_get_rpath_list_by_readelf,
- _get_rpath_list_by_patchelf
+ _get_rpath_list_by_patchelf,
+ _get_rpath_list_by_binutils
}
if is_host("macosx") then
table.insert(ops, 1, _get_rpath_list_by_otool)