[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama updated this revision to Diff 88864. pirama added a comment. Fix typo. https://reviews.llvm.org/D30015 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp lib/Driver/Tools.cpp test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/arm/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/i386/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64/.keep test/Driver/arch-specific-libdir-rpath.c test/Driver/arch-specific-libdir.c test/lit.cfg Index: test/lit.cfg === --- test/lit.cfg +++ test/lit.cfg @@ -392,6 +392,10 @@ if config.host_triple == config.target_triple: config.available_features.add("native") +# Test Driver/arch-specific-libdir-rpath.c is restricted to x86_64-linux +if re.match(r'^x86_64.*-linux', config.target_triple): +config.available_features.add("x86_64-linux") + # Case-insensitive file system def is_filesystem_case_insensitive(): handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) Index: test/Driver/arch-specific-libdir.c === --- /dev/null +++ test/Driver/arch-specific-libdir.c @@ -0,0 +1,52 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the search path. +// +// RUN: %clang %s -### 2>&1 -target i386-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-i386 %s +// +// RUN: %clang %s -### 2>&1 -target i386-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-i386 %s +// +// RUN: %clang %s -### 2>&1 -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-x86_64 %s +// +// RUN: %clang %s -### 2>&1 -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-arm %s +// +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-aarch64 %s +// +// RUN: %clang %s -### 2>&1 -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// +// CHECK-ARCHDIR-i386: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/i386 +// CHECK-ARCHDIR-x86_64: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64 +// CHECK-ARCHDIR-arm: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/arm +// CHECK-ARCHDIR-aarch64: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64 +// +// Have a stricter check for no-archdir - that the driver doesn't add any +// subdirectory from the provided resource directory. +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir Index: test/Driver/arch-specific-libdir-rpath.c === --- /dev/null +++ test/Driver/arch-specific-libdir-rpath.c @@ -0,0 +1,20 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath' for native +// compilations. +// +// -rpath only gets added during native compilation. To keep the test simple, +// just test for x86_64-linux native compilation. +// REQUIRES: x86_64-linux +// +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux{{.*}} "-rpath" {{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir +// CHECK-NO-ARCHDIR-NOT: "-rpath" {{.*}}/Inputs/resource_dir Index: lib/Driver/Tools.cpp
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added inline comments. Comment at: test/Driver/arch-specific-libdir-rpath.c:6 +// -rpath only gets added during native compilation +// REQUIRES: native +// mgorny wrote: > Hahnfeld wrote: > > pirama wrote: > > > pirama wrote: > > > > I feel this test is fragile. Any idea how to further restrict and > > > > require that the default target triple has linux and one of i386, > > > > x86_64, arm, aarch64? > > > > > > > > I could create sub-dirs for all archs returned by > > > > Triple::getArchTypeName (llvm/lib/Support/Triple.cpp) but it seems > > > > overkill. > > > I've restricted the test to just x86_64-linux. > > Instead of `REQUIRES`, you should probably add `-target > > x86_64-unknown-linux` > Hmm, I don't see any good solution for this. Looking at the code, the host > triple is hardcoded, so you'd indeed have to either restrict the test to > triples matching LLVM_HOST_TRIPLE. Or maybe add a command-line option to > override the host triple. Sorry, I missed that it's cross-compiling then. `x86_64` is in that case probably the best thing to do because it's most widespread, also among the buildbots. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
mgorny added a comment. Thanks. The -L tests look good, -rpath is not perfect but I don't think you can improve it without additional changes to the Driver. Comment at: test/Driver/arch-specific-libdir-rpath.c:6 +// -rpath only gets added during native compilation +// REQUIRES: native +// Hahnfeld wrote: > pirama wrote: > > pirama wrote: > > > I feel this test is fragile. Any idea how to further restrict and > > > require that the default target triple has linux and one of i386, x86_64, > > > arm, aarch64? > > > > > > I could create sub-dirs for all archs returned by Triple::getArchTypeName > > > (llvm/lib/Support/Triple.cpp) but it seems overkill. > > I've restricted the test to just x86_64-linux. > Instead of `REQUIRES`, you should probably add `-target x86_64-unknown-linux` Hmm, I don't see any good solution for this. Looking at the code, the host triple is hardcoded, so you'd indeed have to either restrict the test to triples matching LLVM_HOST_TRIPLE. Or maybe add a command-line option to override the host triple. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added a comment. Please adapt the title and summary for the more general changes this has evolved to. Comment at: lib/Driver/Tools.cpp:284 +// If we are not cross-compling, add '-rpath' with architecture-specific +// library path so libraries lined from this path can be automatically +// found. s/lined/linked/ Comment at: test/Driver/arch-specific-libdir-rpath.c:6 +// -rpath only gets added during native compilation +// REQUIRES: native +// pirama wrote: > pirama wrote: > > I feel this test is fragile. Any idea how to further restrict and require > > that the default target triple has linux and one of i386, x86_64, arm, > > aarch64? > > > > I could create sub-dirs for all archs returned by Triple::getArchTypeName > > (llvm/lib/Support/Triple.cpp) but it seems overkill. > I've restricted the test to just x86_64-linux. Instead of `REQUIRES`, you should probably add `-target x86_64-unknown-linux` Comment at: test/Driver/arch-specific-libdir-rpath.c:18 +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux{{.*}} "-rpath" {{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir Can you split that into two lines? Then it won't fail if there is some argument added in between https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama added inline comments. Comment at: test/Driver/arch-specific-libdir-rpath.c:6 +// -rpath only gets added during native compilation +// REQUIRES: native +// pirama wrote: > I feel this test is fragile. Any idea how to further restrict and require > that the default target triple has linux and one of i386, x86_64, arm, > aarch64? > > I could create sub-dirs for all archs returned by Triple::getArchTypeName > (llvm/lib/Support/Triple.cpp) but it seems overkill. I've restricted the test to just x86_64-linux. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama updated this revision to Diff 88799. pirama added a comment. Stricter tests. https://reviews.llvm.org/D30015 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp lib/Driver/Tools.cpp test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/arm/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/i386/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64/.keep test/Driver/arch-specific-libdir-rpath.c test/Driver/arch-specific-libdir.c test/lit.cfg Index: test/lit.cfg === --- test/lit.cfg +++ test/lit.cfg @@ -392,6 +392,10 @@ if config.host_triple == config.target_triple: config.available_features.add("native") +# Test Driver/arch-specific-libdir-rpath.c is restricted to x86_64-linux +if re.match(r'^x86_64.*-linux', config.target_triple): +config.available_features.add("x86_64-linux") + # Case-insensitive file system def is_filesystem_case_insensitive(): handle, path = tempfile.mkstemp(prefix='case-test', dir=config.test_exec_root) Index: test/Driver/arch-specific-libdir.c === --- /dev/null +++ test/Driver/arch-specific-libdir.c @@ -0,0 +1,52 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the search path. +// +// RUN: %clang %s -### 2>&1 -target i386-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-i386 %s +// +// RUN: %clang %s -### 2>&1 -target i386-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-i386 %s +// +// RUN: %clang %s -### 2>&1 -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-x86_64 %s +// +// RUN: %clang %s -### 2>&1 -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-arm %s +// +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR-aarch64 %s +// +// RUN: %clang %s -### 2>&1 -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// +// CHECK-ARCHDIR-i386: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/i386 +// CHECK-ARCHDIR-x86_64: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64 +// CHECK-ARCHDIR-arm: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/arm +// CHECK-ARCHDIR-aarch64: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64 +// +// Have a stricter check for no-archdir - that the driver doesn't add any +// subdirectory from the provided resource directory. +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir Index: test/Driver/arch-specific-libdir-rpath.c === --- /dev/null +++ test/Driver/arch-specific-libdir-rpath.c @@ -0,0 +1,20 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath' for native +// compilations. +// +// -rpath only gets added during native compilation. To keep the test simple, +// just test for x86_64-linux native compilation. +// REQUIRES: x86_64-linux +// +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux{{.*}} "-rpath" {{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir +// CHECK-NO-ARCHDIR-NOT: "-rpath" {{.*}}/Inputs/resource_dir Index: lib/Driver/Tools.cpp
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
mgorny added inline comments. Comment at: test/Driver/arch-specific-libdir.c:6 +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// Please be more specific in the tests, i.e. check if the correct arch dir is selected. Also add a test for i386-* triple, and make sure that both i386-* and i686-* give the same result. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama added inline comments. Comment at: test/Driver/arch-specific-libdir-rpath.c:6 +// -rpath only gets added during native compilation +// REQUIRES: native +// I feel this test is fragile. Any idea how to further restrict and require that the default target triple has linux and one of i386, x86_64, arm, aarch64? I could create sub-dirs for all archs returned by Triple::getArchTypeName (llvm/lib/Support/Triple.cpp) but it seems overkill. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama updated this revision to Diff 88768. pirama added a comment. - Arch-subdir is now always added to -L - It is added to -rpath during native compilation. - Tests have been updated https://reviews.llvm.org/D30015 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp lib/Driver/Tools.cpp test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/arm/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/i386/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64/.keep test/Driver/arch-specific-libdir-rpath.c test/Driver/arch-specific-libdir.c Index: test/Driver/arch-specific-libdir.c === --- /dev/null +++ test/Driver/arch-specific-libdir.c @@ -0,0 +1,38 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the search path. +// +// RUN: %clang %s -### 2>&1 -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir Index: test/Driver/arch-specific-libdir-rpath.c === --- /dev/null +++ test/Driver/arch-specific-libdir-rpath.c @@ -0,0 +1,19 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath' for native +// compilations. +// +// -rpath only gets added during native compilation +// REQUIRES: native +// +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR %s +// +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR %s +// +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux{{.*}} "-rpath" {{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir +// CHECK-NO-ARCHDIR-NOT: "-rpath" {{.*}}/Inputs/resource_dir Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Compilation.h" @@ -276,8 +277,18 @@ // LIBRARY_PATH - included following the user specified library paths. //and only supported on native toolchains. - if (!TC.isCrossCompiling()) + if (!TC.isCrossCompiling()) { addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); + +// If we are not cross-compling, add '-rpath' with architecture-specific +// library path so libraries lined from this path can be automatically +// found. +std::string CandidateRPath = TC.getArchSpecificLibPath(); +if (D.getVFS().exists(CandidateRPath)) { + CmdArgs.push_back("-rpath"); + CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str())); +} + } } /// Add OpenMP linker script arguments at the end of the argument list so that Index: lib/Driver/ToolChain.cpp === --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -10,6 +10,7 @@ #include "clang/Driver/ToolChain.h" #include "Tools.h" #include
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added a comment. Maybe something like the following (without tests): diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index ffb0d60..0f3507d 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -299,6 +299,11 @@ public: const char *getCompilerRTArgString(const llvm::opt::ArgList , StringRef Component, bool Shared = false) const; + + /// Returns /lib//. This is used by runtimes (such + /// as OpenMP) to find arch-specific libraries. + const std::string getArchSpecificLibPath() const; + /// needsProfileRT - returns true if instrumentation profile is on. static bool needsProfileRT(const llvm::opt::ArgList ); diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 6adc038..ae2c08e 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -10,6 +10,7 @@ #include "clang/Driver/ToolChain.h" #include "Tools.h" #include "clang/Basic/ObjCRuntime.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Driver.h" @@ -74,6 +75,10 @@ ToolChain::ToolChain(const Driver , const llvm::Triple , if (!isThreadModelSupported(A->getValue())) D.Diag(diag::err_drv_invalid_thread_model_for_target) << A->getValue() << A->getAsString(Args); + + std::string CandidateLibPath = getArchSpecificLibPath(); + if (getVFS().exists(CandidateLibPath)) +getFilePaths().push_back(CandidateLibPath); } ToolChain::~ToolChain() { @@ -320,6 +325,14 @@ const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList , return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +const std::string ToolChain::getArchSpecificLibPath() const { + SmallString<128> Path(getDriver().ResourceDir); + StringRef OSLibName = getTriple().isOSFreeBSD() ? "freebsd" : getOS(); + llvm::sys::path::append(Path, "lib", OSLibName, + llvm::Triple::getArchTypeName(getArch())); + return Path.str(); +} + bool ToolChain::needsProfileRT(const ArgList ) { if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, false) || diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index cc7d9e1..c0fb4bc 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Compilation.h" @@ -276,8 +277,15 @@ static void AddLinkerInputs(const ToolChain , const InputInfoList , // LIBRARY_PATH - included following the user specified library paths. //and only supported on native toolchains. - if (!TC.isCrossCompiling()) + if (!TC.isCrossCompiling()) { addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); + +std::string CandidateRPath = TC.getArchSpecificLibPath(); +if (D.getVFS().exists(CandidateRPath)) { + CmdArgs.push_back("-rpath"); + CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str())); +} + } } /// Add OpenMP linker script arguments at the end of the argument list so that https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added a comment. In https://reviews.llvm.org/D30015#678294, @pirama wrote: > I am fine to do this more generally, but not sure of the scope. Should this > be always added or only if a runtime (sanitizer or openmp or xray) is > requested? I think always. From my point of view, this would be the right solution for my https://reviews.llvm.org/D26244. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama added a comment. I am fine to do this more generally, but not sure of the scope. Should this be always added or only if a runtime (sanitizer or openmp or xray) is requested? https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added a comment. I still think this should not be done for OpenMP only and hence move out of `addOpenMPRuntime`. (Why the heck are there //two// places to add `-lomp`?!? I'll clean that up later...) https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama added a subscriber: openmp-commits. pirama marked an inline comment as done. pirama added inline comments. Comment at: lib/Driver/Tools.cpp:3267 + if (llvm::sys::fs::is_directory(CandidateLibPath)) +CmdArgs.push_back(Args.MakeArgString("-L" + CandidateLibPath)); + mgorny wrote: > Don't you also need rpath for it? Or is this purely for static runtime? I am doing this for a cross-compiling toolchain (Android NDK) where the actual rpath is not valid at runtime. The runtime is packaged with the application and made available to the loader behind the scenes. That said, I don't think providing an rpath doesn't hurt. I'll wait for input from @cbergstrom and OpenMP folks to see if this'd be useful. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama updated this revision to Diff 88663. pirama added a comment. Use getArchTypeName() instead of getArchName(). https://reviews.llvm.org/D30015 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp lib/Driver/Tools.cpp test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/arm/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/i386/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64/.keep test/Driver/openmp-arch-dir.c Index: test/Driver/openmp-arch-dir.c === --- /dev/null +++ test/Driver/openmp-arch-dir.c @@ -0,0 +1,57 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the search path. This allows multilib toolchains +// to package libomp.so for multiple architectures. + +// Directory resource_dir_with_arch_subdir is setup only for Linux +// REQUIRES: linux +// +// RUN: %clang %s -### 2>&1 -fopenmp -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// Check correctness when -fopenmp is omitted +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-NO-LOMP %s +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir +// CHECK-LOMP: -lomp +// CHECK-NO-LOMP-NOT: -lomp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3260,6 +3260,12 @@ options::OPT_fno_openmp, false)) return; + // Add /lib// to the linker search path if it + // exists. + std::string CandidateLibPath = TC.getArchSpecificLibPath(); + if (llvm::sys::fs::is_directory(CandidateLibPath)) +CmdArgs.push_back(Args.MakeArgString("-L" + CandidateLibPath)); + switch (TC.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: CmdArgs.push_back("-lomp"); @@ -10316,6 +10322,12 @@ // FIXME: Does this really make sense for all GNU toolchains? WantPthread = true; +// Add /lib// to the linker search path if it +// exists. +std::string CandidateLibPath = ToolChain.getArchSpecificLibPath(); +if (llvm::sys::fs::is_directory(CandidateLibPath)) + CmdArgs.push_back(Args.MakeArgString("-L" + CandidateLibPath)); + // Also link the particular OpenMP runtimes. switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: Index: lib/Driver/ToolChain.cpp === --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -320,6 +320,14 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +const std::string ToolChain::getArchSpecificLibPath() const { + SmallString<128> Path(getDriver().ResourceDir); + StringRef OSLibName = getTriple().isOSFreeBSD() ? "freebsd" : getOS(); + llvm::sys::path::append(Path, "lib",
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
mgorny added inline comments. Comment at: lib/Driver/Tools.cpp:3267 + if (llvm::sys::fs::is_directory(CandidateLibPath)) +CmdArgs.push_back(Args.MakeArgString("-L" + CandidateLibPath)); + Don't you also need rpath for it? Or is this purely for static runtime? https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
mgorny added inline comments. Comment at: lib/Driver/ToolChain.cpp:327 + llvm::sys::path::append(Path, "lib", OSLibName, + getArchName()); + return Path.str(); I would suggest using arch type, to avoid e.g. i386/i486/i586 mess. It's really hard to clean it up afterwards, see D26796. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama updated this revision to Diff 88662. pirama added a comment. Changed the name of the utility that builds the arch-specific directory. https://reviews.llvm.org/D30015 Files: include/clang/Driver/ToolChain.h lib/Driver/ToolChain.cpp lib/Driver/Tools.cpp test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/aarch64/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/arm/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/i686/.keep test/Driver/Inputs/resource_dir_with_arch_subdir/lib/linux/x86_64/.keep test/Driver/openmp-arch-dir.c Index: test/Driver/openmp-arch-dir.c === --- /dev/null +++ test/Driver/openmp-arch-dir.c @@ -0,0 +1,57 @@ +// Test that the driver adds an arch-specific subdirectory in +// {RESOURCE_DIR}/lib/linux to the search path. This allows multilib toolchains +// to package libomp.so for multiple architectures. + +// Directory resource_dir_with_arch_subdir is setup only for Linux +// REQUIRES: linux +// +// RUN: %clang %s -### 2>&1 -fopenmp -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target i686-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target x86_64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// RUN: %clang %s -### 2>&1 -fopenmp -target aarch64-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-LOMP %s +// +// Check correctness when -fopenmp is omitted +// RUN: %clang %s -### 2>&1 -target arm-unknown-linux \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-NO-ARCHDIR \ +// RUN: --check-prefix=CHECK-NO-LOMP %s +// +// CHECK-ARCHDIR: -L{{.*}}/Inputs/resource_dir_with_arch_subdir/lib/linux +// CHECK-NO-ARCHDIR-NOT: -L{{.*}}Inputs/resource_dir +// CHECK-LOMP: -lomp +// CHECK-NO-LOMP-NOT: -lomp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3260,6 +3260,12 @@ options::OPT_fno_openmp, false)) return; + // Add /lib// to the linker search path if it + // exists. + std::string CandidateLibPath = TC.getArchSpecificLibPath(); + if (llvm::sys::fs::is_directory(CandidateLibPath)) +CmdArgs.push_back(Args.MakeArgString("-L" + CandidateLibPath)); + switch (TC.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: CmdArgs.push_back("-lomp"); @@ -10316,6 +10322,12 @@ // FIXME: Does this really make sense for all GNU toolchains? WantPthread = true; +// Add /lib// to the linker search path if it +// exists. +std::string CandidateLibPath = ToolChain.getArchSpecificLibPath(); +if (llvm::sys::fs::is_directory(CandidateLibPath)) + CmdArgs.push_back(Args.MakeArgString("-L" + CandidateLibPath)); + // Also link the particular OpenMP runtimes. switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: Index: lib/Driver/ToolChain.cpp === --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -320,6 +320,14 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Shared)); } +const std::string ToolChain::getArchSpecificLibPath() const { + SmallString<128> Path(getDriver().ResourceDir); + StringRef OSLibName = getTriple().isOSFreeBSD() ? "freebsd" : getOS(); +
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added a subscriber: mgorny. Hahnfeld added a comment. Yes, that's the current state. We had some discussion on cfe-dev on that matter: http://lists.llvm.org/pipermail/cfe-dev/2017-January/052512.html Could you slightly adapt your patch so that other runtime libraries can follow this idea in the future? https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
pirama added a comment. In https://reviews.llvm.org/D30015#678243, @Hahnfeld wrote: > Why is this only for OpenMP? I imagine this should be done for **all** > runtime libraries The other runtime libraries have the arch included in the library's name and the driver links the correct file. cbergstrom preferred to look in an arch-specific directory rather (http://lists.llvm.org/pipermail/openmp-dev/2017-February/001659.html). It makes sense for OpenMP because other toolchains may assume the standard library name (libomp.so). https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
Hahnfeld added a comment. Why is this only for OpenMP? I imagine this should be done for **all** runtime libraries https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
srhines added inline comments. Comment at: include/clang/Driver/ToolChain.h:304 + // Returns /lib//. When -fopenmp is specified, + // this directory is added to the linker search path if it exists + const std::string getOpenMPLibPath() const; Add a period at the end of the sentence. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30015: [OpenMP] Add arch-specific directory to search path
danalbert accepted this revision. danalbert added a comment. This revision is now accepted and ready to land. LGTM, but should probably get signoff from someone else as well. https://reviews.llvm.org/D30015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits