Static analyser finding deviation
cover Static analyser finding deviation
This serie introduces a way to suppress a static analyser finding providing a proper justification for it.
The process is explained in the docs/misra/documenting-violations.rst document that this serie will provide.
The tools currently supported are eclair, coverity and cppcheck, but the design is open to support many other static analysis tool.
The changes are split between the first two patches to reduce the review effort, the first patch is introducing the deviation process for the eclair and coverity tools, this is because their analysis system is similar.
The second patch is introducing the same deviation process for cppcheck, modifying the current way it is called from the makefile and improving its analysis.
The third patch is a fix for a tool used for cppcheck and the fourth patch is an example of how a deviation can be applied for some MISRA findings.
Luca Fancellu (4):
xen/Makefile: add analysis-coverity and analysis-eclair xen/Makefile: add analysis-cppcheck and analysis-cppcheck-html tools/misra: fix skipped rule numbers
xen: Justify linker script defined symbols in include/xen/kernel.h
.gitignore | 10 +- docs/misra/cppcheck.txt | 47 +++-- docs/misra/documenting-violations.rst | 173 +++++++++++++++ docs/misra/false-positive-coverity.json | 12 ++ docs/misra/false-positive-cppcheck.json | 12 ++ docs/misra/false-positive-eclair.json | 12 ++ docs/misra/safe.json | 20 ++ xen/Makefile | 181 +++++++++++----- xen/include/hypercall-defs.c | 9 + xen/include/xen/kernel.h | 4 + xen/tools/convert_misra_doc.py | 32 ++- xen/tools/cppcheck-build-suppr-list.sh | 81 +++++++ xen/tools/cppcheck-cc.sh | 223 ++++++++++++++++++++ xen/tools/cppcheck-html-prepare.sh | 110 ++++++++++ xen/tools/cppcheck-plat/arm32-wchar_t4.xml | 17 ++ xen/tools/cppcheck-plat/arm64-wchar_t2.xml | 17 ++ xen/tools/cppcheck-plat/arm64-wchar_t4.xml | 17 ++ xen/tools/cppcheck-plat/x86_64-wchar_t2.xml | 17 ++ xen/tools/cppcheck-plat/x86_64-wchar_t4.xml | 17 ++ xen/tools/cppcheck-txt-prepare.sh | 74 +++++++ xen/tools/xenfusa-gen-tags.py | 81 +++++++ 21 files changed, 1089 insertions(+), 77 deletions(-) create mode 100644 docs/misra/documenting-violations.rst create mode 100644 docs/misra/false-positive-coverity.json create mode 100644 docs/misra/false-positive-cppcheck.json create mode 100644 docs/misra/false-positive-eclair.json create mode 100644 docs/misra/safe.json create mode 100755 xen/tools/cppcheck-build-suppr-list.sh create mode 100755 xen/tools/cppcheck-cc.sh create mode 100755 xen/tools/cppcheck-html-prepare.sh create mode 100644 xen/tools/cppcheck-plat/arm32-wchar_t4.xml create mode 100644 xen/tools/cppcheck-plat/arm64-wchar_t2.xml create mode 100644 xen/tools/cppcheck-plat/arm64-wchar_t4.xml create mode 100644 xen/tools/cppcheck-plat/x86_64-wchar_t2.xml create mode 100644 xen/tools/cppcheck-plat/x86_64-wchar_t4.xml create mode 100755 xen/tools/cppcheck-txt-prepare.sh create mode 100755 xen/tools/xenfusa-gen-tags.py
Signature · 1 line
2.17.1
RFC PATCH 1/4 xen/Makefile: add analysis-coverity and analysis-eclair
Add new targets to makefile, analysis-{coverity,eclair} that will:
- Create a tag database using a new tool called xenfusa-gen-tags.py
- Get every file with the FuSa tag SAF- in-code comment, create a copy of it as <file>.safparse and substituting the tags with proprietary tool syntax in-code comments using the database.
- build Xen, coverity and eclair are capable of intercepting the compiler invocation on every build file so the only action from them is to run these new targets, the file they will analyse will automatically contain understandable suppression in-code comment for them.
- call analysis-clean to restore original files.
In case of any error, the user needs to manually run the target analysis-clean to restore the original files, before that step, any following run of analysis-{coverity,eclair} will stop and won't overwrite the original files.
Add in docs/misra/ the files safe.json and false-positive-{coverity,eclair}.json that are JSON files containing the data structures for the justifications, they are used by the xenfusa-gen-tags.py to create the substitution list.
Add docs/misra/documenting-violations.rst to explain how to add justifications.
Add files to .gitignore and update clean rule content in Makefile.
--- .gitignore | 2 + docs/misra/documenting-violations.rst | 172 ++++++++++++++++++++++++ docs/misra/false-positive-coverity.json | 12 ++ docs/misra/false-positive-eclair.json | 12 ++ docs/misra/safe.json | 11 ++ xen/Makefile | 50 ++++++- xen/tools/xenfusa-gen-tags.py | 81 +++++++++++ 7 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 docs/misra/documenting-violations.rst create mode 100644 docs/misra/false-positive-coverity.json create mode 100644 docs/misra/false-positive-eclair.json create mode 100644 docs/misra/safe.json create mode 100755 xen/tools/xenfusa-gen-tags.py
.gitignore +2 -0
@@ -10,6 +10,7 @@ *.c.cppcheck *.opic *.a +*.safparse *.so *.so.[0-9]* *.bin
@@ -314,6 +315,7 @@ xen/xsm/flask/policy.* xen/xsm/flask/xenpolicy-* tools/flask/policy/policy.conf tools/flask/policy/xenpolicy-* +xen/*.sed xen/xen xen/xen-cppcheck.xml xen/xen-syms
docs/misra/documenting-violations.rst new file +172 -0
172 lines not on this page · raw message
docs/misra/false-positive-coverity.json new file +12 -0
@@ -0,0 +1,12 @@ +{ + "version": "1.0", + "content": [ + { + "id": "SAF-0-false-positive-coverity", + "analyser": {}, + "tool-version": "", + "name": "Sentinel", + "text": "Next ID to be used" + } + ] +}
docs/misra/false-positive-eclair.json new file +12 -0
@@ -0,0 +1,12 @@ +{ + "version": "1.0", + "content": [ + { + "id": "SAF-0-false-positive-eclair", + "analyser": {}, + "tool-version": "", + "name": "Sentinel", + "text": "Next ID to be used" + } + ] +}
docs/misra/safe.json new file +11 -0
@@ -0,0 +1,11 @@ +{ + "version": "1.0", + "content": [ + { + "id": "SAF-0-safe", + "analyser": {}, + "name": "Sentinel", + "text": "Next ID to be used" + } + ] +}
xen/Makefile +48 -2
68 lines not on this page · raw message
xen/tools/xenfusa-gen-tags.py new file +81 -0
82 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 1 line · Luca Fancellu
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{
+| "version": "1.0",
+| "content": [
+| {
+| "id": "SAF-0-false-positive-<tool>",
+| "analyser": {
+| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 2 lines
+| }, +| "tool-version": "<version>",
... it could be
"analyser": {
"<version>": "<proprietary-id>"
},? It's not really clear to me though how a false positive would be correctly recorded which is present over a range of versions.
Quoted 13 lines
xen/Makefile +2
-1@@ -457,7 +457,8 @@ endif # need-config __all: build -main-targets := build install uninstall clean distclean MAP cppcheck cppcheck-html +main-targets := build install uninstall clean distclean MAP cppcheck \ + cppcheck-html analysis-coverity analysis-eclair .PHONY: $(main-targets) ifneq ($(XEN_TARGET_ARCH),x86_32) $(main-targets): %: _% ;
xen/Makefile _clean: · line 576
Quoted 5 lines
xen/Makefile +1
-1@@ -572,7 +573,7 @@ _clean: rm -f $(TARGET).efi $(TARGET).efi.map $(TARGET).efi.stripped rm -f asm-offsets.s arch/*/include/asm/asm-offsets.h rm -f .banner .allconfig.tmp include/xen/compile.h - rm -f cppcheck-misra.* xen-cppcheck.xml + rm -f cppcheck-misra.* xen-cppcheck.xml *.sed
Is *.sed perhaps a little too wide? But yes, we can of course deal with that in case any *.sed file appears in the source tree.
xen/Makefile cppcheck-version: · line 769
Quoted 13 lines
xen/Makefile +9
-0@@ -757,6 +758,51 @@ cppcheck-version: $(objtree)/include/generated/compiler-def.h: $(Q)$(CC) -dM -E -o $@ - < /dev/null +JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))
Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
xen/Makefile cppcheck-version: · line 773
Quoted 3 lines
xen/Makefile +3
-0+.PRECIOUS: $(PARSE_FILE_LIST) $(objtree)/%.sed + +.SECONDEXPANSION:
I have to admit that I'm a little worried of this living relatively early in the script.
xen/Makefile cppcheck-version: · line 777
Quoted 4 lines
xen/Makefile +4
-0+$(objtree)/%.sed: $(JUSTIFICATION_FILES) $(srctree)/tools/xenfusa-gen-tags.py + $(PYTHON) $(srctree)/tools/xenfusa-gen-tags.py \ + $(foreach file, $(filter %.json, $^), --input $(file)) --output $@ \ + --tool $*
To reduce redundancy, how about
$(objtree)/%.sed: $(srctree)/tools/xenfusa-gen-tags.py $(JUSTIFICATION_FILES)
$(PYTHON) $< --output $@ --tool $* \ $(foreach file, $(filter %.json, $^), --input $(file))
?
xen/Makefile cppcheck-version: · line 779
Quoted 1 line
xen/Makefile +1
-0+%.safparse: %
For this to not be overly widely matching, maybe better
$(PARSE_FILE_LIST): %.safparse: %
?
xen/Makefile cppcheck-version: · line 785
Quoted 6 lines
xen/Makefile +6
-0+# Create a copy of the original file (-p preserves also timestamp) + $(Q)if [ -f "$@" ]; then \ + echo "Found $@, please check the integrity of $*"; \ + exit 1; \ + fi + $(Q)cp -p "$*" "$@"
While you use the full source name as the stem, I still think $< would be more clear to use here.
To limit work done, could this me "mv" instead of "cp -p", and then ...
xen/Makefile cppcheck-version: · line 789
Quoted 3 lines
xen/Makefile +3
-0+analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed + $(Q)for file in $(patsubst %.safparse,%,$(PARSE_FILE_LIST)); do \ + sed -i -f "$(objtree)/$*.sed" "$${file}"; \
... with then using
sed -f "$(objtree)/$*.sed" "$${file}.safparse" >"$${file}"here? This would then also have source consistent between prereqs and rule.
xen/Makefile cppcheck-version: · line 793
Quoted 4 lines
xen/Makefile +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile build
This rule doesn't use the stem, so I'm struggling to understand what this is about.
xen/Makefile cppcheck-version: · line 800
Quoted 6 lines
xen/Makefile +6
-0+analysis-clean: +# Reverts the original file (-p preserves also timestamp) + $(Q)find $(srctree) -type f -name "*.safparse" -print | \ + while IFS= read file; do \ + cp -p "$${file}" "$${file%.safparse}"; \ + rm -f "$${file}"; \
Why not "mv"?
xen/Makefile cppcheck-version: · line 804
Quoted 4 lines
xen/Makefile +4
-0+ done + +_analysis-%: analysis-build-% + $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-clean
Again no use of the stem, plus here I wonder if this may not lead to people invoking "analysis-clean" without having said anything about cleaning on their command line.
Quoted 75 lines
xen/tools/xenfusa-gen-tags.py new file +72
-0@@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import sys, getopt, json + +def help(): + print('Usage: {} [OPTION] ...'.format(sys.argv[0])) + print('') + print('This script converts the justification file to a set of sed rules') + print('that will replace generic tags from Xen codebase in-code comments') + print('to in-code comments having the proprietary syntax for the selected') + print('tool.') + print('') + print('Options:') + print(' -i/--input Json file containing the justifications, can be') + print(' passed multiple times for multiple files') + print(' -o/--output Sed file containing the substitution rules') + print(' -t/--tool Tool that will use the in-code comments') + print('') + +# This is the dictionary for the rules that translates to proprietary comments: +# - cppcheck: /* cppcheck-suppress[id] */ +# - coverity: /* coverity[id] */ +# - eclair: /* -E> hide id 1 "" */ +# Add entries to support more analyzers +tool_syntax = { + "cppcheck":"s,^.*/*[[:space:]]*TAG.*$,/* cppcheck-suppress[VID] */,g", + "coverity":"s,^.*/*[[:space:]]*TAG.*$,/* coverity[VID] */,g", + "eclair":"s,^.*/*[[:space:]]*TAG.*$,/* -E> hide VID 1 \"\" */,g" +} + +def main(argv): + infiles = [] + justifications = [] + outfile = '' + tool = '' + + try: + opts, args = getopt.getopt(argv,"hi:o:t:",["input=","output=","tool="]) + except getopt.GetoptError: + help() + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + help() + sys.exit(0) + elif opt in ("-i", "--input"): + infiles.append(arg) + elif opt in ("-o", "--output"): + outfile = arg + elif opt in ("-t", "--tool"): + tool = arg + + # Open all input files + for file in infiles: + try: + handle = open(file, 'rt') + content = json.load(handle) + justifications = justifications + content['content'] + handle.close() + except json.JSONDecodeError: + print('JSON decoding error in file: ' + file) + except: + print('Error opening ' + file) + sys.exit(1) + + try: + outstr = open(outfile, "w") + except: + print('Error creating ' + outfile) + sys.exit(1) + + for j in justifications:
xen/tools/xenfusa-gen-tags.py line 81
Quoted 10 lines
xen/tools/xenfusa-gen-tags.py new file +9
-0+ if tool in j['analyser']: + comment=tool_syntax[tool].replace("TAG",j['id']) + comment=comment.replace("VID",j['analyser'][tool]) + outstr.write('{}\n'.format(comment)) + + outstr.close() + +if __name__ == "__main__": + main(sys.argv[1:])
Nit: ^^^
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Hi Jan
Quoted 16 lines · Luca Fancellu
Quoted 1 line
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{ +| "version": "1.0", +| "content": [ +| { +| "id": "SAF-0-false-positive-<tool>", +| "analyser": { +| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 8 lines
Quoted 2 lines
+| }, +| "tool-version": "<version>",... it could be
"analyser": { "<version>": "<proprietary-id>" },
Yes it’s a bit redundant but it helps re-using the same tool we use for safe.json
Quoted 3 lines
? It's not really clear to me though how a false positive would be correctly recorded which is present over a range of versions.
We could put a range in "tool-version”: “<verision-old> - <version-new>"
Quoted 27 lines
Quoted 14 lines
xen/Makefile +0
-0@@ -457,7 +457,8 @@ endif # need-config
__all: buildxen/Makefile +2
-1-main-targets := build install uninstall clean distclean MAP cppcheck cppcheck-html +main-targets := build install uninstall clean distclean MAP cppcheck \ + cppcheck-html analysis-coverity analysis-eclair.PHONY: $(main-targets)
ifneq ($(XEN_TARGET_ARCH),x86_32)
$(main-targets): %: _% ;xen/Makefile _clean: · line 576
Quoted 5 lines
xen/Makefile +1
-1@@ -572,7 +573,7 @@ _clean: rm -f $(TARGET).efi $(TARGET).efi.map $(TARGET).efi.stripped rm -f asm-offsets.s arch/*/include/asm/asm-offsets.h rm -f .banner .allconfig.tmp include/xen/compile.h - rm -f cppcheck-misra.* xen-cppcheck.xml + rm -f cppcheck-misra.* xen-cppcheck.xml *.sedIs *.sed perhaps a little too wide? But yes, we can of course deal with that in case any *.sed file appears in the source tree.
Quoted 4 lines
xen/Makefile +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/null
Quoted 13 lines
xen/Makefile cppcheck-version: · line 769
Quoted 9 lines
xen/Makefile +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
PARSE_FILE_LIST := $(addsuffix .safparse,$(filter %.c %.h,\
$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Quoted 15 lines
Quoted 4 lines
+.PRECIOUS: $(PARSE_FILE_LIST) $(objtree)/%.sed
+
+.SECONDEXPANSION:I have to admit that I'm a little worried of this living relatively early in the script.
xen/Makefile cppcheck-version: · line 777
Quoted 4 lines
+$(objtree)/%.sed: $(JUSTIFICATION_FILES) $(srctree)/tools/xenfusa-gen-tags.py
xen/Makefile +3
-0+ $(PYTHON) $(srctree)/tools/xenfusa-gen-tags.py \ + $(foreach file, $(filter %.json, $^), --input $(file)) --output $@ \ + --tool $*To reduce redundancy, how about
Quoted 5 lines
$(objtree)/%.sed: $(srctree)/tools/xenfusa-gen-tags.py $(JUSTIFICATION_FILES)
$(PYTHON) $< --output $@ --tool $* \ $(foreach file, $(filter %.json, $^), --input $(file))?
Yes it sounds better
Quoted 8 lines
Quoted 2 lines
+%.safparse: %
For this to not be overly widely matching, maybe better
$(PARSE_FILE_LIST): %.safparse: %
?
Yes very sensible
Quoted 10 lines
xen/Makefile cppcheck-version: · line 785
Quoted 7 lines
xen/Makefile +6
-0+# Create a copy of the original file (-p preserves also timestamp) + $(Q)if [ -f "$@" ]; then \ + echo "Found $@, please check the integrity of $*"; \ + exit 1; \ + fi + $(Q)cp -p "$*" "$@"While you use the full source name as the stem, I still think $< would be more clear to use here.
Agree
Quoted 9 lines
To limit work done, could this me "mv" instead of "cp -p", and then ...
xen/Makefile cppcheck-version: · line 789
Quoted 3 lines
xen/Makefile +3
-0+analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed + $(Q)for file in $(patsubst %.safparse,%,$(PARSE_FILE_LIST)); do \ + sed -i -f "$(objtree)/$*.sed" "$${file}"; \... with then using
Quoted 4 lines
sed -f "$(objtree)/$*.sed" "$${file}.safparse" >"$${file}"here? This would then also have source consistent between prereqs and rule.
We saw that mv is not preserving the timestamp of the file, instead we would like to preserve it, for this reason we used cp -p
Quoted 8 lines
xen/Makefile cppcheck-version: · line 793
Quoted 5 lines
xen/Makefile +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \
$(XEN_ROOT)/docs/misra/false-positive-$$*.jsonThat will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
Or, if you are still worried about “analysis-build-%: analysis-parse-tags-%”, then I can do something like this:
analysis-supported-coverity analysis-supported-eclair:
@echo > /dev/null
analysis-supported-%:
@error Unsupported analysis tool @*
analysis-build-%: analysis-parse-tags-% | analysis-supported-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile build
[…]
_analysis-%: analysis-build-% | analysis-supported-%
$(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-clean
Quoted 10 lines
xen/Makefile cppcheck-version: · line 800
Quoted 7 lines
xen/Makefile +6
-0+analysis-clean: +# Reverts the original file (-p preserves also timestamp) + $(Q)find $(srctree) -type f -name "*.safparse" -print | \ + while IFS= read file; do \ + cp -p "$${file}" "$${file%.safparse}"; \ + rm -f "$${file}"; \Why not "mv"?
Quoted 8 lines
xen/Makefile cppcheck-version: · line 804
Quoted 4 lines
xen/Makefile +4
-0+ done + +_analysis-%: analysis-build-% + $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-cleanAgain no use of the stem, plus here I wonder if this may not lead to people invoking "analysis-clean" without having said anything about cleaning on their command line.
In any case, the cleaning process is very safe and does not clean anything that was not dirty before, so in case of typos, it’s just like a nop.
Quoted 80 lines
Quoted 80 lines
xen/tools/xenfusa-gen-tags.py new file +76
-0@@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import sys, getopt, json + +def help(): + print('Usage: {} [OPTION] ...'.format(sys.argv[0])) + print('') + print('This script converts the justification file to a set of sed rules') + print('that will replace generic tags from Xen codebase in-code comments') + print('to in-code comments having the proprietary syntax for the selected') + print('tool.') + print('') + print('Options:') + print(' -i/--input Json file containing the justifications, can be') + print(' passed multiple times for multiple files') + print(' -o/--output Sed file containing the substitution rules') + print(' -t/--tool Tool that will use the in-code comments') + print('') + +# This is the dictionary for the rules that translates to proprietary comments: +# - cppcheck: /* cppcheck-suppress[id] */ +# - coverity: /* coverity[id] */ +# - eclair: /* -E> hide id 1 "" */ +# Add entries to support more analyzers +tool_syntax = { + "cppcheck":"s,^.*/*[[:space:]]*TAG.*$,/* cppcheck-suppress[VID] */,g", + "coverity":"s,^.*/*[[:space:]]*TAG.*$,/* coverity[VID] */,g", + "eclair":"s,^.*/*[[:space:]]*TAG.*$,/* -E> hide VID 1 \"\" */,g" +} + +def main(argv): + infiles = [] + justifications = [] + outfile = '' + tool = '' + + try: + opts, args = getopt.getopt(argv,"hi:o:t:",["input=","output=","tool="]) + except getopt.GetoptError: + help() + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + help() + sys.exit(0) + elif opt in ("-i", "--input"): + infiles.append(arg) + elif opt in ("-o", "--output"): + outfile = arg + elif opt in ("-t", "--tool"): + tool = arg + + # Open all input files + for file in infiles: + try: + handle = open(file, 'rt') + content = json.load(handle) + justifications = justifications + content['content'] + handle.close() + except json.JSONDecodeError: + print('JSON decoding error in file: ' + file) + except: + print('Error opening ' + file) + sys.exit(1) + + try: + outstr = open(outfile, "w") + except: + print('Error creating ' + outfile) + sys.exit(1) + + for j in justifications: + if tool in j['analyser']: + comment=tool_syntax[tool].replace("TAG",j['id']) + comment=comment.replace("VID",j['analyser'][tool]) + outstr.write('{}\n'.format(comment))
Quoted 8 lines
xen/tools/xenfusa-gen-tags.py line 81
Quoted 6 lines
xen/tools/xenfusa-gen-tags.py new file +5
-0+ + outstr.close() + +if __name__ == "__main__": + main(sys.argv[1:])Nit: ^^^
Will fix
Quoted 2 lines
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 18 lines · Luca Fancellu
Quoted 18 lines · Luca Fancellu
Quoted 1 line
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{ +| "version": "1.0", +| "content": [ +| { +| "id": "SAF-0-false-positive-<tool>", +| "analyser": { +| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 2 lines
+| }, +| "tool-version": "<version>",
Quoted 7 lines
Quoted 5 lines
... it could be
"analyser": { "<version>": "<proprietary-id>" },Yes it’s a bit redundant but it helps re-using the same tool we use for safe.json
I guess the tool could also be made cope without much effort.
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
xen/Makefile cppcheck-version: · line 769
Quoted 9 lines
xen/Makefile +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Quoted 4 lines
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
PARSE_FILE_LIST := $(addsuffix .safparse,$(filter %.c %.h,\ $(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))
That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Quoted 8 lines
Quoted 8 lines
To limit work done, could this me "mv" instead of "cp -p", and then ...
xen/Makefile cppcheck-version: · line 789
Quoted 3 lines
xen/Makefile +3
-0+analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed + $(Q)for file in $(patsubst %.safparse,%,$(PARSE_FILE_LIST)); do \ + sed -i -f "$(objtree)/$*.sed" "$${file}"; \... with then using
Quoted 7 lines
Quoted 4 lines
sed -f "$(objtree)/$*.sed" "$${file}.safparse" >"$${file}"here? This would then also have source consistent between prereqs and rule.
We saw that mv is not preserving the timestamp of the file, instead we would like to preserve it, for this reason we used cp -p
Buggy mv? It certainly doesn't alter timestamps here, and I don't think the spec allows for it doing so (at least when it doesn't need to resort to copying to deal with cross-volume moves, but those can't happen here).
Quoted 11 lines
Quoted 7 lines
xen/Makefile cppcheck-version: · line 793
Quoted 4 lines
xen/Makefile +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
Quoted 8 lines
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.jsonThat will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
But then, without using the stem, how does it know whether to do an Eclair or a Coverity run?
Quoted 11 lines
Or, if you are still worried about “analysis-build-%: analysis-parse-tags-%”, then I can do something like this:
analysis-supported-coverity analysis-supported-eclair:
@echo >/dev/nullanalysis-supported-%:
@error Unsupported analysis tool @*analysis-build-%: analysis-parse-tags-% | analysis-supported-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile build
If I'm not mistaken support for | doesn't exist in make 3.80 (the minimum version we require to be used).
Quoted 18 lines
Quoted 9 lines
xen/Makefile cppcheck-version: · line 800
Quoted 6 lines
xen/Makefile +6
-0+analysis-clean: +# Reverts the original file (-p preserves also timestamp) + $(Q)find $(srctree) -type f -name "*.safparse" -print | \ + while IFS= read file; do \ + cp -p "$${file}" "$${file%.safparse}"; \ + rm -f "$${file}"; \Why not "mv"?
Quoted 8 lines
xen/Makefile cppcheck-version: · line 804
Quoted 4 lines
xen/Makefile +4
-0+ done + +_analysis-%: analysis-build-% + $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-cleanAgain no use of the stem, plus here I wonder if this may not lead to people invoking "analysis-clean" without having said anything about cleaning on their command line.
Quoted 2 lines
In any case, the cleaning process is very safe and does not clean anything that was not dirty before, so in case of typos, it’s just like a nop.
People may put transient files in their trees. Of course they need to be aware that when they specify a "clean" target their files may be deleted. But without any "clean" target specified nothing should be removed.
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 25 lines · Jan Beulich
Quoted 20 lines · Luca Fancellu
Quoted 20 lines · Luca Fancellu
Quoted 1 line
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{ +| "version": "1.0", +| "content": [ +| { +| "id": "SAF-0-false-positive-<tool>", +| "analyser": { +| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 2 lines
+| }, +| "tool-version": "<version>",... it could be
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
"analyser": { "<version>": "<proprietary-id>" },Yes it’s a bit redundant but it helps re-using the same tool we use for safe.json
I guess the tool could also be made cope without much effort.
I can modify the script to take an additional parameter to distinguish between safe.json and false-positive-*.json, then call twice the script and append the result to the .sed file.
Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
xen/Makefile cppcheck-version: · line 769
Quoted 9 lines
xen/Makefile +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST := $(addsuffix .safparse,$(filter %.c %.h,\ $(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Ok would it be ok?
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include=\*.h \
--include=\*.c '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree)))Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
To limit work done, could this me "mv" instead of "cp -p", and then ...
xen/Makefile cppcheck-version: · line 789
Quoted 3 lines
xen/Makefile +3
-0+analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed + $(Q)for file in $(patsubst %.safparse,%,$(PARSE_FILE_LIST)); do \ + sed -i -f "$(objtree)/$*.sed" "$${file}"; \... with then using
sed -f "$(objtree)/$*.sed" "$${file}.safparse" >"$${file}"here? This would then also have source consistent between prereqs and rule.
Quoted 6 lines
Quoted 2 lines
We saw that mv is not preserving the timestamp of the file, instead we would like to preserve it, for this reason we used cp -p
Buggy mv? It certainly doesn't alter timestamps here, and I don't think the spec allows for it doing so (at least when it doesn't need to resort to copying to deal with cross-volume moves, but those can't happen here).
Yes you are right, my assumption was wrong, I will change the code as you suggested.
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines
xen/Makefile cppcheck-version: · line 793
Quoted 5 lines
xen/Makefile +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.json
Quoted 8 lines
Quoted 5 lines
That will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
But then, without using the stem, how does it know whether to do an Eclair or a Coverity run?
Sorry I think I’m a bit lost here, the makefile is working on both analysis-coverity and analysis-eclair because the % is solving in coverity or eclair depending on which the makefile has in input, it is not complaining so I guess it works.
Do you see something not working? If so, are you able to provide a piece of code for that to make me understand?
Quoted 7 lines
Quoted 7 lines
Or, if you are still worried about “analysis-build-%: analysis-parse-tags-%”, then I can do something like this:
analysis-supported-coverity analysis-supported-eclair:
@echo >/dev/null
Quoted 8 lines
Quoted 5 lines
analysis-supported-%:
@error Unsupported analysis tool @*analysis-build-%: analysis-parse-tags-% | analysis-supported-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildIf I'm not mistaken support for | doesn't exist in make 3.80 (the minimum version we require to be used).
IDK, we use order-only prerequisite already in the Makefile.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
xen/Makefile cppcheck-version: · line 800
Quoted 7 lines
xen/Makefile +6
-0+analysis-clean: +# Reverts the original file (-p preserves also timestamp) + $(Q)find $(srctree) -type f -name "*.safparse" -print | \ + while IFS= read file; do \ + cp -p "$${file}" "$${file%.safparse}"; \ + rm -f "$${file}"; \Why not "mv"?
xen/Makefile cppcheck-version: · line 804
Quoted 4 lines
xen/Makefile +4
-0+ done + +_analysis-%: analysis-build-% + $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-cleanAgain no use of the stem, plus here I wonder if this may not lead to people invoking "analysis-clean" without having said anything about cleaning on their command line.
Quoted 6 lines
Quoted 2 lines
In any case, the cleaning process is very safe and does not clean anything that was not dirty before, so in case of typos, it’s just like a nop.
People may put transient files in their trees. Of course they need to be aware that when they specify a "clean" target their files may be deleted. But without any "clean" target specified nothing should be removed.
*.safparse files are not supposed to be used freely by user in their tree, those files will be removed only if the user calls the “analysis-clean” target or if the analysis-coverity or analysis-eclair reaches the end (a process that creates *.safparse).
There is no other way to trigger the “analysis-clean” unintentionally, so I’m not sure about the modification you would like to see there.
Quoted 2 lines
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 31 lines · Luca Fancellu
Quoted 23 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
Quoted 5 lines · Luca Fancellu
Quoted 4 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
xen/Makefile cppcheck-version: · line 769
Quoted 9 lines
xen/Makefile +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST := $(addsuffix .safparse,$(filter %.c %.h,\ $(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Quoted 4 lines
Ok would it be ok?
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include=\*.h \ --include=\*.c '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree)))
Hmm, not sure: --include isn't a standard option to grep, and we generally try to be portable. Actually -R (or -r) isn't either. It may still be okay that way if properly documented where the involved goals will work and where not.
And then - why do you escape slashes in the ERE?
Talking of escaping - personally I find backslash escapes harder to read / grok than quotation, so I'd like to recommend using quotes around each of the two --include (if they remain in the first place) instead of the \* construct.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
xen/Makefile cppcheck-version: · line 793
Quoted 4 lines
xen/Makefile +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.jsonThat will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
Quoted 7 lines
Quoted 2 lines
But then, without using the stem, how does it know whether to do an Eclair or a Coverity run?
Sorry I think I’m a bit lost here, the makefile is working on both analysis-coverity and analysis-eclair because the % is solving in coverity or eclair depending on which the makefile has in input, it is not complaining so I guess it works.
Do you see something not working? If so, are you able to provide a piece of code for that to make me understand?
Well, my problem is that I don't see how the distinction is conveyed without the stem being used. With what you say I understand I'm overlooking something, so I'd appreciate some explanation or at least a pointer.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Or, if you are still worried about “analysis-build-%: analysis-parse-tags-%”, then I can do something like this:
analysis-supported-coverity analysis-supported-eclair:
@echo >/dev/nullanalysis-supported-%:
@error Unsupported analysis tool @*
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
analysis-build-%: analysis-parse-tags-% | analysis-supported-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildIf I'm not mistaken support for | doesn't exist in make 3.80 (the minimum version we require to be used).
IDK, we use order-only prerequisite already in the
Makefile.
Hmm, yes, for $(objtree)/%.c.cppcheck: . Question is whether this was simply overlooked before. As said above such may be okay for these special goals, but this needs properly documenting then.
Quoted 25 lines
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
xen/Makefile cppcheck-version: · line 800
Quoted 6 lines
xen/Makefile +6
-0+analysis-clean: +# Reverts the original file (-p preserves also timestamp) + $(Q)find $(srctree) -type f -name "*.safparse" -print | \ + while IFS= read file; do \ + cp -p "$${file}" "$${file%.safparse}"; \ + rm -f "$${file}"; \Why not "mv"?
xen/Makefile cppcheck-version: · line 804
Quoted 4 lines
xen/Makefile +4
-0+ done + +_analysis-%: analysis-build-% + $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-cleanAgain no use of the stem, plus here I wonder if this may not lead to people invoking "analysis-clean" without having said anything about cleaning on their command line.
Quoted 6 lines
Quoted 2 lines
In any case, the cleaning process is very safe and does not clean anything that was not dirty before, so in case of typos, it’s just like a nop.
People may put transient files in their trees. Of course they need to be aware that when they specify a "clean" target their files may be deleted. But without any "clean" target specified nothing should be removed.
Quoted 6 lines
*.safparse files are not supposed to be used freely by user in their tree, those files will be removed only if the user calls the “analysis-clean” target or if the analysis-coverity or analysis-eclair reaches the end (a process that creates *.safparse).
There is no other way to trigger the “analysis-clean” unintentionally, so I’m not sure about the modification you would like to see there.
I guess I don't understand: You have _analysis-% as the target, which I'd assume will handle _analysis-clean just as much as _analysis-abc. This may be connected to my lack of understanding as expressed further up. Or maybe I'm simply not understanding what the _analysis-% target is about in the first place, because with the analysis-build-% dependency I don't see how _analysis-clean would actually work (with the scope restriction you suggested earlier a rule for analysis-build-clean would not be found afaict).
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 38 lines · Jan Beulich
Quoted 33 lines · Luca Fancellu
Quoted 23 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
Quoted 5 lines · Luca Fancellu
Quoted 4 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
xen/Makefile cppcheck-version: · line 769
Quoted 9 lines
xen/Makefile +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST:= $(addsuffix .safparse,$(filter %.c %.h,\
$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Ok would it be ok?
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include=\*.h \ --include=\*.c '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree)))Hmm, not sure: --include isn't a standard option to grep, and we generally try to be portable. Actually -R (or -r) isn't either. It may still be okay that way if properly documented where the involved goals will work and where not.
Is a comment before the line ok as documentation? To state that —include and -R are not standard options so analysis-{coverity,eclair} will not work without a grep that takes those parameters?
Quoted 7 lines
And then - why do you escape slashes in the ERE?
Talking of escaping - personally I find backslash escapes harder to read / grok than quotation, so I'd like to recommend using quotes around each of the two --include (if they remain in the first place) instead of the \* construct.
Ok I’ve removed the escape from the * and also from slashes:
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include='*.h' \
--include='*.c' '^[[:blank:]]*/\*[[:space:]]+SAF-.*\*/$$' $(srctree)))Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 8 lines
xen/Makefile cppcheck-version: · line 793
Quoted 5 lines
xen/Makefile +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.jsonThat will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
Quoted 7 lines
Quoted 2 lines
But then, without using the stem, how does it know whether to do an Eclair or a Coverity run?
Sorry I think I’m a bit lost here, the makefile is working on both analysis-coverity and analysis-eclair because the % is solving in coverity or eclair depending on which the makefile has in input, it is not complaining so I guess it works.
Do you see something not working? If so, are you able to provide a piece of code for that to make me understand?
Quoted 4 lines
Well, my problem is that I don't see how the distinction is conveyed without the stem being used. With what you say I understand I'm overlooking something, so I'd appreciate some explanation or at least a pointer.
Ok, I have that eclair and coverity shares the same commands to be executed by the build system, so instead of duplicating the targets for coverity and eclair and their recipe, I’ve used the pattern rule to have that these rules:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \
$(XEN_ROOT)/docs/misra/false-positive-$$*.json[…]
.SECONDEXPANSION:
$(objtree)/%.sed: $(srctree)/tools/xenfusa-gen-tags.py $(JUSTIFICATION_FILES)
[…]
[…]
analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed
[…]
analysis-build-%: analysis-parse-tags-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile build
analysis-clean:
[…]
_analysis-%: analysis-build-%
$(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-clean
Matches the case where 'make analysis-coverity’ or ‘make analysis-eclair’ is called.
Now, please correct me if my assumption on the way make works are wrong, here my assumptions:
For example when ‘make analysis-coverity’ is called we have that this rule is the best match for the called target:
_analysis-%:
So anything after _analysis- will be captured with % and this will be transferred to the dependency of the target that is analysis-build-% -> analysis-build-coverity
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
We will have the same with ‘make analysis-eclair’, if we do a mistake typing, like ‘make analysis-coveri’, we will have:
make: Entering directory ‘/path/to/xen/xen'
make: *** No rule to make target 'analysis-coveri'. Stop.
make: Leaving directory '/path/to/xen/xen'
Quoted 54 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Or, if you are still worried about “analysis-build-%: analysis-parse-tags-%”, then I can do something like this:
analysis-supported-coverity analysis-supported-eclair:
@echo >/dev/nullanalysis-supported-%:
@error Unsupported analysis tool @*Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
analysis-build-%: analysis-parse-tags-% | analysis-supported-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildIf I'm not mistaken support for | doesn't exist in make 3.80 (the minimum version we require to be used).
IDK, we use order-only prerequisite already in the
Makefile.Hmm, yes, for $(objtree)/%.c.cppcheck: . Question is whether this was simply overlooked before. As said above such may be okay for these special goals, but this needs properly documenting then.
Quoted 25 lines
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
xen/Makefile cppcheck-version: · line 800
Quoted 6 lines
xen/Makefile +6
-0+analysis-clean: +# Reverts the original file (-p preserves also timestamp) + $(Q)find $(srctree) -type f -name "*.safparse" -print | \ + while IFS= read file; do \ + cp -p "$${file}" "$${file%.safparse}"; \ + rm -f "$${file}"; \Why not "mv"?
xen/Makefile cppcheck-version: · line 804
Quoted 4 lines
xen/Makefile +4
-0+ done + +_analysis-%: analysis-build-% + $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-cleanAgain no use of the stem, plus here I wonder if this may not lead to people invoking "analysis-clean" without having said anything about cleaning on their command line.
Quoted 6 lines
Quoted 2 lines
In any case, the cleaning process is very safe and does not clean anything that was not dirty before, so in case of typos, it’s just like a nop.
People may put transient files in their trees. Of course they need to be aware that when they specify a "clean" target their files may be deleted. But without any "clean" target specified nothing should be removed.
Quoted 6 lines
*.safparse files are not supposed to be used freely by user in their tree, those files will be removed only if the user calls the “analysis-clean” target or if the analysis-coverity or analysis-eclair reaches the end (a process that creates *.safparse).
There is no other way to trigger the “analysis-clean” unintentionally, so I’m not sure about the modification you would like to see there.
Quoted 8 lines
I guess I don't understand: You have _analysis-% as the target, which I'd assume will handle _analysis-clean just as much as _analysis-abc. This may be connected to my lack of understanding as expressed further up. Or maybe I'm simply not understanding what the _analysis-% target is about in the first place, because with the analysis-build-% dependency I don't see how _analysis-clean would actually work (with the scope restriction you suggested earlier a rule for analysis-build-clean would not be found afaict).
_analysis-clean will not work, neither _analysis-abc, because of what I wrote above. analysis-clean instead is called from the recipe of _analysis-% if all its dependency are built correctly, otherwise it’s the user that needs to call it directly by doing “make analysis-clean”.
Quoted 2 lines
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 38 lines · Luca Fancellu
Quoted 38 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 23 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
Quoted 5 lines · Luca Fancellu
Quoted 4 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST:= $(addsuffix .safparse,$(filter %.c %.h,\
$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Ok would it be ok?
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include=\*.h \ --include=\*.c '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree)))
Quoted 8 lines
Quoted 4 lines
Hmm, not sure: --include isn't a standard option to grep, and we generally try to be portable. Actually -R (or -r) isn't either. It may still be okay that way if properly documented where the involved goals will work and where not.
Is a comment before the line ok as documentation? To state that —include and -R are not standard options so analysis-{coverity,eclair} will not work without a grep that takes those parameters?
A comment _might_ be okay. Is there no other documentation on how these goals are to be used? The main question here is how impacting this might be to the various environments we allow Xen to be built in: Would at least modern versions of all Linux distros we care about allow using these rules? What about non-Linux?
And could you at least bail when PARSE_FILE_LIST ends up empty, with a clear error message augmenting the one grep would have issued?
Quoted 11 lines
Quoted 6 lines
And then - why do you escape slashes in the ERE?
Talking of escaping - personally I find backslash escapes harder to read / grok than quotation, so I'd like to recommend using quotes around each of the two --include (if they remain in the first place) instead of the \* construct.
Ok I’ve removed the escape from the * and also from slashes:
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include='*.h' \ --include='*.c' '^[[:blank:]]*/\*[[:space:]]+SAF-.*\*/$$' $(srctree)))
Good - seeing things more clearly now my next question is: Isn't matching just "/* SAF-...*/" a little too lax? And is there really a need to permit leading blanks?
Quoted 60 lines
Quoted 28 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.jsonThat will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
Quoted 7 lines
Quoted 2 lines
But then, without using the stem, how does it know whether to do an Eclair or a Coverity run?
Sorry I think I’m a bit lost here, the makefile is working on both analysis-coverity and analysis-eclair because the % is solving in coverity or eclair depending on which the makefile has in input, it is not complaining so I guess it works.
Do you see something not working? If so, are you able to provide a piece of code for that to make me understand?Quoted 4 lines
Well, my problem is that I don't see how the distinction is conveyed without the stem being used. With what you say I understand I'm overlooking something, so I'd appreciate some explanation or at least a pointer.
Ok, I have that eclair and coverity shares the same commands to be executed by the build system, so instead of duplicating the targets for coverity and eclair and their recipe, I’ve used the pattern rule to have that these rules:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.json[…]
.SECONDEXPANSION:
$(objtree)/%.sed: $(srctree)/tools/xenfusa-gen-tags.py $(JUSTIFICATION_FILES)[…][…]
analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed
[…]analysis-build-%: analysis-parse-tags-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildanalysis-clean:
[…]_analysis-%: analysis-build-%
$(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-clean
Quoted 8 lines
Matches the case where 'make analysis-coverity’ or ‘make analysis-eclair’ is called.
Now, please correct me if my assumption on the way make works are wrong, here my assumptions:
For example when ‘make analysis-coverity’ is called we have that this rule is the best match for the called target:
_analysis-%:
So my main oversight was your addition to main-targets, which makes the connection with this underscore-prefixed goal.
As to you saying "best match" - I didn't think make had such a concept when it comes to considering pattern rules. Aiui it is "first match", in the order that rules were parsed from all involved makefiles.
Quoted 9 lines
So anything after _analysis- will be captured with % and this will be transferred to the dependency of the target that is analysis-build-% -> analysis-build-coverity
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 17 lines
Quoted 17 lines · Luca Fancellu
Quoted 1 line
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{ +| "version": "1.0", +| "content": [ +| { +| "id": "SAF-0-false-positive-<tool>", +| "analyser": { +| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
+| }, +| "tool-version": "<version>",... it could be
"analyser": { "<version>": "<proprietary-id>" },
About this, I’ve investigated a bit and I don’t think this is the right solution, it wouldn't make much sense to have a schema where in one file the analyser dictionary key is the tool name and in another it is a version (or range of versions).
However I can remove the analyser dictionary and use this schema for the false-positive, which is more compact:
|{
| "version": "1.0",
| "content": [
| {
| "id": "SAF-0-false-positive-<tool>",
| “tool-proprietary-id”: "<proprietary-id>”,
| "tool-version": "<version>",
| "name": "R20.7 [...]",
| "text": "[...]"
| },
| {
| "id": "SAF-1-false-positive-<tool>",
| “tool-proprietary-id”: "",
| "tool-version": "",
| "name": "Sentinel",
| "text": "Next ID to be used"
| }
| ]
|}This needs however a change in the initial design and more documentation on the different handlings of the safe.json schema and the false-positive-<tool>.json schema. Is it worth?
Quoted 50 lines · Jan Beulich
Quoted 38 lines · Luca Fancellu
Quoted 38 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 23 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
Quoted 5 lines · Luca Fancellu
Quoted 4 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST:= $(addsuffix .safparse,$(filter %.c %.h,\
$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Ok would it be ok?
PARSE_FILE_LIST:= $(addsuffix .safparse,$(shell grep -ERl --include=\*.h \
--include=\*.c '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree)))Quoted 8 lines
Quoted 4 lines
Hmm, not sure: --include isn't a standard option to grep, and we generally try to be portable. Actually -R (or -r) isn't either. It may still be okay that way if properly documented where the involved goals will work and where not.
Is a comment before the line ok as documentation? To state that —include and -R are not standard options so analysis-{coverity,eclair} will not work without a grep that takes those parameters?
Quoted 8 lines
A comment _might_ be okay. Is there no other documentation on how these goals are to be used? The main question here is how impacting this might be to the various environments we allow Xen to be built in: Would at least modern versions of all Linux distros we care about allow using these rules? What about non-Linux?
And could you at least bail when
PARSE_FILE_LISTends up empty, with a clear error message augmenting the one grep would have issued?
An empty PARSE_FILE_LIST should not generate an error, it just means there are no justifications, but I see it can be problematic in case grep does not work.
What about this? They should be standard options right?
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell find $(srctree) -type f \
-name '*.c' -o -name '*.h' -exec \
grep -El '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' {} + ))Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
And then - why do you escape slashes in the ERE?
Talking of escaping - personally I find backslash escapes harder to read / grok than quotation, so I'd like to recommend using quotes around each of the two --include (if they remain in the first place) instead of the \* construct.
Quoted 8 lines
Quoted 4 lines
Ok I’ve removed the escape from the * and also from slashes:
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include='*.h' \ --include='*.c' '^[[:blank:]]*/\*[[:space:]]+SAF-.*\*/$$' $(srctree)))Good - seeing things more clearly now my next question is: Isn't matching just "/* SAF-...*/" a little too lax? And is there really a need to permit leading blanks?
I’m permitting blanks to allow spaces or tabs, zero or more times before the start of the comment, I think it shall be like that.
About matching, maybe I can match also the number after SAF-, this should be enough,
[…] grep -El '^[[:blank:]]*\/\*[[:space:]]+SAF-[0-9]+.*\*\/$$’ […]
Quoted 68 lines
Quoted 68 lines
Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +4
-0+ done + +analysis-build-%: analysis-parse-tags-% + $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildThis rule doesn't use the stem, so I'm struggling to understand what this is about.
Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that if the user has a typo the rule will run anyway, but it will be stopped by the dependency chain because at the end we have:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.jsonThat will give an error because $(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.
If you think it is not enough, what if I reduce the scope of the rule like this?
_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%
Quoted 7 lines
Quoted 2 lines
But then, without using the stem, how does it know whether to do an Eclair or a Coverity run?
Sorry I think I’m a bit lost here, the makefile is working on both analysis-coverity and analysis-eclair because the % is solving in coverity or eclair depending on which the makefile has in input, it is not complaining so I guess it works.
Do you see something not working? If so, are you able to provide a piece of code for that to make me understand?Quoted 4 lines
Well, my problem is that I don't see how the distinction is conveyed without the stem being used. With what you say I understand I'm overlooking something, so I'd appreciate some explanation or at least a pointer.
Ok, I have that eclair and coverity shares the same commands to be executed by the build system, so instead of duplicating the targets for coverity and eclair and their recipe, I’ve used the pattern rule to have that these rules:
JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ $(XEN_ROOT)/docs/misra/false-positive-$$*.json[…]
.SECONDEXPANSION:
$(objtree)/%.sed: $(srctree)/tools/xenfusa-gen-tags.py $(JUSTIFICATION_FILES)
[…][…]
analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed
[…]analysis-build-%: analysis-parse-tags-%
$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile buildanalysis-clean:
[…]_analysis-%: analysis-build-%
$(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-cleanMatches the case where 'make analysis-coverity’ or ‘make analysis-eclair’ is called.
Now, please correct me if my assumption on the way make works are wrong, here my assumptions:
For example when ‘make analysis-coverity’ is called we have that this rule is the best match for the called target:
Quoted 8 lines
Quoted 1 line
_analysis-%:
So my main oversight was your addition to main-targets, which makes the connection with this underscore-prefixed goal.
As to you saying "best match" - I didn't think make had such a concept when it comes to considering pattern rules. Aiui it is "first match", in the order that rules were parsed from all involved makefiles.
Yes first match is the right term.
Quoted 28 lines
Quoted 10 lines
So anything after _analysis- will be captured with % and this will be transferred to the dependency of the target that is analysis-build-% -> analysis-build-coverity
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
Quoted 5 lines
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
What do you think?
Cheers,
Luca
Quoted 2 lines
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 51 lines · Luca Fancellu
Quoted 15 lines
Quoted 15 lines · Luca Fancellu
Quoted 1 line
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{ +| "version": "1.0", +| "content": [ +| { +| "id": "SAF-0-false-positive-<tool>", +| "analyser": { +| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
+| }, +| "tool-version": "<version>",... it could be
"analyser": { "<version>": "<proprietary-id>" },About this, I’ve investigated a bit and I don’t think this is the right solution, it wouldn't make much sense to have a schema where in one file the analyser dictionary key is the tool name and in another it is a version (or range of versions).
However I can remove the analyser dictionary and use this schema for the false-positive, which is more compact:
|{ | "version": "1.0", | "content": [ | { | "id": "SAF-0-false-positive-<tool>", | “tool-proprietary-id”: "<proprietary-id>”, | "tool-version": "<version>", | "name": "R20.7 [...]", | "text": "[...]" | }, | { | "id": "SAF-1-false-positive-<tool>", | “tool-proprietary-id”: "", | "tool-version": "", | "name": "Sentinel", | "text": "Next ID to be used" | } | ] |}
Quoted 2 lines
This needs however a change in the initial design and more documentation on the different handlings of the safe.json schema and the false-positive-<tool>.json schema. Is it worth?
I think it is, but of others disagree, so be it.
Quoted 59 lines
Quoted 50 lines · Jan Beulich
Quoted 38 lines · Luca Fancellu
Quoted 38 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 23 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
Quoted 5 lines · Luca Fancellu
Quoted 4 lines
(quoted diff) +0
-0@@ -757,6 +758,51 @@ cppcheck-version:$(objtree)/include/generated/compiler-def.h:
$(Q)$(CC) -dM -E -o $@ - < /dev/nullQuoted 13 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \ + $(XEN_ROOT)/docs/misra/false-positive-$$*.json + +# The following command is using grep to find all files that contains a comment +# containing "SAF-<anything>" on a single line. +# %.safparse will be the original files saved from the build system, these files +# will be restored at the end of the analysis step +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\ +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))Please indent such line continuations. And then isn't this going to risk matching non-source files as well? Perhaps you want to restrict this to *.c and *.h?
Yes, how about this, it will filter out *.safparse files while keeping in only .h and .c:
Quoted 7 lines
Quoted 2 lines
PARSE_FILE_LIST:= $(addsuffix .safparse,$(filter %.c %.h,\
$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))That's better, but still means touching all files by grep despite now only a subset really looked for. If I was to use the new goals on a more or less regular basis, I'd expect that this enumeration of files doesn't read _much_ more stuff from disk than is actually necessary.
Ok would it be ok?
PARSE_FILE_LIST:= $(addsuffix .safparse,$(shell grep -ERl --include=\*.h \
--include=\*.c '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree)))Quoted 8 lines
Quoted 4 lines
Hmm, not sure: --include isn't a standard option to grep, and we generally try to be portable. Actually -R (or -r) isn't either. It may still be okay that way if properly documented where the involved goals will work and where not.
Is a comment before the line ok as documentation? To state that —include and -R are not standard options so analysis-{coverity,eclair} will not work without a grep that takes those parameters?
Quoted 8 lines
A comment _might_ be okay. Is there no other documentation on how these goals are to be used? The main question here is how impacting this might be to the various environments we allow Xen to be built in: Would at least modern versions of all Linux distros we care about allow using these rules? What about non-Linux?
And could you at least bail when
PARSE_FILE_LISTends up empty, with a clear error message augmenting the one grep would have issued?
Quoted 8 lines
An empty
PARSE_FILE_LISTshould not generate an error, it just means there are no justifications, but I see it can be problematic in case grep does not work.What about this? They should be standard options right?
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell find $(srctree) -type f \ -name '*.c' -o -name '*.h' -exec \ grep -El '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' {} + ))
Coming closer to being generally usable. You now have the problem of potentially exceeding command line limits (iirc there were issues in find and/or kernels), but I agree it looks standard-conforming now.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
And then - why do you escape slashes in the ERE?
Talking of escaping - personally I find backslash escapes harder to read / grok than quotation, so I'd like to recommend using quotes around each of the two --include (if they remain in the first place) instead of the \* construct.
Ok I’ve removed the escape from the * and also from slashes:
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell grep -ERl --include='*.h' \ --include='*.c' '^[[:blank:]]*/\*[[:space:]]+SAF-.*\*/$$' $(srctree)))
Quoted 6 lines
Quoted 3 lines
Good - seeing things more clearly now my next question is: Isn't matching just "/* SAF-...*/" a little too lax? And is there really a need to permit leading blanks?
I’m permitting blanks to allow spaces or tabs, zero or more times before the start of the comment, I think it shall be like that.
Hmm, I withdraw my question realizing that you want these comments indented the same as the line they relate to.
Quoted 3 lines
About matching, maybe I can match also the number after SAF-, this should be enough,
[…] grep -El '^[[:blank:]]*\/\*[[:space:]]+SAF-[0-9]+.*\*\/$$’ […]
I'd like to suggest to go one tiny step further (and once again to drop the escaping of slashes):
'^[[:blank:]]*/\*[[:space:]]+SAF-[0-9]+-.*\*/$$'
Quoted 30 lines
Quoted 24 lines
Quoted 6 lines
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
Quoted 5 lines
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Quoted 5 lines
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
What do you think?
Personally I'd prefer make goals to behave as such, with no surprises.
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 56 lines · Jan Beulich
Quoted 51 lines · Luca Fancellu
Quoted 15 lines
Quoted 15 lines · Luca Fancellu
Quoted 1 line
+Here is an example to add a new justification in false-positive-<tool>.json::
With <tool> already present in the name, ...
Quoted 7 lines
+|{ +| "version": "1.0", +| "content": [ +| { +| "id": "SAF-0-false-positive-<tool>", +| "analyser": { +| "<tool>": "<proprietary-id>"... can we avoid the redundancy here? Perhaps ...
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
+| }, +| "tool-version": "<version>",... it could be
"analyser": { "<version>": "<proprietary-id>" },About this, I’ve investigated a bit and I don’t think this is the right solution, it wouldn't make much sense to have a schema where in one file the analyser dictionary key is the tool name and in another it is a version (or range of versions).
However I can remove the analyser dictionary and use this schema for the false-positive, which is more compact:
|{ | "version": "1.0", | "content": [ | { | "id": "SAF-0-false-positive-<tool>", | “tool-proprietary-id”: "<proprietary-id>”, | "tool-version": "<version>", | "name": "R20.7 [...]", | "text": "[...]" | }, | { | "id": "SAF-1-false-positive-<tool>", | “tool-proprietary-id”: "", | "tool-version": "", | "name": "Sentinel", | "text": "Next ID to be used" | } | ] |}
Quoted 4 lines
Quoted 2 lines
This needs however a change in the initial design and more documentation on the different handlings of the safe.json schema and the false-positive-<tool>.json schema. Is it worth?
I think it is, but of others disagree, so be it.
So, since no one replied on that, I think everybody agrees that safe and false-positive can have a different schema, I will update the python tool to handle that and I will update the make recipe consequently.
Quoted 54 lines
Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Hmm, not sure: --include isn't a standard option to grep, and we generally try to be portable. Actually -R (or -r) isn't either. It may still be okay that way if properly documented where the involved goals will work and where not.
Is a comment before the line ok as documentation? To state that —include and -R are not standard options so analysis-{coverity,eclair} will not work without a grep that takes those parameters?
Quoted 8 lines
A comment _might_ be okay. Is there no other documentation on how these goals are to be used? The main question here is how impacting this might be to the various environments we allow Xen to be built in: Would at least modern versions of all Linux distros we care about allow using these rules? What about non-Linux?
And could you at least bail when
PARSE_FILE_LISTends up empty, with a clear error message augmenting the one grep would have issued?Quoted 8 lines
An empty
PARSE_FILE_LISTshould not generate an error, it just means there are no justifications, but I see it can be problematic in case grep does not work.What about this? They should be standard options right?
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell find $(srctree) -type f \ -name '*.c' -o -name '*.h' -exec \ grep -El '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' {} + ))Coming closer to being generally usable. You now have the problem of potentially exceeding command line limits (iirc there were issues in find and/or kernels), but I agree it looks standard-conforming now.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
And then - why do you escape slashes in the ERE?
Talking of escaping - personally I find backslash escapes harder to read / grok than quotation, so I'd like to recommend using quotes around each of the two --include (if they remain in the first place) instead of the \* construct.
Ok I’ve removed the escape from the * and also from slashes:
PARSE_FILE_LIST:= $(addsuffix .safparse,$(shell grep -ERl --include='*.h' \
--include='*.c' '^[[:blank:]]*/\*[[:space:]]+SAF-.*\*/$$' $(srctree)))Quoted 6 lines
Quoted 3 lines
Good - seeing things more clearly now my next question is: Isn't matching just "/* SAF-...*/" a little too lax? And is there really a need to permit leading blanks?
I’m permitting blanks to allow spaces or tabs, zero or more times before the start of the comment, I think it shall be like that.
Hmm, I withdraw my question realizing that you want these comments indented the same as the line they relate to.
Quoted 8 lines
Quoted 3 lines
About matching, maybe I can match also the number after SAF-, this should be enough,
[…] grep -El '^[[:blank:]]*\/\*[[:space:]]+SAF-[0-9]+.*\*\/$$’ […]
I'd like to suggest to go one tiny step further (and once again to drop the escaping of slashes):
'^[[:blank:]]*/\*[[:space:]]+SAF-[0-9]+-.*\*/$$'
I agree, I will use this one that is safer and includes your suggestions:
PARSE_FILE_LIST := $(addsuffix .safparse,$(shell find $(srctree) -type f \
-name '*.c' -o -name '*.h' -exec \
grep -El '^[[:blank:]]*/\*[[:space:]]+SAF-[0-9]+-.*\*/$$' {} \; ))Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 7 lines
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Quoted 7 lines
Quoted 5 lines
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
What do you think?
Personally I'd prefer make goals to behave as such, with no surprises.
The analysis-* goal requires a build step, otherwise no analysis can be performed by the analysis tools, so I hope we agree we need to integrate that step as a dependency of the analysis-*.
I understand that the analysis-clean might be a “surprise” if not well documented, this comes from the need to substitute the tags in the tree (to keep the real path in the report log) and to revert them back at the end of the analysis.
So, such script should just mask to the user the analysis-clean invocation in case of errors (with an option to don’t do that)?
Quoted 2 lines
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 37 lines · Luca Fancellu
Quoted 37 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 25 lines
Quoted 7 lines · Luca Fancellu
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
Quoted 5 lines
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
What do you think?
Personally I'd prefer make goals to behave as such, with no surprises.
The analysis-* goal requires a build step, otherwise no analysis can be performed by the analysis tools, so I hope we agree we need to integrate that step as a dependency of the analysis-*.
No, I'm afraid we don't agree. But like said for another piece we didn't initially agree on - if others think what you propose is fine, so be it. I'm specifically adding Anthony to Cc, as he's been working on make rules the most of all of us in the recent past.
Quoted 4 lines
I understand that the analysis-clean might be a “surprise” if not well documented, this comes from the need to substitute the tags in the tree (to keep the real path in the report log) and to revert them back at the end of the analysis.
So, such script should just mask to the user the analysis-clean invocation in case of errors (with an option to don’t do that)?
Hmm, here you're saying "such script", which looks to not fit with the earlier part of your reply above. (Just in case that's what I was to read out of this: I wouldn't see value in a script which existed _solely_ to make the cleaning conditional.)
Did you consider the alternative approach of copying the tree, altering it (while or after copying), running the build there, pulling out the result files, and delete the entire copy? Such a model would likely get away without introducing surprising make rules.
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 60 lines · Jan Beulich
Quoted 37 lines · Luca Fancellu
Quoted 37 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 25 lines
Quoted 7 lines · Luca Fancellu
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
Quoted 5 lines
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
What do you think?
Personally I'd prefer make goals to behave as such, with no surprises.
The analysis-* goal requires a build step, otherwise no analysis can be performed by the analysis tools, so I hope we agree we need to integrate that step as a dependency of the analysis-*.
No, I'm afraid we don't agree. But like said for another piece we didn't initially agree on - if others think what you propose is fine, so be it. I'm specifically adding Anthony to Cc, as he's been working on make rules the most of all of us in the recent past.
Quoted 4 lines
I understand that the analysis-clean might be a “surprise” if not well documented, this comes from the need to substitute the tags in the tree (to keep the real path in the report log) and to revert them back at the end of the analysis.
So, such script should just mask to the user the analysis-clean invocation in case of errors (with an option to don’t do that)?
Hmm, here you're saying "such script", which looks to not fit with the earlier part of your reply above. (Just in case that's what I was to read out of this: I wouldn't see value in a script which existed _solely_ to make the cleaning conditional.)
Quoted 4 lines
Did you consider the alternative approach of copying the tree, altering it (while or after copying), running the build there, pulling out the result files, and delete the entire copy? Such a model would likely get away without introducing surprising make rules.
Another, maybe simpler idea: what if the build step is not a dependency of the analysis-* goals?
Basically, the user is supposed to:
1) call analysis-parse-tags-*
2) build Xen (in any way they like)
3) call analysis-clean
Making steps 1-3 into a single step is slightly more convenient for the user but the downside is that dealing with build errors becomes problematic.
On the other hand, if we let the user call steps 1-3 by hand individually, it is slightly less convenient for the user but they can more easily deal with any build error and sophisticated build configurations.
This is one of those cases where I think "less is more".
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 66 lines · Stefano Stabellini
Quoted 60 lines · Jan Beulich
Quoted 37 lines · Luca Fancellu
Quoted 37 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 25 lines
Quoted 7 lines · Luca Fancellu
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
Quoted 5 lines
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
What do you think?
Personally I'd prefer make goals to behave as such, with no surprises.
The analysis-* goal requires a build step, otherwise no analysis can be performed by the analysis tools, so I hope we agree we need to integrate that step as a dependency of the analysis-*.
No, I'm afraid we don't agree. But like said for another piece we didn't initially agree on - if others think what you propose is fine, so be it. I'm specifically adding Anthony to Cc, as he's been working on make rules the most of all of us in the recent past.
Quoted 4 lines
I understand that the analysis-clean might be a “surprise” if not well documented, this comes from the need to substitute the tags in the tree (to keep the real path in the report log) and to revert them back at the end of the analysis.
So, such script should just mask to the user the analysis-clean invocation in case of errors (with an option to don’t do that)?
Hmm, here you're saying "such script", which looks to not fit with the earlier part of your reply above. (Just in case that's what I was to read out of this: I wouldn't see value in a script which existed _solely_ to make the cleaning conditional.)
Quoted 4 lines
Did you consider the alternative approach of copying the tree, altering it (while or after copying), running the build there, pulling out the result files, and delete the entire copy? Such a model would likely get away without introducing surprising make rules.
Quoted 8 lines
Another, maybe simpler idea: what if the build step is not a dependency of the analysis-* goals?
Basically, the user is supposed to:
1) call analysis-parse-tags-*
2) build Xen (in any way they like)
3) call analysis-clean
Well, that's exactly what I've been proposing, with the (optional) addition of a small (shell) script doing all of the three for ...
Quoted 8 lines
Making steps 1-3 into a single step is slightly more convenient for the user but the downside is that dealing with build errors becomes problematic.
On the other hand, if we let the user call steps 1-3 by hand individually, it is slightly less convenient for the user but they can more easily deal with any build error and sophisticated build configurations.
... convenience.
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 66 lines · Jan Beulich
Quoted 61 lines · Stefano Stabellini
Quoted 60 lines · Jan Beulich
Quoted 37 lines · Luca Fancellu
Quoted 37 lines · Jan Beulich
Quoted 35 lines · Luca Fancellu
Quoted 25 lines
Quoted 7 lines · Luca Fancellu
Now analysis-build-coverity will be called, the best match is analysis-build-%, so again the dependency which is analysis-parse-tags-%, will be translated to analysis-parse-tags-coverity.
Now analysis-parse-tags-coverity will be called, the best match is analysis-parse-tags-%, so the % will Have the ‘coverity’ value and in the dependency we will have $(objtree)/%.sed -> $(objtree)/coverity.sed.
Quoted 6 lines
Looking for $(objtree)/coverity.sed the best match is $(objtree)/%.sed, which will have $(JUSTIFICATION_FILES) and the python script in the dependency, here we will use the second expansion to solve $(XEN_ROOT)/docs/misra/false-positive-$$*.json in $(XEN_ROOT)/docs/misra/false-positive-coverity.json
So now after analysis-parse-tags-coverity has ended its dependency it will start with its recipe, after it finishes, the recipe of analysis-build-coverity will start and it will call make to actually build Xen.
Okay, I see now - this building of Xen really _is_ independent of the checker chosen. I'm not sure though whether it is a good idea to integrate all this, including ...
Quoted 2 lines
After the build finishes, if the status is good, the analysis-build-coverity has finished and the _analysis-coverity recipe can now run, it will call make with the analysis-clean target, restoring any <file>.{c,h}.safparse to <file>.{c,h}.
... the subsequent cleaning. The state of the _source_ tree after a build failure would be different from that after a successful build. Personally I consider this at best surprising.
Quoted 5 lines
I wonder whether instead there could be a shell(?) script driving a sequence of make invocations, leaving the new make goals all be self- contained. Such a script could revert the source tree to its original state even upon build failure by default, with an option allowing to suppress this behavior.
Instead of adding another tool, so another layer to the overall system, I would be more willing to add documentation about this process, explaining how to use the analysis-* build targets, what to expect after a successful run and what to expect after a failure.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
What do you think?
Personally I'd prefer make goals to behave as such, with no surprises.
The analysis-* goal requires a build step, otherwise no analysis can be performed by the analysis tools, so I hope we agree we need to integrate that step as a dependency of the analysis-*.
No, I'm afraid we don't agree. But like said for another piece we didn't initially agree on - if others think what you propose is fine, so be it. I'm specifically adding Anthony to Cc, as he's been working on make rules the most of all of us in the recent past.
Quoted 4 lines
I understand that the analysis-clean might be a “surprise” if not well documented, this comes from the need to substitute the tags in the tree (to keep the real path in the report log) and to revert them back at the end of the analysis.
So, such script should just mask to the user the analysis-clean invocation in case of errors (with an option to don’t do that)?
Hmm, here you're saying "such script", which looks to not fit with the earlier part of your reply above. (Just in case that's what I was to read out of this: I wouldn't see value in a script which existed _solely_ to make the cleaning conditional.)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Did you consider the alternative approach of copying the tree, altering it (while or after copying), running the build there, pulling out the result files, and delete the entire copy? Such a model would likely get away without introducing surprising make rules.
This approach does not work because the report will contain a path that is different from the source path and some web based tools won’t be able to track back the origin of the finding.
e.g. /path/to/xen/arch/arm/<file> is the original file, we run the analysis on /path/to2/xen/arch/arm/<file>, the finding is in /path/to2/xen/arch/arm/<file> but the source repository contains only /path/to/xen/arch/arm/<file>
Quoted 17 lines
Quoted 9 lines
Another, maybe simpler idea: what if the build step is not a dependency of the analysis-* goals?
Basically, the user is supposed to:
1) call analysis-parse-tags-*
2) build Xen (in any way they like)
3) call analysis-cleanWell, that's exactly what I've been proposing, with the (optional) addition of a small (shell) script doing all of the three for ...
Quoted 4 lines
Making steps 1-3 into a single step is slightly more convenient for the user but the downside is that dealing with build errors becomes problematic.
Quoted 6 lines
Quoted 4 lines
On the other hand, if we let the user call steps 1-3 by hand individually, it is slightly less convenient for the user but they can more easily deal with any build error and sophisticated build configurations.
... convenience.
For coverity and eclair, it makes sense, these tools doesn’t require much effort to be integrated, they are built to intercept files, compilers, environment variables during the make run in a transparent way.
So the workflow is:
1) call analysis-parse-tags-*
2) build Xen (in any way they like)
3) call analysis-clean
If we think about cppcheck however, here the story changes, as it requires all these information to be given as inputs, we have to do all the work the commercial tools do under the hood.
The cppcheck workflow instead is:
1) call analysis-parse-tags-cppcheck
2) generate cppcheck suppression list
3) build Xen (and run cppcheck on built source files)
4) collect and generate report
5) call analysis-clean
So let’s think about detaching the build stage from the previous stages, I think it is not very convenient for the user, as during cppcheck analysis we build $(objtree)/include/generated/compiler-def.h, we build $(objtree)/suppression-list.txt, so the user needs to build Xen where those files are created (in-tree or out-of-tree) otherwise the analysis won’t work and that’s the first user requirement (stage #3).
The most critical input to cppcheck is Xen’s $(CC), it comes from the build system in this serie, the user would need to pass the correct one to cppcheck wrapper, together with cppcheck flags, and pass to Xen build stage #3 the wrapper as CC, second user requirement.
After the analysis, the user needs to run some scripts to put together the cppcheck report fragments after its analysis, this step requires also the knowledge of were Xen is built, in-tree or out-of-tree, so here the third user requirement (similar to the first one, but the stage is #4).
In the end, we can see the user would not be able to call individually the targets if it is not mastering the system, it’s too complex to have something working, we could create a script to handle these requirements, but it would be complex as it would do the job of the make system, plus it needs to forward additional make arguments to it as well (CROSS_COMPILE, XEN_TARGET_ARCH, in-tree or Out-of-tree build, ... for example).
In this thread the message is that in case of errors, there will be some artifacts (<file>.safparse, modified <file>) and this is unexpected or surprising, but we are going to add a lot of complexity to handle something that needs just documentation (in my opinion).
If the community don’t agree that documentation is enough, a solution could be to provide a script that in case of errors, calls automatically the analysis-clean target, analysis-<tool> will call also the build step in this case, here some pseudocode:
#!/bin/bash set -e trap [call analysis-clean] EXIT [call analysis-<tool>]
This script needs however all the make arguments that we would have passed to make instead:
./script.sh --tool=<tool> [--dont-clean-on-err] -- CROSS_COMPILE=“[...]“ XEN_TARGET_ARCH=“[...]” [others...]
Quoted 2 lines
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 8 lines · Luca Fancellu
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Jan Beulich
Did you consider the alternative approach of copying the tree, altering it (while or after copying), running the build there, pulling out the result files, and delete the entire copy? Such a model would likely get away without introducing surprising make rules.
Quoted 5 lines
This approach does not work because the report will contain a path that is different from the source path and some web based tools won’t be able to track back the origin of the finding.
e.g. /path/to/xen/arch/arm/<file> is the original file, we run the analysis on /path/to2/xen/arch/arm/<file>, the finding is in /path/to2/xen/arch/arm/<file> but the source repository contains only /path/to/xen/arch/arm/<file>
Simply run "sed" over the result?
Quoted 37 lines
Quoted 16 lines
Quoted 8 lines
Another, maybe simpler idea: what if the build step is not a dependency of the analysis-* goals?
Basically, the user is supposed to:
1) call analysis-parse-tags-*
2) build Xen (in any way they like)
3) call analysis-cleanWell, that's exactly what I've been proposing, with the (optional) addition of a small (shell) script doing all of the three for ...
Quoted 4 lines
Making steps 1-3 into a single step is slightly more convenient for the user but the downside is that dealing with build errors becomes problematic.
Quoted 6 lines
Quoted 4 lines
On the other hand, if we let the user call steps 1-3 by hand individually, it is slightly less convenient for the user but they can more easily deal with any build error and sophisticated build configurations.
... convenience.
For coverity and eclair, it makes sense, these tools doesn’t require much effort to be integrated, they are built to intercept files, compilers, environment variables during the make run in a transparent way.
So the workflow is:
1) call analysis-parse-tags-*
2) build Xen (in any way they like)
3) call analysis-cleanIf we think about cppcheck however, here the story changes, as it requires all these information to be given as inputs, we have to do all the work the commercial tools do under the hood.
Quoted 7 lines
The cppcheck workflow instead is:
1) call analysis-parse-tags-cppcheck
2) generate cppcheck suppression list
3) build Xen (and run cppcheck on built source files)
4) collect and generate report
5) call analysis-clean
Which merely makes for a more involved (shell) script.
Quoted 34 lines
So let’s think about detaching the build stage from the previous stages, I think it is not very convenient for the user, as during cppcheck analysis we build $(objtree)/include/generated/compiler-def.h, we build $(objtree)/suppression-list.txt, so the user needs to build Xen where those files are created (in-tree or out-of-tree) otherwise the analysis won’t work and that’s the first user requirement (stage #3).
The most critical input to cppcheck is Xen’s $(CC), it comes from the build system in this serie, the user would need to pass the correct one to cppcheck wrapper, together with cppcheck flags, and pass to Xen build stage #3 the wrapper as CC, second user requirement.
After the analysis, the user needs to run some scripts to put together the cppcheck report fragments after its analysis, this step requires also the knowledge of were Xen is built, in-tree or out-of-tree, so here the third user requirement (similar to the first one, but the stage is #4).
In the end, we can see the user would not be able to call individually the targets if it is not mastering the system, it’s too complex to have something working, we could create a script to handle these requirements, but it would be complex as it would do the job of the make system, plus it needs to forward additional make arguments to it as well (
CROSS_COMPILE,XEN_TARGET_ARCH, in-tree or Out-of-tree build, ... for example).In this thread the message is that in case of errors, there will be some artifacts (<file>.safparse, modified <file>) and this is unexpected or surprising, but we are going to add a lot of complexity to handle something that needs just documentation (in my opinion).
If the community don’t agree that documentation is enough, a solution could be to provide a script that in case of errors, calls automatically the analysis-clean target, analysis-<tool> will call also the build step in this case, here some pseudocode:
#!/bin/bash set -e trap [call analysis-clean] EXIT [call analysis-<tool>]
Quoted 3 lines
This script needs however all the make arguments that we would have passed to make instead:
./script.sh --tool=<tool> [--dont-clean-on-err] -- CROSS_COMPILE=“[...]“ XEN_TARGET_ARCH=“[...]” [others...]
Well, of course the suggested script would need to be passed overrides you'd otherwise pass with "make build" or alike.
Jan
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
In reply to Luca FancelluQuoted 8 lines · Luca Fancellu
The cppcheck workflow instead is:
1) call analysis-parse-tags-cppcheck
2) generate cppcheck suppression list
3) build Xen (and run cppcheck on built source files)
4) collect and generate report
5) call analysis-clean
Quoted 8 lines
So let’s think about detaching the build stage from the previous stages, I think it is not very convenient for the user, as during cppcheck analysis we build $(objtree)/include/generated/compiler-def.h, we build $(objtree)/suppression-list.txt, so the user needs to build Xen where those files are created (in-tree or out-of-tree) otherwise the analysis won’t work and that’s the first user requirement (stage #3).
The most critical input to cppcheck is Xen’s $(CC), it comes from the build system in this serie, the user would need to pass the correct one to cppcheck wrapper, together with cppcheck flags, and pass to Xen build stage #3 the wrapper as CC, second user requirement.
You could add something like that to Makefile:
export-variables:
@echo "CC='$(CC)'"And if "the user" is a shell script, it could easily figure out what $CC is, without having to duplicate the Makefile's logic for it.
Quoted 3 lines
After the analysis, the user needs to run some scripts to put together the cppcheck report fragments after its analysis, this step requires also the knowledge of were Xen is built, in-tree or out-of-tree, so here the third user requirement (similar to the first one, but the stage is #4).
Don't support out-of-tree, that would make things easier. I don't see how that would work anyway with the needed temporary changes to the source code.
Quoted 4 lines
In the end, we can see the user would not be able to call individually the targets if it is not mastering the system, it’s too complex to have something working, we could create a script to handle these requirements, but it would be complex as it would do the job of the make system, plus it needs to forward additional make arguments to it as well (
CROSS_COMPILE,XEN_TARGET_ARCH, in-tree or Out-of-tree build, ... for example).
Well, instead of running make X XEN_TARGET_ARCH=x86, a script would be run as ./script XEN_TARGET_ARCH=x86, so not much change. Then the script can easily run make "$@".
Cheers,
Signature · 1 line
Anthony PERARD
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
In reply to Luca FancelluQuoted 1 line · Luca Fancellu
xen/Makefile | 50 ++++++-
Hi Luca,
Could you write a shell script which would probably be easier to read/modify than this rather complicated looking set of Makefile rules?
As I see it, a potential analysis shell script would have a single interaction with make, it would just have to run make build CC=cppcheck-gcc or other.
Because I don't see how make is useful in this case. Or maybe you could explain how writing this in make help?
Also non of this would work with out-of-tree builds, as you shouldn't make modification to the source tree.
Cheers,
Signature · 1 line
Anthony PERARD
Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair
Quoted 8 lines · Anthony PERARD
Quoted 1 line · Luca Fancellu
xen/Makefile | 50 ++++++-
Hi Luca,
Hi,
Quoted 3 lines
Could you write a shell script which would probably be easier to read/modify than this rather complicated looking set of
Makefilerules?
I admit the rules are a bit complicated
Quoted 9 lines
As I see it, a potential
analysisshell script would have a single interaction with make, it would just have to runmake build CC=cppcheck-gccor other.Because I don't see how make is useful in this case. Or maybe you could explain how writing this in make help?
Also non of this would work with out-of-tree builds, as you shouldn't make modification to the source tree.
They both are good points, I will rewrite the rules as a script.
Quoted 5 lines
Cheers,
Signature · 1 line
Anthony PERARD
RFC PATCH 2/4 xen/Makefile: add analysis-cppcheck and analysis-cppcheck-html
In reply to Luca FancelluChange cppcheck invocation method by substituting the Makefile targets cppcheck{-html} with analysis-cppcheck{-html}.
Now cppcheck will build Xen while analysing the source files, and it will produce a text output when called with analysis-cppcheck and an additional html output when called with analysis-cppcheck-html. With this patch cppcheck will benefit of platform configuration files that will help it to understand the target of the compilation and improve the analysis.
To do so:
- modify cppcheck calls in Makefile and add files to clean and distclean.
- add platform configuration files for cppcheck.
- add scripts to generate text and html output.
- add cppcheck-cc.sh script that is a wrapper for cppcheck and it's used as Xen compiler, it will intercept all flags given from the make build system and it will execute cppcheck on the compiled file together with the file compilation.
- add a script that generates a suppression list for cppcheck to overcome a problem where cppcheck is not suppressing findings in the headers using in-code comment. The system uses the headers in-code comment to produce the list, so it's transparent to the developer and both c files and header can benefit from in-code comment suppression.
- guarded hypercall-defs.c with CPPCHECK define because cppcheck gets confused as the file does not contain c code.
- add false-positive-cppcheck.json file
- update documentation.
- update .gitignore
--- .gitignore | 8 +- docs/misra/cppcheck.txt | 47 +++-- docs/misra/documenting-violations.rst | 7 +- docs/misra/false-positive-cppcheck.json | 12 ++ xen/Makefile | 143 ++++++++----- xen/include/hypercall-defs.c | 9 + xen/tools/cppcheck-build-suppr-list.sh | 81 +++++++ xen/tools/cppcheck-cc.sh | 223 ++++++++++++++++++++ xen/tools/cppcheck-html-prepare.sh | 110 ++++++++++ xen/tools/cppcheck-plat/arm32-wchar_t4.xml | 17 ++ xen/tools/cppcheck-plat/arm64-wchar_t2.xml | 17 ++ xen/tools/cppcheck-plat/arm64-wchar_t4.xml | 17 ++ xen/tools/cppcheck-plat/x86_64-wchar_t2.xml | 17 ++ xen/tools/cppcheck-plat/x86_64-wchar_t4.xml | 17 ++ xen/tools/cppcheck-txt-prepare.sh | 74 +++++++ 15 files changed, 717 insertions(+), 82 deletions(-) create mode 100644 docs/misra/false-positive-cppcheck.json create mode 100755 xen/tools/cppcheck-build-suppr-list.sh create mode 100755 xen/tools/cppcheck-cc.sh create mode 100755 xen/tools/cppcheck-html-prepare.sh create mode 100644 xen/tools/cppcheck-plat/arm32-wchar_t4.xml create mode 100644 xen/tools/cppcheck-plat/arm64-wchar_t2.xml create mode 100644 xen/tools/cppcheck-plat/arm64-wchar_t4.xml create mode 100644 xen/tools/cppcheck-plat/x86_64-wchar_t2.xml create mode 100644 xen/tools/cppcheck-plat/x86_64-wchar_t4.xml create mode 100755 xen/tools/cppcheck-txt-prepare.sh
.gitignore +6 -2
@@ -7,9 +7,11 @@ *.o *.d *.d2 -*.c.cppcheck +*.cppcheck +*.cppcheck.txt *.opic *.a +*.c.json *.safparse *.so *.so.[0-9]*
@@ -283,9 +285,11 @@ xen/arch/*/efi/efi.h xen/arch/*/efi/pe.c xen/arch/*/efi/runtime.c xen/arch/*/include/asm/asm-offsets.h +xen/build-dir-cppcheck xen/common/config_data.S xen/common/config.gz xen/cppcheck-htmlreport/ +xen/cppcheck-report/ xen/cppcheck-misra.* xen/include/headers*.chk xen/include/compat/*
@@ -317,7 +321,7 @@ tools/flask/policy/policy.conf tools/flask/policy/xenpolicy-* xen/*.sed xen/xen -xen/xen-cppcheck.xml +xen/suppression-list.txt xen/xen-syms xen/xen-syms.map xen/xen.*
docs/misra/cppcheck.txt +26 -21
53 lines not on this page · raw message
docs/misra/documenting-violations.rst +4 -3
@@ -50,6 +50,7 @@ Here is an example to add a new justification in safe.json:: | { | "id": "SAF-0-safe", | "analyser": { +| "cppcheck": "misra-c2012-20.7", | "coverity": "misra_c_2012_rule_20_7_violation", | "eclair": "MC3R1.R20.7" | },
@@ -100,9 +101,9 @@ Here an explanation of the field inside an object of the "content" array: It tells the tool to substitute a Xen in-code comment having this structure: /* SAF-0-safe [...] \*/ - analyser: it is an object containing pair of key-value strings, the key is - the analyser, so it can be coverity or eclair, the value is the proprietary - id corresponding on the finding, for example when coverity is used as - analyser, the tool will translate the Xen in-code coment in this way: + the analyser, so it can be cppcheck, coverity or eclair, the value is the + proprietary id corresponding on the finding, for example when coverity is + used as analyser, the tool will translate the Xen in-code coment in this way: /* SAF-0-safe [...] \*/ -> /* coverity[misra_c_2012_rule_20_7_violation] \*/ if the object doesn't have a key-value, then the corresponding in-code comment won't be translated.
docs/misra/false-positive-cppcheck.json new file +12 -0
@@ -0,0 +1,12 @@ +{ + "version": "1.0", + "content": [ + { + "id": "SAF-0-false-positive-cppcheck", + "analyser": {}, + "tool-version": "", + "name": "Sentinel", + "text": "Next ID to be used" + } + ] +}
xen/Makefile +87 -56
207 lines not on this page · raw message
xen/include/hypercall-defs.c +9 -0
@@ -60,6 +60,13 @@* are possible. */ +/* +* Cppcheck thinks this file needs to be analysed because it is preprocessed by +* the compiler, but it gets confused because this file does not contains C +* code. Hence protect the code when CPPCHECK is used. +*/ +#ifndef CPPCHECK +#ifdef CONFIG_HVM #define PREFIX_hvm hvm#else
@@ -283,3 +290,5 @@ mca do do - - -#ifndef CONFIG_PV_SHIM_EXCLUSIVE paging_domctl_cont do do do do -#endif + +#endif /* !CPPCHECK */
xen/tools/cppcheck-build-suppr-list.sh new file +81 -0
81 lines not on this page · raw message
xen/tools/cppcheck-cc.sh new file +223 -0
223 lines not on this page · raw message
xen/tools/cppcheck-html-prepare.sh new file +110 -0
110 lines not on this page · raw message
xen/tools/cppcheck-plat/arm32-wchar_t4.xml new file +17 -0
@@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<platform> + <char_bit>8</char_bit> + <default-sign>unsigned</default-sign> + <sizeof> + <short>2</short> + <int>4</int> + <long>4</long> + <long-long>8</long-long> + <float>4</float> + <double>8</double> + <long-double>8</long-double> + <pointer>4</pointer> + <size_t>4</size_t> + <wchar_t>4</wchar_t> + </sizeof> +</platform>
xen/tools/cppcheck-plat/arm64-wchar_t2.xml new file +17 -0
@@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<platform> + <char_bit>8</char_bit> + <default-sign>unsigned</default-sign> + <sizeof> + <short>2</short> + <int>4</int> + <long>8</long> + <long-long>8</long-long> + <float>4</float> + <double>8</double> + <long-double>16</long-double> + <pointer>8</pointer> + <size_t>4</size_t> + <wchar_t>2</wchar_t> + </sizeof> +</platform>
xen/tools/cppcheck-plat/arm64-wchar_t4.xml new file +17 -0
@@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<platform> + <char_bit>8</char_bit> + <default-sign>unsigned</default-sign> + <sizeof> + <short>2</short> + <int>4</int> + <long>8</long> + <long-long>8</long-long> + <float>4</float> + <double>8</double> + <long-double>16</long-double> + <pointer>8</pointer> + <size_t>4</size_t> + <wchar_t>4</wchar_t> + </sizeof> +</platform>
xen/tools/cppcheck-plat/x86_64-wchar_t2.xml new file +17 -0
@@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<platform> + <char_bit>8</char_bit> + <default-sign>unsigned</default-sign> + <sizeof> + <short>2</short> + <int>4</int> + <long>8</long> + <long-long>8</long-long> + <float>4</float> + <double>8</double> + <long-double>16</long-double> + <pointer>8</pointer> + <size_t>8</size_t> + <wchar_t>2</wchar_t> + </sizeof> +</platform>
xen/tools/cppcheck-plat/x86_64-wchar_t4.xml new file +17 -0
@@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<platform> + <char_bit>8</char_bit> + <default-sign>unsigned</default-sign> + <sizeof> + <short>2</short> + <int>4</int> + <long>8</long> + <long-long>8</long-long> + <float>4</float> + <double>8</double> + <long-double>16</long-double> + <pointer>8</pointer> + <size_t>8</size_t> + <wchar_t>4</wchar_t> + </sizeof> +</platform>
xen/tools/cppcheck-txt-prepare.sh new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 3/4 tools/misra: fix skipped rule numbers
In reply to Luca FancelluCurrently the script convert_misra_doc.py is using a loop through range(1,22) to enumerate rules that needs to be skipped, however range function does not include the stop counter in the enumeration ending up into list rules until 21.21 instead of including rule 22.
Fix the issue using a dictionary that list the rules in misra c2012.
--- xen/tools/convert_misra_doc.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
xen/tools/convert_misra_doc.py +30 -2
@@ -14,6 +14,34 @@ Usage: import sys, getopt, re +# MISRA rule are identified by two numbers, e.g. Rule 1.2, the main rule number +# and a sub-number. This dictionary contains the number of the MISRA rule as key +# and the maximum sub-number for that rule as value. +misra_c2012_rules = { + 1:4, + 2:7, + 3:2, + 4:2, + 5:9, + 6:2, + 7:4, + 8:14, + 9:5, + 10:8, + 11:9, + 12:5, + 13:6, + 14:4, + 15:7, + 16:7, + 17:8, + 18:8, + 19:2, + 20:14, + 21:21, + 22:10 +} + def main(argv): infile = '' outfile = ''
@@ -142,8 +170,8 @@ def main(argv): skip_list = [] # Search for missing rules and add a dummy text with the rule number - for i in list(range(1,22)): - for j in list(range(1,22)): + for i in misra_c2012_rules: + for j in list(range(1,misra_c2012_rules[i]+1)): if str(i) + '.' + str(j) not in rule_list: outstr.write('Rule ' + str(i) + '.' + str(j) + '\n') outstr.write('No description for rule ' + str(i) + '.' + str(j)
Signature · 1 line
2.17.1
RFC PATCH 4/4 xen: Justify linker script defined symbols in include/xen/kernel.h
In reply to Luca FancelluEclair and Coverity found violation of the MISRA rule 8.6 for the symbols _start, _end, start, _stext, _etext, _srodata, _erodata, _sinittext, _einittext which are declared in xen/include/xen/kernel.h.
All those symbols are defined by the liker script so we can deviate from the rule 8.6 for these cases.
--- docs/misra/safe.json | 9 +++++++++ xen/include/xen/kernel.h | 4 ++++ 2 files changed, 13 insertions(+)
docs/misra/safe.json +9 -0
@@ -3,6 +3,15 @@ "content": [ { "id": "SAF-0-safe", + "analyser": { + "eclair": "MC3R1.R8.6", + "coverity": "misra_c_2012_rule_8_6_violation" + }, + "name": "Rule 8.6: linker script defined symbols", + "text": "It is safe to declare this symbol because it is defined in the linker script." + }, + { + "id": "SAF-1-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used"
xen/include/xen/kernel.h +4 -0
@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \
Signature · 1 line
2.17.1
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Quoted 21 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */
xen/include/xen/kernel.h line 92
Quoted 10 lines
xen/include/xen/kernel.h +1
-0extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \
Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
Jan
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Quoted 32 lines · Jan Beulich
Quoted 27 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ })
Quoted 5 lines
xen/include/xen/kernel.h line 92
Quoted 4 lines
xen/include/xen/kernel.h +1
-0+/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \
Hi Jan,
Quoted 2 lines
Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
The R8.6 is not tool specific, it is to give the quick hint that we are deviating from MISRA Rule 8.6.
Quoted 2 lines
Jan
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Quoted 37 lines · Luca Fancellu
Quoted 29 lines · Jan Beulich
Quoted 27 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ })Quoted 7 lines
xen/include/xen/kernel.h line 92
Quoted 4 lines
xen/include/xen/kernel.h +1
-0+/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
Quoted 2 lines
The R8.6 is not tool specific, it is to give the quick hint that we are deviating from MISRA Rule 8.6.
Well, yes, "tool" was wrong for me to write. Imo references to a specific spec should equally be avoided in in-code comments, as other specs may turn up.
Jan
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Quoted 38 lines · Jan Beulich
Quoted 37 lines · Luca Fancellu
Quoted 36 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ xen/include/xen/kernel.h line 92
Quoted 10 lines
xen/include/xen/kernel.h +1
-0extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
Quoted 6 lines
Quoted 2 lines
The R8.6 is not tool specific, it is to give the quick hint that we are deviating from MISRA Rule 8.6.
Well, yes, "tool" was wrong for me to write. Imo references to a specific spec should equally be avoided in in-code comments, as other specs may turn up.
+1. The comment duplication is not great and sometimes even a short explanation it may not fit in 80 characters (AFAICT the justification should be a one line comment).
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Quoted 45 lines · Julien Grall
Quoted 38 lines · Jan Beulich
Quoted 37 lines · Luca Fancellu
Quoted 36 lines · Jan Beulich
Quoted 21 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ xen/include/xen/kernel.h line 92
Quoted 10 lines
xen/include/xen/kernel.h +1
-0extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The R8.6 is not tool specific, it is to give the quick hint that we are deviating from MISRA Rule 8.6.
Well, yes, "tool" was wrong for me to write. Imo references to a specific spec should equally be avoided in in-code comments, as other specs may turn up.
+1. The comment duplication is not great and sometimes even a short explanation it may not fit in 80 characters (AFAICT the justification should be a one line comment).
Ok we can remove the R8.6 from the comments, is the remaining part ok?
Quoted 4 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Hi Luca,
Quoted 47 lines · Luca Fancellu
Quoted 47 lines · Julien Grall
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Luca Fancellu
Quoted 29 lines · Jan Beulich
Quoted 27 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ })Quoted 7 lines
xen/include/xen/kernel.h line 92
Quoted 4 lines
xen/include/xen/kernel.h +1
-0+/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
The R8.6 is not tool specific, it is to give the quick hint that we are deviating from MISRA Rule 8.6.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Well, yes, "tool" was wrong for me to write. Imo references to a specific spec should equally be avoided in in-code comments, as other specs may turn up.
+1. The comment duplication is not great and sometimes even a short explanation it may not fit in 80 characters (AFAICT the justification should be a one line comment).
Ok we can remove the R8.6 from the comments, is the remaining part ok?
I am afraid no. The comment should only be /* SAF-0-safe */.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 4/4] xen: Justify linker script defined symbols in include/xen/kernel.h
Quoted 56 lines · Julien Grall
Hi Luca,
Quoted 49 lines · Luca Fancellu
Quoted 49 lines · Julien Grall
Quoted 43 lines · Jan Beulich
Quoted 37 lines · Luca Fancellu
Quoted 29 lines · Jan Beulich
Quoted 27 lines · Luca Fancellu
xen/include/xen/kernel.h +3
-0@@ -65,24 +65,28 @@1 ; \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _stext) && (__p < _etext); \ }) +/* SAF-0-safe R8.6 linker script defined symbols */ extern const char _srodata[], _erodata[];#define is_kernel_rodata (p) ({ \ const char *__p = (const char *)(unsigned long)(p); \ (__p >= _srodata) && (__p < _erodata); \ })Quoted 7 lines
xen/include/xen/kernel.h line 92
Quoted 4 lines
xen/include/xen/kernel.h +1
-0+/* SAF-0-safe R8.6 linker script defined symbols */ extern char _sinittext[], _einittext[];#define is_kernel_inittext (p) ({ \ char *__p = (char *)(unsigned long)(p); \Why the "R8.6" everywhere here? Didn't we agree that the in-code comments should be tool-agnostic?
Quoted 2 lines
The R8.6 is not tool specific, it is to give the quick hint that we are deviating from MISRA Rule 8.6.
Well, yes, "tool" was wrong for me to write. Imo references to a specific spec should equally be avoided in in-code comments, as other specs may turn up.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
+1. The comment duplication is not great and sometimes even a short explanation it may not fit in 80 characters (AFAICT the justification should be a one line comment).
Ok we can remove the R8.6 from the comments, is the remaining part ok?
I am afraid no. The comment should only be /* SAF-0-safe */.
Ok I will go for that in the next serie
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall