]> git.ipfire.org Git - thirdparty/glibc.git/commit
Set the retain attribute on _elf_set_element if CC supports [BZ #27492]
authorFangrui Song <maskray@google.com>
Fri, 16 Apr 2021 18:26:39 +0000 (11:26 -0700)
committerFangrui Song <maskray@google.com>
Tue, 31 Aug 2021 22:36:41 +0000 (15:36 -0700)
commitadd8e34cd7223dc6770c34de820651eee879ff65
tree1c4ce7396339c339508a0e7f783740f4c31c60a3
parentbc129fb15b826520d16656df99a29910a487c252
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)
13 files changed:
config.h.in
configure
configure.ac
include/libc-symbols.h
libio/Makefile
libio/tst-cleanup-default-static.c [new file with mode: 0644]
libio/tst-cleanup-default.c [new file with mode: 0644]
libio/tst-cleanup-nostart-stop-gc-static.c [new file with mode: 0644]
libio/tst-cleanup-nostart-stop-gc.c [new file with mode: 0644]
libio/tst-cleanup-start-stop-gc-static.c [new file with mode: 0644]
libio/tst-cleanup-start-stop-gc.c [new file with mode: 0644]
libio/tst-cleanup.c [new file with mode: 0644]
libio/tst-cleanup.exp [new file with mode: 0644]