From de38b2a343e6d64b95c50004943d6107a9e380d0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 15 Jun 2022 11:29:55 -0700 Subject: elf: Remove ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA If an executable has copy relocations for extern protected data, that can only work if the library containing the definition is built with assumptions (a) the compiler emits GOT-generating relocations (b) the linker produces R_*_GLOB_DAT instead of R_*_RELATIVE. Otherwise the library uses its own definition directly and the executable accesses a stale copy. Note: the GOT relocations defeat the purpose of protected visibility as an optimization, but allow rtld to make the executable and library use the same copy when copy relocations are present, but it turns out this never worked perfectly. ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA has strange semantics when both a.so and b.so define protected var and the executable copy relocates var: b.so accesses its own copy even with GLOB_DAT. The behavior change is from commit 62da1e3b00b51383ffa7efc89d8addda0502e107 (x86) and then copied to nios2 (ae5eae7cfc9c4a8297ff82ec6b794faca1976ecc) and arc (0e7d930c4c11de896fe807f67fa1eb756c9c1e05). Without ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, b.so accesses the copy relocated data like a.so. There is now a warning for copy relocation on protected symbol since commit 7374c02b683b7110b853a32496a619410364d70b. It's extremely unlikely anyone relies on the ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA behavior, so let's remove it: this removes a check in the symbol lookup code. --- elf/dl-lookup.c | 60 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) (limited to 'elf') diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c index a42f6d5390..8cb32321da 100644 --- a/elf/dl-lookup.c +++ b/elf/dl-lookup.c @@ -456,59 +456,6 @@ do_lookup_x (const char *undef_name, unsigned int new_hash, if (sym != NULL) { found_it: - /* When UNDEF_MAP is NULL, which indicates we are called from - do_lookup_x on relocation against protected data, we skip - the data definion in the executable from copy reloc. */ - if (ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA - && undef_map == NULL - && map->l_type == lt_executable - && type_class == ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA) - { - const ElfW(Sym) *s; - unsigned int i; - -#if ! ELF_MACHINE_NO_RELA - if (map->l_info[DT_RELA] != NULL - && map->l_info[DT_RELASZ] != NULL - && map->l_info[DT_RELASZ]->d_un.d_val != 0) - { - const ElfW(Rela) *rela - = (const ElfW(Rela) *) D_PTR (map, l_info[DT_RELA]); - unsigned int rela_count - = map->l_info[DT_RELASZ]->d_un.d_val / sizeof (*rela); - - for (i = 0; i < rela_count; i++, rela++) - if (elf_machine_type_class (ELFW(R_TYPE) (rela->r_info)) - == ELF_RTYPE_CLASS_COPY) - { - s = &symtab[ELFW(R_SYM) (rela->r_info)]; - if (!strcmp (strtab + s->st_name, undef_name)) - goto skip; - } - } -#endif -#if ! ELF_MACHINE_NO_REL - if (map->l_info[DT_REL] != NULL - && map->l_info[DT_RELSZ] != NULL - && map->l_info[DT_RELSZ]->d_un.d_val != 0) - { - const ElfW(Rel) *rel - = (const ElfW(Rel) *) D_PTR (map, l_info[DT_REL]); - unsigned int rel_count - = map->l_info[DT_RELSZ]->d_un.d_val / sizeof (*rel); - - for (i = 0; i < rel_count; i++, rel++) - if (elf_machine_type_class (ELFW(R_TYPE) (rel->r_info)) - == ELF_RTYPE_CLASS_COPY) - { - s = &symtab[ELFW(R_SYM) (rel->r_info)]; - if (!strcmp (strtab + s->st_name, undef_name)) - goto skip; - } - } -#endif - } - /* Hidden and internal symbols are local, ignore them. */ if (__glibc_unlikely (dl_symbol_visibility_binds_local_p (sym))) goto skip; @@ -875,12 +822,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, for (scope = symbol_scope; *scope != NULL; i = 0, ++scope) if (do_lookup_x (undef_name, new_hash, &old_hash, *ref, &protected_value, *scope, i, version, flags, - skip_map, - (ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA - && ELFW(ST_TYPE) ((*ref)->st_info) == STT_OBJECT - && type_class == ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA) - ? ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA - : ELF_RTYPE_CLASS_PLT, NULL) != 0) + skip_map, ELF_RTYPE_CLASS_PLT, NULL) != 0) break; if (protected_value.s != NULL && protected_value.m != undef_map) -- cgit 1.4.1