Skip to content

Commit 041fa97

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: add auxiliary vector retrieval for riscv
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. It was tested on riscv64 only. Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 59ea187 commit 041fa97

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/include/nolibc/arch-riscv.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct sys_stat_struct {
171171
})
172172

173173
char **environ __attribute__((weak));
174+
const unsigned long *_auxv __attribute__((weak));
174175

175176
/* startup code */
176177
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
@@ -185,6 +186,15 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
185186
"slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ...
186187
"add a2, a2, "SZREG"\n" // + SZREG (skip null)
187188
"add a2,a2,a1\n" // + argv
189+
190+
"add a3, a2, zero\n" // iterate a3 over envp to find auxv (after NULL)
191+
"0:\n" // do {
192+
"ld a4, 0(a3)\n" // a4 = *a3;
193+
"add a3, a3, "SZREG"\n" // a3 += sizeof(void*);
194+
"bne a4, zero, 0b\n" // } while (a4);
195+
"lui a4, %hi(_auxv)\n" // a4 = &_auxv (high bits)
196+
"sd a3, %lo(_auxv)(a4)\n" // store a3 into _auxv
197+
188198
"lui a3, %hi(environ)\n" // a3 = &environ (high bits)
189199
"sd a2,%lo(environ)(a3)\n" // store envp(a2) into environ
190200
"andi sp,a1,-16\n" // sp must be 16-byte aligned

0 commit comments

Comments
 (0)