skip to main content
research-article
Open access

LOCKSMITH: Practical static race detection for C

Published: 25 January 2011 Publication History

Abstract

Locksmith is a static analysis tool for automatically detecting data races in C programs. In this article, we describe each of Locksmith's component analyses precisely, and present systematic measurements that isolate interesting trade-offs between precision and efficiency in each analysis. Using a benchmark suite comprising stand-alone applications and Linux device drivers totaling more than 200,000 lines of code, we found that a simple no-worklist strategy yielded the most efficient interprocedural dataflow analysis; that our sharing analysis was able to determine that most locations are thread-local, and therefore need not be protected by locks; that modeling C structs and void pointers precisely is key to both precision and efficiency; and that context sensitivity yields a much more precise analysis, though with decreased scalability. Put together, our results illuminate some of the key engineering challenges in building Locksmith and data race detection analyses in particular, and constraint-based program analyses in general.

References

[1]
Agarwal, R., Sasturkar, A., Wang, L., and Stoller, S. D. 2005. Optimized run-time race detection and atomicity checking using partial discovered types. In Proceedings of the 20th IEEE/ACM International Conference on Automated Software Engineering ASE'05. ACM Press, New York, NY, 233--242.
[2]
Agarwal, R. and Stoller, S. D. 2004. Type inference for parameterized race-free java. In Proceedings of the 5th International Conference on Verification, Model Checking and Abstract Interpretation. Lecture Notes in Computer Science, vol. 2937. Springer-Verlag, 149--160.
[3]
Aho, A. V. and Ullman, J. D. 1977. Principles of Compiler Design (Addison-Wesley Series in Computer Science and Information Processing). Addison-Wesley Longman Publishing Co., Inc., Boston, MA.
[4]
Aiken, A., Foster, J. S., Kodumal, J., and Terauchi, T. 2003. Checking and inferring local non-aliasing. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'03). ACM Press, New York, NY, 129--140.
[5]
Alexandrescu, A., Boehm, H., Henney, K., Hutchings, B., Lea, D., and Pugh, B. 2005. Memory model for multithreaded c++: Issues. http://en.scientificcommons.org/42366732.
[6]
Boyapati, C. and Rinard, M. 2001. A parameterized type system for race-free java programs. In Proceedings of the 16th ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages, and Applications. (OOPSLA'01). ACM Press, New York, NY, 56--69.
[7]
Choi, J.-D., Lee, K., Loginov, A., O'Callahan, R., Sarkar, V., and Sridharan, M. 2002. Efficient and precise datarace detection for multithreaded object-oriented programs. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'02). ACM Press, New York, NY, 258--269.
[8]
Cooper, K. D., Harvey, T. J., and Kennedy, K. 2004. Iterative data-flow analysis, revisited. Tech. rep. TR04-100, Department of Computer Science, Rice University.
[9]
Crary, K., Walker, D., and Morrisett, G. 1999. Typed memory management in a calculus of capabilities. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. (POPL'99). ACM Press, New York, NY, 262--275.
[10]
Engler, D. and Ashcraft, K. 2003. Racerx: effective, static detection of race conditions and deadlocks. In Proceedings of the 19th ACM Symposium on Operating Systems Principles (SOSP'03). ACM Press, New York, NY, 237--252.
[11]
Fahndrich, M. and DeLine, R. 2002. Adoption and focus: practical linear types for imperative programming. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'02). ACM Press, New York, NY, 13--24.
[12]
Fähndrich, M., Rehof, J., and Das, M. 2000. Scalable context-sensitive flow analysis using instantiation constraints. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'00). ACM, New York, NY, 253--263.
[13]
Flanagan, C. and Abadi, M. 1999. Types for safe locking. In Proceedings of the 8th European Symposium on Programming Languages and Systems (ESOP'99). Springer-Verlag, 91--108.
[14]
Flanagan, C. and Freund, S. N. 2000. Type-based race detection for java. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'00). ACM Press, New York, NY, 219--232.
[15]
Flanagan, C. and Freund, S. N. 2001. Detecting race conditions in large programs. In Proceedings of the ACM SIGPLAN-SIGSOFT Workshop on Program Analysis for Software Tools and Engineering (PASTE'01). ACM Press, New York, NY, 90--96.
[16]
Flanagan, C. and Freund, S. N. 2004. Atomizer: a dynamic atomicity checker for multithreaded programs. In Proceedings of the 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'04). ACM Press, New York, NY, 256--267.
[17]
Flanagan, C. and Freund, S. N. 2007. Type inference against races. Sci. Comput. Program. 64, 1, 140--165.
[18]
Flanagan, C., Freund, S. N., and Lifshin, M. 2005. Type inference for atomicity. In Proceedings of the ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI'05). ACM Press, New York, NY, 47--58.
[19]
Flanagan, C., Leino, K. R. M., Lillibridge, M., Nelson, G., Saxe, J. B., and Stata, R. 2002. Extended static checking for java. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'02). ACM Press, New York, NY, 234--245.
[20]
Flanagan, C. and Qadeer, S. 2003. A type and effect system for atomicity. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'03). ACM Press, New York, NY, 338--349.
[21]
Foster, J. S., Johnson, R., Kodumal, J., and Aiken, A. 2006. Flow-insensitive type qualifiers. ACM Trans. Program. Lang. Syst. 28, 6, 1035--1087.
[22]
Foster, J. S., Terauchi, T., and Aiken, A. 2002. Flow-sensitive type qualifiers. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'02). ACM Press, New York, NY, 1--12.
[23]
Grossman, D. 2003. Type-safe multithreading in cyclone. In Proceedings of the ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI'03). ACM Press, New York, NY, 13--25.
[24]
Heintze, N. and Tardieu, O. 2001. Ultra-fast aliasing analysis using cla: a million lines of c code in a second. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'01). ACM, New York, NY, 254--263.
[25]
Henglein, F. 1993. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst. 15, 2, 253--289.
[26]
Henglein, F., Makholm, H., and Niss, H. 2001. A direct approach to control-flow sensitive region-based memory management. In Proceedings of the 3rd ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP'01). ACM Press, New York, NY, 175--186.
[27]
Henzinger, T. A., Jhala, R., and Majumdar, R. 2004. Race checking by context inference. SIGPLAN No. 39, 6, 1--13.
[28]
Hote, C. 2004. Runtime error detection through semantic analysis. http//nesl.ee.ucla.edu/courses/ee202a/2005f/papers/Semantic_Analysis.pdf.
[29]
Intel. 2007. Teraflops research chip. http//techresearch.intel.com/ProjectDetails.aspx?Id=151.
[30]
Johnson, R. and Wagner, D. 2004. Finding user/kernel pointer bugs with type inference. In Proceedings of the 13th Conference on USENIX Security Symposium (SSYM'04). USENIX Association, Berkeley, CA, 9--9.
[31]
Kodumal, J. and Aiken, A. 2004. The set constraint/cfl reachability connection in practice. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'04). ACM, New York, NY, 207--218.
[32]
Kodumal, J. and Aiken, A. 2005. Banshee: A scalable constraint-based analysis toolkit. In Proceedings of the 12th International Static Analaysis Symposium. C. Hankin and I. Siveroni, Eds. Lecture Notes in Computer Science, vol. 3672. Springer, 218--234.
[33]
Lamport, L. 1978. Time, clocks, and the ordering of events in a distributed system. Comm. ACM 21, 7, 558--565.
[34]
Leveson, N. G. and Turner, C. S. 1993. An investigation of the therac-25 accidents. Computer 26, 7, 18--41.
[35]
Manson, J., Pugh, W., and Adve, S. V. 2005. The java memory model. In Proceedings of the 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'05). ACM Press, New York, NY, 378--391.
[36]
Mossin, C. 1996. Flow Analysis of Typed Higher-Order Programs. Ph.D. thesis, DIKU, Department of Computer Science, University of Copenhagen.
[37]
Naik, M. and Aiken, A. 2007. Conditional must not aliasing for static race detection. SIGPLAN No. 42, 1, 327--338.
[38]
Naik, M., Aiken, A., and Whaley, J. 2006. Effective static race detection for java. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'06). ACM Press, New York, NY, 308--319.
[39]
Neamtiu, I., Hicks, M., Foster, J. S., and Pratikakis, P. 2008. Contextual effects for version-consistent dynamic software updating and safe concurrent programming. In Proceedings of the ACM Conference on Principles of Programming Languages (POPL). ACM, New York, NY, 37--50.
[40]
Necula, G. C., McPeak, S., Rahul, S. P., and Weimer, W. 2002. Cil: Intermediate language and tools for analysis and transformation of c programs. In Proceedings of the 11th International Conference on Compiler Construction (CC'02). Springer-Verlag, 213--228.
[41]
News.com. 2007. Designer puts 96 cores on single chip. http//news.com.com/Designer+puts+96+cores+on+single+chip/2100-1006_3-5399128.html.
[42]
O'Callahan, R. and Choi, J.-D. 2003. Hybrid dynamic data race detection. In Proceedings of the 9th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP'03). ACM Press, New York, NY, 167--178.
[43]
Pierce, B. C. 2002. Types and Programming Languages. MIT Press, Cambridge, MA.
[44]
Poulsen, K. 2004. Tracking the blackout bug. http://www.securityfocus.com/news/8412.
[45]
Pratikakis, P., Foster, J. S., and Hicks, M. 2006a. Existential label flow inference via CFL reachability. In Proceedings of the Static Analysis Symposium (SAS). Springer, 88--106.
[46]
Pratikakis, P., Foster, J. S., and Hicks, M. 2006b. Locksmith: context-sensitive correlation analysis for race detection. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'06). ACM Press, New York, NY, 320--331.
[47]
Qadeer, S. and Wu, D. 2004. Kiss: keep it simple and sequential. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'04). ACM Press, New York, NY, 14--24.
[48]
Rehof, J. and Fähndrich, M. 2001. Type-base flow analysis: from polymorphic subtyping to cfl-reachability. In Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'01). ACM Press, New York, NY, 54--66.
[49]
Reps, T., Horwitz, S., and Sagiv, M. 1995. Precise interprocedural dataflow analysis via graph reachability. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'95). ACM Press, New York, NY, 49--61.
[50]
Reynolds, J. C. 2004. Toward a grainless semantics for shared-variable concurrency. In Proceedings of the Conference on Foundations of Software Technology and Theoretical Computer Science, K. Lodaya and M. Mahajan, Eds. Lecture Notes in Computer Science, vol. 3328. Springer, 35--48.
[51]
Rose, J., Swamy, N., and Hicks, M. 2005. Dynamic inference of polymorphic lock types. Sci. Comput. Program. 58, 3, 366--383.
[52]
Savage, S., Burrows, M., Nelson, G., Sobalvarro, P., and Anderson, T. 1997. Eraser: A dynamic data race detector for multithreaded programs. ACM Trans. Comput. Syst. 15, 4, 391--411.
[53]
Seidl, H., Vene, V., and Müller-Olm, M. 2003. Global invariants for analyzing multi-threaded applications. Proc. Estonian Acad. Sci. Phys. Math, 413-436.
[54]
Siff, M., Chandra, S., Ball, T., Kunchithapadam, K., and Reps, T. 1999. Coping with type casts in c. In Proceedings of the 7th European Software Engineering Conference Held Jointly with the 7th ACM SIGSOFT International Symposium on Foundations of Software Engineering. Springer-Verlag, 180--198.
[55]
Smith, F., Walker, D., and Morrisett, J. G. 2000. Alias types. In Proceedings of the 9th European Symposium on Programming Languages and Systems (ESOP'00). Springer-Verlag, 366--381.
[56]
Talpin, J.-P. and Jouvelot, P. 1994. The type and effect discipline. Inform. Comput. 111, 2, 245--296.
[57]
Terauchi, T. 2008. Checking race freedom via linear programming. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'08). ACM, New York, NY, 1--10.
[58]
Tofte, M. and Birkedal, L. 1998. A region inference algorithm. ACM Trans. Program. Lang. Syst. 20, 4, 724--767.
[59]
von Praun, C. and Gross, T. R. 2003. Static conflict analysis for multi-threaded object-oriented programs. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI'03). ACM, New York, NY, 115--128.
[60]
Voung, J. W., Jhala, R., and Lerner, S. 2007. Relay: static race detection on millions of lines of code. In Proceedings of the 6th joint meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on the Foundations of Software Engineering (ESEC-FSE'07). ACM, New York, NY, 205--214.

Cited By

View all

Recommendations

Reviews

Prahladavaradan Sampath

We can judge the maturity of a field of scientific inquiry by the nature of the papers published in peer-reviewed journals. This paper indicates that the field of program analysis is reaching a level of maturity-it does not simply focus on novelty and theory, but is also concerned with the practical application of the theory, with some thought given to the repeatability of the results. This paper describes the implementation of a data race analysis for C programs. The authors describe their design decisions and back up these decisions with experimental data from the analysis of a benchmark suite of programs. The data race analysis is composed of a number of smaller analyses that are each specified as constraint satisfaction problems implemented using a dataflow framework. The design of the analyses is motivated by data collected from different experiments. In some cases, the data reinforces folklore, such as the fact that context sensitivity can improve both precision and efficiency. In Sections 4 and 5, the authors dwell in detail on many forms of context sensitivity that improve precision and efficiency. In other cases, the data is surprising: take, for example, the fact that a no-worklist strategy is apparently better than a worklist strategy. The most technically complex part of the paper is Section 6, on universal and existential context sensitivity. Here, however, the authors could have made more of an effort to explain these concepts and their application, as they did in earlier sections. Overall, this paper is an important contribution to the literature. Due to the availability of the full implementation on the authors' Web site (http://www.cs.umd.edu/projects/PL/locksmith/) and the easy availability of the benchmark suite, this paper should encourage more experimental and application-oriented work in program analysis. Online Computing Reviews Service

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 33, Issue 1
January 2011
218 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/1889997
Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 25 January 2011
Accepted: 01 February 2010
Revised: 01 October 2009
Received: 01 July 2008
Published in TOPLAS Volume 33, Issue 1

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Data race
  2. Locksmith
  3. context sensitivity
  4. contextual effects
  5. correlation inference
  6. race detection
  7. sharing analysis
  8. static analysis

Qualifiers

  • Research-article
  • Research
  • Refereed

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)157
  • Downloads (Last 6 weeks)20
Reflects downloads up to 28 Jan 2025

Other Metrics

Citations

Cited By

View all

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media