What should the ABI compatibility rules be for `repr($int)` enums?
还没有人认领这个 Issue。
评估
调研方向
Start by reading the ABI compatibility documentation linked in the issue and compare it with the CFI behavior described in the discussion. The issue presents several possible rules for repr($int) enums, but does not choose a final direction. Done means reaching agreement on a rule that accounts for Rust and C interoperability and CFI behavior.
由索引模型根据 Issue 内容生成。
描述
Currently we do not declare that repr($int) enums are ABI-compatible with $int, at least not in the ABI compatibility docs. We do however say or at least heavily imply that it's fine to use a repr($int) enum on the Rust side together with a C enum on the other side whose underlying type matches $int.
The C standard says that such an enum is compatible with $int. However, CFI implementations violate the C standard and do not allow function signatures to type-pun between enums and their underlying $int. IMO that's quite rude of them, standards exist for a reason. But we can't just ignore that fact, or at least if we do we should be aware of the consequences. If we say that in Rust, repr($int) enums are ABI-compatible with $int, then we must give them the same CFI tag, or else CFI would trigger on entirely well-defined Rust code. That would make such an enum not CFI-compatible with the same enum on the C side. (This is why https://github.com/rust-lang/rust/pull/128600 did not make it.)
(The same question also arises for repr(C) enums where the underlying integer type is left implicit. However, there it would probably be less surprising to say that those are not ABI-compatible with that implicit underlying integer type.)
So, what could we do?
- Convince clang that integer normalization should also normalize enums to their underlying integer type. (Either for all enums, or only for enums with an explicit underlying type.) We already require integer normalization for CFI to work with Rust, and it seems reasonable to include enums in that, at least those with an explicitly declared underlying integer type.
- Declare it EB to do function signature type punning between
repr($int)enums and $int. That would at least avoid nasal demons. Miri currently makes this UB and we haven't gotten reports about this, so making them fully ABI-compatible does not seem to be in high demand. - Make
repr($int)enums are ABI-compatible with $int unless they have a#[cfi_encoding]attribute, in which case a mismatch becomes EB. That would make such enums not CFI-compatible with the corresponding C enum by default: the enums would get an integer CFI tag by default, and FFI code would have to explicitly declare the CFI encoding to be CFI-compatible with the corresponding C code. - Anything else?
My preferred option is 1. CFI should not interfere with well-defined C programs. But I don't know if there is any chance that clang might do that, or if this would have a serious impact on CFI's ability to prevent exploits. Option 2 also seems acceptable, albeit somewhat unfortunate.
Cc @CAD97 @Jules-Bertholet @Darksonn @rcvalle
- 主要语言
- 没有语言数据
- 星标
- 760
- 派生
- 68
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/unsafe-code-guidelines 的其他 Issue
-
I-opsem-nominated
难度 4/5 3-5 天 新手友好度 35/100
rust-lang/unsafe-code-guidelines#634 · 5 条评论 ·
-
难度 5/5 一周以上 新手友好度 15/100
-
难度 5/5 一周以上 新手友好度 12/100
rust-lang/unsafe-code-guidelines#632 · 8 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 10/100
rust-lang/unsafe-code-guidelines#631 · 7 条评论 ·
-
I-opsem-nominated
难度 5/5 一周以上 新手友好度 20/100
rust-lang/unsafe-code-guidelines#630 · 1 个 reaction ·
查看 rust-lang/unsafe-code-guidelines 的全部 Issue
相似的 Issue
-
bug core-lang
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentence未关闭
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
mw00/project-maya#1368 ·
维护者通常 2 天内回复
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
foundry-rs/foundry#18828 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复