Make 'writer' examples to generate x86_64 files

This commit is contained in:
Serge Lamikhov-Center 2020-08-11 05:37:24 -07:00
parent 64e6b2d774
commit e6c59547e3
3 changed files with 9 additions and 7 deletions

2
.gitignore vendored
View File

@ -44,6 +44,8 @@ tests/elf_examples/write_exe_i386_32_section_added
tests/elf_examples/ppc-32bit-testcopy*.elf
tests/elf_examples/null_section_inside_segment*
tests/elf_examples/segment_containing_no_section*
examples/writer/hello_x86_64
examples/write_obj/hello
# various unwanted files (backups, objects, cmake artifacts)
*~

View File

@ -7,7 +7,7 @@
* 2. Execute result file write_obj
* ./write_obj
* 3. Link output file hello.o:
* gcc -m32 -s -nostartfiles -nostdlib hello.o -o hello
* ld -m elf x64 -o hello hello.o
* 4. Run the result file:
* ./hello
*/
@ -21,11 +21,11 @@ int main( void )
elfio writer;
// You can't proceed before this function call!
writer.create( ELFCLASS32, ELFDATA2LSB );
writer.create( ELFCLASS64, ELFDATA2LSB );
writer.set_os_abi( ELFOSABI_LINUX );
writer.set_type( ET_REL );
writer.set_machine( EM_386 );
writer.set_machine(EM_X86_64);
// This is our code
char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4

View File

@ -7,11 +7,11 @@ int main( void )
elfio writer;
// You can't proceed without this function call!
writer.create( ELFCLASS32, ELFDATA2LSB );
writer.create( ELFCLASS64, ELFDATA2LSB );
writer.set_os_abi( ELFOSABI_LINUX );
writer.set_type( ET_EXEC );
writer.set_machine( EM_386 );
writer.set_machine( EM_X86_64 );
// Create code section
section* text_sec = writer.sections.add( ".text" );
@ -41,7 +41,7 @@ int main( void )
// Add code section into program segment
text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() );
// Create data section*
// Create data section
section* data_sec = writer.sections.add( ".data" );
data_sec->set_type( SHT_PROGBITS );
data_sec->set_flags( SHF_ALLOC | SHF_WRITE );
@ -77,7 +77,7 @@ int main( void )
writer.set_entry( 0x08048000 );
// Create ELF file
writer.save( "hello_i386_32" );
writer.save("hello_x86_64");
return 0;
}