1

Topic: Tryout for temporary newer glibc

Hello,

just wanted to share the modifications I had done for having a newer glibc. Taken the version 2.27-2 from Arch Linux therefore as it is compatible for compiling with gcc-6 - another friendly reminder that we need a newer development-stack as version 6 reached its end of life.

Getting the files from here. The PKGBUILD is:

# $Id$
# Maintainer:  Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>

# toolchain build order: inux-libre-lts-api-headers->glibc->binutils->gcc->binutils->glibc
# NOTE: valgrind requires rebuilt with each major glibc version

pkgbase=glibc
pkgname=(glibc lib32-glibc)
pkgver=2.27
pkgrel=2.hyperbola0
arch=(x86_64)
url='http://www.gnu.org/software/libc'
license=(GPL LGPL)
makedepends=(git gd lib32-gcc-libs)
options=(!strip staticlibs)
_commit=23158b08a0908f381459f273a984c6fd328363cb
#source=(git+https://sourceware.org/git/glibc.git#commit=$_commit
source=(https://ftp.gnu.org/gnu/glibc/glibc-$pkgver.tar.xz{,.sig}
        locale.gen.txt
        locale-gen
        lib32-glibc.conf
        bz20338.patch
        nscd.initd)
validpgpkeys=(7273542B39962DF7B299931416792B4EA25340F8) # Carlos O'Donell
sha512sums=('7c5581154487d38d173ce1feb944e60207139cca148bccf066eaae322c0c2d219423bdcfa15c7f9be1b5e45dfc43c641cc5d80d3c3c65837d08a83cdb4e2a147'
            'SKIP'
            '3d9facc6da5159dcd877473c8a4d77006ef5615e2619ef743255112bfa136baf65239367222e87e7ada823d5c7d747aa5204f8365a806141e5884477898ccd14'
            'd92e6ba83ee86c3602e74c52bf5f99ca751f3867edb894dd22c179003cd58a1b4e11237a293a54fe126edafd5add78a65bf3368826b8bfa40451ee374e301961'
            '37858ae269bcf0d9d5adf5ac440ffeb9f5b71cce427ca85ff8cf9de6ae4d6011f8e71b83ec4aa183ab2ce248b563b5452e3d0d4b769a26f410d27bb8a31769a4'
            'ee6cb58bf3f79a702f483318afcd733fe4284609e1755dad7ec0d510c11835a2c850dc2e59e8846b7b0a4d1aff6aacace15eeb9824794fff0d8da84712de9a53'
            '8e9797f6cc7963d7c3233059591fd15c424c5dfa215b618336227982015b27b7a0532735ca70e9f269637e3ab1124c014efb3ce31ade2263a134c545448d89f5')

prepare() {
  mkdir -p glibc-build lib32-glibc-build

  [[ -d glibc-$pkgver ]] && ln -s glibc-$pkgver glibc 
  cd glibc

  local i; for i in ${source[@]}; do
    case ${i%::*} in
      *.patch)
        msg2 "Applying ${i}"
        patch -p1 -i "$srcdir/${i}"
        ;;
    esac
  done
}

