Add a convinience function 'add_section()' to segment class

It is not clear why this hasn't been done initially
This commit is contained in:
Serge Lamikhov-Center 2021-04-08 17:03:05 +03:00
parent 167c5cd690
commit 0fac6ce45b
5 changed files with 14 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@ -48,11 +48,12 @@ class segment
virtual const char* get_data() const = 0;
virtual Elf_Half add_section( section* psec, Elf_Xword addr_align ) = 0;
virtual Elf_Half add_section_index( Elf_Half index,
Elf_Xword addr_align ) = 0;
virtual Elf_Half get_sections_num() const = 0;
virtual Elf_Half get_section_index_at( Elf_Half num ) const = 0;
virtual bool is_offset_initialized() const = 0;
Elf_Xword addr_align ) = 0;
virtual Elf_Half get_sections_num() const = 0;
virtual Elf_Half get_section_index_at( Elf_Half num ) const = 0;
virtual bool is_offset_initialized() const = 0;
protected:
ELFIO_SET_ACCESS_DECL( Elf64_Off, offset );
@ -115,6 +116,12 @@ template <class T> class segment_impl : public segment
return (Elf_Half)sections.size();
}
//------------------------------------------------------------------------------
Elf_Half add_section( section* psec, Elf_Xword addr_align )
{
return add_section_index( psec->get_index(), addr_align );
}
//------------------------------------------------------------------------------
Elf_Half get_sections_num() const { return (Elf_Half)sections.size(); }

View File

@ -83,8 +83,7 @@ int main( void )
text_seg->set_align( PAGE_SIZE );
// Add code section into program segment
text_seg->add_section_index( text_sec->get_index(),
text_sec->get_addr_align() );
text_seg->add_section( text_sec, text_sec->get_addr_align() );
// Create data section
section* data_sec = writer.sections.add( ".data" );
@ -107,8 +106,7 @@ int main( void )
data_seg->set_align( PAGE_SIZE );
// Add code section into program segment
data_seg->add_section_index( data_sec->get_index(),
data_sec->get_addr_align() );
data_seg->add_section( data_sec, data_sec->get_addr_align() );
// Add optional signature for the file producer
section* note_sec = writer.sections.add( ".note" );

View File

@ -174,8 +174,7 @@ bool write_exe_i386( const std::string& filename,
text_seg->set_physical_address( 0x08048000 );
text_seg->set_flags( PF_X | PF_R );
text_seg->set_align( 0x1000 );
text_seg->add_section_index( text_sec->get_index(),
text_sec->get_addr_align() );
text_seg->add_section( text_sec, text_sec->get_addr_align() );
// Create data section*
section* data_sec = writer.sections.add( ".data" );