Skip to content

Commit e28322a

Browse files
author
Salinas, David
authored
Amd/dev/catmoore/rel path (llvm#4422) (llvm#4643)
2 parents 0ade4ba + 93b6499 commit e28322a

File tree

3 files changed

+60
-53
lines changed

3 files changed

+60
-53
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ using namespace clang::driver::tools;
6969
using namespace clang;
7070
using namespace llvm::opt;
7171

72+
static bool addRPathCmdArg(const llvm::opt::ArgList &Args,
73+
ArgStringList &CmdArgs,
74+
const std::string pathCandidate,
75+
bool onlyIfPathExists = true) {
76+
SmallString<0> simplifiedPathCandidate(pathCandidate);
77+
llvm::sys::path::remove_dots(simplifiedPathCandidate, true);
78+
79+
bool pathExists = llvm::sys::fs::exists(simplifiedPathCandidate);
80+
81+
if (onlyIfPathExists && !pathExists)
82+
return false;
83+
84+
CmdArgs.push_back("-rpath");
85+
CmdArgs.push_back(Args.MakeArgString(simplifiedPathCandidate));
86+
return pathExists;
87+
}
88+
7289
static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args,
7390
const llvm::Triple &Triple) {
7491
if (Args.hasArg(clang::driver::options::OPT_pg) &&
@@ -1386,12 +1403,8 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
13861403
// one of the LIBRARY_PATH directories.
13871404
ArgStringList EnvLibraryPaths;
13881405
addDirectoryList(Args, EnvLibraryPaths, "", "LIBRARY_PATH");
1389-
for (auto &EnvLibraryPath : EnvLibraryPaths) {
1390-
if (llvm::sys::fs::exists(EnvLibraryPath)) {
1391-
CmdArgs.push_back("-rpath");
1392-
CmdArgs.push_back(Args.MakeArgString(EnvLibraryPath));
1393-
}
1394-
}
1406+
for (auto &EnvLibraryPath : EnvLibraryPaths)
1407+
addRPathCmdArg(Args, CmdArgs, EnvLibraryPath);
13951408

13961409
if (Args.hasFlag(options::OPT_fopenmp_implicit_rpath,
13971410
options::OPT_fno_openmp_implicit_rpath, true)) {
@@ -1400,46 +1413,33 @@ void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
14001413
SmallString<256> DefaultLibPath =
14011414
llvm::sys::path::parent_path(TC.getDriver().Dir);
14021415
llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
1403-
if (TC.getSanitizerArgs(Args).needsAsanRt()) {
1404-
CmdArgs.push_back("-rpath");
1405-
CmdArgs.push_back(Args.MakeArgString(TC.getCompilerRTPath()));
1406-
}
1416+
if (TC.getSanitizerArgs(Args).needsAsanRt())
1417+
addRPathCmdArg(Args, CmdArgs, TC.getCompilerRTPath(),
1418+
/*onlyIfPathExists=*/false);
14071419

14081420
// In case LibSuffix was not built, try lib
14091421
std::string CandidateRPath_suf = D.Dir + "/../" + LibSuffix;
1410-
CmdArgs.push_back("-rpath");
1411-
CmdArgs.push_back(Args.MakeArgString(CandidateRPath_suf.c_str()));
1412-
14131422
// Add lib directory in case LibSuffix does not exist
14141423
std::string CandidateRPath_lib = D.Dir + "/../lib";
1415-
if ((!llvm::sys::fs::exists(CandidateRPath_suf)) &&
1416-
(llvm::sys::fs::exists(CandidateRPath_lib))) {
1417-
CmdArgs.push_back("-rpath");
1418-
CmdArgs.push_back(Args.MakeArgString(CandidateRPath_lib.c_str()));
1419-
}
1424+
if (!addRPathCmdArg(Args, CmdArgs, CandidateRPath_suf,
1425+
/*onlyIfPathExists=*/false))
1426+
addRPathCmdArg(Args, CmdArgs, CandidateRPath_lib);
14201427

14211428
std::string rocmPath =
14221429
Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ).str();
14231430
if (rocmPath.size() != 0) {
14241431
std::string rocmPath_lib = rocmPath + "/lib";
14251432
std::string rocmPath_suf = rocmPath + "/" + LibSuffix;
1426-
if (llvm::sys::fs::exists(rocmPath_suf)) {
1427-
CmdArgs.push_back("-rpath");
1428-
CmdArgs.push_back(Args.MakeArgString(rocmPath_suf.c_str()));
1429-
} else if (llvm::sys::fs::exists(rocmPath_lib)) {
1430-
CmdArgs.push_back("-rpath");
1431-
CmdArgs.push_back(Args.MakeArgString(rocmPath_lib.c_str()));
1432-
}
1433+
if (!addRPathCmdArg(Args, CmdArgs, rocmPath_suf))
1434+
addRPathCmdArg(Args, CmdArgs, rocmPath_lib);
14331435
}
14341436

14351437
// Add Default lib path to ensure llvm dynamic library is picked up for
14361438
// lib-debug/lib-perf
1437-
if (LibSuffix != "lib" && llvm::sys::fs::exists(DefaultLibPath)){
1438-
CmdArgs.push_back("-rpath");
1439-
CmdArgs.push_back(Args.MakeArgString(DefaultLibPath.c_str()));
1440-
}
1439+
if (LibSuffix != "lib")
1440+
addRPathCmdArg(Args, CmdArgs, DefaultLibPath.c_str());
14411441

1442-
if (llvm::find_if(CmdArgs, [](StringRef str) {
1442+
if (llvm::find_if(CmdArgs, [](StringRef str) {
14431443
return !str.compare("--enable-new-dtags");
14441444
}) == CmdArgs.end())
14451445
CmdArgs.push_back("--disable-new-dtags");
@@ -1479,10 +1479,8 @@ void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
14791479
CandidateRPaths.emplace_back(*CandidateRPath);
14801480

14811481
for (const auto &CandidateRPath : CandidateRPaths) {
1482-
if (TC.getVFS().exists(CandidateRPath)) {
1483-
CmdArgs.push_back("-rpath");
1484-
CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
1485-
}
1482+
if (TC.getVFS().exists(CandidateRPath))
1483+
addRPathCmdArg(Args, CmdArgs, CandidateRPath, /*onlyIfPathExists=*/false);
14861484
}
14871485
}
14881486

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
11
// REQUIRES: amdgpu-registered-target
22

3-
// Asan-Debug: /lib-debug/asan
4-
// Asan-Devel: /lib/asan
5-
// Asan-Perf: /lib-perf/asan
6-
73
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a -fopenmp-runtimelib=lib-debug %s -O3 2>&1 \
8-
// RUN: | FileCheck -check-prefixes=Debug %s
4+
// RUN: | FileCheck -check-prefixes=Debug,Debug-Rel %s
95

106
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a -fopenmp-runtimelib=lib-perf %s -O3 2>&1 \
11-
// RUN: | FileCheck -check-prefixes=Perf %s
7+
// RUN: | FileCheck -check-prefixes=Perf,Perf-Rel %s
128

139
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a -fopenmp-runtimelib=lib %s -O3 2>&1 \
14-
// RUN: | FileCheck -check-prefixes=Devel %s
10+
// RUN: | FileCheck -check-prefixes=Devel,Devel-Rel %s
1511

1612
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a -fopenmp-target-fast %s -O3 2>&1 \
17-
// RUN: | FileCheck -check-prefixes=Default %s
13+
// RUN: | FileCheck -check-prefixes=Devel,Devel-Rel %s
1814

1915
// RUN: not %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a -fopenmp-runtimelib=oopsy %s -O3 2>&1 \
2016
// RUN: | FileCheck -check-prefixes=Error %s
2117

2218
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a:xnack+ -fopenmp-runtimelib=lib-debug -fsanitize=address -shared-libasan %s -O3 2>&1 \
23-
// RUN: | FileCheck -check-prefix=Asan-Debug %s
19+
// RUN: | FileCheck -check-prefixes=Asan-Debug,Asan-Debug-Rel %s
2420

2521
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a:xnack+ -fopenmp-runtimelib=lib -fsanitize=address -shared-libasan %s -O3 2>&1 \
26-
// RUN: | FileCheck -check-prefix=Asan-Devel %s
22+
// RUN: | FileCheck -check-prefixes=Asan-Devel,Asan-Devel-Rel %s
2723

2824
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a:xnack+ -fopenmp-runtimelib=lib-perf -fsanitize=address -shared-libasan %s -O3 2>&1 \
29-
// RUN: | FileCheck -check-prefix=Asan-Perf %s
25+
// RUN: | FileCheck -check-prefixes=Asan-Perf,Asan-Perf-Rel %s
3026

3127
// RUN: %clang -### -fopenmp -nogpuinc -nogpulib --offload-arch=gfx90a:xnack+ -fopenmp-target-fast -fsanitize=address -shared-libasan %s -O3 2>&1 \
32-
// RUN: | FileCheck -check-prefix=Asan-Devel %s
28+
// RUN: | FileCheck -check-prefixes=Asan-Devel,Asan-Devel-Rel %s
29+
30+
// Devel: "-rpath" "{{[^"]*}}[[LIB:(/|\\\\)lib]]"
31+
// Devel-Rel-NOT: "-rpath" "{{[^"]*(/|\\\\)\.\.}}[[LIB]]"
32+
33+
// Debug: "-rpath" "{{[^"]*}}[[LIB:(/|\\\\)lib-debug]]"
34+
// Debug-Rel-NOT: "-rpath" "{{[^"]*(/|\\\\)\.\.}}[[LIB]]"
35+
36+
// Perf: "-rpath" "{{[^"]*}}[[LIB:(/|\\\\)lib-perf]]"
37+
// Perf-Rel-NOT: "-rpath" "{{[^"]*(/|\\\\)\.\.}}[[LIB]]"
38+
39+
// Asan-Devel: "-rpath" "{{[^"]*}}[[LIB:(/|\\\\)lib(/|\\\\)asan]]"
40+
// Asan-Devel-Rel-NOT: "-rpath" "{{[^"]*(/|\\\\)\.\.}}[[LIB]]"
41+
42+
// Asan-Debug: "-rpath" "{{[^"]*}}[[LIB:(/|\\\\)lib-debug(/|\\\\)asan]]"
43+
// Asan-Debug-Rel-NOT: "-rpath" "{{[^"]*(/|\\\\)\.\.}}[[LIB]]"
44+
45+
// Asan-Perf: "-rpath" "{{[^"]*}}[[LIB:(/|\\\\)lib-perf(/|\\\\)asan]]"
46+
// Asan-Perf-Rel-NOT: "-rpath" "{{[^"]*(/|\\\\)\.\.}}[[LIB]]"
3347

34-
// Debug: /lib-debug
35-
// Perf: /lib-perf
36-
// Devel: /../lib
37-
// Default: /../lib
3848
// Error: clang: error: unsupported argument 'oopsy' to option '-fopenmp-runtimelib='

flang/test/Driver/arch-specific-libdir-rpath.f95

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
!
3333
!
3434
! RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
35-
!
3635
! LIBPATH-X86_64: -L[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}
37-
! RPATH-X86_64: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"
3836
!
39-
! NO-RPATH-X86_64-NOT: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"
37+
! RPATH-X86_64: "-rpath" "{{[^"]*(/|\\\\)resource_dir_with_arch_subdir(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"
38+
! NO-RPATH-X86_64-NOT: "-rpath" "{{[^"]*(/|\\\\)resource_dir_with_arch_subdir(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"

0 commit comments

Comments
 (0)