public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Nick Clifton <nickc@redhat.com>
Cc: Binutils <binutils@sourceware.org>,
	hjl.tools@gmail.com, siddhesh@redhat.com
Subject: Re: RFC: ld: Add --text-section-ordering-file (version 4)
Date: Fri, 10 May 2024 21:55:41 +0930	[thread overview]
Message-ID: <Zj4SRVZBm8PIWM2H@squeak.grove.modra.org> (raw)
In-Reply-To: <fdcca315-ca2f-4818-aa22-608b2b839109@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

On Tue, May 07, 2024 at 05:39:58PM +0100, Nick Clifton wrote:
> Hi Guys,
> 
>   So here is an augmented version of Alan's patch.  All that
>   it does is to add some documentation and enhance one of the
>   tests so that it checks ordering the .data section as well
>   as the .text section.
> 
>   Any comments ?
> 
>   If there is nothing too seriously wrong with it, I would like
>   to check the patch in so that we can start testing it in the
>   real world.  We can always augment or change it later on, but
>   it would be nice to have something that people can play with.

ld-scripts/start.s seems to be missing.  You might also like to
consider adding the attached patch, which removes the need to specify
"SECTIONS { }" in --text-ordering-file scripts and gives a syntax
error on trying to alter output sections' address, type, alignment
etc.  Since we ignore them in lang_enter_output_section_statement for
--text-ordering-file scripts we probably ought to make it explicit.

-- 
Alan Modra

[-- Attachment #2: 0001-ld-sort-sections-file-ldgram.y.patch --]
[-- Type: text/x-diff, Size: 4429 bytes --]

From 953ef133271709d51e7dd46728c94fe091e6b97b Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 10 May 2024 17:51:46 +0930
Subject: ld --sort-sections-file ldgram.y


diff --git a/ld/ldgram.y b/ld/ldgram.y
index 0d531fddfa1..07c19ba8692 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -157,7 +157,7 @@ static void yyerror (const char *);
 %token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
 %token <name> VERS_TAG VERS_IDENTIFIER
-%token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
+%token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT INPUT_SECTION_ORDERING_SCRIPT
 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT
 %token EXCLUDE_FILE
 %token CONSTANT
@@ -172,6 +172,7 @@ file:
 		INPUT_SCRIPT script_file
 	|	INPUT_MRI_SCRIPT mri_script_file
 	|	INPUT_VERSION_SCRIPT version_script_file
+	|	INPUT_SECTION_ORDERING_SCRIPT section_ordering_script_file
 	|	INPUT_DYNAMIC_LIST dynamic_list_file
 	|	INPUT_DEFSYM defsym_expr
 	;
@@ -1539,6 +1540,39 @@ opt_semicolon:
 	|	';'
 	;
 
+section_ordering_script_file:
+		{
+		  ldlex_script ();
+		  PUSH_ERROR (_("section-ordering-file script"));
+		}
+		section_ordering_list
+		{
+		  ldlex_popstate ();
+		  POP_ERROR ();
+		}
+	;
+
+section_ordering_list:
+		section_ordering_list section_order
+	|	section_ordering_list statement_anywhere
+	|
+	;
+
+section_order:	NAME ':'
+		{
+		  ldlex_wild ();
+		  lang_enter_output_section_statement
+		    ($1, NULL, 0, NULL, NULL, NULL, NULL, 0, 0);
+		}
+		'{'
+		statement_list_opt
+		'}'
+		{
+		  ldlex_popstate ();
+		  lang_leave_output_section_statement (NULL, NULL, NULL, NULL);
+		}
+		opt_comma
+
 %%
 static void
 yyerror (const char *arg)
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 5708e6f5e34..7a0c3b4be94 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -478,6 +478,7 @@ typedef enum input_enum
   input_script,
   input_mri_script,
   input_version_script,
+  input_section_ordering_script,
   input_dynamic_list,
   input_defsym
 } input_type;