build() {
  local _configure_flags=(
      --prefix=/usr
      --with-headers=/usr/include
      --with-bugurl=https://issues.hyperbola.info/
      --enable-add-ons
      --enable-obsolete-rpc
      --enable-kernel=2.6.32
      --enable-bind-now
      --enable-lock-elision
      --enable-multi-arch
      --enable-stack-protector=strong
      --enable-stackguard-randomization
      --disable-profile
      --disable-werror
  )

  cd "$srcdir/glibc-build"

  echo "slibdir=/lib" >> configparms
  echo "rtlddir=/lib" >> configparms
  echo "sbindir=/usr/sbin" >> configparms
  echo "rootsbindir=/sbin" >> configparms
  echo "vardbdir=/var/lib/misc" >> configparms

  # remove fortify for building libraries
  CPPFLAGS=${CPPFLAGS/-D_FORTIFY_SOURCE=2/}

  "$srcdir/glibc/configure" \
      --libdir=/usr/lib \
      --libexecdir=/usr/libexec \
      ${_configure_flags[@]}

  # build libraries with fortify disabled
  echo "build-programs=no" >> configparms
  make -j4

  # re-enable fortify for programs
  sed -i "/build-programs=/s#no#yes#" configparms

  echo "CC += -D_FORTIFY_SOURCE=2" >> configparms
  echo "CXX += -D_FORTIFY_SOURCE=2" >> configparms
  make -j4

  cd "$srcdir/lib32-glibc-build"
  export CC="gcc -m32 -mstackrealign"
  export CXX="g++ -m32 -mstackrealign"

  echo "slibdir=/lib32" >> configparms
  echo "rtlddir=/lib32" >> configparms
  echo "sbindir=/usr/sbin" >> configparms
  echo "rootsbindir=/sbin" >> configparms

  # remove fortify for building libraries
  CPPFLAGS=${CPPFLAGS/-D_FORTIFY_SOURCE=2/}
  CFLAGS=${CFLAGS/-fno-plt/}
  CXXFLAGS=${CXXFLAGS/-fno-plt/}

  "$srcdir/glibc/configure" \
      --host=i686-pc-linux-gnu \
      --libdir=/usr/lib32 \
      --libexecdir=/usr/libexec \
      ${_configure_flags[@]}

  # build libraries with fortify disabled
  echo "build-programs=no" >> configparms
  make -j4

  # re-enable fortify for programs
  sed -i "/build-programs=/s#no#yes#" configparms

  echo "CC += -D_FORTIFY_SOURCE=2" >> configparms
  echo "CXX += -D_FORTIFY_SOURCE=2" >> configparms
  make -j4

}

check() {
  cd glibc-build

  # remove fortify in preparation to run test-suite
  sed -i '/FORTIFY/d' configparms

  # some failures are "expected"
  make check || true
}

package_glibc() {
  pkgdesc='GNU C Library, with OpenRC support'
  depends=('linux-libre-lts-api-headers>=4.9' tzdata filesystem)
  optdepends=('gd: for memusagestat')
  install=glibc.install
  backup=(etc/gai.conf
          etc/locale.gen
          etc/nscd.conf)
  groups=(base)

  install -dm755 "$pkgdir/etc"
  touch "$pkgdir/etc/ld.so.conf"

  make -C glibc-build install_root="$pkgdir" install
  rm -f "$pkgdir"/etc/ld.so.{cache,conf}

  cd glibc

  install -dm755 "$pkgdir"/usr/lib/locale
  install -m644 nscd/nscd.conf "$pkgdir/etc/nscd.conf"
  install -Dm755 ${srcdir}/nscd.initd ${pkgdir}/etc/init.d/nscd

  install -m644 posix/gai.conf "$pkgdir"/etc/gai.conf

  install -m755 "$srcdir/locale-gen" "$pkgdir/usr/sbin"

  # Create /etc/locale.gen
  install -m644 "$srcdir/locale.gen.txt" "$pkgdir/etc/locale.gen"
  sed -e '1,3d' -e 's|/| |g' -e 's|\\| |g' -e 's|^|#|g' \
    "$srcdir/glibc/localedata/SUPPORTED" >> "$pkgdir/etc/locale.gen"

  if check_option 'debug' n; then
    find "$pkgdir"/usr/bin -type f -executable -exec strip $STRIP_BINARIES {} + 2> /dev/null || true
    find "$pkgdir"/usr/lib -name '*.a' -type f -exec strip $STRIP_STATIC {} + 2> /dev/null || true

    # Do not strip these for gdb and valgrind functionality, but strip the rest
    find "$pkgdir"/usr/lib \
      -not -name 'ld-*.so' \
      -not -name 'libc-*.so' \
      -not -name 'libpthread-*.so' \
      -not -name 'libthread_db-*.so' \
      -name '*-*.so' -type f -exec strip $STRIP_SHARED {} + 2> /dev/null || true
  fi

  # install license files
  install -dm755 ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 ${srcdir}/glibc-${pkgver}/{COPYING{,.LIB},LICENSES} ${pkgdir}/usr/share/licenses/${pkgname}
}

