authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-29 08:51:50+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-31 23:04:48+02:00
logb3c063c8b837822e9ee7a0122620ef0ece9aab13
treefb604032f593d1862a4a11f1fad86d5563036593
parent2579b37ff6e7f08fe90cf920a83e1282e51c571e
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libc: update glibc crt0 code to 2.44


23 files changed, 875 insertions(+), 624 deletions(-)

lib/libc/glibc/elf/elf.h+6-2
......@@ -798,7 +798,8 @@ typedef struct
798798#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
799799#define NT_X86_SHSTK 0x204 /* x86 SHSTK state */
800800#define NT_X86_XSAVE_LAYOUT 0x205 /* XSAVE layout description. */
801#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
801#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves. This was
802 used in now removed s390-32 arch. */
802803#define NT_S390_TIMER 0x301 /* s390 timer register */
803804#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
804805#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
......@@ -846,6 +847,7 @@ typedef struct
846847#define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */
847848#define NT_RISCV_TAGGED_ADDR_CTRL 0x902 /* RISC-V tagged
848849 address control */
850#define NT_RISCV_USER_CFI 0x903 /* RISC-V shadow stack state */
849851#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers. */
850852#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and
851853 status registers. */
......@@ -3470,7 +3472,9 @@ enum
34703472
34713473/* Valid values for the e_flags field. */
34723474
3473#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */
3475#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed.
3476 This was used in now removed s390-32
3477 arch. */
34743478
34753479/* Additional s390 relocs */
34763480
lib/libc/glibc/include/libc-symbols.h+2-1
......@@ -113,6 +113,7 @@
113113#define HAVE_LIBINTL_H 1
114114#define HAVE_WCTYPE_H 1
115115#define HAVE_ISWCTYPE 1
116#define HAVE_MEMPCPY 1
116117#define ENABLE_NLS 1
117118
118119/* The symbols in all the user (non-_) macros are C symbols. */
......@@ -682,7 +683,7 @@ for linking")
682683
683684/* Helper / base macros for indirect function symbols. */
684685#define __ifunc_resolver(type_name, name, expr, init, classifier, ...) \
685 classifier inhibit_stack_protector \
686 classifier \
686687 __typeof (type_name) *name##_ifunc (__VA_ARGS__) \
687688 { \
688689 init (); \
lib/libc/glibc/sysdeps/aarch64/sysdep.h+28-4
......@@ -43,7 +43,6 @@
4343#define FEATURE_1_PAC 2
4444#define FEATURE_1_GCS 4
4545
46/* Add a NT_GNU_PROPERTY_TYPE_0 note. */
4746#define GNU_PROPERTY(type, value) \
4847 .section .note.gnu.property, "a"; \
4948 .p2align 3; \
......@@ -57,9 +56,34 @@
5756 .word 0; \
5857 .text
5958
60/* Add GNU property note with the supported features to all asm code
61 where sysdep.h is included. */
62GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS)
59#ifdef __ARM_BUILDATTR64_FV
60/* Add AArch64 feature bits build attributes. */
61# define FEATURE_1_AND_MARK(value) \
62 .aeabi_subsection aeabi_feature_and_bits, optional, ULEB128; \
63 .if ((value) & FEATURE_1_BTI); \
64 .aeabi_attribute Tag_Feature_BTI, 1; \
65 .else; \
66 .aeabi_attribute Tag_Feature_BTI, 0; \
67 .endif; \
68 .if ((value) & FEATURE_1_GCS); \
69 .aeabi_attribute Tag_Feature_GCS, 1; \
70 .else; \
71 .aeabi_attribute Tag_Feature_GCS, 0; \
72 .endif; \
73 .if ((value) & FEATURE_1_PAC); \
74 .aeabi_attribute Tag_Feature_PAC, 1; \
75 .else; \
76 .aeabi_attribute Tag_Feature_PAC, 0; \
77 .endif; \
78 .text
79#else
80/* Add a NT_GNU_PROPERTY_TYPE_0 note. */
81# define FEATURE_1_AND_MARK(value) GNU_PROPERTY (FEATURE_1_AND, value)
82#endif /* __ARM_BUILDATTR64_FV */
83
84/* Add marking with the supported features to all asm code where sysdep.h
85 is included. */
86FEATURE_1_AND_MARK (FEATURE_1_BTI | FEATURE_1_PAC | FEATURE_1_GCS)
6387
6488/* Define an entry point visible from C. */
6589#define ENTRY(name) \
lib/libc/glibc/sysdeps/arm/start.S+27
......@@ -90,6 +90,7 @@ _start:
9090 push { a1 }
9191
9292#ifdef PIC
93# ifdef SHARED
9394 ldr sl, .L_GOT
9495 adr a4, .L_GOT
9596 add sl, sl, a4
......@@ -103,6 +104,16 @@ _start:
103104 /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
104105 /* Let the libc call main and exit with its return code. */
105106 bl __libc_start_main(PLT)
107# else
108 ldr a1, .L_main_rel /* Load the relative offset of __wrap_main. */
109 adr a4, .L_main_rel /* Load the actual runtime address of the label. */
110 add a1, a4, a1 /* Add them together to get the absolute address. */
111
112 mov a4, #0 /* Used to be init. */
113 push { a4 } /* Used to be fini. */
114
115 bl __libc_start_main
116# endif /* ifdef SHARED */
106117#else
107118
108119 mov a4, #0 /* Used to init. */
......@@ -119,14 +130,30 @@ _start:
119130
120131#ifdef PIC
121132 .align 2
133# ifdef SHARED
122134.L_GOT:
123135 .word _GLOBAL_OFFSET_TABLE_ - .L_GOT
124136 .word main(GOT)
137# else
138.L_main_rel:
139 .word __wrap_main - .L_main_rel
140# endif
125141#endif
126142
127143 .cantunwind
128144 .fnend
129145
146#if defined PIC && !defined SHARED
147/* When main is not defined in the executable but in a shared library then
148 a wrapper is needed, because crt1.o and rcrt1.o share this code and the
149 latter (static PIE) must avoid GOT relocations before __libc_start_main
150 is called. The branch to main is turned into a PLT entry by every linker,
151 unlike a REL32 data relocation against main. */
152 .type __wrap_main, %function
153__wrap_main:
154 b main
155#endif
156
130157/* Define a symbol for the first piece of initialized data. */
131158 .data
132159 .globl __data_start
lib/libc/glibc/sysdeps/htl/libc-lockP.h+14
......@@ -21,6 +21,20 @@
2121
2222#include <pthread.h>
2323
24typedef pthread_rwlock_t __libc_rwlock_t;
25
26#define __libc_rwlock_define(CLASS,NAME) \
27 CLASS __libc_rwlock_t NAME;
28#define __libc_rwlock_define_initialized(CLASS,NAME) \
29 CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER;
30#define __libc_rwlock_init(NAME) __pthread_rwlock_init (&(NAME), NULL)
31#define __libc_rwlock_fini(NAME) ((void) 0)
32#define __libc_rwlock_rdlock(NAME) __pthread_rwlock_rdlock (&(NAME))
33#define __libc_rwlock_wrlock(NAME) __pthread_rwlock_wrlock (&(NAME))
34#define __libc_rwlock_tryrdlock(NAME) __pthread_rwlock_tryrdlock (&(NAME))
35#define __libc_rwlock_trywrlock(NAME) __pthread_rwlock_trywrlock (&(NAME))
36#define __libc_rwlock_unlock(NAME) __pthread_rwlock_unlock (&(NAME))
37
2438/* If we check for a weakly referenced symbol and then perform a
2539 normal jump to it te code generated for some platforms in case of
2640 PIC is unnecessarily slow. What would happen is that the function
lib/libc/glibc/sysdeps/loongarch/start.S+18-8
......@@ -36,6 +36,7 @@
3636#define __ASSEMBLY__ 1
3737#include <entry.h>
3838#include <sys/asm.h>
39#include <sysdep.h>
3940
4041/* The entry point's job is to call __libc_start_main. Per the ABI,
4142 a0 contains the address of a function to be passed to atexit.
......@@ -57,23 +58,32 @@ ENTRY (ENTRY_POINT)
5758/* Terminate call stack by noting ra is undefined. Use a dummy
5859 .cfi_label to force starting the FDE. */
5960 .cfi_label .Ldummy
60 cfi_undefined (1)
61 cfi_undefined (1)
6162 or a5, a0, zero /* rtld_fini */
6263
63 la.pcrel a0, t0, main
64#if defined PIC && !defined SHARED
65 /* Avoid relocation in static PIE since _start is called before it
66 is relocated. */
67 la.pcrel a0, __wrap_main
68#else
69 LA_GOT (a0, main)
70#endif
71
6472 REG_L a1, sp, 0
6573 ADDI a2, sp, SZREG
6674
67 /* Adjust $sp for 16-aligned */
68 BSTRINS sp, zero, 3, 0
75 /* Adjust $sp for 16-bytes aligned */
76 REG_ALIGN_ASM (sp, 4)
6977
7078 move a3, zero /* used to be init */
7179 move a4, zero /* used to be fini */
7280 or a6, sp, zero /* stack_end */
7381
74 la.pcrel ra, t0, __libc_start_main
75 jirl ra, ra, 0
82 CALL (__libc_start_main)
83 CALL (abort)
7684
77 la.pcrel ra, t0, abort
78 jirl ra, ra, 0
85#if defined PIC && !defined SHARED
86__wrap_main:
87 TAIL (main)
88#endif
7989END (ENTRY_POINT)
lib/libc/glibc/sysdeps/loongarch/sys/asm.h created+104
......@@ -0,0 +1,104 @@
1/* Miscellaneous macros.
2 Copyright (C) 2022-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_ASM_H
20#define _SYS_ASM_H
21
22#include <sys/regdef.h>
23#include <sysdeps/generic/sysdep.h>
24
25/* Macros to handle different pointer/register sizes for 32/64-bit code. */
26#if __loongarch_grlen == 64
27#define SZREG 8
28#define REG_L ld.d
29#define REG_S st.d
30#define SRLI srli.d
31#define SLLI slli.d
32#define ADDI addi.d
33#define ADD add.d
34#define SUB sub.d
35#define LI li.d
36#define BSTRINS bstrins.d
37
38#elif __loongarch_grlen == 32
39
40#define SZREG 4
41#define REG_L ld.w
42#define REG_S st.w
43#define SRLI srli.w
44#define SLLI slli.w
45#define ADDI addi.w
46#define ADD add.w
47#define SUB sub.w
48#define LI li.w
49#define BSTRINS bstrins.w
50
51#else
52#error __loongarch_grlen must equal 32 or 64
53#endif
54
55#if __loongarch_frlen == 64
56 #define SZFREG 8
57 #define FREG_L fld.d
58 #define FREG_S fst.d
59#elif __loongarch_frlen == 32
60 #define SZFREG 4
61 #define FREG_L fld.s
62 #define FREG_S fst.s
63#endif
64
65#define SZVREG 16
66#define SZXREG 32
67
68/* Declare leaf routine.
69 The usage of macro LEAF/ENTRY is as follows:
70 1. LEAF(fcn) -- the align value of fcn is .align 3 (default value)
71 2. LEAF(fcn, 6) -- the align value of fcn is .align 6
72*/
73#define LEAF_IMPL(symbol, aln, ...) \
74 .text; \
75 .globl symbol; \
76 .align aln; \
77 .type symbol, @function; \
78symbol: \
79 cfi_startproc;
80
81
82#define LEAF(...) LEAF_IMPL(__VA_ARGS__, 3)
83#define ENTRY(...) LEAF(__VA_ARGS__)
84
85#define LEAF_NO_ALIGN(symbol) \
86 .text; \
87 .globl symbol; \
88 .type symbol, @function; \
89symbol: \
90 cfi_startproc;
91
92#define ENTRY_NO_ALIGN(symbol) LEAF_NO_ALIGN(symbol)
93
94
95/* Mark end of function. */
96#undef END
97#define END(function) \
98 cfi_endproc; \
99 .size function, .- function;
100
101/* Stack alignment. */
102#define ALMASK ~15
103
104#endif /* sys/asm.h */
lib/libc/glibc/sysdeps/loongarch/sysdep.h created+94
......@@ -0,0 +1,94 @@
1/* Macros for LoongArch.
2 Copyright (C) 2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LOONGARCH_SYSDEP_H
20#define _LOONGARCH_SYSDEP_H
21
22#if __loongarch_grlen == 64
23
24#define PTRLOG 3
25/* Align reg to 2^n. Used in C. */
26#define REG_ALIGN_C(reg, n) \
27 "bstrins.d\t" __STRING(reg) ", $zero, (" __STRING(n) "-1), 0"
28
29#elif __loongarch_grlen == 32
30
31#define PTRLOG 2
32#define REG_ALIGN_C(reg, n) \
33 "srli.w\t" __STRING(reg)", " __STRING(reg)", " __STRING(n) "\n\t" \
34 "slli.w\t" __STRING(reg)", " __STRING(reg)", " __STRING(n)
35
36#else
37#error __loongarch_grlen must equal 32 or 64
38#endif
39
40#ifdef __ASSEMBLER__
41
42/* Stack alignment bytes. */
43#define STACK_ALIGN 16
44
45/* Macros to handle different pointer/register sizes for 32/64-bit code. */
46#if __loongarch_grlen == 64
47#define SRAI srai.d
48
49/* Align reg to 2^n. Used in assembly. */
50#define REG_ALIGN_ASM(reg, n) bstrins.d reg, zero, (n-1), 0
51
52#define LOAD_LOCAL(reg, sym) \
53 pcalau12i reg, %pc_hi20(sym); \
54 ld.d reg, reg, %pc_lo12(sym);
55
56#define LOAD_GLOBAL(reg, sym) \
57 la.got reg, sym; \
58 ld.d reg, reg, 0;
59
60#define LA_GOT(reg, sym) la.got reg, t0, sym
61
62#define CALL(sym) call36 sym
63#define TAIL(sym) tail36 t0, sym
64
65#elif __loongarch_grlen == 32 /* __loongarch_grlen == 64 */
66
67#define SRAI srai.w
68
69/* LA32R not have bstrins.w, use srli.w and slli.w on both LA32S and LA32R. */
70#define REG_ALIGN_ASM(reg, n) \
71 srli.w reg, reg, n; \
72 slli.w reg, reg, n;
73
74#define LOAD_LOCAL(reg, sym) \
75 1: pcaddu12i reg, %pcadd_hi20(sym); \
76 ld.w reg, reg, %pcadd_lo12(1b);
77
78#define LOAD_GLOBAL(reg, sym) \
79 1: pcaddu12i reg, %got_pcadd_hi20(sym); \
80 ld.w reg, reg, %pcadd_lo12(1b); \
81 ld.w reg, reg, 0;
82
83#define LA_GOT(reg, sym) la.got reg, sym
84
85#define CALL(sym) call30 sym
86#define TAIL(sym) tail30 t0, sym
87
88#else /* __loongarch_grlen == 64 */
89#error __loongarch_grlen must equal 32 or 64
90#endif /* __loongarch_grlen == 64 */
91
92#endif /* __ASSEMBLER__ */
93
94#endif /* _LOONGARCH_SYSDEP_H */
lib/libc/glibc/sysdeps/mach/libc-lock.h+10-10
......@@ -145,16 +145,16 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
145145#define __rtld_lock_unlock_recursive(NAME) \
146146 __libc_lock_unlock_recursive (NAME)
147147
148/* XXX for now */
149#define __libc_rwlock_define __libc_lock_define
150#define __libc_rwlock_define_initialized __libc_lock_define_initialized
151#define __libc_rwlock_init __libc_lock_init
152#define __libc_rwlock_fini __libc_lock_fini
153#define __libc_rwlock_rdlock __libc_lock_lock
154#define __libc_rwlock_wrlock __libc_lock_lock
155#define __libc_rwlock_tryrdlock __libc_lock_trylock
156#define __libc_rwlock_trywrlock __libc_lock_trylock
157#define __libc_rwlock_unlock __libc_lock_unlock
148/* XXX for now, waiting for a futex-based pthread_rwlock implementation */
149#define __mach_rwlock_define __libc_lock_define
150#define __mach_rwlock_define_initialized __libc_lock_define_initialized
151#define __mach_rwlock_init __libc_lock_init
152#define __mach_rwlock_fini __libc_lock_fini
153#define __mach_rwlock_rdlock __libc_lock_lock
154#define __mach_rwlock_wrlock __libc_lock_lock
155#define __mach_rwlock_tryrdlock __libc_lock_trylock
156#define __mach_rwlock_trywrlock __libc_lock_trylock
157#define __mach_rwlock_unlock __libc_lock_unlock
158158
159159struct __libc_cleanup_frame
160160{
lib/libc/glibc/sysdeps/s390/s390-64/start-2.33.S deleted-107
......@@ -1,107 +0,0 @@
1/* Startup code compliant to the 64 bit S/390 ELF ABI.
2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 In addition to the permissions in the GNU Lesser General Public
12 License, the Free Software Foundation gives you unlimited
13 permission to link the compiled version of this file with other
14 programs, and to distribute those programs without any restriction
15 coming from the use of this file. (The GNU Lesser General Public
16 License restrictions do apply in other respects; for example, they
17 cover modification of the file, and distribution when not linked
18 into another program.)
19
20 Note that people who make modified versions of this file are not
21 obligated to grant this special exception for their modified
22 versions; it is their choice whether to do so. The GNU Lesser
23 General Public License gives permission to release a modified
24 version without this exception; this exception also makes it
25 possible to release a modified version which carries forward this
26 exception.
27
28 The GNU C Library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 Lesser General Public License for more details.
32
33 You should have received a copy of the GNU Lesser General Public
34 License along with the GNU C Library; if not, see
35 <https://www.gnu.org/licenses/>. */
36
37#include <sysdep.h>
38
39/*
40 This is the canonical entry point, usually the first thing in the text
41 segment. Most registers' values are unspecified, except for:
42
43 %r14 Contains a function pointer to be registered with `atexit'.
44 This is how the dynamic linker arranges to have DT_FINI
45 functions called for shared libraries that have been loaded
46 before this code runs.
47
48 %r15 The stack contains the arguments and environment:
49 0(%r15) argc
50 8(%r15) argv[0]
51 ...
52 (8*argc)(%r15) NULL
53 (8*(argc+1))(%r15) envp[0]
54 ...
55 NULL
56*/
57
58 .text
59 .globl _start
60 .type _start,@function
61_start:
62 cfi_startproc
63 /* Mark r14 as undefined in order to stop unwinding here! */
64 cfi_undefined (r14)
65 /* Load argc and argv from stack. */
66 la %r4,8(%r15) # get argv
67 lg %r3,0(%r15) # get argc
68
69 /* Align the stack to a double word boundary. */
70 lghi %r0,-16
71 ngr %r15,%r0
72
73 /* Setup a stack frame and a parameter area. */
74 aghi %r15,-176 # make room on stack
75 xc 0(8,%r15),0(%r15) # clear back-chain
76
77 /* Set up arguments for __libc_start_main:
78 main, argc, argv, envp, _init, _fini, rtld_fini, stack_end
79 Note that envp will be determined later in __libc_start_main.
80 */
81 stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area
82 la %r7,160(%r15)
83 larl %r6,__libc_csu_fini # load pointer to __libc_csu_fini
84 larl %r5,__libc_csu_init # load pointer to __libc_csu_init
85
86 /* Ok, now branch to the libc main routine. */
87#ifdef PIC
88 larl %r2,main@GOTENT # load pointer to main
89 lg %r2,0(%r2)
90 brasl %r14,__libc_start_main@plt
91#else
92 larl %r2,main # load pointer to main
93 brasl %r14,__libc_start_main
94#endif
95
96 /* Crash if __libc_start_main returns. */
97 .word 0
98
99 cfi_endproc
100
101 /* Define a symbol for the first piece of initialized data. */
102 .data
103 .globl __data_start
104__data_start:
105 .long 0
106 .weak data_start
107 data_start = __data_start
lib/libc/glibc/sysdeps/s390/s390-64/start.S deleted-134
......@@ -1,134 +0,0 @@
1/* Startup code compliant to the 64 bit S/390 ELF ABI.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 In addition to the permissions in the GNU Lesser General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file with other
13 programs, and to distribute those programs without any restriction
14 coming from the use of this file. (The GNU Lesser General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked
17 into another program.)
18
19 Note that people who make modified versions of this file are not
20 obligated to grant this special exception for their modified
21 versions; it is their choice whether to do so. The GNU Lesser
22 General Public License gives permission to release a modified
23 version without this exception; this exception also makes it
24 possible to release a modified version which carries forward this
25 exception.
26
27 The GNU C Library is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 Lesser General Public License for more details.
31
32 You should have received a copy of the GNU Lesser General Public
33 License along with the GNU C Library; if not, see
34 <https://www.gnu.org/licenses/>. */
35
36#include <sysdep.h>
37
38/*
39 This is the canonical entry point, usually the first thing in the text
40 segment. Most registers' values are unspecified, except for:
41
42 %r14 Contains a function pointer to be registered with `atexit'.
43 This is how the dynamic linker arranges to have DT_FINI
44 functions called for shared libraries that have been loaded
45 before this code runs.
46
47 %r15 The stack contains the arguments and environment:
48 0(%r15) argc
49 8(%r15) argv[0]
50 ...
51 (8*argc)(%r15) NULL
52 (8*(argc+1))(%r15) envp[0]
53 ...
54 NULL
55*/
56
57 .text
58 .globl _start
59 .type _start,@function
60_start:
61 cfi_startproc
62 /* Mark r14 as undefined in order to stop unwinding here! */
63 cfi_undefined (r14)
64 /* Load argc and argv from stack. */
65 la %r4,8(%r15) # get argv
66 lg %r3,0(%r15) # get argc
67
68 /* Align the stack to a double word boundary. */
69 lghi %r0,-16
70 ngr %r15,%r0
71
72 /* Setup a stack frame and a parameter area. */
73 aghi %r15,-176 # make room on stack
74 xc 0(8,%r15),0(%r15) # clear back-chain
75
76 /* Set up arguments for __libc_start_main:
77 main, argc, argv, envp, _init, _fini, rtld_fini, stack_end
78 Note that envp will be determined later in __libc_start_main.
79 */
80 stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area
81 la %r7,160(%r15)
82 lghi %r6,0 # Used to be fini.
83 lghi %r5,0 # Used to be init.
84
85 /* Ok, now branch to the libc main routine. */
86#ifdef PIC
87# ifdef SHARED
88 /* Used for dynamic linked position independent executable.
89 => Scrt1.o */
90 larl %r2,main@GOTENT # load pointer to main
91 lg %r2,0(%r2)
92# else
93 /* Used for dynamic linked position dependent executable.
94 => crt1.o (glibc configured without --disable-default-pie:
95 PIC is defined)
96 Or for static linked position independent executable.
97 => rcrt1.o (only available if glibc configured without
98 --disable-default-pie: PIC is defined) */
99 larl %r2,__wrap_main
100# endif
101 brasl %r14,__libc_start_main@plt
102#else
103 /* Used for dynamic/static linked position dependent executable.
104 => crt1.o (glibc configured with --disable-default-pie:
105 PIC and SHARED are not defined) */
106 larl %r2,main # load pointer to main
107 brasl %r14,__libc_start_main
108#endif
109
110 /* Crash if __libc_start_main returns. */
111 .word 0
112
113 cfi_endproc
114
115#if defined PIC && !defined SHARED
116 /* When main is not defined in the executable but in a shared library
117 then a wrapper is needed in crt1.o of the static-pie enabled libc,
118 because crt1.o and rcrt1.o share code and the later must avoid the
119 use of GOT relocations before __libc_start_main is called. */
120__wrap_main:
121 cfi_startproc
122 larl %r1,main@GOTENT # load pointer to main
123 lg %r1,0(%r1)
124 br %r1
125 cfi_endproc
126#endif
127
128 /* Define a symbol for the first piece of initialized data. */
129 .data
130 .globl __data_start
131__data_start:
132 .long 0
133 .weak data_start
134 data_start = __data_start
lib/libc/glibc/sysdeps/s390/s390-64/sysdep.h deleted-93
......@@ -1,93 +0,0 @@
1/* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <sysdeps/generic/sysdep.h>
20
21#ifdef __ASSEMBLER__
22
23/* Syntactic details of assembler. */
24
25/* ELF uses byte-counts for .align, most others use log2 of count of bytes. */
26#define ALIGNARG(log2) 1<<log2
27#define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
28
29
30/* Define an entry point visible from C. */
31#define ENTRY(name) \
32 .globl C_SYMBOL_NAME(name); \
33 .type C_SYMBOL_NAME(name),@function; \
34 .align ALIGNARG(4); \
35 C_LABEL(name) \
36 cfi_startproc; \
37 CALL_MCOUNT
38
39#undef END
40#define END(name) \
41 cfi_endproc; \
42 ASM_SIZE_DIRECTIVE(name) \
43
44/* If compiled for profiling, call `mcount' at the start of each function. */
45#ifdef PROF
46#ifdef PIC
47#define CALL_MCOUNT \
48 lgr 0,14 ; larl 1,0f ; brasl 14,_mcount@PLT ; lgr 14,0 ; \
49 .data ; .align 4 ; 0: .long 0 ; .text ;
50#else
51#define CALL_MCOUNT \
52 lgr 0,14 ; larl 1,0f ; brasl 14,_mcount ; lgr 14,0 ; \
53 .data ; .align 4 ; 0: .long 0 ; .text ;
54#endif
55#else
56#define CALL_MCOUNT /* Do nothing. */
57#endif
58
59/* Since C identifiers are not normally prefixed with an underscore
60 on this system, the asm identifier `syscall_error' intrudes on the
61 C name space. Make sure we use an innocuous name. */
62#define syscall_error __syscall_error
63#define mcount _mcount
64
65#undef PSEUDO
66#define PSEUDO(name, syscall_name, args) \
67lose: SYSCALL_PIC_SETUP \
68 jg JUMPTARGET(syscall_error); \
69 .globl syscall_error; \
70 ENTRY (name) \
71 DO_CALL (syscall_name, args); \
72 jm lose
73
74#undef PSEUDO_END
75#define PSEUDO_END(name) \
76 END (name)
77
78#undef JUMPTARGET
79#ifdef SHARED
80#define JUMPTARGET(name) name##@PLT
81#define SYSCALL_PIC_SETUP \
82 larl %r12,_GLOBAL_OFFSET_TABLE_
83#else
84#define JUMPTARGET(name) name
85#define SYSCALL_PIC_SETUP /* Nothing. */
86#endif
87
88/* Local label name for asm code. */
89#ifndef L
90#define L(name) .L##name
91#endif
92
93#endif /* __ASSEMBLER__ */
lib/libc/glibc/sysdeps/s390/start-2.33.S created+107
......@@ -0,0 +1,107 @@
1/* Startup code compliant to the 64 bit S/390 ELF ABI.
2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 In addition to the permissions in the GNU Lesser General Public
12 License, the Free Software Foundation gives you unlimited
13 permission to link the compiled version of this file with other
14 programs, and to distribute those programs without any restriction
15 coming from the use of this file. (The GNU Lesser General Public
16 License restrictions do apply in other respects; for example, they
17 cover modification of the file, and distribution when not linked
18 into another program.)
19
20 Note that people who make modified versions of this file are not
21 obligated to grant this special exception for their modified
22 versions; it is their choice whether to do so. The GNU Lesser
23 General Public License gives permission to release a modified
24 version without this exception; this exception also makes it
25 possible to release a modified version which carries forward this
26 exception.
27
28 The GNU C Library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 Lesser General Public License for more details.
32
33 You should have received a copy of the GNU Lesser General Public
34 License along with the GNU C Library; if not, see
35 <https://www.gnu.org/licenses/>. */
36
37#include <sysdep.h>
38
39/*
40 This is the canonical entry point, usually the first thing in the text
41 segment. Most registers' values are unspecified, except for:
42
43 %r14 Contains a function pointer to be registered with `atexit'.
44 This is how the dynamic linker arranges to have DT_FINI
45 functions called for shared libraries that have been loaded
46 before this code runs.
47
48 %r15 The stack contains the arguments and environment:
49 0(%r15) argc
50 8(%r15) argv[0]
51 ...
52 (8*argc)(%r15) NULL
53 (8*(argc+1))(%r15) envp[0]
54 ...
55 NULL
56*/
57
58 .text
59 .globl _start
60 .type _start,@function
61_start:
62 cfi_startproc
63 /* Mark r14 as undefined in order to stop unwinding here! */
64 cfi_undefined (r14)
65 /* Load argc and argv from stack. */
66 la %r4,8(%r15) # get argv
67 lg %r3,0(%r15) # get argc
68
69 /* Align the stack to a double word boundary. */
70 lghi %r0,-16
71 ngr %r15,%r0
72
73 /* Setup a stack frame and a parameter area. */
74 aghi %r15,-176 # make room on stack
75 xc 0(8,%r15),0(%r15) # clear back-chain
76
77 /* Set up arguments for __libc_start_main:
78 main, argc, argv, envp, _init, _fini, rtld_fini, stack_end
79 Note that envp will be determined later in __libc_start_main.
80 */
81 stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area
82 la %r7,160(%r15)
83 larl %r6,__libc_csu_fini # load pointer to __libc_csu_fini
84 larl %r5,__libc_csu_init # load pointer to __libc_csu_init
85
86 /* Ok, now branch to the libc main routine. */
87#ifdef PIC
88 larl %r2,main@GOTENT # load pointer to main
89 lg %r2,0(%r2)
90 brasl %r14,__libc_start_main@plt
91#else
92 larl %r2,main # load pointer to main
93 brasl %r14,__libc_start_main
94#endif
95
96 /* Crash if __libc_start_main returns. */
97 .word 0
98
99 cfi_endproc
100
101 /* Define a symbol for the first piece of initialized data. */
102 .data
103 .globl __data_start
104__data_start:
105 .long 0
106 .weak data_start
107 data_start = __data_start
lib/libc/glibc/sysdeps/s390/start.S created+134
......@@ -0,0 +1,134 @@
1/* Startup code compliant to the 64 bit S/390 ELF ABI.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 In addition to the permissions in the GNU Lesser General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file with other
13 programs, and to distribute those programs without any restriction
14 coming from the use of this file. (The GNU Lesser General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked
17 into another program.)
18
19 Note that people who make modified versions of this file are not
20 obligated to grant this special exception for their modified
21 versions; it is their choice whether to do so. The GNU Lesser
22 General Public License gives permission to release a modified
23 version without this exception; this exception also makes it
24 possible to release a modified version which carries forward this
25 exception.
26
27 The GNU C Library is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 Lesser General Public License for more details.
31
32 You should have received a copy of the GNU Lesser General Public
33 License along with the GNU C Library; if not, see
34 <https://www.gnu.org/licenses/>. */
35
36#include <sysdep.h>
37
38/*
39 This is the canonical entry point, usually the first thing in the text
40 segment. Most registers' values are unspecified, except for:
41
42 %r14 Contains a function pointer to be registered with `atexit'.
43 This is how the dynamic linker arranges to have DT_FINI
44 functions called for shared libraries that have been loaded
45 before this code runs.
46
47 %r15 The stack contains the arguments and environment:
48 0(%r15) argc
49 8(%r15) argv[0]
50 ...
51 (8*argc)(%r15) NULL
52 (8*(argc+1))(%r15) envp[0]
53 ...
54 NULL
55*/
56
57 .text
58 .globl _start
59 .type _start,@function
60_start:
61 cfi_startproc
62 /* Mark r14 as undefined in order to stop unwinding here! */
63 cfi_undefined (r14)
64 /* Load argc and argv from stack. */
65 la %r4,8(%r15) # get argv
66 lg %r3,0(%r15) # get argc
67
68 /* Align the stack to a double word boundary. */
69 lghi %r0,-16
70 ngr %r15,%r0
71
72 /* Setup a stack frame and a parameter area. */
73 aghi %r15,-176 # make room on stack
74 xc 0(8,%r15),0(%r15) # clear back-chain
75
76 /* Set up arguments for __libc_start_main:
77 main, argc, argv, envp, _init, _fini, rtld_fini, stack_end
78 Note that envp will be determined later in __libc_start_main.
79 */
80 stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area
81 la %r7,160(%r15)
82 lghi %r6,0 # Used to be fini.
83 lghi %r5,0 # Used to be init.
84
85 /* Ok, now branch to the libc main routine. */
86#ifdef PIC
87# ifdef SHARED
88 /* Used for dynamic linked position independent executable.
89 => Scrt1.o */
90 larl %r2,main@GOTENT # load pointer to main
91 lg %r2,0(%r2)
92# else
93 /* Used for dynamic linked position dependent executable.
94 => crt1.o (glibc configured without --disable-default-pie:
95 PIC is defined)
96 Or for static linked position independent executable.
97 => rcrt1.o (only available if glibc configured without
98 --disable-default-pie: PIC is defined) */
99 larl %r2,__wrap_main
100# endif
101 brasl %r14,__libc_start_main@plt
102#else
103 /* Used for dynamic/static linked position dependent executable.
104 => crt1.o (glibc configured with --disable-default-pie:
105 PIC and SHARED are not defined) */
106 larl %r2,main # load pointer to main
107 brasl %r14,__libc_start_main
108#endif
109
110 /* Crash if __libc_start_main returns. */
111 .word 0
112
113 cfi_endproc
114
115#if defined PIC && !defined SHARED
116 /* When main is not defined in the executable but in a shared library
117 then a wrapper is needed in crt1.o of the static-pie enabled libc,
118 because crt1.o and rcrt1.o share code and the later must avoid the
119 use of GOT relocations before __libc_start_main is called. */
120__wrap_main:
121 cfi_startproc
122 larl %r1,main@GOTENT # load pointer to main
123 lg %r1,0(%r1)
124 br %r1
125 cfi_endproc
126#endif
127
128 /* Define a symbol for the first piece of initialized data. */
129 .data
130 .globl __data_start
131__data_start:
132 .long 0
133 .weak data_start
134 data_start = __data_start
lib/libc/glibc/sysdeps/s390/sysdep.h created+93
......@@ -0,0 +1,93 @@
1/* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <sysdeps/generic/sysdep.h>
20
21#ifdef __ASSEMBLER__
22
23/* Syntactic details of assembler. */
24
25/* ELF uses byte-counts for .align, most others use log2 of count of bytes. */
26#define ALIGNARG(log2) 1<<log2
27#define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
28
29
30/* Define an entry point visible from C. */
31#define ENTRY(name) \
32 .globl C_SYMBOL_NAME(name); \
33 .type C_SYMBOL_NAME(name),@function; \
34 .align ALIGNARG(4); \
35 C_LABEL(name) \
36 cfi_startproc; \
37 CALL_MCOUNT
38
39#undef END
40#define END(name) \
41 cfi_endproc; \
42 ASM_SIZE_DIRECTIVE(name) \
43
44/* If compiled for profiling, call `mcount' at the start of each function. */
45#ifdef PROF
46#ifdef PIC
47#define CALL_MCOUNT \
48 lgr 0,14 ; larl 1,0f ; brasl 14,_mcount@PLT ; lgr 14,0 ; \
49 .data ; .align 4 ; 0: .long 0 ; .text ;
50#else
51#define CALL_MCOUNT \
52 lgr 0,14 ; larl 1,0f ; brasl 14,_mcount ; lgr 14,0 ; \
53 .data ; .align 4 ; 0: .long 0 ; .text ;
54#endif
55#else
56#define CALL_MCOUNT /* Do nothing. */
57#endif
58
59/* Since C identifiers are not normally prefixed with an underscore
60 on this system, the asm identifier `syscall_error' intrudes on the
61 C name space. Make sure we use an innocuous name. */
62#define syscall_error __syscall_error
63#define mcount _mcount
64
65#undef PSEUDO
66#define PSEUDO(name, syscall_name, args) \
67lose: SYSCALL_PIC_SETUP \
68 jg JUMPTARGET(syscall_error); \
69 .globl syscall_error; \
70 ENTRY (name) \
71 DO_CALL (syscall_name, args); \
72 jm lose
73
74#undef PSEUDO_END
75#define PSEUDO_END(name) \
76 END (name)
77
78#undef JUMPTARGET
79#ifdef SHARED
80#define JUMPTARGET(name) name##@PLT
81#define SYSCALL_PIC_SETUP \
82 larl %r12,_GLOBAL_OFFSET_TABLE_
83#else
84#define JUMPTARGET(name) name
85#define SYSCALL_PIC_SETUP /* Nothing. */
86#endif
87
88/* Local label name for asm code. */
89#ifndef L
90#define L(name) .L##name
91#endif
92
93#endif /* __ASSEMBLER__ */
lib/libc/glibc/sysdeps/unix/sysv/linux/kernel-features.h+6-1
......@@ -155,7 +155,7 @@
155155 similar to kernel:
156156
157157 - __ASSUME_CLONE_BACKWARDS: for variant 1.
158 - __ASSUME_CLONE_BACKWARDS2: for variant 2 (s390).
158 - __ASSUME_CLONE_BACKWARDS2: for variant 2 (s390x).
159159 - __ASSUME_CLONE_BACKWARDS3: for variant 3 (microblaze).
160160 - __ASSUME_CLONE_DEFAULT: for variant 4.
161161 */
......@@ -266,4 +266,9 @@
266266/* zig patch: don't assume kernel version */
267267#define __ASSUME_MSEAL 0
268268
269/* The PIDFD_GET_INFO ioctl was introduced across all architectures in Linux
270 6.13. */
271/* zig patch: don't assume kernel version */
272#define __ASSUME_PIDFD_GET_INFO 0
273
269274#endif /* kernel-features.h */
lib/libc/glibc/sysdeps/unix/sysv/linux/loongarch/sysdep.h+25-6
......@@ -19,6 +19,7 @@
1919#ifndef _LINUX_LOONGARCH_SYSDEP_H
2020#define _LINUX_LOONGARCH_SYSDEP_H 1
2121
22#include <sysdeps/loongarch/sysdep.h>
2223#include <sysdeps/unix/sysv/linux/sysdep.h>
2324#include <sysdeps/unix/sysdep.h>
2425#include <tls.h>
......@@ -34,9 +35,9 @@
3435#undef PSEUDO
3536#define PSEUDO(name, syscall_name, args) \
3637 ENTRY (name); \
37 li.d a7, SYS_ify (syscall_name); \
38 LI a7, SYS_ify (syscall_name); \
3839 syscall 0; \
39 li.d a7, -4096; \
40 LI a7, -4096; \
4041 bltu a7, a0, .Lsyscall_error##name;
4142
4243#undef PSEUDO_END
......@@ -52,16 +53,16 @@
5253 .Lsyscall_error##name : la t0, rtld_errno; \
5354 sub.w a0, zero, a0; \
5455 st.w a0, t0, 0; \
55 li.d a0, -1;
56 LI a0, -1;
5657
5758#else
5859
5960#define SYSCALL_ERROR_HANDLER(name) \
6061 .Lsyscall_error##name : la.tls.ie t0, errno; \
61 add.d t0, tp, t0; \
62 ADD t0, tp, t0; \
6263 sub.w a0, zero, a0; \
6364 st.w a0, t0, 0; \
64 li.d a0, -1;
65 LI a0, -1;
6566
6667#endif
6768#else
......@@ -74,7 +75,7 @@
7475#undef PSEUDO_NEORRNO
7576#define PSEUDO_NOERRNO(name, syscall_name, args) \
7677 ENTRY (name); \
77 li.d a7, SYS_ify (syscall_name); \
78 LI a7, SYS_ify (syscall_name); \
7879 syscall 0;
7980
8081#undef PSEUDO_END_NOERRNO
......@@ -85,11 +86,17 @@
8586
8687/* Performs a system call, returning the error code. */
8788#undef PSEUDO_ERRVAL
89#if __loongarch_grlen == 64
8890#define PSEUDO_ERRVAL(name, syscall_name, args) \
8991 PSEUDO_NOERRNO (name, syscall_name, args); \
9092 slli.d a0, a0, 32; \
9193 srai.d a0, a0, 32; /* sign_ext */ \
9294 sub.d a0, zero, a0;
95#else
96#define PSEUDO_ERRVAL(name, syscall_name, args) \
97 PSEUDO_NOERRNO (name, syscall_name, args); \
98 sub.w a0, zero, a0;
99#endif
93100
94101#undef PSEUDO_END_ERRVAL
95102#define PSEUDO_END_ERRVAL(name) END (name);
......@@ -109,6 +116,18 @@
109116#undef SYS_ify
110117#define SYS_ify(syscall_name) __NR_##syscall_name
111118
119#if __WORDSIZE == 32
120/* Workarounds for generic code needing to handle 64-bit time_t. */
121#define __NR_clock_getres __NR_clock_getres_time64
122#define __NR_futex __NR_futex_time64
123#define __NR_ppoll __NR_ppoll_time64
124#define __NR_pselect6 __NR_pselect6_time64
125#define __NR_recvmmsg __NR_recvmmsg_time64
126#define __NR_rt_sigtimedwait __NR_rt_sigtimedwait_time64
127#define __NR_semtimedop __NR_semtimedop_time64
128#define __NR_utimensat __NR_utimensat_time64
129#endif /* __WORDSIZE == 32 */
130
112131#ifndef __ASSEMBLER__
113132
114133#define VDSO_NAME "LINUX_5.10"
lib/libc/glibc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h+14-22
......@@ -57,42 +57,34 @@
5757#define __TIMER_T_TYPE void *
5858#define __BLKSIZE_T_TYPE __SLONGWORD_TYPE
5959#define __FSID_T_TYPE struct { int __val[2]; }
60#if defined __GNUC__ && __GNUC__ <= 2
61/* Compatibility with g++ 2.95.x. */
62#define __SSIZE_T_TYPE __SWORD_TYPE
63#else
64/* size_t is unsigned long int on s390 -m31. */
65#define __SSIZE_T_TYPE __SLONGWORD_TYPE
66#endif
60
61/* With s390-32, __SSIZE_T_TYPE was __SWORD_TYPE for compatibility with
62 g++ 2.95.x. Afterwards __SLONGWORD_TYPE was needed as size_t was
63 unsigned long int on s390-32.
64 Now as only s390-64 exists, __SWORD_TYPE can be used as also used in the
65 generic version as both types result in long int. */
66#define __SSIZE_T_TYPE __SWORD_TYPE
67
6768#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
6869#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
69#define __CPU_MASK_TYPE __ULONGWORD_TYPE
70#define __CPU_MASK_TYPE __ULONGWORD_TYPE
7071
71#ifdef __s390x__
7272/* Tell the libc code that off_t and off64_t are actually the same type
7373 for all ABI purposes, even if possibly expressed as different base types
7474 for C type-checking purposes. */
75# define __OFF_T_MATCHES_OFF64_T 1
75#define __OFF_T_MATCHES_OFF64_T 1
7676
7777/* Same for ino_t and ino64_t. */
78# define __INO_T_MATCHES_INO64_T 1
78#define __INO_T_MATCHES_INO64_T 1
7979
8080/* And for __rlim_t and __rlim64_t. */
81# define __RLIM_T_MATCHES_RLIM64_T 1
81#define __RLIM_T_MATCHES_RLIM64_T 1
8282
8383/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */
84# define __STATFS_MATCHES_STATFS64 1
84#define __STATFS_MATCHES_STATFS64 1
8585
8686/* And for getitimer, setitimer and rusage */
87# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
88#else
89# define __RLIM_T_MATCHES_RLIM64_T 0
90
91# define __STATFS_MATCHES_STATFS64 0
92
93/* And for getitimer, setitimer and rusage */
94# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0
95#endif
87#define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
9688
9789/* Number of descriptors that can fit in an `fd_set'. */
9890#define __FD_SETSIZE 1024
lib/libc/glibc/sysdeps/unix/sysv/linux/s390/kernel-features.h-3
......@@ -47,9 +47,6 @@
4747# undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
4848# undef __ASSUME_SYSVIPC_DEFAULT_IPC_64
4949#endif
50#ifndef __s390x__
51# define __ASSUME_SYSVIPC_BROKEN_MODE_T
52#endif
5350
5451#undef __ASSUME_CLONE_DEFAULT
5552#define __ASSUME_CLONE_BACKWARDS2
lib/libc/glibc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h deleted-178
......@@ -1,178 +0,0 @@
1/* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LINUX_S390_SYSDEP_H
20#define _LINUX_S390_SYSDEP_H
21
22#include <sysdeps/s390/s390-64/sysdep.h>
23#include <sysdeps/unix/sysdep.h>
24#include <sysdeps/unix/sysv/linux/s390/sysdep.h>
25#include <sysdeps/unix/sysv/linux/sysdep.h>
26#include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
27#include <tls.h>
28
29/* For Linux we can use the system call table in the header file
30 /usr/include/asm/unistd.h
31 of the kernel. But these symbols do not follow the SYS_* syntax
32 so we have to redefine the `SYS_ify' macro here. */
33/* In newer 2.1 kernels __NR_syscall is missing so we define it here. */
34#define __NR_syscall 0
35
36#undef SYS_ify
37#define SYS_ify(syscall_name) __NR_##syscall_name
38
39#ifdef __ASSEMBLER__
40
41/* Linux uses a negative return value to indicate syscall errors, unlike
42 most Unices, which use the condition codes' carry flag.
43
44 Since version 2.1 the return value of a system call might be negative
45 even if the call succeeded. E.g., the `lseek' system call might return
46 a large offset. Therefore we must not anymore test for < 0, but test
47 for a real error by making sure the value in gpr2 is a real error
48 number. Linus said he will make sure that no syscall returns a value
49 in -1 .. -4095 as a valid result so we can safely test with -4095. */
50
51#undef PSEUDO
52#define PSEUDO(name, syscall_name, args) \
53 .text; \
54 ENTRY (name) \
55 DO_CALL (syscall_name, args); \
56 lghi %r4,-4095 ; \
57 clgr %r2,%r4 ; \
58 jgnl SYSCALL_ERROR_LABEL
59
60#undef PSEUDO_END
61#define PSEUDO_END(name) \
62 SYSCALL_ERROR_HANDLER; \
63 END (name)
64
65#undef PSEUDO_NOERRNO
66#define PSEUDO_NOERRNO(name, syscall_name, args) \
67 .text; \
68 ENTRY (name) \
69 DO_CALL (syscall_name, args)
70
71#undef PSEUDO_END_NOERRNO
72#define PSEUDO_END_NOERRNO(name) \
73 SYSCALL_ERROR_HANDLER; \
74 END (name)
75
76#undef PSEUDO_ERRVAL
77#define PSEUDO_ERRVAL(name, syscall_name, args) \
78 .text; \
79 ENTRY (name) \
80 DO_CALL (syscall_name, args); \
81 lcgr %r2,%r2
82
83#undef PSEUDO_END_ERRVAL
84#define PSEUDO_END_ERRVAL(name) \
85 SYSCALL_ERROR_HANDLER; \
86 END (name)
87
88#undef SYSCALL_ERROR_LABEL
89#ifndef PIC
90# undef SYSCALL_ERROR_LABEL
91# define SYSCALL_ERROR_LABEL syscall_error
92# define SYSCALL_ERROR_HANDLER
93#else
94# if RTLD_PRIVATE_ERRNO
95# undef SYSCALL_ERROR_LABEL
96# define SYSCALL_ERROR_LABEL 0f
97# define SYSCALL_ERROR_HANDLER \
980: larl %r1,rtld_errno; \
99 lcr %r2,%r2; \
100 st %r2,0(%r1); \
101 lghi %r2,-1; \
102 br %r14
103# elif defined _LIBC_REENTRANT
104# if IS_IN (libc)
105# define SYSCALL_ERROR_ERRNO __libc_errno
106# else
107# define SYSCALL_ERROR_ERRNO errno
108# endif
109# undef SYSCALL_ERROR_LABEL
110# define SYSCALL_ERROR_LABEL 0f
111# define SYSCALL_ERROR_HANDLER \
1120: lcr %r0,%r2; \
113 larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
114 lg %r1,0(%r1); \
115 ear %r2,%a0; \
116 sllg %r2,%r2,32; \
117 ear %r2,%a1; \
118 st %r0,0(%r1,%r2); \
119 lghi %r2,-1; \
120 br %r14
121# else
122# undef SYSCALL_ERROR_LABEL
123# define SYSCALL_ERROR_LABEL 0f
124# define SYSCALL_ERROR_HANDLER \
1250: larl %r1,_GLOBAL_OFFSET_TABLE_; \
126 lg %r1,errno@GOT(%r1); \
127 lcr %r2,%r2; \
128 st %r2,0(%r1); \
129 lghi %r2,-1; \
130 br %r14
131# endif /* _LIBC_REENTRANT */
132#endif /* PIC */
133
134/* Linux takes system call arguments in registers:
135
136 syscall number 1 call-clobbered
137 arg 1 2 call-clobbered
138 arg 2 3 call-clobbered
139 arg 3 4 call-clobbered
140 arg 4 5 call-clobbered
141 arg 5 6 call-saved
142 arg 6 7 call-saved
143
144 (Of course a function with say 3 arguments does not have entries for
145 arguments 4 and 5.)
146 For system calls with 6 parameters a stack operation is required
147 to load the 6th parameter to register 7. Call saved register 7 is
148 moved to register 0 and back to avoid an additional stack frame.
149 */
150
151#define DO_CALL(syscall, args) \
152 .if args > 5; \
153 lgr %r0,%r7; \
154 lg %r7,160(%r15); \
155 .endif; \
156 lghi %r1,SYS_ify (syscall); \
157 svc 0; \
158 .if args > 5; \
159 lgr %r7,%r0; \
160 .endif
161
162#define ret \
163 br 14
164
165#define ret_NOERRNO \
166 br 14
167
168#define ret_ERRVAL \
169 br 14
170
171#else
172
173# undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
174# define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
175
176#endif /* __ASSEMBLER__ */
177
178#endif /* _LINUX_S390_SYSDEP_H */
lib/libc/glibc/sysdeps/unix/sysv/linux/s390/sysdep.h+186-37
......@@ -1,5 +1,5 @@
1/* Syscall definitions, Linux s390 version.
2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
1/* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
33 This file is part of the GNU C Library.
44
55 The GNU C Library is free software; you can redistribute it and/or
......@@ -14,15 +14,163 @@
1414
1515 You should have received a copy of the GNU Lesser General Public
1616 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
17 <https://www.gnu.org/licenses/>. */
1818
19#ifndef __ASSEMBLY__
19#ifndef _LINUX_S390_SYSDEP_H
20#define _LINUX_S390_SYSDEP_H
21
22#include <sysdeps/s390/sysdep.h>
23#include <sysdeps/unix/sysdep.h>
24#include <sysdeps/unix/sysv/linux/sysdep.h>
25#include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
26#include <tls.h>
27
28/* For Linux we can use the system call table in the header file
29 /usr/include/asm/unistd.h
30 of the kernel. But these symbols do not follow the SYS_* syntax
31 so we have to redefine the `SYS_ify' macro here. */
32/* In newer 2.1 kernels __NR_syscall is missing so we define it here. */
33#define __NR_syscall 0
2034
2135#undef SYS_ify
2236#define SYS_ify(syscall_name) __NR_##syscall_name
2337
24#undef INTERNAL_SYSCALL_NCS
25#define INTERNAL_SYSCALL_NCS(no, nr, args...) \
38#ifdef __ASSEMBLER__
39
40/* Linux uses a negative return value to indicate syscall errors, unlike
41 most Unices, which use the condition codes' carry flag.
42
43 Since version 2.1 the return value of a system call might be negative
44 even if the call succeeded. E.g., the `lseek' system call might return
45 a large offset. Therefore we must not anymore test for < 0, but test
46 for a real error by making sure the value in gpr2 is a real error
47 number. Linus said he will make sure that no syscall returns a value
48 in -1 .. -4095 as a valid result so we can safely test with -4095. */
49
50# undef PSEUDO
51# define PSEUDO(name, syscall_name, args) \
52 .text; \
53 ENTRY (name) \
54 DO_CALL (syscall_name, args); \
55 lghi %r4,-4095 ; \
56 clgr %r2,%r4 ; \
57 jgnl SYSCALL_ERROR_LABEL
58
59# undef PSEUDO_END
60# define PSEUDO_END(name) \
61 SYSCALL_ERROR_HANDLER; \
62 END (name)
63
64# undef PSEUDO_NOERRNO
65# define PSEUDO_NOERRNO(name, syscall_name, args) \
66 .text; \
67 ENTRY (name) \
68 DO_CALL (syscall_name, args)
69
70# undef PSEUDO_END_NOERRNO
71# define PSEUDO_END_NOERRNO(name) \
72 SYSCALL_ERROR_HANDLER; \
73 END (name)
74
75# undef PSEUDO_ERRVAL
76# define PSEUDO_ERRVAL(name, syscall_name, args) \
77 .text; \
78 ENTRY (name) \
79 DO_CALL (syscall_name, args); \
80 lcgr %r2,%r2
81
82# undef PSEUDO_END_ERRVAL
83# define PSEUDO_END_ERRVAL(name) \
84 SYSCALL_ERROR_HANDLER; \
85 END (name)
86
87# undef SYSCALL_ERROR_LABEL
88# ifndef PIC
89# undef SYSCALL_ERROR_LABEL
90# define SYSCALL_ERROR_LABEL syscall_error
91# define SYSCALL_ERROR_HANDLER
92# else
93# if RTLD_PRIVATE_ERRNO
94# undef SYSCALL_ERROR_LABEL
95# define SYSCALL_ERROR_LABEL 0f
96# define SYSCALL_ERROR_HANDLER \
970: larl %r1,rtld_errno; \
98 lcr %r2,%r2; \
99 st %r2,0(%r1); \
100 lghi %r2,-1; \
101 br %r14
102# elif defined _LIBC_REENTRANT
103# if IS_IN (libc)
104# define SYSCALL_ERROR_ERRNO __libc_errno
105# else
106# define SYSCALL_ERROR_ERRNO errno
107# endif
108# undef SYSCALL_ERROR_LABEL
109# define SYSCALL_ERROR_LABEL 0f
110# define SYSCALL_ERROR_HANDLER \
1110: lcr %r0,%r2; \
112 larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
113 lg %r1,0(%r1); \
114 ear %r2,%a0; \
115 sllg %r2,%r2,32; \
116 ear %r2,%a1; \
117 st %r0,0(%r1,%r2); \
118 lghi %r2,-1; \
119 br %r14
120# else
121# undef SYSCALL_ERROR_LABEL
122# define SYSCALL_ERROR_LABEL 0f
123# define SYSCALL_ERROR_HANDLER \
1240: larl %r1,_GLOBAL_OFFSET_TABLE_; \
125 lg %r1,errno@GOT(%r1); \
126 lcr %r2,%r2; \
127 st %r2,0(%r1); \
128 lghi %r2,-1; \
129 br %r14
130# endif /* _LIBC_REENTRANT */
131# endif /* PIC */
132
133/* Linux takes system call arguments in registers:
134
135 syscall number 1 call-clobbered
136 arg 1 2 call-clobbered
137 arg 2 3 call-clobbered
138 arg 3 4 call-clobbered
139 arg 4 5 call-clobbered
140 arg 5 6 call-saved
141 arg 6 7 call-saved
142
143 (Of course a function with say 3 arguments does not have entries for
144 arguments 4 and 5.)
145 For system calls with 6 parameters a stack operation is required
146 to load the 6th parameter to register 7. Call saved register 7 is
147 moved to register 0 and back to avoid an additional stack frame.
148 */
149
150# define DO_CALL(syscall, args) \
151 .if args > 5; \
152 lgr %r0,%r7; \
153 lg %r7,160(%r15); \
154 .endif; \
155 lghi %r1,SYS_ify (syscall); \
156 svc 0; \
157 .if args > 5; \
158 lgr %r7,%r0; \
159 .endif
160
161# define ret \
162 br 14
163
164# define ret_NOERRNO \
165 br 14
166
167# define ret_ERRVAL \
168 br 14
169
170#else /* not __ASSEMBLER__ */
171
172# undef INTERNAL_SYSCALL_NCS
173# define INTERNAL_SYSCALL_NCS(no, nr, args...) \
26174 ({ \
27175 DECLARGS_##nr(args) \
28176 register unsigned long int _nr __asm__("1") = (unsigned long int)(no); \
......@@ -34,51 +182,52 @@
34182 : "memory" ); \
35183 _ret; })
36184
37#undef INTERNAL_SYSCALL
38#define INTERNAL_SYSCALL(name, nr, args...) \
185# undef INTERNAL_SYSCALL
186# define INTERNAL_SYSCALL(name, nr, args...) \
39187 INTERNAL_SYSCALL_NCS(__NR_##name, nr, args)
40188
41#define DECLARGS_0()
42#define DECLARGS_1(arg1) \
189# define DECLARGS_0()
190# define DECLARGS_1(arg1) \
43191 register unsigned long int gpr2 __asm__ ("2") = (unsigned long int)(arg1);
44#define DECLARGS_2(arg1, arg2) \
192# define DECLARGS_2(arg1, arg2) \
45193 DECLARGS_1(arg1) \
46194 register unsigned long int gpr3 __asm__ ("3") = (unsigned long int)(arg2);
47#define DECLARGS_3(arg1, arg2, arg3) \
195# define DECLARGS_3(arg1, arg2, arg3) \
48196 DECLARGS_2(arg1, arg2) \
49197 register unsigned long int gpr4 __asm__ ("4") = (unsigned long int)(arg3);
50#define DECLARGS_4(arg1, arg2, arg3, arg4) \
198# define DECLARGS_4(arg1, arg2, arg3, arg4) \
51199 DECLARGS_3(arg1, arg2, arg3) \
52200 register unsigned long int gpr5 __asm__ ("5") = (unsigned long int)(arg4);
53#define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
201# define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
54202 DECLARGS_4(arg1, arg2, arg3, arg4) \
55203 register unsigned long int gpr6 __asm__ ("6") = (unsigned long int)(arg5);
56#define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
204# define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
57205 DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
58206 register unsigned long int gpr7 __asm__ ("7") = (unsigned long int)(arg6);
59207
60#define ASMFMT_0
61#define ASMFMT_1 , "0" (gpr2)
62#define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
63#define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
64#define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
65#define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
66#define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
208# define ASMFMT_0
209# define ASMFMT_1 , "0" (gpr2)
210# define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
211# define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
212# define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
213# define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
214# define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
67215
68#define VDSO_NAME "LINUX_2.6.29"
69#define VDSO_HASH 123718585
216# define VDSO_NAME "LINUX_2.6.29"
217# define VDSO_HASH 123718585
70218
71219/* List of system calls which are supported as vsyscalls. */
72#ifdef __s390x__
73#define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres"
74#define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime"
75#define HAVE_GETRANDOM_VSYSCALL "__kernel_getrandom"
76#else
77#define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres"
78#define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime"
79#endif
80#define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday"
81#define HAVE_GETCPU_VSYSCALL "__kernel_getcpu"
82
83#define HAVE_CLONE3_WRAPPER 1
84#endif
220# define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres"
221# define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime"
222# define HAVE_GETRANDOM_VSYSCALL "__kernel_getrandom"
223# define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday"
224# define HAVE_GETCPU_VSYSCALL "__kernel_getcpu"
225
226# define HAVE_CLONE3_WRAPPER 1
227
228# undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
229# define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
230
231#endif /* __ASSEMBLER__ */
232
233#endif /* _LINUX_S390_SYSDEP_H */
lib/libc/glibc/sysdeps/unix/sysv/linux/s390/xstatver.h+6-15
......@@ -1,19 +1,10 @@
11/* Versions of the 'struct stat' data structure used in compatibility xstat
22 functions. */
3
4#include <bits/wordsize.h>
5
6#if __WORDSIZE == 64
7# define _STAT_VER_KERNEL 0
8# define _STAT_VER_LINUX 1
9# define _MKNOD_VER_LINUX 0
10#else
11# define _STAT_VER_LINUX_OLD 1
12# define _STAT_VER_KERNEL 1
13# define _STAT_VER_SVR4 2
14# define _STAT_VER_LINUX 3
15# define _MKNOD_VER_LINUX 1
16# define _MKNOD_VER_SVR4 2
17#endif
3#define _STAT_VER_KERNEL 0
4#define _STAT_VER_LINUX 1
185#define _STAT_VER _STAT_VER_LINUX
6
7/* Versions of the 'xmknod' interface used in compatibility xmknod
8 functions. */
9#define _MKNOD_VER_LINUX 0
1910#define _MKNOD_VER _MKNOD_VER_LINUX
src/libs/glibc.zig+1-3
......@@ -398,7 +398,7 @@ fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![
398398 try result.appendSlice("powerpc" ++ s ++ "powerpc32");
399399 }
400400 } else if (arch == .s390x) {
401 try result.appendSlice("s390" ++ s ++ "s390-64");
401 try result.appendSlice("s390");
402402 } else if (arch.isLoongArch()) {
403403 try result.appendSlice("loongarch");
404404 } else if (arch == .m68k) {
......@@ -607,8 +607,6 @@ fn add_include_dirs_arch(
607607 try args.append("-I");
608608 try args.append(try path.join(arena, &[_][]const u8{ dir, "s390", nptl }));
609609 } else {
610 try args.append("-I");
611 try args.append(try path.join(arena, &[_][]const u8{ dir, "s390" ++ s ++ "s390-64" }));
612610 try args.append("-I");
613611 try args.append(try path.join(arena, &[_][]const u8{ dir, "s390" }));
614612 }