[PATCH] D10356: scan-build: Add --analyzer-target option
Honggyu Kim
hong.gyu.kim at lge.com
Tue Aug 4 05:49:51 PDT 2015
honggyu.kim added a comment.
Hi Ted,
Let's me show you the full command and the error with verbose message.
If I run the following command with previous scan-build (i.e. without --analyzer-target option)
$ scan-build -v -v -v --use-cc=arm-linux-gnueabi-gcc make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
...
CC arch/arm/kernel/opcodes.o
First, it does the normal compilation with given compiler, "arm-linux-gnueabi-gcc", as follows:
arm-linux-gnueabi-gcc -Wp,-MD,arch/arm/kernel/.opcodes.o.d -nostdinc -isystem /opt/toolchain/arm-linux-gnueabi-4.8-2014.11-x86_64/bin/../lib/gcc/arm-linux-gnueabi/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-xxxx/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fomit-frame-pointer -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DKBUILD_STR(s)=#s -DKBUILD_BASENAME=KBUILD_STR(opcodes) -DKBUILD_MODNAME=KBUILD_STR(opcodes) -c -o arch/arm/kernel/opcodes.o arch/arm/kernel/opcodes.c
Then, it does analysis with clang static analyzer as follows:
[LOCATION]: /home/hong.gyu.kim/work.hard/kernel/clang/linux
#SHELL (cd '/home/hong.gyu.kim/work.hard/kernel/clang/linux' && '/home/hong.gyu.kim/usr/bin/clang' '-cc1' '-triple' 'x86_64-unknown-linux-gnu' '-analyze' '-disable-free' '-disable-llvm-verifier' '-main-file-name' 'opcodes.c' '-analyzer-store=region' '-analyzer-opt-analyze-nested-blocks' '-analyzer-eagerly-assume' '-analyzer-checker=core' '-analyzer-checker=unix' '-analyzer-checker=deadcode' '-analyzer-checker=security.insecureAPI.UncheckedReturn' '-analyzer-checker=security.insecureAPI.getpw' '-analyzer-checker=security.insecureAPI.gets' '-analyzer-checker=security.insecureAPI.mktemp' '-analyzer-checker=security.insecureAPI.mkstemp' '-analyzer-checker=security.insecureAPI.vfork' '-analyzer-output' 'plist' '-w' '-mrelocation-model' 'static' '-mthread-model' 'posix' '-relaxed-aliasing' '-fmath-errno' '-masm-verbose' '-mconstructor-aliases' '-munwind-tables' '-fuse-init-array' '-target-cpu' 'armv7-a' '-no-implicit-float' '-target-linker-version' '2.22' '-momit-leaf-frame-pointer' '-dwarf-column-info' '-nostdsysteminc' '-nobuiltininc' '-resource-dir' '/home/hong.gyu.kim/usr/bin/../lib/clang/3.7.0' '-isystem' '/opt/toolchain/arm-linux-gnueabi-4.8-2014.11-x86_64/bin/../lib/gcc/arm-linux-gnueabi/4.8.3/include' '-include' './include/linux/kconfig.h' '-D' '__KERNEL__' '-D' '__LINUX_ARM_ARCH__=7' '-U' 'arm' '-D' 'CC_HAVE_ASM_GOTO' '-D' 'KBUILD_STR(s)=#s' '-D' 'KBUILD_BASENAME=KBUILD_STR(opcodes)' '-D' 'KBUILD_MODNAME=KBUILD_STR(opcodes)' '-I' './arch/arm/include' '-I' 'arch/arm/include/generated/uapi' '-I' 'arch/arm/include/generated' '-I' 'include' '-I' './arch/arm/include/uapi' '-I' 'arch/arm/include/generated/uapi' '-I' './include/uapi' '-I' 'include/generated/uapi' '-I' 'arch/arm/mach-xxxx/include' '-O2' '-Wno-trigraphs' '-Wno-format-security' '-Wno-unused-but-set-variable' '-Wno-pointer-sign' '-std=gnu89' '-fdebug-compilation-dir' '/home/hong.gyu.kim/work.hard/kernel/clang/linux' '-ferror-limit' '19' '-fmessage-length' '0' '-fwrapv' '-mstackrealign' '-fobjc-runtime=gcc' '-fno-common' '-fdiagnostics-show-option' '-vectorize-loops' '-vectorize-slp' '-analyzer-display-progress' '-analyzer-output=html' '-o' '/tmp/scan-build-2015-08-04-210454-16108-1' '-x' 'c' 'arch/arm/kernel/opcodes.c')
And this shows an error.
error: unknown target CPU 'armv7-a'
If I just simplify the log message, it looks like this:
1. compilation with arm-linux-gnueabi-gcc
arm-linux-gnueabi-gcc ... -march=armv7-a ... -c -o arch/arm/kernel/opcodes.o arch/arm/kernel/opcodes.c
As you can see the above, there's no problem for compilation.
2. analysis with clang static analyzer
'clang' '-cc1' '-triple' 'x86_64-unknown-linux-gnu' '-analyze' ... '-target-cpu' 'armv7-a' ... 'arch/arm/kernel/opcodes.c'
In analysis step, clang uses the default -triple option "x86_64-unknown-linux-gnu", but still uses the the same arguments including "-target-cpu armv7-a". It makes a conflict and shows "error: unknown target CPU 'armv7-a'".
With --analyzer-target option, we can provide target info to clang static analyzer as follows:
$ scan-build -v -v -v --analyzer-target=arm-linux-gnueabi --use-cc=arm-linux-gnueabi-gcc make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
...
CC arch/arm/kernel/opcodes.o
1. compilation works the same as before
arm-linux-gnueabi-gcc ... -march=armv7-a ... -c -o arch/arm/kernel/opcodes.o arch/arm/kernel/opcodes.c
2. analysis uses the target triple that is given by --analyzer-target option and analysis works fine then.
'clang' '-cc1' '-triple' 'armv7--linux-gnueabi' '-analyze' ... '-target-cpu' 'cortex-a8' ... 'arch/arm/kernel/opcodes.c')
So we have to use the same target triple for compilation and analysis by using this option. Please let me know if there's a better way to fix this issue.
http://reviews.llvm.org/D10356
More information about the cfe-commits
mailing list