aboutsummaryrefslogtreecommitdiff
path: root/include/libc-symbols.h
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2021-04-16 11:26:39 -0700
committerFangrui Song <maskray@google.com>2021-08-31 15:36:41 -0700
commitadd8e34cd7223dc6770c34de820651eee879ff65 (patch)
tree1c4ce7396339c339508a0e7f783740f4c31c60a3 /include/libc-symbols.h
parentbc129fb15b826520d16656df99a29910a487c252 (diff)
downloadglibc-add8e34cd7223dc6770c34de820651eee879ff65.zip
glibc-add8e34cd7223dc6770c34de820651eee879ff65.tar.gz
glibc-add8e34cd7223dc6770c34de820651eee879ff65.tar.bz2
Set the retain attribute on _elf_set_element if CC supports [BZ #27492]
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. GNU ld 2.37 and LLD 13 will support -z start-stop-gc which allow C identifier name sections to be GCed even if there are live __start_/__stop_ references. Without the change, there are some static linking problems, e.g. _IO_cleanup (libio/genops.c) may be discarded by ld --gc-sections, so stdout is not flushed on exit. Note: GCC may warning 'retain' attribute ignored while __has_attribute(retain) is 1 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587). Reviewed-by: H.J. Lu <hjl.tools@gmail.com> (cherry picked from commit cd6ae7ea5431c2b8f16201fb0e2c413bf8d2df06)
Diffstat (limited to 'include/libc-symbols.h')
-rw-r--r--include/libc-symbols.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index c40f5fb..1e00fcb 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -286,6 +286,12 @@ for linking")
*/
+#ifdef HAVE_GNU_RETAIN
+# define attribute_used_retain __attribute__ ((__used__, __retain__))
+#else
+# define attribute_used_retain __attribute__ ((__used__))
+#endif
+
/* Symbol set support macros. */
/* Make SYMBOL, which is in the text segment, an element of SET. */
@@ -301,12 +307,12 @@ for linking")
/* When building a shared library, make the set section writable,
because it will need to be relocated at run time anyway. */
# define _elf_set_element(set, symbol) \
- static const void *__elf_set_##set##_element_##symbol##__ \
- __attribute__ ((used, section (#set))) = &(symbol)
+ static const void *__elf_set_##set##_element_##symbol##__ \
+ attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
#else
# define _elf_set_element(set, symbol) \
- static const void *const __elf_set_##set##_element_##symbol##__ \
- __attribute__ ((used, section (#set))) = &(symbol)
+ static const void *const __elf_set_##set##_element_##symbol##__ \
+ attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
#endif
/* Define SET as a symbol set. This may be required (it is in a.out) to