From f79b0bdf6a2f5365c3fb932929aa1b5de91d33e8 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Tue, 6 Dec 2016 15:23:31 +0300 Subject: [PATCH] Changed link stage from using "clang++" to "clang -lc++abi". --- backend.native/tests/build.gradle | 61 ++++++++++++++++++------------- build.gradle | 3 +- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index a3334d2b01e..e9d7458ea2d 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -104,41 +104,44 @@ abstract class KonanTest extends DefaultTask { return project.isLinux() } - // TODO: stop copy-pasting - protected String linkDl() { + protected List linkCppAbi() { + if (linux()) { + return ["-Wl,-Bstatic", "-lc++abi", "-Wl,-Bdynamic"] + } else { + // Life is hard. MacOS linker is harder. + // This is how we force the linker to link statically. + return ["${project.llvmDir}/lib/libc++abi.a"] + } + } + + protected List linkPlatform() { if (linux()) { - return "-ldl" + return ["-ldl", "-lpthread", "-lm", "-rdynamic"] } else { - return "" + return [] } } - protected String linkM() { - if (linux()) { - return "-lm" - } - else { - return "" - } + protected List libLink() { + def libs = [] + libs.addAll(linkPlatform()) + libs.addAll(linkCppAbi()) + return libs } - protected String rdynamic() { - if (linux()) { - return "-rdynamic" - } - else { - return "" - } - } } class UnitKonanTest extends KonanTest { void compileTest(File sourceS, File runtimeS, File stdlibKtBc, File exe) { def testC = sourceS.absolutePath.replace(".kt.S", "-test.c") project.execClang { - commandLine "clang++", runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, - "-o", exe.absolutePath, linkDl(), linkM(), rdynamic(), '-xc', testC, mainC + executable "clang" + def argList = [] + argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, + "-o", exe.absolutePath, testC, mainC ]) + argList.addAll(libLink()) + args argList } } } @@ -146,8 +149,12 @@ class UnitKonanTest extends KonanTest { class RunKonanTest extends KonanTest { void compileTest(File sourceS, File runtimeS, File libraryPath, File exe) { project.execClang { - commandLine "clang++", launcherBc.absolutePath, startKtBc.absolutePath, runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, - "-o", exe.absolutePath, linkDl(), linkM(), rdynamic(), '-xc' + executable "clang" + def argList = [] + argList.addAll([ launcherBc.absolutePath, startKtBc.absolutePath, + runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, "-o", exe.absolutePath ]) + argList.addAll(libLink()) + args argList } } } @@ -202,8 +209,12 @@ class LinkKonanTest extends KonanTest { void compileTest(File sourceS, File runtimeS, File stdlibKtBc, File exe) { def testC = sourceS.absolutePath.replace(".kt.S", "-test.c") project.execClang { - commandLine "clang++", runtimeS.absolutePath, stdlibKtBc.absolutePath, sourceS.absolutePath, - "-o", exe.absolutePath, linkDl(), rdynamic(), '-xc', testC, mainC + executable "clang" + def argList = [] + argList.addAll([ runtimeS.absolutePath, stdlibKtBc.absolutePath, + sourceS.absolutePath, "-o", exe.absolutePath, testC, mainC ]) + argList.addAll(libLink()) + args argList } } diff --git a/build.gradle b/build.gradle index cd1cbe2daeb..402cbfb5c35 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,8 @@ allprojects { binDir = "$gccToolchainDir/$gnuTriplet/bin" ext.clangArgs.addAll([ "--sysroot=$gccToolchainDir/$gnuTriplet/sysroot", - "--gcc-toolchain=$gccToolchainDir" + "--gcc-toolchain=$gccToolchainDir", + "-L$llvmDir/lib" ]) } else { binDir = "$sysrootDir/usr/bin"