Browse Source

ldso_sh: add support for protected symbols to SH

Protected symbols should not be overridden by
symbols from other modules. Such symbols are exported
i.e. globally visible, but references from whithin
defining modules are satisfied locally.

Signed-off-by: Salvatore Cro <salvatore.cro@st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Salvatore Cro 14 năm trước cách đây
mục cha
commit
74407db52d
1 tập tin đã thay đổi với 24 bổ sung18 xóa
  1. 24 18
      ldso/ldso/sh/elfinterp.c

+ 24 - 18
ldso/ldso/sh/elfinterp.c

@@ -166,26 +166,32 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope,
 	reloc_type = ELF32_R_TYPE(rpnt->r_info);
 	symtab_index = ELF32_R_SYM(rpnt->r_info);
 	symbol_addr = 0;
-	symname = strtab + symtab[symtab_index].st_name;
 
 	if (symtab_index) {
-		symbol_addr = (unsigned long) _dl_find_hash(symname, scope, tpnt,
-							    elf_machine_type_class(reloc_type), &tls_tpnt);
-		/*
-		 * We want to allow undefined references to weak symbols - this might
-		 * have been intentional.  We should not be linking local symbols
-		 * here, so all bases should be covered.
-		 */
-
-		if (!symbol_addr
-			&& (ELF_ST_TYPE(symtab[symtab_index].st_info) != STT_TLS)
-			&& (ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK)) {
-			_dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
-			            _dl_progname, strtab + symtab[symtab_index].st_name);
-
-			/* Let the caller to handle the error: it may be non fatal if called from dlopen */
-			return 1;
-		}
+		symname = strtab + symtab[symtab_index].st_name;
+		if (ELF32_ST_VISIBILITY(symtab[symtab_index].st_other)
+			 != STV_PROTECTED) {
+			symbol_addr = (unsigned long) _dl_find_hash(symname, scope, tpnt,
+								elf_machine_type_class(reloc_type), &tls_tpnt);
+			/*
+			 * We want to allow undefined references to weak symbols - this might
+			 * have been intentional.  We should not be linking local symbols
+			 * here, so all bases should be covered.
+			 */
+
+			if (!symbol_addr
+				&& (ELF_ST_TYPE(symtab[symtab_index].st_info) != STT_TLS)
+				&& (ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK)) {
+				_dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
+				            _dl_progname, strtab + symtab[symtab_index].st_name);
+
+				/* Let the caller to handle the error: it may be non fatal if called from dlopen */
+				return 1;
+			}
+		} else
+			/* Resolve protected symbols locally */
+			symbol_addr = DL_FIND_HASH_VALUE(tpnt, elf_machine_type_class(reloc_type),
+											&symtab[symtab_index]);
 	}
 
 #if defined (__SUPPORT_LD_DEBUG__)