Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Mix Testing: Specifying and Testing ABI Compatibility of C/C++ Atomics Implementations

Published: 08 October 2024 Publication History

Abstract

The correctness of complex software depends on the correctness of both the source code and the compilers that generate corresponding binary code. Compilers must do more than preserve the semantics of a single source file: they must ensure that generated binaries can be composed with other binaries to form a final executable. The compatibility of composition is ensured using an Application Binary Interface (ABI), which specifies details of calling conventions, exception handling, and so on. Unfortunately, there are no official ABIs for concurrent programs, so different atomics mappings, although correct in isolation, may induce bugs when composed. Indeed, today, mixing binaries generated by different compilers can lead to an erroneous resulting binary. We present mix testing: a new technique designed to find compiler bugs when the instructions of a C/C++ test are separately compiled for multiple compatible architectures and then mixed together. We define a class of compiler bugs, coined mixing bugs, that arise when parts of a program are compiled separately using different mappings from C/C++ atomic operations to assembly sequences. To demonstrate the generality of mix testing, we have designed and implemented a tool, atomic-mixer, which we have used: (a) to reproduce one existing non-mixing bug that state-of-the-art concurrency testing tools are limited to being able to find (showing that atomic-mixer at least meets the capabilities of these tools), and (b) to find four previously-unknown mixing bugs in LLVM and GCC, and one prospective mixing bug in mappings proposed for the Java Virtual Machine. Lastly, we have worked with engineers at Arm to specify, for the first time, an atomics ABI for Armv8, and have used atomic-mixer to validate the LLVM and GCC compilers against it.

References

[1]
Jade Alglave and Luc Maranget. 2021. herdtools7. https://github.com/herd/herdtools7 Accessed: 2019-10-06
[2]
Jade Alglave, Luc Maranget, Susmit Sarkar, and Peter Sewell. 2012. Fences in Weak Memory Models (Extended Version). Form. Methods Syst. Des., 40, 2 (2012), April, 170–205. issn:0925-9856 https://doi.org/10.1007/s10703-011-0135-z
[3]
Arm-Limited. 2021. Armv8 AArch64 Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/aarch64.cat
[4]
Arm-Limited. 2024. https://github.com/ARM-software/abi-aa/issues Accessed: 2024-14-02
[5]
Arm-Limited. 2024. Arm Architecture Reference Manual. Arm-Limited, Cambridge, UK. https://developer.arm.com/documentation/ddi0487/latest/
[6]
Arvind Arvind and Jan-Willem Maessen. 2006. Memory Model = Instruction Reordering + Store Atomicity. SIGARCH Comput. Archit. News, 34, 2 (2006), may, 29–40. issn:0163-5964 https://doi.org/10.1145/1150019.1136489
[7]
Mohamed Faouzi Atig, Ahmed Bouajjani, Sebastian Burckhardt, and Madanlal Musuvathi. 2010. On the Verification Problem for Weak Memory Models. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’10). Association for Computing Machinery, New York, NY, USA. 7–18. isbn:9781605584799 https://doi.org/10.1145/1706299.1706303
[8]
Mark John Batty. 2014. The C11 and C++11 Concurrency Model. Ph. D. Dissertation. University of Cambridge.
[9]
Hans-J. Boehm and Sarita V. Adve. 2008. Foundations of the C++ Concurrency Memory Model. In Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’08). Association for Computing Machinery, New York, NY, USA. 68–78. isbn:9781595938602 https://doi.org/10.1145/1375581.1375591
[10]
Soham Chakraborty and Viktor Vafeiadis. 2016. Validating Optimizations of Concurrent C/C++ Programs. In Proceedings of the 2016 International Symposium on Code Generation and Optimization (CGO ’16). ACM, New York, NY, USA. 216–226. isbn:978-1-4503-3778-6 https://doi.org/10.1145/2854038.2854051
[11]
Simon Colin. 2022. RC11 Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/rc11.cat
[12]
Will Deacon. 2014. arm64: atomics: fix use of acquire + release for full barrier semantics. http://lists.infradead.org/pipermail/linux-arm-kernel/2014-February/229588.html
[13]
Wilco Dijkstra. 2024. Alignment of _Atomic structs incompatible between GCC and LLVM. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115954
[14]
Luke Geeson. 2023. [AArch64]: Atomic Exchange Allows Reordering past Acquire Fence. https://github.com/llvm/llvm-project/issues/68428
[15]
Luke Geeson. 2023. Add (__)(u)int128(_t) parsing to CType. https://github.com/herd/herdtools7/pull/520
[16]
Luke Geeson. 2023. [lib/gen]: fixed __int128 parsing. https://github.com/herd/herdtools7/pull/553
[17]
Luke Geeson. 2024. [AArch64]: 128-bit Sequentially Consistent load allows reordering before prior store when armv8 and armv8.4 implementations are Mixed. https://github.com/llvm/llvm-project/issues/81978
[18]
Luke Geeson. 2024. [Armv7-a]: Sequentially Consistent Load Allows Reordering of Prior Store when Implementations are Mixed. https://github.com/llvm/llvm-project/issues/65541#issuecomment-1709229837
[19]
Luke Geeson. 2024. [Armv7/v8 Mixing Bug]: 64-bit Sequentially Consistent Load can be Reordered before Store of RMW when v7 and v8 Implementations are Mixed. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111416
[20]
Luke Geeson. 2024. Weak Memory Demands Model-based Compiler Testing. https://doi.org/10.48550/arXiv.2401.09474 arxiv:2401.09474.
[21]
Luke Geeson, James Brotherston, James Dijkstra, Alastair F. Donaldson, Lee Smith, Tyler Sorensen, and John Wickerson. 2024. Artifact for "Mix Testing: Specifying and Testing ABI Compatibility Of C/C++ Atomics Implementations". https://doi.org/10.5281/zenodo.13625822
[22]
Luke Geeson and Wilco Dijkstra. 2024. C/C++ Atomics Application Binary Interface Standard for the Arm® 64-bit Architecture. https://github.com/ARM-software/abi-aa/releases/tag/2024Q3
[23]
Luke Geeson and Lee Smith. 2024. Compiler Testing with Relaxed Memory Models. In 2024 IEEE/ACM International Symposium on Code Generation and Optimization (CGO). 334–348. https://doi.org/10.1109/CGO57630.2024.10444836
[24]
Open ISO-C-Std. 2022. ISO/IEC 9899:201x. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2912.pdf
[25]
Ori Lahav, Viktor Vafeiadis, Jeehoon Kang, Chung-Kil Hur, and Derek Dreyer. 2017. Repairing Sequential Consistency in C/C++11. PLDI 2017. ACM, New York, NY, USA. 618–632. isbn:978-1-4503-4988-8 https://doi.org/10.1145/3062341.3062352
[26]
L. Lamport. 1979. How to Make a Multiprocessor Computer That Correctly Executes Multiprocess Programs. IEEE Trans. Comput., 28, 9 (1979), Sept., 690–691. issn:0018-9340 https://doi.org/10.1109/TC.1979.1675439
[27]
Vu Le, Mehrdad Afshari, and Zhendong Su. 2014. Compiler Validation via Equivalence modulo Inputs. SIGPLAN Not., 49, 6 (2014), June, 216–226. issn:0362-1340 https://doi.org/10.1145/2666356.2594334
[28]
Sung-Hwan Lee. 2023. A miscompilation bug in LICMPass (concurrency). https://github.com/llvm/llvm-project/issues/64188
[29]
Xavier Leroy. 2009. Formal Verification of a Realistic Compiler. Commun. ACM, 52, 7 (2009), July, 107–115. issn:0001-0782 https://doi.org/10.1145/1538788.1538814
[30]
LLVM-Phabricator. 2023. [AArch64] Codegen for FEAT_LRCPC3. https://reviews.llvm.org/D141429#inline-1378324
[31]
LLVM-Phabricator. 2023. [WoA] Use fences for sequentially consistent stores/writes. https://reviews.llvm.org/D141748
[32]
Arm Ltd. 2022. AArch32 Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/aarch32.cat
[33]
Robert Mandl. 1985. Orthogonal Latin squares: an application of experiment design to compiler testing. Commun. ACM, 28, 10 (1985), oct, 1054–1058. issn:0001-0782 https://doi.org/10.1145/4372.4375
[34]
Luc Maranget. 2022. RISC-V Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/riscv.cat
[35]
Luc Maranget and Jade Alglave. 2022. ARM Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/arm.cat
[36]
Luc Maranget and Jade Alglave. 2022. IBM PowerPC Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/ppc.cat
[37]
Luc Maranget and Jade Alglave. 2023. MIPS Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/mips.cat
[38]
Luc Maranget and Jade Alglave. 2023. x86-64 Memory Model. https://github.com/herd/herdtools7/blob/master/herd/libdir/x86tso-mixed.cat
[39]
Microsoft. 2024. ELF x86-64-ABI psABI. https://gitlab.com/x86-psABIs/x86-64-ABI Accessed: 2024-02-07
[40]
Microsoft. 2024. Overview of x64 ABI conventions. https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170 Accessed: 2024-02-07
[41]
Robin Morisset, Pankaj Pawan, and Francesco Zappa Nardelli. 2013. Compiler Testing via a Theory of Sound Optimisations in the C11/C++11 Memory Model. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’13). ACM, New York, NY, USA. 187–196. isbn:978-1-4503-2014-6 https://doi.org/10.1145/2491956.2491967
[42]
James T. Perconti and Amal Ahmed. 2014. Verifying an Open Compiler Using Multi-language Semantics. In Proceedings of the 23rd European Symposium on Programming Languages and Systems - Volume 8410. Springer-Verlag, Berlin, Heidelberg. 128–148. isbn:9783642548321 https://doi.org/10.1007/978-3-642-54833-8_8
[43]
programmerjake. 2023. x86-32 -mno-x87 64-bit atomic load miscompilation. https://github.com/llvm/llvm-project/issues/64969
[44]
Mono Project. 2024. The Mono Project, atomic source code. https://github.com/mono/mono/blob/44e6226c31d8ffcae58f81350d71a728edecfe22/mono/utils/atomic.h#L209 Accessed: 2024-02-29
[45]
Peter Sewell and Jaroslav Ševčík. 2014. C/C++11 mappings to processors. https://www.cl.cam.ac.uk/ pes20/cpp/cpp0xmappings.html
[46]
Ole Tange. 2023. GNU Parallel 20230222. https://doi.org/10.5281/zenodo.7668338 GNU Parallel is a general parallelizer to run multiple serial command line programs in parallel without changing them.
[47]
Kyrylo Tkachov. 2024. Enabling the LDAPR instructions for C/C++ compilers. https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/enabling-rcpc-in-gcc-and-llvm
[48]
Jaroslav Ševčík. 2011. Safe Optimisations for Shared-memory Concurrent Programs. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’11). ACM, New York, NY, USA. 306–316. isbn:978-1-4503-0663-8 https://doi.org/10.1145/1993498.1993534
[49]
Jaroslav Ševčík, Viktor Vafeiadis, Francesco Zappa Nardelli, Suresh Jagannathan, and Peter Sewell. 2013. CompCertTSO: A Verified Compiler for Relaxed-Memory Concurrency. J. ACM, 60, 3 (2013), Article 22, June, 50 pages. issn:0004-5411 https://doi.org/10.1145/2487241.2487248
[50]
John Wickerson, Mark Batty, Tyler Sorensen, and George A. Constantinides. 2017. Automatically Comparing Memory Consistency Models. POPL 2017. ACM, New York, NY, USA. 190–204. isbn:978-1-4503-4660-3 https://doi.org/10.1145/3009837.3009838
[51]
Wikipedia. 2024. Internal Compiler Errors. https://en.wikipedia.org/wiki/Compilation_error#Internal_Compiler_Errors
[52]
Matt Windsor, Alastair F. Donaldson, and John Wickerson. 2021. C4: The C Compiler Concurrency Checker. In Proceedings of the 30th ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA 2021). ACM, New York, NY, USA. 670–673. isbn:9781450384599 https://doi.org/10.1145/3460319.3469079
[53]
Xuejun Yang, Yang Chen, Eric Eide, and John Regehr. 2011. Finding and Understanding Bugs in C Compilers. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’11). ACM, New York, NY, USA. 283–294. isbn:978-1-4503-0663-8 https://doi.org/10.1145/1993498.1993532

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 8, Issue OOPSLA2
October 2024
2691 pages
EISSN:2475-1421
DOI:10.1145/3554319
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution-ShareAlike International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 08 October 2024
Published in PACMPL Volume 8, Issue OOPSLA2

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Compiler Testing
  2. Concurrency
  3. Interoperability

Qualifiers

  • Research-article

Funding Sources

  • EPSRC
  • epsrc

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 162
    Total Downloads
  • Downloads (Last 12 months)162
  • Downloads (Last 6 weeks)47
Reflects downloads up to 20 Jan 2025

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media