Skip to content
Snippets Groups Projects
Commit 5dd8ba29 authored by Mario Werner's avatar Mario Werner
Browse files

assign sections to the segments during load based on the offsets

parent f78a5195
Branches
Tags
No related merge requests found
...@@ -378,6 +378,18 @@ class elfio ...@@ -378,6 +378,18 @@ class elfio
seg->load( stream, (std::streamoff)offset + i * entry_size ); seg->load( stream, (std::streamoff)offset + i * entry_size );
seg->set_index( i ); 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 // Add section into the segments' container
segments_.push_back( seg ); segments_.push_back( seg );
} }
......
...@@ -54,6 +54,7 @@ class section ...@@ -54,6 +54,7 @@ class section
virtual void append_data( const std::string& data ) = 0; virtual void append_data( const std::string& data ) = 0;
protected: protected:
virtual Elf64_Off get_offset() const = 0;
virtual void set_index( Elf_Half ) = 0; virtual void set_index( Elf_Half ) = 0;
virtual void load( std::ifstream& f, virtual void load( std::ifstream& f,
std::streampos header_offset ) = 0; std::streampos header_offset ) = 0;
...@@ -194,6 +195,13 @@ class section_impl : public section ...@@ -194,6 +195,13 @@ class section_impl : public section
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
protected: protected:
//------------------------------------------------------------------------------
Elf64_Off
get_offset() const
{
return header.sh_offset;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void void
set_index( Elf_Half value ) set_index( Elf_Half value )
......
...@@ -134,6 +134,12 @@ class segment_impl : public segment ...@@ -134,6 +134,12 @@ class segment_impl : public segment
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
protected: protected:
//------------------------------------------------------------------------------
Elf64_Off
get_offset() const
{
return ph.p_offset;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void void
set_index( Elf_Half value ) set_index( Elf_Half value )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment