public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: Alan Modra <amodra@gmail.com>, Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org, Luca Boccassi <luca.boccassi@microsoft.com>
Subject: Output section type (READONLY)
Date: Fri, 28 Jan 2022 23:45:45 -0800	[thread overview]
Message-ID: <20220129074545.csaig4kn5bk4si5k@gmail.com> (raw)

[PATCH v2] ld: add READONLY attribute for SECTIONS
(https://sourceware.org/pipermail/binutils/2021-July/117492.html) added
READONLY. There was no justification as to why it was added.

It was presumably to make an output section non-writable by default.
But for

   % cat output-section-types.t
   SECTIONS {
     .rom  (NOLOAD)   : { LONG(1234); }
     .ro (READONLY)   : { LONG(5678); }
     .over (OVERLAY)  : { LONG(0123); }
     /DISCARD/        : { *(*) }
   }

.ro does not have the SHF_WRITE flag even without (READONLY).
The unneeded SHF_WRITE flag has been fixed by Alan for
https://sourceware.org/bugzilla/show_bug.cgi?id=26378#c11 .

---

Well, READONLY has another behavior that it forces non-SHF_WRITE output
even if an input section has the SHF_WRITE flag.

   % cat output-section-types.t
   SECTIONS {
     .rom  (NOLOAD)   : { LONG(1234); }
     .ro (READONLY)   : { LONG(5678); *(.ro) }
     .over (OVERLAY)  : { LONG(0123); }
     /DISCARD/        : { *(*) }
   }
   % cat x.s
   .section .ro,"aw"
   .quad 0

The output .ro does not have SHF_WRITE. There is no warning.

  [ 2] .ro               PROGBITS        0000000000000004 001004 000004 00   A  0   0  1

I find this quite dangerous if an input section has the SHF_WRITE flag.
I do not see in what circumstances a user may want this behavior.
This just seems very dangerous to use in general.
What went lucky is that
https://sourceware.org/binutils/docs/ld/Output-Section-Type.html does not have
the feature listed yet, so hopefully very few people will be lured to use this.

             reply	other threads:[~2022-01-29  7:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29  7:45 Fangrui Song [this message]
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
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=20220129074545.csaig4kn5bk4si5k@gmail.com \
    --to=i@maskray.me \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=luca.boccassi@microsoft.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).