| author | |
| committer | |
| log | 1c342ca7c38d396bc38235af25058543c86c5bed |
| tree | aa27247ae0bbf72ece08de1be3a93649f43bbf45 |
| parent | 35f81211941548b7f1c2b25a1ead0acfb69b3ab5 |
| signature |
* sysident_assym.h was manually expanded.
* The ELF_NOTE_MARCH_DESC and ELF_NOTE_MARCH_DESCSZ macros will be defined
by the compiler.
* Legacy .init/.fini stuff was removed.
* GCJ nonsense was removed.14 files changed, 1108 insertions(+), 0 deletions(-)
lib/libc/netbsd/lib/csu/arch/aarch64/crt0.S created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | /*	$NetBSD: crt0.S,v 1.2 2018/11/26 17:37:44 joerg Exp $	*/ | ||
| 2 | |||
| 3 | /*- | ||
| 4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | * by Matt Thomas of 3am Software Foundry. | ||
| 9 | * | ||
| 10 | * Redistribution and use in source and binary forms, with or without | ||
| 11 | * modification, are permitted provided that the following conditions | ||
| 12 | * are met: | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in the | ||
| 17 | * documentation and/or other materials provided with the distribution. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <aarch64/asm.h> | ||
| 33 | |||
| 34 | RCSID("$NetBSD: crt0.S,v 1.2 2018/11/26 17:37:44 joerg Exp $") | ||
| 35 | |||
| 36 | STRONG_ALIAS(_start,__start) | ||
| 37 | |||
| 38 | _ENTRY(__start) | ||
| 39 | 	/* | ||
| 40 | 	 * void ___start(void (*cleanup)(void), | ||
| 41 | 	 * struct ps_strings *ps_strings); | ||
| 42 | 	 */ | ||
| 43 | 	mov	x1, x2 | ||
| 44 | 	b	___start | ||
| 45 | END(__start) | ||
lib/libc/netbsd/lib/csu/arch/earm/crt0.S created+61| ... | @@ -0,0 +1,61 @@ | ||
| 1 | /*	$NetBSD: crt0.S,v 1.4 2018/11/26 17:37:44 joerg Exp $	*/ | ||
| 2 | |||
| 3 | /*- | ||
| 4 | * Copyright (c) 2012 The NetBSD Foundation, Inc. | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | * by Matt Thomas of 3am Software Foundry. | ||
| 9 | * | ||
| 10 | * Redistribution and use in source and binary forms, with or without | ||
| 11 | * modification, are permitted provided that the following conditions | ||
| 12 | * are met: | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in the | ||
| 17 | * documentation and/or other materials provided with the distribution. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <arm/asm.h> | ||
| 33 | |||
| 34 | RCSID("$NetBSD: crt0.S,v 1.4 2018/11/26 17:37:44 joerg Exp $") | ||
| 35 | |||
| 36 | STRONG_ALIAS(_start,__start) | ||
| 37 | |||
| 38 | _ENTRY(__start) | ||
| 39 | 	/* | ||
| 40 | 	 * ps_strings is passed in r0 and cleanup in r2. | ||
| 41 | 	 * It should be ps_string in r1 and cleanup in r0. | ||
| 42 | 	 */ | ||
| 43 | 	mov	r1, r0 | ||
| 44 | 	mov	r0, r2 | ||
| 45 | |||
| 46 | 	/* Ensure the stack is properly aligned before calling C code. */ | ||
| 47 | #if !defined(__thumb__) | ||
| 48 | 	bic	sp, sp, #7 | ||
| 49 | #else | ||
| 50 | 	movs	r6, #7 | ||
| 51 | 	mov	r7, sp | ||
| 52 | 	bics	r7, r7, r6 | ||
| 53 | 	mov	sp, r7 | ||
| 54 | #endif | ||
| 55 | |||
| 56 | 	/* | ||
| 57 | 	 * void ___start(void (*cleanup)(void), | ||
| 58 | 	 * struct ps_strings *ps_strings); | ||
| 59 | 	 */ | ||
| 60 | |||
| 61 | 	b	___start | ||
lib/libc/netbsd/lib/csu/arch/i386/crt0.S created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | /* $NetBSD: crt0.S,v 1.4 2018/11/26 17:37:45 joerg Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Christos Zoulas | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <machine/asm.h> | ||
| 39 | |||
| 40 | RCSID("$NetBSD: crt0.S,v 1.4 2018/11/26 17:37:45 joerg Exp $") | ||
| 41 | |||
| 42 | 	.hidden ___start | ||
| 43 | |||
| 44 | STRONG_ALIAS(_start,__start) | ||
| 45 | _ENTRY(__start) | ||
| 46 | 	pushl	%ebx | ||
| 47 | 	pushl	%edx | ||
| 48 | 	call	___start | ||
lib/libc/netbsd/lib/csu/arch/m68k/crt0.S created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #include <machine/asm.h> | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1999 Klaus Klein | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | RCSID("$NetBSD: crt0.S,v 1.5 2018/11/26 17:37:45 joerg Exp $") | ||
| 39 | |||
| 40 | STRONG_ALIAS(_start,__start) | ||
| 41 | |||
| 42 | _ENTRY(__start) | ||
| 43 | 	movl	%a2,-(%sp)		| ps_strings | ||
| 44 | 	movl	%a1,-(%sp)		| cleanup | ||
| 45 | 	| call: ___start(cleanup, ps_strings) | ||
| 46 | 	jbsr	___start | ||
| 47 | END(__start) | ||
lib/libc/netbsd/lib/csu/arch/mips/crt0.S created+59| ... | @@ -0,0 +1,59 @@ | ||
| 1 | /* $NetBSD: crt0.S,v 1.4 2018/11/26 17:37:45 joerg Exp $ */ | ||
| 2 | |||
| 3 | /*- | ||
| 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | * by Matt Thomas of 3am Software Foundry. | ||
| 9 | * | ||
| 10 | * Redistribution and use in source and binary forms, with or without | ||
| 11 | * modification, are permitted provided that the following conditions | ||
| 12 | * are met: | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in the | ||
| 17 | * documentation and/or other materials provided with the distribution. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <mips/asm.h> | ||
| 33 | |||
| 34 | RCSID("$NetBSD: crt0.S,v 1.4 2018/11/26 17:37:45 joerg Exp $") | ||
| 35 | |||
| 36 | STRONG_ALIAS(_start,__start) | ||
| 37 | |||
| 38 | /* | ||
| 39 | *	Assumes kernel (or ld_elf.so) passes the following parameters to | ||
| 40 | *	user-space in registers: | ||
| 41 | * | ||
| 42 | *	a0 stack pointer (0 if setregs didn't fill this in) | ||
| 43 | *	a1 cleanup | ||
| 44 | *	a2 Obj_Entry | ||
| 45 | *	a3 ps_strings | ||
| 46 | * | ||
| 47 | * XXX Does this violate the ABI? | ||
| 48 | * as well as the usual registers (pc, sp, and t9 == pc for ABI). | ||
| 49 | */ | ||
| 50 | |||
| 51 | NESTED_NOPROFILE(__start, CALLFRAME_SIZ, ra) | ||
| 52 | 	SETUP_GP | ||
| 53 | 	SETUP_GP64(t3, __start) | ||
| 54 | 	move	a0, a1		/* cleanup */ | ||
| 55 | 	PTR_L	t9,%call16(_C_LABEL(___start))(gp) | ||
| 56 | 	 move	a1, a3		/* ps_strings */ | ||
| 57 | 	.reloc 1f,R_MIPS_JALR,___start | ||
| 58 | 1:	jr	t9 | ||
| 59 | END(__start) | ||
lib/libc/netbsd/lib/csu/arch/powerpc/crt0.S created+56| ... | @@ -0,0 +1,56 @@ | ||
| 1 | /*- | ||
| 2 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 6 | * by Matt Thomas of 3am Software Foundry. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include <powerpc/asm.h> | ||
| 31 | |||
| 32 | RCSID("$NetBSD: crt0.S,v 1.7 2018/11/26 17:37:45 joerg Exp $") | ||
| 33 | |||
| 34 | STRONG_ALIAS(_start,__start) | ||
| 35 | |||
| 36 | 	.hidden ___start | ||
| 37 | |||
| 38 | #ifndef _LP64 | ||
| 39 | 	.weak	_SDA_BASE_ | ||
| 40 | #endif | ||
| 41 | |||
| 42 | ENTRY_NOPROFILE(__start) | ||
| 43 | #ifndef _LP64 | ||
| 44 | 	bcl	20,31,1f | ||
| 45 | 1: | ||
| 46 | 	mflr	%r11 | ||
| 47 | 	/* SVR4 ABI says small data is in r13 */ | ||
| 48 | 	addis	%r13,%r11,_SDA_BASE_-1b@ha | ||
| 49 | 	addi	%r13,%r13,_SDA_BASE_-1b@l | ||
| 50 | #endif | ||
| 51 | |||
| 52 | 	mr	%r3,%r7		/* cleanup */ | ||
| 53 | 	mr	%r4,%r8		/* ps_strings */ | ||
| 54 | |||
| 55 | 	CALL(___start) | ||
| 56 | END(__start) | ||
lib/libc/netbsd/lib/csu/arch/sparc/crt0.S created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | /* $NetBSD: crt0.S,v 1.3 2018/11/26 17:37:45 joerg Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Christos Zoulas | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <machine/asm.h> | ||
| 39 | |||
| 40 | RCSID("$NetBSD: crt0.S,v 1.3 2018/11/26 17:37:45 joerg Exp $") | ||
| 41 | |||
| 42 | STRONG_ALIAS(_start,__start) | ||
| 43 | |||
| 44 | 	! called with: | ||
| 45 | 	! %g3 = cleanup | ||
| 46 | 	! %g1 = ps_strings | ||
| 47 | 	! call: ___start(cleanup, ps_strings) | ||
| 48 | _ENTRY(__start) | ||
| 49 | 	mov	0, %fp | ||
| 50 | 	andn	%sp, 7,	%sp		! align stack | ||
| 51 | 	sub	%sp, 24, %sp		! expand to standard stack frame size | ||
| 52 | 	mov	%g3, %o0 | ||
| 53 | 	call	___start | ||
| 54 | 	 mov	%g1, %o1 | ||
| 55 | |||
lib/libc/netbsd/lib/csu/arch/sparc64/crt0.S created+59| ... | @@ -0,0 +1,59 @@ | ||
| 1 | /* $NetBSD: crt0.S,v 1.2 2018/11/26 17:37:46 joerg Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Christos Zoulas | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <machine/asm.h> | ||
| 39 | |||
| 40 | RCSID("$NetBSD: crt0.S,v 1.2 2018/11/26 17:37:46 joerg Exp $") | ||
| 41 | |||
| 42 | STRONG_ALIAS(_start,__start) | ||
| 43 | |||
| 44 | 	.align 4 | ||
| 45 | 	.register %g3,#scratch | ||
| 46 | 	.register %g2,#scratch | ||
| 47 | |||
| 48 | 	! called with: | ||
| 49 | 	! %g3 = cleanup | ||
| 50 | 	! %g2 = obj | ||
| 51 | 	! %g1 = ps_strings | ||
| 52 | 	! call: ___start(cleanup, ps_strings) | ||
| 53 | _ENTRY(__start) | ||
| 54 | 	clr	%fp | ||
| 55 | 	clr	%g4			! data base for some memory models | ||
| 56 | 	mov	%g3, %o0 | ||
| 57 | 	ba,pt	%icc,___start | ||
| 58 | 	 mov	%g1, %o1 | ||
| 59 | |||
lib/libc/netbsd/lib/csu/arch/x86_64/crt0.S created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | /* $NetBSD: crt0.S,v 1.4 2018/11/26 17:37:46 joerg Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Christos Zoulas | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | */ | ||
| 35 | |||
| 36 | #include <machine/asm.h> | ||
| 37 | |||
| 38 | RCSID("$NetBSD: crt0.S,v 1.4 2018/11/26 17:37:46 joerg Exp $") | ||
| 39 | |||
| 40 | STRONG_ALIAS(_start,__start) | ||
| 41 | 	.hidden ___start | ||
| 42 | |||
| 43 | _ENTRY(__start) | ||
| 44 | 	andq $~15,%rsp | ||
| 45 | 	subq $8,%rsp | ||
| 46 | 	movq	%rdx, %rdi | ||
| 47 | 	movq	%rbx, %rsi | ||
| 48 | 	jmp	___start | ||
lib/libc/netbsd/lib/csu/common/crt0-common.c created+351| ... | @@ -0,0 +1,351 @@ | ||
| 1 | /* $NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Christos Zoulas | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <sys/cdefs.h> | ||
| 39 | __RCSID("$NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $"); | ||
| 40 | |||
| 41 | #include <sys/types.h> | ||
| 42 | #include <sys/exec.h> | ||
| 43 | #include <sys/exec_elf.h> | ||
| 44 | #include <sys/syscall.h> | ||
| 45 | #include <machine/profile.h> | ||
| 46 | #include <stdlib.h> | ||
| 47 | #include <unistd.h> | ||
| 48 | |||
| 49 | #include "csu-common.h" | ||
| 50 | |||
| 51 | extern int main(int, char **, char **); | ||
| 52 | |||
| 53 | typedef void (*fptr_t)(void); | ||
| 54 | #ifndef HAVE_INITFINI_ARRAY | ||
| 55 | extern void	_init(void); | ||
| 56 | extern void	_fini(void); | ||
| 57 | #endif | ||
| 58 | extern void	_libc_init(void); | ||
| 59 | |||
| 60 | /* | ||
| 61 | * Arrange for _DYNAMIC to be weak and undefined (and therefore to show up | ||
| 62 | * as being at address zero, unless something else defines it). That way, | ||
| 63 | * if we happen to be compiling without -static but with without any | ||
| 64 | * shared libs present, things will still work. | ||
| 65 | */ | ||
| 66 | |||
| 67 | __weakref_visible int rtld_DYNAMIC __weak_reference(_DYNAMIC); | ||
| 68 | |||
| 69 | #ifdef MCRT0 | ||
| 70 | extern void	monstartup(u_long, u_long); | ||
| 71 | extern void	_mcleanup(void); | ||
| 72 | extern unsigned char __etext, __eprol; | ||
| 73 | #endif /* MCRT0 */ | ||
| 74 | |||
| 75 | static char	 empty_string[] = ""; | ||
| 76 | |||
| 77 | char		**environ __common; | ||
| 78 | struct ps_strings *__ps_strings __common = 0; | ||
| 79 | char		*__progname __common = empty_string; | ||
| 80 | |||
| 81 | __dead __dso_hidden void ___start(void (*)(void), struct ps_strings *); | ||
| 82 | |||
| 83 | #define	write(fd, s, n)	__syscall(SYS_write, (fd), (s), (n)) | ||
| 84 | |||
| 85 | #define	_FATAL(str)				\ | ||
| 86 | do {						\ | ||
| 87 | 	write(2, str, sizeof(str)-1);		\ | ||
| 88 | 	_exit(1);				\ | ||
| 89 | } while (0) | ||
| 90 | |||
| 91 | /* | ||
| 92 | * If we are using INIT_ARRAY/FINI_ARRAY and we are linked statically, | ||
| 93 | * we have to process these instead of relying on RTLD to do it for us. | ||
| 94 | * | ||
| 95 | * Since we don't need .init or .fini sections, just code them in C | ||
| 96 | * to make life easier. | ||
| 97 | */ | ||
| 98 | extern const fptr_t __preinit_array_start[] __dso_hidden; | ||
| 99 | extern const fptr_t __preinit_array_end[] __dso_hidden __weak; | ||
| 100 | extern const fptr_t __init_array_start[] __dso_hidden; | ||
| 101 | extern const fptr_t __init_array_end[] __dso_hidden __weak; | ||
| 102 | extern const fptr_t __fini_array_start[] __dso_hidden; | ||
| 103 | extern const fptr_t __fini_array_end[] __dso_hidden __weak; | ||
| 104 | |||
| 105 | static inline void | ||
| 106 | _preinit(void) | ||
| 107 | { | ||
| 108 | 	for (const fptr_t *f = __preinit_array_start; f < __preinit_array_end; f++) { | ||
| 109 | 		(*f)(); | ||
| 110 | 	} | ||
| 111 | } | ||
| 112 | |||
| 113 | static inline void | ||
| 114 | _initarray(void) | ||
| 115 | { | ||
| 116 | 	for (const fptr_t *f = __init_array_start; f < __init_array_end; f++) { | ||
| 117 | 		(*f)(); | ||
| 118 | 	} | ||
| 119 | } | ||
| 120 | |||
| 121 | static void | ||
| 122 | _finiarray(void) | ||
| 123 | { | ||
| 124 | 	for (const fptr_t *f = __fini_array_start; f < __fini_array_end; f++) { | ||
| 125 | 		(*f)(); | ||
| 126 | 	} | ||
| 127 | } | ||
| 128 | |||
| 129 | #if \ | ||
| 130 | defined(__aarch64__) || \ | ||
| 131 | defined(__powerpc__) || \ | ||
| 132 | defined(__sparc__) || \ | ||
| 133 | defined(__x86_64__) | ||
| 134 | #define HAS_IPLTA | ||
| 135 | static void fix_iplta(void) __noinline; | ||
| 136 | #elif \ | ||
| 137 | defined(__arm__) || \ | ||
| 138 | defined(__i386__) | ||
| 139 | #define HAS_IPLT | ||
| 140 | static void fix_iplt(void) __noinline; | ||
| 141 | #endif | ||
| 142 | |||
| 143 | |||
| 144 | #ifdef HAS_IPLTA | ||
| 145 | #include <stdio.h> | ||
| 146 | extern const Elf_Rela __rela_iplt_start[] __dso_hidden __weak; | ||
| 147 | extern const Elf_Rela __rela_iplt_end[] __dso_hidden __weak; | ||
| 148 | #ifdef __sparc__ | ||
| 149 | #define IFUNC_RELOCATION R_TYPE(JMP_IREL) | ||
| 150 | #include <machine/elf_support.h> | ||
| 151 | #define write_plt(where, value) sparc_write_branch((void *)where, (void *)value) | ||
| 152 | #else | ||
| 153 | #define IFUNC_RELOCATION R_TYPE(IRELATIVE) | ||
| 154 | #define write_plt(where, value) *where = value | ||
| 155 | #endif | ||
| 156 | |||
| 157 | static void | ||
| 158 | fix_iplta(void) | ||
| 159 | { | ||
| 160 | 	const Elf_Rela *rela, *relalim; | ||
| 161 | 	uintptr_t relocbase = 0; | ||
| 162 | 	Elf_Addr *where, target; | ||
| 163 | |||
| 164 | 	rela = __rela_iplt_start; | ||
| 165 | 	relalim = __rela_iplt_end; | ||
| 166 | 	for (; rela < relalim; ++rela) { | ||
| 167 | 		if (ELF_R_TYPE(rela->r_info) != IFUNC_RELOCATION) | ||
| 168 | 			abort(); | ||
| 169 | 		where = (Elf_Addr *)(relocbase + rela->r_offset); | ||
| 170 | 		target = (Elf_Addr)(relocbase + rela->r_addend); | ||
| 171 | 		target = ((Elf_Addr(*)(void))target)(); | ||
| 172 | 		write_plt(where, target); | ||
| 173 | 	} | ||
| 174 | } | ||
| 175 | #endif | ||
| 176 | #ifdef HAS_IPLT | ||
| 177 | extern const Elf_Rel __rel_iplt_start[] __dso_hidden __weak; | ||
| 178 | extern const Elf_Rel __rel_iplt_end[] __dso_hidden __weak; | ||
| 179 | #define IFUNC_RELOCATION R_TYPE(IRELATIVE) | ||
| 180 | |||
| 181 | static void | ||
| 182 | fix_iplt(void) | ||
| 183 | { | ||
| 184 | 	const Elf_Rel *rel, *rellim; | ||
| 185 | 	uintptr_t relocbase = 0; | ||
| 186 | 	Elf_Addr *where, target; | ||
| 187 | |||
| 188 | 	rel = __rel_iplt_start; | ||
| 189 | 	rellim = __rel_iplt_end; | ||
| 190 | 	for (; rel < rellim; ++rel) { | ||
| 191 | 		if (ELF_R_TYPE(rel->r_info) != IFUNC_RELOCATION) | ||
| 192 | 			abort(); | ||
| 193 | 		where = (Elf_Addr *)(relocbase + rel->r_offset); | ||
| 194 | 		target = ((Elf_Addr(*)(void))*where)(); | ||
| 195 | 		*where = target; | ||
| 196 | 	} | ||
| 197 | } | ||
| 198 | #endif | ||
| 199 | |||
| 200 | #if defined(__x86_64__) || defined(__i386__) | ||
| 201 | # define HAS_RELOCATE_SELF | ||
| 202 | # if defined(__x86_64__) | ||
| 203 | # define RELA | ||
| 204 | # define REL_TAG DT_RELA | ||
| 205 | # define RELSZ_TAG DT_RELASZ | ||
| 206 | # define REL_TYPE Elf_Rela | ||
| 207 | # else | ||
| 208 | # define REL_TAG DT_REL | ||
| 209 | # define RELSZ_TAG DT_RELSZ | ||
| 210 | # define REL_TYPE Elf_Rel | ||
| 211 | # endif | ||
| 212 | |||
| 213 | #include <elf.h> | ||
| 214 | |||
| 215 | static void relocate_self(struct ps_strings *) __noinline; | ||
| 216 | |||
| 217 | static void | ||
| 218 | relocate_self(struct ps_strings *ps_strings) | ||
| 219 | { | ||
| 220 | 	AuxInfo *aux = (AuxInfo *)(ps_strings->ps_argvstr + ps_strings->ps_nargvstr + | ||
| 221 | 	 ps_strings->ps_nenvstr + 2); | ||
| 222 | 	uintptr_t relocbase = (uintptr_t)~0U; | ||
| 223 | 	const Elf_Phdr *phdr = NULL; | ||
| 224 | 	Elf_Half phnum = (Elf_Half)~0; | ||
| 225 | |||
| 226 | 	for (; aux->a_type != AT_NULL; ++aux) { | ||
| 227 | 		switch (aux->a_type) { | ||
| 228 | 		case AT_BASE: | ||
| 229 | 			if (aux->a_v) | ||
| 230 | 				return; | ||
| 231 | 			break; | ||
| 232 | 		case AT_PHDR: | ||
| 233 | 			phdr = (void *)aux->a_v; | ||
| 234 | 			break; | ||
| 235 | 		case AT_PHNUM: | ||
| 236 | 			phnum = (Elf_Half)aux->a_v; | ||
| 237 | 			break; | ||
| 238 | 		} | ||
| 239 | 	} | ||
| 240 | |||
| 241 | 	if (phdr == NULL || phnum == (Elf_Half)~0) | ||
| 242 | 		return; | ||
| 243 | |||
| 244 | 	const Elf_Phdr *phlimit = phdr + phnum, *dynphdr = NULL; | ||
| 245 | |||
| 246 | 	for (; phdr < phlimit; ++phdr) { | ||
| 247 | 		if (phdr->p_type == PT_DYNAMIC) | ||
| 248 | 			dynphdr = phdr; | ||
| 249 | 		if (phdr->p_type == PT_PHDR) | ||
| 250 | 			relocbase = (uintptr_t)phdr - phdr->p_vaddr; | ||
| 251 | 	} | ||
| 252 | 	if (dynphdr == NULL || relocbase == (uintptr_t)~0U) | ||
| 253 | 		return; | ||
| 254 | |||
| 255 | 	Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase); | ||
| 256 | |||
| 257 | 	const REL_TYPE *relocs = 0, *relocslim; | ||
| 258 | 	Elf_Addr relocssz = 0; | ||
| 259 | |||
| 260 | 	for (; dynp->d_tag != DT_NULL; dynp++) { | ||
| 261 | 		switch (dynp->d_tag) { | ||
| 262 | 		case REL_TAG: | ||
| 263 | 			relocs = | ||
| 264 | 			 (const REL_TYPE *)(relocbase + dynp->d_un.d_ptr); | ||
| 265 | 			break; | ||
| 266 | 		case RELSZ_TAG: | ||
| 267 | 			relocssz = dynp->d_un.d_val; | ||
| 268 | 			break; | ||
| 269 | 		} | ||
| 270 | 	} | ||
| 271 | 	relocslim = (const REL_TYPE *)((const uint8_t *)relocs + relocssz); | ||
| 272 | 	for (; relocs < relocslim; ++relocs) { | ||
| 273 | 		Elf_Addr *where; | ||
| 274 | |||
| 275 | 		where = (Elf_Addr *)(relocbase + relocs->r_offset); | ||
| 276 | |||
| 277 | 		switch (ELF_R_TYPE(relocs->r_info)) { | ||
| 278 | 		case R_TYPE(RELATIVE): /* word64 B + A */ | ||
| 279 | #ifdef RELA | ||
| 280 | 			*where = (Elf_Addr)(relocbase + relocs->r_addend); | ||
| 281 | #else | ||
| 282 | 			*where += (Elf_Addr)relocbase; | ||
| 283 | #endif | ||
| 284 | 			break; | ||
| 285 | #ifdef IFUNC_RELOCATION | ||
| 286 | 		case IFUNC_RELOCATION: | ||
| 287 | 			break; | ||
| 288 | #endif | ||
| 289 | 		default: | ||
| 290 | 			abort(); | ||
| 291 | 		} | ||
| 292 | 	} | ||
| 293 | } | ||
| 294 | #endif | ||
| 295 | |||
| 296 | void | ||
| 297 | ___start(void (*cleanup)(void),			/* from shared loader */ | ||
| 298 | struct ps_strings *ps_strings) | ||
| 299 | { | ||
| 300 | #if defined(HAS_RELOCATE_SELF) | ||
| 301 | 	relocate_self(ps_strings); | ||
| 302 | #endif | ||
| 303 | |||
| 304 | 	if (ps_strings == NULL) | ||
| 305 | 		_FATAL("ps_strings missing\n"); | ||
| 306 | 	__ps_strings = ps_strings; | ||
| 307 | |||
| 308 | 	environ = ps_strings->ps_envstr; | ||
| 309 | |||
| 310 | 	if (ps_strings->ps_argvstr[0] != NULL) { | ||
| 311 | 		char *c; | ||
| 312 | 		__progname = ps_strings->ps_argvstr[0]; | ||
| 313 | 		for (c = ps_strings->ps_argvstr[0]; *c; ++c) { | ||
| 314 | 			if (*c == '/') | ||
| 315 | 				__progname = c + 1; | ||
| 316 | 		} | ||
| 317 | 	} else { | ||
| 318 | 		__progname = empty_string; | ||
| 319 | 	} | ||
| 320 | |||
| 321 | 	if (cleanup != NULL) | ||
| 322 | 		atexit(cleanup); | ||
| 323 | |||
| 324 | 	_libc_init(); | ||
| 325 | |||
| 326 | 	if (&rtld_DYNAMIC == NULL) { | ||
| 327 | #ifdef HAS_IPLTA | ||
| 328 | 		fix_iplta(); | ||
| 329 | #endif | ||
| 330 | #ifdef HAS_IPLT | ||
| 331 | 		fix_iplt(); | ||
| 332 | #endif | ||
| 333 | 	} | ||
| 334 | |||
| 335 | 	_preinit(); | ||
| 336 | |||
| 337 | #ifdef MCRT0 | ||
| 338 | 	atexit(_mcleanup); | ||
| 339 | 	monstartup((u_long)&__eprol, (u_long)&__etext); | ||
| 340 | #endif | ||
| 341 | |||
| 342 | 	atexit(_finiarray); | ||
| 343 | 	_initarray(); | ||
| 344 | |||
| 345 | #ifndef HAVE_INITFINI_ARRAY | ||
| 346 | 	atexit(_fini); | ||
| 347 | 	_init(); | ||
| 348 | #endif | ||
| 349 | |||
| 350 | 	exit(main(ps_strings->ps_nargvstr, ps_strings->ps_argvstr, environ)); | ||
| 351 | } | ||
lib/libc/netbsd/lib/csu/common/crtbegin.c created+135| ... | @@ -0,0 +1,135 @@ | ||
| 1 | /*- | ||
| 2 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 6 | * by Matt Thomas of 3am Software Foundry. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | #include <sys/cdefs.h> | ||
| 30 | __RCSID("$NetBSD: crtbegin.c,v 1.17 2018/12/28 18:17:11 christos Exp $"); | ||
| 31 | |||
| 32 | /* zig patch: no crtbegin.h */ | ||
| 33 | |||
| 34 | typedef void (*fptr_t)(void); | ||
| 35 | |||
| 36 | /* zig patch: remove gcj nonsense */ | ||
| 37 | |||
| 38 | #if !defined(HAVE_INITFINI_ARRAY) | ||
| 39 | extern __dso_hidden const fptr_t __CTOR_LIST__start __asm("__CTOR_LIST__"); | ||
| 40 | |||
| 41 | __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = { | ||
| 42 | 	(fptr_t) -1, | ||
| 43 | }; | ||
| 44 | __dso_hidden extern const fptr_t __CTOR_LIST_END__[]; | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #ifdef SHARED | ||
| 48 | __dso_hidden void *__dso_handle = &__dso_handle; | ||
| 49 | |||
| 50 | __weakref_visible void cxa_finalize(void *) | ||
| 51 | 	__weak_reference(__cxa_finalize); | ||
| 52 | #else | ||
| 53 | __dso_hidden void *__dso_handle; | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #if !defined(__ARM_EABI__) || defined(__ARM_DWARF_EH__) | ||
| 57 | __dso_hidden const long __EH_FRAME_LIST__[0] __section(".eh_frame"); | ||
| 58 | |||
| 59 | __weakref_visible void register_frame_info(const void *, const void *) | ||
| 60 | 	__weak_reference(__register_frame_info); | ||
| 61 | __weakref_visible void deregister_frame_info(const void *) | ||
| 62 | 	__weak_reference(__deregister_frame_info); | ||
| 63 | |||
| 64 | static long dwarf_eh_object[8]; | ||
| 65 | #endif | ||
| 66 | |||
| 67 | static void __do_global_ctors_aux(void) __used; | ||
| 68 | |||
| 69 | /* zig patch: use .init_array */ | ||
| 70 | __attribute__((constructor)) | ||
| 71 | static void | ||
| 72 | __do_global_ctors_aux(void) | ||
| 73 | { | ||
| 74 | 	static unsigned char __initialized; | ||
| 75 | |||
| 76 | 	if (__initialized) | ||
| 77 | 		return; | ||
| 78 | |||
| 79 | 	__initialized = 1; | ||
| 80 | |||
| 81 | #if !defined(__ARM_EABI__) || defined(__ARM_DWARF_EH__) | ||
| 82 | 	if (register_frame_info) | ||
| 83 | 		register_frame_info(__EH_FRAME_LIST__, &dwarf_eh_object); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | /* zig patch: remove gcj nonsense */ | ||
| 87 | |||
| 88 | #if !defined(HAVE_INITFINI_ARRAY) | ||
| 89 | 	for (const fptr_t *p = __CTOR_LIST_END__; p > &__CTOR_LIST__start + 1; ) { | ||
| 90 | 		(*(*--p))(); | ||
| 91 | 	} | ||
| 92 | #endif | ||
| 93 | } | ||
| 94 | |||
| 95 | #if !defined(__ARM_EABI__) || defined(SHARED) || defined(__ARM_DWARF_EH__) | ||
| 96 | #if !defined(HAVE_INITFINI_ARRAY) | ||
| 97 | extern __dso_hidden const fptr_t __DTOR_LIST__start __asm("__DTOR_LIST__"); | ||
| 98 | |||
| 99 | __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = { | ||
| 100 | 	(fptr_t) -1, | ||
| 101 | }; | ||
| 102 | __dso_hidden extern const fptr_t __DTOR_LIST_END__[]; | ||
| 103 | #endif | ||
| 104 | |||
| 105 | static void __do_global_dtors_aux(void) __used; | ||
| 106 | |||
| 107 | /* zig patch: use .fini_array */ | ||
| 108 | __attribute__((destructor)) | ||
| 109 | static void | ||
| 110 | __do_global_dtors_aux(void) | ||
| 111 | { | ||
| 112 | 	static unsigned char __finished; | ||
| 113 | |||
| 114 | 	if (__finished) | ||
| 115 | 		return; | ||
| 116 | |||
| 117 | 	__finished = 1; | ||
| 118 | |||
| 119 | #ifdef SHARED | ||
| 120 | 	if (cxa_finalize) | ||
| 121 | 		(*cxa_finalize)(__dso_handle); | ||
| 122 | #endif | ||
| 123 | |||
| 124 | #if !defined(HAVE_INITFINI_ARRAY) | ||
| 125 | 	for (const fptr_t *p = &__DTOR_LIST__start + 1; p < __DTOR_LIST_END__; ) { | ||
| 126 | 		(*(*p++))(); | ||
| 127 | 	} | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #if !defined(__ARM_EABI__) || defined(__ARM_DWARF_EH__) | ||
| 131 | 	if (deregister_frame_info) | ||
| 132 | 		deregister_frame_info(__EH_FRAME_LIST__); | ||
| 133 | #endif | ||
| 134 | } | ||
| 135 | #endif /* !__ARM_EABI__ || SHARED || __ARM_DWARF_EH__ */ | ||
lib/libc/netbsd/lib/csu/common/csu-common.h created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | /*- | ||
| 2 | * Copyright (c) 2021 The NetBSD Foundation, Inc. | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * 1. Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer in the | ||
| 12 | * documentation and/or other materials provided with the distribution. | ||
| 13 | * | ||
| 14 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 15 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 16 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 24 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 25 | */ | ||
| 26 | |||
| 27 | /* | ||
| 28 | * For historical reasons the following symbols are defined both in libc | ||
| 29 | * and csu and need to be common | ||
| 30 | */ | ||
| 31 | #if __has_attribute(__common__) | ||
| 32 | #define	__common	__attribute((__common__)) | ||
| 33 | #else | ||
| 34 | #define	__common | ||
| 35 | #endif | ||
| 36 | extern char *__progname __common; | ||
| 37 | extern char **environ __common; | ||
| 38 | extern struct ps_strings *__ps_strings __common; | ||
lib/libc/netbsd/lib/csu/common/sysident.S created+89| ... | @@ -0,0 +1,89 @@ | ||
| 1 | /* $NetBSD: sysident.S,v 1.3 2014/05/14 14:59:14 joerg Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1997 Christopher G. Demetriou | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * 3. All advertising materials mentioning features or use of this software | ||
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed for the | ||
| 18 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 19 | * information about NetBSD. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission. | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | * | ||
| 34 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 35 | */ | ||
| 36 | |||
| 37 | /* | ||
| 38 | * Here we define the NetBSD OS Version in an ELF .note section, structured | ||
| 39 | * like: | ||
| 40 | * | ||
| 41 | * [NOTE HEADER] | ||
| 42 | *	long		name size | ||
| 43 | *	long		description size | ||
| 44 | *	long		note type | ||
| 45 | * | ||
| 46 | * [NOTE DATUM] | ||
| 47 | *	string		OS name | ||
| 48 | * | ||
| 49 | * OSVERSION notes also have: | ||
| 50 | *	long		OS version (__NetBSD_Version__ constant from param.h) | ||
| 51 | * | ||
| 52 | * The DATUM fields should be padded out such that their actual (not | ||
| 53 | * declared) sizes % 4 == 0. | ||
| 54 | * | ||
| 55 | * These are used by the kernel to determine if this binary is really a | ||
| 56 | * NetBSD binary, or some other OS's. | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "sysident_assym.h" | ||
| 60 | |||
| 61 | 	.section ".note.netbsd.ident", "a" | ||
| 62 | 	.p2align 2 | ||
| 63 | |||
| 64 | 	.long	ELF_NOTE_NETBSD_NAMESZ | ||
| 65 | 	.long	ELF_NOTE_NETBSD_DESCSZ | ||
| 66 | 	.long	ELF_NOTE_TYPE_NETBSD_TAG | ||
| 67 | 	.ascii	"NetBSD\0\0"	/* ELF_NOTE_NETBSD_NAME */ | ||
| 68 | 	.long	__NetBSD_Version__ | ||
| 69 | |||
| 70 | 	.section ".note.netbsd.pax", "a" | ||
| 71 | 	.p2align 2 | ||
| 72 | |||
| 73 | 	.long	ELF_NOTE_PAX_NAMESZ | ||
| 74 | 	.long	ELF_NOTE_PAX_DESCSZ | ||
| 75 | 	.long	ELF_NOTE_TYPE_PAX_TAG | ||
| 76 | 	.ascii	"PaX\0"		/* ELF_NOTE_PAX_NAME */ | ||
| 77 | 	.long	0 | ||
| 78 | |||
| 79 | #ifdef ELF_NOTE_MARCH_DESC | ||
| 80 | 	.section ".note.netbsd.march", "a" | ||
| 81 | 	.p2align 2 | ||
| 82 | |||
| 83 | 	.long	ELF_NOTE_MARCH_NAMESZ | ||
| 84 | 	.long	ELF_NOTE_MARCH_DESCSZ | ||
| 85 | 	.long	ELF_NOTE_TYPE_MARCH_TAG | ||
| 86 | 	.ascii	"NetBSD\0\0" | ||
| 87 | 	.asciz	ELF_NOTE_MARCH_DESC | ||
| 88 | 	.p2align 2 | ||
| 89 | #endif | ||
lib/libc/netbsd/lib/csu/common/sysident_assym.h created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | /* zig patch: manually expanded from sysident_assym.cf */ | ||
| 2 | |||
| 3 | #define	ELF_NOTE_NETBSD_NAMESZ		7 | ||
| 4 | #define	ELF_NOTE_NETBSD_DESCSZ		4 | ||
| 5 | #define	ELF_NOTE_TYPE_NETBSD_TAG	1 | ||
| 6 | #define	ELF_NOTE_PAX_NAMESZ		4 | ||
| 7 | #define	ELF_NOTE_PAX_DESCSZ		4 | ||
| 8 | #define	ELF_NOTE_TYPE_PAX_TAG		3 | ||
| 9 | |||
| 10 | /* zig patch: ELF_NOTE_MARCH_DESC and ELF_NOTE_MARCH_DESCSZ defined by the compiler */ | ||
| 11 | #ifdef ELF_NOTE_MARCH_DESC | ||
| 12 | #define	ELF_NOTE_MARCH_NAMESZ		7 | ||
| 13 | #define	ELF_NOTE_TYPE_MARCH_TAG		5 | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #define	ELF_NOTE_MCMODEL_NAMESZ		7 | ||
| 17 | #define	ELF_NOTE_TYPE_MCMODEL_TAG	6 | ||