Commit 67d108e2 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Willy Tarreau

tools/nolibc: completely remove optional environ support

In commit 52e423f5 ("tools/nolibc: export environ as a weak symbol on i386")
and friends the asm startup logic was extended to directly populate the
"environ" array.

This makes it impossible for "environ" to be dropped by the linker.
Therefore also drop the other logic to handle non-present "environ".

Also add a testcase to validate the initialization of environ.
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent 4beb9be8
...@@ -83,11 +83,10 @@ void free(void *ptr) ...@@ -83,11 +83,10 @@ void free(void *ptr)
* declared as a char **, and must be terminated by a NULL (it is recommended * declared as a char **, and must be terminated by a NULL (it is recommended
* to set this variable to the "envp" argument of main()). If the requested * to set this variable to the "envp" argument of main()). If the requested
* environment variable exists its value is returned otherwise NULL is * environment variable exists its value is returned otherwise NULL is
* returned. getenv() is forcefully inlined so that the reference to "environ" * returned.
* will be dropped if unused, even at -O0.
*/ */
static __attribute__((unused)) static __attribute__((unused))
char *_getenv(const char *name, char **environ) char *getenv(const char *name)
{ {
int idx, i; int idx, i;
...@@ -102,13 +101,6 @@ char *_getenv(const char *name, char **environ) ...@@ -102,13 +101,6 @@ char *_getenv(const char *name, char **environ)
return NULL; return NULL;
} }
static __inline__ __attribute__((unused,always_inline))
char *getenv(const char *name)
{
extern char **environ;
return _getenv(name, environ);
}
static __attribute__((unused)) static __attribute__((unused))
unsigned long getauxval(unsigned long type) unsigned long getauxval(unsigned long type)
{ {
......
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
#define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2))) #define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2)))
#define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1) #define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1)
/* will be used by nolibc by getenv() */ /* will be used to test initialization of environ */
char **environ; static char **test_envp;
/* will be used by some test cases as readable file, please don't write it */ /* will be used by some test cases as readable file, please don't write it */
static const char *argv0; static const char *argv0;
...@@ -787,6 +787,7 @@ int run_stdlib(int min, int max) ...@@ -787,6 +787,7 @@ int run_stdlib(int min, int max)
* test numbers. * test numbers.
*/ */
switch (test + __LINE__ + 1) { switch (test + __LINE__ + 1) {
CASE_TEST(environ); EXPECT_PTREQ(1, environ, test_envp); break;
CASE_TEST(getenv_TERM); EXPECT_STRNZ(1, getenv("TERM")); break; CASE_TEST(getenv_TERM); EXPECT_STRNZ(1, getenv("TERM")); break;
CASE_TEST(getenv_blah); EXPECT_STRZR(1, getenv("blah")); break; CASE_TEST(getenv_blah); EXPECT_STRZR(1, getenv("blah")); break;
CASE_TEST(setcmp_blah_blah); EXPECT_EQ(1, strcmp("blah", "blah"), 0); break; CASE_TEST(setcmp_blah_blah); EXPECT_EQ(1, strcmp("blah", "blah"), 0); break;
...@@ -1120,7 +1121,7 @@ int main(int argc, char **argv, char **envp) ...@@ -1120,7 +1121,7 @@ int main(int argc, char **argv, char **envp)
char *test; char *test;
argv0 = argv[0]; argv0 = argv[0];
environ = envp; test_envp = envp;
/* when called as init, it's possible that no console was opened, for /* when called as init, it's possible that no console was opened, for
* example if no /dev file system was provided. We'll check that fd#1 * example if no /dev file system was provided. We'll check that fd#1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment