]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
3 months agogetaddrinfo: Fix leak with AI_ALL [BZ #28852] google/grte/v5-2.27/master
Siddhesh Poyarekar [Thu, 3 Mar 2022 17:37:42 +0000 (23:07 +0530)] 
getaddrinfo: Fix leak with AI_ALL [BZ #28852]

Use realloc in convert_hostent_to_gaih_addrtuple and fix up pointers in
the result list so that a single block is maintained for
hostbyname3_r/hostbyname2_r and freed in gaih_inet.  This result is
never merged with any other results, since the hosts database does not
permit merging.

Resolves BZ #28852.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: DJ Delorie <dj@redhat.com>
3 months agoOptimize pthread_cond_timedwait to avoid unnecessary call to clock_gettime for CLOCK_...
Justin King [Thu, 11 Jan 2024 18:51:23 +0000 (18:51 +0000)] 
Optimize pthread_cond_timedwait to avoid unnecessary call to clock_gettime for CLOCK_MONOTONIC

3 months agogetcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)
Siddhesh Poyarekar [Fri, 21 Jan 2022 18:02:56 +0000 (23:32 +0530)] 
getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)

Cherry-picked from 23e0e8f5f1fb5ed150253d986ecccdc90c2dcd5e in main branch.
Test included with this commit is not cherry-picked because it requires more
changes.

No valid path returned by getcwd would fit into 1 byte, so reject the
size early and return NULL with errno set to ERANGE.  This change is
prompted by CVE-2021-3999, which describes a single byte buffer
underflow and overflow when all of the following conditions are met:

- The buffer size (i.e. the second argument of getcwd) is 1 byte
- The current working directory is too long
- '/' is also mounted on the current working directory

Sequence of events:

- In sysdeps/unix/sysv/linux/getcwd.c, the syscall returns ENAMETOOLONG
  because the linux kernel checks for name length before it checks
  buffer size

- The code falls back to the generic getcwd in sysdeps/posix

- In the generic func, the buf[0] is set to '\0' on line 250

- this while loop on line 262 is bypassed:

    while (!(thisdev == rootdev && thisino == rootino))

  since the rootfs (/) is bind mounted onto the directory and the flow
  goes on to line 449, where it puts a '/' in the byte before the
  buffer.

- Finally on line 458, it moves 2 bytes (the underflowed byte and the
  '\0') to the buf[0] and buf[1], resulting in a 1 byte buffer overflow.

- buf is returned on line 469 and errno is not set.

