Skip to contentSkip to conversation

scripts: Translate profile2linkerlist.

PATCH In review Jorge Natz 2 participants 2 messages Aug 7, 2016

lore
Share & tools
lore

Jorge Natz

author
#0 lore raw

PATCH 1/1 scripts: Translate profile2linkerlist.

profile2linkerlist.pl is a script that takes the sorted output of the readprofile command and turns it into a list of C functions in a format for linker lists. Make the script more portable across POSIX systems. This script does not use any shell-specific features, only POSIX ones. A POSIX shell is present on all UNIX systems, while Perl is not as commonplace.

---

scripts/profile2linkerlist.pl +0 -19
diff -uprN a/scripts/profile2linkerlist.pl b/scripts/profile2linkerlist.pl
@@ -1,19 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Takes a (sorted) output of readprofile and turns it into a list suitable for
-# linker scripts
-#
-# usage:
-#	 readprofile | sort -rn | perl profile2linkerlist.pl > functionlist
-#
-use strict;
-
-while (<>) {
-  my $line = $_;
-
-  $_ =~ /\W*[0-9]+\W*([a-zA-Z\_0-9]+)\W*[0-9]+/;
-
-  print "*(.text.$1)\n"
-      unless ($line =~ /unknown/) || ($line =~ /total/);
-}
scripts/profile2linkerlist.sh +18 -0
diff -uprN a/scripts/profile2linkerlist.sh b/scripts/profile2linkerlist.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Takes a (sorted) output of readprofile and turns it into a list suitable for
+# linker scripts.
+#
+# usage:
+#         readprofile | sort -rn | ./profile2linkerlist.sh > functionlist
+
+# Exit on error
+set -e
+
+while read LINE; do
+	LINE=$( echo $LINE | sed -e s"/[0-9.][0-9.]*//" -e s"/[0-9.][0-9.]*$//" | xargs)
+	case $LINE in *unknown*|*total* ) continue
+	;;
+	esac
+	echo '*(.text.'$LINE')'
+done
#1 lore raw

Dne 7.8.2016 v 20:33 Jorge Natz napsal(a):

Quoted 6 lines
scripts/profile2linkerlist.pl +0 -6
-while (<>) {
-  my $line = $_;
-
-  $_ =~ /\W*[0-9]+\W*([a-zA-Z\_0-9]+)\W*[0-9]+/;
-
-  print "*(.text.$1)\n"

[...]

scripts/profile2linkerlist.sh line 18

Quoted 6 lines
scripts/profile2linkerlist.sh +6 -0
+	LINE=$( echo $LINE | sed -e s"/[0-9.][0-9.]*//" -e s"/[0-9.][0-9.]*$//" | xargs)
+	case $LINE in *unknown*|*total* ) continue
+	;;
+	esac
+	echo '*(.text.'$LINE')'
+done

The two regular expressions are not equivalent and the shell version does not take into account the locale-dependent decimal separator. It also does not handle localized "total", but that's an issue of the perl version as well. Since this script is not used during kernel build, its dependency on perl is less of an issue and it can be left as is.

Michal