| author | |
| committer | |
| log | f1b14b91f1f0c381c0d2c8c7ba3fd8df8a937227 |
| tree | 0a06f856c8483c4908d1baf68b6630769ed967b1 |
| parent | a64989ee704255f61639c9714c5a38b4d6eb0a9e |
__libc_start_main() from glibc.2.33.so or older needs to have a __libc_csu_init function callback parameter.
glibc-2.34 on the other hand has a different __libc_start_main() that does not use it,
and the start.S file from glibc-2.34 no longer construct the init function and pass null when calling __libc_start_main.
So, When targetting an older glibc, use the start.s files as they were in glibc-2.33 and construct the __libc_csu_init function.
fixes #10386 #1051220 files changed, 2345 insertions(+), 5 deletions(-)
lib/libc/glibc/csu/elf-init-2-33.c created+106| ... | ... | @@ -0,0 +1,106 @@ |
| 1 | /* Startup support for ELF initializers/finalizers in the main executable. | |
| 2 | Copyright (C) 2002-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library; if not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | #include <stddef.h> | |
| 37 | ||
| 38 | ||
| 39 | /* These magic symbols are provided by the linker. */ | |
| 40 | extern void (*__preinit_array_start []) (int, char **, char **) | |
| 41 | attribute_hidden; | |
| 42 | extern void (*__preinit_array_end []) (int, char **, char **) | |
| 43 | attribute_hidden; | |
| 44 | extern void (*__init_array_start []) (int, char **, char **) | |
| 45 | attribute_hidden; | |
| 46 | extern void (*__init_array_end []) (int, char **, char **) | |
| 47 | attribute_hidden; | |
| 48 | extern void (*__fini_array_start []) (void) attribute_hidden; | |
| 49 | extern void (*__fini_array_end []) (void) attribute_hidden; | |
| 50 | ||
| 51 | ||
| 52 | #ifndef NO_INITFINI | |
| 53 | /* These function symbols are provided for the .init/.fini section entry | |
| 54 | points automagically by the linker. */ | |
| 55 | extern void _init (void); | |
| 56 | extern void _fini (void); | |
| 57 | #endif | |
| 58 | ||
| 59 | ||
| 60 | /* These functions are passed to __libc_start_main by the startup code. | |
| 61 | These get statically linked into each program. For dynamically linked | |
| 62 | programs, this module will come from libc_nonshared.a and differs from | |
| 63 | the libc.a module in that it doesn't call the preinit array. */ | |
| 64 | ||
| 65 | ||
| 66 | void | |
| 67 | __libc_csu_init (int argc, char **argv, char **envp) | |
| 68 | { | |
| 69 | /* For dynamically linked executables the preinit array is executed by | |
| 70 | the dynamic linker (before initializing any shared object). */ | |
| 71 | ||
| 72 | #ifndef LIBC_NONSHARED | |
| 73 | /* For static executables, preinit happens right before init. */ | |
| 74 | { | |
| 75 | const size_t size = __preinit_array_end - __preinit_array_start; | |
| 76 | size_t i; | |
| 77 | for (i = 0; i < size; i++) | |
| 78 | (*__preinit_array_start [i]) (argc, argv, envp); | |
| 79 | } | |
| 80 | #endif | |
| 81 | ||
| 82 | #ifndef NO_INITFINI | |
| 83 | _init (); | |
| 84 | #endif | |
| 85 | ||
| 86 | const size_t size = __init_array_end - __init_array_start; | |
| 87 | for (size_t i = 0; i < size; i++) | |
| 88 | (*__init_array_start [i]) (argc, argv, envp); | |
| 89 | } | |
| 90 | ||
| 91 | /* This function should not be used anymore. We run the executable's | |
| 92 | destructor now just like any other. We cannot remove the function, | |
| 93 | though. */ | |
| 94 | void | |
| 95 | __libc_csu_fini (void) | |
| 96 | { | |
| 97 | #ifndef LIBC_NONSHARED | |
| 98 | size_t i = __fini_array_end - __fini_array_start; | |
| 99 | while (i-- > 0) | |
| 100 | (*__fini_array_start [i]) (); | |
| 101 | ||
| 102 | # ifndef NO_INITFINI | |
| 103 | _fini (); | |
| 104 | # endif | |
| 105 | #endif | |
| 106 | } |
lib/libc/glibc/sysdeps/aarch64/start-2-33.S created+112| ... | ... | @@ -0,0 +1,112 @@ |
| 1 | /* Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
| 2 | ||
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public License as | |
| 7 | published by the Free Software Foundation; either version 2.1 of the | |
| 8 | License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library. If not, see | |
| 17 | <https://www.gnu.org/licenses/>. */ | |
| 18 | ||
| 19 | #include <sysdep.h> | |
| 20 | ||
| 21 | /* This is the canonical entry point, usually the first thing in the text | |
| 22 | segment. | |
| 23 | ||
| 24 | Note that the code in the .init section has already been run. | |
| 25 | This includes _init and _libc_init | |
| 26 | ||
| 27 | ||
| 28 | At this entry point, most registers' values are unspecified, except: | |
| 29 | ||
| 30 | x0/w0	Contains a function pointer to be registered with `atexit'. | |
| 31 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 32 | 		functions called for shared libraries that have been loaded | |
| 33 | 		before this code runs. | |
| 34 | ||
| 35 | sp		The stack contains the arguments and environment: | |
| 36 | 		0(sp)			argc | |
| 37 | 		8(sp)			argv[0] | |
| 38 | 		... | |
| 39 | 		(8*argc)(sp)		NULL | |
| 40 | 		(8*(argc+1))(sp)	envp[0] | |
| 41 | 		... | |
| 42 | 					NULL | |
| 43 | */ | |
| 44 | ||
| 45 | 	.text | |
| 46 | 	.globl _start | |
| 47 | 	.type _start,#function | |
| 48 | _start: | |
| 49 | 	/* Create an initial frame with 0 LR and FP */ | |
| 50 | 	mov	x29, #0 | |
| 51 | 	mov	x30, #0 | |
| 52 | ||
| 53 | 	/* Setup rtld_fini in argument register */ | |
| 54 | 	mov	x5, x0 | |
| 55 | ||
| 56 | 	/* Load argc and a pointer to argv */ | |
| 57 | 	ldr	PTR_REG (1), [sp, #0] | |
| 58 | 	add	x2, sp, #PTR_SIZE | |
| 59 | ||
| 60 | 	/* Setup stack limit in argument register */ | |
| 61 | 	mov	x6, sp | |
| 62 | ||
| 63 | #ifdef PIC | |
| 64 | # ifdef SHARED | |
| 65 | adrp x0, :got:main | |
| 66 | 	ldr PTR_REG (0), [x0, #:got_lo12:main] | |
| 67 | ||
| 68 | adrp x3, :got:__libc_csu_init | |
| 69 | 	ldr PTR_REG (3), [x3, #:got_lo12:__libc_csu_init] | |
| 70 | ||
| 71 | adrp x4, :got:__libc_csu_fini | |
| 72 | 	ldr PTR_REG (4), [x4, #:got_lo12:__libc_csu_fini] | |
| 73 | # else | |
| 74 | 	adrp	x0, __wrap_main | |
| 75 | 	add	x0, x0, :lo12:__wrap_main | |
| 76 | 	adrp	x3, __libc_csu_init | |
| 77 | 	add	x3, x3, :lo12:__libc_csu_init | |
| 78 | 	adrp	x4, __libc_csu_fini | |
| 79 | 	add	x4, x4, :lo12:__libc_csu_fini | |
| 80 | # endif | |
| 81 | #else | |
| 82 | 	/* Set up the other arguments in registers */ | |
| 83 | 	MOVL (0, main) | |
| 84 | 	MOVL (3, __libc_csu_init) | |
| 85 | 	MOVL (4, __libc_csu_fini) | |
| 86 | #endif | |
| 87 | ||
| 88 | 	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini, | |
| 89 | 			 stack_end) */ | |
| 90 | ||
| 91 | 	/* Let the libc call main and exit with its return code. */ | |
| 92 | 	bl	__libc_start_main | |
| 93 | ||
| 94 | 	/* should never get here....*/ | |
| 95 | 	bl	abort | |
| 96 | ||
| 97 | #if defined PIC && !defined SHARED | |
| 98 | 	/* When main is not defined in the executable but in a shared library | |
| 99 | 	 then a wrapper is needed in crt1.o of the static-pie enabled libc, | |
| 100 | 	 because crt1.o and rcrt1.o share code and the later must avoid the | |
| 101 | 	 use of GOT relocations before __libc_start_main is called. */ | |
| 102 | __wrap_main: | |
| 103 | 	b	main | |
| 104 | #endif | |
| 105 | ||
| 106 | 	/* Define a symbol for the first piece of initialized data. */ | |
| 107 | 	.data | |
| 108 | 	.globl __data_start | |
| 109 | __data_start: | |
| 110 | 	.long 0 | |
| 111 | 	.weak data_start | |
| 112 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/alpha/start-2-33.S created+85| ... | ... | @@ -0,0 +1,85 @@ |
| 1 | /* Startup code for Alpha/ELF. | |
| 2 | Copyright (C) 1993-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | Contributed by Richard Henderson <rth@tamu.edu> | |
| 5 | ||
| 6 | The GNU C Library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | In addition to the permissions in the GNU Lesser General Public | |
| 12 | License, the Free Software Foundation gives you unlimited | |
| 13 | permission to link the compiled version of this file with other | |
| 14 | programs, and to distribute those programs without any restriction | |
| 15 | coming from the use of this file. (The GNU Lesser General Public | |
| 16 | License restrictions do apply in other respects; for example, they | |
| 17 | cover modification of the file, and distribution when not linked | |
| 18 | into another program.) | |
| 19 | ||
| 20 | Note that people who make modified versions of this file are not | |
| 21 | obligated to grant this special exception for their modified | |
| 22 | versions; it is their choice whether to do so. The GNU Lesser | |
| 23 | General Public License gives permission to release a modified | |
| 24 | version without this exception; this exception also makes it | |
| 25 | possible to release a modified version which carries forward this | |
| 26 | exception. | |
| 27 | ||
| 28 | The GNU C Library is distributed in the hope that it will be useful, | |
| 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 31 | Lesser General Public License for more details. | |
| 32 | ||
| 33 | You should have received a copy of the GNU Lesser General Public | |
| 34 | License along with the GNU C Library. If not, see | |
| 35 | <https://www.gnu.org/licenses/>. */ | |
| 36 | ||
| 37 | #include <sysdep.h> | |
| 38 | ||
| 39 | 	.text | |
| 40 | 	.align 3 | |
| 41 | 	.globl _start | |
| 42 | 	.ent _start, 0 | |
| 43 | 	.type _start,@function | |
| 44 | _start: | |
| 45 | 	.frame	$15, 0, $15 | |
| 46 | 	br	gp, 1f | |
| 47 | 1:	ldgp	gp, 0(gp) | |
| 48 | 	subq	sp, 16, sp | |
| 49 | 	mov	0, $15 | |
| 50 | 	.prologue 0 | |
| 51 | ||
| 52 | /* Load address of the user's main function. */ | |
| 53 | 	lda	a0, main | |
| 54 | ||
| 55 | 	ldl	a1, 16(sp)	/* get argc */ | |
| 56 | 	lda	a2, 24(sp)	/* get argv */ | |
| 57 | ||
| 58 | /* Load address of our own entry points to .fini and .init. */ | |
| 59 | 	lda	a3, __libc_csu_init | |
| 60 | 	lda	a4, __libc_csu_fini | |
| 61 | ||
| 62 | /* Store address of the shared library termination function. */ | |
| 63 | 	mov	v0, a5 | |
| 64 | ||
| 65 | /* Provide the highest stack address to the user code. */ | |
| 66 | 	stq	sp, 0(sp) | |
| 67 | ||
| 68 | /* Call the user's main function, and exit with its value. | |
| 69 | But let the libc call main. */ | |
| 70 | 	jsr	ra, __libc_start_main | |
| 71 | ||
| 72 | /* Die very horribly if exit returns. Call_pal hlt is callable from | |
| 73 | kernel mode only; this will result in an illegal instruction trap. */ | |
| 74 | 	call_pal 0 | |
| 75 | 	.end _start | |
| 76 | ||
| 77 | /* For ECOFF backwards compatibility. */ | |
| 78 | weak_alias (_start, __start) | |
| 79 | ||
| 80 | /* Define a symbol for the first piece of initialized data. */ | |
| 81 | 	.data | |
| 82 | 	.globl __data_start | |
| 83 | __data_start: | |
| 84 | 	.weak data_start | |
| 85 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/arm/start-2-33.S created+148| ... | ... | @@ -0,0 +1,148 @@ |
| 1 | /* Startup code for ARM & ELF | |
| 2 | Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library. If not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | /* This is the canonical entry point, usually the first thing in the text | |
| 37 | segment. | |
| 38 | ||
| 39 | 	Note that the code in the .init section has already been run. | |
| 40 | 	This includes _init and _libc_init | |
| 41 | ||
| 42 | ||
| 43 | 	At this entry point, most registers' values are unspecified, except: | |
| 44 | ||
| 45 | a1		Contains a function pointer to be registered with `atexit'. | |
| 46 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 47 | 		functions called for shared libraries that have been loaded | |
| 48 | 		before this code runs. | |
| 49 | ||
| 50 | sp		The stack contains the arguments and environment: | |
| 51 | 		0(sp)			argc | |
| 52 | 		4(sp)			argv[0] | |
| 53 | 		... | |
| 54 | 		(4*argc)(sp)		NULL | |
| 55 | 		(4*(argc+1))(sp)	envp[0] | |
| 56 | 		... | |
| 57 | 					NULL | |
| 58 | */ | |
| 59 | ||
| 60 | /* Tag_ABI_align8_preserved: This code preserves 8-byte | |
| 61 | alignment in any callee. */ | |
| 62 | 	.eabi_attribute 25, 1 | |
| 63 | /* Tag_ABI_align8_needed: This code may require 8-byte alignment from | |
| 64 | the caller. */ | |
| 65 | 	.eabi_attribute 24, 1 | |
| 66 | ||
| 67 | #if defined(__thumb2__) | |
| 68 | 	.thumb | |
| 69 | 	.syntax unified | |
| 70 | #endif | |
| 71 | ||
| 72 | 	.text | |
| 73 | 	.globl _start | |
| 74 | 	.type _start,#function | |
| 75 | _start: | |
| 76 | /* Protect against unhandled exceptions. */ | |
| 77 | .fnstart | |
| 78 | 	/* Clear the frame pointer and link register since this is the outermost frame. */ | |
| 79 | 	mov fp, #0 | |
| 80 | 	mov lr, #0 | |
| 81 | ||
| 82 | 	/* Pop argc off the stack and save a pointer to argv */ | |
| 83 | 	pop { a2 } | |
| 84 | 	mov a3, sp | |
| 85 | ||
| 86 | 	/* Push stack limit */ | |
| 87 | 	push { a3 } | |
| 88 | ||
| 89 | 	/* Push rtld_fini */ | |
| 90 | 	push { a1 } | |
| 91 | ||
| 92 | #ifdef PIC | |
| 93 | 	ldr sl, .L_GOT | |
| 94 | 	adr a4, .L_GOT | |
| 95 | 	add sl, sl, a4 | |
| 96 | ||
| 97 | 	ldr ip, .L_GOT+4	/* __libc_csu_fini */ | |
| 98 | 	ldr ip, [sl, ip] | |
| 99 | ||
| 100 | 	push { ip }		/* Push __libc_csu_fini */ | |
| 101 | ||
| 102 | 	ldr a4, .L_GOT+8	/* __libc_csu_init */ | |
| 103 | 	ldr a4, [sl, a4] | |
| 104 | ||
| 105 | 	ldr a1, .L_GOT+12	/* main */ | |
| 106 | 	ldr a1, [sl, a1] | |
| 107 | ||
| 108 | 	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ | |
| 109 | 	/* Let the libc call main and exit with its return code. */ | |
| 110 | 	bl __libc_start_main(PLT) | |
| 111 | #else | |
| 112 | 	/* Fetch address of __libc_csu_fini */ | |
| 113 | 	ldr ip, =__libc_csu_fini | |
| 114 | ||
| 115 | 	/* Push __libc_csu_fini */ | |
| 116 | 	push { ip } | |
| 117 | ||
| 118 | 	/* Set up the other arguments in registers */ | |
| 119 | 	ldr a1, =main | |
| 120 | 	ldr a4, =__libc_csu_init | |
| 121 | ||
| 122 | 	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ | |
| 123 | 	/* Let the libc call main and exit with its return code. */ | |
| 124 | 	bl __libc_start_main | |
| 125 | #endif | |
| 126 | ||
| 127 | 	/* should never get here....*/ | |
| 128 | 	bl abort | |
| 129 | ||
| 130 | #ifdef PIC | |
| 131 | 	.align 2 | |
| 132 | .L_GOT: | |
| 133 | 	.word _GLOBAL_OFFSET_TABLE_ - .L_GOT | |
| 134 | 	.word __libc_csu_fini(GOT) | |
| 135 | 	.word __libc_csu_init(GOT) | |
| 136 | 	.word main(GOT) | |
| 137 | #endif | |
| 138 | ||
| 139 | .cantunwind | |
| 140 | .fnend | |
| 141 | ||
| 142 | /* Define a symbol for the first piece of initialized data. */ | |
| 143 | 	.data | |
| 144 | 	.globl __data_start | |
| 145 | __data_start: | |
| 146 | 	.long 0 | |
| 147 | 	.weak data_start | |
| 148 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/hppa/start-2-33.S created+152| ... | ... | @@ -0,0 +1,152 @@ |
| 1 | /* ELF startup code for HPPA. | |
| 2 | Copyright (C) 2002-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library. If not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | 	.import main, code | |
| 37 | 	.import $global$, data | |
| 38 | 	.import __libc_start_main, code | |
| 39 | 	.import __libc_csu_fini, code | |
| 40 | 	.import __libc_csu_init, code | |
| 41 | ||
| 42 | 	/* Have the linker create plabel words so we get PLABEL32 | |
| 43 | 	 relocs and not 21/14. The use of 21/14 relocs is only | |
| 44 | 	 supported in the latest dynamic linker. */ | |
| 45 | #ifdef PIC | |
| 46 | 	.section	.data.rel.ro,"aw",@progbits | |
| 47 | #else | |
| 48 | 	.section	.rodata,"a",@progbits | |
| 49 | #endif | |
| 50 | 	.align 4 | |
| 51 | .Lpmain: | |
| 52 | 	.word P%main | |
| 53 | .Lp__libc_start_main: | |
| 54 | 	.word P%__libc_start_main | |
| 55 | .Lp__libc_csu_fini: | |
| 56 | 	.word P%__libc_csu_fini | |
| 57 | .Lp__libc_csu_init: | |
| 58 | 	.word P%__libc_csu_init | |
| 59 | ||
| 60 | 	.text | |
| 61 | 	.align 4 | |
| 62 | 	.globl _start | |
| 63 | 	.export _start, ENTRY | |
| 64 | 	.type _start,@function | |
| 65 | _start: | |
| 66 | 	/* At entry to the function we have: | |
| 67 | ||
| 68 | 		r26 - Unused | |
| 69 | 		r25 - argc | |
| 70 | 		r24 - argv | |
| 71 | 		r23 - False _dl_fini plabel address | |
| 72 | ||
| 73 | 	 This function is called from the lower half of RTLD_START. | |
| 74 | ||
| 75 | 	 The call to __libc_start_main expects: | |
| 76 | ||
| 77 | 		1. r26 - Application main | |
| 78 | 		2. r25 - argc | |
| 79 | 		3. r24 - argv | |
| 80 | 		4. r23 - __libc_csu_init | |
| 81 | 		5. sp-52 - __libc_csu_fini | |
| 82 | 		6. sp-56 - rtld_fini | |
| 83 | 		7. sp-60 - stackend */ | |
| 84 | ||
| 85 | 	.proc | |
| 86 | 	.callinfo | |
| 87 | 	/* Clear previous-sp. */ | |
| 88 | 	stw	%r0, -4(%sp) | |
| 89 | 	/* Setup the stack and frame. */ | |
| 90 | 	stw	%rp, -20(%sp) | |
| 91 | 	ldo	64(%sp), %sp | |
| 92 | 	stw	%sp, -4(%sp) | |
| 93 | 	stw	%r19, -32(%sp) | |
| 94 | ||
| 95 | 	/* argc and argv should be in 25 and 24 (2nd and 3rd argument) */ | |
| 96 | 	/* void (*rtld_fini) (void) (6th argument) */ | |
| 97 | 	stw	%r23, -56(%sp) | |
| 98 | ||
| 99 | 	/* Need to setup 1, 4, 5, and 7th arguments */ | |
| 100 | ||
| 101 | #ifdef PIC | |
| 102 | 	/* Load $global$ address into %dp */ | |
| 103 | 	bl	.+8, %dp | |
| 104 | 	addil	L'$global$-$PIC_pcrel$0+1, %dp | |
| 105 | 	ldo	R'$global$-$PIC_pcrel$0+5(%r1), %dp | |
| 106 | ||
| 107 | 	/* load main (1st argument) */ | |
| 108 | 	addil	LT'.Lpmain, %r19 | |
| 109 | 	ldw	RT'.Lpmain(%r1), %r26 | |
| 110 | 	ldw	0(%r26),%r26 | |
| 111 | 	/* void (*init) (void) (4th argument) */ | |
| 112 | 	addil	LT'.Lp__libc_csu_init, %r19 | |
| 113 | 	ldw	RT'.Lp__libc_csu_init(%r1), %r23 | |
| 114 | 	ldw	0(%r23), %r23 | |
| 115 | 	/* void (*fini) (void) (5th argument) */ | |
| 116 | 	addil	LT'.Lp__libc_csu_fini, %r19 | |
| 117 | 	ldw	RT'.Lp__libc_csu_fini(%r1), %r22 | |
| 118 | 	ldw	0(%r22), %r22 | |
| 119 | #else | |
| 120 | 	/* Load $global$ address into %dp */ | |
| 121 | 	ldil	L%$global$, %dp | |
| 122 | 	ldo	R%$global$(%dp), %dp | |
| 123 | ||
| 124 | 	/* load main (1st argument) */ | |
| 125 | 	ldil	LR'.Lpmain, %r26 | |
| 126 | 	ldw	RR'.Lpmain(%r26), %r26 | |
| 127 | 	/* void (*init) (void) (4th argument) */ | |
| 128 | 	ldil	LR'.Lp__libc_csu_init, %r23 | |
| 129 | 	ldw	RR'.Lp__libc_csu_init(%r23), %r23 | |
| 130 | 	/* void (*fini) (void) (5th argument) */ | |
| 131 | 	ldil	LR'.Lp__libc_csu_fini, %r22 | |
| 132 | 	ldw	RR'.Lp__libc_csu_fini(%r22), %r22 | |
| 133 | #endif | |
| 134 | 	/* Store 5th argument */ | |
| 135 | 	stw	%r22, -52(%sp) | |
| 136 | 	/* void *stack_end (7th argument) */ | |
| 137 | 	stw	%sp, -60(%sp) | |
| 138 | 	bl	__libc_start_main,%r2 | |
| 139 | 	nop | |
| 140 | 	/* die horribly if it returned (it shouldn't) */ | |
| 141 | 	iitlbp %r0,(%sr0,%r0) | |
| 142 | 	nop | |
| 143 | ||
| 144 | 	.procend | |
| 145 | ||
| 146 | /* Define a symbol for the first piece of initialized data. */ | |
| 147 | 	.data | |
| 148 | 	.globl __data_start | |
| 149 | __data_start: | |
| 150 | 	.long 0 | |
| 151 | 	.weak data_start | |
| 152 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/i386/start-2-33.S created+151| ... | ... | @@ -0,0 +1,151 @@ |
| 1 | /* Startup code compliant to the ELF i386 ABI. | |
| 2 | Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library; if not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | /* This is the canonical entry point, usually the first thing in the text | |
| 37 | segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry | |
| 38 | point runs, most registers' values are unspecified, except for: | |
| 39 | ||
| 40 | %edx		Contains a function pointer to be registered with `atexit'. | |
| 41 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 42 | 		functions called for shared libraries that have been loaded | |
| 43 | 		before this code runs. | |
| 44 | ||
| 45 | %esp		The stack contains the arguments and environment: | |
| 46 | 		0(%esp)			argc | |
| 47 | 		4(%esp)			argv[0] | |
| 48 | 		... | |
| 49 | 		(4*argc)(%esp)		NULL | |
| 50 | 		(4*(argc+1))(%esp)	envp[0] | |
| 51 | 		... | |
| 52 | 					NULL | |
| 53 | */ | |
| 54 | ||
| 55 | #include <sysdep.h> | |
| 56 | ||
| 57 | ENTRY (_start) | |
| 58 | 	/* Clearing frame pointer is insufficient, use CFI. */ | |
| 59 | 	cfi_undefined (eip) | |
| 60 | 	/* Clear the frame pointer. The ABI suggests this be done, to mark | |
| 61 | 	 the outermost frame obviously. */ | |
| 62 | 	xorl %ebp, %ebp | |
| 63 | ||
| 64 | 	/* Extract the arguments as encoded on the stack and set up | |
| 65 | 	 the arguments for `main': argc, argv. envp will be determined | |
| 66 | 	 later in __libc_start_main. */ | |
| 67 | 	popl %esi		/* Pop the argument count. */ | |
| 68 | 	movl %esp, %ecx		/* argv starts just at the current stack top.*/ | |
| 69 | ||
| 70 | 	/* Before pushing the arguments align the stack to a 16-byte | |
| 71 | 	(SSE needs 16-byte alignment) boundary to avoid penalties from | |
| 72 | 	misaligned accesses. Thanks to Edward Seidl <seidl@janed.com> | |
| 73 | 	for pointing this out. */ | |
| 74 | 	andl $0xfffffff0, %esp | |
| 75 | 	pushl %eax		/* Push garbage because we allocate | |
| 76 | 				 28 more bytes. */ | |
| 77 | ||
| 78 | 	/* Provide the highest stack address to the user code (for stacks | |
| 79 | 	 which grow downwards). */ | |
| 80 | 	pushl %esp | |
| 81 | ||
| 82 | 	pushl %edx		/* Push address of the shared library | |
| 83 | 				 termination function. */ | |
| 84 | ||
| 85 | #ifdef PIC | |
| 86 | 	/* Load PIC register. */ | |
| 87 | 	call 1f | |
| 88 | 	addl $_GLOBAL_OFFSET_TABLE_, %ebx | |
| 89 | ||
| 90 | 	/* Push address of our own entry points to .fini and .init. */ | |
| 91 | 	leal __libc_csu_fini@GOTOFF(%ebx), %eax | |
| 92 | 	pushl %eax | |
| 93 | 	leal __libc_csu_init@GOTOFF(%ebx), %eax | |
| 94 | 	pushl %eax | |
| 95 | ||
| 96 | 	pushl %ecx		/* Push second argument: argv. */ | |
| 97 | 	pushl %esi		/* Push first argument: argc. */ | |
| 98 | ||
| 99 | # ifdef SHARED | |
| 100 | 	pushl main@GOT(%ebx) | |
| 101 | # else | |
| 102 | 	/* Avoid relocation in static PIE since _start is called before | |
| 103 | 	 it is relocated. Don't use "leal main@GOTOFF(%ebx), %eax" | |
| 104 | 	 since main may be in a shared object. Linker will convert | |
| 105 | 	 "movl main@GOT(%ebx), %eax" to "leal main@GOTOFF(%ebx), %eax" | |
| 106 | 	 if main is defined locally. */ | |
| 107 | 	movl main@GOT(%ebx), %eax | |
| 108 | 	pushl %eax | |
| 109 | # endif | |
| 110 | ||
| 111 | 	/* Call the user's main function, and exit with its value. | |
| 112 | 	 But let the libc call main. */ | |
| 113 | 	call __libc_start_main@PLT | |
| 114 | #else | |
| 115 | 	/* Push address of our own entry points to .fini and .init. */ | |
| 116 | 	pushl $__libc_csu_fini | |
| 117 | 	pushl $__libc_csu_init | |
| 118 | ||
| 119 | 	pushl %ecx		/* Push second argument: argv. */ | |
| 120 | 	pushl %esi		/* Push first argument: argc. */ | |
| 121 | ||
| 122 | 	pushl $main | |
| 123 | ||
| 124 | 	/* Call the user's main function, and exit with its value. | |
| 125 | 	 But let the libc call main. */ | |
| 126 | 	call __libc_start_main | |
| 127 | #endif | |
| 128 | ||
| 129 | 	hlt			/* Crash if somehow `exit' does return. */ | |
| 130 | ||
| 131 | #ifdef PIC | |
| 132 | 1:	movl	(%esp), %ebx | |
| 133 | 	ret | |
| 134 | #endif | |
| 135 | END (_start) | |
| 136 | ||
| 137 | /* To fulfill the System V/i386 ABI we need this symbol. Yuck, it's so | |
| 138 | meaningless since we don't support machines < 80386. */ | |
| 139 | 	.section .rodata | |
| 140 | 	.globl _fp_hw | |
| 141 | _fp_hw:	.long 3 | |
| 142 | 	.size _fp_hw, 4 | |
| 143 | 	.type _fp_hw,@object | |
| 144 | ||
| 145 | /* Define a symbol for the first piece of initialized data. */ | |
| 146 | 	.data | |
| 147 | 	.globl __data_start | |
| 148 | __data_start: | |
| 149 | 	.long 0 | |
| 150 | 	.weak data_start | |
| 151 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/ia64/start-2-33.S created+118| ... | ... | @@ -0,0 +1,118 @@ |
| 1 | /* Copyright (C) 1999-2020 Free Software Foundation, Inc. | |
| 2 | This file is part of the GNU C Library. | |
| 3 | Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library; if not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | #include <sysdep.h> | |
| 37 | ||
| 38 | #include <asm/fpu.h> | |
| 39 | ||
| 40 | /* | |
| 41 | * Arguments for __libc_start_main: | |
| 42 | *	out0:	main | |
| 43 | *	out1:	argc | |
| 44 | *	out2:	argv | |
| 45 | *	out3:	init | |
| 46 | *	out4:	fini | |
| 47 | *	out5:	rtld_fini | |
| 48 | *	out6:	stack_end | |
| 49 | */ | |
| 50 | ||
| 51 | 	.align 32 | |
| 52 | 	.global _start | |
| 53 | ||
| 54 | 	.proc _start | |
| 55 | 	.type _start,@function | |
| 56 | _start: | |
| 57 | 	.prologue | |
| 58 | 	.save rp, r0 | |
| 59 | 	.body | |
| 60 | 	.prologue | |
| 61 | 	{ .mlx | |
| 62 | 	 alloc r2 = ar.pfs,0,0,7,0 | |
| 63 | 	 movl r3 = FPSR_DEFAULT | |
| 64 | 	} | |
| 65 | 	{ .mlx | |
| 66 | 	 adds out2 = 16, sp	/* get address of argc value */ | |
| 67 | 	 movl gp = @gprel(0f) | |
| 68 | 	 ;; | |
| 69 | 	} | |
| 70 | 0:	{ .mmi | |
| 71 | 	 ld8 out1 = [out2], 8	/* load argc and move out2 to become argv */ | |
| 72 | 	 mov.m r10 = ar.bsp	/* fetch rbs base address */ | |
| 73 | 	 mov r9 = ip | |
| 74 | 	 ;; | |
| 75 | 	} | |
| 76 | 	{ .mii | |
| 77 | 	 mov ar.fpsr = r3 | |
| 78 | 	 sub gp = r9, gp	/* back-compute gp value */ | |
| 79 | 	 adds out6 = 16, sp	/* highest non-environment stack address */ | |
| 80 | 	 ;; | |
| 81 | 	} | |
| 82 | 	{ | |
| 83 | 	 addl r11 = @ltoff(__libc_ia64_register_backing_store_base), gp | |
| 84 | 	 addl out0 = @ltoff(@fptr(main)), gp | |
| 85 | 	 addl out3 = @ltoff(@fptr(__libc_csu_init)), gp | |
| 86 | 	 ;; | |
| 87 | 	} | |
| 88 | 	{ .mmi | |
| 89 | 	 ld8 r3 = [r11]	/* pointer to __libc_ia64_register_backing_store_base */ | |
| 90 | 	 ld8 out0 = [out0]	/* pointer to `main' function descriptor */ | |
| 91 | 	 addl out4 = @ltoff(@fptr(__libc_csu_fini)), gp | |
| 92 | 	 ;; | |
| 93 | 	} | |
| 94 | 	{ .mmi | |
| 95 | 	 ld8 out3 = [out3]	/* pointer to `init' function descriptor */ | |
| 96 | 	 ld8 out4 = [out4]	/* pointer to `fini' function descriptor */ | |
| 97 | 	 nop 0 | |
| 98 | 	} | |
| 99 | 	.body | |
| 100 | 	{ .mib | |
| 101 | 	 st8 [r3] = r10 | |
| 102 | 	 mov out5 = ret0	/* dynamic linker destructor */ | |
| 103 | 	 br.call.sptk.few rp = __libc_start_main | |
| 104 | 	} | |
| 105 | 	{ .mib | |
| 106 | 	 break 0	/* break miserably if we ever return */ | |
| 107 | 	} | |
| 108 | 	.endp _start | |
| 109 | ||
| 110 | /* Define a symbol for the first piece of initialized data. */ | |
| 111 | 	.data | |
| 112 | 	.globl __data_start | |
| 113 | __data_start: | |
| 114 | 	.long 0 | |
| 115 | 	.weak data_start | |
| 116 | 	data_start = __data_start | |
| 117 | ||
| 118 | 	.common __libc_ia64_register_backing_store_base, 8, 8 |
lib/libc/glibc/sysdeps/m68k/start-2-33.S created+120| ... | ... | @@ -0,0 +1,120 @@ |
| 1 | /* Startup code compliant to the ELF m68k ABI. | |
| 2 | Copyright (C) 1996-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library. If not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | /* This is the canonical entry point, usually the first thing in the text | |
| 37 | segment. The SVR4/m68k ABI says that when the entry point runs, | |
| 38 | most registers' values are unspecified, except for: | |
| 39 | ||
| 40 | %a1		Contains a function pointer to be registered with `atexit'. | |
| 41 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 42 | 		functions called for shared libraries that have been loaded | |
| 43 | 		before this code runs. | |
| 44 | ||
| 45 | %sp		The stack contains the arguments and environment: | |
| 46 | 		0(%sp)			argc | |
| 47 | 		4(%sp)			argv[0] | |
| 48 | 		... | |
| 49 | 		(4*argc)(%sp)		NULL | |
| 50 | 		(4*(argc+1))(%sp)	envp[0] | |
| 51 | 		... | |
| 52 | 					NULL | |
| 53 | */ | |
| 54 | ||
| 55 | #include <sysdep.h> | |
| 56 | ||
| 57 | 	.text | |
| 58 | 	.globl _start | |
| 59 | 	.type _start,@function | |
| 60 | _start: | |
| 61 | 	/* Clear the frame pointer. The ABI suggests this be done, to mark | |
| 62 | 	 the outermost frame obviously. */ | |
| 63 | 	sub.l %fp, %fp | |
| 64 | ||
| 65 | 	/* Extract the arguments as encoded on the stack and set up the | |
| 66 | 	 arguments for `main': argc, argv. envp will be determined | |
| 67 | 	 later in __libc_start_main. */ | |
| 68 | 	move.l (%sp)+, %d0	/* Pop the argument count. */ | |
| 69 | 	move.l %sp, %a0		/* The argument vector starts just at the | |
| 70 | 				 current stack top. */ | |
| 71 | ||
| 72 | 	/* Provide the highest stack address to the user code (for stacks | |
| 73 | 	 which grow downward). */ | |
| 74 | 	pea (%sp) | |
| 75 | ||
| 76 | 	pea (%a1)		/* Push address of the shared library | |
| 77 | 				 termination function. */ | |
| 78 | ||
| 79 | #ifdef PIC | |
| 80 | 	/* Load PIC register. */ | |
| 81 | 	LOAD_GOT (%a5) | |
| 82 | ||
| 83 | 	/* Push the address of our own entry points to `.fini' and | |
| 84 | 	 `.init'. */ | |
| 85 | 	move.l __libc_csu_fini@GOT(%a5), -(%sp) | |
| 86 | 	move.l __libc_csu_init@GOT(%a5), -(%sp) | |
| 87 | ||
| 88 | 	pea (%a0)		/* Push second argument: argv. */ | |
| 89 | 	move.l %d0, -(%sp)	/* Push first argument: argc. */ | |
| 90 | ||
| 91 | 	move.l main@GOT(%a5), -(%sp) | |
| 92 | ||
| 93 | 	/* Call the user's main function, and exit with its value. But | |
| 94 | 	 let the libc call main. */ | |
| 95 | 	jbsr __libc_start_main@PLTPC | |
| 96 | #else | |
| 97 | 	/* Push the address of our own entry points to `.fini' and | |
| 98 | 	 `.init'. */ | |
| 99 | 	pea __libc_csu_fini | |
| 100 | 	pea __libc_csu_init | |
| 101 | ||
| 102 | 	pea (%a0)		/* Push second argument: argv. */ | |
| 103 | 	move.l %d0, -(%sp)	/* Push first argument: argc. */ | |
| 104 | ||
| 105 | 	pea main | |
| 106 | ||
| 107 | 	/* Call the user's main function, and exit with its value. But | |
| 108 | 	 let the libc call main. */ | |
| 109 | 	jbsr __libc_start_main | |
| 110 | #endif | |
| 111 | ||
| 112 | 	illegal			/* Crash if somehow `exit' does return. */ | |
| 113 | ||
| 114 | /* Define a symbol for the first piece of initialized data. */ | |
| 115 | 	.data | |
| 116 | 	.globl __data_start | |
| 117 | __data_start: | |
| 118 | 	.long 0 | |
| 119 | 	.weak data_start | |
| 120 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/microblaze/start-2-33.S created+84| ... | ... | @@ -0,0 +1,84 @@ |
| 1 | /* Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
| 2 | ||
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library. If not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | .text | |
| 37 | .globl _start | |
| 38 | .type _start,@function | |
| 39 | _start: | |
| 40 | /* On entry the stack contains the following args: | |
| 41 | r1+0 - argc | |
| 42 | r1+4 - argv[0] | |
| 43 | ... | |
| 44 | r1+4*(argc-1) - argv[argc-1] | |
| 45 | r1+4*argc - NULL | |
| 46 | r1+4*argc + 4 - envp[0] | |
| 47 | ... | |
| 48 | NULL | |
| 49 | */ | |
| 50 | addk r3,r0,r0 | |
| 51 | addk r5,r1,r0 | |
| 52 | 1: | |
| 53 | addik r5,r5,4 | |
| 54 | lw r4,r5,r0 | |
| 55 | bneid r4,1b | |
| 56 | addik r3,r3,1 | |
| 57 | addik r6,r3,-1 | |
| 58 | sw r6,r1,r0 | |
| 59 | addik r7,r1,4 | |
| 60 | addik r1,r1,-24 | |
| 61 | #ifdef SHARED | |
| 62 | /* Setup PIC. */ | |
| 63 | mfs r20,rpc | |
| 64 | addik r20,r20,_GLOBAL_OFFSET_TABLE_+8 | |
| 65 | lwi r5,r20,main@GOT | |
| 66 | lwi r8,r20,__libc_csu_init@GOT | |
| 67 | lwi r9,r20,__libc_csu_fini@GOT | |
| 68 | brid __libc_start_main@PLT | |
| 69 | addk r10,r0,r0 | |
| 70 | #else | |
| 71 | addik r5,r0,main | |
| 72 | addik r8,r0,__libc_csu_init | |
| 73 | addik r9,r0,__libc_csu_fini | |
| 74 | brid __libc_start_main | |
| 75 | addk r10,r0,r0 | |
| 76 | #endif | |
| 77 | ||
| 78 | /* Define a symbol for the first piece of initialized data. */ | |
| 79 | .data | |
| 80 | .globl __data_start | |
| 81 | __data_start: | |
| 82 | .long 0 | |
| 83 | .weak data_start | |
| 84 | data_start = __data_start |
lib/libc/glibc/sysdeps/mips/start-2-33.S created+185| ... | ... | @@ -0,0 +1,185 @@ |
| 1 | /* Startup code compliant to the ELF Mips ABI. | |
| 2 | Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library. If not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | #define __ASSEMBLY__ 1 | |
| 37 | #include <entry.h> | |
| 38 | #include <sgidefs.h> | |
| 39 | #include <sys/asm.h> | |
| 40 | ||
| 41 | #ifndef ENTRY_POINT | |
| 42 | #error ENTRY_POINT needs to be defined for start.S on MIPS/ELF. | |
| 43 | #endif | |
| 44 | ||
| 45 | /* This is the canonical entry point, usually the first thing in the text | |
| 46 | segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry | |
| 47 | point runs, most registers' values are unspecified, except for: | |
| 48 | ||
| 49 | v0 ($2)	Contains a function pointer to be registered with `atexit'. | |
| 50 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 51 | 		functions called for shared libraries that have been loaded | |
| 52 | 		before this code runs. | |
| 53 | ||
| 54 | sp ($29)	The stack contains the arguments and environment: | |
| 55 | 		0(%esp)			argc | |
| 56 | 		4(%esp)			argv[0] | |
| 57 | 		... | |
| 58 | 		(4*argc)(%esp)		NULL | |
| 59 | 		(4*(argc+1))(%esp)	envp[0] | |
| 60 | 		... | |
| 61 | 					NULL | |
| 62 | ra ($31)	The return address register is set to zero so that programs | |
| 63 | 		that search backword through stack frames recognize the last | |
| 64 | 		stack frame. | |
| 65 | */ | |
| 66 | ||
| 67 | ||
| 68 | /* We need to call: | |
| 69 | __libc_start_main (int (*main) (int, char **, char **), int argc, | |
| 70 | 		 char **argv, void (*init) (void), void (*fini) (void), | |
| 71 | 		 void (*rtld_fini) (void), void *stack_end) | |
| 72 | */ | |
| 73 | ||
| 74 | 	.text | |
| 75 | 	.globl ENTRY_POINT | |
| 76 | 	.type ENTRY_POINT,@function | |
| 77 | #ifndef __mips16 | |
| 78 | ENTRY_POINT: | |
| 79 | # ifdef __PIC__ | |
| 80 | 	SETUP_GPX($0) | |
| 81 | 	SETUP_GPX64($25,$0) | |
| 82 | # else | |
| 83 | 	PTR_LA $28, _gp		/* Setup GP correctly if we're non-PIC. */ | |
| 84 | 	move $31, $0 | |
| 85 | # endif | |
| 86 | ||
| 87 | 	PTR_LA $4, main		/* main */ | |
| 88 | 	PTR_L $5, 0($29)		/* argc */ | |
| 89 | 	PTR_ADDIU $6, $29, PTRSIZE	/* argv */ | |
| 90 | ||
| 91 | 	/* Allocate space on the stack for seven arguments (o32 only) | |
| 92 | 	 and make sure the stack is aligned to double words (8 bytes) | |
| 93 | 	 on o32 and quad words (16 bytes) on n32 and n64. */ | |
| 94 | ||
| 95 | 	and $29, -2 * SZREG | |
| 96 | # if _MIPS_SIM == _ABIO32 | |
| 97 | 	PTR_SUBIU $29, 32 | |
| 98 | # endif | |
| 99 | 	PTR_LA $7, __libc_csu_init		/* init */ | |
| 100 | 	PTR_LA $8, __libc_csu_fini | |
| 101 | # if _MIPS_SIM == _ABIO32 | |
| 102 | 	PTR_S $8, 16($29)		/* fini */ | |
| 103 | 	PTR_S $2, 20($29)		/* rtld_fini */ | |
| 104 | 	PTR_S $29, 24($29)		/* stack_end */ | |
| 105 | # else | |
| 106 | 	move $9, $2		/* rtld_fini */ | |
| 107 | 	move $10, $29		/* stack_end */ | |
| 108 | # endif | |
| 109 | 	PTR_LA $25, __libc_start_main | |
| 110 | 	jalr $25 | |
| 111 | hlt:	b hlt			/* Crash if somehow it does return. */ | |
| 112 | ||
| 113 | #elif _MIPS_SIM == _ABIO32 /* __mips16 */ | |
| 114 | 	/* MIPS16 entry point. */ | |
| 115 | 	.set	mips16 | |
| 116 | ENTRY_POINT: | |
| 117 | # ifdef __PIC__ | |
| 118 | 	li	$3, %hi(_gp_disp) | |
| 119 | 	addiu	$4, $pc, %lo(_gp_disp) | |
| 120 | 	sll	$3, 16 | |
| 121 | 	addu	$3, $4 | |
| 122 | 	move	$gp, $3 | |
| 123 | # else | |
| 124 | 	li	$3, %hi(_gp) | |
| 125 | 	sll	$3, 16 | |
| 126 | 	addiu	$3, %lo(_gp) | |
| 127 | 	move	$gp, $3 | |
| 128 | # endif | |
| 129 | 	/* Tie end of stack frames. */ | |
| 130 | 	li	$4, 0 | |
| 131 | 	move	$31, $4 | |
| 132 | 	/* Create new SP value in $7, including alignment. */ | |
| 133 | 	li	$4, 2 * SZREG | |
| 134 | 	neg	$4, $4 | |
| 135 | 	move	$7, $sp | |
| 136 | 	and	$7, $4 | |
| 137 | 	addiu	$7, -32 | |
| 138 | 	/* Load arguments with original SP. */ | |
| 139 | 	lw	$5, 0($sp) | |
| 140 | 	addiu	$6, $sp, PTRSIZE | |
| 141 | 	/* Update SP. */ | |
| 142 | 	move	$sp, $7 | |
| 143 | 	/* Lay out last arguments, and call __libc_start_main(). */ | |
| 144 | # ifdef __PIC__ | |
| 145 | 	sw	$7, 24($sp)			/* stack_end */ | |
| 146 | 	lw	$4, %got(__libc_csu_fini)($3) | |
| 147 | 	lw	$7, %got(__libc_csu_init)($3)	/* init */ | |
| 148 | 	sw	$4, 16($sp)			/* fini */ | |
| 149 | 	lw	$4, %got(main)($3)		/* main */ | |
| 150 | 	lw	$3, %call16(__libc_start_main)($3) | |
| 151 | 	sw	$2, 20($sp)			/* rtld_fini */ | |
| 152 | 	move	$25, $3 | |
| 153 | 	jalr	$3 | |
| 154 | # else | |
| 155 | 	lw	$4, 1f | |
| 156 | 	sw	$7, 24($sp)			/* stack_end */ | |
| 157 | 	lw	$7, 2f				/* init */ | |
| 158 | 	sw	$4, 16($sp)			/* fini */ | |
| 159 | 	lw	$4, 3f				/* main */ | |
| 160 | 	sw	$2, 20($sp)			/* rtld_fini */ | |
| 161 | 	/* Load and call __libc_start_main(). */ | |
| 162 | 	lw	$3, 4f | |
| 163 | 	jalr	$3 | |
| 164 | # endif | |
| 165 | hlt:	b	hlt		/* Crash if somehow it does return. */ | |
| 166 | # ifndef __PIC__ | |
| 167 | 	.align	2 | |
| 168 | 1:	.word	__libc_csu_fini | |
| 169 | 2:	.word	__libc_csu_init | |
| 170 | 3:	.word	main | |
| 171 | 4:	.word	__libc_start_main | |
| 172 | # endif | |
| 173 | ||
| 174 | #else /* __mips16 && _MIPS_SIM != _ABIO32 */ | |
| 175 | # error "MIPS16 support for N32/N64 not implemented" | |
| 176 | ||
| 177 | #endif /* __mips16 */ | |
| 178 | ||
| 179 | /* Define a symbol for the first piece of initialized data. */ | |
| 180 | 	.data | |
| 181 | 	.globl __data_start | |
| 182 | __data_start: | |
| 183 | 	.long 0 | |
| 184 | 	.weak data_start | |
| 185 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/powerpc/powerpc32/start-2-33.S created+95| ... | ... | @@ -0,0 +1,95 @@ |
| 1 | /* Startup code for programs linked with GNU libc. | |
| 2 | Copyright (C) 1998-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library; if not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | #include <sysdep.h> | |
| 37 | ||
| 38 | /* We do not want .eh_frame info for crt1.o since crt1.o is linked | |
| 39 | before crtbegin.o, the file defining __EH_FRAME_BEGIN__. */ | |
| 40 | #undef cfi_startproc | |
| 41 | #define cfi_startproc | |
| 42 | #undef cfi_endproc | |
| 43 | #define cfi_endproc | |
| 44 | ||
| 45 | /* These are the various addresses we require. */ | |
| 46 | #ifdef PIC | |
| 47 | 	.section ".data" | |
| 48 | #else | |
| 49 | 	.section ".rodata" | |
| 50 | #endif | |
| 51 | 	.align	2 | |
| 52 | L(start_addresses): | |
| 53 | 	.long	_SDA_BASE_ | |
| 54 | 	.long	main | |
| 55 | 	.long 	__libc_csu_init | |
| 56 | 	.long 	__libc_csu_fini | |
| 57 | 	ASM_SIZE_DIRECTIVE(L(start_addresses)) | |
| 58 | ||
| 59 | 	.section ".text" | |
| 60 | ENTRY(_start) | |
| 61 | /* Save the stack pointer, in case we're statically linked under Linux. */ | |
| 62 | 	mr	r9,r1 | |
| 63 | /* Set up an initial stack frame, and clear the LR. */ | |
| 64 | 	clrrwi	r1,r1,4 | |
| 65 | #ifdef PIC | |
| 66 | 	SETUP_GOT_ACCESS(r13,got_label) | |
| 67 | 	li	r0,0 | |
| 68 | #else | |
| 69 | 	li	r0,0 | |
| 70 | #endif | |
| 71 | 	stwu	r1,-16(r1) | |
| 72 | 	mtlr	r0 | |
| 73 | 	stw	r0,0(r1) | |
| 74 | /* Set r13 to point at the 'small data area', and put the address of | |
| 75 | start_addresses in r8. Also load the GOT pointer so that new PLT | |
| 76 | calls work, like the one to __libc_start_main. */ | |
| 77 | #ifdef PIC | |
| 78 | 	addis	r30,r13,_GLOBAL_OFFSET_TABLE_-got_label@ha | |
| 79 | 	addis	r8,r13,L(start_addresses)-got_label@ha | |
| 80 | 	addi	r30,r30,_GLOBAL_OFFSET_TABLE_-got_label@l | |
| 81 | 	lwzu	r13, L(start_addresses)-got_label@l(r8) | |
| 82 | #else | |
| 83 | 	lis	r8,L(start_addresses)@ha | |
| 84 | 	lwzu	r13,L(start_addresses)@l(r8) | |
| 85 | #endif | |
| 86 | /* and continue in libc-start, in glibc. */ | |
| 87 | 	b	JUMPTARGET(__libc_start_main) | |
| 88 | END(_start) | |
| 89 | ||
| 90 | /* Define a symbol for the first piece of initialized data. */ | |
| 91 | 	.section ".data" | |
| 92 | 	.globl	__data_start | |
| 93 | __data_start: | |
| 94 | 	.long	0 | |
| 95 | weak_alias (__data_start, data_start) |
lib/libc/glibc/sysdeps/powerpc/powerpc64/start-2-33.S created+92| ... | ... | @@ -0,0 +1,92 @@ |
| 1 | /* Startup code for programs linked with GNU libc. PowerPC64 version. | |
| 2 | Copyright (C) 1998-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library; if not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | #include <sysdep.h> | |
| 37 | ||
| 38 | /* We do not want .eh_frame info for crt1.o since crt1.o is linked | |
| 39 | before crtbegin.o, the file defining __EH_FRAME_BEGIN__. */ | |
| 40 | #undef cfi_startproc | |
| 41 | #define cfi_startproc | |
| 42 | #undef cfi_endproc | |
| 43 | #define cfi_endproc | |
| 44 | ||
| 45 | /* These are the various addresses we require. */ | |
| 46 | #ifdef PIC | |
| 47 | 	.section ".data.rel.ro.local","aw" | |
| 48 | #else | |
| 49 | 	.section ".rodata" | |
| 50 | #endif | |
| 51 | 	.align	3 | |
| 52 | L(start_addresses): | |
| 53 | 	.quad	0 /* was _SDA_BASE_ but not in 64-bit ABI*/ | |
| 54 | /* function descriptors so don't need JUMPTARGET */ | |
| 55 | 	.quad	main | |
| 56 | 	.quad 	__libc_csu_init | |
| 57 | 	.quad 	__libc_csu_fini | |
| 58 | ||
| 59 | 	ASM_SIZE_DIRECTIVE(L(start_addresses)) | |
| 60 | ||
| 61 | 	.section	".toc","aw" | |
| 62 | .L01: | |
| 63 | 	.tc	L(start_addresses)[TC],L(start_addresses) | |
| 64 | 	.section ".text" | |
| 65 | ENTRY (_start) | |
| 66 | /* Save the stack pointer, in case we're statically linked under Linux. */ | |
| 67 | 	mr	r9,r1 | |
| 68 | /* Set up an initial stack frame, and clear the LR. */ | |
| 69 | 	clrrdi	r1,r1,4 | |
| 70 | 	li	r0,0 | |
| 71 | 	stdu	r1,-128(r1) | |
| 72 | 	mtlr	r0 | |
| 73 | 	std	r0,0(r1) | |
| 74 | ||
| 75 | /* put the address of start_addresses in r8... ** | |
| 76 | ** PPC64 ABI uses R13 for thread local, so we leave it alone */ | |
| 77 | 	ld	r8,.L01@toc(r2) | |
| 78 | ||
| 79 | /* and continue in libc-start, in glibc. */ | |
| 80 | 	b	JUMPTARGET(__libc_start_main) | |
| 81 | /* Older versions of ld need this nop to recognize that it's OK to call via a | |
| 82 | TOC adjusting stub. */ | |
| 83 | 	nop | |
| 84 | ||
| 85 | END(_start) | |
| 86 | ||
| 87 | /* Define a symbol for the first piece of initialized data. */ | |
| 88 | 	.section ".data" | |
| 89 | 	.globl	__data_start | |
| 90 | __data_start: | |
| 91 | 	.long	0 | |
| 92 | weak_alias (__data_start, data_start) |
lib/libc/glibc/sysdeps/riscv/start-2-33.S created+86| ... | ... | @@ -0,0 +1,86 @@ |
| 1 | /* Startup code compliant to the ELF RISC-V ABI. | |
| 2 | Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library. If not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | #define __ASSEMBLY__ 1 | |
| 37 | #include <entry.h> | |
| 38 | #include <sysdep.h> | |
| 39 | #include <sys/asm.h> | |
| 40 | ||
| 41 | /* The entry point's job is to call __libc_start_main. Per the ABI, | |
| 42 | a0 contains the address of a function to be passed to atexit. | |
| 43 | __libc_start_main wants this in a5. */ | |
| 44 | ||
| 45 | ENTRY (ENTRY_POINT) | |
| 46 | 	/* Terminate call stack by noting ra is undefined. Use a dummy | |
| 47 | 	 .cfi_label to force starting the FDE. */ | |
| 48 | 	.cfi_label .Ldummy | |
| 49 | 	cfi_undefined (ra) | |
| 50 | 	call load_gp | |
| 51 | 	mv a5, a0 /* rtld_fini. */ | |
| 52 | 	/* main may be in a shared library. */ | |
| 53 | 	la a0, main | |
| 54 | 	REG_L a1, 0(sp) /* argc. */ | |
| 55 | 	addi a2, sp, SZREG /* argv. */ | |
| 56 | 	andi sp, sp, ALMASK /* Align stack. */ | |
| 57 | 	lla a3, __libc_csu_init | |
| 58 | 	lla a4, __libc_csu_fini | |
| 59 | 	mv a6, sp /* stack_end. */ | |
| 60 | ||
| 61 | 	call __libc_start_main@plt | |
| 62 | 	ebreak | |
| 63 | END (ENTRY_POINT) | |
| 64 | ||
| 65 | /* Dynamic links need the global pointer to be initialized prior to calling | |
| 66 | any shared library's initializers, so we use preinit_array to load it. | |
| 67 | This doesn't cut it for static links, though, since the global pointer | |
| 68 | needs to be initialized before calling __libc_start_main in that case. | |
| 69 | So we redundantly initialize it at the beginning of _start. */ | |
| 70 | ||
| 71 | load_gp: | |
| 72 | .option push | |
| 73 | .option norelax | |
| 74 | 	lla gp, __global_pointer$ | |
| 75 | .option pop | |
| 76 | 	ret | |
| 77 | ||
| 78 | 	.section .preinit_array,"aw" | |
| 79 | 	.dc.a load_gp | |
| 80 | ||
| 81 | /* Define a symbol for the first piece of initialized data. */ | |
| 82 | 	.data | |
| 83 | 	.globl __data_start | |
| 84 | __data_start: | |
| 85 | 	.weak data_start | |
| 86 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/s390/s390-32/start-2-33.S created+218| ... | ... | @@ -0,0 +1,218 @@ |
| 1 | /* Startup code compliant to the ELF s390 ABI. | |
| 2 | Copyright (C) 2000-2020 Free Software Foundation, Inc. | |
| 3 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). | |
| 4 | This file is part of the GNU C Library. | |
| 5 | ||
| 6 | The GNU C Library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | In addition to the permissions in the GNU Lesser General Public | |
| 12 | License, the Free Software Foundation gives you unlimited | |
| 13 | permission to link the compiled version of this file with other | |
| 14 | programs, and to distribute those programs without any restriction | |
| 15 | coming from the use of this file. (The GNU Lesser General Public | |
| 16 | License restrictions do apply in other respects; for example, they | |
| 17 | cover modification of the file, and distribution when not linked | |
| 18 | into another program.) | |
| 19 | ||
| 20 | Note that people who make modified versions of this file are not | |
| 21 | obligated to grant this special exception for their modified | |
| 22 | versions; it is their choice whether to do so. The GNU Lesser | |
| 23 | General Public License gives permission to release a modified | |
| 24 | version without this exception; this exception also makes it | |
| 25 | possible to release a modified version which carries forward this | |
| 26 | exception. | |
| 27 | ||
| 28 | The GNU C Library is distributed in the hope that it will be useful, | |
| 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 31 | Lesser General Public License for more details. | |
| 32 | ||
| 33 | You should have received a copy of the GNU Lesser General Public | |
| 34 | License along with the GNU C Library; if not, see | |
| 35 | <https://www.gnu.org/licenses/>. */ | |
| 36 | ||
| 37 | #include <sysdep.h> | |
| 38 | ||
| 39 | /* | |
| 40 | This is the canonical entry point, usually the first thing in the text | |
| 41 | segment. Most registers' values are unspecified, except for: | |
| 42 | ||
| 43 | %r14 Contains a function pointer to be registered with `atexit'. | |
| 44 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 45 | 		functions called for shared libraries that have been loaded | |
| 46 | 		before this code runs. | |
| 47 | ||
| 48 | %r15		The stack contains the arguments and environment: | |
| 49 | 		0(%r15)			argc | |
| 50 | 		4(%r15)			argv[0] | |
| 51 | 		... | |
| 52 | 		(4*argc)(%r15)		NULL | |
| 53 | 		(4*(argc+1))(%r15)	envp[0] | |
| 54 | 		... | |
| 55 | 					NULL | |
| 56 | */ | |
| 57 | ||
| 58 | 	.text | |
| 59 | 	.globl _start | |
| 60 | 	.type _start,@function | |
| 61 | _start: | |
| 62 | 	cfi_startproc | |
| 63 | 	/* Mark r14 as undefined in order to stop unwinding here! */ | |
| 64 | 	cfi_undefined (r14) | |
| 65 | ||
| 66 | 	/* Check if the kernel provides highgprs facility if needed by | |
| 67 | 	 the binary. */ | |
| 68 | ||
| 69 | 	lr	%r6,%r15 | |
| 70 | 	la	%r6,4(%r6) /* Skip the argument counter. */ | |
| 71 | ||
| 72 | .L11:	l	%r5,0(%r6) /* Skip the argument vector. */ | |
| 73 | 	la	%r6,4(%r6) | |
| 74 | 	ltr	%r5,%r5 | |
| 75 | 	jne	.L11 | |
| 76 | ||
| 77 | .L12:	l	%r5,0(%r6) /* Skip the environment vector. */ | |
| 78 | 	la	%r6,4(%r6) | |
| 79 | 	ltr	%r5,%r5 | |
| 80 | 	jne	.L12 | |
| 81 | ||
| 82 | 	/* Usually the auxiliary vector can be expected directly after | |
| 83 | 	 the environment variables. But we have to skip extra zeros | |
| 84 | 	 because the loader might have removed unsecure variables for | |
| 85 | 	 setuid programs. */ | |
| 86 | ||
| 87 | .L26:	l	%r5,0(%r6) | |
| 88 | 	la	%r6,4(%r6) | |
| 89 | 	ltr	%r5,%r5 | |
| 90 | 	jz	.L26 | |
| 91 | ||
| 92 | 	ahi	%r6,-4 | |
| 93 | ||
| 94 | 	/* Obtain the needed values from the auxiliary vector. */ | |
| 95 | ||
| 96 | 	lhi	%r7,16	 /* AT_HWCAP */ | |
| 97 | 	lhi	%r8,3	 /* AT_PHDR */ | |
| 98 | 	lhi	%r9,5 /* AT_PHNUM */ | |
| 99 | 	lhi	%r2,4 /* AT_PHENT */ | |
| 100 | .L13:	l	%r5,0(%r6) | |
| 101 | 	clr	%r5,%r7 | |
| 102 | 	jne	.L15 | |
| 103 | 	l	%r10,4(%r6) /* r10 = AT_HWCAP value. */ | |
| 104 | .L15:	clr	%r5,%r8 | |
| 105 | 	jne	.L16 | |
| 106 | 	l	%r11,4(%r6) /* r11 = AT_PHDR value. */ | |
| 107 | .L16:	clr	%r5,%r9 | |
| 108 | 	jne	.L17 | |
| 109 | 	l	%r12,4(%r6) /* r12 = AT_PHNUM value. */ | |
| 110 | .L17:	clr	%r5,%r2 | |
| 111 | 	jne	.L18 | |
| 112 | 	l	%r0,4(%r6) /* r0 = AT_PHENT value. */ | |
| 113 | .L18:	ltr	%r5,%r5 | |
| 114 | 	la	%r6,8(%r6) | |
| 115 | 	jnz	.L13 | |
| 116 | ||
| 117 | 	/* Locate the ELF header by looking for the first PT_LOAD | |
| 118 | 	 segment with a p_offset of zero. */ | |
| 119 | ||
| 120 | 	lr	%r4,%r11 /* Backup AT_PHDR. */ | |
| 121 | 	lhi	%r7,1 /* PT_LOAD id */ | |
| 122 | 	lhi	%r8,0 | |
| 123 | .L19:	cl	%r7,0(%r4) /* p_type == PT_LOAD? */ | |
| 124 | 	jne	.L20 | |
| 125 | 	cl	%r8,4(%r4) /* p_offset == 0? */ | |
| 126 | 	jne	.L20 | |
| 127 | 	l	%r9,8(%r4) /* r9 = PT_LOAD.p_vaddr <- ELF header address */ | |
| 128 | 	j	.L24 | |
| 129 | .L20:	alr	%r4,%r0 /* r4 += AT_PHENT value */ | |
| 130 | 	brct	%r12,.L19 | |
| 131 | ||
| 132 | 	j	.+2 /* Trap, there must be such a phdr. */ | |
| 133 | ||
| 134 | .L24:	lr	%r4,%r11 /* Backup AT_PHDR. */ | |
| 135 | 	lhi	%r2,6 /* PT_PHDR id */ | |
| 136 | .L23:	cl	%r2,0(%r4) | |
| 137 | 	jne	.L22 | |
| 138 | 	l	%r3,8(%r4) /* r3 = PT_PHDR p_vaddr */ | |
| 139 | 	j	.L25 | |
| 140 | .L22:	alr	%r4,%r0 /* r4 += AT_PHENT value */ | |
| 141 | 	brct	%r12,.L23 | |
| 142 | ||
| 143 | 	j	.L14	 /* No PT_PHDR found - skip checking. */ | |
| 144 | ||
| 145 | .L25:	slr	%r11,%r3 /* AT_PHDR - PT_PHDR.p_vaddr (relocation offset)*/ | |
| 146 | 	alr	%r9,%r11 /* PT_LOAD.p_vaddr += relocation offset */ | |
| 147 | ||
| 148 | 	l	%r5,36(%r9) /* Load the e_flags field. */ | |
| 149 | 	tml	%r5,1 | |
| 150 | 	jz	.L14	 /* Binary does not require highgprs facility. */ | |
| 151 | ||
| 152 | 	tml	%r10,512 /* Check the AT_HWCAP value. */ | |
| 153 | 	jz	2 /* Trap if no highgprs facility available. */ | |
| 154 | .L14: | |
| 155 | ||
| 156 | 	/* Setup pointer to literal pool of _start */ | |
| 157 | 	basr %r13,0 | |
| 158 | .L0: ahi %r13,.Llit-.L0 | |
| 159 | ||
| 160 | 	/* load argc and argv from stack */ | |
| 161 | 	la %r4,4(%r15) # get argv | |
| 162 | 	l %r3,0(%r15) # get argc | |
| 163 | ||
| 164 | 	/* align the stack to a double word boundary */ | |
| 165 | 	lhi %r0,-8 | |
| 166 | 	nr %r15,%r0 | |
| 167 | ||
| 168 | 	/* Setup a stack frame and a parameter area */ | |
| 169 | 	ahi %r15,-104 # make room on stack | |
| 170 | 	xc 0(4,%r15),0(%r15) # clear back-chain | |
| 171 | ||
| 172 | 	/* set up arguments for __libc_start_main: | |
| 173 | 	 main, argc, argv, envp, _init, _fini, rtld_fini, stack_end | |
| 174 | 	 Note that envp will be determined later in __libc_start_main | |
| 175 | 	 */ | |
| 176 | 	stm %r14,%r15,96(%r15) # store rtld_fini/stack_end to parameter area | |
| 177 | 	la %r7,96(%r15) | |
| 178 | 	l %r6,.L2-.Llit(%r13) # load pointer to __libc_csu_fini | |
| 179 | 	l %r5,.L1-.Llit(%r13) # load pointer to __libc_csu_init | |
| 180 | 	l %r2,.L3-.Llit(%r13) # load pointer to main | |
| 181 | 	l %r1,.L4-.Llit(%r13)	# load pointer to __libc_start_main | |
| 182 | #ifdef PIC | |
| 183 | 	l %r12,.L5-.Llit(%r13) # load .got pointer | |
| 184 | 	la	%r6,0(%r13,%r6) | |
| 185 | 	la	%r5,0(%r13,%r5) | |
| 186 | 	la	%r12,0(%r13,%r12) | |
| 187 | 	l	%r2,0(%r12,%r2) | |
| 188 | 	la	%r1,0(%r13,%r1) | |
| 189 | #endif | |
| 190 | ||
| 191 | 	/* ok, now branch to the libc main routine */ | |
| 192 | 	basr %r14,%r1 | |
| 193 | ||
| 194 | 	/* crash if __libc_start_main returns */ | |
| 195 | 	.word 0 | |
| 196 | ||
| 197 | 	cfi_endproc | |
| 198 | .Llit: | |
| 199 | #ifndef PIC | |
| 200 | .L1: .long __libc_csu_init | |
| 201 | .L2: .long __libc_csu_fini | |
| 202 | .L3: .long main | |
| 203 | .L4: .long __libc_start_main | |
| 204 | #else | |
| 205 | .L1: .long __libc_csu_init-.Llit | |
| 206 | .L2: .long __libc_csu_fini-.Llit | |
| 207 | .L3: .long main@GOT | |
| 208 | .L4: .long __libc_start_main@plt-.Llit | |
| 209 | .L5: .long _GLOBAL_OFFSET_TABLE_-.Llit | |
| 210 | #endif | |
| 211 | ||
| 212 | /* Define a symbol for the first piece of initialized data. */ | |
| 213 | 	.data | |
| 214 | 	.globl __data_start | |
| 215 | __data_start: | |
| 216 | 	.long 0 | |
| 217 | 	.weak data_start | |
| 218 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/s390/s390-64/start-2-33.S created+107| ... | ... | @@ -0,0 +1,107 @@ |
| 1 | /* Startup code compliant to the 64 bit S/390 ELF ABI. | |
| 2 | Copyright (C) 2001-2020 Free Software Foundation, Inc. | |
| 3 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). | |
| 4 | This file is part of the GNU C Library. | |
| 5 | ||
| 6 | The GNU C Library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | In addition to the permissions in the GNU Lesser General Public | |
| 12 | License, the Free Software Foundation gives you unlimited | |
| 13 | permission to link the compiled version of this file with other | |
| 14 | programs, and to distribute those programs without any restriction | |
| 15 | coming from the use of this file. (The GNU Lesser General Public | |
| 16 | License restrictions do apply in other respects; for example, they | |
| 17 | cover modification of the file, and distribution when not linked | |
| 18 | into another program.) | |
| 19 | ||
| 20 | Note that people who make modified versions of this file are not | |
| 21 | obligated to grant this special exception for their modified | |
| 22 | versions; it is their choice whether to do so. The GNU Lesser | |
| 23 | General Public License gives permission to release a modified | |
| 24 | version without this exception; this exception also makes it | |
| 25 | possible to release a modified version which carries forward this | |
| 26 | exception. | |
| 27 | ||
| 28 | The GNU C Library is distributed in the hope that it will be useful, | |
| 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 31 | Lesser General Public License for more details. | |
| 32 | ||
| 33 | You should have received a copy of the GNU Lesser General Public | |
| 34 | License along with the GNU C Library; if not, see | |
| 35 | <https://www.gnu.org/licenses/>. */ | |
| 36 | ||
| 37 | #include <sysdep.h> | |
| 38 | ||
| 39 | /* | |
| 40 | This is the canonical entry point, usually the first thing in the text | |
| 41 | segment. Most registers' values are unspecified, except for: | |
| 42 | ||
| 43 | %r14		Contains a function pointer to be registered with `atexit'. | |
| 44 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 45 | 		functions called for shared libraries that have been loaded | |
| 46 | 		before this code runs. | |
| 47 | ||
| 48 | %r15		The stack contains the arguments and environment: | |
| 49 | 		0(%r15)			argc | |
| 50 | 		8(%r15)			argv[0] | |
| 51 | 		... | |
| 52 | 		(8*argc)(%r15)		NULL | |
| 53 | 		(8*(argc+1))(%r15)	envp[0] | |
| 54 | 		... | |
| 55 | 					NULL | |
| 56 | */ | |
| 57 | ||
| 58 | 	.text | |
| 59 | 	.globl _start | |
| 60 | 	.type _start,@function | |
| 61 | _start: | |
| 62 | 	cfi_startproc | |
| 63 | 	/* Mark r14 as undefined in order to stop unwinding here! */ | |
| 64 | 	cfi_undefined (r14) | |
| 65 | 	/* Load argc and argv from stack. */ | |
| 66 | 	la	%r4,8(%r15)		# get argv | |
| 67 | 	lg	%r3,0(%r15)		# get argc | |
| 68 | ||
| 69 | 	/* Align the stack to a double word boundary. */ | |
| 70 | 	lghi	%r0,-16 | |
| 71 | 	ngr	%r15,%r0 | |
| 72 | ||
| 73 | 	/* Setup a stack frame and a parameter area. */ | |
| 74 | 	aghi	%r15,-176		# make room on stack | |
| 75 | 	xc	0(8,%r15),0(%r15)	# clear back-chain | |
| 76 | ||
| 77 | 	/* Set up arguments for __libc_start_main: | |
| 78 | 	 main, argc, argv, envp, _init, _fini, rtld_fini, stack_end | |
| 79 | 	 Note that envp will be determined later in __libc_start_main. | |
| 80 | 	 */ | |
| 81 | 	stmg	%r14,%r15,160(%r15)	# store rtld_fini/stack_end to parameter area | |
| 82 | 	la	%r7,160(%r15) | |
| 83 | 	larl	%r6,__libc_csu_fini	# load pointer to __libc_csu_fini | |
| 84 | 	larl	%r5,__libc_csu_init	# load pointer to __libc_csu_init | |
| 85 | ||
| 86 | 	/* Ok, now branch to the libc main routine. */ | |
| 87 | #ifdef PIC | |
| 88 | 	larl	%r2,main@GOTENT		# load pointer to main | |
| 89 | 	lg	%r2,0(%r2) | |
| 90 | 	brasl	%r14,__libc_start_main@plt | |
| 91 | #else | |
| 92 | 	larl	%r2,main		# load pointer to main | |
| 93 | 	brasl	%r14,__libc_start_main | |
| 94 | #endif | |
| 95 | ||
| 96 | 	/* Crash if __libc_start_main returns.	*/ | |
| 97 | 	.word	0 | |
| 98 | ||
| 99 | 	cfi_endproc | |
| 100 | ||
| 101 | 	/* Define a symbol for the first piece of initialized data. */ | |
| 102 | 	.data | |
| 103 | 	.globl __data_start | |
| 104 | __data_start: | |
| 105 | 	.long 0 | |
| 106 | 	.weak data_start | |
| 107 | 	data_start = __data_start |
lib/libc/glibc/sysdeps/sh/start-2-33.S created+111| ... | ... | @@ -0,0 +1,111 @@ |
| 1 | /* Startup code for SH & ELF. | |
| 2 | Copyright (C) 1999-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | In addition to the permissions in the GNU Lesser General Public | |
| 11 | License, the Free Software Foundation gives you unlimited | |
| 12 | permission to link the compiled version of this file with other | |
| 13 | programs, and to distribute those programs without any restriction | |
| 14 | coming from the use of this file. (The GNU Lesser General Public | |
| 15 | License restrictions do apply in other respects; for example, they | |
| 16 | cover modification of the file, and distribution when not linked | |
| 17 | into another program.) | |
| 18 | ||
| 19 | Note that people who make modified versions of this file are not | |
| 20 | obligated to grant this special exception for their modified | |
| 21 | versions; it is their choice whether to do so. The GNU Lesser | |
| 22 | General Public License gives permission to release a modified | |
| 23 | version without this exception; this exception also makes it | |
| 24 | possible to release a modified version which carries forward this | |
| 25 | exception. | |
| 26 | ||
| 27 | The GNU C Library is distributed in the hope that it will be useful, | |
| 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 30 | Lesser General Public License for more details. | |
| 31 | ||
| 32 | You should have received a copy of the GNU Lesser General Public | |
| 33 | License along with the GNU C Library; if not, see | |
| 34 | <https://www.gnu.org/licenses/>. */ | |
| 35 | ||
| 36 | /* This is the canonical entry point, usually the first thing in the text | |
| 37 | segment. | |
| 38 | ||
| 39 | 	Note that the code in the .init section has already been run. | |
| 40 | 	This includes _init and _libc_init | |
| 41 | ||
| 42 | ||
| 43 | 	At this entry point, most registers' values are unspecified, except: | |
| 44 | ||
| 45 | r4		Contains a function pointer to be registered with `atexit'. | |
| 46 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 47 | 		functions called for shared libraries that have been loaded | |
| 48 | 		before this code runs. | |
| 49 | ||
| 50 | sp		The stack contains the arguments and environment: | |
| 51 | 		0(sp)			argc | |
| 52 | 		4(sp)			argv[0] | |
| 53 | 		... | |
| 54 | 		(4*argc)(sp)		NULL | |
| 55 | 		(4*(argc+1))(sp)	envp[0] | |
| 56 | 		... | |
| 57 | 					NULL | |
| 58 | */ | |
| 59 | ||
| 60 | 	.text | |
| 61 | 	.globl _start | |
| 62 | 	.type _start,@function | |
| 63 | _start: | |
| 64 | 	/* Clear the frame pointer since this is the outermost frame. */ | |
| 65 | 	mov #0, r14 | |
| 66 | ||
| 67 | 	/* Pop argc off the stack and save a pointer to argv */ | |
| 68 | 	mov.l @r15+,r5 | |
| 69 | 	mov r15, r6 | |
| 70 | ||
| 71 | 	/* Push the last arguments to main() onto the stack */ | |
| 72 | 	mov.l r4,@-r15 | |
| 73 | 	mov.l L_fini,r0 | |
| 74 | 	mov.l r0,@-r15 | |
| 75 | ||
| 76 | 	/* Set up the other arguments for main() that go in registers */ | |
| 77 | 	mov.l L_main,r4 | |
| 78 | 	mov.l L_init,r7 | |
| 79 | ||
| 80 | 	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini) */ | |
| 81 | ||
| 82 | 	/* Let the libc call main and exit with its return code. */ | |
| 83 | 	mov.l L_libc_start_main,r1 | |
| 84 | 	jsr @r1 | |
| 85 | 	nop | |
| 86 | 	/* should never get here....*/ | |
| 87 | 	mov.l L_abort,r1 | |
| 88 | 	jsr @r1 | |
| 89 | 	nop | |
| 90 | 	.align	2 | |
| 91 | L_main: | |
| 92 | 	.long	main | |
| 93 | L_init: | |
| 94 | 	.long	__libc_csu_init | |
| 95 | L_fini: | |
| 96 | 	.long	__libc_csu_fini | |
| 97 | L_libc_start_main: | |
| 98 | 	.long	__libc_start_main | |
| 99 | L_abort: | |
| 100 | 	.long	abort | |
| 101 | /* Define a symbol for the first piece of initialized data. */ | |
| 102 | 	.data | |
| 103 | 	.globl __data_start | |
| 104 | __data_start: | |
| 105 | 	.long 0 | |
| 106 | 	.weak data_start | |
| 107 | 	data_start = __data_start | |
| 108 | 	.global __fpscr_values | |
| 109 | __fpscr_values: | |
| 110 | 	.long 0 | |
| 111 | 	.long 0x80000 |
lib/libc/glibc/sysdeps/sparc/sparc32/start-2-33.S created+99| ... | ... | @@ -0,0 +1,99 @@ |
| 1 | /* Startup code for elf32-sparc | |
| 2 | Copyright (C) 1997-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997. | |
| 5 | ||
| 6 | The GNU C Library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | In addition to the permissions in the GNU Lesser General Public | |
| 12 | License, the Free Software Foundation gives you unlimited | |
| 13 | permission to link the compiled version of this file with other | |
| 14 | programs, and to distribute those programs without any restriction | |
| 15 | coming from the use of this file. (The GNU Lesser General Public | |
| 16 | License restrictions do apply in other respects; for example, they | |
| 17 | cover modification of the file, and distribution when not linked | |
| 18 | into another program.) | |
| 19 | ||
| 20 | Note that people who make modified versions of this file are not | |
| 21 | obligated to grant this special exception for their modified | |
| 22 | versions; it is their choice whether to do so. The GNU Lesser | |
| 23 | General Public License gives permission to release a modified | |
| 24 | version without this exception; this exception also makes it | |
| 25 | possible to release a modified version which carries forward this | |
| 26 | exception. | |
| 27 | ||
| 28 | The GNU C Library is distributed in the hope that it will be useful, | |
| 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 31 | Lesser General Public License for more details. | |
| 32 | ||
| 33 | You should have received a copy of the GNU Lesser General Public | |
| 34 | License along with the GNU C Library; if not, see | |
| 35 | <https://www.gnu.org/licenses/>. */ | |
| 36 | ||
| 37 | #include <sysdep.h> | |
| 38 | ||
| 39 | ||
| 40 | 	.section ".text" | |
| 41 | 	.align 4 | |
| 42 | 	.global _start | |
| 43 | 	.type _start,#function | |
| 44 | _start: | |
| 45 | #ifdef PIC | |
| 46 | 	SETUP_PIC_REG(l7) | |
| 47 | #endif | |
| 48 | ||
| 49 | /* Terminate the stack frame, and reserve space for functions to | |
| 50 | drop their arguments. */ | |
| 51 | 	mov	%g0, %fp | |
| 52 | 	sub	%sp, 6*4, %sp | |
| 53 | ||
| 54 | /* Extract the arguments and environment as encoded on the stack. The | |
| 55 | argument info starts after one register window (16 words) past the SP. */ | |
| 56 | 	ld	[%sp+22*4], %o1 | |
| 57 | 	add	%sp, 23*4, %o2 | |
| 58 | ||
| 59 | /* Load the addresses of the user entry points. */ | |
| 60 | #ifndef PIC | |
| 61 | 	sethi	%hi(main), %o0 | |
| 62 | 	sethi	%hi(__libc_csu_init), %o3 | |
| 63 | 	sethi	%hi(__libc_csu_fini), %o4 | |
| 64 | 	or	%o0, %lo(main), %o0 | |
| 65 | 	or	%o3, %lo(__libc_csu_init), %o3 | |
| 66 | 	or	%o4, %lo(__libc_csu_fini), %o4 | |
| 67 | #else | |
| 68 | 	sethi	%gdop_hix22(main), %o0 | |
| 69 | 	sethi	%gdop_hix22(__libc_csu_init), %o3 | |
| 70 | 	sethi	%gdop_hix22(__libc_csu_fini), %o4 | |
| 71 | 	xor	%o0, %gdop_lox10(main), %o0 | |
| 72 | 	xor	%o3, %gdop_lox10(__libc_csu_init), %o3 | |
| 73 | 	xor	%o4, %gdop_lox10(__libc_csu_fini), %o4 | |
| 74 | 	ld	[%l7 + %o0], %o0, %gdop(main) | |
| 75 | 	ld	[%l7 + %o3], %o3, %gdop(__libc_csu_init) | |
| 76 | 	ld	[%l7 + %o4], %o4, %gdop(__libc_csu_fini) | |
| 77 | #endif | |
| 78 | ||
| 79 | /* When starting a binary via the dynamic linker, %g1 contains the | |
| 80 | address of the shared library termination function, which will be | |
| 81 | registered with atexit(). If we are statically linked, this will | |
| 82 | be NULL. */ | |
| 83 | 	mov	%g1, %o5 | |
| 84 | ||
| 85 | /* Let libc do the rest of the initialization, and call main. */ | |
| 86 | 	call	__libc_start_main | |
| 87 | 	 nop | |
| 88 | ||
| 89 | /* Die very horribly if exit returns. */ | |
| 90 | 	unimp | |
| 91 | ||
| 92 | 	.size _start, .-_start | |
| 93 | ||
| 94 | /* Define a symbol for the first piece of initialized data. */ | |
| 95 | 	.data | |
| 96 | 	.globl	__data_start | |
| 97 | __data_start: | |
| 98 | 	.long	0 | |
| 99 | weak_alias (__data_start, data_start) |
lib/libc/glibc/sysdeps/sparc/sparc64/start-2-33.S created+100| ... | ... | @@ -0,0 +1,100 @@ |
| 1 | /* Startup code for elf64-sparc | |
| 2 | Copyright (C) 1997-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997. | |
| 5 | ||
| 6 | The GNU C Library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | In addition to the permissions in the GNU Lesser General Public | |
| 12 | License, the Free Software Foundation gives you unlimited | |
| 13 | permission to link the compiled version of this file with other | |
| 14 | programs, and to distribute those programs without any restriction | |
| 15 | coming from the use of this file. (The GNU Lesser General Public | |
| 16 | License restrictions do apply in other respects; for example, they | |
| 17 | cover modification of the file, and distribution when not linked | |
| 18 | into another program.) | |
| 19 | ||
| 20 | Note that people who make modified versions of this file are not | |
| 21 | obligated to grant this special exception for their modified | |
| 22 | versions; it is their choice whether to do so. The GNU Lesser | |
| 23 | General Public License gives permission to release a modified | |
| 24 | version without this exception; this exception also makes it | |
| 25 | possible to release a modified version which carries forward this | |
| 26 | exception. | |
| 27 | ||
| 28 | The GNU C Library is distributed in the hope that it will be useful, | |
| 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 31 | Lesser General Public License for more details. | |
| 32 | ||
| 33 | You should have received a copy of the GNU Lesser General Public | |
| 34 | License along with the GNU C Library; if not, see | |
| 35 | <https://www.gnu.org/licenses/>. */ | |
| 36 | ||
| 37 | #include <sysdep.h> | |
| 38 | ||
| 39 | ||
| 40 | 	.section ".text" | |
| 41 | 	.align 4 | |
| 42 | 	.global _start | |
| 43 | 	.type _start,#function | |
| 44 | _start: | |
| 45 | #ifdef PIC | |
| 46 | 	SETUP_PIC_REG(l7) | |
| 47 | #endif | |
| 48 | ||
| 49 | /* Terminate the stack frame, and reserve space for functions to | |
| 50 | drop their arguments. */ | |
| 51 | 	mov	%g0, %fp | |
| 52 | 	sub	%sp, 6*8, %sp | |
| 53 | ||
| 54 | /* Extract the arguments and environment as encoded on the stack. The | |
| 55 | argument info starts after one register window (16 words) past the SP, | |
| 56 | plus the bias we added, plus the magic v9 STACK_BIAS. */ | |
| 57 | 	ldx	[%sp+STACK_BIAS+22*8], %o1 | |
| 58 | 	add	%sp, STACK_BIAS+23*8, %o2 | |
| 59 | ||
| 60 | /* Load the addresses of the user entry points. */ | |
| 61 | #ifndef PIC | |
| 62 | 	sethi	%hi(main), %o0 | |
| 63 | 	sethi	%hi(__libc_csu_init), %o3 | |
| 64 | 	sethi	%hi(__libc_csu_fini), %o4 | |
| 65 | 	or	%o0, %lo(main), %o0 | |
| 66 | 	or	%o3, %lo(__libc_csu_init), %o3 | |
| 67 | 	or	%o4, %lo(__libc_csu_fini), %o4 | |
| 68 | #else | |
| 69 | 	sethi	%gdop_hix22(main), %o0 | |
| 70 | 	sethi	%gdop_hix22(__libc_csu_init), %o3 | |
| 71 | 	sethi	%gdop_hix22(__libc_csu_fini), %o4 | |
| 72 | 	xor	%o0, %gdop_lox10(main), %o0 | |
| 73 | 	xor	%o3, %gdop_lox10(__libc_csu_init), %o3 | |
| 74 | 	xor	%o4, %gdop_lox10(__libc_csu_fini), %o4 | |
| 75 | 	ldx	[%l7 + %o0], %o0, %gdop(main) | |
| 76 | 	ldx	[%l7 + %o3], %o3, %gdop(__libc_csu_init) | |
| 77 | 	ldx	[%l7 + %o4], %o4, %gdop(__libc_csu_fini) | |
| 78 | #endif | |
| 79 | ||
| 80 | /* When starting a binary via the dynamic linker, %g1 contains the | |
| 81 | address of the shared library termination function, which will be | |
| 82 | registered with atexit(). If we are statically linked, this will | |
| 83 | be NULL. */ | |
| 84 | 	mov %g1, %o5 | |
| 85 | ||
| 86 | /* Let libc do the rest of the initialization, and call main. */ | |
| 87 | 	call __libc_start_main | |
| 88 | 	 nop | |
| 89 | ||
| 90 | /* Die very horribly if exit returns. */ | |
| 91 | 	illtrap	0 | |
| 92 | ||
| 93 | 	.size _start, .-_start | |
| 94 | ||
| 95 | /* Define a symbol for the first piece of initialized data. */ | |
| 96 | 	.data | |
| 97 | 	.globl	__data_start | |
| 98 | __data_start: | |
| 99 | 	.long	0 | |
| 100 | weak_alias (__data_start, data_start) |
lib/libc/glibc/sysdeps/x86_64/start-2-33.S created+131| ... | ... | @@ -0,0 +1,131 @@ |
| 1 | /* Startup code compliant to the ELF x86-64 ABI. | |
| 2 | Copyright (C) 2001-2020 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | Contributed by Andreas Jaeger <aj@suse.de>, 2001. | |
| 5 | ||
| 6 | The GNU C Library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | In addition to the permissions in the GNU Lesser General Public | |
| 12 | License, the Free Software Foundation gives you unlimited | |
| 13 | permission to link the compiled version of this file with other | |
| 14 | programs, and to distribute those programs without any restriction | |
| 15 | coming from the use of this file. (The GNU Lesser General Public | |
| 16 | License restrictions do apply in other respects; for example, they | |
| 17 | cover modification of the file, and distribution when not linked | |
| 18 | into another program.) | |
| 19 | ||
| 20 | Note that people who make modified versions of this file are not | |
| 21 | obligated to grant this special exception for their modified | |
| 22 | versions; it is their choice whether to do so. The GNU Lesser | |
| 23 | General Public License gives permission to release a modified | |
| 24 | version without this exception; this exception also makes it | |
| 25 | possible to release a modified version which carries forward this | |
| 26 | exception. | |
| 27 | ||
| 28 | The GNU C Library is distributed in the hope that it will be useful, | |
| 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 31 | Lesser General Public License for more details. | |
| 32 | ||
| 33 | You should have received a copy of the GNU Lesser General Public | |
| 34 | License along with the GNU C Library; if not, see | |
| 35 | <https://www.gnu.org/licenses/>. */ | |
| 36 | ||
| 37 | /* This is the canonical entry point, usually the first thing in the text | |
| 38 | segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry | |
| 39 | point runs, most registers' values are unspecified, except for: | |
| 40 | ||
| 41 | %rdx		Contains a function pointer to be registered with `atexit'. | |
| 42 | 		This is how the dynamic linker arranges to have DT_FINI | |
| 43 | 		functions called for shared libraries that have been loaded | |
| 44 | 		before this code runs. | |
| 45 | ||
| 46 | %rsp		The stack contains the arguments and environment: | |
| 47 | 		0(%rsp)				argc | |
| 48 | 		LP_SIZE(%rsp)			argv[0] | |
| 49 | 		... | |
| 50 | 		(LP_SIZE*argc)(%rsp)		NULL | |
| 51 | 		(LP_SIZE*(argc+1))(%rsp)	envp[0] | |
| 52 | 		... | |
| 53 | 						NULL | |
| 54 | */ | |
| 55 | ||
| 56 | #include <sysdep.h> | |
| 57 | ||
| 58 | ENTRY (_start) | |
| 59 | 	/* Clearing frame pointer is insufficient, use CFI. */ | |
| 60 | 	cfi_undefined (rip) | |
| 61 | 	/* Clear the frame pointer. The ABI suggests this be done, to mark | |
| 62 | 	 the outermost frame obviously. */ | |
| 63 | 	xorl %ebp, %ebp | |
| 64 | ||
| 65 | 	/* Extract the arguments as encoded on the stack and set up | |
| 66 | 	 the arguments for __libc_start_main (int (*main) (int, char **, char **), | |
| 67 | 		 int argc, char *argv, | |
| 68 | 		 void (*init) (void), void (*fini) (void), | |
| 69 | 		 void (*rtld_fini) (void), void *stack_end). | |
| 70 | 	 The arguments are passed via registers and on the stack: | |
| 71 | 	main:		%rdi | |
| 72 | 	argc:		%rsi | |
| 73 | 	argv:		%rdx | |
| 74 | 	init:		%rcx | |
| 75 | 	fini:		%r8 | |
| 76 | 	rtld_fini:	%r9 | |
| 77 | 	stack_end:	stack.	*/ | |
| 78 | ||
| 79 | 	mov %RDX_LP, %R9_LP	/* Address of the shared library termination | |
| 80 | 				 function. */ | |
| 81 | #ifdef __ILP32__ | |
| 82 | 	mov (%rsp), %esi	/* Simulate popping 4-byte argument count. */ | |
| 83 | 	add $4, %esp | |
| 84 | #else | |
| 85 | 	popq %rsi		/* Pop the argument count. */ | |
| 86 | #endif | |
| 87 | 	/* argv starts just at the current stack top. */ | |
| 88 | 	mov %RSP_LP, %RDX_LP | |
| 89 | 	/* Align the stack to a 16 byte boundary to follow the ABI. */ | |
| 90 | 	and $~15, %RSP_LP | |
| 91 | ||
| 92 | 	/* Push garbage because we push 8 more bytes. */ | |
| 93 | 	pushq %rax | |
| 94 | ||
| 95 | 	/* Provide the highest stack address to the user code (for stacks | |
| 96 | 	 which grow downwards). */ | |
| 97 | 	pushq %rsp | |
| 98 | ||
| 99 | #ifdef PIC | |
| 100 | 	/* Pass address of our own entry points to .fini and .init. */ | |
| 101 | 	mov __libc_csu_fini@GOTPCREL(%rip), %R8_LP | |
| 102 | 	mov __libc_csu_init@GOTPCREL(%rip), %RCX_LP | |
| 103 | ||
| 104 | 	mov main@GOTPCREL(%rip), %RDI_LP | |
| 105 | #else | |
| 106 | 	/* Pass address of our own entry points to .fini and .init. */ | |
| 107 | 	mov $__libc_csu_fini, %R8_LP | |
| 108 | 	mov $__libc_csu_init, %RCX_LP | |
| 109 | ||
| 110 | 	mov $main, %RDI_LP | |
| 111 | #endif | |
| 112 | ||
| 113 | 	/* Call the user's main function, and exit with its value. | |
| 114 | 	 But let the libc call main. Since __libc_start_main in | |
| 115 | 	 libc.so is called very early, lazy binding isn't relevant | |
| 116 | 	 here. Use indirect branch via GOT to avoid extra branch | |
| 117 | 	 to PLT slot. In case of static executable, ld in binutils | |
| 118 | 	 2.26 or above can convert indirect branch into direct | |
| 119 | 	 branch. */ | |
| 120 | 	call *__libc_start_main@GOTPCREL(%rip) | |
| 121 | ||
| 122 | 	hlt			/* Crash if somehow `exit' does return.	 */ | |
| 123 | END (_start) | |
| 124 | ||
| 125 | /* Define a symbol for the first piece of initialized data. */ | |
| 126 | 	.data | |
| 127 | 	.globl __data_start | |
| 128 | __data_start: | |
| 129 | 	.long 0 | |
| 130 | 	.weak data_start | |
| 131 | 	data_start = __data_start |
src/glibc.zig+45-5| ... | ... | @@ -182,6 +182,10 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 182 | 182 | defer arena_allocator.deinit(); |
| 183 | 183 | const arena = arena_allocator.allocator(); |
| 184 | 184 | |
| 185 | const target = comp.getTarget(); | |
| 186 | const target_version = target.os.version_range.linux.glibc; | |
| 187 | const start_needs_init_fini_functions = target_version.major < 2 or (target_version.major == 2 and target_version.minor <= 33); | |
| 188 | ||
| 185 | 189 | switch (crt_file) { |
| 186 | 190 | .crti_o => { |
| 187 | 191 | var args = std.ArrayList([]const u8).init(arena); |
| ... | ... | @@ -243,7 +247,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 243 | 247 | "-Wa,--noexecstack", |
| 244 | 248 | }); |
| 245 | 249 | break :blk .{ |
| 246 | .src_path = try start_asm_path(comp, arena, "start.S"), | |
| 250 | .src_path = try start_asm_path(comp, arena, if (start_needs_init_fini_functions) "start-2-33.S" else "start.S"), | |
| 247 | 251 | .extra_flags = args.items, |
| 248 | 252 | }; |
| 249 | 253 | }; |
| ... | ... | @@ -269,7 +273,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 269 | 273 | return comp.build_crt_file("Scrt1", .Obj, &[_]Compilation.CSourceFile{ start_o, abi_note_o }); |
| 270 | 274 | }, |
| 271 | 275 | .libc_nonshared_a => { |
| 272 | const target = comp.getTarget(); | |
| 273 | 276 | const s = path.sep_str; |
| 274 | 277 | const linux_prefix = lib_libc_glibc ++ |
| 275 | 278 | "sysdeps" ++ s ++ "unix" ++ s ++ "sysv" ++ s ++ "linux" ++ s; |
| ... | ... | @@ -309,7 +312,44 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 309 | 312 | .{ .path = linux_prefix ++ "stat_t64_cp.c" }, |
| 310 | 313 | }; |
| 311 | 314 | |
| 312 | var c_source_files: [deps.len]Compilation.CSourceFile = undefined; | |
| 315 | var c_source_files: [deps.len + 1]Compilation.CSourceFile = undefined; | |
| 316 | ||
| 317 | if (start_needs_init_fini_functions) { | |
| 318 | c_source_files[0] = blk: { | |
| 319 | var args = std.ArrayList([]const u8).init(arena); | |
| 320 | try args.appendSlice(&[_][]const u8{ | |
| 321 | "-std=gnu11", | |
| 322 | "-fgnu89-inline", | |
| 323 | "-fmerge-all-constants", | |
| 324 | "-fno-stack-protector", | |
| 325 | "-fmath-errno", | |
| 326 | "-I", | |
| 327 | try lib_path(comp, arena, lib_libc_glibc ++ "csu"), | |
| 328 | }); | |
| 329 | try add_include_dirs(comp, arena, &args); | |
| 330 | try args.appendSlice(&[_][]const u8{ | |
| 331 | "-DSTACK_PROTECTOR_LEVEL=0", | |
| 332 | "-fPIC", | |
| 333 | "-fno-stack-protector", | |
| 334 | "-fno-common", | |
| 335 | "-ftls-model=initial-exec", | |
| 336 | "-D_LIBC_REENTRANT", | |
| 337 | "-include", | |
| 338 | try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-modules.h"), | |
| 339 | "-DMODULE_NAME=libc", | |
| 340 | "-Wno-nonportable-include-path", | |
| 341 | "-include", | |
| 342 | try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"), | |
| 343 | "-DPIC", | |
| 344 | "-DLIBC_NONSHARED=1", | |
| 345 | "-DTOP_NAMESPACE=glibc", | |
| 346 | }); | |
| 347 | break :blk .{ | |
| 348 | .src_path = try lib_path(comp, arena, lib_libc_glibc ++ "csu" ++ path.sep_str ++ "elf-init-2-33.c"), | |
| 349 | .extra_flags = args.items, | |
| 350 | }; | |
| 351 | }; | |
| 352 | } | |
| 313 | 353 | |
| 314 | 354 | for (deps) |dep, i| { |
| 315 | 355 | var args = std.ArrayList([]const u8).init(arena); |
| ... | ... | @@ -353,12 +393,12 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 353 | 393 | shared_def, |
| 354 | 394 | "-DTOP_NAMESPACE=glibc", |
| 355 | 395 | }); |
| 356 | c_source_files[i] = .{ | |
| 396 | c_source_files[i + @boolToInt(start_needs_init_fini_functions)] = .{ | |
| 357 | 397 | .src_path = try lib_path(comp, arena, dep.path), |
| 358 | 398 | .extra_flags = args.items, |
| 359 | 399 | }; |
| 360 | 400 | } |
| 361 | return comp.build_crt_file("c_nonshared", .Lib, &c_source_files); | |
| 401 | return comp.build_crt_file("c_nonshared", .Lib, c_source_files[0 .. deps.len + @boolToInt(start_needs_init_fini_functions)]); | |
| 362 | 402 | }, |
| 363 | 403 | } |
| 364 | 404 | } |