m68k: Handle fewer relocations for RTLD_BOOTSTRAP (#BZ29071)

m68k is a non-PI_STATIC_AND_HIDDEN arch which uses a GOT relocation when
loading the address of a jump table. The GOT load may be reordered
before processing R_68K_RELATIVE relocations, leading to an
unrelocated/incorrect jump table, which will cause a crash.

The foolproof approach is to add an optimization barrier (e.g. calling
an non-inlinable function after relative relocations are resolved). That
is non-trivial given the current code structure, so just use the simple
approach to avoid the jump table: handle only the essential reloctions
for RTLD_BOOTSTRAP code.

This is based on Andreas Schwab's patch and fixed ld.so crash on m68k.

Reviewed-by: Adheemrval Zanella  <adhemerval.zanella@linaro.org>
This commit is contained in:
Fangrui Song 2022-04-20 10:24:15 -07:00
parent 62be968167
commit a8e9b5b807

View File

@ -234,6 +234,11 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
switch (r_type) switch (r_type)
{ {
case R_68K_GLOB_DAT:
case R_68K_JMP_SLOT:
*reloc_addr = value;
break;
#ifndef RTLD_BOOTSTRAP
case R_68K_COPY: case R_68K_COPY:
if (sym == NULL) if (sym == NULL)
/* This can happen in trace mode if an object could not be /* This can happen in trace mode if an object could not be
@ -252,10 +257,6 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
memcpy (reloc_addr_arg, (void *) value, memcpy (reloc_addr_arg, (void *) value,
MIN (sym->st_size, refsym->st_size)); MIN (sym->st_size, refsym->st_size));
break; break;
case R_68K_GLOB_DAT:
case R_68K_JMP_SLOT:
*reloc_addr = value;
break;
case R_68K_8: case R_68K_8:
*(char *) reloc_addr = value + reloc->r_addend; *(char *) reloc_addr = value + reloc->r_addend;
break; break;
@ -276,7 +277,6 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
case R_68K_PC32: case R_68K_PC32:
*reloc_addr = value + reloc->r_addend - (Elf32_Addr) reloc_addr; *reloc_addr = value + reloc->r_addend - (Elf32_Addr) reloc_addr;
break; break;
#ifndef RTLD_BOOTSTRAP
case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPMOD32:
/* Get the information from the link map returned by the /* Get the information from the link map returned by the
resolv function. */ resolv function. */
@ -294,9 +294,9 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
*reloc_addr = TLS_TPREL_VALUE (sym_map, sym, reloc); *reloc_addr = TLS_TPREL_VALUE (sym_map, sym, reloc);
} }
break; break;
#endif /* !RTLD_BOOTSTRAP */
case R_68K_NONE: /* Alright, Wilbur. */ case R_68K_NONE: /* Alright, Wilbur. */
break; break;
#endif /* !RTLD_BOOTSTRAP */
default: default:
_dl_reloc_bad_type (map, r_type, 0); _dl_reloc_bad_type (map, r_type, 0);
break; break;