1 /* $NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $ */
4 * Copyright (c) 2002 Matt Fredette
5 * Copyright (c) 1999 Klaus Klein
6 * Copyright (c) 1995 Christopher G. Demetriou
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the
20 * NetBSD Project. See http://www.NetBSD.org/ for
21 * information about NetBSD.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
41 static void ___start(struct ps_strings
*,
42 void (*cleanup
)(void), const Obj_Entry
*, int)
44 __attribute__((__used__
))
53 " .type _start,@function \n"
54 " .type __start,@function \n"
57 " .import _GLOBAL_OFFSET_TABLE_ \n"
60 " depi 0, 31, 2, %r27 \n"
61 "L$lpc: addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 8), %r27 \n"
62 " ldo R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 12)(%r1),%r27 \n"
65 " copy %r27, %arg3 \n");
68 ___start(struct ps_strings
*ps_strings
,
69 void (*cleanup
)(void), /* from shared loader */
70 const Obj_Entry
*obj
, /* from shared loader */
77 argc
= ps_strings
->ps_nargvstr
;
78 argv
= ps_strings
->ps_argvstr
;
79 environ
= ps_strings
->ps_envstr
;
81 if ((__progname
= argv
[0]) != NULL
) { /* NULL ptr if argc = 0 */
82 if ((__progname
= _strrchr(__progname
, '/')) == NULL
)
88 if (ps_strings
!= (struct ps_strings
*)0)
89 __ps_strings
= ps_strings
;
92 if (&rtld_DYNAMIC
!= NULL
)
93 _rtld_setup(cleanup
, obj
);
100 monstartup((u_long
)&_eprol
, (u_long
)&_etext
);
104 * Since crt0.o, crtbegin.o, and crtend.o are always
105 * compiled PIC, they must have %r19 set correctly on
106 * entry to any function they contain. However, when
107 * a program is linked statically, the linker does
108 * not fill a PLABEL relocation with a pointer to a
109 * true PLABEL, it just fills it with the offset of the
110 * function. This shows the linker's assumption that
111 * when linking statically, *all* of the code has *not*
112 * been compiled PIC. I guess to assume otherwise
113 * would be a performance hit, as you would end up
114 * with unnecessary PLABELs for function pointers.
116 * But here, passing the address of the PIC _fini to
117 * atexit, we must make sure that we pass a PLABEL.
119 fini_plabel
[0] = (int)_fini
;
120 if (fini_plabel
[0] & 2)
121 /* _fini is already a PLABEL. */
125 atexit((void (*)(void))(((int)fini_plabel
) | 2));
129 exit(main(argc
, argv
, environ
));
133 * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
135 #if defined(LIBC_SCCS) && !defined(lint)
136 __RCSID("$NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $");
137 #endif /* LIBC_SCCS and not lint */