From e2836bf68a009906a2468ea03c58109dda9336a0 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 28 Jun 2023 14:27:34 +0200 Subject: [PATCH] ldso: remove deprecated support for legacy 'main' Besides the removal of the legacy 'main' support, this patch simplifies the lib/startup/_main.cc. Issue #2199 --- repos/base/lib/symbols/ld | 3 - repos/base/src/ld/genode_dyn.dl | 1 - repos/base/src/ld/genode_dyn.ld | 7 +-- repos/base/src/lib/ldso/main.cc | 35 ------------ repos/base/src/lib/startup/_main.cc | 89 +++++++---------------------- 5 files changed, 25 insertions(+), 110 deletions(-) diff --git a/repos/base/lib/symbols/ld b/repos/base/lib/symbols/ld index d19a069fb0..f631e15e73 100644 --- a/repos/base/lib/symbols/ld +++ b/repos/base/lib/symbols/ld @@ -400,9 +400,6 @@ _ZnwjPN6Genode9AllocatorE T _ZnwjRN6Genode9AllocatorE T _ZnwmPN6Genode9AllocatorE T _ZnwmRN6Genode9AllocatorE T -genode_argc D 4 -genode_argv D 8 -genode_envp B 8 lx_environ B 8 memcpy W memmove W diff --git a/repos/base/src/ld/genode_dyn.dl b/repos/base/src/ld/genode_dyn.dl index c063c5617d..9f5149bc20 100644 --- a/repos/base/src/ld/genode_dyn.dl +++ b/repos/base/src/ld/genode_dyn.dl @@ -15,5 +15,4 @@ _dtors_end; _ZN9Component9constructERN6Genode3EnvE; _ZN9Component10stack_sizeEv; - main; }; diff --git a/repos/base/src/ld/genode_dyn.ld b/repos/base/src/ld/genode_dyn.ld index a3a77fef1a..ce35f023c1 100644 --- a/repos/base/src/ld/genode_dyn.ld +++ b/repos/base/src/ld/genode_dyn.ld @@ -34,16 +34,15 @@ SECTIONS /* * The ELF entry point is unused for dynamically linked components. The - * dynamic linker determined the entry point by looking up the symbol of - * the 'Component::construct' function or - if it does not exist - the - * 'main' function (for legacy components). + * dynamic linker determines the entry point by looking up the symbol of + * the 'Component::construct' function. * * \deprecated The support for legacy main functions will be removed. * * The 'KEEP' directive prevents text that is reachable from one of the * possible entry points from being garbage collected. */ - KEEP(*(.text._ZN9Component9constructERN6Genode3EnvE .text.main)) + KEEP(*(.text._ZN9Component9constructERN6Genode3EnvE)) *(.text .stub .text.* .gnu.linkonce.t.*) diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index 688c696212..bb73543d1a 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -337,18 +337,6 @@ Linker::Ld &Linker::Ld::linker() } -/* - * Defined in the startup library, passed to legacy main functions. - */ -extern char **genode_argv; -extern int genode_argc; -extern char **genode_envp; - -static int exit_status; - -static void exit_on_suspended() { genode_exit(exit_status); } - - /** * The dynamic binary to load */ @@ -452,29 +440,6 @@ struct Linker::Binary : private Root_object, public Elf_object return; } - /* - * The 'Component::construct' function is missing. This may be the - * case for legacy components that still implement a 'main' function. - * - * \deprecated the handling of legacy 'main' functions will be removed - */ - if (Elf::Addr addr = lookup_symbol("main")) { - warning("using legacy main function, please convert to 'Component::construct'"); - - /* execute static constructors before calling legacy 'main' */ - finish_static_construction(); - - exit_status = ((int (*)(int, char **, char **))addr)(genode_argc, - genode_argv, - genode_envp); - - /* trigger suspend in the entry point */ - env.ep().schedule_suspend(exit_on_suspended, nullptr); - - /* return to entrypoint and exit via exit_on_suspended() */ - return; - } - error("dynamic linker: component-entrypoint lookup failed"); throw Fatal(); } diff --git a/repos/base/src/lib/startup/_main.cc b/repos/base/src/lib/startup/_main.cc index d8724f1192..02880138ef 100644 --- a/repos/base/src/lib/startup/_main.cc +++ b/repos/base/src/lib/startup/_main.cc @@ -14,9 +14,7 @@ */ /* Genode includes */ -#include #include -#include /* platform-specific local helper functions */ #include @@ -29,8 +27,6 @@ addr_t init_main_thread_result; static Platform *platform_ptr; -enum { MAIN_THREAD_STACK_SIZE = 16*1024 }; - /** * Satisfy crt0.s in static programs, LDSO overrides this symbol @@ -42,6 +38,8 @@ void init_rtld() init_cxx_guard(); } +void * __dso_handle = 0; + /** * Lower bound of the stack, solely used for sanity checking @@ -49,31 +47,6 @@ void init_rtld() extern unsigned char __initial_stack_base[]; -/** - * The first thread in a program - */ -struct Main_thread : Thread -{ - Main_thread() - : - Thread(Weight::DEFAULT_WEIGHT, "main", MAIN_THREAD_STACK_SIZE, Type::MAIN) - { } - - /********************** - ** Thread interface ** - **********************/ - - void entry() override { } -}; - - -Main_thread * main_thread() -{ - static Main_thread s { }; - return &s; -} - - /** * Create a thread object for the main thread * @@ -90,14 +63,28 @@ extern "C" void init_main_thread() platform_ptr = &init_platform(); - /* create a thread object for the main thread */ - main_thread(); + /* + * Create a 'Thread' object for the main thread + */ + static constexpr size_t STACK_SIZE = 16*1024; - /** + struct Main_thread : Thread + { + Main_thread() + : + Thread(Weight::DEFAULT_WEIGHT, "main", STACK_SIZE, Type::MAIN) + { } + + void entry() override { /* never executed */ } + }; + + static Main_thread main_thread { }; + + /* * The new stack pointer enables the caller to switch from its current * environment to the those that the thread object provides. */ - addr_t const sp = reinterpret_cast(main_thread()->stack_top()); + addr_t const sp = reinterpret_cast(main_thread.stack_top()); init_main_thread_result = sp; /* @@ -117,26 +104,6 @@ extern "C" void init_main_thread() } } -void * __dso_handle = 0; - - -/** - * Dummy default arguments for main function - */ -static char argv0[] = { '_', 'm', 'a', 'i', 'n', 0}; -static char *argv[1] = { argv0 }; - - -/** - * Arguments for main function - * - * These global variables may be initialized by a constructor provided by an - * external library. - */ -char **genode_argv = argv; -int genode_argc = 1; -char **genode_envp = 0; - namespace Genode { @@ -157,22 +124,10 @@ namespace Genode { } -extern "C" int _main() +extern "C" int _main() /* executed with the stack within the stack area */ { - Genode::bootstrap_component(*platform_ptr); + bootstrap_component(*platform_ptr); /* never reached */ return 0; } - - -extern int main(int argc, char **argv, char **envp); - - -void Component::construct(Genode::Env &env) __attribute__((weak)); -void Component::construct(Genode::Env &) -{ - /* call real main function */ - main(genode_argc, genode_argv, genode_envp); -} -