package_lib32-glibc() {
  pkgdesc='GNU C Library (32-bit)'
  depends=("glibc=$pkgver")

  cd lib32-glibc-build

  make install_root="$pkgdir" install
  rm -rf "$pkgdir"/{etc,sbin,usr/{bin,sbin,share},var}

  # We need to keep 32 bit specific header files
  find "$pkgdir/usr/include" -type f -not -name '*-32.h' -delete

  # Dynamic linker
  mkdir ${pkgdir}/lib
  ln -s ../lib32/ld-linux.so.2 "$pkgdir/lib/"

  # Add lib32 paths to the default library search path
  install -Dm644 "$srcdir/lib32-glibc.conf" "$pkgdir/etc/ld.so.conf.d/lib32-glibc.conf"

  # Symlink /usr/lib32/locale to /usr/lib/locale
  ln -s ../lib/locale "$pkgdir/usr/lib32/locale"

  if check_option 'debug' n; then
    find "$pkgdir"/usr/lib32 -name '*.a' -type f -exec strip $STRIP_STATIC {} + 2> /dev/null || true
    find "$pkgdir"/usr/lib32 \
      -not -name 'ld-*.so' \
      -not -name 'libc-*.so' \
      -not -name 'libpthread-*.so' \
      -not -name 'libthread_db-*.so' \
      -name '*-*.so' -type f -exec strip $STRIP_SHARED {} + 2> /dev/null || true
  fi

  # install license files
  install -dm755 ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 ${srcdir}/glibc-${pkgver}/{COPYING{,.LIB},LICENSES} ${pkgdir}/usr/share/licenses/${pkgname}
}

Please note therefore, that you also need to modify the file lib32-glibc.conf and build an INIT-script for nscd as the version coming up from Arch Linux uses systemd completely. So you should therefore also have a look onto the glibc here at Hyperbola. I'm testing this one for some days now and it is running very well. Happy hacking! smile

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!

2

Re: Tryout for temporary newer glibc

Here is a rework PKGBUILD for glibc 2.30:

# Maintainer (Arch): Allan McRae <allan@archlinux.org>
# Contributor (Artix): artoo <artoo@cromnix.org>
# Maintainer: André Silva <emulatorman@hyperbola.info>
# Contributor: Luke R. <g4jc@hyperbola.info>

# toolchain build order: linux-libre-lts-api-headers->glibc->binutils->gcc->binutils->glibc
# NOTE: valgrind requires rebuilt with each major glibc version

pkgbase=glibc
pkgname=(glibc lib32-glibc)
pkgver=2.30
_debver=2.30
_debrel=8
pkgrel=1.hyperbola0
pkgdesc="GNU C Library"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/libc"
license=('GPL-2' 'LGPL-2.1')
makedepends=('gcc>=8' 'python' 'quilt' 'lib32-gcc-libs')
options=('!strip' 'staticlibs')
install=glibc.install
source=(https://ftp.gnu.org/gnu/glibc/glibc-$pkgver.tar.bz2{,.sig}
        https://deb.debian.org/debian/pool/main/g/glibc/glibc_$_debver-$_debrel.debian.tar.xz
        locale.gen.txt
        locale-gen
        sdt.h sdt-config.h
        bz20338.patch
        file-truncated-while-reading-soname-after-patchelf.patch
        nscd.initd
        lib32-glibc.conf)
