public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Fāng-ruì Sòng" <maskray@google.com>
To: Carlos O'Donell <carlos@redhat.com>,
	Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org, binutils@sourceware.org
Subject: Re: [PATCH v2] elf: Support DT_RELR relative relocation format [BZ #27924]
Date: Sun, 31 Oct 2021 21:50:05 -0700	[thread overview]
Message-ID: <20211101045005.cgdr3dv2pczf5yjb@google.com> (raw)
In-Reply-To: <b6d5e23f-063a-1057-28c7-3dfd43525238@linaro.org>

On 2021-10-29, Adhemerval Zanella wrote:
>
>
>On 29/10/2021 16:35, Carlos O'Donell via Binutils wrote:
>> On 10/29/21 14:38, Fāng-ruì Sòng wrote:
>>> On Fri, Oct 29, 2021 at 11:21 AM Carlos O'Donell <carlos@redhat.com> wrote:
>>>>
>>>> On 10/16/21 20:50, Fangrui Song via Binutils wrote:
>>>>> PIE and shared objects usually have many relative relocations. In
>>>>> 2017/2018, SHT_RELR/DT_RELR was proposed on
>>>>> https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/GxjM0L-PBAAJ
>>>>> ("Proposal for a new section type SHT_RELR") and is a pre-standard. RELR
>>>>> usually takes 3% or smaller space than R_*_RELATIVE relocations. The
>>>>> virtual memory size of a mostly statically linked PIE is typically 5~10%
>>>>> smaller.
>>>>
>>>> We've been going over this patch on the weekly Monday patch queue review.
>>>>
>>>> I took a note to point out that one of the blockers here is that it is difficult
>>>> to immediately test this work because it requires a working glibc build using
>>>> ldd (which has support for DT_RELR).
>>>
>>> No:) There may be a misunderstanding.
>>>
>>> To test the feature: a DT_RELR executable is needed.
>>> Currently only ld.lld --pack-dyn-relocs=relr supports generating
>>> DT_RELR binaries,
>>> but glibc itself does not need to be linked with ld.lld.
>>
>> This is true.
>>
>> However, running the entire testsuite with ld.lld and DT_RELR gives wider coverage
>> and improves confidence in the feature.
>>
>>> If the patch is accepted, GNU ld built glibc will support DT_RELR
>>> programs linked by ld.lld.
>>
>> I agree, but in that scenario, lacking the ability to link the entire testsuite
>> with ld.lld reduces testing coverage for the feature.

I use a hacked /usr/local/bin/ld to link tst- test- objects with --pack-dyn-relocs=relr:

% cat /usr/local/bin/ld
#!/bin/zsh
output=
prev_arg=
for arg in "$@"; do
   [[ $prev_arg == -o ]] && output=$arg
   prev_arg=$arg
done

if [[ $output =~ 'tst-|test-' ]]; then
   exec ~/Stable/bin/ld.lld --pack-dyn-relocs=relr "$@"
else
   exec ~/Stable/bin/ld.lld "$@"
fi
% ~/Stable/bin/ld.lld --version
LLD 14.0.0 (compatible with GNU linkers)
% readelf -WS elf/tst-absolute-sym | grep relr.dyn
   [11] .relr.dyn         00000013: <unknown> 0000000000000f90 000f90 000020 08   A  0   0  8


Most tests pass, except the 7 nptl tests which spawn a gdb process and do some complex stuff with it:

% comm -3 <(grep '^FAIL' tests.sum | sort) <(grep '^FAIL' ../lld0/tests.sum | sort)
FAIL: nptl/test-condattr-printers
FAIL: nptl/test-cond-printers
FAIL: nptl/test-mutexattr-printers
FAIL: nptl/test-mutex-printers
FAIL: nptl/test-rwlockattr-printers
FAIL: nptl/test-rwlock-printers
FAIL: nptl/tst-pthread-gdb-attach-static

