diff mbox series

[RFC,3/6] sys/cdefs.h: Define __TEXT_STARTUP & __TEXT_EXIT

Message ID 20230515144815.3939017-4-bugaevc@gmail.com
State New
Headers show
Series .text.subsections for some questionable benefit | expand

Commit Message

Sergey Bugaev May 15, 2023, 2:48 p.m. UTC
GCC already tries to place functions that it knows will only be called
at startup (constructors and main ()) into .text.startup, and those that
will only be called at exit (destructors) into .text.exit, to improve
cache locality. These contents of these sections then get grouped
together during linking.

What GCC does not know is that glibc contains a lot of code that is not
ELF constructors or destructors (nor main ()), but that is also only
executed on startup or exit. To help GCC and the linker group such code
together, we can mark it up explicitly.

To that end, this patch introduces __TEXT_STARTUP and __TEXT_EXIT macros
that can be applied to functions to mark them as startup-only or
exit-only, respectively.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 include/sys/cdefs.h | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h
index ef78edda..da866784 100644
--- a/include/sys/cdefs.h
+++ b/include/sys/cdefs.h
@@ -43,6 +43,9 @@  rtld_hidden_proto (__chk_fail)
 
 #endif
 
+#define __TEXT_STARTUP __attribute__ ((section (".text.startup")))
+#define __TEXT_EXIT __attribute__ ((section (".text.exit")))
+
 #endif /* !defined _ISOMAC */
 
 #endif