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
This commit is contained in:
Norman Feske 2023-06-28 14:27:34 +02:00
parent 1d82a049bf
commit e2836bf68a
5 changed files with 25 additions and 110 deletions

View File

@ -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

View File

@ -15,5 +15,4 @@
_dtors_end;
_ZN9Component9constructERN6Genode3EnvE;
_ZN9Component10stack_sizeEv;
main;
};

View File

@ -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.*)

View File

@ -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();
}

View File

@ -14,9 +14,7 @@
*/
/* Genode includes */
#include <base/sleep.h>
#include <base/thread.h>
#include <base/component.h>
/* platform-specific local helper functions */
#include <base/internal/globals.h>
@ -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<addr_t>(main_thread()->stack_top());
addr_t const sp = reinterpret_cast<addr_t>(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);
}