public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org,
	"Frédéric Rivière" <frederic.riviere@microej.com>
Subject: Re: load of in-place relocation addend in AArch64
Date: Thu, 28 Mar 2024 00:10:52 -0700	[thread overview]
Message-ID: <DS7PR12MB5765D2B7676629B643DBAB22CB3B2@DS7PR12MB5765.namprd12.prod.outlook.com> (raw)
In-Reply-To: <56093691-58df-4917-99e7-41a47e5e1e5d@microej.com>

On Sun, Dec 10, 2023 at 11:51 PM Frédéric Rivière
<frederic.riviere@microej.com> wrote:
>
> Hi Nick,
>
> I understand the reason and I agree with a warning, because in the
> meantime I realized that REL relocations are correctly supported when
> there is no in-place addend.
>
> So we could improve the message as following:
>
> "Warning: REL type relocations are not expected for architecture
> 'aarch64' - in-place addends with non-zero values are not supported."
>
> Also I believe it would be perfect if this message could be printed only
> during the relocation process, to avoid impacting the other tools.
>
> I'm not familiar with LD code base but is there any chance to be able to
> retrieve the original relocation kind when we are in the
> "elfNN_aarch64_relocate_section" function ?
>
> (for example by being able to retrieve the original relocation section
> type or the relocation entry size for example)
>
> Best Regards,
>
> --Frédéric

I'd love to see better REL support :), at least for static data
relocations (generated from .long/.quad).

While REL is often inadequate for static code relocations because the
instruction to be modified (commonly 4 bytes on RISC architectures)
limits the available space for the addend,
using RELA can be unnecessarily bulky for data and debug sections
where the constraints on addend size don't apply.

I have made a quick analysis using a modified clang.
In a -O0 -g -gpubnames build, using REL for non-code sections
(sections without the SHF_EXECINSTR flag) decreased relocation size by
27.1% and the .o file size by 6.4%.

```
         |reloc size | .o size
---------+-----------+------------
RELA     | 550519056 | 2339938120
REL data | 401209104 | 2190607000  -Wa,--implicit-addends-for-data
CREL     |  44865612 | 1834284744  -Wa,--crel,--implicit-addends-for-data
```

I have filed https://sourceware.org/bugzilla/show_bug.cgi?id=31567
("gas/ld: Implicit addends for non-code sections").
LLVM RFC: https://discourse.llvm.org/t/rfc-implicit-addends-for-non-code-sections/78000

> On 12/7/2023 6:16 PM, Nick Clifton wrote:
> > Hi Frédéric,
> >
> >   OK, I have produced a small patch (attached) which adds this warning
> >   message to the linker's output:
> >
> >     $ ld test_AArch64_with_REL.o
> >     ld: test_AArch64_with_REL.o: Warning: REL type relocations are not
> > expected for architecture 'aarch64' - support may be incomplete
> >
> >   This warning does not actually stop the link from completing however.
> >   The reason for this is that the code where the relocations are loaded
> >   is shared by other tools, which do still work with REL relocations.
> >   For example the objdump tool is able to display the relocations without
> >   any problems:
> >
> >     $ objdump -r test_AArch64_with_REL.o
> >     BFD: test_AArch64_with_REL.o: Warning: REL type relocations are
> > not expected for architecture 'aarch64' - support may be incomplete
> >
> >     test_AArch64_with_REL.o:     file format elf64-littleaarch64
> >
> >     RELOCATION RECORDS FOR
> > [.text.__icetea__virtual__com_is2t_icetea_support_test_BImpl___bar__I]:
> >     OFFSET           TYPE              VALUE
> >     0000000000000008 R_AARCH64_ABS32
> > com_is2t_icetea_support_test_AImpl___bar
> >     [...]
> >
> >   This strikes me as a compromise solution at best, but it is better
> >   than the current situation nonetheless.
> >
> >   What do you think ?
> >
> > Cheers
> >   Nick
> >
> >
> >
> --
> MicroEJ <http://www.microej.com>
>
> Frédéric RIVIERE
> /CTO Office Member & VP Product/
>
> 11 rue du Chemin Rouge - Bat. D 44373 Nantes Cedex 3, France
> https://www.linkedin.com/in/fredericriviere/
>
> Twitter <https://twitter.com/microej> LinkedIn
> <https://www.linkedin.com/company/microej> Youtube
> <https://www.youtube.com/@MicroEJ_News>
>
> event <https://www.microej.com/event/>
>
> This email (and all attachments) may contain information that is
> proprietary privileged, and/or confidential. If you received this e-mail
> in error or if it was improperly forwarded to you, the information
> contained in the e-mail should, at all times, remain confidential.
> Please notify the sender immediately by e-mail, and delete or destroy
> the original and any copies. Any unauthorized use, disclosure,
> reproduction, retention or distribution by any person other than the
> intended recipient is strictly prohibited.
>

      reply	other threads:[~2024-03-28  7:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06  8:08 Frédéric Rivière
2023-12-06 11:14 ` Nick Clifton
2023-12-06 15:02   ` Frédéric Rivière
2023-12-06 15:31     ` Nick Clifton
2023-12-06 16:56       ` Frédéric Rivière
2023-12-07 17:16         ` Nick Clifton
2023-12-11  7:51           ` Frédéric Rivière
2024-03-28  7:10             ` Fangrui Song [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=DS7PR12MB5765D2B7676629B643DBAB22CB3B2@DS7PR12MB5765.namprd12.prod.outlook.com \
    --to=i@maskray.me \
    --cc=binutils@sourceware.org \
    --cc=frederic.riviere@microej.com \
    --cc=nickc@redhat.com \
    /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).