Skip to content
Snippets Groups Projects
Commit 6c190788 authored by Martin Bickel's avatar Martin Bickel Committed by Serge Lamikhov-Center
Browse files

Fixed section to segment mapping for 0-length sections

parent 6dad9432
No related branches found
No related tags found
No related merge requests found
......@@ -419,6 +419,18 @@ class elfio
return num;
}
//------------------------------------------------------------------------------
//! Checks whether the addresses of the section entirely fall within the given segment.
//! It doesn't matter if the addresses are memory addresses, or file offsets,
//! they just need to be in the same address space
bool is_sect_in_seg ( Elf64_Off sect_begin, Elf_Xword sect_size, Elf64_Off seg_begin, Elf64_Off seg_end ) {
if ( sect_size > 0 ) {
return seg_begin <= sect_begin && sect_begin + sect_size <= seg_end;
} else {
return seg_begin <= sect_begin && sect_begin < seg_end;
}
}
//------------------------------------------------------------------------------
bool load_segments( std::istream& stream )
{
......@@ -454,12 +466,8 @@ class elfio
// SHF_ALLOC sections are matched based on the virtual address
// otherwise the file offset is matched
if( psec->get_flags() & SHF_ALLOC
? (segVBaseAddr <= psec->get_address()
&& psec->get_address() + psec->get_size()
<= segVEndAddr)
: (segBaseOffset <= psec->get_offset()
&& psec->get_offset() + psec->get_size()
<= segEndOffset)) {
? is_sect_in_seg( psec->get_address(), psec->get_size(), segVBaseAddr, segVEndAddr )
: is_sect_in_seg( psec->get_offset(), psec->get_size(), segBaseOffset, segEndOffset )) {
seg->add_section_index( psec->get_index(),
psec->get_addr_align() );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment