Commit Graph

42098 Commits

Author SHA1 Message Date
Flavio Cruz
da49165ea6 mig_strncpy: ensure destination string is null terminated
Message-ID: <xaqw66fuawxm5hzgjscfg2oyp6lxflm5tnbb7u253pw3gmdy4m@5z42mw2qz2l2>
2025-02-10 19:44:46 +01:00
gfleury
6bcd7bf100 htl: stop exporting __pthread_default_barrierattr.
since all symbol that use it are now in libc
Message-ID: <20250209200108.865599-9-gfleury@disroot.org>
2025-02-10 01:39:17 +01:00
gfleury
710bbc9659 htl: move pthread_barrier_wait into libc.
Message-ID: <20250209200108.865599-8-gfleury@disroot.org>
2025-02-10 01:39:17 +01:00
gfleury
2789003489 htl: move pthread_barrier_init into libc.
Message-ID: <20250209200108.865599-7-gfleury@disroot.org>
2025-02-10 01:39:17 +01:00
gfleury
735c9b73d6 htl: move pthread_barrier_destroy into libc.
Message-ID: <20250209200108.865599-6-gfleury@disroot.org>
2025-02-10 01:39:17 +01:00
gfleury
ccf19a68ab htl: move pthread_barrierattr_getpshared, pthread_barrierattr_setpshared into libc.
Message-ID: <20250209200108.865599-5-gfleury@disroot.org>
2025-02-10 01:39:17 +01:00
gfleury
ca2a95ee67 htl: move pthread_barrierattr_init into libc.
Message-ID: <20250209200108.865599-4-gfleury@disroot.org>
2025-02-10 01:18:56 +01:00
gfleury
40cbd3c361 htl: move pthread_barrierattr_destroy into libc.
Message-ID: <20250209200108.865599-3-gfleury@disroot.org>
2025-02-10 01:18:17 +01:00
gfleury
7d799d85e8 htl: move __pthread_default_barrierattr into libc.
Message-ID: <20250209200108.865599-2-gfleury@disroot.org>
2025-02-10 01:17:50 +01:00
DJ Delorie
bb6496b964 manual: Update signal descriptions
Based on auditing all the signals and source trees for Hurd and
Linux...

SIGSYS - This is not used for a bad system call (ENOSYS is used
for that).  This is used by SECCOMP and some cases where an invalid
sub-function was requested.

SIGSTKFLT - Note it used to be a coprocessor stack fault but is now
obsolete and available for general user use.

SIGLOST - Hurd only now; note that its original purpose as an NFS
lock lost signal is obsolete.

SIGPWR - Note this is for power lost *and* power restored, and is
more a user-mode signal than a kernel-generated signal.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-02-05 23:35:29 -05:00
Tulio Magno Quites Machado Filho
cdb0800022 libio: Replace __LP64__ with __WORDSIZE
__LP64__ is a GCC extension and shouldn't be used in an installed
header.

Fixes: 596a61cf6b (libio: Start to return errors when flushing fwrite's buffer [BZ #29459], 2025-01-28)
Reported-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Arjun Shankar <arjun@redhat.com>
2025-02-05 16:18:40 -03:00
Florian Weimer
3755ffb665 powerpc64le: Also avoid IFUNC for __mempcpy
Code used during early static startup in elf/dl-tls.c uses
__mempcpy.

Fixes commit cbd9fd2369 ("Consolidate
TLS block allocation for static binaries with ld.so").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2025-02-05 09:53:11 +01:00
Florian Weimer
68c9ef4419 elf: Build dl-tls.o with early startup symbol redirections
This is required when building for powerpc64le POWER8 with GCC 8
at least.

Fixes commit cbd9fd2369 ("Consolidate
TLS block allocation for static binaries with ld.so").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2025-02-05 09:52:16 +01:00
DJ Delorie
37a0933e1b manual: make @manpageurl more specific to each output
Tweak the @manpageurl macro to customize the output for
each of html, info, and pdf output.  HTML and PDF (at
least, these days) support clicking on the link title,
whereas info does not.  Add text to the intro section
explaining which man pages are normative and which
aren't.
2025-02-04 14:30:13 -05:00
Adhemerval Zanella
09e7f4d594 math: Fix tanf for some inputs (BZ 32630)
The logic was copied wrong from CORE-MATH.
2025-02-03 09:40:39 -03:00
Florian Weimer
fc058b46c7 elf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen
The _dl_find_object function uses a binary search and is faster if
there are many objects.
2025-02-02 20:10:09 +01:00
Florian Weimer
b05e78d473 elf: Add fast path to dlopen for fully-opened maps
If the map is already fully open (has matching flags and its
own scope allocated), it is not necessary to unprotected memory
during dlopen.
2025-02-02 20:10:09 +01:00
Florian Weimer
edc6842bbc elf: Determine the caller link map in _dl_open
No functional change expected.

This is in preparation of adding a fast path to dlopen in case
no link map changes are required.
2025-02-02 20:10:09 +01:00
Florian Weimer
d12cb8e452 elf: Merge __dl_libc_freemem into __rtld_libc_freeres
The functions serve very similar purposes.  The advantage of
__rtld_libc_freeres is that it is located within ld.so, so it is
more natural to poke at link map internals there.

This slightly regresses cleanup capabilities for statically linked
binaries.  If that becomes a problem, we should start calling
__rtld_libc_freeres from __libc_freeres (perhaps after renaming it).
2025-02-02 20:10:09 +01:00
Florian Weimer
749310c61b elf: Add l_soname accessor function for DT_SONAME values
It's not necessary to introduce temporaries because the compiler
is able to evaluate l_soname just once in constracts like:

  l_soname (l) != NULL && strcmp (l_soname (l), LIBC_SO) != 0
2025-02-02 20:10:09 +01:00
Florian Weimer
aa1bf89039 elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object
So that they can eventually be called separately from dlopen.
2025-02-02 20:10:08 +01:00
Sergey Bugaev
a7aad6e2b7 hurd: Use the new __proc_reauthenticate_complete protocol 2025-02-01 18:20:42 +01:00
Florian Weimer
96429bcc91 elf: Do not add a copy of _dl_find_object to libc.so
This reduces code size and dependencies on ld.so internals from
libc.so.

Fixes commit f4c142bb9f
("arm: Use _dl_find_object on __gnu_Unwind_Find_exidx (BZ 31405)").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2025-02-01 12:37:58 +01:00
gfleury
cf51d18b9d htl: move pthread_setcancelstate into libc.
sysdeps/pthread/sem_open.c: call pthread_setcancelstate directely
since forward declaration is gone on hurd too
Message-ID: <20250201080202.494671-1-gfleury@disroot.org>
2025-02-01 11:24:14 +01:00
Adhemerval Zanella
04588633cf math: Fix sinhf for some inputs (BZ 32627)
The logic was copied wrong from CORE-MATH.
2025-01-31 13:05:41 -03:00
Adhemerval Zanella
c79277a167 math: Fix log10p1f internal table value (BZ 32626)
It was copied wrong from CORE-MATH.
2025-01-31 13:05:41 -03:00
Tulio Magno Quites Machado Filho
1b29cb7b78 manual: Safety annotations for timespec_get and timespec_getres
Add preliminary annotations that are consistent with clock_gettime and
clock_getres.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-01-31 12:13:20 -03:00
Adhemerval Zanella
22a11aa1c3 sh: Fix tst-guard1 build
The tests uses ARCH_MIN_GUARD_SIZE and the sysdep.h include is not
required.
2025-01-31 09:34:36 -03:00
Arjun Shankar
47c4f4045c manual: Add links to POSIX Semaphores man-pages documentation
The POSIX Semaphores functions are currently undocumented in our info
pages.  This commit adds links to the man-pages documentation for all
the `sem_*' functions (except `sem_clockwait') so that they refer to
some useful documentation instead of just being stubs.  `sem_clockwait'
isn't documented by man-pages but thankfully already has a small useful
blurb in our own docs.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-01-30 15:18:45 +01:00
Arjun Shankar
a3a5634d9b manual: Consolidate POSIX Semaphores docs in Threads chapter
This commit moves the `sem_*' family of functions from the IPC chapter,
replacing them with a reference to their new location in the Threads
chapter.  `sem_clockwait' is also moved out of the Non-POSIX Extensions
subsection since it is now included in the standard since Issue 8:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_clockwait.html

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-01-30 15:18:45 +01:00
Petr Malat
4c43173eba ld.so: Decorate BSS mappings
Decorate BSS mappings with [anon: glibc: .bss <file>], for example
[anon: glibc: .bss /lib/libc.so.6]. The string ".bss" is already used
by bionic so use the same, but add the filename as well. If the name
would be longer than what the kernel allows, drop the directory part
of the path.

Refactor glibc.mem.decorate_maps check to a separate function and use
it to avoid assembling a name, which would not be used later.

Signed-off-by: Petr Malat <oss@malat.biz>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-01-30 10:16:37 -03:00
Adhemerval Zanella
a6fbe36b7f nptl: Add support for setup guard pages with MADV_GUARD_INSTALL
Linux 6.13 (662df3e5c3766) added a lightweight way to define guard areas
through madvise syscall.  Instead of PROT_NONE the guard region through
mprotect, userland can madvise the same area with a special flag, and
the kernel ensures that accessing the area will trigger a SIGSEGV (as for
PROT_NONE mapping).

The madvise way has the advantage of less kernel memory consumption for
the process page-table (one less VMA per guard area), and slightly less
contention on kernel (also due to the fewer VMA areas being tracked).

The pthread_create allocates a new thread stack in two ways: if a guard
area is set (the default) it allocates the memory range required using
PROT_NONE and then mprotect the usable stack area. Otherwise, if a
guard page is not set it allocates the region with the required flags.

For the MADV_GUARD_INSTALL support, the stack area region is allocated
with required flags and then the guard region is installed.  If the
kernel does not support it, the usual way is used instead (and
MADV_GUARD_INSTALL is disabled for future stack creations).

The stack allocation strategy is recorded on the pthread struct, and it
is used in case the guard region needs to be resized.  To avoid needing
an extra field, the 'user_stack' is repurposed and renamed to 'stack_mode'.

This patch also adds a proper test for the pthread guard.

I checked on x86_64, aarch64, powerpc64le, and hppa with kernel 6.13.0-rc7.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-30 10:16:37 -03:00
John David Anglin
8e86549d14 nptl: Correct stack size attribute when stack grows up [BZ #32574]
Set stack size attribute to the size of the mmap'd region only
when the size of the remaining stack space is less than the size
of the mmap'd region.

This was reversed.  As a result, the initial stack size was only
135168 bytes.  On architectures where the stack grows down, the
initial stack size is approximately 8384512 bytes with the default
rlimit settings.  The small main stack size on hppa broke
applications like ruby that check for stack overflows.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
2025-01-29 16:51:16 -05:00
Florian Weimer
32ac9f8049 manual: Update compatibility note on flushing of line-oriented files
Operation systems which represent text files in a line-oriented
fashion (and not as byte streams with a character sequence reserved
for line termination) logically cannot flush a buffer without
also creating a terminated line.

Update this portability note and move it to the Binary Streams
section.  Add another related compatibility concern, too.
2025-01-29 13:16:50 +01:00
gfleury
9a31eb64db htl: move pthread_setcanceltype into libc.
Message-ID: <20250103103750.870897-7-gfleury@disroot.org>
2025-01-29 02:32:36 +01:00
gfleury
265c5991af htl: move pthread_mutex_consistent, pthread_mutex_consistent_np into libc.
Message-ID: <20250103103750.870897-6-gfleury@disroot.org>
2025-01-29 02:32:36 +01:00
gfleury
8bfabe7a92 htl: move pthread_mutex_destroy into libc.
Message-ID: <20250103103750.870897-5-gfleury@disroot.org>
2025-01-29 02:32:36 +01:00
gfleury
be9f0e7681 htl: move pthread_mutex_getprioceiling, pthread_mutex_setprioceiling into libc
Message-ID: <20250103103750.870897-4-gfleury@disroot.org>
2025-01-29 02:32:36 +01:00
gfleury
2ebc2d8e24 htl: move pthread_mutex_{lock, unlock, trylock, timedlock, clocklock}
I haven't exposed _pthread_mutex_lock,  _pthread_mutex_trylock and
_pthread_mutex_unlock in GLIBC_PRIVATE since there aren't used in any
code in libpthread
Message-ID: <20250103103750.870897-3-gfleury@disroot.org>
2025-01-29 02:32:36 +01:00
gfleury
e892a93073 htl: move pthread_mutex_init into libc.
Message-ID: <20250103103750.870897-2-gfleury@disroot.org>
2025-01-29 02:32:36 +01:00
gfleury
56b25bfd60 htl: remove leftover for pthread_mutexattr_settype
from b386295727
2025-01-29 02:32:36 +01:00
Joseph Myers
203452a460 Add test of input file flushing / offset issues
Having fixed several bugs relating to flushing of FILE* streams (with
fflush and other operations) and their offsets (both the file position
indicator in the FILE*, and the offset in the underlying open file
description), especially after ungetc but not limited to that case,
add a test that more systematically covers different combinations of
cases for such issues, with 57220 separate scenarios tested (which
include examples of all the five separate fixed bugs), all of which
pass given the five previous bug fixes.

Tested for x86_64.
2025-01-28 23:39:12 +00:00
Joseph Myers
3ff3b9997c Fix fflush handling for mmap files after ungetc (bug 32535)
As discussed in bug 32535, fflush fails on files opened for reading
using mmap after ungetc.  Fix the logic to handle this case and still
compute the file offset correctly.

Tested for x86_64.
2025-01-28 23:20:08 +00:00
Joseph Myers
0dcc0b2f63 Fix fseek handling for mmap files after ungetc or fflush (bug 32529)
As discussed in bug 32529, fseek fails on files opened for reading
using mmap after ungetc.  The implementation of fseek for such files
has an offset computation that's also incorrect after fflush.  A
combined fix addresses both problems (with tests for both included as
well) and it seems reasonable to consider them a single bug.

Tested for x86_64.
2025-01-28 22:35:21 +00:00
Joseph Myers
94251ae99e Make fflush (NULL) flush input files (bug 32369)
As discussed in bug 32369 and required by POSIX, the POSIX feature
fflush (NULL) should flush input files, not just output files.  The
POSIX requirement is that "fflush() shall perform this flushing action
on all streams for which the behavior is defined above", and the
definition for input files is for "a stream open for reading with an
underlying file description, if the file is not already at EOF, and
the file is one capable of seeking".

Implement this requirement in glibc.  (The underlying flushing
implementation is what deals with avoiding errors for seeking on an
unseekable file.)

Tested for x86_64.
2025-01-28 21:53:49 +00:00
Joseph Myers
be6818be31 Make fclose seek input file to right offset (bug 12724)
As discussed in bug 12724 and required by POSIX, before an input file
(based on an underlying seekable file descriptor) is closed, fclose is
sometimes required to seek that file descriptor to the correct offset,
so that any other file descriptors sharing the underlying open file
description are left at that offset (as a motivating example, a script
could call a sequence of commands each of which processes some data
from (seekable) stdin using stdio; fclose needs to do this so that
each successive command can read exactly the data not handled by
previous commands), but glibc fails to do this.

The precise POSIX wording has changed a few times; in the 2024 edition
it's "If the file is not already at EOF, and the file is one capable
of seeking, the file offset of the underlying open file description
shall be set to the file position of the stream if the stream is the
active handle to the underlying file description.".

Add appropriate logic to _IO_new_file_close_it to handle this case.  I
haven't made any attempt to test or change things in this area for the
"old" functions.

Note that there was a previous attempt to fix bug 12724, reverted in
commit eb6cbd249f.  The fix version here
addresses the original test in that bug report without breaking the
one given in a subsequent comment in that bug report (which works with
glibc before the patch, but maybe was broken by the original fix that
was reverted).

The logic here tries to take care not to seek the file, even to its
newly computed current offset, if at EOF / possibly not the active
handle; even seeking to the current offset would be problematic
because of a potential race (fclose computes the current offset,
another thread or process with the active handle does its own seek,
fclose does a seek (not permitted by POSIX in this case) that loses
the effect of the seek on the active handle in another thread or
process).  There are tests included for various cases of being or not
being the active handle, though there aren't tests for the potential
race condition.

Tested for x86_64.
2025-01-28 20:22:56 +00:00
Joseph Myers
377e9733b5 Fix fflush after ungetc on input file (bug 5994)
As discussed in bug 5994 (plus duplicates), POSIX requires fflush
after ungetc to discard pushed-back characters but preserve the file
position indicator.  For this purpose, each ungetc decrements the file
position indicator by 1; it is unspecified after ungetc at the start
of the file, and after ungetwc, so no special handling is needed for
either of those cases.

This is fixed with appropriate logic in _IO_new_file_sync.  I haven't
made any attempt to test or change things in this area for the "old"
functions; the case of files using mmap is addressed in a subsequent
patch (and there seem to be no problems in this area with files opened
with fmemopen).

Tested for x86_64.
2025-01-28 19:38:27 +00:00
Tulio Magno Quites Machado Filho
1515f74fd8 libio: Add a new fwrite test that evaluates partial writes
Test if the file-position is correctly updated when fwrite tries to
flush its internal cache but is not able to completely write all items.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-28 15:37:44 -03:00
Tulio Magno Quites Machado Filho
596a61cf6b libio: Start to return errors when flushing fwrite's buffer [BZ #29459]
When an error happens, fwrite is expected to return a value that is less
than nmemb.  If this error happens while flushing its internal buffer,
fwrite is in a complex scenario: all the data might have been written to
the buffer, indicating a successful copy, but the buffer is expected to
be flushed and it was not.

POSIX.1-2024 states the following about errors on fwrite:

    If an error occurs, the resulting value of the file-position indicator
    for the stream is unspecified.

    The fwrite() function shall return the number of elements successfully
    written, which may be less than nitems if a write error is encountered.

With that in mind, this commit modifies _IO_new_file_write in order to
return the total number of bytes written via the file pointer.  It also
modifies fwrite in order to use the new information and return the
correct number of bytes written even when sputn returns EOF.

Add 2 tests:

1. tst-fwrite-bz29459: This test is based on the reproducer attached to
   bug 29459.  In order to work, it requires to pipe stdout to another
   process making it hard to reuse test-driver.c.  This code is more
   specific to the issue reported.
2. tst-fwrite-pipe: Recreates the issue by creating a pipe that is shared
   with a child process.  Reuses test-driver.c.  Evaluates a more generic
   scenario.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-28 15:37:44 -03:00
Martin Coufal
45c42b65c2 Add new tests for fopen
Adding some basic tests for fopen, testing different modes, stream
positioning and concurrent read/write operation on files.
Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-28 12:50:50 -05:00