Wait, how does placing ZST statics work again?
还没有人认领这个 Issue。
评估
调研方向
Start by reading the Rust reference PR #1657 and the linked unsafe-code-guidelines issues about ZST statics, then compare the address-range and byte-set interpretations described here. Done means reaching and documenting a decision about which rule should govern ZST static placement, including how it fits the LLVM and embedded-development constraints.
由索引模型根据 Issue 内容生成。
描述
As revealed in https://github.com/rust-lang/reference/pull/1657 there is not an immediately shared understanding on ZST statics and where they should go. There are two major ways to interpret "ZST statics do not overlap with other statics". One is "statics are their address ranges" and the other is "statics are their byte sets". We need to pick one.
Other relevant-seeming issues:
- https://github.com/rust-lang/unsafe-code-guidelines/issues/545
- https://github.com/rust-lang/unsafe-code-guidelines/issues/397
- https://github.com/rust-lang/unsafe-code-guidelines/issues/259
- https://github.com/rust-lang/unsafe-code-guidelines/issues/256
- https://github.com/rust-lang/unsafe-code-guidelines/issues/206
Statics As Address Ranges
Expressed by @RalfJung as:
fn does_overlap(r1: Range<usize>, r2: Range<usize>) -> bool {
!(r1.end <= r2.start || r2.end <= r1.start)
}
Pros
- very straightforward definition, which removes some nonintuitive scenarios
- still allows placing a
static ZST: ()at the start or end address of a givenstatic ARRAY: [u8; N] - stronger, which may allow proving things more easily (i.e. optimizations)
Cons
- induces more UB if people combine Rust with linker scripts to reposition
statics in ways that are incompatible with this rule - requires more R&D to develop a good alternative for people using linker control that doesn't cause UB left and right
Statics As Byte Sets
Elegantly phrased by @CAD97 as: "No byte of memory is contained in more than one static item."
This rule seems to be functionally equivalent to the other phrasing offered, which is "static items cannot alias other static items (using the definition of aliasing from the reference aliasing model)".
Pros
- potentially less UB for embedded developers
- makes the logic between "where a ZST allocation can go" and "where a ZST
&mut ()can go" more uniform
Cons
- this rule allows some unexpected scenarios
- seems like it may be unnecessarily weak and may prove incompatible with LLVM
- hard to say if the patterns this enables will actually be sound-in-practice, even if we allow this
Constraints
We have some preexisting concerns. Each is pushing us in the opposite direction:
- LLVM doesn't seem to actually handle the notion of a
static ZST: ()strictly nesting in anotherstatic ARRAY: [u8; N]well. This does imply we may be passing up a number of optimizations if we adopt the byte-set rule, suggesting that we should pick the address-based rule.- Note that currently, LLVM doesn't seem to handle the notion of
static ZST: ()... at all, really[^1]
- Note that currently, LLVM doesn't seem to handle the notion of
- Embedded developers (including kernel and driver developers) often need the ability to slice-and-dice the address space. Some of this is done using fixed-size statics, but another common way to do this is using
statics that are relocated using linker control (flags or linker scripts), which then have their addresses extracted and then composed with a pointer of ambiguous (or, slightly more rarely, known-appropriate) provenance. Often, both. If ZSTs are allowed to be nested in other statics, this has better composition and enables this rule.
[^1]: according to https://github.com/rust-lang/reference/pull/1657#issuecomment-2464528692 and https://llvm.godbolt.org/z/6qTvx3qxd
- 主要语言
- 没有语言数据
- 星标
- 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 天内回复