# DP: Description: i386 ld.so gets sigsegv when i686 optimized library is used,
#		   because the structure size of rtld_global and rtld_global_ro 
#		   are different due to HP_TIMING_AVAIL availability.
#		   This patch aligns those sizes for using i686 optimized library.
# DP: Author: Daniel Jacobowitz <dan@debian.org>
# DP: Upstream status: Pending
# DP: Status Details:
# DP: Date: 2003-10-03 (Updated 2003-10-12), (Updated 2005-01-02, 2005-03-03 gotom)
 
2005-03-03  GOTO Masanori  <gotom@debian.org>

	* sysdeps/generic/ldsodefs.h (struct rtld_global, rtld_global_ro):
	Include timing members if HP_TIMING_PAD is defined.

2005-01-02  GOTO Masanori  <gotom@debian.org>

	* elf/Makefile: Regenerate.

2003-10-12  Daniel Jacobowitz  <drow@mvista.com>

	* sysdeps/generic/ldsodefs.h (struct rtld_global): Include timing
	members if HP_TIMING_PAD is defined.
	* sysdeps/i386/hp-timing.h: New file.
	* elf/Makefile: Add dl-altinit to routines, shared-only-routines.
	* elf/dl-altinit.c: New file.

---
 elf/Makefile               |    6 +++++-
 elf/dl-altinit.c           |   43 +++++++++++++++++++++++++++++++++++++++++++
 sysdeps/generic/ldsodefs.h |    4 ++--
 sysdeps/i386/hp-timing.h   |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 3 deletions(-)

--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -322,7 +322,7 @@ struct rtld_global
   /* The object to be initialized first.  */
   EXTERN struct link_map *_dl_initfirst;
 
-#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
+#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL || HP_TIMING_PAD
   /* Start time on CPU clock.  */
   EXTERN hp_timing_t _dl_cpuclock_offset;
 #endif
@@ -543,7 +543,7 @@ struct rtld_global_ro
   /* All search directories defined at startup.  */
   EXTERN struct r_search_path_elem *_dl_init_all_dirs;
 
-#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
+#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL || HP_TIMING_PAD
   /* Overhead of a high-precision timing measurement.  */
   EXTERN hp_timing_t _dl_hp_timing_overhead;
 #endif
--- /dev/null
+++ b/sysdeps/i386/hp-timing.h
@@ -0,0 +1,34 @@
+/* High precision, low overhead timing functions.  i386 version.
+   Copyright (C) 2003 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 _i386_HP_TIMING_H
+#define _i386_HP_TIMING_H	1
+
+#define hp_timing_t hp_timing_t__
+#include <sysdeps/generic/hp-timing.h>
+#undef hp_timing_t
+
+/* We don't use high-precision timers, but we might load an i686 libpthread
+   which does.  */
+#define HP_TIMING_PAD 1
+
+/* i686 uses 64bit values for the times.  */
+typedef unsigned long long int hp_timing_t;
+
+#endif	/* hp-timing.h */
--- /dev/null
+++ b/elf/dl-altinit.c
@@ -0,0 +1,43 @@
+/* Extra initializers for shared libc.
+   Copyright (C) 2003 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.  */
+
+#include <ldsodefs.h>
+#include <hp-timing.h>
+
+/* This file is used from the shared libc, to initialize anything which
+   ld.so should have initialized but didn't - for instance, if ld.so
+   is built for a machine without HP_TIMING but libc.so is built for
+   a machine with HP_TIMING, clock_gettime will expect dl_cpuclock_offset
+   to be initialized.  */
+
+static void
+dlinit_hptiming (void)
+{
+#if HP_TIMING_AVAIL || HP_SMALL_TIMING_AVAIL
+  if (GL(dl_cpuclock_offset) == 0)
+    HP_TIMING_NOW (GL(dl_cpuclock_offset));
+#endif
+}
+
+static void dlinit_alt (void) __attribute__((constructor));
+static void
+dlinit_alt (void)
+{
+  dlinit_hptiming ();
+}
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -24,7 +24,7 @@ include ../Makeconfig
 headers		= elf.h bits/elfclass.h link.h bits/link.h
 routines	= $(dl-routines) dl-support dl-iteratephdr \
 		  dl-addr enbl-secure dl-profstub \
-		  dl-origin dl-libc dl-sym dl-tsd dl-sysdep
+		  dl-origin dl-libc dl-sym dl-tsd dl-sysdep dl-altinit
 
 # The core dynamic linking functions are in libc for the static and
 # profiled libraries.
@@ -50,6 +50,10 @@ CFLAGS-dl-runtime.c = -fexceptions -fasy
 CFLAGS-dl-lookup.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-dl-iterate-phdr.c = $(uses-callbacks)
 
+# We only need to re-run initializers if ld.so and libc.so might be built
+# for different machines, so only shared libraries need dl-altinit.
+shared-only-routines += dl-altinit
+
 ifeq ($(unwind-find-fde),yes)
 routines += unwind-dw2-fde-glibc
 shared-only-routines += unwind-dw2-fde-glibc
