]> sourceware.org Git - glibc.git/log
glibc.git
3 years agoaarch64: revert memcpy optimze for kunpeng to avoid performance degradation
Shuo Wang [Wed, 20 Jan 2021 07:20:44 +0000 (15:20 +0800)]
aarch64: revert memcpy optimze for kunpeng to avoid performance degradation

In commit 863d775c481704baaa41855fc93e5a1ca2dc6bf6, kunpeng920 is added to default memcpy version,
however, there is performance degradation when the copy size is some large bytes, eg: 100k.
This is the result, tested in glibc-2.28:
             before backport  after backport  Performance improvement
memcpy_1k      0.005              0.005                 0.00%
memcpy_10k     0.032              0.029                 10.34%
memcpy_100k    0.356              0.429                 -17.02%
memcpy_1m      7.470              11.153                -33.02%

This is the demo
#include "stdio.h"
#include "string.h"
#include "stdlib.h"

char a[1024*1024] = {12};
char b[1024*1024] = {13};
int main(int argc, char *argv[])
{
    int i = atoi(argv[1]);
    int j;
    int size = atoi(argv[2]);

    for (j = 0; j < i; j++)
        memcpy(b, a, size*1024);
    return 0;
}

# gcc -g -O0 memcpy.c -o memcpy
# time taskset -c 10 ./memcpy 100000 1024

Co-authored-by: liqingqing <liqingqing3@huawei.com>
3 years agoMake libc symbols hidden in static PIE
Szabolcs Nagy [Wed, 6 Jan 2021 11:31:04 +0000 (11:31 +0000)]
Make libc symbols hidden in static PIE

Hidden visibility can avoid indirections and RELATIVE relocs in
static PIE libc.

The check should use IS_IN_LIB instead of IS_IN(libc) since all
symbols are defined locally in static PIE and the optimization is
useful in all libraries not just libc. However the test system
links objects from libcrypt.a into dynamic linked test binaries
where hidden visibility does not work.  I think mixing static and
shared libc components in the same binary should not be supported
usage, but to be safe only use hidden in libc.a.

On some targets (i386) this optimization cannot be applied because
hidden visibility PIE ifunc functions don't work, so it is gated by
NO_HIDDEN_EXTERN_FUNC_IN_PIE.

