void __start(int argc, char **argv, char **envp, void (*cleanup)(void), /* from shared loader */ const Obj_Entry *obj, /* from shared loader */ struct ps_strings *ps_strings) { environ = envp; if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(__progname, '/')) == NULL) __progname = argv[0]; else __progname++; } if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; #ifdef DYNAMIC if (&_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); #endif atexit(_fini); _init(); exit(main(argc, argv, environ)); }
void _start(int argc, char **argv, char **envp, const Obj_Entry *obj, /* from shared loader */ void (*cleanup)(void), /* from shared loader */ struct ps_strings *ps_strings) /* NetBSD extension */ { char *namep; /* * Initialize the Small Data Area registers. * _SDA_BASE is defined in the SVR4 ABI for PPC. * * Do the initialization in a PIC manner. */ __asm( "bcl 20,31,1f;" "1: mflr 11;" "addis 13,11,rtld_SDA_BASE_-1b@ha;" "addi 13,13,rtld_SDA_BASE_-1b@l;" ::: "lr" ); if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(namep, '/')) == NULL) __progname = namep; else __progname++; } environ = envp; if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; #ifdef DYNAMIC if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif _libc_init(); #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); #endif atexit(_fini); _init(); exit(main(argc, argv, environ)); }
void _start(int argc, char **argv, char **envp, const Obj_Entry *obj, /* from shared loader */ void (*cleanup)(void), /* from shared loader */ struct ps_strings *ps_strings) /* NetBSD extension */ { char *namep; /* * Initialize the Small Data Area registers. * _SDA_BASE is defined in the SVR4 ABI for PPC. * _SDA2_BASE is defined in the E[mbedded] ABI for PPC. */ __asm( "lis %r13,_SDA_BASE_@ha;" "addi %r13,%r13,_SDA_BASE_@l;" "lis %r2,_SDA2_BASE_@ha;" "addi %r2,%r2,_SDA2_BASE_@l" ); if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(namep, '/')) == NULL) __progname = namep; else __progname++; } environ = envp; if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; #ifdef DYNAMIC if (&_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); #endif atexit(_fini); _init(); exit(main(argc, argv, environ)); }
void ___start(char **sp, void (*cleanup)(void), /* from shared loader */ const Obj_Entry *obj, /* from shared loader */ struct ps_strings *ps_strings) { long argc; char **argv, *namep; argc = *(long *)sp; argv = sp + 1; environ = sp + 2 + argc; /* 2: argc + NULL ending argv */ if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(namep, '/')) == NULL) __progname = namep; else __progname++; } if (ps_strings != (struct ps_strings *)0 && ps_strings != (struct ps_strings *)0xbabefacedeadbeef) __ps_strings = ps_strings; #ifdef DYNAMIC if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif _libc_init(); #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); #endif atexit(_fini); _init(); exit(main(argc, argv, environ)); }
static void ___start(struct ps_strings *ps_strings, void (*cleanup)(void), /* from shared loader */ const Obj_Entry *obj, /* from shared loader */ int dp) { int argc; char **argv; int fini_plabel[2]; argc = ps_strings->ps_nargvstr; argv = ps_strings->ps_argvstr; environ = ps_strings->ps_envstr; if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(__progname, '/')) == NULL) __progname = argv[0]; else __progname++; } if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; #ifdef DYNAMIC /* * XXX fredette - when not compiling PIC, you currently * can't detect an undefined weak symbol by seeing if * its address is NULL. The compiler emits code to find * _DYNAMIC relative to %dp, the assembler notes the * needed relocations, but when the linker sees that the * (weak) symbol isn't defined it drops the ball - the * relocations are never filled, and the binary ends up * with code that sees an address of %dp plus zero, * which != NULL. * * Arguably the linker could/should distinguish between * code that is after a weak undefined symbol's contents * from code that is after its address. In the first case, * it would warn and/or bail. In the second case, it * would fix up instructions to give a symbol address * of NULL. * * For now, we take the easy way out and compare &_DYNAMIC * to %dp, as well as to NULL. */ if (&_DYNAMIC != NULL && (int)&_DYNAMIC != dp) _rtld_setup(cleanup, obj); #endif #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); #endif /* * Since crt0.o, crtbegin.o, and crtend.o are always * compiled PIC, they must have %r19 set correctly on * entry to any function they contain. However, when * a program is linked statically, the linker does * not fill a PLABEL relocation with a pointer to a * true PLABEL, it just fills it with the offset of the * function. This shows the linker's assumption that * when linking statically, *all* of the code has *not* * been compiled PIC. I guess to assume otherwise * would be a performance hit, as you would end up * with unnecessary PLABELs for function pointers. * * But here, passing the address of the PIC _fini to * atexit, we must make sure that we pass a PLABEL. */ fini_plabel[0] = (int)_fini; if (fini_plabel[0] & 2) /* _fini is already a PLABEL. */ atexit(_fini); else { fini_plabel[1] = dp; atexit((void (*)(void))(((int)fini_plabel) | 2)); } _init(); exit(main(argc, argv, environ)); }