develooper Front page | perl.perl5.porters | Postings from September 2010

[PATCH] Only export the public symbols in shared libperls

Thread Next
From:
Florian Ragwitz
Date:
September 2, 2010 12:50
Subject:
[PATCH] Only export the public symbols in shared libperls
Message ID:
1283456979-8124-1-git-send-email-rafl@debian.org
Only works on ELF platforms, and does require a linker that understands
--version-script. That's probably GNU ld only.
---
 .gitignore                |    2 ++
 Makefile.SH               |   18 +++++++++++++++++-
 Porting/bump-perl-version |    6 ++++++
 makedef.pl                |   28 +++++++++++++++++++++-------
 4 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index adf8b97..0ce9676 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,6 +63,8 @@ bug*.pl
 *.gcda
 *.gcno
 
+libperl.version
+
 dll.base
 /ext/DynaLoader/dl_win32.xs
 splittree.pl
diff --git a/Makefile.SH b/Makefile.SH
index 5948f4d..d932179 100755
--- a/Makefile.SH
+++ b/Makefile.SH
@@ -722,6 +722,22 @@ $(LIBPERL_NONSHR): $(obj)
 
 !NO!SUBS!
 	;;
+*)
+        # ELF platforms with GNU linker
+        if [ "$bin_ELF" = 'define' -a "$gccversion" != '' ]; then
+            case "$useshrplib" in
+            define|true|[yY]*)
+		    $spitshell >>$Makefile <<'!NO!SUBS!'
+LIBPERLLDSCRIPT = libperl.version
+SHRPLDFLAGS += -Wl,--version-script=$(LIBPERLLDSCRIPT)
+
+libperl.version: $(MINIPERL_EXE) makedef.pl config.sh $(SYM) $(SYMH) $(CONFIGPM)
+	$(MINIPERL) makedef.pl PLATFORM=gnuelf CC_FLAGS="$(OPTIMIZE)" > $@
+
+!NO!SUBS!
+		    ;;
+            esac
+        fi
 esac
 
 if test -s $Makefile_s ; then
@@ -752,7 +768,7 @@ $(DTRACE_O): perldtrace.d
 		;;
     esac
 	$spitshell >>$Makefile <<'!NO!SUBS!'
-$(LIBPERL): $& $(obj) $(DYNALOADER) $(LIBPERLEXPORT)
+$(LIBPERL): $& $(obj) $(DYNALOADER) $(LIBPERLEXPORT) $(LIBPERLLDSCRIPT)
 !NO!SUBS!
 	case "$useshrplib" in
 	true)
diff --git a/Porting/bump-perl-version b/Porting/bump-perl-version
index e478cf0..3a9f052 100644
--- a/Porting/bump-perl-version
+++ b/Porting/bump-perl-version
@@ -105,6 +105,12 @@ my $old_decimal = sprintf "%d.%03d%03d", $oldx, $oldy, $oldz; # 5.011001
 
 my @maps =  (
     [
+        qr{\b (LIBPERL_) ([\d.]+) (\s+ \{)}x,
+        sub { $2, ($newy % 2) ? "$1$newx.$newy.$newz$3" : "$1$newx.$newy$3" },
+        ($oldy % 2) ? "$oldx.$oldy.$oldz" : "$oldx.$oldy",
+        qr/makedef/,
+    ],
+    [
 	qr{^((?:api_)?version(?:=|\s+)'?) (\d+) ('?) (?!\.)}x,
 	sub { $2, "$1$newy$3" },
 	$oldy,
diff --git a/makedef.pl b/makedef.pl
index 810a4c8..a2285f7 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -59,7 +59,7 @@ while (@ARGV) {
     }
 }
 
-my @PLATFORM = qw(aix win32 wince os2 MacOS netware);
+my @PLATFORM = qw(aix win32 wince os2 MacOS netware gnuelf);
 my %PLATFORM;
 @PLATFORM{@PLATFORM} = ();
 
@@ -255,6 +255,10 @@ elsif ($PLATFORM eq 'netware') {
 	    output_symbol("perl_clone_host");
 	}
 }
+elsif ($PLATFORM eq 'gnuelf') {
+    print "LIBPERL_5.13.3 {\n";
+    print "  global:\n";
+}
 
 my %skip;
 my %export;
@@ -621,6 +625,11 @@ elsif ($PLATFORM eq 'netware') {
 			PerlIO_perlio
 			)];
 }
+elsif ($PLATFORM eq 'gnuelf') {
+	emit_symbols [qw(
+		boot_DynaLoader
+	)];
+}
 
 unless ($define{'DEBUGGING'}) {
     skip_symbols [qw(
@@ -1226,15 +1235,14 @@ if ($define{'MULTIPLICITY'}) {
 	my $glob = readvar($f, sub { "Perl_" . $_[1] . $_[2] . "_ptr" });
 	emit_symbols $glob;
     }
-    unless ($define{'USE_ITHREADS'}) {
-	# XXX needed for XS extensions that define PERL_CORE
-	emit_symbol("PL_curinterp");
-    }
-    # XXX AIX seems to want the perlvars.h symbols, for some reason
-    if ($PLATFORM eq 'aix' or $PLATFORM eq 'os2') {	# OS/2 needs PL_thr_key
+    if ($define{'USE_ITHREADS'}) {
 	my $glob = readvar($perlvars_h);
 	emit_symbols $glob;
     }
+    else {
+	# XXX needed for XS extensions that define PERL_CORE
+	emit_symbol("PL_curinterp");
+    }
 }
 else {
     unless ($define{'PERL_GLOBAL_STRUCT'}) {
@@ -1622,6 +1630,9 @@ if ($PLATFORM eq 'os2') {
 ; LAST_ORDINAL=$sym_ord
 EOP
 }
+elsif ($PLATFORM eq 'gnuelf') {
+    print "\n  local: *;\n};\n";
+}
 
 sub emit_symbol {
     my $symbol = shift;
@@ -1670,6 +1681,9 @@ sub output_symbol {
 	elsif ($PLATFORM eq 'netware') {
 	print "\t$symbol,\n";
 	}
+    elsif ($PLATFORM eq 'gnuelf') {
+        print "    $symbol;\n";
+    }
 }
 
 1;
-- 
1.7.1


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About