You should use a dummy push instead (e.g. push rax), it's much smaller (1 byte vs 4) and it's entry point anyway.

I know that Linux is probably going to always give this (mis)alignment on entry point just to be compatible, but I'm just saying that libc (the library that hijacks the entry point of all C apps that use it on Linux) realigns the stack on entry point (as if it's unreliable). Paranoia? But I'd err on the side of caution and just use a "and rsp, -16".

So what is the answer? Can we, or can we not, simply use ret to return to the loader in Linux? Is it "official" or just a coincidence? Do the docs say anything on the matter? Do the docs even exist?

You can use ret, if you are going to link your object file with gcc (or another compiler). In this case gcc automatically includes precompiled startup code which calls the main function to you program.
However if you specify entry point manually (--entry=main with gcc, or entry main with fasm) you should not use ret, since at the time when program starts [rsp] contains not a return address, but argc.
The program startup process is documented in the ELF specification for x86_64.

So what is the answer? Can we, or can we not, simply use ret to return to the loader in Linux? Is it "official" or just a coincidence? Do the docs say anything on the matter? Do the docs even exist?

You use ret if your code is called from C runtime. If it is not you specify entry point,
usually _start and call sysexit.
If making standalone fasm executable sysexit is arbitrary and entry point wahtever.
You should be aware that in case of main called from C runtime rdi contains argc,rsi points to argv array. In case not, those values are on stack.

@system error: In respect to the output from gdb, that's not his code, it's the C runtime's code which calls his main, so thanks for proving my point?

Usually, when people code "main" function in asm, I don't assume them to use the C runtime (why wouldn't they use C otherwise?). Don't get me wrong, I understand people who want total control over the code in their app (obviously excluding external library calls), but linking the C runtime automatically makes your program not contain only your own code, since it pulls it, so I don't see much point in coding "main" in asm then (the app will be semi-bloated anyway; I mean if you want main in asm, minimal bloat should be a goal no? not like main is a hot path).

(btw I don't use the C runtime even in C/C++ code, just pass -nostdlib to GCC you can still use some of the standard library as normal imported dynamic libs, just not baked into your own app; some do require an "init" function call __init_libc_main tho)

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum