assign sections to the segments during load based on the offsets

This commit is contained in:
Mario Werner 2014-02-13 18:46:25 +01:00
parent f78a519522
commit 5dd8ba29bd
3 changed files with 26 additions and 0 deletions

View File

@ -378,6 +378,18 @@ class elfio
seg->load( stream, (std::streamoff)offset + i * entry_size );
seg->set_index( i );
// add sections to the segments based on the load address
Elf64_Off segBaseOffset = seg->get_offset();
Elf64_Off segEndOffset = segBaseOffset + seg->get_memory_size();
Elf_Half sec_num = sections.size();
for(Elf_Half j = 0; j < sec_num; ++j) {
const section* psec = sections[j];
Elf64_Off secOffset = psec->get_offset();
if( segBaseOffset <= secOffset && secOffset < segEndOffset)
seg->add_section_index(psec->get_index(),
psec->get_addr_align());
}
// Add section into the segments' container
segments_.push_back( seg );
}

View File

@ -54,6 +54,7 @@ class section
virtual void append_data( const std::string& data ) = 0;
protected:
virtual Elf64_Off get_offset() const = 0;
virtual void set_index( Elf_Half ) = 0;
virtual void load( std::ifstream& f,
std::streampos header_offset ) = 0;
@ -194,6 +195,13 @@ class section_impl : public section
//------------------------------------------------------------------------------
protected:
//------------------------------------------------------------------------------
Elf64_Off
get_offset() const
{
return header.sh_offset;
}
//------------------------------------------------------------------------------
void
set_index( Elf_Half value )

View File

@ -134,6 +134,12 @@ class segment_impl : public segment
//------------------------------------------------------------------------------
protected:
//------------------------------------------------------------------------------
Elf64_Off
get_offset() const
{
return ph.p_offset;
}
//------------------------------------------------------------------------------
void
set_index( Elf_Half value )