]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
18 months agoApply asm redirection in gmp.h before first use
Adhemerval Zanella [Thu, 10 Mar 2022 22:04:47 +0000 (19:04 -0300)] 
Apply asm redirection in gmp.h before first use

For clang the redeclaration after the first use, the visibility attribute
is silently ignored (symbol is STV_DEFAULT) while the asm label attribute
causes an error.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoRewrite find_cxx_header config configure.ac
Adhemerval Zanella [Wed, 2 Nov 2022 14:55:57 +0000 (11:55 -0300)] 
Rewrite find_cxx_header config configure.ac

With clang if the main file is <stdin>, the first non-main-file
dependency is not listed in the -MP output.  Although it was fixed
on clang-16 [1], this change adds portability for older version.

[1] https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoelf/tlsdeschtab.h: Add the Malloc return value check in _dl_make_tlsdesc_dynamic()
Xiaoming Ni [Fri, 4 Nov 2022 09:30:00 +0000 (17:30 +0800)] 
elf/tlsdeschtab.h: Add the Malloc return value check in _dl_make_tlsdesc_dynamic()

Check the return value of malloc based on the function header comment of
 _dl_make_tlsdesc_dynamic(). If the return value fails, NULL is returned.

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
18 months agoelf: Disable some subtests of ifuncmain1, ifuncmain5 for !PIE
Florian Weimer [Fri, 4 Nov 2022 17:37:16 +0000 (18:37 +0100)] 
elf: Disable some subtests of ifuncmain1, ifuncmain5 for !PIE

18 months agoposix: Make posix_spawn extensions available by default
Florian Weimer [Fri, 4 Nov 2022 06:43:59 +0000 (07:43 +0100)] 
posix: Make posix_spawn extensions available by default

Some sources merely include <spawn.h> without -D_GNU_SOURCE and expect
declarations for posix_spawn_file_actions_addchdir_np to be available.
For consistency, declare posix_spawn_file_actions_addfchdir_np,
posix_spawn_file_actions_addclosefrom_np,
posix_spawn_file_actions_addtcsetpgrp_np as well.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agox86_64: Implement evex512 version of strrchr and wcsrchr
Sunil K Pandey [Tue, 9 Aug 2022 14:57:29 +0000 (07:57 -0700)] 
x86_64: Implement evex512 version of strrchr and wcsrchr

Changes from v1:
  Use vec api for register.
  Replace VPCMP with VPCMPEQ
  Restructure and remove 1 unconditional jump.
  Change page cross logic to use sall.

This patch implements following evex512 version of string functions.
evex512 version takes up to 30% less cycle as compared to evex,
depending on length and alignment.

- strrchr function using 512 bit vectors.
- wcsrchr function using 512 bit vectors.

Code size data:

strrchr-evex.o 879 byte
strrchr-evex512.o 601 byte (-32%)

wcsrchr-evex.o 882 byte
wcsrchr-evex512.o 572 byte (-35%)

Placeholder function, not used by any processor at the moment.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
18 months agoelf: Introduce <dl-call_tls_init_tp.h> and call_tls_init_tp (bug 29249)
Florian Weimer [Thu, 3 Nov 2022 16:28:03 +0000 (17:28 +0100)] 
elf: Introduce <dl-call_tls_init_tp.h> and call_tls_init_tp (bug 29249)

This makes it more likely that the compiler can compute the strlen
argument in _startup_fatal at compile time, which is required to
avoid a dependency on strlen this early during process startup.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
18 months agoLoongArch: Fix ABI related macros in elf.h to keep consistent with binutils[1].
caiyinyu [Wed, 12 Oct 2022 12:28:42 +0000 (20:28 +0800)] 
LoongArch: Fix ABI related macros in elf.h to keep consistent with binutils[1].

[1]:
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=c4a7e6b56218e1d5a858682186b542e2eae01a4a;hp=0d94a8735055432029237612a6eb9165db1ec9dd
[2]:
Reference: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version

18 months agoscripts/glibcelf.py: Properly report <elf.h> parsing failures
Florian Weimer [Thu, 3 Nov 2022 11:24:17 +0000 (12:24 +0100)] 
scripts/glibcelf.py: Properly report <elf.h> parsing failures

Without this change, parse failures result in an exception:

Traceback (most recent call last):
  File "tst-glibcelf.py", line 23, in <module>
    import glibcelf
  File "/path/to/git/scripts/glibcelf.py", line 226, in <module>
    _elf_h = _parse_elf_h()
  File "/path/to/git/scripts/glibcelf.py", line 221, in _parse_elf_h
    result = glibcpp.macro_eval(glibcpp.macro_definitions(tokens), reporter)
  File "/path/to/git/scripts/glibcpp.py", line 379, in macro_eval
    reporter.error(md.line, 'macro {} redefined'.format(md.name))
  File "/path/to/git/scripts/glibcelf.py", line 214, in error
    errors += 1
UnboundLocalError: local variable 'errors' referenced before assignment

