编译glibc遇到的问题

https://blog.csdn.net/jiuweideqixu/article/details/104408432

 

因为学习堆的时候需要glibc2.26以下的版本,决定自己在docker里编译一个glibc2.24,中间遇到一些bug记录如下

.symver on common symbols
编译时报错

/tmp/ccPRCqlU.s: Error: `loc1@GLIBC_2.2.5' can't be versioned to common symbol 'loc1'
/tmp/ccPRCqlU.s: Error: `loc2@GLIBC_2.2.5' can't be versioned to common symbol 'loc2'
/tmp/ccPRCqlU.s: Error: `locs@GLIBC_2.2.5' can't be versioned to common symbol 'locs'
  • 1
  • 2
  • 3

解决方案:https://patchwork.ozlabs.org/patch/780067/
patch

--- a/misc/regexp.c
+++ b/misc/regexp.c
@@ -29,14 +29,15 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23)
 
-/* Define the variables used for the interface.  */
-char *loc1;
-char *loc2;
+/* Define the variables used for the interface.  Avoid .symver on common
+   symbol, which just creates a new common symbol, not an alias.  */
+char *loc1 __attribute__ ((nocommon));
+char *loc2 __attribute__ ((nocommon));
 compat_symbol (libc, loc1, loc1, GLIBC_2_0);
 compat_symbol (libc, loc2, loc2, GLIBC_2_0);
 
 /* Although we do not support the use we define this variable as well.  */
-char *locs;
+char *locs __attribute__ ((nocommon));
 compat_symbol (libc, locs, locs, GLIBC_2_0);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

target ‘/root/build/math/e_pow.o’ failed
报错如下:

../sysdeps/ieee754/dbl-64/e_pow.c:469:13: error: ‘<<’ in boolean context, did you mean ‘<’ ? [-Werror=int-in-bool-context]
       if (n << (k - 20))
           ~~^~~~~~~~~~~
../sysdeps/ieee754/dbl-64/e_pow.c:471:17: error: ‘<<’ in boolean context, did you mean ‘<’ ? [-Werror=int-in-bool-context]
       return (n << (k - 21)) ? -1 : 1;
              ~~~^~~~~~~~~~~~
../sysdeps/ieee754/dbl-64/e_pow.c:477:9: error: ‘<<’ in boolean context, did you mean ‘<’ ? [-Werror=int-in-bool-context]
   if (m << (k + 12))
       ~~^~~~~~~~~~~
../sysdeps/ieee754/dbl-64/e_pow.c:479:13: error: ‘<<’ in boolean context, did you mean ‘<’ ? [-Werror=int-in-bool-context]
   return (m << (k + 11)) ? -1 : 1;
          ~~~^~~~~~~~~~~~
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

解决方案: https://patchwork.ozlabs.org/patch/680578/
patch

diff --git a/sysdeps/ieee754/dbl-64/e_pow.c b/sysdeps/ieee754/dbl-64/e_pow.c
index 663fa39..bd758b5 100644
--- a/!
+++ b/sysdeps/ieee754/dbl-64/e_pow.c
@@ -466,15 +466,15 @@  checkint (double x)
     return (n & 1) ? -1 : 1;	/* odd or even */
   if (k > 20)
     {
-      if (n << (k - 20))
+      if (n << (k - 20) != 0)
 	return 0;		/* if not integer */
-      return (n << (k - 21)) ? -1 : 1;
+      return (n << (k - 21) != 0) ? -1 : 1;
     }
   if (n)
     return 0;			/*if  not integer */
   if (k == 20)
     return (m & 1) ? -1 : 1;
-  if (m << (k + 12))
+  if (m << (k + 12) != 0)
     return 0;
-  return (m << (k + 11)) ? -1 : 1;
+  return (m << (k + 11) != 0) ? -1 : 1;
 }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

sunrpc/rpc_parse.c

rpc_parse.c:543:23: error: ‘%d’ directive writing between 1 and 10 bytes into a region of size 7 [-Werror=format-overflow=]
     sprintf (name, "%s%d", ARGNAME, num); /* default name of argument */
                       ^~
rpc_parse.c:543:20: note: directive argument in the range [1, 2147483647]
     sprintf (name, "%s%d", ARGNAME, num); /* default name of argument */
                    ^~~~~~
rpc_parse.c:543:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 10
     sprintf (name, "%s%d", ARGNAME, num); /* default name of argument */
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

解决方案:

--- a/sunrpc/rpc_parse.c
+++ b/sunrpc/rpc_parse.c
@@ -521,7 +521,7 @@ static void
 get_prog_declaration (declaration * dec, defkind dkind, int num /* arg number */ )
 {
   token tok;
-  char name[10];		/* argument name */
+  char name[MAXLINESIZE];		/* argument name */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

nis/nss_nisplus/nisplus-alias.c

nss_nisplus/nisplus-alias.c:300:12: error: argument 1 null where non-null expected [-Werror=nonnull]
[ERROR]      nss_nisplus/nisplus-alias.c:303:39: error: '%s' directive argument is null [-Werror=format-truncation=]
[ERROR]      make[3]: *** [/Volumes/OSXElCapitan/Users/mrdekk/casesafe/.build/x86_64-ubuntu16.04-linux-gnu/build/build-libc-final/multilib/nis/nisplus-alias.os] Error 1
[ERROR]      make[3]: *** Waiting for unfinished jobs....
[ERROR]      make[2]: *** [nis/others] Error 2
[ERROR]      make[1]: *** [all] Error 2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

解决方案:

diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index 7f698b4e6d..509ace1f83 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -297,10 +297,10 @@  _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
       return NSS_STATUS_UNAVAIL;
     }
 
-  char buf[strlen (name) + 9 + tablename_len];
+  char buf[tablename_len + 9];
   int olderr = errno;
 
-  snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+  snprintf (buf, sizeof (buf), "[name=],%s", tablename_val);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

build目录缺少/etc/ld.so.conf
解决方案:

cd etc/
touch ld.so.conf
  • 1
  • 2

转自:https://blog.wh98.me/2019/03/20/%E7%BC%96%E8%AF%91glibc%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/
作者:hustcw
参考:
https://blog.csdn.net/qq_40827990/article/details/89295472

 

gawk '/\.gnu\.glibc-stub\./ { \sub(/\.gnu\.glibc-stub\./, "", $2); \stubs[$2] = 1; } \END { for (s in stubs) print "#define __stub_" s }' > /root/glibc-2.23/glibc-build/math/stubsT
gawk: error while loading shared libraries: /lib64/libm.so.6: invalid ELF header
make[2]: *** [/root/glibc-2.23/glibc-build/math/stubs] Error 127
make[2]: Leaving directory `/root/glibc-2.23/math'
make[1]: *** [math/subdir_install] Error 2
make[1]: Leaving directory `/root/glibc-2.23'
make: *** [install] Error 2



解决办法(在另外的窗口执行):

# cd /lib64
# unlink libm.so.6
# ln -s libm-2.23.so libm.so.6

然后再次执行make install
看到如下信息就是安装成功了

LD_SO=ld-linux-x86-64.so.2 CC="gcc" /usr/bin/perl scripts/test-installation.pl /root/glibc-2.23/glibc-build/
Your new glibc installation seems to be ok.
make[1]: Leaving directory `/root/glibc-2.23'
4、验证
# ldd --version
ldd (GNU libc) 2.23
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.


