From 82473183a567d6e1f332230486da64ca524575b6 Mon Sep 17 00:00:00 2001 From: yuyoyuppe Date: Fri, 15 Jan 2016 18:46:05 +0600 Subject: [PATCH 1/4] feature + tests --- src/tools/gcc.lua | 17 ++++++++++++++--- tests/tools/test_gcc.lua | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index c1263231..1d36d5af 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -297,7 +297,6 @@ end -- The "-l" flag is fine for system libraries - local links = config.getlinks(cfg, "system", "fullpath") for _, link in ipairs(links) do if path.isframework(link) then @@ -305,7 +304,20 @@ elseif path.isobjectfile(link) then table.insert(result, link) else - table.insert(result, "-l" .. path.getname(link)) + local endswith = function(s, ptrn) + return ptrn == string.sub(s, -string.len(ptrn)) + end + local name = path.getname(link) + -- 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") + elseif endswith(name, ":shared") then + name = string.sub(name, 0, -8) + table.insert(result, "-Wl,-Bdynamic -l" .. name) + else + table.insert(result, "-l" .. name) + end end end @@ -360,4 +372,3 @@ end return nil end - diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index 59d3aecd..97ae4991 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -510,3 +510,25 @@ prepare() test.contains("-flto", gcc.getldflags(cfg)) end + + +-- +-- Check link mode preference for system libraries. +-- + 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)) + end + + function suite.linksModePreference_onStaticThenShared() + links { "fs_stub:static", "net_stub" } + prepare() + 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" } + prepare() + test.contains({ "-Wl,-Bdynamic -lfs_stub", "-Wl,-Bstatic -lnet_stub -Wl,-Bdynamic" }, gcc.getlinks(cfg)) + end From 196d46a412ac96f51cf6948cad93797bb20c5430 Mon Sep 17 00:00:00 2001 From: yuyoyuppe Date: Fri, 15 Jan 2016 22:02:01 +0600 Subject: [PATCH 2/4] add grouping by link mode --- src/tools/gcc.lua | 19 ++++++++++++++++--- tests/tools/test_gcc.lua | 12 ++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) 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 From df8c2fd36e2c545e4ca4771fa78d2086247ab0b7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 15 Jan 2016 21:08:30 +0500 Subject: [PATCH 3/4] minor format fix --- src/tools/gcc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 79425dfd..645b54d0 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -331,7 +331,7 @@ if #static_syslibs > 1 then table.insert(static_syslibs, "-Wl,-Bdynamic") move(static_syslibs, result) - end + end move(shared_syslibs, result) return result From 618f9227a33e4b9ec300f8b5f0ee0e90c3fc85ed Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 16 Jan 2016 11:46:38 +0500 Subject: [PATCH 4/4] cosmetic fix --- src/tools/gcc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 645b54d0..97a617dd 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -308,10 +308,10 @@ table.insert(result, link) else local endswith = function(s, ptrn) - return ptrn == string.sub(s, -string.len(ptrn)) + return ptrn == string.sub(s, -string.len(ptrn)) end local name = path.getname(link) - -- Check link mode preference and set flags for linker accordingly + -- Check whether link mode decorator is present if endswith(name, ":static") then name = string.sub(name, 0, -8) table.insert(static_syslibs, "-l" .. name)