llvm.org GIT mirror llvm / 3d176ae
Convert obj->getSymbolName to sym->getName. I doesn't depend on the object anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240996 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
5 changed file(s) with 19 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
370370 ///
371371 /// \p SymTab is used to lookup the string table to use to get the symbol's
372372 /// name.
373 ErrorOr getSymbolName(StringRef StrTab, const Elf_Sym *Symb) const;
374373 ErrorOr getSectionName(const Elf_Shdr *Section) const;
375374 uint64_t getSymbolIndex(const Elf_Sym *sym) const;
376375 ErrorOr > getSectionContents(const Elf_Shdr *Sec) const;
880879 template
881880 ErrorOr
882881 ELFFile::getStaticSymbolName(const Elf_Sym *Symb) const {
883 return getSymbolName(DotStrtab, Symb);
882 return Symb->getName(DotStrtab);
884883 }
885884
886885 template
895894 if (IsDynamic)
896895 return getDynamicSymbolName(Symb);
897896 return getStaticSymbolName(Symb);
898 }
899
900 template
901 ErrorOr ELFFile::getSymbolName(StringRef StrTab,
902 const Elf_Sym *Sym) const {
903 uint32_t Offset = Sym->st_name;
904 if (Offset >= StrTab.size())
905 return object_error::parse_failed;
906 return StringRef(StrTab.data() + Offset);
907897 }
908898
909899 template
931921 // Non-dynamic symbols can have versions in their names
932922 // A name of the form 'foo@V1' indicates version 'V1', non-default.
933923 // A name of the form 'foo@@V2' indicates version 'V2', default version.
934 ErrorOr SymName = getSymbolName(StrTab, symb);
924 ErrorOr SymName = symb->getName(StrTab);
935925 if (!SymName)
936926 return SymName;
937927 StringRef Name = *SymName;
99 #ifndef LLVM_OBJECT_ELFTYPES_H
1010 #define LLVM_OBJECT_ELFTYPES_H
1111
12 #include "llvm/Object/Error.h"
1213 #include "llvm/Support/DataTypes.h"
1314 #include "llvm/Support/ELF.h"
1415 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/ErrorOr.h"
1517
1618 namespace llvm {
1719 namespace object {
204206 bool isExternal() const {
205207 return getBinding() != ELF::STB_LOCAL;
206208 }
207 };
209
210 ErrorOr getName(StringRef StrTab) const;
211 };
212
213 template
214 ErrorOr Elf_Sym_Impl::getName(StringRef StrTab) const {
215 uint32_t Offset = this->st_name;
216 if (Offset >= StrTab.size())
217 return object_error::parse_failed;
218 return StringRef(StrTab.data() + Offset);
219 }
208220
209221 /// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
210222 /// (.gnu.version). This structure is identical for ELF32 and ELF64.
358358 return EC;
359359 Target = *SecName;
360360 } else {
361 ErrorOr SymName = EF.getSymbolName(StrTab, symb);
361 ErrorOr SymName = symb->getName(StrTab);
362362 if (!SymName)
363363 return SymName.getError();
364364 Target = *SymName;
759759 const Elf_Shdr *StrTableSec = Obj->getSection(SymTable->sh_link);
760760 ErrorOr StrTableOrErr = Obj->getStringTable(StrTableSec);
761761 if (!error(StrTableOrErr.getError()))
762 TargetName =
763 errorOrDefault(Obj->getSymbolName(*StrTableOrErr, Sym.second));
762 TargetName = errorOrDefault(Sym.second->getName(*StrTableOrErr));
764763 }
765764
766765 if (opts::ExpandRelocs) {
188188 return EC;
189189 StringRef StrTab = *StrTabOrErr;
190190
191 ErrorOr NameOrErr = Obj.getSymbolName(StrTab, NamePair.second);
191 ErrorOr NameOrErr = NamePair.second->getName(StrTab);
192192 if (std::error_code EC = NameOrErr.getError())
193193 return EC;
194194 R.Symbol = NameOrErr.get();
313313 auto sectionContents = Obj.getSectionContents(Shdr);
314314 if (std::error_code ec = sectionContents.getError())
315315 return ec;
316 ErrorOr symbolName = Obj.getSymbolName(StrTab, symbol);
316 ErrorOr symbolName = symbol->getName(StrTab);
317317 if (std::error_code EC = symbolName.getError())
318318 return EC;
319319 S->Info = *symbolName;