public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Michael Matz <matz@suse.de>
To: Fangrui Song <i@maskray.me>
Cc: Luca Boccassi <bluca@debian.org>,
	 "binutils@sourceware.org" <binutils@sourceware.org>
Subject: Re: Output section type (READONLY)
Date: Wed, 2 Feb 2022 16:54:57 +0000 (UTC)	[thread overview]
Message-ID: <alpine.LSU.2.20.2202021649230.3972@wotan.suse.de> (raw)
In-Reply-To: <MWHPR1201MB0110C90C35792AD3DCB7006FCB279@MWHPR1201MB0110.namprd12.prod.outlook.com>

Hello,

On Tue, 1 Feb 2022, Fangrui Song wrote:

> On 2022-02-01, Luca Boccassi wrote:
> >> > For READONLY, I am thinking more in line with "whether we need this
> >> > feature at all"... If no input has SHF_WRITE, the output naturally
> >> does
> >> > not have SHF_WRITE; if an input has SHF_WRITE, chancing the output
> >> to
> >> > non-SHF_WRITE is weird and error-prone.
> >>
> >> I do not know if this counts as a *justified* use of READONLY, but it
> >> was
> >> used recently in an attempt to add a new feature to Fedora rawhide:
> >>
> >>
> >> https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects#New_system:_.note.package
> >>
> >> The feature used a custom linker script fragment to add a note
> >> section
> >> into the executable being created, and this script used the READONLY
> >> keyword:
> >>
> >>    SECTIONS
> >>    {
> >>      .note.package (READONLY) : ALIGN(4) {
> >>          BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of
> >> Owner including NUL */
> >>   [...]
> >>      }
> >>    }
> >>    INSERT AFTER .note.gnu.build-id;
> 
> Yes, I recently learned that Fedora started to use (READONLY).
> The usage feels strange to me as .note.package should not have the
> SHF_WRITE flag, even without READONLY....
> 
> In https://sourceware.org/bugzilla/show_bug.cgi?id=26378#c11 , Alan
> changed such sections to be read-only by default in 2020 to support a
> Linux use case. I do not understand why a new keyword has to be
> invented...

Agreed.

> The next thing I feel uncomfortable with is the abuse of .note* indicates
> a SHT_NOTE section. The type, in my opinion, should be explicitly
> specified. In ELF, attributes are identified as well known integers.
> The magic section prefix ".note" is contrary to this.
> 
> I shall add a note that gold doesn't magically set an output section .note*
> to SHT_NOTE and this behavior makes a lot of sense to me.
> 
> To allow forward progress, I created
> https://sourceware.org/pipermail/binutils/2022-February/119591.html
> (ld: Support customized output section type) and I'd recommend that the
> linker script fragment
> 
>    .note.package (READONLY) : ALIGN(4) {
> 
> switches to
> 
>    .note.package (TYPE=SHT_NOTE) : ALIGN(4) {

Also agreed.

(We can't remove the implicit .note* -> SHT_NOTE behaviour anymore, but it 
shouldn't have been there from the beginning).

> >> This turned out to be problematic however as gold does not support
> >> the
> >> READONLY attribute, nor the INSERT AFTER directive...
> 
> This is the reason that I really recommend a synthesized .o file,
> instead of a synthesized output section description using data
> commands...

More agreement.  I also think that the synthesized sections should rather 
be thought of as and handled like (by ld) input sections, going through 
the normal linker processing (which would remove the need for "INSERT 
AFTER").  That's a largish change, so not something we can do now anymore, 
probably.

IOW: I think the introduction of READONLY was ill-advised :-/  But, ... 
well :)


Ciao,
Michael.

  reply	other threads:[~2022-02-02 16:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29  7:45 Fangrui Song
2022-01-29 16:46 ` Luca Boccassi
2022-01-29 18:51   ` Fangrui Song
2022-01-31 13:33 ` Nick Clifton
2022-02-01  3:39   ` Fangrui Song
2022-02-01 11:07     ` Nick Clifton
2022-02-01 11:59       ` Luca Boccassi
2022-02-02  7:29         ` Fangrui Song
2022-02-02 16:54           ` Michael Matz [this message]
2022-02-02 18:12             ` Luca Boccassi
2022-02-16 17:38               ` Nick Clifton
2022-02-16 19:03                 ` Luca Boccassi
2022-02-17  2:12                 ` Fangrui Song
2022-02-21 23:04                   ` Alan Modra
2022-02-21 23:30                     ` Fangrui Song

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=alpine.LSU.2.20.2202021649230.3972@wotan.suse.de \
    --to=matz@suse.de \
    --cc=binutils@sourceware.org \
    --cc=bluca@debian.org \
    --cc=i@maskray.me \
    /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).