validpgpkeys=('7273542B39962DF7B299931416792B4EA25340F8') # Carlos O'Donell <carlos@systemhalted.org>
sha512sums=('0cb272ddf5bd305fb083486b601c59447964ec320bad2fd3d993a6d27672d697a343184bb032d40ffff2dd3e8da77acba4d5f4bbbfd0621cd2969ef827c20ca0'
            'SKIP'
            '674a632ad20e9c423fac1413aa8a373b0fed7170741e2a32e3a375a212f523b1356863775f5ead7a4ebd4aefc113e77d20ab7be964f1e393e59406e9661d35f2'
            '3d9facc6da5159dcd877473c8a4d77006ef5615e2619ef743255112bfa136baf65239367222e87e7ada823d5c7d747aa5204f8365a806141e5884477898ccd14'
            'd92e6ba83ee86c3602e74c52bf5f99ca751f3867edb894dd22c179003cd58a1b4e11237a293a54fe126edafd5add78a65bf3368826b8bfa40451ee374e301961'
            '8551a79591faad04030e6a792125f4afa81b36606efafd82451cd01470298d21eb0f85a1513b958b02aa9c3266df6a912a476f9840c8489506d16164aa8e2d49'
            '45b8689048e7fe18efb1c49d207aa871f049b4020fb5d25800d60b719451e2b860d4c0ed3b352fc28c311e3c9d3d1f48458e48dab318c14c2975d194678843c4'
            '817947b727e45a90ff2ba3f41447965178d41c1f5e4468a4daa7f80869e6fa103f17a633122179ba50439b09c6a04fe6aa028a3a08081df77f130a4470e28461'
            'b1e2beb7e9e5380230f24231aa2fe14118b89541a4cca6c1bd4bd94fd2ddffb4acc0f5f858407df8d1d830264b0894b1328278c44ebf8a0e847c16c1089494b0'
            '8e9797f6cc7963d7c3233059591fd15c424c5dfa215b618336227982015b27b7a0532735ca70e9f269637e3ab1124c014efb3ce31ade2263a134c545448d89f5'
            '37858ae269bcf0d9d5adf5ac440ffeb9f5b71cce427ca85ff8cf9de6ae4d6011f8e71b83ec4aa183ab2ce248b563b5452e3d0d4b769a26f410d27bb8a31769a4')

prepare() {
  mkdir -p glibc-build lib32-glibc-build

  cd glibc-${pkgver}

  if [[ ${pkgver%.*} = ${_debver%.*} ]]; then
    # Debian patches
    export QUILT_PATCHES=debian/patches
    export QUILT_REFRESH_ARGS='-p ab --no-timestamps --no-index'
    export QUILT_DIFF_ARGS='--no-timestamps'

    mv "$srcdir"/debian .

    # Doesn't apply and seems unimportant
    rm -v debian/patches/all/local-remove-manual.diff || true
    rm -rv debian/patches/alpha || true
    rm -v debian/patches/any/local-bindresvport_blacklist.diff || true
    rm -v debian/patches/any/local-bootstrap-headers.diff || true
    rm -v debian/patches/any/local-disable-libnss-db.diff || true
    rm -v debian/patches/any/local-ldconfig.diff || true
    rm -v debian/patches/any/local-ldconfig-ignore-ld.so.diff || true
    rm -v debian/patches/any/local-ldconfig-multiarch.diff || true
    rm -v debian/patches/any/local-ld-multiarch.diff || true
    rm -v debian/patches/any/local-ldso-disable-hwcap.diff || true
    rm -v debian/patches/any/local-libpic.diff || true
    rm -v debian/patches/any/local-nss-upgrade.diff || true
    rm -v debian/patches/any/local-rtlddir-cross.diff || true
    rm -v debian/patches/any/local-tcsetaddr.diff || true
    rm -v debian/patches/any/submitted-bits-fcntl_h-at.diff || true
    rm -v debian/patches/any/unsubmitted-ldso-machine-mismatch.diff || true
    rm -rv debian/patches/arm || true
    rm -v debian/patches/git-updates.diff || true
    rm -rv debian/patches/hppa || true
    rm -rv debian/patches/hurd-i386 || true
    rm -rv debian/patches/i386 || true
    rm -rv debian/patches/kfreebsd || true
    rm -rv debian/patches/m68k || true
    rm -rv debian/patches/mips || true
    rm -rv debian/patches/powerpc || true
    rm -rv debian/patches/sh4 || true

    quilt push -av
  fi

  # sync fgetsgent_r.c with grp/fgetgrent_r.c
  patch -p1 -i ../bz20338.patch

  # file truncated while reading soname after patchelf
  patch -p1 -i ../file-truncated-while-reading-soname-after-patchelf.patch
}

