diff --git a/lib/libc/glibc/elf/elf.h b/lib/libc/glibc/elf/elf.h index 46a01281cb0fb5322d5124f0443c11dea4d5b721..b482fcfb64890752fc1aa4e9d208a7b94f022d38 100644 --- a/lib/libc/glibc/elf/elf.h +++ b/lib/libc/glibc/elf/elf.h @@ -798,7 +798,8 @@ typedef struct #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ #define NT_X86_SHSTK 0x204 /* x86 SHSTK state */ #define NT_X86_XSAVE_LAYOUT 0x205 /* XSAVE layout description. */ -#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ +#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves. This was + used in now removed s390-32 arch. */ #define NT_S390_TIMER 0x301 /* s390 timer register */ #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */ #define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */ @@ -846,6 +847,7 @@ typedef struct #define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */ #define NT_RISCV_TAGGED_ADDR_CTRL 0x902 /* RISC-V tagged address control */ +#define NT_RISCV_USER_CFI 0x903 /* RISC-V shadow stack state */ #define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers. */ #define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers. */ @@ -3470,7 +3472,9 @@ enum /* Valid values for the e_flags field. */ -#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */ +#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. + This was used in now removed s390-32 + arch. */ /* Additional s390 relocs */ diff --git a/lib/libc/glibc/include/libc-symbols.h b/lib/libc/glibc/include/libc-symbols.h index bebfc67cec098bf106bb9231bd3ff47e8f85d31f..a6aef303a22fa1a23c2a8f88f33451c803476e38 100644 --- a/lib/libc/glibc/include/libc-symbols.h +++ b/lib/libc/glibc/include/libc-symbols.h @@ -113,6 +113,7 @@ #define HAVE_LIBINTL_H 1 #define HAVE_WCTYPE_H 1 #define HAVE_ISWCTYPE 1 +#define HAVE_MEMPCPY 1 #define ENABLE_NLS 1 /* The symbols in all the user (non-_) macros are C symbols. */ @@ -682,7 +683,7 @@ for linking") /* Helper / base macros for indirect function symbols. */ #define __ifunc_resolver(type_name, name, expr, init, classifier, ...) \ - classifier inhibit_stack_protector \ + classifier \ __typeof (type_name) *name##_ifunc (__VA_ARGS__) \ { \ init (); \ diff --git a/lib/libc/glibc/sysdeps/aarch64/sysdep.h b/lib/libc/glibc/sysdeps/aarch64/sysdep.h index da4b7f3fd32c4fbd62ce777d1857baeda279dcbb..77e6564d97bb5473bc915dde142522f7ee938914 100644 --- a/lib/libc/glibc/sysdeps/aarch64/sysdep.h +++ b/lib/libc/glibc/sysdeps/aarch64/sysdep.h @@ -43,7 +43,6 @@ #define FEATURE_1_PAC 2 #define FEATURE_1_GCS 4 -/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ #define GNU_PROPERTY(type, value) \ .section .note.gnu.property, "a"; \ .p2align 3; \ @@ -57,9 +56,34 @@ .word 0; \ .text -/* Add GNU property note with the supported features to all asm code - where sysdep.h is included. */ -GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS) +#ifdef __ARM_BUILDATTR64_FV +/* Add AArch64 feature bits build attributes. */ +# define FEATURE_1_AND_MARK(value) \ + .aeabi_subsection aeabi_feature_and_bits, optional, ULEB128; \ + .if ((value) & FEATURE_1_BTI); \ + .aeabi_attribute Tag_Feature_BTI, 1; \ + .else; \ + .aeabi_attribute Tag_Feature_BTI, 0; \ + .endif; \ + .if ((value) & FEATURE_1_GCS); \ + .aeabi_attribute Tag_Feature_GCS, 1; \ + .else; \ + .aeabi_attribute Tag_Feature_GCS, 0; \ + .endif; \ + .if ((value) & FEATURE_1_PAC); \ + .aeabi_attribute Tag_Feature_PAC, 1; \ + .else; \ + .aeabi_attribute Tag_Feature_PAC, 0; \ + .endif; \ + .text +#else +/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ +# define FEATURE_1_AND_MARK(value) GNU_PROPERTY (FEATURE_1_AND, value) +#endif /* __ARM_BUILDATTR64_FV */ + +/* Add marking with the supported features to all asm code where sysdep.h + is included. */ +FEATURE_1_AND_MARK (FEATURE_1_BTI | FEATURE_1_PAC | FEATURE_1_GCS) /* Define an entry point visible from C. */ #define ENTRY(name) \ diff --git a/lib/libc/glibc/sysdeps/arm/start.S b/lib/libc/glibc/sysdeps/arm/start.S index a7e62b39346d18be9d46f64048b092e7c873b068..6b154dc7d33e3450b94991e9d827a3edf85acc9f 100644 --- a/lib/libc/glibc/sysdeps/arm/start.S +++ b/lib/libc/glibc/sysdeps/arm/start.S @@ -90,6 +90,7 @@ _start: push { a1 } #ifdef PIC +# ifdef SHARED ldr sl, .L_GOT adr a4, .L_GOT add sl, sl, a4 @@ -103,6 +104,16 @@ _start: /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ /* Let the libc call main and exit with its return code. */ bl __libc_start_main(PLT) +# else + ldr a1, .L_main_rel /* Load the relative offset of __wrap_main. */ + adr a4, .L_main_rel /* Load the actual runtime address of the label. */ + add a1, a4, a1 /* Add them together to get the absolute address. */ + + mov a4, #0 /* Used to be init. */ + push { a4 } /* Used to be fini. */ + + bl __libc_start_main +# endif /* ifdef SHARED */ #else mov a4, #0 /* Used to init. */ @@ -119,14 +130,30 @@ _start: #ifdef PIC .align 2 +# ifdef SHARED .L_GOT: .word _GLOBAL_OFFSET_TABLE_ - .L_GOT .word main(GOT) +# else +.L_main_rel: + .word __wrap_main - .L_main_rel +# endif #endif .cantunwind .fnend +#if defined PIC && !defined SHARED +/* When main is not defined in the executable but in a shared library then + a wrapper is needed, because crt1.o and rcrt1.o share this code and the + latter (static PIE) must avoid GOT relocations before __libc_start_main + is called. The branch to main is turned into a PLT entry by every linker, + unlike a REL32 data relocation against main. */ + .type __wrap_main, %function +__wrap_main: + b main +#endif + /* Define a symbol for the first piece of initialized data. */ .data .globl __data_start diff --git a/lib/libc/glibc/sysdeps/htl/libc-lockP.h b/lib/libc/glibc/sysdeps/htl/libc-lockP.h index a88eea4344004d7bcacdcd6bb827547ab9a41026..e20e40f2540f0d23b4215910637196cb0ad91959 100644 --- a/lib/libc/glibc/sysdeps/htl/libc-lockP.h +++ b/lib/libc/glibc/sysdeps/htl/libc-lockP.h @@ -21,6 +21,20 @@ #include +typedef pthread_rwlock_t __libc_rwlock_t; + +#define __libc_rwlock_define(CLASS,NAME) \ + CLASS __libc_rwlock_t NAME; +#define __libc_rwlock_define_initialized(CLASS,NAME) \ + CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER; +#define __libc_rwlock_init(NAME) __pthread_rwlock_init (&(NAME), NULL) +#define __libc_rwlock_fini(NAME) ((void) 0) +#define __libc_rwlock_rdlock(NAME) __pthread_rwlock_rdlock (&(NAME)) +#define __libc_rwlock_wrlock(NAME) __pthread_rwlock_wrlock (&(NAME)) +#define __libc_rwlock_tryrdlock(NAME) __pthread_rwlock_tryrdlock (&(NAME)) +#define __libc_rwlock_trywrlock(NAME) __pthread_rwlock_trywrlock (&(NAME)) +#define __libc_rwlock_unlock(NAME) __pthread_rwlock_unlock (&(NAME)) + /* If we check for a weakly referenced symbol and then perform a normal jump to it te code generated for some platforms in case of PIC is unnecessarily slow. What would happen is that the function diff --git a/lib/libc/glibc/sysdeps/loongarch/start.S b/lib/libc/glibc/sysdeps/loongarch/start.S index 72452f5307ef430c06fd5852190c68d5f1295366..7be47a034df972d645cd6bd4a09afa0c450f5ca2 100644 --- a/lib/libc/glibc/sysdeps/loongarch/start.S +++ b/lib/libc/glibc/sysdeps/loongarch/start.S @@ -36,6 +36,7 @@ #define __ASSEMBLY__ 1 #include #include +#include /* The entry point's job is to call __libc_start_main. Per the ABI, a0 contains the address of a function to be passed to atexit. @@ -57,23 +58,32 @@ ENTRY (ENTRY_POINT) /* Terminate call stack by noting ra is undefined. Use a dummy .cfi_label to force starting the FDE. */ .cfi_label .Ldummy - cfi_undefined (1) + cfi_undefined (1) or a5, a0, zero /* rtld_fini */ - la.pcrel a0, t0, main +#if defined PIC && !defined SHARED + /* Avoid relocation in static PIE since _start is called before it + is relocated. */ + la.pcrel a0, __wrap_main +#else + LA_GOT (a0, main) +#endif + REG_L a1, sp, 0 ADDI a2, sp, SZREG - /* Adjust $sp for 16-aligned */ - BSTRINS sp, zero, 3, 0 + /* Adjust $sp for 16-bytes aligned */ + REG_ALIGN_ASM (sp, 4) move a3, zero /* used to be init */ move a4, zero /* used to be fini */ or a6, sp, zero /* stack_end */ - la.pcrel ra, t0, __libc_start_main - jirl ra, ra, 0 + CALL (__libc_start_main) + CALL (abort) - la.pcrel ra, t0, abort - jirl ra, ra, 0 +#if defined PIC && !defined SHARED +__wrap_main: + TAIL (main) +#endif END (ENTRY_POINT) diff --git a/lib/libc/glibc/sysdeps/loongarch/sys/asm.h b/lib/libc/glibc/sysdeps/loongarch/sys/asm.h new file mode 100644 index 0000000000000000000000000000000000000000..de44aacfa411fc9f6be2ddcd64acea0a75117cea --- /dev/null +++ b/lib/libc/glibc/sysdeps/loongarch/sys/asm.h @@ -0,0 +1,104 @@ +/* Miscellaneous macros. + Copyright (C) 2022-2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _SYS_ASM_H +#define _SYS_ASM_H + +#include +#include + +/* Macros to handle different pointer/register sizes for 32/64-bit code. */ +#if __loongarch_grlen == 64 +#define SZREG 8 +#define REG_L ld.d +#define REG_S st.d +#define SRLI srli.d +#define SLLI slli.d +#define ADDI addi.d +#define ADD add.d +#define SUB sub.d +#define LI li.d +#define BSTRINS bstrins.d + +#elif __loongarch_grlen == 32 + +#define SZREG 4 +#define REG_L ld.w +#define REG_S st.w +#define SRLI srli.w +#define SLLI slli.w +#define ADDI addi.w +#define ADD add.w +#define SUB sub.w +#define LI li.w +#define BSTRINS bstrins.w + +#else +#error __loongarch_grlen must equal 32 or 64 +#endif + +#if __loongarch_frlen == 64 + #define SZFREG 8 + #define FREG_L fld.d + #define FREG_S fst.d +#elif __loongarch_frlen == 32 + #define SZFREG 4 + #define FREG_L fld.s + #define FREG_S fst.s +#endif + +#define SZVREG 16 +#define SZXREG 32 + +/* Declare leaf routine. + The usage of macro LEAF/ENTRY is as follows: + 1. LEAF(fcn) -- the align value of fcn is .align 3 (default value) + 2. LEAF(fcn, 6) -- the align value of fcn is .align 6 +*/ +#define LEAF_IMPL(symbol, aln, ...) \ + .text; \ + .globl symbol; \ + .align aln; \ + .type symbol, @function; \ +symbol: \ + cfi_startproc; + + +#define LEAF(...) LEAF_IMPL(__VA_ARGS__, 3) +#define ENTRY(...) LEAF(__VA_ARGS__) + +#define LEAF_NO_ALIGN(symbol) \ + .text; \ + .globl symbol; \ + .type symbol, @function; \ +symbol: \ + cfi_startproc; + +#define ENTRY_NO_ALIGN(symbol) LEAF_NO_ALIGN(symbol) + + +/* Mark end of function. */ +#undef END +#define END(function) \ + cfi_endproc; \ + .size function, .- function; + +/* Stack alignment. */ +#define ALMASK ~15 + +#endif /* sys/asm.h */ diff --git a/lib/libc/glibc/sysdeps/loongarch/sysdep.h b/lib/libc/glibc/sysdeps/loongarch/sysdep.h new file mode 100644 index 0000000000000000000000000000000000000000..d5fc0b08633b383c8bbcb9e0213c214d9a141c3b --- /dev/null +++ b/lib/libc/glibc/sysdeps/loongarch/sysdep.h @@ -0,0 +1,94 @@ +/* Macros for LoongArch. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _LOONGARCH_SYSDEP_H +#define _LOONGARCH_SYSDEP_H + +#if __loongarch_grlen == 64 + +#define PTRLOG 3 +/* Align reg to 2^n. Used in C. */ +#define REG_ALIGN_C(reg, n) \ + "bstrins.d\t" __STRING(reg) ", $zero, (" __STRING(n) "-1), 0" + +#elif __loongarch_grlen == 32 + +#define PTRLOG 2 +#define REG_ALIGN_C(reg, n) \ + "srli.w\t" __STRING(reg)", " __STRING(reg)", " __STRING(n) "\n\t" \ + "slli.w\t" __STRING(reg)", " __STRING(reg)", " __STRING(n) + +#else +#error __loongarch_grlen must equal 32 or 64 +#endif + +#ifdef __ASSEMBLER__ + +/* Stack alignment bytes. */ +#define STACK_ALIGN 16 + +/* Macros to handle different pointer/register sizes for 32/64-bit code. */ +#if __loongarch_grlen == 64 +#define SRAI srai.d + +/* Align reg to 2^n. Used in assembly. */ +#define REG_ALIGN_ASM(reg, n) bstrins.d reg, zero, (n-1), 0 + +#define LOAD_LOCAL(reg, sym) \ + pcalau12i reg, %pc_hi20(sym); \ + ld.d reg, reg, %pc_lo12(sym); + +#define LOAD_GLOBAL(reg, sym) \ + la.got reg, sym; \ + ld.d reg, reg, 0; + +#define LA_GOT(reg, sym) la.got reg, t0, sym + +#define CALL(sym) call36 sym +#define TAIL(sym) tail36 t0, sym + +#elif __loongarch_grlen == 32 /* __loongarch_grlen == 64 */ + +#define SRAI srai.w + +/* LA32R not have bstrins.w, use srli.w and slli.w on both LA32S and LA32R. */ +#define REG_ALIGN_ASM(reg, n) \ + srli.w reg, reg, n; \ + slli.w reg, reg, n; + +#define LOAD_LOCAL(reg, sym) \ + 1: pcaddu12i reg, %pcadd_hi20(sym); \ + ld.w reg, reg, %pcadd_lo12(1b); + +#define LOAD_GLOBAL(reg, sym) \ + 1: pcaddu12i reg, %got_pcadd_hi20(sym); \ + ld.w reg, reg, %pcadd_lo12(1b); \ + ld.w reg, reg, 0; + +#define LA_GOT(reg, sym) la.got reg, sym + +#define CALL(sym) call30 sym +#define TAIL(sym) tail30 t0, sym + +#else /* __loongarch_grlen == 64 */ +#error __loongarch_grlen must equal 32 or 64 +#endif /* __loongarch_grlen == 64 */ + +#endif /* __ASSEMBLER__ */ + +#endif /* _LOONGARCH_SYSDEP_H */ diff --git a/lib/libc/glibc/sysdeps/mach/libc-lock.h b/lib/libc/glibc/sysdeps/mach/libc-lock.h index 236a24ad807ea292bb25258d64ffb5658f5ddcf5..c5c67ccf9daa2fc5a02b63321f9fcdcf4617ec59 100644 --- a/lib/libc/glibc/sysdeps/mach/libc-lock.h +++ b/lib/libc/glibc/sysdeps/mach/libc-lock.h @@ -145,16 +145,16 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #define __rtld_lock_unlock_recursive(NAME) \ __libc_lock_unlock_recursive (NAME) -/* XXX for now */ -#define __libc_rwlock_define __libc_lock_define -#define __libc_rwlock_define_initialized __libc_lock_define_initialized -#define __libc_rwlock_init __libc_lock_init -#define __libc_rwlock_fini __libc_lock_fini -#define __libc_rwlock_rdlock __libc_lock_lock -#define __libc_rwlock_wrlock __libc_lock_lock -#define __libc_rwlock_tryrdlock __libc_lock_trylock -#define __libc_rwlock_trywrlock __libc_lock_trylock -#define __libc_rwlock_unlock __libc_lock_unlock +/* XXX for now, waiting for a futex-based pthread_rwlock implementation */ +#define __mach_rwlock_define __libc_lock_define +#define __mach_rwlock_define_initialized __libc_lock_define_initialized +#define __mach_rwlock_init __libc_lock_init +#define __mach_rwlock_fini __libc_lock_fini +#define __mach_rwlock_rdlock __libc_lock_lock +#define __mach_rwlock_wrlock __libc_lock_lock +#define __mach_rwlock_tryrdlock __libc_lock_trylock +#define __mach_rwlock_trywrlock __libc_lock_trylock +#define __mach_rwlock_unlock __libc_lock_unlock struct __libc_cleanup_frame { diff --git a/lib/libc/glibc/sysdeps/s390/s390-64/start-2.33.S b/lib/libc/glibc/sysdeps/s390/s390-64/start-2.33.S deleted file mode 100644 index 02ed4aad512752f7299f9eef82763de8db9a8349..0000000000000000000000000000000000000000 --- a/lib/libc/glibc/sysdeps/s390/s390-64/start-2.33.S +++ /dev/null @@ -1,107 +0,0 @@ -/* Startup code compliant to the 64 bit S/390 ELF ABI. - Copyright (C) 2001-2020 Free Software Foundation, Inc. - Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - In addition to the permissions in the GNU Lesser General Public - License, the Free Software Foundation gives you unlimited - permission to link the compiled version of this file with other - programs, and to distribute those programs without any restriction - coming from the use of this file. (The GNU Lesser General Public - License restrictions do apply in other respects; for example, they - cover modification of the file, and distribution when not linked - into another program.) - - Note that people who make modified versions of this file are not - obligated to grant this special exception for their modified - versions; it is their choice whether to do so. The GNU Lesser - General Public License gives permission to release a modified - version without this exception; this exception also makes it - possible to release a modified version which carries forward this - exception. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -/* - This is the canonical entry point, usually the first thing in the text - segment. Most registers' values are unspecified, except for: - - %r14 Contains a function pointer to be registered with `atexit'. - This is how the dynamic linker arranges to have DT_FINI - functions called for shared libraries that have been loaded - before this code runs. - - %r15 The stack contains the arguments and environment: - 0(%r15) argc - 8(%r15) argv[0] - ... - (8*argc)(%r15) NULL - (8*(argc+1))(%r15) envp[0] - ... - NULL -*/ - - .text - .globl _start - .type _start,@function -_start: - cfi_startproc - /* Mark r14 as undefined in order to stop unwinding here! */ - cfi_undefined (r14) - /* Load argc and argv from stack. */ - la %r4,8(%r15) # get argv - lg %r3,0(%r15) # get argc - - /* Align the stack to a double word boundary. */ - lghi %r0,-16 - ngr %r15,%r0 - - /* Setup a stack frame and a parameter area. */ - aghi %r15,-176 # make room on stack - xc 0(8,%r15),0(%r15) # clear back-chain - - /* Set up arguments for __libc_start_main: - main, argc, argv, envp, _init, _fini, rtld_fini, stack_end - Note that envp will be determined later in __libc_start_main. - */ - stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area - la %r7,160(%r15) - larl %r6,__libc_csu_fini # load pointer to __libc_csu_fini - larl %r5,__libc_csu_init # load pointer to __libc_csu_init - - /* Ok, now branch to the libc main routine. */ -#ifdef PIC - larl %r2,main@GOTENT # load pointer to main - lg %r2,0(%r2) - brasl %r14,__libc_start_main@plt -#else - larl %r2,main # load pointer to main - brasl %r14,__libc_start_main -#endif - - /* Crash if __libc_start_main returns. */ - .word 0 - - cfi_endproc - - /* Define a symbol for the first piece of initialized data. */ - .data - .globl __data_start -__data_start: - .long 0 - .weak data_start - data_start = __data_start diff --git a/lib/libc/glibc/sysdeps/s390/s390-64/start.S b/lib/libc/glibc/sysdeps/s390/s390-64/start.S deleted file mode 100644 index b555503811657b26de5fef1ea9d1feaaea66e359..0000000000000000000000000000000000000000 --- a/lib/libc/glibc/sysdeps/s390/s390-64/start.S +++ /dev/null @@ -1,134 +0,0 @@ -/* Startup code compliant to the 64 bit S/390 ELF ABI. - Copyright (C) 2001-2026 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - In addition to the permissions in the GNU Lesser General Public - License, the Free Software Foundation gives you unlimited - permission to link the compiled version of this file with other - programs, and to distribute those programs without any restriction - coming from the use of this file. (The GNU Lesser General Public - License restrictions do apply in other respects; for example, they - cover modification of the file, and distribution when not linked - into another program.) - - Note that people who make modified versions of this file are not - obligated to grant this special exception for their modified - versions; it is their choice whether to do so. The GNU Lesser - General Public License gives permission to release a modified - version without this exception; this exception also makes it - possible to release a modified version which carries forward this - exception. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -/* - This is the canonical entry point, usually the first thing in the text - segment. Most registers' values are unspecified, except for: - - %r14 Contains a function pointer to be registered with `atexit'. - This is how the dynamic linker arranges to have DT_FINI - functions called for shared libraries that have been loaded - before this code runs. - - %r15 The stack contains the arguments and environment: - 0(%r15) argc - 8(%r15) argv[0] - ... - (8*argc)(%r15) NULL - (8*(argc+1))(%r15) envp[0] - ... - NULL -*/ - - .text - .globl _start - .type _start,@function -_start: - cfi_startproc - /* Mark r14 as undefined in order to stop unwinding here! */ - cfi_undefined (r14) - /* Load argc and argv from stack. */ - la %r4,8(%r15) # get argv - lg %r3,0(%r15) # get argc - - /* Align the stack to a double word boundary. */ - lghi %r0,-16 - ngr %r15,%r0 - - /* Setup a stack frame and a parameter area. */ - aghi %r15,-176 # make room on stack - xc 0(8,%r15),0(%r15) # clear back-chain - - /* Set up arguments for __libc_start_main: - main, argc, argv, envp, _init, _fini, rtld_fini, stack_end - Note that envp will be determined later in __libc_start_main. - */ - stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area - la %r7,160(%r15) - lghi %r6,0 # Used to be fini. - lghi %r5,0 # Used to be init. - - /* Ok, now branch to the libc main routine. */ -#ifdef PIC -# ifdef SHARED - /* Used for dynamic linked position independent executable. - => Scrt1.o */ - larl %r2,main@GOTENT # load pointer to main - lg %r2,0(%r2) -# else - /* Used for dynamic linked position dependent executable. - => crt1.o (glibc configured without --disable-default-pie: - PIC is defined) - Or for static linked position independent executable. - => rcrt1.o (only available if glibc configured without - --disable-default-pie: PIC is defined) */ - larl %r2,__wrap_main -# endif - brasl %r14,__libc_start_main@plt -#else - /* Used for dynamic/static linked position dependent executable. - => crt1.o (glibc configured with --disable-default-pie: - PIC and SHARED are not defined) */ - larl %r2,main # load pointer to main - brasl %r14,__libc_start_main -#endif - - /* Crash if __libc_start_main returns. */ - .word 0 - - cfi_endproc - -#if defined PIC && !defined SHARED - /* When main is not defined in the executable but in a shared library - then a wrapper is needed in crt1.o of the static-pie enabled libc, - because crt1.o and rcrt1.o share code and the later must avoid the - use of GOT relocations before __libc_start_main is called. */ -__wrap_main: - cfi_startproc - larl %r1,main@GOTENT # load pointer to main - lg %r1,0(%r1) - br %r1 - cfi_endproc -#endif - - /* Define a symbol for the first piece of initialized data. */ - .data - .globl __data_start -__data_start: - .long 0 - .weak data_start - data_start = __data_start diff --git a/lib/libc/glibc/sysdeps/s390/s390-64/sysdep.h b/lib/libc/glibc/sysdeps/s390/s390-64/sysdep.h deleted file mode 100644 index 18ed5f1b039fe6555493d8e230918bf24a41a2bb..0000000000000000000000000000000000000000 --- a/lib/libc/glibc/sysdeps/s390/s390-64/sysdep.h +++ /dev/null @@ -1,93 +0,0 @@ -/* Assembler macros for 64 bit S/390. - Copyright (C) 2001-2026 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#ifdef __ASSEMBLER__ - -/* Syntactic details of assembler. */ - -/* ELF uses byte-counts for .align, most others use log2 of count of bytes. */ -#define ALIGNARG(log2) 1<. */ + +#include + +/* + This is the canonical entry point, usually the first thing in the text + segment. Most registers' values are unspecified, except for: + + %r14 Contains a function pointer to be registered with `atexit'. + This is how the dynamic linker arranges to have DT_FINI + functions called for shared libraries that have been loaded + before this code runs. + + %r15 The stack contains the arguments and environment: + 0(%r15) argc + 8(%r15) argv[0] + ... + (8*argc)(%r15) NULL + (8*(argc+1))(%r15) envp[0] + ... + NULL +*/ + + .text + .globl _start + .type _start,@function +_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here! */ + cfi_undefined (r14) + /* Load argc and argv from stack. */ + la %r4,8(%r15) # get argv + lg %r3,0(%r15) # get argc + + /* Align the stack to a double word boundary. */ + lghi %r0,-16 + ngr %r15,%r0 + + /* Setup a stack frame and a parameter area. */ + aghi %r15,-176 # make room on stack + xc 0(8,%r15),0(%r15) # clear back-chain + + /* Set up arguments for __libc_start_main: + main, argc, argv, envp, _init, _fini, rtld_fini, stack_end + Note that envp will be determined later in __libc_start_main. + */ + stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area + la %r7,160(%r15) + larl %r6,__libc_csu_fini # load pointer to __libc_csu_fini + larl %r5,__libc_csu_init # load pointer to __libc_csu_init + + /* Ok, now branch to the libc main routine. */ +#ifdef PIC + larl %r2,main@GOTENT # load pointer to main + lg %r2,0(%r2) + brasl %r14,__libc_start_main@plt +#else + larl %r2,main # load pointer to main + brasl %r14,__libc_start_main +#endif + + /* Crash if __libc_start_main returns. */ + .word 0 + + cfi_endproc + + /* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start diff --git a/lib/libc/glibc/sysdeps/s390/start.S b/lib/libc/glibc/sysdeps/s390/start.S new file mode 100644 index 0000000000000000000000000000000000000000..b555503811657b26de5fef1ea9d1feaaea66e359 --- /dev/null +++ b/lib/libc/glibc/sysdeps/s390/start.S @@ -0,0 +1,134 @@ +/* Startup code compliant to the 64 bit S/390 ELF ABI. + Copyright (C) 2001-2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file with other + programs, and to distribute those programs without any restriction + coming from the use of this file. (The GNU Lesser General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into another program.) + + Note that people who make modified versions of this file are not + obligated to grant this special exception for their modified + versions; it is their choice whether to do so. The GNU Lesser + General Public License gives permission to release a modified + version without this exception; this exception also makes it + possible to release a modified version which carries forward this + exception. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* + This is the canonical entry point, usually the first thing in the text + segment. Most registers' values are unspecified, except for: + + %r14 Contains a function pointer to be registered with `atexit'. + This is how the dynamic linker arranges to have DT_FINI + functions called for shared libraries that have been loaded + before this code runs. + + %r15 The stack contains the arguments and environment: + 0(%r15) argc + 8(%r15) argv[0] + ... + (8*argc)(%r15) NULL + (8*(argc+1))(%r15) envp[0] + ... + NULL +*/ + + .text + .globl _start + .type _start,@function +_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here! */ + cfi_undefined (r14) + /* Load argc and argv from stack. */ + la %r4,8(%r15) # get argv + lg %r3,0(%r15) # get argc + + /* Align the stack to a double word boundary. */ + lghi %r0,-16 + ngr %r15,%r0 + + /* Setup a stack frame and a parameter area. */ + aghi %r15,-176 # make room on stack + xc 0(8,%r15),0(%r15) # clear back-chain + + /* Set up arguments for __libc_start_main: + main, argc, argv, envp, _init, _fini, rtld_fini, stack_end + Note that envp will be determined later in __libc_start_main. + */ + stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area + la %r7,160(%r15) + lghi %r6,0 # Used to be fini. + lghi %r5,0 # Used to be init. + + /* Ok, now branch to the libc main routine. */ +#ifdef PIC +# ifdef SHARED + /* Used for dynamic linked position independent executable. + => Scrt1.o */ + larl %r2,main@GOTENT # load pointer to main + lg %r2,0(%r2) +# else + /* Used for dynamic linked position dependent executable. + => crt1.o (glibc configured without --disable-default-pie: + PIC is defined) + Or for static linked position independent executable. + => rcrt1.o (only available if glibc configured without + --disable-default-pie: PIC is defined) */ + larl %r2,__wrap_main +# endif + brasl %r14,__libc_start_main@plt +#else + /* Used for dynamic/static linked position dependent executable. + => crt1.o (glibc configured with --disable-default-pie: + PIC and SHARED are not defined) */ + larl %r2,main # load pointer to main + brasl %r14,__libc_start_main +#endif + + /* Crash if __libc_start_main returns. */ + .word 0 + + cfi_endproc + +#if defined PIC && !defined SHARED + /* When main is not defined in the executable but in a shared library + then a wrapper is needed in crt1.o of the static-pie enabled libc, + because crt1.o and rcrt1.o share code and the later must avoid the + use of GOT relocations before __libc_start_main is called. */ +__wrap_main: + cfi_startproc + larl %r1,main@GOTENT # load pointer to main + lg %r1,0(%r1) + br %r1 + cfi_endproc +#endif + + /* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start diff --git a/lib/libc/glibc/sysdeps/s390/sysdep.h b/lib/libc/glibc/sysdeps/s390/sysdep.h new file mode 100644 index 0000000000000000000000000000000000000000..18ed5f1b039fe6555493d8e230918bf24a41a2bb --- /dev/null +++ b/lib/libc/glibc/sysdeps/s390/sysdep.h @@ -0,0 +1,93 @@ +/* Assembler macros for 64 bit S/390. + Copyright (C) 2001-2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#ifdef __ASSEMBLER__ + +/* Syntactic details of assembler. */ + +/* ELF uses byte-counts for .align, most others use log2 of count of bytes. */ +#define ALIGNARG(log2) 1< #include #include #include @@ -34,9 +35,9 @@ #undef PSEUDO #define PSEUDO(name, syscall_name, args) \ ENTRY (name); \ - li.d a7, SYS_ify (syscall_name); \ + LI a7, SYS_ify (syscall_name); \ syscall 0; \ - li.d a7, -4096; \ + LI a7, -4096; \ bltu a7, a0, .Lsyscall_error##name; #undef PSEUDO_END @@ -52,16 +53,16 @@ .Lsyscall_error##name : la t0, rtld_errno; \ sub.w a0, zero, a0; \ st.w a0, t0, 0; \ - li.d a0, -1; + LI a0, -1; #else #define SYSCALL_ERROR_HANDLER(name) \ .Lsyscall_error##name : la.tls.ie t0, errno; \ - add.d t0, tp, t0; \ + ADD t0, tp, t0; \ sub.w a0, zero, a0; \ st.w a0, t0, 0; \ - li.d a0, -1; + LI a0, -1; #endif #else @@ -74,7 +75,7 @@ #undef PSEUDO_NEORRNO #define PSEUDO_NOERRNO(name, syscall_name, args) \ ENTRY (name); \ - li.d a7, SYS_ify (syscall_name); \ + LI a7, SYS_ify (syscall_name); \ syscall 0; #undef PSEUDO_END_NOERRNO @@ -85,11 +86,17 @@ /* Performs a system call, returning the error code. */ #undef PSEUDO_ERRVAL +#if __loongarch_grlen == 64 #define PSEUDO_ERRVAL(name, syscall_name, args) \ PSEUDO_NOERRNO (name, syscall_name, args); \ slli.d a0, a0, 32; \ srai.d a0, a0, 32; /* sign_ext */ \ sub.d a0, zero, a0; +#else +#define PSEUDO_ERRVAL(name, syscall_name, args) \ + PSEUDO_NOERRNO (name, syscall_name, args); \ + sub.w a0, zero, a0; +#endif #undef PSEUDO_END_ERRVAL #define PSEUDO_END_ERRVAL(name) END (name); @@ -109,6 +116,18 @@ #undef SYS_ify #define SYS_ify(syscall_name) __NR_##syscall_name +#if __WORDSIZE == 32 +/* Workarounds for generic code needing to handle 64-bit time_t. */ +#define __NR_clock_getres __NR_clock_getres_time64 +#define __NR_futex __NR_futex_time64 +#define __NR_ppoll __NR_ppoll_time64 +#define __NR_pselect6 __NR_pselect6_time64 +#define __NR_recvmmsg __NR_recvmmsg_time64 +#define __NR_rt_sigtimedwait __NR_rt_sigtimedwait_time64 +#define __NR_semtimedop __NR_semtimedop_time64 +#define __NR_utimensat __NR_utimensat_time64 +#endif /* __WORDSIZE == 32 */ + #ifndef __ASSEMBLER__ #define VDSO_NAME "LINUX_5.10" diff --git a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h index 826a1e425c1a2b3b1ee712643d53284412275bfa..6e2be2270f3ef2352418c9ca49af32ecd9e1f9ca 100644 --- a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h +++ b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/bits/typesizes.h @@ -57,42 +57,34 @@ #define __TIMER_T_TYPE void * #define __BLKSIZE_T_TYPE __SLONGWORD_TYPE #define __FSID_T_TYPE struct { int __val[2]; } -#if defined __GNUC__ && __GNUC__ <= 2 -/* Compatibility with g++ 2.95.x. */ -#define __SSIZE_T_TYPE __SWORD_TYPE -#else -/* size_t is unsigned long int on s390 -m31. */ -#define __SSIZE_T_TYPE __SLONGWORD_TYPE -#endif + +/* With s390-32, __SSIZE_T_TYPE was __SWORD_TYPE for compatibility with + g++ 2.95.x. Afterwards __SLONGWORD_TYPE was needed as size_t was + unsigned long int on s390-32. + Now as only s390-64 exists, __SWORD_TYPE can be used as also used in the + generic version as both types result in long int. */ +#define __SSIZE_T_TYPE __SWORD_TYPE + #define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE #define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE -#define __CPU_MASK_TYPE __ULONGWORD_TYPE +#define __CPU_MASK_TYPE __ULONGWORD_TYPE -#ifdef __s390x__ /* Tell the libc code that off_t and off64_t are actually the same type for all ABI purposes, even if possibly expressed as different base types for C type-checking purposes. */ -# define __OFF_T_MATCHES_OFF64_T 1 +#define __OFF_T_MATCHES_OFF64_T 1 /* Same for ino_t and ino64_t. */ -# define __INO_T_MATCHES_INO64_T 1 +#define __INO_T_MATCHES_INO64_T 1 /* And for __rlim_t and __rlim64_t. */ -# define __RLIM_T_MATCHES_RLIM64_T 1 +#define __RLIM_T_MATCHES_RLIM64_T 1 /* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */ -# define __STATFS_MATCHES_STATFS64 1 +#define __STATFS_MATCHES_STATFS64 1 /* And for getitimer, setitimer and rusage */ -# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1 -#else -# define __RLIM_T_MATCHES_RLIM64_T 0 - -# define __STATFS_MATCHES_STATFS64 0 - -/* And for getitimer, setitimer and rusage */ -# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0 -#endif +#define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1 /* Number of descriptors that can fit in an `fd_set'. */ #define __FD_SETSIZE 1024 diff --git a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/kernel-features.h b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/kernel-features.h index a955c18738ad557e51a261b279eb2e3111870924..d7af29285fc538b2deda44f9aab98e5fcb60fef1 100644 --- a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/kernel-features.h +++ b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/kernel-features.h @@ -47,9 +47,6 @@ # undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS # undef __ASSUME_SYSVIPC_DEFAULT_IPC_64 #endif -#ifndef __s390x__ -# define __ASSUME_SYSVIPC_BROKEN_MODE_T -#endif #undef __ASSUME_CLONE_DEFAULT #define __ASSUME_CLONE_BACKWARDS2 diff --git a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h deleted file mode 100644 index 9c9e2a271f57c5ce5d2efef9fc23c36ea55da6ac..0000000000000000000000000000000000000000 --- a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h +++ /dev/null @@ -1,178 +0,0 @@ -/* Assembler macros for 64 bit S/390. - Copyright (C) 2001-2026 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _LINUX_S390_SYSDEP_H -#define _LINUX_S390_SYSDEP_H - -#include -#include -#include -#include -#include /* For RTLD_PRIVATE_ERRNO. */ -#include - -/* For Linux we can use the system call table in the header file - /usr/include/asm/unistd.h - of the kernel. But these symbols do not follow the SYS_* syntax - so we have to redefine the `SYS_ify' macro here. */ -/* In newer 2.1 kernels __NR_syscall is missing so we define it here. */ -#define __NR_syscall 0 - -#undef SYS_ify -#define SYS_ify(syscall_name) __NR_##syscall_name - -#ifdef __ASSEMBLER__ - -/* Linux uses a negative return value to indicate syscall errors, unlike - most Unices, which use the condition codes' carry flag. - - Since version 2.1 the return value of a system call might be negative - even if the call succeeded. E.g., the `lseek' system call might return - a large offset. Therefore we must not anymore test for < 0, but test - for a real error by making sure the value in gpr2 is a real error - number. Linus said he will make sure that no syscall returns a value - in -1 .. -4095 as a valid result so we can safely test with -4095. */ - -#undef PSEUDO -#define PSEUDO(name, syscall_name, args) \ - .text; \ - ENTRY (name) \ - DO_CALL (syscall_name, args); \ - lghi %r4,-4095 ; \ - clgr %r2,%r4 ; \ - jgnl SYSCALL_ERROR_LABEL - -#undef PSEUDO_END -#define PSEUDO_END(name) \ - SYSCALL_ERROR_HANDLER; \ - END (name) - -#undef PSEUDO_NOERRNO -#define PSEUDO_NOERRNO(name, syscall_name, args) \ - .text; \ - ENTRY (name) \ - DO_CALL (syscall_name, args) - -#undef PSEUDO_END_NOERRNO -#define PSEUDO_END_NOERRNO(name) \ - SYSCALL_ERROR_HANDLER; \ - END (name) - -#undef PSEUDO_ERRVAL -#define PSEUDO_ERRVAL(name, syscall_name, args) \ - .text; \ - ENTRY (name) \ - DO_CALL (syscall_name, args); \ - lcgr %r2,%r2 - -#undef PSEUDO_END_ERRVAL -#define PSEUDO_END_ERRVAL(name) \ - SYSCALL_ERROR_HANDLER; \ - END (name) - -#undef SYSCALL_ERROR_LABEL -#ifndef PIC -# undef SYSCALL_ERROR_LABEL -# define SYSCALL_ERROR_LABEL syscall_error -# define SYSCALL_ERROR_HANDLER -#else -# if RTLD_PRIVATE_ERRNO -# undef SYSCALL_ERROR_LABEL -# define SYSCALL_ERROR_LABEL 0f -# define SYSCALL_ERROR_HANDLER \ -0: larl %r1,rtld_errno; \ - lcr %r2,%r2; \ - st %r2,0(%r1); \ - lghi %r2,-1; \ - br %r14 -# elif defined _LIBC_REENTRANT -# if IS_IN (libc) -# define SYSCALL_ERROR_ERRNO __libc_errno -# else -# define SYSCALL_ERROR_ERRNO errno -# endif -# undef SYSCALL_ERROR_LABEL -# define SYSCALL_ERROR_LABEL 0f -# define SYSCALL_ERROR_HANDLER \ -0: lcr %r0,%r2; \ - larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \ - lg %r1,0(%r1); \ - ear %r2,%a0; \ - sllg %r2,%r2,32; \ - ear %r2,%a1; \ - st %r0,0(%r1,%r2); \ - lghi %r2,-1; \ - br %r14 -# else -# undef SYSCALL_ERROR_LABEL -# define SYSCALL_ERROR_LABEL 0f -# define SYSCALL_ERROR_HANDLER \ -0: larl %r1,_GLOBAL_OFFSET_TABLE_; \ - lg %r1,errno@GOT(%r1); \ - lcr %r2,%r2; \ - st %r2,0(%r1); \ - lghi %r2,-1; \ - br %r14 -# endif /* _LIBC_REENTRANT */ -#endif /* PIC */ - -/* Linux takes system call arguments in registers: - - syscall number 1 call-clobbered - arg 1 2 call-clobbered - arg 2 3 call-clobbered - arg 3 4 call-clobbered - arg 4 5 call-clobbered - arg 5 6 call-saved - arg 6 7 call-saved - - (Of course a function with say 3 arguments does not have entries for - arguments 4 and 5.) - For system calls with 6 parameters a stack operation is required - to load the 6th parameter to register 7. Call saved register 7 is - moved to register 0 and back to avoid an additional stack frame. - */ - -#define DO_CALL(syscall, args) \ - .if args > 5; \ - lgr %r0,%r7; \ - lg %r7,160(%r15); \ - .endif; \ - lghi %r1,SYS_ify (syscall); \ - svc 0; \ - .if args > 5; \ - lgr %r7,%r0; \ - .endif - -#define ret \ - br 14 - -#define ret_NOERRNO \ - br 14 - -#define ret_ERRVAL \ - br 14 - -#else - -# undef HAVE_INTERNAL_BRK_ADDR_SYMBOL -# define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1 - -#endif /* __ASSEMBLER__ */ - -#endif /* _LINUX_S390_SYSDEP_H */ diff --git a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/sysdep.h b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/sysdep.h index ee2d92edff1f0ee2fb8e0a25217e35dccbd0ff30..42fb8aa4692be8cd884dc9cb076b7c62412c03f0 100644 --- a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -1,5 +1,5 @@ -/* Syscall definitions, Linux s390 version. - Copyright (C) 2019-2026 Free Software Foundation, Inc. +/* Assembler macros for 64 bit S/390. + Copyright (C) 2001-2026 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -14,15 +14,163 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see - . */ + . */ -#ifndef __ASSEMBLY__ +#ifndef _LINUX_S390_SYSDEP_H +#define _LINUX_S390_SYSDEP_H + +#include +#include +#include +#include /* For RTLD_PRIVATE_ERRNO. */ +#include + +/* For Linux we can use the system call table in the header file + /usr/include/asm/unistd.h + of the kernel. But these symbols do not follow the SYS_* syntax + so we have to redefine the `SYS_ify' macro here. */ +/* In newer 2.1 kernels __NR_syscall is missing so we define it here. */ +#define __NR_syscall 0 #undef SYS_ify #define SYS_ify(syscall_name) __NR_##syscall_name -#undef INTERNAL_SYSCALL_NCS -#define INTERNAL_SYSCALL_NCS(no, nr, args...) \ +#ifdef __ASSEMBLER__ + +/* Linux uses a negative return value to indicate syscall errors, unlike + most Unices, which use the condition codes' carry flag. + + Since version 2.1 the return value of a system call might be negative + even if the call succeeded. E.g., the `lseek' system call might return + a large offset. Therefore we must not anymore test for < 0, but test + for a real error by making sure the value in gpr2 is a real error + number. Linus said he will make sure that no syscall returns a value + in -1 .. -4095 as a valid result so we can safely test with -4095. */ + +# undef PSEUDO +# define PSEUDO(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + DO_CALL (syscall_name, args); \ + lghi %r4,-4095 ; \ + clgr %r2,%r4 ; \ + jgnl SYSCALL_ERROR_LABEL + +# undef PSEUDO_END +# define PSEUDO_END(name) \ + SYSCALL_ERROR_HANDLER; \ + END (name) + +# undef PSEUDO_NOERRNO +# define PSEUDO_NOERRNO(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + DO_CALL (syscall_name, args) + +# undef PSEUDO_END_NOERRNO +# define PSEUDO_END_NOERRNO(name) \ + SYSCALL_ERROR_HANDLER; \ + END (name) + +# undef PSEUDO_ERRVAL +# define PSEUDO_ERRVAL(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + DO_CALL (syscall_name, args); \ + lcgr %r2,%r2 + +# undef PSEUDO_END_ERRVAL +# define PSEUDO_END_ERRVAL(name) \ + SYSCALL_ERROR_HANDLER; \ + END (name) + +# undef SYSCALL_ERROR_LABEL +# ifndef PIC +# undef SYSCALL_ERROR_LABEL +# define SYSCALL_ERROR_LABEL syscall_error +# define SYSCALL_ERROR_HANDLER +# else +# if RTLD_PRIVATE_ERRNO +# undef SYSCALL_ERROR_LABEL +# define SYSCALL_ERROR_LABEL 0f +# define SYSCALL_ERROR_HANDLER \ +0: larl %r1,rtld_errno; \ + lcr %r2,%r2; \ + st %r2,0(%r1); \ + lghi %r2,-1; \ + br %r14 +# elif defined _LIBC_REENTRANT +# if IS_IN (libc) +# define SYSCALL_ERROR_ERRNO __libc_errno +# else +# define SYSCALL_ERROR_ERRNO errno +# endif +# undef SYSCALL_ERROR_LABEL +# define SYSCALL_ERROR_LABEL 0f +# define SYSCALL_ERROR_HANDLER \ +0: lcr %r0,%r2; \ + larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \ + lg %r1,0(%r1); \ + ear %r2,%a0; \ + sllg %r2,%r2,32; \ + ear %r2,%a1; \ + st %r0,0(%r1,%r2); \ + lghi %r2,-1; \ + br %r14 +# else +# undef SYSCALL_ERROR_LABEL +# define SYSCALL_ERROR_LABEL 0f +# define SYSCALL_ERROR_HANDLER \ +0: larl %r1,_GLOBAL_OFFSET_TABLE_; \ + lg %r1,errno@GOT(%r1); \ + lcr %r2,%r2; \ + st %r2,0(%r1); \ + lghi %r2,-1; \ + br %r14 +# endif /* _LIBC_REENTRANT */ +# endif /* PIC */ + +/* Linux takes system call arguments in registers: + + syscall number 1 call-clobbered + arg 1 2 call-clobbered + arg 2 3 call-clobbered + arg 3 4 call-clobbered + arg 4 5 call-clobbered + arg 5 6 call-saved + arg 6 7 call-saved + + (Of course a function with say 3 arguments does not have entries for + arguments 4 and 5.) + For system calls with 6 parameters a stack operation is required + to load the 6th parameter to register 7. Call saved register 7 is + moved to register 0 and back to avoid an additional stack frame. + */ + +# define DO_CALL(syscall, args) \ + .if args > 5; \ + lgr %r0,%r7; \ + lg %r7,160(%r15); \ + .endif; \ + lghi %r1,SYS_ify (syscall); \ + svc 0; \ + .if args > 5; \ + lgr %r7,%r0; \ + .endif + +# define ret \ + br 14 + +# define ret_NOERRNO \ + br 14 + +# define ret_ERRVAL \ + br 14 + +#else /* not __ASSEMBLER__ */ + +# undef INTERNAL_SYSCALL_NCS +# define INTERNAL_SYSCALL_NCS(no, nr, args...) \ ({ \ DECLARGS_##nr(args) \ register unsigned long int _nr __asm__("1") = (unsigned long int)(no); \ @@ -34,51 +182,52 @@ : "memory" ); \ _ret; }) -#undef INTERNAL_SYSCALL -#define INTERNAL_SYSCALL(name, nr, args...) \ +# undef INTERNAL_SYSCALL +# define INTERNAL_SYSCALL(name, nr, args...) \ INTERNAL_SYSCALL_NCS(__NR_##name, nr, args) -#define DECLARGS_0() -#define DECLARGS_1(arg1) \ +# define DECLARGS_0() +# define DECLARGS_1(arg1) \ register unsigned long int gpr2 __asm__ ("2") = (unsigned long int)(arg1); -#define DECLARGS_2(arg1, arg2) \ +# define DECLARGS_2(arg1, arg2) \ DECLARGS_1(arg1) \ register unsigned long int gpr3 __asm__ ("3") = (unsigned long int)(arg2); -#define DECLARGS_3(arg1, arg2, arg3) \ +# define DECLARGS_3(arg1, arg2, arg3) \ DECLARGS_2(arg1, arg2) \ register unsigned long int gpr4 __asm__ ("4") = (unsigned long int)(arg3); -#define DECLARGS_4(arg1, arg2, arg3, arg4) \ +# define DECLARGS_4(arg1, arg2, arg3, arg4) \ DECLARGS_3(arg1, arg2, arg3) \ register unsigned long int gpr5 __asm__ ("5") = (unsigned long int)(arg4); -#define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \ +# define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \ DECLARGS_4(arg1, arg2, arg3, arg4) \ register unsigned long int gpr6 __asm__ ("6") = (unsigned long int)(arg5); -#define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \ +# define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \ DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \ register unsigned long int gpr7 __asm__ ("7") = (unsigned long int)(arg6); -#define ASMFMT_0 -#define ASMFMT_1 , "0" (gpr2) -#define ASMFMT_2 , "0" (gpr2), "d" (gpr3) -#define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4) -#define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5) -#define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6) -#define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7) +# define ASMFMT_0 +# define ASMFMT_1 , "0" (gpr2) +# define ASMFMT_2 , "0" (gpr2), "d" (gpr3) +# define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4) +# define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5) +# define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6) +# define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7) -#define VDSO_NAME "LINUX_2.6.29" -#define VDSO_HASH 123718585 +# define VDSO_NAME "LINUX_2.6.29" +# define VDSO_HASH 123718585 /* List of system calls which are supported as vsyscalls. */ -#ifdef __s390x__ -#define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" -#define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" -#define HAVE_GETRANDOM_VSYSCALL "__kernel_getrandom" -#else -#define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" -#define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" -#endif -#define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" -#define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" - -#define HAVE_CLONE3_WRAPPER 1 -#endif +# define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" +# define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +# define HAVE_GETRANDOM_VSYSCALL "__kernel_getrandom" +# define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" +# define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" + +# define HAVE_CLONE3_WRAPPER 1 + +# undef HAVE_INTERNAL_BRK_ADDR_SYMBOL +# define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1 + +#endif /* __ASSEMBLER__ */ + +#endif /* _LINUX_S390_SYSDEP_H */ diff --git a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/xstatver.h b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/xstatver.h index 9923199e407ccd8c3c341695841bcc07802c0189..f24ab4a9ee158d7f0890cd228b20bf1e278d332b 100644 --- a/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/xstatver.h +++ b/lib/libc/glibc/sysdeps/unix/sysv/linux/s390/xstatver.h @@ -1,19 +1,10 @@ /* Versions of the 'struct stat' data structure used in compatibility xstat functions. */ - -#include - -#if __WORDSIZE == 64 -# define _STAT_VER_KERNEL 0 -# define _STAT_VER_LINUX 1 -# define _MKNOD_VER_LINUX 0 -#else -# define _STAT_VER_LINUX_OLD 1 -# define _STAT_VER_KERNEL 1 -# define _STAT_VER_SVR4 2 -# define _STAT_VER_LINUX 3 -# define _MKNOD_VER_LINUX 1 -# define _MKNOD_VER_SVR4 2 -#endif +#define _STAT_VER_KERNEL 0 +#define _STAT_VER_LINUX 1 #define _STAT_VER _STAT_VER_LINUX + +/* Versions of the 'xmknod' interface used in compatibility xmknod + functions. */ +#define _MKNOD_VER_LINUX 0 #define _MKNOD_VER _MKNOD_VER_LINUX diff --git a/src/libs/glibc.zig b/src/libs/glibc.zig index 59abb61f333a8baf6ce54a485ff3dcdbdefd2afc..fce076dba86d74c52756d72419ed8859633992b5 100644 --- a/src/libs/glibc.zig +++ b/src/libs/glibc.zig @@ -398,7 +398,7 @@ fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![ try result.appendSlice("powerpc" ++ s ++ "powerpc32"); } } else if (arch == .s390x) { - try result.appendSlice("s390" ++ s ++ "s390-64"); + try result.appendSlice("s390"); } else if (arch.isLoongArch()) { try result.appendSlice("loongarch"); } else if (arch == .m68k) { @@ -607,8 +607,6 @@ fn add_include_dirs_arch( try args.append("-I"); try args.append(try path.join(arena, &[_][]const u8{ dir, "s390", nptl })); } else { - try args.append("-I"); - try args.append(try path.join(arena, &[_][]const u8{ dir, "s390" ++ s ++ "s390-64" })); try args.append("-I"); try args.append(try path.join(arena, &[_][]const u8{ dir, "s390" })); }