llvm.org GIT mirror llvm / efcef81
[llvm-readobj][ELF] Factor out the code retrieve ELF symbol information (section name, section index, full name) into the separate functions. No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210509 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 6 years ago
1 changed file(s) with 50 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
109109 }
110110
111111 } // namespace llvm
112
113 template
114 static std::string getFullSymbolName(const ELFO &Obj,
115 typename ELFO::Elf_Sym_Iter Symbol) {
116 StringRef SymbolName = errorOrDefault(Obj.getSymbolName(Symbol));
117 if (!Symbol.isDynamic())
118 return SymbolName;
119
120 std::string FullSymbolName(SymbolName);
121
122 bool IsDefault;
123 ErrorOr Version =
124 Obj.getSymbolVersion(nullptr, &*Symbol, IsDefault);
125 if (Version) {
126 FullSymbolName += (IsDefault ? "@@" : "@");
127 FullSymbolName += *Version;
128 } else
129 error(Version.getError());
130 return FullSymbolName;
131 }
132
133 template
134 static void
135 getSectionNameIndex(const ELFO &Obj, typename ELFO::Elf_Sym_Iter Symbol,
136 StringRef &SectionName, unsigned &SectionIndex) {
137 SectionIndex = Symbol->st_shndx;
138 if (SectionIndex == SHN_UNDEF) {
139 SectionName = "Undefined";
140 } else if (SectionIndex >= SHN_LOPROC && SectionIndex <= SHN_HIPROC) {
141 SectionName = "Processor Specific";
142 } else if (SectionIndex >= SHN_LOOS && SectionIndex <= SHN_HIOS) {
143 SectionName = "Operating System Specific";
144 } else if (SectionIndex > SHN_HIOS && SectionIndex < SHN_ABS) {
145 SectionName = "Reserved";
146 } else if (SectionIndex == SHN_ABS) {
147 SectionName = "Absolute";
148 } else if (SectionIndex == SHN_COMMON) {
149 SectionName = "Common";
150 } else {
151 if (SectionIndex == SHN_XINDEX)
152 SectionIndex = Obj.getSymbolTableIndex(&*Symbol);
153 assert(SectionIndex != SHN_XINDEX &&
154 "getSymbolTableIndex should handle this");
155 const typename ELFO::Elf_Shdr *Sec = Obj.getSection(SectionIndex);
156 SectionName = errorOrDefault(Obj.getSectionName(Sec));
157 }
158 }
112159
113160 static const EnumEntry ElfClass[] = {
114161 { "None", ELF::ELFCLASSNONE },
650697
651698 template
652699 void ELFDumper::printSymbol(typename ELFO::Elf_Sym_Iter Symbol) {
653 StringRef SymbolName = errorOrDefault(Obj->getSymbolName(Symbol));
654
655 unsigned SectionIndex = Symbol->st_shndx;
700 unsigned SectionIndex = 0;
656701 StringRef SectionName;
657 if (SectionIndex == SHN_UNDEF) {
658 SectionName = "Undefined";
659 } else if (SectionIndex >= SHN_LOPROC && SectionIndex <= SHN_HIPROC) {
660 SectionName = "Processor Specific";
661 } else if (SectionIndex >= SHN_LOOS && SectionIndex <= SHN_HIOS) {
662 SectionName = "Operating System Specific";
663 } else if (SectionIndex > SHN_HIOS && SectionIndex < SHN_ABS) {
664 SectionName = "Reserved";
665 } else if (SectionIndex == SHN_ABS) {
666 SectionName = "Absolute";
667 } else if (SectionIndex == SHN_COMMON) {
668 SectionName = "Common";
669 } else {
670 if (SectionIndex == SHN_XINDEX)
671 SectionIndex = Obj->getSymbolTableIndex(&*Symbol);
672 assert(SectionIndex != SHN_XINDEX &&
673 "getSymbolTableIndex should handle this");
674 const Elf_Shdr *Sec = Obj->getSection(SectionIndex);
675 SectionName = errorOrDefault(Obj->getSectionName(Sec));
676 }
677
678 std::string FullSymbolName(SymbolName);
679 if (Symbol.isDynamic()) {
680 bool IsDefault;
681 ErrorOr Version = Obj->getSymbolVersion(nullptr, &*Symbol,
682 IsDefault);
683 if (Version) {
684 FullSymbolName += (IsDefault ? "@@" : "@");
685 FullSymbolName += *Version;
686 } else
687 error(Version.getError());
688 }
702 getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex);
703 std::string FullSymbolName = getFullSymbolName(*Obj, Symbol);
689704
690705 DictScope D(W, "Symbol");
691706 W.printNumber("Name", FullSymbolName, Symbol->st_name);