[PATCH] elf: Keep zero-sized relocation section in section group

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] elf: Keep zero-sized relocation section in section group

Sourceware - binutils list mailing list
We must keep zero-sized relocation section in a section group.  Otherwise,
the relocation section will be missing from the section group.

        PR ld/25767
        * elflink.c (bfd_elf_final_link): Keep zero-sized relocation
        section in section group.
---
 bfd/elflink.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 7c0849423a..3b29cc127a 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12058,11 +12058,15 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 
       if (o->reloc_count > 0)
  o->flags |= SEC_RELOC;
-      else
+      else if (info->resolve_section_groups || !elf_group_name (o))
  {
   /* Explicitly clear the SEC_RELOC flag.  The linker tends to
      set it (this is probably a bug) and if it is set
-     assign_section_numbers will create a reloc section.  */
+     assign_section_numbers will create a reloc section.
+
+     PR ld/25767: We must keep zero-sized relocation section
+     in a section group.  Otherwise, that relocation section
+     will be missing from the section group.  */
   o->flags &=~ SEC_RELOC;
  }
 
--
2.25.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] elf: Keep zero-sized relocation section in section group

Sourceware - binutils list mailing list
On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
> We must keep zero-sized relocation section in a section group.  Otherwise,
> the relocation section will be missing from the section group.

Wouldn't it be better to get rid of these bogus relocation sections?
Should be possible with a change to _bfd_elf_fixup_group_sections, I
think.

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] elf: Keep zero-sized relocation section in section group

Fangrui Song-2
On 2020-04-03, Alan Modra via Binutils wrote:

>On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
>> We must keep zero-sized relocation section in a section group.  Otherwise,
>> the relocation section will be missing from the section group.
>
>Wouldn't it be better to get rid of these bogus relocation sections?
>Should be possible with a change to _bfd_elf_fixup_group_sections, I
>think.
>
>--
>Alan Modra
>Australia Development Lab, IBM

"19990502 sourceware import" contains

+      if (o->reloc_count > 0)
+       o->flags |= SEC_RELOC;
+      else
+       {
+         /* Explicitly clear the SEC_RELOC flag.  The linker tends to
+            set it (this is probably a bug) and if it is set
+            assign_section_numbers will create a reloc section.  */
+         o->flags &=~ SEC_RELOC;
+       }

"this is probably a bug" Shouldn't we fix the bug?
Reply | Threaded
Open this post in threaded view
|

[PATCH] elf: Remove zero-sized relocation section from section group

Sourceware - binutils list mailing list
In reply to this post by Sourceware - binutils list mailing list
On Thu, Apr 2, 2020 at 9:45 PM Alan Modra <[hidden email]> wrote:
>
> On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
> > We must keep zero-sized relocation section in a section group.  Otherwise,
> > the relocation section will be missing from the section group.
>
> Wouldn't it be better to get rid of these bogus relocation sections?
> Should be possible with a change to _bfd_elf_fixup_group_sections, I
> think.

Here is the patch which does that.  OK for master?

Thanks.

--
H.J.

0001-elf-Remove-zero-sized-relocation-section-from-sectio.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] elf: Keep zero-sized relocation section in section group

Sourceware - binutils list mailing list
In reply to this post by Fangrui Song-2
On Thu, Apr 2, 2020 at 11:34 PM Fangrui Song <[hidden email]> wrote:

>
> On 2020-04-03, Alan Modra via Binutils wrote:
> >On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
> >> We must keep zero-sized relocation section in a section group.  Otherwise,
> >> the relocation section will be missing from the section group.
> >
> >Wouldn't it be better to get rid of these bogus relocation sections?
> >Should be possible with a change to _bfd_elf_fixup_group_sections, I
> >think.
> >
> >--
> >Alan Modra
> >Australia Development Lab, IBM
>
> "19990502 sourceware import" contains
>
> +      if (o->reloc_count > 0)
> +       o->flags |= SEC_RELOC;
> +      else
> +       {
> +         /* Explicitly clear the SEC_RELOC flag.  The linker tends to
> +            set it (this is probably a bug) and if it is set
> +            assign_section_numbers will create a reloc section.  */
> +         o->flags &=~ SEC_RELOC;
> +       }
>
> "this is probably a bug" Shouldn't we fix the bug?

