move the section table to the end of the elf file

This commit is contained in:
Mario Werner 2014-11-14 13:40:25 +01:00
parent c743d0bf74
commit 755b92c580
4 changed files with 23 additions and 30 deletions

Binary file not shown.

View File

@ -155,11 +155,23 @@ class elfio
}
bool is_still_good = true;
fill_final_attributes();
set_current_file_position();
// define layout specific header fields
// The position of the segment table is fixed after the header.
// The position of the section table is variable and needs to be fixed
// before saving.
header->set_segments_num( segments.size() );
header->set_segments_offset( segments.size() ? header->get_header_size() : 0 );
header->set_sections_num( sections.size() );
header->set_sections_offset( 0 );
// layout the first section right after the segment table
current_file_pos = header->get_header_size() +
header->get_segment_entry_size() * header->get_segments_num();
is_still_good = layout_segments_and_their_sections();
is_still_good = is_still_good && layout_sections_without_segments();
is_still_good = is_still_good && layout_section_table();
is_still_good = is_still_good && save_header( f );
is_still_good = is_still_good && save_sections( f );
@ -419,24 +431,6 @@ class elfio
return true;
}
//------------------------------------------------------------------------------
void fill_final_attributes()
{
// Fill not completed fields in the header
header->set_segments_num( segments.size() );
if ( segments.size() == 0 ) {
header->set_segments_offset( 0 );
}
else {
header->set_segments_offset( header->get_header_size() );
}
header->set_sections_num( sections.size() );
header->set_sections_offset( header->get_header_size() +
header->get_segment_entry_size() * segments.size() );
}
//------------------------------------------------------------------------------
bool save_header( std::ofstream& f )
{
@ -472,16 +466,6 @@ class elfio
return true;
}
//------------------------------------------------------------------------------
void set_current_file_position()
{
current_file_pos = header->get_header_size() +
header->get_segment_entry_size() * header->get_segments_num() +
header->get_section_entry_size() * header->get_sections_num();
}
//------------------------------------------------------------------------------
bool is_section_without_segment( unsigned int section_index )
{
@ -662,6 +646,15 @@ class elfio
return true;
}
//------------------------------------------------------------------------------
bool layout_section_table()
{
// simply place the section table at the end for now
// TODO should this table be aligned?
header->set_sections_offset(current_file_pos);
return true;
}
//------------------------------------------------------------------------------
public: