[llvmlinux] [GSoC: Static analysis] Report 1 + PATCH

Jan-Simon Möller dl9pf at gmx.de
Wed Jun 26 20:17:26 UTC 2013


I did a normal kernel build and then went into src/linux and called:

dl9pf at elrond:~/llvmlinux/targets/vexpress/src/linux> 
'/home/dl9pf/llvmlinux/toolchain/clang/install/bin/clang-3.4' '-cc1' '-triple' 
'armv7-none-linux-gnueabi' '-analyze' '-disable-free' '-disable-llvm-verifier' 
'-main-file-name' 'bounds.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' '-mdisable-fp-elim' '-fmath-errno' '-masm-verbose' 
'-mconstructor-aliases' '-munwind-tables' '-fuse-init-array' '-no-implicit-
float' '-nostdsysteminc' '-nobuiltininc' '-resource-dir' 
'/home/dl9pf/llvmlinux/toolchain/clang/install/bin/../lib/clang/3.4' '-
isystem' 
'/home/dl9pf/llvmlinux/toolchain/clang/install/bin/../lib/clang/3.4/include' 
'-include' 
'/home/dl9pf/llvmlinux/targets/vexpress/src/linux/include/linux/kconfig.h' '-D' 
'__KERNEL__' '-D' '__LINUX_ARM_ARCH__=7' '-D' 'KBUILD_STR(s)=#s' '-D' 
'KBUILD_BASENAME=KBUILD_STR(bounds)' '-D' 'KBUILD_MODNAME=KBUILD_STR(bounds)' 
'-I' '/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include' '-I' 
'arch/arm/include/generated' '-I' 'include' '-I' 
'/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/uapi' '-I' 
'arch/arm/include/generated/uapi' '-I' 
'/home/dl9pf/llvmlinux/targets/vexpress/src/linux/include/uapi' '-I' 
'include/generated/uapi' '-Wno-trigraphs' '-Wno-format-security' '-Wno-asm-
operand-widths' '-Wno-unused-variable' '-Wno-format-invalid-specifier' '-Wno-
tautological-compare' '-Wno-pointer-sign' '-fdebug-compilation-dir' 
'/home/dl9pf/llvmlinux/targets/vexpress/src/linux' '-ferror-limit' '19' '-
fmessage-length' '0' '-mstackrealign' '-fno-builtin' '-fobjc-runtime=gcc' '-
fobjc-default-synthesize-properties' '-fdiagnostics-show-option' '-backend-
option' '-vectorize-loops' '-analyzer-display-progress' '-analyzer-
output=html' '-o' '/home/dl9pf/llvmlinux/targets/vexpress/tmp/scan-
build-2013-06-26-6' '-x' 'c' 'kernel/bounds.c' 
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/ptrace.h 
valid_user_regs
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/ptrace.h 
regs_return_value
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/ptrace.h 
regs_get_register
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/ptrace.h 
kernel_stack_pointer
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/ptrace.h 
user_stack_pointer
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/irqflags.h 
arch_local_irq_save
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/irqflags.h 
arch_local_irq_enable
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/irqflags.h 
arch_local_irq_disable
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/irqflags.h 
arch_local_save_flags
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/irqflags.h 
arch_local_irq_restore
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/irqflags.h 
arch_irqs_disabled_flags
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
____atomic_set_bit
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
____atomic_clear_bit
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
____atomic_change_bit
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
____atomic_test_and_set_bit
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
____atomic_test_and_clear_bit
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
____atomic_test_and_change_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h __set_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h __clear_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h __change_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h __test_and_set_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h __test_and_clear_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h 
__test_and_change_bit
ANALYZE (Syntax): include/asm-generic/bitops/non-atomic.h test_bit
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
constant_fls
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h 
fls
ANALYZE (Syntax): include/asm-generic/bitops/fls64.h fls64
ANALYZE (Syntax): include/asm-generic/bitops/sched.h sched_find_first_bit
ANALYZE (Syntax): include/asm-generic/bitops/arch_hweight.h __arch_hweight32
ANALYZE (Syntax): include/asm-generic/bitops/arch_hweight.h __arch_hweight16
ANALYZE (Syntax): include/asm-generic/bitops/arch_hweight.h __arch_hweight8
ANALYZE (Syntax): include/asm-generic/bitops/arch_hweight.h __arch_hweight64
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/swab.h 
__arch_swahb32
ANALYZE (Syntax): 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/swab.h 
__arch_swab32
ANALYZE (Syntax): include/uapi/linux/swab.h __fswab16
ANALYZE (Syntax): include/uapi/linux/swab.h __fswab32
ANALYZE (Syntax): include/uapi/linux/swab.h __fswab64
ANALYZE (Syntax): include/uapi/linux/swab.h __fswahw32
ANALYZE (Syntax): include/uapi/linux/swab.h __fswahb32
ANALYZE (Syntax): include/uapi/linux/swab.h __swab16p
ANALYZE (Syntax): include/uapi/linux/swab.h __swab32p
ANALYZE (Syntax): include/uapi/linux/swab.h __swab64p
ANALYZE (Syntax): include/uapi/linux/swab.h __swahw32p
ANALYZE (Syntax): include/uapi/linux/swab.h __swahb32p
ANALYZE (Syntax): include/uapi/linux/swab.h __swab16s
ANALYZE (Syntax): include/uapi/linux/swab.h __swab32s
ANALYZE (Syntax): include/uapi/linux/swab.h __swab64s
ANALYZE (Syntax): include/uapi/linux/swab.h __swahw32s
ANALYZE (Syntax): include/uapi/linux/swab.h __swahb32s
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __cpu_to_le64p
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __le64_to_cpup
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __cpu_to_le32p
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __le32_to_cpup
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __cpu_to_le16p
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __le16_to_cpup
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __cpu_to_be64p
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __be64_to_cpup
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __cpu_to_be32p
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __be32_to_cpup
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __cpu_to_be16p
ANALYZE (Syntax): include/uapi/linux/byteorder/little_endian.h __be16_to_cpup
ANALYZE (Syntax): include/linux/byteorder/generic.h le16_add_cpu
ANALYZE (Syntax): include/linux/byteorder/generic.h le32_add_cpu
ANALYZE (Syntax): include/linux/byteorder/generic.h le64_add_cpu
ANALYZE (Syntax): include/linux/byteorder/generic.h be16_add_cpu
ANALYZE (Syntax): include/linux/byteorder/generic.h be32_add_cpu
ANALYZE (Syntax): include/linux/byteorder/generic.h be64_add_cpu
ANALYZE (Syntax): include/asm-generic/bitops/le.h find_next_zero_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h find_next_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h find_first_zero_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h test_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h set_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h clear_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h __set_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h __clear_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h test_and_set_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h test_and_clear_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h __test_and_set_bit_le
ANALYZE (Syntax): include/asm-generic/bitops/le.h __test_and_clear_bit_le
ANALYZE (Syntax): include/linux/bitops.h get_bitmask_order
ANALYZE (Syntax): include/linux/bitops.h get_count_order
ANALYZE (Syntax): include/linux/bitops.h hweight_long
ANALYZE (Syntax): include/linux/bitops.h rol64
ANALYZE (Syntax): include/linux/bitops.h ror64
ANALYZE (Syntax): include/linux/bitops.h rol32
ANALYZE (Syntax): include/linux/bitops.h ror32
ANALYZE (Syntax): include/linux/bitops.h rol16
ANALYZE (Syntax): include/linux/bitops.h ror16
ANALYZE (Syntax): include/linux/bitops.h rol8
ANALYZE (Syntax): include/linux/bitops.h ror8
ANALYZE (Syntax): include/linux/bitops.h sign_extend32
ANALYZE (Syntax): include/linux/bitops.h fls_long
ANALYZE (Syntax): include/linux/bitops.h __ffs64
ANALYZE (Syntax): include/linux/log2.h __ilog2_u32
ANALYZE (Syntax): include/linux/log2.h __ilog2_u64
ANALYZE (Syntax): include/linux/log2.h is_power_of_2
ANALYZE (Syntax): include/linux/log2.h __roundup_pow_of_two
ANALYZE (Syntax): include/linux/log2.h __rounddown_pow_of_two
ANALYZE (Syntax): include/linux/printk.h printk_get_level
ANALYZE (Syntax): include/linux/printk.h printk_skip_level
ANALYZE (Syntax): include/linux/printk.h console_silent
ANALYZE (Syntax): include/linux/printk.h console_verbose
ANALYZE (Syntax): include/linux/printk.h no_printk
ANALYZE (Syntax): include/linux/string.h strstrip
ANALYZE (Syntax): include/linux/string.h strstarts
ANALYZE (Syntax): include/linux/string.h kbasename
ANALYZE (Syntax): include/linux/dynamic_debug.h ddebug_remove_module
ANALYZE (Syntax): include/linux/dynamic_debug.h ddebug_dyndbg_module_param_cb
ANALYZE (Syntax): include/linux/kernel.h __might_sleep
ANALYZE (Syntax): include/linux/kernel.h might_fault
ANALYZE (Syntax): include/linux/kernel.h kstrtoul
ANALYZE (Syntax): include/linux/kernel.h kstrtol
ANALYZE (Syntax): include/linux/kernel.h kstrtou64
ANALYZE (Syntax): include/linux/kernel.h kstrtos64
ANALYZE (Syntax): include/linux/kernel.h kstrtou32
ANALYZE (Syntax): include/linux/kernel.h kstrtos32
ANALYZE (Syntax): include/linux/kernel.h kstrtou64_from_user
ANALYZE (Syntax): include/linux/kernel.h kstrtos64_from_user
ANALYZE (Syntax): include/linux/kernel.h kstrtou32_from_user
ANALYZE (Syntax): include/linux/kernel.h kstrtos32_from_user
ANALYZE (Syntax): include/linux/kernel.h hex_byte_pack
ANALYZE (Syntax): include/linux/kernel.h pack_hex_byte
ANALYZE (Syntax): include/linux/kernel.h tracing_start
ANALYZE (Syntax): include/linux/kernel.h tracing_stop
ANALYZE (Syntax): include/linux/kernel.h ftrace_off_permanent
ANALYZE (Syntax): include/linux/kernel.h trace_dump_stack
ANALYZE (Syntax): include/linux/kernel.h tracing_on
ANALYZE (Syntax): include/linux/kernel.h tracing_off
ANALYZE (Syntax): include/linux/kernel.h tracing_is_on
ANALYZE (Syntax): include/linux/kernel.h tracing_snapshot
ANALYZE (Syntax): include/linux/kernel.h tracing_snapshot_alloc
ANALYZE (Syntax): include/linux/kernel.h trace_printk
ANALYZE (Syntax): include/linux/kernel.h ftrace_vprintk
ANALYZE (Syntax): include/linux/kernel.h ftrace_dump
ANALYZE (Syntax): include/linux/bug.h is_warning_bug
ANALYZE (Syntax): kernel/bounds.c foo
ANALYZE (Path,  Inline_Regular): kernel/bounds.c foo
In file included from kernel/bounds.c:9:
In file included from include/linux/page-flags.h:9:
In file included from include/linux/bug.h:4:
In file included from 
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bug.h:59:
In file included from include/asm-generic/bug.h:13:
In file included from include/linux/kernel.h:10:
In file included from include/linux/bitops.h:22:
/home/dl9pf/llvmlinux/targets/vexpress/src/linux/arch/arm/include/asm/bitops.h:250:3: 
warning: Value stored to 'x' is never read
                x <<= 1;
                ^     ~
1 warning generated.


So this works, now the interesting part is how to get that triple properly 
added or propagated to the cc1 stage.
-- 

Dipl.-Ing.
Jan-Simon Möller

jansimon.moeller at gmx.de
On Wednesday 26 June 2013 12:45:02 Mark Charlebois wrote:
> Eduard,
> 
> See llvmlinux/arch/arm/bin/clang-wrap.sh for a script that passes clang the
> required parameters to cross compile for userspace ARMv7 code.
> 
> See llvmlinux/test/unit/register-var/Makefile for an example using
> clang_wrap.
> 
> There is also an example in llvmlinux/test/unit/ARM64bit/Makefile for
> setting the parameters.
> 
> It is a bit of a black art and not at all well documented.
> 
> -Mark
> 
> On Wed, Jun 26, 2013 at 10:29 AM, Eduard Bachmakov 
<e.bachmakov at gmail.com>wrote:
> > Alright after tons of tinkering I came up with the following conclusions.
> > 
> >   1. I can't confirm if this is arm specific or just non-x64 because
> > 
> > every other arch failed to compile for me.
> > 
> >   2. It is not an issue with environment or make variables.
> >   3. There is no compilation issue, it's just the analysis run that
> > 
> > fails (that was clear before but know it's definite)
> > 
> >   4. The offending line is in here:
> > '/home/e/llvmlinux/toolchain/clang/install/bin/clang-3.4' '-cc1'
> > '-triple' 'x86_64-unknown-linux-gnu' '-analyze' '-disable-free'
> > '-disable-llvm-verifier' '-main-file-name' 'bounds.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' '-mdisable-fp-elim'
> > '-fmath-errno' '-masm-verbose' '-mconstructor-aliases'
> > '-munwind-tables' '-fuse-init-array' '-no-implicit-float'
> > '-target-cpu' 'armv7-a' '-nostdsysteminc' '-nobuiltininc'
> > '-resource-dir'
> > '/home/e/llvmlinux/toolchain/clang/install/bin/../lib/clang/3.4'
> > '-isystem'
> > '/home/e/llvmlinux/toolchain/clang/install/bin/../lib/clang/3.4/include'
> > '-include'
> > '/home/e/llvmlinux/targets/vexpress/src/linux/include/linux/kconfig.h'
> > '-D' '__KERNEL__' '-D' '__LINUX_ARM_ARCH__=7' '-D' 'KBUILD_STR(s)=#s'
> > '-D' 'KBUILD_BASENAME=KBUILD_STR(bounds)' '-D'
> > 'KBUILD_MODNAME=KBUILD_STR(bounds)' '-I'
> > '/home/e/llvmlinux/targets/vexpress/src/linux/arch/arm/include' '-I'
> > 'arch/arm/include/generated' '-I' 'include' '-I'
> > '/home/e/llvmlinux/targets/vexpress/src/linux/arch/arm/include/uapi'
> > '-I' 'arch/arm/include/generated/uapi' '-I'
> > '/home/e/llvmlinux/targets/vexpress/src/linux/include/uapi' '-I'
> > 'include/generated/uapi' '-Wno-trigraphs' '-Wno-format-security'
> > '-Wno-asm-operand-widths' '-Wno-unused-variable'
> > '-Wno-format-invalid-specifier' '-Wno-tautological-compare'
> > '-Wno-pointer-sign' '-fdebug-compilation-dir'
> > '/home/e/llvmlinux/targets/vexpress/src/linux' '-ferror-limit' '19'
> > '-fmessage-length' '0' '-mstackrealign' '-fno-builtin'
> > '-fobjc-runtime=gcc' '-fobjc-default-synthesize-properties'
> > '-fdiagnostics-show-option' '-backend-option' '-vectorize-loops'
> > '-analyzer-display-progress' '-analyzer-output=html' '-o'
> > '/home/e/llvmlinux/targets/vexpress/tmp/scan-build-2013-06-26-6' '-x'
> > 'c' 'kernel/bounds.c'
> > 
> > In particular, '-target-cpu' 'armv7-a' doesn't work. I'm not sure how
> > target-cpu works so I started guessing things like armv7 or arm but
> > that didn't work either. According to clang -cc1 -help, target-cpu
> > seems to be the only thing to have an influence on target architecture
> > (with -cc1 -arch or -march or -mtune don't seem to be supported). I
> > did a few tests with clang -### and it turns out that -march=xyz is
> > translated to -target-cpu xyz .
> > 
> > A quick test on my host clang 3.3 I getting the same issue for a
> > trivial test like "clang -march=armv7-a bla.c", which surprises me
> > since we're using -march for the actual built
> > 
> > My current guess is that '-triple' 'x86_64-unknown-linux-gnu'  might
> > be the real reason behind the problem because ...
> > 
> > clang -\#\#\# -target arm-none-linux-gnueabi bla.c
> > includes "-triple" "armv4t-none-linux-gnueabi" and "-target-cpu"
> > "arm7tdmi"
> > 
> > and it compiles on my system (doesn't assemble but that's another issue)
> > 
> > ... does anyone know how targets/triples are defined? Or what they're
> > really called so I can search for docs online?
> > 
> > On Wed, Jun 26, 2013 at 10:24 AM, Jan-Simon Möller <dl9pf at gmx.de> wrote:
> > > Comments inline ...
> > > --
> > > 
> > > Dipl.-Ing.
> > > Jan-Simon Möller
> > > 
> > > jansimon.moeller at gmx.de
> > > 
> > > On Monday 24 June 2013 20:57:00 Eduard Bachmakov wrote:
> > >> Hey everyone,
> > >> 
> > >> After what felt like a million do-overs I think I found a workable
> > >> location for the integration of clang-analyzer. See patch below.
> > >> 
> > >> The GOOD: x64 works. How?
> > >> 
> > >>     cd targets/x86_64; make kernel-scan-build; scan-view <watch end of
> > >> 
> > >> output, last line before time statistics>
> > >> 
> > >> The BAD: Should work for other targets, however, it seems some flags
> > >> aren't passed down in cases of cross-compilation, I'm ironing that
> > >> out. Feel free to try though!
> > > 
> > > Check:
> > > ccc-analyzer ~ line 693 .  Seems like "@Archs" is empty in the ARM case
> > 
> > and
> > 
> > > thus we don't set it properly (and seem like to default to x86).
> > > 
> > >> The UGLY: takes forever. However, JSM might donate a stripped down
> > >> .config soon. That would speed things up a bit.
> > > 
> > > Best,
> > > JS
> > 
> > _______________________________________________
> > LLVMLinux mailing list
> > LLVMLinux at lists.linuxfoundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/llvmlinux


More information about the LLVMLinux mailing list