This resolves BZ #28769.

Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Qualys Security Advisory <qsa@qualys.com>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
3 months agoCVE-2018-19591: if_nametoindex: Fix descriptor for overlong name [BZ #23927]
Florian Weimer [Tue, 27 Nov 2018 15:12:43 +0000 (16:12 +0100)] 
CVE-2018-19591: if_nametoindex: Fix descriptor for overlong name [BZ #23927]

3 months agoCVE-2016-10739: getaddrinfo: Fully parse IPv4 address strings [BZ #20018]
Florian Weimer [Mon, 21 Jan 2019 20:26:03 +0000 (21:26 +0100)] 
CVE-2016-10739: getaddrinfo: Fully parse IPv4 address strings [BZ #20018]

Some tests in original commit are not included because they depend on headers that
are not present in GRTEv5 branch.

The IPv4 address parser in the getaddrinfo function is changed so that
it does not ignore trailing whitespace and all characters after it.
For backwards compatibility, the getaddrinfo function still recognizes
legacy name syntax, such as 192.000.002.010 interpreted as 192.0.2.8
(octal).

This commit does not change the behavior of inet_addr and inet_aton.
gethostbyname already had additional sanity checks (but is switched
over to the new __inet_aton_exact function for completeness as well).

To avoid sending the problematic query names over DNS, commit
6ca53a2453598804a2559a548a08424fca96434a ("resolv: Do not send queries
for non-host-names in nss_dns [BZ #24112]") is needed.

4 months agoTypo in configure.ac
Pranav Kant [Wed, 3 Jan 2024 22:03:30 +0000 (22:03 +0000)] 
Typo in configure.ac

Fallback from 0778e25fe1f34789794689f99e25b0c5ff001795

4 months agoReplace math-barriers with math_private
Pranav Kant [Fri, 29 Dec 2023 00:20:33 +0000 (00:20 +0000)] 
Replace math-barriers with math_private

That's where the definition for math_force_eval was before refactoring

4 months agoExpose __isinff128 for clang
Pranav Kant [Fri, 29 Dec 2023 00:19:59 +0000 (00:19 +0000)] 
Expose __isinff128 for clang

4 months agox86_64: Add SSE sfp-exceptions
Adhemerval Zanella [Thu, 26 Mar 2020 14:00:56 +0000 (11:00 -0300)] 
x86_64: Add SSE sfp-exceptions

The exported x86_64 fenv.h functions operate on both i387 and SSE (since
they should work on both float, double, and long double) while the
internal libc_fe* set either SSE (float, double, and float128) or
i387 (long double).

The libgcc __sfp_handle_exceptions (used on float128 implementation),
however, will set either SEE or i387 exception depending of the
exception to raise.  This broke the internal assumption of float128
where only SSE operations will be used.

This patch reimplements the libgcc __sfp_handle_exceptions to use only
SSE operations and sets libgcc to use it instead of its own
implementation.

And I think we should fix libgcc in a similar manner, since checking on
config/i386/64/sfp-machine.h it already only supports SSE rounding mode
and x86_64 ABI also expectes float128 to use SSE registers [1]
(although it is not clear on how future implementation might implement
it).

Checked on x86_64-linux-gnu.

[1] https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI

4 months agoSync configure.ac with configure script
Pranav Kant [Thu, 28 Dec 2023 22:49:45 +0000 (22:49 +0000)] 
Sync configure.ac with configure script

Fallback from bade6276d16523f81a1dedf22e591730592f15d6

4 months agoGet rid of WANT_FLOAT128 usage in floatn.h
Pranav Kant [Thu, 28 Dec 2023 22:46:30 +0000 (22:46 +0000)] 
Get rid of WANT_FLOAT128 usage in floatn.h

This header is installed system-wide. It's not correct to introduce a new
macro WANT_FLOAT128 in this because then we are either forcing the compiler to
make it an inbuilt macro to make glibc expose all float128 functionality, or asking
our clients to -DWANT_FLOAT128 to get float128 functionality in glibc.

Given we are primarily going to have float128 enabled GRTE now, we don't need to have
guards for non-float128 cases.

4 months ago-DWANT_FLOAT usage and enable float128 tests
Pranav Kant [Wed, 27 Dec 2023 21:56:41 +0000 (21:56 +0000)] 
-DWANT_FLOAT usage and enable float128 tests

7 months agox86: Respect --disable-float128 flag to disable FLOAT128 functionality
Pranav Kant [Thu, 28 Sep 2023 00:09:32 +0000 (00:09 +0000)] 
x86: Respect --disable-float128 flag to disable FLOAT128 functionality

7 months agox86: Define __HAVE_FLOAT128 for Clang and use __builtin_*f128 code path
Fangrui Song [Sun, 10 Oct 2021 21:38:00 +0000 (14:38 -0700)] 
x86: Define __HAVE_FLOAT128 for Clang and use __builtin_*f128 code path

Clang supports __builtin_fabsf128 (despite not supporting _Float128) but
_not _builtin_fabsq.
By falling back to `typedef __float128 _Float128;`, the float128 code
will be buildable with Clang.

7 months agoconfigure: Use same pattern to find headers for clang
Pranav Kant [Wed, 27 Sep 2023 18:55:40 +0000 (18:55 +0000)] 
configure: Use same pattern to find headers for clang

7 months agomath: x86: Use prefix for FP_INIT_ROUNDMODE
Adhemerval Zanella [Thu, 10 Mar 2022 17:48:44 +0000 (14:48 -0300)] 
math: x86: Use prefix for FP_INIT_ROUNDMODE

Not all compilers support the inline asm prefix '%v' to emit the avx
instruction if AVX is enable.  Use a prefix instead.

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

7 months agoAvoid error due to -Wimplicit-function-declaration
Pranav Kant [Tue, 26 Sep 2023 19:03:26 +0000 (19:03 +0000)] 
Avoid error due to -Wimplicit-function-declaration

7 months agomath: x86: Avoid the use of __libgcc_cmp_return__ for __gcc_CMPtype
Adhemerval Zanella [Thu, 10 Mar 2022 17:41:31 +0000 (14:41 -0300)] 
math: x86: Avoid the use of __libgcc_cmp_return__ for __gcc_CMPtype

8 months agoAdd -Wl,--undefined-version when using newer lld
Fangrui Song [Tue, 29 Aug 2023 03:30:46 +0000 (03:30 +0000)] 
Add -Wl,--undefined-version when using newer lld

to work around errors like

    version script assignment of 'GLIBC_2.4' to symbol '__stack_chk_guard' failed: symbol not defined

14 months agoApply upstream commit __builtin_FILE commit to GRTEv5.
Paul Pluzhnikov [Fri, 10 Feb 2023 20:40:56 +0000 (20:40 +0000)] 
Apply upstream commit __builtin_FILE commit to GRTEv5.

https://sourceware.org/git/?p=glibc.git;a=commit;h=e42ec822190056895e55e5140ce2304e67e34445

18 months agonptl: Make mmap and munmap in thread stack allocation interposable
Nilay Vaish [Thu, 27 Oct 2022 18:33:49 +0000 (11:33 -0700)] 
nptl: Make mmap and munmap in thread stack allocation interposable

b/238021577: __mmap and __munmap are not interposable.  Call
interposable mmap and munmap instead so that we can capture thread stack
allocations.

18 months agoFix build of nptl/tst-thread_local1.cc with GCC 12
Joseph Myers [Mon, 2 Aug 2021 16:33:44 +0000 (16:33 +0000)] 
Fix build of nptl/tst-thread_local1.cc with GCC 12

The test nptl/tst-thread_local1.cc fails to build with GCC mainline
because of changes to what libstdc++ headers implicitly include what
other headers:

tst-thread_local1.cc: In function 'int do_test()':
tst-thread_local1.cc:177:5: error: variable 'std::array<std::pair<const char*, std::function<void(void* (*)(void*))> >, 2> do_thread_X' has initializer but incomplete type
  177 |     do_thread_X
      |     ^~~~~~~~~~~

Fix this by adding an explicit include of <array>.

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

(cherry picked from commit 2ee9b24f47db8d0a8d0ccadb999335a1d4cfc364)

23 months ago<string.h>: Define __CORRECT_ISO_CPP_STRING_H_PROTO for Clang [BZ #25232]
Kamlesh Kumar [Thu, 5 Dec 2019 15:49:00 +0000 (16:49 +0100)] 
<string.h>: Define __CORRECT_ISO_CPP_STRING_H_PROTO for Clang [BZ #25232]

Without the asm redirects, strchr et al. are not const-correct.

libc++ has a wrapper header that works with and without
__CORRECT_ISO_CPP_STRING_H_PROTO (using a Clang extension).  But when
Clang is used with libstdc++ or just C headers, the overloaded functions
with the correct types are not declared.

This change does not impact current GCC (with libstdc++ or libc++).

(cherry picked from commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3)

2 years agoMakeconfig: Update clang_rt.crtbegin.o filename
Fangrui Song [Tue, 3 May 2022 04:01:43 +0000 (21:01 -0700)] 
Makeconfig: Update clang_rt.crtbegin.o filename

2 years agoRemove x86_64 specific lowlevellock/cancellation
Fangrui Song [Wed, 27 Apr 2022 21:01:19 +0000 (14:01 -0700)] 
Remove x86_64 specific lowlevellock/cancellation

The x86_64 specific implemention has CFI directives like
`.cfi_adjust_cfa_offset 128` which are incorrect when RBP is used as the
canonical frame address.

This follows the spirit of the following two commits by removing the
x86_64 specific implementation. The generic implementation will be used.

eb76e5b465a4b7b569cde4b4f57d1fcb4695c1c6 ("nptl: Reinstate pthread_timedjoin_np as a cancellation point (BZ#24215)")
c50e1c263ec15e98da3235e663049156fd1afcfa ("x86: Remove arch-specific low level lock implementation")

2 years agoelf: Support DT_RELR relative relocation format
Fangrui Song [Mon, 25 Apr 2022 23:50:00 +0000 (16:50 -0700)] 
elf: Support DT_RELR relative relocation format

Adapted from
https://sourceware.org/pipermail/libc-alpha/2022-April/138085.html
([PATCH v11 0/7] Support DT_RELR relative relocation format),
which is expected to be included in glibc 2.36.

glibc 2.35 has a fair amount of rtld changes to avoid nested functions
(https://sourceware.org/PR27220). This patch is carefully crafted to
make the minimal changes.

Notebly, this commit

* works around b/208156916 by not bumping DT_NUM. DT_RELR and DT_RELRSZ
  take the l_info slots at DT_VERSYM+1 and DT_VERSYM+2.
* avoids changes to include/link.h
* removes the time travel compatibility check (error if DT_RELR is used
  without GLIBC_ABI_DT_RELR version need). This needs link.h change and
  the detected case cannot happen if we correctly use
  -Wl,-z,pack-relative-relocs.

2 years agoconfigure: Don't check LD -v --help for LIBC_LINKER_FEATURE
Fangrui Song [Mon, 25 Apr 2022 23:48:25 +0000 (16:48 -0700)] 
configure: Don't check LD -v --help for LIBC_LINKER_FEATURE

When LIBC_LINKER_FEATURE is used to check a linker option with the equal
sign, it will likely fail because the LD -v --help output may look like
`-z lam-report=[none|warning|error]` while the needle is something like
`-z lam-report=warning`.

The LD -v --help filter doesn't save much time, so just remove it.

(cherry picked from commit 8438135d3481853e300e1043cfee3946dadb28b3)

2 years agoUse libc_hidden_* for atoi (bug 15105).
Joseph Myers [Mon, 26 Feb 2018 18:17:47 +0000 (18:17 +0000)] 
Use libc_hidden_* for atoi (bug 15105).

Continuing the fixes for localplt test failures with -Os arising from
functions not being inlined in that case, this patch fixes such
failures for atoi by using libc_hidden_proto and libc_hidden_def.

Tested for x86_64 (both that it removes this particular localplt
failure for -Os, and that the testsuite continues to pass without
-Os).

[BZ #15105]
* stdlib/atoi.c (atoi): Use libc_hidden_def.
* include/stdlib.h [!_ISOMAC] (atoi): Use libc_hidden_proto.

(cherry picked from commit 20602c72fa54bc0923314820ec8148186096bf3b)

2 years agoUse libc_hidden_* for tolower, toupper (bug 15105).
Joseph Myers [Fri, 23 Feb 2018 13:54:53 +0000 (13:54 +0000)] 
Use libc_hidden_* for tolower, toupper (bug 15105).

Continuing the fixes for localplt test failures with -Os arising from
functions not being inlined in that case, this patch fixes such
failures for tolower and toupper by using libc_hidden_proto and
libc_hidden_def.

Tested for x86_64 (both that it removes this particular localplt
failure for -Os, and that the testsuite continues to pass without
-Os).

2018-02-22  Joseph Myers  <joseph@codesourcery.com>

[BZ #15105]
* ctype/ctype.c (tolower): Use libc_hidden_def.
(toupper): Likewise.
* include/ctype.h [!_ISOMAC] (tolower): Use libc_hidden_proto.
[!_ISOMAC] (toupper): Likewise.

(cherry picked from commit 54412d20618b7b93f136a168e788573575f8a7a6)

2 years agoUse libc_hidden_* for argz_next, __argz_next (bug 15105).
Joseph Myers [Thu, 15 Feb 2018 21:00:02 +0000 (21:00 +0000)] 
Use libc_hidden_* for argz_next, __argz_next (bug 15105).

Among other localplt test failures when building with -Os, there are
libc.so PLT references for argz_next and __argz_next.  This is a
simple case of functions that are inlined for -O2 but not for -Os;
this patch adds libc_hidden_proto / libc_hidden_def for them to avoid
localplt failures even when not inlined.

Tested for x86_64 (both that it removes these particular localplt
failures for -Os - but other such failures remain so the bug can't yet
be closed - and that the testsuite continues to pass without -Os).

[BZ #15105]
* include/argz.h (argz_next): Use libc_hidden_proto.
(__argz_next): Likewise.
* string-argz-next.c (__argz_next): Use libc_hidden_def.
(argz_next): Use libc_hidden_weak.

(cherry picked from commit 055ac2a7eeb14755e946440af3d2cdfe95f18f8e)

2 years agoUse libc_hidden_* for __cmsg_nxthdr (bug 15105).
Joseph Myers [Thu, 15 Feb 2018 20:59:12 +0000 (20:59 +0000)] 
Use libc_hidden_* for __cmsg_nxthdr (bug 15105).

Among other localplt test failures when building with -Os, there are
libc.so PLT references for __cmsg_nxthdr.  This is a simple case of a
function that is inlined for -O2 but not for -Os; this patch adds
libc_hidden_proto / libc_hidden_def for it to avoid a localplt failure
even when it is not inlined.

Tested for x86_64 (both that it removes this particular localplt
failure for -Os - but other such failures remain so the bug can't yet
be closed - and that the testsuite continues to pass without -Os).

[BZ #15105]
* include/sys/socket.h [!_ISOMAC] (__cmsg_nxthdr): Use
libc_hidden_proto.
* sysdeps/unix/sysv/linux/cmsg_nxthdr.c (__cmsg_nxthdr): Use
libc_hidden_def.

(cherry picked from commit e4452a2d19279d4c90bcafe09ec3cbfd3efe9b6a)

2 years agoUse libc_hidden_* for fputs (bug 15105).
Joseph Myers [Thu, 15 Feb 2018 20:58:16 +0000 (20:58 +0000)] 
Use libc_hidden_* for fputs (bug 15105).

Among other localplt test failures when building with -Os, there are
libc.so PLT references for fputs.  fputs calls normally get redirected
to _IO_fputs by a macro in include/stdio.h (and _IO_fputs in turn uses
libc_hidden_proto), but GCC can convert an fprintf call with a
constant string argument into an fputs call, which of course is then
unaffected by the macro redirection.  (I don't know why this issue
only appears with -Os.)

This patch duly adds a use of libc_hidden_proto for fputs.  I see no
obvious reason why the fputs macro redirection is needed at all, but
this patch does not change it.

Tested for x86_64 (both that it removes this particular localplt
failure for -Os - but other such failures remain so the bug can't yet
be closed - and that the testsuite continues to pass without -Os).

[BZ #15105]
* include/stdio.h [!_ISOMAC && IS_IN (libc)] (fputs): Use
libc_hidden_proto.
* libio/iofputs.c (fputs): Use libc_hidden_weak.

(cherry picked from commit 499b315324519f8deb5b42a143a76319934a3ab0)

2 years agoFix -Os gnu_dev_* linknamespace, localplt issues (bug 15105, bug 19463).
Joseph Myers [Wed, 7 Feb 2018 14:57:31 +0000 (14:57 +0000)] 
Fix -Os gnu_dev_* linknamespace, localplt issues (bug 15105, bug 19463).

Building with -Os produces linknamespace and localplt failures for,
among other functions, gnu_dev_major, gnu_dev_minor and
gnu_dev_makedev.

The issue is that those functions are not inlined when building with
-Os.  While one could force them to be inlined in that case, it seems
more natural to fix this issue similarly to other namespace issues.
Thus, this patch makes gnu_dev_* into weak aliases for hidden symbols
__gnu_dev_*; __gnu_dev_* are then defined as inlines in the internal
include/sys/sysmacros.h, and uses of gnu_dev_* (often via the macros
major, minor and makedev) for which there are namespace issues are
changed to use __gnu_dev_*; where there are no namespace issues, use
of libc_hidden_proto serves to avoid unnecessary local PLT entry use.

Tested for x86_64, (a) without -Os, to verify the testsuite continues
to pass without problems and that the functions called under their new
names continue to be inlined as expected in that case; (b) with -Os,
to verify that the linknamespace and localplt failures in question go
away (but because of other such failures present, neither of the
relevant bugs can yet be closed).

[BZ #15105]
[BZ #19463]
* include/sys/sysmacros.h [!_ISOMAC]
(__SYSMACROS_NEED_IMPLEMENTATION): Define macro.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC]
(_SYS_SYSMACROS_H_WRAPPER): Likewise.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (gnu_dev_major): Use
libc_hidden_proto.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (gnu_dev_minor): Likewise.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (gnu_dev_makedev):
Likewise.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (__SYSMACROS_DECL_TEMPL):
Undefine and redefine to add use __gnu_dev_ prefix.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (__SYSMACROS_IMPL_TEMPL):
Likewise.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (__gnu_dev_major): Declare
and define as hidden inline function.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (__gnu_dev_minor):
Likewise.
[!_SYS_SYSMACROS_H_WRAPPER && !_ISOMAC] (__gnu_dev_makedev):
Likewise.
* misc/makedev.c (OUT_OF_LINE_IMPL_TEMPL): Use __gnu_dev_ prefix.
(gnu_dev_major): Use weak_alias and libc_hidden_weak.
(gnu_dev_minor): Likewise.
(gnu_dev_makedev): Likewise.
* csu/check_fds.c (check_one_fd): Use __gnu_dev_makedev instead of
makedev.
* posix/wordexp.c (exec_comm_child): Likewise.
* sysdeps/mach/hurd/xmknodat.c (__xmknodat): Use __gnu_dev_minor
instead of minor and __gnu_dev_major instead of major.
* sysdeps/unix/sysv/linux/device-nrs.h (DEV_TTY_P): Use
__gnu_dev_major instead of major.
* sysdeps/unix/sysv/linux/pathconf.c (distinguish_extX): Use
__gnu_dev_major instead of gnu_dev_major and __gnu_dev_minor
instead of gnu_dev_minor.
* sysdeps/unix/sysv/linux/ptsname.c (MASTER_P): Likewise.
(SLAVE_P): Likewise.
(__ptsname_internal): Use __gnu_dev_minor instead of minor.
* sysdeps/unix/sysv/linux/ttyname.h (is_pty): Use __gnu_dev_major
instead of major.

(cherry picked from commit 8b4a118222c7ed41bc653943b542915946dff1dd)

2 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>
(cherry picked from commit 87d583c6e8cd0e49f64da76636ebeec033298b4d)

2 years agoUse a better workaround for clang lack of _builtin_va_arg_pack
Stan Shebs [Fri, 12 Nov 2021 14:48:03 +0000 (06:48 -0800)] 
Use a better workaround for clang lack of _builtin_va_arg_pack

2 years agoSet the retain attribute on _elf_set_element if CC supports [BZ #27492]
Fangrui Song [Fri, 16 Apr 2021 18:26:39 +0000 (11:26 -0700)] 
Set the retain attribute on _elf_set_element if CC supports [BZ #27492]

So that text_set_element/data_set_element/bss_set_element defined
variables will be retained by the linker.

Note: 'used' and 'retain' are orthogonal: 'used' makes sure the variable
will not be optimized out; 'retain' prevents section garbage collection
if the linker support SHF_GNU_RETAIN.

GNU ld 2.37 and LLD 13 will support -z start-stop-gc which allow C
identifier name sections to be GCed even if there are live
__start_/__stop_ references.

Without the change, there are some static linking problems, e.g.
_IO_cleanup (libio/genops.c) may be discarded by ld --gc-sections, so
stdout is not flushed on exit.

Note: GCC may warning 'retain' attribute ignored while __has_attribute(retain)
is 1 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587).

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit cd6ae7ea5431c2b8f16201fb0e2c413bf8d2df06)

2 years agopowerpc: Use --no-tls-get-addr-optimize in test only if the linker supports it
Fangrui Song [Tue, 24 Aug 2021 16:26:44 +0000 (09:26 -0700)] 
powerpc: Use --no-tls-get-addr-optimize in test only if the linker supports it

LLD doesn't support --{,no-}tls-get-addr-optimize.

Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
(cherry picked from commit f9cd7d5d194c652e9ec31634da3fc8ef1bf06780)

2 years agoelf: Drop elf/tls-macros.h in favor of __thread and tls_model attributes [BZ #28152...
Fangrui Song [Mon, 16 Aug 2021 16:59:30 +0000 (09:59 -0700)] 
elf: Drop elf/tls-macros.h in favor of __thread and tls_model attributes [BZ #28152] [BZ #28205]

elf/tls-macros.h was added for TLS testing when GCC did not support
__thread. __thread and tls_model attributes are mature now and have been
used by many newer tests.

Also delete tst-tls2.c which tests .tls_common (unused by modern GCC and
unsupported by Clang/LLD). .tls_common and .tbss definition are almost
identical after linking, so the runtime test doesn't add additional
coverage.  Assembler and linker tests should be on the binutils side.

When LLD 13.0.0 is allowed in configure.ac
(https://sourceware.org/pipermail/libc-alpha/2021-August/129866.html),
`make check` result is on par with glibc built with GNU ld on aarch64
and x86_64.

As a future clean-up, TLS_GD/TLS_LD/TLS_IE/TLS_IE macros can be removed from
sysdeps/*/tls-macros.h. We can add optional -mtls-dialect={gnu2,trad}
tests to ensure coverage.

Tested on aarch64-linux-gnu, powerpc64le-linux-gnu, and x86_64-linux-gnu.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 33c50ef42878b07ee6ead8b3f1a81d8c2c74697c)

2 years agoaarch64: Make elf_machine_{load_address,dynamic} robust [BZ #28203]
Fangrui Song [Wed, 11 Aug 2021 16:00:37 +0000 (09:00 -0700)] 
aarch64: Make elf_machine_{load_address,dynamic} robust [BZ #28203]

The AArch64 ABI is largely platform agnostic and does not specify
_GLOBAL_OFFSET_TABLE_[0] ([1]). glibc ld.so turns out to be probably the
only user of _GLOBAL_OFFSET_TABLE_[0] and GNU ld defines the value
to the link-time address _DYNAMIC. [2]

In 2012, __ehdr_start was implemented in GNU ld and gold in binutils
2.23.  Using adrp+add / (-mcmodel=tiny) adr to access
__ehdr_start/_DYNAMIC gives us a robust way to get the load address and
the link-time address of _DYNAMIC.

[1]: From a psABI maintainer, https://bugs.llvm.org/show_bug.cgi?id=49672#c2
[2]: LLD's aarch64 port does not set _GLOBAL_OFFSET_TABLE_[0] to the
link-time address _DYNAMIC.
LLD is widely used on aarch64 Android and ChromeOS devices.  Software
just works without the need for _GLOBAL_OFFSET_TABLE_[0].

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 43d06ed218fc8be58987bdfd00e21e5720f0b862)

2 years agoelf: Unconditionally use __ehdr_start
Fangrui Song [Fri, 27 Aug 2021 00:41:24 +0000 (17:41 -0700)] 
elf: Unconditionally use __ehdr_start

We can consider __ehdr_start (from binutils 2.23 onwards)
unconditionally supported, since configure.ac requires binutils>=2.25.

The configure.ac check is related to an ia64 bug fixed by binutils 2.24.
See https://sourceware.org/pipermail/libc-alpha/2014-August/053503.html

Tested on x86_64-linux-gnu. Tested build-many-glibcs.py with
aarch64-linux-gnu and s390x-linux-gnu.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 302247c89121e8d4c7629e589edbb4974fff6edb)

2 years agowordexp: handle overflow in positional parameter number (bug 28011)
Andreas Schwab [Fri, 25 Jun 2021 13:02:47 +0000 (15:02 +0200)] 
wordexp: handle overflow in positional parameter number (bug 28011)

Use strtoul instead of atoi so that overflow can be detected.

2 years agoDisable tests that need more-recent infrastructure
Stan Shebs [Fri, 23 Jul 2021 17:06:02 +0000 (10:06 -0700)] 
Disable tests that need more-recent infrastructure

2 years agointl: Handle translation output codesets with suffixes [BZ #26383]
Arjun Shankar [Fri, 25 Sep 2020 12:47:06 +0000 (14:47 +0200)] 
intl: Handle translation output codesets with suffixes [BZ #26383]

Commit 91927b7c7643 (Rewrite iconv option parsing [BZ #19519]) did not
handle cases where the output codeset for translations (via the `gettext'
family of functions) might have a caller specified encoding suffix such as
TRANSLIT or IGNORE.  This led to a regression where translations did not
work when the codeset had a suffix.

This commit fixes the above issue by parsing any suffixes passed to
__dcigettext and adds two new test-cases to intl/tst-codeset.c to
verify correct behaviour.  The iconv-internal function __gconv_create_spec
and the static iconv-internal function gconv_destroy_spec are now visible
internally within glibc and used in intl/dcigettext.c.

2 years agoRewrite iconv option parsing [BZ #19519]
Arjun Shankar [Tue, 7 Jul 2020 18:31:48 +0000 (20:31 +0200)] 
Rewrite iconv option parsing [BZ #19519]

This commit replaces string manipulation during `iconv_open' and iconv_prog
option parsing with a structured, flag based conversion specification.  In
doing so, it alters the internal `__gconv_open' interface and accordingly
adjusts its uses.

This change fixes several hangs in the iconv program and therefore includes
a new test to exercise iconv_prog options that originally led to these hangs.
It also includes a new regression test for option handling in the iconv
function.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoiconv: Accept redundant shift sequences in IBM1364 [BZ #26224]
Arjun Shankar [Wed, 4 Nov 2020 11:19:38 +0000 (12:19 +0100)] 
iconv: Accept redundant shift sequences in IBM1364 [BZ #26224]

The IBM1364, IBM1371, IBM1388, IBM1390 and IBM1399 character sets
share converter logic (iconvdata/ibm1364.c) which would reject
redundant shift sequences when processing input in these character
sets.  This led to a hang in the iconv program (CVE-2020-27618).

This commit adjusts the converter to ignore redundant shift sequences
and adds test cases for iconv_prog hangs that would be triggered upon
their rejection.  This brings the implementation in line with other
converters that also ignore redundant shift sequences (e.g. IBM930
etc., fixed in commit 692de4b3960d).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2 years agoiconv: Fix incorrect UCS4 inner loop bounds (BZ#26923)
Michael Colavita [Thu, 19 Nov 2020 16:44:40 +0000 (11:44 -0500)] 
iconv: Fix incorrect UCS4 inner loop bounds (BZ#26923)

Previously, in UCS4 conversion routines we limit the number of
characters we examine to the minimum of the number of characters in the
input and the number of characters in the output. This is not the
correct behavior when __GCONV_IGNORE_ERRORS is set, as we do not consume
an output character when we skip a code unit. Instead, track the input
and output pointers and terminate the loop when either reaches its
limit.

This resolves assertion failures when resetting the input buffer in a step of
iconv, which assumes that the input will be fully consumed given sufficient
output space.

2 years agomath/test-sinl-pseudo: Use stack protector only if available
Florian Weimer [Thu, 13 Feb 2020 16:01:15 +0000 (17:01 +0100)] 
math/test-sinl-pseudo: Use stack protector only if available

This fixes commit 9333498794cde1d5cca518bad ("Avoid ldbl-96 stack
corruption from range reduction of pseudo-zero (bug 25487).").

2 years agoAvoid ldbl-96 stack corruption from range reduction of pseudo-zero (bug 25487).
Joseph Myers [Wed, 12 Feb 2020 23:31:56 +0000 (23:31 +0000)] 
Avoid ldbl-96 stack corruption from range reduction of pseudo-zero (bug 25487).

Bug 25487 reports stack corruption in ldbl-96 sinl on a pseudo-zero
argument (an representation where all the significand bits, including
the explicit high bit, are zero, but the exponent is not zero, which
is not a valid representation for the long double type).

Although this is not a valid long double representation, existing
practice in this area (see bug 4586, originally marked invalid but
subsequently fixed) is that we still seek to avoid invalid memory
accesses as a result, in case of programs that treat arbitrary binary
data as long double representations, although the invalid
representations of the ldbl-96 format do not need to be consistently
handled the same as any particular valid representation.

This patch makes the range reduction detect pseudo-zero and unnormal
representations that would otherwise go to __kernel_rem_pio2, and
returns a NaN for them instead of continuing with the range reduction
process.  (Pseudo-zero and unnormal representations whose unbiased
exponent is less than -1 have already been safely returned from the
function before this point without going through the rest of range
reduction.)  Pseudo-zero representations would previously result in
the value passed to __kernel_rem_pio2 being all-zero, which is
definitely unsafe; unnormal representations would previously result in
a value passed whose high bit is zero, which might well be unsafe
since that is not a form of input expected by __kernel_rem_pio2.

Tested for x86_64.

2 years agoposix: Sync gnulib regex implementation
Adhemerval Zanella [Wed, 20 Dec 2017 11:47:44 +0000 (09:47 -0200)] 
posix: Sync gnulib regex implementation

This patch syncs the regex implementation with gnulib (commit 0ee5212).
Only two changes in GLIBC regex testing are required:

  1. posix/bug-regex28.c: as previously discussed [1] the change of
     expected results on the pattern should be safe.

  2. posix/PCRE.tests: the ERE (a)|\1 is malformed (in the sense that
     the \1 doesn't mean anything) and although current GLIBC accepts
     it has undefined behavior.  This patch removes the specific test.

This sync contains some patches from thread 'Regex: Make libc regex
more usable outside GLIBC.' [2] which have been pushed upstream in
gnulib.  This patches also fixes some regex issues (BZ #23233,
BZ #21163, BZ #18986, BZ #13762) and I did not add testcases for
both #23233 and #13762 because I couldn't think a simple way to
trigger the expected failure path to trigger them.

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

[BZ #23233]
[BZ #21163]
[BZ #18986]
[BZ #13762]
* posix/Makefile (tests): Add bug-regex37 and bug-regex38.
* posix/PCRE.tests: Remove invalid test.
* posix/bug-regex28.c: Fix expected values for used syntax.
* posix/bug-regex37.c: New file.
* posix/bug-regex38.c: Likewise.
* posix/regcomp.c: Sync with gnulib.
* posix/regex.c: Likewise.
* posix/regex.h: Likewise.
* posix/regex_internal.c: Likewise.
* posix/regex_internal.h: Likewise.
* posix/regexec.c: Likewise.

[1] https://sourceware.org/ml/libc-alpha/2017-12/msg00807.html
[2] https://sourceware.org/ml/libc-alpha/2017-12/msg00237.html

2 years agoFix use-after-free in glob when expanding ~user (bug 25414)
Andreas Schwab [Wed, 19 Feb 2020 16:21:46 +0000 (17:21 +0100)] 
Fix use-after-free in glob when expanding ~user (bug 25414)

The value of `end_name' points into the value of `dirname', thus don't
deallocate the latter before the last use of the former.

2 years agoFix a return type in elf unload test
Stan Shebs [Thu, 22 Jul 2021 20:00:52 +0000 (13:00 -0700)] 
Fix a return type in elf unload test

2 years agoFix buffer overrun in EUC-KR conversion module (bz #24973)
Andreas Schwab [Mon, 21 Dec 2020 03:26:43 +0000 (08:56 +0530)] 
Fix buffer overrun in EUC-KR conversion module (bz #24973)

The byte 0xfe as input to the EUC-KR conversion denotes a user-defined
area and is not allowed.  The from_euc_kr function used to skip two bytes
when told to skip over the unknown designation, potentially running over
the buffer end.

2 years agogconv: Fix assertion failure in ISO-2022-JP-3 module (bug 27256)
Florian Weimer [Wed, 27 Jan 2021 12:36:12 +0000 (13:36 +0100)] 
gconv: Fix assertion failure in ISO-2022-JP-3 module (bug 27256)

The conversion loop to the internal encoding does not follow
the interface contract that __GCONV_FULL_OUTPUT is only returned
after the internal wchar_t buffer has been filled completely.  This
is enforced by the first of the two asserts in iconv/skeleton.c:

      /* We must run out of output buffer space in this
 rerun.  */
      assert (outbuf == outerr);
      assert (nstatus == __GCONV_FULL_OUTPUT);

This commit solves this issue by queuing a second wide character
which cannot be written immediately in the state variable, like
other converters already do (e.g., BIG5-HKSCS or TSCII).

Reported-by: Tavis Ormandy <taviso@gmail.com>
2 years agoRead f->func.cxa under the lock.
Vitaly Buka [Thu, 15 Jul 2021 21:39:33 +0000 (14:39 -0700)] 
Read f->func.cxa under the lock.

2 years agoFix bug where ld.so hashtable would retain strings passed to dlopen().
Ambrose Feinstein [Thu, 15 Jul 2021 20:53:47 +0000 (13:53 -0700)] 
Fix bug where ld.so hashtable would retain strings passed to dlopen().

2 years agoExtend elf/unload8 to test an additional load/unload pattern
Stan Shebs [Thu, 15 Jul 2021 19:57:50 +0000 (12:57 -0700)] 
Extend elf/unload8 to test an additional load/unload pattern

2 years agoDon't crash if /var/tmp doesn't exist
Shu-Chun Weng [Mon, 3 May 2021 23:47:10 +0000 (16:47 -0700)] 
Don't crash if /var/tmp doesn't exist

`xstat` is checked `stat64` crashing the program if the latter returns
failure. In this loop, we are trying to find one folder that satisfies
the condition, no reason to crash the program if one folder doesn't.

2 years agoMore aggressively prevent a buffer from being optimized out
Shu-Chun Weng [Mon, 3 May 2021 23:12:44 +0000 (16:12 -0700)] 
More aggressively prevent a buffer from being optimized out

The volatile global variable was first introduced in e86f9654c. I have
noticed the compiler still optimizing the buffer out on AArch64
presumably because the assignment is after all other observable
behaviors so it's still valid to eliminate it.

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

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

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

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2 years ago[PATCH 7/7] sin/cos slow paths: refactor sincos implementation
Wilco Dijkstra [Tue, 3 Apr 2018 15:49:33 +0000 (16:49 +0100)] 
[PATCH 7/7] sin/cos slow paths: refactor sincos implementation

Refactor the sincos implementation - rather than rely on odd partial inlining
of preprocessed portions from sin and cos, explicitly write out the cases.
This makes sincos much easier to maintain and provides an additional 16-20%
speedup between 0 and 2^27.  The overall speedup of sincos is 48% over this range.
Between 0 and PI it is 66% faster.

* sysdeps/ieee754/dbl-64/s_sin.c (__sin): Cleanup ifdefs.
(__cos): Likewise.
* sysdeps/ieee754/dbl-64/s_sin.c (__sincos): Refactor using the same
logic as sin and cos.

2 years ago[PATCH 6/7] sin/cos slow paths: refactor duplicated code into dosin
Wilco Dijkstra [Tue, 3 Apr 2018 15:46:10 +0000 (16:46 +0100)] 
[PATCH 6/7] sin/cos slow paths: refactor duplicated code into dosin

Refactor duplicated code into do_sin.  Since all calls to do_sin use copysign to
set the sign of the result, move it inside do_sin.  Small inputs use a separate
polynomial, so move this into do_sin as well (the check is based on the more
conservative case when doing large range reduction, but could be relaxed).

* sysdeps/ieee754/dbl-64/s_sin.c (do_sin): Use TAYLOR_SIN for small
inputs.  Return correct sign.
(do_sincos): Remove small input check before do_sin, let do_sin set
the sign.
(__sin): Likewise.
(__cos): Likewise.

2 years ago[PATCH 5/7] sin/cos slow paths: remove unused slowpath functions
Wilco Dijkstra [Tue, 3 Apr 2018 15:43:34 +0000 (16:43 +0100)] 
[PATCH 5/7] sin/cos slow paths: remove unused slowpath functions

Remove all unused slowpath functions.

* sysdeps/ieee754/dbl-64/s_sin.c (TAYLOR_SLOW): Remove.
(do_cos_slow): Likewise.
(do_sin_slow): Likewise.
(reduce_and_compute): Likewise.
(slow): Likewise.
(slow1): Likewise.
(slow2): Likewise.
(sloww): Likewise.
(sloww1): Likewise.
(sloww2): Likewise.
(bslow): Likewise.
(bslow1): Likewise.
(bslow2): Likewise.
(cslow2): Likewise.

2 years ago[PATCH 4/7] sin/cos slow paths: remove slow paths from huge range reduction
Wilco Dijkstra [Tue, 3 Apr 2018 15:41:36 +0000 (16:41 +0100)] 
[PATCH 4/7] sin/cos slow paths: remove slow paths from huge range reduction

For huge inputs use the improved do_sincos function as well.  Now no cases use
the correction factor returned by do_sin, do_cos and TAYLOR_SIN, so remove it.

* sysdeps/ieee754/dbl-64/s_sin.c (TAYLOR_SIN): Remove cor parameter.
(do_cos): Remove corp parameter and calculations.
(do_sin): Likewise.
(do_sincos): Remove cor variable.
(__sin): Use do_sincos for huge inputs.
(__cos): Likewise.
* sysdeps/ieee754/dbl-64/s_sincos.c (__sincos): Likewise.
(reduce_and_compute_sincos): Remove unused function.

2 years ago[PATCH 3/7] sin/cos slow paths: remove slow paths from small range reduction
Wilco Dijkstra [Tue, 3 Apr 2018 15:33:13 +0000 (16:33 +0100)] 
[PATCH 3/7] sin/cos slow paths: remove slow paths from small range reduction

This patch improves the accuracy of the range reduction.  When the input is
large (2^27) and very close to a multiple of PI/2, using 110 bits of PI is not
enough.  Improve range reduction accuracy to 136 bits.  As a result the special
checks for results close to zero can be removed.  The ULP of the polynomials is
at worst 0.55ULP, so there is no reason for the slow functions, and they can be
removed.

* sysdeps/ieee754/dbl-64/s_sin.c (reduce_sincos_1): Rename to
reduce_sincos, improve accuracy to 136 bits.
(do_sincos_1): Rename to do_sincos, remove fallbacks to slow functions.
(__sin): Use improved reduction and simplified do_sincos calculation.
(__cos): Likewise.
* sysdeps/ieee754/dbl-64/s_sincos.c (__sincos): Likewise.

2 years ago[PATCH 2/7] sin/cos slow paths: remove large range reduction
Wilco Dijkstra [Tue, 3 Apr 2018 15:28:03 +0000 (16:28 +0100)] 
[PATCH 2/7] sin/cos slow paths: remove large range reduction

This patch removes the large range reduction code and defers to the huge range
reduction code.  The first level range reducer supports inputs up to 2^27,
which is way too large given that inputs for sin/cos are typically small
(< 10), and optimizing for a smaller range would give a significant speedup.

Input values above 2^27 are practically never used, so there is no reason for
supporting range reduction between 2^27 and 2^48.  Removing it significantly
simplifies code and enables further speedups.  There is about a 2.3x slowdown
in this range due to __branred being extremely slow  (a better algorithm could
easily more than double performance).

* sysdeps/ieee754/dbl-64/s_sin.c (reduce_sincos_2): Remove function.
(do_sincos_2): Likewise.
(__sin): Remove middle range reduction case.
(__cos): Likewise.
* sysdeps/ieee754/dbl-64/s_sincos.c (__sincos): Remove middle range
reduction case.

2 years ago[PATCH 1/7] sin/cos slow paths: avoid slow paths for small inputs
Wilco Dijkstra [Tue, 3 Apr 2018 15:24:29 +0000 (16:24 +0100)] 
[PATCH 1/7] sin/cos slow paths: avoid slow paths for small inputs

This series of patches removes the slow patchs from sin, cos and sincos.
Besides greatly simplifying the implementation, the new version is also much
faster for inputs up to PI (41% faster) and for large inputs needing range
reduction (27% faster).

ULP is ~0.55 with no errors found after testing 1.6 billion inputs across most
of the range with mpsin and mpcos.  The number of incorrectly rounded results
(ie. ULP >0.5) is at most ~2750 per million inputs between 0.125 and 0.5,
the average is ~850 per million between 0 and PI.

Tested on AArch64 and x86_64 with no regressions.

The first patch removes the slow paths for the cases where the input is small
and doesn't require range reduction.  Update ULP tables for sin, cos and sincos
on AArch64 and x86_64.

* sysdeps/aarch64/libm-test-ulps: Update ULP for sin, cos, sincos.
* sysdeps/ieee754/dbl-64/s_sin.c (__sin): Remove slow paths for small
inputs.
(__cos): Likewise.
* sysdeps/x86_64/fpu/libm-test-ulps: Update ULP for sin, cos, sincos.

2 years agolocale: Align _nl_C_LC_CTYPE_class and _nl_C_LC_CTYPE_class32
Lirong Yuan [Thu, 1 Apr 2021 19:37:23 +0000 (12:37 -0700)] 
locale: Align _nl_C_LC_CTYPE_class and _nl_C_LC_CTYPE_class32

Otherwise, programs that use character classification macros such as
isspace may observe unaligned pointers.

2 years agoChange this offsetof computation to use c89 offsetof. Tested:
Nick Lewycky [Thu, 16 Apr 2015 18:15:58 +0000 (11:15 -0700)] 
Change this offsetof computation to use c89 offsetof. Tested:

2 years agoUpdate build process to create libnsl stub
Stan Shebs [Tue, 3 Nov 2020 21:30:16 +0000 (13:30 -0800)] 
Update build process to create libnsl stub

2 years agoForward-port google-nsl-stub
Paul Pluzhnikov [Fri, 28 Feb 2014 14:44:46 +0000 (06:44 -0800)] 
Forward-port google-nsl-stub

2 years agoFix memory leak in TLS allocation
James Y Knight [Wed, 21 Oct 2020 20:38:14 +0000 (13:38 -0700)] 
Fix memory leak in TLS allocation

2 years agoAdd a test of TLS support that will fail if leaky
Stan Shebs [Wed, 21 Oct 2020 20:19:47 +0000 (13:19 -0700)] 
Add a test of TLS support that will fail if leaky

2 years agoLet time and gettimeofday use vdso by removing old clang workaround
Stan Shebs [Tue, 6 Oct 2020 20:08:18 +0000 (13:08 -0700)] 
Let time and gettimeofday use vdso by removing old clang workaround

2 years agoUse crt*.o files from llvm compiler-rt when building with clang
Stan Shebs [Tue, 9 Jun 2020 17:09:34 +0000 (10:09 -0700)] 
Use crt*.o files from llvm compiler-rt when building with clang

2 years agoDo not use ppc-specific long double pack/unpack when compiling with clang
Stan Shebs [Tue, 9 Jun 2020 17:05:56 +0000 (10:05 -0700)] 
Do not use ppc-specific long double pack/unpack when compiling with clang

2 years agoRemove old workaround in power7 logb functions, clang no longer crashes on the inline...
Stan Shebs [Thu, 6 Feb 2020 19:58:01 +0000 (11:58 -0800)] 
Remove old workaround in power7 logb functions, clang no longer crashes on the inline assembly

2 years agoAdditional fixes for llvm-as
Josh Kunz [Fri, 24 Jan 2020 01:37:14 +0000 (17:37 -0800)] 
Additional fixes for llvm-as

Unlike GCC, llvm always uses an integrated assembler, which attempts to
recognized all `asm` statements written in the C code. glibc uses some
syntactically invalid asm statements to emit constants into assembly that
are later extracted with a sed or AWK script.

This change fixes two such invalid `asm` statements by wrapping the
output in a `.ascii` directive.. This does not break the sed/AWK (the same
special sequence is output) but it makes the statement syntactically valid.

See cf8e3f8757 for a previous fix for the same issue.

2 years agoAdd workaround for infinite looping in ppc vsyscall for sched_getcpu.
Stan Shebs [Fri, 24 Jan 2020 16:17:38 +0000 (08:17 -0800)] 
Add workaround for infinite looping in ppc vsyscall for sched_getcpu.

2 years agoAdd -Wno-incomplete-setjmp-declaration to prevent clang from unhelpfully complaining...
Stan Shebs [Fri, 24 Jan 2020 16:16:04 +0000 (08:16 -0800)] 
Add -Wno-incomplete-setjmp-declaration to prevent clang from unhelpfully complaining about __sigsetjmp, both in library build and testsuite runs.

2 years agoUpdate passwd.borg handling to use passwd.borg.real
Stan Shebs [Fri, 20 Dec 2019 21:58:35 +0000 (13:58 -0800)] 
Update passwd.borg handling to use passwd.borg.real

2 years agoAdd a case to async-signal-safe TLS to set static TLS instead of waiting for a dlopen...
Stan Shebs [Fri, 8 Nov 2019 21:41:17 +0000 (13:41 -0800)] 
Add a case to async-signal-safe TLS to set static TLS instead of waiting for a dlopen that may not actually be happening.

2 years agoAdd an LD_DEBUG=tls option to help debug thread-local storage handling in ld.so
Stan Shebs [Fri, 8 Nov 2019 20:40:53 +0000 (12:40 -0800)] 
Add an LD_DEBUG=tls option to help debug thread-local storage handling in ld.so

2 years agoRemove an unneeded local refactor in _dl_update_slotinfo
Stan Shebs [Wed, 30 Oct 2019 20:32:13 +0000 (13:32 -0700)] 
Remove an unneeded local refactor in _dl_update_slotinfo

2 years agoFix year 2039 bug for localtime with 64-bit time_t (bug 22639).
Joseph Myers [Fri, 18 May 2018 11:57:15 +0000 (11:57 +0000)] 
Fix year 2039 bug for localtime with 64-bit time_t (bug 22639).

Bug 22639 reports localtime failing to handle time offset transitions
correctly in 2039 and later on platforms with 64-bit time_t.

The problem is the use of SECSPERDAY (constant 86400) in calculations
such as

    t = ((year - 1970) * 365
 + /* Compute the number of leapdays between 1970 and YEAR
      (exclusive).  There is a leapday every 4th year ...  */
 + ((year - 1) / 4 - 1970 / 4)
 /* ... except every 100th year ... */
 - ((year - 1) / 100 - 1970 / 100)
 /* ... but still every 400th year.  */
 + ((year - 1) / 400 - 1970 / 400)) * SECSPERDAY;

where t is of type time_t and year is of type int.  Before my commit
92bd70fb85bce57ac47ba5d8af008736832c955a (an update from tzcode,
included in 2.26 and later releases), SECSPERDAY was obtained from a
file imported from tzcode, where the value included a cast to
int_fast32_t.  On 64-bit platforms, glibc defines int_fast32_t to be
long int, so 64-bit, but my patch resulted in it changing to int.
(The bug would probably have existed even before my patch for x32,
which has 64-bit time_t but 32-bit int_fast32_t, but I haven't
verified that.)

This patch fixes the problem by including a cast to time_t in the
definition of SECSPERDAY.  (64-bit time support for 32-bit systems
should move such code that isn't a public interface to using the
internal 64-bit version of time_t throughout.)

Tested for x86_64 and x86.

[BZ #22639]
* time/tzset.c (SECSPERDAY): Cast to time_t.
* time/tst-y2039.c: New file.
* time/Makefile (tests): Add tst-y2039.

2 years agoReduce __MAX_ALLOCA_CUTOFF to 8192
Stan Shebs [Tue, 8 Oct 2019 21:30:43 +0000 (14:30 -0700)] 
Reduce __MAX_ALLOCA_CUTOFF to 8192

2 years agoMake multi-arch ifunc support work with clang
Stan Shebs [Tue, 8 Oct 2019 20:00:12 +0000 (13:00 -0700)] 
Make multi-arch ifunc support work with clang

2 years agoRevert clang workaround for _begin that is no longer needed
Stan Shebs [Tue, 8 Oct 2019 14:07:18 +0000 (07:07 -0700)] 
Revert clang workaround for _begin that is no longer needed

2 years agoRedesign the fastload support for additional performance
Ambrose Feinstein [Wed, 11 Sep 2019 21:53:28 +0000 (14:53 -0700)] 
Redesign the fastload support for additional performance

2 years agoAdd comments explaining the diff from cf8e3f8757
Josh Kunz [Mon, 12 Aug 2019 20:28:09 +0000 (13:28 -0700)] 
Add comments explaining the diff from cf8e3f8757

These comments should make it easier to see the (small) diff introduced
in cf8e3f8757. Without these comments, the diff may get list on a future
upstream merge.

2 years agoMake gen-XX-const scripts work with llvm-as
Josh Kunz [Wed, 7 Aug 2019 18:40:50 +0000 (11:40 -0700)] 
Make gen-XX-const scripts work with llvm-as

The gen-as-const and gen-py-const scripts are used to generate integer constant
definitions from a list of constant C-expressions. This is achieved by
generating a C program with inline `asm` statements, that depend on
these constant expressions. During compilation, the constant expressions
are evaluated, and included in the inline asm. The build process
generates only the assembly, and then used `sed` to extract the values
from the assembly text.

This is clever. It allows the build process to extract the value of C
statements built under the target architecture. The implementation is a
bit fragile, but it is not immediately obvious to me how it could be
improved.

This change slightly modifies `gen-as-const` and `gen-py-const` to emit
valid assembly directives instead of invalid directives that were
previously emitted. Since the values are extracted via string parsing,
this has no effect on the values extracted. This is needed because the
LLVM assembler validates all statements before emitting them, whereas it
appears GCC will literally emit any `asm` directives without validation
or recognition.

2 years agoFix sense of a test in the static-linking version of ppc get_clockfreq
Stan Shebs [Fri, 17 May 2019 19:25:19 +0000 (12:25 -0700)] 
Fix sense of a test in the static-linking version of ppc get_clockfreq

2 years agoMakes it compile for AArch64
Shu-Chun Weng [Fri, 19 Apr 2019 21:50:50 +0000 (14:50 -0700)] 
Makes it compile for AArch64

De-nesting fix in 83c02e85 changed function signature but AArch64 was untested.

2 years agoMakes AArch64 assembly acceptable to clang
Shu-Chun Weng [Fri, 19 Apr 2019 21:47:59 +0000 (14:47 -0700)] 
Makes AArch64 assembly acceptable to clang

According to ARMv8 architecture reference manual section C7.2.188, SIMD MOV (to
general) instruction format is

  MOV <Xd>, <Vn>.D[<index>]

gas appears to accept "<Vn>.2D[<index>]" as well, but clang's assembler does
not. C.f. https://community.arm.com/developer/ip-products/processors/f/cortex-a-forum/5214/aarch64-assembly-syntax-for-armclang

2 years agoInclude STATIC_PIE_BOOTSTRAP with !NESTING in powerpc64/dl-machine.h
Siva Chandra Reddy [Tue, 9 Apr 2019 18:57:19 +0000 (11:57 -0700)] 
Include STATIC_PIE_BOOTSTRAP with !NESTING in powerpc64/dl-machine.h

2 years agoActuall use LLVM_OBJCOPY if available.
Siva Chandra Reddy [Mon, 8 Apr 2019 20:54:25 +0000 (13:54 -0700)] 
Actuall use LLVM_OBJCOPY if available.

2 years agoUse llvm-objcopy, if available, to remove the .llvm_addrsig sections.
Siva Chandra Reddy [Fri, 5 Apr 2019 14:46:36 +0000 (07:46 -0700)] 
Use llvm-objcopy, if available, to remove the .llvm_addrsig sections.

2 years agoEnable relaxed relocations when building certain object files for x86_64.
Siva Chandra Reddy [Tue, 2 Apr 2019 17:18:01 +0000 (10:18 -0700)] 
Enable relaxed relocations when building certain object files for x86_64.

2 years agoUn-nest an include in dl-reloc-static-pie.c.
Siva Chandra Reddy [Mon, 1 Apr 2019 18:26:29 +0000 (11:26 -0700)] 
Un-nest an include in dl-reloc-static-pie.c.

A corresponding adjustment in sysdeps/x86_64/dl-machine.h has also been
made.

2 years agoDisable -mfloat128 for clang, lets power9 insns into power8 executables
Stan Shebs [Mon, 25 Mar 2019 22:21:27 +0000 (15:21 -0700)] 
Disable -mfloat128 for clang, lets power9 insns into power8 executables

2 years agoAlso work around clang bctrl issue in get_clockfreq.c
Stan Shebs [Mon, 25 Mar 2019 21:03:24 +0000 (14:03 -0700)] 
Also work around clang bctrl issue in get_clockfreq.c