1 //===-- LTOModule.cpp - LLVM Link Time Optimizer --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Link Time Optimization library. This library is
11 // intended to be used by linker to optimize code at link time.
13 //===----------------------------------------------------------------------===//
15 #include "LTOModule.h"
16 #include "llvm/Constants.h"
17 #include "llvm/LLVMContext.h"
18 #include "llvm/Module.h"
19 #include "llvm/Bitcode/ReaderWriter.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/MC/MCInst.h"
22 #include "llvm/MC/MCStreamer.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCSymbol.h"
25 #include "llvm/MC/MCTargetAsmParser.h"
26 #include "llvm/MC/SubtargetFeature.h"
27 #include "llvm/MC/MCParser/MCAsmParser.h"
28 #include "llvm/Target/TargetRegisterInfo.h"
29 #include "llvm/Support/Host.h"
30 #include "llvm/Support/MemoryBuffer.h"
31 #include "llvm/Support/Path.h"
32 #include "llvm/Support/SourceMgr.h"
33 #include "llvm/Support/TargetRegistry.h"
34 #include "llvm/Support/TargetSelect.h"
35 #include "llvm/Support/system_error.h"
36 #include "llvm/ADT/OwningPtr.h"
37 #include "llvm/ADT/Triple.h"
40 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
41 : _module(m), _target(t),
42 _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL),
43 _mangler(_context, *_target->getTargetData()) {}
45 /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
47 bool LTOModule::isBitcodeFile(const void *mem, size_t length) {
48 return llvm::sys::IdentifyFileType((char*)mem, length)
49 == llvm::sys::Bitcode_FileType;
52 bool LTOModule::isBitcodeFile(const char *path) {
53 return llvm::sys::Path(path).isBitcodeFile();
56 /// isBitcodeFileForTarget - Returns 'true' if the file (or memory contents) is
57 /// LLVM bitcode for the specified triple.
58 bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length,
59 const char *triplePrefix) {
60 MemoryBuffer *buffer = makeBuffer(mem, length);
63 return isTargetMatch(buffer, triplePrefix);
66 bool LTOModule::isBitcodeFileForTarget(const char *path,
67 const char *triplePrefix) {
68 OwningPtr<MemoryBuffer> buffer;
69 if (MemoryBuffer::getFile(path, buffer))
71 return isTargetMatch(buffer.take(), triplePrefix);
74 /// isTargetMatch - Returns 'true' if the memory buffer is for the specified
76 bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
77 std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
79 return strncmp(Triple.c_str(), triplePrefix, strlen(triplePrefix)) == 0;
82 /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership of
84 LTOModule *LTOModule::makeLTOModule(const char *path, std::string &errMsg) {
85 OwningPtr<MemoryBuffer> buffer;
86 if (error_code ec = MemoryBuffer::getFile(path, buffer)) {
87 errMsg = ec.message();
90 return makeLTOModule(buffer.take(), errMsg);
93 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
94 size_t size, std::string &errMsg) {
95 return makeLTOModule(fd, path, size, size, 0, errMsg);
98 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
102 std::string &errMsg) {
103 OwningPtr<MemoryBuffer> buffer;
104 if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, file_size,
105 map_size, offset, false)) {
106 errMsg = ec.message();
109 return makeLTOModule(buffer.take(), errMsg);
112 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
113 std::string &errMsg) {
114 OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
117 return makeLTOModule(buffer.take(), errMsg);
120 LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
121 std::string &errMsg) {
122 static bool Initialized = false;
124 InitializeAllTargets();
125 InitializeAllTargetMCs();
126 InitializeAllAsmParsers();
130 // parse bitcode buffer
131 OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext(),
138 std::string Triple = m->getTargetTriple();
140 Triple = sys::getDefaultTargetTriple();
142 // find machine architecture for this module
143 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
147 // construct LTOModule, hand over ownership of module and target
148 SubtargetFeatures Features;
149 Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
150 std::string FeatureStr = Features.getString();
152 TargetOptions Options;
153 TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr,
155 LTOModule *Ret = new LTOModule(m.take(), target);
156 if (Ret->parseSymbols(errMsg)) {
164 /// makeBuffer - Create a MemoryBuffer from a memory range.
165 MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
166 const char *startPtr = (char*)mem;
167 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false);
170 /// objcClassNameFromExpression - Get string that the data pointer points to.
171 bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
172 if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
173 Constant *op = ce->getOperand(0);
174 if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
175 Constant *cn = gvn->getInitializer();
176 if (ConstantDataArray *ca = dyn_cast<ConstantDataArray>(cn)) {
177 if (ca->isCString()) {
178 name = ".objc_class_name_" + ca->getAsCString().str();
187 /// addObjCClass - Parse i386/ppc ObjC class data structure.
188 void LTOModule::addObjCClass(GlobalVariable *clgv) {
189 ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer());
192 // second slot in __OBJC,__class is pointer to superclass name
193 std::string superclassName;
194 if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
195 NameAndAttributes info;
196 StringMap<NameAndAttributes>::value_type &entry =
197 _undefines.GetOrCreateValue(superclassName);
198 if (!entry.getValue().name) {
199 const char *symbolName = entry.getKey().data();
200 info.name = symbolName;
201 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
202 info.isFunction = false;
204 entry.setValue(info);
208 // third slot in __OBJC,__class is pointer to class name
209 std::string className;
210 if (objcClassNameFromExpression(c->getOperand(2), className)) {
211 StringSet::value_type &entry = _defines.GetOrCreateValue(className);
214 NameAndAttributes info;
215 info.name = entry.getKey().data();
216 info.attributes = LTO_SYMBOL_PERMISSIONS_DATA |
217 LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT;
218 info.isFunction = false;
220 _symbols.push_back(info);
224 /// addObjCCategory - Parse i386/ppc ObjC category data structure.
225 void LTOModule::addObjCCategory(GlobalVariable *clgv) {
226 ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer());
229 // second slot in __OBJC,__category is pointer to target class name
230 std::string targetclassName;
231 if (!objcClassNameFromExpression(c->getOperand(1), targetclassName))
234 NameAndAttributes info;
235 StringMap<NameAndAttributes>::value_type &entry =
236 _undefines.GetOrCreateValue(targetclassName);
238 if (entry.getValue().name)
241 const char *symbolName = entry.getKey().data();
242 info.name = symbolName;
243 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
244 info.isFunction = false;
246 entry.setValue(info);
249 /// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
250 void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
251 std::string targetclassName;
252 if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName))
255 NameAndAttributes info;
256 StringMap<NameAndAttributes>::value_type &entry =
257 _undefines.GetOrCreateValue(targetclassName);
258 if (entry.getValue().name)
261 const char *symbolName = entry.getKey().data();
262 info.name = symbolName;
263 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
264 info.isFunction = false;
266 entry.setValue(info);
269 /// addDefinedDataSymbol - Add a data symbol as defined to the list.
270 void LTOModule::addDefinedDataSymbol(GlobalValue *v) {
271 // Add to list of defined symbols.
272 addDefinedSymbol(v, false);
274 // Special case i386/ppc ObjC data structures in magic sections:
275 // The issue is that the old ObjC object format did some strange
276 // contortions to avoid real linker symbols. For instance, the
277 // ObjC class data structure is allocated statically in the executable
278 // that defines that class. That data structures contains a pointer to
279 // its superclass. But instead of just initializing that part of the
280 // struct to the address of its superclass, and letting the static and
281 // dynamic linkers do the rest, the runtime works by having that field
282 // instead point to a C-string that is the name of the superclass.
283 // At runtime the objc initialization updates that pointer and sets
284 // it to point to the actual super class. As far as the linker
285 // knows it is just a pointer to a string. But then someone wanted the
286 // linker to issue errors at build time if the superclass was not found.
287 // So they figured out a way in mach-o object format to use an absolute
288 // symbols (.objc_class_name_Foo = 0) and a floating reference
289 // (.reference .objc_class_name_Bar) to cause the linker into erroring when
290 // a class was missing.
291 // The following synthesizes the implicit .objc_* symbols for the linker
292 // from the ObjC data structures generated by the front end.
293 if (v->hasSection() /* && isTargetDarwin */) {
294 // special case if this data blob is an ObjC class definition
295 if (v->getSection().compare(0, 15, "__OBJC,__class,") == 0) {
296 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
301 // special case if this data blob is an ObjC category definition
302 else if (v->getSection().compare(0, 18, "__OBJC,__category,") == 0) {
303 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
308 // special case if this data blob is the list of referenced classes
309 else if (v->getSection().compare(0, 18, "__OBJC,__cls_refs,") == 0) {
310 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
317 /// addDefinedFunctionSymbol - Add a function symbol as defined to the list.
318 void LTOModule::addDefinedFunctionSymbol(Function *f) {
319 // add to list of defined symbols
320 addDefinedSymbol(f, true);
323 /// addDefinedSymbol - Add a defined symbol to the list.
324 void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) {
325 // ignore all llvm.* symbols
326 if (def->getName().startswith("llvm."))
329 // string is owned by _defines
330 SmallString<64> Buffer;
331 _mangler.getNameWithPrefix(Buffer, def, false);
333 // set alignment part log2() can have rounding errors
334 uint32_t align = def->getAlignment();
335 uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0;
337 // set permissions part
339 attr |= LTO_SYMBOL_PERMISSIONS_CODE;
341 GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
342 if (gv && gv->isConstant())
343 attr |= LTO_SYMBOL_PERMISSIONS_RODATA;
345 attr |= LTO_SYMBOL_PERMISSIONS_DATA;
348 // set definition part
349 if (def->hasWeakLinkage() || def->hasLinkOnceLinkage() ||
350 def->hasLinkerPrivateWeakLinkage() ||
351 def->hasLinkerPrivateWeakDefAutoLinkage())
352 attr |= LTO_SYMBOL_DEFINITION_WEAK;
353 else if (def->hasCommonLinkage())
354 attr |= LTO_SYMBOL_DEFINITION_TENTATIVE;
356 attr |= LTO_SYMBOL_DEFINITION_REGULAR;
359 if (def->hasHiddenVisibility())
360 attr |= LTO_SYMBOL_SCOPE_HIDDEN;
361 else if (def->hasProtectedVisibility())
362 attr |= LTO_SYMBOL_SCOPE_PROTECTED;
363 else if (def->hasExternalLinkage() || def->hasWeakLinkage() ||
364 def->hasLinkOnceLinkage() || def->hasCommonLinkage() ||
365 def->hasLinkerPrivateWeakLinkage())
366 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
367 else if (def->hasLinkerPrivateWeakDefAutoLinkage())
368 attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN;
370 attr |= LTO_SYMBOL_SCOPE_INTERNAL;
372 StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer);
375 // fill information structure
376 NameAndAttributes info;
377 StringRef Name = entry.getKey();
378 info.name = Name.data();
379 assert(info.name[Name.size()] == '\0');
380 info.attributes = attr;
381 info.isFunction = isFunction;
384 // add to table of symbols
385 _symbols.push_back(info);
388 /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the
390 void LTOModule::addAsmGlobalSymbol(const char *name,
391 lto_symbol_attributes scope) {
392 StringSet::value_type &entry = _defines.GetOrCreateValue(name);
394 // only add new define if not already defined
395 if (entry.getValue())
400 NameAndAttributes &info = _undefines[entry.getKey().data()];
402 if (info.symbol == 0) {
403 // If we haven't seen this symbol before, save it and we may see it again.
404 StringMap<NameAndAttributes>::value_type
405 &asm_entry = _asm_defines.GetOrCreateValue(name);
406 NameAndAttributes &asm_info = _asm_defines[asm_entry.getKey().data()];
407 asm_info.name = name;
408 asm_info.attributes = scope;
409 asm_info.isFunction = false;
415 addDefinedFunctionSymbol(cast<Function>(info.symbol));
417 addDefinedDataSymbol(info.symbol);
419 _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK;
420 _symbols.back().attributes |= scope;
423 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
425 void LTOModule::addAsmGlobalSymbolUndef(const char *name) {
426 StringMap<NameAndAttributes>::value_type &entry =
427 _undefines.GetOrCreateValue(name);
429 _asm_undefines.push_back(entry.getKey().data());
431 // we already have the symbol
432 if (entry.getValue().name)
435 uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED;;
436 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
437 NameAndAttributes info;
438 info.name = entry.getKey().data();
439 info.attributes = attr;
440 info.isFunction = false;
443 entry.setValue(info);
446 /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet to a
447 /// list to be resolved later.
448 void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) {
449 // ignore all llvm.* symbols
450 if (decl->getName().startswith("llvm."))
453 // ignore all aliases
454 if (isa<GlobalAlias>(decl))
457 SmallString<64> name;
458 _mangler.getNameWithPrefix(name, decl, false);
460 StringMap<NameAndAttributes>::value_type &entry =
461 _undefines.GetOrCreateValue(name);
463 // we already have the symbol
464 if (entry.getValue().name)
467 StringMap<NameAndAttributes>::value_type &asm_entry =
468 _asm_defines.GetOrCreateValue(name);
470 if (asm_entry.getValue().name != 0) {
472 addDefinedFunctionSymbol(cast<Function>(decl));
474 addDefinedDataSymbol(decl);
476 _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK;
477 _symbols.back().attributes |= asm_entry.getValue().attributes;
481 NameAndAttributes info;
483 info.name = entry.getKey().data();
485 if (decl->hasExternalWeakLinkage())
486 info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
488 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
490 info.isFunction = isFunc;
493 entry.setValue(info);
497 class RecordStreamer : public MCStreamer {
499 enum State { NeverSeen, Global, Defined, DefinedGlobal, Used};
502 StringMap<State> Symbols;
504 void markDefined(const MCSymbol &Symbol) {
505 State &S = Symbols[Symbol.getName()];
518 void markGlobal(const MCSymbol &Symbol) {
519 State &S = Symbols[Symbol.getName()];
533 void markUsed(const MCSymbol &Symbol) {
534 State &S = Symbols[Symbol.getName()];
548 // FIXME: mostly copied for the obj streamer.
549 void AddValueSymbols(const MCExpr *Value) {
550 switch (Value->getKind()) {
552 // FIXME: What should we do in here?
555 case MCExpr::Constant:
558 case MCExpr::Binary: {
559 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
560 AddValueSymbols(BE->getLHS());
561 AddValueSymbols(BE->getRHS());
565 case MCExpr::SymbolRef:
566 markUsed(cast<MCSymbolRefExpr>(Value)->getSymbol());
570 AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr());
576 typedef StringMap<State>::const_iterator const_iterator;
578 const_iterator begin() {
579 return Symbols.begin();
582 const_iterator end() {
583 return Symbols.end();
586 RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
588 virtual void ChangeSection(const MCSection *Section) {}
589 virtual void InitSections() {}
590 virtual void EmitLabel(MCSymbol *Symbol) {
591 Symbol->setSection(*getCurrentSection());
592 markDefined(*Symbol);
594 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {}
595 virtual void EmitThumbFunc(MCSymbol *Func) {}
596 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
597 // FIXME: should we handle aliases?
598 markDefined(*Symbol);
600 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
601 if (Attribute == MCSA_Global)
604 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
605 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
606 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {}
607 virtual void EmitCOFFSymbolStorageClass(int StorageClass) {}
608 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
609 unsigned Size , unsigned ByteAlignment) {
610 markDefined(*Symbol);
612 virtual void EmitCOFFSymbolType(int Type) {}
613 virtual void EndCOFFSymbolDef() {}
614 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
615 unsigned ByteAlignment) {
616 markDefined(*Symbol);
618 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
619 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
620 unsigned ByteAlignment) {}
621 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
622 uint64_t Size, unsigned ByteAlignment) {}
623 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
624 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
625 unsigned AddrSpace) {}
626 virtual void EmitULEB128Value(const MCExpr *Value) {}
627 virtual void EmitSLEB128Value(const MCExpr *Value) {}
628 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
630 unsigned MaxBytesToEmit) {}
631 virtual void EmitCodeAlignment(unsigned ByteAlignment,
632 unsigned MaxBytesToEmit) {}
633 virtual bool EmitValueToOffset(const MCExpr *Offset,
634 unsigned char Value ) { return false; }
635 virtual void EmitFileDirective(StringRef Filename) {}
636 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
637 const MCSymbol *LastLabel,
638 const MCSymbol *Label,
639 unsigned PointerSize) {}
641 virtual void EmitInstruction(const MCInst &Inst) {
643 for (unsigned i = Inst.getNumOperands(); i--; )
644 if (Inst.getOperand(i).isExpr())
645 AddValueSymbols(Inst.getOperand(i).getExpr());
647 virtual void FinishImpl() {}
649 } // end anonymous namespace
651 /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the
652 /// defined or undefined lists.
653 bool LTOModule::addAsmGlobalSymbols(std::string &errMsg) {
654 const std::string &inlineAsm = _module->getModuleInlineAsm();
655 if (inlineAsm.empty())
658 OwningPtr<RecordStreamer> Streamer(new RecordStreamer(_context));
659 MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(inlineAsm);
661 SrcMgr.AddNewSourceBuffer(Buffer, SMLoc());
662 OwningPtr<MCAsmParser> Parser(createMCAsmParser(SrcMgr,
664 *_target->getMCAsmInfo()));
665 OwningPtr<MCSubtargetInfo> STI(_target->getTarget().
666 createMCSubtargetInfo(_target->getTargetTriple(),
667 _target->getTargetCPU(),
668 _target->getTargetFeatureString()));
669 OwningPtr<MCTargetAsmParser>
670 TAP(_target->getTarget().createMCAsmParser(*STI, *Parser.get()));
672 errMsg = "target " + std::string(_target->getTarget().getName()) +
673 " does not define AsmParser.";
677 Parser->setTargetParser(*TAP);
678 int Res = Parser->Run(false);
682 for (RecordStreamer::const_iterator i = Streamer->begin(),
683 e = Streamer->end(); i != e; ++i) {
684 StringRef Key = i->first();
685 RecordStreamer::State Value = i->second;
686 if (Value == RecordStreamer::DefinedGlobal)
687 addAsmGlobalSymbol(Key.data(), LTO_SYMBOL_SCOPE_DEFAULT);
688 else if (Value == RecordStreamer::Defined)
689 addAsmGlobalSymbol(Key.data(), LTO_SYMBOL_SCOPE_INTERNAL);
690 else if (Value == RecordStreamer::Global ||
691 Value == RecordStreamer::Used)
692 addAsmGlobalSymbolUndef(Key.data());
697 /// isDeclaration - Return 'true' if the global value is a declaration.
698 static bool isDeclaration(const GlobalValue &V) {
699 if (V.hasAvailableExternallyLinkage())
701 if (V.isMaterializable())
703 return V.isDeclaration();
706 /// parseSymbols - Parse the symbols from the module and model-level ASM and add
707 /// them to either the defined or undefined lists.
708 bool LTOModule::parseSymbols(std::string &errMsg) {
710 for (Module::iterator f = _module->begin(), e = _module->end(); f != e; ++f) {
711 if (isDeclaration(*f))
712 addPotentialUndefinedSymbol(f, true);
714 addDefinedFunctionSymbol(f);
718 for (Module::global_iterator v = _module->global_begin(),
719 e = _module->global_end(); v != e; ++v) {
720 if (isDeclaration(*v))
721 addPotentialUndefinedSymbol(v, false);
723 addDefinedDataSymbol(v);
727 if (addAsmGlobalSymbols(errMsg))
731 for (Module::alias_iterator a = _module->alias_begin(),
732 e = _module->alias_end(); a != e; ++a) {
733 if (isDeclaration(*a->getAliasedGlobal()))
734 // Is an alias to a declaration.
735 addPotentialUndefinedSymbol(a, false);
737 addDefinedDataSymbol(a);
740 // make symbols for all undefines
741 for (StringMap<NameAndAttributes>::iterator u =_undefines.begin(),
742 e = _undefines.end(); u != e; ++u) {
743 // If this symbol also has a definition, then don't make an undefine because
744 // it is a tentative definition.
745 if (_defines.count(u->getKey())) continue;
746 NameAndAttributes info = u->getValue();
747 _symbols.push_back(info);