Skip to content

Commit

Permalink
[clang] [MinGW] Explicitly always pass the -fno-use-init-array
Browse files Browse the repository at this point in the history
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 llvm#55938.
  • Loading branch information
mstorsjo committed Oct 9, 2023
1 parent 29b2082 commit 89521ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Driver/mingw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 89521ab

Please sign in to comment.