This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

[PATCH 1/5][v2][BZ #15022] Avoid repeated calls to DL_STATIC_INIT


On Fri, 31 May 2013, Roland McGrath wrote:

> I don't understand the situation with _dl_static_init.  It seems wrong that
> DL_STATIC_INIT should ever be called more than once on the same module.
> It's just like initializers.  Why isn't it done inside _dl_init or where
> _dl_init is called in dl_open_worker?

 Good question -- I don't know.  DL_STATIC_INIT was added by H.J. Lu:

2001-01-10  H.J. Lu  <hjl@gnu.org>

	* elf/dl-libc.c (do_dlopen): Call DL_STATIC_INIT for static binaries.
	* sysdeps/unix/sysv/linux/ia64/Makefile (sysdep-dl-routines): Add
	dl-static.
	* sysdeps/unix/sysv/linux/ia64/Versions (ld): Add _dl_var_init.
	* sysdeps/generic/ldsodefs.h (DL_STATIC_INIT): Defined if not defined.
	* sysdeps/unix/sysv/linux/ia64/ldsodefs.h: New file.
	* sysdeps/unix/sysv/linux/ia64/dl-static.c: New file.
	* sysdeps/unix/sysv/linux/ia64/Dist: Add dl-static.c.

and:

2001-01-11  H.J. Lu  <hjl@gnu.org>

	* elf/dl-libc.c (do_dlopen): Move DL_STATIC_INIT to ...
	* elf/dl-open.c (_dl_open): Here.
	* sysdeps/unix/sysv/linux/ia64/dl-static.c (_dl_static_lock):
	Make it static.
	(_dl_static_init): Initialize the variables every time when possible.
	* sysdeps/unix/sysv/linux/ia64/ldsodefs.h (DL_STATIC_INIT):
	Undefine it first.

after a discussion started at:

http://www.sourceware.org/ml/libc-alpha/2001-01/msg00097.html

-- H.J. can you please tell us if you have anything to add?

>  Then it would never be called at all
> for the dummy "main executable" link_map.  I think we should get that
> cleaned up before attempting your fix.

 Your suggestion sounds fine to me.  Especially as DL_STATIC_INIT has to 
be called before any shared object's static initialisers, because those 
may rely on state initialised by DL_STATIC_INIT (the initialisation of 
which state is supposed to be transparent to user code), e.g. on the page 
size reported being handled here for the two targets affected.

 This change does not cause any regressions for the mips-linux target and 
(since this is not currently covered) I have verified (using both the 
forthcoming test cases and manually) that getpagesize still returns the 
correct value after this change.  I'm not sure if this change should refer 
to BZ #15022, please let me know what you think.  OK to apply?

2013-06-19  Maciej W. Rozycki  <macro@codesourcery.com>

	* elf/dl-open.c (_dl_open) [!SHARED]: Move call to DL_STATIC_INIT
	over to...
	(dl_open_worker) [!SHARED]: ... here.

  Maciej

glibc-static-dl-init.diff
Index: glibc-fsf-trunk-quilt/elf/dl-open.c
===================================================================
--- glibc-fsf-trunk-quilt.orig/elf/dl-open.c	2013-06-17 12:46:08.000000000 +0100
+++ glibc-fsf-trunk-quilt/elf/dl-open.c	2013-06-17 15:35:29.402773296 +0100
@@ -568,6 +568,10 @@ cannot load any more object with static 
   if (relocation_in_progress)
     LIBC_PROBE (reloc_complete, 3, args->nsid, r, new);
 
+#ifndef SHARED
+  DL_STATIC_INIT (new);
+#endif
+
   /* Run the initializer functions of new objects.  */
   _dl_init (new, args->argc, args->argv, args->env);
 
@@ -721,10 +725,6 @@ no more namespaces available for dlmopen
   /* Release the lock.  */
   __rtld_lock_unlock_recursive (GL(dl_load_lock));
 
-#ifndef SHARED
-  DL_STATIC_INIT (args.map);
-#endif
-
   return args.map;
 }
 


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