On Wed, May 10, 2023 at 8:26 PM Paul Eggert <egg...@cs.ucla.edu> wrote: > > On 5/9/23 18:40, Sam James wrote: > > It looks like this is still the case in master as well. > > Thanks for reporting that. Simply including unistd.h isn't enough in > general, as POSIX no longer requires getpagesize to be declared there. > So I instead installed the attached patch, which changes the test so > that it doesn't use getpagesize. This is a conservative-enough approach > that it should be OK to squeeze it in before the next Autoconf release.
Thanks. Unfortunately that doesn't resolve the issue and might even make it worse. I'm configuring libgtop with clang-15 on an amd64 system using: > CC="clang" CXX="clang" CFLAGS="-std=c99 -Werror=implicit-function-declaration > -Werror=implicit-int -Werror=incompatible-function-pointer-types" ./autogen.sh With an unpatched autoconf, AC_FUNC_MMAP produces this output in config.log: > configure:17004: checking for working mmap > configure:17156: clang -o conftest -std=c99 > -Werror=implicit-function-declaration -Werror=implicit-int > -Werror=incompatible-function-pointer-types conftest.c >&5 > conftest.c:137:14: error: call to undeclared function 'getpagesize'; ISO C99 > and later do not support implicit function declarations > [-Werror,-Wimplicit-function-declaration] > pagesize = getpagesize (); > ^ > 1 error generated. > configure:17156: $? = 1 > configure: program exited with status 1 (My patch was useless because the conftest.c file was already including unistd.h. I assume some #define is necessary to expose the prototype for getpagesize) And with your patch: > configure:17004: checking for working mmap > configure:17121: clang -o conftest -std=c99 > -Werror=implicit-function-declaration -Werror=implicit-int > -Werror=incompatible-function-pointer-types conftest.c >&5 > configure:17121: $? = 0 > configure:17121: ./conftest > ./configure: line 2069: 909713 Bus error (core dumped) > ./conftest$ac_exeext > configure:17121: $? = 135 > configure: program exited with status 135 The SIGBUS comes from Program received signal SIGBUS, Bus error. 0x000055555555536d in main () at conftest.c:130 130 if (*(data2 + i)) (gdb) l 125 return 5; 126 data2 = (char *) mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L); 127 if (data2 == MAP_FAILED) 128 return 6; 129 for (i = 0; i < pagesize; ++i) 130 if (*(data2 + i)) 131 return 7; 132 close (fd2); 133 if (munmap (data2, pagesize)) 134 return 8; (gdb) p i $1 = 4096 Changing pagesize s/8192/4096/ in the program makes it work. I suspect the comment above this code indicates what the problem is: /* Next, check that the tail of a page is zero-filled. File must have non-zero length, otherwise we risk SIGBUS for entire page. */ We're mmap'ing a 1-byte file, and since the pagesize on amd64 is 4096 bytes, only the first 4096 byte page (of two) is mapped. Accessing the second page triggers the SIGBUS.