The module 'relocatable-prog-wrapper' includes a flattened view of the 'canonicalize-lgpl' module. Since the 'canonicalize-lgpl' module has changed a month ago, the 'relocatable-prog-wrapper' may produce compilation errors on platforms where it is needed (AIX, Cygwin, as well as older versions of other platforms).
This series of patches updates the 'relocatable-prog-wrapper' module. Since build-aux/install-reloc compiles all of its files unconditionally (no conditional AC_LIBOBJ), files such as lib/malloc.c now need a #include guard. 2021-01-31 Bruno Haible <br...@clisp.org> relocatable-prog-wrapper: Update after recent changes. * lib/relocwrapper.c: Update comments. * modules/relocatable-prog-wrapper (Files): Add lib/scratch_buffer.h, lib/malloc/scratch_buffer*, lib/malloc.c, lib/realloc.c, lib/free.c, lib/mempcpy.c, lib/rawmemchr.c, m4/lstat.m4. Remove lib/lstat.c. (Depends-on): Add c99, eloop-threshold, fcntl-h, idx, intprops, libc-config, stddef, sys_stat. Remove alloca-opt. (configure.ac): Invoke gl_FUNC_MALLOC_POSIX, gl_FUNC_REALLOC_POSIX, gl_FUNC_FREE, gl_FUNC_MEMPCPY, gl_FUNC_RAWMEMCHR. * lib/canonicalize-lgpl.c (memmove): Undefine in the relocwrapper. * build-aux/install-reloc (func_create_wrapper): Compile also malloc/scratch_buffer_*.c, malloc.c, realloc.c, free.c, mempcpy.c, rawmemchr.c. Don't compile lstat.c. Make it possible to compile rawmemchr.c separately, unconditionally. * lib/rawmemchr.c: Don't define rawmemchr if not needed. Make it possible to compile mempcpy.c separately, unconditionally. * lib/mempcpy.c: Don't define mempcpy if not needed. Make it possible to compile free.c separately, unconditionally. * m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX. * lib/free.c: Don't define rpl_free if not needed. Make it possible to compile realloc.c separately, unconditionally. * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/realloc.c: Don't define rpl_realloc if not needed. Make it possible to compile malloc.c separately, unconditionally. * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/malloc.c: Don't define rpl_malloc if not needed.
>From eae672ebce3fbb777670debd458905cfb2a0adc4 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 31 Jan 2021 12:30:18 +0100 Subject: [PATCH 1/6] Make it possible to compile malloc.c separately, unconditionally. * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/malloc.c: Don't define rpl_malloc if not needed. --- ChangeLog | 6 ++++++ lib/malloc.c | 16 +++++++++++----- modules/malloc-posix | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96d81e5..bc19d19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-01-31 Bruno Haible <br...@clisp.org> + Make it possible to compile malloc.c separately, unconditionally. + * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. + * lib/malloc.c: Don't define rpl_malloc if not needed. + +2021-01-31 Bruno Haible <br...@clisp.org> + canonicalize-lgpl: Simplify. * lib/canonicalize-lgpl.c (_GL_USE_STDLIB_ALLOC): Remove macro. diff --git a/lib/malloc.c b/lib/malloc.c index 325064d..887cdde 100644 --- a/lib/malloc.c +++ b/lib/malloc.c @@ -30,7 +30,11 @@ #include <stdlib.h> -#include <errno.h> +/* A function definition is only needed if NEED_MALLOC_GNU is defined above + or if the module 'malloc-posix' requests it. */ +#if NEED_MALLOC_GNU || (GNULIB_MALLOC_POSIX && !HAVE_MALLOC_POSIX) + +# include <errno.h> /* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */ @@ -40,17 +44,19 @@ rpl_malloc (size_t n) { void *result; -#if NEED_MALLOC_GNU +# if NEED_MALLOC_GNU if (n == 0) n = 1; -#endif +# endif result = malloc (n); -#if !HAVE_MALLOC_POSIX +# if !HAVE_MALLOC_POSIX if (result == NULL) errno = ENOMEM; -#endif +# endif return result; } + +#endif diff --git a/modules/malloc-posix b/modules/malloc-posix index b5ab594..1a2d72c 100644 --- a/modules/malloc-posix +++ b/modules/malloc-posix @@ -14,6 +14,7 @@ if test $REPLACE_MALLOC = 1; then AC_LIBOBJ([malloc]) fi gl_STDLIB_MODULE_INDICATOR([malloc-posix]) +gl_MODULE_INDICATOR([malloc-posix]) Makefile.am: -- 2.7.4
>From 64bdee095f60ec708937d73132b95377e27a827e Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 31 Jan 2021 12:39:31 +0100 Subject: [PATCH 2/6] Make it possible to compile realloc.c separately, unconditionally. * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/realloc.c: Don't define rpl_realloc if not needed. --- ChangeLog | 4 ++++ lib/realloc.c | 20 +++++++++++++------- modules/realloc-posix | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc19d19..e9e2b36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-01-31 Bruno Haible <br...@clisp.org> + Make it possible to compile realloc.c separately, unconditionally. + * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. + * lib/realloc.c: Don't define rpl_realloc if not needed. + Make it possible to compile malloc.c separately, unconditionally. * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/malloc.c: Don't define rpl_malloc if not needed. diff --git a/lib/realloc.c b/lib/realloc.c index 35caeab..51d8d21 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -37,7 +37,11 @@ #include <stdlib.h> -#include <errno.h> +/* A function definition is only needed if NEED_REALLOC_GNU is defined above + or if the module 'realloc-posix' requests it. */ +#if NEED_REALLOC_GNU || (GNULIB_REALLOC_POSIX && !HAVE_REALLOC_POSIX) + +# include <errno.h> /* Change the size of an allocated block of memory P to N bytes, with error checking. If N is zero, change it to 1. If P is NULL, @@ -48,7 +52,7 @@ rpl_realloc (void *p, size_t n) { void *result; -#if NEED_REALLOC_GNU +# if NEED_REALLOC_GNU if (n == 0) { n = 1; @@ -57,23 +61,25 @@ rpl_realloc (void *p, size_t n) free (p); p = NULL; } -#endif +# endif if (p == NULL) { -#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE +# if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE if (n == 0) n = 1; -#endif +# endif result = malloc (n); } else result = realloc (p, n); -#if !HAVE_REALLOC_POSIX +# if !HAVE_REALLOC_POSIX if (result == NULL) errno = ENOMEM; -#endif +# endif return result; } + +#endif diff --git a/modules/realloc-posix b/modules/realloc-posix index 8e4924d..7f48110 100644 --- a/modules/realloc-posix +++ b/modules/realloc-posix @@ -15,6 +15,7 @@ if test $REPLACE_REALLOC = 1; then AC_LIBOBJ([realloc]) fi gl_STDLIB_MODULE_INDICATOR([realloc-posix]) +gl_MODULE_INDICATOR([realloc-posix]) Makefile.am: -- 2.7.4
>From 3dfe86d1522029f12c84bec55c8fb3c6c9c561dc Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 31 Jan 2021 12:41:33 +0100 Subject: [PATCH 3/6] Make it possible to compile free.c separately, unconditionally. * m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX. * lib/free.c: Don't define rpl_free if not needed. --- ChangeLog | 4 ++++ lib/free.c | 16 +++++++++++----- m4/free.m4 | 7 +++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e9e2b36..b8d5cd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-01-31 Bruno Haible <br...@clisp.org> + Make it possible to compile free.c separately, unconditionally. + * m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX. + * lib/free.c: Don't define rpl_free if not needed. + Make it possible to compile realloc.c separately, unconditionally. * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/realloc.c: Don't define rpl_realloc if not needed. diff --git a/lib/free.c b/lib/free.c index 5c89787..3f5968c 100644 --- a/lib/free.c +++ b/lib/free.c @@ -19,15 +19,19 @@ #include <config.h> +/* Specification. */ #include <stdlib.h> -#include <errno.h> +/* A function definition is only needed if HAVE_FREE_POSIX is not defined. */ +#if !HAVE_FREE_POSIX + +# include <errno.h> void rpl_free (void *p) -#undef free +# undef free { -#if defined __GNUC__ && !defined __clang__ +# if defined __GNUC__ && !defined __clang__ /* An invalid GCC optimization <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98396> would optimize away the assignments in the code below, when link-time @@ -39,9 +43,11 @@ rpl_free (void *p) errno = 0; free (p); errno = err[errno == 0]; -#else +# else int err = errno; free (p); errno = err; -#endif +# endif } + +#endif diff --git a/m4/free.m4 b/m4/free.m4 index d671376..a7923b9 100644 --- a/m4/free.m4 +++ b/m4/free.m4 @@ -1,4 +1,4 @@ -# free.m4 serial 5 +# free.m4 serial 6 # Copyright (C) 2003-2005, 2009-2021 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -40,7 +40,10 @@ AC_DEFUN([gl_FUNC_FREE], ]) case $gl_cv_func_free_preserves_errno in - *yes) ;; + *yes) + AC_DEFINE([HAVE_FREE_POSIX], [1], + [Define if the 'free' function is guaranteed to preserve errno.]) + ;; *) REPLACE_FREE=1 ;; esac ]) -- 2.7.4
>From 9c86ea67f0b554284251bbe325db033cfe4a8368 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 31 Jan 2021 12:42:21 +0100 Subject: [PATCH 4/6] Make it possible to compile mempcpy.c separately, unconditionally. * lib/mempcpy.c: Don't define mempcpy if not needed. --- ChangeLog | 3 +++ lib/mempcpy.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index b8d5cd7..3e74dc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-01-31 Bruno Haible <br...@clisp.org> + Make it possible to compile mempcpy.c separately, unconditionally. + * lib/mempcpy.c: Don't define mempcpy if not needed. + Make it possible to compile free.c separately, unconditionally. * m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX. * lib/free.c: Don't define rpl_free if not needed. diff --git a/lib/mempcpy.c b/lib/mempcpy.c index c61132e..6e9500c 100644 --- a/lib/mempcpy.c +++ b/lib/mempcpy.c @@ -19,6 +19,9 @@ /* Specification. */ #include <string.h> +/* A function definition is only needed if HAVE_MEMPCPY is not defined. */ +#if !HAVE_MEMPCPY + /* Copy N bytes of SRC to DEST, return pointer to bytes after the last written byte. */ void * @@ -26,3 +29,5 @@ mempcpy (void *dest, const void *src, size_t n) { return (char *) memcpy (dest, src, n) + n; } + +#endif -- 2.7.4
>From a12d5bafef2103373e775683eba778c98f0142ce Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 31 Jan 2021 12:42:33 +0100 Subject: [PATCH 5/6] Make it possible to compile rawmemchr.c separately, unconditionally. * lib/rawmemchr.c: Don't define rawmemchr if not needed. --- ChangeLog | 3 +++ lib/rawmemchr.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3e74dc5..3af98a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-01-31 Bruno Haible <br...@clisp.org> + Make it possible to compile rawmemchr.c separately, unconditionally. + * lib/rawmemchr.c: Don't define rawmemchr if not needed. + Make it possible to compile mempcpy.c separately, unconditionally. * lib/mempcpy.c: Don't define mempcpy if not needed. diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c index bbb250f..f4d5030 100644 --- a/lib/rawmemchr.c +++ b/lib/rawmemchr.c @@ -19,6 +19,9 @@ /* Specification. */ #include <string.h> +/* A function definition is only needed if HAVE_RAWMEMCHR is not defined. */ +#if !HAVE_RAWMEMCHR + /* Find the first occurrence of C in S. */ void * rawmemchr (const void *s, int c_in) @@ -134,3 +137,5 @@ rawmemchr (const void *s, int c_in) char_ptr++; return (void *) char_ptr; } + +#endif -- 2.7.4
>From 24446f2dda800d854142d5bab5c980e6fa3326d4 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 31 Jan 2021 12:42:47 +0100 Subject: [PATCH 6/6] relocatable-prog-wrapper: Update after recent changes. * lib/relocwrapper.c: Update comments. * modules/relocatable-prog-wrapper (Files): Add lib/scratch_buffer.h, lib/malloc/scratch_buffer*, lib/malloc.c, lib/realloc.c, lib/free.c, lib/mempcpy.c, lib/rawmemchr.c, m4/lstat.m4. Remove lib/lstat.c. (Depends-on): Add c99, eloop-threshold, fcntl-h, idx, intprops, libc-config, stddef, sys_stat. Remove alloca-opt. (configure.ac): Invoke gl_FUNC_MALLOC_POSIX, gl_FUNC_REALLOC_POSIX, gl_FUNC_FREE, gl_FUNC_MEMPCPY, gl_FUNC_RAWMEMCHR. * lib/canonicalize-lgpl.c (memmove): Undefine in the relocwrapper. * build-aux/install-reloc (func_create_wrapper): Compile also malloc/scratch_buffer_*.c, malloc.c, realloc.c, free.c, mempcpy.c, rawmemchr.c. Don't compile lstat.c. --- ChangeLog | 14 ++++++++++++++ build-aux/install-reloc | 19 +++++++++++++++++-- lib/canonicalize-lgpl.c | 6 ++++++ lib/relocwrapper.c | 20 ++++++++++++++++++-- modules/relocatable-prog-wrapper | 31 +++++++++++++++++++++++++++---- 5 files changed, 82 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3af98a9..2bf4088 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2021-01-31 Bruno Haible <br...@clisp.org> + relocatable-prog-wrapper: Update after recent changes. + * lib/relocwrapper.c: Update comments. + * modules/relocatable-prog-wrapper (Files): Add lib/scratch_buffer.h, + lib/malloc/scratch_buffer*, lib/malloc.c, lib/realloc.c, lib/free.c, + lib/mempcpy.c, lib/rawmemchr.c, m4/lstat.m4. Remove lib/lstat.c. + (Depends-on): Add c99, eloop-threshold, fcntl-h, idx, intprops, + libc-config, stddef, sys_stat. Remove alloca-opt. + (configure.ac): Invoke gl_FUNC_MALLOC_POSIX, gl_FUNC_REALLOC_POSIX, + gl_FUNC_FREE, gl_FUNC_MEMPCPY, gl_FUNC_RAWMEMCHR. + * lib/canonicalize-lgpl.c (memmove): Undefine in the relocwrapper. + * build-aux/install-reloc (func_create_wrapper): Compile also + malloc/scratch_buffer_*.c, malloc.c, realloc.c, free.c, mempcpy.c, + rawmemchr.c. Don't compile lstat.c. + Make it possible to compile rawmemchr.c separately, unconditionally. * lib/rawmemchr.c: Don't define rawmemchr if not needed. diff --git a/build-aux/install-reloc b/build-aux/install-reloc index bb43e5d..e74f02d 100755 --- a/build-aux/install-reloc +++ b/build-aux/install-reloc @@ -237,8 +237,16 @@ func_create_wrapper () "$srcdir"/readlink.c \ "$srcdir"/stat.c \ "$srcdir"/canonicalize-lgpl.c \ + "$srcdir"/malloc/scratch_buffer_dupfree.c \ + "$srcdir"/malloc/scratch_buffer_grow.c \ + "$srcdir"/malloc/scratch_buffer_grow_preserve.c \ + "$srcdir"/malloc/scratch_buffer_set_array_size.c \ + "$srcdir"/malloc.c \ + "$srcdir"/realloc.c \ + "$srcdir"/free.c \ + "$srcdir"/mempcpy.c \ + "$srcdir"/rawmemchr.c \ "$srcdir"/malloca.c \ - "$srcdir"/lstat.c \ "$srcdir"/relocatable.c \ "$srcdir"/setenv.c \ "$srcdir"/c-ctype.c \ @@ -255,8 +263,15 @@ func_create_wrapper () readlink.o \ stat.o \ canonicalize-lgpl.o \ + scratch_buffer_dupfree.o \ + scratch_buffer_grow.o \ + scratch_buffer_grow_preserve.o \ + scratch_buffer_set_array_size.o \ + malloc.o \ + realloc.o \ + mempcpy.o \ + rawmemchr.o \ malloca.o \ - lstat.o \ relocatable.o \ setenv.o \ c-ctype.o diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 5a280c6..c6fef17 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -75,6 +75,12 @@ # define __rawmemchr rawmemchr # define __readlink readlink # define __stat stat +# if IN_RELOCWRAPPER + /* When building the relocatable program wrapper, use the system's memmove + function, not the gnulib override, otherwise we would get a link error. + */ +# undef memmove +# endif #endif /* Suppress bogus GCC -Wmaybe-uninitialized warnings. */ diff --git a/lib/relocwrapper.c b/lib/relocwrapper.c index 0624bd9..771da89 100644 --- a/lib/relocwrapper.c +++ b/lib/relocwrapper.c @@ -29,10 +29,26 @@ -> readlink -> stat -> canonicalize-lgpl + -> libc-config + -> errno + -> fcntl-h + -> stdbool + -> sys_stat + -> unistd + -> eloop-threshold -> filename - -> malloca - -> lstat + -> idx + -> intprops + -> scratch_buffer + -> malloc-posix + -> realloc-posix + -> free-posix + -> pathmax + -> mempcpy + -> rawmemchr -> readlink + -> stat + -> double-slash-root -> relocatable -> setenv -> malloca diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper index f97fdae..da9ad30 100644 --- a/modules/relocatable-prog-wrapper +++ b/modules/relocatable-prog-wrapper @@ -17,9 +17,19 @@ lib/allocator.c lib/readlink.c lib/stat.c lib/canonicalize-lgpl.c +lib/scratch_buffer.h +lib/malloc/scratch_buffer.h +lib/malloc/scratch_buffer_dupfree.c +lib/malloc/scratch_buffer_grow.c +lib/malloc/scratch_buffer_grow_preserve.c +lib/malloc/scratch_buffer_set_array_size.c +lib/malloc.c +lib/realloc.c +lib/free.c +lib/mempcpy.c +lib/rawmemchr.c lib/malloca.h lib/malloca.c -lib/lstat.c lib/relocatable.h lib/relocatable.c lib/setenv.c @@ -28,6 +38,7 @@ lib/c-ctype.c m4/largefile.m4 m4/malloca.m4 m4/canonicalize.m4 +m4/lstat.m4 m4/eealloc.m4 m4/environ.m4 m4/readlink.m4 @@ -35,19 +46,26 @@ m4/relocatable-lib.m4 m4/setenv.m4 Depends-on: -alloca-opt +c99 double-slash-root +eloop-threshold +environ errno +fcntl-h filename +idx +intprops largefile +libc-config pathmax ssize_t stdbool +stddef stdint stdlib -unistd -environ string +sys_stat +unistd verify xalloc-oversized @@ -58,6 +76,11 @@ configure.ac: AC_REQUIRE([AC_C_RESTRICT]) gl_FUNC_READLINK_SEPARATE gl_CANONICALIZE_LGPL_SEPARATE +gl_FUNC_MALLOC_POSIX +gl_FUNC_REALLOC_POSIX +gl_FUNC_FREE +gl_FUNC_MEMPCPY +gl_FUNC_RAWMEMCHR gl_MALLOCA gl_RELOCATABLE_LIBRARY gl_FUNC_SETENV_SEPARATE -- 2.7.4