@@ -1119,61 +1119,51 @@ InputFile *LazyObjFile::fetch() {
1119
1119
}
1120
1120
1121
1121
template <class ELFT > void LazyObjFile::parse () {
1122
- for (StringRef Sym : getSymbolNames ())
1123
- Symtab->addLazyObject <ELFT>(Sym, *this );
1122
+ // A lazy object file wraps either a bitcode file or an ELF file.
1123
+ if (isBitcode (this ->MB )) {
1124
+ std::unique_ptr<lto::InputFile> Obj =
1125
+ CHECK (lto::InputFile::create (this ->MB ), this );
1126
+ for (const lto::InputFile::Symbol &Sym : Obj->symbols ())
1127
+ if (!Sym.isUndefined ())
1128
+ Symtab->addLazyObject <ELFT>(Saver.save (Sym.getName ()), *this );
1129
+ return ;
1130
+ }
1131
+
1132
+ switch (getELFKind (this ->MB )) {
1133
+ case ELF32LEKind:
1134
+ addElfSymbols<ELF32LE>();
1135
+ return ;
1136
+ case ELF32BEKind:
1137
+ addElfSymbols<ELF32BE>();
1138
+ return ;
1139
+ case ELF64LEKind:
1140
+ addElfSymbols<ELF64LE>();
1141
+ return ;
1142
+ case ELF64BEKind:
1143
+ addElfSymbols<ELF64BE>();
1144
+ return ;
1145
+ default :
1146
+ llvm_unreachable (" getELFKind" );
1147
+ }
1124
1148
}
1125
1149
1126
- template <class ELFT > std::vector<StringRef> LazyObjFile::getElfSymbols () {
1127
- typedef typename ELFT::Shdr Elf_Shdr;
1128
- typedef typename ELFT::Sym Elf_Sym;
1129
- typedef typename ELFT::SymRange Elf_Sym_Range;
1150
+ template <class ELFT > void LazyObjFile::addElfSymbols () {
1151
+ ELFFile<ELFT> Obj = check (ELFFile<ELFT>::create (MB.getBuffer ()));
1152
+ ArrayRef<typename ELFT::Shdr> Sections = CHECK (Obj.sections (), this );
1130
1153
1131
- ELFFile<ELFT> Obj = check (ELFFile<ELFT>::create (this ->MB .getBuffer ()));
1132
- ArrayRef<Elf_Shdr> Sections = CHECK (Obj.sections (), this );
1133
- for (const Elf_Shdr &Sec : Sections) {
1154
+ for (const typename ELFT::Shdr &Sec : Sections) {
1134
1155
if (Sec.sh_type != SHT_SYMTAB)
1135
1156
continue ;
1136
1157
1137
- Elf_Sym_Range Syms = CHECK (Obj.symbols (&Sec), this );
1158
+ typename ELFT::SymRange Syms = CHECK (Obj.symbols (&Sec), this );
1138
1159
uint32_t FirstNonLocal = Sec.sh_info ;
1139
1160
StringRef StringTable =
1140
1161
CHECK (Obj.getStringTableForSymtab (Sec, Sections), this );
1141
- std::vector<StringRef> V;
1142
1162
1143
- for (const Elf_Sym &Sym : Syms.slice (FirstNonLocal))
1163
+ for (const typename ELFT::Sym &Sym : Syms.slice (FirstNonLocal))
1144
1164
if (Sym.st_shndx != SHN_UNDEF)
1145
- V.push_back (CHECK (Sym.getName (StringTable), this ));
1146
- return V;
1147
- }
1148
- return {};
1149
- }
1150
-
1151
- std::vector<StringRef> LazyObjFile::getBitcodeSymbols () {
1152
- std::unique_ptr<lto::InputFile> Obj =
1153
- CHECK (lto::InputFile::create (this ->MB ), this );
1154
- std::vector<StringRef> V;
1155
- for (const lto::InputFile::Symbol &Sym : Obj->symbols ())
1156
- if (!Sym.isUndefined ())
1157
- V.push_back (Saver.save (Sym.getName ()));
1158
- return V;
1159
- }
1160
-
1161
- // Returns a vector of globally-visible defined symbol names.
1162
- std::vector<StringRef> LazyObjFile::getSymbolNames () {
1163
- if (isBitcode (this ->MB ))
1164
- return getBitcodeSymbols ();
1165
-
1166
- switch (getELFKind (this ->MB )) {
1167
- case ELF32LEKind:
1168
- return getElfSymbols<ELF32LE>();
1169
- case ELF32BEKind:
1170
- return getElfSymbols<ELF32BE>();
1171
- case ELF64LEKind:
1172
- return getElfSymbols<ELF64LE>();
1173
- case ELF64BEKind:
1174
- return getElfSymbols<ELF64BE>();
1175
- default :
1176
- llvm_unreachable (" getELFKind" );
1165
+ Symtab->addLazyObject <ELFT>(CHECK (Sym.getName (StringTable), this ),
1166
+ *this );
1177
1167
}
1178
1168
}
1179
1169
@@ -1203,7 +1193,6 @@ template <class ELFT> void elf::readJustSymbolsFile(MemoryBufferRef MB) {
1203
1193
StringRef StringTable =
1204
1194
CHECK (Obj.getStringTableForSymtab (Sec, Sections), ObjName);
1205
1195
1206
- std::vector<std::pair<StringRef, uint64_t >> Ret;
1207
1196
for (const Elf_Sym &Sym : Syms.slice (FirstNonLocal))
1208
1197
if (Sym.st_shndx != SHN_UNDEF)
1209
1198
Symtab->addRegular (CHECK (Sym.getName (StringTable), ObjName),
0 commit comments