This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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] __attribute__((visibility(...))) for ld.so


Hi!

This patch makes ld.so on ia32 smaller by another 1KB and on ia64 by 1.5KB
by killing some unnecessary memory dereferences.
Bootstrapped on i386/i686/ia64/alpha/alphaev6.

2002-02-28  Jakub Jelinek  <jakub@redhat.com>

	* elf/rtld.c (_rtld_global): Remove .protected.
	(_rtld_local): Strong alias to _rtld_global.
	* elf/Makefile (CFLAGS-.os): Add -D_RTLD_LOCAL if compiling rtld
	only .os object.
	* sysdeps/generic/ldsodefs.h (GL): If SHARED and _RTLD_LOCAL, use
	_rtld_local instead of _rtld_global.
	(_rtld_local): Add hidden extern, possibly in .sdata section.

--- libc/elf/rtld.c.jj	Thu Feb 28 12:31:20 2002
+++ libc/elf/rtld.c	Thu Feb 28 16:18:08 2002
@@ -91,11 +91,7 @@ struct rtld_global _rtld_global =
     ._dl_hwcap_mask = HWCAP_IMPORTANT,
     ._dl_load_lock = _LIBC_LOCK_RECURSIVE_INITIALIZER
   };
-/* There must only be the definition in ld.so itself.  */
-#ifdef HAVE_PROTECTED
-asm (".protected _rtld_global");
-#endif
-
+strong_alias (_rtld_global, _rtld_local);
 
 static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
 		     ElfW(Addr) *user_entry);
--- libc/elf/Makefile.jj	Mon Feb 18 23:39:22 2002
+++ libc/elf/Makefile	Thu Feb 28 16:02:19 2002
@@ -250,6 +250,8 @@ CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'
 CFLAGS-dl-cache.c = $(SYSCONF-FLAGS)
 CFLAGS-cache.c = $(SYSCONF-FLAGS)
 
+CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),-D_RTLD_LOCAL)
+
 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(strip $(modules-names))))
 generated += $(addsuffix .so,$(strip $(modules-names)))
 
--- libc/sysdeps/alpha/dl-machine.h.jj	Thu Feb 28 12:33:15 2002
+++ libc/sysdeps/alpha/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -328,7 +328,7 @@ $fixup_stack_ret:						\n\
 " RTLD_START_SPECIAL_INIT "					\n\
 	/* Call _dl_init(_dl_loaded, argc, argv, envp) to run	\n\
 	   initializers.  */					\n\
-	ldq	$16, _rtld_global				\n\
+	ldq	$16, _rtld_local				\n\
 	ldq	$17, 0($sp)					\n\
 	lda	$18, 8($sp)					\n\
 	s8addq	$17, 8, $19					\n\
--- libc/sysdeps/arm/dl-machine.h.jj	Mon Feb  4 17:34:53 2002
+++ libc/sysdeps/arm/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -324,7 +324,7 @@ _dl_start_user:
 .L_STACK_END:
 	.word	__libc_stack_end(GOT)
 .L_LOADED:
-	.word	_rtld_global(GOT)
+	.word	_rtld_local(GOT)
 .previous\n\
 ");
 
