Bug #79778 MySQL Community Server package for Solaris 10 x86/amd64 broken
Submitted: 25 Dec 2015 20:09 Modified: 16 Jan 2016 14:40
Reporter: Dennis Clarke Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S2 (Serious)
Version:5.6.27 OS:Solaris (Oracle Solaris 10 1/13 s10x_u11wos_24a X86)
Assigned to: CPU Architecture:Any
Tags: RPATH, RUNPATH

[25 Dec 2015 20:09] Dennis Clarke
Description:
The libmysqlclient.so.18.1.0 library within MySQL Community Server package for Solaris 10 is broken because the RUNPATH and RPATH are wrong. 

The ELF information for the dynamic section within libmysqlclient.so.18.1.0 clearly states that the Oracle Studio 12.2 redistributable library libstlport.so.1 is NEEDED yet the person that created the package forgot to set the LD_OPTIONS and LD_RUNPATH correctly.  Therefore the libstlport library can NOT be located by the run time linker and the package is broken. 

STOP using LD_LIBRARY_PATH when you compile a package to be distributed out to users or you get a broken package. 

Anyways here are the details : 

$ elfdump -devl /opt/mysql/mysql/lib/libmysqlclient.so.18.1.0

ELF Header
  ei_magic:   { 0x7f, E, L, F }
  ei_class:   ELFCLASS64          ei_data:       ELFDATA2LSB
  ei_osabi:   ELFOSABI_NONE       ei_abiversion: 0
  e_machine:  EM_AMD64            e_version:     EV_CURRENT
  e_type:     ET_DYN
  e_flags:                     0
  e_entry:                     0  e_ehsize:     64  e_shstrndx:  43
  e_shoff:              0xcfbbd8  e_shentsize:  64  e_shnum:     44
  e_phoff:                  0x40  e_phentsize:  56  e_phnum:     5

Version Needed Section:  .SUNW_version
            file                        version
            libthread.so.1              SUNW_1.4             
            libsocket.so.1              SUNW_1.4             
            libm.so.2                   SUNW_1.1             
            librt.so.1                  SUNW_0.7             

Dynamic Section:  .dynamic
     index  tag                value
       [0]  NEEDED            0x349d2             libthread.so.1
       [1]  NEEDED            0x349ea             libsocket.so.1
       [2]  NEEDED            0x34a20             libnsl.so.1
       [3]  NEEDED            0x349f9             libm.so.2
       [4]  NEEDED            0x34a0c             librt.so.1
       [5]  NEEDED            0x34a2c             libstlport.so.1
       [6]  INIT              0x1fb398            
       [7]  FINI              0x1fb440            
       [8]  SONAME            0x34a3c             libmysqlclient.so.18
       [9]  RUNPATH           0x34a51             /opt/studio12u2/lib/stlport4/amd64:/opt/studio12u2/lib/amd64
      [10]  RPATH             0x34a51             /opt/studio12u2/lib/stlport4/amd64:/opt/studio12u2/lib/amd64
      [11]  HASH              0x57688             
      [12]  STRTAB            0x843f8             
      [13]  STRSZ             0x34a8e             
      [14]  SYMTAB            0x629f0             
      [15]  SYMENT            0x18                
      [16]  CHECKSUM          0x2825              
      [17]  VERNEED           0xb8e88             
      [18]  VERNEEDNUM        0x4                 
      [19]  PLTRELSZ          0x8d18              
      [20]  PLTREL            0x7                 
      [21]  JMPREL            0xd9638             
      [22]  RELA              0xb8f08             
      [23]  RELASZ            0x29448             
      [24]  RELAENT           0x18                
      [25]  FEATURE_1         0x1                 [ PARINIT ]
      [26]  SUNW_CAP          0x158               
      [27]  FLAGS             0                   0
      [28]  FLAGS_1           0                   0
      [29]  PLTGOT            0x222aa0            
      [30]  NULL              0                   

See the need for libstlport.so.1 there ? 

Well the path /opt/studio12u2/lib/stlport4/amd64 is useless because the actual libstlport file inside the package is located down under /opt/mysql/mysql with everything else. 

Broken. 

See fix instructions below. 

How to repeat:
$ cat trivial.c

#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>

int main(int argc, char **argv) {
  printf("MySQL client version: %s\n", mysql_get_client_info());
  exit(0);
}

unset LD_LIBRARY_PATH
unset LD_OPTIONS
unset LD_RUN_PATH

