Certifying and Reasoning on Cost Annotations in C Programs

  • Nicolas Ayache
  • Roberto M. Amadio
  • Yann Régis-Gianas
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7437)


We present a so-called labelling method to enrich a compiler in order to turn it into a “cost annotating compiler”, that is, a compiler which can lift pieces of information on the execution cost of the object code as cost annotations on the source code. These cost annotations characterize the execution costs of code fragments of constant complexity. The first contribution of this paper is a proof methodology that extends standard simulation proofs of compiler correctness to ensure that the cost annotations on the source code are sound and precise with respect to an execution cost model of the object code.

As a second contribution, we demonstrate that our label-based instrumentation is scalable because it consists in a modular extension of the compilation chain. To that end, we report our successful experience in implementing and testing the labelling approach on top of a prototype compiler written in ocaml for (a large fragment of) the C language.

As a third and last contribution, we provide evidence for the usability of the generated cost annotations as a mean to reason on the concrete complexity of programs written in C. For this purpose, we present a Frama-C plugin that uses our cost annotating compiler to automatically infer trustworthy logic assertions about the concrete worst case execution cost of programs written in a fragment of the C language. These logic assertions are synthetic in the sense that they characterize the cost of executing the entire program, not only constant-time fragments. (These bounds may depend on the size of the input data.) We report our experimentations on some C programs, especially programs generated by a compiler for the synchronous programming language Lustre used in critical embedded software.


Block Cipher Label Transition System Source Language Source Program Execution Cost 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Amadio, R.M., Ayache, N., Memarian, K., Saillard, R., Régis-Gianas, Y.: Compiler Design and Intermediate Languages. Deliverable 2.1 of [4]Google Scholar
  2. 2.
    Ayache, N., Amadio, R.M., Régis-Gianas, Y.: Certifying and reasoning on cost annotations of C programs. Research Report 00702665 (June 2012)Google Scholar
  3. 3.
    Amadio, R.M., Régis-Gianas, Y.: Certifying and Reasoning on Cost Annotations of Functional Programs. In: Peña, R., van Eekelen, M., Shkaravska, O. (eds.) FOPARA 2011. LNCS, vol. 7177, pp. 72–89. Springer, Heidelberg (2012)Google Scholar
  4. 4.
    Certified complexity (Project description). ICT-2007.8.0 FET Open, Grant 243881Google Scholar
  5. 5.
    Correnson, L., Cuoq, P., Kirchner, F., Prevosto, V., Puccetti, A., Signoles, J., Yakobowski, B.: Frama-C user manual. CEA-LIST, Software Safety Laboratory, Saclay, F-91191,
  6. 6.
    Cousot, P., Cousot, R.: Abstract Interpretation Frameworks. Jou. of Logic and Computation 2(4), 511–547 (1992)MathSciNetzbMATHCrossRefGoogle Scholar
  7. 7.
    Ferdinand, C., Heckmann, R., Le Sergent, T., Lopes, D., Martin, B., Fornari, X., Martin, F.: Combining a high-level design tool for safety-critical systems with a tool for WCET analysis of executables. In: Embedded Real Time Software (2008)Google Scholar
  8. 8.
    Fornari, X.: Understanding how SCADE suite KCG generates safe C code. White paper, Esterel Technologies (2010)Google Scholar
  9. 9.
    Larus, J.: Assemblers, linkers, and the SPIM simulator. Appendix of Computer Organization and Design: the hw/sw interface. Hennessy and Patterson (2005)Google Scholar
  10. 10.
    MCS 51 Microcontroller Family User’s Manual. Publication number 121517. Intel Corporation (1994)Google Scholar
  11. 11.
    Leroy, X.: Formal verification of a realistic compiler. Commun. ACM 52(7), 107–115 (2009)CrossRefGoogle Scholar
  12. 12.
    Leroy, X.: Mechanized semantics, with applications to program proof and compiler verification. In: Marktoberdorf Summer School (2009)Google Scholar
  13. 13.
    Necula, G., McPeak, S., Rahul, S.P., Weimer, W.: CIL: Intermediate Language and Tools for Analysis and Transformation of C Programs. In: Horspool, R.N. (ed.) CC 2002. LNCS, vol. 2304, pp. 213–228. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  14. 14.
    Wilhelm, R., et al.: The worst-case execution-time problem - overview of methods and survey of tools. ACM Trans. Embedded Comput. Syst. 7(3) (2008)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Nicolas Ayache
    • 1
    • 2
  • Roberto M. Amadio
    • 1
  • Yann Régis-Gianas
    • 1
    • 2
  1. 1.Université Paris Diderot (UMR-CNRS 7126)France
  2. 2.INRIAFrance

Personalised recommendations