[clang] aed2fdb - [Hexagon] Update paths for linux/musl
Sid Manning via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 11:46:35 PDT 2020
Author: Sid Manning
Date: 2020-04-07T13:45:52-05:00
New Revision: aed2fdb1671c31ceff6997af56ae67831dad2595
URL: https://github.com/llvm/llvm-project/commit/aed2fdb1671c31ceff6997af56ae67831dad2595
DIFF: https://github.com/llvm/llvm-project/commit/aed2fdb1671c31ceff6997af56ae67831dad2595.diff
LOG: [Hexagon] Update paths for linux/musl
Update the sysroot expectation to match other targets and breakout
linux/musl toolchain tests into a new file.
Differential Revision: https://reviews.llvm.org/D77440
Added:
clang/test/Driver/Inputs/hexagon_tree/Tools/target/hexagon/include/c++/v1/readme
clang/test/Driver/hexagon-toolchain-linux.c
Modified:
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/Hexagon.h
clang/test/Driver/hexagon-toolchain-elf.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 4a5e8254dfa0..cf0a0335fbdf 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -273,12 +273,13 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
if (!Args.hasArg(options::OPT_shared, options::OPT_nostartfiles,
options::OPT_nostdlib))
- CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/crt1.o"));
+ CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/usr/lib/crt1.o"));
else if (Args.hasArg(options::OPT_shared) &&
!Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
- CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/Scrt1.o"));
+ CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/usr/lib/crti.o"));
- CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + D.SysRoot + "/lib"));
+ CmdArgs.push_back(
+ Args.MakeArgString(StringRef("-L") + D.SysRoot + "/usr/lib"));
Args.AddAllArgs(CmdArgs,
{options::OPT_T_Group, options::OPT_e, options::OPT_s,
options::OPT_t, options::OPT_u_Group});
@@ -288,7 +289,10 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lclang_rt.builtins-hexagon");
CmdArgs.push_back("-lc");
}
-
+ if (D.CCCIsCXX()) {
+ if (HTC.ShouldLinkCXXStdlib(Args))
+ HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
+ }
return;
}
@@ -508,6 +512,22 @@ HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple,
HexagonToolChain::~HexagonToolChain() {}
+void HexagonToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ CXXStdlibType Type = GetCXXStdlibType(Args);
+ switch (Type) {
+ case ToolChain::CST_Libcxx:
+ CmdArgs.push_back("-lc++");
+ CmdArgs.push_back("-lc++abi");
+ CmdArgs.push_back("-lunwind");
+ break;
+
+ case ToolChain::CST_Libstdcxx:
+ CmdArgs.push_back("-lstdc++");
+ break;
+ }
+}
+
Tool *HexagonToolChain::buildAssembler() const {
return new tools::hexagon::Assembler(*this);
}
@@ -571,7 +591,10 @@ void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
const Driver &D = getDriver();
if (!D.SysRoot.empty()) {
SmallString<128> P(D.SysRoot);
- llvm::sys::path::append(P, "include");
+ if (getTriple().isMusl())
+ llvm::sys::path::append(P, "usr/include");
+ else
+ llvm::sys::path::append(P, "include");
addExternCSystemInclude(DriverArgs, CC1Args, P.str());
return;
}
@@ -581,7 +604,22 @@ void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include");
}
-
+void HexagonToolChain::addLibCxxIncludePaths(
+ const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const {
+ const Driver &D = getDriver();
+ if (!D.SysRoot.empty() && getTriple().isMusl())
+ addLibStdCXXIncludePaths(D.SysRoot + "/usr/include/c++/v1", "", "", "", "",
+ "", DriverArgs, CC1Args);
+ else if (getTriple().isMusl())
+ addLibStdCXXIncludePaths("/usr/include/c++/v1", "", "", "", "", "",
+ DriverArgs, CC1Args);
+ else {
+ std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs);
+ addLibStdCXXIncludePaths(TargetDir, "/hexagon/include/c++/v1", "", "", "",
+ "", DriverArgs, CC1Args);
+ }
+}
void HexagonToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
@@ -594,14 +632,22 @@ void HexagonToolChain::addLibStdCxxIncludePaths(
ToolChain::CXXStdlibType
HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const {
Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
- if (!A)
- return ToolChain::CST_Libstdcxx;
-
+ if (!A) {
+ if (getTriple().isMusl())
+ return ToolChain::CST_Libcxx;
+ else
+ return ToolChain::CST_Libstdcxx;
+ }
StringRef Value = A->getValue();
- if (Value != "libstdc++")
+ if (Value != "libstdc++" && Value != "libc++")
getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args);
- return ToolChain::CST_Libstdcxx;
+ if (Value == "libstdc++")
+ return ToolChain::CST_Libstdcxx;
+ else if (Value == "libc++")
+ return ToolChain::CST_Libcxx;
+ else
+ return ToolChain::CST_Libstdcxx;
}
bool HexagonToolChain::isAutoHVXEnabled(const llvm::opt::ArgList &Args) {
diff --git a/clang/lib/Driver/ToolChains/Hexagon.h b/clang/lib/Driver/ToolChains/Hexagon.h
index 0158b9c42af9..7b2af9a799cc 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.h
+++ b/clang/lib/Driver/ToolChains/Hexagon.h
@@ -81,12 +81,18 @@ class LLVM_LIBRARY_VISIBILITY HexagonToolChain : public Linux {
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
+ void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+
const char *getDefaultLinker() const override {
return getTriple().isMusl() ? "ld.lld" : "hexagon-link";
}
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
+ void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const override;
+
StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
bool IsIntegratedAssemblerDefault() const override {
return true;
diff --git a/clang/test/Driver/Inputs/hexagon_tree/Tools/target/hexagon/include/c++/v1/readme b/clang/test/Driver/Inputs/hexagon_tree/Tools/target/hexagon/include/c++/v1/readme
new file mode 100644
index 000000000000..6e2cef0143f5
--- /dev/null
+++ b/clang/test/Driver/Inputs/hexagon_tree/Tools/target/hexagon/include/c++/v1/readme
@@ -0,0 +1,4 @@
+Git does not record empty directories. Create a dummy file in each directory
+here. Strictly speaking, putting dummy files in leaf directories should be
+sufficient, but adding them everywhere reduces the risk of repeating the same
+problem in case new directories are added.
diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c
index ee5fb220d220..4590522d2b40 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -598,88 +598,6 @@
// RUN: | FileCheck -check-prefix=CHECK084 %s
// CHECK084: "-fno-use-init-array"
// -----------------------------------------------------------------------------
-// Passing --musl
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN: -mcpu=hexagonv60 \
-// RUN: -fuse-ld=lld \
-// RUN: --sysroot=/hexagon \
-// RUN: %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK085 %s
-// CHECK085-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
-// CHECK085: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
-// CHECK085: "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
-// CHECK085: "-lclang_rt.builtins-hexagon" "-lc"
-// -----------------------------------------------------------------------------
-// Passing --musl --shared
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN: -mcpu=hexagonv60 \
-// RUN: --sysroot=/hexagon -shared \
-// RUN: %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK086 %s
-// CHECK086-NOT: -dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1
-// CHECK086: "/hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o"
-// CHECK086: "-lclang_rt.builtins-hexagon" "-lc"
-// CHECK086-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
-// -----------------------------------------------------------------------------
-// Passing --musl -nostdlib
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN: -mcpu=hexagonv60 \
-// RUN: --sysroot=/hexagon -nostdlib \
-// RUN: %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK087 %s
-// CHECK087: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
-// CHECK087-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
-// CHECK087-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
-// CHECK087-NOT: -lclang_rt.builtins-hexagon
-// CHECK087-NOT: -lc
-// -----------------------------------------------------------------------------
-// Passing --musl -nostartfiles
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN: -mcpu=hexagonv60 \
-// RUN: --sysroot=/hexagon -nostartfiles \
-// RUN: %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK088 %s
-// CHECK088: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
-// CHECK088-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
-// CHECK088-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
-// CHECK088: "-lclang_rt.builtins-hexagon" "-lc"
-// -----------------------------------------------------------------------------
-// Passing --musl -nodefaultlibs
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN: -mcpu=hexagonv60 \
-// RUN: --sysroot=/hexagon -nodefaultlibs \
-// RUN: %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK089 %s
-// CHECK089: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
-// CHECK089: "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
-// CHECK089-NOT: -lclang_rt.builtins-hexagon
-// CHECK089-NOT: -lc
-// -----------------------------------------------------------------------------
-// Not Passing -fno-use-init-array when musl is selected
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN: -mcpu=hexagonv60 \
-// RUN: %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK090 %s
-// CHECK090-NOT: -fno-use-init-array
-// -----------------------------------------------------------------------------
-// Check default linker for musl
-// -----------------------------------------------------------------------------
-// RUN: %clang -### -target hexagon-unknown-linux-musl %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK091 %s
-// CHECK091: ld.lld
-// -----------------------------------------------------------------------------
// Check default linker for elf
// -----------------------------------------------------------------------------
// RUN: %clang -### -target hexagon-unknown-elf %s 2>&1 \
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c b/clang/test/Driver/hexagon-toolchain-linux.c
new file mode 100644
index 000000000000..6c47044a2c0c
--- /dev/null
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -0,0 +1,101 @@
+// -----------------------------------------------------------------------------
+// Passing --musl
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: -fuse-ld=lld \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK000 %s
+// CHECK000-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crti.o
+// CHECK000: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK000: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o"
+// CHECK000: "-lclang_rt.builtins-hexagon" "-lc"
+// -----------------------------------------------------------------------------
+// Passing --musl --shared
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -shared \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK001 %s
+// CHECK001-NOT: -dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1
+// CHECK001: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crti.o"
+// CHECK001: "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK001-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// -----------------------------------------------------------------------------
+// Passing --musl -nostdlib
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -nostdlib \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK002 %s
+// CHECK002: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK002-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crti.o
+// CHECK002-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK002-NOT: -lclang_rt.builtins-hexagon
+// CHECK002-NOT: -lc
+// -----------------------------------------------------------------------------
+// Passing --musl -nostartfiles
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -nostartfiles \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK003 %s
+// CHECK003: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK003-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK003-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK003: "-lclang_rt.builtins-hexagon" "-lc"
+// -----------------------------------------------------------------------------
+// Passing --musl -nodefaultlibs
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -nodefaultlibs \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK004 %s
+// CHECK004: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK004: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o"
+// CHECK004-NOT: -lclang_rt.builtins-hexagon
+// CHECK004-NOT: -lc
+// -----------------------------------------------------------------------------
+// Not Passing -fno-use-init-array when musl is selected
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK005 %s
+// CHECK005-NOT: -fno-use-init-array
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+// c++ when musl is selected
+// -----------------------------------------------------------------------------
+// RUN: %clangxx -### -target hexagon-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree \
+// RUN: -mcpu=hexagonv60 \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK006 %s
+// CHECK006: "-internal-isystem" "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1"
+// -----------------------------------------------------------------------------
+// c++ when musl is selected
+// -----------------------------------------------------------------------------
+// RUN: %clangxx -### -target hexagon-unknown-elf \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -stdlib=libc++ \
+// RUN: -mcpu=hexagonv60 \
+// RUN: %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK007 %s
+// CHECK007: "-internal-isystem" "{{.*}}hexagon{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1"
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK008 %s
+// CHECK008: ld.lld
More information about the cfe-commits
mailing list