mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
libc: update startup code from freebsd 15
This commit is contained in:
Vendored
+1
-2
@@ -1,9 +1,8 @@
|
||||
# @(#)COPYRIGHT 8.2 (Berkeley) 3/21/94
|
||||
|
||||
The compilation of software known as FreeBSD is distributed under the
|
||||
following terms:
|
||||
|
||||
Copyright (c) 1992-2023 The FreeBSD Project.
|
||||
Copyright (c) 1992-2025 The FreeBSD Project.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+6
-9
@@ -49,15 +49,12 @@ _start:
|
||||
#ifdef GCRT
|
||||
subq $16, %rsp
|
||||
#endif
|
||||
movq %rsi, %rcx
|
||||
movq %rdi, %rsi /* argv = ap */
|
||||
addq $8, %rsi /* argv += 1 */
|
||||
movq %rdi, %rdx /* env = ap */
|
||||
addq $16, %rdx /* env += 2 */
|
||||
movslq (%rdi), %rax
|
||||
movl %eax, %edi /* argc = *(long *)(void *)ap */
|
||||
shlq $3, %rax
|
||||
addq %rax, %rdx /* env += argc */
|
||||
movq %rsi, %rcx /* cleanup */
|
||||
movslq (%rdi), %rax /* long *ap; tmpargc = *ap */
|
||||
leaq 0x8(%rdi), %rsi /* argv = ap + 1 */
|
||||
leaq 0x10(%rdi, %rax, 8), %rdx /* env = ap + 2 + tmpargc */
|
||||
movl %eax, %edi /* argc = tmpargc */
|
||||
|
||||
#ifdef PIC
|
||||
/*
|
||||
* XXX. %rip relative addressing is not intended for use in the
|
||||
|
||||
-1
@@ -41,7 +41,6 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/elf_common.h>
|
||||
|
||||
|
||||
+2
-43
@@ -21,7 +21,6 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "crt.h"
|
||||
@@ -41,9 +40,8 @@ void __cxa_finalize(void *) __weak_symbol;
|
||||
* When we have ctors/dtors call from the dtor handler before calling
|
||||
* any dtors, otherwise use a destructor.
|
||||
*/
|
||||
#ifndef HAVE_CTORS
|
||||
/* zig patch: no HAVE_CTORS */
|
||||
__attribute__((destructor))
|
||||
#endif
|
||||
static void
|
||||
run_cxa_finalize(void)
|
||||
{
|
||||
@@ -53,43 +51,4 @@ run_cxa_finalize(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* On some architectures and toolchains we may need to call the .dtors.
|
||||
* These are called in the order they are in the ELF file.
|
||||
*/
|
||||
#ifdef HAVE_CTORS
|
||||
static void __do_global_dtors_aux(void) __used;
|
||||
|
||||
static crt_func __CTOR_LIST__[] __section(".ctors") __used = {
|
||||
(crt_func)-1
|
||||
};
|
||||
static crt_func __DTOR_LIST__[] __section(".dtors") __used = {
|
||||
(crt_func)-1
|
||||
};
|
||||
|
||||
static void
|
||||
__do_global_dtors_aux(void)
|
||||
{
|
||||
crt_func fn;
|
||||
int n;
|
||||
|
||||
#ifdef SHARED
|
||||
run_cxa_finalize();
|
||||
#endif
|
||||
|
||||
for (n = 1;; n++) {
|
||||
fn = __DTOR_LIST__[n];
|
||||
if (fn == (crt_func)0 || fn == (crt_func)-1)
|
||||
break;
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
asm (
|
||||
".pushsection .fini \n"
|
||||
"\t" INIT_CALL_SEQ(__do_global_dtors_aux) "\n"
|
||||
".popsection \n"
|
||||
);
|
||||
#endif
|
||||
|
||||
/* zig patch: remove gcj nonsense */
|
||||
/* zig patch: no HAVE_CTORS */
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
* for more information.
|
||||
*/
|
||||
|
||||
.section .note.tag,"aG",%note,.freebsd.noteG,comdat
|
||||
.section .note.tag,"aGR",%note,.freebsd.noteG,comdat
|
||||
.p2align 2
|
||||
.4byte 2f-1f
|
||||
.4byte 4f-3f
|
||||
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-1-Clause
|
||||
*
|
||||
* Copyright 2018 Andrew Turner
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <sys/cdefs.h>
|
||||
#include "crt.h"
|
||||
|
||||
typedef void (*crt_func)(void);
|
||||
|
||||
/* zig patch: remove gcj nonsense */
|
||||
|
||||
#ifdef HAVE_CTORS
|
||||
|
||||
/*
|
||||
* On some architectures and toolchains we may need to call the .ctors.
|
||||
* These are called in the reverse order they are in the ELF file.
|
||||
*/
|
||||
static void __do_global_ctors_aux(void) __used;
|
||||
|
||||
static crt_func __CTOR_END__[] __section(".ctors") __used = {
|
||||
(crt_func)0
|
||||
};
|
||||
static crt_func __DTOR_END__[] __section(".dtors") __used = {
|
||||
(crt_func)0
|
||||
};
|
||||
|
||||
static void
|
||||
__do_global_ctors_aux(void)
|
||||
{
|
||||
crt_func fn;
|
||||
int n;
|
||||
|
||||
for (n = 1;; n++) {
|
||||
fn = __CTOR_END__[-n];
|
||||
if (fn == (crt_func)0 || fn == (crt_func)-1)
|
||||
break;
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
asm (
|
||||
".pushsection .init \n"
|
||||
"\t" INIT_CALL_SEQ(__do_global_ctors_aux) "\n"
|
||||
".popsection \n"
|
||||
);
|
||||
#endif
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
#include <sys/elf_common.h>
|
||||
#include "notes.h"
|
||||
|
||||
.section .note.tag,"a",%note
|
||||
.section .note.tag,"aR",%note
|
||||
.p2align 2
|
||||
.4byte 2f-1f
|
||||
.4byte 4f-3f
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "notes.h"
|
||||
|
||||
.section .note.tag,"a",%note
|
||||
.section .note.tag,"aR",%note
|
||||
.p2align 2
|
||||
.4byte 2f-1f
|
||||
.4byte 4f-3f
|
||||
|
||||
+1
-2
@@ -24,8 +24,7 @@
|
||||
#ifndef _CRT_H_
|
||||
#define _CRT_H_
|
||||
|
||||
/* zig patch: no HAVE_CTORS */
|
||||
#define CTORS_CONSTRUCTORS
|
||||
/* zig patch: no HAVE_CTORS/CTORS_CONSTRUCTORS */
|
||||
#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
|
||||
|
||||
#endif
|
||||
|
||||
+1
-2
@@ -24,8 +24,7 @@
|
||||
#ifndef _CRT_H_
|
||||
#define _CRT_H_
|
||||
|
||||
/* zig patch: no HAVE_CTORS */
|
||||
#define CTORS_CONSTRUCTORS
|
||||
/* zig patch: no HAVE_CTORS/CTORS_CONSTRUCTORS */
|
||||
#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
|
||||
|
||||
#endif
|
||||
|
||||
+22
-86
@@ -37,6 +37,8 @@
|
||||
#include <sys/_types.h>
|
||||
#include <sys/_pthreadtypes.h>
|
||||
|
||||
#include <libsys.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
/*
|
||||
@@ -185,10 +187,12 @@ typedef enum {
|
||||
PJT_GETTHREADID_NP,
|
||||
PJT_ATTR_GET_NP,
|
||||
PJT_GETNAME_NP,
|
||||
PJT_SUSPEND_ALL_NP,
|
||||
PJT_RESUME_ALL_NP,
|
||||
PJT_MAX
|
||||
} pjt_index_t;
|
||||
|
||||
typedef int (*pthread_func_t)(void);
|
||||
typedef void (*pthread_func_t)(void);
|
||||
typedef pthread_func_t pthread_func_entry_t[2];
|
||||
|
||||
extern pthread_func_entry_t __thr_jtable[];
|
||||
@@ -197,9 +201,10 @@ void __set_error_selector(int *(*arg)(void));
|
||||
int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
|
||||
void *(calloc_cb)(__size_t, __size_t));
|
||||
|
||||
typedef int (*interpos_func_t)(void);
|
||||
typedef void (*interpos_func_t)(void);
|
||||
interpos_func_t *__libc_interposing_slot(int interposno);
|
||||
extern interpos_func_t __libc_interposing[] __hidden;
|
||||
interpos_func_t *__libsys_interposing_slot(int interposno);
|
||||
|
||||
enum {
|
||||
INTERPOS_accept,
|
||||
@@ -244,11 +249,18 @@ enum {
|
||||
INTERPOS_map_stacks_exec,
|
||||
INTERPOS_fdatasync,
|
||||
INTERPOS_clock_nanosleep,
|
||||
INTERPOS_distribute_static_tls,
|
||||
INTERPOS__reserved0, /* was distribute_static_tls */
|
||||
INTERPOS_pdfork,
|
||||
INTERPOS_uexterr_gettext,
|
||||
INTERPOS_MAX
|
||||
};
|
||||
|
||||
#define _INTERPOS_SYS(type, idx, ...) \
|
||||
((type *)*(__libc_interposing_slot(idx)))(__VA_ARGS__)
|
||||
#define INTERPOS_SYS(syscall, ...) \
|
||||
_INTERPOS_SYS(__sys_## syscall ##_t, INTERPOS_## syscall \
|
||||
__VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
/*
|
||||
* yplib internal interfaces
|
||||
*/
|
||||
@@ -333,102 +345,22 @@ struct __siginfo;
|
||||
struct __ucontext;
|
||||
struct __wrusage;
|
||||
enum idtype;
|
||||
int __sys_aio_suspend(const struct aiocb * const[], int,
|
||||
const struct timespec *);
|
||||
int __sys_accept(int, struct sockaddr *, __socklen_t *);
|
||||
int __sys_accept4(int, struct sockaddr *, __socklen_t *, int);
|
||||
int __sys_clock_gettime(__clockid_t, struct timespec *ts);
|
||||
int __sys_clock_nanosleep(__clockid_t, int,
|
||||
const struct timespec *, struct timespec *);
|
||||
int __sys_close(int);
|
||||
int __sys_close_range(unsigned, unsigned, int);
|
||||
int __sys_connect(int, const struct sockaddr *, __socklen_t);
|
||||
int __sys_fcntl(int, int, ...);
|
||||
int __sys_fdatasync(int);
|
||||
int __sys_fstat(int fd, struct stat *);
|
||||
int __sys_fstatfs(int fd, struct statfs *);
|
||||
int __sys_fstatat(int, const char *, struct stat *, int);
|
||||
int __sys_fsync(int);
|
||||
__pid_t __sys_fork(void);
|
||||
int __sys_ftruncate(int, __off_t);
|
||||
__ssize_t __sys_getdirentries(int, char *, __size_t, __off_t *);
|
||||
int __sys_getfsstat(struct statfs *, long, int);
|
||||
int __sys_gettimeofday(struct timeval *, struct timezone *);
|
||||
int __sys_kevent(int, const struct kevent *, int, struct kevent *,
|
||||
int, const struct timespec *);
|
||||
__off_t __sys_lseek(int, __off_t, int);
|
||||
void *__sys_mmap(void *, __size_t, int, int, int, __off_t);
|
||||
int __sys_msync(void *, __size_t, int);
|
||||
int __sys_nanosleep(const struct timespec *, struct timespec *);
|
||||
int __sys_open(const char *, int, ...);
|
||||
int __sys_openat(int, const char *, int, ...);
|
||||
int __sys_pdfork(int *, int);
|
||||
int __sys_pselect(int, struct fd_set *, struct fd_set *,
|
||||
struct fd_set *, const struct timespec *,
|
||||
const __sigset_t *);
|
||||
int __sys_ptrace(int, __pid_t, char *, int);
|
||||
int __sys_poll(struct pollfd *, unsigned, int);
|
||||
int __sys_ppoll(struct pollfd *, unsigned, const struct timespec *,
|
||||
const __sigset_t *);
|
||||
__ssize_t __sys_pread(int, void *, __size_t, __off_t);
|
||||
__ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
|
||||
__ssize_t __sys_read(int, void *, __size_t);
|
||||
__ssize_t __sys_readv(int, const struct iovec *, int);
|
||||
__ssize_t __sys_recv(int, void *, __size_t, int);
|
||||
__ssize_t __sys_recvfrom(int, void *, __size_t, int, struct sockaddr *,
|
||||
__socklen_t *);
|
||||
__ssize_t __sys_recvmsg(int, struct msghdr *, int);
|
||||
int __sys_sched_getcpu(void);
|
||||
int __sys_select(int, struct fd_set *, struct fd_set *,
|
||||
struct fd_set *, struct timeval *);
|
||||
__ssize_t __sys_sendmsg(int, const struct msghdr *, int);
|
||||
__ssize_t __sys_sendto(int, const void *, __size_t, int,
|
||||
const struct sockaddr *, __socklen_t);
|
||||
int __sys_setcontext(const struct __ucontext *);
|
||||
int __sys_sigaction(int, const struct sigaction *,
|
||||
struct sigaction *);
|
||||
int __sys_sigprocmask(int, const __sigset_t *, __sigset_t *);
|
||||
int __sys_sigsuspend(const __sigset_t *);
|
||||
int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *,
|
||||
const struct timespec *);
|
||||
int __sys_sigwait(const __sigset_t *, int *);
|
||||
int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *);
|
||||
int __sys___specialfd(int, const void *, __size_t);
|
||||
int __sys_statfs(const char *, struct statfs *);
|
||||
int __sys_swapcontext(struct __ucontext *,
|
||||
const struct __ucontext *);
|
||||
int __sys_thr_kill(long, int);
|
||||
int __sys_thr_self(long *);
|
||||
int __sys_truncate(const char *, __off_t);
|
||||
__pid_t __sys_wait4(__pid_t, int *, int, struct rusage *);
|
||||
__pid_t __sys_wait6(enum idtype, __id_t, int *, int,
|
||||
struct __wrusage *, struct __siginfo *);
|
||||
__ssize_t __sys_write(int, const void *, __size_t);
|
||||
__ssize_t __sys_writev(int, const struct iovec *, int);
|
||||
int __sys_shm_open2(const char *, int, __mode_t, int, const char *);
|
||||
|
||||
int __libc_execvpe(const char *, char * const *, char * const *);
|
||||
int __libc_sigaction(int, const struct sigaction *,
|
||||
struct sigaction *) __hidden;
|
||||
int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *)
|
||||
__hidden;
|
||||
int __libc_sigsuspend(const __sigset_t *) __hidden;
|
||||
int __libc_sigwait(const __sigset_t * __restrict,
|
||||
int * restrict sig);
|
||||
int __libsys_sigwait(const __sigset_t *, int *) __hidden;
|
||||
int __libc_system(const char *);
|
||||
int __libc_tcdrain(int);
|
||||
int __fcntl_compat(int fd, int cmd, ...);
|
||||
|
||||
int __sys_futimens(int fd, const struct timespec *times) __hidden;
|
||||
int __sys_utimensat(int fd, const char *path,
|
||||
const struct timespec *times, int flag) __hidden;
|
||||
|
||||
int _elf_aux_info(int aux, void *buf, int buflen);
|
||||
struct dl_phdr_info;
|
||||
int __elf_phdr_match_addr(struct dl_phdr_info *, void *);
|
||||
void __init_elf_aux_vector(void);
|
||||
void __libc_map_stacks_exec(void);
|
||||
void __libc_distribute_static_tls(__size_t, void *, __size_t, __size_t);
|
||||
__uintptr_t __libc_static_tls_base(__size_t);
|
||||
|
||||
void _pthread_cancel_enter(int);
|
||||
void _pthread_cancel_leave(int);
|
||||
@@ -444,7 +376,11 @@ struct __nl_cat_d;
|
||||
struct _xlocale;
|
||||
struct __nl_cat_d *__catopen_l(const char *name, int type,
|
||||
struct _xlocale *locale);
|
||||
int __strerror_rl(int errnum, char *strerrbuf, __size_t buflen,
|
||||
int __strerror_rl(int errnum, char *strerrbuf, size_t buflen,
|
||||
struct _xlocale *locale);
|
||||
|
||||
struct uexterror;
|
||||
int __uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz);
|
||||
int __libc_uexterr_gettext(char *buf, size_t bufsz);
|
||||
|
||||
#endif /* _LIBC_PRIVATE_H_ */
|
||||
|
||||
@@ -139,10 +139,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.path = "common" ++ path.sep_str ++ "crtbrand.S",
|
||||
.flags = acflags.items,
|
||||
},
|
||||
.{
|
||||
.path = "common" ++ path.sep_str ++ "crtend.c",
|
||||
.flags = cflags.items,
|
||||
},
|
||||
.{
|
||||
.path = "common" ++ path.sep_str ++ "feature_note.S",
|
||||
.flags = acflags.items,
|
||||
|
||||
Reference in New Issue
Block a user