From compiling my app to checking the test.elf it creates here is the full ouput to display what I mean
Code:
misty alpha
Writing ELF Header...
Writing Symbols...
Writing Segment Header/s...
Writing Program Header/s...
Writing Program Instructions...
Flushing file...
./test.elf
Segmentation fault
readelf -all test.elf
ELF Header:
Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - GNU
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x19c
Start of program headers: 356 (bytes into file)
Start of section headers: 100 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 1
Size of section headers: 64 (bytes)
Number of section headers: 4
Section header string table index: 2
readelf: Error: Section 2 has invalid sh_entsize of 0000000000000024
readelf: Error: (Using the expected size of 24 for the rest of this dump)
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] ^�ELF^B^A^A^C NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] ELF^B^A^A^C PROGBITS 000000000000019c 00000000
0000000000000006 0000000000000000 WXSLlp 0 0 0
[ 2] LF^B^A^A^C SYMTAB 0000000000000040 00000000
0000000000000024 0000000000000018 S 3 3 1
[ 3] F^B^A^A^C STRTAB 0000000000000040 00000000
0000000000000024 0000000000000001 S 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
l (large), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000000000 0x000000000000019c 0x000000000000019c
0x0000000000000006 0x0000000000000006 RWE 0x0
Section to Segment mapping:
Segment Sections...
00
There is no dynamic section in this file.
There are no relocations in this file.
The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.
Symbol table 'LF^B^A^A^C' contains 1 entry:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0x1003e0002 FUNC LOCAL INTERNAL bad section index[769] <corrupt>
No version information found in this file.
Exiting...
------------------
(program exited with code: 0)
Press return to continue
The test.elf my app created (for hex editor only atm):
test.elf - Google Drive
The code I used to create the section header ".strtab"
Code:
elf64_t elf64 = {0};
segment_t e64 = {
0, "ELF Header",
{ sizeof(elf64_t), 1, 1, &elf64 }
};
segment_t stxt = Symbols();
segment_t es64 = {
stxt.pos + stxt.mem.size, "Segment Header/s",
{ sizeof(elsh64_t) * 4, 4, 4, calloc( 4, sizeof(elsh64_t) ) }
}; elsh64_t *es64v = (elsh64_t*)es64.mem.buff, *es64e = es64v;
...
/* Fill segment header .strtab */
es64e = &es64v[--s];
es64e->sh_name = s;
es64e->sh_type = ELSH_SHT_STRTAB;
es64e->sh_flags = 0x20;
es64e->sh_addr = stxt.pos;
es64e->sh_size = stxt.mem.size;
es64e->sh_offset = 0;
es64e->sh_link = 0;
es64e->sh_info = 0;
es64e->sh_adralign = 1;
es64e->sh_entsize = 1;