Author: quic-k
Date: 2026-07-13T08:19:51-05:00
New Revision: ff599bba9d370bf58e4a34f9f29b4fb6234013f0

URL: 
https://github.com/llvm/llvm-project/commit/ff599bba9d370bf58e4a34f9f29b4fb6234013f0
DIFF: 
https://github.com/llvm/llvm-project/commit/ff599bba9d370bf58e4a34f9f29b4fb6234013f0.diff

LOG: [Hexagon] Enable init-array by default for picolibc (#208639)

Picolibc uses the modern .init_array/.fini_array mechanism rather than
legacy .init/.fini sections. Extend UseInitArrayDefault in
HexagonToolChain::addClangTargetOptions to also return true when
--cstdlib=picolibc is selected, preventing -fno-use-init-array from
being passed to cc1.

Signed-off-by: Kushal Pal <[email protected]>

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Hexagon.cpp
    clang/test/Driver/hexagon-toolchain-picolibc.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 4dd519a2c239b..2b44b70d06be1 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -833,7 +833,9 @@ void HexagonToolChain::addClangTargetOptions(const ArgList 
&DriverArgs,
                                              BoundArch BA,
                                              Action::OffloadKind) const {
 
-  bool UseInitArrayDefault = getTriple().isMusl();
+  bool UseInitArrayDefault =
+      getTriple().isMusl() ||
+      GetCStdlibType(DriverArgs) == ToolChain::CST_Picolibc;
 
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
                           options::OPT_fno_use_init_array,

diff  --git a/clang/test/Driver/hexagon-toolchain-picolibc.c 
b/clang/test/Driver/hexagon-toolchain-picolibc.c
index 85ead7da4cf26..2e46668689695 100644
--- a/clang/test/Driver/hexagon-toolchain-picolibc.c
+++ b/clang/test/Driver/hexagon-toolchain-picolibc.c
@@ -252,6 +252,15 @@
 // RUN:   -mcpu=hexagonv68 -G0 -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-H2-LIBPATHS-G0 %s
 // CHECK-H2-LIBPATHS-G0: 
"-L{{.*}}{{/|\\\\}}Inputs{{/|\\\\}}hexagon_tree{{/|\\\\}}Tools{{/|\\\\}}bin{{/|\\\\}}..{{/|\\\\}}target{{/|\\\\}}picolibc{{/|\\\\}}hexagon-unknown-h2-elf{{/|\\\\}}lib{{/|\\\\}}v68-G0"
 
+// 
-----------------------------------------------------------------------------
+// --cstdlib=picolibc enables init-array (not legacy .init/.fini)
+// 
-----------------------------------------------------------------------------
+// RUN: %clang --target=hexagon-none-elf --cstdlib=picolibc -### %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-INIT-ARRAY
+// CHECK-INIT-ARRAY-NOT: "-fno-use-init-array"
+
+// RUN: %clang --target=hexagon-h2-elf --cstdlib=picolibc -### %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-H2-INIT-ARRAY
+// CHECK-H2-INIT-ARRAY-NOT: "-fno-use-init-array"
+
 // 
=============================================================================
 // --sysroot tests: verify includes, library paths, and start files when an
 // explicit sysroot is provided together with --cstdlib=picolibc.


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to