public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Output section type (READONLY)
@ 2022-01-29  7:45 Fangrui Song
  2022-01-29 16:46 ` Luca Boccassi
  2022-01-31 13:33 ` Nick Clifton
  0 siblings, 2 replies; 15+ messages in thread
From: Fangrui Song @ 2022-01-29  7:45 UTC (permalink / raw)
  To: Alan Modra, Nick Clifton; +Cc: binutils, Luca Boccassi

[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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-02-21 23:37 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29  7:45 Output section type (READONLY) 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
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

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).