elf: Keep zero-sized relocation section in section group

Message ID 20200403034118.192936-1-hjl.tools@gmail.com
State New
Headers show
Series
  • elf: Keep zero-sized relocation section in section group
Related show

Commit Message

H.J. Lu via Binutils April 3, 2020, 3:41 a.m.
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(-)

-- 
2.25.1

Comments

H.J. Lu via Binutils April 3, 2020, 4:45 a.m. | #1
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
Fangrui Song April 3, 2020, 6:34 a.m. | #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?
H.J. Lu via Binutils April 3, 2020, 8:49 p.m. | #3
On Thu, Apr 2, 2020 at 11:34 PM Fangrui Song <i@maskray.me> 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.

Patch

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;
 	}