path: root/libc
AgeCommit message (Collapse)Author
2016-09-26use a single libc and deduplicate threading codeWaldemar Brodkorb
Similar to musl libc a single libc has many benefits and solves some open issues with uClibc-ng. - no pthread_mutex_* weak symbols exported anymore - applications no longer failing to link when either -lrt or -lpthread are missing for dynamic and static linking mode - smaller C library - slightly better runtime performance
2016-09-26always assume tgkill is presentWaldemar Brodkorb
We do not support 2.4 Linux kernels anyway, and almost all newer 2.6 kernels should have tgkill syscall. Cleanup the raise situation, pt-raise.c is unused, sync raise.c with latest GNU libc. Signed-off-by: Waldemar Brodkorb <>
2016-09-21microblaze: fixup headers to make gdb compile happyWaldemar Brodkorb
Add some definitions and fix some types to make gdb compile happy.
2016-09-19elf-{fdpic, dsbt}.h: avoid void pointer's subtractionRahul Bedarkar
elf-fdpic.h or elf-dsbt.h is included by link.h. When C++ program includes <link.h>, we get following build failure. ../usr/include/bits/elf-fdpic.h: In function 'void* __reloc_pointer(void*, const elf32_fdpic_loadmap*)': ../usr/include/bits/elf-fdpic.h:95: error: invalid use of 'void' void pointer addition and subtraction is not allowed in C++ as it has undetermined size, however in C with language extension it is possible because sizeof void is treated as one byte. Instead of performing subtraction on void pointers, typecast it to char* first. This build failure is detected by Buildroot autobuilder. Signed-off-by: Rahul Bedarkar <>
2016-08-27remove DOMULTI supportWaldemar Brodkorb
A single test with targeting ARM showed that this feature seems bit rotted. Remove DOMULTI and simplify Makefiles.
2016-08-17ARC: Support syscall ABI v4Vineet Gupta
The syscall ABI includes the gcc functional calling ABI since a syscall implies userland caller and kernel callee. The current gcc ABI (v3) for ARCv2 ISA required 64-bit data be passed in even-odd register pairs, (potentially punching reg holes when passing such values as args). This was partly driven by the fact that the double-word LDD/STD instructions in ARCv2 expect the register alignment and thus gcc forcing this avoids extra MOV at the cost of a few unused register (which we have plenty anyways). This however was rejected as part of upstreaming gcc port to HS. So the new ABI v4 doesn't enforce the even-odd reg restriction. Do note that for ARCompact ISA builds v3 and v4 are practically the same in terms of gcc code generation. This change is dormant for now (gcc 4.8.x based tools) and will only kick in with switch to gcc 6.x based tools. Signed-off-by: Vineet Gupta <>
2016-08-08arm: fix compile in thumb modeWaldemar Brodkorb
Fix a regression introduced by commit 0550ecce0e6580c5ad34e9a9a39ff18ccf8774f9 Reported by Buildroot developers. Embedded test must be extented to ARMv7 thumb2 builds to find such regressions next time. It wasn't triggered by a cortex-m4 ARM noMMU build.
2016-08-05sunrpc: Do not use alloca in clntudp_callWaldemar Brodkorb
CVE-2016-4429: The call is technically in a loop, and under certain circumstances (which are quite difficult to reproduce in a test case), alloca can be invoked repeatedly during a single call to clntudp_call. As a result, the available stack space can be exhausted (even though individual alloca sizes are bounded implicitly by what can fit into a UDP packet, as a side effect of the earlier successful send operation). From GNU libc:;a=commit;h=bc779a1a5b3035133024b21e2f339fe4219fb11c
2016-08-01arc: crt1: Fix to PIECupertino Miranda
crt1.S needed to use a got relative reference. Libraries like pthreads define a _init and unless it is GOT, the linker will fail because it will try to create a dynamic reloc on .text section, more precisely on __start. Signed-off-by: Cupertino Miranda <> Signed-off-by: Alexey Brodkin <> Cc: Vlad Zakharov <> Cc: Vineet Gupta <>
2016-07-31include missing Linux extension headers for poll.hWaldemar Brodkorb
This was found by Buildroot autobuilders for m68k.
2016-07-31arc: clone: Simplify CLONE_THREAD detectionAlexey Brodkin
This change was inspired by similar change in glibc:;a=commit;h=0cb313f7cb0e418b3d56f3a2ac69790522ab825d Current Linux kernel requires CLONE_VM to be set with CLONE_THREAD otherwise returning -EINVAL, see man clone2. This means we don't need to check for both CLONE_THREAD and CLONE_VM instead we may simplify code a lot and just check 1 bit (CLONE_THREAD). Signed-off-by: Alexey Brodkin <> Acked-by: Vineet Gupta <>
2016-07-31arc: clone: Fix CLONE_THREAD detectionAlexey Brodkin
For thread group case (CLONE_THREAD), the cached PID of new process/thread need not be reset. The old logic to decide that was flawed as it would be true only for exact combination of CLONE_THREAD + _VM, but would fail for CLONE_THREAD + _VM + _xyz. More detailed tear-down of current and new code below. Current implementation is: --------------------->8-------------------- ; r12 contains clone flags mov_s r2, CLONE_THREAD_N_VM; r2 contains bit mask and_s r2, r2, r12 ; r2 contains bit mask AND clone flags ; but r12 still contains the same flags brne r2, r12, .Lgo_thread ; here we compare modified mask with ; flags as they were and skip pthread TID/PID ; setup if r2 != r12 which happens all ; the time except clone flags were ; exactly CLONE_THREAD | CLONE_VM --------------------->8-------------------- New implementation is: --------------------->8-------------------- ; r12 contains clone flags mov_s r2, CLONE_THREAD_N_VM; r2 contains bit mask and_s r12, r12, r2 ; r12 contains clone flags AND bit mask ; i.e. we did mask all flags except ; CLONE_THREAD and CLONE_VM breq r2, r12, .Lgo_thread ; here we compare masked flags with ; target mask and if they match we skip ; pthread TID/PID setup --------------------->8-------------------- Signed-off-by: Alexey Brodkin <> Acked-by: Vineet Gupta <>
2016-07-31arc: clone: Recover PID correctlyAlexey Brodkin
Caught by tst-getpid1 test from uClibc's test-suite. It looks like original implementation was not correct. The code in question is supposed to recover PID of the new thread. And by no means that could happen with clone() syscall while getpid() does exactly this. Signed-off-by: Alexey Brodkin <> Acked-by: Vineet Gupta <> Reported-by: Eugeniy Paltsev <>
2016-07-31remove unused code, RTLD_PRIVATE_ERRNO is never definedWaldemar Brodkorb
2016-07-31deduplicate jmpbuf-unwind.hWaldemar Brodkorb
Reviewed-by: Max Filippov <>
2016-07-17cleanup CALL_MCOUNT / PROFWaldemar Brodkorb
As this is only implemented for a few architecture and not well tested, just remove it.
2016-07-17x86_64: remove dead code, SHARED is not defined when compilingWaldemar Brodkorb
2016-07-17cleanup PTR_MANGLE/PTR_DEMANGLE supportWaldemar Brodkorb
As this is only implemented for a few architecture and not well tested, just remove it. Reviewed-by: Max Filippov <>
2016-07-17mips: add regdef.h glibc compatibility headerWaldemar Brodkorb
2016-07-03arm: cleanup redundant macros for syscallsWaldemar Brodkorb
In uClibc-ng the syscall macros are in bits/syscalls.h.
2016-06-30nds32: add support for new architectureWaldemar Brodkorb
Add support for Andes Technology NDS32 architecture. See here for more informaton. Verification of the port from an older uClibc port was done on a sponsored AG101p board. The testsuite only has 5 errors, three are related to an existing bug in dlclose() with LT.old, also happening on cris32 and m68k. Failures to fallocate/posix_fallocate are unresolved. Thanks to Andes Technology sponsoring the hardware and being very helpful while doing the uClibc-ng porting. Signed-off-by: Waldemar Brodkorb <>
2016-06-24bits/sigset.h: Fix _EXTERN_INLINE redefinitionLeonid Lisovskiy
Commit 251a3c19cb "sleep: employ __USE_EXTERN_INLINES (with necessary fixes)" introduces following problems: 1. __USE_EXTERN_INLINES forcibly enabled build fails ... LD libc/libc_so.a(cmsg_nxthdr.os): In function `__GI___cmsg_nxthdr': cmsg_nxthdr.c:(.text.__GI___cmsg_nxthdr+0x0): multiple definition of `__GI___cmsg_nxthdr' libc/libc_so.a(close.os):close.c:(.text.__GI___cmsg_nxthdr+0x0): first defined here libc/libc_so.a(creat.os): In function `__GI___cmsg_nxthdr': creat.c:(.text.__GI___cmsg_nxthdr+0x0): multiple definition of `__GI___cmsg_nxthdr' libc/libc_so.a(close.os):close.c:(.text.__GI___cmsg_nxthdr+0x0): first defined here ... 2. libuargp wrongly contains __cmsg_nxthdr/__sigismember/__sigdelset/__sigaddset global symbols on platforms which includes signal.h from sys/procfs.h As result, static linking will fail: TEST_LINK argp/ bug-argp1 /home/wbx/ppc-static/target_qemu-ppc-macppc_uclibc-ng_hard/usr/lib/libc.a(sigsetops.os): In function `__GI___sigismember': sigsetops.c:(.text+0x0): multiple definition of `__sigismember' /home/wbx/ppc-static/target_qemu-ppc-macppc_uclibc-ng_hard/usr/lib/libuargp.a(argp-xinl.os):argp-xinl.c:(.text+0x0): first defined here /home/wbx/ppc-static/target_qemu-ppc-macppc_uclibc-ng_hard/usr/lib/libc.a(sigsetops.os): In function `__GI___sigaddset': sigsetops.c:(.text+0x28): multiple definition of `__sigaddset' /home/wbx/ppc-static/target_qemu-ppc-macppc_uclibc-ng_hard/usr/lib/libuargp.a(argp-xinl.os):argp-xinl.c:(.text+0x28): first defined here /home/wbx/ppc-static/target_qemu-ppc-macppc_uclibc-ng_hard/usr/lib/libc.a(sigsetops.os): In function `__GI___sigdelset': sigsetops.c:(.text+0x4c): multiple definition of `__sigdelset' /home/wbx/ppc-static/target_qemu-ppc-macppc_uclibc-ng_hard/usr/lib/libuargp.a(argp-xinl.os):argp-xinl.c:(.text+0x4c): first defined here We have to partially revert 251a3c19cb to fix problems above. It is safe to do this after commit 162cfaea20 *: inline constant __sig{add,del}set and __sigismember since we are able to use new inlines from within libc and leave the rest of world(__USE_EXTERN_INLINES) equal to glibc now. Signed-off-by: Leonid Lisovskiy <>
2016-06-24inet/resolv: Try search domains first for unqualified namesIngo van Lil
When resolving an unqualified host name, the resolver tries the original name first before appending the domains from the search list. If a TLD with the same name exists, the query will succeed (but yield no A record) and the resolver will return HOST_NOT_FOUND without trying the search domains. This patch changes the lookup order for unqualified host names (without dots) to try the search domains first and the original name last. Signed-off-by: Ingo van Lil <>
2016-06-23ARC: Enable shared crt1Vineet Gupta
Currently crt1 takes address of functions (main,_init,_fini) directly which doesn't generate truely position independent code, but zero based values instead. e.g. | __start: | ... | add_s r2,sp,0x4 | mov_s r0, main generates to | 000156ec <__start>: | ... | 156f4: add_s r2,sp,0x4 | 156f6: mov_s r0,0x15f7c | ... | 00015f7c <main>: | 15f7c: push_s blink This works just fine for the normal (non PIE) dynamic executables since they are loaded at address 0. However this is not true for PIE executables. So for Scrt1 we use a true position independent way when taking function addresses. Cc: <> Cc: <> Cc: Cupertino Miranda <> Signed-off-by: Vineet Gupta <>
2016-06-23libs: install backward compatibility symlinksAlexey Brodkin
Simplify the switch from uClibc to uClibc-ng. Apps already built against uClibc-0.9.x.y require .so.0 libs to present on target which in case of current uClibc-ng is not the case and those apps could not be run. This change creates symlinks from .so.1 to .so.0 for most of other libs in the same way as it was done by 23e96d89b6ab "ldso: install backward compatibility symlink by default" Signed-off-by: Alexey Brodkin <> Cc: Waldemar Brodkorb <> Cc: Vineet Gupta <> Cc: Anton Kolesov <>
2016-06-23ARC: Implement .note.ABI-tag section in crt1.SAnton Kolesov
Linux Standard Base specifies section .note.ABI-tag that can be considered as a marker for ELF files targeted to Linux systems. See This section, for example, is used by the GDB to identify Linux ELFs as compared to baremetal ELFs that do not have this section. Signed-off-by: Anton Kolesov <> Cc: Vineet Gupta <>
2016-06-21inet/getaddrinfo: fix AF_V4MAPPED behavior for non IPv6 host resolutionWenzel, Alexander
When trying to resolve a hostname by getaddrinfo() using some specific settings, it will always return -EAI_NONAME (Name or service not known). To reproduce this behavior, you need to request an IPv6 address with the additional AF_V4MAPPED flag set from an non IPv6 capable hostname. If you choose a IPv4/IPv6 capable hostname like, everything works fine. This patch is more or less a port [1][2] from the glibc and their behavior for the AF_V4MAPPED flag. To test the bug you can use the following snippet. ---- 8< ---- int ret; struct addrinfo* result; struct addrinfo hints; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET6; hints.ai_flags = AI_V4MAPPED; ret = getaddrinfo("", NULL, &hints, &result); printf("getaddrinfo(): %i", ret); ---- 8< ---- [1];a=commit;f=sysdeps/posix/getaddrinfo.c;h=925c3c5c71596c02f7e58a0ffcdcaae44eb065c1 [2];a=commit;f=sysdeps/posix/getaddrinfo.c;h=28977c2c1acb789660ad47e0d88e42486059c916 Signed-off-by: Alexander Wenzel <>
2016-06-19bugfix: ARM: memset.S: use unsigned comparisonsLucian Cojocar
The 'BLT' instruction checks for *signed* values. So if a3, length parameter of memset, is negative, then value added to the PC will be large. memset(buf, 0xaa, 0xffff0000) triggers the bug. GDB session without the patch: """ $ gdb ./main-buggy-memset.elf -q Reading symbols from ./main-buggy-memset.elf...done. (gdb) x/i memset 0x8770 <memset>: mov r3, r0 (gdb) r Starting program: /root/memset/main-buggy-memset.elf Program received signal SIGSEGV, Segmentation fault. 0x00048808 in ?? () """ The $pc is outside of the memset function because: """ (gdb) x/i $pc => 0x87e4 <memset+116>: add pc, pc, r2, lsl #2 (gdb) info reg $r2 r2 0x10007 65543 """ GDB session with the bug fixed (patch applied): """ $ gdb ./main-fixed-memset.elf -q Reading symbols from ./main-fixed-memset.elf...done. (gdb) x/i memset 0x8770 <memset>: mov r3, r0 (gdb) r Starting program: /root/memset/main-fixed-memset.elf Program received signal SIGSEGV, Segmentation fault. memset () at libc/string/arm/memset.S:92 92 libc/string/arm/memset.S: No such file or directory. (gdb) x/i $pc => 0x87b0 <memset+64>: stmia r3!, {r1, r12} (gdb) info reg $r3 r3 0x15000 86016 (gdb) info proc mappings process 5822 Mapped address spaces: Start Addr End Addr Size Offset objfile 0x8000 0xb000 0x3000 0x0 /root/memset/main-fixed-memset.elf 0x12000 0x15000 0x3000 0x2000 /root/memset/main-fixed-memset.elf 0xb6fff000 0xb7000000 0x1000 0x0 [sigpage] 0xbefdf000 0xbf000000 0x21000 0x0 0xffff0000 0xffff1000 0x1000 0x0 [vectors] (gdb) info reg $sp sp 0x14d78 0x14d78 """ GDB crashes inside the memset function, on the store instruction. This time the crash is (as expected) because of a memory access imediately after the memory region that contains the stack -- the buffer that's being memset'd is allocated on the stack. Signed-off-by: Lucian Cojocar <>
2016-06-19or1k: add dummy sys/user.h for straceWaldemar Brodkorb
2016-06-15sysconf: Support _SC_(AV)?PHYS_PAGES.Nicolas Cavallari
Do it by following the trail of the existing commented code, which implemented it by calling get_phys_pages() and get_avphys_pages(). This patch implements these two functions, which are also glibc extensions. Some program/libraries (e.g. libuv) assumes that sysconf(_SC_PHYS_PAGES) works on linux and never check for -1, thus they report an insane amount of memory. Signed-off-by: Nicolas Cavallari <>
2016-06-12Fix return value of fwrite when a 'hard' error occursJan Vangorp
When a 'hard' error occurs, fwrite reports that all data was written or buffered even if that is not the case. It should report how much data was actually written and buffered. Signed-off-by: Jan Vangorp <>
2016-06-12Fix infinite loop when fopencookie custom write returns 0 on errorJan Vangorp
The man page for fopencookie prescribes that custom write functions should return 0 on error (and should definitely not return a negative value) [1]. However, the uClibc implementation expects a negative return value in case of an error (libc/stdio/_WRITE.c). If the write function returns 0 on error, we drop into an infinite loop if the error persists. This patch wraps the user supplied write function such that a 0 return value is converted to -1. errno is first set to EAGAIN such that if the custom write function does not set errno in case of error, this is treated as a "soft" error. Custom write functions that cater towards uClibc and _do_ return a negative value are not affected. If no custom write function is supplied, set errno to EINVAL such that this condition is treated as a "hard" error. Previously the behaviour depended on whether the last error before the write happened to be a "hard" or a "soft" error. [1] Signed-off-by: Jan Vangorp <>
2016-06-07ssp: remove SSP legacy codeWaldemar Brodkorb
Nobody should use gcc 3.3 nowadays.
2016-06-07microblaze: remove unused dead codeWaldemar Brodkorb
These files are not used, no regression found while running the testsuite.
2016-06-03ppc: cleanup unsupported ppc64 codeWaldemar Brodkorb
Remove ppc64 bits and bytes, as we don't support ppc64 and it makes the code more readable without the dead code.
2016-06-01remove MJN only debug messagesWaldemar Brodkorb
2016-05-29mips: allow to disable prefetch support in memcpy/memsetWaldemar Brodkorb
There exist some problem with the new memcpy/memset functions imported from GNU libc/newlib. If you have any problem with the new MIPS optimized assembly try to disable prefetching support. Thanks to Rene Nielsen and Matthew Fortune analyzing the problem so far.
2016-05-28sparc: remove unused 64 bit support codeWaldemar Brodkorb
2016-05-24microblaze: fix setjmp/longjmpWaldemar Brodkorb
Sync mostly with GNU libc implementation of setjmp/longjmp. Just generate PIC compatible code, so no difference for static builds are made. Add sysdep.h with some handy assembly macros used inside setjmp.S/__longjmp.S. This unbreaks dynamic linker support, first test suite run only shows 10 errors, which doesn't look so bad.
2016-05-18remove, rename linuxthreads.oldWaldemar Brodkorb isn't really useful with the existence of NPTL/TLS for well supported architectures. There is no reason to use for ARM/MIPS or other architectures supporting NPTL/TLS. It is not available for noMMU architectures like Blackfin or FR-V. To simplify the live of the few uClibc-ng developers, is removed and LT.old is renamed to LT. LINUXTHREADS_OLD -> UCLIBC_HAS_LINUXTHREADS
2016-04-26sparc: add deprecated context switching functionsWaldemar Brodkorb
Ported over from glibc mostly without changes. Lightly tested with mongrel2 in qemu-system-sparc.
2016-04-17remove unused defines for lm32/or1kWaldemar Brodkorb
2016-04-15replace FSF addresses with URLsNikola Forró
License notices in most of the source files refer to an outdated FSF address. Replace it with URL, like in the rest of the source files.Signed-off-by: Nikola Forró <>
2016-04-11simplify getpagesize, do not depend on kernel macrosWaldemar Brodkorb
Signed-off-by: Waldemar Brodkorb <>
2016-04-03Provide an alias to _obstack_freeAlexey Neyman
GDB 7.11 does not build if compiled against uclibc-ng (1.0.12 was used, but the problematic code exists in 1.0.13 as well). The reason is that GDB release includes its own obstack implementation, but elides the code if <gnu-versions.h> declares a compatible obstack implementation in libc. uclibc-ng does claim compatible obstack interface (GDB expects version 2, but accepts version 1 if sizeof(int) == sizeof(size_t)), however, uclibc-ng does not provide the _obstack_free symbol that is a part of the interface (glibc does provide this symbol). This later causes a link failure. The attached patch makes uclibc-ng enables an alias _obstack_free -> obstack_free. Signed-off-by: Alexey Neyman <>
2016-03-31bits/byteswap-common.h: import recent headers from glibcAnthony G. Basile
On systems where uClibc doesn't provide an arch specific byteswap.h, we fall back on bits/byteswap-common.h. However, there is a bug in this header in the __bswap_constant_64(x) macro. If, for example, a double is passed, we get 'invalid operands to binary &' in which we mismatch a 'double' and 'long long unsigned int'. The newer glibc headers fix this and so we import them. Also, since the inclusion of byteswap.h is not appropriate for assembly code, we guard a portion of endian.h which uses byteswap.h from inclusion in any assembly. This is needed, for example, for f2fs-tools 1.6.0 on 32-bit big endian PowerPC. Signed-off-by: Anthony G. Basile <>
2016-03-31arm: simplify handling of Thumb related optionsThomas Petazzoni
Currently, the Thumb support on ARM has three related options, which are not trivial for users to understand, and are in fact not needed: - The USE_BX option is not needed: knowing whether BX is available or not is easy. If you have an ARM > v4 or ARMv4T, then BX is available, otherwise it's not. This is the logic used in glibc. - The USE_LDREXSTREX option is not needed: whenever Thumb2 is available, ldrex/strex are available, so we can simply rely on __thumb2__ to determine whether ldrex/strex should be used, without requiring a option. - Once USE_BX and USE_LDREXSTREX are removed, the only thing left that COMPILE_IN_THUMB does is to set -mthumb. This makes the option unnecessary, as on ARM at least, the user is already supposed to pass -march=<foo> or other compiler options tuning the library for a specific ARM variant. There is no reason to do otherwise for Thumb, which allows to get rid of the COMPILE_IN_THUMB option. Signed-off-by: Thomas Petazzoni <>
2016-03-31xtensa: fix __sigsetjmp call12 caseMax Filippov
Register window saving loop in __sigsetjmp incorrectly calculates offset in the jmp_buf in case it was called with call12. The bug was introduced in commit f4b1b7ade7971141 "xtensa: fix setjmp that didn't save all registers correctly". Signed-off-by: Max Filippov <>
2016-03-10getaddrinfo: correct AI_V4MAPPED handlingPeter Korsgaard
As recently reported on the Buildroot list: DNS lookups with Node.js currently fails on uClibc-ng. The reason for this is the way AI_V4MAPPED is handled. According to POSIX, AI_V4MAPPED should be ignored unless ai_family is AF_INET6: If the AI_V4MAPPED flag is specified along with an ai_family of AF_INET6, then getaddrinfo() shall return IPv4-mapped IPv6 addresses on finding no matching IPv6 addresses (ai_addrlen shall be 16). The AI_V4MAPPED flag shall be ignored unless ai_family equals AF_INET6. uClibc-ng was also handling AI_V4MAPPED for AF_UNSPEC, fix that. Signed-off-by: Peter Korsgaard <>
2016-03-10DNS: Don't apply search domains to PTR lookupsTim Hockin
This lessens the load on upstream DNS servers (and it was just nonsensical). Signed-off-by: Tim Hockin <>