1

I am trying to install glibc on Alpine Linux. I am running Alpine Linux in the Docker. Here are the steps I am using:

  1. docker pull alpine
  2. docker run -it alpine /bin/sh
  3. apk add --no-cache make gcc linux-headers bsd-compat-headers gawk bison binutils coreutils diffutils gettext bash grep sed texinfo perl
  4. wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
  5. tar -xzf glibc-2.28.tar.gz
  6. cd glibc-2.28
  7. mkdir glibc-build
  8. cd glibc-build
  9. ../configure --prefix=/usr \ --disable-profile --enable-add-ons \ --libexecdir=/usr/bin --with-headers=/usr/include \ --enable-static-pie
  10. cat > /etc/ld.so.conf << "EOF"

    # Begin /etc/ld.so.conf
    
    /usr/local/lib
    /opt/lib
    
    # End /etc/ld.so.conf
    EOF
    
  11. make

  12. make install

I am getting following error on 11th step:

/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lssp_nonshared

collect2: error: ld returned 1 exit status

make[2]: *** [Makefile:129: /glibc-2.28/glibc-build/elf/sotruss-lib.so] Error 1

make[2]: Leaving directory '/glibc-2.28/elf'

make[1]: *** [Makefile:258: elf/subdir_lib] Error 2

make[1]: Leaving directory '/glibc-2.28'

make: *** [Makefile:9: all] Error 2

If I try to add --disable-shared flag than another errors occur.

The error could be solved by adding libc-dev with the following command: apk add --no-cache libc-dev. But this way I would have two C libraries but I need my application to use glibc specifically.

UPDATE

If I run apk add --no-cache libc-dev, make command passes successfully but make install fails with the following error:

Execution of gcc failed!

The script has found some problems with your installation!

Please read the FAQ and the README file and check the following:

  • Did you change the gcc specs file (necessary after upgrading from Linux libc5)?

  • Are there any symbolic links of the form libXXX.so to old libraries?

    Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,

    libm.so should point to the newly installed glibc file - and there should be

    only one such link (check e.g. /lib and /usr/lib)

You should restart this script from your build directory after you've fixed all problems!

Btw. the script doesn't work if you're installing GNU libc not as your primary library!

NutCracker
  • 11,485
  • 4
  • 44
  • 68

2 Answers2

4

Eventually, I changed few steps in order to build glibc on Alpine Linux.

Here are the steps that worked for me:

  1. docker pull alpine
  2. docker run -it alpine /bin/sh
  3. wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
  4. tar -xzf glibc-2.28.tar.gz
  5. cd glibc-2.28
  6. mkdir glibc-build
  7. cd glibc-build
  8. apk add --no-cache make gcc gawk bison linux-headers libc-dev
  9. ../configure --prefix=/usr \ --disable-profile --enable-add-ons \ --libexecdir=/usr/lib --with-headers=/usr/include \ --without-cvs --enable-static-pie
  10. cat > /etc/ld.so.conf << "EOF" # Begin /etc/ld.so.conf /usr/local/lib /opt/lib /usr/lib /usr/lib64 /usr/libexec # End /etc/ld.so.conf EOF
  11. make
  12. make install

I hope these steps will work for everybody else also.

NutCracker
  • 11,485
  • 4
  • 44
  • 68
0

Installing musl-dev should get you past that build error, too, so you'll be building glibc against musl.

The musl-dev package has its own /usr/lib/libssp_nonshared.a:

https://pkgs.alpinelinux.org/contents?file=libssp_nonshared.a&path=&name=musl-dev&branch=v3.8&repo=main&arch=x86_64

valiano
  • 16,433
  • 7
  • 64
  • 79
  • 1
    And how can I then force my application to use `glibc` instead of `musl`? – NutCracker Oct 12 '18 at 17:11
  • You should be able to do so by pointing the compiler to the glibc headers locations (using the `-I` / `-isystem` gcc options or similar), during build, and by pointing the linker/compiler driver to the correct library (using `rpath`) for linking, using glibc's `ld` instead of the default musl `ld` – valiano Oct 12 '18 at 18:21
  • For `rpath`, see: https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host and particularily: https://stackoverflow.com/a/851229/7256341 – valiano Oct 12 '18 at 18:23