diff --git a/ld/ldlex.l b/ld/ldlex.l
index e113c90812b..aa613100db0 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -120,11 +120,12 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
       parser_input = input_selected;
       switch (t)
 	{
-	case input_script: return INPUT_SCRIPT; break;
-	case input_mri_script: return INPUT_MRI_SCRIPT; break;
-	case input_version_script: return INPUT_VERSION_SCRIPT; break;
-	case input_dynamic_list: return INPUT_DYNAMIC_LIST; break;
-	case input_defsym: return INPUT_DEFSYM; break;
+	case input_script: return INPUT_SCRIPT;
+	case input_mri_script: return INPUT_MRI_SCRIPT;
+	case input_version_script: return INPUT_VERSION_SCRIPT;
+	case input_section_ordering_script: return INPUT_SECTION_ORDERING_SCRIPT;
+	case input_dynamic_list: return INPUT_DYNAMIC_LIST;
+	case input_defsym: return INPUT_DEFSYM;
 	default: abort ();
 	}
     }
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 16c8298498d..037099b9d37 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -465,7 +465,7 @@ main (int argc, char **argv)
 	display_external_script ();
       saved_script_handle = hold_script_handle;
       in_section_ordering = true;
-      parser_input = input_script;
+      parser_input = input_section_ordering_script;
       yyparse ();
       in_section_ordering = false;
 
diff --git a/ld/testsuite/ld-scripts/section-order-1a.t b/ld/testsuite/ld-scripts/section-order-1a.t
index e3786818fea..0eacf3b3927 100644
--- a/ld/testsuite/ld-scripts/section-order-1a.t
+++ b/ld/testsuite/ld-scripts/section-order-1a.t
@@ -1,15 +1,12 @@
-SECTIONS
-{
-  .text : {
-    *(.text.yyy)
-    *(.text.b?r)
-    *(.text)
-    *(.text.xxx .text.foo)
-  }
+.text : {
+  *(.text.yyy)
+  *(.text.b?r)
+  *(.text)
+  *(.text.xxx .text.foo)
+}
 
-  .data : {
-    *(.data.small)
-    *(.big*)
-    *(.bar .baz*)
-  }
+.data : {
+  *(.data.small)
+  *(.big*)
+  *(.bar .baz*)
 }
diff --git a/ld/testsuite/ld-scripts/section-order-1b.t b/ld/testsuite/ld-scripts/section-order-1b.t
index 896653b2608..6a36250dcbc 100644
--- a/ld/testsuite/ld-scripts/section-order-1b.t
+++ b/ld/testsuite/ld-scripts/section-order-1b.t
@@ -1,9 +1,7 @@
-SECTIONS {
-  .text : {
-    *(.text.yyy)
-    *(.text.b?r)
-    *(*t)
-    *(.text.xxx)
-    *(.text.foo)
-  }
+.text : {
+  *(.text.yyy)
+  *(.text.b?r)
+  *(*t)
+  *(.text.xxx)
+  *(.text.foo)
 }

  reply	other threads:[~2024-05-10 12:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 13:01 RFC: ld: Add --text-section-ordering-file (version 2) Nick Clifton
2024-04-25 15:32 ` H.J. Lu
2024-04-26  9:38   ` Nick Clifton
2024-04-26  1:46 ` Hans-Peter Nilsson
2024-04-26  9:46   ` Nick Clifton
2024-04-27  0:46     ` Hans-Peter Nilsson
2024-04-26  4:17 ` Alan Modra
2024-04-26  9:59   ` Nick Clifton
2024-04-26 12:43     ` Alan Modra
2024-04-29  0:12       ` Alan Modra
2024-05-02 15:16         ` Nick Clifton
2024-05-06 18:27         ` H.J. Lu
2024-05-10 21:46           ` Noah Goldstein
2024-05-11 13:01             ` H.J. Lu
2024-05-07 16:39         ` RFC: ld: Add --text-section-ordering-file (version 4) Nick Clifton
2024-05-10 12:25           ` Alan Modra [this message]
2024-05-10 16:00             ` Nick Clifton

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=Zj4SRVZBm8PIWM2H@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    --cc=nickc@redhat.com \
    --cc=siddhesh@redhat.com \
    /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).