Skip to contentSkip to conversation

about using smatch in all debian C code

DISCUSSION 李书畅 2 participants 32 messages Nov 9, 2023 – Mar 22, 2024

lore
Share & tools
lore

李书畅

author
#0 lore raw

Hello Dan, I am an undergraduate student of Dongliang Mu's team.I'm recently working on a project on how to run smatch in all debian C code, but I found that there is little documentation on use smatch on code other than the linux kernel,so I am having trouble with this project.I'd like to ask you what do I need to do to use smatch (simplifying some of the rules is fine) in general C code, and is there documentation that can help?

#1 lore raw
Quoted 9 lines · 李书畅

Hello Dan, I am an undergraduate student of Dongliang Mu's team. I'm recently working on a project on how to run smatch in all debian C code, but I found that there is little documentation on use smatch on code other than the linux kernel,so I am having trouble with this project.

I'd like to ask you what do I need to do to use smatch (simplifying some of the rules is fine) in general C code, and is there documentation that can help?

Basically you want to call smatch with all the same arguments that you pass to GCC plus some specific smatch arguments at the begining.

That's kind of what the cgcc script is supposed to do. So maybe you could:
export REAL_CC=$(which gcc)
export CHECK="/path/to/smatch --info"

(The --info argument will generate a ton of output so that's one way to be sure it's working).

Then if you were just checking one project, I would say to modify the Makefiles to call cgcc instead of gcc but if you're checking everything maybe move the real gcc to real_gcc and move cgcc to /usr/bin/gcc

The other issue that you're going to run into is with recursive Makefiles where it cd's to a different directory before building things. In that situation the warnings just say "foo.c:123 warning blah blah blah". So what you want to do is pass --full-path.

export CHECK="/path/to/smatch --info --full-path"

Anyway, I haven't done any of this before so I can't promise it will work. Let me know either way. Let me know any issues you run into and I'll see what I can do to help.

I'm traveling for a week so I might not very responsive until Nov 20.

regards,
dan carpenter

author
#2 lore raw

I'm trying to create a database for qemu (a C project, which is in the same directory as smatch) and I've tried running the following script: . ./smatch/devel/smatch_data/db/create_db.sh, but it's not working, what should I do?

Quoted 48 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]>
发送时间: 2023-11-09 15:57:03 (星期四)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: about using smatch in all debian C code

Quoted 9 lines · 李书畅

Hello Dan, I am an undergraduate student of Dongliang Mu's team. I'm recently working on a project on how to run smatch in all debian C code, but I found that there is little documentation on use smatch on code other than the linux kernel,so I am having trouble with this project.

I'd like to ask you what do I need to do to use smatch (simplifying some of the rules is fine) in general C code, and is there documentation that can help?

Basically you want to call smatch with all the same arguments that you pass to GCC plus some specific smatch arguments at the begining.

That's kind of what the cgcc script is supposed to do. So maybe you could:
export REAL_CC=$(which gcc)
export CHECK="/path/to/smatch --info"

(The --info argument will generate a ton of output so that's one way to be sure it's working).

Then if you were just checking one project, I would say to modify the Makefiles to call cgcc instead of gcc but if you're checking everything maybe move the real gcc to real_gcc and move cgcc to /usr/bin/gcc

The other issue that you're going to run into is with recursive Makefiles where it cd's to a different directory before building things. In that situation the warnings just say "foo.c:123 warning blah blah blah". So what you want to do is pass --full-path.

export CHECK="/path/to/smatch --info --full-path"

Anyway, I haven't done any of this before so I can't promise it will work. Let me know either way. Let me know any issues you run into and I'll see what I can do to help.

I'm traveling for a week so I might not very responsive until Nov 20.

regards,
dan carpenter

#3 lore raw
Quoted 4 lines · 李书畅

I'm trying to create a database for qemu (a C project, which is in the same directory as smatch) and I've tried running the following script:
. ./smatch/devel/smatch_data/db/create_db.sh, but it's not working, what should I do?

Before you create a database, you want to get Smatch running without a database. Once that works, then you can build it again, passing the --info option to Smatch. That will create a text file with a bunch of SQL in it. Run the create_db.sh script on the test file.

regards,
dan carpenter

author
#4 lore raw

I'm sorry Dan, after reading smatch.txt, I still can't figure out how to run smatch over a single C file before building a database, can you show me the commands I need to enter? It's like the following directory format:

qemu (compiled)
-block.c
smatch (compiled)

regards,
Lishu Chang

Quoted 20 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]> 发送时间: 2024-03-06 14:40:12 (星期三)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: about using smatch in all debian C code

Quoted 4 lines · 李书畅

I'm trying to create a database for qemu (a C project, which is in the same directory as smatch) and I've tried running the following script:
. ./smatch/devel/smatch_data/db/create_db.sh, but it's not working, what should I do?

Before you create a database, you want to get Smatch running without a database. Once that works, then you can build it again, passing the --info option to Smatch. That will create a text file with a bunch of SQL in it. Run the create_db.sh script on the test file.

regards,
dan carpenter

#5 lore raw
Quoted 9 lines · 李书畅

I'm sorry Dan, after reading smatch.txt, I still can't figure out how to run smatch over a single C file before building a database, can you show me the commands I need to enter? It's like the following directory format:

qemu (compiled)
-block.c
smatch (compiled)

Smatch needs all the same flags and arguments that we pass to GCC, plus a couple others which are specific to Smatch such as -p=kernel. So in the kernel the build system will call:

gcc --foo --bar --whatever file.c
smatch -p=kernel --foo --bar --whatever file.c

But that's because the kernel build system was already set up to run a static checker. When you're compiling something else, then the way to do it is to trick the build system into using smatch/cgcc script as the compiler instead of gcc. The cgcc script will run gcc and then run $CHECK (where check is sparse by default).

So with normal makefiles you would do something like:

CHECK="~/smatch/smatch -p=qemu" CC=~/smatch/cgcc make

But qemu is using a mix of Makefiles and meson to build and I don't really know how that works.

regards,
dan carpenter

#6 lore raw

I had hoped that I could make it work using:

./configure --cc=~/smatch/cgcc --cpu=x86_64

But it dies with:

mkvenv: installing meson==1.2.3
mkvenv: checking for sphinx>=1.6
mkvenv: checking for sphinx_rtd_theme>=0.5

*** Ouch! ***

Could not provide build dependency 'sphinx==5.3.0':
• Python package 'sphinx' was not found nor installed.
• mkvenv was configured to operate offline and did not check PyPI.
• 'sphinx-build' was detected on your system at '/usr/bin/sphinx-build', but the build is using an isolated virtual environment.

Sphinx not found/usable, disabling docs.

ERROR: Unrecognized host OS (uname -s reports 'Linux')

regards,
dan carpenter

author
#7 lore raw

After installing all the dependency, I also tried : ./configure --cc=~/smatch/cgcc --cpu=x86_64 , and it died with:

python determined to be '/usr/bin/python3'
python version: Python 3.8.10
mkvenv: Creating non-isolated virtual environment at 'pyvenv'
mkvenv: checking for tomli>=1.2.0
mkvenv: installing tomli>=1.2.0
mkvenv: checking for meson>=0.63.0
mkvenv: installing meson==1.2.3
mkvenv: checking for sphinx>=1.6
mkvenv: checking for sphinx_rtd_theme>=0.5
The Meson build system
Version: 1.2.3
Source dir: /home/lsc20011130/qemu
Build dir: /home/lsc20011130/qemu/build
Build type: native build
Project name: qemu
Project version: 8.2.50
C compiler for the host machine: /home/lsc20011130/smatch/cgcc -m64 -mcx16 (gcc 9.3.0 "cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0") C linker for the host machine: /home/lsc20011130/smatch/cgcc -m64 -mcx16 ld.bfd 2.34
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program scripts/symlink-install-tree.py found: YES (/home/lsc20011130/qemu/build/pyvenv/bin/python3 /home/lsc20011130/qemu/scripts/symlink-install-tree.py) Program sh found: YES (/usr/bin/sh)
Program python3 found: YES (/home/lsc20011130/qemu/build/pyvenv/bin/python3)
Program iasl found: NO
Program bzip2 found: YES (/usr/bin/bzip2)
WARNING: No include directory found parsing "/home/lsc20011130/smatch/cgcc -m64 -mcx16 -xc -E -v -" output
Compiler for C supports link arguments -Wl,-z,relro: YES
Compiler for C supports link arguments -Wl,-z,now: YES
Compiler for C supports link arguments -Wl,--warn-common: YES
Checking if "-fzero-call-used-regs=used-gpr" compiles: NO
Compiler for C supports arguments -ftrivial-auto-var-init=zero: NO
Compiler for C supports arguments -Wempty-body: YES
Compiler for C supports arguments -Wendif-labels: YES
Compiler for C supports arguments -Wexpansion-to-defined: YES
Compiler for C supports arguments -Wformat-security: YES
Compiler for C supports arguments -Wformat-y2k: YES
Compiler for C supports arguments -Wignored-qualifiers: YES
Compiler for C supports arguments -Wimplicit-fallthrough=2: YES
Compiler for C supports arguments -Winit-self: YES
Compiler for C supports arguments -Wmissing-format-attribute: YES
Compiler for C supports arguments -Wmissing-prototypes: YES
Compiler for C supports arguments -Wnested-externs: YES
Compiler for C supports arguments -Wold-style-declaration: YES
Compiler for C supports arguments -Wold-style-definition: YES
Compiler for C supports arguments -Wredundant-decls: YES
Compiler for C supports arguments -Wshadow=local: YES
Compiler for C supports arguments -Wstrict-prototypes: YES
Compiler for C supports arguments -Wtype-limits: YES
Compiler for C supports arguments -Wundef: YES
Compiler for C supports arguments -Wvla: YES
Compiler for C supports arguments -Wwrite-strings: YES
Compiler for C supports arguments -Wno-gnu-variable-sized-type-not-at-end: NO
Compiler for C supports arguments -Wno-initializer-overrides: NO
Compiler for C supports arguments -Wno-missing-include-dirs: YES
Compiler for C supports arguments -Wno-psabi: YES
Compiler for C supports arguments -Wno-shift-negative-value: YES
Compiler for C supports arguments -Wno-string-plus-int: NO
Compiler for C supports arguments -Wno-tautological-type-limit-compare: NO
Compiler for C supports arguments -Wno-typedef-redefinition: NO
Compiler for C supports arguments -Wthread-safety: NO
Program cgcc found: YES (/usr/bin/cgcc)
Program scripts/check_sparse.py found: YES (/home/lsc20011130/qemu/build/pyvenv/bin/python3 /home/lsc20011130/qemu/scripts/check_sparse.py) Library m found: YES
Run-time dependency threads found: YES
Library util found: YES
Run-time dependency appleframeworks found: NO (tried framework)
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Run-time dependency xencontrol found: NO (tried pkgconfig)
Library xenstore found: NO
Library xenctrl found: NO
Library xendevicemodel found: NO
Library xenforeignmemory found: NO
Library xengnttab found: NO
Library xenevtchn found: NO
Library xentoolcore found: NO
Run-time dependency glib-2.0 found: YES 2.64.6
Run-time dependency gmodule-no-export-2.0 found: YES 2.64.6
Run-time dependency gio-2.0 found: YES 2.64.6
Traceback (most recent call last):
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/mesonmain.py", line 194, in run
return options.run_func(options)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/msetup.py", line 358, in run
app.generate()
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/msetup.py", line 183, in generate
return self._generate(env, capture, vslite_ctx)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/msetup.py", line 228, in _generate

    intr.run()
  File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreter/interpreter.py", line 3002, in run
    super().run()

File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 164, in run
self.evaluate_codeblock(self.ast, start=1)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 190, in evaluate_codeblock
raise e
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 182, in evaluate_codeblock
self.evaluate_statement(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 206, in evaluate_statement
return self.evaluate_if(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 301, in evaluate_if
self.evaluate_codeblock(i.block)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 190, in evaluate_codeblock
raise e
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 182, in evaluate_codeblock
self.evaluate_statement(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 206, in evaluate_statement
return self.evaluate_if(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 286, in evaluate_if
result = self.evaluate_statement(i.condition)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 218, in evaluate_statement
return self.evaluate_andstatement(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 359, in evaluate_andstatement
r = self.evaluate_statement(cur.right)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 222, in evaluate_statement
return self.evaluate_notstatement(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 273, in evaluate_notstatement
v = self.evaluate_statement(cur.value)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 200, in evaluate_statement
return self.method_call(cur)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 550, in method_call
res = obj.method_call(method_name, args, kwargs)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/baseobjects.py", line 94, in method_call
return method(args, kwargs)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/decorators.py", line 277, in wrapper
return f(*nargs, **wrapped_kwargs)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreterbase/decorators.py", line 596, in wrapper
return f(*wrapped_args, **wrapped_kwargs)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/interpreter/compiler.py", line 499, in links_method
result, cached = self.compiler.links(code, self.environment,
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/compilers/compilers.py", line 1322, in links
return self.compiles(code, env, extra_args=extra_args,
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/compilers/compilers.py", line 1307, in compiles
with self._build_wrapper(code, env, extra_args, dependencies, mode, disable_cache=disable_cache) as p:
File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/compilers/compilers.py", line 1299, in _build_wrapper
with self.cached_compile(code, env.coredata, extra_args=args, mode=mode, temp_dir=env.scratch_dir) as r:
File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/compilers/compilers.py", line 896, in cached_compile
with self.compile(code, extra_args=extra_args, mode=mode, want_output=False, temp_dir=temp_dir) as p:
File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/compilers/compilers.py", line 867, in compile
p, stdo, stde = Popen_safe_logged(command_list, msg='Command line', cwd=tmpdirname, env=os_env)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/utils/universal.py", line 1528, in Popen_safe_logged
p, o, e = Popen_safe(args, **kwargs)
File "/home/lsc20011130/qemu/build/pyvenv/lib/python3.8/site-packages/mesonbuild/utils/universal.py", line 1487, in Popen_safe
o, e = p.communicate(write)
File "/usr/lib/python3.8/subprocess.py", line 1028, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/usr/lib/python3.8/subprocess.py", line 1910, in _communicate
stderr = self._translate_newlines(stderr,
File "/usr/lib/python3.8/subprocess.py", line 905, in _translate_newlines
data = data.decode(encoding, errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 4663: invalid start byte

../meson.build:950:28: ERROR: Unhandled python exception

This is a Meson bug and should be reported!

ERROR: meson setup failed

regards,
Lishu Chang

Quoted 31 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]> 发送时间: 2024-03-07 03:25:40 (星期四)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: about using smatch in all debian C code

I had hoped that I could make it work using:

./configure --cc=~/smatch/cgcc --cpu=x86_64

But it dies with:

mkvenv: installing meson==1.2.3
mkvenv: checking for sphinx>=1.6
mkvenv: checking for sphinx_rtd_theme>=0.5

*** Ouch! ***

Could not provide build dependency 'sphinx==5.3.0':
• Python package 'sphinx' was not found nor installed.
• mkvenv was configured to operate offline and did not check PyPI.
• 'sphinx-build' was detected on your system at '/usr/bin/sphinx-build', but the build is using an isolated virtual environment.

Sphinx not found/usable, disabling docs.

ERROR: Unrecognized host OS (uname -s reports 'Linux')

regards,
dan carpenter

#8 lore raw

I figured it out. You need to:

export CHECK="/home/user/smatch/smatch --file-output"

Then you can't use ~/ in the --cc option. It has to be /home/user/smatch/cgcc. But then Smatch/Sparse still doesn't compile the code correctly. There are tons of compile errors. This is really a Sparse problem (Smatch uses Sparse as a parser). I suspect that fixing it will be difficult.

regards,
dan carpenter

author
#9 lore raw

Thanks Dan for your reply to me, I get it.
I'll give up making smatch work on qemu,
and find some other C projects outside of the Linux kernel, which have simpler makefiles. So that it's easier for smatch to run on them. Do you have any advice on which C programs to choose?

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]> 发送时间: 2024-03-07 17:49:00 (星期四)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: about using smatch in all debian C code

I figured it out. You need to:

export CHECK="/home/user/smatch/smatch --file-output"

Then you can't use ~/ in the --cc option. It has to be /home/user/smatch/cgcc. But then Smatch/Sparse still doesn't compile the code correctly. There are tons of compile errors. This is really a Sparse problem (Smatch uses Sparse as a parser). I suspect that fixing it will be difficult.

regards,
dan carpenter

author
#10 lore raw
In reply to Dan Carpenter

Hello Dan, this time I tried to use smatch in a simpler C project named NtyCo,
Its program address is : https://github.com/wangbojing/NtyCo.
And I tried CHECK="/home/lsc20011130/smatch/smatch -p=NtyCo" CC=/home/lsc20011130/smatch/cgcc make, it seems worked. then I tried /home/lsc20011130/smatch/smatch -p=NtyCo --foo --bar --/home/lsc20011130/NtyCo/core/nty_epoll.c. But it doesn't output anything (even though I put some obvious error code in the C file),
I want to know which of my steps went wrong.

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]> 发送时间: 2024-03-07 17:49:00 (星期四)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: about using smatch in all debian C code

I figured it out. You need to:

export CHECK="/home/user/smatch/smatch --file-output"

Then you can't use ~/ in the --cc option. It has to be /home/user/smatch/cgcc. But then Smatch/Sparse still doesn't compile the code correctly. There are tons of compile errors. This is really a Sparse problem (Smatch uses Sparse as a parser). I suspect that fixing it will be difficult.

regards,
dan carpenter

author
#11 lore raw

I figure it out, I tried
CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/NtyCo/core" CC=/home/lsc20011130/smatch/cgcc make , and it works fine.

Quoted 32 lines · 李书畅

Hello Dan, this time I tried to use smatch in a simpler C project named NtyCo,
Its program address is : https://github.com/wangbojing/NtyCo.
And I tried CHECK="/home/lsc20011130/smatch/smatch -p=NtyCo" CC=/home/lsc20011130/smatch/cgcc make, it seems worked. then I tried /home/lsc20011130/smatch/smatch -p=NtyCo --foo --bar --/home/lsc20011130/NtyCo/core/nty_epoll.c. But it doesn't output anything (even though I put some obvious error code in the C file),
I want to know which of my steps went wrong.

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]> 发送时间: 2024-03-07 17:49:00 (星期四)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: about using smatch in all debian C code

I figured it out. You need to:

export CHECK="/home/user/smatch/smatch --file-output"

Then you can't use ~/ in the --cc option. It has to be /home/user/smatch/cgcc. But then Smatch/Sparse still doesn't compile the code correctly. There are tons of compile errors. This is really a Sparse problem (Smatch uses Sparse as a parser). I suspect that fixing it will be difficult.

regards,
dan carpenter

#12 lore raw
Quoted 3 lines · 李书畅

I figure it out, I tried
CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/NtyCo/core" CC=/home/lsc20011130/smatch/cgcc make , and it works fine.

I don't think you want to add the "/home/lsc20011130/NtyCo/core" part...

But I'm happy that it's working. Don't hesitate to ask if you run into more issues.

regards,
dan carpenter

#26 lore raw
In reply to 李书畅
Quoted 6 lines · 李书畅

Hello Dan, this time I tried to use smatch in a simpler C project named NtyCo,
Its program address is : https://github.com/wangbojing/NtyCo.
And I tried CHECK="/home/lsc20011130/smatch/smatch -p=NtyCo" CC=/home/lsc20011130/smatch/cgcc make, it seems worked. then I tried /home/lsc20011130/smatch/smatch -p=NtyCo --foo --bar --/home/lsc20011130/NtyCo/core/nty_epoll.c. But it doesn't output anything (even though I put some obvious error code in the C file),
I want to know which of my steps went wrong.

It's not going to catch every bug. One thing the I do is I pass the --debug option to Smatch. That generates a ton of output so I'm sure it's working.

regards,
dan carpenter

author
#27 lore raw

Hello Dan, in the smatch.txt, you said :
If you are building something else (which is not the Linux kernel) then use something like:
make CHECK="~/progs/smatch/devel/smatch --full-path" \
CC=~/progs/smatch/devel/smatch/cgcc | tee smatch_warns.txt,

I'd like to know what file does this full-path refer to? And if it means the full path of the C project you want to check, what is the difference between using '-p=' and '--full-path'?

regards,
Lishu Chang

Quoted 21 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]>
发送时间: 2024-03-11 13:01:54 (星期一)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: Re: about using smatch in all debian C code

Quoted 6 lines · 李书畅

Hello Dan, this time I tried to use smatch in a simpler C project named NtyCo,
Its program address is : https://github.com/wangbojing/NtyCo.
And I tried CHECK="/home/lsc20011130/smatch/smatch -p=NtyCo" CC=/home/lsc20011130/smatch/cgcc make, it seems worked. then I tried /home/lsc20011130/smatch/smatch -p=NtyCo --foo --bar --/home/lsc20011130/NtyCo/core/nty_epoll.c. But it doesn't output anything (even though I put some obvious error code in the C file),
I want to know which of my steps went wrong.

It's not going to catch every bug. One thing the I do is I pass the --debug option to Smatch. That generates a ton of output so I'm sure it's working.

regards,
dan carpenter

author
#30 lore raw
In reply to Dan Carpenter

Hello Dan, I'd like to know are there any requirements for the makefile of a C project (e.g. not using meson to build) to prevent similar sparse problems?

regards,
Lishu Chang

Quoted 12 lines · Dan Carpenter

I figured it out. You need to:

export CHECK="/home/user/smatch/smatch --file-output"

Then you can't use ~/ in the --cc option. It has to be /home/user/smatch/cgcc. But then Smatch/Sparse still doesn't compile the code correctly. There are tons of compile errors. This is really a Sparse problem (Smatch uses Sparse as a parser). I suspect that fixing it will be difficult.

regards,
dan carpenter

#31 lore raw
Quoted 3 lines · 李书畅

Hello Dan, I'd like to know are there any requirements for the makefile of a C project (e.g. not using meson to build) to prevent similar sparse problems?

It's not a problem that it used meson. We figured that solved that. The issue was that Sparse couldn't find the correct header files... I don't really have a good answer for that. I suspect it has to do with #pragmas but I didn't look.

regards,
dan carpenter

#28 lore raw
In reply to 李书畅
Quoted 8 lines · 李书畅

Hello Dan, in the smatch.txt, you said :
If you are building something else (which is not the Linux kernel) then use something like:
make CHECK="~/progs/smatch/devel/smatch --full-path" \
CC=~/progs/smatch/devel/smatch/cgcc | tee smatch_warns.txt,

I'd like to know what file does this full-path refer to? And if it means the full path of the C project you want to check, what is the difference between using '-p=' and '--full-path'?

-p stands for --project. It's for when there is project specific code. Mostly it's the linux kernel which has tons of specific checks.

The --full-path option is for recursive Makefiles where you enter sub-directorys and run make. The kernel doesn't use a recursive build system so all the warning messages have drivers/foo/bar/file.c. Nice. But with a recursive build system the warning messages just have file.c. Then when you add --full-path they have /home/whatever/kernel/drivers/foo/bar/file.c
which isn't as nice, but it's more useful than just file.c

regards,
dan carpenter

author
#29 lore raw

Thanks Dan for your reply, you made it very clear.

regards,
Lishu Chang

Quoted 23 lines · Dan Carpenter
Quoted 8 lines · 李书畅

Hello Dan, in the smatch.txt, you said :
If you are building something else (which is not the Linux kernel) then use something like:
make CHECK="~/progs/smatch/devel/smatch --full-path" \
CC=~/progs/smatch/devel/smatch/cgcc | tee smatch_warns.txt,

I'd like to know what file does this full-path refer to? And if it means the full path of the C project you want to check, what is the difference between using '-p=' and '--full-path'?

-p stands for --project. It's for when there is project specific code. Mostly it's the linux kernel which has tons of specific checks.

The --full-path option is for recursive Makefiles where you enter sub-directorys and run make. The kernel doesn't use a recursive build system so all the warning messages have drivers/foo/bar/file.c. Nice. But with a recursive build system the warning messages just have file.c. Then when you add --full-path they have /home/whatever/kernel/drivers/foo/bar/file.c
which isn't as nice, but it's more useful than just file.c

regards,
dan carpenter

author
#13 lore raw
In reply to Dan Carpenter

I realized that my previous statement was wrong.
In this case, as I tried : make CHECK="/home/lsc20011130/smatch/smatch" CC=/home/lsc20011130/smatch/cgcc, the output is:

if [ ! -d "objs" ]; then \
        mkdir -p objs; \\
mkdir -p objs; \\
if [ ! -d "bin" ]; then \ \
        mkdir -p bin; \ \

mkdir -p bin; \fi
core/
make -C core/
make[1]: Entering directory '/home/lsc20011130/NtyCo/core'
/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /home/lsc20011130/NtyCo/objs/nty_epoll.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /home/lsc20011130/NtyCo/objs/nty_coroutine.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /home/lsc20011130/NtyCo/objs/nty_socket.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core core /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /home/lsc20011130/NtyCo/objs/nty_schedule.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core
make[1]: Leaving directory '/home/lsc20011130/NtyCo/core'
ar rcs libntyco.a /home/lsc20011130/NtyCo/objs/nty_socket.o /home/lsc20011130/NtyCo/objs/nty_coroutine.o /home/lsc20011130/NtyCo/objs/ nty_epoll.o /home/lsc20011130/NtyCo/objs/nty_schedule.o

cgcc runs, but sparse doesn't seem to work successfully.

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]>
发送时间: 2024-03-11 13:00:42 (星期一)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: Re: Re: about using smatch in all debian C code

Quoted 3 lines · 李书畅

I figure it out, I tried
CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/NtyCo/core" CC=/home/lsc20011130/smatch/cgcc make , and it works fine.

I don't think you want to add the "/home/lsc20011130/NtyCo/core" part...

But I'm happy that it's working. Don't hesitate to ask if you run into more issues.

regards,
dan carpenter

author
#14 lore raw

I put some obvious errors in the code and add --info to smatch, but the output does't change at all :

if [ ! -d "objs" ]; then \
        mkdir -p objs; \\
mkdir -p objs; \\
if [ ! -d "bin" ]; then \ \
        mkdir -p bin; \ \

mkdir -p bin; \fi
core/
make -C core/
make[1]: Entering directory '/home/lsc20011130/NtyCo/core'
/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /home/lsc20011130/NtyCo/objs/nty_epoll.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /home/lsc20011130/NtyCo/objs/nty_coroutine.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /home/lsc20011130/NtyCo/objs/nty_socket.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core core /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /home/lsc20011130/NtyCo/objs/nty_schedule.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core
make[1]: Leaving directory '/home/lsc20011130/NtyCo/core'
ar rcs libntyco.a /home/lsc20011130/NtyCo/objs/nty_socket.o /home/lsc20011130/NtyCo/objs/nty_coroutine.o /home/lsc20011130/NtyCo/objs/ nty_epoll.o /home/lsc20011130/NtyCo/objs/nty_schedule.o

Sparse is clearly not working, I'm confused.

regards,
Lishu Chang

Quoted 45 lines · 李书畅

I realized that my previous statement was wrong.
In this case, as I tried : make CHECK="/home/lsc20011130/smatch/smatch" CC=/home/lsc20011130/smatch/cgcc, the output is:

if [ ! -d "objs" ]; then \
        mkdir -p objs; \\
mkdir -p objs; \\
if [ ! -d "bin" ]; then \ \
        mkdir -p bin; \ \

mkdir -p bin; \fi
core/
make -C core/
make[1]: Entering directory '/home/lsc20011130/NtyCo/core'
/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /home/lsc20011130/NtyCo/objs/nty_epoll.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /home/lsc20011130/NtyCo/objs/nty_coroutine.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /home/lsc20011130/NtyCo/objs/nty_socket.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core core /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /home/lsc20011130/NtyCo/objs/nty_schedule.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core
make[1]: Leaving directory '/home/lsc20011130/NtyCo/core'
ar rcs libntyco.a /home/lsc20011130/NtyCo/objs/nty_socket.o /home/lsc20011130/NtyCo/objs/nty_coroutine.o /home/lsc20011130/NtyCo/objs/ nty_epoll.o /home/lsc20011130/NtyCo/objs/nty_schedule.o

cgcc runs, but sparse doesn't seem to work successfully.

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]>
发送时间: 2024-03-11 13:00:42 (星期一)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: Re: Re: about using smatch in all debian C code

Quoted 3 lines · 李书畅

I figure it out, I tried
CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/NtyCo/core" CC=/home/lsc20011130/smatch/cgcc make , and it works fine.

I don't think you want to add the "/home/lsc20011130/NtyCo/core" part...

But I'm happy that it's working. Don't hesitate to ask if you run into more issues.

regards,
dan carpenter

author
#15 lore raw

Hello Dan, please ignore my previous two e-mails, which are summarized in this one. The current situation is as follows:
I went directly into the NtyCo subdirectory NtyCo/core, changed the gcc to cgcc in the makefile and ran:

sudo make

the output (sparse show me the warnings) :

/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /nty_epoll.o
/home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /nty_coroutine.o
nty_coroutine.c:258:6: warning: symbol 'nty_coroutine_renice' was not declared. Should it be static?
nty_coroutine.c:279:6: warning: symbol 'nty_coroutine_detach' was not declared. Should it be static?
/home/lsc20011130/smatch/cgcc -c nty_socket.c -o /nty_socket.o
nty_socket.c:421:9: error: symbol 'recvfrom' redeclared with different type (originally declared at /usr/include/sys/socket.h:163) - incompatible argument 5 (different base types) nty_socket.c:504:9: error: symbol 'sendto' redeclared with different type (originally declared at /usr/include/sys/socket.h:152) - incompatible argument 5 (different base types) nty_socket.c:529:5: error: symbol 'accept' redeclared with different type (originally declared at /usr/include/sys/socket.h:232) - incompatible argument 2 (different base types) nty_socket.c:579:5: error: symbol 'connect' redeclared with different type (originally declared at /usr/include/sys/socket.h:126) - incompatible argument 2 (different base types) /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /nty_schedule.o
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_INSERT_COLOR' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_REMOVE_COLOR' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_REMOVE' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_INSERT' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_FIND' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_NFIND' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_NEXT' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_PREV' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_MINMAX' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_INSERT_COLOR' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_REMOVE_COLOR' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_REMOVE' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_INSERT' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_FIND' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_NFIND' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_NEXT' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_PREV' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_MINMAX' was not declared. Should it be static?
nty_schedule.c:122:34: warning: missing braces around initializer
nty_schedule.c:121:15: warning: symbol 'nty_schedule_search_wait' was not declared. Should it be static?
nty_schedule.c:135:34: warning: missing braces around initializer
nty_schedule.c:181:6: warning: symbol 'nty_schedule_cancel_wait' was not declared. Should it be static?
nty_schedule.c:185:6: warning: symbol 'nty_schedule_free' was not declared. Should it be static?
nty_schedule.c:201:5: warning: symbol 'nty_schedule_create' was not declared. Should it be static?

but if I run :
sudo make CHECK="/home/lsc20011130/smatch/smatch --info", instead of sudo make
the output (all the waring disappear):

/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /nty_epoll.o /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /nty_coroutine.o /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /nty_socket.o /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /nty_schedule.o

I would like to know if this is normal? I'm not familiar with static analysis, so forgive me if I ask some simple and silly questions.

Quoted 70 lines · 李书畅

I put some obvious errors in the code and add --info to smatch, but the output does't change at all :

if [ ! -d "objs" ]; then \
        mkdir -p objs; \\
mkdir -p objs; \\
if [ ! -d "bin" ]; then \ \
        mkdir -p bin; \ \

mkdir -p bin; \fi
core/
make -C core/
make[1]: Entering directory '/home/lsc20011130/NtyCo/core'
/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /home/lsc20011130/NtyCo/objs/nty_epoll.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /home/lsc20011130/NtyCo/objs/nty_coroutine.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /home/lsc20011130/NtyCo/objs/nty_socket.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core core /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /home/lsc20011130/NtyCo/objs/nty_schedule.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core
make[1]: Leaving directory '/home/lsc20011130/NtyCo/core'
ar rcs libntyco.a /home/lsc20011130/NtyCo/objs/nty_socket.o /home/lsc20011130/NtyCo/objs/nty_coroutine.o /home/lsc20011130/NtyCo/objs/ nty_epoll.o /home/lsc20011130/NtyCo/objs/nty_schedule.o

Sparse is clearly not working, I'm confused.

regards,
Lishu Chang

Quoted 45 lines · 李书畅

I realized that my previous statement was wrong.
In this case, as I tried : make CHECK="/home/lsc20011130/smatch/smatch" CC=/home/lsc20011130/smatch/cgcc, the output is:

if [ ! -d "objs" ]; then \
        mkdir -p objs; \\
mkdir -p objs; \\
if [ ! -d "bin" ]; then \ \
        mkdir -p bin; \ \

mkdir -p bin; \fi
core/
make -C core/
make[1]: Entering directory '/home/lsc20011130/NtyCo/core'
/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /home/lsc20011130/NtyCo/objs/nty_epoll.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /home/lsc20011130/NtyCo/objs/nty_coroutine.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /home/lsc20011130/NtyCo/objs/nty_socket.o -lpthread -O3 -ldl -I /home/lsc20011130/NtyCo/core core /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /home/lsc20011130/NtyCo/objs/nty_schedule.o -lpthread -O3 -ldl -I /home/lsc20011130/ NtyCo/core
make[1]: Leaving directory '/home/lsc20011130/NtyCo/core'
ar rcs libntyco.a /home/lsc20011130/NtyCo/objs/nty_socket.o /home/lsc20011130/NtyCo/objs/nty_coroutine.o /home/lsc20011130/NtyCo/objs/ nty_epoll.o /home/lsc20011130/NtyCo/objs/nty_schedule.o

cgcc runs, but sparse doesn't seem to work successfully.

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]>
发送时间: 2024-03-11 13:00:42 (星期一)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: Re: Re: about using smatch in all debian C code

Quoted 3 lines · 李书畅

I figure it out, I tried
CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/NtyCo/core" CC=/home/lsc20011130/smatch/cgcc make , and it works fine.

I don't think you want to add the "/home/lsc20011130/NtyCo/core" part...

But I'm happy that it's working. Don't hesitate to ask if you run into more issues.

regards,
dan carpenter

#16 lore raw
Quoted 46 lines · 李书畅

Hello Dan, please ignore my previous two e-mails, which are summarized in this one. The current situation is as follows:
I went directly into the NtyCo subdirectory NtyCo/core, changed the gcc to cgcc in the makefile and ran:

sudo make

the output (sparse show me the warnings) :

/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /nty_epoll.o
/home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /nty_coroutine.o
nty_coroutine.c:258:6: warning: symbol 'nty_coroutine_renice' was not declared. Should it be static?
nty_coroutine.c:279:6: warning: symbol 'nty_coroutine_detach' was not declared. Should it be static?
/home/lsc20011130/smatch/cgcc -c nty_socket.c -o /nty_socket.o
nty_socket.c:421:9: error: symbol 'recvfrom' redeclared with different type (originally declared at /usr/include/sys/socket.h:163) - incompatible argument 5 (different base types) nty_socket.c:504:9: error: symbol 'sendto' redeclared with different type (originally declared at /usr/include/sys/socket.h:152) - incompatible argument 5 (different base types) nty_socket.c:529:5: error: symbol 'accept' redeclared with different type (originally declared at /usr/include/sys/socket.h:232) - incompatible argument 2 (different base types) nty_socket.c:579:5: error: symbol 'connect' redeclared with different type (originally declared at /usr/include/sys/socket.h:126) - incompatible argument 2 (different base types) /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /nty_schedule.o
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_INSERT_COLOR' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_REMOVE_COLOR' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_REMOVE' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_INSERT' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_FIND' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_NFIND' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_NEXT' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_PREV' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_MINMAX' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_INSERT_COLOR' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_REMOVE_COLOR' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_REMOVE' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_INSERT' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_FIND' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_NFIND' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_NEXT' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_PREV' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_MINMAX' was not declared. Should it be static?
nty_schedule.c:122:34: warning: missing braces around initializer
nty_schedule.c:121:15: warning: symbol 'nty_schedule_search_wait' was not declared. Should it be static?
nty_schedule.c:135:34: warning: missing braces around initializer
nty_schedule.c:181:6: warning: symbol 'nty_schedule_cancel_wait' was not declared. Should it be static?
nty_schedule.c:185:6: warning: symbol 'nty_schedule_free' was not declared. Should it be static?
nty_schedule.c:201:5: warning: symbol 'nty_schedule_create' was not declared. Should it be static?

but if I run :
sudo make CHECK="/home/lsc20011130/smatch/smatch --info", instead of sudo make
the output (all the waring disappear):

Quoted 8 lines

/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /nty_epoll.o /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /nty_coroutine.o /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /nty_socket.o /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /nty_schedule.o

I would like to know if this is normal? I'm not familiar with static analysis, so forgive me if I ask some simple and silly questions.

Feel free to ask questions. In this case, what you're seeing is not normal at all.

If the cgcc script is able to run sparse then it's able to run smatch. The --info option should produce output for every function so it should definitely produce output here.

The only thing I can think of is that maybe it's because smatch outputs to stdout and sparse outputs to stderr? What about if you pass --file-output to smatch? CHECK="/home/lsc20011130/smatch/smatch --info --file-output" That should create a bunch of files that end in foo.c.smatch, foo.c.smatch.sql and foo.c.smatch.caller_info

regards,
dan carpenter

author
#17 lore raw

As I tried :
CHECK="/home/lsc20011130/smatch/smatch --info --file-output",
for each .c file, the above three file are created , and there's a lot of information in these files, like:

nty_schedule.c:98 nty_schedule_sched_sleepdown() info: param_mapper 0 => _nty_coroutine_rbtree_sleep_RB_INSERT 1 nty_schedule.c:113 nty_schedule_desched_sleepdown() info: param_mapper 0 => _nty_coroutine_rbtree_sleep_RB_REMOVE 1 nty_schedule.c:144 nty_schedule_desched_wait() error: we previously assumed 'co' could be null (see line 141)

nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 0, -1, '%call_marker%', 'void(*)(char*, char*, uint, char*)'); nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 1001, 0, '$', '8349466724068225024'); nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 1001, 1, '$', '5566788581620412416');

nty_coroutine.c:55 _save_stack() SQL: insert into function_type values(0x7feb7cc204ad2699, '_save_stack', 1, 0, 'struct _nty_coroutine*'); nty_coroutine.c:55 _save_stack() SQL: insert into parameter_name values(0x7feb7cc204ad2699, '_save_stack', 1, 0, 'co');

regards,
Lishu Chang

Quoted 72 lines · Dan Carpenter
Quoted 46 lines · 李书畅

Hello Dan, please ignore my previous two e-mails, which are summarized in this one. The current situation is as follows:
I went directly into the NtyCo subdirectory NtyCo/core, changed the gcc to cgcc in the makefile and ran:

sudo make

the output (sparse show me the warnings) :

/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /nty_epoll.o
/home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /nty_coroutine.o
nty_coroutine.c:258:6: warning: symbol 'nty_coroutine_renice' was not declared. Should it be static?
nty_coroutine.c:279:6: warning: symbol 'nty_coroutine_detach' was not declared. Should it be static?
/home/lsc20011130/smatch/cgcc -c nty_socket.c -o /nty_socket.o
nty_socket.c:421:9: error: symbol 'recvfrom' redeclared with different type (originally declared at /usr/include/sys/socket.h:163) - incompatible argument 5 (different base types) nty_socket.c:504:9: error: symbol 'sendto' redeclared with different type (originally declared at /usr/include/sys/socket.h:152) - incompatible argument 5 (different base types) nty_socket.c:529:5: error: symbol 'accept' redeclared with different type (originally declared at /usr/include/sys/socket.h:232) - incompatible argument 2 (different base types) nty_socket.c:579:5: error: symbol 'connect' redeclared with different type (originally declared at /usr/include/sys/socket.h:126) - incompatible argument 2 (different base types) /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /nty_schedule.o
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_INSERT_COLOR' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_REMOVE_COLOR' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_REMOVE' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_INSERT' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_FIND' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_NFIND' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_NEXT' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_PREV' was not declared. Should it be static?
nty_schedule.c:82:1: warning: symbol '_nty_coroutine_rbtree_sleep_RB_MINMAX' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_INSERT_COLOR' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_REMOVE_COLOR' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_REMOVE' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_INSERT' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_FIND' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_NFIND' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_NEXT' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_PREV' was not declared. Should it be static?
nty_schedule.c:83:1: warning: symbol '_nty_coroutine_rbtree_wait_RB_MINMAX' was not declared. Should it be static?
nty_schedule.c:122:34: warning: missing braces around initializer
nty_schedule.c:121:15: warning: symbol 'nty_schedule_search_wait' was not declared. Should it be static?
nty_schedule.c:135:34: warning: missing braces around initializer
nty_schedule.c:181:6: warning: symbol 'nty_schedule_cancel_wait' was not declared. Should it be static?
nty_schedule.c:185:6: warning: symbol 'nty_schedule_free' was not declared. Should it be static?
nty_schedule.c:201:5: warning: symbol 'nty_schedule_create' was not declared. Should it be static?

