-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] [hexagon] handle --unwindlib arg #99552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-hexagon @llvm/pr-subscribers-clang-driver Author: Brian Cain (androm3da) ChangesFull diff: https://github.com/llvm/llvm-project/pull/99552.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 359c0de7f811c..2a1f58ade74a2 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<
+ "unwind library '%0' is not supported by this platform">;
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..6df60c3e945ee 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();
+ 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..edbd333628747 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: unwind library 'libgcc' is not supported by this platform
+// CHECK013-NOT: "-lgcc_eh"
+// CHECK013-NOT: "-lgcc_s"
+// CHECK013-NOT: "-lunwind"
|
@llvm/pr-subscribers-clang Author: Brian Cain (androm3da) ChangesFull diff: https://github.com/llvm/llvm-project/pull/99552.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 359c0de7f811c..2a1f58ade74a2 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<
+ "unwind library '%0' is not supported by this platform">;
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..6df60c3e945ee 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();
+ 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..edbd333628747 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: unwind library 'libgcc' is not supported by this platform
+// CHECK013-NOT: "-lgcc_eh"
+// CHECK013-NOT: "-lgcc_s"
+// CHECK013-NOT: "-lunwind"
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
304b87c
to
4729e43
Compare
@@ -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< | |||
"unwind library '%0' is not supported by this platform">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps the message could be made more similar to err_drv_unsupported_rtlib_for_platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately changed it because I didn't know how to describe this platform in the %1
.
But yeah I can make it like that and use the triple I guess.
Signed-off-by: Brian Cain <[email protected]>
4729e43
to
c7fae87
Compare
Summary: Signed-off-by: Brian Cain <[email protected]> Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251395
No description provided.