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] Add STB_SECONDARY support


Hi,

This patch adds STB_SECONDARY support to ld.so.  STB_SECONDARY symbols
behave exactly the same as STB_WEAK symbols when LD_DYNAMIC_WEAK is set.
OK to install after 2.17 is open?

Thanks.


H.J.
---
2012-06-30  H.J. Lu  <hongjiu.lu@intel.com>

	* elf/dl-addr.c (determine_info): Also check STB_SECONDARY.
	* elf/dl-lookup.c (do_lookup_x): Handle STB_SECONDARY.
	(_dl_lookup_symbol_x): Likewise.
	* elf/sprof.c (read_symbols): Likewise.
	* elf/elf.h (STB_SECONDARY): New.

diff --git a/elf/dl-addr.c b/elf/dl-addr.c
index 498faf1..dc2aca3 100644
--- a/elf/dl-addr.c
+++ b/elf/dl-addr.c
@@ -87,7 +87,8 @@ determine_info (const ElfW(Addr) addr, struct link_map *match, Dl_info *info,
 
       for (; (void *) symtab < (void *) symtabend; ++symtab)
 	if ((ELFW(ST_BIND) (symtab->st_info) == STB_GLOBAL
-	     || ELFW(ST_BIND) (symtab->st_info) == STB_WEAK)
+	     || ELFW(ST_BIND) (symtab->st_info) == STB_WEAK
+	     || ELFW(ST_BIND) (symtab->st_info) == STB_SECONDARY)
 	    && ELFW(ST_TYPE) (symtab->st_info) != STT_TLS
 	    && (symtab->st_shndx != SHN_UNDEF
 		|| symtab->st_value != 0)
diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
index a2a699b..877eb76 100644
--- a/elf/dl-lookup.c
+++ b/elf/dl-lookup.c
@@ -285,10 +285,15 @@ do_lookup_x (const char *undef_name, uint_fast32_t new_hash,
 	found_it:
 	  switch (__builtin_expect (ELFW(ST_BIND) (sym->st_info), STB_GLOBAL))
 	    {
+	    case STB_SECONDARY:
+	      /* Secondary definition.  Use this value if we don't find
+		 another.  */
+	      goto dynamic_weak;
 	    case STB_WEAK:
 	      /* Weak definition.  Use this value if we don't find another.  */
 	      if (__builtin_expect (GLRO(dl_dynamic_weak), 0))
 		{
+dynamic_weak:
 		  if (! result->s)
 		    {
 		      result->s = sym;
@@ -768,7 +773,9 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map,
 
   if (__builtin_expect (current_value.s == NULL, 0))
     {
-      if ((*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK)
+      if ((*ref == NULL
+	   || (ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK
+	       && ELFW(ST_BIND) ((*ref)->st_info) != STB_SECONDARY))
 	  && skip_map == NULL
 	  && !(GLRO(dl_debug_mask) & DL_DEBUG_UNUSED))
 	{
diff --git a/elf/elf.h b/elf/elf.h
index 6522ea6..9802f8a 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -444,7 +444,8 @@ typedef struct
 #define STB_LOCAL	0		/* Local symbol */
 #define STB_GLOBAL	1		/* Global symbol */
 #define STB_WEAK	2		/* Weak symbol */
-#define	STB_NUM		3		/* Number of defined types.  */
+#define STB_SECONDARY	3		/* Secondary symbol */
+#define	STB_NUM		4		/* Number of defined types.  */
 #define STB_LOOS	10		/* Start of OS-specific */
 #define STB_GNU_UNIQUE	10		/* Unique symbol.  */
 #define STB_HIOS	12		/* End of OS-specific */
diff --git a/elf/sprof.c b/elf/sprof.c
index 2097d31..2325180 100644
--- a/elf/sprof.c
+++ b/elf/sprof.c
@@ -1078,7 +1078,8 @@ read_symbols (struct shobj *shobj)
 	    newsym->name = &shobj->strtab[sym->st_name];
 	    newsym->addr = sym->st_value;
 	    newsym->size = sym->st_size;
-	    newsym->weak = ELFW(ST_BIND) (sym->st_info) == STB_WEAK;
+	    newsym->weak = (ELFW(ST_BIND) (sym->st_info) == STB_SECONDARY
+			    || ELFW(ST_BIND) (sym->st_info) == STB_WEAK);
 	    newsym->hidden = (ELFW(ST_VISIBILITY) (sym->st_other)
 			      != STV_DEFAULT);
 	    newsym->ticks = 0;
@@ -1136,7 +1137,8 @@ read_symbols (struct shobj *shobj)
 	      newsym->name = &strtab[symtab->st_name];
 	      newsym->addr = symtab->st_value;
 	      newsym->size = symtab->st_size;
-	      newsym->weak = ELFW(ST_BIND) (symtab->st_info) == STB_WEAK;
+	      newsym->weak = (ELFW(ST_BIND) (symtab->st_info) == STB_SECONDARY
+			      || ELFW(ST_BIND) (symtab->st_info) == STB_WEAK);
 	      newsym->hidden = (ELFW(ST_VISIBILITY) (symtab->st_other)
 				!= STV_DEFAULT);
 	      newsym->ticks = 0;
-- 
1.7.10.2


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