From cd6ae7ea5431c2b8f16201fb0e2c413bf8d2df06 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 16 Apr 2021 11:26:39 -0700 Subject: 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 --- config.h.in | 3 +++ 1 file changed, 3 insertions(+) (limited to 'config.h.in') diff --git a/config.h.in b/config.h.in index ca1547ae67..96a08c7757 100644 --- a/config.h.in +++ b/config.h.in @@ -187,6 +187,9 @@ /* Define if gcc supports attribute ifunc. */ #undef HAVE_GCC_IFUNC +/* Define if CC supports attribute retain. */ +#undef HAVE_GNU_RETAIN + /* Define if the linker defines __ehdr_start. */ #undef HAVE_EHDR_START -- cgit 1.4.1