[clang] c298e5a - [Gnu toolchain] Move GCC multilib/multiarch paths support from Linux to Gnu
Sylvestre Ledru via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 03:13:05 PDT 2020
Author: Samuel Thibault
Date: 2020-05-01T12:12:27+02:00
New Revision: c298e5a022928b59941d74680a41fc9c76038b2a
URL: https://github.com/llvm/llvm-project/commit/c298e5a022928b59941d74680a41fc9c76038b2a
DIFF: https://github.com/llvm/llvm-project/commit/c298e5a022928b59941d74680a41fc9c76038b2a.diff
LOG: [Gnu toolchain] Move GCC multilib/multiarch paths support from Linux to Gnu
Summary: The current code for GNU/Linux is actually completely generic, and can be moved to Gnu, so it can benefit GNU/Hurd and GNU/kFreeBSD
Reviewers: kristina, sammccall, lebedev.ri, MaskRay, arsenm, phosek
Reviewed By: MaskRay, phosek
Subscribers: wdng, ormris, emaste, arichardson, krytarowski, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73845
Added:
Modified:
clang/lib/Driver/ToolChains/Hurd.cpp
clang/test/Driver/hurd.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index ce1806c4043b..3448e4f4a294 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -63,7 +63,19 @@ static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
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 @@ Hurd::Hurd(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
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 @@ Hurd::Hurd(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
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 @@ void Hurd::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// 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))
diff --git a/clang/test/Driver/hurd.c b/clang/test/Driver/hurd.c
index a6ca8ea3379f..7dbbe923557b 100644
--- a/clang/test/Driver/hurd.c
+++ b/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"
More information about the cfe-commits
mailing list