Use shared globals to init __progname + environ
Initialize the __progname and environ global variables using
libc_shared_globals rather than KernelArgumentBlock.
Also: suppose the linker is invoked on an executable:
linker prog [args...]
The first argument passed to main() and constructor functions is "prog"
rather than "linker". For consistency, this CL changes the BSD
__progname global from "linker" to "prog".
Bug: none
Test: bionic unit tests
Change-Id: I376d76953c9436706dbc53911ef6585c1acc1c31
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index f2168b8..51fbe07 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -96,14 +96,15 @@
BIONIC_STOP_UNWIND;
KernelArgumentBlock args(raw_args);
+ __libc_shared_globals()->init_progname = args.argv[0];
// Initializing the globals requires TLS to be available for errno.
__libc_init_main_thread(args);
__libc_init_globals(args);
- __libc_init_AT_SECURE(args);
- __libc_init_common(args);
+ __libc_init_AT_SECURE(args.envp);
+ __libc_init_common();
apply_gnu_relro();