Skip to content

Building libc6 compat

aborkar-ibm edited this page Apr 30, 2018 · 24 revisions

Building libc6-compat

The instructions provided below specify the steps to build libc6-compat version 1.1.19 on Linux on IBM Z for the following distributions:

  • RHEL (7.3, 7.4)
  • SLES (12 SP2, 12 SP3)
  • Ubuntu (16.04, 17.10, 18.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified

  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it

Step 1: Install the Dependencies

  • RHEL (7.3, 7.4)

      sudo yum install -y gcc gcc-c++ make wget tar      
    
  • SLES (12 SP2, 12 SP3)

      sudo zypper install -y gcc gcc-c++ make wget tar bzip2 zlib-devel 
    
  • Ubuntu (16.04, 17.10, 18.04)

      sudo apt-get update
      sudo apt-get install -y gcc g++ tar wget make cmake bzip2 zlib1g-dev g++-multilib
    

Step 2: Build and install libc6-compat

  • Download source code

    cd /<source_root>/
    wget http://git.musl-libc.org/cgit/musl/snapshot/musl-1.1.19.tar.gz
    tar -xvf musl-1.1.19.tar.gz
    
  • Build and install gcc 6.3.0 (Only for Ubuntu 16.04, 17.10, 18.04)

    • Get gcc source code

      cd /<source_root>/
      wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-6.3.0/gcc-6.3.0.tar.gz
      tar -xvzf gcc-6.3.0.tar.gz  
      cd gcc-6.3.0/  
      ./contrib/download_prerequisites
      
      cd /<source_root>/
      mkdir gcc_build  
      cd gcc_build/  
      ../gcc-6.3.0/configure --prefix="/opt/gcc" --enable-shared --with-system-zlib --enable-threads=posix --enable-__cxa_atexit --enable-checking --enable-gnu-indirect-function --enable-languages="c,c++" --disable-bootstrap --disable-multilib  
      

      Note: By changing the prefix, you can specify a different installation directory. Make sure to use the same directory in below commands

      Note: Modify //gcc-6.3.0/gcc/ubsan.c file as per below patch only on Ubuntu 17.10 and 18.04 before building:

      --- a/gcc/ubsan.c
      +++ b/gcc/ubsan.c
      @@ -1471,7 +1471,7 @@ ubsan_use_new_style_p (location_t loc)
      
         expanded_location xloc = expand_location (loc);
         if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0
      -      || xloc.file == '\0' || xloc.file[0] == '\xff'
      +      || xloc.file[0] == '\0' || xloc.file[0] == '\xff'
             || xloc.file[1] == '\xff')
           return false;
    • Build and Install

      make  
      sudo make install  
      export PATH=/opt/gcc/bin:$PATH
      
  • Build and Install libc6-compat

    cd /<source_root>/musl-1.1.19
    ./configure 
    make 
    sudo make install
    

Note: By default, configure installs to a prefix of "/usr/local/musl". This differs from the behavior of most configure scripts, and is chosen specifically to avoid clashing with libraries already present on the system. DO NOT set the prefix to "/usr", "/usr/local", or "/" unless you're upgrading libc on an existing musl-based system. Doing so will break your existing system when you run "make install" and it may be difficult to recover.

Step 3: Verify libc6-compat (Optional)

  • After installing, you should be able to use musl via the musl-gcc wrapper. For example:
#include <stdio.h>
int main()
{
	printf("hello, world!\n");
	return 0;
}
EOF
/usr/local/musl/bin/musl-gcc hello.c
./a.out

Note: The above program should compile and execute successfully printing the string hello, world.

Notes:

  • To configure autoconf-based program to compile and link against musl, set the CC variable to musl-gcc when running configure, as in: CC=musl-gcc ./configure ...
  • You will probably also want to use --prefix when building libraries to ensure that they are installed under the musl prefix and not in the main host system library directories.

References:

Clone this wiki locally