3 ms·
Well, if you really want to confound things you could write your own __start which is typically the entry point called by the kernel, which in turn calls `main(
by gumby 3y ago
Well, if you really want to confound things you could write your own __start which is typically the entry point called by the kernel, which in turn calls `main()`.
But actually that's just by convention: C (and C++) programs drop `__start` into the binary and then tell the linker to mark the binary (mostly an ELF file these days, thank goodness) to indicate that the entry point is the symbol `__start`. There can be different versions depending on how many arguments to `main()` are requested, or it can simply pass all three and let the function body ignore the unwanted ones.
If you really want to confuse the TA, write the following program:
#include <stdio.h>
void foo();
int main() {
printf ("I'm in main\n");
foo();
printf ("I'm still in main\n");
}
void foo() {
printf ("I'm in foo!\n");
}
Then tell the linker to mark `foo` as your entry point. You could do this from the command line or even a custom linker script.
Of course depending on what your OS needs from `__start` you may have to do some extra setup, sorry. But this might work on Linux.
I've actually been thinking of modifying gcc's `__start` to pass the arguments and env vars as a span (well, the function __start calls that calls `main()`.)