| author | |
| committer | |
| log | dbfeb07a17209f79f76fc3caa50d0a2410bcab27 |
| tree | 4d0b59066922400522e2e97c209a6c1dd890d13b |
| parent | 66bcba6b9d796046199df647a24d10f60516b73f |
| signature |
4 files changed, 102 insertions(+), 7 deletions(-)
lib/libc/netbsd/lib/csu/arch/riscv/crt0.S created+62| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | /*	$NetBSD: crt0.S,v 1.3.4.1 2026/03/04 19:27:22 martin Exp $	*/ | |
| 2 | ||
| 3 | /*- | |
| 4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | |
| 5 | * All rights reserved. | |
| 6 | * | |
| 7 | * This code is derived from software contributed to The NetBSD Foundation | |
| 8 | * by Matt Thomas of 3am Software Foundry. | |
| 9 | * | |
| 10 | * Redistribution and use in source and binary forms, with or without | |
| 11 | * modification, are permitted provided that the following conditions | |
| 12 | * are met: | |
| 13 | * 1. Redistributions of source code must retain the above copyright | |
| 14 | * notice, this list of conditions and the following disclaimer. | |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 16 | * notice, this list of conditions and the following disclaimer in the | |
| 17 | * documentation and/or other materials provided with the distribution. | |
| 18 | * | |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | */ | |
| 31 | ||
| 32 | #include <machine/asm.h> | |
| 33 | ||
| 34 | RCSID("$NetBSD: crt0.S,v 1.3.4.1 2026/03/04 19:27:22 martin Exp $") | |
| 35 | ||
| 36 | STRONG_ALIAS(_start,__start) | |
| 37 | ||
| 38 | _ENTRY(__start) | |
| 39 | 	/* | |
| 40 | 	 * void ___start(void (*cleanup)(void), struct ps_strings *ps_strings); | |
| 41 | 	 */ | |
| 42 | 	.option push | |
| 43 | 	.option norelax | |
| 44 | 	lla	gp, __global_pointer$ | |
| 45 | 	.option pop | |
| 46 | ||
| 47 | 	j	___start | |
| 48 | END(__start) | |
| 49 | ||
| 50 | 	.option push | |
| 51 | 	.option norelax | |
| 52 | ||
| 53 | _ENTRY(_start_setgp) | |
| 54 | 	lla	gp, __global_pointer$ | |
| 55 | 	.option pop | |
| 56 | 	ret | |
| 57 | END(_start_setgp) | |
| 58 | ||
| 59 | 	.section	.preinit_array, "aw" | |
| 60 | 	.p2align	PTR_SCALESHIFT | |
| 61 | 	PTR_WORD	_start_setgp | |
| 62 |
lib/libc/netbsd/lib/csu/common/crt0-common.c+32-7| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | /* $NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $ */ | |
| 1 | /* $NetBSD: crt0-common.c,v 1.30 2025/05/02 23:04:06 riastradh Exp $ */ | |
| 2 | 2 | |
| 3 | 3 | /* |
| 4 | 4 | * Copyright (c) 1998 Christos Zoulas |
| ... | ... | @@ -36,13 +36,16 @@ |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | 38 | #include <sys/cdefs.h> |
| 39 | __RCSID("$NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $"); | |
| 39 | __RCSID("$NetBSD: crt0-common.c,v 1.30 2025/05/02 23:04:06 riastradh Exp $"); | |
| 40 | 40 | |
| 41 | 41 | #include <sys/types.h> |
| 42 | 42 | #include <sys/exec.h> |
| 43 | 43 | #include <sys/exec_elf.h> |
| 44 | 44 | #include <sys/syscall.h> |
| 45 | ||
| 45 | 46 | #include <machine/profile.h> |
| 47 | ||
| 48 | #include <limits.h> | |
| 46 | 49 | #include <stdlib.h> |
| 47 | 50 | #include <unistd.h> |
| 48 | 51 | |
| ... | ... | @@ -55,7 +58,6 @@ typedef void (*fptr_t)(void); |
| 55 | 58 | extern void	_init(void); |
| 56 | 59 | extern void	_fini(void); |
| 57 | 60 | #endif |
| 58 | extern void	_libc_init(void); | |
| 59 | 61 | |
| 60 | 62 | /* |
| 61 | 63 | * Arrange for _DYNAMIC to be weak and undefined (and therefore to show up |
| ... | ... | @@ -254,11 +256,19 @@ relocate_self(struct ps_strings *ps_strings) |
| 254 | 256 | |
| 255 | 257 | 	Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase); |
| 256 | 258 | |
| 259 | 	const Elf_Relr *relr = 0, *relrlim; | |
| 257 | 260 | 	const REL_TYPE *relocs = 0, *relocslim; |
| 258 | 	Elf_Addr relocssz = 0; | |
| 261 | 	Elf_Addr relrsz = 0, relocssz = 0; | |
| 259 | 262 | |
| 260 | 263 | 	for (; dynp->d_tag != DT_NULL; dynp++) { |
| 261 | 264 | 		switch (dynp->d_tag) { |
| 265 | 		case DT_RELR: | |
| 266 | 			relr = | |
| 267 | 			 (const Elf_Relr *)(relocbase + dynp->d_un.d_ptr); | |
| 268 | 			break; | |
| 269 | 		case DT_RELRSZ: | |
| 270 | 			relrsz = dynp->d_un.d_val; | |
| 271 | 			break; | |
| 262 | 272 | 		case REL_TAG: |
| 263 | 273 | 			relocs = |
| 264 | 274 | 			 (const REL_TYPE *)(relocbase + dynp->d_un.d_ptr); |
| ... | ... | @@ -268,7 +278,22 @@ relocate_self(struct ps_strings *ps_strings) |
| 268 | 278 | 			break; |
| 269 | 279 | 		} |
| 270 | 280 | 	} |
| 281 | 	relrlim = (const Elf_Relr *)((const uint8_t *)relr + relrsz); | |
| 271 | 282 | 	relocslim = (const REL_TYPE *)((const uint8_t *)relocs + relocssz); |
| 283 | 	while (relr < relrlim) { | |
| 284 | 		Elf_Addr *where; | |
| 285 | ||
| 286 | 		where = (Elf_Addr *)(relocbase + *relr); | |
| 287 | 		*where++ += relocbase; | |
| 288 | 		while (++relr < relrlim && *relr & 1) { | |
| 289 | 			unsigned i; | |
| 290 | ||
| 291 | 			for (i = 1; i < CHAR_BIT*sizeof(*relr); i++, where++) { | |
| 292 | 				if (*relr & ((Elf_Relr)1 << i)) | |
| 293 | 					*where += relocbase; | |
| 294 | 			} | |
| 295 | 		} | |
| 296 | 	} | |
| 272 | 297 | 	for (; relocs < relocslim; ++relocs) { |
| 273 | 298 | 		Elf_Addr *where; |
| 274 | 299 | |
| ... | ... | @@ -318,9 +343,6 @@ ___start(void (*cleanup)(void),			/* from shared loader */ |
| 318 | 343 | 		__progname = empty_string; |
| 319 | 344 | 	} |
| 320 | 345 | |
| 321 | 	if (cleanup != NULL) | |
| 322 | 		atexit(cleanup); | |
| 323 | ||
| 324 | 346 | 	_libc_init(); |
| 325 | 347 | |
| 326 | 348 | 	if (&rtld_DYNAMIC == NULL) { |
| ... | ... | @@ -334,6 +356,9 @@ ___start(void (*cleanup)(void),			/* from shared loader */ |
| 334 | 356 | |
| 335 | 357 | 	_preinit(); |
| 336 | 358 | |
| 359 | 	if (cleanup != NULL) | |
| 360 | 		atexit(cleanup); | |
| 361 | ||
| 337 | 362 | #ifdef MCRT0 |
| 338 | 363 | 	atexit(_mcleanup); |
| 339 | 364 | 	monstartup((u_long)&__eprol, (u_long)&__etext); |
lib/libc/netbsd/lib/csu/common/csu-common.h+2| ... | ... | @@ -36,3 +36,5 @@ |
| 36 | 36 | extern char *__progname __common; |
| 37 | 37 | extern char **environ __common; |
| 38 | 38 | extern struct ps_strings *__ps_strings __common; |
| 39 | ||
| 40 | void _libc_init(void) __attribute__((__constructor__, __used__)); |
src/libs/netbsd.zig+6| ... | ... | @@ -158,6 +158,12 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 158 | 158 | .condition = target.cpu.arch == .powerpc, |
| 159 | 159 | }, |
| 160 | 160 | |
| 161 | .{ | |
| 162 | .path = "arch" ++ path.sep_str ++ "riscv" ++ path.sep_str ++ "crt0.S", | |
| 163 | .flags = acflags.items, | |
| 164 | .condition = target.cpu.arch.isRISCV(), | |
| 165 | }, | |
| 166 | ||
| 161 | 167 | .{ |
| 162 | 168 | .path = "arch" ++ path.sep_str ++ "sparc" ++ path.sep_str ++ "crt0.S", |
| 163 | 169 | .flags = acflags.items, |