@@ -430,23 +430,26 @@ void Parser::parse_binary(void) {
430
430
}
431
431
432
432
// Try to parse using sections
433
- if (this ->binary_ ->relocations_ .size () == 0 ) {
434
- for (const Section& section : this ->binary_ ->sections ()) {
435
-
436
- try {
437
- if (section.type () == ELF_SECTION_TYPES::SHT_REL) {
438
-
439
- this ->parse_section_relocations <ELF_T, typename ELF_T::Elf_Rel>(section);
440
- }
441
- else if (section.type () == ELF_SECTION_TYPES::SHT_RELA) {
442
- this ->parse_section_relocations <ELF_T, typename ELF_T::Elf_Rela>(section);
443
- }
444
-
445
- } catch (const exception & e) {
446
- LOG (WARNING) << " Unable to parse relocations from section '"
447
- << section.name () << " '"
448
- << " (" << e.what () << " )" ;
433
+ // If we don't have any relocations, we parse all relocation sections
434
+ // otherwise, only the non-allocated sections to avoid parsing dynamic
435
+ // relocations (or plt relocations) twice.
436
+ bool skip_allocated_sections = this ->binary_ ->relocations_ .size () > 0 ;
437
+ for (const Section& section : this ->binary_ ->sections ()) {
438
+ if (skip_allocated_sections && section.has (ELF_SECTION_FLAGS::SHF_ALLOC)){
439
+ continue ;
440
+ }
441
+ try {
442
+ if (section.type () == ELF_SECTION_TYPES::SHT_REL) {
443
+ this ->parse_section_relocations <ELF_T, typename ELF_T::Elf_Rel>(section);
449
444
}
445
+ else if (section.type () == ELF_SECTION_TYPES::SHT_RELA) {
446
+ this ->parse_section_relocations <ELF_T, typename ELF_T::Elf_Rela>(section);
447
+ }
448
+
449
+ } catch (const exception & e) {
450
+ LOG (WARNING) << " Unable to parse relocations from section '"
451
+ << section.name () << " '"
452
+ << " (" << e.what () << " )" ;
450
453
}
451
454
}
452
455
0 commit comments