Skip to content

Commit 758f333

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: export environ as a weak symbol on riscv
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 on riscv64 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 8f7fafe commit 758f333

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/include/nolibc/arch-riscv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ struct sys_stat_struct {
170170
_arg1; \
171171
})
172172

173+
char **environ __attribute__((weak));
174+
173175
/* startup code */
174176
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
175177
{
@@ -183,6 +185,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
183185
"slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ...
184186
"add a2, a2, "SZREG"\n" // + SZREG (skip null)
185187
"add a2,a2,a1\n" // + argv
188+
"lui a3, %hi(environ)\n" // a3 = &environ (high bits)
189+
"sd a2,%lo(environ)(a3)\n" // store envp(a2) into environ
186190
"andi sp,a1,-16\n" // sp must be 16-byte aligned
187191
"call main\n" // main() returns the status code, we'll exit with it.
188192
"li a7, 93\n" // NR_exit == 93

0 commit comments

Comments
 (0)