LFS Glibc-2.40

安装Glibc
case $(uname -m) in
    i?86)   ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
    ;;
    x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
            ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
    ;;
esac

cd $LFS/sources

VERSION=2.40
tar xf glibc-${VERSION}.tar.xz
cd glibc-${VERSION}

patch -Np1 -i ../glibc-2.40-fhs-1.patch

mkdir -v build
cd       build

echo "rootsbindir=/usr/sbin" > configparms

../configure                             \
      --prefix=/usr                      \
      --host=$LFS_TGT                    \
      --build=$(../scripts/config.guess) \
      --enable-kernel=4.19               \
      --with-headers=$LFS/usr/include    \
      --disable-nscd                     \
      libc_cv_slibdir=/usr/lib

make
# 以lfs身份执行,确保将软件包安装到$LFS;如果错误以root身份执行安装到host主机,会导致host主机操作系统故障
make DESTDIR=$LFS install

# 改正 ldd 脚本中硬编码的可执行文件加载器路径
sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd

备注

文档中提到 『有报告称该软件包在并行构建时可能失败,如果发生了这种情况,加上 -j1 选项重新执行 make 命令。』

我第一次编译没有问题,但是再次编译遇到显示找不到某个文件 ld: cannot find -lgcc_s: No such file or directory :

...
/mnt/lfs/tools/lib/gcc/x86_64-lfs-linux-gnu/13.2.0/../../../../x86_64-lfs-linux-gnu/bin/ld: cannot find -lgcc_s: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [../Rules:227: /mnt/lfs/sources/glibc-2.39/build/support/links-dso-program] Error 1
make[2]: Leaving directory '/mnt/lfs/sources/glibc-2.39/support'
make[1]: *** [Makefile:484: support/others] Error 2
make[1]: Leaving directory '/mnt/lfs/sources/glibc-2.39'
make: *** [Makefile:9: all] Error 2

警告

确认新工具链的各基本功能 (编译和链接) 能如我们所预期的那样工作。执行以下命令进行完整性检查

检查新工具链基本功能(编译和链接)
echo 'int main(){}' | $LFS_TGT-gcc -xc -
readelf -l a.out | grep ld-linux

输出应该类似:

检查新工具链基本功能(编译和链接)输出信息
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]