cosmopolitan/test/libc
Jōshin ed8fadea37
Keep argv[0], add COSMOPOLITAN_PROGRAM_EXECUTABLE (#980)
* Introduce env.com

Handy tool for debugging environment issues.

* Inject path as COSMOPOLITAN_PROGRAM_EXECUTABLE

`argv[0]` was previously being used as a communication channel between
the loader and the binary, giving the binary its full path for use e.g.
in `GetProgramExecutableName`. But `argv[0]` is not a good channel for
this; much of what made 2a3813c6 so gross is due to that.

This change fixes the issue by preserving `argv[0]` and establishing a
new communication channel: `COSMOPOLITAN_PROGRAM_EXECUTABLE`.

The M1 loader will always set this as the first variable. Linux should
soon follow. On the other side, `GetProgramExecutableName` checks that
variable first. If it sees it, it trusts it as-is.

A lot of the churn in `ape/ape-m1.c` in this change is actually backing
out hacks introduced in 2a3813c6; the best comparison is:

    git diff 2a3813c6^..
2023-12-04 12:45:46 -08:00
..
calls Keep argv[0], add COSMOPOLITAN_PROGRAM_EXECUTABLE (#980) 2023-12-04 12:45:46 -08:00
dns Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
fmt Reduce header complexity 2023-11-28 14:39:42 -08:00
intrin Make memcmp() and memchr() go fast again 2023-11-29 05:17:21 -08:00
log Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
mem Reduce header complexity 2023-11-28 14:39:42 -08:00
nexgen32e Reduce header complexity 2023-11-28 14:39:42 -08:00
proc Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
release Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
runtime Reduce header complexity 2023-11-28 14:39:42 -08:00
sock Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
stdio Reduce header complexity 2023-11-28 14:39:42 -08:00
str Reduce header complexity 2023-11-28 14:39:42 -08:00
thread Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
time Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
tinymath Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
x Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00
xed Reduce header complexity 2023-11-28 14:39:42 -08:00
BUILD.mk Rename makefiles BUILD.mk 2023-11-28 11:21:08 -08:00