Skip to content

Commit 9b8688c

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: export environ as a weak symbol on arm64
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 52e423f commit 9b8688c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/include/nolibc/arch-aarch64.h

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

172+
char **environ __attribute__((weak));
173+
172174
/* startup code */
173175
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
174176
{
@@ -178,6 +180,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
178180
"lsl x2, x0, 3\n" // envp (x2) = 8*argc ...
179181
"add x2, x2, 8\n" // + 8 (skip null)
180182
"add x2, x2, x1\n" // + argv
183+
"adrp x3, environ\n" // x3 = &environ (high bits)
184+
"str x2, [x3, #:lo12:environ]\n" // store envp into environ
181185
"and sp, x1, -16\n" // sp must be 16-byte aligned in the callee
182186
"bl main\n" // main() returns the status code, we'll exit with it.
183187
"mov x8, 93\n" // NR_exit == 93

0 commit comments

Comments
 (0)