build() {
  local _configure_flags=(
      --prefix=/usr
      --with-headers=/usr/include
      --with-bugurl=https://issues.hyperbola.info/
      --enable-add-ons
      --enable-obsolete-rpc
      --enable-kernel=2.6.32
      --enable-bind-now
      --disable-profile
      --enable-stackguard-randomization
      --enable-stack-protector=strong
      --enable-lock-elision
      --enable-multi-arch
      --disable-werror
  )

  cd "$srcdir"/glibc-build

  if [[ ${CARCH} = "i686" ]]; then
    # Hack to fix NPTL issues with Xen, only required on 32bit platforms
    export CFLAGS="${CFLAGS} -mno-tls-direct-seg-refs"
  fi

  echo "slibdir=/lib" >> configparms
  echo "rtlddir=/lib" >> configparms
  echo "sbindir=/usr/sbin" >> configparms
  echo "rootsbindir=/sbin" >> configparms
  echo "vardbdir=/var/lib/misc" >> configparms

  # remove fortify for building libraries
  CPPFLAGS=${CPPFLAGS/-D_FORTIFY_SOURCE=2/}

  ../${pkgname}-${pkgver}/configure \
      --libdir=/usr/lib \
      --libexecdir=/usr/libexec \
      ${_configure_flags[@]}


  # build libraries with fortify disabled
  echo "build-programs=no" >> configparms
  make

  # re-enable fortify for programs
  sed -i "/build-programs=/s#no#yes#" configparms

  echo "CC += -D_FORTIFY_SOURCE=2" >> configparms
  echo "CXX += -D_FORTIFY_SOURCE=2" >> configparms
  make

  cd "$srcdir"/lib32-glibc-build
  export CC="gcc -m32 -mstackrealign"
  export CXX="g++ -m32 -mstackrealign"

  echo "slibdir=/lib32" >> configparms
  echo "rtlddir=/lib32" >> configparms
  echo "sbindir=/usr/sbin" >> configparms
  echo "rootsbindir=/sbin" >> configparms

  # remove fortify for building libraries
  CPPFLAGS=${CPPFLAGS/-D_FORTIFY_SOURCE=2/}
  CFLAGS=${CFLAGS/-fno-plt/}
  CXXFLAGS=${CXXFLAGS/-fno-plt/}

  ../${pkgname}-${pkgver}/configure \
      --host=i686-pc-linux-gnu \
      --libdir=/usr/lib32 \
      --libexecdir=/usr/libexec \
      ${_configure_flags[@]}

  # build libraries with fortify disabled
  echo "build-programs=no" >> configparms
  make

  # re-enable fortify for programs
  sed -i "/build-programs=/s#no#yes#" configparms

  echo "CC += -D_FORTIFY_SOURCE=2" >> configparms
  echo "CXX += -D_FORTIFY_SOURCE=2" >> configparms
  make
}

check() {
  cd glibc-build

  # remove fortify in preparation to run test-suite
  sed -i '/FORTIFY/d' configparms

  # some failures are "expected"
  make check || true
}

