Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for "as_needed" #5628

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions xmake/modules/core/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading