Hi, I watched your amazing stream about this project.
I noticed that if the entry point was not at the beginning of code segment (by setting entry <label>
) the current impelemention do not detect the correct beggining of Machine code. like:
format ELF64 executable 3
SYS_write = 1
SYS_exit = 60
STDOUT = 1
segment readable executable
; <-------- original entry point
; these must not be executed ,
; (but the elf.js parser must shows them in result console as first machine code bytes)
syscall
syscall
syscall
print: ; rsi=str.ptr rdx=str.size
mov rax, SYS_write
mov rdi, STDOUT
syscall
ret
exit: ; rdi=retcode
mov rax, SYS_exit
syscall
ret
entry main ; <-------- change of entry point of the program
main:
mov rsi, hello
mov rdx, hello_sz
call print
mov rdi, 0
call exit
ret ; UNREACHABLE
segment readable writable
hello: db "Hello, World!", 10
hello_sz = $-hello
now if I run the elf.js parse routine,
It doesn't show repeated syscall
bytecode and it gives me:
Ehdr.e_entry
= 4194513
Phdrs[0].p_vaddr
= 4194304
4194513-4194304 = 209
but the correct offset for beginning of the machine code must remains 64(ElfH)+2*56(ProgH)=176
I think because this project may lead to porth development, it's better to use a better way to detect start of the machine code (separate it from entry point), OR just keep in mind to not change entry point from the start of the segment to other addresses.