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/linker/linker_main.cpp b/linker/linker_main.cpp
index 442ecd9..7edfd54 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -290,7 +290,7 @@
#endif
// Sanitize the environment.
- __libc_init_AT_SECURE(args);
+ __libc_init_AT_SECURE(args.envp);
// Initialize system properties
__system_properties_init(); // may use 'environ'
@@ -655,6 +655,7 @@
g_argc = args.argc - __libc_shared_globals()->initial_linker_arg_count;
g_argv = args.argv + __libc_shared_globals()->initial_linker_arg_count;
g_envp = args.envp;
+ __libc_shared_globals()->init_progname = g_argv[0];
// Initialize static variables. Note that in order to
// get correct libdl_info we need to call constructors