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]

Re: [RFC][BZ #16046] dl_iterate_phdr should not expose internal stub.


On Thu, 16 Jan 2014, Ondřej Bílka wrote:

> >  I have identified what I believe is another place where such 
> > special-casing can be removed now that we have a proper link map in static 
> > executables.  I'll see if I can address both these issues shortly.
> > 
> Any progress with this? What is another place that needs a special
> casing? 

 No progress, sorry.  Do you think it's important to fix for 2.19?  I'll 
see what I can do to get at it ASAP.

 Here's the other place I had in mind; patch untested.  Since then I have 
identified a couple of other code pieces scattered around that now look 
dead and would benefit from a clean-up.  I plan to handle this stuff all 
at once.

2014-01-17  Maciej W. Rozycki  <macro@codesourcery.com>

	* csu/libc-tls.c (static_map): Remove variable.
	(__libc_setup_tls): Use main executable's link map for TLS data.

  Maciej

glibc-static-tls-link-map.diff
Index: glibc-fsf-trunk-quilt/csu/libc-tls.c
===================================================================
--- glibc-fsf-trunk-quilt.orig/csu/libc-tls.c	2014-01-16 21:12:16.000000000 +0000
+++ glibc-fsf-trunk-quilt/csu/libc-tls.c	2014-01-17 06:00:29.431963646 +0000
@@ -42,9 +42,6 @@ static struct
   struct dtv_slotinfo info[2 + TLS_SLOTINFO_SURPLUS];
 } static_slotinfo;
 
-/* Fake link map for the application.  */
-static struct link_map static_map;
-
 
 /* Highest dtv index currently needed.  */
 size_t _dl_tls_max_dtv_idx;
@@ -162,14 +159,16 @@ __libc_setup_tls (size_t tcbsize, size_t
   _dl_static_dtv[0].counter = (sizeof (_dl_static_dtv) / sizeof (_dl_static_dtv[0])) - 2;
   // _dl_static_dtv[1].counter = 0;		would be needed if not already done
 
+  struct link_map *main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
+
   /* Initialize the TLS block.  */
 #if TLS_TCB_AT_TP
   _dl_static_dtv[2].pointer.val = ((char *) tlsblock + tcb_offset
 			       - roundup (memsz, align ?: 1));
-  static_map.l_tls_offset = roundup (memsz, align ?: 1);
+  main_map->l_tls_offset = roundup (memsz, align ?: 1);
 #elif TLS_DTV_AT_TP
   _dl_static_dtv[2].pointer.val = (char *) tlsblock + tcb_offset;
-  static_map.l_tls_offset = tcb_offset;
+  main_map->l_tls_offset = tcb_offset;
 #else
 # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
 #endif
@@ -193,19 +192,17 @@ __libc_setup_tls (size_t tcbsize, size_t
   if (__builtin_expect (lossage != NULL, 0))
     __libc_fatal (lossage);
 
-  /* We have to create a fake link map which normally would be created
-     by the dynamic linker.  It just has to have enough information to
-     make the TLS routines happy.  */
-  static_map.l_tls_align = align;
-  static_map.l_tls_blocksize = memsz;
-  static_map.l_tls_initimage = initimage;
-  static_map.l_tls_initimage_size = filesz;
-  static_map.l_type = lt_executable;
-  static_map.l_tls_modid = 1;
+  /* Update the executable's link map with enough information to make
+     the TLS routines happy.  */
+  main_map->l_tls_align = align;
+  main_map->l_tls_blocksize = memsz;
+  main_map->l_tls_initimage = initimage;
+  main_map->l_tls_initimage_size = filesz;
+  main_map->l_tls_modid = 1;
 
   init_slotinfo ();
   // static_slotinfo.si.slotinfo[1].gen = 0; already zero
-  static_slotinfo.si.slotinfo[1].map = &static_map;
+  static_slotinfo.si.slotinfo[1].map = main_map;
 
   memsz = roundup (memsz, align ?: 1);
 


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