[clang] 962d018 - [clang] [hexagon] handle --unwindlib arg (#99552)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 19:12:24 PDT 2024
Author: Brian Cain
Date: 2024-07-18T21:12:21-05:00
New Revision: 962d018234cb8c94e387fe3950cd030658850541
URL: https://github.com/llvm/llvm-project/commit/962d018234cb8c94e387fe3950cd030658850541
DIFF: https://github.com/llvm/llvm-project/commit/962d018234cb8c94e387fe3950cd030658850541.diff
LOG: [clang] [hexagon] handle --unwindlib arg (#99552)
Signed-off-by: Brian Cain <bcain at quicinc.com>
Added:
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-toolchain-linux.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index cfa897f28b4c0..26a9792e6a608 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -156,6 +156,8 @@ def err_drv_unsupported_rtlib_for_platform : Error<
"unsupported runtime library '%0' for platform '%1'">;
def err_drv_invalid_unwindlib_name : Error<
"invalid unwind library name in argument '%0'">;
+def err_drv_unsupported_unwind_for_platform : Error<
+ "unsupported unwind library '%0' for platform '%1'">;
def err_drv_incompatible_unwindlib : Error<
"--rtlib=libgcc requires --unwindlib=libgcc">;
def err_drv_incompatible_options : Error<
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 12b3b99df7ca1..29781399cbab4 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -366,11 +366,14 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
options::OPT_t, options::OPT_u_Group});
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
+ ToolChain::UnwindLibType UNW = HTC.GetUnwindLibType(Args);
+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
if (NeedsSanitizerDeps) {
linkSanitizerRuntimeDeps(HTC, Args, CmdArgs);
- CmdArgs.push_back("-lunwind");
+ if (UNW != ToolChain::UNW_None)
+ CmdArgs.push_back("-lunwind");
}
if (NeedsXRayDeps)
linkXRayRuntimeDeps(HTC, Args, CmdArgs);
@@ -618,13 +621,24 @@ HexagonToolChain::~HexagonToolChain() {}
void HexagonToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
CXXStdlibType Type = GetCXXStdlibType(Args);
+ ToolChain::UnwindLibType UNW = GetUnwindLibType(Args);
+ if (UNW != ToolChain::UNW_None && UNW != ToolChain::UNW_CompilerRT) {
+ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
+ if (A) {
+ getDriver().Diag(diag::err_drv_unsupported_unwind_for_platform)
+ << A->getValue() << getTriple().normalize();
+ return;
+ }
+ }
+
switch (Type) {
case ToolChain::CST_Libcxx:
CmdArgs.push_back("-lc++");
if (Args.hasArg(options::OPT_fexperimental_library))
CmdArgs.push_back("-lc++experimental");
CmdArgs.push_back("-lc++abi");
- CmdArgs.push_back("-lunwind");
+ if (UNW != ToolChain::UNW_None)
+ CmdArgs.push_back("-lunwind");
break;
case ToolChain::CST_Libstdcxx:
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c b/clang/test/Driver/hexagon-toolchain-linux.c
index fe32638417ea4..86cc9a30e932c 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,36 @@
// CHECK010: crt1.o
// CHECK010: "-L/tmp"
// CHECK010-NOT: "-lstandalone"
+
+// -----------------------------------------------------------------------------
+// unwindlib
+// -----------------------------------------------------------------------------
+// RUN: %clangxx --unwindlib=none \
+// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK011 %s
+// CHECK011: InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK011: crt1.o
+// CHECK011-NOT: "-lunwind"
+// CHECK011-NOT: "-lgcc_eh"
+// CHECK012-NOT: "-lgcc_s"
+
+
+// RUN: %clangxx --rtlib=compiler-rt --unwindlib=libunwind \
+// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK012 %s
+// RUN: %clangxx \
+// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK012 %s
+// CHECK012: InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK012: crt1.o
+// CHECK012: "-lunwind"
+// CHECK012-NOT: "-lgcc_eh"
+// CHECK012-NOT: "-lgcc_s"
+
+// RUN: not %clangxx --rtlib=compiler-rt --unwindlib=libgcc \
+// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK013 %s
+// CHECK013: error: unsupported unwind library 'libgcc' for platform 'hexagon-unknown-linux-musl'
+// CHECK013-NOT: "-lgcc_eh"
+// CHECK013-NOT: "-lgcc_s"
+// CHECK013-NOT: "-lunwind"
More information about the cfe-commits
mailing list