报错:

setenv.c: In function '__unsetenv':
setenv.c:279:6: error: suggest explicit braces to avoid ambiguous 'else' [-Werror=parentheses]
   if (ep != NULL)
      ^
cc1: all warnings being treated as errors
../o-iterator.mk:9: recipe for target '/builddir/build/BUILD/glibc-arm-linux-gnu-2.23/build-arm-linux-gnu-glibc/stdlib/setenv.o' failed
make[2]: *** [/builddir/build/BUILD/glibc-arm-linux-gnu-2.23/build-arm-linux-gnu-glibc/stdlib/setenv.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/builddir/build/BUILD/glibc-arm-linux-gnu-2.23/glibc-2.23/stdlib'
Makefile:214: recipe for target 'stdlib/subdir_lib' failed
make[1]: *** [stdlib/subdir_lib] Error 2
make[1]: Leaving directory '/builddir/build/BUILD/glibc-arm-linux-gnu-2.23/glibc-2.23'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

原因:

glibc-2.23/nis/nis_call.c与
glibc-2.23/stdlib/setenv.c
大括号缺失
  • 1
  • 2
  • 3

解决方法:

glibc-2.23/nis/nis_call.c

diff -up glibc-arm-linux-gnu-2.23/glibc-2.23/nis/nis_call.c.gcc61 glibc-arm-linux-gnu-2.23/glibc-2.23/nis/nis_call.c
--- glibc-arm-linux-gnu-2.23/glibc-2.23/nis/nis_call.c.gcc61	2016-02-18 18:54:00.000000000 +0100
+++ glibc-arm-linux-gnu-2.23/glibc-2.23/nis/nis_call.c	2016-05-19 18:44:24.288550322 +0200
@@ -680,6 +680,7 @@ nis_server_cache_add (const_nis_name nam
   /* Choose which entry should be evicted from the cache.  */
   loc = &nis_server_cache[0];
   if (*loc != NULL)
+  {
     for (i = 1; i < 16; ++i)
       if (nis_server_cache[i] == NULL)
 	{
@@ -690,6 +691,7 @@ nis_server_cache_add (const_nis_name nam
 	       || ((*loc)->uses == nis_server_cache[i]->uses
 		   && (*loc)->expires > nis_server_cache[i]->expires))
 	loc = &nis_server_cache[i];
+  }
   old = *loc;
   *loc = new;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

glibc-2.23/stdlib/setenv.c

diff -up glibc-arm-linux-gnu-2.23/glibc-2.23/stdlib/setenv.c.gcc61 glibc-arm-linux-gnu-2.23/glibc-2.23/stdlib/setenv.c
--- glibc-arm-linux-gnu-2.23/glibc-2.23/stdlib/setenv.c.gcc61	2016-02-18 18:54:00.000000000 +0100
+++ glibc-arm-linux-gnu-2.23/glibc-2.23/stdlib/setenv.c	2016-05-19 18:41:09.778640989 +0200
@@ -277,6 +277,7 @@ unsetenv (const char *name)
 
   ep = __environ;
   if (ep != NULL)
+  {
     while (*ep != NULL)
       if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
 	{
@@ -290,6 +291,7 @@ unsetenv (const char *name)
 	}
       else
 	++ep;
+  }
 
   UNLOCK;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
 
 
posted on 2024-02-03 00:40  独上兰舟1  阅读(213)  评论(0编辑  收藏  举报