mirror of
https://github.com/serge1/ELFIO.git
synced 2025-01-16 04:14:39 +00:00
assign sections to the segments during load based on the offsets
This commit is contained in:
parent
f78a519522
commit
5dd8ba29bd
@ -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 );
|
||||
}
|
||||
|
@ -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 )
|
||||
|
@ -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 )
|
||||
|
Loading…
Reference in New Issue
Block a user