export control for darwin, as committed

Geoffrey Keating gkeating@apple.com
Wed Jul 27 18:26:00 GMT 2005


This is the version I'm actually committing, it has two changes from
the previous version:
- doc patch as suggested by jsm, to mention use of perl
- testing on linux revealed I'd forgotten a 'test', causing the 'yes'
  program to be run

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/libstdc++-darwinexport-1.patch============
Index: gcc/ChangeLog
2005-07-25  Geoffrey Keating  <geoffk@apple.com>

	* doc/install.texi (Prerequisites): Mention that perl is needed
	to do export control in libstdc++ targetting Darwin.

Index: libstdc++-v3/ChangeLog
2005-07-25  Geoffrey Keating  <geoffk@apple.com>

	* acinclude.m4 (GLIBCXX_ENABLE_SYMVERS): Handle darwin-export,
	and make it the default for Darwin.
	* scripts/make-exports.pl: New.
	* src/Makefile.am: Update for changes to GLIBCXX_ENABLE_SYMVERS.
	Handle darwin-export.
	* configure: Regenerate.
	* include/Makefile.in: Regenerate.
	* libmath/Makefile.in: Regenerate.
	* libsupc++/Makefile.in: Regenerate.
	* po/Makefile.in: Regenerate.
	* src/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.

Index: gcc/doc/install.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.363
diff -u -p -u -p -r1.363 install.texi
--- gcc/doc/install.texi	26 Jul 2005 15:56:54 -0000	1.363
+++ gcc/doc/install.texi	27 Jul 2005 18:22:28 -0000
@@ -398,6 +398,8 @@ snapshots of the development sources are
 Necessary when regenerating @file{Makefile} dependencies in libiberty.
 Necessary when regenerating @file{libiberty/functions.texi}.
 Necessary when generating manpages from Texinfo manuals.
+Necessary when targetting Darwin, building libstdc++,
+and not using @option{--disable-symvers}.
 Used by various scripts to generate some files included in CVS (mainly
 Unicode-related and rarely changing) from source tables.
 
Index: libstdc++-v3/acinclude.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acinclude.m4,v
retrieving revision 1.320
diff -u -p -u -p -r1.320 acinclude.m4
--- libstdc++-v3/acinclude.m4	28 Jun 2005 19:51:38 -0000	1.320
+++ libstdc++-v3/acinclude.m4	27 Jul 2005 18:22:28 -0000
@@ -1671,16 +1671,30 @@ AC_DEFUN([GLIBCXX_ENABLE_SYMVERS], [
 
 GLIBCXX_ENABLE(symvers,$1,[=STYLE],
   [enables symbol versioning of the shared library],
-  [permit yes|no|gnu])
+  [permit yes|no|gnu|darwin-export])
 
 # If we never went through the GLIBCXX_CHECK_LINKER_FEATURES macro, then we
 # don't know enough about $LD to do tricks...
 AC_REQUIRE([GLIBCXX_CHECK_LINKER_FEATURES])
-# FIXME  The following test is too strict, in theory.
-if test $enable_shared = no ||
-        test "x$LD" = x ||
-        test x$glibcxx_gnu_ld_version = x; then
-  enable_symvers=no
+
+# Turn a 'yes' into a suitable default.
+if test x$enable_symvers = xyes ; then
+  if test $enable_shared = no ||
+     test "x$LD" = x ; then
+    enable_symvers=no
+  elif test $with_gnu_ld == yes ; then
+    enable_symvers=gnu
+  else
+    case ${target_os} in
+      darwin*)
+	enable_symvers=darwin-export ;;
+      *)
+      AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
+      AC_MSG_WARN([=== you are not using a supported linker.])
+      AC_MSG_WARN([=== Symbol versioning will be disabled.])
+	enable_symvers=no ;;
+    esac
+  fi
 fi
 
 # Check to see if libgcc_s exists, indicating that shared libgcc is possible.
