Wait, how does placing ZST statics work again?
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Sin datos de lenguaje
- Estrellas
- 760
- Forks
- 68
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/unsafe-code-guidelines
-
I-opsem-nominated
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
rust-lang/unsafe-code-guidelines#634 · 5 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 12/100
rust-lang/unsafe-code-guidelines#632 · 8 comentarios · 1 reacción ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
rust-lang/unsafe-code-guidelines#631 · 7 comentarios ·
-
I-opsem-nominated
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
rust-lang/unsafe-code-guidelines#630 · 1 reacción ·
Todos los issues de rust-lang/unsafe-code-guidelines
Issues similares
-
bug core-lang
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentenceAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mw00/project-maya#1368 ·
Los mantenedores suelen responder en 2 días
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
foundry-rs/foundry#18828 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día