bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/26256] Support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER compone


From: hjl.tools at gmail dot com
Subject: [Bug ld/26256] Support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER components in an output section
Date: Tue, 22 Dec 2020 13:22:03 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=26256

--- Comment #14 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Fangrui Song from comment #13)
> (In reply to H.J. Lu from comment #12)
> > (In reply to Fangrui Song from comment #10)
> > > (In reply to H.J. Lu from comment #8)
> > > > Created attachment 13070 [details]
> > > > A patch with tests
> > > > 
> > > > Try this.
> > > 
> > > With a minor change, it'll match LLD (I place ordered sections before
> > > unordered sections because Solaris folks said they did so).
> > > 
> > > +      /* Place ordered sections before unordered sections.  */
> > > +      if (bsec != NULL)
> > > + return 1;
> > > +      else if (asec != NULL)
> > > + return -1;
> > > +      return 0;
> > > 
> > > For the test case lld/test/ELF/linkorder-mixed.s , ld-new produced %t, %t1
> > > and %t3 now match LLD.
> > > %t2 and %t4 still don't, but they are probably corner cases and don't 
> > > matter
> > > in practice.
> > 
> > %t2 and %t4 are lld specific behavior.
> 
> 
> I actually think %t2 and %t4 are generic: ordered .rodata.bar (.byte 3)
> precedes unordered .rodata.bar (.byte 2)
> 
>   SECTIONS { .rodata : {*(.rodata.foo) *(.rodata.bar)} }
> 
> What LLD does is to perform SHF_LINK_ORDER sorting within the input section
> description *(.rodata.bar). I agree that this is a corner case which can
> hardly do harm in practice.

It is a bug:

diff --git a/bfd/elflink.c b/bfd/elflink.c
index a1e4635e96..ddff3bfe7b 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -11988,9 +11988,7 @@ elf_fixup_link_order (struct bfd_link_info *info, bfd
*abfd, asection *o)
   for (p = o->map_head.link_order; p != NULL; p = p->next)
     sections[seen_linkorder++] = p;

-  for (indirect_sections = sections, n = 0;
-       n < seen_linkorder;
-       indirect_sections++, n++)
+  for (indirect_sections = sections, n = 0; n < seen_linkorder;)
     {
       /* Find the first bfd_indirect_link_order section.  */
       if (indirect_sections[0]->type == bfd_indirect_link_order)
@@ -12012,6 +12010,11 @@ elf_fixup_link_order (struct bfd_link_info *info, bfd
*abfd, asection *o)
     indirect_sections += n_indirect;
     n += n_indirect;
   }
+      else
+  {
+    indirect_sections++;
+    n++;
+  }
     }

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]