Bug #71011 strlcat compiled even if we have strlcat
Submitted: 26 Nov 2013 13:04 Modified: 4 Dec 2013 18:26
Reporter: Patrick Middleton Email Updates:
Status: Unsupported Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.6.14GA OS:MacOS (10.4)
Assigned to: CPU Architecture:Any

[26 Nov 2013 13:04] Patrick Middleton
Description:
configure.cmake:CHECK_FUNCTION_EXISTS (strlcat HAVE_STRLCAT)

but, mysys_ssl/crypt_genhash_impl.cc defines strlcat, without an #if !HAVE_STRLCAT guard macro

and this causes linker problems if the standard library provides strlcat.  Which on MacOSX it does.

How to repeat:
On MacOSX, I'm doing this:

rm -rf bld
mkdir bld
cd bld
cmake .. \
  -DWITH_PARTITION_STORAGE_ENGINE=OFF \
  -DCMAKE_OSX_ARCHITECTURES="ppc;i386" \
  -DCMAKE_OSX_SYSROOT="/Developer/SDKs/MacOSX10.4u.sdk" \
  -DCMAKE_OSX_DEPLOYMENT_TARGET="10.4" \
  -DCURSES_LIBRARY="/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libcurses.dylib" \
  -DCURSES_NCURSES_LIBRARY="/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libncurses.dylib" \
  -DCURSES_FORM_LIBRARY="/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libform.dylib"
  make install
cd ..

Suggested fix:
Add a guard macro.  Patch forthcoming.  Found in 5.6.14GA but appears to be present in 5.7.2-m12
[26 Nov 2013 13:05] Patrick Middleton
Patch for mysys_ssl/crypt_genhash_impl.cc against 5.6.14GA

Attachment: crypt_genhash_impl.cc.patch (application/octet-stream, text), 574 bytes.

[29 Nov 2013 17:52] MySQL Verification Team
Hi,

Please, can you answer me whether you are building 32 or 64 bit version ???

This is important as you could get different results in building ...
[2 Dec 2013 17:15] Patrick Middleton
Building 32 bit,  '-DCMAKE_OSX_ARCHITECTURES="ppc;i386"'
not x86_64 or ppc64

Not sure what you mean anyway.  I looked at the stub library of interest (/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libSystem.B.dylib), it contains four architectures, I separated out each using /usr/bin/lipo then used /usr/bin/nm to see the symbol tables.  All four define strlcat.

cp /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libSystem.B.dylib /tmp/libSystem.B.dylib
cd /tmp
for arch in ppc i386 x86_64 ppc64 ; do /usr/bin/lipo libSystem.B.dylib -thin $arch -output libSystem.$arch.B.dylib ; done 
for arch in ppc i386 x86_64 ppc64 ; do echo $arch ; /usr/bin/nm libSystem.$arch.B.dylib | grep strlcat ; done
[3 Dec 2013 17:13] MySQL Verification Team
Hi!

I have run the scripts and make and everything compiles and links without a single error or warning !!!

This could be because I am using OS X 10.6, but we do not support any OS X older then 10.6, and hence we do not support 10.4 either !!!

Have you got any errors or warning in compiling and linking ???
[4 Dec 2013 12:07] Patrick Middleton
Yes, there was an error when linking on 10.4.
I was also building on 10.6, while investigating what I later filed as bug 71009. When building on 10.6 the warning did not appear.  Without my patch on 10.4, I got this:

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[ 77%] Building CXX object sql/CMakeFiles/mysqld.dir/main.cc.o
Linking CXX executable mysqld
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: for architecture ppc
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _strlcat
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../libSystem.dylib(strlcat.So) definition of _strlcat
../mysys_ssl/libmysys_ssl.a(crypt_genhash_impl.cc.o) private external definition of _strlcat in section (__TEXT,__text)
collect2: ld returned 1 exit status
/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: for architecture i386
/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: multiple definitions of symbol _strlcat
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libSystem.dylib(strlcat.So) definition of _strlcat
../mysys_ssl/libmysys_ssl.a(crypt_genhash_impl.cc.o) private external definition of _strlcat in section (__TEXT,__text)
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccEYAtsZ.out (No such file or directory)
make[2]: *** [sql/mysqld] Error 1
make[1]: *** [sql/CMakeFiles/mysqld.dir/all] Error 2
make: *** [all] Error 2
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Three source files in 5.6.14GA all define strlcat():
cmd-line-utils/libedit/np/strlcat.c
mysys_ssl/crypt_genhash_impl.cc
storage/ndb/test/src/getarg.c

but the Cmake-generated scripts test for whether we have strlcat in the standard library, and both cmd-line-utils/libedit/np/strlcat.c and storage/ndb/test/src/getarg.c use a guard macro, so strlcat() is only compiled in them if the standard library doesn't have strlcat.

The problem is that, as per my example patch, in mysys_ssl/crypt_genhash_impl.cc the guard macro is missing.
[4 Dec 2013 14:23] MySQL Verification Team
Hi!

I just got confirmation from our Engineering department. We support only OS X 10.6 and higher. All bug reports, patches , etc for lower versions are to be ignored. There is no longer any maintenance for 10.5 , 10.4 and earlier.

Hence, "Not a Bug" ...
[4 Dec 2013 16:09] Patrick Middleton
I am sure there are plenty of other non-obsolete platforms where links will fail because of duplicated symbols because someone omitted the guard macro around the definition of strlcat().