@@ -102,7 +102,7 @@ bool GetBuildIdFromNoteFile(const std::string& filename, BuildId* build_id) {
102
102
103
103
template <class ELFT >
104
104
bool GetBuildIdFromELFFile (const llvm::object::ELFFile<ELFT>* elf, BuildId* build_id) {
105
- for (auto section_iterator = elf->begin_sections (); section_iterator != elf->end_sections ();
105
+ for (auto section_iterator = elf->section_begin (); section_iterator != elf->section_end ();
106
106
++section_iterator) {
107
107
if (section_iterator->sh_type == llvm::ELF::SHT_NOTE) {
108
108
auto contents = elf->getSectionContents (&*section_iterator);
@@ -206,48 +206,44 @@ bool IsArmMappingSymbol(const char* name) {
206
206
}
207
207
208
208
template <class ELFT >
209
- void ParseSymbolsFromELFFile (const llvm::object::ELFFile <ELFT>* elf ,
209
+ void ParseSymbolsFromELFFile (const llvm::object::ELFObjectFile <ELFT>* elf_obj ,
210
210
std::function<void (const ElfFileSymbol&)> callback) {
211
+ auto elf = elf_obj->getELFFile ();
211
212
bool is_arm = (elf->getHeader ()->e_machine == llvm::ELF::EM_ARM ||
212
213
elf->getHeader ()->e_machine == llvm::ELF::EM_AARCH64);
213
- auto begin = elf-> begin_symbols ();
214
- auto end = elf-> end_symbols ();
214
+ auto begin = elf_obj-> symbol_begin ();
215
+ auto end = elf_obj-> symbol_end ();
215
216
if (begin == end) {
216
- begin = elf-> begin_dynamic_symbols ();
217
- end = elf-> end_dynamic_symbols ();
217
+ begin = elf_obj-> dynamic_symbol_begin ();
218
+ end = elf_obj-> dynamic_symbol_end ();
218
219
}
219
220
for (; begin != end; ++begin) {
220
- auto & elf_symbol = *begin;
221
-
222
221
ElfFileSymbol symbol;
223
-
224
- auto shdr = elf ->getSection (&elf_symbol );
225
- if (shdr == nullptr ) {
222
+ auto elf_symbol = static_cast < const llvm::object::ELFSymbolRef*>(&*begin);
223
+ auto section_it = elf_symbol ->getSection ();
224
+ if (!section_it ) {
226
225
continue ;
227
226
}
228
- auto section_name = elf-> getSectionName (shdr) ;
229
- if (section_name. getError () || section_name. get () .empty ()) {
227
+ llvm::StringRef section_name;
228
+ if (section_it. get ()-> getName (section_name) || section_name.empty ()) {
230
229
continue ;
231
230
}
232
- if (section_name.get () == " .text" ) {
231
+ if (section_name.str () == " .text" ) {
233
232
symbol.is_in_text_section = true ;
234
233
}
235
234
236
- auto symbol_name = elf-> getSymbolName (begin );
237
- if (symbol_name. getError ()) {
235
+ auto symbol_name = elf_symbol-> getName ( );
236
+ if (! symbol_name || symbol_name. get (). empty ()) {
238
237
continue ;
239
238
}
240
239
symbol.name = symbol_name.get ();
241
- if (symbol.name .empty ()) {
242
- continue ;
243
- }
244
- symbol.vaddr = elf_symbol.st_value ;
240
+ symbol.vaddr = elf_symbol->getValue ();
245
241
if ((symbol.vaddr & 1 ) != 0 && is_arm) {
246
242
// Arm sets bit 0 to mark it as thumb code, remove the flag.
247
243
symbol.vaddr &= ~1 ;
248
244
}
249
- symbol.len = elf_symbol. st_size ;
250
- int type = elf_symbol. getType ();
245
+ symbol.len = elf_symbol-> getSize () ;
246
+ int type = elf_symbol-> getELFType ();
251
247
if (type == llvm::ELF::STT_FUNC) {
252
248
symbol.is_func = true ;
253
249
} else if (type == llvm::ELF::STT_NOTYPE) {
@@ -303,9 +299,9 @@ bool ParseSymbolsFromEmbeddedElfFile(const std::string& filename, uint64_t file_
303
299
return false ;
304
300
}
305
301
if (auto elf = llvm::dyn_cast<llvm::object::ELF32LEObjectFile>(ret.obj )) {
306
- ParseSymbolsFromELFFile (elf-> getELFFile () , callback);
302
+ ParseSymbolsFromELFFile (elf, callback);
307
303
} else if (auto elf = llvm::dyn_cast<llvm::object::ELF64LEObjectFile>(ret.obj )) {
308
- ParseSymbolsFromELFFile (elf-> getELFFile () , callback);
304
+ ParseSymbolsFromELFFile (elf, callback);
309
305
} else {
310
306
LOG (ERROR) << " unknown elf format in file " << filename;
311
307
return false ;
@@ -317,7 +313,7 @@ template <class ELFT>
317
313
bool ReadMinExecutableVirtualAddress (const llvm::object::ELFFile<ELFT>* elf, uint64_t * p_vaddr) {
318
314
bool has_vaddr = false ;
319
315
uint64_t min_addr = std::numeric_limits<uint64_t >::max ();
320
- for (auto it = elf->begin_program_headers (); it != elf->end_program_headers (); ++it) {
316
+ for (auto it = elf->program_header_begin (); it != elf->program_header_end (); ++it) {
321
317
if ((it->p_type == llvm::ELF::PT_LOAD) && (it->p_flags & llvm::ELF::PF_X)) {
322
318
if (it->p_vaddr < min_addr) {
323
319
min_addr = it->p_vaddr ;
@@ -361,7 +357,7 @@ bool ReadMinExecutableVirtualAddressFromElfFile(const std::string& filename,
361
357
template <class ELFT >
362
358
bool ReadSectionFromELFFile (const llvm::object::ELFFile<ELFT>* elf, const std::string& section_name,
363
359
std::string* content) {
364
- for (auto it = elf->begin_sections (); it != elf->end_sections (); ++it) {
360
+ for (auto it = elf->section_begin (); it != elf->section_end (); ++it) {
365
361
auto name_or_err = elf->getSectionName (&*it);
366
362
if (name_or_err && *name_or_err == section_name) {
367
363
auto data_or_err = elf->getSectionContents (&*it);
0 commit comments