This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libstdc++] Factor out symbol extraction from abi_check, sort in C locale


After I experienced increasing weirdness with the system() calls in
abi_check.cc, Loren suggested pulling that part back out into a shell
script, and I highly agree.  This incorporates the sorting fix, that we
use the C locale rather than en_US or whatever happens to be in effect.

Checking this in will not require regenerating the baseline files, since
the fact that the files are sorted currently doesn't matter to abi_check
(yet) or anything else (yet).

I'm still trying to think of a way to merge baseline files.  Jakub's given
lots of good suggestions.

The presence of "../src/.libs/libstdc++.so" in the top Makefile is ugly;
a more automated way to get this string would be nice.

The new-abi-baseline rule is just barely useful for now.  It's mostly
there to let us play with new formats for baseline files.

Tested x86/linux.  I'll check this into trunk tomorrow sometime, and
will wait a few days for the branch.


2002-09-13  Phil Edwards  <pme@gcc.gnu.org>

	* testsuite/abi_check.cc:  Pull shell fragments out into...
	* config/abi/extract_syms:  ...here.  New file.
	* Makefile.am (check_abi):  Change to match.
	(new-abi-baseline):  New target.
	* Makefile.in:  Regenerated.


Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/Makefile.am,v
retrieving revision 1.33
diff -u -3 -p -r1.33 Makefile.am
--- Makefile.am	23 Aug 2002 19:33:37 -0000	1.33
+++ Makefile.am	14 Sep 2002 02:44:17 -0000
@@ -46,10 +46,25 @@ check-script-install: $(top_builddir)/mk
 	  cd testsuite; \
 	  @glibcpp_builddir@/mkcheck 1)
 
+# Use 'new-abi-baseline' to create an initial symbol file.  Then run
+# 'check-abi' to test for changes against that file.
 baseline_file = @baseline_file@
 check-abi: $(top_builddir)/testsuite/abi_check
 	-(cd testsuite; \
-	  ./abi_check ${baseline_file})
+	  ${top_srcdir}/config/abi/extract_syms \
+	     ../src/.libs/libstdc++.so \
+	     ./current_symbols.txt; \
+	  ./abi_check --check ./current_symbols.txt ${baseline_file})
+
+new-abi-baseline:
+	-@(output=${baseline_file}; \
+	  if test -f $${output}; then \
+	    output=$${output}.new; \
+	    t=`echo $${output} | sed 's=.*config/abi/=='`; \
+	    echo "Baseline file already exists, writing to $${t} instead."; \
+	  fi; \
+	  ${top_srcdir}/config/abi/extract_syms \
+	     src/.libs/libstdc++.so $${output})
 
 # These rules are messy, but are hella worth it.
 doxygen:
Index: config/abi/extract_syms
===================================================================
RCS file: config/abi/extract_syms
diff -N config/abi/extract_syms
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/abi/extract_syms	14 Sep 2002 02:44:17 -0000
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# Copyright (C) 2002 Free Software Foundation, Inc.
+#
+# This file is part of the GNU ISO C++ Library.  This library is free
+# software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this library; see the file COPYING.  If not, write to the Free
+# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+# As a special exception, you may use this file as part of a free software
+# library without restriction.  Specifically, if other files instantiate
+# templates or use macros or inline functions from this file, or you compile
+# this file and link it with other files to produce an executable, this
+# file does not by itself cause the resulting executable to be covered by
+# the GNU General Public License.  This exception does not however
+# invalidate any other reasons why the executable file might be covered by
+# the GNU General Public License.
+
+
+if test ${#} -lt 2 || test $1 = '--help'; then
+  echo "Usage:  extract_syms  shared_lib output_file" 1>&2
+  exit 1
+fi
+
+lib=$1
+output=$2
+
+# GNU binutils, somewhere after version 2.11.2, requires -W/--wide to avoid
+# default line truncation.  -W is not supported and truncation did not occur
+# by default before that point.
+readelf="readelf --symbols"
+if readelf --help | grep -- --wide > /dev/null; then
+    readelf="$readelf --wide"
+fi
+
+# This avoids weird sorting problems later.
+export LC_ALL=C
+
+tmp=extract.$$
+
+${readelf} ${lib} | sed '/\.dynsym/,/^$/p;d' | egrep -v ' (LOCAL|UND) ' |\
+awk '{ if ($4 == "FUNC" || $4 == "NOTYPE")
+         printf "%s:%s\n", $4, $8;
+       else if ($4 == "OBJECT")
+         printf "%s:%s:%s\n", $4, $3, $8;
+     }' | sort | uniq > $tmp 2>&1
+#       else printf "Huh?  What is %s?\n", $8;
+
+
+# I think we'll be doing some more with this file, but for now, dump.
+mv $tmp $output
+
+exit 0
Index: testsuite/abi_check.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/abi_check.cc,v
retrieving revision 1.6
diff -u -3 -p -r1.6 abi_check.cc
--- testsuite/abi_check.cc	9 Sep 2002 20:26:42 -0000	1.6
+++ testsuite/abi_check.cc	14 Sep 2002 02:44:17 -0000
@@ -28,6 +28,8 @@
 // the GNU General Public License.
 
 // Benjamin Kosnik  <bkoz@redhat.com>
