[3/4] ld: Include the text section order file in PE COFF linker scripts

Message ID 20240119194552.1255481-4-hjl.tools@gmail.com
State Unresolved
Headers
Series None |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

H.J. Lu Jan. 19, 2024, 7:45 p.m. UTC
  Include the text section order file in PE COFF linker scripts and enable
--text-section-ordering-file tests for PE COFF targets.

	* scripttempl/i386beos.sc: Include the text section order file.
	* scripttempl/i386go32.sc: Likewise.
	* scripttempl/mcorepe.sc: Likewise.
	* scripttempl/pe.sc: Likewise.
	* scripttempl/pep.sc: Likewise.
	* testsuite/ld-scripts/text-order-1a.d: Remove target.
	* testsuite/ld-scripts/text-order-1b.d: Likewise.
	* testsuite/ld-scripts/text-order-1c.d: Likewise.
	* testsuite/ld-scripts/text-order.exp: Only run for ELF and PE
	COFF targets.
---
 ld/scripttempl/i386beos.sc              | 1 +
 ld/scripttempl/i386go32.sc              | 1 +
 ld/scripttempl/mcorepe.sc               | 1 +
 ld/scripttempl/pe.sc                    | 1 +
 ld/scripttempl/pep.sc                   | 1 +
 ld/testsuite/ld-scripts/start.s         | 2 ++
 ld/testsuite/ld-scripts/text-order-1a.d | 1 -
 ld/testsuite/ld-scripts/text-order-1b.d | 1 -
 ld/testsuite/ld-scripts/text-order-1c.d | 1 -
 ld/testsuite/ld-scripts/text-order.exp  | 3 ++-
 10 files changed, 9 insertions(+), 4 deletions(-)
  

Patch

diff --git a/ld/scripttempl/i386beos.sc b/ld/scripttempl/i386beos.sc
index 6c512e67760..cc3d737b21c 100644
--- a/ld/scripttempl/i386beos.sc
+++ b/ld/scripttempl/i386beos.sc
@@ -60,6 +60,7 @@  SECTIONS
   {
     ${RELOCATING+ __text_start__ = . ;}
     ${RELOCATING+ KEEP (*(SORT_NONE(.init)))}
+    ${RELOCATING+INCLUDE config.text_section_ordering_file}
     *(.text)
     ${R_TEXT}
     *(.glue_7t)
diff --git a/ld/scripttempl/i386go32.sc b/ld/scripttempl/i386go32.sc
index 9b992279e4e..3a229319988 100644
--- a/ld/scripttempl/i386go32.sc
+++ b/ld/scripttempl/i386go32.sc
@@ -34,6 +34,7 @@  ${RELOCATING+ENTRY (${ENTRY})}
 SECTIONS
 {
   .text ${RELOCATING+ ${TARGET_PAGE_SIZE}+SIZEOF_HEADERS} : {
+    ${RELOCATING+INCLUDE config.text_section_ordering_file}
     *(.text)
     ${RELOCATING+*(.text.*)}
     ${RELOCATING+*(.gnu.linkonce.t*)}
diff --git a/ld/scripttempl/mcorepe.sc b/ld/scripttempl/mcorepe.sc
index 3262102e85e..13dc5b1c89e 100644
--- a/ld/scripttempl/mcorepe.sc
+++ b/ld/scripttempl/mcorepe.sc
@@ -66,6 +66,7 @@  SECTIONS
   .text ${RELOCATING+ __image_base__ + __section_alignment__ } :
   {
     ${RELOCATING+ KEEP (*(SORT_NONE(.init)))}
+    ${RELOCATING+INCLUDE config.text_section_ordering_file}
     *(.text)
     ${R_TEXT}
     ${RELOCATING+ *(.text.*)}
diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
index 70f5194b02f..b2691e0ef18 100644
--- a/ld/scripttempl/pe.sc
+++ b/ld/scripttempl/pe.sc
@@ -91,6 +91,7 @@  SECTIONS
   .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
   {
     ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
+    ${RELOCATING+INCLUDE config.text_section_ordering_file}
     *(.text)
     ${R_TEXT}
     ${RELOCATING+ *(.text.*)}
diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
index 63039f11574..f35e50c9430 100644
--- a/ld/scripttempl/pep.sc
+++ b/ld/scripttempl/pep.sc
@@ -92,6 +92,7 @@  SECTIONS
   .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
   {
     ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
+    ${RELOCATING+INCLUDE config.text_section_ordering_file}
     *(.text)
     ${R_TEXT}
     ${RELOCATING+ *(.text.*)}
diff --git a/ld/testsuite/ld-scripts/start.s b/ld/testsuite/ld-scripts/start.s
index 4d8239479a6..3f646267716 100644
--- a/ld/testsuite/ld-scripts/start.s
+++ b/ld/testsuite/ld-scripts/start.s
@@ -5,6 +5,8 @@  start:
 _start:
 	.global __start
 __start:
+	.global _mainCRTStartup	/* Used by PE targets.  */
+_mainCRTStartup:
 	.global main	/* Used by HPPA targets.  */
 main:
 	.globl	_main	/* Used by LynxOS targets.  */
diff --git a/ld/testsuite/ld-scripts/text-order-1a.d b/ld/testsuite/ld-scripts/text-order-1a.d
index d6f976f42ad..3aca3d6d5e9 100644
--- a/ld/testsuite/ld-scripts/text-order-1a.d
+++ b/ld/testsuite/ld-scripts/text-order-1a.d
@@ -3,7 +3,6 @@ 
 #source: start.s
 #ld: --text-section-ordering-file text-order-1a.t
 #nm: -n
-#target: [is_elf_format]
 
 #...
 [0-9a-f]+ T yyy
diff --git a/ld/testsuite/ld-scripts/text-order-1b.d b/ld/testsuite/ld-scripts/text-order-1b.d
index 3d6f4fd8d66..c9d83276da6 100644
--- a/ld/testsuite/ld-scripts/text-order-1b.d
+++ b/ld/testsuite/ld-scripts/text-order-1b.d
@@ -3,7 +3,6 @@ 
 #source: start.s
 #ld: --text-section-ordering-file text-order-1b.t
 #nm: -n
-#target: [is_elf_format]
 
 #...
 [0-9a-f]+ T yyy
diff --git a/ld/testsuite/ld-scripts/text-order-1c.d b/ld/testsuite/ld-scripts/text-order-1c.d
index 4166d634606..91f0a6bee4d 100644
--- a/ld/testsuite/ld-scripts/text-order-1c.d
+++ b/ld/testsuite/ld-scripts/text-order-1c.d
@@ -3,5 +3,4 @@ 
 #source: start.s
 #ld: --text-section-ordering-file text-order-1c.t
 #nm: -n
-#target: [is_elf_format]
 #error: .*: nested include 'text-order-1b.t' in the text section ordering file: 'text-order-1c.t'
diff --git a/ld/testsuite/ld-scripts/text-order.exp b/ld/testsuite/ld-scripts/text-order.exp
index 30cb531137e..2e51fd6f62a 100644
--- a/ld/testsuite/ld-scripts/text-order.exp
+++ b/ld/testsuite/ld-scripts/text-order.exp
@@ -18,7 +18,8 @@ 
 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
 # MA 02110-1301, USA.
 
-if { !([is_elf_format] && ![is_generic]) } {
+# ELF and PE COFF linker targets support input .text.* sections.
+if { !([is_elf_format] || [is_pecoff_format]) } {
     return
 }