Skip to content

Commit 8f7fafe

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: export environ as a weak symbol on mips
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 with mips24kc (BE) 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 a6f29a2 commit 8f7fafe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/include/nolibc/arch-mips.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ struct sys_stat_struct {
176176
_arg4 ? -_num : _num; \
177177
})
178178

179+
char **environ __attribute__((weak));
180+
179181
/* startup code, note that it's called __start on MIPS */
180182
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
181183
{
@@ -191,6 +193,9 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
191193
"sll $a2, $a0, 2\n" // a2 = argc * 4
192194
"add $a2, $a2, $a1\n" // envp = argv + 4*argc ...
193195
"addiu $a2, $a2, 4\n" // ... + 4
196+
"lui $a3, %hi(environ)\n" // load environ into a3 (hi)
197+
"addiu $a3, %lo(environ)\n" // load environ into a3 (lo)
198+
"sw $a2,($a3)\n" // store envp(a2) into environ
194199
"li $t0, -8\n"
195200
"and $sp, $sp, $t0\n" // sp must be 8-byte aligned
196201
"addiu $sp,$sp,-16\n" // the callee expects to save a0..a3 there!

0 commit comments

Comments
 (0)