Bruno Haible [Mon, 8 Jan 2024 17:10:28 +0000 (18:10 +0100)]
jit/cache tests: Avoid test failure on OpenBSD.
* modules/jit/cache-tests (Files): Add m4/warnings.m4.
(configure.ac): Set and substitute DISABLE_OPENBSD_RETGUARD.
(Makefile.am): Set test_cache_CFLAGS.
* tests/jit/test-cache.c (main): If the compiler defines _RET_PROTECTOR,
skip the test.
Bruno Haible [Tue, 2 Jan 2024 10:37:05 +0000 (11:37 +0100)]
strverscmp: Work around bug in musl libc 1.2.3 and in Cygwin.
Reported by Dmitry Bogatov <KAction@gnu.org> via Simon Josefsson in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-01/msg00002.html>.
* m4/string_h.m4 (gl_STRING_H_DEFAULTS): Initialize REPLACE_STRVERSCMP.
* m4/strverscmp.m4 (gl_FUNC_STRVERSCMP): Test whether strverscmp works
and set REPLACE_STRVERSCMP if not.
* lib/string.in.h (strverscmp): Consider REPLACE_STRVERSCMP.
* modules/strverscmp (Depends-on, configure.ac): Likewise.
* modules/string (Makefile.am): Substitute REPLACE_STRVERSCMP.
* tests/test-strverscmp.c (main): Add test cases suggested by Dmitry
Bogatov and by Simon Josefsson.
* doc/glibc-functions/strverscmp.texi: Mention the musl and Cygwin bug.
Update version info regarding FreeBSD.
Paul Eggert [Tue, 2 Jan 2024 00:51:51 +0000 (16:51 -0800)]
update-copyright-tests: immunize against self
Problem reported by Bernhard Voelker in:
https://lists.gnu.org/r/bug-gnulib/2024-01/msg00003.html
* tests/test-update-copyright.sh (ight): New var.
Use it in tests, to prevent update-copyright from
messing with the test data.
* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): Pass
-Wno-tautological-constant-out-of-range-compare to clang, as it’s
the warning is enabled by default and in portable code where type
ranges are platform dependent it is generally more trouble than
it’s worth.
Without this change, Ubuntu clang version 16.0.6 (15) issues
warnings like this: “In file included from xalloc-die.c:25:
./error.h:28:3: warning: #include_next in file found relative to
primary source file or found by absolute path; will search from
start of include path [-Winclude-next-absolute-path]”.
And sure enough, each file includes itself rather than the
next include file and it’s only the subsidiary include that
gets around to including the next include file.
* lib/argmatch.c, lib/chdir-long.c, lib/clean-temp-simple.c:
* lib/clean-temp.c, lib/closein.c, lib/closeout.c, lib/copy-acl.c:
* lib/copy-file.c, lib/creat.c, lib/csharpcomp.c:
* lib/csharpexec.c, lib/error.c, lib/exclude.c, lib/execute.c:
* lib/faccessat.c, lib/fopen.c, lib/freopen.c, lib/getopt.c:
* lib/getopt1.c, lib/git-merge-changelog.c, lib/javacomp.c:
* lib/javaexec.c, lib/javaversion.c, lib/mkdir-p.c, lib/open.c:
* lib/openat-die.c, lib/openat.c, lib/os2-spawn.c:
* lib/pagealign_alloc.c, lib/pipe-filter-gi.c:
* lib/pipe-filter-ii.c, lib/same.c, lib/set-acl.c:
* lib/sigpipe-die.c, lib/spawn-pipe.c, lib/sys_socket.c, lib/truncate.c:
* lib/unistd.c, lib/verror.c, lib/wait-process.c, lib/wctype-h.c:
* lib/xalloc-die.c, lib/xfreopen.c, lib/xmemcoll.c, lib/xprintf.c:
* lib/xsetenv.c, lib/xstdopen.c, lib/xstrtol-error.c:
Use ‘#include <foo.h>’ instead of ‘#include "foo.h"’ if foo.h
possibly uses #include_next. (However, don’t do this on OSF/1
which has its own problems.)
Paul Eggert [Thu, 28 Dec 2023 19:15:56 +0000 (11:15 -0800)]
stat-time: fix macOS bug with negative file times
macOS has a bug similar (but not identical) to Solaris when
file timestamps are negative: tv_nsec might go negative.
Problem reported on Darwin 8.11.0 for GNU Tar by Gordon Steemson in:
https://lists.gnu.org/r/bug-tar/2023-12/msg00001.html
This was evidently Mac OS X 10.4.11; I reproduced it on
Darwin 21.6.0 (macOS 12.5).
* lib/stat-time.h (STAT_TIMESPEC_OFFSETOF): New macro.
(stat_time_normalize): Also normalize timestamps on macOS.
* m4/fstat.m4 (gl_FUNC_FSTAT):
* m4/fstatat.m4 (gl_FUNC_FSTATAT):
* m4/lstat.m4 (gl_FUNC_LSTAT):
* m4/stat.m4 (gl_FUNC_STAT):
Also replace on macOS.
* tests/jit/test-cache.c (CODE): New macro.
(struct func): New type.
(main): Initialize f more carefully.
* modules/jit/cache-tests (Depends-on): Add host-cpu-c-abi.
selinux-h: add stubs and wrappers for raw counterparts
Add stubs and wrappers of already covered libselinux interfaces for
their `raw` counterparts. These counterparts perform the same
operation expect for context translation. Context translation is used
to convert SELinux MCS/MLS labels into human readable form, see
mcstransd(8).
* lib/se-selinux.in.h: Add declarations for raw variants.
* lib/se-label.in.h: Likewise.
* lib/getfilecon.c: Add wrappers for problematic raw variants.
* m4/selinux-selinux-h.m4: Use wrappers for problematic raw variants.
Paul Eggert [Tue, 12 Dec 2023 01:47:38 +0000 (17:47 -0800)]
savedir: scale better when sorting by name
* lib/savedir.c: Include attribute.h.
(direntry_t): The ‘name’ member is now idx_t, not char *,
so that it survives name_space relocation.
(direntry_cmp_name, direntry_cmp_inode, comparison_function):
Adjust to qsort_r API, and to direntry_t layout change.
(streamsavedir): Redo to avoid need for xstrdup on each directory
entry. Instead, copy the string data into name_space; this
typically scales better the memory allocator is called O(log N)
rather than O(N) times. Use qsort_r so that name_space can be
passed to the comparison functions. Simplify calls to ‘free’ so
that lack of leakage is more obvious.
* modules/savedir (Depends-on): Add attribute, qsort_r.
Paul Eggert [Mon, 11 Dec 2023 18:57:06 +0000 (10:57 -0800)]
getopt: pacify gcc -Wanalyzer-null-dereference
* lib/getopt.c (process_long_option): Simplify logic slightly.
This pacifies gcc -flto -Wanalyzer-null-dereference when compiling
GNU tar on x86-64 with gcc 13.2.1 20231205 (Red Hat 13.2.1-6).
Pádraig Brady [Sun, 10 Dec 2023 14:46:58 +0000 (14:46 +0000)]
bootstrap: fix option propagation with --bootstrap-sync
* top/bootstrap: Ensure options are propagated through
upgrade_bootstrap().
* top/bootstrap-funclib.sh: Likewise.
* build-aux/bootstrap: Auto generated with `make build-aux/bootstrap`.
Fixes https://bugs.gnu.org/67731
Paul Eggert [Sat, 2 Dec 2023 06:19:22 +0000 (22:19 -0800)]
frexp: pacify clang re address-of-volatile
Problem reported by Sam James in:
https://lists.gnu.org/r/bug-gnulib/2023-12/msg00013.html
* m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Don’t try to convert
‘double volatile *’ to ‘void const *’ as the C standard
doesn’t allow accessing volatile variables through
pointer-to-nonvolatile.
* m4/frexpf.m4 (gl_FUNC_FREXPF_WORKS): Likewise.
Paul Eggert [Fri, 1 Dec 2023 20:17:32 +0000 (12:17 -0800)]
Update portability doc for CHERI, C23
* doc/gnulib-readme.texi:
Prefer “null pointer” to “@code{NULL}” since C23 has nullptr.
(Portability guidelines): Mention C99 instead of C89 for what
Gnulib assumes of headers.
(C99 features avoided): Mention CHERI issue with intptr_t etc.
(Other portability assumptions): Say that C23 requires two’s
complement. Mention CHERI’s holes.
Bruno Haible [Fri, 1 Dec 2023 18:39:26 +0000 (19:39 +0100)]
obstack: Avoid undefined behaviour.
Reported by Alexey Palienko <Alexey.Palienko@cma.se> in
<https://lists.gnu.org/archive/html/bug-m4/2023-02/msg00000.html>.
* lib/obstack.in.h: Include <stdint.h>.
(__BPTR_ALIGN): Remove macro.
(__PTR_ALIGN): For the optimized case, compute the alignment through
uintptr_t, instead of computing NULL + something.
Reported by David Edelsohn <dje.gcc@gmail.com> in
<https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636830.html>,
<https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636843.html>.
* m4/threadlib.m4 (gl_THREADLIB_BODY): If --disable-threads was
specified, define AVOID_ANY_THREADS to 1.
* lib/mbtowc-lock.c: Omit all code if --disable-threads was specified.
* lib/nl_langinfo-lock.c: Likewise.
* lib/setlocale-lock.c: Likewise.
* lib/mbtowc-lock.h: Omit locking code if --disable-threads was
specified.
* lib/nl_langinfo.c: Likewise.
* lib/setlocale_null.c: Likewise.
* lib/mbrtowc.c: Don't include any multithreading headers if
--disable-threads was specified.
* lib/mbrtoc32.c: Likewise.
Bruno Haible [Fri, 17 Nov 2023 11:49:40 +0000 (12:49 +0100)]
gettext: Recognize a statically built libintl on macOS and AIX.
Reported by David Edelsohn <dje.gcc@gmail.com> in
<https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636558.html>.
* m4/gettext.m4 (AM_GNU_GETTEXT): In the
"checking for GNU gettext in libintl..." test, add also the special
system library dependencies needed on macOS and AIX.
Paul Eggert [Wed, 15 Nov 2023 08:09:03 +0000 (00:09 -0800)]
striconveha: pacify gcc -Wcast-align
* lib/striconveha.c (uniconv_register_autodetect): Rewrite to
avoid the need to cast from char * to a pointer to a more strictly
aligned type. Use decls after statements to avoid some repetition.
Paul Eggert [Mon, 13 Nov 2023 07:21:40 +0000 (23:21 -0800)]
rawmemchr: speed up, particularly on CHERI
* lib/rawmemchr.c (rawmemchr) [__CHERI__]: Use memchr instead of
one-byte reads. This sped up a simple benchmark (rawmemchr on
100,000 bytes) by 6x on a Research Morello SoC r0p0 on CheriBSD 14.
[!__CHERI__]: Use sizeof, not alignof, as better alignment
should help performance a bit on some platforms.
* modules/rawmemchr (Depends-on): Remove alignasof.
Bruno Haible [Sat, 11 Nov 2023 23:45:39 +0000 (00:45 +0100)]
ssfmalloc: Take advantage of CHERI bounds-checking.
* lib/ssfmalloc.h: Include <cheri.h>.
(struct dissected_page_header) [CHERI]: Add field 'whole_page'.
(init_small_block_page, init_medium_block_page) [CHERI]: Initialize it.
(free_block_from_pool) [CHERI]: Use this field to initialize
pool->freeable_page.
(allocate_block) [CHERI]: Return a pointer with a tight upper bound.
vasnprintf: Re-enable parsing of directive with I64 (regr. 2023-03-24).
In 480a59ba60 (*printf-posix: ISO C 23: Support size specifiers 'wN' and
'wfN'., 2023-03-24), a major refactoring hides a bug in the conversion
of the code handling Windows' "%I64*" family of printf() formats:
before the refactoring, the "64" part was skipped (as desired), but
afterwards that part is not skipped and therefore the '6' is mistaken
for a conversion character. Which is invalid, of course, causing the
code to error out.
Fix this by skipping the "64" part again.
This bug was uncovered by the Git for Windows project when gettext
v0.22.3 switched to the gnulib code as work horse of the
libintl_vsnprintf() function.
* lib/printf-parse.c (PRINTF_PARSE): When parsing a size specifier
"I64", increment cp by 3, not 1.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Copyright-paperwork-exempt: Yes
Bruno Haible [Sat, 11 Nov 2023 19:04:02 +0000 (20:04 +0100)]
malloca: Take advantage of CHERI bounds-checking.
* lib/malloca.h: Include <cheri.h>.
(malloca) [CHERI]: In the stack-allocation case, return a pointer with
a tight lower bound and a tight upper bound.
* lib/malloca.c: Include <cheri.h>.
(small_t) [CHERI]: Define as uintptr_t.
(mmalloca) [CHERI]: Return a pointer with a tight upper bound.
(freea) [CHERI]: Update.
Bruno Haible [Sat, 11 Nov 2023 18:34:26 +0000 (19:34 +0100)]
ialloc: Take advantage of CHERI bounds-checking.
* lib/ialloc.h: Include <cheri.h>.
(irealloc): When s is 0, return a pointer whose bounds are of size 0,
not 1.
(ireallocarray): When n or s is 0, return a pointer whose bounds are of
size 0, not 1.
Paul Eggert [Sat, 11 Nov 2023 07:04:35 +0000 (23:04 -0800)]
di-set: port better to CHERI-64
* lib/di-set.c: Include stdint.h.
(hashint): Make it uintptr_t, not size_t, since it’s for use
when converting to pointer and back again. This suppresses
a false positive on CHERI-64.
* modules/di-set (Depends-on): Add stdint.
Paul Eggert [Sat, 11 Nov 2023 06:33:49 +0000 (22:33 -0800)]
stdio: fix port to older macOS
* lib/stdio.in.h: It’s pre macOS 13, not pre macOS 10.13.
Problem reported by Sevan Janiyan in:
https://lists.gnu.org/r/bug-gnulib/2023-11/msg00066.html
et seq.
Bruno Haible [Fri, 10 Nov 2023 15:48:18 +0000 (16:48 +0100)]
random tests: Add multithread-safety test.
* tests/test-random-mt.c: New file.
* modules/random-tests (Files): Add it.
(Depends-on): Add xalloc, thread, yield.
(Makefile.am): Also build and test test-random-mt.
Bruno Haible [Fri, 10 Nov 2023 15:46:17 +0000 (16:46 +0100)]
random: Fix multithread-safety bug in general.
* m4/random.m4 (gl_FUNC_RANDOM): Override also macOS, FreeBSD, Solaris,
Cygwin, Haiku.
* doc/posix-functions/random.texi: Mention the wider scope of the
multithread-safety bug.
Paul Eggert [Thu, 9 Nov 2023 18:50:30 +0000 (10:50 -0800)]
stdio: port better to older macOS
* lib/stdio.in.h: Do not define _POSIX_C_SOURCE on older macOS,
as it is not needed and defining it causes other problems.
Problem reported by Sevan Janiyan in:
https://mail.gnu.org/r/bug-gnulib/2023-11/msg00039.html
Bruno Haible [Thu, 9 Nov 2023 15:00:28 +0000 (16:00 +0100)]
rand: New module.
* lib/rand.c: New file, based on glibc/stdlib/rand.c.
* m4/rand.m4: New file.
* modules/rand: New file.
* doc/posix-functions/rand.texi: Mention the new module.
Bruno Haible [Thu, 9 Nov 2023 14:56:32 +0000 (15:56 +0100)]
random: Fix multithread-safety bug on CheriBSD.
* m4/random.m4 (gl_FUNC_RANDOM): Override on CheriBSD.
* lib/random.c: Include glthread/lock.h.
(__libc_lock_define_initialized, __libc_lock_lock, __libc_lock_unlock):
Define to do real locking.
* modules/random (Depends-on): Add lock.
* doc/posix-functions/random.texi: Mention the multithread-safety
problem.
Bruno Haible [Thu, 9 Nov 2023 02:32:20 +0000 (03:32 +0100)]
pthread-rwlock: Port to Mac OS X 10.4.
Reported by Sevan Janiyan <venture37@geeklan.co.uk>.
* m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): On macOS, test for the
presence of PTHREAD_RWLOCK_INITIALIZER. If it is not defined, don't
attempt to use pthread_rwlock_init.
Paul Eggert [Tue, 7 Nov 2023 18:54:58 +0000 (10:54 -0800)]
malloca: pacify -Wcheri-provenance
This shouldn’t affect generated code when optimizing.
* lib/malloca.c (mmalloca): Pacify -Wcheri-provenance on CHERI-64 cc.
(freea): Assign to temporaries to simplify debugging and avoid casts.
Paul Eggert [Tue, 7 Nov 2023 07:46:53 +0000 (23:46 -0800)]
stdint-tests: port to CHERI etc
* tests/test-stdint.c: Test intptr_t only if INTPTR_MAX is
defined, since the type is optional. Similarly for uintptr_t.
If CHERI, don’t assume TYPE_MINIMUM and TYPE_MAXIMUM works on
intptr_t, and similarly for TYPE_MAXIMUM and uintptr_t.
Bruno Haible [Tue, 7 Nov 2023 01:04:59 +0000 (02:04 +0100)]
fenv-*: Avoid test failures on OpenBSD/mips64.
* tests/test-fenv-round.c (test_towardzero, test_upward, test_downward):
Skip the 'long double' tests on OpenBSD/mips64.
* tests/test-fenv-except-tracking-2.c (main): On OpenBSD/mips64, skip
the 'long double' test.
* tests/test-fenv-except-trapping-2.c (main): Skip the '4' tests and the
'long double' tests also on OpenBSD/mips64.
* doc/posix-functions/fesetround.texi: Mention OpenBSD/mips64 here too.
Bruno Haible [Tue, 7 Nov 2023 01:04:47 +0000 (02:04 +0100)]
fenv-exceptions-tracking-c99: Fix test failures on OpenBSD/mips64.
* m4/fenv-exceptions-tracking.m4 (gl_FENV_EXCEPTIONS_TRACKING): On
OpenBSD/mips, set REPLACE_FECLEAREXCEPT to 1.
* doc/posix-functions/feclearexcept.texi: Mention the OpenBSD/mips64
bug.
* m4/fenv-exceptions-state.m4 (gl_FENV_EXCEPTIONS_STATE): No need to set
gl_cv_func_fesetexceptflag_works1 to 'no' on OpenBSD/mips.