diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 1d36d5af..79425dfd 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -298,6 +298,9 @@ -- The "-l" flag is fine for system libraries local links = config.getlinks(cfg, "system", "fullpath") + local static_syslibs = {"-Wl,-Bstatic"} + local shared_syslibs = {} + for _, link in ipairs(links) do if path.isframework(link) then table.insert(result, "-framework " .. path.getbasename(link)) @@ -311,16 +314,26 @@ -- Check link mode preference and set flags for linker accordingly if endswith(name, ":static") then name = string.sub(name, 0, -8) - table.insert(result, "-Wl,-Bstatic -l" .. name .. " -Wl,-Bdynamic") + table.insert(static_syslibs, "-l" .. name) elseif endswith(name, ":shared") then name = string.sub(name, 0, -8) - table.insert(result, "-Wl,-Bdynamic -l" .. name) + table.insert(shared_syslibs, "-l" .. name) else - table.insert(result, "-l" .. name) + table.insert(shared_syslibs, "-l" .. name) end end end + local move = function(a1, a2) + local t = #a2 + for i = 1, #a1 do a2[t + i] = a1[i] end + end + if #static_syslibs > 1 then + table.insert(static_syslibs, "-Wl,-Bdynamic") + move(static_syslibs, result) + end + move(shared_syslibs, result) + return result end diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index 97ae4991..1260210c 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -518,17 +518,17 @@ function suite.linksModePreference_onAllStatic() links { "fs_stub:static", "net_stub:static" } prepare() - test.contains({ "-Wl,-Bstatic -lfs_stub -Wl,-Bdynamic", "-Wl,-Bstatic -lnet_stub -Wl,-Bdynamic" }, gcc.getlinks(cfg)) + test.contains({ "-Wl,-Bstatic", "-lfs_stub", "-Wl,-Bdynamic", "-lnet_stub"}, gcc.getlinks(cfg)) end - function suite.linksModePreference_onStaticThenShared() + function suite.linksModePreference_onStaticAndShared() links { "fs_stub:static", "net_stub" } prepare() - test.contains({ "-Wl,-Bstatic -lfs_stub -Wl,-Bdynamic", "-lnet_stub" }, gcc.getlinks(cfg)) + test.contains({ "-Wl,-Bstatic", "-lfs_stub", "-Wl,-Bdynamic", "-lnet_stub"}, gcc.getlinks(cfg)) end - function suite.linksModePreference_onSharedThenStatic() - links { "fs_stub:shared", "net_stub:static" } + function suite.linksModePreference_onAllShared() + links { "fs_stub:shared", "net_stub:shared" } prepare() - test.contains({ "-Wl,-Bdynamic -lfs_stub", "-Wl,-Bstatic -lnet_stub -Wl,-Bdynamic" }, gcc.getlinks(cfg)) + test.excludes({ "-Wl,-Bstatic" }, gcc.getlinks(cfg)) end