]> sourceware.org Git - glibc.git/log
glibc.git
3 years agoresolv: Move __res_get_nsaddr to its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move __res_get_nsaddr to its own file and into libc

Eliminate the use of the EXT macro from it because it does not
add clarity.  The function was added to res_send.c in 2015, and
the copyright year reflects that.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Rename res_comp.c to res-name-checking.c and move into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Rename res_comp.c to res-name-checking.c and move into libc

This reflects what the remaining functions in the file do.

The __res_dnok, __res_hnok, __res_mailok, __res_ownok were moved
with the script, using --no-new-version, and turned into compat
symbols.  __libc_res_dnok@@GLIBC_PRIVATE and
__libc_res_hnok@@GLIBC_PRIVATE are added for internal use, to avoid
accidentally binding to compatibility symbols.  The new public
symbols res_dnok, res_hnok, res_mailok, res_ownok were added using
make update-all-abi.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move dn_skipname to its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move dn_skipname to its own file and into libc

And reformat it to GNU style.

dn_skipname is used outside glibc, so do not deprecate it,
and export it as dn_skipname (not __dn_skipname).  Due to internal
users, provide a __libc_dn_skipname alias, and keep __dn_skipname
as a pure compatibility symbol.

__dn_skipname@GLIBC_2.0 was moved using the script, and
dn_skipname@@GLIBC_2.34 was added using make update-all-abi.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move dn_comp to its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move dn_comp to its own file and into libc

And reformat it to GNU style.

dn_comp is used in various programs, so keep it as a non-deprecated
symbol.  Switch to dn_comp (not __dn_comp) for the ABI name.  There
are no internal users, so interposition is not a problem.

The __dn_comp symbol was moved with scripts/move-symbol-to-libc.py
--no-new-version.  dn_comp@@GLIBC_2.34 was added with
make update-all-abi.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move _getlong, _getshort, __putlong, __putshort to res-putget
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move _getlong, _getshort, __putlong, __putshort to res-putget

And reformat to GNU style.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move dn_expand to its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move dn_expand to its own file and into libc

And reformat to GNU style.

This switches back to the dn_expand name for the ABI symbol and turns
__dn_expand into a compatibility symbol.  With the improved namespace
management in current glibc, it is no longer necessary to use a
private namespace symbol.  To avoid old code binding to a
GLIBC_PRIVATE symbol by accident, use __libc_dn_expand for the
internal symbol name.

The symbols dn_expand, __dnexpand were moved using
scripts/move-symbol-to-libc.py, followed by an adjustment to make
dn_expand the only GLIBC_2.34 symbol.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move ns_name_compress into its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move ns_name_compress into its own file and into libc

And reformat to GNU style.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move ns_name_pack into its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move ns_name_pack into its own file and into libc

And reformat to GNU style, and eliminate the labellen function.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move ns_name_pton into its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move ns_name_pton into its own file and into libc

And reformat to GNU style, and eliminate the digits variable.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move ns_name_uncompress into its own file and into libc
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move ns_name_uncompress into its own file and into libc

And reformat to GNU style.  Check for negative error returns
(instead of -1).

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move ns_name_skip to its own file and into libc (bug 28091)
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Move ns_name_skip to its own file and into libc (bug 28091)

And reformat to GNU style.  Avoid out-of-bounds pointer arithmetic.
This also results in a fix of bug 28091 due to the additional packet
length checks.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@systemhalted.org>
3 years agoresolv: Deprecate legacy interfaces in libresolv
Florian Weimer [Mon, 19 Jul 2021 05:55:27 +0000 (07:55 +0200)]
resolv: Deprecate legacy interfaces in libresolv

Debugging interfaces: p_*, fp_*, and sym_* could conceivably be
used to produce debug out, but these functions have not been
updated to parse more resource records, so they are not very useful
today.  Likewise for ns_sprintrr and ns_sprintrrf.  ns_format_ttl and
ns_parse_ttl are related to these.

Internal implementation details: res_isourserver is probably only
useful in the implementation of a stub resolver, and so is
res_nameinquery.

Unclear semantics and bad performance: ns_samedomain, ns_subdomain,
ns_makecanon, ns_samename do textual converions & copies instead of
checking equivalence of the wire format.

inet_neta cannot handle IPv6 addresses.

res_hostalias has been superseded by getaddrinfo with AI_CANONNAME.
hostalias is not thread-safe.

Some functions have int as size arguments instead of size_t, so they
do not follow current coding practices.  However, dn_expand and
b64_ntop are somewhat widely used (to name just two examples), so
deprecating them seems problematic.

Reviewed-by: Carlos O'Donell <carlos@systemhalted.org>
3 years agotst-safe-linking: make false positives even more improbable
Siddhesh Poyarekar [Mon, 19 Jul 2021 02:59:25 +0000 (08:29 +0530)]
tst-safe-linking: make false positives even more improbable

There is a 1 in 16 chance of a corruption escaping safe-linking and to
guard against spurious failures, tst-safe-linking runs each subtest 10
times to ensure that the chance is reduced to 1 in 2^40.  However, in
the 1 in 16 chance that a corruption does escape safe linking, it
could well be caught by other sanity checks we do in malloc, which
then results in spurious test failures like below:

test test_fastbin_consolidate failed with a different error
  expected: malloc_consolidate(): unaligned fastbin chunk detected

  actual:   malloc_consolidate(): invalid chunk size

This failure is seen more frequently on i686; I was able to reproduce
it in about 5 min of running it in a loop.

Guard against such failures by recording them and retrying the test.
Also, do not fail the test if we happened to get defeated by the 1 in
2^40 odds if in at least one of the instances it was detected by other
checks.

Finally, bolster the odds to 2^64 by running 16 times instead of 10.
The test still has a chance of failure so it is still flaky in theory.
However in practice if we see a failure here then it's more likely
that there's a bug than it being an issue with the test.  Add more
printfs and also dump them to stdout so that in the event the test
actually fails, we will have some data to try and understand why it
may have failed.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agohtl: Do not expose pthread hidden proto outside libpthread
Samuel Thibault [Sun, 18 Jul 2021 20:25:33 +0000 (20:25 +0000)]
htl: Do not expose pthread hidden proto outside libpthread

Only libpthread.so can access them.

3 years agoelf: Fix a wrong array access on tst-tls20
Adhemerval Zanella [Fri, 16 Jul 2021 11:32:05 +0000 (08:32 -0300)]
elf: Fix a wrong array access on tst-tls20

Check on x86_64-linux-gnu with --enable-stack-protector=all.

