]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: optionally emit _etext last, before .data
authorHans-Peter Nilsson <hp@bitrange.com>
Sun, 19 Jul 2020 04:08:07 +0000 (06:08 +0200)
committerHans-Peter Nilsson <hp@bitrange.com>
Sun, 19 Jul 2020 04:08:07 +0000 (06:08 +0200)
So, here's my suggestion for making _init .. __etext cover .text +
.rodata (including things like the read-only exception tables) for
elf64mmix.  A quick web search gives that __etext (and friends) isn't
well defined, so each target can interpret the "end of text segment"
to their own liking.  It seems likely this change is also a better fit
than the default for other ports, at least those with .rodata after
.text in the same segment.

The presence of a separate rodata-segment is optional (and not true
for elf64mmix).  This is reflected in the name as SEPARATE_TEXT /
SEPARATE_CODE isn't considered, to keep it simple; each target has to
make sure their settings of variables make sense.

ld:
* scripttempl/elf.sc (ETEXT_LAST_IN_RODATA_SEGMENT): New variable.
* emulparams/elf64mmix.sh (ETEXT_LAST_IN_RODATA_SEGMENT): Define.
* testsuite/ld-mmix/sec-1.d: Adjust.

ld/ChangeLog
ld/emulparams/elf64mmix.sh
ld/scripttempl/elf.sc
ld/testsuite/ld-mmix/sec-1.d

index 51a4e9c53bdc8eaad1d4780d30c22ee76b55e63a..37a94aa88068dbb356d3dce403ee06100a3df13e 100644 (file)
@@ -1,3 +1,9 @@
+2020-07-19  Hans-Peter Nilsson  <hp@bitrange.com>
+
+       * scripttempl/elf.sc (ETEXT_LAST_IN_RODATA_SEGMENT): New variable.
+       * emulparams/elf64mmix.sh (ETEXT_LAST_IN_RODATA_SEGMENT): Define.
+       * testsuite/ld-mmix/sec-1.d: Adjust.
+
 2020-07-19  Alan Modra  <amodra@gmail.com>
 
        * emultempl/ppc64elf.em (power10-stubs): Accept optional "auto" arg.
index dffc6cc6f7d11758b5d29843093e0de0662d1e2c..75e24be2e2a4ad56bf7da7bccb150becd597fff6 100644 (file)
@@ -44,6 +44,10 @@ ${RELOCATING+
  PROVIDE (Main = DEFINED (Main) ? Main : (DEFINED (_start) ? _start : _start.));
 }"
 
+# We need a symbol at the end of the read-only data, which is
+# colocated with the code.  We make __etext fit.
+ETEXT_LAST_IN_RODATA_SEGMENT=" "
+
 OTHER_SECTIONS='
  .MMIX.reg_contents :
  {
index 0b8b32a44076f54a85547ec2191e5ae58c322ed3..eb74743e5c31a5f70af25d8fe211e0ccd651c98f 100644 (file)
@@ -62,6 +62,9 @@
 #      OTHER_SYMBOLS - symbols to place right at the end of the script.
 #      ETEXT_NAME - name of a symbol for the end of the text section,
 #              normally etext.
+#      ETEXT_LAST_IN_RODATA_SEGMENT - emit ETEXT_NAME after all sections in
+#              the read-only data segment (which may or may not be equal to
+#              the code segment), instead of after just the code parts.
 #      SEPARATE_CODE - if set, .text and similar sections containing
 #              actual machine instructions must be in wholly disjoint
 #              pages from any other data, including headers
@@ -526,9 +529,9 @@ cat <<EOF
     KEEP (*(SORT_NONE(.fini)))
     ${RELOCATING+${FINI_END}}
   } ${FILL}
-  ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);}
-  ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);}
-  ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);}
+  ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT-PROVIDE (__${ETEXT_NAME} = .);}}
+  ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT-PROVIDE (_${ETEXT_NAME} = .);}}
+  ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT-PROVIDE (${ETEXT_NAME} = .);}}
   ${RELOCATING+${TEXT_SEGMENT_ALIGN}}
 EOF
 
@@ -574,6 +577,10 @@ cat <<EOF
   .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges${RELOCATING+*}) }
   ${TEXT_PLT+${PLT_NEXT_DATA+${PLT} ${OTHER_PLT_SECTIONS}}}
 
+  ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT+PROVIDE (__${ETEXT_NAME} = .);}}
+  ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT+PROVIDE (_${ETEXT_NAME} = .);}}
+  ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT+PROVIDE (${ETEXT_NAME} = .);}}
+
   ${RELOCATING+/* Adjust the address for the data segment.  We want to adjust up to
      the same address within the page on the next page up.  */}
   ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
index 5e31b3fd645bae78be09266598d834693af89799..6f82c8e91142e7ce0e7e67c9f159141b5a99ebae 100644 (file)
@@ -24,7 +24,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
 
 SYMBOL TABLE:
 #...
-0+1d g +\*ABS\* _etext
+0+30 g +\*ABS\* _etext
 #...
 2000000000000013 g +\*ABS\* __bss_start
 2000000000000013 g +\*ABS\* _edata