[PATCH] Support cross compiling to arm on ubuntu.

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Sun Oct 27 08:02:42 PDT 2013


  Add a missing .keep

Hi chandlerc, logan,

http://llvm-reviews.chandlerc.com/D2031

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2031?vs=5176&id=5178#toc

Files:
  lib/Driver/ToolChains.cpp
  test/Driver/Inputs/fedora_18_tree/etc/redhat-release
  test/Driver/Inputs/x86-64_ubuntu_13.10/etc/debian_version
  test/Driver/Inputs/x86-64_ubuntu_13.10/lib/.keep
  test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crt1.o
  test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crti.o
  test/Driver/Inputs/x86-64_ubuntu_13.10/usr/arm-linux-gnueabihf/lib/crtn.o
  test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtbegin.o
  test/Driver/Inputs/x86-64_ubuntu_13.10/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/crtend.o
  test/Driver/cross-linux.c
  test/Driver/linux-ld.c

Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -2127,9 +2127,9 @@
   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 @@
     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 @@
     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 @@
     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 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 @@
 
   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 @@
   // 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 @@
     // 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);
 
Index: test/Driver/Inputs/fedora_18_tree/etc/redhat-release
===================================================================
--- /dev/null
+++ test/Driver/Inputs/fedora_18_tree/etc/redhat-release
@@ -0,0 +1 @@
+Fedora release 18 (Spherical Cow)
Index: test/Driver/Inputs/x86-64_ubuntu_13.10/etc/debian_version
===================================================================
--- /dev/null
+++ test/Driver/Inputs/x86-64_ubuntu_13.10/etc/debian_version
@@ -0,0 +1 @@
+wheezy/sid
Index: test/Driver/cross-linux.c
===================================================================
--- test/Driver/cross-linux.c
+++ test/Driver/cross-linux.c
@@ -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: test/Driver/linux-ld.c
===================================================================
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -86,10 +86,10 @@
 // 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"
@@ -119,10 +119,10 @@
 // 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"
@@ -245,6 +245,24 @@
 // 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 fedora 18 on arm.
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=armv7-unknown-linux-gnueabihf \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2031.2.patch
Type: text/x-patch
Size: 9810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131027/cb130df8/attachment.bin>


More information about the cfe-commits mailing list