+// Blame subsequent hacks on Loren J. Rittle <ljrittle@acm.org>, Phil
+// Edwards <pme@gcc.gnu.org>, and a cast of dozens at libstdc++@gcc.gnu.org.
 
 #include <string>
 #include <ext/hash_map>
@@ -259,63 +261,39 @@ report_symbol_info(const symbol_info& sy
   cout << endl;
 }
 
-int main(int argc, char** argv)
+
+int
+main(int argc, char** argv)
 {
   using namespace std;
 
-  // Get arguments.
-  if (argc != 2)
-    {
-      cerr << "Usage:  abi_check baseline_file" << endl;
+  // Get arguments.  (Heading towards getopt_long, I can feel it.)
+  string argv1;
+  if (argc < 4 || (string("--help") == (argv1 = argv[1])))
+    {
+      cerr << "Usage:  abi_check --check   current_syms_file baseline_file\n"
+              "                  --help\n\n"
+	   << endl;
       exit(1);
     }
-  const char* baseline_file = argv[1];
-  const char* test_file = "current_symbols.txt";
-  const char* test_lib = "../src/.libs/libstdc++.so";
+
+  const char* test_file = argv[2];
+  const char* baseline_file = argv[3];
 
   // Quick sanity/setup check
-  if (access(baseline_file, R_OK) != 0)
-    {
-      cerr << "Cannot read baseline file " << baseline_file << endl;
-      exit(1);
-    }
-  if (access(test_lib, R_OK) != 0)
+  if (access(test_file, R_OK) != 0)
     {
-      cerr << "Cannot read library " << test_lib
+      cerr << "Cannot read symbols file " << test_file
            << ", did you forget to build first?" << endl;
       exit(1);
     }
-
-  // Get list of symbols.
-  // Assume external symbol list computed "as if" by
-  /*
-   readelf -s -W libstdc++.so | sed '/\.dynsym/,/^$/p;d' | egrep -v
-   ' (LOCAL|UND) ' | awk '{ if ($4 == "FUNC" || $4 == "NOTYPE") printf
-   "%s:%s\n", $4, $8; else if ($4 == "OBJECT") printf "%s:%s:%s\n", $4,
-   $3, $8;}' | sort >& current_symbols.txt
-   */
-
-  // GNU binutils, somewhere after version 2.11.2, requires -W/--wide
-  // to avoid default line truncation.  -W is not supported and
-  // truncation did not occur by default before that point.
-  bool readelf_need_wide =
-    (system("readelf --help | grep -- --wide >/dev/null") == 0);
-
-  ostringstream cmd;
-  cmd << "readelf -s " << (readelf_need_wide ? "-W " : "") << test_lib
-      << " | sed '/\\.dynsym/,/^$/p;d' | egrep -v ' (LOCAL|UND) ' | "
-         "awk '{ if ($4 == \"FUNC\" || $4 == \"NOTYPE\") "
-                   "printf \"%s:%s\\n\", $4, $8; "
-                 "else if ($4 == \"OBJECT\") "
-                   "printf \"%s:%s:%s\\n\", $4, $3, $8;}' | sort > "
-      << test_file << " 2>&1";
-  if (system(cmd.str().c_str()) != 0)
+  if (access(baseline_file, R_OK) != 0)
     {
-      cerr << "Unable to generate the list of exported symbols." << endl;
-      exit(2);
+      cerr << "Cannot read baseline file " << baseline_file << endl;
+      exit(1);
     }
 
-  // Input both list of symbols into container.
+  // Input both lists of symbols into container.
   symbol_infos  baseline_symbols;
   symbol_names  baseline_names;
   symbol_infos  test_symbols;
@@ -323,7 +301,7 @@ int main(int argc, char** argv)
   create_symbol_data(baseline_file, baseline_symbols, baseline_names);
   create_symbol_data(test_file, test_symbols, test_names);
 
-  // Basic sanity check. (Was: error checking, what's that?)
+  // More sanity checking.
   const symbol_names::size_type baseline_size = baseline_names.size();
   const symbol_names::size_type test_size = test_names.size();
   if (!baseline_size || !test_size)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]