4 ms·
any ideas for a more compact and efficient way to get argc and argv on both linux and freebsd without bringing in libc?
by ngnk 7y ago
any ideas for a more compact and efficient way to get argc and argv on both linux and freebsd without bringing in libc?
- saagarjha 7y agoPortably? No.
- duskwuff 7y agoGiven that the interpreter makes system calls directly using inline assembly [1], I suspect that any hope of portability went out the window long ago. [1]: https://bitbucket.org/ngn/k/src/b54eb5cfea5eb821fe1de68d2a8ad4b97f88e765/k.h#lines-63 https://bitbucket.org/ngn/k/src/b54eb5cfea5eb821fe1de68d2a8a...
- ngnk 7y agoacross architectures: you're right, as of now it's x86_64 only across operating systems: it works on linux and freebsd as-is (thanks bakul), and with a few changes on windows+libc (thanks ktye) - https://github.com/ktye/i/tree/master/_/ngn https://github.com/ktye/i/tree/master/_/ngn though i personally never use windows
- kick 7y agoThanks for writing/freeing this! I've had a lot of fun with it since a friend first pointed out that it had been released under a libre license.
- pja 7y agoNope :) But http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html http://dbp-consulting.com/tutorials/debugging/linuxProgramSt... does suggest zeroing the top-most frame (%ebp) and making sure the stack is 16-byte aligned might also be worth doing. (Possibly it’s already 16-byte aligned already because you jmp to main instead of calling it though?)
- ngnk 7y agothat's a good read, thanks. afaik zeroing %rbp here plays no role other than to assist debuggers. i'm not sure if alignment makes any measurable difference. if it does, it'll be worth doing. i jmp to main() because i wrote it and i know it never returns. it exit()-s.
- saagarjha 7y ago> afaik zeroing %rbp here plays no role other than to assist debuggers. Yep, it marks function frame boundaries. If you don't particularly care, you may want to consider compiling with -fomit-frame-pointer and the compiler will return this register back to the set of general purpose ones for it to use. > i'm not sure if alignment makes any measurable difference. if it does, it'll be worth doing. It will if you end up emitting any SSE instructions, because they will cause loads and stores that need to be aligned.
- 3xblah 7y agoI use _getenv in k3 a=arg1 b=arg2 k c.k