From 8704d6bc2902e9d41b3918bb06b3d9e4da411ec9 Mon Sep 17 00:00:00 2001 From: KkemChen Date: Tue, 17 Sep 2024 10:27:47 +0800 Subject: [PATCH 1/2] add support for "as_needed" --- xmake/modules/core/tools/gcc.lua | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 569f1375682..9376f3bc66e 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 + tabel.join2(flags, prefix_flags, linkflags, suffix_flags) end if #flags == 0 then flags = linkflags From d78cfadb369f46b0c6b04dfdea4454909a144442 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 17 Sep 2024 21:21:12 +0800 Subject: [PATCH 2/2] Update gcc.lua --- xmake/modules/core/tools/gcc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 9376f3bc66e..97b826b68c7 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -381,7 +381,7 @@ function nf_linkgroup(self, linkgroup, opt) table.insert(prefix_flags, "-Wl,--start-group") table.insert(suffix_flags, 1, "-Wl,--end-group") end - tabel.join2(flags, prefix_flags, linkflags, suffix_flags) + table.join2(flags, prefix_flags, linkflags, suffix_flags) end if #flags == 0 then flags = linkflags