package_glibc() {
  pkgdesc='GNU C Library, with OpenRC support'
  depends=('linux-libre-lts-api-headers>=4.9' tzdata filesystem)
  optdepends=('gd: for memusagestat')
  install=glibc.install
  backup=(etc/gai.conf
          etc/locale.gen
          etc/nscd.conf)
  groups=(base)

  cd glibc-build

  install -dm755 ${pkgdir}/etc
  touch ${pkgdir}/etc/ld.so.conf

  make install_root=${pkgdir} install

  rm -f ${pkgdir}/etc/ld.so.{cache,conf}

  install -dm755 ${pkgdir}/usr/lib/locale

  install -m644 ${srcdir}/${pkgname}-${pkgver}/nscd/nscd.conf ${pkgdir}/etc/nscd.conf

  install -Dm755 ${srcdir}/nscd.initd ${pkgdir}/etc/init.d/nscd

  install -m644 ${srcdir}/${pkgname}-${pkgver}/posix/gai.conf ${pkgdir}/etc/gai.conf

  install -m755 ${srcdir}/locale-gen ${pkgdir}/usr/sbin

  # create /etc/locale.gen
  install -m644 ${srcdir}/locale.gen.txt ${pkgdir}/etc/locale.gen
  sed -e '1,3d' -e 's|/| |g' -e 's|\\| |g' -e 's|^|#|g' \
    ${srcdir}/glibc-${pkgver}/localedata/SUPPORTED >> ${pkgdir}/etc/locale.gen

  if check_option 'debug' n; then
    find "${pkgdir}"/{sbin,usr/{,s}bin} -type f -executable -exec strip $STRIP_BINARIES {} + 2> /dev/null || true
    find "${pkgdir}"/{,usr/}lib -name '*.a' -type f -exec strip $STRIP_STATIC {} + 2> /dev/null || true

    # Do not strip these for gdb and valgrind functionality, but strip the rest
    find "${pkgdir}"{,/usr}/lib \
      -not -name 'ld-*.so' \
      -not -name 'libc-*.so' \
      -not -name 'libpthread-*.so' \
      -not -name 'libthread_db-*.so' \
      -name '*-*.so' -type f -exec strip $STRIP_SHARED {} + 2> /dev/null || true
  fi

  # provide tracing probes to libstdc++ for exceptions, possibly for other
  # libraries too. useful for gdb's catch command.
  install -Dm644 "${srcdir}/sdt.h" "${pkgdir}/usr/include/sys/sdt.h"
  install -Dm644 "${srcdir}/sdt-config.h" "${pkgdir}/usr/include/sys/sdt-config.h"

  # install license files
  install -dm755 ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 ${srcdir}/glibc-${pkgver}/{COPYING{,.LIB},LICENSES} ${pkgdir}/usr/share/licenses/${pkgname}
}

package_lib32-glibc() {
  pkgdesc='GNU C Library (32-bit)'
  depends=("glibc=$pkgver")

  cd lib32-glibc-build

  make install_root="$pkgdir" install
  rm -rf "$pkgdir"/{etc,sbin,usr/{bin,sbin,share},var}

  # We need to keep 32 bit specific header files
  find "$pkgdir/usr/include" -type f -not -name '*-32.h' -delete

  # Dynamic linker
  mkdir ${pkgdir}/lib
  ln -s ../lib32/ld-linux.so.2 "$pkgdir/lib/"

  # Add lib32 paths to the default library search path
  install -Dm644 "$srcdir/lib32-glibc.conf" "$pkgdir/etc/ld.so.conf.d/lib32-glibc.conf"

  # Symlink /usr/lib32/locale to /usr/lib/locale
  ln -s ../lib/locale "$pkgdir/usr/lib32/locale"

  if check_option 'debug' n; then
    find "$pkgdir"/usr/lib32 -name '*.a' -type f -exec strip $STRIP_STATIC {} + 2> /dev/null || true
    find "$pkgdir"/usr/lib32 \
      -not -name 'ld-*.so' \
      -not -name 'libc-*.so' \
      -not -name 'libpthread-*.so' \
      -not -name 'libthread_db-*.so' \
      -name '*-*.so' -type f -exec strip $STRIP_SHARED {} + 2> /dev/null || true
  fi

  # install license files
  install -dm755 ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 ${srcdir}/glibc-${pkgver}/{COPYING{,.LIB},LICENSES} ${pkgdir}/usr/share/licenses/${pkgname}
}

The needed additional files can be found here.
Did a rework because of multilib-support.

Human being in favor with clear principles and so also for freedom in soft- and hardware!

Certainly anyone who has the power to make you believe absurdities has the power to make you commit injustices: For a life of every being full with peace and kindness, including diversity and freedom. Capitalism is destroying our minds, the planet itself and the universe in the end!