Skip to content

Commit 1cce162

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: add auxiliary vector retrieval for x86_64
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]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 2ab4aa4 commit 1cce162

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/include/nolibc/arch-x86_64.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct sys_stat_struct {
179179
})
180180

181181
char **environ __attribute__((weak));
182+
const unsigned long *_auxv __attribute__((weak));
182183

183184
/* startup code */
184185
/*
@@ -195,6 +196,12 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
195196
"lea 8(%rsi,%rdi,8),%rdx\n" // then a NULL then envp (third arg, %rdx)
196197
"mov %rdx, environ\n" // save environ
197198
"xor %ebp, %ebp\n" // zero the stack frame
199+
"mov %rdx, %rax\n" // search for auxv (follows NULL after last env)
200+
"0:\n"
201+
"add $8, %rax\n" // search for auxv using rax, it follows the
202+
"cmp -8(%rax), %rbp\n" // ... NULL after last env (rbp is zero here)
203+
"jnz 0b\n"
204+
"mov %rax, _auxv\n" // save it into _auxv
198205
"and $-16, %rsp\n" // x86 ABI : esp must be 16-byte aligned before call
199206
"call main\n" // main() returns the status code, we'll exit with it.
200207
"mov %eax, %edi\n" // retrieve exit code (32 bit)

0 commit comments

Comments
 (0)