[clang] [clang] [MinGW] Explicitly always pass the -fno-use-init-array (PR #68571)

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 9 03:21:13 PDT 2023


https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/68571

On MinGW targets, the .ctors section is always used for constructors.

Make sure that all layers of code generation is aware of this, wherever it matters, by passing the -fno-use-init-array option, setting the TargetOptions field UseInitArray to false.

This fixes https://github.com/llvm/llvm-project/issues/55938.

>From 89521ab0bfd12d7f45cacd3fa1d6c3f27ff54ab6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Mon, 9 Oct 2023 13:13:28 +0300
Subject: [PATCH] [clang] [MinGW] Explicitly always pass the
 -fno-use-init-array

On MinGW targets, the .ctors section is always used for constructors.

Make sure that all layers of code generation is aware of this,
wherever it matters, by passing the -fno-use-init-array option,
setting the TargetOptions field UseInitArray to false.

This fixes https://github.com/llvm/llvm-project/issues/55938.
---
 clang/lib/Driver/ToolChains/MinGW.cpp | 2 ++
 clang/test/Driver/mingw.cpp           | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5872e13bda358f8..d3d829a8ddbdb95 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -709,6 +709,8 @@ void toolchains::MinGW::addClangTargetOptions(
     }
   }
 
+  CC1Args.push_back("-fno-use-init-array");
+
   for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
                    options::OPT_mconsole, options::OPT_mdll}) {
     if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
diff --git a/clang/test/Driver/mingw.cpp b/clang/test/Driver/mingw.cpp
index 0f276820d0fff22..bb22a0652b486e1 100644
--- a/clang/test/Driver/mingw.cpp
+++ b/clang/test/Driver/mingw.cpp
@@ -77,3 +77,6 @@
 // CHECK_NO_SUBSYS-NOT: "--subsystem"
 // CHECK_SUBSYS_CONSOLE: "--subsystem" "console"
 // CHECK_SUBSYS_WINDOWS: "--subsystem" "windows"
+
+// RUN: %clang -target i686-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_NO_INIT_ARRAY %s
+// CHECK_NO_INIT_ARRAY: "-fno-use-init-array"



More information about the cfe-commits mailing list