Add back r201608, r201622, r201624 and r201625
r201608 made llvm corretly handle private globals with MachO. r201622 fixed
a bug in it and r201624 and r201625 were changes for using private linkage,
assuming that llvm would do the right thing.
They all got reverted because r201608 introduced a crash in LTO. This patch
includes a fix for that. The issue was that TargetLoweringObjectFile now has
to be initialized before we can mangle names of private globals. This is
trivially true during the normal codegen pipeline (the asm printer does it),
but LTO has to do it manually.
llvm-svn: 201700
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index 909b92e..86b67ef 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -176,6 +176,16 @@
m->materializeAllPermanently();
LTOModule *Ret = new LTOModule(m.take(), target);
+
+ // We need a MCContext set up in order to get mangled names of private
+ // symbols. It is a bit odd that we need to report uses and definitions
+ // of private symbols, but it does look like ld64 expects to be informed
+ // of at least the ones with an 'l' prefix.
+ MCContext &Context = Ret->_context;
+ const TargetLoweringObjectFile &TLOF =
+ target->getTargetLowering()->getObjFileLowering();
+ const_cast<TargetLoweringObjectFile &>(TLOF).Initialize(Context, *target);
+
if (Ret->parseSymbols(errMsg)) {
delete Ret;
return NULL;
@@ -381,7 +391,7 @@
// string is owned by _defines
SmallString<64> Buffer;
- _mangler.getNameWithPrefix(Buffer, def);
+ _target->getTargetLowering()->getNameWithPrefix(Buffer, def, _mangler);
// set alignment part log2() can have rounding errors
uint32_t align = def->getAlignment();
@@ -517,7 +527,7 @@
return;
SmallString<64> name;
- _mangler.getNameWithPrefix(name, decl);
+ _target->getTargetLowering()->getNameWithPrefix(name, decl, _mangler);
StringMap<NameAndAttributes>::value_type &entry =
_undefines.GetOrCreateValue(name);