@@ -1710,39 +1724,34 @@ changequote([,])dnl
   AC_MSG_RESULT($glibcxx_shared_libgcc)
 fi
 
-# For GNU ld, we need at least this version.  The format is described in
-# GLIBCXX_CHECK_LINKER_FEATURES above.
-glibcxx_min_gnu_ld_version=21400
-
-# Check to see if unspecified "yes" value can win, given results above.
-# Change "yes" into either "no" or a style name.
-if test $enable_symvers = yes; then
-  if test $with_gnu_ld = yes &&
-     test $glibcxx_shared_libgcc = yes;
-  then
-    if test $glibcxx_gnu_ld_version -ge $glibcxx_min_gnu_ld_version ; then
-      enable_symvers=gnu
-    else
-      # The right tools, the right setup, but too old.  Fallbacks?
-      AC_MSG_WARN(=== Linker version $glibcxx_gnu_ld_version is too old for)
-      AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
-      AC_MSG_WARN(=== You would need to upgrade your binutils to version)
-      AC_MSG_WARN(=== $glibcxx_min_gnu_ld_version or later and rebuild GCC.)
-      if test $glibcxx_gnu_ld_version -ge 21200 ; then
-        # Globbing fix is present, proper block support is not.
-        AC_MSG_WARN([=== Symbol versioning will be disabled.])
-        enable_symvers=no
-      else
-        # 2.11 or older.
-        AC_MSG_WARN([=== Symbol versioning will be disabled.])
-        enable_symvers=no
-      fi
-    fi
-  else
-    # just fail for now
+# If no shared libgcc, can't win.
+if test $glibcxx_shared_libgcc != yes &&
+   test $enable_symvers != no ; then
     AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
-    AC_MSG_WARN([=== either you are not using a supported linker, or you are])
-    AC_MSG_WARN([=== not building a shared libgcc_s (which is required).])
+    AC_MSG_WARN([=== you are not building a shared libgcc_s.])
+    AC_MSG_WARN([=== Symbol versioning will be disabled.])
+    enable_symvers=no
+  enable_symvers=no
+fi
+
+# Check to see if 'gnu' can win.
+if test $enable_symvers = gnu; then
+  # For GNU ld, we need at least this version.  The format is described in
+  # GLIBCXX_CHECK_LINKER_FEATURES above.
+  glibcxx_min_gnu_ld_version=21400
+
+  if test $with_gnu_ld != yes ; then
+    # just fail for now
+    AC_MSG_WARN([=== You have requested GNU symbol versioning, but])
+    AC_MSG_WARN([=== you are not using the GNU linker.])
+    AC_MSG_WARN([=== Symbol versioning will be disabled.])
+    enable_symvers=no
+  elif test $glibcxx_gnu_ld_version -lt $glibcxx_min_gnu_ld_version ; then
+    # The right tools, the right setup, but too old.  Fallbacks?
+    AC_MSG_WARN(=== Linker version $glibcxx_gnu_ld_version is too old for)
+    AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
+    AC_MSG_WARN(=== You would need to upgrade your binutils to version)
+    AC_MSG_WARN(=== $glibcxx_min_gnu_ld_version or later and rebuild GCC.)
     AC_MSG_WARN([=== Symbol versioning will be disabled.])
     enable_symvers=no
   fi
@@ -1756,7 +1765,10 @@ case $enable_symvers in
   gnu)
     SYMVER_MAP=config/linker-map.gnu
     AC_DEFINE(_GLIBCXX_SYMVER, 1, 
-              [Define to use symbol versioning in the shared library.])
+              [Define to use GNU symbol versioning in the shared library.])
+    ;;
+  darwin-export)
+    SYMVER_MAP=config/linker-map.gnu
     ;;
 esac
 
@@ -1787,7 +1799,9 @@ AC_MSG_RESULT([$glibcxx_ptrdiff_t_is_i])
 
 AC_SUBST(SYMVER_MAP)
 AC_SUBST(port_specific_symbol_files)
-GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
+GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_GNU, test $enable_symvers == gnu)
+GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_DARWIN_EXPORT, dnl
+  test $enable_symvers == darwin-export)
 AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)
 ])
 
Index: libstdc++-v3/scripts/make_exports.pl
===================================================================
RCS file: libstdc++-v3/scripts/make_exports.pl
diff -N libstdc++-v3/scripts/make_exports.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libstdc++-v3/scripts/make_exports.pl	27 Jul 2005 18:22:38 -0000
@@ -0,0 +1,144 @@
+#!/usr/bin/perl -w
+
+# This script takes two arguments, a version script and a dynamic library
+# (in that order), and prints a list of symbols to be exported from the
+# library.
+# It expects a 'nm' with the POSIX '-P' option, but everyone has one of
+# those, right?  It also expects that symbol names have a leading underscore,
+# which is somewhat less likely.
+
+use File::Glob ':glob';
+use FileHandle;
+use IPC::Open2;
+
+# The glob patterns that are to be applied to the demangled name
+my @cxx_globs = ();
+# The glob patterns that apply directly to the name in the .o files
+my @globs = ();
+# The patterns for local variables (usually just '*').
+my @ignored = ();
+
+##########
+# Fill in the various glob arrays.
+
+# The next pattern will go into this array.
+my $glob = \@globs;
+my $symvers = shift;
+
+open F,$symvers or die $!;
+
+while (<F>) {
+    chomp;
+    # Lines of the form '} SOME_VERSION_NAME_1.0;'
+    if (/^[ \t]*\}[ \tA-Z0-9_.a-z]*;[ \t]*$/) {
+      $glob = \@globs;
+      next;
+    }
+    # Comment and blank lines
+    next if (/^[ \t]*\#/);
+    next if (/^[ \t]*$/);
+    # Lines of the form 'SOME_VERSION_NAME_1.1 {'
+    next if (/^[A-Z0-9_. \t]*{$/);
+    # Ignore 'global:'
+    next if (/^[ \t]*global:$/);
+    # After 'local:', globs should be ignored, they won't be exported.
+    if (/^[ \t]*local:$/) {
+	$glob = \@ignored;
+	next;
+    }
+    # After 'extern "C++"', globs are C++ patterns
+    if (/^[ \t]*extern \"C\+\+\"[ \t]*$/) {
+	$glob = \@cxx_globs;
+	next;
+    }
+    # Catch globs.  Note that '{}' is not allowed in globs by this script,
+    # so only '*' and '[]' are available.
+    if (/^[ \t]*([^ \t;{}#]+);?[ \t]*$/) {
+	my $ptn = $1;
+	# Turn the glob into a regex by replacing '*' with '.*'.
+	$ptn =~ s/\*/\.\*/g;
+	push @$glob,$ptn;
+	next;
+    }
+    # Important sanity check.  This script can't handle lots of formats
+    # that GNU ld can, so be sure to error out if one is seen!
+    die "strange line `$_'";
+}
+close F;
+
+# Make 'if (1)' for debugging.
+if (0) {
+    print "cxx:\n";
+    (printf "%s\n",$_) foreach (@cxx_globs);
+    print "globs:\n";
+    (printf "%s\n", $_) foreach (@globs);
+    print "ignored:\n";
+    (printf "%s\n", $_) foreach (@ignored);
+}
+
+##########
+# Combine the arrays into single regular expressions
+# This cuts the time required from about 30 seconds to about 0.5 seconds.
+
+my $glob_regex = '^_(' . (join '|',@globs) . ')$';
+my $cxx_regex = (join '|',@cxx_globs);
+
+##########
+# Get all the symbols from the library, match them, and add them to a hash.
+
+my %export_hash = ();
+
+# Process each symbol.
+print STDERR 'nm -P '.(join ' ',@ARGV).'|';
+open NM,'nm -P '.(join ' ',@ARGV).'|' or die $!;
+# Talk to c++filt through a pair of file descriptors.
+open2(*FILTIN, *FILTOUT, "c++filt") or die $!;
+NAME: while (<NM>) {
+    my $i;
+    chomp;
+
+    # nm prints out stuff at the start, ignore it.
+    next if (/^$/);
+    next if (/:$/);
+    # Ignore undefined and local symbols.
+    next if (/^([^ ]+) [Ua-z] /);
+
+    # $sym is the name of the symbol, $noeh_sym is the same thing with
+    # any '.eh' suffix removed.
+    die "unknown nm output $_" if (! /^([^ ]+) [A-Z] /);
+    my $sym = $1;
+    my $noeh_sym = $sym;
+    $noeh_sym =~ s/\.eh$//;
+
+    # Maybe it matches one of the patterns based on the symbol in the .o file.
+    if ($noeh_sym =~ /$glob_regex/) {
+        $export_hash{$sym} = 1;
+	next NAME;
+    }
+
+    # No?  Well, maybe its demangled form matches one of those patterns.
+    printf FILTOUT "%s\n",$noeh_sym;
+    my $dem = <FILTIN>;
+    chomp $dem;
+    if ($dem =~ /$cxx_regex/) {
+        $export_hash{$sym} = 2;
+	next NAME;
+    }
+
+    # No?  Well, then ignore it.
+}
+close NM or die "nm error";
+close FILTOUT or die "c++filt error";
+close FILTIN or die "c++filt error";
+
+##########
+# Print out the export file
+
+# Print information about generating this file
+print "# This is a generated file.\n";
+print "# It was generated by:\n";
+printf "# %s %s %s\n", $0, $symvers, (join ' ',@ARGV);
+
+foreach my $i (keys %export_hash) {
+  printf "%s\n",$i or die;
+}
Index: libstdc++-v3/src/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.149
diff -u -p -u -p -r1.149 Makefile.am
--- libstdc++-v3/src/Makefile.am	17 Jun 2005 07:33:53 -0000	1.149
+++ libstdc++-v3/src/Makefile.am	27 Jul 2005 18:22:38 -0000
@@ -28,7 +28,7 @@ include $(top_srcdir)/fragment.am
 toolexeclib_LTLIBRARIES = libstdc++.la
 
 # Symbol versioning for shared libraries.
-if GLIBCXX_BUILD_VERSIONED_SHLIB
+if ENABLE_SYMVERS_GNU
 version_arg = -Wl,--version-script=libstdc++-symbol.ver
 version_dep = libstdc++-symbol.ver
 libstdc++-symbol.ver:  ${glibcxx_srcdir}/$(SYMVER_MAP)
@@ -40,9 +40,23 @@ libstdc++-symbol.ver:  ${glibcxx_srcdir}
 	  rm tmp.top tmp.bottom; \
 	fi
 else
+if ENABLE_SYMVERS_DARWIN_EXPORT
+version_arg = -Wl,-exported_symbols_list,libstdc++-symbol.explist
+version_dep = libstdc++-symbol.explist
+libstdc++-symbol.explist : ${glibcxx_srcdir}/$(SYMVER_MAP) \
+		${glibcxx_srcdir}/scripts/make_exports.pl \
+		$(libstdc___la_OBJECTS) $(libstdc___la_LIBADD)
+	perl ${glibcxx_srcdir}/scripts/make_exports.pl \
+	  ${glibcxx_srcdir}/$(SYMVER_MAP) \
+	  $(libstdc___la_OBJECTS:%.lo=.libs/%.o) \
+	 `echo $(libstdc___la_LIBADD) | \
+	    sed 's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
+	 > $@ || (rm -f $@ ; exit 1)
+else
 version_arg =
 version_dep =
 endif
+endif
 
 
 # Source files linked in via configuration/make substitution for a
============================================================



More information about the Gcc-patches mailing list