From 4aee2f759ab7bf2ad9534941afef0195040ba5db Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 26 Jul 2022 22:40:28 +0200 Subject: user/libc: a _start that automatically selfrelocates PIEs --- src/user/app/init/main.c | 5 +---- src/user/app/testelf/main.c | 15 +++------------ 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'src/user/app') diff --git a/src/user/app/init/main.c b/src/user/app/init/main.c index 426933f..788fd78 100644 --- a/src/user/app/init/main.c +++ b/src/user/app/init/main.c @@ -11,10 +11,7 @@ __attribute__((visibility("hidden"))) extern char _image_base[]; -__attribute__((section(".text.startup"))) int main(void) { - elf_selfreloc(); - freopen("/kdev/com1", "a+", stdout); printf("in init (stage 2), loaded at 0x%x\n", &_image_base); @@ -73,5 +70,5 @@ int main(void) { _syscall_await(); printf("init: quitting\n"); - exit(0); + return 0; } diff --git a/src/user/app/testelf/main.c b/src/user/app/testelf/main.c index 93a5e11..a3e54b8 100644 --- a/src/user/app/testelf/main.c +++ b/src/user/app/testelf/main.c @@ -1,18 +1,9 @@ -#include #include -#include -#include -#include const char *str = "Hello!\n", *str2 = "World.\n"; -__attribute__((visibility("hidden"))) -extern char _image_base[]; - int main(void) { - elf_selfreloc(); - printf("loaded at %x\n", &_image_base); - printf(str); - printf(str2); - exit(0); + printf("elftest's &main == 0x%x\n", &main); + printf("%s%s", str, str2); + return 0; } -- cgit v1.2.3