--- libc/sysdeps/generic/ldsodefs.h.jj	Thu Feb 28 12:33:16 2002
+++ libc/sysdeps/generic/ldsodefs.h	Thu Feb 28 16:08:44 2002
@@ -199,7 +199,11 @@ typedef void (*receiver_fct) (int, const
 # define GL(name) _##name
 #else
 # define EXTERN
-# define GL(name) _rtld_global._##name
+# ifdef _RTLD_LOCAL
+#  define GL(name) _rtld_local._##name
+# else
+#  define GL(name) _rtld_global._##name
+# endif
 struct rtld_global
 {
 #endif
@@ -371,6 +375,19 @@ struct rtld_global
 #ifdef SHARED
 };
 extern struct rtld_global _rtld_global;
+# ifdef _RTLD_LOCAL
+#  ifdef HAVE_VISIBILITY_ATTRIBUTE
+#   ifdef HAVE_SDATA_SECTION
+#    define __rtld_local_attribute__ \
+	    __attribute__ ((visibility ("hidden"), section (".sdata")))
+#   else
+#    define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
+#   endif
+#  else
+#   define __rtld_local_attribute__
+#  endif
+extern struct rtld_global _rtld_local __rtld_local_attribute__;
+# endif
 #endif
 #undef EXTERN
 
--- libc/sysdeps/hppa/dl-machine.h.jj	Mon Feb  4 17:35:18 2002
+++ libc/sysdeps/hppa/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -362,8 +362,8 @@ asm (									\
 "	stw	%r24,-44(%sp)\n"					\
 									\
 ".Lnofix:\n"								\
-"	addil	LT'_rtld_global,%r19\n"					\
-"	ldw	RT'_rtld_global(%r1),%r26\n"				\
+"	addil	LT'_rtld_local,%r19\n"					\
+"	ldw	RT'_rtld_local(%r1),%r26\n"				\
 "	bl	set_dp, %r2\n"						\
 "	ldw	0(%r26),%r26\n"						\
 									\
--- libc/sysdeps/cris/dl-machine.h.jj	Mon Feb  4 17:34:53 2002
+++ libc/sysdeps/cris/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -212,7 +212,7 @@ _dl_start_user:
 	move.d	$sp,$r12
 	addq	4,$r12
 	;  main_map: at _dl_loaded.
-	move.d	[$r0+_rtld_global:GOT16],$r9
+	move.d	[$r0+_rtld_local:GOT16],$r9
 	move.d	[$r9],$r10
 	move.d	_dl_init_internal:PLTG,$r9
 	add.d	$r0,$r9
--- libc/sysdeps/i386/dl-machine.h.jj	Mon Feb 18 23:39:52 2002
+++ libc/sysdeps/i386/dl-machine.h	Thu Feb 28 17:33:58 2002
@@ -239,11 +239,10 @@ _dl_start_user:\n\
 " RTLD_START_SPECIAL_INIT "\n\
 	# Load the parameters again.\n\
 	# (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
-	movl _rtld_global@GOT(%ebx), %esi\n\
-	leal 8(%esp,%edx,4), %eax\n\
+	movl _rtld_local@GOTOFF(%ebx), %eax\n\
+	leal 8(%esp,%edx,4), %esi\n\
 	leal 4(%esp), %ecx\n\
-	pushl %eax\n\
-	movl (%esi), %eax\n\
+	pushl %esi\n\
 	# Call the function to run the initializers.\n\
 	call _dl_init_internal@PLT\n\
 	# Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
--- libc/sysdeps/ia64/dl-machine.h.jj	Mon Feb  4 17:35:18 2002
+++ libc/sysdeps/ia64/dl-machine.h	Thu Feb 28 17:15:46 2002
@@ -381,7 +381,7 @@ elf_machine_runtime_setup (struct link_m
 "	{ .mmi\n"							      \
 "	  mov out3 = r11\n"						      \
 "	  sub r17 = r17, r3	/* Substract _dl_skip_args. */\n"	      \
-"	  addl out0 = @ltoff(_rtld_global), gp\n"			      \
+"	  addl out0 = @gprel(_rtld_local), gp\n"			      \
 "	}\n"								      \
 "1:	/* Copy env. */\n"						      \
 "	{ .mfi\n"							      \
@@ -396,11 +396,9 @@ elf_machine_runtime_setup (struct link_m
 "	}\n"								      \
 "	{ .mmb\n"							      \
 "	  st8 [r10] = out1		/* Record the new argc. */\n"	      \
-"	  ld8 out0 = [out0]\n"						      \
-"	  ;;\n"								      \
+"	  ld8 out0 = [out0]		/* get the linkmap */\n"	      \
 "	}\n"								      \
 "	{ .mmb\n"							      \
-"	  ld8 out0 = [out0]		/* get the linkmap */\n"	      \
 "	  st8 [r2] = r17		/* Load the new _dl_argv. */\n"	      \
 "	  br.call.sptk.many b0 = _dl_init_internal#\n"			      \
 "	  ;;\n"								      \
--- libc/sysdeps/m68k/dl-machine.h.jj	Mon Feb  4 17:35:19 2002
+++ libc/sysdeps/m68k/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -176,7 +176,7 @@ _dl_start_user:\n\
 	pea 8(%sp, %d1*4)\n\
 	pea 8(%sp)\n\
 	move.l %d1, -(%sp)\n\
-	move.l ([_rtld_global@GOT.w, %a5]), -(%sp)\n\
+	move.l ([_rtld_local@GOT.w, %a5]), -(%sp)\n\
 	jbsr _dl_init_internal@PLTPC\n\
 	addq.l #8, %sp\n\
 	addq.l #8, %sp\n\
--- libc/sysdeps/mips/mips64/dl-machine.h.jj	Mon Feb  4 17:35:19 2002
+++ libc/sysdeps/mips/mips64/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -480,7 +480,7 @@ _dl_start_user:\n\
 	# Save back the modified argument count.\n\
 	sd $4, 0($29)\n\
 1:	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
-	ld $4, _rtld_global\n\
+	ld $4, _rtld_local\n\
 	ld $5, 0($29)\n\
 	dla $6, 4($29)\n\
 	dla $7, 8($29)\n\
@@ -492,7 +492,7 @@ _dl_start_user:\n\
 	dla $31, _dl_fini\n\
 	# Jump to the user entry point.\n\
 1:	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
-	lw $4, _rtld_global\n\
+	lw $4, _rtld_local\n\
 	lw $5, 0($29)\n\
 	la $6, 4($29)\n\
 	la $7, 8($29)\n\
--- libc/sysdeps/mips/dl-machine.h.jj	Sat Feb  9 00:32:19 2002
+++ libc/sysdeps/mips/dl-machine.h	Thu Feb 28 16:48:57 2002
@@ -441,7 +441,7 @@ _dl_start_user:\n\
 	# Save back the modified argument count.\n\
 	sw $4, 0($29)\n\
 1:	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
-	lw $4, _rtld_global\n\
+	lw $4, _rtld_local\n\
 	lw $5, 0($29)\n\
 	la $6, 4($29)\n\
 	sll $7, $5, 2\n\
--- libc/sysdeps/sparc/sparc32/dl-machine.h.jj	Mon Feb  4 17:35:19 2002
+++ libc/sysdeps/sparc/sparc32/dl-machine.h	Thu Feb 28 16:48:58 2002
@@ -312,9 +312,9 @@ _dl_start_user:
 	bne	23b
 	 add	%i1, 8, %i1
   /* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp.  */
-3:	sethi	%hi(_rtld_global), %o0
+3:	sethi	%hi(_rtld_local), %o0
 	add	%sp, 23*4, %o2
-	orcc	%o0, %lo(_rtld_global), %o0
+	orcc	%o0, %lo(_rtld_local), %o0
 	sll	%i5, 2, %o3
 	ld	[%l7+%o0], %o0
 	add	%o3, 4, %o3
--- libc/sysdeps/sparc/sparc64/dl-machine.h.jj	Mon Feb  4 17:35:20 2002
+++ libc/sysdeps/sparc/sparc64/dl-machine.h	Thu Feb 28 16:48:58 2002
@@ -745,9 +745,9 @@ elf_machine_runtime_setup (struct link_m
 "	 add	%i1, 16, %i1\n"						\
 "	stx	%l5, [%l4]\n"						\
 "  /* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp.  */\n"	\
-"2:	sethi	%hi(_rtld_global), %o0\n"				\
+"2:	sethi	%hi(_rtld_local), %o0\n"				\
 "	add	%sp, " __S(STACK_BIAS) " + 23*8, %o2\n"			\
-"	orcc	%o0, %lo(_rtld_global), %o0\n"				\
+"	orcc	%o0, %lo(_rtld_local), %o0\n"				\
 "	sllx	%i5, 3, %o3\n"						\
 "	ldx	[%l7 + %o0], %o0\n"					\
 "	add	%o3, 8, %o3\n"						\
--- libc/sysdeps/sh/dl-machine.h.jj	Mon Feb  4 17:35:19 2002
+++ libc/sysdeps/sh/dl-machine.h	Thu Feb 28 16:48:58 2002
@@ -388,7 +388,7 @@ _dl_start_user:\n\
 .L_dl_init:\n\
 	.long _dl_init_internal@PLT\n\
 .L_dl_loaded:\n\
-	.long _rtld_global@GOT\n\
+	.long _rtld_local@GOT\n\
 .L_dl_starting_up:\n\
 	.long _dl_starting_up@GOT\n\
 .L_dl_fini:\n\
--- libc/sysdeps/s390/s390-32/dl-machine.h.jj	Mon Feb  4 17:35:19 2002
+++ libc/sysdeps/s390/s390-32/dl-machine.h	Thu Feb 28 16:48:58 2002
@@ -287,7 +287,7 @@ _dl_start_user:\n\
 	# Call the function to run the initializers.\n\
 	# Load the parameters:\n\
 	# (%r2, %r3, %r4, %r5) = (_dl_loaded, argc, argv, envp)\n\
-	l     %r2,_rtld_global@GOT(%r12)\n\
+	l     %r2,_rtld_local@GOT(%r12)\n\
 	l     %r2,0(%r2)\n\
 	l     %r3,96(%r15)\n\
 	la    %r4,100(%r15)\n\
--- libc/sysdeps/s390/s390-64/dl-machine.h.jj	Mon Feb  4 17:35:19 2002
+++ libc/sysdeps/s390/s390-64/dl-machine.h	Thu Feb 28 16:48:58 2002
@@ -262,7 +262,7 @@ _dl_start_user:\n\
 	# Call the function to run the initializers.\n\
 	# Load the parameters:\n\
 	# (%r2, %r3, %r4, %r5) = (_dl_loaded, argc, argv, envp)\n\
-	lghi  %r2,_rtld_global@GOT
+	lghi  %r2,_rtld_local@GOT
 	lg    %r2,0(%r2,%r12)\n\
 	lg    %r2,0(%r2)\n\
 	lg    %r3,160(%r15)\n\
--- libc/sysdeps/x86_64/dl-machine.h.jj	Mon Feb  4 17:35:21 2002
+++ libc/sysdeps/x86_64/dl-machine.h	Thu Feb 28 16:48:58 2002
@@ -250,7 +250,7 @@ _dl_start_user:\n\
 	# argc -> rsi\n\
 	movq %rdx, %rsi\n\
 	# _dl_loaded -> rdi\n\
-	movq _rtld_global@GOTPCREL(%rip), %rdi\n\
+	movq _rtld_local@GOTPCREL(%rip), %rdi\n\
 	movq (%rdi), %rdi\n\
 	# env -> rcx\n\
 	leaq 16(%rsp,%rdx,8), %rcx\n\
--- libc/configure.in.jj	Thu Feb 28 12:31:19 2002
+++ libc/configure.in	Thu Feb 28 13:23:13 2002
@@ -1001,6 +1001,44 @@ EOF
   AC_SUBST(libc_cv_asm_protected_directive)
   AC_DEFINE(HAVE_PROTECTED)
 
+  if test $libc_cv_asm_protected_directive = yes; then
+    AC_CACHE_CHECK(whether __attribute__((visibility())) is supported,
+		 libc_cv_visibility_attribute,
+		 [cat > conftest.c <<EOF
+		  int foo __attribute__ ((visibility ("hidden"))) = 1;
+		  int bar __attribute__ ((visibility ("protected"))) = 1;
+EOF
+		  libc_cv_visibility_attribute=no
+		  if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+		    if grep '\.hidden.*foo' conftest.s >/dev/null; then
+		      if grep '\.protected.*bar' conftest.s >/dev/null; then
+			libc_cv_visibility_attribute=yes
+		      fi
+		    fi
+		  fi
+		  rm -f conftest.[cs]
+		 ])
+    if test $libc_cv_visibility_attribute = yes; then
+      AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE)
+    fi
+  fi
+
+  if test $libc_cv_visibility_attribute = yes -a $gnu_ld = yes; then
+    AC_CACHE_CHECK(whether to put _rtld_local into .sdata section,
+		 libc_cv_have_sdata_section,
+		 [echo "int i;" > conftest.c
+		  libc_cv_have_sdata_section=no
+		  if ${CC-cc} -shared -Wl,--verbose conftest.c -o conftest.so 2>&1 \
+		     | grep '\.sdata' >/dev/null; then
+		    libc_cv_have_sdata_section=yes
+		  fi
+		  rm -f conftest.c conftest.so
+		 ])
+    if test $libc_cv_have_sdata_section = yes; then
+      AC_DEFINE(HAVE_SDATA_SECTION)
+    fi
+  fi
+
   AC_CACHE_CHECK(for -z nodelete option,
 		 libc_cv_z_nodelete, [dnl
   cat > conftest.c <<EOF
--- libc/configure.jj	Thu Feb 28 12:36:21 2002
+++ libc/configure	Thu Feb 28 13:23:28 2002
@@ -2806,6 +2806,62 @@ echo "$ac_t""$libc_cv_asm_protected_dire
 EOF
 
 
+  if test $libc_cv_asm_protected_directive = yes; then
+    echo $ac_n "checking whether __attribute__((visibility())) is supported""... $ac_c" 1>&6
+echo "configure:2812: checking whether __attribute__((visibility())) is supported" >&5
+if eval "test \"`echo '$''{'libc_cv_visibility_attribute'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.c <<EOF
+		  int foo __attribute__ ((visibility ("hidden"))) = 1;
+		  int bar __attribute__ ((visibility ("protected"))) = 1;
+EOF
+		  libc_cv_visibility_attribute=no
+		  if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+		    if grep '\.hidden.*foo' conftest.s >/dev/null; then
+		      if grep '\.protected.*bar' conftest.s >/dev/null; then
+			libc_cv_visibility_attribute=yes
+		      fi
+		    fi
+		  fi
+		  rm -f conftest.cs
+		 
+fi
+
+echo "$ac_t""$libc_cv_visibility_attribute" 1>&6
+    if test $libc_cv_visibility_attribute = yes; then
+      cat >> confdefs.h <<\EOF
+#define HAVE_VISIBILITY_ATTRIBUTE 1
+EOF
+
+    fi
+  fi
+
+  if test $libc_cv_visibility_attribute = yes -a $gnu_ld = yes; then
+    echo $ac_n "checking whether to put _rtld_local into .sdata section""... $ac_c" 1>&6
+echo "configure:2842: checking whether to put _rtld_local into .sdata section" >&5
+if eval "test \"`echo '$''{'libc_cv_have_sdata_section'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  echo "int i;" > conftest.c
+		  libc_cv_have_sdata_section=no
+		  if ${CC-cc} -shared -Wl,--verbose conftest.c -o conftest.so 2>&1 \
+		     | grep '\.sdata' >/dev/null; then
+		    libc_cv_have_sdata_section=yes
+		  fi
+		  rm -f conftest.c conftest.so
+		 
+fi
+
+echo "$ac_t""$libc_cv_have_sdata_section" 1>&6
+    if test $libc_cv_have_sdata_section = yes; then
+      cat >> confdefs.h <<\EOF
+#define HAVE_SDATA_SECTION 1
+EOF
+
+    fi
+  fi
+
   echo $ac_n "checking for -z nodelete option""... $ac_c" 1>&6
 echo "configure:2811: checking for -z nodelete option" >&5
 if eval "test \"`echo '$''{'libc_cv_z_nodelete'+set}'`\" = set"; then
--- libc/config.h.in.jj	Mon Feb 18 23:39:07 2002
+++ libc/config.h.in	Thu Feb 28 13:21:39 2002
@@ -102,6 +102,12 @@
 /* Define if the assembler supported .protected.  */
 #undef	HAVE_PROTECTED
 
+/* Define if the compiler supports __attribute__ ((visibility (...))).  */
+#undef	HAVE_VISIBILITY_ATTRIBUTE
+
+/* Define if _rtld_local structure should be forced into .sdata section.  */
+#undef	HAVE_SDATA_SECTION
+
 /* Define if binutils support TLS handling.  */
 #undef	HAVE_TLS_SUPPORT
 

	Jakub


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