From -static-pie linked 'int main(){}' this shaves off 71 relative
relocs on aarch64 and reduces code size by about 2k.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agocsu: Move static pie self relocation later [BZ #27072]
Szabolcs Nagy [Tue, 19 Jan 2021 17:17:01 +0000 (17:17 +0000)]
csu: Move static pie self relocation later [BZ #27072]

IFUNC resolvers may depend on tunables and cpu feature setup so
move static pie self relocation after those.

It is hard to guarantee that the ealy startup code does not rely
on relocations so this is a bit fragile. It would be more robust
to handle RELATIVE relocs early and only IRELATIVE relocs later,
but the current relocation processing code cannot do that.

The early startup code up to relocation processing includes

  _dl_aux_init (auxvec);
  __libc_init_secure ();
  __tunables_init (__environ);
  ARCH_INIT_CPU_FEATURES ();
  _dl_relocate_static_pie ();

These are simple enough that RELATIVE relocs can be avoided.

The following steps include

  ARCH_SETUP_IREL ();
  ARCH_SETUP_TLS ();
  ARCH_APPLY_IREL ();

On some targets IRELATIVE processing relies on TLS setup on
others TLS setup relies on IRELATIVE relocs, so the right
position for _dl_relocate_static_pie is target dependent.
For now move self relocation as early as possible on targets
that support static PIE.

Fixes bug 27072.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoUse hidden visibility for early static PIE code
Szabolcs Nagy [Fri, 15 Jan 2021 12:49:24 +0000 (12:49 +0000)]
Use hidden visibility for early static PIE code

Extern symbol access in position independent code usually involves GOT
indirection which needs RELATIVE reloc in a static linked PIE. (On
some targets this is avoided e.g. because the linker can relax a GOT
access to a pc-relative access, but this is not generally true.) Code
that runs before static PIE self relocation must avoid relying on
dynamic relocations which can be ensured by using hidden visibility.
However we cannot just make all symbols hidden:

On i386, all calls to IFUNC functions must go through PLT and calls to
hidden functions CANNOT go through PLT in PIE since EBX used in PIE PLT
may not be set up for local calls to hidden IFUNC functions.

This patch aims to make symbol references hidden in code that is used
before and by _dl_relocate_static_pie when building a static PIE libc.
Note: for an object that is used in the startup code, its references
and definition may not have consistent visibility: it is only forced
hidden in the startup code.

This is needed for fixing bug 27072.

Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agocsu: Avoid weak ref for __ehdr_start in static PIE
Szabolcs Nagy [Wed, 6 Jan 2021 14:28:02 +0000 (14:28 +0000)]
csu: Avoid weak ref for __ehdr_start in static PIE

All linkers support __ehdr_start that support static PIE linking,
so there is no need to check for its presence via a weak reference.

This avoids a RELATIVE relocation in static PIE startup code on some
targets.

With non-PIE static linking the weak ref check is kept in case the
linker does not support __ehdr_start.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoconfigure: Check for static PIE support
Szabolcs Nagy [Wed, 20 Jan 2021 12:26:31 +0000 (12:26 +0000)]
configure: Check for static PIE support

Add SUPPORT_STATIC_PIE that targets can define if they support
static PIE. This requires PI_STATIC_AND_HIDDEN support and various
linker features as described in

  commit 9d7a3741c9e59eba87fb3ca6b9f979befce07826
  Add --enable-static-pie configure option to build static PIE [BZ #19574]

Currently defined on x86_64, i386 and aarch64 where static PIE is
known to work.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoelf: Avoid RELATIVE relocs in __tunables_init
Szabolcs Nagy [Tue, 12 Jan 2021 16:28:27 +0000 (16:28 +0000)]
elf: Avoid RELATIVE relocs in __tunables_init

With static pie linking pointers in the tunables list need
RELATIVE relocs since the absolute address is not known at link
time. We want to avoid relocations so the static pie self
relocation can be done after tunables are initialized.

This is a simple fix that embeds the tunable strings into the
tunable list instead of using pointers.  It is possible to have
a more compact representation of tunables with some additional
complexity in the generator and tunable parser logic.  Such
optimization will be useful if the list of tunables grows.

There is still an issue that tunables_strdup allocates and the
failure handling code path is sufficiently complex that it can
easily have RELATIVE relocations.  It is possible to avoid the
early allocation and only change environment variables in a
setuid exe after relocations are processed.  But that is a
bigger change and early failure is fatal anyway so it is not
as critical to fix right away. This is bug 27181.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoelf: Make the tunable struct definition internal only
Szabolcs Nagy [Wed, 6 Jan 2021 17:19:24 +0000 (17:19 +0000)]
elf: Make the tunable struct definition internal only

The representation of the tunables including type information and
the tunable list structure are only used in the implementation not
in the tunables api that is exposed to usage within glibc.

This patch moves the representation related definitions into the
existing dl-tunable-types.h and uses that only for implementation.

The tunable callback and related types are moved to dl-tunables.h
because they are part of the tunables api.

This reduces the details exposed in the tunables api so the internals
are easier to change.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years ago<sys/platform/x86.h>: Remove the C preprocessor magic
H.J. Lu [Fri, 25 Dec 2020 15:30:46 +0000 (07:30 -0800)]
<sys/platform/x86.h>: Remove the C preprocessor magic

In <sys/platform/x86.h>, define CPU features as enum instead of using
the C preprocessor magic to make it easier to wrap this functionality
in other languages.  Move the C preprocessor magic to internal header
for better GCC codegen when more than one features are checked in a
single expression as in x86-64 dl-hwcaps-subdirs.c.

1. Rename COMMON_CPUID_INDEX_XXX to CPUID_INDEX_XXX.
2. Move CPUID_INDEX_MAX to sysdeps/x86/include/cpu-features.h.
3. Remove struct cpu_features and __x86_get_cpu_features from
<sys/platform/x86.h>.
4. Add __x86_get_cpuid_feature_leaf to <sys/platform/x86.h> and put it
in libc.
5. Make __get_cpu_features() private to glibc.
6. Replace __x86_get_cpu_features(N) with __get_cpu_features().
7. Add _dl_x86_get_cpu_features to GLIBC_PRIVATE.
8. Use a single enum index for each CPU feature detection.
9. Pass the CPUID feature leaf to __x86_get_cpuid_feature_leaf.
10. Return zero struct cpuid_feature for the older glibc binary with a
smaller CPUID_INDEX_MAX [BZ #27104].
11. Inside glibc, use the C preprocessor magic so that cpu_features data
can be loaded just once leading to more compact code for glibc.

256 bits are used for each CPUID leaf.  Some leaves only contain a few
features.  We can add exceptions to such leaves.  But it will increase
code sizes and it is harder to provide backward/forward compatibilities
when new features are added to such leaves in the future.

When new leaves are added, _rtld_global_ro offsets will change which
leads to race condition during in-place updates. We may avoid in-place
updates by

1. Rename the old glibc.
2. Install the new glibc.
3. Remove the old glibc.

NB: A function, __x86_get_cpuid_feature_leaf , is used to avoid the copy
relocation issue with IFUNC resolver as shown in IFUNC resolver tests.

3 years agoposix: Fix fnmatch.c on bootstrap
Adhemerval Zanella [Wed, 20 Jan 2021 16:07:59 +0000 (16:07 +0000)]
posix: Fix fnmatch.c on bootstrap

Only define FALLTHROUGH for _LIBC and do not check __clang_major__
value.

It partially syncs with gnulib 5c52f00c69f39fe.

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

3 years agostdlib: Add testcase for BZ #26241
Adhemerval Zanella [Tue, 29 Dec 2020 15:24:28 +0000 (12:24 -0300)]
stdlib: Add testcase for BZ #26241

Old implementation of realpath allocates a PATH_MAX using alloca for
each symlink in the path, leading to MAXSYMLINKS times PATH_MAX
maximum stack usage.

The test create a symlink with __eloop_threshold() loops and creates
a thread with minimum stack size (obtained through
support_small_stack_thread_attribute).  The thread issues a stack
allocations that fill the thread allocated stack minus some slack
plus and the realpath usage (which assumes a bounded stack usage).
If realpath uses more than about 2 * PATH_MAX plus some slack it
triggers a stackoverflow.

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

Reviewed-by: DJ Delorie <dj@redhat.com>
3 years agoposix: Fix regex_internal.h on bootstrap
Adhemerval Zanella [Wed, 20 Jan 2021 12:55:17 +0000 (12:55 +0000)]
posix: Fix regex_internal.h on bootstrap

Only define FALLTHROUGH for _LIBC and do not check __clang_major__
value.

It partially syncs with gnulib 5c52f00c69f39fe.

Checked with build-many-glibcs.py for aarch64-linux-gnu,
x86_64-linux-gnu, and s390x-linux-gnu.

3 years agoUse <startup.h> in __libc_init_secure
H.J. Lu [Fri, 15 Jan 2021 14:46:12 +0000 (06:46 -0800)]
Use <startup.h> in __libc_init_secure

Since __libc_init_secure is called before ARCH_SETUP_TLS, it must use
"int $0x80" for system calls in i386 static PIE.  Add startup_getuid,
startup_geteuid, startup_getgid and startup_getegid to <startup.h>.
Update __libc_init_secure to use them.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoelf: Avoid RELATIVE relocation for _dl_sysinfo
H.J. Lu [Mon, 18 Jan 2021 11:45:46 +0000 (11:45 +0000)]
elf: Avoid RELATIVE relocation for _dl_sysinfo

Set the default _dl_sysinfo in _dl_aux_init to avoid RELATIVE relocation
in static PIE.

This is needed for fixing bug 27072 on x86.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agolibmvec: Add extra-test-objs to test-extras
H.J. Lu [Fri, 15 Jan 2021 02:39:24 +0000 (18:39 -0800)]
libmvec: Add extra-test-objs to test-extras

Add extra-test-objs to test-extras so that they are compiled with
-DMODULE_NAME=testsuite instead of -DMODULE_NAME=libc.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoHurd: Add rtld-strncpy-c.c
H.J. Lu [Tue, 19 Jan 2021 02:19:16 +0000 (18:19 -0800)]
Hurd: Add rtld-strncpy-c.c

All IFUNC functions which are used in ld.so must have a rtld version if
the IFUNC version isn't safe to use in ld.so.

3 years agoUpdate MIPS libm-test-ulps.
Joseph Myers [Mon, 18 Jan 2021 21:36:00 +0000 (21:36 +0000)]
Update MIPS libm-test-ulps.

3 years agoUpdate arm libm-test-ulps.
Joseph Myers [Mon, 18 Jan 2021 20:22:51 +0000 (20:22 +0000)]
Update arm libm-test-ulps.

3 years agoUpdate powerpc-nofpu libm-test-ulps.
Joseph Myers [Mon, 18 Jan 2021 20:21:07 +0000 (20:21 +0000)]
Update powerpc-nofpu libm-test-ulps.

3 years agoUpdate hppa libm-test-ulps
John David Anglin [Mon, 18 Jan 2021 14:23:10 +0000 (14:23 +0000)]
Update hppa libm-test-ulps

3 years agoARC: nofpu: Regenerate ulps
Vineet Gupta [Mon, 18 Jan 2021 00:39:45 +0000 (16:39 -0800)]
ARC: nofpu: Regenerate ulps

3 years agold.so: Add --list-tunables to print tunable values
H.J. Lu [Sun, 12 Jul 2020 13:04:53 +0000 (06:04 -0700)]
ld.so: Add --list-tunables to print tunable values

Pass --list-tunables to ld.so to print tunables with min and max values.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agomath/test-tgmath2: Fix fabs failure when no long double
Stafford Horne [Thu, 7 Jan 2021 21:45:36 +0000 (06:45 +0900)]
math/test-tgmath2: Fix fabs failure when no long double

I have been testing with GCC trunk and GLIBC master while working on the
OpenRISC port.  This test has been failing with fabs not being called,
This is caused as my architecture is configure with no long double
meaning the two calls are the same:

  TEST (fabs (Vdouble1), double, fabs);
  TEST (fabs (Vldouble1), ldouble, fabs);

Instead of the tgmath calls resolving to fabs and fabsl both calls are
fabs.  Next, do to compiler optimiations the second call is eliminated.
Fix this by invoking the failing TEST with Vldouble2.

Note, I also updated the FAIL message to more clearly show where the
failure happened, so I see:

  FAIL: math/test-tgmath2
  original exit status 1
  wrong function called, fabs (ldouble) failure on line 174

Cc: Joseph Myers <joseph@codesourcery.com>
3 years agox86: Move x86 processor cache info to cpu_features
H.J. Lu [Fri, 18 Sep 2020 14:55:14 +0000 (07:55 -0700)]
x86: Move x86 processor cache info to cpu_features

1. Move x86 processor cache info to _dl_x86_cpu_features in ld.so.
2. Update tunable bounds with TUNABLE_SET_WITH_BOUNDS.
3. Move x86 cache info initialization to dl-cacheinfo.h and initialize
x86 cache info in init_cpu_features ().
4. Put x86 cache info for libc in cacheinfo.h, which is included in
libc-start.c in libc.a and is included in cacheinfo.c in libc.so.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoFix x86 build with --enable-tunable=no
Adhemerval Zanella [Thu, 14 Jan 2021 14:18:21 +0000 (11:18 -0300)]
Fix x86 build with --enable-tunable=no

Checked on x86_64-linux-gnu.

3 years agoifuncmain6pie: Remove the circular IFUNC dependency [BZ #20019]
H.J. Lu [Mon, 4 Jan 2021 22:25:39 +0000 (14:25 -0800)]
ifuncmain6pie: Remove the circular IFUNC dependency [BZ #20019]

On x86, ifuncmain6pie failed with:

[hjl@gnu-cfl-2 build-i686-linux]$ ./elf/ifuncmain6pie --direct
./elf/ifuncmain6pie: IFUNC symbol 'foo' referenced in '/export/build/gnu/tools-build/glibc-32bit/build-i686-linux/elf/ifuncmod6.so' is defined in the executable and creates an unsatisfiable circular dependency.
[hjl@gnu-cfl-2 build-i686-linux]$ readelf -rW elf/ifuncmod6.so | grep foo
00003ff4  00000706 R_386_GLOB_DAT         0000400c   foo_ptr
00003ff8  00000406 R_386_GLOB_DAT         00000000   foo
0000400c  00000401 R_386_32               00000000   foo
[hjl@gnu-cfl-2 build-i686-linux]$

Remove non-JUMP_SLOT relocations against foo in ifuncmod6.so, which
trigger the circular IFUNC dependency, and build ifuncmain6pie with
-Wl,-z,lazy.

3 years agoUse the right argument code in unnormal tests
Siddhesh Poyarekar [Wed, 13 Jan 2021 03:38:07 +0000 (09:08 +0530)]
Use the right argument code in unnormal tests

Use the right argument code (j) in the unnormal tests and cast inputs
from the ieee_long_double_shape_type struct to Float64x to properly
test it.

3 years agoldconfig/x86: Store ISA level in cache and aux cache
H.J. Lu [Sat, 5 Dec 2020 15:01:58 +0000 (07:01 -0800)]
ldconfig/x86: Store ISA level in cache and aux cache

Store ISA level in the portion of the unused upper 32 bits of the hwcaps
field in cache and the unused pad field in aux cache.  ISA level is stored
and checked only for shared objects in glibc-hwcaps subdirectories.  The
shared objects in the default directories aren't checked since there are
no fallbacks for these shared objects.

Tested on x86-64-v2, x86-64-v3 and x86-64-v4 machines with
--disable-hardcoded-path-in-tests and --enable-hardcoded-path-in-tests.

3 years agoelf: work around a gcc bug in elf_get_dynamic_info
Szabolcs Nagy [Mon, 11 Jan 2021 09:04:53 +0000 (09:04 +0000)]
elf: work around a gcc bug in elf_get_dynamic_info

Since commit 2f056e8a5dd4dc0f075413f931e82cede37d1057
"aarch64: define PI_STATIC_AND_HIDDEN",
building glibc with gcc-8 on aarch64 fails with

/BLD/elf/librtld.os: in function `elf_get_dynamic_info':
/SRC/elf/get-dynamic-info.h:70:(.text+0xad8): relocation truncated to
 fit: R_AARCH64_ADR_PREL_PG_HI21 against symbol `_rtld_local' defined
 in .data section in /BLD/elf/librtld.os

This is a gcc bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98618
The bug is fixed on gcc-10 and not yet backported. gcc-9 is affected,
but the issue happens to not trigger in glibc, gcc-8 and older seems
to miscompile rtld.os.

Rewriting the affected code in elf_get_dynamic_info seems to make the
issue go away on <= gcc-9.

The change makes the logic a bit clearer too (by separating the index
computation and array update) and drops an older gcc workaround (since
gcc 4.6 is no longer supported).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agox86: Set header.feature_1 in TCB for always-on CET [BZ #27177]
H.J. Lu [Wed, 13 Jan 2021 03:00:13 +0000 (19:00 -0800)]
x86: Set header.feature_1 in TCB for always-on CET [BZ #27177]

Update dl_cet_check() to set header.feature_1 in TCB when both IBT and
SHSTK are always on.

3 years agoposix: consume less entropy on tempname
Adhemerval Zanella [Tue, 12 Jan 2021 12:17:09 +0000 (09:17 -0300)]
posix: consume less entropy on tempname

The first getrandom is used only for __GT_NOCREATE, which is inherently
insecure and can use the entropy as a small improvement.  On the
second and later attempts it might help against DoS attacks.

It sync with gnulib commit 854fbb81d91f7a0f2b463e7ace2499dee2f380f2.

Checked on x86_64-linux-gnu.

3 years agoMakerules: Do not require startup files for format.lds probe object
Florian Weimer [Tue, 12 Jan 2021 11:22:47 +0000 (12:22 +0100)]
Makerules: Do not require startup files for format.lds probe object

During statically linked bootstrap, the compiler does not have
the required startup files, so do a smaller dummy link to obtain
the output format information.

Fixes commit 87d583c6e8cd0e49f64da76636ebeec033298b4d ("install:
Replace scripts/output-format.sed with objdump -f [BZ #26559]").

3 years agoinstall: Replace scripts/output-format.sed with objdump -f [BZ #26559]
Fangrui Song [Mon, 11 Jan 2021 19:56:54 +0000 (11:56 -0800)]
install: Replace scripts/output-format.sed with objdump -f [BZ #26559]

GNU ld and gold have supported --print-output-format since 2011. glibc
requires binutils>=2.25 (2015), so if LD is GNU ld or gold, we can
assume the option is supported.

lld is by default a cross linker supporting multiple targets. It auto
detects the file format and does not need OUTPUT_FORMAT. It does not
support --print-output-format.

By parsing objdump -f, we can support all the three linkers.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agomath: Add BZ#18980 fix back on dbl-64 cosh
Adhemerval Zanella [Mon, 11 Jan 2021 19:38:40 +0000 (16:38 -0300)]
math: Add BZ#18980 fix back on dbl-64 cosh

It is regression from 9e97f239eae1f2b1 (Remove dbl-64/wordsize-64
(part 2)) where is missed to add the BZ#18980 fix (9e97f239eae1f2b1).

Checked on i686-linux-gnu.

3 years agoposix: Sync tempname with gnulib [BZ #26648]
Adhemerval Zanella [Tue, 29 Sep 2020 11:56:07 +0000 (08:56 -0300)]
posix: Sync tempname with gnulib [BZ #26648]

It syncs with gnulib commit b1268f22f443e8e4b9e.  The try_tempname_len
now uses getrandom on each iteration to get entropy and only uses the
clock plus ASLR as source of entropy if getrandom fails.

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

3 years agoposix: Fix return value of system if shell can not be executed [BZ #27053]
Adhemerval Zanella [Fri, 11 Dec 2020 18:23:05 +0000 (15:23 -0300)]
posix: Fix return value of system if shell can not be executed [BZ #27053]

POSIX states that system returned code for failure to execute the shell
shall be as if the shell had terminated using _exit(127).  This
behaviour was removed with 5fb7fc96350575.

Checked on x86_64-linux-gnu.

3 years agosupport: Add xchmod wrapper
Adhemerval Zanella [Mon, 14 Dec 2020 14:42:33 +0000 (11:42 -0300)]
support: Add xchmod wrapper

Checked on x86_64-linux-gnu.

3 years agoUpdate STATX_ATTR_DAX value from Linux 5.10.
Joseph Myers [Mon, 11 Jan 2021 14:57:08 +0000 (14:57 +0000)]
Update STATX_ATTR_DAX value from Linux 5.10.

This patch updates the value of STATX_ATTR_DAX in bits/statx-generic.h
for a change made in Linux 5.10.  (As with previous such changes, this
only does anything if glibc is being used with old kernel headers.)

Tested for x86_64.

3 years agoriscv: Initialize $gp before resolving the IRELATIVE relocation
Vincent Chen [Tue, 15 Dec 2020 09:16:40 +0000 (17:16 +0800)]
riscv: Initialize $gp before resolving the IRELATIVE relocation

The $gp register may be used to access the global variable in
the PDE program, so the $gp register should be initialized before
executing the IFUNC resolver of PDE program to avoid unexpected
error occurs.

3 years agoriscv: support GNU indirect function
Vincent Chen [Tue, 15 Dec 2020 09:16:39 +0000 (17:16 +0800)]
riscv: support GNU indirect function

Enable riscv glibc to support GNU indirect function

3 years agoposix: Correct attribute access mode on readlinkat [BZ #27024].
Martin Sebor [Sun, 10 Jan 2021 20:45:39 +0000 (13:45 -0700)]
posix: Correct attribute access mode on readlinkat [BZ #27024].

3 years ago Add xfchmod to libsupport
Alexandra Hájková [Sat, 26 Dec 2020 19:44:34 +0000 (20:44 +0100)]
 Add xfchmod to libsupport

3 years agoAdd xchdir to libsupport.
Alexandra Hájková [Sat, 26 Dec 2020 17:45:13 +0000 (18:45 +0100)]
Add xchdir to libsupport.

3 years agoPOSIX locale: Fix typo in comment
Marc Aurèle La France [Sat, 9 Jan 2021 04:55:58 +0000 (21:55 -0700)]
POSIX locale: Fix typo in comment

3 years agoARC: Regenerate ulps
Vineet Gupta [Wed, 6 Jan 2021 18:52:40 +0000 (10:52 -0800)]
ARC: Regenerate ulps

Reinstate pass for

FAIL: math/test-double-cosh
FAIL: math/test-double-sinh
FAIL: math/test-float32x-cosh
FAIL: math/test-float32x-sinh
FAIL: math/test-float64-cosh
FAIL: math/test-float64-sinh
FAIL: math/test-ldouble-cosh
FAIL: math/test-ldouble-sinh

3 years agomntent: Use __putc_unlocked instead of fputc_unlocked
Siddhesh Poyarekar [Fri, 8 Jan 2021 15:31:25 +0000 (21:01 +0530)]
mntent: Use __putc_unlocked instead of fputc_unlocked

__putc_unlocked is guaranteed to be inlined all the time as opposed to
fputc_unlocked, which does not get inlined when glibc is built with
-Os.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
3 years agoaarch64: define PI_STATIC_AND_HIDDEN
Szabolcs Nagy [Tue, 5 Jan 2021 16:10:40 +0000 (16:10 +0000)]
aarch64: define PI_STATIC_AND_HIDDEN

AArch64 always uses pc relative access to static and hidden object
symbols, but the config setting was previously missing.

This affects ld.so start up code.

3 years agoUpdate NEWS for CVE-2019-25013.
Siddhesh Poyarekar [Fri, 8 Jan 2021 03:47:06 +0000 (09:17 +0530)]
Update NEWS for CVE-2019-25013.

3 years agox86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker [BZ #26717]
H.J. Lu [Fri, 9 Oct 2020 13:06:56 +0000 (06:06 -0700)]
x86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker [BZ #26717]

GCC 11 supports -march=x86-64-v[234] to enable x86 micro-architecture ISA
levels:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97250

and -mneeded to emit GNU_PROPERTY_X86_ISA_1_NEEDED property with
GNU_PROPERTY_X86_ISA_1_V[234] marker:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/13

Binutils support for GNU_PROPERTY_X86_ISA_1_V[234] marker were added by

commit b0ab06937385e0ae25cebf1991787d64f439bf12
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 30 06:49:57 2020 -0700

    x86: Support GNU_PROPERTY_X86_ISA_1_BASELINE marker

and

commit 32930e4edbc06bc6f10c435dbcc63131715df678
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 9 05:05:57 2020 -0700

    x86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker

GNU_PROPERTY_X86_ISA_1_NEEDED property in x86 ELF binaries indicate the
micro-architecture ISA level required to execute the binary.  The marker
must be added by programmers explicitly in one of 3 ways:

1. Pass -mneeded to GCC.
2. Add the marker in the linker inputs as this patch does.
3. Pass -z x86-64-v[234] to the linker.

Add GNU_PROPERTY_X86_ISA_1_BASELINE and GNU_PROPERTY_X86_ISA_1_V[234]
marker support to ld.so if binutils 2.32 or newer is used to build glibc:

1. Add GNU_PROPERTY_X86_ISA_1_BASELINE and GNU_PROPERTY_X86_ISA_1_V[234]
markers to elf.h.
2. Add GNU_PROPERTY_X86_ISA_1_BASELINE and GNU_PROPERTY_X86_ISA_1_V[234]
marker to abi-note.o based on the ISA level used to compile abi-note.o,
assuming that the same ISA level is used to compile the whole glibc.
3. Add isa_1 to cpu_features to record the supported x86 ISA level.
4. Rename _dl_process_cet_property_note to _dl_process_property_note and
add GNU_PROPERTY_X86_ISA_1_V[234] marker detection.
5. Update _rtld_main_check and _dl_open_check to check loaded objects
with the incompatible ISA level.
6. Add a testcase to verify that dlopen an x86-64-v4 shared object fails
on lesser platforms.
7. Use <get-isa-level.h> in dl-hwcaps-subdirs.c and tst-glibc-hwcaps.c.

Tested under i686, x32 and x86-64 modes on x86-64-v2, x86-64-v3 and
x86-64-v4 machines.

Marked elf/tst-isa-level-1 with x86-64-v4, ran it on x86-64-v3 machine
and got:

[hjl@gnu-cfl-2 build-x86_64-linux]$ ./elf/tst-isa-level-1
./elf/tst-isa-level-1: CPU ISA level is lower than required
[hjl@gnu-cfl-2 build-x86_64-linux]$

3 years agoRemove dbl-64/wordsize-64 (part 2)
Wilco Dijkstra [Thu, 7 Jan 2021 15:26:26 +0000 (15:26 +0000)]
Remove dbl-64/wordsize-64 (part 2)

Remove the wordsize-64 implementations by merging them into the main dbl-64
directory.  The second patch just moves all wordsize-64 files and removes a
few wordsize-64 uses in comments and Implies files.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoRemove dbl-64/wordsize-64
Wilco Dijkstra [Thu, 7 Jan 2021 15:02:51 +0000 (15:02 +0000)]
Remove dbl-64/wordsize-64

Remove the wordsize-64 implementations by merging them into the main dbl-64
directory.  The first patch adds special cases needed for 32-bit targets
(FIX_INT_FP_CONVERT_ZERO and FIX_DBL_LONG_CONVERT_OVERFLOW) to the
wordsize-64 versions.  This has no effect on 64-bit targets since they don't
define these macros.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoAdd SEGV_MTEAERR and SEGV_MTESERR from Linux 5.10.
Joseph Myers [Wed, 6 Jan 2021 18:23:00 +0000 (18:23 +0000)]
Add SEGV_MTEAERR and SEGV_MTESERR from Linux 5.10.

Linux 5.10 adds constants SEGV_MTEAERR and SEGV_MTESERR to
asm-generic/siginfo.h.  Add these to glibc's bits/siginfo-consts.h.

Tested for x86_64.

3 years agosupport: Add support_small_thread_stack_size
Adhemerval Zanella [Tue, 29 Dec 2020 14:52:41 +0000 (11:52 -0300)]
support: Add support_small_thread_stack_size

It returns the minimum stack size large enough to cover most internal
glibc stack usage.

3 years agostdlib: Sync canonicalize with gnulib [BZ #10635] [BZ #26592] [BZ #26341] [BZ #24970]
Adhemerval Zanella [Tue, 29 Dec 2020 14:37:34 +0000 (11:37 -0300)]
stdlib: Sync canonicalize with gnulib [BZ #10635] [BZ #26592] [BZ #26341] [BZ #24970]

It sync with gnulib version ae9fb3d66.  The testcase for BZ#23741
(stdlib/test-bz22786.c) is adjusted to check also for ENOMEM.

The patch fixes multiple realpath issues:

  - Portability fixes for errno clobbering on free (BZ#10635).  The
    function does not call free directly anymore, although it might be
    done through scratch_buffer_free.  The free errno clobbering is
    being tracked by BZ#17924.

  - Pointer arithmetic overflows in realpath (BZ#26592).

  - Realpath cyclically call __alloca(path_max) to consume too much
    stack space (BZ#26341).

  - Realpath mishandles EOVERFLOW; stat not needed anyway (BZ#24970).
    The check is done through faccessat now.

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

3 years agomalloc: Add scratch_buffer_dupfree
Adhemerval Zanella [Mon, 28 Dec 2020 12:50:23 +0000 (09:50 -0300)]
malloc: Add scratch_buffer_dupfree

It returns a copy of the buffer up to a defined size.  It will be used
on realpath sync with gnulib.

3 years agoImport filename.h from gnulib
Adhemerval Zanella [Tue, 29 Dec 2020 13:27:56 +0000 (10:27 -0300)]
Import filename.h from gnulib

And use to simplify stdlib/canonicalize.c implementation.

3 years agoImport idx.h from gnulib
Adhemerval Zanella [Tue, 29 Dec 2020 13:27:28 +0000 (10:27 -0300)]
Import idx.h from gnulib

And use to simplify stdlib/canonicalize.c implementation.

3 years agoalpha: Provide wait4 for static library [BZ #27150]
Adhemerval Zanella [Tue, 5 Jan 2021 14:22:25 +0000 (11:22 -0300)]
alpha: Provide wait4 for static library [BZ #27150]

This ia regression from 09153638cfef91, versioned_symbol acts as
weak_alias for !SHARED but it is undefined to avoid non versioned
alias from the generic implementation.

Checked with a build for alpha-linux-gnu.

3 years agoaarch64: push the set of rules before falling into slow path
Shuo Wang [Tue, 5 Jan 2021 02:04:12 +0000 (10:04 +0800)]
aarch64: push the set of rules before falling into slow path

It is supposed to save the rules for the instructions before falling into slow path.

Tested in glibc-2.28 before fixing:
Thread 2 "xxxxxxx" hit Breakpoint 1, _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:149
149 stp x1,  x2, [sp, #-32]!
Missing separate debuginfos, use: dnf debuginfo-install libgcc-7.3.0-20190804.h24.aarch64
(gdb) ni
_dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:150
150 stp x3,  x4, [sp, #16]
(gdb)
_dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:157
157 mrs x4, tpidr_el0
(gdb)
158 ldr PTR_REG (1), [x0,#TLSDESC_ARG]
(gdb)
159 ldr PTR_REG (0), [x4,#TCBHEAD_DTV]
(gdb)
160 ldr PTR_REG (3), [x1,#TLSDESC_GEN_COUNT]
(gdb)
161 ldr PTR_REG (2), [x0,#DTV_COUNTER]
(gdb)
162 cmp PTR_REG (3), PTR_REG (2)
(gdb)
163 b.hi 2f
(gdb)
165 ldp PTR_REG (2), PTR_REG (3), [x1,#TLSDESC_MODID]
(gdb)
166 add PTR_REG (0), PTR_REG (0), PTR_REG (2), lsl #(PTR_LOG_SIZE + 1)
(gdb)
167 ldr PTR_REG (0), [x0] /* Load val member of DTV entry.  */
(gdb)
168 cmp PTR_REG (0), #TLS_DTV_UNALLOCATED
(gdb)
169 b.eq 2f
(gdb) bt
#0  _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:169
#1  0x0000ffffbe4fbb44 in OurFunction (threadId=4294967295)
    at /home/test/test_function.c:30
#2  0x0000000000400c08 in initaaa () at thread.c:58
#3  0x0000000000400c50 in thread_proc (param=0x0) at thread.c:71
#4  0x0000ffffbf6918bc in start_thread (arg=0xfffffffff29f) at pthread_create.c:486
#5  0x0000ffffbf5669ec in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78
(gdb) ni
_dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:184
184 stp x29, x30, [sp,#-16*NSAVEXREGPAIRS]!
(gdb) bt
#0  _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:184
#1  0x0000ffffbe4fbb44 in OurFunction (threadId=4294967295)
    at /home/test/test_function.c:30
#2  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Co-authored-by: liqingqing <liqingqing3@huawei.com>
3 years agonptl: Fix comment typo in pthread_cond_wait.c
Jangwoong Kim [Sat, 2 Jan 2021 11:57:37 +0000 (20:57 +0900)]
nptl: Fix comment typo in pthread_cond_wait.c

3 years agox86: Check IFUNC definition in unrelocated executable [BZ #20019]
H.J. Lu [Mon, 28 Dec 2020 13:28:49 +0000 (05:28 -0800)]
x86: Check IFUNC definition in unrelocated executable [BZ #20019]

Calling an IFUNC function defined in unrelocated executable also leads to
segfault.  Issue a fatal error message when calling IFUNC function defined
in the unrelocated executable from a shared library.

3 years agohurd: Fix mmap(!MAP_FIXED) on bogus address
Samuel Thibault [Mon, 4 Jan 2021 19:22:59 +0000 (20:22 +0100)]
hurd: Fix mmap(!MAP_FIXED) on bogus address

In the !MAP_FIXED case, when a bogus address is given mmap should pick up a
valide address rather than returning EINVAL: Posix only talks about
EINVAL for the MAP_FIXED case.

This fixes long-running ghc processes.

3 years agox86-64: Avoid rep movsb with short distance [BZ #27130]
H.J. Lu [Sat, 25 Jan 2020 22:19:40 +0000 (14:19 -0800)]
x86-64: Avoid rep movsb with short distance [BZ #27130]

When copying with "rep movsb", if the distance between source and
destination is N*4GB + [1..63] with N >= 0, performance may be very
slow.  This patch updates memmove-vec-unaligned-erms.S for AVX and
AVX512 versions with the distance in RCX:

cmpl $63, %ecx
// Don't use "rep movsb" if ECX <= 63
jbe L(Don't use rep movsb")
Use "rep movsb"

Benchtests data with bench-memcpy, bench-memcpy-large, bench-memcpy-random
and bench-memcpy-walk on Skylake, Ice Lake and Tiger Lake show that its
performance impact is within noise range as "rep movsb" is only used for
data size >= 4KB.

3 years agoaarch64: fix stack missing after sp is updated
Shuo Wang [Mon, 4 Jan 2021 12:42:52 +0000 (20:42 +0800)]
aarch64: fix stack missing after sp is updated

After sp is updated, the CFA offset should be set before next instruction.
Tested in glibc-2.28:
Thread 2 "xxxxxxx" hit Breakpoint 1, _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:149
149 stp x1,  x2, [sp, #-32]!
Missing separate debuginfos, use: dnf debuginfo-install libgcc-7.3.0-20190804.h24.aarch64
(gdb) bt
#0  _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:149
#1  0x0000ffffbe4fbb44 in OurFunction (threadId=3194870184)
    at /home/test/test_function.c:30
#2  0x0000000000400c08 in initaaa () at thread.c:58
#3  0x0000000000400c50 in thread_proc (param=0x0) at thread.c:71
#4  0x0000ffffbf6918bc in start_thread (arg=0xfffffffff29f) at pthread_create.c:486
#5  0x0000ffffbf5669ec in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78
(gdb) ni
_dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:150
150 stp x3,  x4, [sp, #16]
(gdb) bt
#0  _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:150
#1  0x0000ffffbe4fbb44 in OurFunction (threadId=3194870184)
    at /home/test/test_function.c:30
#2  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) ni
_dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:157
157 mrs x4, tpidr_el0
(gdb) bt
#0  _dl_tlsdesc_dynamic () at ../sysdeps/aarch64/dl-tlsdesc.S:157
#1  0x0000ffffbe4fbb44 in OurFunction (threadId=3194870184)
    at /home/test/test_function.c:30
#2  0x0000000000400c08 in initaaa () at thread.c:58
#3  0x0000000000400c50 in thread_proc (param=0x0) at thread.c:71
#4  0x0000ffffbf6918bc in start_thread (arg=0xfffffffff29f) at pthread_create.c:486
#5  0x0000ffffbf5669ec in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

Signed-off-by: liqingqing <liqingqing3@huawei.com>
Signed-off-by: Shuo Wang <wangshuo47@huawei.com>
3 years agonptl: Remove set*id, set*gid files which are not built
Florian Weimer [Mon, 4 Jan 2021 15:27:46 +0000 (16:27 +0100)]
nptl: Remove set*id, set*gid files which are not built

3 years agoDrop nan-pseudo-number.h usage from tests
Siddhesh Poyarekar [Mon, 4 Jan 2021 12:10:04 +0000 (17:40 +0530)]
Drop nan-pseudo-number.h usage from tests

Make the tests use TEST_COND_intel96 to decide on whether to build the
unnormal tests instead of the macro in nan-pseudo-number.h and then
drop the header inclusion.  This unbreaks test runs on all
architectures that do not have ldbl-96.

Also drop the HANDLE_PSEUDO_NUMBERS macro since it is not used
anywhere.

3 years agoposix: Sync fnmatch with gnulib
Adhemerval Zanella [Wed, 30 Dec 2020 19:15:38 +0000 (16:15 -0300)]
posix: Sync fnmatch with gnulib

It sync with gnulib commit 43ee1a6bf.

Checked on x86_64-linux-gnu.

3 years agoSync flexmember.h with gnulib
Adhemerval Zanella [Wed, 30 Dec 2020 19:14:58 +0000 (16:14 -0300)]
Sync flexmember.h with gnulib

It sync with gnulib commit 43ee1a6bf.

3 years agoSync intprops.h with gnulib
Adhemerval Zanella [Tue, 29 Dec 2020 20:42:52 +0000 (17:42 -0300)]
Sync intprops.h with gnulib

It sync with gnulib commit 43ee1a6bf.

Checked on x86_64-linux-gnu.

3 years agoposix: Sync glob code with gnulib
Adhemerval Zanella [Tue, 29 Dec 2020 20:41:19 +0000 (17:41 -0300)]
posix: Sync glob code with gnulib

It sync with gnulib commit 43ee1a6bf and fixes and use-after-free
bug (gnulib commit 717766da8926e36).

Checked on x86_64-linux-gnu.

3 years agoposix: Sync regex code with gnulib
Adhemerval Zanella [Tue, 29 Dec 2020 20:32:25 +0000 (17:32 -0300)]
posix: Sync regex code with gnulib

It sync with gnulib commit 43ee1a6bf.  The main change is 9682f18e9.
(which does not have a meaniful description).

Checked on x86_64-linux-gnu.

3 years agoMove generic nan-pseudo-number.h to ldbl-96
Siddhesh Poyarekar [Fri, 1 Jan 2021 00:57:11 +0000 (06:27 +0530)]
Move generic nan-pseudo-number.h to ldbl-96

The concept of pseudo number formats only exists in the realm of the
96 bit long double format.

3 years agoSync FDL from https://www.gnu.org/licenses/fdl-1.3.texi
Paul Eggert [Sat, 2 Jan 2021 20:46:25 +0000 (12:46 -0800)]
Sync FDL from https://www.gnu.org/licenses/fdl-1.3.texi

3 years agoSync move-if-change from Gnulib
Paul Eggert [Sat, 2 Jan 2021 20:43:58 +0000 (12:43 -0800)]
Sync move-if-change from Gnulib

This alters move-if-change so that its --version option outputs
the correct copyright date automatically.  One less thing
to update by hand.

3 years agoUpdate automatically-generated copyright dates
Paul Eggert [Sat, 2 Jan 2021 19:56:24 +0000 (11:56 -0800)]
Update automatically-generated copyright dates

These were updated simply by running "make" to regen the files.

3 years agoUpdate copyright dates not handled by scripts/update-copyrights.
Paul Eggert [Sat, 2 Jan 2021 19:47:54 +0000 (11:47 -0800)]
Update copyright dates not handled by scripts/update-copyrights.

I've updated copyright dates in glibc for 2021.  This is the patch for
the changes not generated by scripts/update-copyrights and subsequent
build / regeneration of generated files.  As well as the usual annual
updates, mainly dates in --version output (minus csu/version.c which
previously had to be handled manually but is now successfully updated
by update-copyrights), there is a small change to the copyright notice
in NEWS which should let NEWS get updated automatically next year.

Please remember to include 2021 in the dates for any new files added
in future (which means updating any existing uncommitted patches you
have that add new files to use the new copyright dates in them).

3 years agoUpdate copyright dates with scripts/update-copyrights
Paul Eggert [Sat, 2 Jan 2021 19:32:25 +0000 (11:32 -0800)]
Update copyright dates with scripts/update-copyrights

I used these shell commands:

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

and then ignored the output, which consisted lines saying "FOO: warning:
copyright statement not found" for each of 6694 files FOO.
I then removed trailing white space from benchtests/bench-pthread-locks.c
and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this
diagnostic from Savannah:
remote: *** pre-commit check failed ...
remote: *** error: lines with trailing whitespace found
remote: error: hook declined to update refs/heads/master

3 years agoaarch64: use PTR_ARG and SIZE_ARG instead of DELOUSE
Szabolcs Nagy [Thu, 17 Dec 2020 10:03:05 +0000 (10:03 +0000)]
aarch64: use PTR_ARG and SIZE_ARG instead of DELOUSE

DELOUSE was added to asm code to make them compatible with non-LP64
ABIs, but it is an unfortunate name and the code was not compatible
with ABIs where pointer and size_t are different. Glibc currently
only supports the LP64 ABI so these macros are not really needed or
tested, but for now the name is changed to be more meaningful instead
of removing them completely.

Some DELOUSE macros were dropped: clone, strlen and strnlen used it
unnecessarily.

The out of tree ILP32 patches are currently not maintained and will
likely need a rework to rebase them on top of the time64 changes.

3 years agononstring: Enable __FORTIFY_LEVEL=3
Siddhesh Poyarekar [Tue, 15 Dec 2020 18:20:09 +0000 (23:50 +0530)]
nonstring: Enable __FORTIFY_LEVEL=3

Use __builtin_dynamic_object_size in the remaining functions that
don't have compiler builtins as is the case for string functions.

3 years agostring: Enable __FORTIFY_LEVEL=3
Siddhesh Poyarekar [Wed, 30 Dec 2020 05:39:58 +0000 (11:09 +0530)]
string: Enable __FORTIFY_LEVEL=3

This change enhances fortified string functions to use
__builtin_dynamic_object_size under _FORTIFY_SOURCE=3 whenever the
compiler supports it.

3 years agoIntroduce _FORTIFY_SOURCE=3
Siddhesh Poyarekar [Wed, 30 Dec 2020 06:24:00 +0000 (11:54 +0530)]
Introduce _FORTIFY_SOURCE=3

Introduce a new _FORTIFY_SOURCE level of 3 to enable additional
fortifications that may have a noticeable performance impact, allowing
more fortification coverage at the cost of some performance.

With llvm 9.0 or later, this will replace the use of
__builtin_object_size with __builtin_dynamic_object_size.

__builtin_dynamic_object_size
-----------------------------

__builtin_dynamic_object_size is an LLVM builtin that is similar to
__builtin_object_size.  In addition to what __builtin_object_size
does, i.e. replace the builtin call with a constant object size,
__builtin_dynamic_object_size will replace the call site with an
expression that evaluates to the object size, thus expanding its
applicability.  In practice, __builtin_dynamic_object_size evaluates
these expressions through malloc/calloc calls that it can associate
with the object being evaluated.

A simple motivating example is below; -D_FORTIFY_SOURCE=2 would miss
this and emit memcpy, but -D_FORTIFY_SOURCE=3 with the help of
__builtin_dynamic_object_size is able to emit __memcpy_chk with the
allocation size expression passed into the function:

void *copy_obj (const void *src, size_t alloc, size_t copysize)
{
  void *obj = malloc (alloc);
  memcpy (obj, src, copysize);
  return obj;
}

Limitations
-----------

If the object was allocated elsewhere that the compiler cannot see, or
if it was allocated in the function with a function that the compiler
does not recognize as an allocator then __builtin_dynamic_object_size
also returns -1.

Further, the expression used to compute object size may be non-trivial
and may potentially incur a noticeable performance impact.  These
fortifications are hence enabled at a new _FORTIFY_SOURCE level to
allow developers to make a choice on the tradeoff according to their
environment.

3 years agoWarn on unsupported fortification levels
Siddhesh Poyarekar [Thu, 10 Dec 2020 11:17:02 +0000 (16:47 +0530)]
Warn on unsupported fortification levels

Make the _FORTIFY_SOURCE macro soup in features.h warn about
unsupported fortification levels.  For example, it will warn about
_FORTIFY_SOURCE=3 and over with an indication of which level has been
selected.

Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
3 years agopowerpc: Use scv instruction on clone when available
Matheus Castanho [Thu, 3 Dec 2020 17:15:28 +0000 (14:15 -0300)]
powerpc: Use scv instruction on clone when available

clone already uses r31 to temporarily save input arguments before doing the
syscall, so we use a different register to read from the TCB. We can also avoid
allocating another stack frame, which is not needed since we can simply extend
the usage of the red zone.

Tested-by: Lucas A. M. Magalhães <lamm@linux.ibm.com>
Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
3 years agopowerpc: Runtime selection between sc and scv for syscalls
Matheus Castanho [Thu, 3 Dec 2020 17:15:27 +0000 (14:15 -0300)]
powerpc: Runtime selection between sc and scv for syscalls

Linux kernel v5.9 added support for system calls using the scv
instruction for POWER9 and later.  The new codepath provides better
performance (see below) if compared to using sc.  For the
foreseeable future, both sc and scv mechanisms will co-exist, so this
patch enables glibc to do a runtime check and use scv when it is
available.

Before issuing the system call to the kernel, we check hwcap2 in the TCB
for PPC_FEATURE2_SCV to see if scv is supported by the kernel.  If not,
we fallback to sc and keep the old behavior.

The kernel implements a different error return convention for scv, so
when returning from a system call we need to handle the return value
differently depending on the instruction we used to enter the kernel.

For syscalls implemented in ASM, entry and exit are implemented by
different macros (PSEUDO and PSEUDO_RET, resp.), which may be used in
sequence (e.g. for templated syscalls) or with other instructions in
between (e.g. clone).  To avoid accessing the TCB a second time on
PSEUDO_RET to check which instruction we used, the value read from
hwcap2 is cached on a non-volatile register.

This is not needed when using INTERNAL_SYSCALL macro, since entry and
exit are bundled into the same inline asm directive.

The dynamic loader may issue syscalls before the TCB has been setup
so it always uses sc with no extra checks.  For the static case, there
is no compile-time way to determine if we are inside startup code,
so we also check the value of the thread pointer before effectively
accessing the TCB.  For such situations in which the availability of
scv cannot be determined, sc is always used.

Support for scv in syscalls implemented in their own ASM file (clone and
vfork) will be added later. For now simply use sc as before.

Average performance over 1M calls for each syscall "type":
  - stat: C wrapper calling INTERNAL_SYSCALL
  - getpid: templated ASM syscall
  - syscall: call to gettid using syscall function

  Standard:
     stat : 1.573445 us / ~3619 cycles
   getpid : 0.164986 us / ~379 cycles
  syscall : 0.162743 us / ~374 cycles

  With scv:
     stat : 1.537049 us / ~3535 cycles <~ -84 cycles  / -2.32%
   getpid : 0.109923 us / ~253 cycles  <~ -126 cycles / -33.25%
  syscall : 0.116410 us / ~268 cycles  <~ -106 cycles / -28.34%

Tested on powerpc, powerpc64, powerpc64le (with and without scv)

Tested-by: Lucas A. M. Magalhães <lamm@linux.ibm.com>
Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
3 years agomalloc: preserve errno on mcheck hooks [BZ #17924]
Adhemerval Zanella [Tue, 29 Dec 2020 20:12:21 +0000 (17:12 -0300)]
malloc: preserve errno on mcheck hooks [BZ #17924]

Similar to the fix 69fda43b8d, save and restore errno for the hook
functions used for MALLOC_CHECK_=3.

It fixes the malloc/tst-free-errno-mcheck regression.

Checked on x86_64-linux-gnu.

3 years agox86 long double: Add tests for pseudo normal numbers
Siddhesh Poyarekar [Thu, 24 Dec 2020 02:44:20 +0000 (08:14 +0530)]
x86 long double: Add tests for pseudo normal numbers

Add some tests for fpclassify, isnan, isinf and issignaling.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agox86 long double: Consider pseudo numbers as signaling
Siddhesh Poyarekar [Thu, 24 Dec 2020 02:27:25 +0000 (07:57 +0530)]
x86 long double: Consider pseudo numbers as signaling

Add support to treat pseudo-numbers specially and implement x86
version to consider all of them as signaling.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoio: Remove xmknod{at} implementations
Adhemerval Zanella [Mon, 26 Oct 2020 11:58:01 +0000 (08:58 -0300)]
io: Remove xmknod{at} implementations

With xmknod wrapper functions removed (589260cef8), the mknod functions
are now properly exported, and version is done using symbols versioning
instead of the extra _MKNOD_* argument.

It also allows us to consolidate Linux and Hurd mknod implementation.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agoio: Remove xstat implementations
Adhemerval Zanella [Fri, 23 Oct 2020 19:40:06 +0000 (16:40 -0300)]
io: Remove xstat implementations

With xstat wrapper functions removed (8ed005daf0), the stat functions
are now properly exported, and version is done using symbols versioning
instead of the extra _STAT_* argument.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
3 years agofree: preserve errno [BZ#17924]
Paul Eggert [Tue, 29 Dec 2020 08:45:49 +0000 (00:45 -0800)]
free: preserve errno [BZ#17924]

In the next release of POSIX, free must preserve errno
<https://www.austingroupbugs.net/view.php?id=385>.
Modify __libc_free to save and restore errno, so that
any internal munmap etc. syscalls do not disturb the caller's errno.
Add a test malloc/tst-free-errno.c (almost all by Bruno Haible),
and document that free preserves errno.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agohurd: Accept including hurd/version.h
Samuel Thibault [Tue, 29 Dec 2020 02:26:12 +0000 (03:26 +0100)]
hurd: Accept including hurd/version.h

We need it to get the RPC API version.

3 years agohurd: Add WSTOPPED/WCONTINUED/WEXITED/WNOWAIT support [BZ #23091]
Samuel Thibault [Mon, 28 Dec 2020 22:37:04 +0000 (23:37 +0100)]
hurd: Add WSTOPPED/WCONTINUED/WEXITED/WNOWAIT support [BZ #23091]

The new __proc_waitid RPC now expects WEXITED to be passed, allowing to
properly implement waitid, and thus define the missing W* macros
(according to FreeBSD values).

3 years agosupport: Make support_process_state_wait wait less
Samuel Thibault [Mon, 28 Dec 2020 22:05:14 +0000 (23:05 +0100)]
support: Make support_process_state_wait wait less

Tests such as posix/tst-waitid.c make heavy use of
support_process_state_wait, and thus on non-Linux where it falls back
to sleeping, a 2s sleep makes such test time out, while 1s remains
fine enough.

3 years agohurd: set sigaction for signal preemptors in arch-independent file
Samuel Thibault [Sat, 26 Dec 2020 16:57:52 +0000 (17:57 +0100)]
hurd: set sigaction for signal preemptors in arch-independent file

Instead of having the arch-specific trampoline setup code detect whether
preemption happened or not, we'd rather pass it the sigaction. In the
future, this may also allow to change sa_flags from post_signal().

3 years agohurd: Fix spawni SPAWN_XFLAGS_TRY_SHELL with empty argv
Samuel Thibault [Sat, 26 Dec 2020 15:39:40 +0000 (16:39 +0100)]
hurd: Fix spawni SPAWN_XFLAGS_TRY_SHELL with empty argv

When argv is empty, we need to add the original script to be run on the
shell command line.

3 years agohurd: Try shell in posix_spawn* only in compat mode
Samuel Thibault [Sat, 26 Dec 2020 14:12:04 +0000 (15:12 +0100)]
hurd: Try shell in posix_spawn* only in compat mode

Reported by Bruno Haible <bruno@clisp.org>

3 years agoRemove _ISOMAC check from <cpu-features.h>
H.J. Lu [Thu, 24 Dec 2020 23:43:34 +0000 (15:43 -0800)]
Remove _ISOMAC check from <cpu-features.h>

Remove _ISOMAC check from <cpu-features.h> since it isn't an installer
header file.

3 years agox86: Remove the duplicated CPU_FEATURE_CPU_P
H.J. Lu [Thu, 24 Dec 2020 02:34:34 +0000 (18:34 -0800)]
x86: Remove the duplicated CPU_FEATURE_CPU_P

CPU_FEATURE_CPU_P is defined in sysdeps/x86/sys/platform/x86.h.  Remove
the duplicated CPU_FEATURE_CPU_P in sysdeps/x86/include/cpu-features.h.

3 years agoPartially revert 681900d29683722b1cb0a8e565a0585846ec5a61
Siddhesh Poyarekar [Tue, 15 Dec 2020 10:36:48 +0000 (16:06 +0530)]
Partially revert 681900d29683722b1cb0a8e565a0585846ec5a61

Do not attempt to fix the significand top bit in long double input
received in printf.  The code should never reach here because isnan
should now detect unnormals as NaN.  This is already a NOP for glibc
since it uses the gcc __builtin_isnan, which detects unnormals as NaN.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
3 years agox86 long double: Support pseudo numbers in isnanl
Siddhesh Poyarekar [Wed, 23 Dec 2020 08:32:02 +0000 (14:02 +0530)]
x86 long double: Support pseudo numbers in isnanl

This syncs up isnanl behaviour with gcc.  Also move the isnanl
implementation to sysdeps/x86 and remove the sysdeps/x86_64 version.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This page took 0.091918 seconds and 5 git commands to generate.