Thread (6 messages) 6 messages, 5 authors, 2022-03-11

Re: [PATCH] powerpc: Replace ppc64 DT_RELACOUNT usage with DT_RELASZ/24

flat view

From: Alexey Kardashevskiy <hidden>
Date: 2022-03-11 04:36:10
Also in: lkml, llvm


On 3/11/22 15:15, Michael Ellerman wrote:
Fāng-ruì Sòng [off-list ref] writes:
quoted
On Thu, Mar 10, 2022 at 11:48 AM Nick Desaulniers
[off-list ref] wrote:
quoted
On Tue, Mar 8, 2022 at 9:53 PM Fangrui Song [off-list ref] wrote:
quoted
DT_RELACOUNT is an ELF dynamic tag inherited from SunOS indicating the
number of R_*_RELATIVE relocations. It is optional but {ld.lld,ld.lld}
-z combreloc always creates it (if non-zero) to slightly speed up glibc
ld.so relocation resolving by avoiding R_*R_PPC64_RELATIVE type
comparison. The tag is otherwise nearly unused in the wild and I'd
recommend that software avoids using it.

lld>=14.0.0 (since commit da0e5b885b25cf4ded0fa89b965dc6979ac02ca9)
underestimates DT_RELACOUNT for ppc64 when position-independent long
branch thunks are used. Correcting it needs non-trivial arch-specific
complexity which I'd prefer to avoid. Since our code always compares the
relocation type with R_PPC64_RELATIVE, replacing every occurrence of
DT_RELACOUNT with DT_RELASZ/sizeof(Elf64_Rela)=DT_RELASZ/24 is a correct
alternative.
checking that sizeof(Elf64_Rela) == 24, yep: https://godbolt.org/z/bb4aKbo5T
quoted
DT_RELASZ is in practice bounded by an uint32_t. Dividing x by 24 can be
implemented as (uint32_t)(x*0xaaaaaaab) >> 4.
Yep: https://godbolt.org/z/x9445ePPv
quoted
Link: https://github.com/ClangBuiltLinux/linux/issues/1581
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Fangrui Song <redacted>
---
  arch/powerpc/boot/crt0.S       | 28 +++++++++++++++++-----------
  arch/powerpc/kernel/reloc_64.S | 15 +++++++++------
  2 files changed, 26 insertions(+), 17 deletions(-)
...
quoted
I rebased the patch on
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
master and got a conflict.
Seems that https://lore.kernel.org/linuxppc-dev/20220309061822.168173-1-aik@ozlabs.ru/T/#u (local)
("[PATCH kernel v4] powerpc/64: Add UADDR64 relocation support") fixed
the issue.
It just doesn't change arch/powerpc/boot/crt0.S
Yeah sorry, I applied Alexey's v4 just before I saw your patch arrive on
the list.

If one of you can rework this so it applies on top that would be great :)

I guess it is me as now I have to add that UARRD64 thing to crt0.S as well, don't I?

And also we are giving up on the llvm ld having a bug with RELACOUNT?

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help