but if I run :
sudo make CHECK="/home/lsc20011130/smatch/smatch --info", instead of sudo make
the output (all the waring disappear):

Quoted 8 lines

/home/lsc20011130/smatch/cgcc -c nty_epoll.c -o /nty_epoll.o /home/lsc20011130/smatch/cgcc -c nty_coroutine.c -o /nty_coroutine.o /home/lsc20011130/smatch/cgcc -c nty_socket.c -o /nty_socket.o /home/lsc20011130/smatch/cgcc -c nty_schedule.c -o /nty_schedule.o

I would like to know if this is normal? I'm not familiar with static analysis, so forgive me if I ask some simple and silly questions.

Feel free to ask questions. In this case, what you're seeing is not normal at all.

If the cgcc script is able to run sparse then it's able to run smatch. The --info option should produce output for every function so it should definitely produce output here.

The only thing I can think of is that maybe it's because smatch outputs to stdout and sparse outputs to stderr? What about if you pass --file-output to smatch? CHECK="/home/lsc20011130/smatch/smatch --info --file-output" That should create a bunch of files that end in foo.c.smatch, foo.c.smatch.sql and foo.c.smatch.caller_info

regards,
dan carpenter

#18 lore raw
Quoted 8 lines · 李书畅

As I tried :
CHECK="/home/lsc20011130/smatch/smatch --info --file-output",
for each .c file, the above three file are created , and there's a lot of information in these files, like:

