diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-07-06 23:13:03 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-07-06 23:33:42 -0700 |
commit | 517a471bc0945657dc331c16d4bed74c7dc5b3b5 (patch) | |
tree | acf3d4efd4adf77994f688592e2e1f972089c4a3 | |
parent | 21b5cf52e2e31e26529d9b47fc6fafdf88a73f75 (diff) | |
download | mu-517a471bc0945657dc331c16d4bed74c7dc5b3b5.tar.gz |
4316
Second attempt at commit 4291. We'll now not copy the headers into memory, but we'll still allocate space for them. Still some security benefits, and I'm gaining confidence that I understand the ELF format.
-rw-r--r-- | subx/021translate.cc | 9 | ||||
-rwxr-xr-x | subx/ex1 | bin | 96 -> 96 bytes | |||
-rw-r--r-- | subx/ex1.1.subx | 2 | ||||
-rwxr-xr-x | subx/teensy/test5 | bin | 96 -> 96 bytes | |||
-rw-r--r-- | subx/teensy/test5.s | 15 |
5 files changed, 15 insertions, 11 deletions
diff --git a/subx/021translate.cc b/subx/021translate.cc index 2f34f8dd..354eaf0a 100644 --- a/subx/021translate.cc +++ b/subx/021translate.cc @@ -100,14 +100,15 @@ void dump_elf_header(ostream& out) { uint32_t p_type = 0x1; emit(p_type); // p_offset - uint32_t p_offset = 0; + uint32_t p_offset = /*size of ehdr*/52 + /*size of phdr*/32; emit(p_offset); // p_vaddr - emit(START); + uint32_t addr = START+p_offset; + emit(addr); // p_paddr - emit(START); + emit(addr); // p_filesz - uint32_t size = (End_of_program-/*we're not using location 0*/1) + /*size of ehdr*/52 + /*size of phdr*/32; + uint32_t size = End_of_program - /*we're not using location 0*/1; emit(size); // p_memsz emit(size); diff --git a/subx/ex1 b/subx/ex1 index 205f8d60..f3c9730d 100755 --- a/subx/ex1 +++ b/subx/ex1 Binary files differdiff --git a/subx/ex1.1.subx b/subx/ex1.1.subx index 2741213b..97e52d60 100644 --- a/subx/ex1.1.subx +++ b/subx/ex1.1.subx @@ -8,7 +8,7 @@ # instruction mod, reg, Reg/Mem bits scale, index, base # 1-3 bytes 0/1 byte 0/1 byte 0/1/2/4 bytes 0/1/2/4 bytes bb 2a 00 00 00 # copy 0x2a (42) to EBX - 05 01 00 00 00 # copy 1 to EAX + b8 01 00 00 00 # copy 1 to EAX cd 80 # int 80h # vim:ft=subx diff --git a/subx/teensy/test5 b/subx/teensy/test5 index 4d2da664..f3c9730d 100755 --- a/subx/teensy/test5 +++ b/subx/teensy/test5 Binary files differdiff --git a/subx/teensy/test5.s b/subx/teensy/test5.s index d549306b..ca7c86e4 100644 --- a/subx/teensy/test5.s +++ b/subx/teensy/test5.s @@ -25,11 +25,14 @@ ehdrsize equ $ - ehdr phdr: ; Elf32_Phdr dd 1 ; p_type - dd 0 ; p_offset - dd $$ ; p_vaddr - dd $$ ; p_paddr - dd filesize ; p_filesz - dd filesize ; p_memsz + # don't copy ehdr or phdr into the first segment. + dd 0x54 ; p_offset + # but you can't save on bytes for them, because p_align. + # messing with the ORG won't help you here. + dd 0x08048054 ; p_vaddr + dd 0x08048054 ; p_paddr + dd codesize ; p_filesz + dd codesize ; p_memsz dd 5 ; p_flags dd 0x1000 ; p_align phdrsize equ $ - phdr @@ -39,4 +42,4 @@ _start: mov eax, 1 int 0x80 -filesize equ $ - $$ +codesize equ $ - _start |