Skip to content

Commit a2b8c49

Browse files
authored
[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 #55938.
1 parent d37056c commit a2b8c49

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/Driver/ToolChains/MinGW.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ void toolchains::MinGW::addClangTargetOptions(
709709
}
710710
}
711711

712+
CC1Args.push_back("-fno-use-init-array");
713+
712714
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
713715
options::OPT_mconsole, options::OPT_mdll}) {
714716
if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))

clang/test/Driver/mingw.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@
7777
// CHECK_NO_SUBSYS-NOT: "--subsystem"
7878
// CHECK_SUBSYS_CONSOLE: "--subsystem" "console"
7979
// CHECK_SUBSYS_WINDOWS: "--subsystem" "windows"
80+
81+
// RUN: %clang -target i686-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_NO_INIT_ARRAY %s
82+
// CHECK_NO_INIT_ARRAY: "-fno-use-init-array"

0 commit comments

Comments
 (0)