aboutsummaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorGravatar Willy Tarreau <w@1wt.eu> 2023-01-10 08:24:21 +0100
committerGravatar Paul E. McKenney <paulmck@kernel.org> 2023-01-10 13:33:56 -0800
commita6f29a2c41f3d283e78e00dc8974e6efacaccf37 (patch)
tree64529de606f4d88654c0c9f28ccd147c6bab6785 /tools/include
parenttools/nolibc: export environ as a weak symbol on arm64 (diff)
downloadlinux-a6f29a2c41f3d283e78e00dc8974e6efacaccf37.tar.gz
linux-a6f29a2c41f3d283e78e00dc8974e6efacaccf37.tar.bz2
linux-a6f29a2c41f3d283e78e00dc8974e6efacaccf37.zip
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 <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/arch-arm.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h
index 48bd95492c87..79666b590e87 100644
--- a/tools/include/nolibc/arch-arm.h
+++ b/tools/include/nolibc/arch-arm.h
@@ -196,6 +196,8 @@ struct sys_stat_struct {
_arg1; \
})
+char **environ __attribute__((weak));
+
/* startup code */
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
{
@@ -206,6 +208,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
"add %r2, %r0, $1\n" // envp = (argc + 1) ...
"lsl %r2, %r2, $2\n" // * 4 ...
"add %r2, %r2, %r1\n" // + argv
+ "ldr %r3, 1f\n" // r3 = &environ (see below)
+ "str %r2, [r3]\n" // store envp into environ
"mov %r3, $8\n" // AAPCS : sp must be 8-byte aligned in the
"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)
"bl main\n" // main() returns the status code, we'll exit with it.
"movs r7, $1\n" // NR_exit == 1
"svc $0x00\n"
- );
+ ".align 2\n" // below are the pointers to a few variables
+ "1:\n"
+ ".word environ\n"
+ );
__builtin_unreachable();
}