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"
17 #include "llvm/Constants.h"
18 #include "llvm/LLVMContext.h"
19 #include "llvm/Module.h"
20 #include "llvm/ADT/OwningPtr.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/Bitcode/ReaderWriter.h"
23 #include "llvm/Support/SystemUtils.h"
24 #include "llvm/Support/MemoryBuffer.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/Host.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/Process.h"
29 #include "llvm/Support/SourceMgr.h"
30 #include "llvm/Support/system_error.h"
31 #include "llvm/Target/Mangler.h"
32 #include "llvm/Target/SubtargetFeature.h"
33 #include "llvm/MC/MCAsmInfo.h"
34 #include "llvm/MC/MCContext.h"
35 #include "llvm/MC/MCExpr.h"
36 #include "llvm/MC/MCInst.h"
37 #include "llvm/MC/MCParser/MCAsmParser.h"
38 #include "llvm/MC/MCStreamer.h"
39 #include "llvm/MC/MCSymbol.h"
40 #include "llvm/Target/TargetAsmParser.h"
41 #include "llvm/Target/TargetMachine.h"
42 #include "llvm/Target/TargetRegistry.h"
43 #include "llvm/Target/TargetSelect.h"
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 bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length,
57 const char *triplePrefix) {
58 MemoryBuffer *buffer = makeBuffer(mem, length);
61 return isTargetMatch(buffer, triplePrefix);
65 bool LTOModule::isBitcodeFileForTarget(const char *path,
66 const char *triplePrefix) {
67 OwningPtr<MemoryBuffer> buffer;
68 if (MemoryBuffer::getFile(path, buffer))
70 return isTargetMatch(buffer.take(), triplePrefix);
73 // Takes ownership of buffer.
74 bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
75 std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
77 return (strncmp(Triple.c_str(), triplePrefix,
78 strlen(triplePrefix)) == 0);
82 LTOModule::LTOModule(Module *m, TargetMachine *t)
83 : _module(m), _target(t)
87 LTOModule *LTOModule::makeLTOModule(const char *path,
88 std::string &errMsg) {
89 OwningPtr<MemoryBuffer> buffer;
90 if (error_code ec = MemoryBuffer::getFile(path, buffer)) {
91 errMsg = ec.message();
94 return makeLTOModule(buffer.get(), errMsg);
97 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
99 std::string &errMsg) {
100 OwningPtr<MemoryBuffer> buffer;
101 if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, size)) {
102 errMsg = ec.message();
105 return makeLTOModule(buffer.get(), errMsg);
108 /// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
109 /// requires the byte past end of the buffer to be a zero. We might get lucky
110 /// and already be that way, otherwise make a copy. Also if next byte is on a
111 /// different page, don't assume it is readable.
112 MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
113 const char *startPtr = (char*)mem;
114 const char *endPtr = startPtr+length;
115 if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
117 return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
119 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
123 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
124 std::string &errMsg) {
125 OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
128 return makeLTOModule(buffer.get(), errMsg);
131 LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
132 std::string &errMsg) {
133 static bool Initialized = false;
135 InitializeAllTargets();
136 InitializeAllAsmParsers();
140 // parse bitcode buffer
141 OwningPtr<Module> m(ParseBitcodeFile(buffer, getGlobalContext(), &errMsg));
145 std::string Triple = m->getTargetTriple();
147 Triple = sys::getHostTriple();
149 // find machine architecture for this module
150 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
154 // construct LTModule, hand over ownership of module and target
155 SubtargetFeatures Features;
156 Features.getDefaultSubtargetFeatures("" /* cpu */, llvm::Triple(Triple));
157 std::string FeatureStr = Features.getString();
158 TargetMachine *target = march->createTargetMachine(Triple, FeatureStr);
159 LTOModule *Ret = new LTOModule(m.take(), target);
160 bool Err = Ret->ParseSymbols();
169 const char *LTOModule::getTargetTriple() {
170 return _module->getTargetTriple().c_str();
173 void LTOModule::setTargetTriple(const char *triple) {
174 _module->setTargetTriple(triple);
177 void LTOModule::addDefinedFunctionSymbol(Function *f, Mangler &mangler) {
178 // add to list of defined symbols
179 addDefinedSymbol(f, mangler, true);
181 // add external symbols referenced by this function.
182 for (Function::iterator b = f->begin(); b != f->end(); ++b) {
183 for (BasicBlock::iterator i = b->begin(); i != b->end(); ++i) {
184 for (unsigned count = 0, total = i->getNumOperands();
185 count != total; ++count) {
186 findExternalRefs(i->getOperand(count), mangler);
192 // Get string that data pointer points to.
193 bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
194 if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
195 Constant *op = ce->getOperand(0);
196 if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
197 Constant *cn = gvn->getInitializer();
198 if (ConstantArray *ca = dyn_cast<ConstantArray>(cn)) {
199 if (ca->isCString()) {
200 name = ".objc_class_name_" + ca->getAsString();
209 // Parse i386/ppc ObjC class data structure.
210 void LTOModule::addObjCClass(GlobalVariable *clgv) {
211 if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
212 // second slot in __OBJC,__class is pointer to superclass name
213 std::string superclassName;
214 if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
215 NameAndAttributes info;
216 StringMap<NameAndAttributes>::value_type &entry =
217 _undefines.GetOrCreateValue(superclassName.c_str());
218 if (!entry.getValue().name) {
219 const char *symbolName = entry.getKey().data();
220 info.name = symbolName;
221 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
222 entry.setValue(info);
225 // third slot in __OBJC,__class is pointer to class name
226 std::string className;
227 if (objcClassNameFromExpression(c->getOperand(2), className)) {
228 StringSet::value_type &entry =
229 _defines.GetOrCreateValue(className.c_str());
231 NameAndAttributes info;
232 info.name = entry.getKey().data();
233 info.attributes = (lto_symbol_attributes)
234 (LTO_SYMBOL_PERMISSIONS_DATA |
235 LTO_SYMBOL_DEFINITION_REGULAR |
236 LTO_SYMBOL_SCOPE_DEFAULT);
237 _symbols.push_back(info);
243 // Parse i386/ppc ObjC category data structure.
244 void LTOModule::addObjCCategory(GlobalVariable *clgv) {
245 if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
246 // second slot in __OBJC,__category is pointer to target class name
247 std::string targetclassName;
248 if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) {
249 NameAndAttributes info;
251 StringMap<NameAndAttributes>::value_type &entry =
252 _undefines.GetOrCreateValue(targetclassName.c_str());
254 if (entry.getValue().name)
257 const char *symbolName = entry.getKey().data();
258 info.name = symbolName;
259 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
260 entry.setValue(info);
266 // Parse i386/ppc ObjC class list data structure.
267 void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
268 std::string targetclassName;
269 if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) {
270 NameAndAttributes info;
272 StringMap<NameAndAttributes>::value_type &entry =
273 _undefines.GetOrCreateValue(targetclassName.c_str());
274 if (entry.getValue().name)
277 const char *symbolName = entry.getKey().data();
278 info.name = symbolName;
279 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
280 entry.setValue(info);
285 void LTOModule::addDefinedDataSymbol(GlobalValue *v, Mangler &mangler) {
286 // Add to list of defined symbols.
287 addDefinedSymbol(v, mangler, false);
289 // Special case i386/ppc ObjC data structures in magic sections:
290 // The issue is that the old ObjC object format did some strange
291 // contortions to avoid real linker symbols. For instance, the
292 // ObjC class data structure is allocated statically in the executable
293 // that defines that class. That data structures contains a pointer to
294 // its superclass. But instead of just initializing that part of the
295 // struct to the address of its superclass, and letting the static and
296 // dynamic linkers do the rest, the runtime works by having that field
297 // instead point to a C-string that is the name of the superclass.
298 // At runtime the objc initialization updates that pointer and sets
299 // it to point to the actual super class. As far as the linker
300 // knows it is just a pointer to a string. But then someone wanted the
301 // linker to issue errors at build time if the superclass was not found.
302 // So they figured out a way in mach-o object format to use an absolute
303 // symbols (.objc_class_name_Foo = 0) and a floating reference
304 // (.reference .objc_class_name_Bar) to cause the linker into erroring when
305 // a class was missing.
306 // The following synthesizes the implicit .objc_* symbols for the linker
307 // from the ObjC data structures generated by the front end.
308 if (v->hasSection() /* && isTargetDarwin */) {
309 // special case if this data blob is an ObjC class definition
310 if (v->getSection().compare(0, 15, "__OBJC,__class,") == 0) {
311 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
316 // special case if this data blob is an ObjC category definition
317 else if (v->getSection().compare(0, 18, "__OBJC,__category,") == 0) {
318 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
323 // special case if this data blob is the list of referenced classes
324 else if (v->getSection().compare(0, 18, "__OBJC,__cls_refs,") == 0) {
325 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
331 // add external symbols referenced by this data.
332 for (unsigned count = 0, total = v->getNumOperands();
333 count != total; ++count) {
334 findExternalRefs(v->getOperand(count), mangler);
339 void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
341 // ignore all llvm.* symbols
342 if (def->getName().startswith("llvm."))
345 // ignore available_externally
346 if (def->hasAvailableExternallyLinkage())
349 // string is owned by _defines
350 SmallString<64> Buffer;
351 mangler.getNameWithPrefix(Buffer, def, false);
353 // set alignment part log2() can have rounding errors
354 uint32_t align = def->getAlignment();
355 uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0;
357 // set permissions part
359 attr |= LTO_SYMBOL_PERMISSIONS_CODE;
361 GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
362 if (gv && gv->isConstant())
363 attr |= LTO_SYMBOL_PERMISSIONS_RODATA;
365 attr |= LTO_SYMBOL_PERMISSIONS_DATA;
368 // set definition part
369 if (def->hasWeakLinkage() || def->hasLinkOnceLinkage() ||
370 def->hasLinkerPrivateWeakLinkage() ||
371 def->hasLinkerPrivateWeakDefAutoLinkage())
372 attr |= LTO_SYMBOL_DEFINITION_WEAK;
373 else if (def->hasCommonLinkage())
374 attr |= LTO_SYMBOL_DEFINITION_TENTATIVE;
376 attr |= LTO_SYMBOL_DEFINITION_REGULAR;
379 if (def->hasHiddenVisibility())
380 attr |= LTO_SYMBOL_SCOPE_HIDDEN;
381 else if (def->hasProtectedVisibility())
382 attr |= LTO_SYMBOL_SCOPE_PROTECTED;
383 else if (def->hasExternalLinkage() || def->hasWeakLinkage() ||
384 def->hasLinkOnceLinkage() || def->hasCommonLinkage() ||
385 def->hasLinkerPrivateWeakLinkage())
386 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
387 else if (def->hasLinkerPrivateWeakDefAutoLinkage())
388 attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN;
390 attr |= LTO_SYMBOL_SCOPE_INTERNAL;
392 // add to table of symbols
393 NameAndAttributes info;
394 StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer.c_str());
397 StringRef Name = entry.getKey();
398 info.name = Name.data();
399 assert(info.name[Name.size()] == '\0');
400 info.attributes = (lto_symbol_attributes)attr;
401 _symbols.push_back(info);
404 void LTOModule::addAsmGlobalSymbol(const char *name,
405 lto_symbol_attributes scope) {
406 StringSet::value_type &entry = _defines.GetOrCreateValue(name);
408 // only add new define if not already defined
409 if (entry.getValue())
413 const char *symbolName = entry.getKey().data();
414 uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR;
416 NameAndAttributes info;
417 info.name = symbolName;
418 info.attributes = (lto_symbol_attributes)attr;
419 _symbols.push_back(info);
422 void LTOModule::addAsmGlobalSymbolUndef(const char *name) {
423 StringMap<NameAndAttributes>::value_type &entry =
424 _undefines.GetOrCreateValue(name);
426 _asm_undefines.push_back(entry.getKey().data());
428 // we already have the symbol
429 if (entry.getValue().name)
432 uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED;;
433 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
434 NameAndAttributes info;
435 info.name = entry.getKey().data();
436 info.attributes = (lto_symbol_attributes)attr;
438 entry.setValue(info);
441 void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
443 // ignore all llvm.* symbols
444 if (decl->getName().startswith("llvm."))
447 // ignore all aliases
448 if (isa<GlobalAlias>(decl))
451 SmallString<64> name;
452 mangler.getNameWithPrefix(name, decl, false);
454 StringMap<NameAndAttributes>::value_type &entry =
455 _undefines.GetOrCreateValue(name.c_str());
457 // we already have the symbol
458 if (entry.getValue().name)
461 NameAndAttributes info;
463 info.name = entry.getKey().data();
464 if (decl->hasExternalWeakLinkage())
465 info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
467 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
469 entry.setValue(info);
474 // Find external symbols referenced by VALUE. This is a recursive function.
475 void LTOModule::findExternalRefs(Value *value, Mangler &mangler) {
476 if (GlobalValue *gv = dyn_cast<GlobalValue>(value)) {
477 if (!gv->hasExternalLinkage())
478 addPotentialUndefinedSymbol(gv, mangler);
479 // If this is a variable definition, do not recursively process
480 // initializer. It might contain a reference to this variable
481 // and cause an infinite loop. The initializer will be
482 // processed in addDefinedDataSymbol().
486 // GlobalValue, even with InternalLinkage type, may have operands with
487 // ExternalLinkage type. Do not ignore these operands.
488 if (Constant *c = dyn_cast<Constant>(value)) {
489 // Handle ConstantExpr, ConstantStruct, ConstantArry etc.
490 for (unsigned i = 0, e = c->getNumOperands(); i != e; ++i)
491 findExternalRefs(c->getOperand(i), mangler);
496 class RecordStreamer : public MCStreamer {
498 enum State { NeverSeen, Global, Defined, DefinedGlobal, Used};
501 StringMap<State> Symbols;
503 void markDefined(const MCSymbol &Symbol) {
504 State &S = Symbols[Symbol.getName()];
517 void markGlobal(const MCSymbol &Symbol) {
518 State &S = Symbols[Symbol.getName()];
532 void markUsed(const MCSymbol &Symbol) {
533 State &S = Symbols[Symbol.getName()];
547 // FIXME: mostly copied for the obj streamer.
548 void AddValueSymbols(const MCExpr *Value) {
549 switch (Value->getKind()) {
551 // FIXME: What should we do in here?
554 case MCExpr::Constant:
557 case MCExpr::Binary: {
558 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
559 AddValueSymbols(BE->getLHS());
560 AddValueSymbols(BE->getRHS());
564 case MCExpr::SymbolRef:
565 markUsed(cast<MCSymbolRefExpr>(Value)->getSymbol());
569 AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr());
575 typedef StringMap<State>::const_iterator const_iterator;
577 const_iterator begin() {
578 return Symbols.begin();
581 const_iterator end() {
582 return Symbols.end();
585 RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
587 virtual void ChangeSection(const MCSection *Section) {}
588 virtual void InitSections() {}
589 virtual void EmitLabel(MCSymbol *Symbol) {
590 Symbol->setSection(*getCurrentSection());
591 markDefined(*Symbol);
593 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {}
594 virtual void EmitThumbFunc(MCSymbol *Func) {}
595 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
596 // FIXME: should we handle aliases?
597 markDefined(*Symbol);
599 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
600 if (Attribute == MCSA_Global)
603 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
604 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
605 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {}
606 virtual void EmitCOFFSymbolStorageClass(int StorageClass) {}
607 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
608 unsigned Size , unsigned ByteAlignment) {
609 markDefined(*Symbol);
611 virtual void EmitCOFFSymbolType(int Type) {}
612 virtual void EndCOFFSymbolDef() {}
613 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
614 unsigned ByteAlignment) {
615 markDefined(*Symbol);
617 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
618 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {}
619 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
620 uint64_t Size, unsigned ByteAlignment) {}
621 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
622 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
623 bool isPCRel, unsigned AddrSpace) {}
624 virtual void EmitULEB128Value(const MCExpr *Value,
625 unsigned AddrSpace = 0) {}
626 virtual void EmitSLEB128Value(const MCExpr *Value,
627 unsigned AddrSpace = 0) {}
628 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
630 unsigned MaxBytesToEmit) {}
631 virtual void EmitCodeAlignment(unsigned ByteAlignment,
632 unsigned MaxBytesToEmit) {}
633 virtual void EmitValueToOffset(const MCExpr *Offset,
634 unsigned char Value ) {}
635 virtual void EmitFileDirective(StringRef Filename) {}
636 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
637 const MCSymbol *LastLabel,
638 const MCSymbol *Label) {}
640 virtual void EmitInstruction(const MCInst &Inst) {
642 for (unsigned i = Inst.getNumOperands(); i--; )
643 if (Inst.getOperand(i).isExpr())
644 AddValueSymbols(Inst.getOperand(i).getExpr());
646 virtual void Finish() {}
650 bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
651 const std::string &inlineAsm = _module->getModuleInlineAsm();
653 OwningPtr<RecordStreamer> Streamer(new RecordStreamer(Context));
654 MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(inlineAsm);
656 SrcMgr.AddNewSourceBuffer(Buffer, SMLoc());
657 OwningPtr<MCAsmParser> Parser(createMCAsmParser(_target->getTarget(), SrcMgr,
659 *_target->getMCAsmInfo()));
660 OwningPtr<TargetAsmParser>
661 TAP(_target->getTarget().createAsmParser(*Parser.get(), *_target.get()));
662 Parser->setTargetParser(*TAP);
663 int Res = Parser->Run(false);
667 for (RecordStreamer::const_iterator i = Streamer->begin(),
668 e = Streamer->end(); i != e; ++i) {
669 StringRef Key = i->first();
670 RecordStreamer::State Value = i->second;
671 if (Value == RecordStreamer::DefinedGlobal)
672 addAsmGlobalSymbol(Key.data(), LTO_SYMBOL_SCOPE_DEFAULT);
673 else if (Value == RecordStreamer::Defined)
674 addAsmGlobalSymbol(Key.data(), LTO_SYMBOL_SCOPE_INTERNAL);
675 else if (Value == RecordStreamer::Global ||
676 Value == RecordStreamer::Used)
677 addAsmGlobalSymbolUndef(Key.data());
682 bool LTOModule::ParseSymbols() {
683 // Use mangler to add GlobalPrefix to names to match linker names.
684 MCContext Context(*_target->getMCAsmInfo(), NULL);
685 Mangler mangler(Context, *_target->getTargetData());
688 for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {
689 if (f->isDeclaration())
690 addPotentialUndefinedSymbol(f, mangler);
692 addDefinedFunctionSymbol(f, mangler);
696 for (Module::global_iterator v = _module->global_begin(),
697 e = _module->global_end(); v != e; ++v) {
698 if (v->isDeclaration())
699 addPotentialUndefinedSymbol(v, mangler);
701 addDefinedDataSymbol(v, mangler);
705 if (addAsmGlobalSymbols(Context))
709 for (Module::alias_iterator i = _module->alias_begin(),
710 e = _module->alias_end(); i != e; ++i) {
711 if (i->isDeclaration())
712 addPotentialUndefinedSymbol(i, mangler);
714 addDefinedDataSymbol(i, mangler);
717 // make symbols for all undefines
718 for (StringMap<NameAndAttributes>::iterator it=_undefines.begin();
719 it != _undefines.end(); ++it) {
720 // if this symbol also has a definition, then don't make an undefine
721 // because it is a tentative definition
722 if (_defines.count(it->getKey()) == 0) {
723 NameAndAttributes info = it->getValue();
724 _symbols.push_back(info);
731 uint32_t LTOModule::getSymbolCount() {
732 return _symbols.size();
736 lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) {
737 if (index < _symbols.size())
738 return _symbols[index].attributes;
740 return lto_symbol_attributes(0);
743 const char *LTOModule::getSymbolName(uint32_t index) {
744 if (index < _symbols.size())
745 return _symbols[index].name;