llvm.org GIT mirror llvm / e7b068f
Add range access to MCAssembler's symbol collection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206631 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
5 changed file(s) with 39 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
832832
833833 typedef SymbolDataListType::const_iterator const_symbol_iterator;
834834 typedef SymbolDataListType::iterator symbol_iterator;
835
836 typedef iterator_range symbol_range;
837 typedef iterator_range const_symbol_range;
835838
836839 typedef std::vector FileNameVectorType;
837840 typedef FileNameVectorType::const_iterator const_file_name_iterator;
10981101 symbol_iterator symbol_end() { return Symbols.end(); }
10991102 const_symbol_iterator symbol_end() const { return Symbols.end(); }
11001103
1104 symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
1105 const_symbol_range symbols() const { return make_range(symbol_begin(), symbol_end()); }
1106
11011107 size_t symbol_size() const { return Symbols.size(); }
11021108
11031109 /// @}
529529 // The presence of symbol versions causes undefined symbols and
530530 // versions declared with @@@ to be renamed.
531531
532 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
533 ie = Asm.symbol_end(); it != ie; ++it) {
534 const MCSymbol &Alias = it->getSymbol();
532 for (MCSymbolData &OriginalData : Asm.symbols()) {
533 const MCSymbol &Alias = OriginalData.getSymbol();
535534 const MCSymbol &Symbol = Alias.AliasedSymbol();
536535 MCSymbolData &SD = Asm.getSymbolData(Symbol);
537536
546545
547546 // Aliases defined with .symvar copy the binding from the symbol they alias.
548547 // This is the first place we are able to copy this information.
549 it->setExternal(SD.isExternal());
550 MCELF::SetBinding(*it, MCELF::GetBinding(SD));
548 OriginalData.setExternal(SD.isExternal());
549 MCELF::SetBinding(OriginalData, MCELF::GetBinding(SD));
551550
552551 StringRef Rest = AliasName.substr(Pos);
553552 if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
10451044 }
10461045
10471046 // Add the data for the symbols.
1048 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
1049 ie = Asm.symbol_end(); it != ie; ++it) {
1050 const MCSymbol &Symbol = it->getSymbol();
1047 for (MCSymbolData &SD : Asm.symbols()) {
1048 const MCSymbol &Symbol = SD.getSymbol();
10511049
10521050 bool Used = UsedInReloc.count(&Symbol);
10531051 bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
10541052 bool isSignature = RevGroupMap.count(&Symbol);
10551053
1056 if (!isInSymtab(Asm, *it,
1054 if (!isInSymtab(Asm, SD,
10571055 Used || WeakrefUsed || isSignature,
10581056 Renames.count(&Symbol)))
10591057 continue;
10601058
10611059 ELFSymbolData MSD;
1062 MSD.SymbolData = it;
1060 MSD.SymbolData = &SD;
10631061 const MCSymbol *BaseSymbol = getBaseSymbol(Layout, Symbol);
10641062
10651063 // Undefined symbols are global, but this is the first place we
10661064 // are able to set it.
1067 bool Local = isLocal(*it, isSignature, Used);
1068 if (!Local && MCELF::GetBinding(*it) == ELF::STB_LOCAL) {
1065 bool Local = isLocal(SD, isSignature, Used);
1066 if (!Local && MCELF::GetBinding(SD) == ELF::STB_LOCAL) {
10691067 assert(BaseSymbol);
1070 MCSymbolData &SD = Asm.getSymbolData(*BaseSymbol);
1071 MCELF::SetBinding(*it, ELF::STB_GLOBAL);
1068 MCSymbolData &BaseData = Asm.getSymbolData(*BaseSymbol);
10721069 MCELF::SetBinding(SD, ELF::STB_GLOBAL);
1070 MCELF::SetBinding(BaseData, ELF::STB_GLOBAL);
10731071 }
10741072
10751073 if (!BaseSymbol) {
10761074 MSD.SectionIndex = ELF::SHN_ABS;
1077 } else if (it->isCommon()) {
1075 } else if (SD.isCommon()) {
10781076 assert(!Local);
10791077 MSD.SectionIndex = ELF::SHN_COMMON;
10801078 } else if (BaseSymbol->isUndefined()) {
10831081 else
10841082 MSD.SectionIndex = ELF::SHN_UNDEF;
10851083 if (!Used && WeakrefUsed)
1086 MCELF::SetBinding(*it, ELF::STB_WEAK);
1084 MCELF::SetBinding(SD, ELF::STB_WEAK);
10871085 } else {
10881086 const MCSectionELF &Section =
10891087 static_cast(BaseSymbol->getSection());
429429 // First, scan the symbol table to build a lookup table from fragments to
430430 // defining symbols.
431431 DenseMap DefiningSymbolMap;
432 for (MCAssembler::symbol_iterator it = getAssembler().symbol_begin(),
433 ie = getAssembler().symbol_end(); it != ie; ++it) {
434 if (getAssembler().isSymbolLinkerVisible(it->getSymbol()) &&
435 it->getFragment()) {
432 for (MCSymbolData &SD : getAssembler().symbols()) {
433 if (getAssembler().isSymbolLinkerVisible(SD.getSymbol()) &&
434 SD.getFragment()) {
436435 // An atom defining symbol should never be internal to a fragment.
437 assert(it->getOffset() == 0 && "Invalid offset in atom defining symbol!");
438 DefiningSymbolMap[it->getFragment()] = it;
436 assert(SD.getOffset() == 0 && "Invalid offset in atom defining symbol!");
437 DefiningSymbolMap[SD.getFragment()] = &SD;
439438 }
440439 }
441440
515515 // table, then sort the symbols is chosen to match 'as'. Even though it
516516 // doesn't matter for correctness, this is important for letting us diff .o
517517 // files.
518 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
519 ie = Asm.symbol_end(); it != ie; ++it) {
520 const MCSymbol &Symbol = it->getSymbol();
518 for (MCSymbolData &SD : Asm.symbols()) {
519 const MCSymbol &Symbol = SD.getSymbol();
521520
522521 // Ignore non-linker visible symbols.
523 if (!Asm.isSymbolLinkerVisible(it->getSymbol()))
522 if (!Asm.isSymbolLinkerVisible(SD.getSymbol()))
524523 continue;
525524
526 if (!it->isExternal() && !Symbol.isUndefined())
525 if (!SD.isExternal() && !Symbol.isUndefined())
527526 continue;
528527
529528 uint64_t &Entry = StringIndexMap[Symbol.getName()];
534533 }
535534
536535 MachSymbolData MSD;
537 MSD.SymbolData = it;
536 MSD.SymbolData = &SD;
538537 MSD.StringIndex = Entry;
539538
540539 if (Symbol.isUndefined()) {
551550 }
552551
553552 // Now add the data for local symbols.
554 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
555 ie = Asm.symbol_end(); it != ie; ++it) {
556 const MCSymbol &Symbol = it->getSymbol();
553 for (MCSymbolData &SD : Asm.symbols()) {
554 const MCSymbol &Symbol = SD.getSymbol();
557555
558556 // Ignore non-linker visible symbols.
559 if (!Asm.isSymbolLinkerVisible(it->getSymbol()))
557 if (!Asm.isSymbolLinkerVisible(SD.getSymbol()))
560558 continue;
561559
562 if (it->isExternal() || Symbol.isUndefined())
560 if (SD.isExternal() || Symbol.isUndefined())
563561 continue;
564562
565563 uint64_t &Entry = StringIndexMap[Symbol.getName()];
570568 }
571569
572570 MachSymbolData MSD;
573 MSD.SymbolData = it;
571 MSD.SymbolData = &SD;
574572 MSD.StringIndex = Entry;
575573
576574 if (Symbol.isAbsolute()) {
620618
621619 void MachObjectWriter::markAbsoluteVariableSymbols(MCAssembler &Asm,
622620 const MCAsmLayout &Layout) {
623 for (MCAssembler::symbol_iterator i = Asm.symbol_begin(),
624 e = Asm.symbol_end();
625 i != e; ++i) {
626 MCSymbolData &SD = *i;
621 for (MCSymbolData &SD : Asm.symbols()) {
627622 if (!SD.getSymbol().isVariable())
628623 continue;
629624
664664 for (MCAssembler::const_iterator i = Asm.begin(), e = Asm.end(); i != e; i++)
665665 DefineSection(*i);
666666
667 for (MCAssembler::const_symbol_iterator i = Asm.symbol_begin(),
668 e = Asm.symbol_end();
669 i != e; i++) {
670 if (ExportSymbol(*i, Asm)) {
671 DefineSymbol(*i, Asm, Layout);
672 }
673 }
667 for (MCSymbolData &SD : Asm.symbols())
668 if (ExportSymbol(SD, Asm))
669 DefineSymbol(SD, Asm, Layout);
674670 }
675671
676672 void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,