Hi Paul, > installed the attached patches. The first two merely merge changes from > glibc and cleanup, the last one fixes the bug and adds a test case.
A testdir for 'random_r' produces a compilation failure on FreeBSD 11: cc -DHAVE_CONFIG_H -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1 -I/home/bruno/include -Wall -g -O2 -MT random_r.o -MD -MP -MF .deps/random_r.Tpo -c -o random_r.o ../../gllib/random_r.c In file included from ../../gllib/random_r.c:68: In file included from ./stdlib.h:36: /usr/include/stdlib.h:175:56: error: expected ')' int posix_memalign(void **, size_t, size_t) __nonnull(1); /* (ADV) */ ^ 1 error generated. The reason are these definitions: gllib/cdefs.h: #define __nonnull(params) __attribute__ ((__nonnull__ params)) /usr/include/sys/cdefs.h: #define __nonnull(x) __attribute__((__nonnull__(x))) /usr/include/stdlib.h: int posix_memalign(void **, size_t, size_t) __nonnull(1); /* (ADV) */ The patch below fixes it, by avoiding to define __nonnull. But the problem is deeper than that: <libc-config.h> undefines more than 60 symbols that are prefixed with __ and replaces them with glibc's definition. But then, compilation units such as lib/malloc/scratch_buffer_grow.c go on to include header files such as <stdbool.h>, <stddef.h>, <stdlib.h>, which references the gnulib replacements, which end up including the system headers <stdbool.h>, <stddef.h>, <stdlib.h> - but with the glibc definitions of the 60 symbols in effect. IMO the only way to reliably use <libc-config.h> would be that after including it, you don't include any system headers any more. 2018-06-23 Bruno Haible <br...@clisp.org> libc-config: Fix conflict with FreeBSD include files. * lib/cdefs.h (__nonnull): Remove definition. * lib/libc-config.h (__nonnull): Remove undefinition. diff --git a/lib/cdefs.h b/lib/cdefs.h index f6c20fe..76325c5 100644 --- a/lib/cdefs.h +++ b/lib/cdefs.h @@ -282,13 +282,10 @@ # define __attribute_format_strfmon__(a,b) /* Ignore */ #endif -/* The nonull function attribute allows to mark pointer parameters which - must not be NULL. */ -#if __GNUC_PREREQ (3,3) -# define __nonnull(params) __attribute__ ((__nonnull__ params)) -#else -# define __nonnull(params) -#endif +/* The nonnull function attribute allows to mark pointer parameters which + must not be NULL. + In Gnulib we use the macro _GL_ARG_NONNULL instead of __nonnull, because + __nonnull is defined in an incompatible way in FreeBSD's include files. */ /* If fortification mode, we warn about unused results of certain function calls which can lead to problems. */ diff --git a/lib/libc-config.h b/lib/libc-config.h index 747d620..14f0bb4 100644 --- a/lib/libc-config.h +++ b/lib/libc-config.h @@ -136,7 +136,6 @@ #undef __glibc_macro_warning1 #undef __glibc_unlikely #undef __inline -#undef __nonnull #undef __ptr_t #undef __restrict #undef __restrict_arr