about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog60
-rw-r--r--Makeconfig33
-rw-r--r--Makefile4
-rw-r--r--Makerules32
-rw-r--r--Rules6
-rw-r--r--dlfcn/dlfcn.c12
-rw-r--r--fedora/branch.mk4
-rw-r--r--include/libc-symbols.h3
-rw-r--r--linuxthreads/ChangeLog5
-rw-r--r--linuxthreads/descr.h4
-rw-r--r--scripts/lib-names.awk66
-rw-r--r--scripts/soversions.awk58
-rw-r--r--shlib-versions15
-rw-r--r--stdlib/Makefile6
-rw-r--r--stdlib/random_r.c11
-rw-r--r--stdlib/tst-random2.c59
-rw-r--r--sysdeps/powerpc/bits/link.h (renamed from sysdeps/powerpc/powerpc64/bits/link.h)3
-rw-r--r--sysdeps/powerpc/powerpc32/bits/link.h62
18 files changed, 307 insertions, 136 deletions
diff --git a/ChangeLog b/ChangeLog
index a79fdbe8a4..f37011feb1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,63 @@
+2005-02-10  Roland McGrath  <roland@redhat.com>
+
+	[BZ #157]
+	* include/libc-symbols.h (stub_warning): Emit a marker section called
+	.gnu.glibc-stub.NAME.
+	* Makerules ($(objpfx)stubs): Depend on object files, not dep files.
+	Use objdump to collect those marker section names.
+	($(common-objpfx)shlib.lds): Discard .gnu.glibc-stub.* sections.
+
+	* Rules (subdir_objs, subdir_stubs): New phony targets.
+	* Makefile (+subdir_targets): Add them.
+
+	* Makerules ($(common-objpfx)Versions.all): Grok new leading column in
+	soversions.i.
+
+	* scripts/lib-names.awk: Consider [0-9].* a "number", not just [0-9]+.
+	Reported by H.J. Lu <hongjiu.lu@intel.com>.
+
+	* scripts/lib-names.awk: Always print WORDSIZE32 section first when
+	doing two.
+
+2005-02-10  Jakub Jelinek  <jakub@redhat.com>
+
+	* sysdeps/powerpc/powerpc32/bits/link.h: Removed.
+	* sysdeps/powerpc/powerpc64/bits/link.h: Moved to...
+	* sysdeps/powerpc/bits/link.h: ... here.  New file.
+
+2005-02-09  Jakub Jelinek  <jakub@redhat.com>
+
+	[BZ #710]
+	* stdlib/random_r.c (__initstate_r): Save old state.
+	* stdlib/Makefile (tests): Add tst-random2.
+	* stdlib/tst-random2.c: New test.
+	Reported by Peter Bergner <bergner@vnet.ibm.com>.
+
+2005-01-25  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* dlfcn/dlfcn.c (init): Put it in .init_array section.
+
+2005-02-10  Roland McGrath  <roland@redhat.com>
+
+	[BZ #632]
+	* scripts/soversions.awk: Expect cpu, vendor, os as separate variables
+	from command line.
+	Grok shlib-versions lines with WORDSIZE* in second column.
+	Add new leading column to output, DEFAULT for existing output lines.
+	Also emit lines with WORDSIZE* for alternate configurations.
+	* Makeconfig ($(common-objpfx)soversions.i): Pass those variables.
+	($(common-objpfx)soversions.mk): Grok new column, use only DEFAULT.
+	($(common-objpfx)gnu/lib-names.stmp): Depend on soversions.i instead
+	of soversions.mk; replace inline shell script with use of ...
+	* scripts/lib-names.awk: New file.  If input has non-DEFAULT lines,
+	emit multiple sets of macros under #if.
+	* shlib-versions (x86_64-.*-.*): Add WORDSIZE32 line mapping to i686.
+	(s390x-.*-.*): Likewise for s390.
+	(powerpc64-.*-.*): Likewise for powerpc.
+	(sparc64-.*-.*): Likewise for sparc.
+	(s390-.*-.*, powerpc.*-.*-.*, sparc.*-.*-.*): Add WORDSIZE64 entries
+	for these mapping back to the above.
+
 2005-02-08  Jakub Jelinek  <jakub@redhat.com>
 
 	* elf/dl-load.c (_dl_map_object_from_fd): Fix a typo.
diff --git a/Makeconfig b/Makeconfig
index 5ecda01169..306053241d 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -787,11 +787,14 @@ soversions-default-setname = $(patsubst %, %,\
 $(common-objpfx)soversions.i: $(..)scripts/soversions.awk \
 			      $(common-objpfx)shlib-versions.v
 	$(AWK) -v default_setname='$(soversions-default-setname)' \
-	       -v config='$(config-machine)-$(config-vendor)-$(config-os)' \
+	       -v cpu='$(config-machine)' \
+	       -v vendor='$(config-vendor)' \
+	       -v os='$(config-os)' \
 	       -f $^ > $@T
 	mv -f $@T $@
 $(common-objpfx)soversions.mk: $(common-objpfx)soversions.i
-	(while read lib number setname; do \
+	(while read which lib number setname; do \
+	   test x"$$which" = xDEFAULT || continue; \
 	   case $$number in \
 	     [0-9]*) echo "$$lib.so-version=.$$number"; \
 		     echo "all-sonames+=$$lib=$$lib.so\$$($$lib.so-version)";;\
@@ -812,31 +815,11 @@ postclean-generated += soversions.mk soversions.i \
 before-compile += $(common-objpfx)gnu/lib-names.h
 ifeq ($(soversions.mk-done),t)
 $(common-objpfx)gnu/lib-names.h: $(common-objpfx)gnu/lib-names.stmp; @:
-$(common-objpfx)gnu/lib-names.stmp: $(common-objpfx)soversions.mk
+$(common-objpfx)gnu/lib-names.stmp: $(..)scripts/lib-names.awk \
+				    $(common-objpfx)soversions.i
 	$(make-target-directory)
 	@rm -f ${@:stmp=T} $@
-	(echo '/* This file is automatically generated.';\
-	 echo '   It defines macros to allow user program to find the shared';\
-	 echo '   library files which come as part of GNU libc.  */';\
-	 echo '#ifndef __GNU_LIB_NAMES_H'; \
-	 echo '#define __GNU_LIB_NAMES_H	1'; \
-	 echo; \
-	 (libs='$(all-sonames)';\
-	  for l in $$libs; do \
-	    name=`echo $$l | sed 's/.*=//'`; \
-	    upname=`echo $$l | sed 's/=.*//' | \
-		    tr 'abcdefghijklmnopqrstuvwxyz-' \
-		       'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`; \
-	    upname2=`echo $$name | sed 's/[.]so.*//' | \
-		     tr 'abcdefghijklmnopqrstuvwxyz-' \
-		        'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`; \
-	    echo "#define	$${upname}_SO	\"$$name\""; \
-	    if test $$upname != $$upname2; then \
-	      echo "#define	$${upname2}_SO	\"$$name\""; \
-	    fi; \
-	  done;) | sort; \
-	 echo; \
-	 echo '#endif	/* gnu/lib-names.h */';) > ${@:stmp=T}
+	$(AWK) -f $^ > ${@:stmp=T}
 	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
 	touch $@
 endif
diff --git a/Makefile b/Makefile
index 50ee40c26a..c2f4ae32a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1991-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -64,7 +64,7 @@ endif # $(AUTOCONF) = no
 		   subdir_update-abi subdir_check-abi 			\
 		   subdir_echo-headers 					\
 		   subdir_install					\
-		   subdir_testclean					\
+		   subdir_objs subdir_stubs subdir_testclean		\
 		   $(addprefix install-, no-libc.a bin lib data headers others)
 
 headers := limits.h values.h features.h gnu-versions.h bits/libc-lock.h \
diff --git a/Makerules b/Makerules
index 5d7b24f31f..887d7275c3 100644
--- a/Makerules
+++ b/Makerules
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1991-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -338,7 +338,8 @@ $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
 			      $(common-objpfx)soversions.i \
 			      $(common-objpfx)Versions.def.v
-	{ while read lib version setname; do \
+	{ while read which lib version setname; do \
+	    test x"$$which" = xDEFAULT || continue; \
 	    test -z "$$setname" || echo "$$lib : $$setname"; \
 	  done < $(word 2,$^); \
 	  cat $(word 3,$^); \
@@ -491,7 +492,7 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
 		 PROVIDE(__start___libc_freeres_ptrs = .); \
 		 *(__libc_freeres_ptrs) \
 		 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
-	      -e 's/^.*\*(\.jcr).*$$/& \
+	      -e 's@^.*\*(\.jcr).*$$@& \
 		 PROVIDE(__start___libc_subfreeres = .);\
 		 __libc_subfreeres : { *(__libc_subfreeres) }\
 		 PROVIDE(__stop___libc_subfreeres = .);\
@@ -500,7 +501,8 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
 		 PROVIDE(__stop___libc_atexit = .);\
 		 PROVIDE(__start___libc_thread_subfreeres = .);\
 		 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
-		 PROVIDE(__stop___libc_thread_subfreeres = .);/'
+		 PROVIDE(__stop___libc_thread_subfreeres = .);\
+		 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
 	mv -f $@T $@
 common-generated += shlib.lds
 
@@ -1384,19 +1386,15 @@ ifdef objpfx
 .PHONY: stubs # The parent Makefile calls this target.
 stubs: $(objpfx)stubs
 endif
-$(objpfx)stubs: $(+depfiles)
-ifneq (,$(strip $(+depfiles)))
-# Use /dev/null since `...` might expand to empty.
-	c=`($(patsubst %/,cd % &&,$(objpfx)) \
-	    sed -n -e 's@\$$(common-objpfx)@$(common-objpfx)@g' \
-		   -e 's@\$$(objpfx)@$(objpfx)@g' \
-		   -e '/stub-tag\.h/{; g; s/./&/p; }' \
-		   -e '/:/{x; s/^.*$$//; x; }' \
-		   -e 's/^.*://;s/\\$$//;s/^ *\([^ ][^ ]*\) .*$$/\1/' \
-		   -e '/^[^ ][^ ]*$$/{G;s/^.*\n\(..*\)/\1/;s/\n//;h; }' \
-		   $(patsubst $(objpfx)%,%,$^)) | sort | uniq`; \
-	sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
-	    $$c /dev/null > $@T
+objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
+		  $(addprefix $(objpfx),$(extra-objs))
+$(objpfx)stubs: $(objs-for-stubs)
+ifneq (,$(strip $(objs-for-stubs)))
+	$(OBJDUMP) -h $^ | \
+	$(AWK) '/\.gnu\.glibc-stub\./ { \
+	          sub(/\.gnu\.glibc-stub\./, "", $$2); \
+		  stubs[$$2] = 1; } \
+		END { for (s in stubs) print "#define __stub_" s }' > $@T
 	mv -f $@T $@
 else
 	> $@
diff --git a/Rules b/Rules
index a29daaa7b5..5758611081 100644
--- a/Rules
+++ b/Rules
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2000,2002,2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1991-2000,2002,2003, 2004, 2005 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -165,7 +165,9 @@ distclean: clean
 .PHONY: subdir_install
 subdir_install: install-no-libc.a lib-noranlib stubs
 
-.PHONY: subdir_TAGS
+.PHONY: subdir_objs subdir_stubs subdir_TAGS
+subdir_objs: objs
+subdir_stubs: stubs
 subdir_TAGS: TAGS
 
 # Target required by the Hurd to ensure that all the MiG-generated
diff --git a/dlfcn/dlfcn.c b/dlfcn/dlfcn.c
index 9c0a84afb8..8047150763 100644
--- a/dlfcn/dlfcn.c
+++ b/dlfcn/dlfcn.c
@@ -23,11 +23,17 @@
 int __dlfcn_argc attribute_hidden;
 char **__dlfcn_argv attribute_hidden;
 
-
-void
-__attribute__ ((constructor))
+#ifdef HAVE_INITFINI_ARRAY
+static void
 init (int argc, char *argv[])
 {
   __dlfcn_argc = argc;
   __dlfcn_argv = argv;
 }
+
+static void (*const init_array []) (int argc, char *argv[])
+     __attribute__ ((section (".init_array"), aligned (sizeof (void *))))
+     __attribute_used__ = { init };
+#else
+# error "Need linker with .init_array support."
+#endif
diff --git a/fedora/branch.mk b/fedora/branch.mk
index 10a2e2b6a4..bdbe9df107 100644
--- a/fedora/branch.mk
+++ b/fedora/branch.mk
@@ -1,5 +1,5 @@
 # This file is updated automatically by Makefile.
 glibc-branch := fedora
 glibc-base := HEAD
-fedora-sync-date := 2005-02-08 22:13 UTC
-fedora-sync-tag := fedora-glibc-20050208T2213
+fedora-sync-date := 2005-02-11 08:53 UTC
+fedora-sync-tag := fedora-glibc-20050211T0853
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index dcc46cc80f..f3526ca053 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -1,6 +1,6 @@
 /* Support macros for making weak and strong aliases for symbols,
    and for using symbol sets and linker warnings with GNU ld.
-   Copyright (C) 1995-1998,2000-2003,2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998,2000-2003,2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -279,6 +279,7 @@
 
 /* A canned warning for sysdeps/stub functions.  */
 #define	stub_warning(name) \
+  __make_section_unallocated (".gnu.glibc-stub." #name) \
   link_warning (name, \
 		"warning: " #name " is not implemented and will always fail")
 
diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog
index 329f2d8b12..4cbcfbb7a3 100644
--- a/linuxthreads/ChangeLog
+++ b/linuxthreads/ChangeLog
@@ -1,3 +1,8 @@
+2005-02-09  Daniel Jacobowitz  <dan@codesourcery.com>
+
+	* descr.h (__pthread_find_self, thread_self): Mark as pure
+	instead of const.
+
 2005-02-07  Jakub Jelinek  <jakub@redhat.com>
 
 	* specific.c (pthread_key_delete): If pthread_create has not been
diff --git a/linuxthreads/descr.h b/linuxthreads/descr.h
index bea8b912f7..2b1e49a0ba 100644
--- a/linuxthreads/descr.h
+++ b/linuxthreads/descr.h
@@ -239,9 +239,9 @@ extern int __pthread_nonstandard_stacks;
 
 /* Recover thread descriptor for the current thread */
 
-extern pthread_descr __pthread_find_self (void) __attribute__ ((const));
+extern pthread_descr __pthread_find_self (void) __attribute__ ((pure));
 
-static inline pthread_descr thread_self (void) __attribute__ ((const));
+static inline pthread_descr thread_self (void) __attribute__ ((pure));
 static inline pthread_descr thread_self (void)
 {
 #ifdef THREAD_SELF
diff --git a/scripts/lib-names.awk b/scripts/lib-names.awk
new file mode 100644
index 0000000000..77e6668515
--- /dev/null
+++ b/scripts/lib-names.awk
@@ -0,0 +1,66 @@
+# awk script for soversions.i -> gnu/lib-names.h; see Makeconfig.
+
+$1 != "DEFAULT" { multi = 1 }
+
+#
+{
+  lib = $2;
+  version = $3;
+  if ($3 !~ /^[0-9]/) {
+    soname = $3;
+    extra = $3;
+    sub(/\.so.*$/, "", extra);
+  }
+  else {
+    soname = lib ".so." $3;
+    extra = "";
+  }
+  soname = "\"" soname "\"";
+  lib = toupper(lib);
+  extra = toupper(extra);
+  gsub(/-/, "_", lib);
+  gsub(/-/, "_", extra);
+  macros[$1 FS lib "_SO"] = soname;
+  if (extra)
+    macros[$1 FS extra "_SO"] = soname;
+}
+
+END {
+  print "/* This file is automatically generated.";
+  print "   It defines macros to allow user program to find the shared";
+  print "   library files which come as part of GNU libc.  */";
+  print "#ifndef __GNU_LIB_NAMES_H";
+  print "#define __GNU_LIB_NAMES_H	1";
+  print "";
+
+  pfx = multi ? "# define " : "#define ";
+  for (elt in macros) {
+    split(elt, x);
+    line = sprintf("%-40s%s", pfx x[2], macros[elt]);
+    if (x[1] in lines)
+      lines[x[1]] = lines[x[1]] "\n" line;
+    else
+      lines[x[1]] = line;
+  }
+
+  if (multi) {
+    # Print these in a fixed order so the result is identical
+    # on both sides of the coin.
+    if (!("WORDSIZE32" in lines))
+      lines["WORDSIZE32"] = lines["DEFAULT"];
+    if (!("WORDSIZE64" in lines))
+      lines["WORDSIZE64"] = lines["DEFAULT"];
+    print "#include <bits/wordsize.h>\n";
+    print "#if __WORDSIZE == 32";
+    cmd = "LC_ALL=C sort"; print lines["WORDSIZE32"] | cmd; close(cmd);
+    print "#else"
+    cmd = "LC_ALL=C sort"; print lines["WORDSIZE64"] | cmd; close(cmd);
+    print "#endif";
+  }
+  else {
+    cmd = "LC_ALL=C sort"; print lines["DEFAULT"] | cmd; close(cmd);
+  }
+
+  print "";
+  print "#endif	/* gnu/lib-names.h */"
+}
diff --git a/scripts/soversions.awk b/scripts/soversions.awk
index 6207088514..3d50c4deeb 100644
--- a/scripts/soversions.awk
+++ b/scripts/soversions.awk
@@ -1,14 +1,29 @@
-# awk script for shlib-versions.v.i -> soversions.i; see Makeconfig.
+# awk script for shlib-versions.v -> soversions.i; see Makeconfig.
 
-# Only lines matching `config' (set with -v) are relevant to us.
-config !~ $1 { next }
+BEGIN {
+  config = cpu "-" vendor "-" os;
+  configs[config] = "DEFAULT";
+}
+
+{ thiscf = $1 }
+
+$2 ~ /WORDSIZE[3264]/ {
+  if (config ~ thiscf) {
+    othercf = $3;
+    sub(/@CPU@/, cpu, othercf);
+    sub(/@VENDOR@/, vendor, othercf);
+    sub(/@OS@/, os, othercf);
+    configs[othercf] = $2;
+  }
+  next;
+}
 
 # Obey the first matching DEFAULT line.
 $2 == "DEFAULT" {
-  if (!matched_default) {
-    matched_default = 1;
+  if (!matched_default[thiscf]) {
+    matched_default[thiscf] = 1;
     $1 = $2 = "";
-    default_setname = $0;
+    default_set[thiscf] = $0;
   }
   next
 }
@@ -19,20 +34,33 @@ $2 == "DEFAULT" {
   lib = number = $2;
   sub(/=.*$/, "", lib);
   sub(/^.*=/, "", number);
-  if (lib in numbers) next;
-  numbers[lib] = number;
+  if ((thiscf FS lib) in numbers) next;
+  numbers[thiscf FS lib] = number;
+  order[thiscf FS lib] = ++order_n;
   if (NF > 2) {
     $1 = $2 = "";
-    versions[lib] = $0
+    versions[thiscf FS lib] = $0
   }
 }
 
 END {
-  for (lib in numbers) {
-    set = (lib in versions) ? versions[lib] : default_setname;
-    if (set)
-      print lib, numbers[lib], set;
-    else
-      print lib, numbers[lib];
+  for (elt in numbers) {
+    split(elt, x);
+    cf = x[1];
+    lib = x[2];
+    if (default_setname && !(cf in default_set) && config ~ cf)
+      default_set[cf] = default_setname;
+    set = (elt in versions) ? versions[elt] : default_set[cf];
+    line = set ? (lib FS numbers[elt] FS set) : (lib FS numbers[elt]);
+    for (c in configs)
+      if (c ~ cf) {
+	if (!((c FS lib) in lineorder) || order[elt] < lineorder[c FS lib]) {
+	  lineorder[c FS lib] = order[elt];
+	  lines[c FS lib] = configs[c] FS line;
+	}
+      }
+  }
+  for (c in lines) {
+    print lines[c]
   }
 }
diff --git a/shlib-versions b/shlib-versions
index 72cbb4af0e..aaeb9669b2 100644
--- a/shlib-versions
+++ b/shlib-versions
@@ -17,6 +17,11 @@
 # to apply on matching configurations when the matching entry for a particular
 # library has no third column.  The defaults must precede the entries they
 # apply to.
+#
+# An entry with WORDSIZE* in the second column gives an alternate
+# configuration tuple whose macros will be conditionally defined in
+# gnu/lib-names.h; @CPU@, @VENDOR@, @OS@ can be used in the third
+# column to compose the alternate tuple matched against the patterns here.
 
 # Configuration		DEFAULT			Earliest symbol set
 # -------------		---------------		------------------------------
@@ -27,6 +32,16 @@ x86_64-.*-linux.*       DEFAULT			GLIBC_2.2.5
 powerpc64-.*-linux.*	DEFAULT			GLIBC_2.3
 .*-.*-gnu-gnu.*		DEFAULT			GLIBC_2.2.6
 
+# Configuration		WORDSIZE[32|64]		Alternate configuration
+# -------------		----------		-----------------------
+x86_64-.*-.*		WORDSIZE32		i686-@VENDOR@-@OS@
+s390x-.*-.*		WORDSIZE32		s390-@VENDOR@-@OS@
+s390-.*-.*		WORDSIZE64		s390x-@VENDOR@-@OS@
+powerpc64-.*-.*		WORDSIZE32		powerpc-@VENDOR@-@OS@
+powerpc.*-.*-.*		WORDSIZE64		powerpc64-@VENDOR@-@OS@
+sparc64-.*-.*		WORDSIZE32		sparc-@VENDOR@-@OS@
+sparc.*-.*-.*		WORDSIZE64		sparc64-@VENDOR@-@OS@
+
 # Configuration		Library=version		Earliest symbol set (optional)
 # -------------		---------------		------------------------------
 
diff --git a/stdlib/Makefile b/stdlib/Makefile
index a0c0e71704..fafe6061a0 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -61,9 +61,9 @@ distribute	:= exit.h grouping.h abort-instr.h isomac.c tst-fmtmsg.sh   \
 test-srcs	:= tst-fmtmsg
 tests		:= tst-strtol tst-strtod testmb testrand testsort testdiv   \
 		   test-canon test-canon2 tst-strtoll tst-environ	    \
-		   tst-xpg-basename tst-random tst-bsearch tst-limits	    \
-		   tst-rand48 bug-strtod tst-setcontext test-a64l tst-qsort \
-		   tst-system testmb2
+		   tst-xpg-basename tst-random tst-random2 tst-bsearch	    \
+		   tst-limits tst-rand48 bug-strtod tst-setcontext	    \
+		   test-a64l tst-qsort tst-system testmb2
 
 include ../Makeconfig
 
diff --git a/stdlib/random_r.c b/stdlib/random_r.c
index 09677e6077..c85fd5eeef 100644
--- a/stdlib/random_r.c
+++ b/stdlib/random_r.c
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995 Free Software Foundation
+   Copyright (C) 1995, 2005 Free Software Foundation
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -240,10 +240,19 @@ __initstate_r (seed, arg_state, n, buf)
   int degree;
   int separation;
   int32_t *state;
+  int old_type;
+  int32_t *old_state;
 
   if (buf == NULL)
     goto fail;
 
+  old_type = buf->rand_type;
+  old_state = buf->state;
+  if (old_type == TYPE_0)
+    old_state[-1] = TYPE_0;
+  else
+    old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
+
   if (n >= BREAK_3)
     type = n < BREAK_4 ? TYPE_3 : TYPE_4;
   else if (n < BREAK_1)
diff --git a/stdlib/tst-random2.c b/stdlib/tst-random2.c
new file mode 100644
index 0000000000..aa1b89d905
--- /dev/null
+++ b/stdlib/tst-random2.c
@@ -0,0 +1,59 @@
+/* Test initstate saving the old state.
+   Copyright (C) 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main (void)
+{
+  int pass;
+  int ret = 0;
+  long int r[2];
+
+  for (pass = 0; pass < 2; pass++)
+    {
+      srandom (0x12344321);
+
+      int j;
+      for (j = 0; j < 3; ++j)
+	random ();
+      if (pass == 1)
+	{
+	  char state[128];
+	  char *ostate = initstate (0x34562101, state, 128);
+	  if (setstate (ostate) != state)
+	    {
+	      puts ("setstate (ostate) != state");
+	      ret = 1;
+	    }
+	}
+
+      random ();
+      r[pass] = random ();
+    }
+
+  if (r[0] != r[1])
+    {
+      printf ("%ld != %ld\n", r[0], r[1]);
+      ret = 1;
+    }
+  return ret;
+}
diff --git a/sysdeps/powerpc/powerpc64/bits/link.h b/sysdeps/powerpc/bits/link.h
index 863336241a..f8e6734fe0 100644
--- a/sysdeps/powerpc/powerpc64/bits/link.h
+++ b/sysdeps/powerpc/bits/link.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+/* Machine-specific declarations for dynamic linker interface.  PowerPC version
+   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
diff --git a/sysdeps/powerpc/powerpc32/bits/link.h b/sysdeps/powerpc/powerpc32/bits/link.h
deleted file mode 100644
index 7f44087120..0000000000
--- a/sysdeps/powerpc/powerpc32/bits/link.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C 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
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#ifndef	_LINK_H
-# error "Never include <bits/link.h> directly; use <link.h> instead."
-#endif
-
-
-/* Registers for entry into PLT on PPC32.  */
-typedef struct La_ppc32_regs
-{
-  uint32_t lr_reg[8];
-  double lr_fp[8];
-  uint32_t lr_vreg[12][4];
-  uint32_t lr_r1;
-  uint32_t lr_lr;
-} La_ppc32_regs;
-
-/* Return values for calls from PLT on PPC32.  */
-typedef struct La_ppc32_retval
-{
-  uint32_t lrv_r3;
-  uint32_t lrv_r4;
-  double lrv_fp[8];
-  uint32_t lrv_v2[4];
-} La_ppc32_retval;
-
-
-__BEGIN_DECLS
-
-extern Elf32_Addr la_ppc32_gnu_pltenter (Elf32_Sym *__sym,
-					 unsigned int __ndx,
-					 uintptr_t *__refcook,
-					 uintptr_t *__defcook,
-					 La_ppc32_regs *__regs,
-					 unsigned int *__flags,
-					 const char *__symname,
-					 long int *__framesizep);
-extern unsigned int la_ppc32_gnu_pltexit (Elf32_Sym *__sym,
-					  unsigned int __ndx,
-					  uintptr_t *__refcook,
-					  uintptr_t *__defcook,
-					  const La_ppc32_regs *__inregs,
-					  La_ppc32_retval *__outregs,
-					  const char *symname);
-
-__END_DECLS