Skip to content

Commit c7fae87

Browse files
committed
[clang] [hexagon] handle --unwindlib arg
Signed-off-by: Brian Cain <[email protected]>
1 parent 493d504 commit c7fae87

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def err_drv_unsupported_rtlib_for_platform : Error<
156156
"unsupported runtime library '%0' for platform '%1'">;
157157
def err_drv_invalid_unwindlib_name : Error<
158158
"invalid unwind library name in argument '%0'">;
159+
def err_drv_unsupported_unwind_for_platform : Error<
160+
"unsupported unwind library '%0' for platform '%1'">;
159161
def err_drv_incompatible_unwindlib : Error<
160162
"--rtlib=libgcc requires --unwindlib=libgcc">;
161163
def err_drv_incompatible_options : Error<

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,14 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
366366
options::OPT_t, options::OPT_u_Group});
367367
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
368368

369+
ToolChain::UnwindLibType UNW = HTC.GetUnwindLibType(Args);
370+
369371
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
370372
if (NeedsSanitizerDeps) {
371373
linkSanitizerRuntimeDeps(HTC, Args, CmdArgs);
372374

373-
CmdArgs.push_back("-lunwind");
375+
if (UNW != ToolChain::UNW_None)
376+
CmdArgs.push_back("-lunwind");
374377
}
375378
if (NeedsXRayDeps)
376379
linkXRayRuntimeDeps(HTC, Args, CmdArgs);
@@ -618,13 +621,24 @@ HexagonToolChain::~HexagonToolChain() {}
618621
void HexagonToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
619622
ArgStringList &CmdArgs) const {
620623
CXXStdlibType Type = GetCXXStdlibType(Args);
624+
ToolChain::UnwindLibType UNW = GetUnwindLibType(Args);
625+
if (UNW != ToolChain::UNW_None && UNW != ToolChain::UNW_CompilerRT) {
626+
const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
627+
if (A) {
628+
getDriver().Diag(diag::err_drv_unsupported_unwind_for_platform)
629+
<< A->getValue() << getTriple().normalize();
630+
return;
631+
}
632+
}
633+
621634
switch (Type) {
622635
case ToolChain::CST_Libcxx:
623636
CmdArgs.push_back("-lc++");
624637
if (Args.hasArg(options::OPT_fexperimental_library))
625638
CmdArgs.push_back("-lc++experimental");
626639
CmdArgs.push_back("-lc++abi");
627-
CmdArgs.push_back("-lunwind");
640+
if (UNW != ToolChain::UNW_None)
641+
CmdArgs.push_back("-lunwind");
628642
break;
629643

630644
case ToolChain::CST_Libstdcxx:

clang/test/Driver/hexagon-toolchain-linux.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,36 @@
119119
// CHECK010: crt1.o
120120
// CHECK010: "-L/tmp"
121121
// CHECK010-NOT: "-lstandalone"
122+
123+
// -----------------------------------------------------------------------------
124+
// unwindlib
125+
// -----------------------------------------------------------------------------
126+
// RUN: %clangxx --unwindlib=none \
127+
// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
128+
// RUN: | FileCheck -check-prefix=CHECK011 %s
129+
// CHECK011: InstalledDir: [[INSTALLED_DIR:.+]]
130+
// CHECK011: crt1.o
131+
// CHECK011-NOT: "-lunwind"
132+
// CHECK011-NOT: "-lgcc_eh"
133+
// CHECK012-NOT: "-lgcc_s"
134+
135+
136+
// RUN: %clangxx --rtlib=compiler-rt --unwindlib=libunwind \
137+
// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
138+
// RUN: | FileCheck -check-prefix=CHECK012 %s
139+
// RUN: %clangxx \
140+
// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
141+
// RUN: | FileCheck -check-prefix=CHECK012 %s
142+
// CHECK012: InstalledDir: [[INSTALLED_DIR:.+]]
143+
// CHECK012: crt1.o
144+
// CHECK012: "-lunwind"
145+
// CHECK012-NOT: "-lgcc_eh"
146+
// CHECK012-NOT: "-lgcc_s"
147+
148+
// RUN: not %clangxx --rtlib=compiler-rt --unwindlib=libgcc \
149+
// RUN: --target=hexagon-unknown-linux-musl %s -### 2>&1 \
150+
// RUN: | FileCheck -check-prefix=CHECK013 %s
151+
// CHECK013: error: unsupported unwind library 'libgcc' for platform 'hexagon-unknown-linux-musl'
152+
// CHECK013-NOT: "-lgcc_eh"
153+
// CHECK013-NOT: "-lgcc_s"
154+
// CHECK013-NOT: "-lunwind"

0 commit comments

Comments
 (0)