升级glibc

下载路径:https://ftp.gnu.org/gnu/glibc/

安装方法:

wget http://ftp.gnu.org/gnu/glibc/glibc-2.33.tar.gz

tar zxvf glibc-2.33.tar.gz

cd glibc-2.33

mkdir build

cd build

../configure –prefix=/opt/glibc-2.33
glibc不能单独放在其他地方,否则会出现大部分命令segfault报错

../configure –prefix=/usr –disable-profile –enable-add-ons
–with-headers=/usr/include –with-binutils=/usr/bin

make -j4 尽量不要用多核,可能造成编译错误

make

make install

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/glibc-2.33/lib
(不建议使LD_LIBRARY_PATH,会出现段错误)

出现make compiler版本太低的问题

解决办法:升级gcc和Make

注意:不要随意修改或删除/lib64/libc.so.6,否则会造成无法登录,无法执行大部分命令等严重问题

查看libc.so.6中包含的GLIBC版本:

strings /opt/glibc-2.33/lib/libc.so.6 | grep GLIBC

对某个APP添加特定GLIBC库:

LD_PRELOAD=/opt/glibc${libc_version}/lib/libc.so.6:/opt/glibc${libc_version}/lib/libpthread.so.0:/opt/glibc${libc_version}/lib/ld-linux-x86-64.so.2
./my_app

查看glibc版本:

ldd –version

问题 make install 报cannot find -lnss_test2 错误

/usr/bin/perl scripts/test-installation.pl /tmp/glibc-2.31/build/

/usr/bin/ld: cannot find -lnss_test2

LD_SO=ld-linux-x86-64.so.2 CC=”gcc -B/usr/bin/“ /usr/bin/perl

scripts/test-installation.pl /tmp/glibc-2.31/build/

/usr/bin/ld: /lib/../lib64/libnss_nis.so: undefined reference to

‘_nsl_default_nss@GLIBC_PRIVATE’

可以从上面脚本信息看到是 scripts/test-installation.pl 有报错,
进去看一下, 主目录下的 Makefile

122 ifneq (no,$(PERL))

123 ifeq (/usr,$(prefix))

124 ifeq (,$(install_root))

125 LD_SO=$(ld.so-version) CC=”$(CC)” $(PERL) scripts/

test-installation.pl $(common-objpfx)

126 endif

127 endif

128 endif

129 endif

130 endif

123 ifeq (/usr,$(prefix)) 看来是和configure配置的prefix设置为/usr有关

具体的脚本 scripts/test-installation.pl 大致流程:

  1. 读取共享库版本;

  2. 使用这些动态库生成一个文件;

  3. 通过ldd检验一下

解决动态库 nss_test2 报错

调整一下 增加下面一行不再进行验证

128 && $name ne “nss_test2”

105 # Read names and versions of all shared libraries that are part of

106 # glibc

107 open SOVERSIONS, $soversions

111 %versions = ();

112

113 while () {

114 next if (/^all-sonames/);

115 chop;

116 if (/^lib/) {

117 ($name, $version)= /^lib(.).so-version=.(.)$/;

118 # Filter out some libraries we don’t want to link:

119 # - nss_ldap since it’s not yet available

120 # - libdb1 since it conflicts with libdb

121 # - libthread_db since it contains unresolved references

122 # - it’s just a test NSS module

123 # - We don’t provide the libgcc so we don’t test it

124 # - libmvec if it wasn’t built

125 next if ($build_mathvec == 0 && $name eq “mvec”);

126 if ($name ne “nss_ldap” && $name ne “db1”

127 && $name ne “thread_db”

128 && $name ne “nss_test2”

129 && $name ne “nss_test1” && $name ne “libgcc_s”) {

130 $link_libs .= “ -l$name”;

131 $versions{$name} = $version;

132 }

133 } elsif ($LD_SO ne “”) {

134 ($ld_so_name, $ld_so_version) = split (‘.so.’, $LD_SO);

135 } else {

136 if (/^ld.so/) {

137 ($ld_so_name, $ld_so_version)= /=(.).so.(.)$/;

138 }

139 }

140 }

….

解决动态库 undefined reference to ‘_nsl_default_nss@GLIBC_PRIVATE’

这个看下nis/Makefile

71 ifeq ($(build-obsolete-nsl),yes)

72 libnsl-routines += nss-default

configure 增加 –enable-obsolete-nsl

#configure –help

–enable-obsolete-nsl build and install the obsolete libnsl

library and depending NSS modules

按照下面格式重新调整一下,重新编译就可以了

../configure –prefix=/usr –with-headers=/usr/include

–with-binutils=/usr/bin –enable-obsolete-nsl


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!