PR26378, sections initialised only by linker scripts are always read/write
authorAlan Modra <amodra@gmail.com>
Sat, 12 Sep 2020 01:19:13 +0000 (10:49 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 18 Jan 2021 12:37:40 +0000 (23:07 +1030)
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.

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.

ld/ChangeLog
ld/ldlang.c
ld/testsuite/ld-elf/size-2.d

index 92fa8a4e1c36ef2df9b60a56a71358de979f7ed3..688a4427e828c7ba8f206a109e4ad8b97a0676d0 100644 (file)
@@ -1,3 +1,10 @@
+2021-01-18  Alan Modra  <amodra@gmail.com>
+
+       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.
+
 2021-01-17  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/27193
index 4ae9cec8853c9ce742e79b60e3a05c03af261244..8014e7a6eef503e669d9252f890729f01a1357ab 100644 (file)
@@ -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;
index 14202245e6c6cf696575dbd36cf94ff58a9efaed..9f1a9cf48fa192bda776306154f7275662672372 100644 (file)
@@ -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 .*
This page took 0.029086 seconds and 4 git commands to generate.