mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Breno Rodrigues Alves <breno3011alves@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Breno Rodrigues Alves <breno3011alves@gmail.com>
Subject: [RFC PATCH 4/4] scripts: convert profile2linkerlist.pl to Python
Date: Sun, 18 Oct 2026 07:12:27 -0300	[thread overview]
Message-ID: <20261018101227.7680-5-breno3011alves@gmail.com> (raw)
In-Reply-To: <20261018101227.7680-1-breno3011alves@gmail.com>

Faithful re-implementation of profile2linkerlist.pl in Python 3
(stdlib only).

Note: the original Perl script has a regex that expects the
historical readprofile format '<num> <name> <num>'. Modern
readprofile outputs '<num>\t<name>', so the script produces
incorrect output for modern input (e.g. '*(.text.3)' instead
of '*(.text.foo)'). This behavior is preserved faithfully;
a follow-up patch can fix the regex separately.

Tested with the same input on both versions; output is
byte-for-byte identical.

Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
---
 scripts/profile2linkerlist.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100755 scripts/profile2linkerlist.py

diff --git a/scripts/profile2linkerlist.py b/scripts/profile2linkerlist.py
new file mode 100755
index 000000000..fb7a6def3
--- /dev/null
+++ b/scripts/profile2linkerlist.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# Takes a (sorted) output of readprofile and turns it into a list suitable
+# for linker scripts.
+#
+# usage:
+#     readprofile | sort -rn | python3 profile2linkerlist.py > functionlist
+
+import re
+import sys
+
+RE_PROFILE = re.compile(r'\W*[0-9]+\W*([a-zA-Z_0-9]+)\W*[0-9]+')
+
+
+def main():
+    for line in sys.stdin:
+        if 'unknown' in line or 'total' in line:
+            continue
+        m = RE_PROFILE.search(line)
+        if m:
+            print(f'*(.text.{m.group(1)})')
+    return 0
+
+
+if __name__ == '__main__':
+    sys.exit(main())
\ No newline at end of file
-- 
2.43.0


      parent reply	other threads:[~2026-10-18 10:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18 10:12 [RFC PATCH 0/4] scripts: convert four small Perl utilities " Breno Rodrigues Alves
2026-10-18 10:12 ` [RFC PATCH 1/4] scripts: convert bootgraph.pl " Breno Rodrigues Alves
2026-10-18 10:12 ` [RFC PATCH 2/4] scripts: convert checkincludes.pl " Breno Rodrigues Alves
2026-10-18 10:12 ` [RFC PATCH 3/4] scripts: convert markup_oops.pl " Breno Rodrigues Alves
2026-10-18 10:12 ` Breno Rodrigues Alves [this message]

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=20261018101227.7680-5-breno3011alves@gmail.com \
    --to=breno3011alves@gmail.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /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

all inboxes | Powered by JetHome®