From: "H.J. Lu" <hjl.tools@gmail.com>
To: Alan Modra <amodra@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] elf: Remove zero-sized relocation section from section group
Date: Fri, 3 Apr 2020 19:05:22 -0700 [thread overview]
Message-ID: <CAMe9rOqraqtrG5AKBO+yfjdave6YfY8YGDu978a+9LPi2tVM3A@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOqcQ000XxTG3cejpS8Fem-Cp3fLRCAupHyq+cC8061ekQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]
On Fri, Apr 3, 2020 at 6:56 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Apr 3, 2020 at 5:36 PM Alan Modra <amodra@gmail.com> 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 <amodra@gmail.com> 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.
[-- Attachment #2: 0001-elf-Remove-zero-sized-relocation-section-from-sectio.patch --]
[-- Type: text/x-patch, Size: 2253 bytes --]
From fad689e7b5d92d50986ec040071e84b5eb50604f Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 2 Apr 2020 20:38:02 -0700
Subject: [PATCH] elf: Remove zero-sized relocation section from section group
Remove zero-sized relocation section from a section group since it has
been removed from the output.
PR ld/25767
* elf.c (_bfd_elf_fixup_group_sections): Remove zero-sized
relocation section from section group.
---
bfd/elf.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/bfd/elf.c b/bfd/elf.c
index 86dadea05c..1780074f5a 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7929,19 +7929,34 @@ _bfd_elf_fixup_group_sections (bfd *ibfd, asection *discarded)
elf_section_flags (s->output_section) &= ~SHF_GROUP;
elf_group_name (s->output_section) = NULL;
}
- /* Conversely, if the member section is not being output
- but the SHT_GROUP section is, then adjust its size. */
- else if (s->output_section == discarded
- && isec->output_section != discarded)
+ else
{
struct bfd_elf_section_data *elf_sec = elf_section_data (s);
- removed += 4;
- if (elf_sec->rel.hdr != NULL
- && (elf_sec->rel.hdr->sh_flags & SHF_GROUP) != 0)
- removed += 4;
- if (elf_sec->rela.hdr != NULL
- && (elf_sec->rela.hdr->sh_flags & SHF_GROUP) != 0)
- removed += 4;
+ if (s->output_section == discarded
+ && isec->output_section != discarded)
+ {
+ /* Conversely, if the member section is not being
+ output but the SHT_GROUP section is, then adjust
+ its size. */
+ removed += 4;
+ if (elf_sec->rel.hdr != NULL
+ && (elf_sec->rel.hdr->sh_flags & SHF_GROUP) != 0)
+ removed += 4;
+ if (elf_sec->rela.hdr != NULL
+ && (elf_sec->rela.hdr->sh_flags & SHF_GROUP) != 0)
+ removed += 4;
+ }
+ else
+ {
+ /* Also adjust for zero-sized relocation member
+ section. */
+ if (elf_sec->rel.hdr != NULL
+ && elf_sec->rel.hdr->sh_size == 0)
+ removed += 4;
+ if (elf_sec->rela.hdr != NULL
+ && elf_sec->rela.hdr->sh_size == 0)
+ removed += 4;
+ }
}
s = elf_next_in_group (s);
if (s == first)
--
2.25.1
prev parent reply other threads:[~2020-04-04 2:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-03 3:41 [PATCH] elf: Keep zero-sized relocation section in " H.J. Lu
2020-04-03 4:45 ` Alan Modra
2020-04-03 6:34 ` Fangrui Song
2020-04-03 20:49 ` H.J. Lu
2020-04-03 20:48 ` [PATCH] elf: Remove zero-sized relocation section from " H.J. Lu
2020-04-04 0:36 ` Alan Modra
2020-04-04 1:56 ` H.J. Lu
2020-04-04 2:05 ` H.J. Lu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOqraqtrG5AKBO+yfjdave6YfY8YGDu978a+9LPi2tVM3A@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).