[PATCH v2] gas: Allow SHF_GNU_RETAIN on .note/.rodata.str sections
Alan Modra
amodra@gmail.com
Tue Feb 16 03:04:02 GMT 2021
On Mon, Feb 15, 2021 at 06:20:19PM -0800, H.J. Lu wrote:
> On Mon, Feb 15, 2021 at 3:28 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Mon, Feb 15, 2021 at 07:43:39AM -0800, H.J. Lu wrote:
> > > On Sat, Feb 13, 2021 at 7:25 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > >
> > > > Since SHF_GNU_RETAIN is allowed on SHT_NOTE section, strip SHF_GNU_RETAIN
> > > > when checking incorrect section attributes on SHT_NOTE section.
> > > >
> > > > PR gas/27412
> > > > * config/obj-elf.c (obj_elf_change_section): Strip SHF_GNU_RETAIN.
> > > > * testsuite/gas/elf/elf.exp: Run section28.
> > > > * testsuite/gas/elf/section28.d: New file.
> > > > * testsuite/gas/elf/section28.s: Likewise.
> > > > ---
> > > > gas/config/obj-elf.c | 8 +++++++-
> > > > gas/testsuite/gas/elf/elf.exp | 1 +
> > > > gas/testsuite/gas/elf/section28.d | 15 +++++++++++++++
> > > > gas/testsuite/gas/elf/section28.s | 11 +++++++++++
> > > > 4 files changed, 34 insertions(+), 1 deletion(-)
> > > > create mode 100644 gas/testsuite/gas/elf/section28.d
> > > > create mode 100644 gas/testsuite/gas/elf/section28.s
> > > >
> > > > diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
> > > > index f52dc69f0c3..13f54b10857 100644
> > > > --- a/gas/config/obj-elf.c
> > > > +++ b/gas/config/obj-elf.c
> > > > @@ -667,12 +667,18 @@ obj_elf_change_section (const char *name,
> > > > | SHF_MASKPROC))
> > > > & ~ssect->attr) != 0)
> > > > {
> > > > + /* Strip SHF_GNU_RETAIN. */
> > > > + bfd_vma generic_attr = attr;
> > > > + if (elf_tdata (stdoutput)->has_gnu_osabi)
> > > > + generic_attr &= ~SHF_GNU_RETAIN;
> > > > +
> > > > /* As a GNU extension, we permit a .note section to be
> > > > allocatable. If the linker sees an allocatable .note
> > > > section, it will create a PT_NOTE segment in the output
> > > > file. We also allow "x" for .note.GNU-stack. */
> > > > if (ssect->type == SHT_NOTE
> > > > - && (attr == SHF_ALLOC || attr == SHF_EXECINSTR))
> > > > + && (generic_attr == SHF_ALLOC
> > > > + || generic_attr == SHF_EXECINSTR))
> > > > ;
> > > > /* Allow different SHF_MERGE and SHF_STRINGS if we have
> > > > something like .rodata.str. */
> >
> > Should you be using generic_attr in later tests in this block? If we
> > allow .rodata.str with a differing SHF_MERGE flag then it seems
> > reasonable to also allow SHF_GNU_RETAIN to differ.
> >
>
> Like this?
Why not use generic_attr in *all* of the tests in this block? I think
that would be better. OK with that change.
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list