Commit Graph

2106 Commits

Author SHA1 Message Date
H.J. Lu 1864775abc 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.

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.

(cherry picked from commits 6ea5b57afa5cdc9ce367d2b69a2cebfb273e4617
 and 7137d682ebfcb6db5dfc5f39724718699922f06c)
2021-01-13 14:30:42 -08:00
H.J. Lu 420ade1f64 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.

(cherry picked from commit 2ef23b520597f4ea1790a669b83e608f24f4cf12)
2021-01-13 09:24:35 -08:00
H.J. Lu 8493ba72b1 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.

(cherry picked from commit 3ec5d83d2a237d39e7fd6ef7a0bc8ac4c171a4a5)
2021-01-12 07:01:34 -08:00
H.J. Lu 83aaa17144 NEWS: Mention BZ 25933 fix 2020-07-04 09:59:10 -07:00
Florian Weimer b0d3f7858c nss_compat: internal_end*ent may clobber errno, hiding ERANGE [BZ #25976]
During cleanup, before returning from get*_r functions, the end*ent
calls must not change errno.  Otherwise, an ERANGE error from the
underlying implementation can be hidden, causing unexpected lookup
failures.  This commit introduces an internal_end*ent_noerror
function which saves and restore errno, and marks the original
internal_end*ent function as warn_unused_result, so that it is used
only in contexts were errors from it can be handled explicitly.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 790b8dda4455865cb8c3a47801f4304c1a43baf6)
2020-05-19 16:33:04 +02:00
Kamlesh Kumar 42786ee476 <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)
2019-12-05 16:55:19 +01:00
Florian Weimer 0b4c3e1e0b x86: Assume --enable-cet if GCC defaults to CET [BZ #25225]
This links in CET support if GCC defaults to CET.  Otherwise, __CET__
is defined, yet CET functionality is not compiled and linked into the
dynamic loader, resulting in a linker failure due to undefined
references to _dl_cet_check and _dl_open_check.

(cherry picked from commit 9fb8139079ef0bb1aa33a4ae418cbb113b9b9da7)
2019-12-03 21:08:49 +01:00
Florian Weimer 44a61d4589 libio: Disable vtable validation for pre-2.1 interposed handles [BZ #25203]
Commit c402355dfa ("libio: Disable
vtable validation in case of interposition [BZ #23313]") only covered
the interposable glibc 2.1 handles, in libio/stdfiles.c.  The
parallel code in libio/oldstdfiles.c needs similar detection logic.

Fixes (again) commit db3476aff1
("libio: Implement vtable verification [BZ #20191]").

Change-Id: Ief6f9f17e91d1f7263421c56a7dc018f4f595c21
(cherry picked from commit cb61630ed712d033f54295f776967532d3f4b46a)
2019-11-28 14:17:27 +01:00
Florian Weimer 5422ac2d08 Update NEWS for CVE-2019-19126 2019-11-22 13:45:03 +01:00
Marcin Kościelnicki 2626b15e88 rtld: Check __libc_enable_secure before honoring LD_PREFER_MAP_32BIT_EXEC (CVE-2019-19126) [BZ #25204]
The problem was introduced in glibc 2.23, in commit
b9eb92ab05
("Add Prefer_MAP_32BIT_EXEC to map executable pages with MAP_32BIT").

(cherry picked from commit d5dfad4326fc683c813df1e37bbf5cf920591c8e)
Change-Id: Ib782573b4623ee3edfa9f98ad62f69b9d8edcb27
2019-11-22 13:11:36 +01:00
Aurelien Jarno a132a2c305 alpha: force old OSF1 syscalls for getegid, geteuid and getppid [BZ #24986]
On alpha, Linux kernel 5.1 added the standard getegid, geteuid and
getppid syscalls (commit ecf7e0a4ad15287). Up to now alpha was using
the corresponding OSF1 syscalls through:
 - sysdeps/unix/alpha/getegid.S
 - sysdeps/unix/alpha/geteuid.S
 - sysdeps/unix/alpha/getppid.S

When building against kernel headers >= 5.1, the glibc now use the new
syscalls through sysdeps/unix/sysv/linux/syscalls.list. When it is then
used with an older kernel, the corresponding 3 functions fail.

A quick fix is to move the OSF1 wrappers under the
sysdeps/unix/sysv/linux/alpha directory so they override the standard
linux ones. A better fix would be to try the new syscalls and fallback
to the old OSF1 in case the new ones fail. This can be implemented in
a later commit.

Changelog:
	[BZ #24986]
        * sysdeps/unix/alpha/getegid.S: Move to ...
	* sysdeps/unix/sysv/linux/alpha/getegid.S: ... here.
        * sysdeps/unix/alpha/geteuid.S: Move to ...
	* sysdeps/unix/sysv/linux/alpha/geteuid.S: ... here.
        * sysdeps/unix/alpha/getppid.S: Move to ...
	* sysdeps/unix/sysv/linux/alpha/getppid.S: ... here
2019-09-14 20:12:11 +02:00
Florian Weimer a00dc2a18f NEWS: Add deprecated section heading 2019-07-09 10:34:07 +02:00
Florian Weimer da347f4aa3 io: Remove copy_file_range emulation [BZ #24744]
The kernel is evolving this interface (e.g., removal of the
restriction on cross-device copies), and keeping up with that
is difficult.  Applications which need the function should
run kernels which support the system call instead of relying on
the imperfect glibc emulation.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 5a659ccc0ec217ab02a4c273a1f6d346a359560a)
2019-07-09 10:01:21 +02:00
Dmitry V. Levin 34fb5f61d3 libio: do not attempt to free wide buffers of legacy streams [BZ #24228]
Commit a601b74d31 aka glibc-2.23~693
("In preparation for fixing BZ#16734, fix failure in misc/tst-error1-mem
when _G_HAVE_MMAP is turned off.") introduced a regression:
_IO_unbuffer_all now invokes _IO_wsetb to free wide buffers of all
files, including legacy standard files which are small statically
allocated objects that do not have wide buffers and the _mode member,
causing memory corruption.

Another memory corruption in _IO_unbuffer_all happens when -1
is assigned to the _mode member of legacy standard files that
do not have it.

[BZ #24228]
* libio/genops.c (_IO_unbuffer_all)
[SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)]: Do not attempt to free wide
buffers and access _IO_FILE_complete members of legacy libio streams.
* libio/tst-bz24228.c: New file.
* libio/tst-bz24228.map: Likewise.
* libio/Makefile [build-shared] (tests): Add tst-bz24228.
[build-shared] (generated): Add tst-bz24228.mtrace and
tst-bz24228.check.
[run-built-tests && build-shared] (tests-special): Add
$(objpfx)tst-bz24228-mem.out.
(LDFLAGS-tst-bz24228, tst-bz24228-ENV): New variables.
($(objpfx)tst-bz24228-mem.out): New rule.

(cherry picked from commit 21cc130b78a4db9113fb6695e2b951e697662440)
2019-06-20 17:32:07 +00:00
Mark Wielaard 980cb43f15 Update NEWS for BZ#24476 Guard __dlerror_main_freeres. 2019-05-16 15:25:40 +02:00
Andreas Schwab c6177be4b9 Fix crash in _IO_wfile_sync (bug 20568)
When computing the length of the converted part of the stdio buffer, use
the number of consumed wide characters, not the (negative) distance to the
end of the wide buffer.

(cherry picked from commit 32ff397533715988c19cbf3675dcbd727ec13e18)
2019-05-15 17:09:05 +02:00
Adhemerval Zanella eaea1dfbe9 elf: Fix pldd (BZ#18035)
Since 9182aa6799 (Fix vDSO l_name for GDB's, BZ#387) the initial link_map
for executable itself and loader will have both l_name and l_libname->name
holding the same value due:

 elf/dl-object.c

 95   new->l_name = *realname ? realname : (char *) newname->name + libname_len - 1;

Since newname->name points to new->l_libname->name.

This leads to pldd to an infinite call at:

 elf/pldd-xx.c

203     again:
204       while (1)
205         {
206           ssize_t n = pread64 (memfd, tmpbuf.data, tmpbuf.length, name_offset);

228           /* Try the l_libname element.  */
229           struct E(libname_list) ln;
230           if (pread64 (memfd, &ln, sizeof (ln), m.l_libname) == sizeof (ln))
231             {
232               name_offset = ln.name;
233               goto again;
234             }

Since the value at ln.name (l_libname->name) will be the same as previously
read. The straightforward fix is just avoid the check and read the new list
entry.

I checked also against binaries issues with old loaders with fix for BZ#387,
and pldd could dump the shared objects.

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, and
powerpc64le-linux-gnu.

	[BZ #18035]
	* elf/Makefile (tests-container): Add tst-pldd.
	* elf/pldd-xx.c: Use _Static_assert in of pldd_assert.
	(E(find_maps)): Avoid use alloca, use default read file operations
	instead of explicit LFS names, and fix infinite	loop.
	* elf/pldd.c: Explicit set _FILE_OFFSET_BITS, cleanup headers.
	(get_process_info): Use _Static_assert instead of assert, use default
	directory operations instead of explicit LFS names, and free some
	leadek pointers.
	* elf/tst-pldd.c: New file.

(cherry picked from commit 1a4c27355e146b6d8cc6487b998462c7fdd1048f)
2019-04-26 14:31:22 +02:00
Florian Weimer 0744a268bc Revert "memusagestat: use local glibc when linking [BZ #18465]"
This reverts commit 42dfc13abf.

The position of the -Wl,-rpath-link= options on the linker command
line is not correct, so the new way of linking memusagestat does not
always work.
2019-04-25 14:58:13 +02:00
Mike Frysinger 42dfc13abf memusagestat: use local glibc when linking [BZ #18465]
The memusagestat is the only binary that has its own link line which
causes it to be linked against the existing installed C library.  It
has been this way since it was originally committed in 1999, but I
don't see any reason as to why.  Since we want all the programs we
build locally to be against the new copy of glibc, change the build
to be like all other programs.

(cherry picked from commit f9b645b4b0a10c43753296ce3fa40053fa44606a)
2019-04-24 19:07:46 +02:00
Carlos O'Donell dcd2b97dd1 malloc: Set and reset all hooks for tracing (Bug 16573)
If an error occurs during the tracing operation, particularly during a
call to lock_and_info() which calls _dl_addr, we may end up calling back
into the malloc-subsystem and relock the loader lock and deadlock. For
all intents and purposes the call to _dl_addr can call any of the malloc
family API functions and so we should disable all tracing before calling
such loader functions.  This is similar to the strategy that the new
malloc tracer takes when calling the real malloc, namely that all
tracing ceases at the boundary to the real function and any faults at
that point are the purvue of the library (though the new tracer does
this on a per-thread basis in an MT-safe fashion). Since the new tracer
and the hook deprecation are not yet complete we must fix these issues
where we can.

Tested on x86_64 with no regressions.

Co-authored-by: Kwok Cheung Yeung <kcy@codesourcery.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit e621246ec6393ea08ae50310f9d5e72500f8c9bc)
2019-04-15 20:49:32 +02:00
TAMUKI Shoichi 0941350c20 ja_JP locale: Add entry for the new Japanese era [BZ #22964]
The Japanese era name will be changed on May 1, 2019.  The Japanese
government made a preliminary announcement on April 1, 2019.

The glibc ja_JP locale must be updated to include the new era name for
strftime's alternative year format support.

This is a minimal cherry pick of just the required locale changes.

(cherry picked from commit 466afec30896585b60c2106df7a722a86247c9f3)
2019-04-03 19:42:20 +02:00
Aurelien Jarno 10dd17da71 Record CVE-2019-9169 in NEWS and ChangeLog [BZ #24114]
(cherry picked from commit b626c5aa5d0673a9caa48fb79fba8bda237e6fa8)
2019-03-16 23:27:47 +01:00
Florian Weimer 067fc32968 nptl: Fix invalid Systemtap probe in pthread_join [BZ #24211]
After commit f1ac7455831546e5dca0ed98fe8af2686fae7ce6 ("arm: Use "nr"
constraint for Systemtap probes [BZ #24164]"), we load pd->result into
a register in the probe below:

      /* Free the TCB.  */
      __free_tcb (pd);
    }
  else
    pd->joinid = NULL;

  LIBC_PROBE (pthread_join_ret, 3, threadid, result, pd->result);

However, at this point, the thread descriptor has been freed.  If the
thread stack does not fit into the thread stack cache, the memory will
have been unmapped, and the program will crash in the probe.

(cherry picked from commit bc10e22c90e42613bd5dafb77b80a9ea1759dd1b)
2019-02-15 21:27:01 +01:00
Florian Weimer c096b008d2 nptl: Avoid fork handler lock for async-signal-safe fork [BZ #24161]
Commit 27761a1042 ("Refactor atfork
handlers") introduced a lock, atfork_lock, around fork handler list
accesses.  It turns out that this lock occasionally results in
self-deadlocks in malloc/tst-mallocfork2:

(gdb) bt
#0  __lll_lock_wait_private ()
    at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:63
#1  0x00007f160c6f927a in __run_fork_handlers (who=(unknown: 209394016),
    who@entry=atfork_run_prepare) at register-atfork.c:116
#2  0x00007f160c6b7897 in __libc_fork () at ../sysdeps/nptl/fork.c:58
#3  0x00000000004027d6 in sigusr1_handler (signo=<optimized out>)
    at tst-mallocfork2.c:80
#4  sigusr1_handler (signo=<optimized out>) at tst-mallocfork2.c:64
#5  <signal handler called>
#6  0x00007f160c6f92e4 in __run_fork_handlers (who=who@entry=atfork_run_parent)
    at register-atfork.c:136
#7  0x00007f160c6b79a2 in __libc_fork () at ../sysdeps/nptl/fork.c:152
#8  0x0000000000402567 in do_test () at tst-mallocfork2.c:156
#9  0x0000000000402dd2 in support_test_main (argc=1, argv=0x7ffc81ef1ab0,
    config=config@entry=0x7ffc81ef1970) at support_test_main.c:350
#10 0x0000000000402362 in main (argc=<optimized out>, argv=<optimized out>)
    at ../support/test-driver.c:168

If no locking happens in the single-threaded case (where fork is
expected to be async-signal-safe), this deadlock is avoided.
(pthread_atfork is not required to be async-signal-safe, so a fork
call from a signal handler interrupting pthread_atfork is not
a problem.)

(cherry picked from commit 669ff911e2571f74a2668493e326ac9a505776bd)
2019-02-08 12:54:41 +01:00
Florian Weimer 2de15ac957 arm: Use "nr" constraint for Systemtap probes [BZ #24164]
With the default "nor" constraint, current GCC will use the "o"
constraint for constants, after emitting the constant to memory.  That
results in unparseable Systemtap probe notes such as "-4@.L1052".
Removing the "o" alternative and using "nr" instead avoids this.

(cherry picked from commit f1ac7455831546e5dca0ed98fe8af2686fae7ce6)
2019-02-05 13:49:03 +01:00
H.J. Lu 726a78867b x86-64 memcmp: Use unsigned Jcc instructions on size [BZ #24155]
Since the size argument is unsigned. we should use unsigned Jcc
instructions, instead of signed, to check size.

Tested on x86-64 and x32, with and without --disable-multi-arch.

	[BZ #24155]
	CVE-2019-7309
	* NEWS: Updated for CVE-2019-7309.
	* sysdeps/x86_64/memcmp.S: Use RDX_LP for size.  Clear the
	upper 32 bits of RDX register for x32.  Use unsigned Jcc
	instructions, instead of signed.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memcmp-2.
	* sysdeps/x86_64/x32/tst-size_t-memcmp-2.c: New test.

(cherry picked from commit 3f635fb43389b54f682fc9ed2acc0b2aaf4a923d)
2019-02-04 12:27:04 -08:00
Siddhesh Poyarekar 330c9d0db1 Prepare for 2.29 release
* NEWS: Add the list of bugs fixed in 2.29.
	* manual/contrib.texi: Update contributors list with some more
	names.
 	* manual/install.texi: Update latest versions of packages
 	tested.
 	* INSTALL: Regenerated.
2019-01-31 22:01:21 +05:30
TAMUKI Shoichi 32f600a272 strftime: Pass the additional flags from "%EY" to "%Ey" [BZ #24096]
The full representation of the alternative calendar year (%EY)
typically includes an internal use of "%Ey".  As a GNU extension,
apply any flags on "%EY" (e.g. "%_EY", "%-EY") to the internal "%Ey",
allowing users of "%EY" to control how the year is padded.

Reviewed-by: Rafal Luzynski <digitalfreak@lingonborough.com>
Reviewed-by: Zack Weinberg <zackw@panix.com>

ChangeLog:

	[BZ #24096]
	* manual/time.texi (strftime): Document "%EC" and "%EY".
	* time/Makefile (tests): Add tst-strftime2.
	(LOCALES): Add ja_JP.UTF-8, lo_LA.UTF-8, and th_TH.UTF-8.
	* time/strftime_l.c (__strftime_internal): Add argument yr_spec to
	override padding for "%Ey".
	If an optional flag ('_' or '-') is specified to "%EY", interpret the
	"%Ey" in the subformat as if decorated with that flag.
	* time/tst-strftime2.c: New file.
2019-01-24 23:04:12 +09:00
TAMUKI Shoichi b22eed3710 strftime: Set the default width of "%Ey" to 2 [BZ #23758]
In Japanese locales, strftime's alternative year format (%Ey) produces
a year numbered within a time period called an _era_.  A new era
typically begins when a new emperor is enthroned.  The result of "%Ey"
is therefore usually a one- or two-digit number.

Many programs that display Japanese era dates assume that the era year
is two digits wide.  To improve how these programs display dates
during the first nine years of a new era, change "%Ey" to pad one-
digit numbers on the left with a zero.  This change applies to all
locales.  It is expected to be harmless for other locales that use the
alternative year format (e.g. lo_LA and th_TH, in which "%Ey" produces
the year of the Buddhist calendar) as those calendars' year numbers
are already more than two digits wide, and this is not expected to
change.

This change needs to be in place before 2019-05-01 CE, as a new era is
scheduled to begin on that date.

Reviewed-by: Zack Weinberg <zackw@panix.com>
Reviewed-by: Rafal Luzynski <digitalfreak@lingonborough.com>

ChangeLog:

	[BZ #23758]
	* manual/time.texi (strftime): Document "%Ey".
	* time/strftime_l.c (__strftime_internal): Set the default width
	padding with zero of "%Ey" to 2.
2019-01-24 23:00:53 +09:00
Florian Weimer 108bc4049f CVE-2016-10739: getaddrinfo: Fully parse IPv4 address strings [BZ #20018]
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
6ca53a2453 ("resolv: Do not send queries
for non-host-names in nss_dns [BZ #24112]") is needed.
2019-01-21 21:26:03 +01:00
H.J. Lu 97700a34f3 x86-64 memchr/wmemchr: Properly handle the length parameter [BZ# 24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes memchr/wmemchr for x32.  Tested on x86-64 and x32.  On
x86-64, libc.so is the same with and withou the fix.

	[BZ# 24097]
	CVE-2019-6488
	* sysdeps/x86_64/memchr.S: Use RDX_LP for length.  Clear the
	upper 32 bits of RDX register.
	* sysdeps/x86_64/multiarch/memchr-avx2.S: Likewise.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memchr and
	tst-size_t-wmemchr.
	* sysdeps/x86_64/x32/test-size_t.h: New file.
	* sysdeps/x86_64/x32/tst-size_t-memchr.c: Likewise.
	* sysdeps/x86_64/x32/tst-size_t-wmemchr.c: Likewise.
2019-01-21 11:24:13 -08:00
Zack Weinberg 03992356e6
Use C99-compliant scanf under _GNU_SOURCE with modern compilers.
The only difference between noncompliant and C99-compliant scanf is
that the former accepts the archaic GNU extension '%as' (also %aS and
%a[...]) meaning to allocate space for the input string with malloc.
This extension conflicts with C99's use of %a as a format _type_
meaning to read a floating-point number; POSIX.1-2008 standardized
equivalent functionality using the modifier letter 'm' instead (%ms,
%mS, %m[...]).

The extension was already disabled in most conformance modes:
specifically, any mode that doesn't involve _GNU_SOURCE and _does_
involve either strict conformance to C99 or loose conformance to both
C99 and POSIX.1-2001 would get the C99-compliant scanf.  With
compilers new enough to use -std=gnu11 instead of -std=gnu89, or
equivalent, that includes the default mode.

With this patch, we now provide C99-compliant scanf in all
configurations except when _GNU_SOURCE is defined *and*
__STDC_VERSION__ or __cplusplus (whichever is relevant) indicates
C89/C++98.  This leaves the old scanf available under e.g. -std=c89
-D_GNU_SOURCE, but removes it from e.g. -std=gnu11 -D_GNU_SOURCE (it
was already not present under -std=gnu11 without -D_GNU_SOURCE) and
from -std=gnu89 without -D_GNU_SOURCE.

There needs to be an internal override so we can compile the
noncompliant scanf itself.  This is the same problem we had when we
removed 'gets' from _GNU_SOURCE and it's dealt with the same way:
there's a new __GLIBC_USE symbol, DEPRECATED_SCANF, which defaults to
off under the appropriate conditions for external code, but can be
overridden by individual files within stdio.

We also run into problems with PLT bypass for internal uses of sscanf,
because libc_hidden_proto uses __REDIRECT and so does the logic in
stdio.h for choosing which implementation of scanf to use; __REDIRECT
isn't transitive, so include/stdio.h needs to bridge the gap with a
macro.  As far as I can tell, sscanf is the only function in this
family that's internally called by unrelated code.

Finally, there are several tests in stdio-common that use the
extension.  bug21.c is a regression test for a crash; it still
exercises the relevant code when changed to use %ms instead of %as.
scanf14.c through scanf17.c are more complicated since they are
actually testing the subtleties of the extension - under what
circumstances is 'a' treated as a modifier letter, etc.  I changed all
of them to use %ms instead of %as as well, but duplicated scanf14.c
and scanf16.c as scanf14a.c and scanf16a.c.  These still use %as and
are compiled with -std=gnu89 to access the old extension.  A bunch of
diagnostic overrides and manual workarounds for the old stdio.h
behavior become unnecessary.  Yay!

	* include/features.h (__GLIBC_USE_DEPRECATED_SCANF): New __GLIBC_USE
	parameter.  Only use deprecated scanf when __USE_GNU is defined
	and __STDC_VERSION__ is less than 199901L or __cplusplus is less
	than 201103L, whichever is relevant for the language being compiled.

	* libio/stdio.h, libio/bits/stdio-ldbl.h: Decide whether to redirect
	scanf, fscanf, sscanf, vscanf, vfscanf, and vsscanf to their
	__isoc99_ variants based only on __GLIBC_USE (DEPRECATED_SCANF).
	* wcsmbs/wchar.h: wcsmbs/bits/wchar-ldbl.h: Likewise for
	wscanf, fwscanf, swscanf, vwscanf, vfwscanf, and vswscanf.

	* libio/iovsscanf.c
	* libio/fwscanf.c
	* libio/iovswscanf.c
	* libio/swscanf.c
	* libio/vscanf.c
	* libio/vwscanf.c
	* libio/wscanf.c
	* stdio-common/fscanf.c
	* stdio-common/scanf.c
	* stdio-common/vfscanf.c
	* stdio-common/vfwscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-compat.c
	* sysdeps/ieee754/ldbl-opt/nldbl-fscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-fwscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-scanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-sscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-swscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-vfscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-vfwscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-vscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-vsscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-vswscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-vwscanf.c
	* sysdeps/ieee754/ldbl-opt/nldbl-wscanf.c:
	Override __GLIBC_USE_DEPRECATED_SCANF to 1.

	* stdio-common/sscanf.c: Likewise.  Remove ldbl_hidden_def for __sscanf.
	* stdio-common/isoc99_sscanf.c: Add libc_hidden_def for __isoc99_sscanf.
	* include/stdio.h: Provide libc_hidden_proto for __isoc99_sscanf,
	not sscanf.
	[!__GLIBC_USE (DEPRECATED_SCANF)]: Define sscanf as __isoc99_scanf
	with a preprocessor macro.

	* stdio-common/bug21.c, stdio-common/scanf14.c:
	Use %ms instead of %as, %mS instead of %aS, %m[] instead of %a[];
	remove DIAG_IGNORE_NEEDS_COMMENT for -Wformat.
	* stdio-common/scanf16.c: Likewise.  Add __attribute__ ((format (scanf)))
	to xscanf, xfscanf, xsscanf.

	* stdio-common/scanf14a.c: New copy of scanf14.c which still uses
	%as, %aS, %a[].  Remove DIAG_IGNORE_NEEDS_COMMENT for -Wformat.
	* stdio-common/scanf16a.c: New copy of scanf16.c which still uses
	%as, %aS, %a[].  Add __attribute__ ((format (scanf))) to xscanf,
	xfscanf, xsscanf.
	* stdio-common/scanf15.c, stdio-common/scanf17.c: No need to
	override feature selection macros or provide definitions of u_char etc.
	* stdio-common/Makefile (tests): Add scanf14a and scanf16a.
	(CFLAGS-scanf15.c, CFLAGS-scanf17.c): Remove.
	(CFLAGS-scanf14a.c, CFLAGS-scanf16a.c): New.  Compile these files
	with -std=gnu89.
2019-01-03 11:12:39 -05:00
Joseph Myers c9123888d8 Update copyright dates not handled by scripts/update-copyrights.
I've updated copyright dates in glibc for 2019.  This is the patch for
the changes not generated by scripts/update-copyrights and subsequent
build / regeneration of generated files.

Please remember to include 2019 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).

	* NEWS: Update copyright dates.
	* catgets/gencat.c (print_version): Likewise.
	* csu/version.c (banner): Likewise.
	* debug/catchsegv.sh: Likewise.
	* debug/pcprofiledump.c (print_version): Likewise.
	* debug/xtrace.sh (do_version): Likewise.
	* elf/ldconfig.c (print_version): Likewise.
	* elf/ldd.bash.in: Likewise.
	* elf/pldd.c (print_version): Likewise.
	* elf/sotruss.sh: Likewise.
	* elf/sprof.c (print_version): Likewise.
	* iconv/iconv_prog.c (print_version): Likewise.
	* iconv/iconvconfig.c (print_version): Likewise.
	* locale/programs/locale.c (print_version): Likewise.
	* locale/programs/localedef.c (print_version): Likewise.
	* login/programs/pt_chown.c (print_version): Likewise.
	* malloc/memusage.sh (do_version): Likewise.
	* malloc/memusagestat.c (print_version): Likewise.
	* malloc/mtrace.pl: Likewise.
	* manual/libc.texinfo: Likewise.
	* nptl/version.c (banner): Likewise.
	* nscd/nscd.c (print_version): Likewise.
	* nss/getent.c (print_version): Likewise.
	* nss/makedb.c (print_version): Likewise.
	* posix/getconf.c (main): Likewise.
	* scripts/test-installation.pl: Likewise.
	* sysdeps/unix/sysv/linux/lddlibc4.c (main): Likewise.
2019-01-01 00:15:13 +00:00
Joseph Myers 04277e02d7 Update copyright dates with scripts/update-copyrights.
* All files with FSF copyright notices: Update copyright dates
	using scripts/update-copyrights.
	* locale/programs/charmap-kw.h: Regenerated.
	* locale/programs/locfile-kw.h: Likewise.
2019-01-01 00:11:28 +00:00
Rafal Luzynski 5fc3eca750 NEWS: Fix another typo ("multithread..." -> "multi-threaded...").
Thank you Florian Weimer and Paul Eggert for proofreading this.
2018-12-28 21:19:50 +01:00
Rafal Luzynski e46d7dedcf NEWS: Fix a minor typo ("incosistent" -> "inconsistent"). 2018-12-28 08:55:34 +01:00
Joseph Myers 192963be49 Require GCC 5 or later to build glibc (bug 23993).
We know that building glibc with GCC 4.9 is broken on various
platforms (bug 23993).  As it's more than a year since we last
increased the minimum GCC version to build glibc, this patch changes
the requirement to be GCC 5 or later (indeed, based on 4.9 having been
required for building 2.26, it would be consistent in terms of timing
to require GCC 6 or later from the 2.30 release onwards).  It
deliberately just updates the configure test and corresponding
documentation, leaving removal of no-longer-needed __GNUC_PREREQ tests
for a separate patch.

In the NEWS entry, the requirement for a newer GCC version for
powerpc64le is reiterated (as in the entry for the 4.9 requirement in
2.26) to avoid suggesting the version requirement there has gone down.
(If that version goes up further as part of support for binary128 long
double, of course the wording would change at that time.)

Tested for x86_64.

	[BZ #23993]
	* configure.ac (libc_cv_compiler_ok): Require GCC 5 or later.
	* configure: Regenerated.
	* manual/install.texi (Tools for Compilation): Update minimum GCC
	version.
	* INSTALL: Regenerated.
2018-12-21 17:53:40 +00:00
Mao Han 5f72b00591 Add C-SKY port
This patch add two abi combinations support for C-SKY ABIV2: soft-float
little endian, hard float little endian. C-SKY ABI manual and architecture
user guide are available from: https://github.com/c-sky/csky-doc

	* config.h.in (CSKYABI, CSKY_HARD_FLOAT): New Define.
	* scripts/build-many-glibcs.py: Add C-SKY targets.
	* sysdeps/csky/Implies: New file.
	* sysdeps/csky/Makefile: Likewise.
	* sysdeps/csky/abiv2/__longjmp.S: Likewise.
	* sysdeps/csky/abiv2/csky-mcount.S: Likewise.
	* sysdeps/csky/abiv2/dl-trampoline.S: Likewise.
	* sysdeps/csky/abiv2/memcmp.S: Likewise.
	* sysdeps/csky/abiv2/memcpy.S: Likewise.
	* sysdeps/csky/abiv2/memmove.S: Likewise.
	* sysdeps/csky/abiv2/memset.S: Likewise.
	* sysdeps/csky/abiv2/setjmp.S: Likewise.
	* sysdeps/csky/abiv2/start.S: Likewise.
	* sysdeps/csky/abiv2/strcmp.S: Likewise.
	* sysdeps/csky/abiv2/strcpy.S: Likewise.
	* sysdeps/csky/abiv2/strlen.S: Likewise.
	* sysdeps/csky/abiv2/tls-macros.h: Likewise.
	* sysdeps/csky/abort-instr.h: Likewise.
	* sysdeps/csky/atomic-machine.h: Likewise.
	* sysdeps/csky/bits/endian.h: Likewise.
	* sysdeps/csky/bits/fenv.h: Likewise.
	* sysdeps/csky/bits/link.h: Likewise.
	* sysdeps/csky/bits/setjmp.h: Likewise.
	* sysdeps/csky/bsd-_setjmp.S: Likewise.
	* sysdeps/csky/bsd-setjmp.S: Likewise.
	* sysdeps/csky/configure: Likewise.
	* sysdeps/csky/configure.ac: Likewise.
	* sysdeps/csky/dl-machine.h: Likewise.
	* sysdeps/csky/dl-procinfo.c: Likewise.
	* sysdeps/csky/dl-procinfo.h: Likewise.
	* sysdeps/csky/dl-sysdep.h: Likewise.
	* sysdeps/csky/dl-tls.h: Likewise.
	* sysdeps/csky/fpu/fclrexcpt.c: Likewise.
	* sysdeps/csky/fpu/fedisblxcpt.c: Likewise.
	* sysdeps/csky/fpu/feenablxcpt.c: Likewise.
	* sysdeps/csky/fpu/fegetenv.c: Likewise.
	* sysdeps/csky/fpu/fegetexcept.c: Likewise.
	* sysdeps/csky/fpu/fegetmode.c: Likewise.
	* sysdeps/csky/fpu/fegetround.c: Likewise.
	* sysdeps/csky/fpu/feholdexcpt.c: Likewise.
	* sysdeps/csky/fpu/fenv_libc.h: Likewise.
	* sysdeps/csky/fpu/fenv_private.h: Likewise.
	* sysdeps/csky/fpu/fesetenv.c: Likewise.
	* sysdeps/csky/fpu/fesetexcept.c: Likewise.
	* sysdeps/csky/fpu/fesetmode.c: Likewise.
	* sysdeps/csky/fpu/fesetround.c: Likewise.
	* sysdeps/csky/fpu/feupdateenv.c: Likewise.
	* sysdeps/csky/fpu/fgetexcptflg.c: Likewise.
	* sysdeps/csky/fpu/fix-fp-int-convert-overflow.h: Likewise.
	* sysdeps/csky/fpu/fraiseexcpt.c: Likewise.
	* sysdeps/csky/fpu/fsetexcptflg.c: Likewise.
	* sysdeps/csky/fpu/ftestexcept.c: Likewise.
	* sysdeps/csky/fpu/libm-test-ulps: Likewise.
	* sysdeps/csky/fpu/libm-test-ulps-name: Likewise.
	* sysdeps/csky/fpu_control.h: Likewise.
	* sysdeps/csky/gccframe.h: Likewise.
	* sysdeps/csky/jmpbuf-unwind.h: Likewise.
	* sysdeps/csky/ldsodefs.h: Likewise.
	* sysdeps/csky/libc-tls.c: Likewise.
	* sysdeps/csky/linkmap.h: Likewise.
	* sysdeps/csky/machine-gmon.h: Likewise.
	* sysdeps/csky/memusage.h: Likewise.
	* sysdeps/csky/nofpu/Implies: Likewise.
	* sysdeps/csky/nofpu/libm-test-ulps: Likewise.
	* sysdeps/csky/nofpu/libm-test-ulps-name: Likewise.
	* sysdeps/csky/nptl/Makefile: Likewise.
	* sysdeps/csky/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/csky/nptl/bits/semaphore.h: Likewise.
	* sysdeps/csky/nptl/pthread-offsets.h: Likewise.
	* sysdeps/csky/nptl/pthreaddef.h: Likewise.
	* sysdeps/csky/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/csky/nptl/tls.h: Likewise.
	* sysdeps/csky/preconfigure: Likewise.
	* sysdeps/csky/sfp-machine.h: Likewise.
	* sysdeps/csky/sotruss-lib.c: Likewise.
	* sysdeps/csky/stackinfo.h: Likewise.
	* sysdeps/csky/sysdep.h: Likewise.
	* sysdeps/csky/tininess.h: Likewise.
	* sysdeps/csky/tst-audit.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/Implies: Likewise.
	* sysdeps/unix/sysv/linux/csky/Makefile: Likewise.
	* sysdeps/unix/sysv/linux/csky/Versions: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/____longjmp_chk.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/getcontext.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/setcontext.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/swapcontext.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/syscall.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym: Likewise.
	* sysdeps/unix/sysv/linux/csky/bits/procfs.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/bits/shmlba.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/c++-types.data: Likewise.
	* sysdeps/unix/sysv/linux/csky/configure: Likewise.
	* sysdeps/unix/sysv/linux/csky/configure.ac: Likewise.
	* sysdeps/unix/sysv/linux/csky/ipc_priv.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/kernel-features.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/ld.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/ldconfig.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/libBrokenLocale.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libanl.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libcrypt.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libdl.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libresolv.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/librt.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libthread_db.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libutil.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/localplt.data: Likewise.
	* sysdeps/unix/sysv/linux/csky/makecontext.c: Likewise.
	* sysdeps/unix/sysv/linux/csky/profil-counter.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/pt-vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/csky/register-dump.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/shlib-versions: Likewise.
	* sysdeps/unix/sysv/linux/csky/sigcontextinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/sys/cachectl.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/sys/user.h: Likewise.
	* sysdeps/unix/sysv/linux/csky/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/csky/sysdep.h: Likewise.
2018-12-21 09:48:04 +08:00
H.J. Lu a092ca9453 Add getcpu
Add

  #include <sched.h>

  int getcpu (unsigned int *cpu, unsigned int *node);

to return currently used CPU and NUMA node.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.

	* NEWS: Mention getcpu.
	* include/sched.h (__getcpu): New libc_hidden_proto.
	* manual/resource.texi: Document getcpu.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/bits/sched.h (getcpu): New prototype.
	* sysdeps/unix/sysv/linux/getcpu.c: New file.
	* sysdeps/unix/sysv/linux/tst-skeleton-affinity.c (test_size):
	Also check getcpu.
2018-12-07 09:17:50 -08:00
Florian Weimer 3a3fb75572 posix: New function posix_spawn_file_actions_addfchdir_np [BZ #17405]
Along with posix_spawn_file_actions_addchdir,
posix_spawn_file_actions_addfchdir is the subject of a change proposal
for POSIX: <http://austingroupbugs.net/view.php?id=1208>
2018-12-07 16:04:05 +01:00
Adhemerval Zanella 14d0e87d9b posix: Use posix_spawn on popen
This patch uses posix_spawn on popen instead of fork and execl.  On Linux
this has the advantage of much lower memory consumption (usually 32 Kb
minimum for the mmap stack area).

Two issues are also fixed with this change:

  * BZ#17490: although POSIX pthread_atfork description only list 'fork'
    as the function that should execute the atfork handlers, popen
    description states that:

      '[...] shall be *as if* a child process were created within the popen()
       call using the fork() function [...]'

    Other libc/system seems to follow the idea atfork handlers should not be
    executed for popen:

    libc/system	| run atfork handles   | notes
    ------------|----------------------|---------------------------------------
    Freebsd	|        no            | uses vfork
    Solaris 11	|        no            |
    MacOSX 11   |        no            | implemented through posix_spawn syscall
    ------------|----------------------|----------------------------------------

    Similar to posix_spawn and system, popen idea is to spawn a different
    binary so all the POSIX rationale to run the atfork handlers to avoid
    internal process inconsistency is not really required and in some cases
    might be unsafe.

  * BZ#22834: the described scenario, where the forked process might access
    invalid memory due an inconsistent state in multithreaded environment,
    should not happen because posix_spawn does not access the affected
    data structure (proc_file_chain).

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

	[BZ #22834]
	[BZ #17490]
	* NEWS: Add new semantic for atfork with popen and system.
	* libio/iopopen.c (_IO_new_proc_open): use posix_spawn instead of
	fork and execl.
2018-11-30 18:42:05 -02:00
Florian Weimer d527c860f5 CVE-2018-19591: if_nametoindex: Fix descriptor for overlong name [BZ #23927] 2018-11-27 18:12:49 +01:00
Florian Weimer 4a938cb273 posix: New function posix_spawn_file_actions_addchdir_np [BZ #17405] 2018-11-06 16:08:12 +01:00
Joseph Myers c6982f7efc Patch to require Python 3.4 or later to build glibc.
This patch makes Python 3.4 or later a required tool for building
glibc, so allowing changes of awk, perl etc. code used in the build
and test to Python code without any such changes needing makefile
conditionals or to handle older Python versions.

This patch makes the configure test for Python check the version and
give an error if Python is missing or too old, and removes makefile
conditionals that are no longer needed.  It does not itself convert
any code from another language to Python, and does not remove any
compatibility with older Python versions from existing scripts.

Tested for x86_64.

	* configure.ac (PYTHON_PROG): Use AC_CHECK_PROG_VER.  Set
	critic_missing for versions before 3.4.
	* configure: Regenerated.
	* manual/install.texi (Tools for Compilation): Document
	requirement for Python to build glibc.
	* INSTALL: Regenerated.
	* Rules [PYTHON]: Make code unconditional.
	* benchtests/Makefile [PYTHON]: Likewise.
	* conform/Makefile [PYTHON]: Likewise.
	* manual/Makefile [PYTHON]: Likewise.
	* math/Makefile [PYTHON]: Likewise.
2018-10-29 15:28:05 +00:00
Joseph Myers b71ac2b9ce Use gen-libm-test.py to generate ulps table for manual.
This patch extends gen-libm-test.py to generate the ulps table for the
manual, so meaning there is only a single ulps file parser needed and
another Perl script is eliminated.  As with the introduction of
gen-libm-test.py, this is designed to generate exactly the same
libm-err.texi as libm-err-tab.pl did.  (gen-libm-test.py is still
shorter in lines than the old gen-libm-test.pl even after this patch.)
Note that this introduces a Python dependency for building the manual,
which is thus noted in install.texi and NEWS.

Tested building html / info / pdf versions of the manual.

	* math/gen-libm-test.py: Import os.
	(ALL_FLOATS_MANUAL): New constant.
	(ALL_FLOATS_SUFFIX): Likewise.
	(Ulps.all_functions): New function.
	(real_all_ulps): Likewise.
	(generate_err_table_sub): Likewise.
	(generate_err_table): Likewise.
	(main): Handle -s and -m options.
	* manual/libm-err-tab.pl: Remove.
	* manual/Makefile ($(objpfx)stamp-libm-err): Use gen-libm-test.py
	instead of libm-err-tab.pl.
	[$(PERL) != no]: Change condition to [$(if $(PYTHON),$(PERL),no)
	!= no].
	* manual/install.texi (Tools for Compilation): Document
	requirement for Python to build manual.
	* INSTALL: Regenerated.
2018-10-24 20:34:31 +00:00
Adhemerval Zanella f0458cf4f9 powerpc: Only enable TLE with PPC_FEATURE2_HTM_NOSC
Linux from 3.9 through 4.2 does not abort HTM transaction on syscalls,
instead it suspend and resume it when leaving the kernel.  The
side-effects of the syscall will always remain visible, even if the
transaction is aborted.  This is an issue when transaction is used along
with futex syscall, on pthread_cond_wait for instance, where the futex
call might succeed but the transaction is rolled back leading the
pthread_cond object in an inconsistent state.

Glibc used to prevent it by always aborting a transaction before issuing
a syscall.  Linux 4.2 also decided to abort active transaction in
syscalls which makes the glibc workaround superfluous.  Worse, glibc
transaction abortion leads to a performance issue on recent kernels
where the HTM state is saved/restore lazily (v4.9).  By aborting a
transaction on every syscalls, regardless whether a transaction has being
initiated before, GLIBS makes the kernel always save/restore HTM state
(it can not even lazily disable it after a certain number of syscall
iterations).

Because of this shortcoming, Transactional Lock Elision is just enabled
when it has been explicitly set (either by tunables of by a configure
switch) and if kernel aborts HTM transactions on syscalls
(PPC_FEATURE2_HTM_NOSC).  It is reported that using simple benchmark [1],
the context-switch is about 5% faster by not issuing a tabort in every
syscall in newer kernels.

Checked on powerpc64le-linux-gnu with 4.4.0 kernel (Ubuntu 16.04).

	* NEWS: Add note about new TLE support on powerpc64le.
	* sysdeps/powerpc/nptl/tcb-offsets.sym (TM_CAPABLE): Remove.
	* sysdeps/powerpc/nptl/tls.h (tcbhead_t): Rename tm_capable to
	__ununsed1.
	(TLS_INIT_TP, TLS_DEFINE_INIT_TP): Remove tm_capable setup.
	(THREAD_GET_TM_CAPABLE, THREAD_SET_TM_CAPABLE): Remove macros.
	* sysdeps/powerpc/powerpc32/sysdep.h,
	sysdeps/powerpc/powerpc64/sysdep.h (ABORT_TRANSACTION_IMPL,
	ABORT_TRANSACTION): Remove macros.
	* sysdeps/powerpc/sysdep.h (ABORT_TRANSACTION): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/elision-conf.c (elision_init): Set
	__pthread_force_elision iff PPC_FEATURE2_HTM_NOSC is set.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h,
	sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
	sysdeps/unix/sysv/linux/powerpc/syscall.S (ABORT_TRANSACTION): Remove
	usage.
	* sysdeps/unix/sysv/linux/powerpc/not-errno.h: Remove file.

Reported-by: Breno Leitão <leitao@debian.org>
2018-09-21 10:18:03 -07:00
Szabolcs Nagy 424c4f60ed Add new pow implementation
The algorithm is exp(y * log(x)), where log(x) is computed with about
1.3*2^-68 relative error (1.5*2^-68 without fma), returning the result
in two doubles, and the exp part uses the same algorithm (and lookup
tables) as exp, but takes the input as two doubles and a sign (to handle
negative bases with odd integer exponent).  The __exp1 internal symbol
is no longer necessary.

There is separate code path when fma is not available but the worst case
error is about 0.54 ULP in both cases.  The lookup table and consts for
log are 4168 bytes.  The .rodata+.text is decreased by 37908 bytes on
aarch64.  The non-nearest rounding error is less than 1 ULP.

Improvements on Cortex-A72 compared to current glibc master:
pow thruput: 2.40x in [0.01 11.1]x[0.01 11.1]
pow latency: 1.84x in [0.01 11.1]x[0.01 11.1]

Tested on
aarch64-linux-gnu (defined __FP_FAST_FMA, TOINT_INTRINSICS) and
arm-linux-gnueabihf (!defined __FP_FAST_FMA, !TOINT_INTRINSICS) and
x86_64-linux-gnu (!defined __FP_FAST_FMA, !TOINT_INTRINSICS) and
powerpc64le-linux-gnu (defined __FP_FAST_FMA, !TOINT_INTRINSICS) targets.

	* NEWS: Mention pow improvements.
	* math/Makefile (type-double-routines): Add e_pow_log_data.
	* sysdeps/generic/math_private.h (__exp1): Remove.
	* sysdeps/i386/fpu/e_pow_log_data.c: New file.
	* sysdeps/ia64/fpu/e_pow_log_data.c: New file.
	* sysdeps/ieee754/dbl-64/Makefile (CFLAGS-e_pow.c): Allow fma
	contraction.
	* sysdeps/ieee754/dbl-64/e_exp.c (__exp1): Remove.
	(exp_inline): Remove.
	(__ieee754_exp): Only single double input is handled.
	* sysdeps/ieee754/dbl-64/e_pow.c: Rewrite.
	* sysdeps/ieee754/dbl-64/e_pow_log_data.c: New file.
	* sysdeps/ieee754/dbl-64/math_config.h (issignaling_inline): Define.
	(__pow_log_data): Define.
	* sysdeps/ieee754/dbl-64/upow.h: Remove.
	* sysdeps/ieee754/dbl-64/upow.tbl: Remove.
	* sysdeps/m68k/m680x0/fpu/e_pow_log_data.c: New file.
	* sysdeps/x86_64/fpu/multiarch/Makefile (CFLAGS-e_pow-fma.c): Allow fma
	contraction.
	(CFLAGS-e_pow-fma4.c): Likewise.
2018-09-19 10:04:51 +01:00
Joseph Myers 3f7f1d180d Fix MIPS n32 pr_sigpend, pr_sighold, pr_flag type (bug 23656).
As discussed at
<https://sourceware.org/ml/libc-alpha/2018-09/msg00191.html> and
followup discussions, the MIPS n32 definitions of pr_sigpend and
pr_sighold in struct elf_prstatus, and pr_flag in struct elf_prpsinfo,
are wrong to use unsigned long long int; actual n32 core dumps use a
32-bit type there, so userspace unsigned long int is correct for all
MIPS ABIs.  This patch removes the conditionals (also thereby aligning
the structures with other architectures and so facilitating future
unification of different versions of this header).

Tested with build-many-glibcs.py for its MIPS configurations.

	[BZ #23656]
	* sysdeps/unix/sysv/linux/mips/sys/procfs.h (struct elf_prstatus):
	Remove [_MIPS_SIM = _ABIN32] conditional case.
	(struct elf_prpsinfo): Likewise.
2018-09-14 16:02:57 +00:00
Joseph Myers d59f3e5e0f Fix sys/procfs.h pr_uid, pr_gid type (bug 23649).
As noted in
<https://sourceware.org/ml/libc-alpha/2018-09/msg00178.html>, glibc's
sys/procfs.h headers for microblaze, mips (n64), nios2 and riscv have
incorrect types for the pr_uid and pr_gid members of struct
elf_prpsinfo (as does the generic Linux version, but nothing uses
that).

This patch fixes those headers to use unsigned int.  The generic Linux
version is also fixed, but I do *not* recommend making new
architectures use it yet.  Rather, I think it should be reworked to
look more like a copy of the AArch64 version, but with a new
<bits/procfs.h> header included to provide register set definitions;
<bits/procfs.h> would then be architecture-specific while many
architectures could use the generic <sys/procfs.h>.  This fix is
deliberately separate from any reworking to use a generic header more,
since it's possible there could be uses for backporting this fix but
not for backporting a subsequent cleanup.

Tested with build-many-glibcs.py.  This of course doesn't provide much
validation of the structure layout; if the Linux kernel is fixed so
that "#include <linux/elfcore.h>" actually compiles with the headers
from "make headers_install" (and if the layout in both headers is
meant to be the same, whatever ABI we are building for), I have a test
that can be added to glibc to check the layout against that from the
Linux kernel.

	[BZ #23649]
	* sysdeps/unix/sysv/linux/microblaze/sys/procfs.h (struct
	elf_prpsinfo): Use unsigned int for pr_uid and pr_gid.
	* sysdeps/unix/sysv/linux/mips/sys/procfs.h (struct elf_prpsinfo):
	Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/procfs.h (struct
	elf_prpsinfo): Likewise.
	* sysdeps/unix/sysv/linux/riscv/sys/procfs.h (struct
	elf_prpsinfo): Likewise.
	* sysdeps/unix/sysv/linux/sys/procfs.h (struct elf_prpsinfo):
	Likewise.
2018-09-14 13:21:33 +00:00
Szabolcs Nagy 3e08ff544b Add new log2 implementation
Similar algorithm is used as in log: log2(2^k x) = k + log2(c) + log2(x/c)
where the last term is approximated by a polynomial of x/c - 1, the first
order coefficient is about 1/ln2 in this case.

There is separate code path when fma instruction is not available for
computing x/c - 1 precisely, for which the table size is doubled.

The worst case error is 0.547 ULP (0.55 without fma), the read only
global data size is 1168 bytes (2192 without fma) on aarch64.  The
non-nearest rounding error is less than 1 ULP.

Improvements on Cortex-A72 compared to current glibc master:
log2 thruput: 2.00x in [0.01 11.1]
log2 latency: 2.04x in [0.01 11.1]
log2 thruput: 2.17x in [0.999 1.001]
log2 latency: 2.88x in [0.999 1.001]

Tested on
aarch64-linux-gnu (defined __FP_FAST_FMA)
arm-linux-gnueabihf (!defined __FP_FAST_FMA)
x86_64-linux-gnu (!defined __FP_FAST_FMA)
powerpc64le-linxu-gnu (defined __FP_FAST_FMA)
targets.

	* NEWS: Mention log2 improvements.
	* math/Makefile (type-double-routines): Add e_log2_data.
	* sysdeps/i386/fpu/e_log2_data.c: New file.
	* sysdeps/ia64/fpu/e_log2_data.c: New file.
	* sysdeps/ieee754/dbl-64/e_log2.c: Rewrite.
	* sysdeps/ieee754/dbl-64/e_log2_data.c: New file.
	* sysdeps/ieee754/dbl-64/math_config.h (__log2_data): Add.
	* sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c: Remove.
	* sysdeps/m68k/m680x0/fpu/e_log2_data.c: New file.
2018-09-12 17:36:33 +01:00