Index: clang/lib/Driver/ToolChains/Hurd.cpp =================================================================== --- clang/lib/Driver/ToolChains/Hurd.cpp +++ clang/lib/Driver/ToolChains/Hurd.cpp @@ -63,7 +63,19 @@ Hurd::Hurd(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + Multilibs = GCCInstallation.getMultilibs(); + SelectedMultilib = GCCInstallation.getMultilib(); std::string SysRoot = computeSysRoot(); + ToolChain::path_list &PPaths = getProgramPaths(); + + Generic_GCC::PushPPaths(PPaths); + + // The selection of paths to try here is designed to match the patterns which + // the GCC driver itself uses, as this is part of the GCC-compatible driver. + // This was determined by running GCC in a fake filesystem, creating all + // possible permutations of these directories, and seeing which ones it added + // to the link paths. path_list &Paths = getFilePaths(); const std::string OSLibDir = std::string(getOSLibDir(Triple, Args)); @@ -73,8 +85,11 @@ ExtraOpts.push_back("--build-id"); #endif - // If we are currently running Clang inside of the requested system root, add - // its parent library paths to those searched. + Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths); + + // Similar to the logic for GCC above, if we currently running Clang inside + // of the requested system root, add its parent library paths to + // those searched. // FIXME: It's not clear whether we should use the driver's installed // directory ('Dir' below) or the ResourceDir. if (StringRef(D.Dir).startswith(SysRoot)) { @@ -88,8 +103,11 @@ addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); - // If we are currently running Clang inside of the requested system root, add - // its parent library path to those searched. + Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths); + + // Similar to the logic for GCC above, if we are currently running Clang + // inside of the requested system root, add its parent library path to those + // searched. // FIXME: It's not clear whether we should use the driver's installed // directory ('Dir' below) or the ResourceDir. if (StringRef(D.Dir).startswith(SysRoot)) @@ -156,6 +174,9 @@ // Lacking those, try to detect the correct set of system includes for the // target triple. + + AddMultilibIncludeArgs(DriverArgs, CC1Args); + if (getTriple().getArch() == llvm::Triple::x86) { std::string Path = SysRoot + "/usr/include/i386-gnu"; if (D.getVFS().exists(Path)) Index: clang/test/Driver/hurd.c =================================================================== --- clang/test/Driver/hurd.c +++ clang/test/Driver/hurd.c @@ -11,7 +11,7 @@ // CHECK: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" // CHECK: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" // CHECK: "-dynamic-linker" "/lib/ld.so" -// CHECK: "crtbegin.o" +// CHECK: "{{.*}}/usr/lib/gcc/i386-gnu/4.6.0{{/|\\\\}}crtbegin.o" // CHECK: "-L[[SYSROOT]]/lib/i386-gnu" // CHECK: "-L[[SYSROOT]]/lib/../lib32" // CHECK: "-L[[SYSROOT]]/usr/lib/i386-gnu" @@ -33,7 +33,7 @@ // CHECK-STATIC: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" // CHECK-STATIC: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" // CHECK-STATIC: "-static" -// CHECK-STATIC: "crtbeginT.o" +// CHECK-STATIC: "{{.*}}/usr/lib/gcc/i386-gnu/4.6.0{{/|\\\\}}crtbeginT.o" // CHECK-STATIC: "-L[[SYSROOT]]/lib/i386-gnu" // CHECK-STATIC: "-L[[SYSROOT]]/lib/../lib32" // CHECK-STATIC: "-L[[SYSROOT]]/usr/lib/i386-gnu" @@ -53,10 +53,21 @@ // CHECK-SHARED: "-internal-externc-isystem" "[[SYSROOT]]/include" // CHECK-SHARED: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" // CHECK-SHARED: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" -// CHECK-SHARED: "crtbeginS.o" +// CHECK-SHARED: "{{.*}}/usr/lib/gcc/i386-gnu/4.6.0{{/|\\\\}}crtbeginS.o" // CHECK-SHARED: "-L[[SYSROOT]]/lib/i386-gnu" // CHECK-SHARED: "-L[[SYSROOT]]/lib/../lib32" // CHECK-SHARED: "-L[[SYSROOT]]/usr/lib/i386-gnu" // CHECK-SHARED: "-L[[SYSROOT]]/usr/lib/../lib32" // CHECK-SHARED: "-L[[SYSROOT]]/lib" // CHECK-SHARED: "-L[[SYSROOT]]/usr/lib" + +// RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \ +// RUN: --gcc-toolchain=%S/Inputs/basic_cross_hurd_tree/usr \ +// RUN: --target=i386-pc-gnu \ +// RUN: | FileCheck --check-prefix=CHECK-CROSS %s +// CHECK-CROSS-NOT: warning: +// CHECK-CROSS: "-cc1" "-triple" "i386-pc-hurd-gnu" +// CHECK-CROSS: "{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i386-gnu/4.6.0/../../../../i386-gnu/bin{{/|\\\\}}as" "--32" +// CHECK-CROSS: "{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i386-gnu/4.6.0/../../../../i386-gnu/bin{{/|\\\\}}ld" {{.*}} "-m" "elf_i386" +// CHECK-CROSS: "{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i386-gnu/4.6.0{{/|\\\\}}crtbegin.o" +// CHECK-CROSS: "-L{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i386-gnu/4.6.0/../../../../i386-gnu/lib"