[PATCH v2] Support for SHF_GNU_RETAIN ELF Section Flag
H.J. Lu
hjl.tools@gmail.com
Tue Sep 29 19:54:52 GMT 2020
On Tue, Sep 29, 2020 at 12:38 PM Fangrui Song <i@maskray.me> wrote:
>
> >>
> >> // a.h
> >> __attribute__((section("sec")))
> >> inline void bar() { ... }
> >> // a.c
> >> #include "a.h"
> >> __attribute__((section("sec"), retain))
> >> void foo() {
> >> }
> >>
> >> compiles to
> >>
> >> .section sec,"a",@progbits
> >> ...
> >> .section sec,"aR",@progbits
> >> ...
> >>
> >> You will get a gas error for changing section flags
> >> (https://sourceware.org/pipermail/binutils/2020-February/109945.html)
> >>
> >
> >There is no error in this case.
> >The original patch handled it, and it has been further improved in v2.
> >There's even a testcase testing exactly the functionality you say is
> >broken.
> >
> > gas/testsuite/gas/elf/section22.s:
> > .section .bss,"aw"
> > ...
> > .section .bss,"awR",%nobits
> >
> >I already gave a detailed response to your reloc proposal:
> >https://sourceware.org/pipermail/binutils/2020-September/113450.html
>
> Letting the following assembly creates two .bss sections adds an exception to
> "gas: error for section type, attr, or entsize change"
> (https://sourceware.org/pipermail/binutils/2020-February/109945.html)
> for which I have achieved consensus with Alan Modra and some LLVM
> toolchain folks. That is why I hope we could re-consider this design
> choice.
>
> .section .bss,"aw"
> .section .bss,"awR",%nobits
>
FWIW, GNU assembler has been able to create multiple sections with
the same section name for a while. For SHF_GNU_RETAIN, we added
+/* Create unique input sections for sections with the same name, but different
+ values for the flags in this mask. */
+#define SEC_ASSEMBLER_SHF_MASK SHF_GNU_RETAIN
to control when to create a new section with the same section name.
For other cases, no new section is created.
--
H.J.
More information about the Gnu-gabi
mailing list