From 67516fa555c02e1b2ca148536842855c57d34960 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 15 Apr 2021 17:03:21 +0200 Subject: [PATCH] LibC: Shared libraries shouldn't have an entry point The _start() function attempts to call main() which is a problem when trying to build a shared library with --no-undefined: $ echo > t.c $ gcc -shared -Wl,--no-undefined -o t.so t.c /usr/local/lib/gcc/i686-pc-serenity/10.2.0/../../../../i686-pc-serenity/bin/ld: /usr/lib/crt0_shared.o: in function `_start': ./Build/i686/../../Userland/Libraries/LibC/crt0_shared.cpp:56: undefined reference to `main' collect2: error: ld returned 1 exit status Also, unless explicitly requested by the user shared libraries should not have an entry point (e.g. _start) at all. --- Userland/Libraries/LibC/crt0_shared.cpp | 32 ------------------------- 1 file changed, 32 deletions(-) diff --git a/Userland/Libraries/LibC/crt0_shared.cpp b/Userland/Libraries/LibC/crt0_shared.cpp index df834b7580..8d18d67412 100644 --- a/Userland/Libraries/LibC/crt0_shared.cpp +++ b/Userland/Libraries/LibC/crt0_shared.cpp @@ -31,36 +31,4 @@ #include #include -extern "C" { - -extern u32 __stack_chk_guard; - -int main(int, char**, char**); - -extern void __libc_init(); -extern void _init(); -extern char** environ; -extern bool __environ_is_malloced; - -int _start(int argc, char** argv, char** env); -int _start(int argc, char** argv, char** env) -{ - u32 original_stack_chk = __stack_chk_guard; - arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard)); - - if (__stack_chk_guard == 0) - __stack_chk_guard = original_stack_chk; - - _init(); - - int status = main(argc, argv, env); - - // Restore the stack guard to the value we entered _start with, - // so we don't trigger the stack canary check on the way out. - __stack_chk_guard = original_stack_chk; - - return status; -} -} - void* __dso_handle __attribute__((__weak__));