Friday, April 14, 2017

Re: programming in Assembly

On Fri, 14 Apr 2017, Kartik Agaram wrote:
> Many thanks! Yes, a static binary is perfectly fine at this time :) A
> couple of follow-up questions, if y'all would please indulge me:
>
> 1. Now that I am reminded of this handy new `readelf` tool, I go
> running it on the new static executable I just generated.
...
> Why is the file type showing up as a shared object file in spite of it
> being a statically compiled binary?

Because its a PIE binary.


> 2. I tried running the above file in a 64-bit OpenBSD, and got a couple
> of reasonable looking errors:
...
> In response I tried some ham-handed modifications, basically replacing
> the registers with 64-bit variants, and letting the assembler figure out
> operand-size suffixes.
...
> Could you please point me at why this fails?

The differences between the i386 and amd64 ABI are too large to explain
here. If you search the web for "amd64 ELF ABI" you'll find the doc that
describes how arguments are passed and how syscalls are performed. The
short version is "not on the stack, and using syscall instead of int$80"
Or look at the libc source code or disassemble libc.a and see how it does
it.


Philip Guenther

No comments:

Post a Comment