Skip to content

Commit b37cd62

Browse files
committed
[IRGen] Set TargetOpts.UseInitArray in getIRTargetOptions().
IRGen sets up the `llvm::TargetOptions` by itself, rather than copying them from the Clang instance (it has to do this, at present, because Clang doesn't provide a way to get it to initialise one). Unfortunately, it didn't set `UseInitArray`, which when linking with GNU `ld` or `gold` is *fine* because those linkers automatically convert `.ctors` and `.dtors` sections into `.init_array` and `.fini_array` respectively. *However*, `lld` does *not* do this conversion, so when using `lld`, if the compiler generates a constructor or destructor function, it won't be called(!) The fix is to set `UseInitArray` properly; I chose to copy the setting from Clang, just in case Clang knows of a reason why it shouldn't be `true`. rdar://123504095
1 parent 168a977 commit b37cd62

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ swift::getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx) {
138138

139139
auto *Clang = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
140140

141+
// Set UseInitArray appropriately.
142+
TargetOpts.UseInitArray = Clang->getCodeGenOpts().UseInitArray;
143+
141144
// WebAssembly doesn't support atomics yet, see
142145
// https://github.com/apple/swift/issues/54533 for more details.
143146
if (Clang->getTargetInfo().getTriple().isOSBinFormatWasm())

0 commit comments

Comments
 (0)