path: root/libc/sysdeps
AgeCommit message (Collapse)Author
10 daysopen: Add support for O_TMPFILENicolas Cavallari
Since Linux 3.11, O_TMPFILE allows to create unnamed files that can be linked later on. It is internally defined as (O_TMPFILE | O_DIRECTORY) to make it fail on old kernels. Copying definitions from glibc for O_TMPFILE is not enough to support O_TMPFILE; The open() wrapper also need to pass the mode when the flag contains O_TMPFILE, otherwise, it will pass mode 000 which will succeed but yield unexpected results. openat() is curiously not affected since it passes the mode unconditionally.. Signed-off-by: Nicolas Cavallari <>
2021-02-18fcntl.h: Make F_DUPFD_CLOEXEC if _USE_XOPEN2K8Paul Cercueil
The F_DUPFD_CLOEXEC flag was added in POSIX 2008.09. Signed-off-by: Paul Cercueil <>
2021-01-28use renameat2 syscall, when renameat isn't availableWaldemar Brodkorb
2021-01-27fix umount2 compilation for alpha on Linux 5.xWaldemar Brodkorb
2021-01-27sh: Add 64-bit time types from kernelGeoffrey Le Gourriérec
Building uclibc 1.0.37 for SuperH architecture with linux-headers 5.10.7 fails at libpthread level due to missing time-related data structures, usually defined by the kernel. Define those missing data structures in SuperH-specific kernel_types.h. Context: building for sh4eb-r2d[1] and sh4-r2d[1] boards emulations for QEMU using the buildroot image generation tool. Regarding the issue, a patch[3] was already issued in the kernel some time ago, which aimed to solve precisely this problem. After coming up with a quick and dirty patch for buildroot modifying Linux headers[4], some discussion was sparked on the subject with Linux folks[5]. Some analyzing later, conclusion was that: 1) Previously mentioned patch[4] was fixing the symptom, not the ill 2) SuperH-specific code in uclibc could be patched instead, to solve the problem for other use cases (e.g. building just a toolchain) [1] [2] [3] [4] [5] Signed-off-by: Geoffrey Le Gourriérec <>
2020-10-02kvx: add support for kvx arch to uClibc-ngYann Sionneau
This commit adds support for Kalray VLIW family (kvx) Kalray kv3 core is embedded in Kalray Coolidge SoC. This core which is the third of the KV family has the following features: 32/64 bits execution mode 6-issue VLIW architecture 64 x 64bits general purpose registers SIMD instructions little-endian In order to build a usable toolchain, build scripts are provided at the following address: Kalray uses FOSS which is available at This includes Linux kernel, uClibc-ng, gcc, binutils, etc. Signed-off-by: Clément Léger <> Signed-off-by: Guillaume Thouvenin <> Signed-off-by: Laurent Thevenoux <> Signed-off-by: Marc Poulhies <> Signed-off-by: Marius Gligor <> Signed-off-by: Yann Sionneau <>
2020-09-15Fix memory corruption due to struct stat fieldYann Sionneau
Kernel stat/stat64 structure and uClibc-ng ones were not in sync regarding the timespec fields. Kernel had them but uClibc did not expose it in some cases. Man page says that stat struct should have timespec fields if: * _POSIX_C_SOURCE is defined to 200809L or greater or * _XOPEN_SOURCE is defined to 700 or greater or * _BSD_SOURCE is defined or * _SVID_SOURCE is defined In the case of buildroot vim build, neither _BSD_SOURCE nor _SVID_SOURCE were defined. Only _POSIX_C_SOURCE and _XOPEN_SOURCE were defined. uClibc-ng header only checked for _BSD_SOURCE and _SVID_SOURCE via __USE_MISC. This patch adds a check to __USE_XOPEN2K8 which is defined if _POSIX_C_SOURCE >= 200809L or _XOPEN_SOURCE >= 700 This for instance fixes a crash at startup of vim (not the busybox one) on aarch64 and all other arch where in kernel STAT_HAVE_NSEC is set and where stat.h in uClibc-ng comes from libc/sysdeps/linux/common-generic/bits Signed-off-by: Yann Sionneau <>
2020-08-19Add {name, open}_to_handle_at() implementationPetr Vorel
copied from musl 1.2.1. Signed-off-by: Petr Vorel <>
2020-08-17riscv64: add __riscv_flush_icacheWaldemar Brodkorb
Always use the systemcall as uClibc-ng has no vdso support. Tested with libffi and python in qemu-system-riscv64.
2020-08-15sys/random.h include stddef.hWaldemar Brodkorb
Reported-By: akater <>
2020-08-11xtensa: add exclusive access supportMax Filippov
Add XCHAL definitions for S32C1I and EXCLUSIVE options to xtensa-config.h, include it in places that implement atomic operations and add implementations with exclusive access option opcodes. Signed-off-by: Max Filippov <>
2020-08-11xtensa: relax memory constraint in atomic assemblyMax Filippov
Replace "a" constraints with "+m" to avoid forcing atomic variable address into a register and let the compiler use non-zero offset in load/store opcodes. Signed-off-by: Max Filippov <>
2020-07-02Rename __unused struct members to include a namespaceEd Wildgoose
Rename various spare fields in structs to include a namespace This should avoid accidental clashes with uses of the __unused symbol in upstream projects. eg currently it causes a compile error in dhcpcd 8.x due to their re-use of the __unused symbol as a macro This follows the style of glibc which does something equivalent
2020-05-17mips: Do not include hi and lo in __SYSCALL_CLOBBERS for R6Romain Naour
From [1] "GCC 10 (PR 91233) won't silently allow registers that are not architecturally available to be present in the clobber list anymore, resulting in build failure for mips*r6 targets in form of: ... .../sysdep.h:146:2: error: the register ‘lo’ cannot be clobbered in ‘asm’ for the current target 146 | __asm__ volatile ( \ | ^~~~~~~ This is because base R6 ISA doesn't define hi and lo registers w/o DSP extension. This patch provides the alternative definitions of __SYSCALL_CLOBBERS for r6 targets that won't include those registers." [1];a=commit;h=020b2a97bb15f807c0482f0faee2184ed05bcad8 Signed-off-by: Romain Naour <> Cc: Waldemar Brodkorb <>
2020-04-01statx: make include conditional, fixes non-csky arch buildroot buildsWaldemar Brodkorb
2020-02-07aarch64/bits: provide sigstack.hVladimir Murzin
It fixes tst-signal6 and friends. Signed-off-by: Vladimir Murzin <>
2020-02-07aarch64/sys: update ucontext.hVladimir Murzin
It fixes tst-cancel1 and friends. Signed-off-by: Vladimir Murzin <>
2020-02-07common/bits: Fix ipc_perm and semid_ds definitions for 64-bit archesVladimir Murzin
It fixes: FAIL sem got 1 expected 0 failed: incorrect sem_nsems! semget(IPC_CREAT) = 0 semctl(k) = 0 sem_nsems = 0 for aarch64. Signed-off-by: Vladimir Murzin <>
2020-02-03csky: add statx conditionalsWaldemar Brodkorb
Similar to glibc commit;a=commit;h=6bbfc5c09fc5b5e3d4a0cddbbd4e2e457767dae7 we need to handle Linux kernel change, which removed stat64 family from default syscall set. Signed-off-by: Waldemar Brodkorb <> Signed-off-by: Waldemar Brodkorb <>
2020-01-30poll: avoid calling select with empty sets which hangs the processYann Sionneau
Avoid calling select with empty sets which hangs the process This makes uClibc-ng act like glibc and musl Without this fix the test_poll of python3 testsuite hangs forever Scenario of the issue: If you call poll with only invalid file descriptors, like in python3 testsuite ( You will go through uClibc poll emulation code, which is based on select syscall. Your first call to select will fail, it will return -1 and errno will be set to EBADF: Then you will go through the for loop which tests individually each file descriptor by calling select on each one: each call will also return -1 with errno being equal to EBADF. Therefore all pollfd will have the POLLNVAL flag in their respective revents field. And, the most important, rset/wset/xset will stay empty. Then the for loop ends, the "continue" makes the while loop run again. The following select() is run again: But this time the sets are empty. If the poll was called with timeout set to -1, this select will hang forever because there is no timeout and the sets are empty so no event will ever wake it up. test program: int main(void) { struct pollfd pfd; int ret; int pipe_fds[2]; pipe(pipe_fds); close(pipe_fds[0]); close(pipe_fds[1]); pfd.fd = pipe_fds[0]; = POLLIN | POLLOUT | POLLPRI; pfd.revents = 0; ret = poll(&pfd, 1, -1); printf("ret: %d\n", ret); if (ret < 0) printf("error: %s", strerror(errno)); else { puts("revents: "); if (pfd.revents & POLLERR) printf(" POLLERR"); if (pfd.revents & POLLHUP) printf(" POLLHUP"); if (pfd.revents & POLLNVAL) printf(" POLLNVAL"); puts(""); } return 0; } This hangs on uClibc-ng aarch64 and Kalray's arch (kv3) but does the following on musl and glibc: " ret: 1 revents: POLLNVAL " strace output of this program with uClibc *without* the patch applied: pselect6(4, [3], [3], [3], NULL, NULL) = -1 EBADF (Bad file descriptor) pselect6(4, [3], [3], [3], {tv_sec=0, tv_nsec=0}, NULL) = -1 EBADF (Bad file descriptor) pselect6(0, 0x7ffffffb80, 0x7ffffffb68, 0x7ffffffb50, NULL, NULL (never finishes) strace output of this program with uClibc *with* the patch applied: pselect6(4, [3], [3], [3], NULL, NULL) = -1 EBADF (Bad file descriptor) pselect6(4, [3], [3], [3], {tv_sec=0, tv_nsec=0}, NULL) = -1 EBADF (Bad file descriptor) write(1, "ret: 1\n", 7ret: 1 ) = 7 write(1, "revents: \n", 10revents: ) = 10 write(1, " POLLNVAL\n", 10 POLLNVAL ) = 10 exit_group(0) = ? +++ exited with 0 +++
2019-11-17fix PTRAVE_EVENT_SECCOMP typo in ptrace.hJoris Vink
Hi, This diff fixes a typo in the PTRACE_EVENT_SECCOMP event code. The typo itself was introduced in 2012 when syncing with glibc header files and was itself fixed in 2013 in the glibc headers.
2019-11-08riscv64: implement NPTL/TLSWaldemar Brodkorb
basically from or1k port of uClibc-ng, with fixes for structures in pthreadtypes.h from 64 bit architectures. 18 testsuite failures counted.
2019-11-06riscv64: lazy relocations do not work like sparc/m68kWaldemar Brodkorb
2019-11-05implement fexecve from glibcWaldemar Brodkorb
2019-10-31riscv64: add shared library supportWaldemar Brodkorb
2019-10-30Make __syscall_error return long, as expected by syscall() callersCarlos Santos
The return type of syscall() is long so __syscall_error, which is jumped to by syscall handlers to stash an error number into errno, must return long too otherwhise it returs 4294967295L instead of -1L. For example, syscall for x86_64 is defined in libc/sysdeps/linux/x86_64/syscall.S as syscall: movq %rdi, %rax /* Syscall number -> rax. */ movq %rsi, %rdi /* shift arg1 - arg5. */ movq %rdx, %rsi movq %rcx, %rdx movq %r8, %r10 movq %r9, %r8 movq 8(%rsp),%r9 /* arg6 is on the stack. */ syscall /* Do the system call. */ cmpq $-4095, %rax /* Check %rax for error. */ jae __syscall_error /* Branch forward if it failed. */ ret /* Return to caller. */ In libc/sysdeps/linux/x86_64/__syscall_error.c, __syscall_error is defined as int __syscall_error(void) attribute_hidden; int __syscall_error(void) { register int err_no __asm__ ("%rcx"); __asm__ ("mov %rax, %rcx\n\t" "neg %rcx"); __set_errno(err_no); return -1; } So __syscall_error returns -1 as a 32-bit int in a 64-bit register, %rax (0x00000000ffffffff, whose decimal value is decimal 4294967295) and a test like this always returns false: if (syscall(number, ...) == -1) foo(); Fix the error by making __syscall_error return a long, like syscall(). The problem can be circumvented by the caller by coercing the returned value to int before comparing it to -1: if ((int) syscall(number, ...) == -1) foo(); The same problem probably occurs on other 64-bit systems but so far only x86_64 was tested, so this change must be considered experimental. Signed-off-by: Carlos Santos <>
2019-10-15Fix value for O_mask_was_saved based on gdb observationmirabilos
(gdb) print offsetof(struct __jmp_buf_tag, __mask_was_saved) $12 = (int *) 0x1f0 using
2019-10-15sparc64: Make structure match kernel uapimirabilos
Update from linux/arch/sparc/include/uapi/asm/uctx.h
2019-10-15sparc64: Use the jmpbuf-offsets.h header instead of duplicating itmirabilos
2019-10-10aarch64: sync with glibc code to see any differences in a better wayWaldemar Brodkorb
2019-10-05or1k: Fix compiling with PIC and latest binutils use PLT for __syscall_errorStafford Horne
This symbol was causing a build failure with the new toolchain. It looks like it has always been wrong. The main issue was checking for PIC rather than __PIC__. Remove all PSEUDO_* macros and ther SYSCALL_ERROR_NAME macro as they are not needed by uclibc-ng, they are used in glibc for building up syscalls there, but not here. Fixes error: /opt/shorne/software/or1k-linux/bin/../lib/gcc/or1k-linux/9.0.1/../../../../or1k-linux/bin/ld: libc/libc_so.a(or1k_clone.os): pc-relative relocation against dynamic symbol __syscall_error /opt/shorne/software/or1k-linux/bin/../lib/gcc/or1k-linux/9.0.1/../../../../or1k-linux/bin/ld: final link failed: bad value Signed-off-by: Stafford Horne <>
2019-09-30PowerPC: Fix termios definitionsAdhemerval Zanella
This patch fixes the incorrect guard by __USE_MISC of struct winsize and struct termio in powerpc termios header. Current states leads to build failures if the program defines _XOPEN_SOURCE, but not _DEFAULT_SOURCE or either _BSD_SOURCE or _SVID_SOURCE. Without any definition, __USE_MISC will not be defined and neither the struct definitions. This patch copies the default Linux ioctl-types.h by adjusting only the character control field (c_cc) size in struct termio. Signed-off-by: Vadim Kochan <> [Vadim: adopted for uclibc ]
2019-07-05riscv: clear a3/a4 in crt1Christoph Hellwig
We don't support shared libraries and thus _init/_fini. But loading nommu binaries blows they aren't cleared, so do that. Signed-off-by: Christoph Hellwig <>
2019-07-05riscv: add the MAP_UNINITIALIZED definitionChristoph Hellwig
This avoids a nommu build failure. Signed-off-by: Christoph Hellwig <>
2019-05-27sparc: remove asm constraintRomain Naour
uClibc-ng don't build with gcc 9.1 [1] due to a new check that "catch illegal asm constraint usage" [2]. gcc 9.1 print this error: "invalid hard register usage between earlyclobber operand and input operand" The asm constraint is present in uClibc since it support sparc (back in 2002)[3]. Note: There is no such constraint is Glibc counterpart code [4]. [1] [2] [3] [4] +;a=blob;f=sysdeps/unix/sysv/linux/sparc/sysdep.h;h=981b2a26b7a91093f821c97876 +e55bc4be2d9f8a;hb=HEAD
2019-05-13preadv/pwritev: fix offset argument typeMax Filippov
preadv/pwritev don't provide separate version for 64-bit wide off_t, and default to 32-bit wide off_t, which results in a mismatch between declaration and definition for user programs built with -D_FILE_OFFSET_BITS=64. Make offset argument of both functions __off64_t. This fixes test misc/tst-preadvwritev on xtensa. Signed-off-by: Max Filippov <>
2018-12-14xtensa: add custom bits/poll.hMax Filippov
Definitions of POLLWRNORM, POLLWRBAND and POLLREMOVE in xtensa linux kernel are non-standard. Provide bits/poll.h with correct values for these constants. This fixes the following strace build errors: In file included from xlat/pollflags.h:4:0, from poll.c:34: ./static_assert.h:40:24: error: static assertion failed: "POLLWRBAND != 0x0100" # define static_assert _Static_assert ^ xlat/pollflags.h:75:1: note: in expansion of macro ‘static_assert’ static_assert((POLLWRBAND) == (0x0100), "POLLWRBAND != 0x0100"); ^~~~~~~~~~~~~ ./static_assert.h:40:24: error: static assertion failed: "POLLREMOVE != 0x0800" # define static_assert _Static_assert ^ xlat/pollflags.h:117:1: note: in expansion of macro ‘static_assert’ static_assert((POLLREMOVE) == (0x0800), "POLLREMOVE != 0x0800"); ^~~~~~~~~~~~~ Signed-off-by: Max Filippov <>
2018-12-14several patches for uclibc
I've got several patches to fix ltp/openmp/uclibc-ng-test testcase fail on c-sky. - fix a ltp testcase. - fix the problem that pthread creat will fail when libomp is linked before libc, the variable pagesize is not init. - fix tst-cancel4 and tst-cancel16. tst-cancelx4 and tst-cancelx16 still fail with this patch applied, cleanup handler is not called for open/creat/fcntl, seems some thing wrong with unwind, I haven't check the rootcause yet.
2018-11-27statfs.h: sync generic header with glibcWaldemar Brodkorb
Fix issues with aarch64 and df with mismatching header between kernel and libc.
2018-11-23Defined INLINE_SYSCALL_NOERR_NCS in mips/bits/syscalls.hVolodymyr Boyko
On Linux/MIPS (O32 ABI) for system call we have two result registers - v0 and a3. v0 contains actual syscall result on success or error number on fail, a3 set to 0/1 for indicating syscall success/fail. (if a3 == 1, v0 contains errno). Now as we can see from definition of handle_sys (arch/mips/kernel/scall32-o32.S), handler treats returned by syscall function (let's call "original") values in range [-EMAXERRNO; 0[ as -errno, a3 is set to 1 and final returned (to userspace) value is (-original). INLINE_SYSCALL_NOERR_NCS defined in mips/bits/syscalls.h will handle this behaviour. Signed-off-by: Volodymyr Boyko <>
2018-11-01Add support for Thumb-only processors.Christophe Lyon
* ldso/ldso/arm/aeabi_read_tp.S: Add Thumb version. * ldso/ldso/arm/dl-startup.h: Do not force ARM encoding, adjust for Thumb. * ldso/ldso/arm/resolve.S: Force Thumb encoding on Thumb-only processors. * libc/sysdeps/linux/arm/crt1.S: Do not force ARM encoding, adjust for Thumb. Signed-off-by: Mickaël Guêné <> Signed-off-by: Christophe Lyon <>
2018-11-01time.h: Add CLOCK_TAIPetr Vorel
Added in kernel in kernel 3.10 in 1ff3c9677bff ("timekeeping: Add CLOCK_TAI clockid") NOTE: CLOCK_SGI_CYCLE was not added, as it has been lately removed. Signed-off-by: Petr Vorel <>
2018-10-20do not expose recvmmsg/sendmmsg for unsupported kernelsWaldemar Brodkorb
2018-09-21bugfix renameat2 wrong implement.Guo Ren
Signed-off-by: Guo Ren <>
2018-08-16sched_setaffinity: use the same style with glibc'sGuo Ren
Call getpid() in INTERNAL_SYSCALL will break the argument regs, because gcc couldn't save destoryed regs for system call asm. Ref to glibc, we could just remove all the check code. Signed-off-by: Guo Ren <>
2018-08-10arm/clone.S: Fix threading supportChristophe Lyon
Change clone.S so that in FDPIC case we take into account the fact that we are given a function descriptor. * libc/sysdeps/linux/arm/clone.S (__clone): Support __FDPIC__. Signed-off-by: Mickaël Guêné <> Signed-off-by: Christophe Lyon <>
2018-08-10Add runtime support needed for C++ exceptionsChristophe Lyon
Implements __gnu_Unwind_Find_got(), which is called from libgcc while unwinding. * libc/sysdeps/linux/arm/Makefile.arch (CSRC): Add find._got.c. * libc/sysdeps/linux/arm/find_got.c: New file. Signed-off-by: Mickaël Guêné <> Signed-off-by: Christophe Lyon <>
2018-08-10Add application startup code for FDPICChristophe Lyon
* libc/sysdeps/linux/arm/crt1.S: Define _start for __FDPIC__. Signed-off-by: Mickaël Guêné <> Signed-off-by: Christophe Lyon <>
2018-08-10rtld: Add FDPIC code for armChristophe Lyon
Add FDPIC dynamic relocations support, similar to what other FDPIC targets do. Lazy binding is implemented in a folllow-up patch. Disable the SEND* macros because they involve relocations to access constant strings that are unsupported by the existing arm version. Define DL_START, START, ARCH_NEEDS_BOOTSTRAP_RELOCS, DL_CHECK_LIB_TYPE similarly to what other FDPIC targets do. Define raise() because _dl_find_hash references __aeabi_uidivmod, which uses __aeabi_idiv0 which in turn references raise. * include/elf.h (R_ARM_FUNCDESC): Define. (R_ARM_FUNCDESC_VALUE): Define. * ldso/include/dl-string.h (SEND_STDERR, SEND_ADDRESS_STDERR) (SEND_NUMBER_STDERR): Define empty for __FDPIC__. * ldso/ldso/arm/dl-inlines.h: New file. * ldso/ldso/arm/dl-startup.h (PERFORM_BOOTSTRAP_RELOC): Fix type of load_addr. Fix handling of R_ARM_RELATIVE, add support for R_ARM_FUNCDESC_VALUE. (DL_START, START): Define for __FDPIC__. (raise): Define. * ldso/ldso/arm/dl-sysdep.h (ARCH_NEEDS_BOOTSTRAP_RELOCS): Define. (DL_CHECK_LIB_TYPE): Define. (elf_machine_type_class): Take into account FDPIC related relocations. (elf_machine_load_address): Support __FDPIC__. (elf_machine_relative): Likewise. * ldso/ldso/arm/elfinterp.c (_dl_linux_resolver): Dummy support for __FDPIC__, implemented in a later patch. (_dl_do_reloc): Fix reloc_adr computation for __FDPIC__, fix handling of local symbols. Fix handling of R_ARM_RELATIVE, add support for R_ARM_FUNCDESC_VALUE, R_ARM_FUNCDESC. * ldso/ldso/arm/resolve.S: Make _dl_linux_resolve hidden. * ldso/ldso/fdpic/dl-inlines.h (htab_delete): Declare. * libc/sysdeps/linux/arm/bits/elf-fdpic.h: New file, similar to bfin's. * libc/sysdeps/linux/arm/crtreloc.c: Likewise. * libc/sysdeps/linux/arm/find_exidx.c (__dl_addr_in_loadaddr) Define. (find_exidx_callback): Support __FDPIC__. Signed-off-by: Mickaël Guêné <> Signed-off-by: Christophe Lyon <>
2018-06-10risc-v: initial 64 bit port, static only (no TLS/NPTL)Waldemar Brodkorb
Only a simple hello world is tested in qemu system emulation.