PIC and arm/linux-crt0.S

Shaun Jackman sjackman@gmail.com
Mon Jun 26 16:28:00 GMT 2006


On 6/26/06, Shaun Jackman <sjackman@gmail.com> wrote:
> The manner in which arm/linux-crt0.S writes to environ is not
> compatible with PIC. So, I can either...
>
> * patch linux-crt0.S and write the PIC store operation in assembler
>         (I'm more inclined to let the compiler do this for me)
> * have _start call _main instead of main and do the write there
>         * and add _main to linux-syscalls1.c
>         * or create a new linux-crt1.c to hold _main.

I hacked up linux-crt1.c, and I prefer it over the other options. See
below for the source code. It saves me from emulating a compiler, and
handles other code generation cases I probably haven't thought of. The
downside is that it requires both a linux-crt0.S and a linux-crt1.c.
Although, with this change the primary purpose of linux-crt0.S would
be to change into thumb mode. I could do instead accomplish this task
in a couple lines of inline assembler and entirely replace
linux-crt0.S with linux-crt0.c.

Cheers,
Shaun

#include <stdlib.h>
#include <unistd.h>

int _main(int argc, char *argv[])
{
	environ = argv + argc + 1;
	exit(main(argc, argv, environ));
}



More information about the Newlib mailing list