[PATCH] Set the retain attribute on _elf_set_element if CC supports [BZ #27492]
Florian Weimer
fweimer@redhat.com
Mon Mar 15 07:28:18 GMT 2021
* Fangrui Song via Libc-alpha:
> So that text_set_element/data_set_element/bss_set_element defined
> variables will be retained by the linker.
>
> Note: 'used' and 'retain' are orthogonal: 'used' makes sure the variable
> will not be optimized out; 'retain' prevents section garbage collection
> if the linker support SHF_GNU_RETAIN.
This needs recent-ish GCC 11, see commit 6347f4a0904fce17e ("Add retain
attribute to place symbols in SHF_GNU_RETAIN section).
> +#ifdef __has_attribute
> +#if __has_attribute (retain)
> +# ifdef SHARED
Indentation is off there.
It's probably simpler to define a new macro, like
ELEMENT_SECTION_ATTRIBUTES, and use that unconditionally, perhaps like
this?
#ifndef __ASSEMBLER__
# if defined (__has_attribute) && __has_attribute (retain)
# define ELEMENT_SECTION_ATTRIBUTES used, retain
# else
# define ELEMENT_SECTION_ATTRIBUTES used
# endif
#endif
Have you checked that __has_attribute (retain) is only true on GCC if
the underlying linker has retain support and the attribute does not
produce a warning?
Thanks,
Florian
More information about the Libc-alpha
mailing list