-
-
Notifications
You must be signed in to change notification settings - Fork 698
More reliable $prog.ape #1071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More reliable $prog.ape #1071
Conversation
Now it doesn't matter what argv `$prog.ape` is invoked with. We just get our executable path the apple way. https://github.com/opensource-apple/dyld/blob/master/src/dyld.cpp#L4789
This is good enough, and better than argv[0] in most cases.
Unlike loader.c, we need AccessCommand to handle the `.ape` indirection. So FindCommand stays.
I want to rework AccessCommand a bit now that we no longer need to path search in the indirect case. |
No longer need to do a path search in the indirect case, nor check for the .ape file's presence.
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I forgot about Apple's auxv string array. Is there anything else good we can pilfer from there?
Here's what it gives us. Nothing looks immediately useful to me. % cc apple.c -o apple
% cat apple.c
#include <stdio.h>
int main(int argc, char *argv[], char *envp[])
{
char **p;
for (p = envp; *p; ++p) {
}
for (++p; *p; ++p) {
printf("%s\n", *p);
}
return 0;
}
% ./apple
executable_path=./apple
ptr_munge=
main_stack=
executable_file=0x1a0100000d,0x1689fd4
dyld_file=0x1a0100000d,0xfffffff0009a8fa
executable_cdhash=1360c6329d477bc5198ee5997a4f5f5ae8166f9e
executable_boothash=b110e39ca11baa63bdb1da60bdc0c2cc15731989
arm64e_abi=os
th_port= |
Notably though, we should grab |
Here's the actual Apple exec code that creates the auxv string array. The The BTW, Apple's loader source is here, which I found interesting. The link shows the loader code lines which disallow static binaries on M1, obviating the need for two Apple loaders in Cosmopolitan. Note that development and debug kernels allow M1 static binaries! |
Now it doesn't matter what argv
$prog.ape
is invoked with. We just get our executable path the apple way.https://github.com/opensource-apple/dyld/blob/master/src/dyld.cpp#L4789
PR also includes passing
AT_FLAGS
from the M1 loader, which lets theGetProgramExecutableName
tests always detect whetherargv[0]
should be tested fromauxv
.Also changes
literally
to matchloader.c
in behavior.