[clang] [Hexagon] Add LTO options to Hexagon driver link args (PR #191336)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 20:58:32 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-hexagon
Author: Brian Cain (androm3da)
<details>
<summary>Changes</summary>
The Hexagon driver's constructHexagonLinkArgs() was not calling addLTOOptions(). This meant that LTO plugin options weren't forwarded to the linker.
This caused a crash when using ThinLTO with -fenable-matrix on llvm-test-suite/SingleSource/UnitTests/matrix-types-spec.cpp: LowerMatrixIntrinsicsPass did not run in the LTO backend because -enable-matrix was not forwarded via -plugin-opt.
Add the addLTOOptions() call to both the musl and bare-metal code paths in constructHexagonLinkArgs().
---
Full diff: https://github.com/llvm/llvm-project/pull/191336.diff
3 Files Affected:
- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+8)
- (modified) clang/test/Driver/hexagon-toolchain-elf.c (+12)
- (modified) clang/test/Driver/hexagon-toolchain-linux.c (+13)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index e5c90089f8cf0..801682eef57d3 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -358,6 +358,10 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
options::OPT_t, options::OPT_u_Group});
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
+ if (D.isUsingLTO())
+ addLTOOptions(HTC, Args, CmdArgs, Output, Inputs,
+ D.getLTOMode() == LTOK_Thin);
+
ToolChain::UnwindLibType UNW = HTC.GetUnwindLibType(Args);
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -438,6 +442,10 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
+ if (D.isUsingLTO())
+ addLTOOptions(HTC, Args, CmdArgs, Output, Inputs,
+ D.getLTOMode() == LTOK_Thin);
+
//----------------------------------------------------------------------------
// Libraries
//----------------------------------------------------------------------------
diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c
index f2634559f75ea..16cfddedc12ca 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -598,3 +598,15 @@
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
// RUN: -mcpu=hexagonv60 %s 2>&1 | FileCheck -check-prefix=CHECK384 %s
// CHECK384: "-fno-use-init-array"
+// -----------------------------------------------------------------------------
+// ThinLTO passes LTO options to the linker
+// -----------------------------------------------------------------------------
+// RUN: touch %t.o
+// RUN: %clang -### --target=hexagon-unknown-elf \
+// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN: -mcpu=hexagonv60 \
+// RUN: -fuse-ld=lld \
+// RUN: -flto=thin -fenable-matrix \
+// RUN: %t.o 2>&1 | FileCheck -check-prefix=CHECK-LTO %s
+// CHECK-LTO: "-plugin-opt=thinlto"
+// CHECK-LTO: "-plugin-opt=-enable-matrix"
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c b/clang/test/Driver/hexagon-toolchain-linux.c
index c1a59c1fc99b5..05d8b53ec1aad 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -213,3 +213,16 @@
// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree %s 2>&1 | FileCheck -check-prefix=CHECK-NOSAN %s
// CHECK-NOSAN-NOT: "-L{{.*}}{{/|\\\\}}msan"
// CHECK-NOSAN-NOT: "-L{{.*}}{{/|\\\\}}asan"
+// -----------------------------------------------------------------------------
+// ThinLTO passes LTO options to the linker
+// -----------------------------------------------------------------------------
+// RUN: touch %t.o
+// 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: -flto=thin -fenable-matrix \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree %t.o 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-LTO %s
+// CHECK-LTO: "-plugin-opt=thinlto"
+// CHECK-LTO: "-plugin-opt=-enable-matrix"
``````````
</details>
https://github.com/llvm/llvm-project/pull/191336
More information about the cfe-commits
mailing list