nty_schedule.c:98 nty_schedule_sched_sleepdown() info: param_mapper 0 => _nty_coroutine_rbtree_sleep_RB_INSERT 1 nty_schedule.c:113 nty_schedule_desched_sleepdown() info: param_mapper 0 => _nty_coroutine_rbtree_sleep_RB_REMOVE 1 nty_schedule.c:144 nty_schedule_desched_wait() error: we previously assumed 'co' could be null (see line 141)

Quoted 7 lines

nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 0, -1, '%call_marker%', 'void(*)(char*, char*, uint, char*)'); nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 1001, 0, '$', '8349466724068225024'); nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 1001, 1, '$', '5566788581620412416');

nty_coroutine.c:55 _save_stack() SQL: insert into function_type values(0x7feb7cc204ad2699, '_save_stack', 1, 0, 'struct _nty_coroutine*'); nty_coroutine.c:55 _save_stack() SQL: insert into parameter_name values(0x7feb7cc204ad2699, '_save_stack', 1, 0, 'co');

Excelent. That's working then.

WLOG="smatch_warns.txt"
find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > $WLOG
find -name \*.c.smatch.sql -exec cat \{\} \; -exec rm \{\} \; > $WLOG.sql find -name \*.c.smatch.caller_info -exec cat \{\} \; -exec rm \{\} \; > $WLOG.caller_info

