[RFC PATCH 4/4] scripts: convert profile2linkerlist.pl to Python

From: Breno Rodrigues Alves

Date: Sun Oct 18 2026 - 06:14:12 EST


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@xxxxxxxxx>
---
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