]> granicus.if.org Git - clang/commitdiff
Do not use "lib32" directory to create a library/object files
authorSimon Atanasyan <satanasyan@mips.com>
Fri, 14 Sep 2012 11:27:24 +0000 (11:27 +0000)
committerSimon Atanasyan <satanasyan@mips.com>
Fri, 14 Sep 2012 11:27:24 +0000 (11:27 +0000)
paths when target is MIPS 32-bit.

The patch reviewed by Chandler Carruth.

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

14 files changed:
lib/Driver/ToolChains.cpp
test/Driver/Inputs/debian_6_mips_tree/lib/.keep [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/lib32/.keep [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/lib64/.keep [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib/crt1.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib/crti.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/64/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/n32/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib32/crt1.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib32/crti.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib64/crt1.o [new file with mode: 0644]
test/Driver/Inputs/debian_6_mips_tree/usr/lib64/crti.o [new file with mode: 0644]
test/Driver/linux-ld.c

index d6bd0a80d4848fbfbe4e2f81ac803041af031215..0fd520284030ae4416cafd5199efd90dba9d57b6 100644 (file)
@@ -2037,6 +2037,28 @@ static void addPathIfExists(Twine Path, ToolChain::path_list &Paths) {
   if (llvm::sys::fs::exists(Path)) Paths.push_back(Path.str());
 }
 
+static bool isMipsArch(llvm::Triple::ArchType Arch) {
+  return Arch == llvm::Triple::mips ||
+         Arch == llvm::Triple::mipsel ||
+         Arch == llvm::Triple::mips64 ||
+         Arch == llvm::Triple::mips64el;
+}
+
+static StringRef getMultilibDir(const llvm::Triple &Triple,
+                                const ArgList &Args) {
+  if (!isMipsArch(Triple.getArch()))
+    return Triple.isArch32Bit() ? "lib32" : "lib64";
+
+  // lib32 directory has a special meaning on MIPS targets.
+  // It contains N32 ABI binaries. Use this folder if produce
+  // code for N32 ABI only.
+  Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
+  if (A && (A->getValue(Args) == StringRef("n32")))
+    return "lib32";
+
+  return Triple.isArch32Bit() ? "lib" : "lib64";
+}
+
 Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   : Generic_ELF(D, Triple, Args) {
   llvm::Triple::ArchType Arch = Triple.getArch();
@@ -2060,11 +2082,6 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
     ExtraOpts.push_back("-X");
 
-  const bool IsMips = Arch == llvm::Triple::mips ||
-                      Arch == llvm::Triple::mipsel ||
-                      Arch == llvm::Triple::mips64 ||
-                      Arch == llvm::Triple::mips64el;
-
   const bool IsAndroid = Triple.getEnvironment() == llvm::Triple::Android;
 
   // Do not use 'gnu' hash style for Mips targets because .gnu.hash
@@ -2072,7 +2089,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS
   // ABI requires a mapping between the GOT and the symbol table.
   // Android loader does not support .gnu.hash.
-  if (!IsMips && !IsAndroid) {
+  if (!isMipsArch(Arch) && !IsAndroid) {
     if (IsRedhat(Distro) || IsOpenSuse(Distro) ||
         (IsUbuntu(Distro) && Distro >= UbuntuMaverick))
       ExtraOpts.push_back("--hash-style=gnu");
@@ -2101,7 +2118,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   // to the link paths.
   path_list &Paths = getFilePaths();
 
-  const std::string Multilib = Triple.isArch32Bit() ? "lib32" : "lib64";
+  const std::string Multilib = getMultilibDir(Triple, Args);
   const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot);
 
   // Add the multilib suffixed paths where they are available.
diff --git a/test/Driver/Inputs/debian_6_mips_tree/lib/.keep b/test/Driver/Inputs/debian_6_mips_tree/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/lib32/.keep b/test/Driver/Inputs/debian_6_mips_tree/lib32/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/lib64/.keep b/test/Driver/Inputs/debian_6_mips_tree/lib64/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib/crt1.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib/crt1.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib/crti.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib/crti.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/64/crtbegin.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/64/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/crtbegin.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/n32/crtbegin.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib/gcc/mipsel-linux-gnu/4.4/n32/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib32/crt1.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib32/crt1.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib32/crti.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib32/crti.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib64/crt1.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib64/crt1.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/debian_6_mips_tree/usr/lib64/crti.o b/test/Driver/Inputs/debian_6_mips_tree/usr/lib64/crti.o
new file mode 100644 (file)
index 0000000..e69de29
index fc7b55858c68d4f217c963e5d268476d07a8f49d..cb2efbbcf316a03f93971a28474da893d39859ff 100644 (file)
 // CHECK-ANDROID-PIE: "-lgcc"
 // CHECK-ANDROID-PIE-NOT: "gcc_s"
 // CHECK-ANDROID-PIE: "{{.*}}/crtend_android.o"
+//
+// Check linker invocation on Debian 6 MIPS 32/64-bit.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target mipsel-linux-gnu \
+// RUN:     --sysroot=%S/Inputs/debian_6_mips_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-DEBIAN-ML-MIPSEL %s
+// CHECK-DEBIAN-ML-MIPSEL: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-DEBIAN-ML-MIPSEL: "{{.*}}/usr/lib/gcc/mipsel-linux-gnu/4.4/../../../../lib/crt1.o"
+// CHECK-DEBIAN-ML-MIPSEL: "{{.*}}/usr/lib/gcc/mipsel-linux-gnu/4.4/../../../../lib/crti.o"
+// CHECK-DEBIAN-ML-MIPSEL: "{{.*}}/usr/lib/gcc/mipsel-linux-gnu/4.4/crtbegin.o"
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/usr/lib/gcc/mipsel-linux-gnu/4.4"
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/usr/lib/gcc/mipsel-linux-gnu/4.4/../../../../lib"
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/lib/../lib"
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/usr/lib/../lib"
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/usr/lib/gcc/mipsel-linux-gnu/4.4/../../.."
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/lib"
+// CHECK-DEBIAN-ML-MIPSEL: "-L[[SYSROOT]]/usr/lib"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     -target mips64el-linux-gnu \
+// RUN:     --sysroot=%S/Inputs/debian_6_mips_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-DEBIAN-ML-MIPS64EL %s
+// CHECK-DEBIAN-ML-MIPS64EL: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-DEBIAN-ML-MIPS64EL: "{{.*}}/usr/lib/gcc/mipsel-linux-gnu/4.4/../../../../lib64/crt1.o"
+// CHECK-DEBIAN-ML-MIPS64EL: "{{.*}}/usr/lib/gcc/mipsel-linux-gnu/4.4/../../../../lib64/crti.o"
+// CHECK-DEBIAN-ML-MIPS64EL: "{{.*}}/usr/lib/gcc/mipsel-linux-gnu/4.4/64/crtbegin.o"
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/usr/lib/gcc/mipsel-linux-gnu/4.4/64"
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/usr/lib/gcc/mipsel-linux-gnu/4.4/../../../../lib64"
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/lib/../lib64"
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/usr/lib/../lib64"
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/usr/lib/gcc/mipsel-linux-gnu/4.4/../../.."
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/lib"
+// CHECK-DEBIAN-ML-MIPS64EL: "-L[[SYSROOT]]/usr/lib"