% cat nptl/test-condattr-printers.out
Error: Response does not match the expected pattern.
Command: print *condvar
Expected pattern: pthread_cond_t
Response:  Cannot access memory at address 0xffffd788
(gdb)



The 4000+ PASSes give me confidence that the DT_RELR does the right thing.



I read the generic-abi thread in 2019 but just noted that a comment from Ali Bahrami deserved my re-read
https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/0PMCJ0hjBAAJ

"My free advice (worth what you paid for it) is to roll out the support, and
  then wait a bit before turning on the use widely, so that the support is in
  place before it is needed, and to not complicate things with a way to
  catch time travelers. The window of time where this can be a problem
  is finite, and once you're past it, you'll be glad to have a simpler system."

I hope that I have captured the status well enough in https://maskray.me/blog/2021-10-31-relative-relocations-and-relr#glibc :)

>>>> What is the status of the lld support patches for glibc?
>>>
>>> aarch64 and x86-64 work well for me.
>>
>> ... but they aren't yet committed?
>>
>> Do we have a patchwork series for them?
>>
>> https://patchwork.sourceware.org/project/glibc/list/?series=4199
>>
>>> Seems that Adhemerval may be interested in adding a lld configuration
>>> to scripts/build-many-glibcs.py
>>
>> checking version of ld... 12.0.1, bad
>> ...
>> configure: error:
>> *** These critical programs are missing or too old: LLD
>> *** Check the INSTALL file for required versions.
>>
>> What's the fix for this?

13.0.0 is needed :)

>I summarized the previous status of glibc plus lld on [1].  In a short,
>only x86_64, i686, and aarch64 works without testcase regressions (i686
>does show one regression, elf/ifuncmain6pie).  I am working on arm,
>I could get it build and having the testcase without only 11 regression
>(all of them related to ifunc). I plan to send the patches soon.
>
>The powerpc builds but either loader or libc fails to run.  The riscv
>also builds with an extra patch to set -mno-relax (to avoid R_RISCV_ALIGN
>generation since lld does not support it), but I didn't not actually
>test if works as expected.
>
>The other supported architectures, sparc64 and mips, seems to be broken
>and it would require much more work.
>
>[1] https://sourceware.org/pipermail/libc-alpha/2021-October/132315.html

      reply	other threads:[~2021-11-01  4:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-17  0:50 Fangrui Song
2021-10-18 14:42 ` H.J. Lu
2021-10-18 16:16   ` Fāng-ruì Sòng
2021-10-18 17:28     ` H.J. Lu
2021-10-18 18:15       ` Fāng-ruì Sòng
2021-10-18 18:27         ` H.J. Lu
2021-10-18 19:19           ` Fāng-ruì Sòng
2021-10-18 19:44             ` H.J. Lu
2021-10-18 20:11               ` Fāng-ruì Sòng
2021-10-18 21:10                 ` Joseph Myers
2021-10-18 22:27                   ` H.J. Lu
2021-10-18 22:30                     ` Joseph Myers
2021-10-18 22:42                       ` H.J. Lu
2021-10-18 23:00                         ` Joseph Myers
2021-10-18 23:36                           ` H.J. Lu
2021-10-18 23:44                             ` Joseph Myers
2021-10-19  1:05                               ` H.J. Lu
2021-10-18 19:21       ` Joseph Myers
2021-10-18 19:45         ` H.J. Lu
2021-10-29 18:21 ` Carlos O'Donell
2021-10-29 18:36   ` H.J. Lu
2021-10-29 19:15     ` Fangrui Song
2021-10-29 18:38   ` Fāng-ruì Sòng
2021-10-29 19:35     ` Carlos O'Donell
2021-10-29 19:53       ` Adhemerval Zanella
2021-11-01  4:50         ` Fāng-ruì Sòng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211101045005.cgdr3dv2pczf5yjb@google.com \
    --to=maskray@google.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=binutils@sourceware.org \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).