Then you can do:
smatch_data/db/create_db.sh -p=kernel smatch_warns.txt

That will build the db.

Then rerun, keeping the --file-output but without the --info.

regards,
dan carpenter

author
#19 lore raw

It's working !
Though the output does't change, but for each .c file, it create a .smatch file, which show me the warn and error. Can you explain the WLOG command for me?
Other than that, for other similar C projects, do I need to go through the above steps as well?

regards,
Lishu Chang

Quoted 33 lines · Dan Carpenter
Quoted 8 lines · 李书畅

As I tried :
CHECK="/home/lsc20011130/smatch/smatch --info --file-output",
for each .c file, the above three file are created , and there's a lot of information in these files, like:

nty_schedule.c:98 nty_schedule_sched_sleepdown() info: param_mapper 0 => _nty_coroutine_rbtree_sleep_RB_INSERT 1 nty_schedule.c:113 nty_schedule_desched_sleepdown() info: param_mapper 0 => _nty_coroutine_rbtree_sleep_RB_REMOVE 1 nty_schedule.c:144 nty_schedule_desched_wait() error: we previously assumed 'co' could be null (see line 141)

Quoted 7 lines

nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 0, -1, '%call_marker%', 'void(*)(char*, char*, uint, char*)'); nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 1001, 0, '$', '8349466724068225024'); nty_coroutine.c:58 _save_stack() SQL_caller_info: insert into caller_info values (0x7feb7cc204ad2699, '_save_stack', '__assert_fail', %CALL_ID%, 0, 1001, 1, '$', '5566788581620412416');

