svn commit: r245133 - in head/lib/csu: amd64 arm common i386-elf mips powerpc powerpc64 sparc64
Konstantin Belousov
kib at FreeBSD.org
Mon Jan 7 17:58:30 UTC 2013
Author: kib
Date: Mon Jan 7 17:58:27 2013
New Revision: 245133
URL: http://svnweb.freebsd.org/changeset/base/245133
Log:
Only assign the environ in the startup code when environ is NULL.
Preloaded library could have changed the environment, and
unconditional assingment to the environ undoes the customization.
The binaries needs to be recompiled to get the fix.
Move the common code to set up environ and __progname into the helper.
Note that ia64 possibly not fixed, due to it still using old csu.
Reported and tested by: John Hein <jhein at symmetricom.com>
Reviewed by: kan, scf
Approved by: secteam (simon)
MFC after: 2 weeks
Modified:
head/lib/csu/amd64/crt1.c
head/lib/csu/arm/crt1.c
head/lib/csu/common/ignore_init.c
head/lib/csu/i386-elf/crt1_c.c
head/lib/csu/mips/crt1.c
head/lib/csu/powerpc/crt1.c
head/lib/csu/powerpc64/crt1.c
head/lib/csu/sparc64/crt1.c
Modified: head/lib/csu/amd64/crt1.c
==============================================================================
--- head/lib/csu/amd64/crt1.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/amd64/crt1.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -61,9 +61,7 @@ _start(char **ap, void (*cleanup)(void))
argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
Modified: head/lib/csu/arm/crt1.c
==============================================================================
--- head/lib/csu/arm/crt1.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/arm/crt1.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -98,10 +98,7 @@ __start(int argc, char **argv, char **en
const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void))
{
- environ = env;
-
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
Modified: head/lib/csu/common/ignore_init.c
==============================================================================
--- head/lib/csu/common/ignore_init.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/common/ignore_init.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -87,14 +87,18 @@ handle_static_init(int argc, char **argv
}
static inline void
-handle_progname(const char *v)
+handle_argv(int argc, char *argv[], char **env)
{
const char *s;
- __progname = v;
- for (s = __progname; *s != '\0'; s++) {
- if (*s == '/')
- __progname = s + 1;
+ if (environ == NULL)
+ environ = env;
+ if (argc > 0 && argv[0] != NULL) {
+ __progname = argv[0];
+ for (s = __progname; *s != '\0'; s++) {
+ if (*s == '/')
+ __progname = s + 1;
+ }
}
}
Modified: head/lib/csu/i386-elf/crt1_c.c
==============================================================================
--- head/lib/csu/i386-elf/crt1_c.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/i386-elf/crt1_c.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -61,10 +61,7 @@ _start1(fptr cleanup, int argc, char *ar
char **env;
env = argv + argc + 1;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
-
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
else
Modified: head/lib/csu/mips/crt1.c
==============================================================================
--- head/lib/csu/mips/crt1.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/mips/crt1.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -71,9 +71,7 @@ __start(char **ap,
argc = * (long *) ap;
argv = ap + 1;
env = ap + 2 + argc;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
Modified: head/lib/csu/powerpc/crt1.c
==============================================================================
--- head/lib/csu/powerpc/crt1.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/powerpc/crt1.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -81,10 +81,8 @@ _start(int argc, char **argv, char **env
struct ps_strings *ps_strings)
{
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
Modified: head/lib/csu/powerpc64/crt1.c
==============================================================================
--- head/lib/csu/powerpc64/crt1.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/powerpc64/crt1.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -81,10 +81,7 @@ _start(int argc, char **argv, char **env
struct ps_strings *ps_strings)
{
- environ = env;
-
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
Modified: head/lib/csu/sparc64/crt1.c
==============================================================================
--- head/lib/csu/sparc64/crt1.c Mon Jan 7 16:38:13 2013 (r245132)
+++ head/lib/csu/sparc64/crt1.c Mon Jan 7 17:58:27 2013 (r245133)
@@ -85,9 +85,7 @@ _start(char **ap, void (*cleanup)(void),
argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
More information about the svn-src-head
mailing list