Skip to main content
QUICK 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 Science参考文献 8被引用 16
一句话总结

本文识别出Power和ARMv7架构上广泛接受的C/C++尾同步编译器映射的两个反例,表明这些映射违反了C/C++内存模型,允许出现禁止的执行行为。作者揭示了这些映射正确性证明中的一个关键缺陷,即该证明未能考虑通过非SC中间访问产生的hb(happens-before)边,从而破坏了sc(顺序一致性)顺序与hb关系之间的一致性。

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.

研究动机与目标

  • 证明在C/C++内存模型下,Power和ARMv7架构上广泛使用的C/C++尾同步编译器映射是错误的。
  • 识别出C/C++内存模型明令禁止但尾同步映射允许的特定程序执行序列。
  • 揭示这些映射正确性证明中的关键疏漏,尤其是关于hb与sc顺序一致性的部分。
  • 评估当前编译器和硬件在这些缺陷方面的状态。
  • 主张必须修改编译器映射或C/C++内存模型,以确保正确编译。

提出的方法

  • 构建两个小测试反例:IRIW和RWC,用以暴露尾同步映射中的违规行为。
  • 分析这些测试在Power和ARMv7上的C/C++和汇编级别行为,重点关注内存顺序和同步机制。
  • 识别出当hb边通过非SC中间访问产生时,尾同步映射无法强制实现hb一致性。
  • 揭示Batty等人证明中的缺陷:其假设任意线性化(posc ∪ cosc ∪ frsc ∪ erfsc)*足以确保sc-hb一致性,但该关系未考虑通过非SC操作产生的传递性hb边。
  • 在Power硬件上验证反例,并分析其在ARMv7硬件和模型上的行为。
  • 比较GCC和Clang编译器的行为,表明它们在实践中避开了有缺陷的尾同步映射。

实验结果

研究问题

  • RQ1能否在C/C++内存模型下证明Power和ARMv7架构上C/C++尾同步编译器映射的正确性?
  • RQ2是否存在C/C++内存模型明令禁止但尾同步映射允许的特定程序执行?
  • RQ3为何尾同步映射正确性证明未能检测到这些违规行为?
  • RQ4现代编译器如GCC和Clang在实践中是否使用了有缺陷的尾同步映射?
  • RQ5这些禁止的行为是否能在实际的Power或ARMv7硬件上被观测到?

主要发现

  • Power和ARMv7架构上C/C++的尾同步编译器映射允许违反C/C++内存模型的执行序列,特别是在通过非SC中间访问产生hb边的情况下。
  • 两个具体的反例——IRIW和RWC小测试——表明尾同步映射允许出现如r1=1, r2=0, r3=0等被C/C++标准禁止的结果。
  • Batty等人证明中存在关键漏洞:其假设线性化(posc ∪ cosc ∪ frsc ∪ erfsc)*足以确保sc-hb一致性,但该关系未考虑通过非SC操作产生的传递性hb边。
  • 这些被禁止的行为在使用尾同步映射编译后,已在Power硬件上被实际观测到,证实了该问题的实际严重性。
  • GCC和Clang在实践中并未使用有缺陷的尾同步映射(Power上使用的是前导同步),且在ARMv7上使用更强的屏障(dmb ish)实现加载获取,因此在实践中避开了该问题。
  • 尽管如此,由于另一个独立的反例,前导同步映射现在也被证明存在缺陷,这意味着在当前内存模型下,目前尚无任何映射能正确地将C/C++编译到Power或ARMv7架构。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。