$ /opt/solarisstudio12.4/bin/cc $CFLAGS -I/opt/mysql/mysql/include -c -o trivial.o trivial.c 
$ /opt/solarisstudio12.4/bin/cc $CFLAGS -L/opt/mysql/mysql/lib -R/opt/mysql/mysql/lib -o trivial trivial.o -lmysqlclient 

$ ldd trivial
        libmysqlclient.so.18 =>  /opt/mysql/mysql/lib/libmysqlclient.so.18
        libc.so.1 =>     /lib/64/libc.so.1
        libthread.so.1 =>        /lib/64/libthread.so.1
        libsocket.so.1 =>        /lib/64/libsocket.so.1
        libnsl.so.1 =>   /lib/64/libnsl.so.1
        libm.so.2 =>     /lib/64/libm.so.2
        librt.so.1 =>    /lib/64/librt.so.1
        libstlport.so.1 =>       (file not found)
        libmp.so.2 =>    /lib/64/libmp.so.2
        libmd.so.1 =>    /lib/64/libmd.so.1
        libscf.so.1 =>   /lib/64/libscf.so.1
        libaio.so.1 =>   /lib/64/libaio.so.1
        libdoor.so.1 =>  /lib/64/libdoor.so.1
        libuutil.so.1 =>         /lib/64/libuutil.so.1
        libgen.so.1 =>   /lib/64/libgen.so.1

Got it ? 

The libstlport lib is in the wrong place because your /opt/mysql/mysql/lib/libmysqlclient.so.18 is broken. Your RPATH is wrong. 

The only short term solution to this stupidity is to create a filepath in /opt and then copy the libstlport lin in there like so : 

ls  /opt/studio12u2/lib/stlport4/amd64/libstlport.so.1

$ ./trivial
MySQL client version: 5.6.27

Suggested fix:
Recompile the package and this time you ensure that the RPATH and the RUNPATH of the output binaries are set correctly. 

set LD_RUN_PATH=/opt/mysql/mysql/lib

also unset LD_LIBRARY_PATH

Then compile you package and then make sure to use the Oracle Studio 12.4 compiler. Not the older Studio 12.2.

Also. get the redistributable /opt/solarisstudio12.4/lib/stlport4/libstlport.so.1 and put THAT file into /opt/mysql/mysql/lib.

Rebuild the package and then test something anything and make sure that LD_LIBRARY_PATH is blank !
[27 Dec 2015 0:13] Dennis Clarke
The problem runs deeper. It seems as if this RPATH and RUNPATH issue has been around a while however someone now brought in the libstlport dependency which did not exist before. On a sparc server with a previous release of MySQL I see this : 

dev-db_$ pkginfo -l mysql 
   PKGINST:  mysql
      NAME:  MySQL Community Server (GPL)
  CATEGORY:  application
      ARCH:  sparc
   VERSION:  5.5.46
   BASEDIR:  /opt/mysql
    VENDOR:  Oracle Corporation
    PSTAMP:  MySQL Release Engineering
  INSTDATE:  Nov 19 2015 14:21
     EMAIL:  mysql-build@oss.oracle.com                                                                                             
    STATUS:  completely installed
     FILES:     6742 installed pathnames
                 150 directories
                 105 executables
             3015691 blocks used (approx)

dev-db_$ ls -lap /opt/mysql/mysql/lib/libmysqlclient*
-rw-r--r--   1 root     bin      24352368 Sep 18 16:09 /opt/mysql/mysql/lib/libmysqlclient.a
lrwxrwxrwx   1 root     root          41 Nov 19 14:21 /opt/mysql/mysql/lib/libmysqlclient.so -> /opt/mysql/mysql/lib/libmysqlclient.so.18*
lrwxrwxrwx   1 root     root          45 Nov 19 14:21 /opt/mysql/mysql/lib/libmysqlclient.so.18 -> /opt/mysql/mysql/lib/libmysqlclient.so.18.0.0*
-rwxr-xr-x   1 root     bin      12851856 Sep 18 16:09 /opt/mysql/mysql/lib/libmysqlclient.so.18.0.0
lrwxrwxrwx   1 root     root          37 Nov 19 14:21 /opt/mysql/mysql/lib/libmysqlclient_r.a -> /opt/mysql/mysql/lib/libmysqlclient.a
lrwxrwxrwx   1 root     root          38 Nov 19 14:21 /opt/mysql/mysql/lib/libmysqlclient_r.so -> /opt/mysql/mysql/lib/libmysqlclient.so*
lrwxrwxrwx   1 root     root          41 Nov 19 14:21 /opt/mysql/mysql/lib/libmysqlclient_r.so.18 -> /opt/mysql/mysql/lib/libmysqlclient.so.18*
lrwxrwxrwx   1 root     root          45 Nov 19 14:21 /opt/mysql/mysql/lib/libmysqlclient_r.so.18.0.0 -> /opt/mysql/mysql/lib/libmysqlclient.so.18.0.0*

