Monday, February 25, 2013

static analysis with llvm

Using Scan Build

LLVM comes with a static analyzer - http://clang-analyzer.llvm.org. It works by overriding CC. So, to use it with autoconf'ed project, you need to first run it when running configure and then make. On Ubuntu you can always apt-get it, but if you are interested in building from source then take a look at my other post.
$ scan-build ./configure
$ scan-build make
In some case, esp. if you are building from source, scan-build may not find clang. So you will need to explicitly, pass the path to clang to scan-build. E.g. if clang is installed (via make install) at /proj/staging/llvm, then you will need to pass --use-analyzer to scan-build.

$ scan-build --use-analyzer=/proj/staging/llvm/bin/clang ./configure
$ scan-build --use-analyzer=/proj/staging/llvm/bin/clang make

Integrating Clang Static Analyzer into Makefile.am

Alex has a different approach to running scan build. In this post, he shows how to include a step to run the analyzer in every build. This is really neat because there is no change to your standard build flow. Every time you run make, it automatically calls the analyzer (or not if you don't include the step to all-local).

The flip side is that you need to use clang as the compiler only and not gcc or any other compiler. 

More Details on Clang Static Analyzer

More details on LLVM's static analyzer is available at http://clang-analyzer.llvm.org/scan-build.html.

Example of a Bug that Clang Static Analyzer found

I ran scan-build against wayland source some time back and caught a bug immediately - https://bugs.freedesktop.org/show_bug.cgi?id=61385.

To incorporate Alex's idea, a small patch to src/Makefile.am is required. Just add the following changes to Wayland's src/Makefile.am and then rebuild. Note that you must use clang as the compiler in this case.

+analyzer_srcs =                                      \
+    $(filter %.c, $(libwayland_util_la_SOURCES))     \
+    $(filter %.c, $(libwayland_server_la_SOURCES))   \
+    $(filter %.c, $(libwayland_client_la_SOURCES))
+
+analyzer_plists = $(analyzer_srcs:%.c=%.plist)
+
+$(analyzer_plists): %.plist: %.c
+       @echo "  CCSA  " $@
+       @$(COMPILE) --analyze $< -o $@
+
+all-local: $(analyzer_plists)
+
+MOSTLYCLEANFILES = $(analyzer_plists)

Sunday, February 24, 2013

Linux News - Feb 24, 2013


1 Sony

  • Gamers rejoice - PS4 announced (shipping end of 2013) - http://www.wired.com/gamelife/2013/02/sony-liveblog/. Moving away from PS3's Cell Architecture (PowerPC) to a PC Architecture (AMD X86-64) with 8 GB RAM. GPU is AMD Radeon based which they claim can hit 1.84 Terflops. So, PS4 won't run PS3 Games I guess.

2 Linux

3 Minix

4 NetBSD

5 Voyager

Sunday, February 17, 2013

Installing Freebsd 9.1 on an USB Stick

If you want to evaluate Freebsd, then the quickest way to do that is by trying it out on with USB stick. However the download page does not have USB images and instead there is an ISO file to burn on a CD.

Here are my instructions for installing Freebsd on an USB memory stick. Tried and tested on Freebsd 9.1.

1. Download and install mfsbsd from http://bit.ly/1d4VpA2. Pick the usb image and flash to the USB stick that you want to use.
2. To flash the image on MacOS, run diskutil list to find the drive. Then run diskutil umountDisk diskX to umount all partitions on it. Finally run dd if=mfsbsd-9.1-RELEASE-i386.img of=/dev/rdiskX bs=4m to write the image to the USB Stick.
3. Reboot and boot from the USB Stick. This will drop you into the mfsbsd prompt. Goto /dev and see what daX devices are present. Use fdisk to figure out which one maps to your USB drive.
4. Now run bsdinstall from /usr/sbin. When choosing the location to install, pick the same daX device that maps to the USB Stick.
5. ????
6. Profit.

Linux News - Feb 17, 2013


1 Linux

1.1 Releases
1.2 Unix History
  • http://www.levenez.com/unix/ has a great view of how Unix has evolved from UNICS in 1969. QNX afficianados will appreciate how QNX started as QUNIX in 1980 and hit Beta in 1983. In comparision, the first Android Beta was in 2007 as a fork from 2.6.23. So, why is it important to look at Unix History? That's because most of the code in Linux is long-lived and the linux community takes backward compatibility very seriously!
  • There is a simplified version on Wikipedia - http://en.wikipedia.org/wiki/File:Unix_history-simple.png.  
2 QA and Testing

2.1 Trinity Fuzz Tester
2.2 QA on Ubuntu
2.3 Static Checker for Linux Kernel
2.4 SystemTap
2.5 UMockdev
3 Virtualization

3.1 Qemu
  • Qemu 1.4.0 released. Claims that a guest os can perform at 95% of native performance.
4 Driverless Car