aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2022-12-12libio: Convert __vswprintf_internal to buffers (bug 27857)fw/vfprintf-2Florian Weimer6-89/+57
Always null-terminate the buffer and set E2BIG if the buffer is too small. This fixes bug 27857.
2022-12-12libio: Convert __obstack_vprintf_internal to buffers (bug 27124)Florian Weimer3-120/+58
This fixes bug 27124 because the problematic built-in vtable is gone.
2022-12-12libio: Convert __vdprintf_internal to buffersFlorian Weimer3-28/+49
The internal buffer size is set to 2048 bytes. This is less than the original BUFSIZ value used by buffered_vfprintf before the conversion, but it hopefully covers all cases where write boundaries matter.
2022-12-12libio: Convert __vasprintf_internal to buffersFlorian Weimer3-45/+104
The buffer resizing algorithm is slightly different. The initial buffer is on the stack, and small buffers are directly allocated on the heap using the exact required size. The overhead of the additional copy is compensated by the lowered setup cost for buffers compared to libio streams.
2022-12-12libio: Convert __vsprintf_internal to buffersFlorian Weimer3-52/+24
2022-12-12stdio-common: Add lock optimization to vfprintf and vfwprintfFlorian Weimer1-0/+8
After the rewrite and the implicit unbuffered streams handling, this is very straightforward to add.
2022-12-12stdio-common: Convert vfprintf and related functions to buffersFlorian Weimer16-1474/+943
vfprintf is entangled with vfwprintf (of course), __printf_fp, __printf_fphex, __vstrfmon_l_internal, and the strfrom family of functions. The latter use the internal snprintf functionality, so vsnprintf is converted as well. The simples conversion is __printf_fphex, followed by __vstrfmon_l_internal and __printf_fp, and finally __vfprintf_internal and __vfwprintf_internal. __vsnprintf_internal and strfrom* are mostly consuming the new interfaces, so they are comparatively simple. __printf_fp is a public symbol, so the FILE *-based interface had to preserved. The __printf_fp rewrite does not change the actual binary-to-decimal conversion algorithm, and digits are still not emitted directly to the target buffer. However, the staging buffer now uses bytes instead of wide characters, and one buffer copy is eliminated. The changes are at least performance-neutral in my testing. Floating point printing and snprintf improved measurably, so that this Lua script for i=1,5000000 do print(i, i * math.pi) end runs about 5% faster for me. To preserve fprintf performance for a simple "%d" format, this commit has some logic changes under LABEL (unsigned_number) to avoid additional function calls. There are certainly some very easy performance improvements here: binary, octal and hexadecimal formatting can easily avoid the temporary work buffer (the number of digits can be computed ahead-of-time using one of the __builtin_clz* built-ins). Decimal formatting can use a specialized version of _itoa_word for base 10. The existing (inconsistent) width handling between strfmon and printf is preserved here. __print_fp_buffer_1 would have to use __translated_number_width to achieve ISO conformance for printf. Test expectations in libio/tst-vtables-common.c are adjusted because the internal staging buffer merges all virtual function calls into one. In general, stack buffer usage is greatly reduced, particularly for unbuffered input streams. __printf_fp can still use a large buffer in binary128 mode for %g, though.
2022-12-12stdio-common: Add __translated_number_widthFlorian Weimer3-1/+55
This function will be used to compute the width of a number after i18n digit translation.
2022-12-12stdio-common: Add __printf_function_invokeFlorian Weimer5-0/+114
And __wprintf_function_invoke. These functions will be used to to call registered printf specifier callbacks on printf buffers after vfprintf and vfwprintf have been converted to buffers. The new implementation avoids alloca/variable length arrays.
2022-12-12stdio-common: Introduce buffers for implementing printfFlorian Weimer28-0/+1522
These buffers will eventually be used instead of FILE * objects to implement printf functions. The multibyte buffer is struct __printf_buffer, the wide buffer is struct __wprintf_buffer. To enable writing type-generic code, the header files printf_buffer-char.h and printf_buffer-wchar_t.h define the Xprintf macro differently, enabling Xprintf (buffer) to stand for __printf_buffer and __wprintf_buffer as appropriate. For common cases, macros like Xprintf_buffer are provided as a more syntactically convenient shortcut. Buffer-specific flush callbacks are implemented with a switch statement instead of a function pointer, to avoid hardening issues similar to those of libio vtables. struct __printf_buffer_as_file is needed to support custom printf specifiers because the public interface for that requires passing a FILE *, which is why there is a trapdoor back from these buffers to FILE * streams. Since the immediate user of these interfaces knows when processing has finished, there is no flush callback for the end of processing, only a flush callback for the intermediate buffer flush.
2022-12-12locale: Implement struct grouping_iteratorFlorian Weimer4-1/+461
The iterator allows grouping while scanning forward through the digits. This enables emitting digits as they are processed. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2022-12-09time: Use 64 bit time on tzfileAdhemerval Zanella Netto1-1/+1
The tzfile_mtime is already compared to 64 bit time_t stat call. Reviewed-by: DJ Delorie <dj@redhat.com>
2022-12-09nscd: Use 64 bit time_t on libc nscd routines (BZ# 29402)Adhemerval Zanella Netto2-2/+2
Although the nscd module is built with 64 bit time_t, the routines linked direct to libc.so need to use the internal symbols. Reviewed-by: DJ Delorie <dj@redhat.com>
2022-12-09nis: Build libnsl with 64 bit time_tAdhemerval Zanella Netto2-6/+6
And remove the usage of glibc reserved names. Reviewed-by: DJ Delorie <dj@redhat.com>
2022-12-08realloc: Return unchanged if request is within usable sizeSiddhesh Poyarekar2-0/+33
If there is enough space in the chunk to satisfy the new size, return the old pointer as is, thus avoiding any locks or reallocations. The only real place this has a benefit is in large chunks that tend to get satisfied with mmap, since there is a large enough spare size (up to a page) for it to matter. For allocations on heap, the extra size is typically barely a few bytes (up to 15) and it's unlikely that it would make much difference in performance. Also added a smoke test to ensure that the old pointer is returned unchanged if the new size to realloc is within usable size of the old pointer. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: DJ Delorie <dj@redhat.com>
2022-12-07Linux: Consolidate typesizes.hAdhemerval Zanella Netto9-0/+646
The generic (sysdeps/unix/sysv/linux/generic/bits/typesizes.h) and default (bits/typesizes.h) differs in two fields: bits/typesizes.h Linux generic __NLINK_T_TYPE __UWORD_TYPE __U32_TYPE __BLKSIZE_T_TYPE __SLONGWORD_TYPE __S32_TYPE Sinceit leads to different C++ mangling names, the default typesize.h is copied for the requires archtiectures and the generic is make the default Linux one. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Make generic fcntl.h the default oneAdhemerval Zanella Netto2-57/+54
It is currently used for csky, arc, nios2, and or1k. Newer 64 bit architecture, like riscv32 and loongarch, reimplement it to override F_GETLK64/F_SETLK64/F_SETLKW64. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: make generic xstatver.h the default oneAdhemerval Zanella Netto4-11/+37
And copy the current default one to required ABIs. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Remove generic sysdepAdhemerval Zanella Netto10-33/+21
The includes chain is added on each architecture sysdep.h and the __NR__llseek hack is moved to lseek.c and lseek64.c. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Assume and consolidate shutdown wire-up syscallAdhemerval Zanella Netto10-15/+8
And disable if kernel does not support it. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Assume and consolidate listen wire-up syscallAdhemerval Zanella Netto10-17/+6
And disable if kernel does not support it. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Assume and consolidate socketpair wire-up syscallAdhemerval Zanella Netto10-14/+5
And disable if kernel does not support it. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Assume and consolidate socket wire-up syscallAdhemerval Zanella Netto10-14/+5
And disable if kernel does not support it. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: Assume and consolidate bind wire-up syscallAdhemerval Zanella Netto10-14/+9
And disable if kernel does not support it. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate ____longjmp_chkAdhemerval Zanella Netto1-3/+3
Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate sendfile implementationAdhemerval Zanella Netto7-11/+49
This is similar to other LFS consolidation, where the non-LFS is only built if __OFF_T_MATCHES_OFF64_T is not defined and the LFS version is aliased to non-LFS name if __OFF_T_MATCHES_OFF64_T is defined. For non-LFS variant, use sendfile syscall if defined, otherwise use sendfile64 plus the offset overflow check (as generic implementation). Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate unlink implementationAdhemerval Zanella Netto1-2/+7
Use unlink syscall if defined, otherwise use unlinkat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate symlink implementationAdhemerval Zanella Netto1-2/+7
Use symlink syscall if defined, otherwise use symlinkat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate rmdir implementationAdhemerval Zanella Netto1-2/+7
Use rmdir syscall if defined, otherwise use unlinkat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate readlink implementationAdhemerval Zanella Netto1-2/+7
Use readlink syscall if defined, otherwise readlinkat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate mkdir implementationAdhemerval Zanella Netto1-7/+8
Use mkdir syscall if defined, otherwise use mkdirat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate link implementationAdhemerval Zanella Netto1-2/+7
Use link syscall if defined, otherwise use linkat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate lchown implementationAdhemerval Zanella Netto1-3/+8
Use lchown syscall if defined, otherwise use fchownat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate inotify_init implementationAdhemerval Zanella Netto1-2/+7
Use inotify_init syscall if defined, otherwise use inotify_init1. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Lninux: consolidate epoll_create implementationAdhemerval Zanella Netto1-2/+7
Use epoll_create syscall if defined, otherwise use epoll_create1. Reviewed-by: Florian Weimer <fweimer@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate dup2 implementationAdhemerval Zanella Netto1-2/+7
Use dup2 syscall if defined, otherwise use dup3. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate chown implementationAdhemerval Zanella Netto1-2/+7
Use chown syscall if defined, otherwise use fchownat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07Linux: consolidate chmod implementationAdhemerval Zanella Netto1-3/+7
Use chmod syscall if defined, otherwise use fchmodat. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-12-07linux: Consolidate dl-origin.cAdhemerval Zanella Netto2-88/+5
Use the generic implementation as the default, since the syscall is supported by all architectures. Also cleanup some headers and remove the INTERNAL_SYSCALL_ERROR_P usage (the INTERNAL_SYSCALL_CALL macro already returns an negative value if an error occurs).
2022-12-07linux: Use long int for syscall return valueXing Li1-1/+1
The linux syscall ABI returns long, so the generic syscall code for linux should use long for the return value. This fixes the truncation of the return value of the syscall function when that does not fit into an int. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2022-12-07LoongArch: Use medium cmodel build libc_nonshared.a.Chenghua Xu3-0/+38
This patch is used to fix address out-of-bounds error when building Chrome.
2022-12-06x86_64: State assembler is being tested on sysdeps/x86/configureAdhemerval Zanella2-3/+3
2022-12-06configure: Remove AS checkAdhemerval Zanella6-76/+3
The assembler is not issued directly, but rather always through CC wrapper. The binutils version check if done with LD instead. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-12-06configure: Remove check if ld is GNUAdhemerval Zanella3-127/+91
Assume linker has gnu argument input style. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-12-06configure: Remove check if as is GNUAdhemerval Zanella2-26/+0
It is not used in any place. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-12-06configure: Move locale tools earlyAdhemerval Zanella2-649/+649
When using --with-binutils, the configure might not use the specified linker or assembler while checking for expected support. Move the tools check early, before any compiler usage test. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-12-02hurd: Make getrandom cache the server portSergey Bugaev1-15/+102
Previously, getrandom would, each time it's called, traverse the file system to find /dev/urandom, fetch some random data from it, then throw away that port. This is quite slow, while calls to getrandom are genrally expected to be fast. Additionally, this means that getrandom can not work when /dev/urandom is unavailable, such as inside a chroot that lacks one. User programs expect calls to getrandom to work inside a chroot if they first call getrandom outside of the chroot. In particular, this is known to break the OpenSSH server, and in that case the issue is exacerbated by the API of arc4random, which prevents it from properly reporting errors, forcing glibc to abort on failure. This causes sshd to just die once it tries to generate a random number. Caching the random server port, in a manner similar to how socket server ports are cached, both improves the performance and works around the chroot issue. Tested on i686-gnu with the following program: pthread_barrier_t barrier; void *worker(void*) { pthread_barrier_wait(&barrier); uint32_t sum = 0; for (int i = 0; i < 10000; i++) { sum += arc4random(); } return (void *)(uintptr_t) sum; } int main() { pthread_t threads[THREAD_COUNT]; pthread_barrier_init(&barrier, NULL, THREAD_COUNT); for (int i = 0; i < THREAD_COUNT; i++) { pthread_create(&threads[i], NULL, worker, NULL); } for (int i = 0; i < THREAD_COUNT; i++) { void *retval; pthread_join(threads[i], &retval); printf("Thread %i: %lu\n", i, (unsigned long)(uintptr_t) retval); } In my totally unscientific benchmark, with this patch, this completes in about 7 seconds, whereas previously it took about 50 seconds. This program was also used to test that getrandom () doesn't explode if the random server dies, but instead reopens the /dev/urandom anew. I have also verified that with this patch, OpenSSH can once again accept connections properly. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20221202135558.23781-1-bugaevc@gmail.com>
2022-12-02powerpc64: Remove old strncmp optimizationRajalakshmi Srinivasaraghavan5-256/+2
This patch cleans up the power4 strncmp optimization for powerpc64 which is unlikely to be used anywhere. Tested on ppc64le with and without --disable-multi-arch flag. Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2022-12-02x86-64 strncpy: Properly handle the length parameter [BZ# 29839]H.J. Lu2-0/+8
On x32, the size_t parameter may be passed in the lower 32 bits of a 64-bit register with the non-zero upper 32 bits. The string/memory functions written in assembly can only use the lower 32 bits of a 64-bit register as length or must clear the upper 32 bits before using the full 64-bit register for length. This pach fixes strncpy for x32. Tested on x86-64 and x32. On x86-64, libc.so is the same with and without the fix. Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2022-12-02x86-64 strncat: Properly handle the length parameter [BZ# 24097]H.J. Lu5-1/+73
On x32, the size_t parameter may be passed in the lower 32 bits of a 64-bit register with the non-zero upper 32 bits. The string/memory functions written in assembly can only use the lower 32 bits of a 64-bit register as length or must clear the upper 32 bits before using the full 64-bit register for length. This pach fixes strncat for x32. Tested on x86-64 and x32. On x86-64, libc.so is the same with and without the fix. Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>