Skip to content

Commit f50c638

Browse files
mstorsjotru
authored andcommitted
[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 llvm/llvm-project#55938. (cherry picked from commit a2b8c49c1839076b540c542c024fcfe2361a3e47)
1 parent d10b731 commit f50c638

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ void toolchains::MinGW::addClangTargetOptions(
699699
}
700700
}
701701

702+
CC1Args.push_back("-fno-use-init-array");
703+
702704
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
703705
options::OPT_mconsole, options::OPT_mdll}) {
704706
if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))

clang/test/Driver/mingw.cpp

Lines changed: 3 additions & 0 deletions
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)