[PATCH][Solaris] Add -lc also when linking shared libraries
Xan López via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 10:22:03 PDT 2015
On Mon, Sep 07, 2015 at 09:07:41AM -0700, Saleem Abdulrasool wrote:
> > Basically check that -lc is present when clang is called in a certain
> > way I guess? Or something more sophisticated?
>
>
> Yeah, that it is present when a DSO or executable is linked.
Right, maybe something like this. Patch attached.
(If it seems fine please commit it for me, I do not have commit
rights)
Xan
-------------- next part --------------
>From b73b50ebd8d14aebc71b5480ad0f33ccf15c5885 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Xan=20L=C3=B3pez?= <xan at igalia.com>
Date: Mon, 17 Aug 2015 16:04:26 +0200
Subject: [PATCH] [Solaris] Add -lc also when linking shared libraries
This is actually needed, otherwise libc won't be added at all. For
instance when building libclang.so all the libc symbols won't be
found, with ld warning about libc being an "implicit dependency".
---
lib/Driver/Tools.cpp | 2 +-
test/Driver/solaris-ld.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 867d201..a4d6ee8 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -6965,9 +6965,9 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (getToolChain().getDriver().CCCIsCXX())
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lgcc_s");
+ CmdArgs.push_back("-lc");
if (!Args.hasArg(options::OPT_shared)) {
CmdArgs.push_back("-lgcc");
- CmdArgs.push_back("-lc");
CmdArgs.push_back("-lm");
}
}
diff --git a/test/Driver/solaris-ld.c b/test/Driver/solaris-ld.c
index 0e1b89f..d871b59 100644
--- a/test/Driver/solaris-ld.c
+++ b/test/Driver/solaris-ld.c
@@ -14,3 +14,20 @@
// CHECK: "{{.*}}/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2{{/|\\\\}}crtbegin.o"
// CHECK: "{{.*}}/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2{{/|\\\\}}crtend.o"
// CHECK: "{{.*}}/usr/lib/crtn.o"
+// CHECK "-lc"
+// CHECK "-lgcc_s"
+// CHECK "-lgcc"
+// CHECK "-lm"
+
+// Check the right -l flags are present with -shared
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o -shared 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/sparc-sun-solaris2.11 \
+// RUN: | FileCheck --check-prefix=CHECK-SHARED %s
+
+// CHECK-SHARED: ld{{.*}}"
+// CHECK-SHARED "-lc"
+// CHECK-SHARED "-lgcc_s"
+// CHECK-SHARED-NOT "-lgcc"
+// CHECK-SHARED-NOT: "-lm"
--
2.4.3
More information about the cfe-commits
mailing list