From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id 0E4823858D1E; Wed, 20 Apr 2022 21:55:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E4823858D1E Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/release/2.35/master] m68k: Handle fewer relocations for RTLD_BOOTSTRAP (#BZ29071) X-Act-Checkin: glibc X-Git-Author: Fangrui Song X-Git-Refname: refs/heads/release/2.35/master X-Git-Oldrev: 68d3a9a69696b46f2e552330dd0de5512c36302d X-Git-Newrev: d3feff2232ec27f05ca619ca8b314155d9018224 Message-Id: <20220420215502.0E4823858D1E@sourceware.org> Date: Wed, 20 Apr 2022 21:55:02 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2022 21:55:02 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d3feff2232ec27f05ca619ca8b314155d9018224 commit d3feff2232ec27f05ca619ca8b314155d9018224 Author: Fangrui Song Date: Wed Apr 20 10:24:15 2022 -0700 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 (cherry picked from commit a8e9b5b8079d18116ca69c9797e77804ecf2ee7e) Diff: --- sysdeps/m68k/dl-machine.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sysdeps/m68k/dl-machine.h b/sysdeps/m68k/dl-machine.h index c44ab055aa..bb51b4198c 100644 --- a/sysdeps/m68k/dl-machine.h +++ b/sysdeps/m68k/dl-machine.h @@ -234,6 +234,11 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], switch (r_type) { + case R_68K_GLOB_DAT: + case R_68K_JMP_SLOT: + *reloc_addr = value; + break; +#ifndef RTLD_BOOTSTRAP case R_68K_COPY: if (sym == NULL) /* 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, MIN (sym->st_size, refsym->st_size)); break; - case R_68K_GLOB_DAT: - case R_68K_JMP_SLOT: - *reloc_addr = value; - break; case R_68K_8: *(char *) reloc_addr = value + reloc->r_addend; break; @@ -276,7 +277,6 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], case R_68K_PC32: *reloc_addr = value + reloc->r_addend - (Elf32_Addr) reloc_addr; break; -#ifndef RTLD_BOOTSTRAP case R_68K_TLS_DTPMOD32: /* Get the information from the link map returned by the 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); } break; -#endif /* !RTLD_BOOTSTRAP */ case R_68K_NONE: /* Alright, Wilbur. */ break; +#endif /* !RTLD_BOOTSTRAP */ default: _dl_reloc_bad_type (map, r_type, 0); break;