authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-26 13:44:56+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-26 14:35:39+02:00
logdbfeb07a17209f79f76fc3caa50d0a2410bcab27
tree4d0b59066922400522e2e97c209a6c1dd890d13b
parent66bcba6b9d796046199df647a24d10f60516b73f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libc: update NetBSD crt0 to 11.0


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
34RCSID("$NetBSD: crt0.S,v 1.3.4.1 2026/03/04 19:27:22 martin Exp $")
35
36STRONG_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
48END(__start)
49
50 .option push
51 .option norelax
52
53_ENTRY(_start_setgp)
54 lla gp, __global_pointer$
55 .option pop
56 ret
57END(_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,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 $ */
22
3/*3/*
4 * Copyright (c) 1998 Christos Zoulas4 * Copyright (c) 1998 Christos Zoulas
...@@ -36,13 +36,16 @@...@@ -36,13 +36,16 @@
36 */36 */
3737
38#include <sys/cdefs.h>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 $");
4040
41#include <sys/types.h>41#include <sys/types.h>
42#include <sys/exec.h>42#include <sys/exec.h>
43#include <sys/exec_elf.h>43#include <sys/exec_elf.h>
44#include <sys/syscall.h>44#include <sys/syscall.h>
45
45#include <machine/profile.h>46#include <machine/profile.h>
47
48#include <limits.h>
46#include <stdlib.h>49#include <stdlib.h>
47#include <unistd.h>50#include <unistd.h>
4851
...@@ -55,7 +58,6 @@ typedef void (*fptr_t)(void);...@@ -55,7 +58,6 @@ typedef void (*fptr_t)(void);
55extern void _init(void);58extern void _init(void);
56extern void _fini(void);59extern void _fini(void);
57#endif60#endif
58extern void _libc_init(void);
5961
60/*62/*
61 * Arrange for _DYNAMIC to be weak and undefined (and therefore to show up63 * 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,11 +256,19 @@ relocate_self(struct ps_strings *ps_strings)
254256
255 Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase);257 Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase);
256258
259 const Elf_Relr *relr = 0, *relrlim;
257 const REL_TYPE *relocs = 0, *relocslim;260 const REL_TYPE *relocs = 0, *relocslim;
258 Elf_Addr relocssz = 0;261 Elf_Addr relrsz = 0, relocssz = 0;
259262
260 for (; dynp->d_tag != DT_NULL; dynp++) {263 for (; dynp->d_tag != DT_NULL; dynp++) {
261 switch (dynp->d_tag) {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 case REL_TAG:272 case REL_TAG:
263 relocs =273 relocs =
264 (const REL_TYPE *)(relocbase + dynp->d_un.d_ptr);274 (const REL_TYPE *)(relocbase + dynp->d_un.d_ptr);
...@@ -268,7 +278,22 @@ relocate_self(struct ps_strings *ps_strings)...@@ -268,7 +278,22 @@ relocate_self(struct ps_strings *ps_strings)
268 break;278 break;
269 }279 }
270 }280 }
281 relrlim = (const Elf_Relr *)((const uint8_t *)relr + relrsz);
271 relocslim = (const REL_TYPE *)((const uint8_t *)relocs + relocssz);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 for (; relocs < relocslim; ++relocs) {297 for (; relocs < relocslim; ++relocs) {
273 Elf_Addr *where;298 Elf_Addr *where;
274299
...@@ -318,9 +343,6 @@ ___start(void (*cleanup)(void), /* from shared loader */...@@ -318,9 +343,6 @@ ___start(void (*cleanup)(void), /* from shared loader */
318 __progname = empty_string;343 __progname = empty_string;
319 }344 }
320345
321 if (cleanup != NULL)
322 atexit(cleanup);
323
324 _libc_init();346 _libc_init();
325347
326 if (&rtld_DYNAMIC == NULL) {348 if (&rtld_DYNAMIC == NULL) {
...@@ -334,6 +356,9 @@ ___start(void (*cleanup)(void), /* from shared loader */...@@ -334,6 +356,9 @@ ___start(void (*cleanup)(void), /* from shared loader */
334356
335 _preinit();357 _preinit();
336358
359 if (cleanup != NULL)
360 atexit(cleanup);
361
337#ifdef MCRT0362#ifdef MCRT0
338 atexit(_mcleanup);363 atexit(_mcleanup);
339 monstartup((u_long)&__eprol, (u_long)&__etext);364 monstartup((u_long)&__eprol, (u_long)&__etext);
lib/libc/netbsd/lib/csu/common/csu-common.h+2
...@@ -36,3 +36,5 @@...@@ -36,3 +36,5 @@
36extern char *__progname __common;36extern char *__progname __common;
37extern char **environ __common;37extern char **environ __common;
38extern struct ps_strings *__ps_strings __common;38extern struct ps_strings *__ps_strings __common;
39
40void _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,6 +158,12 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
158 .condition = target.cpu.arch == .powerpc,158 .condition = target.cpu.arch == .powerpc,
159 },159 },
160160
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 .path = "arch" ++ path.sep_str ++ "sparc" ++ path.sep_str ++ "crt0.S",168 .path = "arch" ++ path.sep_str ++ "sparc" ++ path.sep_str ++ "crt0.S",
163 .flags = acflags.items,169 .flags = acflags.items,