Yes, the real bug will be fixed :-).

--
H.J.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] elf: Remove zero-sized relocation section from section group

Sourceware - binutils list mailing list
In reply to this post by Sourceware - binutils list mailing list
On Fri, Apr 03, 2020 at 01:48:42PM -0700, H.J. Lu wrote:

> On Thu, Apr 2, 2020 at 9:45 PM Alan Modra <[hidden email]> wrote:
> >
> > On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
> > > We must keep zero-sized relocation section in a section group.  Otherwise,
> > > the relocation section will be missing from the section group.
> >
> > Wouldn't it be better to get rid of these bogus relocation sections?
> > Should be possible with a change to _bfd_elf_fixup_group_sections, I
> > think.
>
> Here is the patch which does that.  OK for master?

OK, thanks.

Hmm, do we want a warning message?  I'm OK with it as a reminder to
people to fix their compilers and/or assembly, but other than that it
seems to me that removing an empty relocation section is hardly of
concern to users.  How was your testcase generated?

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] elf: Remove zero-sized relocation section from section group

Sourceware - binutils list mailing list
On Fri, Apr 3, 2020 at 5:36 PM Alan Modra <[hidden email]> wrote:

>
> On Fri, Apr 03, 2020 at 01:48:42PM -0700, H.J. Lu wrote:
> > On Thu, Apr 2, 2020 at 9:45 PM Alan Modra <[hidden email]> wrote:
> > >
> > > On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
> > > > We must keep zero-sized relocation section in a section group.  Otherwise,
> > > > the relocation section will be missing from the section group.
> > >
> > > Wouldn't it be better to get rid of these bogus relocation sections?
> > > Should be possible with a change to _bfd_elf_fixup_group_sections, I
> > > think.
> >
> > Here is the patch which does that.  OK for master?
>
> OK, thanks.
>
> Hmm, do we want a warning message?  I'm OK with it as a reminder to

I will remove the warning.

> people to fix their compilers and/or assembly, but other than that it
> seems to me that removing an empty relocation section is hardly of
> concern to users.  How was your testcase generated?
>

I was given an object file generated by an "unnamed" compiler :-).
I have told them to fix their compiler.

Thanks.

--
H.J.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] elf: Remove zero-sized relocation section from section group

Sourceware - binutils list mailing list
On Fri, Apr 3, 2020 at 6:56 PM H.J. Lu <[hidden email]> wrote:

>
> On Fri, Apr 3, 2020 at 5:36 PM Alan Modra <[hidden email]> wrote:
> >
> > On Fri, Apr 03, 2020 at 01:48:42PM -0700, H.J. Lu wrote:
> > > On Thu, Apr 2, 2020 at 9:45 PM Alan Modra <[hidden email]> wrote:
> > > >
> > > > On Thu, Apr 02, 2020 at 08:41:18PM -0700, H.J. Lu via Binutils wrote:
> > > > > We must keep zero-sized relocation section in a section group.  Otherwise,
> > > > > the relocation section will be missing from the section group.
> > > >
> > > > Wouldn't it be better to get rid of these bogus relocation sections?
> > > > Should be possible with a change to _bfd_elf_fixup_group_sections, I
> > > > think.
> > >
> > > Here is the patch which does that.  OK for master?
> >
> > OK, thanks.
> >
> > Hmm, do we want a warning message?  I'm OK with it as a reminder to
>
> I will remove the warning.
>
> > people to fix their compilers and/or assembly, but other than that it
> > seems to me that removing an empty relocation section is hardly of
> > concern to users.  How was your testcase generated?
> >
>
> I was given an object file generated by an "unnamed" compiler :-).
> I have told them to fix their compiler.
>
> Thanks.
This is what I am checking in.

--
H.J.

0001-elf-Remove-zero-sized-relocation-section-from-sectio.patch (3K) Download Attachment