llvm.org GIT mirror llvm / 24b8780
Make some headway towards compiling all of LLVM. Module-level ASM may contain definitions of functions and globals. However, we were not telling the linker that these globals had definitions. As far as it was concerned, they were just declarations. Attempt to resolve this by inserting module-level ASM functions and globals into the '_symbol' set so that the linker will know that they have values. This gets us further towards our goal of compiling LLVM, but it still has problems when linking libLTO.dylib because of the `-dead_strip' flag that's passed to the linker. <rdar://problem/11124216> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153638 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
2 changed file(s) with 56 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
203203 const char *symbolName = entry.getKey().data();
204204 info.name = symbolName;
205205 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
206 info.isFunction = false;
207 info.symbol = clgv;
206208 entry.setValue(info);
207209 }
208210 }
212214 if (objcClassNameFromExpression(c->getOperand(2), className)) {
213215 StringSet::value_type &entry = _defines.GetOrCreateValue(className);
214216 entry.setValue(1);
217
215218 NameAndAttributes info;
216219 info.name = entry.getKey().data();
217 info.attributes = lto_symbol_attributes(LTO_SYMBOL_PERMISSIONS_DATA |
218 LTO_SYMBOL_DEFINITION_REGULAR |
219 LTO_SYMBOL_SCOPE_DEFAULT);
220 info.attributes = LTO_SYMBOL_PERMISSIONS_DATA |
221 LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT;
222 info.isFunction = false;
223 info.symbol = clgv;
220224 _symbols.push_back(info);
221225 }
222226 }
241245 const char *symbolName = entry.getKey().data();
242246 info.name = symbolName;
243247 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
248 info.isFunction = false;
249 info.symbol = clgv;
244250 entry.setValue(info);
245251 }
246252
259265 const char *symbolName = entry.getKey().data();
260266 info.name = symbolName;
261267 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
268 info.isFunction = false;
269 info.symbol = clgv;
262270 entry.setValue(info);
263271 }
264272
331339 uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0;
332340
333341 // set permissions part
334 if (isFunction)
342 if (isFunction) {
335343 attr |= LTO_SYMBOL_PERMISSIONS_CODE;
336 else {
344 } else {
337345 GlobalVariable *gv = dyn_cast(def);
338346 if (gv && gv->isConstant())
339347 attr |= LTO_SYMBOL_PERMISSIONS_RODATA;
365373 else
366374 attr |= LTO_SYMBOL_SCOPE_INTERNAL;
367375
368 // add to table of symbols
369 NameAndAttributes info;
370376 StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer);
371377 entry.setValue(1);
372378
379 // fill information structure
380 NameAndAttributes info;
373381 StringRef Name = entry.getKey();
374382 info.name = Name.data();
375383 assert(info.name[Name.size()] == '\0');
376 info.attributes = (lto_symbol_attributes)attr;
384 info.attributes = attr;
385 info.isFunction = isFunction;
386 info.symbol = def;
387
388 // add to table of symbols
377389 _symbols.push_back(info);
378390 }
379391
388400 return;
389401
390402 entry.setValue(1);
391 const char *symbolName = entry.getKey().data();
392 uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR;
393 attr |= scope;
394 NameAndAttributes info;
395 info.name = symbolName;
396 info.attributes = (lto_symbol_attributes)attr;
397 _symbols.push_back(info);
403
404 NameAndAttributes &info = _undefines[entry.getKey().data()];
405
406 if (info.isFunction)
407 addDefinedFunctionSymbol(cast(info.symbol));
408 else
409 addDefinedDataSymbol(info.symbol);
398410 }
399411
400412 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
413425 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
414426 NameAndAttributes info;
415427 info.name = entry.getKey().data();
416 info.attributes = (lto_symbol_attributes)attr;
428 info.attributes = attr;
429 info.isFunction = false;
430 info.symbol = 0;
417431
418432 entry.setValue(info);
419433 }
420434
421435 /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet to a
422436 /// list to be resolved later.
423 void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl) {
437 void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) {
424438 // ignore all llvm.* symbols
425439 if (decl->getName().startswith("llvm."))
426440 return;
447461 info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
448462 else
449463 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
464
465 info.isFunction = isFunc;
466 info.symbol = decl;
450467
451468 entry.setValue(info);
452469 }
604621 }
605622 virtual void FinishImpl() {}
606623 };
607 }
624 } // end anonymous namespace
608625
609626 /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the
610627 /// defined or undefined lists.
667684 // add functions
668685 for (Module::iterator f = _module->begin(), e = _module->end(); f != e; ++f) {
669686 if (isDeclaration(*f))
670 addPotentialUndefinedSymbol(f);
687 addPotentialUndefinedSymbol(f, true);
671688 else
672689 addDefinedFunctionSymbol(f);
673690 }
676693 for (Module::global_iterator v = _module->global_begin(),
677694 e = _module->global_end(); v != e; ++v) {
678695 if (isDeclaration(*v))
679 addPotentialUndefinedSymbol(v);
696 addPotentialUndefinedSymbol(v, false);
680697 else
681698 addDefinedDataSymbol(v);
682699 }
686703 return true;
687704
688705 // add aliases
689 for (Module::alias_iterator i = _module->alias_begin(),
690 e = _module->alias_end(); i != e; ++i) {
691 if (isDeclaration(*i->getAliasedGlobal()))
706 for (Module::alias_iterator a = _module->alias_begin(),
707 e = _module->alias_end(); a != e; ++a) {
708 if (isDeclaration(*a->getAliasedGlobal()))
692709 // Is an alias to a declaration.
693 addPotentialUndefinedSymbol(i);
710 addPotentialUndefinedSymbol(a, false);
694711 else
695 addDefinedDataSymbol(i);
712 addDefinedDataSymbol(a);
696713 }
697714
698715 // make symbols for all undefines
699 for (StringMap::iterator it=_undefines.begin(),
700 e = _undefines.end(); it != e; ++it) {
701 // if this symbol also has a definition, then don't make an undefine
702 // because it is a tentative definition
703 if (_defines.count(it->getKey()) == 0) {
704 NameAndAttributes info = it->getValue();
705 _symbols.push_back(info);
706 }
707 }
716 for (StringMap::iterator u =_undefines.begin(),
717 e = _undefines.end(); u != e; ++u) {
718 // If this symbol also has a definition, then don't make an undefine because
719 // it is a tentative definition.
720 if (_defines.count(u->getKey())) continue;
721 NameAndAttributes info = u->getValue();
722 _symbols.push_back(info);
723 }
724
708725 return false;
709726 }
4242 typedef llvm::StringMap StringSet;
4343
4444 struct NameAndAttributes {
45 const char *name;
46 uint32_t attributes;
45 const char *name;
46 uint32_t attributes;
47 bool isFunction;
48 llvm::GlobalValue *symbol;
4749 };
4850
4951 llvm::OwningPtr _module;
133135
134136 /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet
135137 /// to a list to be resolved later.
136 void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl);
138 void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl, bool isFunc);
137139
138140 /// addDefinedSymbol - Add a defined symbol to the list.
139141 void addDefinedSymbol(llvm::GlobalValue *def, bool isFunction);