Picking `c_longdouble` on linux PowerPC

オープン
#166,424 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
8/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, linux, rust
領域
compilers

調査の方向性

This is a design/tracking issue, not a scoped edit: read the whole body first, then the linked compiler-team#1050 ("Store C-compatible types in the target spec") and its Zulip thread, which is where the actual c_longdouble representation decision is being made. The relevant surface is the target spec definitions for the powerpc/powerpc64 Linux targets and how the C-compatible type is recorded there. Done means an agreed mapping (ELFv1 -> ppcf128, ELFv1/ELFv2 BE -> ppcf128, LE ELFv2 -> f128) is written down and reflected in those specs; until then this needs a compiler/targets contributor, not a newcomer.

索引モデルが issue の本文から書いたものです。

説明

F-c_longdouble needs-triage O-PowerPC

This is a weird mix of a tracking issue and design doc, meant to give background on how we should pick what type c_longdouble corresponds to on the Linux PowerPC targets.

Written by @Gelbpunkt and @folkertdev.


On PowerPC targets, there exist several ABIs with a variety of supported types for long double. Additionally, certain libcs and operating systems have decided to ignore ABI specifications and make up their own definitions for long double.

The target tuple does not always uniquely determine what type long double corresponds to, so in some cases we must either split a target, or pick a winner and accept being incompatible with toolchains that pick a different option.

32-bit PowerPC

On 32-bit PowerPC, the ABI leaves only a single choice for long double: double. The LSB spec says not to use long double at all.

However, Clang and GCC actually use the "IBM extended precision" (a double-double type) as their long double type by default. But certain libcs and operating systems like musl libc and some BSDs do use the spec-compliant f64.

Luckily there is generally a definitive choice for long double for a given target OS and target environment: the target tuple uniquely determines what type should be used.

64-bit PowerPC

On 64-bit PowerPC the situation is more complicated. There are two ELF ABIs:

The ELFv1 ABI defines the long double type to be the IBM extended precision type, in ELFv2 this is changed to be a choice between the IBM extended precision type and the IEEE754 binary128 (f128) type. That means different ABIs are in use today:

  • ELFv1 (with long double being the IBM extended precision type)
  • ELFv2 (with long double being the IBM extended precision type)
  • ELFv2 (with long double being the IEEE binary128 type)

Additionally, some BSDs and musl libc have opted to use double as long double. These generally all use the ELFv2 ABI instead of ELFv1, which means there's also:

  • ELFv2 (with long double being double)

which is technically not allowed by the ABI, but done in practice.

Crucially, for 64-bit PowerPC the target tuple does not uniquely determine what type long double corresponds to.

Background on ELFv1 versus ELFv2

Overall there seems to be a trend towards adopting ELFv2, and picking IEEE binary128 as the long double type (see sources below). However, doing so is currently not always possible, and some configurations may never be able to make the switch.

In order to be able to use the IEEE binary128 type on 64-bit PowerPC, GCC and Clang currently require the VSX extension to be enabled. This extension is implied by the powerpc64le baseline (which corresponds to POWER8), so all powerpc64le targets can make use of the IEEE binary128 type.

However, on powerpc64 (big-endian), the baseline in GCC is typically POWER4 (which has neither AltiVec nor VSX) and in LLVM and Rust, it's a PPC970 (which has AltiVec, but not VSX). The IEEE binary128 type could technically also be used with just AltiVec instead of VSX, but this is ongoing work on the LLVM side and currently not possible.

The ELFv2 ABI formally requires an ISA 2.07B (i.e. POWER8) CPU with all extensions (including both AltiVec and VSX), but in practice sets no requirements that wouldn't be met with just AltiVec (VSX doubles the vector register count, but the registers mandated by the ABI are included with AltiVec).

Hence, most distributions that use ELFv2 on big-endian powerpc64 do not include VSX in their baseline, technically breaking the spec. Private conversations with folks at IBM indicates that they're open to changing the ELFv2 specification to officially support this usecase.

Picking c_longdouble on 64-bit PowerPC

So, for Rust this means:

  • ELFv1 is used for legacy glibc targets and should define c_longdouble to be ppcf128 (the IBM extended precision type)
  • Big-endian ELFv2 glibc today can only define c_longdouble to be ppcf128 due to toolchain limitations that may be resolved in the future
  • Little-endian ELFv2 glibc can define c_longdouble to be either ppcf128 or f128
    • The general trend amongst distributions is to move towards f128
      • Debian switched with 13 (Trixie)
      • Fedora switched with 36, which means RHEL 10 made the switch as well
      • Ubuntu switched in 25.10
    • We believe f128 is the right call for Rust in this case because it's the forward-looking choice if we want to avoid a target split for powerpc64le with glibc
      • f128 also has hardware acceleration on POWER9 and later

What's next

The plan here is tentative, it might change. The c_longdouble type will likely stay unstable for a while, and we'll see how the compiler support for ELFv2 and f128 develops.

Links
主要言語
Rust
スター
123k
フォーク
16.6k
平均マージ
2日 17時間
マージ済み PR(30日)
532

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust のほかの issue

rust-lang/rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。