Bug 27923 - ld: Support DT_RELR relative relocation format
Summary: ld: Support DT_RELR relative relocation format
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: 2.38
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-27 17:56 UTC by Fangrui Song
Modified: 2024-02-16 02:01 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-10-29 00:00:00
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-05-27 17:56:27 UTC
The latter part of https://sourceware.org/pipermail/binutils/2020-May/111086.html

Position independent executables and shared objects with -Bsymbolic/-Bsymbolic-functions may have many relative relocations (instead of absolute relocations (e.g. R_X86_64_64)).

Relative relocations can be packed in a compact format to save a lot of space. See the last few messages on https://groups.google.com/g/generic-abi/c/bX460iggiKg

DT_RELR has support in the Linux kernel (arch/arm64/Kconfig ARCH_HAS_RELR) since 2019 https://git.kernel.org/linus/5cf896fb6be3effd9aea455b22213e27be8bdb1d
Comment 1 Anna Lucca 2021-06-02 05:02:00 UTC Comment hidden (spam)
Comment 2 H.J. Lu 2021-10-18 14:45:41 UTC
[hjl@gnu-cfl-2 tmp]$ gcc -pie -fPIE -O2 tst-relr.c
-Wl,--pack-dyn-relocs=relr -fuse-ld=lld
[hjl@gnu-cfl-2 tmp]$ ./a.out
Segmentation fault (core dumped)
[hjl@gnu-cfl-2 tmp]$

Given that the current lld implementation generates broken
binaries for existing glibc without any warning at run-time,
we need a different linker command line option to implement
it properly so that the new binary will fail to run on glibc
without DT_RELR support at run-time.

We can do "-z relr=glibc" which generates DT_RELR and adds a
glibc version dependency against the first version of glibc
with DT_RELR support.
Comment 3 H.J. Lu 2021-10-26 18:40:47 UTC
(In reply to H.J. Lu from comment #2)
> 
> We can do "-z relr=glibc" which generates DT_RELR and adds a
> glibc version dependency against the first version of glibc
> with DT_RELR support.

Here is the proposal:

https://sourceware.org/pipermail/binutils/2021-October/118292.html
Comment 4 H.J. Lu 2021-10-29 13:13:44 UTC
We need an updated proposal without mysterious crashes.  One option
is that the linker should bump EI_ABIVERSION when generating DT_RELR.
Comment 5 H.J. Lu 2022-01-12 14:26:15 UTC
Fixed for i386 and x86-64 by

commit 72aa81732b3aff00e5bf1f69bb794513b3b37464
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jan 5 19:21:45 2022 -0800

    ld: Add glibc dependency for DT_RELR
    
    When DT_RELR is enabled, to avoid random run-time crash with older glibc
    binaries without DT_RELR support, add a GLIBC_ABI_DT_RELR symbol version,
    which is provided by glibc with DT_RELR support, dependency on the shared
    C library if it provides a GLIBC_2.XX symbol version.
Comment 6 Alan Modra 2024-02-16 02:01:09 UTC
Also supported on powerpc64