public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: libc-alpha@sourceware.org
Subject: [RFC PATCH 3/6] sys/cdefs.h: Define __TEXT_STARTUP & __TEXT_EXIT
Date: Mon, 15 May 2023 17:48:12 +0300	[thread overview]
Message-ID: <20230515144815.3939017-4-bugaevc@gmail.com> (raw)
In-Reply-To: <20230515144815.3939017-1-bugaevc@gmail.com>

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 --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
-- 
2.40.1


  parent reply	other threads:[~2023-05-15 14:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 14:48 [RFC PATCH 0/6] .text.subsections for some questionable benefit Sergey Bugaev
2023-05-15 14:48 ` [RFC PATCH 1/6] Mark more functions as __COLD Sergey Bugaev
2023-05-15 15:22   ` Andreas Schwab
2023-05-15 15:27     ` Sergey Bugaev
2023-05-18 17:06       ` [PATCH v2] " Sergey Bugaev
2023-05-18 19:43         ` Adhemerval Zanella Netto
2023-05-19 10:35           ` Sergey Bugaev
2023-05-22 20:41             ` Adhemerval Zanella Netto
2023-05-15 14:48 ` [RFC PATCH 2/6] mcheck: Microoptimize Sergey Bugaev
2023-05-15 14:48 ` Sergey Bugaev [this message]
2023-05-15 14:48 ` [RFC PATCH 4/6] Mark various functions as __TEXT_STARTUP and __TEXT_EXIT Sergey Bugaev
2023-05-15 14:48 ` [RFC PATCH 5/6] Also place entry points into .text.startup Sergey Bugaev
2023-05-15 14:48 ` [RFC PATCH 6/6] mach: In rtld, mark MIG routines as __TEXT_STARTUP Sergey Bugaev
2023-05-15 15:33 ` [RFC PATCH 0/6] .text.subsections for some questionable benefit Cristian Rodríguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230515144815.3939017-4-bugaevc@gmail.com \
    --to=bugaevc@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).