Commit Graph

1584 Commits

Author SHA1 Message Date
Florian Weimer
186cd80b1e Add missing symbols to Version files
Some symbols have explicit versioned_symbol or compat_symbol markers
in the sources, but no corresponding entry in the Versions files.
This presently works because the local: * directive is only applied
to the base version.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-06-02 07:32:19 +02:00
Stefan Liebler
2457175e8b Fix stringop-overflow warning in bug-regex19.c.
Starting with commit
26492c0a14
"Annotate additional APIs with GCC attribute access.",
gcc emits this warning on s390x:
In function 'do_one_test',
    inlined from 'do_mb_tests' at bug-regex19.c:385:11:
bug-regex19.c:271:9: error: 're_search' specified size 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
  271 |   res = re_search (&regbuf, test->string, strlen (test->string),
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272 |      test->start, strlen (test->string) - test->start, NULL);
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/regex.h:2,
                 from bug-regex19.c:22:
bug-regex19.c: In function 'do_mb_tests':
../posix/regex.h:554:17: note: in a call to function 're_search' declared with attribute 'read_only (2, 3)'
  554 | extern regoff_t re_search (struct re_pattern_buffer *__buffer,
      |                 ^~~~~~~~~
...

The function do_one_test is inlined into do_mb_tests on s390x (at least with
gcc 10).  If do_one_test is marked with __attribute__ ((noinline)), there are
no warnings on s390x. If do_one_test is marked with
__attribute__ ((always_inline)), there are the same warnings on x86_64.

test->string points to a variable length array on stack of do_mb_tests
and the content is generated based on the passed test struct.

According to Martin Sebor, this is a false positive caused by the same bug as
the one in nss/makedb.c.  It's fixed in GCC 11 and will also be available in
the next GCC 10.4 release.
2021-05-18 10:07:30 +02:00
Adhemerval Zanella
903bc7dcc2 linux: Use sched_getaffinity for __get_nprocs (BZ #27645)
Both the sysfs and procfs parsing (through GET_NPROCS_PARSER) are
removed in favor the syscall.  The initial scratch buffer should
fit to most of the common usage (1024 bytes with maps to 8192 CPUs).

Checked on x86_64-linux-gnu and aarch64-linux-gnu.
2021-05-07 13:54:09 -03:00
Adhemerval Zanella
db373e4c57 Remove architecture specific sched_cpucount optimizations
And replace the generic algorithm with the Brian Kernighan's one.
GCC optimize it with popcnt if the architecture supports, so there
is no need to add the extra POPCNT define to enable it.

This is really a micro-optimization that only adds complexity:
recent ABIs already support it (x86-64-v2 or power64le) and it
simplifies the code for internal usage, since i686 does not allow an
internal iFUNC call.

Checked on x86_64-linux-gnu, aarch64-linux-gnu, and
powerpc64le-linux-gnu.
2021-05-07 13:35:29 -03:00
Martin Sebor
26492c0a14 Annotate additional APIs with GCC attribute access.
This change continues the improvements to compile-time out of bounds
checking by decorating more APIs with either attribute access, or by
explicitly providing the array bound in APIs such as tmpnam() that
expect arrays of some minimum size as arguments.  (The latter feature
is new in GCC 11.)

The only effects of the attribute and/or the array bound is to check
and diagnose calls to the functions that fail to provide a sufficient
number of elements, and the definitions of the functions that access
elements outside the specified bounds.  (There is no interplay with
_FORTIFY_SOURCE here yet.)

Tested with GCC 7 through 11 on x86_64-linux.
2021-05-06 11:01:05 -06:00
Florian Weimer
0b7d48d106 nptl: Move sem_close, sem_open into libc
The symbols were moved using move-symbol-to-libc.py.

Both functions are moved at the same time because they depend
on internal functions in sysdeps/pthread/sem_routines.c, which
are moved in this commit as well.  Additional hidden prototypes
are required to avoid check-localplt failures.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-05 17:19:38 +02:00
Florian Weimer
2c71177309 posix: Fix Hurd build failure in tst-execveat
This avoids a -Werror compilation failure due to unused local
variables.
2021-05-04 16:03:07 +02:00
Alexandra Hájková
19d83270fc linux: Add execveat system call wrapper
It operates similar to execve and it is is already used to implement
fexecve without requiring /proc to be mounted.  However, different
than fexecve, if the syscall is not supported by the kernel an error
is returned instead of trying a fallback.

Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-05-03 16:46:06 -03:00
Andreas Schwab
b59c698981 Fix argv overrun in getconf (bug 27761)
Correct argument counter accounting when processing the -v option with the
argument directly attached.
2021-04-21 15:11:26 +02:00
Adhemerval Zanella
48ec055ddc posix: Add wait3 tests
The tst-wait4 is moved to common file and used for wait3
tests.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2021-04-15 11:32:40 -03:00
Adhemerval Zanella
2b47727c68 posix: Consolidate register-atfork
Both htl and nptl uses a different data structure to implement atfork
handlers.  The nptl one was refactored by 27761a1042 to use a dynarray
which simplifies the code.

This patch moves the nptl one to be the generic implementation and
replace Hurd linked one.  Different than previous NPTL, Hurd also uses
a global lock, so performance should be similar.

Checked on x86_64-linux-gnu, i686-linux-gnu, and with a build for
i686-gnu.
2021-03-12 10:19:22 -03:00
Florian Weimer
63c317fe31 posix: tst-spawn4-compat can be a regular test
compat_symbol_reference now works for non-internal tests, too.
Also stop building and running the tests on those architectures
that lack the test symbol versions.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-03-09 21:07:24 +01:00
Florian Weimer
8209c5f1f4 posix: tst-glob_lstat_compat no longer needs to be an internal test
compat_symbol_reference is now available for regular tests as well.
Also avoid building and running the tests in case the pre-2.27
symbol version of glob is not available.  This avoids a spurious
UNSUPPORTED result.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-03-09 21:07:24 +01:00
Florian Weimer
3c66792667 posix: glob, glob64 should not be declared __THROW [BZ #27522]
These functions invoke callbacks with GLOB_ALTDIRFUNC, so they
are not leaf functions (as implied by _THROW).  Use __THROWNL
and __REDIRECT_NTHNL to express this.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-03-05 14:07:26 +01:00
Adhemerval Zanella
a79328c745 posix: Falling back to non wide mode in case of encoding error [BZ #14185]
Gnulib has added the proposed fix with aed23714d60 (done in 2005), but
recently with a glibc merge with 67306f6 (done in 2020 with sync back)
it has fallback to old semantic to return -1 on in case of failure.

From gnulib developer feedback it was an oversight.  Although the full
fix for BZ #14185 would require to rewrite fnmatch implementation to use
mbrtowc instead of mbsrtowcs on the full input, this mitigate the issue
and it has been used by gnulib for a long time.

This patch also removes the alloca usage on the string convertion to
wide characters before calling the internal function.

Checked on x86_64-linux-gnu.
2021-02-23 15:58:04 -03:00
Lukasz Majewski
2323a34260 tst: Provide test for sched_rr_get_interval
This change adds new test to assess sched_rr_get_interval's
functionality.

To be more specific - following use cases are checked:
- If the read interval is correct
- If the proper ABI is used - to check if adjacent data is not
  overwritten

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-02-16 20:35:37 +01:00
Adhemerval Zanella
36c604ed36 regex: stop using alloca
It syncs with gnulib version 87ed1f9c4.  No functional changes is
expected.

Checked on x86_64-linux-gnu.
2021-02-09 16:58:16 -03:00
Adhemerval Zanella
f3e5c7262e regexec: remove alloca usage in build_trtable
It syncs with gnulib version 1731fef3d.  On build_trtable prevent
inlining, so that it doesn't bloat the caller's stack and use auto
variables instead of alloca/malloc.

After these changes, build_trtable's total stack allocation is
only 20 KiB on a 64-bit machine, and this is less than glibc's 64
KiB cutoff so there's little point to using alloca to shrink it.

Checked on x86_64-linux-gnu.
2021-02-09 16:57:56 -03:00
Adhemerval Zanella
f0908ba118 regex: remove alloca usage on regex set_regs
It syncs with gnulib version b6207ab38.  It replaces the regmatch_t
with a dynarray list.

Checked on x86_64-linux-gnu.
2021-02-09 16:57:55 -03:00
Florian Weimer
e9fed2438a linux: Require /dev/shm as the shared memory file system
Previously, glibc would pick an arbitrary tmpfs file system from
/proc/mounts if /dev/shm was not available.  This could lead to
an unsuitable file system being picked for the backing storage for
shm_open, sem_open, and related functions.

This patch introduces a new function, __shm_get_name, which builds
the file name under the appropriate (now hard-coded) directory.  It is
called from the various shm_* and sem_* function.  Unlike the
SHM_GET_NAME macro it replaces, the callers handle the return values
and errno updates.  shm-directory.c is moved directly into the posix
subdirectory because it can be implemented directly using POSIX
functionality.  It resides in libc because it is needed by both
librt and nptl/htl.

In the sem_open implementation, tmpfname is initialized directly
from a string constant.  This happens to remove one alloca call.

Checked on x86_64-linux-gnu.
2021-02-08 14:10:42 -03:00
Stafford Horne
a4efbf4475 posix/tst-rfc3484: Fix compile failure linking to local __stat64
After 04986243d1 ("Remove internal usage of extensible stat functions")
linking the __stat64 symbol in getaddrinfo for this test fails with the
below error:

    [...] or1k-smh-linux-gnu/bin/ld: [...]/posix/tst-rfc3484.o: in function `gaiconf_reload':
    [...]/sysdeps/posix/getaddrinfo.c:2136: undefined reference to `__stat64'
    collect2: error: ld returned 1 exit status

This is because __stat64 is a local symbol, the test includes the
getaddrinfo directly and fails to link against the local symbol.  Fix
this by setting up an alias to the global stat64 symbol name like is
done for other local symbol usage.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-02-03 16:12:13 -03:00
H.J. Lu
6c57d32048 sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305]
Add _SC_MINSIGSTKSZ for the minimum signal stack size derived from
AT_MINSIGSTKSZ, which is the minimum number of bytes of free stack
space required in order to gurantee successful, non-nested handling
of a single signal whose handler is an empty function, and _SC_SIGSTKSZ
which is the suggested minimum number of bytes of stack space required
for a signal stack.

If AT_MINSIGSTKSZ isn't available, sysconf (_SC_MINSIGSTKSZ) returns
MINSIGSTKSZ.  On Linux/x86 with XSAVE, the signal frame used by kernel
is composed of the following areas and laid out as:

 ------------------------------
 | alignment padding          |
 ------------------------------
 | xsave buffer               |
 ------------------------------
 | fsave header (32-bit only) |
 ------------------------------
 | siginfo + ucontext         |
 ------------------------------

Compute AT_MINSIGSTKSZ value as size of xsave buffer + size of fsave
header (32-bit only) + size of siginfo and ucontext + alignment padding.

If _SC_SIGSTKSZ_SOURCE or _GNU_SOURCE are defined, MINSIGSTKSZ and SIGSTKSZ
are redefined as

/* Default stack size for a signal handler: sysconf (SC_SIGSTKSZ).  */
 # undef SIGSTKSZ
 # define SIGSTKSZ sysconf (_SC_SIGSTKSZ)

/* Minimum stack size for a signal handler: SIGSTKSZ.  */
 # undef MINSIGSTKSZ
 # define MINSIGSTKSZ SIGSTKSZ

Compilation will fail if the source assumes constant MINSIGSTKSZ or
SIGSTKSZ.

The reason for not simply increasing the kernel's MINSIGSTKSZ #define
(apart from the fact that it is rarely used, due to glibc's shadowing
definitions) was that userspace binaries will have baked in the old
value of the constant and may be making assumptions about it.

For example, the type (char [MINSIGSTKSZ]) changes if this #define
changes.  This could be a problem if an newly built library tries to
memcpy() or dump such an object defined by and old binary.
Bounds-checking and the stack sizes passed to things like sigaltstack()
and makecontext() could similarly go wrong.
2021-02-01 11:00:52 -08:00
Adhemerval Zanella
d7ee6bd8c2 posix: Fix fnmatch.c on bootstrap
Only define FALLTHROUGH for _LIBC and do not check __clang_major__
value.

It partially syncs with gnulib 5c52f00c69f39fe.

Checked with build-many-glibcs.py for aarch64-linux-gnu.
2021-01-20 13:23:33 -03:00
Adhemerval Zanella
1006250ea2 posix: Fix regex_internal.h on bootstrap
Only define FALLTHROUGH for _LIBC and do not check __clang_major__
value.

It partially syncs with gnulib 5c52f00c69f39fe.

Checked with build-many-glibcs.py for aarch64-linux-gnu,
x86_64-linux-gnu, and s390x-linux-gnu.
2021-01-20 09:59:34 -03:00
Martin Sebor
2cd361b511 posix: Correct attribute access mode on readlinkat [BZ #27024]. 2021-01-10 13:45:39 -07:00
Adhemerval Zanella
252864544a posix: Sync fnmatch with gnulib
It sync with gnulib commit 43ee1a6bf.

Checked on x86_64-linux-gnu.
2021-01-04 09:02:39 -03:00
Adhemerval Zanella
9c774ad764 Sync flexmember.h with gnulib
It sync with gnulib commit 43ee1a6bf.
2021-01-04 08:42:25 -03:00
Adhemerval Zanella
4883360415 posix: Sync glob code with gnulib
It sync with gnulib commit 43ee1a6bf and fixes and use-after-free
bug (gnulib commit 717766da8926e36).

Checked on x86_64-linux-gnu.
2021-01-04 08:41:53 -03:00
Adhemerval Zanella
c2a150d089 posix: Sync regex code with gnulib
It sync with gnulib commit 43ee1a6bf.  The main change is 9682f18e9.
(which does not have a meaniful description).

Checked on x86_64-linux-gnu.
2021-01-04 08:38:52 -03:00
Paul Eggert
9fcdec7386 Update copyright dates not handled by scripts/update-copyrights.
I've updated copyright dates in glibc for 2021.  This is the patch for
the changes not generated by scripts/update-copyrights and subsequent
build / regeneration of generated files.  As well as the usual annual
updates, mainly dates in --version output (minus csu/version.c which
previously had to be handled manually but is now successfully updated
by update-copyrights), there is a small change to the copyright notice
in NEWS which should let NEWS get updated automatically next year.

Please remember to include 2021 in the dates for any new files added
in future (which means updating any existing uncommitted patches you
have that add new files to use the new copyright dates in them).
2021-01-02 12:17:34 -08:00
Paul Eggert
2b778ceb40 Update copyright dates with scripts/update-copyrights
I used these shell commands:

../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright
(cd ../glibc && git commit -am"[this commit message]")

and then ignored the output, which consisted lines saying "FOO: warning:
copyright statement not found" for each of 6694 files FOO.
I then removed trailing white space from benchtests/bench-pthread-locks.c
and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this
diagnostic from Savannah:
remote: *** pre-commit check failed ...
remote: *** error: lines with trailing whitespace found
remote: error: hook declined to update refs/heads/master
2021-01-02 12:17:34 -08:00
Siddhesh Poyarekar
f9de8bfe1a nonstring: Enable __FORTIFY_LEVEL=3
Use __builtin_dynamic_object_size in the remaining functions that
don't have compiler builtins as is the case for string functions.
2020-12-31 16:55:21 +05:30
DJ Delorie
f4f3b09111 nsswitch: use new internal API (callers)
Stitch new ABI and types throughout all NSS callers.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2020-12-04 17:16:32 -05:00
Stefan Liebler
aa7e05c304 Mark mtrace tests UNSUPPORTED if bug-ga2.mtrace or tst-leaks2.mtrace are missing
Starting with commit 29fddfc7df, the
tests posix/bug-ga2 and resolv/tst-leaks2 are test-container tests.

If test-container.c returns with EXIT_UNSUPPORTED, the tests with
mtrace() are not executed and the mtrace files do not exist.

Therefore the "mtrace-analysis-part" of those tests are marked
UNSUPPORTED if the mtrace files are missing.

Reported-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
2020-11-25 08:30:17 +01:00
Stefan Liebler
29fddfc7df Use libnss_files.so for tests posix/bug-ga2 and resolv/tst-leaks2 [BZ #26821]
The tests posix/bug-ga2-mem and resolv/mtrace-tst-leaks2 are failing on
fedora 33 as mtrace reports memory leaks.

The /etc/nsswitch.conf differs between
Fedora 32: hosts:      files dns myhostname
Fedora 33: hosts:      files resolve [!UNAVAIL=return] myhostname dns

Therefore /lib64/libnss_resolve.so.2 (from systemd) and the dependencies
libgcc_s.so.1 and libpthread.so.0 are loaded.

Usually all malloc'ed resources from getaddrinfo / gethostbyname are freed
and the libraries are dlclose'd in nss/nsswitch.c:libc_freeres_fn (free_mem).
Unfortunately, /lib64/libnss_resolve.so.2 is marked with DF_1_NODELETE.
As this library is not unmapped, you'll see "Memory not freed".

Therefore those tests are now only relying on libnss_files.so by making
them test-container tests and providing the required configuration files.

By moving the tests to tests-container, those are now running with
"make check".  Therefore the mtrace part of the tests are also moved
from "make xcheck" to "make check".

bug-ga2.c is now using test-driver.c in order to support WAIT_FOR_DEBUGGER
environment variable.
2020-11-23 10:51:24 +01:00
Adhemerval Zanella
01bd62517c Remove tls.h inclusion from internal errno.h
The tls.h inclusion is not really required and limits possible
definition on more arch specific headers.

This is a cleanup to allow inline functions on sysdep.h, more
specifically on i386 and ia64 which requires to access some tls
definitions its own.

No semantic changes expected, checked with a build against all
affected ABIs.
2020-11-13 12:59:19 -03:00
Andreas Schwab
8f8052c2aa Revert "Fix missing redirects in testsuite targets"
This reverts commit d5afb38503.  The log files are actually created by the
various shell scripts that drive the tests.
2020-10-08 10:09:30 +02:00
Andreas Schwab
a140ff9162 Fix handling of collating symbols in fnmatch (bug 26620)
The variable idx contains the index into the extra array, whereas wextra
points into the extra array at this index, containing the length of the
following collating sequence in the wide character representation.
2020-09-16 14:45:10 +02:00
Adhemerval Zanella
04986243d1 Remove internal usage of extensible stat functions
It replaces the internal usage of __{f,l}xstat{at}{64} with the
__{f,l}stat{at}{64}.  It should not change the generate code since
sys/stat.h explicit defines redirections to internal calls back to
xstat* symbols.

Checked with a build for all affected ABIs.  I also check on
x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
2020-09-11 14:35:32 -03:00
Paul Eggert
2cc478ed1b Copy regex_internal.h from Gnulib
Sync this file from Gnulib, thus incorporating the following
fix for a bug with regexps with 16 or more subexpressions:
* posix/regex_internal.h (struct re_backref_cache_entry):
Use bitset_word_t as the type of eps_reachable_subexps_map,
instead of unsigned short int.  This fixes a bug I introduced
to glibc in 2005-09-28T17:33:18Z!drepper@redhat.com (glibc commit
2c05d33f90, BZ #1302).
Remove unused member 'unused'.
2020-08-04 23:47:01 -07:00
Paul Eggert
70c609f303 Copy regex BITSET_WORD_BITS porting from Gnulib
* posix/regex.c (__STDC_WANT_IEC_60559_BFP_EXT__):
Define, for ULONG_WIDTH.  This syncs regex.c from Gnujlib.
* posix/regex_internal.h (ULONG_WIDTH):
Use a more-portable fallback, from Gnulib.
(BITSET_WORD_BITS): Now defined in terms of ULONG_WIDTH.
2020-08-04 23:39:20 -07:00
Paul Eggert
6aa1160d16 Sync regex.h from Gnulib
* posix/regex.h: Remove an ‘#ifndef _CRAY’ that hasn’t been needed
for years in Gnulib (and was needed only because of Gnulib).
2020-08-04 23:24:03 -07:00
Martin Sebor
978e8ac39f Suppress GCC 10 true positive warnings [BZ #25967]
Suppress or avoid warnings in tests that exercise failure modes by making
calls with invalid arguments.

Reviewed-by: DJ Delorie <dj@redhat.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Joseph Myers <joseph@codesourcery.com>
2020-05-11 11:38:02 -06:00
Martin Sebor
06febd8c67 improve out-of-bounds checking with GCC 10 attribute access [BZ #25219]
Adds the access attribute newly introduced in GCC 10 to the subset of
function declarations that are already covered by _FORTIFY_SOURCE and
that don't have corresponding GCC built-in equivalents.

Reviewed-by: DJ Delorie <dj@redhat.com>
2020-05-04 11:21:50 -06:00
Carlos O'Donell
70dfcd9b6c Fix typo in posix/tst-fnmatch.input (Bug 25790)
Reported-by: Michael Builov <mbuilov@gmail.com>
2020-04-15 22:31:40 -04:00
Alistair Francis
c4d4419433 posix: Add wait4 test case
Add a wait4 test case based on the waitid test case.
2020-04-14 09:16:54 -07:00
Adhemerval Zanella
b3b6a40ab9 posix: Refactor tst-waitid (BZ #14666)
The main changes are:

  - Adapt to libsupport.
  - Synchronize the signal handler using atomics.
  - Replace waitpid by waitid calls.
  - Use support_process_state_wait to wait for child state.
  - Add tests for P_PGID and P_ALL.
  - Use sigwaitinfo instead of global state set by the signal handler.

Checked on x86_64-linux-gnu and i686-linux-gnu.
2020-02-27 16:16:16 -03:00
Andreas Schwab
ddc650e9b3 Fix use-after-free in glob when expanding ~user (bug 25414)
The value of `end_name' points into the value of `dirname', thus don't
deallocate the latter before the last use of the former.
2020-02-20 10:48:26 +01:00
Florian Weimer
c1080713ad Add hidden prototypes for __sched_getparam, __sched_getscheduler
This will enable them to be used in libc.so without PLTs.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-20 08:57:01 +01:00
Lukasz Majewski
3fced064f2 y2038: Define __suseconds64_t type to be used with struct __timeval64
The __suseconds64_t type is supposed to be the 64 bit type across all
architectures.

It would be mostly used internally in the glibc - however, when passed to
Linux kernel (very unlikely), if necessary, it shall be converted to 32
bit type (i.e. __suseconds_t)

Build tests:
./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-07 17:55:07 +01:00