summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-09-18 00:23:52 +0800
committerGitHub <[email protected]>2024-09-18 00:23:52 +0800
commitecfd44b5e5e0ca0d9f7ce5e592d870399f2bd4fe (patch)
tree702f72410222bfc4a15f4614df5f5b5911514b46
parent971318d9d33ab5190745cb4a86b4c75e916e72e4 (diff)
parentd78cfadb369f46b0c6b04dfdea4454909a144442 (diff)
Merge pull request #5628 from KkemChen/dev
add support for "as_needed"
-rw-r--r--xmake/modules/core/tools/gcc.lua30
1 files changed, 20 insertions, 10 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 569f13756..97b826b68 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -358,20 +358,30 @@ function nf_linkgroup(self, linkgroup, opt)
local flags = {}
local extra = opt.extra
if extra and not self:is_plat("macosx", "windows", "mingw") then
- local group = extra.group
+ local as_needed = extra.as_needed
local whole = extra.whole
- if group and whole then
- -- https://github.com/xmake-io/xmake/issues/4308
- table.join2(flags, "-Wl,--whole-archive", "-Wl,--start-group", linkflags, "-Wl,--end-group", "-Wl,--no-whole-archive")
- elseif group then
- table.join2(flags, "-Wl,--start-group", linkflags, "-Wl,--end-group")
- elseif whole then
- table.join2(flags, "-Wl,--whole-archive", linkflags, "-Wl,--no-whole-archive")
- end
+ local group = extra.group
local static = extra.static
+ local prefix_flags = {}
+ local suffix_flags = {}
if static then
- table.join2(flags, "-Wl,-Bstatic", linkflags, "-Wl,-Bdynamic")
+ table.insert(prefix_flags, "-Wl,-Bstatic")
+ table.insert(suffix_flags, 1, "-Wl,-Bdynamic")
+ end
+ if as_needed then
+ -- https://github.com/xmake-io/xmake/issues/5621
+ table.insert(prefix_flags, "-Wl,--as-needed")
+ table.insert(suffix_flags, 1, "-Wl,--no-as-needed")
+ end
+ if whole then
+ table.insert(prefix_flags, "-Wl,--whole-archive")
+ table.insert(suffix_flags, 1, "-Wl,--no-whole-archive")
+ end
+ if group then
+ table.insert(prefix_flags, "-Wl,--start-group")
+ table.insert(suffix_flags, 1, "-Wl,--end-group")
end
+ table.join2(flags, prefix_flags, linkflags, suffix_flags)
end
if #flags == 0 then
flags = linkflags