On 2024-07-25 21:01, victorm.l...@amd.com wrote:
From: Victor Lira <victorm.l...@amd.com>

Requested-by: Jan Beulich <jbeul...@suse.com>
Signed-off-by: Victor Lira <victorm.l...@amd.com>
---
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 or 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: Jan Beulich <jbeul...@suse.com>
Cc: Stefano Stabellini <sstabell...@kernel.org>
Cc: roberto.bagn...@bugseng.com
Cc: consult...@bugseng.com
Cc: simone.balla...@bugseng.com
---
Changes v2:
- address style comments
- updated script to use .lds instead of .lds.S
- remove sample output from patch

Changes v3:
- use #!/bin/sh
- update error handling and message similar to ../build.sh
---
 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..61790fb281
--- /dev/null
+++ b/automation/eclair_analysis/linker-symbols.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# 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}/../.."
+
+fatal() {
+  echo "${script_name}: $*" >&2
+  exit 1
+}
+
+usage() {
+  fatal "Usage: ${script_name} <arm|x86>"
+}
+
+if [ $# -ne 1 ]; then
+  usage
+fi
+
+filepath="${src_dir}/xen/arch/${1}/xen.lds"
+
+if [ ! -f "$filepath" ]; then
+ fatal "Could not find ${1} linker script. Must be run after arm/x86 build."
+fi
+

A doubt I came across now: since this script must be run after the build (and hence the analysis), but the configuration must be generated before the analysis, the only way this could work in my opinion is this:

- a build without analysis is performed, just enough to build xen.lds (maybe there is a specific Makefile target to do this) - generate the configuration, then clean everything and then run the analysis

+sed -n "s/^\s*\([a-zA-Z_][a-zA-Z_0-9.\-]*\)\s*=.*;.*$/\1/p" "$filepath"
--
2.25.1

--
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)

Reply via email to