What is the easiest way to check just one *.c file from Linux kernel using pvs-studio? - pvs-studio

What is the easiest way to check just one *.c file from Linux kernel using pvs-studio?
Kernel is a huge project, maybe there is a way to avoid compilation of all files.

If you have compilation parameters of the file in question, you could directly launch the analyzer on this file. Here is an example, and although it's for Windows version (i.e. PVS-Studio.exe), you could do the same under Linux, just replace 'PVS-Studio.exe' with 'PVS-Studio'.

Related

building boost with emscripten on windows

I am trying to build boost using emscripten on windows. In particular, I am trying to use the emscripten toolset as suggested in https://stackoverflow.com/a/47751199/5969590. However, this produces the following error for me:
C:\dev\emsdk\python\3.9.2-1_64bit\python.exe: can't open file 'c:\dev\boost_1_76_0\emcc.py': [Errno 2] No such file or directory
Somewhere in the toolchain boost tries to invoke emcc.py using python, but fails by passing the wrong module path (there is no emcc.py in c:\dev\boost_1_76_0\).
I made sure path environment variables are setup correctly by executing emsdk_env.bat. Running emcc.bat (which internally runs emcc.py) manually, executes the compiler as expected.
I inserted some debug printouts in emcc.bat and from that I gather that the boost toolchain is not using that file. It seems it tries to use python and emcc.py directly. This seems to be where things break down.
Any help or hint is greatly appreciated.
Best,
David
Problem was related to this: What is the reason for batch file path referenced with %~dp0 sometimes changes on changing directory?
I solved the problem by hacking emcc.bat to use hardcoded path to the emcc.py file.

Compiling and embedding lua into a C++ application

For portability reasons, I'd like to compile lua from source when I compile my C++ code. I use lua to read input file.
If I understand correctly, lua's readme mentions that it's possible to do that through src/Makefile. I can't really read it that well. Has anyone figured out how to do it?
is it possible to have it in one command? gcc ....
bonus: how to put it in cmake ?
Lua has a makefile that needs your target platform to build to so you will need to specify make [target platform].
But that is right in the beginning of the readme.
You could try to call the make command from inside your build process.
Cheers
[UPDATE based on the comments]
If you use:
make a PLAT=[target platform]
on the command line in the src directory it will only build the liblua.a library for the target platform then you will just need to copy that file to wherever you need and link against it.

how to recompile the kernel after modifying Read_write.c file on linux-3.6.6

I have compiled my kernel(linux-3.6.6) with success in the debian linux version(12.04).(LinuxPraxis ->is the name of my new version) then I made some modification on Read_write.c file ("I mind I write there some printk to get a message when a named pipe is writting and when it is reading").
Now I hear that I need to recompile my new version. please help me to understand it.
Shall I need to recompile my kernel completely or it is another way to recompile a kernel?
Use "make -j5" to rebuild your kernel image file for host system with 4 cores.
Then run "make install -j5" to install kernel image file.
The "make install" will compress your kernel image file, copy kernel image to /boot and run grub-update to update the grub config file.
If you have already compiled, the Makefile takes care of only recompiling the parts which depend on the changed file(s). There could still be multiple files which depend on it, but the effort should be significantly smaller than the initial compilation nevertheless. You don't have to do anything differently, the compilation works the same; files which already exist on disk which do not depend on the changed file will simply not be recompiled.

Cross-compiling Linux kernel for ARM on Windows using Sourcery Toolchain

I am trying to cross-compile a Linux kernel for an ARM-target (Freescale i.Mx28) on a Windows host. I know that this approach is not the best one compared to using a Linux host, but unfortunately it's not up to me to decide that.
The restrictions are:
The kernel has to be the one provided by Freescale (L2.6.35_MX28_SDK_10.12)
It must be build using Sourcery Toolchain and CodeBench
The whole thing must be done on Windows
I got that far, that I worked around the missing case sensitivity on Windows so that I can extract the kernel sources using Cygwin. But now I got problems with the kernel Makefile. I think there are some issues with the Windows paths as I get the error message *** multiple target patterns. Stop., which comes from the : in paths and other errors concerning the dependency check when configuring:
HOSTCC scripts/basic/fixdep
/usr/bin/sh: scripts/basic/fixdep: cannot execute binary file
make[1]: *** [scripts/basic/fixdep] Error 126
make: *** [scripts_basic] Error 2
Is there a way to port the Makefile without having to rewrite it or is there another way to build the kernel without using the given Makefile? Can I use the sourcery toolchain or IDE to handle the Makefile?
Is there a way to build the kernel within the given restrictions?
To cross compile the kernel, you'll need two compilers: One that is able to build tools that run in your build environment, and one that can create executables for your target.
It seems like you aren't really cross compiling but you have just replaced your compiler. You are now building tools required for the build for ARM and try to run them on Windows.
You can specify which cross compiler to use:
make ARCH=arm CROSS_COMPILE=your-compiler-prefix- ...
You might also have a problem with the filesystem. The filesystem in Windows is case-insensitive and the Kernel build might create files where the case matters. To get support for a case-insensitive filesystem on Windows, you can have a look at Windows Services for UNIX.
Use another toolchain! CodeBench is NOT compatible with building Linux on Windows hosts, not matter what eye candy (lies) they put on their website about using CYGPATH, etc.
I have tried this myself for weeks, and the problem is that CodeBench accepts POSIX paths, but insists outputting Win32 paths that are hard, if not impossible, to control in the Linux Kernel Make procedures.
I'm not saying it is impossible; I'm sure it is possible. But it is not worth the time, no matter what your boss tells you. There are more problems to consider. Another problem is that the tools in the Linux sources ./scripts directory are not directly compatible with the Windows environment and thus, although they might compile they don't run as expected. They need to be patched!
The best chance you have, is by compiling your own cross-compiler with Cygwin. Or find one already cooked for you.

USB GCC Development Environment with Libraries

I'm trying to get something of an environment on a usb stick to develop C++ code in. I plan to use other computers, most of the time linux, to work on this from a command line using g++ and make.
The problem is I need to use some libraries, like Lua and OpenGL, which the computers don't have. I cannot add them to the normal directories, I do not have root on these computers. Most of the solutions I've found involve putting things in /usr/lib/ and the like, but I cannot do that. I've also attempted adding options like '-L/media//lib', which is where they are kept, and it didn't work. When compiling, I get the same errors I got when first switching to an OS with the libraries not installed.
Is there somewhere on the computer outside of /usr/ I can put them, or a way to make gcc 'see' them?
You need more than the libraries to be able to compile code utilizing those libraries. (I'm assuming Linux here, things might be slightly different on e.g. OSX,BSDs,Cygwin,Mingw..)
Libraries
For development you need these 3 things when your code uses a library:
The library header files, .h files
The library development files, libXXX.so or libXXX.a typically
The library runtime files , libXXX.so.Y where Y is a version number. These are not needed if you statically link in the library.
You seem to be missing the header files (?) Add them to your usb stick, say under /media/include
Development
Use (e.g.) the compiler flag -I/media/include when compiling source code to refer to a non-standard location of header files.
Use the compiler/linker flag -L/media/lib to refer to non-standard location of libraries.
You might be missing the first step.
Running
For dynamically linked libraries, the system will load those only from default locations, typically /lib/ , /usr/lib/
Learn the ldd tool to help debug this step.
You need to tell the system where to load additional libraries when you're running a program, here's 3 alternatives:
Systemwide: Edit /etc/ld.so.conf and add /media/libs there. Run ldconfig -a afterwards.
Local, to the current shell only. set the LD_LIBRARY_PATH environment variable to refer to /media/lib, run export LD_LIBRARY_PATH=/media/lib
Executable: Hardcode the non-standard library path in the executable. You add this to the linking step when creating your executable: -Wl,-rpath,/media/lib
Etc.
There could be other reasons things are not working out, if so,
show us the output of ls -l /media/libs , and where you put the library header files, the command line you use to compile/link, and the exact errors you get.
Missing the headers and/or development libraries (for dynamic libraries there is usually a symlink from a libXXX.so to a libXXX.so.Y , the linker needs the libXXX.so , it will not look directly at libXXX.so.Y)
using libraries not compatible with your current OS/architecture. (libraries compiled on one linux distro is often not compatible with another distro, or even another minor version of the same distro)
using an usb stick with a FAT32 filesystem, you'll get in trouble with symlinks..

Resources