aboutsummaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorGravatar Willy Tarreau <w@1wt.eu> 2023-01-10 08:24:22 +0100
committerGravatar Paul E. McKenney <paulmck@kernel.org> 2023-01-10 13:33:56 -0800
commit8f7fafebd1da984c427d53b614e48ebecb456824 (patch)
tree5e5e4cec52333b867f82f4b6b598d74306a5237a /tools/include
parenttools/nolibc: export environ as a weak symbol on arm (diff)
downloadlinux-8f7fafebd1da984c427d53b614e48ebecb456824.tar.gz
linux-8f7fafebd1da984c427d53b614e48ebecb456824.tar.bz2
linux-8f7fafebd1da984c427d53b614e48ebecb456824.zip
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 <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/arch-mips.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h
index a3764f6d267e..7d22f7bc38b3 100644
--- a/tools/include/nolibc/arch-mips.h
+++ b/tools/include/nolibc/arch-mips.h
@@ -176,6 +176,8 @@ struct sys_stat_struct {
_arg4 ? -_num : _num; \
})
+char **environ __attribute__((weak));
+
/* startup code, note that it's called __start on MIPS */
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
{
@@ -191,6 +193,9 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
"sll $a2, $a0, 2\n" // a2 = argc * 4
"add $a2, $a2, $a1\n" // envp = argv + 4*argc ...
"addiu $a2, $a2, 4\n" // ... + 4
+ "lui $a3, %hi(environ)\n" // load environ into a3 (hi)
+ "addiu $a3, %lo(environ)\n" // load environ into a3 (lo)
+ "sw $a2,($a3)\n" // store envp(a2) into environ
"li $t0, -8\n"
"and $sp, $sp, $t0\n" // sp must be 8-byte aligned
"addiu $sp,$sp,-16\n" // the callee expects to save a0..a3 there!