Samba fails to compile with clang (svn) (PATCH)

Joonas Kuorilehto joneskoo at
Tue Jun 18 12:48:07 MDT 2013

Hi all,

While trying to compile samba with the latest clang from svn I hit a 
strange compile problem that Jeremy Allison traced to a clang/gcc 
optimization difference. Looks like clang fails to optimize this one 
specific thing and the compile fails at linking stage. The error was 
referencing to a missing __unsafe_string_function_usage_here_size_t__
function (which is in lib/util/string_wrappers.h).

$ clang -v
clang version 3.4 (trunk 184159)
Target: i386-pc-linux-gnu
Thread model: posix
$ uname -a
Linux myhost 3.2.0-38-generic-pae #61-Ubuntu SMP Tue Feb 19 12:39:51 UTC 
2013 i686 i686 i386 GNU/Linux

I was able to compile successfully by swapping the order in 
CHECK_STRING_SIZE as suggested by Jeremy.

If someone wants to analyze/report this to clang or include in Samba, 
great. Diff below.

Joonas Kuorilehto

diff --git a/lib/util/string_wrappers.h b/lib/util/string_wrappers.h
index 5f9d568..b83d0a3 100644
--- a/lib/util/string_wrappers.h
+++ b/lib/util/string_wrappers.h
@@ -62,7 +62,7 @@ char * __unsafe_string_function_usage_here__(void);

  size_t __unsafe_string_function_usage_here_size_t__(void);

-#define CHECK_STRING_SIZE(d, len) (sizeof(d) != (len) && sizeof(d) != 
sizeof(char *))
+#define CHECK_STRING_SIZE(d, len) (sizeof(d) != sizeof(char *) && 
sizeof(d) != (len))

  /* if the compiler will optimize out function calls, then use this to 
tell if we are
     have the correct types (this works only where sizeof() returns the 
size of the buffer, not

More information about the samba-technical mailing list