]> granicus.if.org Git - clang/commitdiff
Support cross linking to arm on ubuntu.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 28 Oct 2013 18:52:30 +0000 (18:52 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 28 Oct 2013 18:52:30 +0000 (18:52 +0000)
With this patch we correctly determine that ubuntu's ARM tree is not biarch
and use "lib" istead of "lib32".

Without this patch the search inside the arm tree for the crt files was failing
and we would end up trying to use the i686 ones in lib32.

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

16 files changed:
lib/Driver/ToolChains.cpp
test/Driver/Inputs/fedora_18_tree/etc/redhat-release [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/etc/debian_version [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/lib/.keep [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crt1.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crti.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crtn.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crt1.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crti.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crtn.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtend.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtend.o [new file with mode: 0644]
test/Driver/cross-linux.c
test/Driver/linux-ld.c

index 76794535ba871b1e303238fca58c154143641273..e99c1f0e9ab8f0c31d2c8e072018e78701202c3c 100644 (file)
@@ -2127,9 +2127,9 @@ static bool IsUbuntu(enum Distro Distro) {
   return Distro >= UbuntuHardy && Distro <= UbuntuSaucy;
 }
 
-static Distro DetectDistro(llvm::Triple::ArchType Arch) {
+static Distro DetectDistro(StringRef Prefix, llvm::Triple::ArchType Arch) {
   OwningPtr<llvm::MemoryBuffer> File;
-  if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
+  if (!llvm::MemoryBuffer::getFile(Prefix + "/etc/lsb-release", File)) {
     StringRef Data = File.get()->getBuffer();
     SmallVector<StringRef, 8> Lines;
     Data.split(Lines, "\n");
@@ -2153,7 +2153,7 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) {
     return Version;
   }
 
-  if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
+  if (!llvm::MemoryBuffer::getFile(Prefix + "/etc/redhat-release", File)) {
     StringRef Data = File.get()->getBuffer();
     if (Data.startswith("Fedora release"))
       return Fedora;
@@ -2171,7 +2171,7 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) {
     return UnknownDistro;
   }
 
-  if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
+  if (!llvm::MemoryBuffer::getFile(Prefix + "/etc/debian_version", File)) {
     StringRef Data = File.get()->getBuffer();
     if (Data[0] == '5')
       return DebianLenny;
@@ -2184,13 +2184,13 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) {
     return UnknownDistro;
   }
 
-  if (llvm::sys::fs::exists("/etc/SuSE-release"))
+  if (llvm::sys::fs::exists(Prefix + "/etc/SuSE-release"))
     return OpenSUSE;
 
-  if (llvm::sys::fs::exists("/etc/exherbo-release"))
+  if (llvm::sys::fs::exists(Prefix + "/etc/exherbo-release"))
     return Exherbo;
 
-  if (llvm::sys::fs::exists("/etc/arch-release"))
+  if (llvm::sys::fs::exists(Prefix + "/etc/arch-release"))
     return ArchLinux;
 
   return UnknownDistro;
@@ -2265,9 +2265,14 @@ static void addPathIfExists(Twine Path, ToolChain::path_list &Paths) {
 }
 
 static StringRef getMultilibDir(const llvm::Triple &Triple,
+                                bool IsBiarch,
                                 const ArgList &Args) {
-  if (!isMipsArch(Triple.getArch()))
+  if (!isMipsArch(Triple.getArch())) {
+    if (!IsBiarch)
+      return "lib";
+
     return Triple.isArch32Bit() ? "lib32" : "lib64";
+  }
 
   // lib32 directory has a special meaning on MIPS targets.
   // It contains N32 ABI binaries. Use this folder if produce
@@ -2297,7 +2302,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
 
   Linker = GetProgramPath("ld");
 
-  Distro Distro = DetectDistro(Arch);
+  Distro Distro = DetectDistro(SysRoot, Arch);
 
   if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) {
     ExtraOpts.push_back("-z");
@@ -2346,8 +2351,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   // possible permutations of these directories, and seeing which ones it added
   // to the link paths.
   path_list &Paths = getFilePaths();
+  bool IsBiarch;
+  if (IsRedhat(Distro))
+    IsBiarch = true;
+  else if (GCCInstallation.isValid())
+    IsBiarch = !GCCInstallation.getBiarchSuffix().empty();
+  else
+    IsBiarch = true; // FIXME: is this a reasonable fallback?
 
-  const std::string Multilib = getMultilibDir(Triple, Args);
+  const std::string Multilib = getMultilibDir(Triple, IsBiarch, Args);
   const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot);
 
   // Add the multilib suffixed paths where they are available.
@@ -2419,7 +2431,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     // Add the non-multilib suffixed paths (if potentially different).
     const std::string &LibPath = GCCInstallation.getParentLibPath();
     const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
-    if (!GCCInstallation.getBiarchSuffix().empty())
+    if (IsBiarch)
       addPathIfExists(GCCInstallation.getInstallPath() +
                       GCCInstallation.getMultiLibSuffix(), Paths);
 
diff --git a/test/Driver/Inputs/fedora_18_tree/etc/redhat-release b/test/Driver/Inputs/fedora_18_tree/etc/redhat-release
new file mode 100644 (file)
index 0000000..5006ba3
--- /dev/null
@@ -0,0 +1 @@
+Fedora release 18 (Spherical Cow)
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/etc/debian_version b/test/Driver/Inputs/x86-64_ubuntu_13.10/etc/debian_version
new file mode 100644 (file)
index 0000000..743272a
--- /dev/null
@@ -0,0 +1 @@
+wheezy/sid
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/lib/.keep b/test/Driver/Inputs/x86-64_ubuntu_13.10/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crt1.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crt1.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crti.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crti.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crtn.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabi/lib/crtn.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crt1.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crt1.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crti.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crti.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crtn.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crtn.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtbegin.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtend.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtend.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtbegin.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtend.o b/test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtend.o
new file mode 100644 (file)
index 0000000..e69de29
index 3013d80f4c1ee54408636b976c3a1b3d096417bc..3d4384813939faa3b86eb13d204902bad5cbc334 100644 (file)
@@ -36,7 +36,7 @@
 // CHECK-MULTI32-I386: "-m" "elf_i386"
 // CHECK-MULTI32-I386: "crti.o" "[[gcc_install:.*/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0]]{{/|\\\\}}crtbegin.o"
 // CHECK-MULTI32-I386: "-L[[gcc_install]]"
-// CHECK-MULTI32-I386: "-L[[gcc_install]]/../../../../i386-unknown-linux/lib/../lib32"
+// CHECK-MULTI32-I386: "-L[[gcc_install]]/../../../../i386-unknown-linux/lib/../lib"
 // CHECK-MULTI32-I386: "-L[[gcc_install]]/../../../../i386-unknown-linux/lib"
 // CHECK-MULTI32-I386: "-L[[sysroot]]/lib"
 // CHECK-MULTI32-I386: "-L[[sysroot]]/usr/lib"
@@ -89,7 +89,7 @@
 // CHECK-MULTI64-X86-64: "-m" "elf_x86_64"
 // CHECK-MULTI64-X86-64: "crti.o" "[[gcc_install:.*/Inputs/multilib_64bit_linux_tree/usr/lib/gcc/x86_64-unknown-linux/4.6.0]]{{/|\\\\}}crtbegin.o"
 // CHECK-MULTI64-X86-64: "-L[[gcc_install]]"
-// CHECK-MULTI64-X86-64: "-L[[gcc_install]]/../../../../x86_64-unknown-linux/lib/../lib64"
+// CHECK-MULTI64-X86-64: "-L[[gcc_install]]/../../../../x86_64-unknown-linux/lib/../lib"
 // CHECK-MULTI64-X86-64: "-L[[gcc_install]]/../../../../x86_64-unknown-linux/lib"
 // CHECK-MULTI64-X86-64: "-L[[sysroot]]/lib"
 // CHECK-MULTI64-X86-64: "-L[[sysroot]]/usr/lib"
index 729a117ac15d7269198f8788a198eb25e8d24dd8..eb7737a4e9517f91000fc6f87e31053c7bd17c5e 100644 (file)
 // CHECK-32-TO-32: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-32-TO-32: "{{.*}}/usr/lib/gcc/i386-unknown-linux/4.6.0{{/|\\\\}}crtbegin.o"
 // CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0"
-// CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../../../i386-unknown-linux/lib/../lib32"
-// CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../../../lib32"
-// CHECK-32-TO-32: "-L[[SYSROOT]]/lib/../lib32"
-// CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/../lib32"
+// CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../../../i386-unknown-linux/lib/../lib"
+// CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../../../lib"
+// CHECK-32-TO-32: "-L[[SYSROOT]]/lib/../lib"
+// CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/../lib"
 // CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../../../i386-unknown-linux/lib"
 // CHECK-32-TO-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../.."
 // CHECK-32-TO-32: "-L[[SYSROOT]]/lib"
 // CHECK-64-TO-64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-64-TO-64: "{{.*}}/usr/lib/gcc/x86_64-unknown-linux/4.6.0{{/|\\\\}}crtbegin.o"
 // CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0"
-// CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../x86_64-unknown-linux/lib/../lib64"
-// CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../lib64"
-// CHECK-64-TO-64: "-L[[SYSROOT]]/lib/../lib64"
-// CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/../lib64"
+// CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../x86_64-unknown-linux/lib/../lib"
+// CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../lib"
+// CHECK-64-TO-64: "-L[[SYSROOT]]/lib/../lib"
+// CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/../lib"
 // CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../x86_64-unknown-linux/lib"
 // CHECK-64-TO-64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../.."
 // CHECK-64-TO-64: "-L[[SYSROOT]]/lib"
 // CHECK-UBUNTU-12-04-ARM-HF: "{{.*}}/usr/lib/gcc/arm-linux-gnueabihf/4.6.3{{/|\\\\}}crtend.o"
 // CHECK-UBUNTU-12-04-ARM-HF: "{{.*}}/usr/lib/gcc/arm-linux-gnueabihf/4.6.3/../../../arm-linux-gnueabihf{{/|\\\\}}crtn.o"
 //
+// Check Ubuntu 13.10 on x86-64 targeting arm-linux-gnueabihf.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     --target=arm-linux-gnueabihf \
+// RUN:     --sysroot=%S/Inputs/x86-64_ubuntu_13.10 \
+// RUN:   | FileCheck --check-prefix=CHECK-X86-64-UBUNTU-13-10-ARM-HF %s
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-dynamic-linker" "/lib/ld-linux-armhf.so.3"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/crt1.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/crti.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtbegin.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-L[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-L[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-L[[SYSROOT]]/lib/../lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-L[[SYSROOT]]/usr/lib/../lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-L[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtend.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/crtn.o"
+//
+// Check Ubuntu 13.10 on x86-64 targeting arm-linux-gnueabi.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     --target=arm-linux-gnueabi \
+// RUN:     --sysroot=%S/Inputs/x86-64_ubuntu_13.10 \
+// RUN:   | FileCheck --check-prefix=CHECK-X86-64-UBUNTU-13-10-ARM %s
+// CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "-dynamic-linker" "/lib/ld-linux.so.3"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/crt1.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/crti.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtbegin.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "-L[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabi/4.7"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "-L[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "-L[[SYSROOT]]/lib/../lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "-L[[SYSROOT]]/usr/lib/../lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "-L[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/crtend.o"
+// CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/../lib/crtn.o"
+//
 // Check fedora 18 on arm.
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=armv7-unknown-linux-gnueabihf \