mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 20:33:10 +00:00
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.
This commit is contained in:
parent
d719e745fb
commit
67516fa555
|
@ -31,36 +31,4 @@
|
|||
#include <sys/internals.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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__));
|
||||
|
|
Loading…
Reference in a new issue