authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-07 09:17:55+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-07 09:18:38+01:00
log51f62ea918248817ad50fe4c8123aa694b5fbc85
tree652724eade6eb1ee08f8eed162890a7f3c11b96c
parent2f20ee373bbb2527272ed04af46ba68963f8b7ea
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libc: update startup code from freebsd 15


12 files changed, 36 insertions(+), 217 deletions(-)

lib/libc/freebsd/COPYRIGHT+1-2
...@@ -1,9 +1,8 @@...@@ -1,9 +1,8 @@
1# @(#)COPYRIGHT 8.2 (Berkeley) 3/21/94
21
3The compilation of software known as FreeBSD is distributed under the2The compilation of software known as FreeBSD is distributed under the
4following terms:3following terms:
54
6Copyright (c) 1992-2023 The FreeBSD Project.5Copyright (c) 1992-2025 The FreeBSD Project.
76
8Redistribution and use in source and binary forms, with or without7Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions8modification, are permitted provided that the following conditions
lib/libc/freebsd/lib/csu/amd64/crt1_s.S+6-9
...@@ -49,15 +49,12 @@ _start:...@@ -49,15 +49,12 @@ _start:
49#ifdef GCRT49#ifdef GCRT
50 subq $16, %rsp50 subq $16, %rsp
51#endif51#endif
52 movq %rsi, %rcx52 movq %rsi, %rcx /* cleanup */
53 movq %rdi, %rsi /* argv = ap */53 movslq (%rdi), %rax /* long *ap; tmpargc = *ap */
54 addq $8, %rsi /* argv += 1 */54 leaq 0x8(%rdi), %rsi /* argv = ap + 1 */
55 movq %rdi, %rdx /* env = ap */55 leaq 0x10(%rdi, %rax, 8), %rdx /* env = ap + 2 + tmpargc */
56 addq $16, %rdx /* env += 2 */56 movl %eax, %edi /* argc = tmpargc */
57 movslq (%rdi), %rax57
58 movl %eax, %edi /* argc = *(long *)(void *)ap */
59 shlq $3, %rax
60 addq %rax, %rdx /* env += argc */
61#ifdef PIC58#ifdef PIC
62 /*59 /*
63 * XXX. %rip relative addressing is not intended for use in the60 * XXX. %rip relative addressing is not intended for use in the
lib/libc/freebsd/lib/csu/arm/crt1_c.c-1
...@@ -41,7 +41,6 @@...@@ -41,7 +41,6 @@
41 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.41 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */42 */
4343
44#include <sys/cdefs.h>
45#include <sys/param.h>44#include <sys/param.h>
46#include <sys/elf_common.h>45#include <sys/elf_common.h>
4746
lib/libc/freebsd/lib/csu/common/crtbegin.c+2-43
...@@ -21,7 +21,6 @@...@@ -21,7 +21,6 @@
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */22 */
2323
24#include <sys/cdefs.h>
25#include <sys/param.h>24#include <sys/param.h>
2625
27#include "crt.h"26#include "crt.h"
...@@ -41,9 +40,8 @@ void __cxa_finalize(void *) __weak_symbol;...@@ -41,9 +40,8 @@ void __cxa_finalize(void *) __weak_symbol;
41 * When we have ctors/dtors call from the dtor handler before calling40 * When we have ctors/dtors call from the dtor handler before calling
42 * any dtors, otherwise use a destructor.41 * any dtors, otherwise use a destructor.
43 */42 */
44#ifndef HAVE_CTORS43/* zig patch: no HAVE_CTORS */
45__attribute__((destructor))44__attribute__((destructor))
46#endif
47static void45static void
48run_cxa_finalize(void)46run_cxa_finalize(void)
49{47{
...@@ -53,43 +51,4 @@ run_cxa_finalize(void)...@@ -53,43 +51,4 @@ run_cxa_finalize(void)
53}51}
54#endif52#endif
5553
56/*54/* zig patch: no HAVE_CTORS */
57 * On some architectures and toolchains we may need to call the .dtors.
58 * These are called in the order they are in the ELF file.
59 */
60#ifdef HAVE_CTORS
61static void __do_global_dtors_aux(void) __used;
62
63static crt_func __CTOR_LIST__[] __section(".ctors") __used = {
64 (crt_func)-1
65};
66static crt_func __DTOR_LIST__[] __section(".dtors") __used = {
67 (crt_func)-1
68};
69
70static void
71__do_global_dtors_aux(void)
72{
73 crt_func fn;
74 int n;
75
76#ifdef SHARED
77 run_cxa_finalize();
78#endif
79
80 for (n = 1;; n++) {
81 fn = __DTOR_LIST__[n];
82 if (fn == (crt_func)0 || fn == (crt_func)-1)
83 break;
84 fn();
85 }
86}
87
88asm (
89 ".pushsection .fini \n"
90 "\t" INIT_CALL_SEQ(__do_global_dtors_aux) "\n"
91 ".popsection \n"
92);
93#endif
94
95/* zig patch: remove gcj nonsense */
lib/libc/freebsd/lib/csu/common/crtbrand.S+1-1
...@@ -36,7 +36,7 @@...@@ -36,7 +36,7 @@
36 * for more information.36 * for more information.
37 */37 */
3838
39 .section .note.tag,"aG",%note,.freebsd.noteG,comdat39 .section .note.tag,"aGR",%note,.freebsd.noteG,comdat
40 .p2align 240 .p2align 2
41 .4byte 2f-1f41 .4byte 2f-1f
42 .4byte 4f-3f42 .4byte 4f-3f
lib/libc/freebsd/lib/csu/common/crtend.c deleted-65
...@@ -1,65 +0,0 @@
1/*-
2 * SPDX-License-Identifier: BSD-1-Clause
3 *
4 * Copyright 2018 Andrew Turner
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23
24#include <sys/cdefs.h>
25#include "crt.h"
26
27typedef void (*crt_func)(void);
28
29/* zig patch: remove gcj nonsense */
30
31#ifdef HAVE_CTORS
32
33/*
34 * On some architectures and toolchains we may need to call the .ctors.
35 * These are called in the reverse order they are in the ELF file.
36 */
37static void __do_global_ctors_aux(void) __used;
38
39static crt_func __CTOR_END__[] __section(".ctors") __used = {
40 (crt_func)0
41};
42static crt_func __DTOR_END__[] __section(".dtors") __used = {
43 (crt_func)0
44};
45
46static void
47__do_global_ctors_aux(void)
48{
49 crt_func fn;
50 int n;
51
52 for (n = 1;; n++) {
53 fn = __CTOR_END__[-n];
54 if (fn == (crt_func)0 || fn == (crt_func)-1)
55 break;
56 fn();
57 }
58}
59
60asm (
61 ".pushsection .init \n"
62 "\t" INIT_CALL_SEQ(__do_global_ctors_aux) "\n"
63 ".popsection \n"
64);
65#endif
lib/libc/freebsd/lib/csu/common/feature_note.S+1-1
...@@ -29,7 +29,7 @@...@@ -29,7 +29,7 @@
29#include <sys/elf_common.h>29#include <sys/elf_common.h>
30#include "notes.h"30#include "notes.h"
3131
32 .section .note.tag,"a",%note32 .section .note.tag,"aR",%note
33 .p2align 233 .p2align 2
34 .4byte 2f-1f34 .4byte 2f-1f
35 .4byte 4f-3f35 .4byte 4f-3f
lib/libc/freebsd/lib/csu/common/ignore_init_note.S+1-1
...@@ -30,7 +30,7 @@...@@ -30,7 +30,7 @@
3030
31#include "notes.h"31#include "notes.h"
3232
33 .section .note.tag,"a",%note33 .section .note.tag,"aR",%note
34 .p2align 234 .p2align 2
35 .4byte 2f-1f35 .4byte 2f-1f
36 .4byte 4f-3f36 .4byte 4f-3f
lib/libc/freebsd/lib/csu/powerpc/crt.h+1-2
...@@ -24,8 +24,7 @@...@@ -24,8 +24,7 @@
24#ifndef _CRT_H_24#ifndef _CRT_H_
25#define _CRT_H_25#define _CRT_H_
2626
27/* zig patch: no HAVE_CTORS */27/* zig patch: no HAVE_CTORS/CTORS_CONSTRUCTORS */
28#define CTORS_CONSTRUCTORS
29#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"28#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
3029
31#endif30#endif
lib/libc/freebsd/lib/csu/powerpc64/crt.h+1-2
...@@ -24,8 +24,7 @@...@@ -24,8 +24,7 @@
24#ifndef _CRT_H_24#ifndef _CRT_H_
25#define _CRT_H_25#define _CRT_H_
2626
27/* zig patch: no HAVE_CTORS */27/* zig patch: no HAVE_CTORS/CTORS_CONSTRUCTORS */
28#define CTORS_CONSTRUCTORS
29#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"28#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
3029
31#endif30#endif
lib/libc/freebsd/lib/libc/include/libc_private.h+22-86
...@@ -37,6 +37,8 @@...@@ -37,6 +37,8 @@
37#include <sys/_types.h>37#include <sys/_types.h>
38#include <sys/_pthreadtypes.h>38#include <sys/_pthreadtypes.h>
3939
40#include <libsys.h>
41
40extern char **environ;42extern char **environ;
4143
42/*44/*
...@@ -185,10 +187,12 @@ typedef enum {...@@ -185,10 +187,12 @@ typedef enum {
185 PJT_GETTHREADID_NP,187 PJT_GETTHREADID_NP,
186 PJT_ATTR_GET_NP,188 PJT_ATTR_GET_NP,
187 PJT_GETNAME_NP,189 PJT_GETNAME_NP,
190 PJT_SUSPEND_ALL_NP,
191 PJT_RESUME_ALL_NP,
188 PJT_MAX192 PJT_MAX
189} pjt_index_t;193} pjt_index_t;
190194
191typedef int (*pthread_func_t)(void);195typedef void (*pthread_func_t)(void);
192typedef pthread_func_t pthread_func_entry_t[2];196typedef pthread_func_t pthread_func_entry_t[2];
193197
194extern pthread_func_entry_t __thr_jtable[];198extern pthread_func_entry_t __thr_jtable[];
...@@ -197,9 +201,10 @@ void __set_error_selector(int *(*arg)(void));...@@ -197,9 +201,10 @@ void __set_error_selector(int *(*arg)(void));
197int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,201int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
198 void *(calloc_cb)(__size_t, __size_t));202 void *(calloc_cb)(__size_t, __size_t));
199203
200typedef int (*interpos_func_t)(void);204typedef void (*interpos_func_t)(void);
201interpos_func_t *__libc_interposing_slot(int interposno);205interpos_func_t *__libc_interposing_slot(int interposno);
202extern interpos_func_t __libc_interposing[] __hidden;206extern interpos_func_t __libc_interposing[] __hidden;
207interpos_func_t *__libsys_interposing_slot(int interposno);
203208
204enum {209enum {
205 INTERPOS_accept,210 INTERPOS_accept,
...@@ -244,11 +249,18 @@ enum {...@@ -244,11 +249,18 @@ enum {
244 INTERPOS_map_stacks_exec,249 INTERPOS_map_stacks_exec,
245 INTERPOS_fdatasync,250 INTERPOS_fdatasync,
246 INTERPOS_clock_nanosleep,251 INTERPOS_clock_nanosleep,
247 INTERPOS_distribute_static_tls,252 INTERPOS__reserved0, /* was distribute_static_tls */
248 INTERPOS_pdfork,253 INTERPOS_pdfork,
254 INTERPOS_uexterr_gettext,
249 INTERPOS_MAX255 INTERPOS_MAX
250};256};
251257
258#define _INTERPOS_SYS(type, idx, ...) \
259 ((type *)*(__libc_interposing_slot(idx)))(__VA_ARGS__)
260#define INTERPOS_SYS(syscall, ...) \
261 _INTERPOS_SYS(__sys_## syscall ##_t, INTERPOS_## syscall \
262 __VA_OPT__(,) __VA_ARGS__)
263
252/*264/*
253 * yplib internal interfaces265 * yplib internal interfaces
254 */266 */
...@@ -333,102 +345,22 @@ struct __siginfo;...@@ -333,102 +345,22 @@ struct __siginfo;
333struct __ucontext;345struct __ucontext;
334struct __wrusage;346struct __wrusage;
335enum idtype;347enum idtype;
336int __sys_aio_suspend(const struct aiocb * const[], int,
337 const struct timespec *);
338int __sys_accept(int, struct sockaddr *, __socklen_t *);
339int __sys_accept4(int, struct sockaddr *, __socklen_t *, int);
340int __sys_clock_gettime(__clockid_t, struct timespec *ts);
341int __sys_clock_nanosleep(__clockid_t, int,
342 const struct timespec *, struct timespec *);
343int __sys_close(int);
344int __sys_close_range(unsigned, unsigned, int);
345int __sys_connect(int, const struct sockaddr *, __socklen_t);
346int __sys_fcntl(int, int, ...);
347int __sys_fdatasync(int);
348int __sys_fstat(int fd, struct stat *);
349int __sys_fstatfs(int fd, struct statfs *);
350int __sys_fstatat(int, const char *, struct stat *, int);
351int __sys_fsync(int);
352__pid_t __sys_fork(void);
353int __sys_ftruncate(int, __off_t);
354__ssize_t __sys_getdirentries(int, char *, __size_t, __off_t *);
355int __sys_getfsstat(struct statfs *, long, int);
356int __sys_gettimeofday(struct timeval *, struct timezone *);
357int __sys_kevent(int, const struct kevent *, int, struct kevent *,
358 int, const struct timespec *);
359__off_t __sys_lseek(int, __off_t, int);
360void *__sys_mmap(void *, __size_t, int, int, int, __off_t);
361int __sys_msync(void *, __size_t, int);
362int __sys_nanosleep(const struct timespec *, struct timespec *);
363int __sys_open(const char *, int, ...);
364int __sys_openat(int, const char *, int, ...);
365int __sys_pdfork(int *, int);
366int __sys_pselect(int, struct fd_set *, struct fd_set *,
367 struct fd_set *, const struct timespec *,
368 const __sigset_t *);
369int __sys_ptrace(int, __pid_t, char *, int);
370int __sys_poll(struct pollfd *, unsigned, int);
371int __sys_ppoll(struct pollfd *, unsigned, const struct timespec *,
372 const __sigset_t *);
373__ssize_t __sys_pread(int, void *, __size_t, __off_t);
374__ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
375__ssize_t __sys_read(int, void *, __size_t);
376__ssize_t __sys_readv(int, const struct iovec *, int);
377__ssize_t __sys_recv(int, void *, __size_t, int);
378__ssize_t __sys_recvfrom(int, void *, __size_t, int, struct sockaddr *,
379 __socklen_t *);
380__ssize_t __sys_recvmsg(int, struct msghdr *, int);
381int __sys_sched_getcpu(void);
382int __sys_select(int, struct fd_set *, struct fd_set *,
383 struct fd_set *, struct timeval *);
384__ssize_t __sys_sendmsg(int, const struct msghdr *, int);
385__ssize_t __sys_sendto(int, const void *, __size_t, int,
386 const struct sockaddr *, __socklen_t);
387int __sys_setcontext(const struct __ucontext *);
388int __sys_sigaction(int, const struct sigaction *,
389 struct sigaction *);
390int __sys_sigprocmask(int, const __sigset_t *, __sigset_t *);
391int __sys_sigsuspend(const __sigset_t *);
392int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *,
393 const struct timespec *);
394int __sys_sigwait(const __sigset_t *, int *);
395int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *);
396int __sys___specialfd(int, const void *, __size_t);
397int __sys_statfs(const char *, struct statfs *);
398int __sys_swapcontext(struct __ucontext *,
399 const struct __ucontext *);
400int __sys_thr_kill(long, int);
401int __sys_thr_self(long *);
402int __sys_truncate(const char *, __off_t);
403__pid_t __sys_wait4(__pid_t, int *, int, struct rusage *);
404__pid_t __sys_wait6(enum idtype, __id_t, int *, int,
405 struct __wrusage *, struct __siginfo *);
406__ssize_t __sys_write(int, const void *, __size_t);
407__ssize_t __sys_writev(int, const struct iovec *, int);
408int __sys_shm_open2(const char *, int, __mode_t, int, const char *);
409348
349int __libc_execvpe(const char *, char * const *, char * const *);
410int __libc_sigaction(int, const struct sigaction *,350int __libc_sigaction(int, const struct sigaction *,
411 struct sigaction *) __hidden;351 struct sigaction *) __hidden;
412int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *)352int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *)
413 __hidden;353 __hidden;
414int __libc_sigsuspend(const __sigset_t *) __hidden;354int __libc_sigsuspend(const __sigset_t *) __hidden;
415int __libc_sigwait(const __sigset_t * __restrict,355int __libsys_sigwait(const __sigset_t *, int *) __hidden;
416 int * restrict sig);
417int __libc_system(const char *);356int __libc_system(const char *);
418int __libc_tcdrain(int);357int __libc_tcdrain(int);
419int __fcntl_compat(int fd, int cmd, ...);
420
421int __sys_futimens(int fd, const struct timespec *times) __hidden;
422int __sys_utimensat(int fd, const char *path,
423 const struct timespec *times, int flag) __hidden;
424358
425int _elf_aux_info(int aux, void *buf, int buflen);359int _elf_aux_info(int aux, void *buf, int buflen);
426struct dl_phdr_info;360struct dl_phdr_info;
427int __elf_phdr_match_addr(struct dl_phdr_info *, void *);361int __elf_phdr_match_addr(struct dl_phdr_info *, void *);
428void __init_elf_aux_vector(void);362void __init_elf_aux_vector(void);
429void __libc_map_stacks_exec(void);363void __libc_map_stacks_exec(void);
430void __libc_distribute_static_tls(__size_t, void *, __size_t, __size_t);
431__uintptr_t __libc_static_tls_base(__size_t);
432364
433void _pthread_cancel_enter(int);365void _pthread_cancel_enter(int);
434void _pthread_cancel_leave(int);366void _pthread_cancel_leave(int);
...@@ -444,7 +376,11 @@ struct __nl_cat_d;...@@ -444,7 +376,11 @@ struct __nl_cat_d;
444struct _xlocale;376struct _xlocale;
445struct __nl_cat_d *__catopen_l(const char *name, int type,377struct __nl_cat_d *__catopen_l(const char *name, int type,
446 struct _xlocale *locale);378 struct _xlocale *locale);
447int __strerror_rl(int errnum, char *strerrbuf, __size_t buflen,379int __strerror_rl(int errnum, char *strerrbuf, size_t buflen,
448 struct _xlocale *locale);380 struct _xlocale *locale);
449381
382struct uexterror;
383int __uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz);
384int __libc_uexterr_gettext(char *buf, size_t bufsz);
385
450#endif /* _LIBC_PRIVATE_H_ */386#endif /* _LIBC_PRIVATE_H_ */
src/libs/freebsd.zig-4
...@@ -139,10 +139,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -139,10 +139,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
139 .path = "common" ++ path.sep_str ++ "crtbrand.S",139 .path = "common" ++ path.sep_str ++ "crtbrand.S",
140 .flags = acflags.items,140 .flags = acflags.items,
141 },141 },
142 .{
143 .path = "common" ++ path.sep_str ++ "crtend.c",
144 .flags = cflags.items,
145 },
146 .{142 .{
147 .path = "common" ++ path.sep_str ++ "feature_note.S",143 .path = "common" ++ path.sep_str ++ "feature_note.S",
148 .flags = acflags.items,144 .flags = acflags.items,