Overview
CMod is a tool written to enforce a modular programming style in C code, to ensure that modules, when linked together, yield a type correct program.
C syntax does not provide direct support for modules. But over time, programmers have developed a discipline of modular programming which treats .c files as module implementations and .h files as interfaces.
However, without proper enforcement (of the requirements of a module system), mistakes can be made which will not be reported by a normal C compiler. In particular, one module can declare that it requires some symbol of type T1, but in the module defining the symbol it actually has type T2. This problem is compounded
and obfuscated by the extensive use of preprocessor directives which is common
in large C programs. These mistakes can lead to confusing errors that manifest themselves at runtime and are hard to track down.
The reason this problem exists in C is because the language has only an
informal notion of an external interface: the .h file.
CMod provides a way to treat .h as more formal interfaces.
In particular,
it enforces three rules as to how .h files should and should not be
used; if the rules are followed, checked by CMod at compile-time and link-time,
then the final program is likely to be type correct.
In addition to this benefit, it is widely recognized that modular code is easier to maintain, easier to extend and more readable.
Documentation
CMod is designed to be non-intrusive. To get CMod to check code that you develop, simply change your search path to include the CMod wrappers before your actual compiler and linker. The CMod wrappers will do the consistency check before passing your code onto the linker(compiler).
If inconsistencies are found, warnings will be dumped to stdout and detailed diagnostic data will be stored in log files.
Usage Manual:
- Manual: Contains an overview of the
CMod approach to software robustness and it design. It also contains
instructions for compiling and running CMod and interpreting the
reports
generated by CMod. A case study over vsftpd is also presented.
Papers:
- "Modular Information Hiding and Type Safety for C." Saurabh
Srivastava, Michael Hicks, and Jeffrey S. Foster. In Proceedings of the
ACM Workshop on Types in Language Design and Implementation (TLDI),
January 2007. .pdf
abstract/bibtex
- "Modular Information Hiding and Type Safe Linking for C." Saurabh Srivastava, Michael Hicks, Jeffrey S. Foster, and Patrick Jenkins. Submitted to IEEE Transactions on Software Engineering. Full version of TLDI 07 paper. .pdf abstract/bibtex
Detailed Technical Reports:
- "Appendix to CMod: Modular Information Hiding and Type-Safe Linking for C," Saurabh Srivastava, Michael Hicks and Jeffrey S. Foster. Technical Report CS-4874, Department of Computer Science, University of Maryland, June 2007. .pdf
abstract/bibtex
- "Defining and Enforcing C's Module System," Saurabh Srivastava,
Michael Hicks, Jeffrey S. Foster, and Bhargav Kanagal. Technical
Report CS-4816, Department of Computer Science, University of Maryland,
July 2006. .pdf
abstract/bibtex
Source Code
CMod is Open Source / Free Software, and is freely available under the GNU General Public License. It is mostly written in OCaml and interfaces with cpplib (provided by GNU gcc) for preprocessing needs.
Building and Using CMod: For the most up to date instructions
consult the manual.pdf
Download the sources below. Extract and cd into src/ directory. Run make to build the tool. The binaries are installed in the bin/ directory.
CMod requires a compiler that supports separate compilation and linking (e.g. gcc, gcc -c and gcc -o). If the project being checked for consistency requires any other standard tools for successful compilation then they should be available and in the path as well; e.g. gmake, ar etc.
A good codebase to get you started on seeing how the tool runs is vsftpd. Detailed instructions on how to incorporate CMod into the build process and on how to interpret the log files are provided in the README in the distribution.
Builds
CMod is under heavy development.
The builds are numbered as v#.#-b#### where #.# is the version and #### is the subversion revision number for that build.
Bug Reports
Highly appreciated. Direct all bug reports to
.
People
CMod is being developed at the University of Maryland's PL group by: