[RFC PATCH v2] automation: add linker symbol name script

victorm.lira@amd.com posted 1 patch 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/5b2862d6d036248e8cdd76e9884f173c6b7ff325.1721842334.git.victorm.lira@amd.com
There is a newer version of this series
automation/eclair_analysis/linker-symbols.sh | 34 ++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100755 automation/eclair_analysis/linker-symbols.sh
[RFC PATCH v2] automation: add linker symbol name script
Posted by victorm.lira@amd.com 1 month, 2 weeks ago
From: Victor Lira <victorm.lira@amd.com>

Signed-off-by: Victor Lira <victorm.lira@amd.com>
Requested-by: Stefano Stabellini <sstabellini@kernel.org>
---
Notes:
This is a utilty script for help with the MISRA process.
This script matches all linker symbol names in linker script files for
arm and x86.
Not included are symbol names starting with "." or symbol names enclosed
in quotes since the files dont't use any. The regular expression also does
not match for "&=" and similar compound assignments.
---
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: roberto.bagnara@bugseng.com
Cc: consulting@bugseng.com
Cc: simone.ballarin@bugseng.com
---
Changes v2:
- address style comments
- updated script to use .lds instead of .lds.S
- remove sample output from patch
---
 automation/eclair_analysis/linker-symbols.sh | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 automation/eclair_analysis/linker-symbols.sh

diff --git a/automation/eclair_analysis/linker-symbols.sh b/automation/eclair_analysis/linker-symbols.sh
new file mode 100755
index 0000000000..35ec97eb8e
--- /dev/null
+++ b/automation/eclair_analysis/linker-symbols.sh
@@ -0,0 +1,34 @@
+# Stop immediately if any executed command has exit status different from 0.
+set -e
+
+# Extract linker symbol names (except those starting with ".") from assignments.
+
+script_name=$(basename "$0")
+script_dir="$(
+  cd "$(dirname "$0")"
+  echo "${PWD}"
+)"
+src_dir="${script_dir}/../.."
+
+usage() {
+  echo "Usage: ${script_name} <arm|x86>"
+}
+
+if [ $# -ne 1 ]; then
+  usage
+  exit 1
+fi
+
+if [ "$1" != "arm" ] && [ "$1" != "x86" ]; then
+    usage
+    exit 1
+fi
+
+filepath="${src_dir}/xen/arch/${1}/xen.lds"
+
+if [ ! -f "$filepath" ]; then
+    echo "Must be run after build."
+    exit 2
+fi
+
+sed -n "s/^\s*\([a-zA-Z_][a-zA-Z_0-9.\-]*\)\s*=.*;.*$/\1/p" $filepath
--
2.25.1
Re: [RFC PATCH v2] automation: add linker symbol name script
Posted by Jan Beulich 1 month, 2 weeks ago
On 24.07.2024 19:52, victorm.lira@amd.com wrote:
> From: Victor Lira <victorm.lira@amd.com>
> 
> Signed-off-by: Victor Lira <victorm.lira@amd.com>
> Requested-by: Stefano Stabellini <sstabellini@kernel.org>

Note: Tags in chronological order, please. Stefano isn't likely to have requested
that after you signed off on the change. As an aside, aiui Stefano requested this
in response to me having requested it on the call earlier this week.

> --- /dev/null
> +++ b/automation/eclair_analysis/linker-symbols.sh
> @@ -0,0 +1,34 @@
> +# Stop immediately if any executed command has exit status different from 0.
> +set -e
> +
> +# Extract linker symbol names (except those starting with ".") from assignments.
> +
> +script_name=$(basename "$0")
> +script_dir="$(
> +  cd "$(dirname "$0")"
> +  echo "${PWD}"
> +)"
> +src_dir="${script_dir}/../.."
> +
> +usage() {
> +  echo "Usage: ${script_name} <arm|x86>"
> +}
> +
> +if [ $# -ne 1 ]; then
> +  usage
> +  exit 1
> +fi
> +
> +if [ "$1" != "arm" ] && [ "$1" != "x86" ]; then
> +    usage
> +    exit 1
> +fi

This isn't really needed when you ...

> +filepath="${src_dir}/xen/arch/${1}/xen.lds"
> +
> +if [ ! -f "$filepath" ]; then
> +    echo "Must be run after build."
> +    exit 2
> +fi

... check existence first here. Perhaps worth mentioning $1 in the error
message, as having done just some build may not be sufficient.

Plus, for all error messages: The better want re-directing via >&2.

Jan
Re: [RFC PATCH v2] automation: add linker symbol name script
Posted by Stefano Stabellini 1 month, 2 weeks ago
On Wed, 24 Jul 2024, victorm.lira@amd.com wrote:
> From: Victor Lira <victorm.lira@amd.com>
> 
> Signed-off-by: Victor Lira <victorm.lira@amd.com>
> Requested-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> Notes:
> This is a utilty script for help with the MISRA process.
> This script matches all linker symbol names in linker script files for
> arm and x86.
> Not included are symbol names starting with "." or symbol names enclosed
> in quotes since the files dont't use any. The regular expression also does
> not match for "&=" and similar compound assignments.
> ---
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: roberto.bagnara@bugseng.com
> Cc: consulting@bugseng.com
> Cc: simone.ballarin@bugseng.com
> ---
> Changes v2:
> - address style comments
> - updated script to use .lds instead of .lds.S
> - remove sample output from patch
> ---
>  automation/eclair_analysis/linker-symbols.sh | 34 ++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>  create mode 100755 automation/eclair_analysis/linker-symbols.sh
> 
> diff --git a/automation/eclair_analysis/linker-symbols.sh b/automation/eclair_analysis/linker-symbols.sh
> new file mode 100755
> index 0000000000..35ec97eb8e
> --- /dev/null
> +++ b/automation/eclair_analysis/linker-symbols.sh
> @@ -0,0 +1,34 @@

Hi Victor,

A previous comment about the presence of /bin/bash meant to suggest to
use instead something like:

#!/usr/bin/env bash

or if you don't use any bash-ism:

#!/bin/sh

The rest looks OK to me


> +# Stop immediately if any executed command has exit status different from 0.
> +set -e
> +
> +# Extract linker symbol names (except those starting with ".") from assignments.
> +
> +script_name=$(basename "$0")
> +script_dir="$(
> +  cd "$(dirname "$0")"
> +  echo "${PWD}"
> +)"
> +src_dir="${script_dir}/../.."
> +
> +usage() {
> +  echo "Usage: ${script_name} <arm|x86>"
> +}
> +
> +if [ $# -ne 1 ]; then
> +  usage
> +  exit 1
> +fi
> +
> +if [ "$1" != "arm" ] && [ "$1" != "x86" ]; then
> +    usage
> +    exit 1
> +fi
> +
> +filepath="${src_dir}/xen/arch/${1}/xen.lds"
> +
> +if [ ! -f "$filepath" ]; then
> +    echo "Must be run after build."
> +    exit 2
> +fi
> +
> +sed -n "s/^\s*\([a-zA-Z_][a-zA-Z_0-9.\-]*\)\s*=.*;.*$/\1/p" $filepath
> --
> 2.25.1
>