Skip to content

Commit 59ea187

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: add auxiliary vector retrieval for arm
In the _start block we now iterate over envp to find the auxiliary vector after the NULL. The pointer is saved into an _auxv variable that is marked as weak so that it's accessible from multiple units. Signed-off-by: Willy Tarreau <[email protected]> It was tested in arm, thumb1 and thumb2 modes. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 2a39a53 commit 59ea187

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/include/nolibc/arch-arm.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ struct sys_stat_struct {
197197
})
198198

199199
char **environ __attribute__((weak));
200+
const unsigned long *_auxv __attribute__((weak));
200201

201202
/* startup code */
202203
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
@@ -211,6 +212,16 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
211212
"ldr %r3, 1f\n" // r3 = &environ (see below)
212213
"str %r2, [r3]\n" // store envp into environ
213214

215+
"mov r4, r2\n" // search for auxv (follows NULL after last env)
216+
"0:\n"
217+
"mov r5, r4\n" // r5 = r4
218+
"add r4, r4, #4\n" // r4 += 4
219+
"ldr r5,[r5]\n" // r5 = *r5 = *(r4-4)
220+
"cmp r5, #0\n" // and stop at NULL after last env
221+
"bne 0b\n"
222+
"ldr %r3, 2f\n" // r3 = &_auxv (low bits)
223+
"str r4, [r3]\n" // store r4 into _auxv
224+
214225
"mov %r3, $8\n" // AAPCS : sp must be 8-byte aligned in the
215226
"neg %r3, %r3\n" // callee, and bl doesn't push (lr=pc)
216227
"and %r3, %r3, %r1\n" // so we do sp = r1(=sp) & r3(=-8);
@@ -222,6 +233,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
222233
".align 2\n" // below are the pointers to a few variables
223234
"1:\n"
224235
".word environ\n"
236+
"2:\n"
237+
".word _auxv\n"
225238
);
226239
__builtin_unreachable();
227240
}

0 commit comments

Comments
 (0)