Skip to content

Commit 52e423f

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: export environ as a weak symbol on i386
The environ is retrieved from the _start code and is easy to store at this moment. Let's declare the variable weak and store the value into it. By not being static it will be visible to all units. By being weak, if some programs already declared it, they will continue to be able to use it. This was tested both with environ inherited from _start and extracted from envp. Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 89dc509 commit 52e423f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/include/nolibc/arch-i386.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ struct sys_stat_struct {
178178
_eax; \
179179
})
180180

181+
char **environ __attribute__((weak));
182+
181183
/* startup code */
182184
/*
183185
* i386 System V ABI mandates:
@@ -191,6 +193,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
191193
"pop %eax\n" // argc (first arg, %eax)
192194
"mov %esp, %ebx\n" // argv[] (second arg, %ebx)
193195
"lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx)
196+
"mov %ecx, environ\n" // save environ
194197
"xor %ebp, %ebp\n" // zero the stack frame
195198
"and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned before
196199
"sub $4, %esp\n" // the call instruction (args are aligned)

0 commit comments

Comments
 (0)