nty_coroutine.c:55 _save_stack() SQL: insert into function_type values(0x7feb7cc204ad2699, '_save_stack', 1, 0, 'struct _nty_coroutine*'); nty_coroutine.c:55 _save_stack() SQL: insert into parameter_name values(0x7feb7cc204ad2699, '_save_stack', 1, 0, 'co');

Excelent. That's working then.

WLOG="smatch_warns.txt"
find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > $WLOG
find -name \*.c.smatch.sql -exec cat \{\} \; -exec rm \{\} \; > $WLOG.sql find -name \*.c.smatch.caller_info -exec cat \{\} \; -exec rm \{\} \; > $WLOG.caller_info

Then you can do:
smatch_data/db/create_db.sh -p=kernel smatch_warns.txt

That will build the db.

Then rerun, keeping the --file-output but without the --info.

regards,
dan carpenter

#20 lore raw
Quoted 3 lines · 李书畅

It's working !
Though the output does't change, but for each .c file, it create a .smatch file, which show me the warn and error. Can you explain the WLOG command for me?

It's a shell variable I copied and pasted from smatch_scripts/test_kernel.sh

Quoted 1 line

Other than that, for other similar C projects, do I need to go through the above steps as well?

The unfortunate thing is that there doesn't seem to be any standard way of building code... I wish we could just swap out /usr/bin/gcc for the cgcc script but gcc is used as a linker and all sorts of other stuff besides just being a C compiler so it's a bit complicated.

regards,
dan carpenter

author
#21 lore raw

I see.
And in this case, if I just want to check a single .c file other than the whole directory after building the database , what should I do ?

regards,
Lishu Chang

Quoted 16 lines · Dan Carpenter
Quoted 3 lines · 李书畅

It's working !
Though the output does't change, but for each .c file, it create a .smatch file, which show me the warn and error. Can you explain the WLOG command for me?

It's a shell variable I copied and pasted from smatch_scripts/test_kernel.sh

Quoted 1 line

Other than that, for other similar C projects, do I need to go through the above steps as well?

The unfortunate thing is that there doesn't seem to be any standard way of building code... I wish we could just swap out /usr/bin/gcc for the cgcc script but gcc is used as a linker and all sorts of other stuff besides just being a C compiler so it's a bit complicated.

regards,
dan carpenter

#22 lore raw
Quoted 3 lines · 李书畅

I see.
And in this case, if I just want to check a single .c file other than the whole directory after building the database , what should I do ?

It's going to depend on the build system. But normally:

rm path/to/file.o
make CHECK="/path/to/smatch --file-output" path/to/file.o cat path/to/file.c.smatch

regards,
dan carpenter

author
#23 lore raw
In reply to Dan Carpenter

Hello Dan, this time I tried to use smatch in nginx-1.25.4, as the configure file is in the /nginx-1.25.4, I ran ./configure first. The Makefile's content in the /nginx-1.25.4 is as follows:

default: build

clean:
rm -rf Makefile objs

.PHONY: default clean

build:

	$(MAKE) -f objs/Makefile

install:

	$(MAKE) -f objs/Makefile install

modules:

	$(MAKE) -f objs/Makefile modules

upgrade:
/usr/local/nginx/sbin/nginx -t

kill -USR2 cat /usr/local/nginx/logs/nginx.pid sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin

kill -QUIT cat /usr/local/nginx/logs/nginx.pid.oldbin

.PHONY: build install modules upgrade

It's a recursive makefile, so I tried :
make CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/CTestProj/nginx-1.25.4/objs --file-output" CC="/home/lsc20011130/smatch/cgcc"" but it doesn't work, the terminal just show me the right-pointing arrow, i think it's because it can't find the CC. Then, I just cd to the subdirectory /objs, tried to run make here. But it failed with:
make: *** No rule to make target 'src/core/nginx.h', needed by 'objs/src/core/nginx.o'. Stop.It
What should I do in this situation?

regards,
Lishu Chang

Quoted 19 lines

-----原始邮件-----
发件人: "Dan Carpenter" <[email protected]>
发送时间: 2024-03-11 13:00:42 (星期一)
收件人: "李书畅" <[email protected]>
抄送: [email protected]
主题: Re: Re: Re: Re: Re: Re: about using smatch in all debian C code

Quoted 3 lines · 李书畅

I figure it out, I tried
CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/NtyCo/core" CC=/home/lsc20011130/smatch/cgcc make , and it works fine.

I don't think you want to add the "/home/lsc20011130/NtyCo/core" part...

But I'm happy that it's working. Don't hesitate to ask if you run into more issues.

regards,
dan carpenter

#24 lore raw
Quoted 7 lines · 李书畅

It's a recursive makefile, so I tried :
make CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/CTestProj/nginx-1.25.4/objs --file-output" CC="/home/lsc20011130/smatch/cgcc"" but it doesn't work, the terminal just show me the right-pointing arrow, i think it's because it can't find the CC. Then, I just cd to the subdirectory /objs, tried to run make here. But it failed with:
make: *** No rule to make target 'src/core/nginx.h', needed by 'objs/src/core/nginx.o'. Stop.It
What should I do in this situation?

It's building for me:

sudo apt-get build-dep nginx
git clone https://github.com/nginx/nginx
cd nginx
./auto/configure --with-cc=~/smatch/cgcc
export CHECK="~/progs/smatch/devel/smatch --full-path --file-output" make -j8
find -name \*.c.smatch -exec cat \{\} \; > smatch_warns.txt

regards,
dan carpenter

#25 lore raw
Quoted 9 lines · Dan Carpenter
Quoted 7 lines · 李书畅

It's a recursive makefile, so I tried :
make CHECK="/home/lsc20011130/smatch/smatch /home/lsc20011130/CTestProj/nginx-1.25.4/objs --file-output" CC="/home/lsc20011130/smatch/cgcc"" but it doesn't work, the terminal just show me the right-pointing arrow, i think it's because it can't find the CC. Then, I just cd to the subdirectory /objs, tried to run make here. But it failed with:
make: *** No rule to make target 'src/core/nginx.h', needed by 'objs/src/core/nginx.o'. Stop.It
What should I do in this situation?

Quoted 6 lines

It's building for me:

sudo apt-get build-dep nginx
git clone https://github.com/nginx/nginx
cd nginx
./auto/configure --with-cc=~/smatch/cgcc

                             ^^^^^^^^^^^^^
Quoted 1 line

export CHECK="~/progs/smatch/devel/smatch --full-path --file-output"

                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Heh. I leaked where I really keep my programming work. :P These paths would need to be updated to match your system, of course.

regards,
dan carpenter