Skip to content

[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

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
18 changes: 16 additions & 2 deletions clang/lib/Driver/ToolChains/Hexagon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
33 changes: 33 additions & 0 deletions clang/test/Driver/hexagon-toolchain-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading