Skip to main content
QUICK REVIEW

[Paper Review] Counterexamples and Proof Loophole for the C/C++ to POWER and ARMv7 Trailing-Sync Compiler Mappings

Yatin A. Manerkar, Caroline Trippel|arXiv (Cornell University)|Nov 4, 2016
Parallel Computing and Optimization TechniquesComputer Science8 references16 citations
TL;DR

This paper identifies two counterexamples to the widely accepted trailing-sync compiler mappings for C/C++ on Power and ARMv7 architectures, demonstrating that these mappings violate the C/C++ memory model by allowing forbidden execution behaviors. The authors expose a critical flaw in the proof of correctness for these mappings, showing that the proof fails to account for hb (happens-before) edges arising via non-SC intermediate accesses, which undermines the consistency between the sc (sequentially consistent) order and hb relations.

ABSTRACT

The C and C++ high-level languages provide programmers with atomic operations for writing high-performance concurrent code. At the assembly language level, C and C++ atomics get mapped down to individual instructions or combinations of instructions by compilers, depending on the ordering guarantees and synchronization instructions provided by the underlying architecture. These compiler mappings must uphold the ordering guarantees provided by C/C++ atomics or the compiled program will not behave according to the C/C++ memory model. In this paper we discuss two counterexamples to the well-known trailing-sync compiler mappings for the Power and ARMv7 architectures that were previously thought to be proven correct. In addition to the counterexamples, we discuss the loophole in the proof of the mappings that allowed the incorrect mappings to be proven correct. We also discuss the current state of compilers and architectures in relation to the bug.

Motivation & Objective

  • To demonstrate that the widely used trailing-sync compiler mappings for C/C++ on Power and ARMv7 are incorrect under the C/C++ memory model.
  • To identify specific program executions that are forbidden by the C/C++ memory model but allowed by the trailing-sync mappings.
  • To expose a critical oversight in the proof of correctness for these mappings, particularly regarding hb and sc order consistency.
  • To assess the current state of compilers and hardware with respect to these flaws.
  • To argue that either the compiler mappings or the C/C++ memory model must be revised to ensure correct compilation.

Proposed method

  • Constructing two litmus test counterexamples: IRIW and RWC, which expose violations in the trailing-sync mapping.
  • Analyzing the C/C++ and assembly-level behavior of these tests on Power and ARMv7, focusing on memory ordering and synchronization.
  • Identifying that the trailing-sync mapping fails to enforce hb consistency when hb edges arise through non-SC intermediate accesses.
  • Revealing a flaw in the proof by Batty et al. that assumed arbitrary linearization of (posc ∪ cosc ∪ frsc ∪ erfsc)* was sufficient to ensure sc-hb consistency.
  • Validating the counterexamples on Power hardware and analyzing their behavior on ARMv7 hardware and models.
  • Comparing the behavior of GCC and Clang compilers, showing they avoid the flawed trailing-sync mapping in practice.

Experimental results

Research questions

  • RQ1Can the trailing-sync compiler mapping for C/C++ on Power and ARMv7 be proven correct under the C/C++ memory model?
  • RQ2Are there specific program executions that are forbidden by the C/C++ memory model but allowed by the trailing-sync mapping?
  • RQ3Why did the proof of correctness for the trailing-sync mapping fail to detect these violations?
  • RQ4Do modern compilers like GCC and Clang use the flawed trailing-sync mapping in practice?
  • RQ5Can the forbidden behaviors be observed on actual Power or ARMv7 hardware?

Key findings

  • The trailing-sync compiler mapping for C/C++ on Power and ARMv7 allows execution sequences that violate the C/C++ memory model, specifically in cases involving hb edges through non-SC intermediate accesses.
  • Two concrete counterexamples—the IRIW and RWC litmus tests—demonstrate that the trailing-sync mapping permits forbidden outcomes like r1=1, r2=0, r3=0, which are disallowed by the C/C++ standard.
  • The proof of correctness by Batty et al. contains a critical loophole: it assumes that linearizing (posc ∪ cosc ∪ frsc ∪ erfsc)* ensures sc-hb consistency, but this relation does not account for transitive hb edges via non-SC operations.
  • The forbidden behaviors have been observed on Power hardware when compiled with the trailing-sync mapping, confirming the practical severity of the issue.
  • GCC and Clang do not use the flawed trailing-sync mapping for Power (they use leading-sync) and use stronger fences (dmb ish) for ARMv7 load-acquire, thus avoiding the issue in practice.
  • Despite this, the leading-sync mapping is also now known to be flawed due to a separate counterexample, meaning no current mapping correctly compiles C/C++ to Power or ARMv7 under the current memory model.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.