mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-05-30 12:56:37 +03:00
libc: update NetBSD crt0 to 11.0
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
/* $NetBSD: crt0.S,v 1.3.4.1 2026/03/04 19:27:22 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Matt Thomas of 3am Software Foundry.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
RCSID("$NetBSD: crt0.S,v 1.3.4.1 2026/03/04 19:27:22 martin Exp $")
|
||||
|
||||
STRONG_ALIAS(_start,__start)
|
||||
|
||||
_ENTRY(__start)
|
||||
/*
|
||||
* void ___start(void (*cleanup)(void), struct ps_strings *ps_strings);
|
||||
*/
|
||||
.option push
|
||||
.option norelax
|
||||
lla gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
j ___start
|
||||
END(__start)
|
||||
|
||||
.option push
|
||||
.option norelax
|
||||
|
||||
_ENTRY(_start_setgp)
|
||||
lla gp, __global_pointer$
|
||||
.option pop
|
||||
ret
|
||||
END(_start_setgp)
|
||||
|
||||
.section .preinit_array, "aw"
|
||||
.p2align PTR_SCALESHIFT
|
||||
PTR_WORD _start_setgp
|
||||
|
||||
+32
-7
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $ */
|
||||
/* $NetBSD: crt0-common.c,v 1.30 2025/05/02 23:04:06 riastradh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Christos Zoulas
|
||||
@@ -36,13 +36,16 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: crt0-common.c,v 1.27 2022/06/21 06:52:17 skrll Exp $");
|
||||
__RCSID("$NetBSD: crt0-common.c,v 1.30 2025/05/02 23:04:06 riastradh Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/exec.h>
|
||||
#include <sys/exec_elf.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <machine/profile.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -55,7 +58,6 @@ typedef void (*fptr_t)(void);
|
||||
extern void _init(void);
|
||||
extern void _fini(void);
|
||||
#endif
|
||||
extern void _libc_init(void);
|
||||
|
||||
/*
|
||||
* Arrange for _DYNAMIC to be weak and undefined (and therefore to show up
|
||||
@@ -254,11 +256,19 @@ relocate_self(struct ps_strings *ps_strings)
|
||||
|
||||
Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase);
|
||||
|
||||
const Elf_Relr *relr = 0, *relrlim;
|
||||
const REL_TYPE *relocs = 0, *relocslim;
|
||||
Elf_Addr relocssz = 0;
|
||||
Elf_Addr relrsz = 0, relocssz = 0;
|
||||
|
||||
for (; dynp->d_tag != DT_NULL; dynp++) {
|
||||
switch (dynp->d_tag) {
|
||||
case DT_RELR:
|
||||
relr =
|
||||
(const Elf_Relr *)(relocbase + dynp->d_un.d_ptr);
|
||||
break;
|
||||
case DT_RELRSZ:
|
||||
relrsz = dynp->d_un.d_val;
|
||||
break;
|
||||
case REL_TAG:
|
||||
relocs =
|
||||
(const REL_TYPE *)(relocbase + dynp->d_un.d_ptr);
|
||||
@@ -268,7 +278,22 @@ relocate_self(struct ps_strings *ps_strings)
|
||||
break;
|
||||
}
|
||||
}
|
||||
relrlim = (const Elf_Relr *)((const uint8_t *)relr + relrsz);
|
||||
relocslim = (const REL_TYPE *)((const uint8_t *)relocs + relocssz);
|
||||
while (relr < relrlim) {
|
||||
Elf_Addr *where;
|
||||
|
||||
where = (Elf_Addr *)(relocbase + *relr);
|
||||
*where++ += relocbase;
|
||||
while (++relr < relrlim && *relr & 1) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 1; i < CHAR_BIT*sizeof(*relr); i++, where++) {
|
||||
if (*relr & ((Elf_Relr)1 << i))
|
||||
*where += relocbase;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; relocs < relocslim; ++relocs) {
|
||||
Elf_Addr *where;
|
||||
|
||||
@@ -318,9 +343,6 @@ ___start(void (*cleanup)(void), /* from shared loader */
|
||||
__progname = empty_string;
|
||||
}
|
||||
|
||||
if (cleanup != NULL)
|
||||
atexit(cleanup);
|
||||
|
||||
_libc_init();
|
||||
|
||||
if (&rtld_DYNAMIC == NULL) {
|
||||
@@ -334,6 +356,9 @@ ___start(void (*cleanup)(void), /* from shared loader */
|
||||
|
||||
_preinit();
|
||||
|
||||
if (cleanup != NULL)
|
||||
atexit(cleanup);
|
||||
|
||||
#ifdef MCRT0
|
||||
atexit(_mcleanup);
|
||||
monstartup((u_long)&__eprol, (u_long)&__etext);
|
||||
|
||||
+2
@@ -36,3 +36,5 @@
|
||||
extern char *__progname __common;
|
||||
extern char **environ __common;
|
||||
extern struct ps_strings *__ps_strings __common;
|
||||
|
||||
void _libc_init(void) __attribute__((__constructor__, __used__));
|
||||
|
||||
@@ -158,6 +158,12 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.condition = target.cpu.arch == .powerpc,
|
||||
},
|
||||
|
||||
.{
|
||||
.path = "arch" ++ path.sep_str ++ "riscv" ++ path.sep_str ++ "crt0.S",
|
||||
.flags = acflags.items,
|
||||
.condition = target.cpu.arch.isRISCV(),
|
||||
},
|
||||
|
||||
.{
|
||||
.path = "arch" ++ path.sep_str ++ "sparc" ++ path.sep_str ++ "crt0.S",
|
||||
.flags = acflags.items,
|
||||
|
||||
Reference in New Issue
Block a user