Skip to content

Commit a6f29a2

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: export environ as a weak symbol on arm
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 in arm and thumb1 and thumb2 modes, and for each mode, 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 9b8688c commit a6f29a2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/include/nolibc/arch-arm.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ struct sys_stat_struct {
196196
_arg1; \
197197
})
198198

199+
char **environ __attribute__((weak));
200+
199201
/* startup code */
200202
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
201203
{
@@ -206,6 +208,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
206208
"add %r2, %r0, $1\n" // envp = (argc + 1) ...
207209
"lsl %r2, %r2, $2\n" // * 4 ...
208210
"add %r2, %r2, %r1\n" // + argv
211+
"ldr %r3, 1f\n" // r3 = &environ (see below)
212+
"str %r2, [r3]\n" // store envp into environ
209213

210214
"mov %r3, $8\n" // AAPCS : sp must be 8-byte aligned in the
211215
"neg %r3, %r3\n" // callee, and bl doesn't push (lr=pc)
@@ -215,7 +219,10 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
215219
"bl main\n" // main() returns the status code, we'll exit with it.
216220
"movs r7, $1\n" // NR_exit == 1
217221
"svc $0x00\n"
218-
);
222+
".align 2\n" // below are the pointers to a few variables
223+
"1:\n"
224+
".word environ\n"
225+
);
219226
__builtin_unreachable();
220227
}
221228

0 commit comments

Comments
 (0)