On fre, 2010-06-11 at 07:00 +0300, Peter Eisentraut wrote:
> The second problem is that the prototype check for accept() fails.
> This
> is because glibc defines the second argument to be a "transparent
> union", apparently to make it look like a lot of things at once.
> clang
> apparently doesn't understand that.  One could address this by
> checking
> for the typedef that glibc uses explicitly in the configure check, but
> that would appear to defeat the point of the *transparent* union.  A
> workaround is to remove -D_GNU_SOURCE from src/template/linux.
> 
> Predictably, this will make PL/Perl fail to build.
> 
> Also, it will make src/backend/libpq/auth.c fail to build, because
> struct ucred is only defined when _GNU_SOURCE is used.  This would
> actually fail to work on GCC as well, so I think we should add an
> explicit configure check for struct ucred. 

For the record, here is a patch that would address these issues.

At the moment, I'm waiting to get my hands on the new version 2.7 of
clang to see if some of these issues have gone away.

Considering that clang already helped us find one bug in the code, I
think it's worth trying to make this work.
diff --git a/configure.in b/configure.in
index 0a529fa..bb1d0dd 100644
--- a/configure.in
+++ b/configure.in
@@ -390,6 +390,11 @@ choke me
 
 AC_SUBST(SUN_STUDIO_CC)
 
+# Check if it's Clang, which defines __clang__.
+AC_TRY_COMPILE([], [...@%:@ifndef __clang__
+choke me
+...@%:@endif], [CLANG=yes], [CLANG=no])
+
 unset CFLAGS
 
 #
@@ -1102,7 +1107,7 @@ AC_TYPE_INTPTR_T
 AC_TYPE_UINTPTR_T
 AC_TYPE_LONG_LONG_INT
 
-AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
+AC_CHECK_TYPES([struct ucred,struct cmsgcred, struct fcred, struct sockcred], [], [],
 [#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/socket.h>
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index b06b391..27482bd 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -1786,7 +1786,7 @@ ident_unix(int sock, char *ident_user)
 	strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1);
 
 	return true;
-#elif defined(SO_PEERCRED)
+#elif defined(SO_PEERCRED) && defined(HAVE_STRUCT_UCRED)
 	/* Linux style: use getsockopt(SO_PEERCRED) */
 	struct ucred peercred;
 	ACCEPT_TYPE_ARG3 so_len = sizeof(peercred);
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index fd169b6..8d41549 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -529,6 +529,9 @@
 /* Define to 1 if `tm_zone' is member of `struct tm'. */
 #undef HAVE_STRUCT_TM_TM_ZONE
 
+/* Define to 1 if the system has the type `struct ucred'. */
+#undef HAVE_STRUCT_UCRED
+
 /* Define to 1 if you have the <SupportDefs.h> header file. */
 #undef HAVE_SUPPORTDEFS_H
 
diff --git a/src/template/linux b/src/template/linux
index 68da3bb..aff39e8 100644
--- a/src/template/linux
+++ b/src/template/linux
@@ -1,7 +1,9 @@
 # $PostgreSQL$
 
 # Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise
-CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+if test "$CLANG" != yes; then
+  CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+fi
 
 # If --enable-profiling is specified, we need -DLINUX_PROFILE
 PLATFORM_PROFILE_FLAGS="-DLINUX_PROFILE"
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to