编译GLIBC-2.30执行make check时出现链接断言错误求助
info[DT_RPATH] == NULL Assertion Failure When Building GLIBC 2.30 Let's break down what's happening here and walk through the fixes step by step—this is a common gotcha when building newer GLIBC versions on older systems like your RHEL7-based setup.
What's Causing the Assertion Error?
That ld.so assertion fail boils down to one key issue: the test binaries you're building have both DT_RPATH and DT_RUNPATH dynamic linking tags embedded in them. GLIBC's dynamic linker (ld.so) has internal checks for its test suite that don't allow both tags to exist at the same time, hence the crash.
The ldd output you saw is another symptom: your test binaries are still defaulting to the system's old /lib64/ld-linux-x86-64.so.2 instead of your newly built linker, even when you try to specify it explicitly. The conflicting path tags are still causing problems regardless of which linker you use.
Step-by-Step Fixes
1. Adjust Configure Flags to Avoid Dual Path Tags
First, update your configure command to force the linker to only use DT_RUNPATH (and omit DT_RPATH entirely), which will satisfy the assertion check. Add the LDFLAGS parameter below:
../glibc/configure --prefix=$HOME/lib/gnu/glibc_v2 \ CC="$gcc_bin/gcc -m64" \ --with-headers=$kern_headers \ CFLAGS=" -O3" \ CXXFLAGS=" -O3 -std=c++17" \ --with-binutils=$binutils_base/bin \ LDFLAGS="-Wl,--enable-new-dtags"
Quick explanation:
--enable-new-dtagstells your binutils linker to only generate the newerDT_RUNPATHtag instead of bothDT_RPATHandDT_RUNPATH(which is the default behavior). This eliminates the conflict that triggers the assertion.
2. Isolate the Build from System Libraries
Your system's GLIBC 2.17 is likely leaking into the build process. Before running make and make check, set these environment variables to force use of your newly built GLIBC components:
export LD_LIBRARY_PATH=$HOME/lib/glibc_build:$HOME/lib/glibc_build/elf:$HOME/lib/glibc_build/math:$HOME/lib/glibc_build/dlfcn:$HOME/lib/glibc_build/nss:$HOME/lib/glibc_build/nis:$HOME/lib/glibc_build/rt:$HOME/lib/glibc_build/resolv:$HOME/lib/glibc_build/mathvec:$HOME/lib/glibc_build/support:$HOME/lib/glibc_build/crypt:$HOME/lib/glibc_build/nptl export LD_PRELOAD=$HOME/lib/glibc_build/libc.so.6
Then clean your build directory and recompile:
make clean && make -j40 && make check
3. Fix Test Execution to Ignore Embedded Paths
When running individual tests (like your test-as-const-ucontext_i example), add the --inhibit-rpath '' flag to the dynamic linker command. This tells ld.so to ignore any embedded DT_RPATH/DT_RUNPATH tags in the binary and only use the paths you specify:
env GCONV_PATH=$HOME/lib/glibc_build/iconvdata \ LOCPATH=$HOME/lib/glibc_build/localedata LC_ALL=C \ $HOME/lib/glibc_build/elf/ld-linux-x86-64.so.2 \ --library-path $HOME/lib/glibc_build:$HOME/lib/glibc_build/math:$HOME/lib/glibc_build/elf:$HOME/lib/glibc_build/dlfcn:$HOME/lib/glibc_build/nss:$HOME/lib/glibc_build/nis:$HOME/lib/glibc_build/rt:$HOME/lib/glibc_build/resolv:$HOME/lib/glibc_build/mathvec:$HOME/lib/glibc_build/support:$HOME/lib/glibc_build/crypt:$HOME/lib/glibc_build/nptl \ --inhibit-rpath '' \ $HOME/lib/glibc_build/csu/test-as-const-ucontext_i > $HOME/lib/glibc_build/csu/test-as-const-ucontext_i.out; \ ../scripts/evaluate-test.sh csu/test-as-const-ucontext_i $? false false \ $HOME/lib/glibc_build/csu/test-as-const-ucontext_i.test-result
4. Verify Your Binutils Setup
Double-check that you're actually using the Spack-installed binutils 2.33.1, not the system's older linker. Run:
$binutils_base/bin/ld --version
If it doesn't show GNU ld version 2.33.1, your Spack environment isn't loaded correctly. Reactivate your Spack environment and ensure PATH and LD_LIBRARY_PATH prioritize your Spack-installed tools over system ones.
Post-Installation Tips
After running make install, when compiling test programs with your new GLIBC, always use the same gcc@9.2 you used to build GLIBC, and explicitly specify the new linker and library paths:
$gcc_bin/gcc -m64 test.c -o test \ -Wl,--dynamic-linker=$HOME/lib/gnu/glibc_v2/lib/ld-linux-x86-64.so.2 \ -L$HOME/lib/gnu/glibc_v2/lib -lc \ -Wl,-rpath=$HOME/lib/gnu/glibc_v2/lib
For better isolation, consider creating a dedicated Spack environment for this build to avoid system interference:
spack env create glibc-build spack env activate glibc-build spack install binutils@2.33.1 gcc@9.2 gmake@4.2.1 libcap@2.25 linux-headers@4.9.10 libgd@2.2.4
内容的提问来源于stack exchange,提问作者sucksatnetworking