3 years agoelf: Add -Wl,--no-as-needed for tst-tls-manydynamic*mod-dep-bad.so (BZ #28089)
Adhemerval Zanella [Thu, 15 Jul 2021 11:18:21 +0000 (08:18 -0300)]
elf: Add -Wl,--no-as-needed for tst-tls-manydynamic*mod-dep-bad.so (BZ #28089)

The tests explicit requires the dependencies and it is required for
the case the toolchain defaults to -Wl,--as-needed.

Checked on x86_64-linux-gnu.

3 years agoresolv: Move ns_name_unpack to its own file and into libc
Florian Weimer [Thu, 15 Jul 2021 06:28:50 +0000 (08:28 +0200)]
resolv: Move ns_name_unpack to its own file and into libc

Reformat to GNU style. Avoid out-of-bounds buffer arithmetic.
Eliminate the labellen function.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Remove unnecessary res_isourserver_p call from send_dg
Florian Weimer [Thu, 15 Jul 2021 06:28:51 +0000 (08:28 +0200)]
resolv: Remove unnecessary res_isourserver_p call from send_dg

As the comment indicates, the check is unnecessary due to the way the
UDP socket is set up.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Move ns_name_ntop to its own file and into libc
Florian Weimer [Thu, 15 Jul 2021 06:28:50 +0000 (08:28 +0200)]
resolv: Move ns_name_ntop to its own file and into libc

Reformat to GNU style.  Avoid out-of-bounds pointer arithmetic
(e.g., use eom - dn < 2 instead of dn + 1 >= eom).  Inline the
labellen function and fold the compression pointer check into
the length check (l >= 64).  Assume ASCII encoding.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agonss_dns: Do not use deprecated packet parsing functions
Florian Weimer [Thu, 15 Jul 2021 06:28:50 +0000 (08:28 +0200)]
nss_dns: Do not use deprecated packet parsing functions

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoresolv: Sort Makefile routines and Versions lexicographically
Florian Weimer [Thu, 15 Jul 2021 06:28:50 +0000 (08:28 +0200)]
resolv: Sort Makefile routines and Versions lexicographically

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agosocket: Add hidden prototype for setsockopt
Florian Weimer [Thu, 15 Jul 2021 06:28:50 +0000 (08:28 +0200)]
socket: Add hidden prototype for setsockopt

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
3 years agoelf: Fix DTV gap reuse logic (BZ #27135)
Adhemerval Zanella [Fri, 25 Jun 2021 13:54:12 +0000 (10:54 -0300)]
elf: Fix DTV gap reuse logic (BZ #27135)

This is updated version of the 572bd547d57a (reverted by 40ebfd016ad2)
that fixes the _dl_next_tls_modid issues.

This issue with 572bd547d57a patch is the DTV entry will be only
update on dl_open_worker() with the update_tls_slotinfo() call after
all dependencies are being processed by _dl_map_object_deps().  However
_dl_map_object_deps() itself might call _dl_next_tls_modid(), and since
the _dl_tls_dtv_slotinfo_list::map is not yet set the entry will be
wrongly reused.

This patch fixes by renaming the _dl_next_tls_modid() function to
_dl_assign_tls_modid() and by passing the link_map so it can set
the slotinfo value so a subsequente _dl_next_tls_modid() call will
see the entry as allocated.

The intermediary value is cleared up on remove_slotinfo() for the case
a library fails to load with RTLD_NOW.

This patch fixes BZ #27135.

Checked on x86_64-linux-gnu.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
3 years agoFix linknamespace errors and local-plt-usages in nss_files.
Stefan Liebler [Wed, 14 Jul 2021 13:58:08 +0000 (15:58 +0200)]
Fix linknamespace errors and local-plt-usages in nss_files.

After commit f9c8b11ed7726b858cd7b7cea0d3d7c5233d78cf
"nss: Access nss_files through direct references",
when building with -Os, multiple conform/.../linknamespace tests
and elf/check-localplt are failing:
Extra PLT reference: libc.so: fgetc_unlocked
Extra PLT reference: libc.so: getline

Or e.g.:
[initial] glob -> [libc.a(glob.o)] __getpwnam_r -> [libc.a(getpwnam_r.o)] __nss_database_custom -> [libc.a(nsswitch.o)] __nss_module_get_function -> [libc.a(nss_module.o)] __nss_files_functions -> [libc.a(nss_files_functions.o)] _nss_files_endaliasent -> [libc.a(files-alias.o)] feof_unlocked
[initial] glob -> [libc.a(glob.o)] __getpwnam_r -> [libc.a(getpwnam_r.o)] __nss_database_custom -> [libc.a(nsswitch.o)] __nss_module_get_function -> [libc.a(nss_module.o)] __nss_files_functions -> [libc.a(nss_files_functions.o)] _nss_files_endaliasent -> [libc.a(files-alias.o)] fgetc_unlocked
[initial] glob -> [libc.a(glob.o)] __getpwnam_r -> [libc.a(getpwnam_r.o)] __nss_database_custom -> [libc.a(nsswitch.o)] __nss_module_get_function -> [libc.a(nss_module.o)] __nss_files_functions -> [libc.a(nss_files_functions.o)] _nss_files_endnetgrent -> [libc.a(files-netgrp.o)] getline

This patch is using the hidden symbols where possible.
Instead of fputc_unlocked, __putc_unlocked is used.
(Compare to commit eeaa19f75e52d2d48074ae0c423f2311d67c42c6
"mntent: Use __putc_unlocked instead of fputc_unlocked")

3 years agoAdd static tests for __clone_internal
H.J. Lu [Fri, 14 May 2021 22:23:46 +0000 (15:23 -0700)]
Add static tests for __clone_internal

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agox86-64: Add the clone3 wrapper
H.J. Lu [Thu, 13 May 2021 15:24:36 +0000 (08:24 -0700)]
x86-64: Add the clone3 wrapper

extern int clone3 (struct clone_args *__cl_args, size_t __size,
   int (*__func) (void *__arg), void *__arg);

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoAdd an internal wrapper for clone, clone2 and clone3
H.J. Lu [Sat, 13 Feb 2021 19:47:46 +0000 (11:47 -0800)]
Add an internal wrapper for clone, clone2 and clone3

The clone3 system call (since Linux 5.3) provides a superset of the
functionality of clone and clone2.  It also provides a number of API
improvements, including the ability to specify the size of the child's
stack area which can be used by kernel to compute the shadow stack size
when allocating the shadow stack.  Add:

extern int __clone_internal (struct clone_args *__cl_args,
     int (*__func) (void *__arg), void *__arg);

to provide an abstract interface for clone, clone2 and clone3.

1. Simplify stack management for thread creation by passing both stack
base and size to create_thread.
2. Consolidate clone vs clone2 differences into a single file.
3. Call __clone3 if HAVE_CLONE3_WAPPER is defined.  If __clone3 returns
-1 with ENOSYS, fall back to clone or clone2.
4. Use only __clone_internal to clone a thread.  Since the stack size
argument for create_thread is now unconditional, always pass stack size
to create_thread.
5. Enable the public clone3 wrapper in the future after it has been
added to all targets.

NB: Sandbox will return ENOSYS on clone3 in both Chromium:

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src/+/218438259dd795456f0a48f67cbe5b4e520db88b

commit 218438259dd795456f0a48f67cbe5b4e520db88b
Author: Matthew Denton <mpdenton@chromium.org>
Date: Thu Jun 03 20:06:13 2021

Linux sandbox: return ENOSYS for clone3

Because clone3 uses a pointer argument rather than a flags argument, we
cannot examine the contents with seccomp, which is essential to
preventing sandboxed processes from starting other processes. So, we
won't be able to support clone3 in Chromium. This CL modifies the
BPF policy to return ENOSYS for clone3 so glibc always uses the fallback
to clone.

Bug: 1213452
Change-Id: I7c7c585a319e0264eac5b1ebee1a45be2d782303
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2936184
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#888980}

[modify] https://crrev.com/218438259dd795456f0a48f67cbe5b4e520db88b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc

and Firefox:

https://hg.mozilla.org/integration/autoland/rev/ecb4011a0c76

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonss: Fix build error with --disable-nscd
Cooper Qu [Tue, 13 Jul 2021 12:50:40 +0000 (20:50 +0800)]
nss: Fix build error with --disable-nscd

The error is as follows:
nss_module.c: In function 'module_load_nss_files':
nss_module.c:117:7: error: 'is_nscd' undeclared (first use in this function)
  117 |   if (is_nscd)
      |       ^~~~~~~
nss_module.c:117:7: note: each undeclared identifier is reported only once for each function it appears in
nss_module.c:119:51: error: 'nscd_init_cb' undeclared (first use in this function); did you mean 'nscd_init'?
  119 |       void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
      |                                                   ^~~~~~~~~~~~
      |                                                   nscd_init

3 years agohtl: Fix linking static examples against libpthread
Samuel Thibault [Tue, 13 Jul 2021 21:45:57 +0000 (21:45 +0000)]
htl: Fix linking static examples against libpthread

libpthread.a uses some mach and hurd RPCs so we need to link them in.

3 years agohtl: Let libc call __pthread_mutex_{,try,un}lock
Samuel Thibault [Tue, 13 Jul 2021 21:33:39 +0000 (21:33 +0000)]
htl: Let libc call __pthread_mutex_{,try,un}lock

Now that NPTL was moved to libc, libc makes internal __pthread calls, so
htl has to expose them internally.

3 years agoposix: Ignore non opened files on tst-spawn5
Adhemerval Zanella [Tue, 13 Jul 2021 13:46:23 +0000 (10:46 -0300)]
posix: Ignore non opened files on tst-spawn5

The make program  might open a pipe for its job server, which triggers
an invalid check on the spawned process.  This patch now passes the
lowest file descriptor as ithe first argument, so only the range
that was actually opened is checked.

Checked on x86_64-linux-gnu and i686-linux-gnu and centos7 (which
triggers the issue).

3 years agomcheck: Align struct hdr to MALLOC_ALIGNMENT bytes [BZ #28068]
H.J. Lu [Mon, 12 Jul 2021 21:36:39 +0000 (14:36 -0700)]
mcheck: Align struct hdr to MALLOC_ALIGNMENT bytes [BZ #28068]

1. Align struct hdr to MALLOC_ALIGNMENT bytes so that malloc hooks in
libmcheck align memory to MALLOC_ALIGNMENT bytes.
2. Remove tst-mallocalign1 from tests-exclude-mcheck for i386 and x32.
3. Add tst-pvalloc-fortify and tst-reallocarray to tests-exclude-mcheck
since they use malloc_usable_size (see BZ #22057).

This fixed BZ #28068.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
3 years agoLinux: Use 32-bit vDSO for clock_gettime, gettimeofday, time (BZ# 28071)
Adhemerval Zanella [Sat, 10 Jul 2021 20:03:49 +0000 (17:03 -0300)]
Linux: Use 32-bit vDSO for clock_gettime, gettimeofday, time (BZ# 28071)

The previous approach defeats the vDSO optimization on older kernels
because a failing clock_gettime64 system call is performed on every
function call.  It also results in a clobbered errno value, exposing
an OpenJDK bug (JDK-8270244).

This patch fixes by open-code INLINE_VSYSCALL macro and replace all
INLINE_SYSCALL_CALL with INTERNAL_SYSCALL_CALLS.  Now for
__clock_gettime64x, the 64-bit vDSO is used and the 32-bit vDSO is
tried before falling back to 64-bit syscalls.

The previous code preferred 64-bit syscall for the case where the kernel
provides 64-bit time_t syscalls *and* also a 32-bit vDSO (in this case
the *64-bit* syscall should be preferable over the vDSO).  All
architectures that provides 32-bit vDSO (i386, mips, powerpc, s390)
modulo sparc; but I am not sure if some kernels versions do provide
only 32-bit vDSO while still providing 64-bit time_t syscall.
Regardless, for such cases the 64-bit time_t syscall is used if the
vDSO returns overflowed 32-bit time_t.

Tested on i686-linux-gnu (with a time64 and non-time64 kernel),
x86_64-linux-gnu.  Built with build-many-glibcs.py.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
3 years agoReduce <limits.h> pollution due to dynamic PTHREAD_STACK_MIN
Florian Weimer [Mon, 12 Jul 2021 16:43:32 +0000 (18:43 +0200)]
Reduce <limits.h> pollution due to dynamic PTHREAD_STACK_MIN

<limits.h> used to be a header file with no declarations.
GCC's libgomp includes it in a #pragma GCC visibility hidden block.
Including <unistd.h> from <limits.h> (indirectly) declares everything
in <unistd.h> with hidden visibility, resulting in linker failures.

This commit avoids C declarations in assembler mode and only declares
__sysconf in <limits.h> (and not the entire contents of <unistd.h>).
The __sysconf symbol is already part of the ABI.  PTHREAD_STACK_MIN
is no longer defined for __USE_DYNAMIC_STACK_SIZE && __ASSEMBLER__
because there is no possible definition.

Additionally, PTHREAD_STACK_MIN is now defined by <pthread.h> for
__USE_MISC because this is what developers expect based on the macro
name.  It also helps to avoid libgomp linker failures in GCC because
libgomp includes <pthread.h> before its visibility hacks.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agoFix failing nss/tst-nss-files-hosts-long.
Stefan Liebler [Mon, 12 Jul 2021 09:00:53 +0000 (11:00 +0200)]
Fix failing nss/tst-nss-files-hosts-long.

Sometimes the test nss/tst-nss-files-hosts-long is failing as getent
fails with exit-code 2.

This happens if tst-reload1 was run just before this test:
make t=nss/tst-reload1 test
make t=nss/tst-nss-files-hosts-long test
Then the test fails as /etc/nsswitch.conf contains "hosts: test2"
and the hosts are not searched in /etc/hosts at all.

Thus this patch just requests a post cleanup after nss/tst-reload1
has run.

3 years agonis: nis_local_group may read from __nisgroup[-1] (bug 28075)
Florian Weimer [Mon, 12 Jul 2021 05:58:07 +0000 (07:58 +0200)]
nis: nis_local_group may read from __nisgroup[-1] (bug 28075)

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agohurd _Fork: Drop duplicate malloc_fork_lock calls
Samuel Thibault [Sun, 11 Jul 2021 17:51:12 +0000 (17:51 +0000)]
hurd _Fork: Drop duplicate malloc_fork_lock calls

This was put in __libc_fork by c32c868ab8b2 ("posix: Add _Fork [BZ #4737]")
so we need to avoid locking them again in _Fork called by __libc_lock, otherwise
we deadlock.

3 years agosupport: Replace _SC_MINSIGSTKSZ with _SC_SIGSTKSZ
H.J. Lu [Sat, 10 Jul 2021 17:56:50 +0000 (10:56 -0700)]
support: Replace _SC_MINSIGSTKSZ with _SC_SIGSTKSZ

Replace _SC_MINSIGSTKSZ with _SC_SIGSTKSZ since sysconf (_SC_MINSIGSTKSZ)
returns the minimum number of bytes of free stack space required in order
to guarantee successful, non-nested handling of a single signal whose
handler is an empty function while sysconf (_SC_SIGSTKSZ) returns the
suggested minimum number of bytes of stack space required for a signal
stack.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agosupport: Replace MINSIGSTKSZ with sysconf (_SC_MINSIGSTKSZ)
H.J. Lu [Fri, 9 Jul 2021 21:17:04 +0000 (14:17 -0700)]
support: Replace MINSIGSTKSZ with sysconf (_SC_MINSIGSTKSZ)

Replace MINSIGSTKSZ with sysconf (_SC_MINSIGSTKSZ) since the constant
MINSIGSTKSZ used in glibc build may be too small.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agoDefine PTHREAD_STACK_MIN to sysconf(_SC_THREAD_STACK_MIN)
H.J. Lu [Mon, 21 Jun 2021 19:42:56 +0000 (12:42 -0700)]
Define PTHREAD_STACK_MIN to sysconf(_SC_THREAD_STACK_MIN)

The constant PTHREAD_STACK_MIN may be too small for some processors.
Rename _SC_SIGSTKSZ_SOURCE to _DYNAMIC_STACK_SIZE_SOURCE.  When
_DYNAMIC_STACK_SIZE_SOURCE or _GNU_SOURCE are defined, define
PTHREAD_STACK_MIN to sysconf(_SC_THREAD_STACK_MIN) which is changed
to MIN (PTHREAD_STACK_MIN, sysconf(_SC_MINSIGSTKSZ)).

Consolidate <bits/local_lim.h> with <bits/pthread_stack_min.h> to
provide a constant target specific PTHREAD_STACK_MIN value.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agoForce building with -fno-common
Florian Weimer [Fri, 9 Jul 2021 18:09:14 +0000 (20:09 +0200)]
Force building with -fno-common

As a result, is not necessary to specify __attribute__ ((nocommon))
on individual definitions.

GCC 10 defaults to -fno-common on all architectures except ARC,
but this change is compatible with older GCC versions and ARC, too.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agoAdd a generic malloc test for MALLOC_ALIGNMENT
H.J. Lu [Fri, 9 Jul 2021 03:48:14 +0000 (20:48 -0700)]
Add a generic malloc test for MALLOC_ALIGNMENT

1. Add sysdeps/generic/malloc-size.h to define size related macros for
malloc.
2. Move x86_64/tst-mallocalign1.c to malloc and replace ALIGN_MASK with
MALLOC_ALIGN_MASK.
3. Add tst-mallocalign1 to tests-exclude-mcheck for i386 and x32 since
mcheck doesn't honor MALLOC_ALIGNMENT.

3 years agoProperly run tst-spawn5 directly [BZ #28067]
H.J. Lu [Fri, 9 Jul 2021 12:57:51 +0000 (05:57 -0700)]
Properly run tst-spawn5 directly [BZ #28067]

Change tst-spawn5.c to handle tst-spawn5 without optional path to ld.so,
--library-path nor the library path when glibc is configured with
--enable-hardcoded-path-in-tests.  This fixes BZ #28067.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agobuild-many-glibcs.py: Add glibcs-arm-linux-gnueabihf-thumb
Florian Weimer [Fri, 9 Jul 2021 08:59:22 +0000 (10:59 +0200)]
build-many-glibcs.py: Add glibcs-arm-linux-gnueabihf-thumb

Previously, there was no thumb variant, despite that building
glibc in Thumb-2 mode is supported.

3 years agonptl: Use out-of-line wake function in __libc_lock_unlock slow path
Florian Weimer [Fri, 9 Jul 2021 08:59:22 +0000 (10:59 +0200)]
nptl: Use out-of-line wake function in __libc_lock_unlock slow path

This slightly reduces code size, as can be seen below.
__libc_lock_unlock is usually used along with __libc_lock_lock in
the same function.  __libc_lock_lock already has an out-of-line
slow path, so this change should not introduce many additional
non-leaf functions.

This change also fixes a link failure in 32-bit Arm thumb mode
because commit 1f9c804fbd699104adefbce9e56d2c8aa711b6b9
("nptl: Use internal low-level lock type for !IS_IN (libc)")
introduced __libc_do_syscall calls outside of libc.

Before x86-64:

   text    data     bss     dec     hex filename
1937748   20456   54896 2013100  1eb7ac libc.so.6
  25601     856   12768   39225    9939 nss/libnss_db.so.2
  40310     952   25144   66406   10366 nss/libnss_files.so.2

After x86-64:
   text    data     bss     dec     hex filename
1935312   20456   54896 2010664  1eae28 libc.so.6
  25559     864   12768   39191    9917 nss/libnss_db.so.2
  39764     960   25144   65868   1014c nss/libnss_files.so.2

Before i686:

2110961   11272   39144 2161377  20fae1 libc.so.6
  27243     428   12652   40323    9d83 nss/libnss_db.so.2
  43062     476   25028   68566   10bd6 nss/libnss_files.so.2

After i686:

2107347   11272   39144 2157763  20ecc3 libc.so.6
  26929     432   12652   40013    9c4d nss/libnss_db.so.2
  43132     480   25028   68640   10c20 nss/libnss_files.so.2

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agopowerpc64le: Fix typo in configure
Anton Blanchard [Tue, 6 Jul 2021 10:19:36 +0000 (20:19 +1000)]
powerpc64le: Fix typo in configure

The configure script checks for -mlong-double-128 but mentions -mlongdouble
when it fails.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agopowerpc64: Remove strcspn ifunc from the loader
Tulio Magno Quites Machado Filho [Fri, 2 Jul 2021 18:42:31 +0000 (15:42 -0300)]
powerpc64: Remove strcspn ifunc from the loader

5 years ago, commit 8f1b841e452dbb083112fd036033b7f4af506ba0
unintentionally added an ifunc to the loader.
That modification has not caused any harm so far, but it doesn't add any
value either, because the hwcap information is available later during
libc initialization.

Suggested-by: Anton Blanchard <anton@ozlabs.org>
3 years agox86: Remove wcsnlen-sse4_1 from wcslen ifunc-impl-list [BZ #28064]
Noah Goldstein [Thu, 8 Jul 2021 20:13:19 +0000 (16:13 -0400)]
x86: Remove wcsnlen-sse4_1 from wcslen ifunc-impl-list [BZ #28064]

The following commit

commit 6f573a27b6c8b4236445810a44660612323f5a73
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Wed Jun 23 01:19:34 2021 -0400

    x86-64: Add wcslen optimize for sse4.1

Added wcsnlen-sse4.1 to the wcslen ifunc implementation list and did
not add wcslen-sse4.1 to wcslen ifunc implementation list. This commit
fixes that by removing wcsnlen-sse4.1 from the wcslen ifunc
implementation list and adding wcslen-sse4.1 to the ifunc
implementation list.

Testing:
test-wcslen.c, test-rsi-wcslen.c, and test-rsi-strlen.c are passing as
well as all other tests in wcsmbs and string.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agox86-64: Test strlen and wcslen with 0 in the RSI register [BZ #28064]
H.J. Lu [Thu, 8 Jul 2021 20:13:17 +0000 (16:13 -0400)]
x86-64: Test strlen and wcslen with 0 in the RSI register [BZ #28064]

commit 6f573a27b6c8b4236445810a44660612323f5a73
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Wed Jun 23 01:19:34 2021 -0400

    x86-64: Add wcslen optimize for sse4.1

added wcsnlen-sse4.1 to the wcslen ifunc implementation list.  Since the
random value in the the RSI register is larger than the wide-character
string length in the existing wcslen test, it didn't trigger the wcslen
test failure.  Add a test to force 0 into the RSI register before calling
wcslen.

3 years agox86_64: Remove unneeded static PIE check for undefined weak diagnostic
Fangrui Song [Thu, 8 Jul 2021 21:26:22 +0000 (14:26 -0700)]
x86_64: Remove unneeded static PIE check for undefined weak diagnostic

https://sourceware.org/bugzilla/show_bug.cgi?id=21782 dropped an ld
diagnostic for R_X86_64_PC32 referencing an undefined weak symbol in
-pie links.  Arguably keeping the diagnostic like other ports is more
correct, since statically resolving movl foo(%rip), %eax to the
link-time zero address produces a corrupted output.

It turns out that --enable-static-pie builds do not depend on the ld
behavior. GCC generates GOT indirection for weak declarations for
-fPIE/-fPIC, so what ld does with the PC-relative relocation doesn't
really matter.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agoAdd NT_ARM_PAC_ENABLED_KEYS to elf.h
Joseph Myers [Thu, 8 Jul 2021 17:36:27 +0000 (17:36 +0000)]
Add NT_ARM_PAC_ENABLED_KEYS to elf.h

This patch adds the new NT_ARM_PAC_ENABLED_KEYS constant from Linux
5.13 to glibc's elf.h.

Tested for x86_64.

3 years agoposix: Add posix_spawn_file_actions_addclosefrom_np
Adhemerval Zanella [Wed, 10 Mar 2021 15:26:33 +0000 (12:26 -0300)]
posix: Add posix_spawn_file_actions_addclosefrom_np

This patch adds a way to close a range of file descriptors on
posix_spawn as a new file action.  The API is similar to the one
provided by Solaris 11 [1], where the file action causes the all open
file descriptors greater than or equal to input on to be closed when
the new process is spawned.

The function posix_spawn_file_actions_addclosefrom_np is safe to be
implemented by iterating over /proc/self/fd, since the Linux spawni.c
helper process does not use CLONE_FILES, so its has own file descriptor
table and any failure (in /proc operation) aborts the process creation
and returns an error to the caller.

I am aware that this file action might be redundant to the current
approach of POSIX in promoting O_CLOEXEC in more interfaces. However
O_CLOEXEC is still not the default and for some specific usages, the
caller needs to close all possible file descriptors to avoid them
leaking.  Some examples are CPython (discussed in BZ#10353) and OpenJDK
jspawnhelper [2] (where OpenJDK spawns a helper process to exactly
closes all file descriptors).  Most likely any environment which calls
functions that might open file descriptor under the hood and aim to use
posix_spawn might face the same requirement.

Checked on x86_64-linux-gnu and i686-linux-gnu on kernel 5.11 and 4.15.

[1] https://docs.oracle.com/cd/E36784_01/html/E36874/posix-spawn-file-actions-addclosefrom-np-3c.html
[2] https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/childproc.c#L82

3 years agoio: Add closefrom [BZ #10353]
Adhemerval Zanella [Wed, 10 Mar 2021 15:26:32 +0000 (12:26 -0300)]
io: Add closefrom [BZ #10353]

The function closes all open file descriptors greater than or equal to
input argument.  Negative values are clamped to 0, i.e, it will close
all file descriptors.

As indicated by the bug report, this is a common symbol provided by
different systems (Solaris, OpenBSD, NetBSD, FreeBSD) and, although
its has inherent issues with not taking in consideration internal libc
file descriptors (such as syslog), this is also a common feature used
in multiple projects [1][2][3][4][5].

The Linux fallback implementation iterates over /proc and close all
file descriptors sequentially.  Although it was raised the questioning
whether getdents on /proc/self/fd might return disjointed entries
when file descriptor are closed; it does not seems the case on my
testing on multiple kernel (v4.18, v5.4, v5.9) and the same strategy
is used on different projects [1][2][3][5].

Also, the interface is set a fail-safe meaning that a failure in the
fallback results in a process abort.

Checked on x86_64-linux-gnu and i686-linux-gnu on kernel 5.11 and 4.15.

[1] https://github.com/systemd/systemd/blob/5238e9575906297608ff802a27e2ff9effa3b338/src/basic/fd-util.c#L217
[2] https://github.com/lxc/lxc/blob/ddf4b77e11a4d08f09b7b9cd13e593f8c047edc5/src/lxc/start.c#L236
[3] https://github.com/python/cpython/blob/9e4f2f3a6b8ee995c365e86d976937c141d867f8/Modules/_posixsubprocess.c#L220
[4] https://github.com/rust-lang/rust/blob/5f47c0613ed4eb46fca3633c1297364c09e5e451/src/libstd/sys/unix/process2.rs#L303-L308
[5] https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/childproc.c#L82

3 years agolinux: Add close_range
Adhemerval Zanella [Wed, 10 Mar 2021 15:26:31 +0000 (12:26 -0300)]
linux: Add close_range

It was added on Linux 5.9 (278a5fbaed89) with CLOSE_RANGE_CLOEXEC
added on 5.11 (582f1fb6b721f).  Although FreeBSD has added the same
syscall, this only adds the symbol on Linux ports.  This syscall is
required to provided a fail-safe way to implement the closefrom
symbol (BZ #10353).

Checked on x86_64-linux-gnu and i686-linux-gnu on kernel 5.11 and 4.15.

3 years agosupport: Add support_stack_alloc
Adhemerval Zanella [Wed, 10 Mar 2021 15:26:29 +0000 (12:26 -0300)]
support: Add support_stack_alloc

The code to allocate a stack from xsigstack is refactored so it can
be more generic.  The new support_stack_alloc() also set PROT_EXEC
if DEFAULT_STACK_PERMS has PF_X.  This is required on some
 architectures (hppa for instance) and trying to access the rtld
global from testsuite will require more intrusive refactoring
in the ldsodefs.h header.

Checked on x86_64-linux-gnu and i686-linux-gnu.  I also ran
tst-xsigstack on both hppa and ia64.

3 years ago_int_realloc is static
Siddhesh Poyarekar [Wed, 7 Jul 2021 09:31:20 +0000 (15:01 +0530)]
_int_realloc is static

_int_realloc is correctly declared at the top to be static, but
incorrectly defined without the static keyword.  Fix that.  The
generated binaries have identical code.

3 years agoMove mcheck symbol from stdlib to malloc
Siddhesh Poyarekar [Wed, 7 Jul 2021 13:44:00 +0000 (19:14 +0530)]
Move mcheck symbol from stdlib to malloc

It is defined in malloc, so it belongs there.  Verified on x86_64 that
the built libraries are identical despite this change.

3 years agonss: Do not install static linker input files for libnss_files
Florian Weimer [Thu, 8 Jul 2021 12:06:53 +0000 (14:06 +0200)]
nss: Do not install static linker input files for libnss_files

3 years agoelf/tests: Make thrlock and noload depend on libm
Siddhesh Poyarekar [Thu, 8 Jul 2021 08:09:19 +0000 (13:39 +0530)]
elf/tests: Make thrlock and noload depend on libm

Both tests try to dlopen libm.so at runtime, so make them depend on it
so that they're executed if libm.so has been updated.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
3 years agoHarden tcache double-free check
Siddhesh Poyarekar [Wed, 7 Jul 2021 17:32:46 +0000 (23:02 +0530)]
Harden tcache double-free check

The tcache allocator layer uses the tcache pointer as a key to
identify a block that may be freed twice.  Since this is in the
application data area, an attacker exploiting a use-after-free could
potentially get access to the entire tcache structure through this
key.  A detailed write-up was provided by Awarau here:

https://awaraucom.wordpress.com/2020/07/19/house-of-io-remastered/

Replace this static pointer use for key checking with one that is
generated at malloc initialization.  The first attempt is through
getrandom with a fallback to random_bits(), which is a simple
pseudo-random number generator based on the clock.  The fallback ought
to be sufficient since the goal of the randomness is only to make the
key arbitrary enough that it is very unlikely to collide with user
data.

Co-authored-by: Eyal Itkin <eyalit@checkpoint.com>
3 years agonss: Access nss_files through direct references
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
nss: Access nss_files through direct references

This partially fixes static-only NSS support (bug 27959): The files
module no longer needs dlopen.  Support for the dns module remains
to be added, and also support for disabling dlopen altogether.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonss_files: Move into libc
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
nss_files: Move into libc

This is the first step towards fixing bug 27959.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonss_files: Add generic code for set*ent, end*ent and file open
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
nss_files: Add generic code for set*ent, end*ent and file open

This reduces RSS usage if nss_files is not actually used, and can
be used later to make NSS data thread-specific.  It also results in
a small code size reduction.

Before:

   text    data     bss     dec     hex filename
   2288       0      72    2360     938 nss/files-alias.os
   1807       0      72    1879     757 nss/files-ethers.os
   1371       0      72    1443     5a3 nss/files-grp.os
   6246       0      72    6318    18ae nss/files-hosts.os
    869       0       0     869     365 nss/files-initgroups.os
    666       0       0     666     29a nss/files-init.os
   1934       0       0    1934     78e nss/files-netgrp.os
   2353       0      72    2425     979 nss/files-network.os
   2130       0      72    2202     89a nss/files-proto.os
   1372       0      72    1444     5a4 nss/files-pwd.os
   2124       0      72    2196     894 nss/files-rpc.os
   2265       0      72    2337     921 nss/files-service.os
   1125       0      72    1197     4ad nss/files-sgrp.os
   1124       0      72    1196     4ac nss/files-spwd.os

After:

   text    data     bss     dec     hex filename
   2040       0       0    2040     7f8 nss/files-alias.os
   1599       0       0    1599     63f nss/files-ethers.os
   1155       0       0    1155     483 nss/files-grp.os
   6010       0       0    6010    177a nss/files-hosts.os
    869       0       0     869     365 nss/files-initgroups.os
    666       0       0     666     29a nss/files-init.os
   1934       0       0    1934     78e nss/files-netgrp.os
   2129       0       0    2129     851 nss/files-network.os
   1914       0       0    1914     77a nss/files-proto.os
   1156       0       0    1156     484 nss/files-pwd.os
   1908       0       0    1908     774 nss/files-rpc.os
   2057       0       0    2057     809 nss/files-service.os
    909       0       0     909     38d nss/files-sgrp.os
    908       0       0     908     38c nss/files-spwd.os
   1090       0       8    1098     44a nss/nss_files_data.os

27674 code bytes before, 26344 code bytes after, so it is an overall
win despite the extra initialization code.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonss_files: Allocate nscd file registration data on the heap
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
nss_files: Allocate nscd file registration data on the heap

This is only needed if nss_files is loaded by nscd.

Before:

   text    data     bss     dec     hex filename
    767       0   24952   25719    6477 nss/files-init.os

After:

   text    data     bss     dec     hex filename
    666       0       0     666     29a nss/files-init.os

Using PATH_MAX bytes unconditionally for the directory name
is wasteful, but fixing that would constitute another break
of this semi-public ABI.  (The other issue is that with
symbolic links, an arbitrary set of parent directories may need
watching, not just a single one.)

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agolibio: Replace internal _IO_getdelim symbol with __getdelim
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
libio: Replace internal _IO_getdelim symbol with __getdelim

__getdelim is exported, _IO_getdelim is not.  Add a hidden prototype
for __getdelim.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agolibio: Add hidden prototype for ungetc
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
libio: Add hidden prototype for ungetc

And make ungetc the primary symbol, with _IO_ungetc as an alias.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoinet: Add hidden prototype for __inet_network
Florian Weimer [Wed, 7 Jul 2021 16:33:52 +0000 (18:33 +0200)]
inet: Add hidden prototype for __inet_network

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoUpdate MIPS libm-test-ulps
Joseph Myers [Wed, 7 Jul 2021 15:50:18 +0000 (15:50 +0000)]
Update MIPS libm-test-ulps

3 years agoUpdate powerpc-nofpu libm-test-ulps
Joseph Myers [Wed, 7 Jul 2021 15:35:04 +0000 (15:35 +0000)]
Update powerpc-nofpu libm-test-ulps

3 years agosoft-fp: Add __extendhfsf2/__extendhfdf2, __truncsfhf2/__truncdfhf2, __eqhf2/__nehf2
liuhongt [Wed, 7 Jul 2021 02:07:59 +0000 (10:07 +0800)]
soft-fp: Add __extendhfsf2/__extendhfdf2, __truncsfhf2/__truncdfhf2, __eqhf2/__nehf2

1. Add __extendhfdf2/__extendhfsf2 to return an IEEE half converted to IEEE double/single.
2. Add __truncdfhf2/__extendsfhf2 to truncate IEEE double/single into IEEE half.
3. Add __eqhf2/__nehf2 to return 0 if a == b and a,b are not NAN, otherwise return 1.

These are needed by x86 _Float16:

https://software.intel.com/content/www/us/en/develop/download/intel-avx512-fp16-architecture-specification.html

support in GCC.

3 years agoUpdate kernel version to 5.13 in tst-mman-consts.py
Joseph Myers [Wed, 7 Jul 2021 13:24:05 +0000 (13:24 +0000)]
Update kernel version to 5.13 in tst-mman-consts.py

This patch updates the kernel version in the test tst-mman-consts.py
to 5.13.  (There are no new MAP_* constants covered by this test in
5.13 that need any other header changes.)

Tested with build-many-glibcs.py.

3 years agotests-exclude-mcheck: Fix typo
Siddhesh Poyarekar [Wed, 7 Jul 2021 07:55:49 +0000 (13:25 +0530)]
tests-exclude-mcheck: Fix typo

It's tst-realloc, not tst-posix-realloc.  Verified this time to ensure
that the total number of tests reduced by 1.

Reported-by: Stefan Liebler <stli@linux.ibm.com>
3 years agoelf: Clean up GLIBC_PRIVATE exports of internal libdl symbols
Florian Weimer [Wed, 7 Jul 2021 06:40:41 +0000 (08:40 +0200)]
elf: Clean up GLIBC_PRIVATE exports of internal libdl symbols

They are no longer needed after everything has been moved into
libc.  The _dl_vsym test has to be removed because the symbol
cannot be used outside libc anymore.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonptl: Reduce the GLIBC_PRIVATE ABI
Florian Weimer [Wed, 7 Jul 2021 06:40:41 +0000 (08:40 +0200)]
nptl: Reduce the GLIBC_PRIVATE ABI

The remaining symbols are mostly used by libthread_db.
__pthread_get_minstack has to remain exported even though unused.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonptl: Remove GLIBC_2.34 versions of __pthread_mutex_lock, __pthread_mutex_unlock
Florian Weimer [Wed, 7 Jul 2021 06:40:41 +0000 (08:40 +0200)]
nptl: Remove GLIBC_2.34 versions of __pthread_mutex_lock, __pthread_mutex_unlock

Now that there are no internal users anymore, these new symbol
versions can be removed from the public ABI.  The compatibility
symbols remain.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agonptl: Use internal low-level lock type for !IS_IN (libc)
Florian Weimer [Wed, 7 Jul 2021 06:40:41 +0000 (08:40 +0200)]
nptl: Use internal low-level lock type for !IS_IN (libc)

This avoids an ABI hazard (types changing between different modules
of glibc) without introducing linknamespace issues. In particular,
NSS modules now call __lll_lock_wait_private@@GLIBC_PRIVATE to wait
on internal locks (the unlock path is inlined and performs a direct
system call).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoglibc.malloc.check: Fix nit in documentation
Siddhesh Poyarekar [Wed, 7 Jul 2021 01:32:13 +0000 (07:02 +0530)]
glibc.malloc.check: Fix nit in documentation

The tunable will not work with *any* non-zero tunable value since its
list of allowed values is 0-3.  Fix the documentation to reflect that.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoExclude tst-realloc from tests-mcheck
Siddhesh Poyarekar [Tue, 6 Jul 2021 18:01:58 +0000 (23:31 +0530)]
Exclude tst-realloc from tests-mcheck

The realloc (NULL, 0) test in tst-realloc fails with gcc 7.x but
passes with newer gcc.  This is because a newer gcc transforms the
realloc call to malloc (0), thus masking the bug in mcheck.

Disable the test with mcheck for now.  The malloc removal patchset
will fix this and then remove this test from the exclusion list.

Reported-by: Stefan Liebler <stli@linux.ibm.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agolinux: Fix setsockopt fallback
Adhemerval Zanella [Mon, 5 Jul 2021 12:48:48 +0000 (12:48 +0000)]
linux: Fix setsockopt fallback

The final 2 arguments for SO_TIMESTAMP/SO_TIMESTAMPNS are being set
wrongly.

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

3 years agolinux: Use the expected size for SO_TIMESTAMP{NS} convertion
Adhemerval Zanella [Sat, 3 Jul 2021 19:26:11 +0000 (16:26 -0300)]
linux: Use the expected size for SO_TIMESTAMP{NS} convertion

Kernel returns 32-bit values for COMPAT_SO_TIMESTAMP{NS}_OLD,
not 64-bit values.

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

3 years agolinux: Consolidate Linux setsockopt implementation
Adhemerval Zanella [Mon, 5 Jul 2021 13:01:24 +0000 (13:01 +0000)]
linux: Consolidate Linux setsockopt implementation

This patch consolidates the setsockopt implementation on
sysdeps/unix/sysv/linux/getsockopt.c.  The changes are:

  1. Remove it from auto-generation syscalls.list on all architectures.

  2. Add __ASSUME_SETSOCKOPT_SYSCALL as default and undef if for
     specific kernel versions on some architectures.

This also fix a potential issue where 32-bit time_t ABI should use the
linux setsockopt which overrides the underlying SO_* constants used for
socket timestamping for _TIME_BITS=64.

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

3 years agolinux: Consolidate Linux getsockopt implementation
Adhemerval Zanella [Mon, 5 Jul 2021 16:44:26 +0000 (13:44 -0300)]
linux: Consolidate Linux getsockopt implementation

This patch consolidates the getsockopt Linux syscall implementation on
sysdeps/unix/sysv/linux/getsockopt.c.  The changes are:

  1. Remove it from auto-generation syscalls.list on all architectures.

  2. Add __ASSUME_GETSOCKOPT_SYSCALL as default and undef if for
     specific kernel versions on some architectures.

This also fix a potential issue where 32-bit time_t ABI should use the
linux getsockopt which overrides the underlying SO_* constants used for
socket timestamping for _TIME_BITS=64.

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

3 years agomanual: fix description for preadv()
Armin Brauns [Tue, 6 Jul 2021 10:54:48 +0000 (12:54 +0200)]
manual: fix description for preadv()

3 years agoelf: Call free from base namespace on error in dl-libc.c [BZ #27646]
Florian Weimer [Tue, 6 Jul 2021 11:22:01 +0000 (13:22 +0200)]
elf: Call free from base namespace on error in dl-libc.c [BZ #27646]

In dlerror_run, free corresponds to the local malloc in the
namespace, but GLRO (dl_catch_error) uses the malloc from the base
namespace.  elf/tst-dlmopen-gethostbyname triggers this mismatch,
but it does not crash, presumably because of a fastbin deallocation.

Fixes commit c2059edce20c124d1a99f1a94cc52e83b77a917a ("elf: Use
_dl_catch_error from base namespace in dl-libc.c [BZ #27646]") and
commit b2964eb1d9a6b8ab1250e8a881cf406182da5875 ("dlfcn: Failures
after dlmopen should not terminate process [BZ #24772]").

3 years agolinux: Check for null value msghdr struct before use
Khem Raj [Fri, 2 Jul 2021 20:28:10 +0000 (13:28 -0700)]
linux: Check for null value msghdr struct before use

This avoids crashes in libc when cmsg is null and refrencing msg
structure when it is null

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agohooks.c: Remove incorrect comment
Siddhesh Poyarekar [Sun, 4 Jul 2021 12:45:18 +0000 (18:15 +0530)]
hooks.c: Remove incorrect comment

The comment about different values of glibc.malloc.check is no longer
valid.

3 years agomtrace: Add attribute nocommon to mallwatch
Tulio Magno Quites Machado Filho [Fri, 2 Jul 2021 21:12:13 +0000 (18:12 -0300)]
mtrace: Add attribute nocommon to mallwatch

Avoid compilation errors GCC versions that do not default to
-fno-common, e.g. GCC <= 9.

Fixes commit 00d28960c5388a582a0485e07629b553c32dde49 ("mtrace:
Deprecate mallwatch and tr_break").

Suggested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Suggested-by: Florian Weimer <fweimer@redhat.com>
3 years agoMove glibc.malloc.check implementation into its own file
Siddhesh Poyarekar [Fri, 2 Jul 2021 19:18:12 +0000 (00:48 +0530)]
Move glibc.malloc.check implementation into its own file

Separate the malloc check implementation from the malloc hooks.  They
still use the hooks but are now maintained in a separate file.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agomtrace: Deprecate mallwatch and tr_break
Siddhesh Poyarekar [Fri, 2 Jul 2021 19:17:34 +0000 (00:47 +0530)]
mtrace: Deprecate mallwatch and tr_break

The variable and function pair appear to provide a way for users to
set conditional breakpoints in mtrace when a specific address is
returned by the allocator.  This can be achieved by using conditional
breakpoints in gdb so it is redundant.  There is no documentation of
this interface in the manual either, so it appears to have been a hack
that got added to debug malloc.  Deprecate these symbols and do not
call tr_break anymore.

Reviewed-by: DJ Delorie <dj@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agoDrop source dependencies on hooks.c and arena.c
Siddhesh Poyarekar [Fri, 2 Jul 2021 19:16:46 +0000 (00:46 +0530)]
Drop source dependencies on hooks.c and arena.c

Dependencies on hooks.c and arena.c get auto-computed when generating
malloc.o{,s}.d so there is no need to add them manually.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
3 years agomalloc: Initiate tcache shutdown even without allocations [BZ #28028]
JeffyChen [Fri, 2 Jul 2021 15:39:24 +0000 (17:39 +0200)]
malloc: Initiate tcache shutdown even without allocations [BZ #28028]

After commit 1e26d35193efbb29239c710a4c46a64708643320 ("malloc: Fix
tcache leak after thread destruction [BZ #22111]"),
tcache_shutting_down is still not early enough.  When we detach a
thread with no tcache allocated, tcache_shutting_down would still be
false.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agoAdd mcheck tests to malloc
Siddhesh Poyarekar [Fri, 2 Jul 2021 02:25:10 +0000 (07:55 +0530)]
Add mcheck tests to malloc

Like malloc-check, add generic rules to run all tests in malloc by
linking with libmcheck.a so as to provide coverage for mcheck().
Currently the following 12 tests fail:

FAIL: malloc/tst-malloc-backtrace-mcheck
FAIL: malloc/tst-malloc-fork-deadlock-mcheck
FAIL: malloc/tst-malloc-stats-cancellation-mcheck
FAIL: malloc/tst-malloc-tcache-leak-mcheck
FAIL: malloc/tst-malloc-thread-exit-mcheck
FAIL: malloc/tst-malloc-thread-fail-mcheck
FAIL: malloc/tst-malloc-usable-static-mcheck
FAIL: malloc/tst-malloc-usable-static-tunables-mcheck
FAIL: malloc/tst-malloc-usable-tunables-mcheck
FAIL: malloc/tst-malloc_info-mcheck
FAIL: malloc/tst-memalign-mcheck
FAIL: malloc/tst-posix_memalign-mcheck

and they have been added to tests-exclude-mcheck for now to keep
status quo.  At least the last two can be attributed to bugs in
mcheck() but I haven't fixed them here since they should be fixed by
removing malloc hooks.  Others need to be triaged to check if they're
due to mcheck bugs or due to actual bugs.

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agoiconvconfig: Use the public feof_unlocked
Siddhesh Poyarekar [Fri, 2 Jul 2021 11:23:25 +0000 (16:53 +0530)]
iconvconfig: Use the public feof_unlocked

Build of iconvconfig failed with CFLAGS=-Os since __feof_unlocked is
not a public symbol.  Replace with feof_unlocked (defined to
__feof_unlocked when IS_IN (libc)) to fix this.

Reported-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
3 years agoresolv: Move libanl into libc (if libpthread is in libc)
Florian Weimer [Fri, 2 Jul 2021 09:45:00 +0000 (11:45 +0200)]
resolv: Move libanl into libc (if libpthread is in libc)

The symbols gai_cancel, gai_error, gai_suspend, getaddrinfo_a,
__gai_suspend_time64 were moved using scripts/move-symbol-to-libc.py.

For Hurd (which remains !PTHREAD_IN_LIBC), a few #define redirects
had to be added because several pthread functions are not available
under __.  (Linux uses __ prefixes for most hidden aliases, and has
to in some cases to avoid linknamespace issues.)

3 years agopowerpc: optimize strcpy/stpcpy for POWER9/10
Pedro Franco de Carvalho [Wed, 30 Jun 2021 15:36:07 +0000 (12:36 -0300)]
powerpc: optimize strcpy/stpcpy for POWER9/10

This patch modifies the current POWER9 implementation of strcpy and
stpcpy to optimize it for POWER9/10.

Since no new POWER10 instructions are used, the original POWER9 strcpy is
modified instead of creating a new implementation for POWER10.  This
implementation is based on both the original POWER9 implementation of
strcpy and the preamble of the new POWER10 implementation of strlen.

The changes also affect stpcpy, which uses the same implementation with
some additional code before returning.

On POWER9, averaging improvements across the benchmark
inputs (length/source alignment/destination alignment), for an
experiment that ran the benchmark five times, bench-strcpy showed an
improvement of 5.23%, and bench-stpcpy showed an improvement of 6.59%.

On POWER10, bench-strcpy showed 13.16%, and bench-stpcpy showed 13.59%.

The changes are:

1. Removed the null string optimization.

   Although this results in a few extra cycles for the null string, in
   combination with the second change, this resulted in improvements for
   for other cases.

2. Adapted the preamble from strlen for POWER10.

   This is the part of the function that handles up to the first 16 bytes
   of the string.

3. Increased number of unrolled iterations in the main loop to 6.

Reviewed-by: Matheus Castanho <msc@linux.ibm.com>
Tested-by: Matheus Castanho <msc@linux.ibm.com>
3 years agosoft-fp: Add __extendhfxf2 and __truncxfhf2
H.J. Lu [Thu, 1 Jul 2021 15:35:28 +0000 (08:35 -0700)]
soft-fp: Add __extendhfxf2 and __truncxfhf2

1. Add __extendhfxf2 to return an IEEE half converted to IEEE extended.
2. Add __truncxfhf2 to truncate IEEE extended into IEEE half.

These are needed by x86 _Float16:

https://software.intel.com/content/www/us/en/develop/download/intel-avx512-fp16-architecture-specification.html

support in GCC.

3 years agox86: Check RTM_ALWAYS_ABORT for RTM [BZ #28033]
H.J. Lu [Wed, 30 Jun 2021 17:47:06 +0000 (10:47 -0700)]
x86: Check RTM_ALWAYS_ABORT for RTM [BZ #28033]

From

https://www.intel.com/content/www/us/en/support/articles/000059422/processors.html

* Intel TSX will be disabled by default.
* The processor will force abort all Restricted Transactional Memory (RTM)
  transactions by default.
* A new CPUID bit CPUID.07H.0H.EDX[11](RTM_ALWAYS_ABORT) will be enumerated,
  which is set to indicate to updated software that the loaded microcode is
  forcing RTM abort.
* On processors that enumerate support for RTM, the CPUID enumeration bits
  for Intel TSX (CPUID.07H.0H.EBX[11] and CPUID.07H.0H.EBX[4]) continue to
  be set by default after microcode update.
* Workloads that were benefited from Intel TSX might experience a change
  in performance.
* System software may use a new bit in Model-Specific Register (MSR) 0x10F
  TSX_FORCE_ABORT[TSX_CPUID_CLEAR] functionality to clear the Hardware Lock
  Elision (HLE) and RTM bits to indicate to software that Intel TSX is
  disabled.

1. Add RTM_ALWAYS_ABORT to CPUID features.
2. Set RTM usable only if RTM_ALWAYS_ABORT isn't set.  This skips the
string/tst-memchr-rtm etc. testcases on the affected processors, which
always fail after a microcde update.
3. Check RTM feature, instead of usability, against /proc/cpuinfo.

This fixes BZ #28033.

3 years agoUpdate syscall lists for Linux 5.13
Joseph Myers [Thu, 1 Jul 2021 17:37:36 +0000 (17:37 +0000)]
Update syscall lists for Linux 5.13

Linux 5.13 has three new syscalls (landlock_create_ruleset,
landlock_add_rule, landlock_restrict_self).  Update syscall-names.list
and regenerate the arch-syscall.h headers with build-many-glibcs.py
update-syscalls.

Tested with build-many-glibcs.py.

3 years agos390: Fix MEMCHR_Z900_G5 ifunc-variant if n>=0x80000000 [BZ #28024]
Stefan Liebler [Tue, 29 Jun 2021 09:37:28 +0000 (11:37 +0200)]
s390: Fix MEMCHR_Z900_G5 ifunc-variant if n>=0x80000000 [BZ #28024]

On s390 (31bit), the pointer to the first byte after s always wraps
around with n >= 0x80000000 and can lead to stop searching before
end of s.

Thus this patch just use NULL as byte after s in this case and
the srst instruction stops searching with "not found" when wrapping
around from top address to zero.

This is observable with testcase string/test-memchr
starting with commit "String: Add overflow tests for strnlen, memchr,
and strncat [BZ #27974]"
https://sourceware.org/git/?p=glibc.git;a=commit;h=da5a6fba0febbfc90896ce1b2eb75c6d8a88a72d

3 years agoFix extra PLT reference in libc.so due to __glob64_time64 if build with gcc 7.5 on...
Stefan Liebler [Wed, 30 Jun 2021 14:17:37 +0000 (16:17 +0200)]
Fix extra PLT reference in libc.so due to __glob64_time64 if build with gcc 7.5 on 32bit.

Starting with recent commit 84f7ce84474c1648ce96884f1c91ca7b97ca3fc2
"posix: Add glob64 with 64-bit time_t support", elf/check-localplt
fails due to extra PLT reference __glob64_time64 in __glob64_time64
itself.

This is observable with gcc 7.5 on x86_64 with -m32 or s390x with
-m31.  E.g. if build with gcc 10, gcc is generating a call to
__glob64_time64.localalias.

This patch is adding a hidden version of __glob64_time64 in the
same way as for __globfree64_time64.

This page took 0.094538 seconds and 5 git commands to generate.