[PATCH v4] Support SHF_GNU_RETAIN ELF section flag

H.J. Lu hjl.tools@gmail.com
Tue Nov 3 17:43:36 GMT 2020


On Tue, Nov 3, 2020 at 9:33 AM Jozef Lawrynowicz
<jozef.l@mittosystems.com> wrote:
>
> The attached patch is the latest version of the Binutils implementation
> to support the SHF_GNU_RETAIN ELF GNU OSABI section flag, used to save
> sections from linker garbage collection.
>
> Links to previous discussions are available here:
> https://sourceware.org/pipermail/gnu-gabi/2020q3/000429.html
> https://sourceware.org/pipermail/binutils/2020-September/113406.html
> https://sourceware.org/pipermail/binutils/2020-October/113559.html
> https://sourceware.org/pipermail/binutils/2020-October/113769.html
>
> The intention with this latest patch is to support declarations in the
> source code marked with the "used" attribute being saved from linker
> garbage collection. The previously discussed "retain" GCC attribute has
> been removed.
>
> For declarations marked with the "used" attribute, GCC will emit a
> ".retain <symname>" directive, where <symname> is the name of the
> symbol. This hooks into existing GCC functionality for marking a
> symbol as "preserved" (currently used only by Darwin).

I don't believe that the .retain directive is needed.


> GAS supports the .retain directive, and will apply the SHF_GNU_RETAIN
> flag to the section containing the symbol named in the .retain
> directive.
> GAS supports the "R" flag to the .section directive, to mark a section
> with the SHF_GNU_RETAIN flag.
>
> GCC will not emit .section directives with the "R" flag set, so

I have a GCC patch to use the "o" flag:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557675.html
https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539963.html

and GCC should use the "R" flag for ELF targets.


--
H.J.


More information about the Binutils mailing list