Skip to content

Commit 6c53646

Browse files
committed
parse section relocations but do not parse dynamic relocations twice.
1 parent 1014ba0 commit 6c53646

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/ELF/Parser.tcc

+19-16
Original file line numberDiff line numberDiff line change
@@ -430,23 +430,26 @@ void Parser::parse_binary(void) {
430430
}
431431

432432
// 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);
449444
}
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() << ")";
450453
}
451454
}
452455

0 commit comments

Comments
 (0)