[binutils-gdb] ld: Clear map_head_is_link_order for .gnu_object_only

H.J. Lu hjl@sourceware.org
Mon Jul 14 01:13:22 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=939eb467b21de5d18ee703755fb9704a525cfe21

commit 939eb467b21de5d18ee703755fb9704a525cfe21
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jul 14 05:21:32 2025 +0800

    ld: Clear map_head_is_link_order for .gnu_object_only
    
    Clear map_head_is_link_order when generating .gnu_object_only section so
    that lang_add_section can add new sections and .sframe sections will be
    properly merged by _bfd_elf_merge_section_sframe.
    
            PR ld/33146
            * ldlang.c (cmdline_emit_object_only_section): Clear
            map_head_is_link_order.
            * testsuite/ld-plugin/lto.exp (as_gsframe): New.
            (lto_link_tests): Add $as_gsframe to compile lto-4b.o and
            lto-4c.o.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 ld/ldlang.c                    | 3 +++
 ld/testsuite/ld-plugin/lto.exp | 9 +++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ld/ldlang.c b/ld/ldlang.c
index cd1825b1bc0..d4b4ef2f29b 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -10887,6 +10887,9 @@ cmdline_emit_object_only_section (void)
   lang_init (true);
   ldexp_init (true);
 
+  /* Allow lang_add_section to add new sections.  */
+  map_head_is_link_order = false;
+
   /* Set up the object-only output. */
   lang_final ();
 
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index f0d0954ab09..d68e5f44397 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -51,6 +51,11 @@ if { [check_lto_fat_available] } {
   set no_lto "-fno-lto"
 }
 
+set as_gsframe ""
+if { [gas_sframe_check] } {
+    set as_gsframe "-Wa,--gsframe"
+}
+
 # Simple LTO tests and generate input files for complex LTO tests.
 set lto_link_tests [list \
   [list "LTO 1" \
@@ -76,10 +81,10 @@ set lto_link_tests [list \
    "" "-flto $lto_fat" \
    {lto-4a.c} {} ""] \
   [list "Compile 4b" \
-   "" "-O2" \
+   "" "-O2 $as_gsframe" \
    {lto-4b.c} {} ""] \
   [list "Compile 4c" \
-   "" "-O2" \
+   "" "-O2 $as_gsframe" \
    {lto-4c.c} {} ""] \
   [list "Compile 5a" \
    "" "-flto $lto_fat" \


More information about the Binutils-cvs mailing list