flat assembler
Message board for the users of flat assembler.

Index > Linux > argc, argv, argp in AMD64

Author
Thread Post new topic Reply to topic
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 07 Jun 2006, 03:33
Hi Guys,

Just a really quick question. If I link my code to glibc and execute the application, argc, argv, and argp are placed in rdi, rsi and rdx respectively at the start of main, as per the AMD64 SYS V ABI spec.

However if I assemble my application directly to ELF executable, rdi, rsi and rdx are all blank. So where are agrc, argv and argp pointers, when I assemble to my app as a ELF executable, that is what are the register/stack contents when the Linux kernel passes control to my app?

PS. Already googled, but all I get are for 32bit apps, and not x86_64 apps.
PPS. Kernel v2.6.11.7 (stock from kernel.org). Looking through the kernel source hasn't been fruitful either.
Post 07 Jun 2006, 03:33
View user's profile Send private message Visit poster's website Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 514
Location: Czech republic, Slovak republic
Feryno 07 Jun 2006, 07:32
yes, that's right
if you try to load ELF64 under debugger, you can find how and why
in ELF64 created directly by FASM you get args in the stack
dword [rsp]=argc
qword [rsp+8]=pointer to arg0
...
qword [rsp+8 + argc*8]=0 end of args
qword [rsp+8 + argc*8 + 8]=pointer to first string of environment
...
qword [...]=0 end of envirnment

in ELF64 created by linker there are routines for loading libs before main, so
routines read args from stack and prepare them into regs
don't try to step this init routines, you'll waste a lot ot the time until you go to your main asm code

try fdbg from Projects and Ideas section of the forum
I'm working on it, next release with fully functionality will come in few days (I hope until this weekend, I'm finishig the last thing - hardware breakpoints, which is the most belowed debugger feature for me...)
updates on my home page are more frequent than here in the forum, a newer version of fdbg for Linux 64-bit AMD64 is there from 2006 june 05 (hasn't hw bp)

I wasted a lot of time with gdb with ugly asm syntax for uncover problems like your and then I decided to write more FASM-friendly debugger

quick debug trick to bypass init lib routines in case of linking with libc:
put db 0cch at the begin of your asm code
recompile
load under debugger
run
program stops in your main asm code
Post 07 Jun 2006, 07:32
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 09 Jun 2006, 01:19
Hi Feryno,

Thanks for the info, exactly what I was after.
Post 09 Jun 2006, 01:19
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.