]> granicus.if.org Git - clang/commitdiff
For NetBSD/current on X86 do not use libgcc and default to libc++.
authorJoerg Sonnenberger <joerg@bec.de>
Mon, 14 Oct 2013 20:13:05 +0000 (20:13 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Mon, 14 Oct 2013 20:13:05 +0000 (20:13 +0000)
Adjust linkage to make more sense for older releases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192615 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains.cpp
lib/Driver/Tools.cpp
test/Driver/netbsd.c [new file with mode: 0644]
test/Driver/netbsd.cpp [new file with mode: 0644]

index a2e64f2e9a23c32eaf28c8e51f4cd52b71709c4f..ec0d8f387cd450c0cce357e1b41914ac94362194 100644 (file)
@@ -1982,6 +1982,12 @@ NetBSD::GetCXXStdlibType(const ArgList &Args) const {
       << A->getAsString(Args);
   }
 
+  unsigned Major, Minor, Micro;
+  getTriple().getOSVersion(Major, Minor, Micro);
+  if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 23) || Major == 0) {
+    if (getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64)
+      return ToolChain::CST_Libcxx;
+  }
   return ToolChain::CST_Libstdcxx;
 }
 
index 19767fc29019c90acac6b76796fe0218e57377ec..8cf35e8e26659b8ad0b24651576487b5633b1a10 100644 (file)
@@ -5860,34 +5860,39 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
 
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
 
+  unsigned Major, Minor, Micro;
+  getToolChain().getTriple().getOSVersion(Major, Minor, Micro);
+  bool useLibgcc = true;
+  if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 23) || Major == 0) {
+    if (getToolChain().getArch() == llvm::Triple::x86 ||
+        getToolChain().getArch() == llvm::Triple::x86_64)
+      useLibgcc = false;
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib) &&
       !Args.hasArg(options::OPT_nodefaultlibs)) {
     if (D.CCCIsCXX()) {
       getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
       CmdArgs.push_back("-lm");
     }
-    // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
-    // the default system libraries. Just mimic this for now.
-    if (Args.hasArg(options::OPT_static)) {
-      CmdArgs.push_back("-lgcc_eh");
-    } else {
-      CmdArgs.push_back("--as-needed");
-      CmdArgs.push_back("-lgcc_s");
-      CmdArgs.push_back("--no-as-needed");
-    }
-    CmdArgs.push_back("-lgcc");
-
     if (Args.hasArg(options::OPT_pthread))
       CmdArgs.push_back("-lpthread");
     CmdArgs.push_back("-lc");
 
-    CmdArgs.push_back("-lgcc");
-    if (Args.hasArg(options::OPT_static)) {
-      CmdArgs.push_back("-lgcc_eh");
-    } else {
-      CmdArgs.push_back("--as-needed");
-      CmdArgs.push_back("-lgcc_s");
-      CmdArgs.push_back("--no-as-needed");
+    if (useLibgcc) {
+      if (Args.hasArg(options::OPT_static)) {
+        // libgcc_eh depends on libc, so resolve as much as possible,
+        // pull in any new requirements from libc and then get the rest
+        // of libgcc.
+        CmdArgs.push_back("-lgcc_eh");
+        CmdArgs.push_back("-lc");
+        CmdArgs.push_back("-lgcc");
+      } else {
+        CmdArgs.push_back("-lgcc");
+        CmdArgs.push_back("--as-needed");
+        CmdArgs.push_back("-lgcc_s");
+        CmdArgs.push_back("--no-as-needed");
+      }
     }
   }
 
diff --git a/test/Driver/netbsd.c b/test/Driver/netbsd.c
new file mode 100644 (file)
index 0000000..1ca1360
--- /dev/null
@@ -0,0 +1,45 @@
+// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=X86_64 %s
+// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd7.0.0 %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=X86_64-7 %s
+// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd6.0.0 %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=X86_64-6 %s
+
+// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd %s -static -### 2>&1 \
+// RUN: | FileCheck -check-prefix=S-X86_64 %s
+// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd7.0.0 -static %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=S-X86_64-7 %s
+// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd6.0.0 -static %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=S-X86_64-6 %s
+
+// X86_64: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd"
+// X86_64: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// X86_64: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc"
+// X86_64: "crtend.o" "crtn.o"
+
+// X86_64-7: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd7.0.0"
+// X86_64-7: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// X86_64-7: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc"
+// X86_64-7: "crtend.o" "crtn.o"
+
+// X86_64-6: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd6.0.0"
+// X86_64-6: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// X86_64-6: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc"
+// X86_64-6: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+// X86_64-6: "crtend.o" "crtn.o"
+
+// S-X86_64: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd"
+// S-X86_64: ld{{.*}}" "-Bstatic"
+// S-X86_64: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc"
+// S-X86_64: "crtend.o" "crtn.o"
+
+// S-X86_64-7: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd7.0.0"
+// S-X86_64-7: ld{{.*}}" "-Bstatic"
+// S-X86_64-7: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc"
+// S-X86_64-7: "crtend.o" "crtn.o"
+
+// S-X86_64-6: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd6.0.0"
+// S-X86_64-6: ld{{.*}}" "-Bstatic"
+// S-X86_64-6: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc"
+// S-X86_64-6: "-lgcc_eh" "-lc" "-lgcc"
+// S-X86_64-6: "crtend.o" "crtn.o"
diff --git a/test/Driver/netbsd.cpp b/test/Driver/netbsd.cpp
new file mode 100644 (file)
index 0000000..bb79586
--- /dev/null
@@ -0,0 +1,45 @@
+// RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=X86_64 %s
+// RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd7.0.0 %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=X86_64-7 %s
+// RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd6.0.0 %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=X86_64-6 %s
+
+// RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd %s -static -### 2>&1 \
+// RUN: | FileCheck -check-prefix=S-X86_64 %s
+// RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd7.0.0 -static %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=S-X86_64-7 %s
+// RUN: %clangxx -no-canonical-prefixes -target x86_64--netbsd6.0.0 -static %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=S-X86_64-6 %s
+
+// X86_64: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd"
+// X86_64: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// X86_64: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc++"
+// X86_64: "-lm" "-lc" "crtend.o" "crtn.o"
+
+// X86_64-7: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd7.0.0"
+// X86_64-7: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// X86_64-7: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc++"
+// X86_64-7: "-lm" "-lc" "crtend.o" "crtn.o"
+
+// X86_64-6: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd6.0.0"
+// X86_64-6: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// X86_64-6: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lstdc++"
+// X86_64-6: "-lm" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+// X86_64-6: "crtend.o" "crtn.o"
+
+// S-X86_64: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd"
+// S-X86_64: ld{{.*}}" "-Bstatic"
+// S-X86_64: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc++"
+// S-X86_64: "-lm" "-lc" "crtend.o" "crtn.o"
+
+// S-X86_64-7: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd7.0.0"
+// S-X86_64-7: ld{{.*}}" "-Bstatic"
+// S-X86_64-7: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lc++"
+// S-X86_64-7: "-lm" "-lc" "crtend.o" "crtn.o"
+
+// S-X86_64-6: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd6.0.0"
+// S-X86_64-6: ld{{.*}}" "-Bstatic"
+// S-X86_64-6: "-o" "a.out" "crt0.o" "crti.o" "crtbegin.o" "{{.*}}.o" "-lstdc++"
+// S-X86_64-6: "-lm" "-lc" "-lgcc_eh" "-lc" "-lgcc"
+// S-X86_64-6: "crtend.o" "crtn.o"