Skip to content

Commit

Permalink
ldso: remove deprecated support for legacy 'main'
Browse files Browse the repository at this point in the history
Besides the removal of the legacy 'main' support, this patch simplifies
the lib/startup/_main.cc.

Issue #2199
  • Loading branch information
nfeske committed Jul 14, 2023
1 parent 1d82a04 commit e2836bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 110 deletions.
3 changes: 0 additions & 3 deletions repos/base/lib/symbols/ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion repos/base/src/ld/genode_dyn.dl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
_dtors_end;
_ZN9Component9constructERN6Genode3EnvE;
_ZN9Component10stack_sizeEv;
main;
};
7 changes: 3 additions & 4 deletions repos/base/src/ld/genode_dyn.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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.*)
Expand Down
35 changes: 0 additions & 35 deletions repos/base/src/lib/ldso/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();
}
Expand Down
89 changes: 22 additions & 67 deletions repos/base/src/lib/startup/_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand All @@ -42,38 +38,15 @@ void init_rtld()
init_cxx_guard();
}

void * __dso_handle = 0;


/**
* Lower bound of the stack, solely used for sanity checking
*/
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
*
Expand All @@ -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;

/*
Expand All @@ -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 {

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

0 comments on commit e2836bf

Please sign in to comment.