summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2023-01-10 10:24:18 +0300
committerPaul E. McKenney <paulmck@kernel.org>2023-01-11 00:33:55 +0300
commit89dc50921c87e2b4a4612188c5a90abebc02b60d (patch)
tree92fe6711c90ecabb92af71257cca251fbc3b688a /tools/include
parent1caa1154c3e9ad071a07c02431a700ff5df94392 (diff)
downloadlinux-89dc50921c87e2b4a4612188c5a90abebc02b60d.tar.xz
tools/nolibc: export environ as a weak symbol on x86_64
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 <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/arch-x86_64.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h
index 8d482505c347..683702a16a61 100644
--- a/tools/include/nolibc/arch-x86_64.h
+++ b/tools/include/nolibc/arch-x86_64.h
@@ -178,6 +178,8 @@ struct sys_stat_struct {
_ret; \
})
+char **environ __attribute__((weak));
+
/* startup code */
/*
* x86-64 System V ABI mandates:
@@ -191,6 +193,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
"pop %rdi\n" // argc (first arg, %rdi)
"mov %rsp, %rsi\n" // argv[] (second arg, %rsi)
"lea 8(%rsi,%rdi,8),%rdx\n" // then a NULL then envp (third arg, %rdx)
+ "mov %rdx, environ\n" // save environ
"xor %ebp, %ebp\n" // zero the stack frame
"and $-16, %rsp\n" // x86 ABI : esp must be 16-byte aligned before call
"call main\n" // main() returns the status code, we'll exit with it.