test-installation.pl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/usr/bin/perl -w
  2. # Copyright (C) 1997-2026 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4. # The GNU C Library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. # The GNU C Library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Lesser General Public License for more details.
  12. # You should have received a copy of the GNU Lesser General Public
  13. # License along with the GNU C Library; if not, see
  14. # <https://www.gnu.org/licenses/>.
  15. $PACKAGE = "libc";
  16. $progname = $0;
  17. if ($ENV{CC}) {
  18. $CC = $ENV{CC};
  19. } else {
  20. $CC= "gcc";
  21. }
  22. if ($ENV{LD_SO}) {
  23. $LD_SO = $ENV{LD_SO};
  24. } else {
  25. $LD_SO = "";
  26. }
  27. sub usage {
  28. print "Usage: test-installation [soversions.mk]\n";
  29. print " --help print this help, then exit\n";
  30. print " --version print version number, then exit\n";
  31. exit 0;
  32. }
  33. sub installation_problem {
  34. print "The script has found some problems with your installation!\n";
  35. print "Please read the FAQ and the README file and check the following:\n";
  36. print "- Did you change the gcc specs file (necessary after upgrading from\n";
  37. print " Linux libc5)?\n";
  38. print "- Are there any symbolic links of the form libXXX.so to old libraries?\n";
  39. print " Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,\n";
  40. print " libm.so should point to the newly installed glibc file - and there should be\n";
  41. print " only one such link (check e.g. /lib and /usr/lib)\n";
  42. print "You should restart this script from your build directory after you've\n";
  43. print "fixed all problems!\n";
  44. print "Btw. the script doesn't work if you're installing GNU libc not as your\n";
  45. print "primary library!\n";
  46. exit 1;
  47. }
  48. arglist: while (@ARGV) {
  49. if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
  50. $ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
  51. $ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
  52. print "test-installation (GNU $PACKAGE)\n";
  53. print "Copyright (C) 2026 Free Software Foundation, Inc.\n";
  54. print "This is free software; see the source for copying conditions. There is NO\n";
  55. print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
  56. print "Written by Andreas Jaeger <aj\@arthur.rhein-neckar.de>\n";
  57. exit 0;
  58. } elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
  59. $ARGV[0] eq "--help") {
  60. &usage;
  61. } elsif ($ARGV[0] =~ /^-/) {
  62. print "$progname: unrecognized option `$ARGV[0]'\n";
  63. print "Try `$progname --help' for more information.\n";
  64. exit 1;
  65. } else {
  66. last arglist;
  67. }
  68. }
  69. # We expect none or one argument.
  70. if ($#ARGV == -1) {
  71. $dir = ".";
  72. $soversions="soversions.mk";
  73. $config="config.make";
  74. } elsif ($#ARGV == 0) {
  75. if (-d $ARGV[0]) {
  76. $dir = $ARGV[0];
  77. $soversions = "$ARGV[0]/soversions.mk";
  78. $config = "$ARGV[0]/config.make";
  79. } else {
  80. $soversions = $dir = $ARGV[0];
  81. $dir =~ s!/?[^/]*/*$!!;
  82. $config = $dir . "/config.make";
  83. }
  84. } else {
  85. die "Wrong number of arguments.";
  86. }
  87. if (system ("grep -q \"build-mathvec = yes\" $config") == 0) {
  88. $build_mathvec = 1;
  89. } else {
  90. $build_mathvec = 0;
  91. }
  92. # Read names and versions of all shared libraries that are part of
  93. # glibc
  94. open SOVERSIONS, $soversions
  95. or die ("Couldn't open $soversions in build directory!");
  96. $link_libs = "";
  97. %versions = ();
  98. while (<SOVERSIONS>) {
  99. next if (/^all-sonames/);
  100. chop;
  101. if (/^lib/) {
  102. ($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
  103. # Filter out some libraries we don't want to link:
  104. # - nss_ldap since it's not yet available
  105. # - libdb1 since it conflicts with libdb
  106. # - libthread_db since it contains unresolved references
  107. # - it's just a test NSS module
  108. # - We don't provide the libgcc so we don't test it
  109. # - libmvec if it wasn't built
  110. next if ($build_mathvec == 0 && $name eq "mvec");
  111. if ($name ne "nss_ldap" && $name ne "db1"
  112. && $name ne "thread_db"
  113. && $name ne "nss_test1" && $name ne "libgcc_s") {
  114. $link_libs .= " -l$name";
  115. $versions{$name} = $version;
  116. }
  117. } elsif ($LD_SO ne "") {
  118. ($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO);
  119. } else {
  120. if (/^ld\.so/) {
  121. ($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
  122. }
  123. }
  124. }
  125. close SOVERSIONS;
  126. # Create test program and link it against all
  127. # shared libraries
  128. open PRG, ">$dir/test-prg$$.c"
  129. or die ("Couldn't write test file $dir/test-prg$$.c");
  130. print PRG '
  131. #include <stdio.h>
  132. #include <stdlib.h>
  133. int main(void) {
  134. printf ("Your new glibc installation seems to be ok.\n");
  135. exit (0);
  136. }
  137. ';
  138. close PRG;
  139. open GCC, "$CC $dir/test-prg$$.c $link_libs -o $dir/test-prg$$ 2>&1 |"
  140. or die ("Couldn't execute $CC!");
  141. while (<GCC>) {
  142. print $_ if (! /warning/);
  143. }
  144. close GCC;
  145. if ($?) {
  146. print "Execution of $CC failed!\n";
  147. &installation_problem;
  148. }
  149. # Test if test program is linked against the right versions of
  150. # shared libraries
  151. $ok = 1;
  152. %found = ();
  153. open LDD, "ldd $dir/test-prg$$ |"
  154. or die ("Couldn't execute ldd");
  155. while (<LDD>) {
  156. if (/^\s*lib/) {
  157. ($name, $version1, $version2) =
  158. /^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
  159. $found{$name} = 1;
  160. if ($versions{$name} ne $version1 || $version1 ne $version2) {
  161. print "Library lib$name is not correctly installed.\n";
  162. print "Please check your installation!\n";
  163. print "Offending line of ldd output: $_\n";
  164. $ok = 0;
  165. }
  166. }
  167. if (/$ld_so_name/) {
  168. ($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
  169. if ($version1 ne $ld_so_version) {
  170. print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
  171. print "Please check your installation!\n";
  172. print "Offending line of ldd output: $_\n";
  173. $ok = 0;
  174. }
  175. }
  176. }
  177. close LDD;
  178. die "ldd execution failed" if $?;
  179. foreach (keys %versions) {
  180. unless ($found{$_}) {
  181. print "Library lib$_ is not correctly installed since the test program\n";
  182. print "was not linked dynamically against it.\n";
  183. print "Do you have a file/link lib$_.so?\n";
  184. $ok = 0;
  185. }
  186. }
  187. &installation_problem unless $ok;
  188. # Finally execute the test program
  189. system ("$dir/test-prg$$") == 0
  190. or die ("Execution of test program failed");
  191. # Clean up after ourselves
  192. unlink ("$dir/test-prg$$", "$dir/test-prg$$.c");