Abstract
The C language definition leaves the sizes and layouts of types partially unspecified. When a C program makes assumptions about type layout, its semantics is defined only on platforms (C compilers and the underlying hardware) on which those assumptions hold. Previous work on formalizing C-like languages has ignored this issue, either by assuming that programs do not make such assumptions or by assuming that all valid programs target only one platform. In the latter case, the platform's choices are hard-wired in the language semantics.
In this paper, we present a practically-motivated model for a C-like language in which the memory layouts of types are left largely unspecified. The dynamic semantics is parameterized by a platform's layout policy and makes manifest the consequence of platform-dependent (i.e., unspecified) steps. A type-and-effect system produces a layout constraint: a logic formula encoding layout conditions under which the program is memory-safe. We prove that if a program type-checks, it is memory-safe on all platforms satisfying its constraint.
Based on our theory, we have implemented a tool that discovers unportable layout assumptions in C programs. Our approach should generalize to other kinds of platform-dependent assumptions.
- Amal Ahmed and David Walker. The logical approach to stack typing. In International Workshop on Types in Language Design and Implementation, 2003. Google Scholar
Digital Library
- Aleph One Limited. The ARMLinux Book Online, Chapter 10. 2005. http://www.aleph1.co.uk/armlinux/book.Google Scholar
- Robert M. Amadio and Luca Cardelli. Subtyping recursive types. ACM Transactions on Programming Languages and Systems, 15 (4), 1993. Google Scholar
Digital Library
- David F. Bacon. Kava: a Java dialect with a uniform object model for lightweight classes. Concurrency and Computation: Practice and Experience, 15 (3--5), 2003.Google Scholar
Cross Ref
- Sandrine Blazy, Zaynah Dargaye, and Xavier Leroy. Formal verification of a C compiler front-end. In 14th International Symposium on Formal Methods, 2006. Google Scholar
Digital Library
- C Standard 1999. ISO/IEC 9899:1999, International Standard-Programming Languages-C. International Standards Organization, 1999.Google Scholar
- Satish Chandra and Tom Reps. Physical type checking for C. In Workshop on Program Analysis for Software Tools and Engineering, 1999. Google Scholar
Digital Library
- Juan Chen, Dinghao Wu, Andrew W. Appel, and Hai Fang. A provably sound TAL for back-end optimization. In ACM Conference on Programming Language Design and Implementation, 2003. Google Scholar
Digital Library
- Jeremy Condit, Matthew Harren, Scott McPeak, George Necula, and Westley Weimer. CCured in the real world. In ACM Conference on Programming Language Design and Implementation, 2003. Google Scholar
Digital Library
- Jeremy Condit, Matthew Harren, Zachary Anderson, David Gay, and George Necula. Dependent types for low-level programming. In European Symposium on Programming, 2007. Google Scholar
Digital Library
- Karl Crary. Toward a foundational typed assembly language. In 30th ACM Symposium on Principles of Programming Languages, 2003. Google Scholar
Digital Library
- Dinakar Dhurjati, Sumant Kowshik, and Vikram Adve. SAFECode: Enforcing alias analysis for weakly typed languages. In ACM Conference on Programming Language Design and Implementation, 2006. Google Scholar
Digital Library
- Dan Grossman. Type-safe multithreading in Cyclone. In International Workshop on Types in Language Design and Implementation, 2003. Google Scholar
Digital Library
- Dan Grossman. Quantified types in imperative languages. ACM Transactions on Programming Languages and Systems, 28 (3), 2006. Google Scholar
Digital Library
- Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. Region-based memory management in Cyclone. In ACM Conference on Programming Language Design and Implementation, 2002. Google Scholar
Digital Library
- Thomas Hallgren, Mark P. Jones, Rebekah Leslie, and Andrew Tolmach. A principled approach to operating system construction in Haskell. In 10th ACM International Conference on Functional Programming, 2005. Google Scholar
Digital Library
- Nadeem A. Hamid, Zhong Shao, Valery Trifonov, Stefan Monnier, and Zhaozhong Ni. A syntactic approach to foundational proof-carrying code. Journal of Automated Reasoning, 31 (3--4), 2003. Google Scholar
Digital Library
- IBM. Developing embedded software for the IBM PowerPC 970FX processor. Application Note 970, IBM, 2004. http://www.ibm.com/chips/techlib/.Google Scholar
- Trevor Jim, Greg Morrisett, Dan Grossman, Michael Hicks, James Cheney, and Yanling Wang. Cyclone: A safe dialect of C. In USENIX Annual Technical Conference, 2002. Google Scholar
Digital Library
- Xavier Leroy. Formal certification of a compiler back-end. In 33rd ACM Symposium on Principles of Programming Languages, 2006. Google Scholar
Digital Library
- Robert Love. Linux Kernel Development, Second Edition. Novell Press, 2005. Page 328. Google Scholar
Digital Library
- Brad Martin, Anita Rettinger, and Jasmit Singh. Multiplatform porting to 64 bits. Dr. Dobb's Journal, 2005.Google Scholar
- Antoine Mine. Field-sensitive value analysis of embedded c programs with union types and pointer arithmetics. In Conference on Language, Compilers, and Tool Support for Embedded Systems, 2006. Google Scholar
Digital Library
- Greg Morrisett, David Walker, Karl Crary, and Neal Glew. From System F to typed assembly language. ACM Transactions on Programming Languages and Systems, 21 (3), 1999. Google Scholar
Digital Library
- George Necula. Proof-carrying code. In 24th ACM Symposium on Principles of Programming Languages, 1997. Google Scholar
Digital Library
- George Necula, Scott McPeak, Shree Prakash Rahul, and Westley Weimer. CIL: Intermediate language and tools for analysis and transformation of C programs. In Conference on Compiler Construction, 2002. Google Scholar
Digital Library
- George Necula, Scott McPeak, and Westley Weimer. CCured: Type-safe retrofitting of legacy code. In 29th ACM Symposium on Principles of Programming Languages, 2002. Google Scholar
Digital Library
- George Necula, Jeremy Condit, Matthew Harren, Scott McPeak, and Westley Weimer. CCured: Type-safe retrofitting of legacy software. ACM Transactions on Programming Languages and Systems, 27 (3), 2005. Google Scholar
Digital Library
- Marius Nita, Dan Grossman, and Craig Chambers. A theory of platform-dependent low-level software (extended version). 2007. Available at http://www.cs.washington.edu/homes/marius/papers/tpd/.Google Scholar
- Michael Norrish. C formalised in HOL. PhD thesis, University of Cambridge, 1998.Google Scholar
- Leaf Petersen, Robert Harper, Karl Crary, and Frank Pfenning. A type theory for memory allocation and data layout. In 30th ACM Symposium on Principles of Programming Languages, 2003. Google Scholar
Digital Library
- Norman Ramsey, Simon~Peyton Jones, and Christian Lindig. The C-language specification version 2.0, 2005. http://www.cminusminus.org/extern/man2.pdf.Google Scholar
- Micahel Siff, Satish Chandra, Thomas Ball, Krishna Kunchithapadam, and Thomas Reps. Coping with type casts in C. In 7th European Software Engineering Conference 7th ACM Symposium on the Foundations of Software Engineering, 1999. Google Scholar
Digital Library
- Robert P. Wilson and Monica S. Lam. Efficient context-sensitive pointer analysis for C programs. In ACM Conference on Programming Language Design and Implementation, 1995. Google Scholar
Digital Library
Index Terms
A theory of platform-dependent low-level software
Recommendations
A theory of platform-dependent low-level software
POPL '08: Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languagesThe C language definition leaves the sizes and layouts of types partially unspecified. When a C program makes assumptions about type layout, its semantics is defined only on platforms (C compilers and the underlying hardware) on which those assumptions ...
Bypassing portability pitfalls of high-level low-level programming
VMIL '12: Proceedings of the sixth ACM workshop on Virtual machines and intermediate languagesProgram portability is an important software engineering consideration. However, when high-level languages are extended to effectively implement system projects for software engineering gain and safety, portability is compromised--high-level code for ...
Blame for all
POPL '11: Proceedings of the 38th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languagesSeveral programming languages are beginning to integrate static and dynamic typing, including Racket (formerly PLT Scheme), Perl 6, and C# 4.0 and the research languages Sage (Gronski, Knowles, Tomb, Freund, and Flanagan, 2006) and Thorn (Wrigstad, ...







Comments