llvm.org GIT mirror llvm / e8f07a7
Remove Elf_Sym_Iter. It was a fairly broken concept for an ELF only class. An ELF file can have two symbol tables, but they have exactly the same format. There is no concept of a dynamic or a static symbol. Storing this on the iterator also makes us do more work per symbol than necessary. To fetch a name we would: * Find if we had a static or a dynamic symbol. * Look at the corresponding symbol table and find the string table section. * Look at the string table section to fetch its contents. * Compute the name as a substring of the string table. All but the last step can be done per symbol table instead of per symbol. This is a step in that direction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240939 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
6 changed file(s) with 139 addition(s) and 204 deletion(s). Raw diff Collapse all Expand all
157157 enum { NumLowBitsAvailable = 1 };
158158 };
159159
160 class Elf_Sym_Iter {
161 public:
162 typedef ptrdiff_t difference_type;
163 typedef const Elf_Sym value_type;
164 typedef std::random_access_iterator_tag iterator_category;
165 typedef value_type &reference;
166 typedef value_type *pointer;
167
168 /// \brief Default construct iterator.
169 Elf_Sym_Iter() : EntitySize(0), Current(0, false) {}
170 Elf_Sym_Iter(uintX_t EntSize, const char *Start, bool IsDynamic)
171 : EntitySize(EntSize), Current(Start, IsDynamic) {}
172
173 reference operator*() {
174 assert(Current.getPointer() &&
175 "Attempted to dereference an invalid iterator!");
176 return *reinterpret_cast(Current.getPointer());
177 }
178
179 pointer operator->() {
180 assert(Current.getPointer() &&
181 "Attempted to dereference an invalid iterator!");
182 return reinterpret_cast(Current.getPointer());
183 }
184
185 bool operator==(const Elf_Sym_Iter &Other) {
186 return Current == Other.Current;
187 }
188
189 bool operator!=(const Elf_Sym_Iter &Other) { return !(*this == Other); }
190
191 Elf_Sym_Iter &operator++() {
192 assert(Current.getPointer() &&
193 "Attempted to increment an invalid iterator!");
194 Current.setPointer(Current.getPointer() + EntitySize);
195 return *this;
196 }
197
198 Elf_Sym_Iter operator++(int) {
199 Elf_Sym_Iter Tmp = *this;
200 ++*this;
201 return Tmp;
202 }
203
204 Elf_Sym_Iter operator+(difference_type Dist) {
205 assert(Current.getPointer() &&
206 "Attempted to increment an invalid iterator!");
207 Current.setPointer(Current.getPointer() + EntitySize * Dist);
208 return *this;
209 }
210
211 difference_type operator-(const Elf_Sym_Iter &Other) const {
212 assert(EntitySize == Other.EntitySize &&
213 "Subtracting iterators of different EntitySize!");
214 return (Current.getPointer() - Other.Current.getPointer()) / EntitySize;
215 }
216
217 const char *get() const { return Current.getPointer(); }
218
219 bool isDynamic() const { return Current.getInt(); }
220
221 uintX_t getEntSize() const { return EntitySize; }
222
223 private:
224 uintX_t EntitySize;
225 PointerIntPair
226 ArchivePointerTypeTraits > Current;
227 };
228
229 typedef iterator_range<Elf_Sym_Iter> Elf_Sym_Range;
160 typedef iterator_range<const Elf_Sym *> Elf_Sym_Range;
230161
231162 private:
232163 typedef SmallVector Sections_t;
338269 return make_range(begin_sections(), end_sections());
339270 }
340271
341 Elf_Sym_Iter begin_symbols() const;
342 Elf_Sym_Iter end_symbols() const;
272 const Elf_Sym *begin_symbols() const;
273 const Elf_Sym *end_symbols() const;
343274 Elf_Sym_Range symbols() const {
344275 return make_range(begin_symbols(), end_symbols());
345276 }
352283 return make_range(begin_dynamic_table(), end_dynamic_table(NULLEnd));
353284 }
354285
355 Elf_Sym_Iter begin_dynamic_symbols() const {
286 const Elf_Sym *begin_dynamic_symbols() const {
356287 if (DynSymRegion.Addr)
357 return Elf_Sym_Iter(DynSymRegion.EntSize, (const char *)DynSymRegion.Addr,
358 true);
359 return Elf_Sym_Iter(0, nullptr, true);
360 }
361
362 Elf_Sym_Iter end_dynamic_symbols() const {
288 return reinterpret_cast(DynSymRegion.Addr);
289 return nullptr;
290 }
291
292 const Elf_Sym *end_dynamic_symbols() const {
363293 if (DynSymRegion.Addr)
364 return Elf_Sym_Iter(DynSymRegion.EntSize,
365 (const char *)DynSymRegion.Addr + DynSymRegion.Size,
366 true);
367 return Elf_Sym_Iter(0, nullptr, true);
294 return reinterpret_cast(
295 ((const char *)DynSymRegion.Addr + DynSymRegion.Size));
296
297 return nullptr;
298 }
299
300 Elf_Sym_Range dynamic_symbols() const {
301 return make_range(begin_dynamic_symbols(), end_dynamic_symbols());
368302 }
369303
370304 Elf_Rela_Iter begin_dyn_rela() const {
426360 const Elf_Shdr *getSection(uint32_t Index) const;
427361 const Elf_Sym *getSymbol(uint32_t index) const;
428362
429 ErrorOr getSymbolName(Elf_Sym_Iter Sym) const;
430363 ErrorOr getStaticSymbolName(const Elf_Sym *Symb) const;
364 ErrorOr getDynamicSymbolName(const Elf_Sym *Symb) const;
365 ErrorOr getSymbolName(const Elf_Sym *Symb, bool IsDynamic) const;
431366
432367 /// \brief Get the name of \p Symb.
433368 /// \param SymTab The symbol table section \p Symb is contained in.
435370 ///
436371 /// \p SymTab is used to lookup the string table to use to get the symbol's
437372 /// name.
438 ErrorOr getSymbolName(const Elf_Shdr *SymTab,
373 ErrorOr getSymbolName(const Elf_Shdr *StrTab,
439374 const Elf_Sym *Symb) const;
440375 ErrorOr getSectionName(const Elf_Shdr *Section) const;
441376 uint64_t getSymbolIndex(const Elf_Sym *sym) const;
762697 if (SymbolTableSectionHeaderIndex) {
763698 const Elf_Word *ShndxTable = reinterpret_cast(base() +
764699 SymbolTableSectionHeaderIndex->sh_offset);
765 for (Elf_Sym_Iter SI = begin_symbols(), SE = end_symbols(); SI != SE;
766 ++SI) {
700 for (const Elf_Sym &S : symbols()) {
767701 if (*ShndxTable != ELF::SHN_UNDEF)
768 ExtendedSymbolTable[&*SI] = *ShndxTable;
702 ExtendedSymbolTable[&S] = *ShndxTable;
769703 ++ShndxTable;
770704 }
771705 }
843777 }
844778
845779 template
846 typename ELFFile::Elf_Sym_Iter ELFFile::begin_symbols() const {
780 const typename ELFFile::Elf_Sym *ELFFile::begin_symbols() const {
847781 if (!dot_symtab_sec)
848 return Elf_Sym_Iter(0, nullptr, false);
849 return Elf_Sym_Iter(dot_symtab_sec->sh_entsize,
850 (const char *)base() + dot_symtab_sec->sh_offset, false);
851 }
852
853 template
854 typename ELFFile::Elf_Sym_Iter ELFFile::end_symbols() const {
782 return nullptr;
783 return reinterpret_cast(base() + dot_symtab_sec->sh_offset);
784 }
785
786 template
787 const typename ELFFile::Elf_Sym *ELFFile::end_symbols() const {
855788 if (!dot_symtab_sec)
856 return Elf_Sym_Iter(0, nullptr, false);
857 return Elf_Sym_Iter(dot_symtab_sec->sh_entsize,
858 (const char *)base() + dot_symtab_sec->sh_offset +
859 dot_symtab_sec->sh_size,
860 false);
789 return nullptr;
790 return reinterpret_cast(base() + dot_symtab_sec->sh_offset +
791 dot_symtab_sec->sh_size);
861792 }
862793
863794 template
949880 }
950881
951882 template
952 ErrorOr ELFFile::getSymbolName(Elf_Sym_Iter Sym) const {
953 if (!Sym.isDynamic())
954 return getSymbolName(dot_symtab_sec, &*Sym);
955
956 if (!DynStrRegion.Addr || Sym->st_name >= DynStrRegion.Size)
957 return object_error::parse_failed;
958 return StringRef(getDynamicString(Sym->st_name));
959 }
960
961 template
962883 ErrorOr
963884 ELFFile::getStaticSymbolName(const Elf_Sym *Symb) const {
964 return getSymbolName(dot_symtab_sec, Symb);
965 }
966
967 template
968 ErrorOr ELFFile::getSymbolName(const Elf_Shdr *Section,
969 const Elf_Sym *Symb) const {
970 const Elf_Shdr *StrTab = getSection(Section->sh_link);
971 return getString(StrTab, Symb->st_name);
885 return getSymbolName(dot_strtab_sec, Symb);
886 }
887
888 template
889 ErrorOr
890 ELFFile::getDynamicSymbolName(const Elf_Sym *Symb) const {
891 return StringRef(getDynamicString(Symb->st_name));
892 }
893
894 template
895 ErrorOr ELFFile::getSymbolName(const Elf_Sym *Symb,
896 bool IsDynamic) const {
897 if (IsDynamic)
898 return getDynamicSymbolName(Symb);
899 return getStaticSymbolName(Symb);
900 }
901
902 template
903 ErrorOr ELFFile::getSymbolName(const Elf_Shdr *StrTab,
904 const Elf_Sym *Sym) const {
905 return getString(StrTab, Sym->st_name);
972906 }
973907
974908 template
158158 typedef typename ELFFile::Elf_Rela Elf_Rela;
159159 typedef typename ELFFile::Elf_Dyn Elf_Dyn;
160160
161 typedef typename ELFFile::Elf_Sym_Iter Elf_Sym_Iter;
162161 typedef typename ELFFile::Elf_Shdr_Iter Elf_Shdr_Iter;
163162 typedef typename ELFFile::Elf_Dyn_Iter Elf_Dyn_Iter;
164163
223222 const Elf_Rel *getRel(DataRefImpl Rel) const;
224223 const Elf_Rela *getRela(DataRefImpl Rela) const;
225224
226 Elf_Sym_Iter toELFSymIter(DataRefImpl Symb) const {
227 bool IsDynamic = Symb.p & 1;
228 if (IsDynamic)
229 return Elf_Sym_Iter(
230 EF.begin_dynamic_symbols().getEntSize(),
231 reinterpret_cast(Symb.p & ~uintptr_t(1)), IsDynamic);
232 return Elf_Sym_Iter(EF.begin_symbols().getEntSize(),
233 reinterpret_cast(Symb.p), IsDynamic);
234 }
235
236 DataRefImpl toDRI(Elf_Sym_Iter Symb) const {
225 const Elf_Sym *toELFSymIter(DataRefImpl Sym) const {
226 return reinterpret_cast(Sym.p & ~uintptr_t(1));
227 }
228
229 DataRefImpl toDRI(const Elf_Sym *Sym, bool IsDynamic) const {
237230 DataRefImpl DRI;
238 DRI.p = reinterpret_cast(Symb.get()) |
239 static_cast(Symb.isDynamic());
231 DRI.p =
232 reinterpret_cast(Sym) | static_cast(IsDynamic);
240233 return DRI;
241234 }
242235
333326 typedef ELFObjectFile> ELF64BEObjectFile;
334327
335328 template
336 void ELFObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
337 Symb = toDRI(++toELFSymIter(Symb));
338 }
339
340 template
341 std::error_code ELFObjectFile::getSymbolName(DataRefImpl Symb,
329 void ELFObjectFile::moveSymbolNext(DataRefImpl &Sym) const {
330 const Elf_Sym *S = toELFSymIter(Sym);
331 Sym = toDRI(++S, Sym.p & 1);
332 }
333
334 template
335 std::error_code ELFObjectFile::getSymbolName(DataRefImpl Sym,
342336 StringRef &Result) const {
343 ErrorOr Name = EF.getSymbolName(toELFSymIter(Symb));
337 const Elf_Sym *ESym = toELFSymIter(Sym);
338 ErrorOr Name = EF.getSymbolName(ESym, Sym.p & 1);
344339 if (!Name)
345340 return Name.getError();
346341 Result = *Name;
404399
405400 template
406401 uint32_t ELFObjectFile::getSymbolAlignment(DataRefImpl Symb) const {
407 Elf_Sym_Iter Sym = toELFSymIter(Symb);
402 const Elf_Sym *Sym = toELFSymIter(Symb);
408403 if (Sym->st_shndx == ELF::SHN_COMMON)
409404 return Sym->st_value;
410405 return 0;
453448 }
454449
455450 template
456 uint32_t ELFObjectFile::getSymbolFlags(DataRefImpl Symb) const {
457 Elf_Sym_Iter EIter = toELFSymIter(Symb);
458 const Elf_Sym *ESym = &*EIter;
451 uint32_t ELFObjectFile::getSymbolFlags(DataRefImpl Sym) const {
452 const Elf_Sym *ESym = toELFSymIter(Sym);
459453
460454 uint32_t Result = SymbolRef::SF_None;
461455
469463 Result |= SymbolRef::SF_Absolute;
470464
471465 if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION ||
472 EIter == EF.begin_symbols() || EIter == EF.begin_dynamic_symbols())
466 ESym == EF.begin_symbols() || ESym == EF.begin_dynamic_symbols())
473467 Result |= SymbolRef::SF_FormatSpecific;
474468
475469 if (EF.getHeader()->e_machine == ELF::EM_ARM) {
476 if (ErrorOr NameOrErr = EF.getSymbolName(EIter)) {
470 ErrorOr NameOrErr = EF.getSymbolName(ESym, Sym.p & 1);
471 if (NameOrErr) {
477472 StringRef Name = *NameOrErr;
478473 if (Name.startswith("$d") || Name.startswith("$t") ||
479474 Name.startswith("$a"))
583578 template
584579 bool ELFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
585580 DataRefImpl Symb) const {
586 Elf_Sym_Iter ESym = toELFSymIter(Symb);
581 const Elf_Sym *ESym = toELFSymIter(Symb);
587582
588583 uintX_t Index = ESym->st_shndx;
589584 bool Reserved = Index >= ELF::SHN_LORESERVE && Index <= ELF::SHN_HIRESERVE;
664659 default:
665660 report_fatal_error("Invalid symbol table section type!");
666661 case ELF::SHT_SYMTAB:
667 SymbolData = toDRI(EF.begin_symbols() + symbolIdx);
662 SymbolData = toDRI(EF.begin_symbols() + symbolIdx, false);
668663 break;
669664 case ELF::SHT_DYNSYM:
670 SymbolData = toDRI(EF.begin_dynamic_symbols() + symbolIdx);
665 SymbolData = toDRI(EF.begin_dynamic_symbols() + symbolIdx, true);
671666 break;
672667 }
673668
803798
804799 template
805800 basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const {
806 return basic_symbol_iterator(SymbolRef(toDRI(EF.begin_symbols()), this));
801 DataRefImpl Sym = toDRI(EF.begin_symbols(), false);
802 return basic_symbol_iterator(SymbolRef(Sym, this));
807803 }
808804
809805 template
810806 basic_symbol_iterator ELFObjectFile::symbol_end_impl() const {
811 return basic_symbol_iterator(SymbolRef(toDRI(EF.end_symbols()), this));
807 DataRefImpl Sym = toDRI(EF.end_symbols(), false);
808 return basic_symbol_iterator(SymbolRef(Sym, this));
812809 }
813810
814811 template
815812 elf_symbol_iterator ELFObjectFile::dynamic_symbol_begin() const {
816 return symbol_iterator(SymbolRef(toDRI(EF.begin_dynamic_symbols()), this));
813 DataRefImpl Sym = toDRI(EF.begin_dynamic_symbols(), true);
814 return symbol_iterator(SymbolRef(Sym, this));
817815 }
818816
819817 template
820818 elf_symbol_iterator ELFObjectFile::dynamic_symbol_end() const {
821 return symbol_iterator(SymbolRef(toDRI(EF.end_dynamic_symbols()), this));
819 DataRefImpl Sym = toDRI(EF.end_dynamic_symbols(), true);
820 return symbol_iterator(SymbolRef(Sym, this));
822821 }
823822
824823 template
320320 const ELFFile &EF = *Obj->getELFFile();
321321
322322 const Elf_Shdr *sec = EF.getSection(Rel.d.a);
323 const Elf_Shdr *SymTab = EF.getSection(sec->sh_link);
324 assert(SymTab->sh_type == ELF::SHT_SYMTAB ||
325 SymTab->sh_type == ELF::SHT_DYNSYM);
326 const Elf_Shdr *StrTab = EF.getSection(SymTab->sh_link);
323327 uint8_t type;
324328 StringRef res;
325329 int64_t addend = 0;
350354 return EC;
351355 Target = *SecName;
352356 } else {
353 ErrorOr SymName =
354 EF.getSymbolName(EF.getSection(sec->sh_link), symb);
357 ErrorOr SymName = EF.getSymbolName(StrTab, symb);
355358 if (!SymName)
356359 return SymName.getError();
357360 Target = *SymName;
311311 typedef typename object::ELFFile::Elf_Shdr Elf_Shdr;
312312
313313 typedef typename object::ELFFile::Elf_Rel_Iter Elf_Rel_iterator;
314 typedef typename object::ELFFile::Elf_Sym_Iter Elf_Sym_iterator;
315314 typedef typename object::ELFFile::Elf_Shdr_Iter Elf_Shdr_iterator;
316315
317316 static const size_t IndexTableEntrySize;
343342 const size_t PrinterContext::IndexTableEntrySize = 8;
344343
345344 template
346 ErrorOr PrinterContext::FunctionAtAddress(unsigned Section,
347 uint64_t Address) const {
348 for (Elf_Sym_iterator SI = ELF->begin_symbols(), SE = ELF->end_symbols();
349 SI != SE; ++SI)
350 if (SI->st_shndx == Section && SI->st_value == Address &&
351 SI->getType() == ELF::STT_FUNC)
352 return ELF->getSymbolName(SI);
345 ErrorOr
346 PrinterContext::FunctionAtAddress(unsigned Section,
347 uint64_t Address) const {
348 for (const Elf_Sym &Sym : ELF->symbols())
349 if (Sym.st_shndx == Section && Sym.st_value == Address &&
350 Sym.getType() == ELF::STT_FUNC)
351 return ELF->getSymbolName(&Sym, false);
353352 return readobj_error::unknown_symbol;
354353 }
355354
6868 typedef typename ELFO::Elf_Shdr Elf_Shdr;
6969 typedef typename ELFO::Elf_Sym Elf_Sym;
7070
71 void printSymbol(typename ELFO::Elf_Sym_Iter Symbol);
71 void printSymbol(const Elf_Sym *Symbol, bool IsDynamic);
7272
7373 void printRelocations(const Elf_Shdr *Sec);
7474 void printRelocation(const Elf_Shdr *Sec, typename ELFO::Elf_Rela Rel);
122122
123123 template
124124 static std::string getFullSymbolName(const ELFO &Obj,
125 typename ELFO::Elf_Sym_Iter Symbol) {
126 StringRef SymbolName = errorOrDefault(Obj.getSymbolName(Symbol));
127 if (!Symbol.isDynamic())
125 const typename ELFO::Elf_Sym *Symbol,
126 bool IsDynamic) {
127 StringRef SymbolName = errorOrDefault(Obj.getSymbolName(Symbol, IsDynamic));
128 if (!IsDynamic)
128129 return SymbolName;
129130
130131 std::string FullSymbolName(SymbolName);
142143
143144 template
144145 static void
145 getSectionNameIndex(const ELFO &Obj, typename ELFO::Elf_Sym_Iter Symbol,
146 getSectionNameIndex(const ELFO &Obj, const typename ELFO::Elf_Sym *Symbol,
146147 StringRef &SectionName, unsigned &SectionIndex) {
147148 SectionIndex = Symbol->st_shndx;
148149 if (Symbol->isUndefined())
644645
645646 if (opts::SectionSymbols) {
646647 ListScope D(W, "Symbols");
647 for (typename ELFO::Elf_Sym_Iter SymI = Obj->begin_symbols(),
648 SymE = Obj->end_symbols();
649 SymI != SymE; ++SymI) {
650 if (Obj->getSection(&*SymI) == Section)
651 printSymbol(SymI);
648 for (const typename ELFO::Elf_Sym &Sym : Obj->symbols()) {
649 if (Obj->getSection(&Sym) == Section)
650 printSymbol(&Sym, false);
652651 }
653652 }
654653
696695 Obj->getRelocationTypeName(RelI->getType(Obj->isMips64EL()), RelocName);
697696 StringRef SymbolName;
698697 uint32_t SymIndex = RelI->getSymbol(Obj->isMips64EL());
699 typename ELFO::Elf_Sym_Iter Sym = Obj->begin_dynamic_symbols() + SymIndex;
700 SymbolName = errorOrDefault(Obj->getSymbolName(Sym));
698 const typename ELFO::Elf_Sym *Sym = Obj->begin_dynamic_symbols() + SymIndex;
699 SymbolName = errorOrDefault(Obj->getSymbolName(Sym, true));
701700 if (opts::ExpandRelocs) {
702701 DictScope Group(W, "Relocation");
703702 W.printHex("Offset", RelI->r_offset);
756755 if (SecName)
757756 TargetName = SecName.get();
758757 } else if (Sym.first) {
759 TargetName = errorOrDefault(Obj->getSymbolName(Sym.first, Sym.second));
758 const Elf_Shdr *SymTable = Sym.first;
759 const Elf_Shdr *StrTable = Obj->getSection(SymTable->sh_link);
760 TargetName = errorOrDefault(Obj->getSymbolName(StrTable, Sym.second));
760761 }
761762
762763 if (opts::ExpandRelocs) {
777778 template
778779 void ELFDumper::printSymbols() {
779780 ListScope Group(W, "Symbols");
780 for (typename ELFO::Elf_Sym_Iter SymI = Obj->begin_symbols(),
781 SymE = Obj->end_symbols();
782 SymI != SymE; ++SymI) {
783 printSymbol(SymI);
784 }
781 for (const typename ELFO::Elf_Sym &Sym : Obj->symbols())
782 printSymbol(&Sym, false);
785783 }
786784
787785 template
788786 void ELFDumper::printDynamicSymbols() {
789787 ListScope Group(W, "DynamicSymbols");
790788
791 for (typename ELFO::Elf_Sym_Iter SymI = Obj->begin_dynamic_symbols(),
792 SymE = Obj->end_dynamic_symbols();
793 SymI != SymE; ++SymI) {
794 printSymbol(SymI);
795 }
789 for (const typename ELFO::Elf_Sym &Sym : Obj->dynamic_symbols())
790 printSymbol(&Sym, true);
796791 }
797792
798793 template
799 void ELFDumper::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) {
794 void ELFDumper::printSymbol(const typename ELFO::Elf_Sym *Symbol,
795 bool IsDynamic) {
800796 unsigned SectionIndex = 0;
801797 StringRef SectionName;
802798 getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex);
803 std::string FullSymbolName = getFullSymbolName(*Obj, Symbol);
799 std::string FullSymbolName = getFullSymbolName(*Obj, Symbol, IsDynamic);
804800
805801 DictScope D(W, "Symbol");
806802 W.printNumber("Name", FullSymbolName, Symbol->st_name);
11591155 public:
11601156 typedef object::ELFFile ObjectFile;
11611157 typedef typename ObjectFile::Elf_Shdr Elf_Shdr;
1158 typedef typename ObjectFile::Elf_Sym Elf_Sym;
11621159
11631160 MipsGOTParser(const ObjectFile *Obj, StreamWriter &W) : Obj(Obj), W(W) {}
11641161
11651162 void parseGOT(const Elf_Shdr &GOTShdr);
11661163
11671164 private:
1168 typedef typename ObjectFile::Elf_Sym_Iter Elf_Sym_Iter;
11691165 typedef typename ObjectFile::Elf_Addr GOTEntry;
11701166 typedef typename ObjectFile::template ELFEntityIterator
11711167 GOTIter;
11791175 bool getGOTTags(uint64_t &LocalGotNum, uint64_t &GotSym);
11801176 void printGotEntry(uint64_t GotAddr, GOTIter BeginIt, GOTIter It);
11811177 void printGlobalGotEntry(uint64_t GotAddr, GOTIter BeginIt, GOTIter It,
1182 Elf_Sym_Iter Sym);
1178 const Elf_Sym *Sym, bool IsDynamic);
11831179 };
11841180 }
11851181
12051201 return;
12061202 }
12071203
1208 Elf_Sym_Iter DynSymBegin = Obj->begin_dynamic_symbols();
1209 Elf_Sym_Iter DynSymEnd = Obj->end_dynamic_symbols();
1204 const Elf_Sym *DynSymBegin = Obj->begin_dynamic_symbols();
1205 const Elf_Sym *DynSymEnd = Obj->end_dynamic_symbols();
12101206 std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd));
12111207
12121208 if (DtGotSym > DynSymTotal) {
12541250 ListScope GS(W, "Global entries");
12551251
12561252 GOTIter GotGlobalEnd = makeGOTIter(*GOT, DtLocalGotNum + GlobalGotNum);
1257 Elf_Sym_Iter GotDynSym = DynSymBegin + DtGotSym;
1253 const Elf_Sym *GotDynSym = DynSymBegin + DtGotSym;
12581254 for (; It != GotGlobalEnd; ++It) {
12591255 DictScope D(W, "Entry");
1260 printGlobalGotEntry(GOTShdr.sh_addr, GotBegin, It, GotDynSym++);
1256 printGlobalGotEntry(GOTShdr.sh_addr, GotBegin, It, GotDynSym++, true);
12611257 }
12621258 }
12631259
13181314
13191315 template
13201316 void MipsGOTParser::printGlobalGotEntry(uint64_t GotAddr, GOTIter BeginIt,
1321 GOTIter It, Elf_Sym_Iter Sym) {
1317 GOTIter It, const Elf_Sym *Sym,
1318 bool IsDynamic) {
13221319 printGotEntry(GotAddr, BeginIt, It);
13231320
13241321 W.printHex("Value", Sym->st_value);
13291326 getSectionNameIndex(*Obj, Sym, SectionName, SectionIndex);
13301327 W.printHex("Section", SectionName, SectionIndex);
13311328
1332 std::string FullSymbolName = getFullSymbolName(*Obj, Sym);
1329 std::string FullSymbolName = getFullSymbolName(*Obj, Sym, IsDynamic);
13331330 W.printNumber("Name", FullSymbolName, Sym->st_name);
13341331 }
13351332
2222 class ELFDumper {
2323 typedef object::Elf_Sym_Impl Elf_Sym;
2424 typedef typename object::ELFFile::Elf_Shdr Elf_Shdr;
25 typedef typename object::ELFFile::Elf_Sym_Iter Elf_Sym_Iter;
2625 typedef typename object::ELFFile::Elf_Word Elf_Word;
2726
2827 const object::ELFFile &Obj;
2928
30 std::error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S);
29 std::error_code dumpSymbol(const Elf_Sym *Sym, bool IsDynamic,
30 ELFYAML::Symbol &S);
3131 std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
3232 std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
3333 ELFYAML::RelocationSection &S);
121121 }
122122
123123 ELFYAML::Symbol S;
124 if (std::error_code EC = ELFDumper::dumpSymbol(SI, S))
124 if (std::error_code EC = ELFDumper::dumpSymbol(SI, false, S))
125125 return EC;
126126
127127 switch (SI->getBinding())
144144 }
145145
146146 template
147 std::error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym,
147 std::error_code ELFDumper::dumpSymbol(const Elf_Sym *Sym, bool IsDynamic,
148148 ELFYAML::Symbol &S) {
149149 S.Type = Sym->getType();
150150 S.Value = Sym->st_value;
151151 S.Size = Sym->st_size;
152152 S.Other = Sym->st_other;
153153
154 ErrorOr NameOrErr = Obj.getSymbolName(Sym);
154 ErrorOr NameOrErr = Obj.getSymbolName(Sym, IsDynamic);
155155 if (std::error_code EC = NameOrErr.getError())
156156 return EC;
157157 S.Name = NameOrErr.get();
181181 if (!NamePair.first)
182182 return obj2yaml_error::success;
183183
184 ErrorOr NameOrErr =
185 Obj.getSymbolName(NamePair.first, NamePair.second);
184 const Elf_Shdr *SymTab = NamePair.first;
185 const Elf_Shdr *StrTab = Obj.getSection(SymTab->sh_link);
186
187 ErrorOr NameOrErr = Obj.getSymbolName(StrTab, NamePair.second);
186188 if (std::error_code EC = NameOrErr.getError())
187189 return EC;
188190 R.Symbol = NameOrErr.get();
299301 // Get sh_info which is the signature.
300302 const Elf_Sym *symbol = Obj.getSymbol(Shdr->sh_info);
301303 const Elf_Shdr *symtab = Obj.getSection(Shdr->sh_link);
304 const Elf_Shdr *StrTab = Obj.getSection(symtab->sh_link);
302305 auto sectionContents = Obj.getSectionContents(Shdr);
303306 if (std::error_code ec = sectionContents.getError())
304307 return ec;
305 ErrorOr symbolName = Obj.getSymbolName(symtab, symbol);
308 ErrorOr symbolName = Obj.getSymbolName(StrTab, symbol);
306309 if (std::error_code EC = symbolName.getError())
307310 return EC;
308311 S->Info = *symbolName;