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

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 9 23:56:01 PDT 2023


Author: Martin Storsjö
Date: 2023-10-10T09:55:56+03:00
New Revision: a2b8c49c1839076b540c542c024fcfe2361a3e47

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

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

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

When using the .ctors section, the constructors need to be emitted in
reverse order to get them execute in the right order. (Constructors with
a specific priority are sorted separately by the linker later.) In LLVM,
in CodeGen/AsmPrinter/AsmPrinter.cpp, there's code that reverses them
before writing them out, executed when using the .ctors section. This
logic is done whenever TM.Options.UseInitArray is set to false. Thus,
make sure to set UseInitArray to false for this target.

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

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/MinGW.cpp
    clang/test/Driver/mingw.cpp

Removed: 
    


################################################################################
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