diff options
author | dzwdz | 2022-07-26 22:40:28 +0200 |
---|---|---|
committer | dzwdz | 2022-07-26 22:40:28 +0200 |
commit | 4aee2f759ab7bf2ad9534941afef0195040ba5db (patch) | |
tree | 8799d4dac4bd82cc2274e4a8246e6891356b1511 /src | |
parent | d54dcb2efc4be344900a7721ac4b65b47840c5d2 (diff) |
user/libc: a _start that automatically selfrelocates PIEs
Diffstat (limited to 'src')
-rw-r--r-- | src/user/app/init/main.c | 5 | ||||
-rw-r--r-- | src/user/app/testelf/main.c | 15 | ||||
-rw-r--r-- | src/user/bootstrap/main.c | 4 | ||||
-rw-r--r-- | src/user/lib/crt0.c | 10 | ||||
-rw-r--r-- | src/user/linker.ld | 2 |
5 files changed, 18 insertions, 18 deletions
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 <camellia/syscalls.h> #include <stdio.h> -#include <user/lib/elf.h> -#include <user/lib/elfload.h> -#include <unistd.h> 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; } diff --git a/src/user/bootstrap/main.c b/src/user/bootstrap/main.c index fecd38f..089fd68 100644 --- a/src/user/bootstrap/main.c +++ b/src/user/bootstrap/main.c @@ -11,7 +11,7 @@ extern char _bss_end; extern char _initrd; __attribute__((section(".text.startup"))) -int main(void) { +void _start(void) { _syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT); /* move everything provided by the kernel to /kdev */ @@ -34,3 +34,5 @@ int main(void) { } _syscall_exit(1); } + +int main(void) {return 0;} // dummy, needed to link diff --git a/src/user/lib/crt0.c b/src/user/lib/crt0.c new file mode 100644 index 0000000..91bbb05 --- /dev/null +++ b/src/user/lib/crt0.c @@ -0,0 +1,10 @@ +#include "elfload.h" +#include <unistd.h> + +int main(); + +__attribute__((__weak__)) +void _start(void) { + elf_selfreloc(); + exit(main()); +} diff --git a/src/user/linker.ld b/src/user/linker.ld index fcb5fc8..e638289 100644 --- a/src/user/linker.ld +++ b/src/user/linker.ld @@ -1,4 +1,4 @@ -ENTRY(main) +ENTRY(_start) SECTIONS { |