From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 3B1923858D34; Sun, 14 Apr 2024 07:06:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B1923858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713078376; bh=ByzQUMajY2JXLGuBaZiuKjnIGhFegfwxEO6VwvnL41w=; h=From:To:Subject:Date:From; b=gIU5RhKmD1hy/30AMIOanqrN2c1YCiOOIMhFUUY5VvzrX6eyKZ9JG+MFvwa9akocF uXBtaNA/9yfkjaT6pFiEY3qieYktm8U2dRf2JAkh8mwRS+TzN6LE91HvHHwal+BxpC VwG0pp4kUXZvOpPIGOv2LHcojDtzFnISJoNcjK+U= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc/release/2.39/master] powerpc: Fix ld.so address determination for PCREL mode (bug 31640) X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/release/2.39/master X-Git-Oldrev: 7b92f46f04c6cbce19d19ae1099628431858996c X-Git-Newrev: edb9a76e3008725e9dc035d38a58e849a3bde0f1 Message-Id: <20240414070616.3B1923858D34@sourceware.org> Date: Sun, 14 Apr 2024 07:06:16 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=edb9a76e3008725e9dc035d38a58e849a3bde0f1 commit edb9a76e3008725e9dc035d38a58e849a3bde0f1 Author: Florian Weimer Date: Sun Apr 14 08:24:51 2024 +0200 powerpc: Fix ld.so address determination for PCREL mode (bug 31640) This seems to have stopped working with some GCC 14 versions, which clobber r2. With other compilers, the kernel-provided r2 value is still available at this point. Reviewed-by: Peter Bergner (cherry picked from commit 14e56bd4ce15ac2d1cc43f762eb2e6b83fec1afe) Diff: --- sysdeps/powerpc/powerpc64/dl-machine.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h index c6682f3445..2b6f5d2b08 100644 --- a/sysdeps/powerpc/powerpc64/dl-machine.h +++ b/sysdeps/powerpc/powerpc64/dl-machine.h @@ -78,6 +78,7 @@ elf_host_tolerates_class (const Elf64_Ehdr *ehdr) static inline Elf64_Addr elf_machine_load_address (void) __attribute__ ((const)); +#ifndef __PCREL__ static inline Elf64_Addr elf_machine_load_address (void) { @@ -105,6 +106,24 @@ elf_machine_dynamic (void) /* Then subtract off the load address offset. */ return runtime_dynamic - elf_machine_load_address() ; } +#else /* __PCREL__ */ +/* In PCREL mode, r2 may have been clobbered. Rely on relative + relocations instead. */ + +static inline ElfW(Addr) +elf_machine_load_address (void) +{ + extern const ElfW(Ehdr) __ehdr_start attribute_hidden; + return (ElfW(Addr)) &__ehdr_start; +} + +static inline ElfW(Addr) +elf_machine_dynamic (void) +{ + extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; + return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address (); +} +#endif /* __PCREL__ */ /* The PLT uses Elf64_Rela relocs. */ #define elf_machine_relplt elf_machine_rela