This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[gomp] Avoid -Wl,-z,nodlopen (PR libgomp/28482)


Hi!

libgomp ATM uses 32 bytes (on 32-bit arches) resp. 60 bytes (on 64-bit
arches) in PT_TLS, with contemporary glibcs it is possible to dlopen
a couple of such libraries (e.g. glibc 2.5+ reserve about 100 bytes
per namespace, but the pool is global, so if you use just one namespace,
I managed to dlopen 26 of libraries with 60 bytes in .tbss (alignment 8
bytes) on x86_64).  libgomp as is is apparently not dlopenable even without
-Wl,-z,nodlopen, because i386/x86_64 backend helpfully aligns the structure
to 32 bytes and that's just too big requirement for the static TLS area.
The following patch cures this by using the aligned attribute (with it
.tbss needs just 8 byte alignment).

I wonder if we additionally shouldn't change DATA_ALIGMENT on i386 (well,
we'd need a new macro so that the actual decl rather than type is passed)
to also take DECL_THREAD_LOCAL_P into account, TLS space is precious
and wasting bytes this way there is weird.
Richard, what do you think?

2007-05-02  Jakub Jelinek  <jakub@redhat.com>

	PR libgomp/28482
	* configure.tgt: Don't link with -Wl,-z,nodlopen even on Linux.
	* team.c (gomp_tls_data): Use aligned attribute to avoid excessive
	alignment.

--- libgomp/configure.tgt.jj	2007-04-20 12:55:40.000000000 +0200
+++ libgomp/configure.tgt	2007-05-02 17:32:15.000000000 +0200
@@ -11,14 +11,11 @@
 #  XLDFLAGS		Add extra link flags to use.
 
 # Optimize TLS usage by avoiding the overhead of dynamic allocation.
-# This does require that the library be present during process 
-# startup, so mark the library as not to be dlopened.
 if test $have_tls = yes ; then
   case "${target}" in
 
     *-*-linux*)
 	XCFLAGS="${XCFLAGS} -ftls-model=initial-exec"
-	XLDFLAGS="${XLDFLAGS} -Wl,-z,nodlopen"
 	;;
   esac
 fi
--- libgomp/team.c.jj	2007-04-04 16:19:59.000000000 +0200
+++ libgomp/team.c	2007-05-02 18:03:05.000000000 +0200
@@ -44,9 +44,12 @@ pthread_attr_t gomp_thread_attr;
 /* This barrier holds and releases threads waiting in gomp_threads.  */
 static gomp_barrier_t gomp_threads_dock;
 
-/* This is the libgomp per-thread data structure.  */
+/* This is the libgomp per-thread data structure.
+   Aligned attribute is used to avoid any excessive aligning
+   of the structure, since TLS space is precious.  */
 #ifdef HAVE_TLS
-__thread struct gomp_thread gomp_tls_data;
+__thread struct gomp_thread gomp_tls_data
+  __attribute__((aligned (__alignof__ (struct gomp_thread))));
 #else
 pthread_key_t gomp_tls_key;
 #endif

	Jakub


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