[clang] [Clang][VE] Correct rpath handling on VE (PR #67671)
Kazushi Marukawa via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 28 06:28:00 PDT 2023
https://github.com/kaz7 updated https://github.com/llvm/llvm-project/pull/67671
>From f50505a9eb1d86f029bf552cd846ccc8c6deb0e4 Mon Sep 17 00:00:00 2001
From: "Kazushi (Jam) Marukawa" <marukawa at nec.com>
Date: Thu, 28 Sep 2023 19:25:09 +0900
Subject: [PATCH 1/2] [Clang][VE] Correct rpath handling on VE
Add rpath for libc++ libraries in order to not specify rpath by user each
time. Disable -frthlib-add-ppath by default for VE similar to other
architectures. Update regression tests to check modifications.
---
clang/lib/Driver/ToolChains/CommonArgs.cpp | 5 +----
clang/lib/Driver/ToolChains/VEToolchain.cpp | 8 ++++++++
.../ve-unknown-linux-gnu/libc++.so} | 0
.../clang_rt.crtbegin.o} | 0
.../clang_rt.crtend.o} | 0
.../lib/ve-unknown-linux-gnu/libclang_rt.builtins.a | 0
clang/test/Driver/ve-toolchain.c | 8 ++++----
clang/test/Driver/ve-toolchain.cpp | 10 ++++++----
8 files changed, 19 insertions(+), 12 deletions(-)
rename clang/test/Driver/Inputs/basic_ve_tree/{resource_dir/lib/linux/clang_rt.crtbegin-ve.o => lib/ve-unknown-linux-gnu/libc++.so} (100%)
rename clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/{linux/clang_rt.crtend-ve.o => ve-unknown-linux-gnu/clang_rt.crtbegin.o} (100%)
rename clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/{linux/libclang_rt.builtins-ve.a => ve-unknown-linux-gnu/clang_rt.crtend.o} (100%)
create mode 100644 clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6041ef4aeb673ef..e07744e42968596 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -882,11 +882,8 @@ void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) {
- // Enable -frtlib-add-rpath by default for the case of VE.
- const bool IsVE = TC.getTriple().isVE();
- bool DefaultValue = IsVE;
if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
- options::OPT_fno_rtlib_add_rpath, DefaultValue))
+ options::OPT_fno_rtlib_add_rpath, false))
return;
for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
diff --git a/clang/lib/Driver/ToolChains/VEToolchain.cpp b/clang/lib/Driver/ToolChains/VEToolchain.cpp
index 71b6fe2ea3619c1..39529e0b6b35915 100644
--- a/clang/lib/Driver/ToolChains/VEToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/VEToolchain.cpp
@@ -33,6 +33,7 @@ VEToolChain::VEToolChain(const Driver &D, const llvm::Triple &Triple,
// These are OK.
// Default file paths are following:
+ // ${RESOURCEDIR}/lib/ve-unknown-linux-gnu, (== getArchSpecificLibPaths)
// ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
// /lib/../lib64,
// /usr/lib/../lib64,
@@ -46,6 +47,7 @@ VEToolChain::VEToolChain(const Driver &D, const llvm::Triple &Triple,
// Add library directories:
// ${BINPATH}/../lib/ve-unknown-linux-gnu, (== getStdlibPath)
+ // ${RESOURCEDIR}/lib/ve-unknown-linux-gnu, (== getArchSpecificLibPaths)
// ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
// ${SYSROOT}/opt/nec/ve/lib,
if (std::optional<std::string> Path = getStdlibPath())
@@ -141,6 +143,12 @@ void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
tools::addArchSpecificRPath(*this, Args, CmdArgs);
+ // Add paths for libc++.so and other shared libraries.
+ if (std::optional<std::string> Path = getStdlibPath()) {
+ CmdArgs.push_back("-rpath");
+ CmdArgs.push_back(Args.MakeArgString(*Path));
+ }
+
CmdArgs.push_back("-lc++");
if (Args.hasArg(options::OPT_fexperimental_library))
CmdArgs.push_back("-lc++experimental");
diff --git a/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/linux/clang_rt.crtbegin-ve.o b/clang/test/Driver/Inputs/basic_ve_tree/lib/ve-unknown-linux-gnu/libc++.so
similarity index 100%
rename from clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/linux/clang_rt.crtbegin-ve.o
rename to clang/test/Driver/Inputs/basic_ve_tree/lib/ve-unknown-linux-gnu/libc++.so
diff --git a/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/linux/clang_rt.crtend-ve.o b/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/clang_rt.crtbegin.o
similarity index 100%
rename from clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/linux/clang_rt.crtend-ve.o
rename to clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/clang_rt.crtbegin.o
diff --git a/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/linux/libclang_rt.builtins-ve.a b/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/clang_rt.crtend.o
similarity index 100%
rename from clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/linux/libclang_rt.builtins-ve.a
rename to clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/clang_rt.crtend.o
diff --git a/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a b/clang/test/Driver/Inputs/basic_ve_tree/resource_dir/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a
new file mode 100644
index 000000000000000..e69de29bb2d1d64
diff --git a/clang/test/Driver/ve-toolchain.c b/clang/test/Driver/ve-toolchain.c
index 32e25769b6da7a9..078341eb1202d6d 100644
--- a/clang/test/Driver/ve-toolchain.c
+++ b/clang/test/Driver/ve-toolchain.c
@@ -97,8 +97,8 @@
// DEF-SAME: "[[SYSROOT]]/opt/nec/ve/lib/crt1.o"
// DEF-SAME: "[[SYSROOT]]/opt/nec/ve/lib/crti.o"
// DEF-SAME: "-z" "max-page-size=0x4000000"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/clang_rt.crtbegin-ve.o"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/libclang_rt.builtins-ve.a" "-lc"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/libclang_rt.builtins-ve.a"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/clang_rt.crtend-ve.o"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/clang_rt.crtbegin.o"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a" "-lc"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/clang_rt.crtend.o"
// DEF-SAME: "[[SYSROOT]]/opt/nec/ve/lib/crtn.o"
diff --git a/clang/test/Driver/ve-toolchain.cpp b/clang/test/Driver/ve-toolchain.cpp
index 5a33d5eceb61474..15a556517182e87 100644
--- a/clang/test/Driver/ve-toolchain.cpp
+++ b/clang/test/Driver/ve-toolchain.cpp
@@ -25,6 +25,8 @@
// DEFINC-SAME: "-internal-isystem" "{{.*}}/bin/../include/c++/v1"
// DEFINC-SAME: "-internal-isystem" "[[RESOURCE_DIR]]/include"
// DEFINC-SAME: "-internal-isystem" "[[SYSROOT]]/opt/nec/ve/include"
+// DEFINC: nld"
+// DEFINC-SAME: "-rpath" "[[SYSROOT]]/bin/../lib/ve-unknown-linux-gnu"
// RUN: %clangxx -### --target=ve-unknown-linux-gnu \
// RUN: --sysroot %S/Inputs/basic_ve_tree %s \
@@ -146,9 +148,9 @@
// DEF-SAME: "[[SYSROOT]]/opt/nec/ve/lib/crt1.o"
// DEF-SAME: "[[SYSROOT]]/opt/nec/ve/lib/crti.o"
// DEF-SAME: "-z" "max-page-size=0x4000000"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/clang_rt.crtbegin-ve.o"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/clang_rt.crtbegin.o"
// DEF-SAME: "-lc++" "-lc++abi" "-lunwind" "-lpthread" "-ldl"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/libclang_rt.builtins-ve.a" "-lc"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/libclang_rt.builtins-ve.a"
-// DEF-SAME: "[[RESOURCE_DIR]]/lib/linux/clang_rt.crtend-ve.o"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a" "-lc"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/libclang_rt.builtins.a"
+// DEF-SAME: "[[RESOURCE_DIR]]/lib/ve-unknown-linux-gnu/clang_rt.crtend.o"
// DEF-SAME: "[[SYSROOT]]/opt/nec/ve/lib/crtn.o"
>From b37d351ca5048036cd44af6cbd0d55667ff828d0 Mon Sep 17 00:00:00 2001
From: "Kazushi (Jam) Marukawa" <marukawa at nec.com>
Date: Thu, 28 Sep 2023 22:27:21 +0900
Subject: [PATCH 2/2] Change as suggested as clang-format
---
clang/lib/Driver/ToolChains/CommonArgs.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index e07744e42968596..a090e343712f1bc 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2210,12 +2210,12 @@ bool tools::GetSDLFromOffloadArchive(
// Wrapper function used by driver for adding SDLs during link phase.
void tools::AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
- const JobAction &JA,
- const InputInfoList &Inputs,
- const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args,
- StringRef Arch, StringRef Target,
- bool isBitCodeSDL, bool postClangLink) {
+ const JobAction &JA,
+ const InputInfoList &Inputs,
+ const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ StringRef Arch, StringRef Target,
+ bool isBitCodeSDL, bool postClangLink) {
AddStaticDeviceLibs(&C, &T, &JA, &Inputs, C.getDriver(), DriverArgs, CC1Args,
Arch, Target, isBitCodeSDL, postClangLink);
}
More information about the cfe-commits
mailing list