[PATCH v4 11/14] LD: Factor out new input file node insertion

Maciej W. Rozycki macro@orcam.me.uk
Tue Jan 13 01:45:12 GMT 2026


From: Maciej W. Rozycki <macro@redhat.com>

Move code for new input file node insertion in the middle of the 
statement list to a separate function.  No functional change.
---
This has been previously approved, but it makes sense to group it with
later patches from this series.

No change from v3 (15/18), 
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511200003570.57987@angie.orcam.me.uk/>.

No change from v2 (13/16), 
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511061752550.25436@angie.orcam.me.uk/>.

New change in v2.
---
 ld/ldlang.c |   43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

binutils-ld-insert-input-file.diff
Index: binutils-gdb/ld/ldlang.c
===================================================================
--- binutils-gdb.orig/ld/ldlang.c
+++ binutils-gdb/ld/ldlang.c
@@ -2975,6 +2975,31 @@ check_section_callback (lang_wild_statem
     os->all_input_readonly = false;
 }
 
+/* Build a new input file node and arrange to splice the input statement
+   added into statement_list after the current input_file_chain tail.  */
+
+static lang_input_statement_type *
+insert_input_file (const char *name,
+		   lang_input_file_enum_type file_type,
+		   const char *target)
+{
+  lang_statement_union_type **tail = stat_ptr->tail;
+  lang_statement_union_type **after
+    = (void *) ((char *) input_file_chain.tail
+                - offsetof (lang_input_statement_type, next_real_file)
+                + offsetof (lang_input_statement_type, header.next));
+  lang_statement_union_type *rest = *after;
+  lang_input_statement_type *p;
+
+  stat_ptr->tail = after;
+  p = new_afile (name, file_type, target, NULL);
+  *stat_ptr->tail = rest;
+  if (*tail == NULL)
+    stat_ptr->tail = tail;
+
+  return p;
+}
+
 /* This is passed a file name which must have been seen already and
    added to the statement tree.  We will see if it has been opened
    already and had its symbols read.  If not then we'll read it.  */
@@ -3000,23 +3025,11 @@ lookup_name (const char *name)
 
   if (search == NULL)
     {
-      /* Arrange to splice the input statement added by new_afile into
-	 statement_list after the current input_file_chain tail.
-	 We know input_file_chain is not an empty list, and that
+      /* We know input_file_chain is not an empty list, and that
 	 lookup_name was called via open_input_bfds.  Later calls to
 	 lookup_name should always match an existing input_statement.  */
-      lang_statement_union_type **tail = stat_ptr->tail;
-      lang_statement_union_type **after
-	= (void *) ((char *) input_file_chain.tail
-		    - offsetof (lang_input_statement_type, next_real_file)
-		    + offsetof (lang_input_statement_type, header.next));
-      lang_statement_union_type *rest = *after;
-      stat_ptr->tail = after;
-      search = new_afile (name, lang_input_file_is_search_file_enum,
-			  default_target, NULL);
-      *stat_ptr->tail = rest;
-      if (*tail == NULL)
-	stat_ptr->tail = tail;
+      search = insert_input_file (name, lang_input_file_is_search_file_enum,
+				  default_target);
       ASSERT (search != NULL);
     }
 


More information about the Binutils mailing list