dev-db_$ elfdump -devl /opt/mysql/mysql/lib/libmysqlclient.so.18.0.0

ELF Header
  ei_magic:   { 0x7f, E, L, F }
  ei_class:   ELFCLASS64          ei_data:       ELFDATA2MSB
  ei_osabi:   ELFOSABI_NONE       ei_abiversion: 0
  e_machine:  EM_SPARCV9          e_version:     EV_CURRENT
  e_type:     ET_DYN
  e_flags:    [ EF_SPARCV9_TSO ]
  e_entry:                     0  e_ehsize:     64  e_shstrndx:  38
  e_shoff:              0xc410d0  e_shentsize:  64  e_shnum:     39
  e_phoff:                  0x40  e_phentsize:  56  e_phnum:     3

Version Needed Section:  .SUNW_version
            file                        version
            libthread.so.1              SUNW_1.4             
            libm.so.2                   SUNW_1.1             
            libsocket.so.1              SUNW_1.4             

Dynamic Section:  .dynamic
     index  tag                value
       [0]  NEEDED            0x32aba             libthread.so.1
       [1]  NEEDED            0x32af4             libnsl.so.1
       [2]  NEEDED            0x32ad2             libm.so.2
       [3]  NEEDED            0x32b00             librt.so.1
       [4]  NEEDED            0x32ae5             libsocket.so.1
       [5]  INIT              0x1b5218            
       [6]  FINI              0x1b5358            
       [7]  SONAME            0x32b0b             libmysqlclient.so.18
       [8]  RUNPATH           0x32b20             /opt/studio12u2/lib/sparc/64:/opt/studio12u2/lib/v9
       [9]  RPATH             0x32b20             /opt/studio12u2/lib/sparc/64:/opt/studio12u2/lib/v9
      [10]  HASH              0xe8                
      [11]  STRTAB            0x2a5f8             
      [12]  STRSZ             0x32b54             
      [13]  SYMTAB            0xaa38              
      [14]  SYMENT            0x18                
      [15]  CHECKSUM          0x2baa              
      [16]  VERNEED           0x5d150             
      [17]  VERNEEDNUM        0x3                 
      [18]  PLTRELSZ          0x8268              
      [19]  PLTREL            0x7                 
      [20]  JMPREL            0x79998             
      [21]  RELA              0x5d1b0             
      [22]  RELASZ            0x24a50             
      [23]  RELAENT           0x18                
      [24]  REGISTER          0x241               
      [25]  REGISTER          0x253               
      [26]  FEATURE_1         0x1                 [ PARINIT ]
      [27]  FLAGS             0                   0
      [28]  FLAGS_1           0x8000              [ DISPLACE-RELOCS-DONE ]
      [29]  PLTGOT            0x2c9d00            
      [30]  NULL              0                   

So that Studio 12u2 RPATH has been in the build process for a while and was silently ignored because all of the runtime libs needed are found in the default places. The libstlport requirement however, in MySQL 5.6.x and upwards, is a real problem as all downstream software will break that needs libmysqlclient.
[6 Jan 2016 15:47] Tor Didriksen
Posted by developer:
 
Will this be OK:
       [8]  RUNPATH           0x34eef             $ORIGIN/..:$ORIGIN/../lib:/opt/studio12u2/lib/stlport4:/opt/studio12u2/lib/sparc:/opt/studio12u2/lib/stlport4:/opt/studio12u2/lib
       [9]  RPATH             0x34eef             $ORIGIN/..:$ORIGIN/../lib:/opt/studio12u2/lib/stlport4:/opt/studio12u2/lib/sparc:/opt/studio12u2/lib/stlport4:/opt/studio12u2/lib
[16 Jan 2016 14:40] Paul DuBois
Noted in 5.6.29, 5.7.11, 5.8.0 changelogs.

Solaris packages failed to note the dependency of the MySQL client
library on the libstlport library.