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/tests/dl_test.cpp b/tests/dl_test.cpp
index 18ba011..57d04e9 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -104,6 +104,7 @@
std::string expected_output =
"ctor: argc=1 argv[0]=" + helper + "\n" +
"main: argc=1 argv[0]=" + helper + "\n" +
+ "__progname=" + helper + "\n" +
"helper_func called\n";
ExecTestHelper eth;
eth.SetArgs({ kPathToLinker, helper.c_str(), nullptr });
@@ -118,6 +119,7 @@
std::string expected_output =
"ctor: argc=1 argv[0]=" + helper + "\n" +
"main: argc=1 argv[0]=" + helper + "\n" +
+ "__progname=" + helper + "\n" +
"helper_func called\n";
ExecTestHelper eth;
eth.SetArgs({ kPathToLinker, helper.c_str(), nullptr });
diff --git a/tests/libs/exec_linker_helper.cpp b/tests/libs/exec_linker_helper.cpp
index 01a61e0..56b1eaf 100644
--- a/tests/libs/exec_linker_helper.cpp
+++ b/tests/libs/exec_linker_helper.cpp
@@ -28,7 +28,8 @@
#include <stdio.h>
-extern "C" void _start();
+extern "C" const char* __progname;
+
const char* helper_func();
__attribute__((constructor))
@@ -38,6 +39,7 @@
int main(int argc, char* argv[]) {
printf("main: argc=%d argv[0]=%s\n", argc, argv[0]);
+ printf("__progname=%s\n", __progname);
printf("%s\n", helper_func());
return 0;
}