[PATCH] Support SHF_GNU_RETAIN ELF section flag
Jozef Lawrynowicz
jozef.l@mittosystems.com
Thu Sep 24 17:18:08 GMT 2020
On Thu, Sep 24, 2020 at 10:04:46AM -0700, H.J. Lu via Binutils wrote:
> On Thu, Sep 24, 2020 at 9:56 AM Jozef Lawrynowicz
> <jozef.l@mittosystems.com> wrote:
> >
> > On Thu, Sep 24, 2020 at 06:59:07AM -0700, H.J. Lu via Binutils wrote:
> > > On Thu, Sep 24, 2020 at 6:49 AM Jozef Lawrynowicz
> > > <jozef.l@mittosystems.com> wrote:
> > > >
> > > > On Thu, Sep 24, 2020 at 06:18:05AM -0700, H.J. Lu via Binutils wrote:
> > > > > On Wed, Sep 23, 2020 at 1:17 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > > >
> > > > > > On Wed, Sep 23, 2020 at 1:04 PM Jozef Lawrynowicz
> > > > > > <jozef.l@mittosystems.com> wrote:
> > > > > > >
> > > > > > > On Wed, Sep 23, 2020 at 12:03:28PM -0700, H.J. Lu via Binutils wrote:
> > > > > > > > On Wed, Sep 23, 2020 at 11:47 AM Jozef Lawrynowicz
> > > > > > > > <jozef.l@mittosystems.com> wrote:
> > > > > > > > >
> > > > > > > > > On Wed, Sep 23, 2020 at 10:13:37AM -0700, H.J. Lu via Binutils wrote:
> > > > > > > > > > On Wed, Sep 23, 2020 at 9:52 AM Jozef Lawrynowicz
> > > > > > > > > > <jozef.l@mittosystems.com> wrote:
> > > > > > > > > > >
> > > > > > > > > > > On Wed, Sep 23, 2020 at 01:51:56PM +0000, Michael Matz wrote:
> > > > > > > > > > > > Hello,
> > > > > > > > > > > >
> > > > > > > > > > > > On Wed, 23 Sep 2020, H.J. Lu via Binutils wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > > > I think that:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > > .section .text,"ax"
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > > foo:
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > > .retain
> > > > > > > > > > > > > > > retained_fn:
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > is some nice syntactic sugar compared to:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > > .section .text,"ax"
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > > foo:
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > > .section .text,"axR"
> > > > > > > > > > > > > > > retained_fn:
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > It's also partly for convenience; we have other directives which are
> > > > > > > > > > > > > > synonyms or short-hand for each other.
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > You don't need to keep the whole section when only one symbol should
> > > > > > > > > > > > > be kept. Please drop the .retain directive. GCC, as and ld should do the
> > > > > > > > > > > > > right thing with
> > > > > > > > > > > > >
> > > > > > > > > > > > > .section .text,"ax"
> > > > > > > > > > > > > ...
> > > > > > > > > > > > > foo:
> > > > > > > > > > > > > ...
> > > > > > > > > > > > > .section .text,"axR"
> > > > > > > > > > > > >
> > > > > > > > > > > > > retained_fn:
> > > > > > > > > > > > >
> > > > > > > > > > > > > where foo can be dropped and retained_fn will be kept.
> > > > > > > > > > > >
> > > > > > > > > > > > This is not what we discussed at the ABI list, the flag is per section, so
> > > > > > > > > > > > either the whole section is retained or not. What you describe is
> > > > > > > > > > > > something else that would work on a per symbol basis, which would have to
> > > > > > > > > > > > be specified in a different way and might or might not be a good idea.
> > > > > > > > > > > > But let's not conflate these two.
> > > > > > > > > > >
> > > > > > > > > > > Also, the linker cannot currently dissect a section and remove a
> > > > > > > > > > > particular unused symbol anyway. Since garbage collection only operates
> > > > > > > > > > > on the section level, marking the section itself as "retained" seems
> > > > > > > > > > > most appropriate.
> > > > > > > > > >
> > > > > > > > > > It can be done. If you put your branch on
> > > > > > > > > >
> > > > > > > > > > https://gitlab.com/x86-binutils/binutils-gdb
> > > > > > > > > >
> > > > > > > > > > I can help you implement it.
> > > > > > > > >
> > > > > > > > > It's not something I have time to look into at the moment, for now the
> > > > > > > > > aim is just to prevent garbage collection of sections.
> > > > > > > >
> > > > > > > > Linker and assembler already support it. You just need to add SHF_GNU_RETAIN
> > > > > > > > to the framework. Check how SHF_GNU_MBIND works.
> > > > > > >
> > > > > > > Sorry, I don't understand.
> > > > > > >
> > > > > > > Are you saying that LD already supports the garbage collection of
> > > > > > > individual unused symbol definitions from input sections? Whilst
> > > > > > > retaining other symbol definitions which are required by the program?
> > > > > > > I cannot find any reference to this.
> > > > > > >
> > > > > > > How does that relate to SHF_GNU_MBIND? I looked at all the references
> > > > > > > to "mbind" in Binutils and nothing seemed related garbage collection of
> > > > > > > sections, since SHF_GNU_MBIND is just used to indicate a particular
> > > > > > > section should be placed in a special memory area.
> > > > > >
> > > > > > For
> > > > > >
> > > > > > section .text,"ax"
> > > > > > ...
> > > > > > foo:
> > > > > > ...
> > > > > > .section .text,"axR"
> > > > > > retained_fn:
> > > > > >
> > > > > > you need to create a new .text section with SHF_GNU_RETAIN for
> > > > > > retained_fn. See get_section in obj-elf.c. If you want to avoid
> > > > >
> > > > > See users/hjl/elf/master branch at:
> > > > >
> > > > > https://gitlab.com/x86-binutils/binutils-gdb/-/commits/users/hjl/elf/master
> > > > >
> > > > > I removed the .retain directive.
> > > >
> > > > Thanks, the formalization of section flag merging in the assembler is
> > > > nice.
> > > >
> > > > My only comment is that I used the "STT_*" syntax in the .type directive
> > > > instead of % because some targets didn't like the % syntax and emmited
> > > > an error. I don't remember which, maybe it was mmix-elf, in which case
> > > > we don't care :)
> > >
> > > Some targets don't support @object. %object works for all targets.
> >
> > Ah yes, it is in fact the non-existent mmix-elf that can't assemble
> > %object but it works for all real targets.
> >
> > However, some targets don't support the .bss pseudo op which is used in
> > your new tests, so those are failing in some cases.
> >
>
> Which ELF targets don't support .bss? gas/testsuite/gas/elf/bss.s has
>
> .bss
>
> Do they fail this test?
That test only runs for i?86-*-* x86_64-*-* ia64-*-* arm-*-* aarch64-*-*
The .bss directive causes an error for the following targets:
arc-elf avr-elf cr16-elf cris-elf crx-elf d10v-elf d30v-elf dlx-elf
epiphany-elf fr30-elf frv-elf ft32-elf h8300-elf ip2k-elf iq2000-elf
lm32-elf m32r-elf m68hc11-elf m68hc12-elf mep-elf metag-elf mmix-elf
mmix-elf moxie-elf msp430-elf mt-elf nios2-elf or1k-elf pj-elf ppc-elf
pru-elf s12z-elf sh-elf sparc-elf tic6x-elf tilegx-elf tilepro-elf
wasm32-elf xgate-elf xstormy16-elf xtensa-elf z80-elf
Thanks,
Jozef
>
> --
> H.J.
More information about the Binutils
mailing list