[lld] r265085 - [LTO] Inherit options from Codegen before initializing TargetMachine.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 31 17:35:29 PDT 2016
Author: davide
Date: Thu Mar 31 19:35:29 2016
New Revision: 265085
URL: http://llvm.org/viewvc/llvm-project?rev=265085&view=rev
Log:
[LTO] Inherit options from Codegen before initializing TargetMachine.
This fixes bootstrap of llvm-tblgen (with LTO) and PR27150.
Slightly longer explanation follows.
Emission of .init_array instead of .ctors is supported only on a
subset of the Target LLVM supports. Codegen needs to be conservative
and always emit .ctors unless instructed otherwise (based on target).
If the dynamic linker sees .init_array it completely ignores
what's inside .ctors and therefore some constructors are not called
(and this causes llvm-tblgen to crash on startup).
Teach LLD/LTO about the Codegen options so we end up always emitting
.init_array and avoid this issue.
In future, we might end up supporting mix of .ctors and .init_array
in different input files if this shows up as a real-world use case.
The way gold handles this case is mapping .ctors from input into
.init_array in output. There's also another caveat because
as far as I understand .ctors run in reverse order so when we do
the copy/mapping we need to reverse copy in the output if there's
more than one ctor. That's why I'd rather avoid this complicate logic
unless there's a real need.
An analogous reasoning holds for .dtors/.fini_array.
Modified:
lld/trunk/ELF/LTO.cpp
lld/trunk/test/ELF/lto/ctors.ll
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=265085&r1=265084&r2=265085&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Thu Mar 31 19:35:29 2016
@@ -15,6 +15,7 @@
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Linker/IRMover.h"
#include "llvm/Support/StringSaver.h"
@@ -167,7 +168,7 @@ TargetMachine *BitcodeCompiler::getTarge
const Target *T = TargetRegistry::lookupTarget(TripleStr, Msg);
if (!T)
fatal("target not found: " + Msg);
- TargetOptions Options;
+ TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
Reloc::Model R = Config->Pic ? Reloc::PIC_ : Reloc::Static;
return T->createTargetMachine(TripleStr, "", "", Options, R);
}
Modified: lld/trunk/test/ELF/lto/ctors.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/ctors.ll?rev=265085&r1=265084&r2=265085&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/ctors.ll (original)
+++ lld/trunk/test/ELF/lto/ctors.ll Thu Mar 31 19:35:29 2016
@@ -13,4 +13,6 @@ define void @ctor() {
}
; The llvm.global_ctors should end up producing constructors.
-; CHECK: Name: .ctors
+; On x86-64 (linux) we should always emit .init_array and never .ctors.
+; CHECK: Name: .init_array
+; CHECK-NOT: Name: .ctors
More information about the llvm-commits
mailing list