LibELF: Calculate size of relocation table correctly in all cases
RELASZ might include the PLT table as well. Check if that is the case and correct the size of the non-PLT relocation table.
This commit is contained in:
parent
968038aa79
commit
c42e8ddc48
Notes:
sideshowbarker
2024-07-17 10:08:28 +09:00
Author: https://github.com/spholz Commit: https://github.com/SerenityOS/serenity/commit/c42e8ddc48 Pull-request: https://github.com/SerenityOS/serenity/pull/21006 Reviewed-by: https://github.com/timschumi ✅
1 changed files with 13 additions and 0 deletions
|
@ -202,6 +202,19 @@ void DynamicObject::parse()
|
|||
m_size_of_relocation_entry = sizeof(ElfW(Rel));
|
||||
}
|
||||
|
||||
// Whether or not RELASZ (stored in m_size_of_relocation_table) only refers to non-PLT entries is not clearly specified.
|
||||
// So check if [JMPREL, JMPREL+PLTRELSZ) is in [RELA, RELA+RELASZ).
|
||||
// If so, change the size of the non-PLT relocation table.
|
||||
if (m_plt_relocation_offset_location >= m_relocation_table_offset // JMPREL >= RELA
|
||||
&& m_plt_relocation_offset_location < (m_relocation_table_offset + m_size_of_relocation_table)) { // JMPREL < (RELA + RELASZ)
|
||||
// [JMPREL, JMPREL+PLTRELSZ) is in [RELA, RELA+RELASZ)
|
||||
|
||||
// Verify that the ends of the tables match up
|
||||
VERIFY(m_plt_relocation_offset_location + m_size_of_plt_relocation_entry_list == m_relocation_table_offset + m_size_of_relocation_table);
|
||||
|
||||
m_size_of_relocation_table -= m_size_of_plt_relocation_entry_list;
|
||||
}
|
||||
|
||||
auto hash_section_address = hash_section().address().as_ptr();
|
||||
// TODO: consider base address - it might not be zero
|
||||
auto num_hash_chains = ((u32*)hash_section_address)[1];
|
||||
|
|
Loading…
Add table
Reference in a new issue