Bug 64753 - Can not determine the proper size for pid_t
Summary: Can not determine the proper size for pid_t
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 1.7.0
Hardware: Macintosh All
: P2 normal with 3 votes (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-19 02:26 UTC by Adam Stewart
Modified: 2020-09-28 08:23 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Stewart 2020-09-19 02:26:52 UTC
I recently updated to XCode 12 on macOS 10.15.6, which comes with Apple Clang 12.0.0 (LLVM Clang 10.0.0). I am no longer able to compile APR from source. I see the following error message:


In file included from encoding/apr_encode.c:28:
In file included from ./include/apr_encode.h:24:
./include/apr.h:561:2: error: Can not determine the proper size for pid_t
#error Can not determine the proper size for pid_t
 ^
In file included from encoding/apr_encode.c:30:
In file included from ./include/apr_strings.h:52:
./include/apr_want.h:94:8: error: redefinition of 'iovec'
struct iovec
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_iovec_t.h:31:8: note: previous definition is here
struct iovec {
       ^
2 errors generated.
make[1]: *** [encoding/apr_encode.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
In file included from strings/apr_cpystrn.c:17:
./include/apr.h:561:2: error: Can not determine the proper size for pid_t
#error Can not determine the proper size for pid_t
 ^
In file included from passwd/apr_getpass.c:22:
In file included from /var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-apr-1.7.0-pw3odg3co73bcqzmq4nptwwyhbkdxab7/spack-src/include/arch/unix/apr_private.h:1074:
In file included from /var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-apr-1.7.0-pw3odg3co73bcqzmq4nptwwyhbkdxab7/spack-src/include/arch/unix/../apr_private_common.h:24:
In file included from ./include/apr_pools.h:43:
./include/apr.h:561:2: error: Can not determine the proper size for pid_t
#error Can not determine the proper size for pid_t
 ^
In file included from strings/apr_cpystrn.c:18:
In file included from ./include/apr_strings.h:52:
./include/apr_want.h:94:8: error: redefinition of 'iovec'
struct iovec
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_iovec_t.h:31:8: note: previous definition is here
struct iovec {
       ^
In file included from passwd/apr_getpass.c:23:
In file included from ./include/apr_strings.h:52:
./include/apr_want.h:94:8: error: redefinition of 'iovec'
struct iovec
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_iovec_t.h:31:8: note: previous definition is here
struct iovec {
       ^
2 errors generated.
make[1]: *** [strings/apr_cpystrn.lo] Error 1
2 errors generated.
make[1]: *** [passwd/apr_getpass.lo] Error 1
make: *** [all-recursive] Error 1


Compilation worked fine on macOS 10.15.6 with XCode 11, which comes with Apple Clang 11.0.3 (LLVM Clang 9.0.0), so I believe this is a consequence of a stricter compiler.

If anyone can come up with a patch to fix this, I'll add it to the Spack package manager.
Comment 1 Nick Kew 2020-09-19 09:11:25 UTC
Thanks for the report.  I haven't seen this, and have no idea if anyone else on the APR team has.

If you are involved in, or have access to, any Apple/Mac-oriented developer fora, it would be great if you could raise the matter there to try and tap their expertise.
Comment 2 Mario Klebsch 2020-09-25 07:52:55 UTC
The cause is a missing #include <stdlib.h> in a contest.c program. Here is a snippet from config.log:

configure:24467: checking size of pid_t
configure:24492: gcc -o conftest -g -O2 -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -DDARWIN_10  conftest.c -lpthread >&5
conftest.c:155:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^
conftest.c:158:11: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
  if (!f) exit(1);
          ^
conftest.c:158:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
conftest.c:159:22: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  fprintf(f, "%d\n", sizeof(pid_t));
              ~~     ^~~~~~~~~~~~~
              %lu
2 warnings and 1 error generated.
configure:24492: $? = 1
configure: program exited with status 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define __EXTENSIONS__ 1
| #define _ALL_SOURCE 1
| #define _GNU_SOURCE 1
| #define _POSIX_PTHREAD_SEMANTICS 1
| #define _TANDEM_SOURCE 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_ATOMIC_BUILTINS 1
| #define HAVE_PTHREAD_H 1
| #define HAVE_PTHREAD_H 1
| #define HAVE_PTHREAD_MUTEX_RECURSIVE 1
| #define HAVE_PTHREAD_KEY_DELETE 1
| #define HAVE_PTHREAD_RWLOCK_INIT 1
| #define HAVE_PTHREAD_ATTR_SETGUARDSIZE 1
| #define HAVE_PTHREAD_RWLOCKS 1
| #define HAVE_SCHED_H 1
| #define HAVE_SCHED_YIELD 1
| #define READDIR_IS_THREAD_SAFE 1
| #define HAVE_SIGSUSPEND 1
| #define HAVE_SIGWAIT 1
| #define HAVE_POLL 1
| #define HAVE_KQUEUE 1
| #define HAVE_GETPWNAM_R 1
| #define HAVE_GETPWUID_R 1
| #define HAVE_GETGRNAM_R 1
| #define HAVE_GETGRGID_R 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_MMAN_H 1
| #define HAVE_SYS_IPC_H 1
| #define HAVE_SYS_SHM_H 1
| #define HAVE_SYS_FILE_H 1
| #define HAVE_SYS_SOCKET_H 1
| #define HAVE_NET_IF_H 1
| #define HAVE_MMAP 1
| #define HAVE_MUNMAP 1
| #define HAVE_SHM_OPEN 1
| #define HAVE_SHM_UNLINK 1
| #define HAVE_SHMGET 1
| #define HAVE_SHMAT 1
| #define HAVE_SHMDT 1
| #define HAVE_SHMCTL 1
| #define HAVE_MPROTECT 1
| #define HAVE_MAP_ANON 1
| #define anonymous shared memory allocation method 1
| #define USE_SHMEM_MMAP_ANON 1
| #define namebased memory allocation method 1
| #define USE_SHMEM_SHMGET 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_ALLOCA 1
| #define HAVE_CALLOC 1
| #define HAVE_SETSID 1
| #define HAVE_ISINF 1
| #define HAVE_ISNAN 1
| #define HAVE_GETENV 1
| #define HAVE_PUTENV 1
| #define HAVE_SETENV 1
| #define HAVE_UNSETENV 1
| #define HAVE_WRITEV 1
| #define HAVE_GETIFADDRS 1
| #define HAVE_UTIME 1
| #define HAVE_UTIMES 1
| #define HAVE_SETRLIMIT 1
| #define HAVE_GETRLIMIT 1
| #define HAVE_SENDFILE 1
| #define HAVE_SIGACTION 1
| #define HAVE_DECL_SYS_SIGLIST 1
| #define HAVE_FORK 1
| #define HAVE_STRERROR_R 1
| #define HAVE_MMAP 1
| #define HAVE_MEMMOVE 1
| #define HAVE_GETPASS 1
| #define HAVE_GMTIME_R 1
| #define HAVE_LOCALTIME_R 1
| #define HAVE_MKSTEMP 1
| #define STDC_HEADERS 1
| #define HAVE_CTYPE_H 1
| #define HAVE_DIRENT_H 1
| #define HAVE_DLFCN_H 1
| #define HAVE_ERRNO_H 1
| #define HAVE_FCNTL_H 1
| #define HAVE_GRP_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_LIMITS_H 1
| #define HAVE_MACH_O_DYLD_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_NETDB_H 1
| #define HAVE_POLL_H 1
| #define HAVE_PWD_H 1
| #define HAVE_SEMAPHORE_H 1
| #define HAVE_SIGNAL_H 1
| #define HAVE_STDARG_H 1
| #define HAVE_STDDEF_H 1
| #define HAVE_STDIO_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_TERMIOS_H 1
| #define HAVE_TIME_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_ARPA_INET_H 1
| #define HAVE_NETINET_IN_H 1
| #define HAVE_SYS_FILE_H 1
| #define HAVE_SYS_IOCTL_H 1
| #define HAVE_SYS_MMAN_H 1
| #define HAVE_SYS_PARAM_H 1
| #define HAVE_SYS_POLL_H 1
| #define HAVE_SYS_RESOURCE_H 1
| #define HAVE_SYS_SELECT_H 1
| #define HAVE_SYS_SEM_H 1
| #define HAVE_SYS_SIGNAL_H 1
| #define HAVE_SYS_SOCKET_H 1
| #define HAVE_SYS_SOCKIO_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_SYS_SYSCTL_H 1
| #define HAVE_SYS_SYSLIMITS_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_UIO_H 1
| #define HAVE_SYS_UN_H 1
| #define HAVE_SYS_WAIT_H 1
| #define HAVE_NETINET_TCP_H 1
| #define SETPGRP_VOID 1
| #define HAVE_SOCKLEN_T 1
| #define SIZEOF_VOIDP 8
| #define SIZEOF_CHAR 1
| #define SIZEOF_SHORT 2
| #define SIZEOF_INT 4
| #define SIZEOF_LONG 8
| #define SIZEOF_LONG_LONG 8
| /* end confdefs.h.  */
| #include <stdio.h>
| #include <sys/types.h>
| #ifdef WIN32
| #define binmode "b"
| #else
| #define binmode
| #endif
| main()
| {
|   FILE *f=fopen("conftestval", "w" binmode);
|   if (!f) exit(1);
|   fprintf(f, "%d\n", sizeof(pid_t));
|   exit(0);
| }
configure:24502: result: 0
Comment 3 Mario Klebsch 2020-09-25 08:08:08 UTC
There are other conftest.c snippets calling exit() and failing to compile because of #include <stdlib.h> is missing.

Some conftest.c snippets do #include <stdlib.h> unconditionally, other #include <stdlib.h> conditionally, either #ifdef STDC_HEADERS or # ifdef HAVE_STDLIB_H

I added #include <stdlib.h> to all conftest.c snippets calling exit(). apr compiles for me on macOS, but I have not tested it, yet. Here is my diff:

*** configure.orig	2020-09-25 09:58:14.000000000 +0200
--- configure	2020-09-25 10:01:12.000000000 +0200
***************
*** 22913,22918 ****
--- 22913,22919 ----
  #include <errno.h>
  #include <string.h>
  #include <stdio.h>
+ #include <stdlib.h>
  main()
  {
    char buf[1024];
***************
*** 24475,24480 ****
--- 24476,24482 ----
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */
  #include <stdio.h>
+ #include <stdlib.h>
  #include <sys/types.h>
  #ifdef WIN32
  #define binmode "b"
***************
*** 24800,24805 ****
--- 24802,24808 ----
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */
  #include <stdio.h>
+ #include <stdlib.h>
  #include <sys/types.h>
  #ifdef WIN32
  #define binmode "b"
***************
*** 24864,24869 ****
--- 24867,24873 ----
  /* end confdefs.h.  */
  #include <stdio.h>
  #include <stddef.h>
+ #include <stdlib.h>
  #ifdef WIN32
  #define binmode "b"
  #else
***************
*** 24928,24933 ****
--- 24932,24938 ----
  /* end confdefs.h.  */
  #include <stdio.h>
  #include <sys/types.h>
+ #include <stdlib.h>
  #ifdef WIN32
  #define binmode "b"
  #else
***************
*** 25298,25303 ****
--- 25303,25309 ----
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */
  #include <stdio.h>
+ #include <stdlib.h>
  $ac_includes_default
  #ifdef WIN32
  #define binmode "b"
***************
*** 25584,25589 ****
--- 25590,25596 ----
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */
  #include <stdio.h>
+ #include <stdlib.h>
  #include <sys/types.h>
  #include <sys/uio.h>
  #ifdef WIN32
***************
*** 26211,26216 ****
--- 26218,26224 ----
  #include <sys/types.h>
  #include <sys/time.h>
  #include <sys/resource.h>
+ #include <stdlib.h>
  main()
  {
      struct rlimit limit;
***************
*** 26809,26814 ****
--- 26817,26823 ----
  /* end confdefs.h.  */
  
  #include <sys/types.h>
+ #include <stdlib.h>
  #include <pthread.h>
          int main()
          {
***************
*** 27454,27459 ****
--- 27463,27469 ----
  #endif
  #include <fcntl.h>
  #include <errno.h>
+ #include <stdlib.h>
  
  int fd;
  struct flock proc_mutex_lock_it = {0};
***************
*** 28763,28768 ****
--- 28773,28779 ----
  #ifndef HAVE_SOCKLEN_T
  typedef int socklen_t;
  #endif
+ #include <stdlib.h>
  int main(void) {
      int listen_s, connected_s, client_s;
      int listen_port, rc;
***************
*** 28913,28918 ****
--- 28924,28930 ----
  #ifdef HAVE_FCNTL_H
  #include <fcntl.h>
  #endif
+ #include <stdlib.h>
  int main(void) {
      int listen_s, connected_s, client_s;
      int listen_port, rc;
***************
*** 29598,29603 ****
--- 29610,29616 ----
  #ifdef HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
+ #include <stdlib.h>
  
  int main(void) {
      struct addrinfo hints, *ai;
***************
*** 29661,29666 ****
--- 29674,29680 ----
  #ifdef HAVE_NETDB_H
  #include <netdb.h>
  #endif
+ #include <stdlib.h>
  
  int main(void) {
      if (EAI_ADDRFAMILY < 0) {
***************
*** 29722,29727 ****
--- 29736,29742 ----
  #ifdef HAVE_NETINET_IN_H
  #include <netinet/in.h>
  #endif
+ #include <stdlib.h>
  
  int main(void) {
      struct sockaddr_in sa;
Comment 4 Mario Klebsch 2020-09-25 08:31:25 UTC
P.S.
apr-1.7.0 % gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Comment 5 Adam Stewart 2020-09-27 21:08:34 UTC
Thanks Mario, your patch worked perfectly! I'll add this to the Spack package manager. I assume this will be included in the next release of APR?
Comment 6 Ruediger Pluem 2020-09-28 08:23:56 UTC
(In reply to Adam Stewart from comment #5)
> Thanks Mario, your patch worked perfectly! I'll add this to the Spack
> package manager. I assume this will be included in the next release of APR?

Unfortunately the patch is wrong and cannot be included:

1. It needs to be against trunk.
2. Patching configure is wrong as this file is generated from various other files e.g. configure.in via autoconf during building the source tar ball. The source of the first patch location

*** configure.orig	2020-09-25 09:58:14.000000000 +0200
--- configure	2020-09-25 10:01:12.000000000 +0200
***************
*** 22913,22918 ****
--- 22913,22919 ----
  #include <errno.h>
  #include <string.h>
  #include <stdio.h>
+ #include <stdlib.h>
  main()
  {
    char buf[1024];

seem to be here:

Index: build/apr_common.m4
===================================================================
--- build/apr_common.m4	(revision 1881726)
+++ build/apr_common.m4	(working copy)
@@ -495,6 +495,9 @@
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
 main()
 {
   char buf[1024];


It might be also needed to ifdef the include, but this is not done consistently over the various calls to AC_TRY_RUN. I leave it to others to comment whether this is mandatory or not.