public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR26378, sections initialised only by linker scripts are always read/write
Date: Mon, 18 Jan 2021 23:10:01 +1030	[thread overview]
Message-ID: <20210118124001.GV26219@bubble.grove.modra.org> (raw)

This changes the initialisation of output sections so that it is
possible to create read-only sections fed only from linker script
BYTE, SHORT, LONG or QUAD.  That currently isn't possible even for one
of the well-known ELF sections like .rodata, because once a section is
marked read/write that sticks.  On the other hand if we start
read-only, well-known ELF sections end up read/write as appropriate.
For example .tdata will still be SHF_ALLOC + SHF_WRITE + SHF_TLS.

There is a possibility this change will break something, which is why
I'm committing it early in the 2.37 development cycle to give us a
good chance of finding problems before the 2.37 release.

	PR 26378
	* ldlang.c (map_input_to_output_sections): Start with a read-only
	section for data statements.
	* testsuite/ld-elf/size-2.d: Adjust to suit.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 4ae9cec8853..8014e7a6eef 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -4225,7 +4225,7 @@ map_input_to_output_sections
 	      break;
 	    }
 	  if (os->bfd_section == NULL)
-	    init_os (os, flags);
+	    init_os (os, flags | SEC_READONLY);
 	  else
 	    os->bfd_section->flags |= flags;
 	  break;
diff --git a/ld/testsuite/ld-elf/size-2.d b/ld/testsuite/ld-elf/size-2.d
index 14202245e6c..9f1a9cf48fa 100644
--- a/ld/testsuite/ld-elf/size-2.d
+++ b/ld/testsuite/ld-elf/size-2.d
@@ -11,7 +11,7 @@
 .* \.text +PROGBITS +0+100 [0-9a-f]+ 0+10 00  AX .*
 .* \.tdata +PROGBITS +0+110 [0-9a-f]+ 0+20 00 WAT .*
 .* \.tbss +NOBITS +0+130 [0-9a-f]+ 0+30 00 WAT .*
-.* \.map +PROGBITS +0+130 [0-9a-f]+ 0+c 00 +WA .*
+.* \.map +PROGBITS +0+130 [0-9a-f]+ 0+c 00 +A .*
 #...
  +PHDR +(0x0+40 0x0+40 0x0+40 0x0+a8 0x0+a8|0x0+34 0x0+34 0x0+34 0x0+60 0x0+60|0x0+34 0x0+a0 0x0+a0 0x0+60 0x0+60) R .*
  +LOAD +(0x0+40 0x0+40 0x0+40 0x0+fc 0x0+fc|0x0+34 0x0+34 0x0+34 0x0+1(08|10) 0x0+1(08|10)|0x0+34 0x0+a0 0x0+a0 0x0+9c 0x0+9c) R E .*

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2021-01-18 12:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210118124001.GV26219@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@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).