regparm(2) functions on i386 are emitted as ordinary extern C
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
調査の方向性
input.h の regparm 宣言に対する bindgen CLI の経路から始め、Clang の i386 LLVM シグネチャと生成された Rust 宣言を比較します。このサポートされていない ABI をどのように表現すべきかを判断します。完了条件は、binding が互換性のない通常の C 宣言を暗黙に出力しなくなり、報告された reproducer のカバレッジがあることです。
索引モデルが issue の本文から書いたものです。
説明
Input C/C++ header
int regparm2_third(int a, int b, int c) __attribute__((regparm(2)));
Bindgen invocation
$ bindgen input.h \
--rust-target 1.75 \
-- -target i686-unknown-linux-gnu -std=gnu11
Actual output
extern "C" {
pub fn regparm2_third(
a: ::std::os::raw::c_int,
b: ::std::os::raw::c_int,
c: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
}
I defined the function to return its third argument and called it with
(11, 22, 33). The observed results were:
C caller: return=33, callee saw c=33
Generated binding: return=11, callee saw c=11
This reproduces at both -O0 and -O2.
Clang lowers the optimized C definition as:
define dso_local i32 @regparm2_third(
i32 inreg noundef %0,
i32 inreg noundef %1,
i32 noundef returned %2)
The Rust caller instead declares it as:
declare dso_local noundef i32 @regparm2_third(
i32 noundef,
i32 noundef,
i32 noundef)
What is wrong
On 32-bit x86, regparm(2) passes the first two integer arguments in EAX and
EDX, with the third argument on the stack. The generated ordinary C declaration
passes all three arguments on the stack. The Rust caller and C callee therefore
use different locations for the same arguments, without any diagnostic.
Expected output
Rust does not provide a matching regparm ABI. Bindgen should diagnose this
declaration as unsupported and avoid emitting a misleading ordinary C binding,
or generate a C wrapper that preserves the source ABI.
Impact
Calls through the generated declaration read the wrong argument values. In
this reproducer, the third parameter is 11 instead of 33 and the function
returns the wrong value.
Environment
bindgen: 0.72.0, current main 25b23474496e78f6a1fbf1c02cb66f11e4d176d0
bindgen release: 0.72.1
clang/libclang: 15.0.7
rustc: 1.75.0
target: i686-unknown-linux-gnu
OS: Ubuntu 22.04.5 LTS, x86_64 host
- 主要言語
- Rust
- スター
- 5.3k
- フォーク
- 846
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 11
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rust-bindgen のほかの issue
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)対応中かも @lwz23 が 49 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
rust-lang/rust-bindgen#3485 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
rust-lang/rust-bindgen#3483 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
rust-lang/rust-bindgen#3370 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
rust-lang/rust-bindgen#3363 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
rust-lang/rust-bindgen#3540 ·
メンテナーはふだん 1 日以内に返信
rust-lang/rust-bindgen の issue をすべて見る
似ている issue
-
ci javascript tests
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jonathanong/no-mistakes#3258 ·
メンテナーはふだん 1 日以内に返信
-
area: cpu-engines area: fuzzer good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 91/100
hffgzktbcc-blip/ounce-core#402 ·
メンテナーはふだん 1 日以内に返信
-
compiler
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
HerringtonDarkholme/hd-lang#1699 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
swc-project/swc-ai-issues#432 ·
-
SPLADE `/embed_sparse` output depends on the other inputs in the batch (candle BertModel / DistilBertModel)対応中かも @0z5a が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
huggingface/text-embeddings-inference#979 ·
メンテナーはふだん 1 日以内に返信