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 return makeLTOModule(fd, path, size, size, 0, errMsg);
103 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
107 std::string &errMsg) {
108 OwningPtr<MemoryBuffer> buffer;
109 if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, file_size,
110 map_size, offset, false)) {
111 errMsg = ec.message();
114 return makeLTOModule(buffer.get(), errMsg);
117 /// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
118 /// requires the byte past end of the buffer to be a zero. We might get lucky
119 /// and already be that way, otherwise make a copy. Also if next byte is on a
120 /// different page, don't assume it is readable.
121 MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
122 const char *startPtr = (char*)mem;
123 const char *endPtr = startPtr+length;
124 if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
126 return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
128 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
132 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
133 std::string &errMsg) {
134 OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
137 return makeLTOModule(buffer.get(), errMsg);
140 LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
141 std::string &errMsg) {
142 static bool Initialized = false;
144 InitializeAllTargets();
145 InitializeAllAsmParsers();
149 // parse bitcode buffer
150 OwningPtr<Module> m(ParseBitcodeFile(buffer, getGlobalContext(), &errMsg));
154 std::string Triple = m->getTargetTriple();
156 Triple = sys::getHostTriple();
158 // find machine architecture for this module
159 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
163 // construct LTModule, hand over ownership of module and target
164 SubtargetFeatures Features;
165 Features.getDefaultSubtargetFeatures("" /* cpu */, llvm::Triple(Triple));
166 std::string FeatureStr = Features.getString();
167 TargetMachine *target = march->createTargetMachine(Triple, FeatureStr);
168 LTOModule *Ret = new LTOModule(m.take(), target);
169 bool Err = Ret->ParseSymbols();
178 const char *LTOModule::getTargetTriple() {
179 return _module->getTargetTriple().c_str();
182 void LTOModule::setTargetTriple(const char *triple) {
183 _module->setTargetTriple(triple);
186 void LTOModule::addDefinedFunctionSymbol(Function *f, Mangler &mangler) {
187 // add to list of defined symbols
188 addDefinedSymbol(f, mangler, true);
190 // add external symbols referenced by this function.
191 for (Function::iterator b = f->begin(); b != f->end(); ++b) {
192 for (BasicBlock::iterator i = b->begin(); i != b->end(); ++i) {
193 for (unsigned count = 0, total = i->getNumOperands();
194 count != total; ++count) {
195 findExternalRefs(i->getOperand(count), mangler);
201 // Get string that data pointer points to.
202 bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
203 if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
204 Constant *op = ce->getOperand(0);
205 if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
206 Constant *cn = gvn->getInitializer();
207 if (ConstantArray *ca = dyn_cast<ConstantArray>(cn)) {
208 if (ca->isCString()) {
209 name = ".objc_class_name_" + ca->getAsString();
218 // Parse i386/ppc ObjC class data structure.
219 void LTOModule::addObjCClass(GlobalVariable *clgv) {
220 if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
221 // second slot in __OBJC,__class is pointer to superclass name
222 std::string superclassName;
223 if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
224 NameAndAttributes info;
225 StringMap<NameAndAttributes>::value_type &entry =
226 _undefines.GetOrCreateValue(superclassName.c_str());
227 if (!entry.getValue().name) {
228 const char *symbolName = entry.getKey().data();
229 info.name = symbolName;
230 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
231 entry.setValue(info);
234 // third slot in __OBJC,__class is pointer to class name
235 std::string className;
236 if (objcClassNameFromExpression(c->getOperand(2), className)) {
237 StringSet::value_type &entry =
238 _defines.GetOrCreateValue(className.c_str());
240 NameAndAttributes info;
241 info.name = entry.getKey().data();
242 info.attributes = (lto_symbol_attributes)
243 (LTO_SYMBOL_PERMISSIONS_DATA |
244 LTO_SYMBOL_DEFINITION_REGULAR |
245 LTO_SYMBOL_SCOPE_DEFAULT);
246 _symbols.push_back(info);
252 // Parse i386/ppc ObjC category data structure.
253 void LTOModule::addObjCCategory(GlobalVariable *clgv) {
254 if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) {
255 // second slot in __OBJC,__category is pointer to target class name
256 std::string targetclassName;
257 if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) {
258 NameAndAttributes info;
260 StringMap<NameAndAttributes>::value_type &entry =
261 _undefines.GetOrCreateValue(targetclassName.c_str());
263 if (entry.getValue().name)
266 const char *symbolName = entry.getKey().data();
267 info.name = symbolName;
268 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
269 entry.setValue(info);
275 // Parse i386/ppc ObjC class list data structure.
276 void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
277 std::string targetclassName;
278 if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) {
279 NameAndAttributes info;
281 StringMap<NameAndAttributes>::value_type &entry =
282 _undefines.GetOrCreateValue(targetclassName.c_str());
283 if (entry.getValue().name)
286 const char *symbolName = entry.getKey().data();
287 info.name = symbolName;
288 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
289 entry.setValue(info);
294 void LTOModule::addDefinedDataSymbol(GlobalValue *v, Mangler &mangler) {
295 // Add to list of defined symbols.
296 addDefinedSymbol(v, mangler, false);
298 // Special case i386/ppc ObjC data structures in magic sections:
299 // The issue is that the old ObjC object format did some strange
300 // contortions to avoid real linker symbols. For instance, the
301 // ObjC class data structure is allocated statically in the executable
302 // that defines that class. That data structures contains a pointer to
303 // its superclass. But instead of just initializing that part of the
304 // struct to the address of its superclass, and letting the static and
305 // dynamic linkers do the rest, the runtime works by having that field
306 // instead point to a C-string that is the name of the superclass.
307 // At runtime the objc initialization updates that pointer and sets
308 // it to point to the actual super class. As far as the linker
309 // knows it is just a pointer to a string. But then someone wanted the
310 // linker to issue errors at build time if the superclass was not found.
311 // So they figured out a way in mach-o object format to use an absolute
312 // symbols (.objc_class_name_Foo = 0) and a floating reference
313 // (.reference .objc_class_name_Bar) to cause the linker into erroring when
314 // a class was missing.
315 // The following synthesizes the implicit .objc_* symbols for the linker
316 // from the ObjC data structures generated by the front end.
317 if (v->hasSection() /* && isTargetDarwin */) {
318 // special case if this data blob is an ObjC class definition
319 if (v->getSection().compare(0, 15, "__OBJC,__class,") == 0) {
320 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
325 // special case if this data blob is an ObjC category definition
326 else if (v->getSection().compare(0, 18, "__OBJC,__category,") == 0) {
327 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
332 // special case if this data blob is the list of referenced classes
333 else if (v->getSection().compare(0, 18, "__OBJC,__cls_refs,") == 0) {
334 if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
340 // add external symbols referenced by this data.
341 for (unsigned count = 0, total = v->getNumOperands();
342 count != total; ++count) {
343 findExternalRefs(v->getOperand(count), mangler);
348 void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
350 // ignore all llvm.* symbols
351 if (def->getName().startswith("llvm."))
354 // ignore available_externally
355 if (def->hasAvailableExternallyLinkage())
358 // string is owned by _defines
359 SmallString<64> Buffer;
360 mangler.getNameWithPrefix(Buffer, def, false);
362 // set alignment part log2() can have rounding errors
363 uint32_t align = def->getAlignment();
364 uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0;
366 // set permissions part
368 attr |= LTO_SYMBOL_PERMISSIONS_CODE;
370 GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
371 if (gv && gv->isConstant())
372 attr |= LTO_SYMBOL_PERMISSIONS_RODATA;
374 attr |= LTO_SYMBOL_PERMISSIONS_DATA;
377 // set definition part
378 if (def->hasWeakLinkage() || def->hasLinkOnceLinkage() ||
379 def->hasLinkerPrivateWeakLinkage() ||
380 def->hasLinkerPrivateWeakDefAutoLinkage())
381 attr |= LTO_SYMBOL_DEFINITION_WEAK;
382 else if (def->hasCommonLinkage())
383 attr |= LTO_SYMBOL_DEFINITION_TENTATIVE;
385 attr |= LTO_SYMBOL_DEFINITION_REGULAR;
388 if (def->hasHiddenVisibility())
389 attr |= LTO_SYMBOL_SCOPE_HIDDEN;
390 else if (def->hasProtectedVisibility())
391 attr |= LTO_SYMBOL_SCOPE_PROTECTED;
392 else if (def->hasExternalLinkage() || def->hasWeakLinkage() ||
393 def->hasLinkOnceLinkage() || def->hasCommonLinkage() ||
394 def->hasLinkerPrivateWeakLinkage())
395 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
396 else if (def->hasLinkerPrivateWeakDefAutoLinkage())
397 attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN;
399 attr |= LTO_SYMBOL_SCOPE_INTERNAL;
401 // add to table of symbols
402 NameAndAttributes info;
403 StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer.c_str());
406 StringRef Name = entry.getKey();
407 info.name = Name.data();
408 assert(info.name[Name.size()] == '\0');
409 info.attributes = (lto_symbol_attributes)attr;
410 _symbols.push_back(info);
413 void LTOModule::addAsmGlobalSymbol(const char *name,
414 lto_symbol_attributes scope) {
415 StringSet::value_type &entry = _defines.GetOrCreateValue(name);
417 // only add new define if not already defined
418 if (entry.getValue())
422 const char *symbolName = entry.getKey().data();
423 uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR;
425 NameAndAttributes info;
426 info.name = symbolName;
427 info.attributes = (lto_symbol_attributes)attr;
428 _symbols.push_back(info);
431 void LTOModule::addAsmGlobalSymbolUndef(const char *name) {
432 StringMap<NameAndAttributes>::value_type &entry =
433 _undefines.GetOrCreateValue(name);
435 _asm_undefines.push_back(entry.getKey().data());
437 // we already have the symbol
438 if (entry.getValue().name)
441 uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED;;
442 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
443 NameAndAttributes info;
444 info.name = entry.getKey().data();
445 info.attributes = (lto_symbol_attributes)attr;
447 entry.setValue(info);
450 void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
452 // ignore all llvm.* symbols
453 if (decl->getName().startswith("llvm."))
456 // ignore all aliases
457 if (isa<GlobalAlias>(decl))
460 SmallString<64> name;
461 mangler.getNameWithPrefix(name, decl, false);
463 StringMap<NameAndAttributes>::value_type &entry =
464 _undefines.GetOrCreateValue(name.c_str());
466 // we already have the symbol
467 if (entry.getValue().name)
470 NameAndAttributes info;
472 info.name = entry.getKey().data();
473 if (decl->hasExternalWeakLinkage())
474 info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
476 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
478 entry.setValue(info);
483 // Find external symbols referenced by VALUE. This is a recursive function.
484 void LTOModule::findExternalRefs(Value *value, Mangler &mangler) {
485 if (GlobalValue *gv = dyn_cast<GlobalValue>(value)) {
486 if (!gv->hasExternalLinkage())
487 addPotentialUndefinedSymbol(gv, mangler);
488 // If this is a variable definition, do not recursively process
489 // initializer. It might contain a reference to this variable
490 // and cause an infinite loop. The initializer will be
491 // processed in addDefinedDataSymbol().
495 // GlobalValue, even with InternalLinkage type, may have operands with
496 // ExternalLinkage type. Do not ignore these operands.
497 if (Constant *c = dyn_cast<Constant>(value)) {
498 // Handle ConstantExpr, ConstantStruct, ConstantArry etc.
499 for (unsigned i = 0, e = c->getNumOperands(); i != e; ++i)
500 findExternalRefs(c->getOperand(i), mangler);
505 class RecordStreamer : public MCStreamer {
507 enum State { NeverSeen, Global, Defined, DefinedGlobal, Used};
510 StringMap<State> Symbols;
512 void markDefined(const MCSymbol &Symbol) {
513 State &S = Symbols[Symbol.getName()];
526 void markGlobal(const MCSymbol &Symbol) {
527 State &S = Symbols[Symbol.getName()];
541 void markUsed(const MCSymbol &Symbol) {
542 State &S = Symbols[Symbol.getName()];
556 // FIXME: mostly copied for the obj streamer.
557 void AddValueSymbols(const MCExpr *Value) {
558 switch (Value->getKind()) {
560 // FIXME: What should we do in here?
563 case MCExpr::Constant:
566 case MCExpr::Binary: {
567 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
568 AddValueSymbols(BE->getLHS());
569 AddValueSymbols(BE->getRHS());
573 case MCExpr::SymbolRef:
574 markUsed(cast<MCSymbolRefExpr>(Value)->getSymbol());
578 AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr());
584 typedef StringMap<State>::const_iterator const_iterator;
586 const_iterator begin() {
587 return Symbols.begin();
590 const_iterator end() {
591 return Symbols.end();
594 RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
596 virtual void ChangeSection(const MCSection *Section) {}
597 virtual void InitSections() {}
598 virtual void EmitLabel(MCSymbol *Symbol) {
599 Symbol->setSection(*getCurrentSection());
600 markDefined(*Symbol);
602 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {}
603 virtual void EmitThumbFunc(MCSymbol *Func) {}
604 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
605 // FIXME: should we handle aliases?
606 markDefined(*Symbol);
608 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
609 if (Attribute == MCSA_Global)
612 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
613 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
614 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {}
615 virtual void EmitCOFFSymbolStorageClass(int StorageClass) {}
616 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
617 unsigned Size , unsigned ByteAlignment) {
618 markDefined(*Symbol);
620 virtual void EmitCOFFSymbolType(int Type) {}
621 virtual void EndCOFFSymbolDef() {}
622 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
623 unsigned ByteAlignment) {
624 markDefined(*Symbol);
626 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
627 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {}
628 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
629 uint64_t Size, unsigned ByteAlignment) {}
630 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
631 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
632 bool isPCRel, unsigned AddrSpace) {}
633 virtual void EmitULEB128Value(const MCExpr *Value,
634 unsigned AddrSpace = 0) {}
635 virtual void EmitSLEB128Value(const MCExpr *Value,
636 unsigned AddrSpace = 0) {}
637 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
639 unsigned MaxBytesToEmit) {}
640 virtual void EmitCodeAlignment(unsigned ByteAlignment,
641 unsigned MaxBytesToEmit) {}
642 virtual void EmitValueToOffset(const MCExpr *Offset,
643 unsigned char Value ) {}
644 virtual void EmitFileDirective(StringRef Filename) {}
645 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
646 const MCSymbol *LastLabel,
647 const MCSymbol *Label) {}
649 virtual void EmitInstruction(const MCInst &Inst) {
651 for (unsigned i = Inst.getNumOperands(); i--; )
652 if (Inst.getOperand(i).isExpr())
653 AddValueSymbols(Inst.getOperand(i).getExpr());
655 virtual void Finish() {}
659 bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
660 const std::string &inlineAsm = _module->getModuleInlineAsm();
662 OwningPtr<RecordStreamer> Streamer(new RecordStreamer(Context));
663 MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(inlineAsm);
665 SrcMgr.AddNewSourceBuffer(Buffer, SMLoc());
666 OwningPtr<MCAsmParser> Parser(createMCAsmParser(_target->getTarget(), SrcMgr,
668 *_target->getMCAsmInfo()));
669 OwningPtr<TargetAsmParser>
670 TAP(_target->getTarget().createAsmParser(*Parser.get(), *_target.get()));
671 Parser->setTargetParser(*TAP);
672 int Res = Parser->Run(false);
676 for (RecordStreamer::const_iterator i = Streamer->begin(),
677 e = Streamer->end(); i != e; ++i) {
678 StringRef Key = i->first();
679 RecordStreamer::State Value = i->second;
680 if (Value == RecordStreamer::DefinedGlobal)
681 addAsmGlobalSymbol(Key.data(), LTO_SYMBOL_SCOPE_DEFAULT);
682 else if (Value == RecordStreamer::Defined)
683 addAsmGlobalSymbol(Key.data(), LTO_SYMBOL_SCOPE_INTERNAL);
684 else if (Value == RecordStreamer::Global ||
685 Value == RecordStreamer::Used)
686 addAsmGlobalSymbolUndef(Key.data());
691 bool LTOModule::ParseSymbols() {
692 // Use mangler to add GlobalPrefix to names to match linker names.
693 MCContext Context(*_target->getMCAsmInfo(), NULL);
694 Mangler mangler(Context, *_target->getTargetData());
697 for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {
698 if (f->isDeclaration())
699 addPotentialUndefinedSymbol(f, mangler);
701 addDefinedFunctionSymbol(f, mangler);
705 for (Module::global_iterator v = _module->global_begin(),
706 e = _module->global_end(); v != e; ++v) {
707 if (v->isDeclaration())
708 addPotentialUndefinedSymbol(v, mangler);
710 addDefinedDataSymbol(v, mangler);
714 if (addAsmGlobalSymbols(Context))
718 for (Module::alias_iterator i = _module->alias_begin(),
719 e = _module->alias_end(); i != e; ++i) {
720 if (i->isDeclaration())
721 addPotentialUndefinedSymbol(i, mangler);
723 addDefinedDataSymbol(i, mangler);
726 // make symbols for all undefines
727 for (StringMap<NameAndAttributes>::iterator it=_undefines.begin();
728 it != _undefines.end(); ++it) {
729 // if this symbol also has a definition, then don't make an undefine
730 // because it is a tentative definition
731 if (_defines.count(it->getKey()) == 0) {
732 NameAndAttributes info = it->getValue();
733 _symbols.push_back(info);
740 uint32_t LTOModule::getSymbolCount() {
741 return _symbols.size();
745 lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) {
746 if (index < _symbols.size())
747 return _symbols[index].attributes;
749 return lto_symbol_attributes(0);
752 const char *LTOModule::getSymbolName(uint32_t index) {
753 if (index < _symbols.size())
754 return _symbols[index].name;