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# @(#)COPYRIGHT 8.2 (Berkeley) 3/21/94
21
32The compilation of software known as FreeBSD is distributed under the
43following terms:
54
6Copyright (c) 1992-2023 The FreeBSD Project.
5Copyright (c) 1992-2025 The FreeBSD Project.
76
87Redistribution and use in source and binary forms, with or without
98modification, are permitted provided that the following conditions
lib/libc/freebsd/lib/csu/amd64/crt1_s.S+6-9
......@@ -49,15 +49,12 @@ _start:
4949#ifdef GCRT
5050 subq $16, %rsp
5151#endif
52 movq %rsi, %rcx
53 movq %rdi, %rsi /* argv = ap */
54 addq $8, %rsi /* argv += 1 */
55 movq %rdi, %rdx /* env = ap */
56 addq $16, %rdx /* env += 2 */
57 movslq (%rdi), %rax
58 movl %eax, %edi /* argc = *(long *)(void *)ap */
59 shlq $3, %rax
60 addq %rax, %rdx /* env += argc */
52 movq %rsi, %rcx /* cleanup */
53 movslq (%rdi), %rax /* long *ap; tmpargc = *ap */
54 leaq 0x8(%rdi), %rsi /* argv = ap + 1 */
55 leaq 0x10(%rdi, %rax, 8), %rdx /* env = ap + 2 + tmpargc */
56 movl %eax, %edi /* argc = tmpargc */
57
6158#ifdef PIC
6259 /*
6360 * 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 @@
4141 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242 */
4343
44#include <sys/cdefs.h>
4544#include <sys/param.h>
4645#include <sys/elf_common.h>
4746
lib/libc/freebsd/lib/csu/common/crtbegin.c+2-43
......@@ -21,7 +21,6 @@
2121 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2222 */
2323
24#include <sys/cdefs.h>
2524#include <sys/param.h>
2625
2726#include "crt.h"
......@@ -41,9 +40,8 @@ void __cxa_finalize(void *) __weak_symbol;
4140 * When we have ctors/dtors call from the dtor handler before calling
4241 * any dtors, otherwise use a destructor.
4342 */
44#ifndef HAVE_CTORS
43/* zig patch: no HAVE_CTORS */
4544__attribute__((destructor))
46#endif
4745static void
4846run_cxa_finalize(void)
4947{
......@@ -53,43 +51,4 @@ run_cxa_finalize(void)
5351}
5452#endif
5553
56/*
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 */
54/* zig patch: no HAVE_CTORS */
lib/libc/freebsd/lib/csu/common/crtbrand.S+1-1
......@@ -36,7 +36,7 @@
3636 * for more information.
3737 */
3838
39 .section .note.tag,"aG",%note,.freebsd.noteG,comdat
39 .section .note.tag,"aGR",%note,.freebsd.noteG,comdat
4040 .p2align 2
4141 .4byte 2f-1f
4242 .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 @@
2929#include <sys/elf_common.h>
3030#include "notes.h"
3131
32 .section .note.tag,"a",%note
32 .section .note.tag,"aR",%note
3333 .p2align 2
3434 .4byte 2f-1f
3535 .4byte 4f-3f
lib/libc/freebsd/lib/csu/common/ignore_init_note.S+1-1
......@@ -30,7 +30,7 @@
3030
3131#include "notes.h"
3232
33 .section .note.tag,"a",%note
33 .section .note.tag,"aR",%note
3434 .p2align 2
3535 .4byte 2f-1f
3636 .4byte 4f-3f
lib/libc/freebsd/lib/csu/powerpc/crt.h+1-2
......@@ -24,8 +24,7 @@
2424#ifndef _CRT_H_
2525#define _CRT_H_
2626
27/* zig patch: no HAVE_CTORS */
28#define CTORS_CONSTRUCTORS
27/* zig patch: no HAVE_CTORS/CTORS_CONSTRUCTORS */
2928#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
3029
3130#endif
lib/libc/freebsd/lib/csu/powerpc64/crt.h+1-2
......@@ -24,8 +24,7 @@
2424#ifndef _CRT_H_
2525#define _CRT_H_
2626
27/* zig patch: no HAVE_CTORS */
28#define CTORS_CONSTRUCTORS
27/* zig patch: no HAVE_CTORS/CTORS_CONSTRUCTORS */
2928#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
3029
3130#endif
lib/libc/freebsd/lib/libc/include/libc_private.h+22-86
......@@ -37,6 +37,8 @@
3737#include <sys/_types.h>
3838#include <sys/_pthreadtypes.h>
3939
40#include <libsys.h>
41
4042extern char **environ;
4143
4244/*
......@@ -185,10 +187,12 @@ typedef enum {
185187 PJT_GETTHREADID_NP,
186188 PJT_ATTR_GET_NP,
187189 PJT_GETNAME_NP,
190 PJT_SUSPEND_ALL_NP,
191 PJT_RESUME_ALL_NP,
188192 PJT_MAX
189193} pjt_index_t;
190194
191typedef int (*pthread_func_t)(void);
195typedef void (*pthread_func_t)(void);
192196typedef pthread_func_t pthread_func_entry_t[2];
193197
194198extern pthread_func_entry_t __thr_jtable[];
......@@ -197,9 +201,10 @@ void __set_error_selector(int *(*arg)(void));
197201int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
198202 void *(calloc_cb)(__size_t, __size_t));
199203
200typedef int (*interpos_func_t)(void);
204typedef void (*interpos_func_t)(void);
201205interpos_func_t *__libc_interposing_slot(int interposno);
202206extern interpos_func_t __libc_interposing[] __hidden;
207interpos_func_t *__libsys_interposing_slot(int interposno);
203208
204209enum {
205210 INTERPOS_accept,
......@@ -244,11 +249,18 @@ enum {
244249 INTERPOS_map_stacks_exec,
245250 INTERPOS_fdatasync,
246251 INTERPOS_clock_nanosleep,
247 INTERPOS_distribute_static_tls,
252 INTERPOS__reserved0, /* was distribute_static_tls */
248253 INTERPOS_pdfork,
254 INTERPOS_uexterr_gettext,
249255 INTERPOS_MAX
250256};
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
252264/*
253265 * yplib internal interfaces
254266 */
......@@ -333,102 +345,22 @@ struct __siginfo;
333345struct __ucontext;
334346struct __wrusage;
335347enum 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 *);
410350int __libc_sigaction(int, const struct sigaction *,
411351 struct sigaction *) __hidden;
412352int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *)
413353 __hidden;
414354int __libc_sigsuspend(const __sigset_t *) __hidden;
415int __libc_sigwait(const __sigset_t * __restrict,
416 int * restrict sig);
355int __libsys_sigwait(const __sigset_t *, int *) __hidden;
417356int __libc_system(const char *);
418357int __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
425359int _elf_aux_info(int aux, void *buf, int buflen);
426360struct dl_phdr_info;
427361int __elf_phdr_match_addr(struct dl_phdr_info *, void *);
428362void __init_elf_aux_vector(void);
429363void __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
433365void _pthread_cancel_enter(int);
434366void _pthread_cancel_leave(int);
......@@ -444,7 +376,11 @@ struct __nl_cat_d;
444376struct _xlocale;
445377struct __nl_cat_d *__catopen_l(const char *name, int type,
446378 struct _xlocale *locale);
447int __strerror_rl(int errnum, char *strerrbuf, __size_t buflen,
379int __strerror_rl(int errnum, char *strerrbuf, size_t buflen,
448380 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
450386#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
139139 .path = "common" ++ path.sep_str ++ "crtbrand.S",
140140 .flags = acflags.items,
141141 },
142 .{
143 .path = "common" ++ path.sep_str ++ "crtend.c",
144 .flags = cflags.items,
145 },
146142 .{
147143 .path = "common" ++ path.sep_str ++ "feature_note.S",
148144 .flags = acflags.items,