18 months agoelf: Rework exception handling in the dynamic loader [BZ #25486]
Florian Weimer [Thu, 3 Nov 2022 08:39:31 +0000 (09:39 +0100)] 
elf: Rework exception handling in the dynamic loader [BZ #25486]

The old exception handling implementation used function interposition
to replace the dynamic loader implementation (no TLS support) with the
libc implementation (TLS support).  This results in problems if the
link order between the dynamic loader and libc is reversed (bug 25486).

The new implementation moves the entire implementation of the
exception handling functions back into the dynamic loader, using
THREAD_GETMEM and THREAD_SETMEM for thread-local data support.
These depends on Hurd support for these macros, added in commit
b65a82e4e757c1e6cb7073916 ("hurd: Add THREAD_GET/SETMEM/_NC").

One small obstacle is that the exception handling facilities are used
before the TCB has been set up, so a check is needed if the TCB is
available.  If not, a regular global variable is used to store the
exception handling information.

Also rename dl-error.c to dl-catch.c, to avoid confusion with the
dlerror function.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
18 months agolinux: Drop useless include from fstatat.c
Aurelien Jarno [Tue, 1 Nov 2022 19:49:32 +0000 (20:49 +0100)] 
linux: Drop useless include from fstatat.c

It is a left-over from previous refactorings.

Reviewed by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

18 months agoFix OOB read in stdlib thousand grouping parsing [BZ #29727]
Szabolcs Nagy [Tue, 11 Oct 2022 14:24:41 +0000 (15:24 +0100)] 
Fix OOB read in stdlib thousand grouping parsing [BZ #29727]

__correctly_grouped_prefixmb only worked with thousands_len == 1,
otherwise it read past the end of cp or thousands.

This affects scanf formats like %'d, %'f and the internal but
exposed __strto{l,ul,f,d,..}_internal with grouping flag set
and an LC_NUMERIC locale where thousands_len > 1.

Avoid OOB access by considering thousands_len when initializing cp.
This fixes bug 29727.

Found by the morello port with strict bounds checking where

FAIL: stdlib/tst-strtod4
FAIL: stdlib/tst-strtod5i

crashed using a locale with thousands_len==3.

18 months agolinux: Fix fstatat on MIPSn64 (BZ #29730)
Aurelien Jarno [Tue, 1 Nov 2022 19:43:55 +0000 (20:43 +0100)] 
linux: Fix fstatat on MIPSn64 (BZ #29730)

Commit 6e8a0aac2f883 ("time: Fix overflow itimer tests on 32-bit
systems") changed in_time_t_range to assume a 32-bit time_t. This broke
fstatat on MIPSn64 that was using it with a 64-bit time_t due to
difference between stat and stat64. This commit fix that by adding a
MIPSn64 specific version, which bypasses the EOVERFLOW tests.

Resolves: BZ #29730

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoelf: Remove allocate use on _dl_debug_printf
Adhemerval Zanella [Mon, 31 Oct 2022 18:46:38 +0000 (15:46 -0300)] 
elf: Remove allocate use on _dl_debug_printf

The maximum number of directives is already limited by the maximum
value of iovec, and current padding usage on _dl_map_object_from_fd
specifies a value of 16 (2 times sizeof (void *)) in hexa, which is
less than the INT_STRLEN_BOUND(void *) (20 for LP64).

This works if pointers are larger than 8 bytes, for instance 16.
In this case the maximum padding would be 32 and the IFMTSIZE would
be 40.

The resulting code does use a slightly larger static stack, the
output of -fstack-usage (for x86_64):

 * master:
   dl-printf.c:35:1:_dl_debug_vdprintf     1344    dynamic

 * patch:
   dl-printf.c:36:1:_dl_debug_vdprintf     2416    static

However, there is an improvement in code generation:

 * master
   text    data     bss     dec     hex filename
   3309       0       0    3309     ced elf/dl-printf.os

 * patch
   text    data     bss     dec     hex filename
   3151       0       0    3151     c4f elf/dl-printf.os

Checked on x86_64-linux-gnu.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
18 months agonptl: Fix pthread_create.c build with clang
Adhemerval Zanella [Tue, 25 Oct 2022 14:07:59 +0000 (11:07 -0300)] 
nptl: Fix pthread_create.c build with clang

clang complains that libc_hidden_data_def (__nptl_threads_events)
creates an invalid alias:

  pthread_create.c:50:1: error: alias must point to a defined variable or function
  libc_hidden_data_def (__nptl_threads_events)
  ^
  ../include/libc-symbols.h:621:37: note: expanded from macro
  'libc_hidden_data_def'

It seems that clang requires that a proper prototype is defined prior
the hidden alias creation.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoallocate_once: Apply asm redirection before first use
Adhemerval Zanella [Tue, 25 Oct 2022 13:42:16 +0000 (10:42 -0300)] 
allocate_once: Apply asm redirection before first use

Compilers may not be able to apply asm redirections to functions
after these functions are used for the first time, e.g. clang 15.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoalloc_buffer: Apply asm redirection before first use
Adhemerval Zanella [Fri, 11 Mar 2022 18:37:57 +0000 (15:37 -0300)] 
alloc_buffer: Apply asm redirection before first use

Compilers may not be able to apply asm redirections to functions after
these functions are used for the first time, e.g. clang 15.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoconfigure: Use -Wno-ignored-attributes if compiler warns about multiple aliases
Adhemerval Zanella [Fri, 11 Mar 2022 13:40:44 +0000 (10:40 -0300)] 
configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases

clang emits an warning when a double alias redirection is used, to warn
the the original symbol will be used even when weak definition is
overridden.  However, this is a common pattern for weak_alias, where
multiple alias are set to same symbol.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoDisable use of -fsignaling-nans if compiler does not support it
Adhemerval Zanella [Mon, 7 Mar 2022 18:09:53 +0000 (15:09 -0300)] 
Disable use of -fsignaling-nans if compiler does not support it

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agointl: Fix clang -Wunused-but-set-variable on plural.c
Adhemerval Zanella [Wed, 24 Aug 2022 14:13:23 +0000 (11:13 -0300)] 
intl: Fix clang -Wunused-but-set-variable on plural.c

Clang warns that '__gettextnerrs' set but not used:

  intl/plural.c:1034:9: error: variable '__gettextnerrs' set but not used
  [-Werror,-Wunused-but-set-variable]
      int yynerrs = 0;
        ^

Clang 15 (https://reviews.llvm.org/D122271) -Wunused-but-set-variable
gives a warning while GCC doesn't.  The -Wunused-but-set-variable is
available in GCC 4.6, lower than the minimum required version 6.2.

Since the file is auto-generated, suppress the warning with a compiler
flag.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agoApply asm redirection in not-cancel before first use
Adhemerval Zanella [Mon, 24 Oct 2022 19:12:15 +0000 (16:12 -0300)] 
Apply asm redirection in not-cancel before first use

It is avoid a build failure on clang where it can not redeclare function
attribute after its first use.

Reviewed-by: Fangrui Song <maskray@google.com>
18 months agomalloc: Use uintptr_t for pointer alignment
Carlos Eduardo Seo [Wed, 26 Jan 2022 19:00:13 +0000 (16:00 -0300)] 
malloc: Use uintptr_t for pointer alignment

Avoid integer casts that assume unsigned long can represent pointers.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoUse uintptr_t in fts for pointer alignment
Szabolcs Nagy [Tue, 12 Jul 2022 09:59:16 +0000 (10:59 +0100)] 
Use uintptr_t in fts for pointer alignment

The code assumed unsigned long can represent pointers.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoFix build with GCC 13 _FloatN, _FloatNx built-in functions
Joseph Myers [Mon, 31 Oct 2022 23:20:08 +0000 (23:20 +0000)] 
Fix build with GCC 13 _FloatN, _FloatNx built-in functions

GCC 13 has added more _FloatN and _FloatNx versions of existing
<math.h> and <complex.h> built-in functions, for use in libstdc++-v3.

This breaks the glibc build because of how those functions are defined
as aliases to functions with the same ABI but different types.  Add
appropriate -fno-builtin-* options for compiling relevant files, as
already done for the case of long double functions aliasing double
ones and based on the list of files used there.

I fixed some mistakes in that list of double files that I noticed
while implementing this fix, but there may well be more such
(harmless) cases, in this list or the new one (files that don't
actually exist or don't define the named functions as aliases so don't
need the options).  I did try to exclude cases where glibc doesn't
define certain functions for _FloatN or _FloatNx types at all from the
new uses of -fno-builtin-* options.  As with the options for double
files (see the commit message for commit
49348beafe9ba150c9bd48595b3f372299bddbb0, "Fix build with GCC 10 when
long double = double."), it's deliberate that the options are used
even if GCC currently doesn't have a built-in version of a given
functions, so providing some level of future-proofing against more
such built-in functions being added in future.

Tested with build-many-glibcs.py for aarch64-linux-gnu
powerpc-linux-gnu powerpc64le-linux-gnu x86_64-linux-gnu (compilers
and glibcs builds) with GCC mainline.

18 months agoelf: Build tst-relr-mod[34]a.so with $(LDFLAGS-rpath-ORIGIN)
H.J. Lu [Fri, 28 Oct 2022 22:16:32 +0000 (15:16 -0700)] 
elf: Build tst-relr-mod[34]a.so with $(LDFLAGS-rpath-ORIGIN)

When --enable-hardcoded-path-in-tests is used only with DT_RUNPATH,
elf/tst-relr3 and elf/tst-relr4 failed to run.  Their dependency
libraries, tst-relr-mod3a.so and tst-relr-mod4a.so, are failed to
load since DT_RUNPATH on executable doesn't apply to them.  Build
tst-relr-mod3a.so and tst-relr-mod4a.so with $(LDFLAGS-rpath-ORIGIN)
to add DT_RUNPATH for their dependency libraries.
Reviewed-by: Fangrui Song <maskray@google.com>
18 months agox86-64: Improve evex512 version of strlen functions
Sunil K Pandey [Mon, 3 Oct 2022 19:00:53 +0000 (12:00 -0700)] 
x86-64: Improve evex512 version of strlen functions

This patch improves following functionality
- Replace VPCMP with VPCMPEQ.
- Replace page cross check logic with sall.
- Remove extra lea from align_more.
- Remove uncondition loop jump.
- Use bsf to check max length in first vector.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
18 months agoCorrectly determine libc.so 'OUTPUT_FORMAT' when cross-compiling.
Ludovic Courtès [Thu, 1 Jul 2021 21:00:19 +0000 (23:00 +0200)] 
Correctly determine libc.so 'OUTPUT_FORMAT' when cross-compiling.

Commit 87d583c6e8cd0e49f64da76636ebeec033298b4d replaces the sed script
with an "objdump -f" invocation to determine the 'OUTPUT_FORMAT' bit of
the libc.so linker script.

However, when cross-compiling, for example from x86_64-linux-gnu to
aarch64-linux-gnu, "objdump -f" would report the wrong
format ("elf64-little").  Conversely, "aarch64-linux-gnu-objdump -f"
reports "elf64-littleaarch64" as expected.

This patch changes 'configure.ac' to use AC_CHECK_TOOL rather than
'$CC -print-prog-name=objdump' to determine the value of the OBJDUMP
variable.  That way, OBJDUMP is set to TRIPLET-objdump when
cross-compiling for TRIPLET.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
18 months agoRemove unused scratch_buffer_dupfree
Szabolcs Nagy [Tue, 11 Oct 2022 12:23:25 +0000 (13:23 +0100)] 
Remove unused scratch_buffer_dupfree

Turns out scratch_buffer_dupfree internal API was unused since

commit ef0700004bf0dccf493a5e8e21f71d9e7972ea9f
stdlib: Simplify buffer management in canonicalize

And the related test in malloc/tst-scratch_buffer had issues
so it's better to remove it completely.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoFix elf/tst-dlmopen-twice not to exhaust static TLS
Szabolcs Nagy [Tue, 18 Oct 2022 15:33:52 +0000 (16:33 +0100)] 
Fix elf/tst-dlmopen-twice not to exhaust static TLS

By default glibc only allocates enough static TLS for 4 link namespaces
including the initial one. So only use 3 dlmopens in the test.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoUse uintptr_t in string/tester for pointer alignment
Szabolcs Nagy [Mon, 21 Mar 2022 12:36:16 +0000 (12:36 +0000)] 
Use uintptr_t in string/tester for pointer alignment

The code assumed unsigned long can represent pointers.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agostdlib/strfrom: Add copysign to fix NAN issue on riscv (BZ #29501)
Letu Ren [Fri, 21 Oct 2022 14:54:50 +0000 (22:54 +0800)] 
stdlib/strfrom: Add copysign to fix NAN issue on riscv (BZ #29501)

According to the specification of ISO/IEC TS 18661-1:2014,

The strfromd, strfromf, and strfroml functions are equivalent to
snprintf(s, n, format, fp) (7.21.6.5), except the format string contains only
the character %, an optional precision that does not contain an asterisk *, and
one of the conversion specifiers a, A, e, E, f, F, g, or G, which applies to
the type (double, float, or long double) indicated by the function suffix
(rather than  by a length modifier). Use of these functions with any other 20
format string results in undefined behavior.

strfromf will convert the arguement with type float to double first.

According to the latest version of IEEE754 which is published in 2019,

Conversion of a quiet NaN from a narrower format to a wider format in the same
radix, and then back to the same narrower format, should not change the quiet
NaN payload in any way except to make it canonical.

When either an input or result is a NaN, this standard does not interpret the
sign of a NaN. However, operations on bit strings—copy, negate, abs,
copySign—specify the sign bit of a NaN result, sometimes based upon the sign
bit of a NaN operand. The logical predicates totalOrder and isSignMinus are
also affected by the sign bit of a NaN operand. For all other operations, this
standard does not specify the sign bit of a NaN result, even when there is only
one input NaN, or when the NaN is produced from an invalid operation.

converting NAN or -NAN with type float to double doesn't need to keep
the signbit. As a result, this test case isn't mandatory.

The problem is that according to RISC-V ISA manual in chapter 11.3 of
riscv-isa-20191213,

Except when otherwise stated, if the result of a floating-point operation is
NaN, it is the canonical NaN. The canonical NaN has a positive sign and all
significand bits clear except the MSB, a.k.a. the quiet bit. For
single-precision floating-point, this corresponds to the pattern 0x7fc00000.

which means that conversion -NAN from float to double won't keep the signbit.

Since glibc ought to be consistent here between types and architectures, this
patch adds copysign to fix this problem if the string is NAN. This patch
adds two different functions under sysdeps directory to work around the
issue.

This patch has been tested on x86_64 and riscv64.

Resolves: BZ #29501

v2: Change from macros to different inline functions.
v3: Add unlikely check to isnan.
v4: Fix wrong commit message header.
v5: Fix style: add space before parentheses.
v6: Add copyright.
Signed-off-by: Letu Ren <fantasquex@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoFix resource/bug-ulimit1 test
Szabolcs Nagy [Fri, 6 May 2022 13:19:54 +0000 (14:19 +0100)] 
Fix resource/bug-ulimit1 test

ulimit is a variadic function and the second argument must have type
long (or unsigned long).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoFix missing NUL terminator in stdio-common/scanf13 test
Szabolcs Nagy [Tue, 11 Oct 2022 13:57:16 +0000 (14:57 +0100)] 
Fix missing NUL terminator in stdio-common/scanf13 test

sscanf is only defined on nul terminated string input, but '\0' was
missing in this test which caused _IO_str_init_static_internal to
read OOB on the stack when computing the bounds of the string.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoFix off-by-one OOB read in elf/tst-tls20
Szabolcs Nagy [Tue, 11 Oct 2022 12:07:59 +0000 (13:07 +0100)] 
Fix off-by-one OOB read in elf/tst-tls20

The int mods[nmods] array on the stack was overread by one.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoelf: Fix alloca size in _dl_debug_vdprintf
Szabolcs Nagy [Tue, 11 Oct 2022 13:22:35 +0000 (14:22 +0100)] 
elf: Fix alloca size in _dl_debug_vdprintf

The alloca size did not consider the optional width parameter for
padding which could cause buffer underflow. The width is currently used
e.g. by _dl_map_object_from_fd which passes 2 * sizeof(void *) which
can be larger than the alloca buffer size on targets where
sizeof(void *) >= 2 * sizeof(unsigned long).

Even if large width is not used on existing targets it is better to fix
the formatting code to avoid surprises.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agomalloc: Use uintptr_t in alloc_buffer
Szabolcs Nagy [Wed, 16 Mar 2022 12:09:15 +0000 (12:09 +0000)] 
malloc: Use uintptr_t in alloc_buffer

The values represnt pointers and not sizes. The members of struct
alloc_buffer are already uintptr_t.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoFix invalid pointer dereference in wcpcpy_chk
Szabolcs Nagy [Tue, 21 Jun 2022 14:57:48 +0000 (15:57 +0100)] 
Fix invalid pointer dereference in wcpcpy_chk

The src pointer is const and points to a different object, so accessing
dest via src is invalid.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoFix invalid pointer dereference in wcscpy_chk
Szabolcs Nagy [Tue, 21 Jun 2022 13:43:30 +0000 (14:43 +0100)] 
Fix invalid pointer dereference in wcscpy_chk

The src pointer is const and points to a different object, so accessing
dest via src is invalid.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agoaarch64: Fix the extension header write in getcontext and swapcontext
Szabolcs Nagy [Fri, 29 Jul 2022 07:00:06 +0000 (08:00 +0100)] 
aarch64: Fix the extension header write in getcontext and swapcontext

The extension header is two 32bit words and in the last header both
should be 0. There is plenty space in the __reserved area, but it's
better not to write more than we mean to.

18 months agoaarch64: Don't build wordcopy
Szabolcs Nagy [Thu, 28 Jul 2022 13:29:19 +0000 (14:29 +0100)] 
aarch64: Don't build wordcopy

Use an empty wordcopy.c to avoid building the generic one.
It does not seem to be used anywhere.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoscripts: Use bool in tunables initializer
Szabolcs Nagy [Tue, 8 Jun 2021 13:03:38 +0000 (14:03 +0100)] 
scripts: Use bool in tunables initializer

The initializer for a tunable_t set the bool initialized flag to NULL.
This causes a build failure when pointer to bool conversion warns.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
18 months agolonglong.h: update from GCC for LoongArch clz/ctz support
Xi Ruoyao [Sat, 15 Oct 2022 06:12:13 +0000 (14:12 +0800)] 
longlong.h: update from GCC for LoongArch clz/ctz support

Update longlong.h to GCC r13-3269.  Keep our local change (prefer https
for gnu.org URL).

18 months agoelf: Introduce to _dl_call_fini
Florian Weimer [Thu, 27 Oct 2022 09:36:44 +0000 (11:36 +0200)] 
elf: Introduce to _dl_call_fini

This consolidates the destructor invocations from _dl_fini and
dlclose.  Remove the micro-optimization that avoids
calling _dl_call_fini if they are no destructors (as dlclose is quite
expensive anyway).  The debug log message is now printed
unconditionally.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agold.so: Export tls_init_tp_called as __rtld_tls_init_tp_called
Florian Weimer [Thu, 27 Oct 2022 09:36:44 +0000 (11:36 +0200)] 
ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called

This allows the rest of dynamic loader to check whether the TCB
has been set up (and THREAD_GETMEM and THREAD_SETMEM will work).

Reviewed-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
18 months agoscripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY)
Florian Weimer [Thu, 27 Oct 2022 09:36:44 +0000 (11:36 +0200)] 
scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY)

On csky-linux-gnuabiv2, binutils 2.33 produces a DT_JMPREL entry
for the dynamic loader if it does not contain any PLT relocations:

Dynamic section at offset 0x1df48 contains 19 entries:
  Tag        Type                         Name/Value
 0x0000000e (SONAME)                     Library soname: [ld-linux-cskyv2-hf.so.1]
 0x00000004 (HASH)                       0xd4
 0x6ffffef5 (GNU_HASH)                   0x1a8
 0x00000005 (STRTAB)                     0x4ac
 0x00000006 (SYMTAB)                     0x28c
 0x0000000a (STRSZ)                      527 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000003 (PLTGOT)                     0x1f000
 0x00000002 (PLTRELSZ)                   0 (bytes)
 0x00000014 (PLTREL)                     RELA
 0x00000017 (JMPREL)                     0xaa4
 0x00000007 (RELA)                       0x75c
 0x00000008 (RELASZ)                     840 (bytes)
 0x00000009 (RELAENT)                    12 (bytes)
 0x6ffffffc (VERDEF)                     0x700
 0x6ffffffd (VERDEFNUM)                  3
 0x6ffffff0 (VERSYM)                     0x6bc
 0x6ffffff9 (RELACOUNT)                  68
 0x00000000 (NULL)                       0x0

This confuses the script:

Unexpected output from check-localplt: …/elf/ld.so.jmprel:
*** DT_JMPREL does not match any section's address

This commit changes the script to record the DT_PLTRELSZ value and
reject DT_JMPREL values not a section boundary only if DT_PLTRELSZ
is present with a non-zero value.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
18 months agoRemove lingering libSegfault Makefile entries
Adhemerval Zanella [Wed, 26 Oct 2022 18:13:17 +0000 (15:13 -0300)] 
Remove lingering libSegfault Makefile entries

The library was removed by 65ccd641ba.

18 months agoaarch64: Use memcpy_simd as the default memcpy
Wilco Dijkstra [Wed, 26 Oct 2022 13:16:50 +0000 (14:16 +0100)] 
aarch64: Use memcpy_simd as the default memcpy

Since __memcpy_simd is the fastest memcpy on almost all cores, replace
the generic memcpy with it.  If SVE is available, a SVE memcpy will be
used by default (including for Neoverse N2).

18 months agoaarch64: Cleanup memset ifunc
Wilco Dijkstra [Wed, 26 Oct 2022 13:12:55 +0000 (14:12 +0100)] 
aarch64: Cleanup memset ifunc

Cleanup memset ifunc selectors. The A64FX memset relies on a ZVA size of
256, so add an explicit check.

18 months agoelf: Reinstate on DL_DEBUG_BINDINGS _dl_lookup_symbol_x
Adhemerval Zanella [Tue, 25 Oct 2022 16:19:16 +0000 (13:19 -0300)] 
elf: Reinstate on DL_DEBUG_BINDINGS _dl_lookup_symbol_x

The prelink removal done by 6628c742b2c16e wrongly removed the debug
support.

Checked on x86_64-linux-gnu.

18 months agox86_64: Implement evex512 version of strchrnul, strchr and wcschr
Sunil K Pandey [Tue, 26 Jul 2022 20:54:56 +0000 (13:54 -0700)] 
x86_64: Implement evex512 version of strchrnul, strchr and wcschr

This patch implements following evex512 version of string functions.
evex512 version takes up to 30% less cycle as compared to evex,
depending on length and alignment.

- strchrnul function using 512 bit vectors.
- strchr function using 512 bit vectors.
- wcschr function using 512 bit vectors.

Code size data:

strchrnul-evex.o 599 byte
strchrnul-evex512.o 569 byte (-5%)

strchr-evex.o 639 byte
strchr-evex512.o 595 byte (-7%)

wcschr-evex.o 644 byte
wcschr-evex512.o 607 byte (-6%)

Placeholder function, not used by any processor at the moment.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
18 months agolinux: Fix generic struct_stat for 64 bit time (BZ# 29657)
Adhemerval Zanella [Wed, 19 Oct 2022 22:14:04 +0000 (19:14 -0300)] 
linux: Fix generic struct_stat for 64 bit time (BZ# 29657)

The generic Linux struct_stat misses the conditionals to use
bits/struct_stat_time64_helper.h in the __USE_TIME_BITS64 for
architecture that uses __TIMESIZE == 32 (currently csky and nios2).

Since newer ports should not support 32 bit time_t, the generic
implementation should be used as default.

For arm, hppa, and sh a copy of default struct_stat is added,
while for csky and nios a new one based on generic is used, along
with conditionals to use bits/struct_stat_time64_helper.h.

The default struct_stat is also replaced with the generic one.

Checked on aarch64-linux-gnu and arm-linux-gnueabihf.

18 months agomanual: Add missing % in int conversion list
Jakub Wilk [Mon, 24 Oct 2022 11:48:08 +0000 (13:48 +0200)] 
manual: Add missing % in int conversion list

Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
18 months agoAvoid undefined behaviour in ibm128 implementation of llroundl (BZ #29488)
Aurelien Jarno [Sun, 9 Oct 2022 22:39:33 +0000 (00:39 +0200)] 
Avoid undefined behaviour in ibm128 implementation of llroundl (BZ #29488)

Detecting an overflow edge case depended on signed overflow of a long
long. Replace the additions and the overflow checks by
__builtin_add_overflow().

Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
18 months agoRemove all assembly optimizations for htonl and htons
Adhemerval Zanella [Mon, 24 Oct 2022 14:35:04 +0000 (11:35 -0300)] 
Remove all assembly optimizations for htonl and htons

The builtin bswap is already used if optimziation is enabled for
GCC 4.8+, so glibc symbols will be used in a very limited scenarios.

Also, gcc generated code is quite similar to all but ia64 and i386
htons.

Checked on alpha, i686, and ia64.

18 months agoRemove htonl.S for i386/x86_64
Cristian Rodríguez [Thu, 20 Oct 2022 23:02:37 +0000 (23:02 +0000)] 
Remove htonl.S for i386/x86_64

Generic implementation on top of __bswap_32 always expands
inline to either bswap or movbe depending on -march=*.

Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
18 months agoFix BZ #29463 in the ibm128 implementation of y1l too
Michael Hudson-Doyle [Mon, 22 Aug 2022 02:05:04 +0000 (14:05 +1200)] 
Fix BZ #29463 in the ibm128 implementation of y1l too

Avoid moving code across SET_RESTORE_ROUNDL in order to fix
[BZ #29463].

Tested-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
18 months agoAdd ADDRB from Linux 6.0 to bits/termios-c_cflag.h
Joseph Myers [Mon, 24 Oct 2022 13:43:19 +0000 (13:43 +0000)] 
Add ADDRB from Linux 6.0 to bits/termios-c_cflag.h

Linux 6.0 adds a constant ADDRB, a termios c_cflag bit, to its
include/uapi/asm-generic/termbits-common.h.

Add it accordingly to glibc's bits/termios-c_cflag.h headers.  As
other constants in these headers are generally in octal, I converted
the value to octal to match.  As ADDRB isn't in a POSIX-reserved
namespace, I made it conditional on __USE_MISC.

Tested for x86_64.

18 months agox86: Use `testb` for FSRM check in memmove-vec-unaligned-erms
Noah Goldstein [Thu, 20 Oct 2022 02:13:38 +0000 (19:13 -0700)] 
x86: Use `testb` for FSRM check in memmove-vec-unaligned-erms

`testb` saves a bit of code size is the imm-operand can be encoded
1-bytes.

Tested on x86-64.

18 months agox86: Use `testb` for case-locale check in str{n}casecmp-sse42
Noah Goldstein [Thu, 20 Oct 2022 02:13:37 +0000 (19:13 -0700)] 
x86: Use `testb` for case-locale check in str{n}casecmp-sse42

`testb` saves a bit of code size is the imm-operand can be encoded
1-bytes.

Tested on x86-64.

18 months agox86: Use `testb` for case-locale check in str{n}casecmp-sse2
Noah Goldstein [Thu, 20 Oct 2022 02:13:36 +0000 (19:13 -0700)] 
x86: Use `testb` for case-locale check in str{n}casecmp-sse2

`testb` saves a bit of code size is the imm-operand can be encoded
1-bytes.

Tested on x86-64.

18 months agox86: Use `testb` for case-locale check in str{n}casecmp-avx2
Noah Goldstein [Thu, 20 Oct 2022 02:13:35 +0000 (19:13 -0700)] 
x86: Use `testb` for case-locale check in str{n}casecmp-avx2

`testb` saves a bit of code size is the imm-operand can be encoded
1-bytes.

Tested on x86-64.

18 months agox86: Add support for VEC_SIZE == 64 in strcmp-evex.S impl
Noah Goldstein [Thu, 20 Oct 2022 02:15:55 +0000 (19:15 -0700)] 
x86: Add support for VEC_SIZE == 64 in strcmp-evex.S impl

Unused at the moment, but evex512 strcmp, strncmp, strcasecmp{l}, and
strncasecmp{l} functions can be added by including strcmp-evex.S with
"x86-evex512-vecs.h" defined.

In addition save code size a bit in a few places.

1. tzcnt ...         -> bsf ...
2. vpcmp{b|d} $0 ... -> vpcmpeq{b|d}

This saves a touch of code size but has minimal net affect.

Full check passes on x86-64.

18 months agox86: Remove AVX512-BVMI2 instruction from strrchr-evex.S
Noah Goldstein [Thu, 20 Oct 2022 17:26:46 +0000 (10:26 -0700)] 
x86: Remove AVX512-BVMI2 instruction from strrchr-evex.S

commit b412213eee0afa3b51dfe92b736dfc7c981309f5
    Author: Noah Goldstein <goldstein.w.n@gmail.com>
    Date:   Tue Oct 18 17:44:07 2022 -0700

        x86: Optimize strrchr-evex.S and implement with VMM headers

Added `vpcompress{b|d}` to the page-cross logic with is an
AVX512-VBMI2 instruction. This is not supported on SKX. Since the
page-cross logic is relatively cold and the benefit is minimal
revert the page-cross case back to the old logic which is supported
on SKX.

Tested on x86-64.

18 months agosysdeps: arm: Fix preconfigure script for ARMv8/v9 targets [BZ #29698]
Felix Riemann [Tue, 18 Oct 2022 15:20:44 +0000 (17:20 +0200)] 
sysdeps: arm: Fix preconfigure script for ARMv8/v9 targets [BZ #29698]

The ARM preconfigure script tries to detect the capabilities of the
target platform by checking the compiler's predefined architecture
macros. However, if the compiler is tuning for AArch32 on ARMv8/v9 this
step fails:

checking for sysdeps preconfigure fragments... aarch64 alpha arc arm
WARNING: arm/preconfigure: Did not find ARM architecture type; using default

This is because preconfigure.ac doesn't escape the square brackets in
the glob for matching compilers targeting ARMv8. Adding another pair of
brackets to escape the first pair fixes this:

checking for sysdeps preconfigure fragments... aarch64 alpha arc arm
 Found compiler is configured for something newer than v7 - using v7

Signed-off-by: Felix Riemann <felix.riemann@sma.de>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agonis: Fix nis_print_directory
Adhemerval Zanella Netto [Mon, 26 Sep 2022 16:53:24 +0000 (13:53 -0300)] 
nis: Fix nis_print_directory

Remove implicit conversion from enumeration type 'zotypes' to different
type 'nstype'.

Checked on x86_64-linux-gnu.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
18 months agolinux: Avoid shifting a negative signed on POSIX timer interface
Adhemerval Zanella [Tue, 30 Aug 2022 12:08:02 +0000 (09:08 -0300)] 
linux: Avoid shifting a negative signed on POSIX timer interface

The current macros uses pid as signed value, which triggers a compiler
warning for process and thread timers.  Replace MAKE_PROCESS_CPUCLOCK
with static inline function that expects the pid as unsigned.  These
are similar to what Linux does internally.

Checked on x86_64-linux-gnu.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
18 months agoBench: Improve benchtests for memchr, strchr, strnlen, strrchr
Noah Goldstein [Wed, 19 Oct 2022 00:44:09 +0000 (17:44 -0700)] 
Bench: Improve benchtests for memchr, strchr, strnlen, strrchr

1. Add more complete coverage in the medium size range.
2. In strnlen remove the `1 << i` which was UB (`i` could go beyond
   32/64)

18 months agox86: Optimize strrchr-evex.S and implement with VMM headers
Noah Goldstein [Wed, 19 Oct 2022 00:44:07 +0000 (17:44 -0700)] 
x86: Optimize strrchr-evex.S and implement with VMM headers

Optimization is:
1. Cache latest result in "fast path" loop with `vmovdqu` instead of
  `kunpckdq`.  This helps if there are more than one matches.

Code Size Changes:
strrchr-evex.S       :  +30 bytes (Same number of cache lines)

Net perf changes:

Reported as geometric mean of all improvements / regressions from N=10
runs of the benchtests. Value as New Time / Old Time so < 1.0 is
improvement and 1.0 is regression.

strrchr-evex.S       : 0.932 (From cases with higher match frequency)

Full results attached in email.

Full check passes on x86-64.

18 months agox86: Optimize memrchr-evex.S
Noah Goldstein [Wed, 19 Oct 2022 00:44:06 +0000 (17:44 -0700)] 
x86: Optimize memrchr-evex.S

Optimizations are:
1. Use the fact that lzcnt(0) -> VEC_SIZE for memchr to save a branch
   in short string case.
2. Save several instructions in len = [VEC_SIZE, 4 * VEC_SIZE] case.
3. Use more code-size efficient instructions.
- tzcnt ...     -> bsf ...
- vpcmpb $0 ... -> vpcmpeq ...

Code Size Changes:
memrchr-evex.S      :  -29 bytes

Net perf changes:

Reported as geometric mean of all improvements / regressions from N=10
runs of the benchtests. Value as New Time / Old Time so < 1.0 is
improvement and 1.0 is regression.

memrchr-evex.S      : 0.949 (Mostly from improvements in small strings)

Full results attached in email.

Full check passes on x86-64.

18 months agox86: Optimize strnlen-evex.S and implement with VMM headers
Noah Goldstein [Wed, 19 Oct 2022 00:44:05 +0000 (17:44 -0700)] 
x86: Optimize strnlen-evex.S and implement with VMM headers

Optimizations are:
1. Use the fact that bsf(0) leaves the destination unchanged to save a
   branch in short string case.
2. Restructure code so that small strings are given the hot path.
        - This is a net-zero on the benchmark suite but in general makes
      sense as smaller sizes are far more common.
3. Use more code-size efficient instructions.
- tzcnt ...     -> bsf ...
- vpcmpb $0 ... -> vpcmpeq ...
4. Align labels less aggressively, especially if it doesn't save fetch
   blocks / causes the basic-block to span extra cache-lines.

The optimizations (especially for point 2) make the strnlen and
strlen code essentially incompatible so split strnlen-evex
to a new file.

Code Size Changes:
strlen-evex.S       :  -23 bytes
strnlen-evex.S      : -167 bytes

Net perf changes:

Reported as geometric mean of all improvements / regressions from N=10
runs of the benchtests. Value as New Time / Old Time so < 1.0 is
improvement and 1.0 is regression.

strlen-evex.S       : 0.992 (No real change)
strnlen-evex.S      : 0.947

Full results attached in email.

Full check passes on x86-64.

18 months agox86: Shrink / minorly optimize strchr-evex and implement with VMM headers
Noah Goldstein [Wed, 19 Oct 2022 00:44:04 +0000 (17:44 -0700)] 
x86: Shrink / minorly optimize strchr-evex and implement with VMM headers

Size Optimizations:
1. Condence hot path for better cache-locality.
    - This is most impact for strchrnul where the logic strings with
      len <= VEC_SIZE or with a match in the first VEC no fits entirely
      in the first cache line.
2. Reuse common targets in first 4x VEC and after the loop.
3. Don't align targets so aggressively if it doesn't change the number
   of fetch blocks it will require and put more care in avoiding the
   case where targets unnecessarily split cache lines.
4. Align the loop better for DSB/LSD
5. Use more code-size efficient instructions.
- tzcnt ...     -> bsf ...
- vpcmpb $0 ... -> vpcmpeq ...
6. Align labels less aggressively, especially if it doesn't save fetch
   blocks / causes the basic-block to span extra cache-lines.

Code Size Changes:
strchr-evex.S : -63 bytes
strchrnul-evex.S: -48 bytes

Net perf changes:
Reported as geometric mean of all improvements / regressions from N=10
runs of the benchtests. Value as New Time / Old Time so < 1.0 is
improvement and 1.0 is regression.

strchr-evex.S (Fixed)   : 0.971
strchr-evex.S (Rand)    : 0.932
strchrnul-evex.S        : 0.965

Full results attached in email.

Full check passes on x86-64.

18 months agox86: Optimize memchr-evex.S and implement with VMM headers
Noah Goldstein [Wed, 19 Oct 2022 00:44:03 +0000 (17:44 -0700)] 
x86: Optimize memchr-evex.S and implement with VMM headers

Optimizations are:

1. Use the fact that tzcnt(0) -> VEC_SIZE for memchr to save a branch
   in short string case.
2. Restructure code so that small strings are given the hot path.
- This is a net-zero on the benchmark suite but in general makes
      sense as smaller sizes are far more common.
3. Use more code-size efficient instructions.
- tzcnt ...     -> bsf ...
- vpcmpb $0 ... -> vpcmpeq ...
4. Align labels less aggressively, especially if it doesn't save fetch
   blocks / causes the basic-block to span extra cache-lines.

The optimizations (especially for point 2) make the memchr and
rawmemchr code essentially incompatible so split rawmemchr-evex
to a new file.

Code Size Changes:
memchr-evex.S       : -107 bytes
rawmemchr-evex.S    :  -53 bytes

Net perf changes:

Reported as geometric mean of all improvements / regressions from N=10
runs of the benchtests. Value as New Time / Old Time so < 1.0 is
improvement and 1.0 is regression.

memchr-evex.S       : 0.928
rawmemchr-evex.S    : 0.986 (Less targets cross cache lines)

Full results attached in email.

Full check passes on x86-64.

18 months agox86_64: Implement evex512 version of memchr, rawmemchr and wmemchr
Sunil K Pandey [Thu, 18 Aug 2022 13:48:07 +0000 (06:48 -0700)] 
x86_64: Implement evex512 version of memchr, rawmemchr and wmemchr

This patch implements following evex512 version of string functions.
evex512 version takes up to 30% less cycle as compared to evex,
depending on length and alignment.

- memchr function using 512 bit vectors.
- rawmemchr function using 512 bit vectors.
- wmemchr function using 512 bit vectors.

Code size data:

memchr-evex.o 762 byte
memchr-evex512.o 576 byte (-24%)

rawmemchr-evex.o 461 byte
rawmemchr-evex512.o 412 byte (-11%)

wmemchr-evex.o 794 byte
wmemchr-evex512.o 552 byte (-30%)

Placeholder function, not used by any processor at the moment.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
18 months agoString: Improve test coverage for memchr
Sunil K Pandey [Tue, 18 Oct 2022 07:36:51 +0000 (00:36 -0700)] 
String: Improve test coverage for memchr

This test improves memchr coverage near page boundary.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
18 months agoUse PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources
Florian Weimer [Tue, 18 Oct 2022 15:00:07 +0000 (17:00 +0200)] 
Use PTR_MANGLE and PTR_DEMANGLE unconditionally in C sources

In the future, this will result in a compilation failure if the
macros are unexpectedly undefined (due to header inclusion ordering
or header inclusion missing altogether).

Assembler sources are more difficult to convert.  In many cases,
they are hand-optimized for the mangling and no-mangling variants,
which is why they are not converted.

sysdeps/s390/s390-32/__longjmp.c and sysdeps/s390/s390-64/__longjmp.c
are special: These are C sources, but most of the implementation is
in assembler, so the PTR_DEMANGLE macro has to be undefined in some
cases, to match the assembler style.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agoIntroduce <pointer_guard.h>, extracted from <sysdep.h>
Florian Weimer [Tue, 18 Oct 2022 15:00:07 +0000 (17:00 +0200)] 
Introduce <pointer_guard.h>, extracted from <sysdep.h>

This allows us to define a generic no-op version of PTR_MANGLE and
PTR_DEMANGLE.  In the future, we can use PTR_MANGLE and PTR_DEMANGLE
unconditionally in C sources, avoiding an unintended loss of hardening
due to missing include files or unlucky header inclusion ordering.

In i386 and x86_64, we can avoid a <tls.h> dependency in the C
code by using the computed constant from <tcb-offsets.h>.  <sysdep.h>
no longer includes these definitions, so there is no cyclic dependency
anymore when computing the <tcb-offsets.h> constants.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agox86-64: Move LP_SIZE definition to its own header
Florian Weimer [Tue, 18 Oct 2022 15:00:07 +0000 (17:00 +0200)] 
x86-64: Move LP_SIZE definition to its own header

This way, we can define the pointer guard macros without including
<sysdep.h> on x86-64.  Other architectures will not have such an
inclusion dependency, and the implied header file inclusion would
create a porting hazard.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 months agomath: Fix asin and acos invalid exception with old gcc
Szabolcs Nagy [Thu, 13 Oct 2022 10:10:10 +0000 (11:10 +0100)] 
math: Fix asin and acos invalid exception with old gcc

This works around a gcc issue where it const folded inf/inf into nan,
preventing the invalid exception to be signalled.

(x-x)/(x-x) is more robust against optimizations and works for all
out of bounds values including x==nan.

The gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95115
should be fixed on release branches starting from gcc-10, but it is
better to change the code in case glibc is built with older gcc.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
19 months agox86: Update strlen-evex-base to use new reg/vec macros.
Noah Goldstein [Sat, 15 Oct 2022 03:00:30 +0000 (22:00 -0500)] 
x86: Update strlen-evex-base to use new reg/vec macros.

To avoid duplicate the VMM / GPR / mask insn macros in all incoming
evex512 files use the macros defined in 'reg-macros.h' and
'{vec}-macros.h'

This commit does not change libc.so

Tested build on x86-64

19 months agox86: Remove now unused vec header macros.
Noah Goldstein [Sat, 15 Oct 2022 03:00:29 +0000 (22:00 -0500)] 
x86: Remove now unused vec header macros.

This commit does not change libc.so

Tested build on x86-64

19 months agox86: Update memset to use new VEC macros
Noah Goldstein [Sat, 15 Oct 2022 03:00:28 +0000 (22:00 -0500)] 
x86: Update memset to use new VEC macros

Replace %VEC(n) -> %VMM(n)

This commit does not change libc.so

Tested build on x86-64

19 months agox86: Update memmove to use new VEC macros
Noah Goldstein [Sat, 15 Oct 2022 03:00:27 +0000 (22:00 -0500)] 
x86: Update memmove to use new VEC macros

Replace %VEC(n) -> %VMM(n)

This commit does not change libc.so

Tested build on x86-64

19 months agox86: Update memrchr to use new VEC macros
Noah Goldstein [Sat, 15 Oct 2022 03:00:26 +0000 (22:00 -0500)] 
x86: Update memrchr to use new VEC macros

Replace %VEC(n) -> %VMM(n)

This commit does not change libc.so

Tested build on x86-64

19 months agox86: Update VEC macros to complete API for evex/evex512 impls
Noah Goldstein [Sat, 15 Oct 2022 03:00:25 +0000 (22:00 -0500)] 
x86: Update VEC macros to complete API for evex/evex512 impls

1) Copy so that backport will be easier.
2) Make section only define if there is not a previous definition
3) Add `VEC_lo` definition for proper reg-width but in the
   ymm/zmm0-15 range.
4) Add macros for accessing GPRs based on VEC_SIZE
        This is to make it easier to do think like:
        ```
            vpcmpb %VEC(0), %VEC(1), %k0
            kmov{d|q} %k0, %{eax|rax}
            test %{eax|rax}
        ```
        It adds macro s.t any GPR can get the proper width with:
            `V{upcase_GPR_name}`

        and any mask insn can get the proper width with:
            `{upcase_mask_insn_without_postfix}`

This commit does not change libc.so

Tested build on x86-64

19 months agoelf: Do not completely clear reused namespace in dlmopen (bug 29600)
Florian Weimer [Fri, 14 Oct 2022 09:02:25 +0000 (11:02 +0200)] 
elf: Do not completely clear reused namespace in dlmopen (bug 29600)

The data in the _ns_debug member must be preserved, otherwise
_dl_debug_initialize enters an infinite loop.  To be conservative,
only clear the libc_map member for now, to fix bug 29528.

Fixes commit d0e357ff45a75553dee3b17ed7d303bfa544f6fe
("elf: Call __libc_early_init for reused namespaces (bug 29528)"),
by reverting most of it.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
19 months agomalloc: Switch global_max_fast to uint8_t
Florian Weimer [Thu, 13 Oct 2022 03:45:41 +0000 (05:45 +0200)] 
malloc: Switch global_max_fast to uint8_t

MAX_FAST_SIZE is 160 at most, so a uint8_t is sufficient.  This makes
it harder to use memory corruption, by overwriting global_max_fast
with a large value, to fundamentally alter malloc behavior.

Reviewed-by: DJ Delorie <dj@redhat.com>
19 months agoAdd NT_S390_PV_CPU_DATA from Linux 6.0 to elf.h
Joseph Myers [Wed, 12 Oct 2022 14:28:47 +0000 (14:28 +0000)] 
Add NT_S390_PV_CPU_DATA from Linux 6.0 to elf.h

Add the new NT_S390_PV_CPU_DATA constant from Linux 6.0 to glibc's
elf.h.

Tested for x86_64.

19 months agoAdd AArch64 HWCAP2_EBF16 from Linux 6.0 to bits/hwcap.h
Joseph Myers [Wed, 12 Oct 2022 14:28:14 +0000 (14:28 +0000)] 
Add AArch64 HWCAP2_EBF16 from Linux 6.0 to bits/hwcap.h

Linux 6.0 adds a new AArch64 HWCAP2 bit, HWCAP2_EBF16.  Add this to
glibc's bits/hwcap.h.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

19 months agoString: Improve test coverage for memchr
Sunil K Pandey [Mon, 10 Oct 2022 16:28:14 +0000 (09:28 -0700)] 
String: Improve test coverage for memchr

This test improves memchr coverage near page boundary.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
19 months agoelf: Remove -fno-tree-loop-distribute-patterns usage on dl-support
Adhemerval Zanella [Thu, 6 Oct 2022 15:35:35 +0000 (12:35 -0300)] 
elf: Remove -fno-tree-loop-distribute-patterns usage on dl-support

Besides the option being gcc specific, this approach is still fragile
and not future proof since we do not know if this will be the only
optimization option gcc will add that transforms loops to memset
(or any libcall).

This patch adds a new header, dl-symbol-redir-ifunc.h, that can b
used to redirect the compiler generated libcalls to port the generic
memset implementation if required.

Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
19 months agosocket: Use offsetof in SUN_LEN (bug 29578)
Andreas Schwab [Mon, 19 Sep 2022 08:10:09 +0000 (10:10 +0200)] 
socket: Use offsetof in SUN_LEN (bug 29578)

Use offsetof instead of its traditional expansion in the definition of the
SUN_LEN macro, to avoid a warning from the undefined behaviour sanitizer.

19 months agoExpose all MAP_ constants in <sys/mman.h> unconditionally (bug 29375)
Andreas Schwab [Tue, 16 Aug 2022 13:18:11 +0000 (15:18 +0200)] 
Expose all MAP_ constants in <sys/mman.h> unconditionally (bug 29375)

POSIX reserves the MAP_ prefix for <sys/mman.h>, so there is no need to
conditionalize their definitions on feature test macros.

19 months agoLoongArch: Fix the condition to use PC-relative addressing in start.S
Xi Ruoyao [Sun, 2 Oct 2022 14:23:09 +0000 (22:23 +0800)] 
LoongArch: Fix the condition to use PC-relative addressing in start.S

A start.o compiled from start.S with -DPIC and no -DSHARED is used by
both crt1.o and rcrt1.o.  So the LoongArch static PIE patch
unintentionally introduced PC-relative addressing for main and
__libc_start_main into crt1.o.

While the latest Binutils (trunk, which will be released as 2.40)
supports the PC-relative relocs against an external function by creating
a PLT entry, the 2.39 release branch doesn't (and won't) support this.
An error is raised:

    "PLT stub does not represent and symbol not defined."

So, we need the following changes:

1. Check if ld supports the PC-relative relocs against an external
   function.  If it's not supported, we deem static PIE unsupported.
2. Change start.S.  If static PIE is supported, use PC-relative
   addressing for main and __libc_start_main and rely on the linker to
   create PLT entries.  Otherwise, restore the old behavior (using GOT
   to address these functions).

An alternative would be adding a new "static-pie-start.S", and some
custom logic into Makefile to build rcrt1.o with it.  And, restore
start.S to the state before static PIE change so crt1.o won't contain
PC-relative relocs against external symbols.  But I can't see any
benefit of this alternative, so I'd just keep it simple.

Tested by building glibc with the following configurations:

1. Binutils trunk + GCC trunk.  Static PIE enabled.  All tests
   passed.
2. Binutils 2.39 branch + GCC trunk.  Static PIE disabled.  Tests
   related to ifunc failed (it's a known issue).  All other tests
   passed.
3. Binutils 2.39 branch + GCC 12 branch, cross compilation with
   build-many-glibcs.py from x86_64-linux-gnu.  Static PIE disabled.
   Build succeeded.

19 months agoarm: Enable USE_ATOMIC_COMPILER_BUILTINS (BZ #24774)
Adhemerval Zanella [Tue, 28 Sep 2021 17:53:28 +0000 (17:53 +0000)] 
arm: Enable USE_ATOMIC_COMPILER_BUILTINS (BZ #24774)

As per other architectures.  I have checked on a armv8 hardware with
the following configurations:

  arm-linux-gnueabihf (gcc built with --with-float=hard --with-cpu=arm926ej-s)
  armv5-linux-gnueabihf (-march=armv5te -mfpu=vfpv3)
  armv7-linux-gnueabihf (-march=armv7-a -mfpu=vfpv3)
  armv7-thumb-linux-gnueabihf (-march=armv7-a -mfpu=vfpv3 -mthumb)
  armv7-neon-linux-gnueabihf (-march=armv7-a -mfpu=neon)
  armv7-neonhard-linux-gnueabihf (-march=armv7-a -mfpu=neon -mfloat-abi=hard)

Without any regression.

I haven't dig into the code, but since Linux atomic-machine.h handle
pre-ARMv6 and ARMv6 I expect the compiler might have some small room
to optimize.

The code size also improves is most of the configurations:

* master

   text    data     bss     dec     hex filename
1727801    9720   37928 1775449  1b1759  arm-linux-gnueabihf/libc.so
1691729    9720   37928 1739377  1a8a71  arm-linux-gnueabihf-armv7-disable-multi-arch/libc.so
1725509    9720   37928 1773157  1b0e65  armv5-linux-gnueabihf/libc.so
1700757    9720   37928 1748405  1aadb5  armv6-linux-gnueabihf/libc.so
1698973    9720   37928 1746621  1aa6bd  armv6t2-linux-gnueabihf/libc.so
1695481    9752   37928 1743161  1a9939  armv7-linux-gnueabihf/libc.so
1692917    9744   37928 1740589  1a8f2d  armv7-neonhard-linux-gnueabihf/libc.so
1692917    9744   37928 1740589  1a8f2d  armv7-neon-linux-gnueabihf/libc.so
1225353    9752   37928 1273033  136cc9  armv7-thumb-linux-gnueabihf/libc.so

* patched

   text    data     bss     dec     hex filename
1726805    9720   37928 1774453  1b1375 arm-linux-gnueabihf/libc.so
1689321    9720   37928 1736969  1a8109 arm-linux-gnueabihf-armv7-disable-multi-arch/libc.so
1724433    9720   37928 1772081  1b0a31 armv5-linux-gnueabihf/libc.so
1698301    9720   37928 1745949  1aa41d armv6-linux-gnueabihf/libc.so
1696525    9720   37928 1744173  1a9d2d armv6t2-linux-gnueabihf/libc.so
1693009    9752   37928 1740689  1a8f91 armv7-linux-gnueabihf/libc.so
1690493    9744   37928 1738165  1a85b5 armv7-neonhard-linux-gnueabihf/libc.so
1690493    9744   37928 1738165  1a85b5 armv7-neon-linux-gnueabihf/libc.so
1223837    9752   37928 1271517  1366dd armv7-thumb-linux-gnueabihf/libc.so

The idea is eventually move all architectures to use compiler builtins.

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Tested-by: Aurelien Jarno <aurelien@aurel32.net>
19 months agocsu: Disable stack protector for static-reloc for static-pie
Adhemerval Zanella [Wed, 5 Oct 2022 17:07:28 +0000 (14:07 -0300)] 
csu: Disable stack protector for static-reloc for static-pie

For instance on x86_64 with gcc 12.1.1 andwith fstack-protector
enabled the empty function still generates a stack protector code
sequence:

  0000000000000000 <_dl_relocate_static_pie>:
     0:   48 83 ec 18             sub    $0x18,%rsp
     4:   64 48 8b 04 25 28 00    mov    %fs:0x28,%rax
     b:   00 00
     d:   48 89 44 24 08          mov    %rax,0x8(%rsp)
    12:   31 c0                   xor    %eax,%eax
    14:   48 8b 44 24 08          mov    0x8(%rsp),%rax
    19:   64 48 2b 04 25 28 00    sub    %fs:0x28,%rax
    20:   00 00
    22:   75 05                   jne    29 <_dl_relocate_static_pie+0x29>
    24:   48 83 c4 18             add    $0x18,%rsp
    28:   c3                      ret
    29:   e8 00 00 00 00          call   2e <_dl_relocate_static_pie+0x2e>

And since the function is called prior thread pointer setup, it
triggers a invalid memory access (this is shown with the failure
of elf/tst-tls1-static-non-pie).

Although it might characterizes as compiler issue or missed
optimization, to be safe also disables stack protector on
static-reloc object.

Checked on x86_64-linux-gnu and sparc64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
19 months agoNEWS: Fix grammar
Andreas Schwab [Thu, 6 Oct 2022 11:17:16 +0000 (13:17 +0200)] 
NEWS: Fix grammar

19 months agoelf: Simplify output of hwcap subdirectories in ld.so help
Javier Pello [Tue, 27 Sep 2022 18:10:08 +0000 (20:10 +0200)] 
elf: Simplify output of hwcap subdirectories in ld.so help

The print_hwcap_1 machinery was useful for the legacy hwcaps
subdirectories, but it is not worth the trouble now that they
are gone.

Signed-off-by: Javier Pello <devel@otheo.eu>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
19 months agoelf: Remove _dl_string_hwcap
Javier Pello [Tue, 27 Sep 2022 18:09:28 +0000 (20:09 +0200)] 
elf: Remove _dl_string_hwcap

Removal of legacy hwcaps support from the dynamic loader left
no users of _dl_string_hwcap.

Signed-off-by: Javier Pello <devel@otheo.eu>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
19 months agoAdd NEWS entry for legacy hwcaps removal
Javier Pello [Tue, 27 Sep 2022 18:08:47 +0000 (20:08 +0200)] 
Add NEWS entry for legacy hwcaps removal

Add a NEWS entry noting the removal of the legacy hwcaps search
mechanism for shared objects.

Signed-off-by: Javier Pello <devel@otheo.eu>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
19 months agoelf: Remove hwcap and bits_hwcap fields from struct cache_entry
Javier Pello [Tue, 27 Sep 2022 18:08:09 +0000 (20:08 +0200)] 
elf: Remove hwcap and bits_hwcap fields from struct cache_entry

They were set to 0 on initialisation and never changed later after
last commit.

Signed-off-by: Javier Pello <devel@otheo.eu>
Reviewed-by: Florian Weimer <fweimer@redhat.com>