compiler: no escape analysis at -opt=0
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- build-system, compilers
Direzione di ricerca
Start in transform.Optimize and trace how the function-attrs and OptimizeAllocs passes are scheduled at -opt=0; compare with the escape-analysis behavior cited from cmd/compile. Reproduce the supplied //go:noheap, interrupt-handler, and startup randomness cases at -opt=0. Done means these cases build or run without unintended heap allocation while existing optimization behavior remains correct.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
At -opt=0, transform.Optimize does not run OptimizeAllocs. Each local whose address is passed to a call is allocated on the heap. I think this is a correctness problem, because code that is correct at -opt=1 fails at -opt=0.
With -gc=none, the build fails. #6613 reports this for the rp2 clock code, with object allocated on the heap with -gc=none.
In a //go:noheap function, the build also fails. The runtime.alloc_noheap comment says the call "must either be optimized away or throw a linker error". This program builds at -opt=1. At -opt=0 it fails with object allocated on the heap in //go:noheap function.
package main
//go:noheap
func main() {
var a int
add(&a)
}
//go:noinline
func add(p *int) { *p++ }
In an interrupt handler, the program aborts. At -opt=0 this handler calls runtime.alloc for c, and alloc in gc_blocks.go calls runtimeFatal("heap alloc in interrupt"). At -opt=1, c is a stack slot.
func handler(interrupt.Interrupt) {
c := counter{&total, 1}
c.add() // func (c *counter) add()
}
#5823 is an earlier case. At -opt=0, hardwareRand allocated n with runtime.alloc before initHeap, and linux programs crashed before main. At -opt=0, Go code cannot pass the address of a stack variable to a call. So 94173b29 replaced getrandom with the AT_RANDOM bytes from getauxval.
The generic startupRand still calls hardwareRand. On windows/amd64 at -opt=0, runtime.run calls initRand before initHeap, and hardwareRand calls runtime.alloc for n. I have not run this on Windows.
OptimizeAllocs has run only above -opt=0 since 42196525 added it as an optimisation. f41b6a3b and 85d223c5 later added the interrupt check and //go:noheap, and both depend on this pass.
The gc compiler runs escape analysis when -N disables optimisations. cmd/compile calls escape.Funcs with no check of -N, and its comment says escape analysis is required. See https://github.com/golang/go/blob/go1.27.4/src/cmd/compile/internal/gc/main.go#L285-L294. With -gcflags='-N -l -m', gc reports c does not escape for the receiver above, and main.main does not call runtime.newobject.
I propose that transform.Optimize also runs function-attrs and OptimizeAllocs at -opt=0. I tried this on the three cases above. All three build, and the handler uses a stack slot.
cc @rdon-key @dgryski
- Lingua principale
- Go
- Stelle
- 17.8k
- Fork
- 1.1k
- Merge medio
- 1g 4h
- PR unite (30g)
- 380
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tinygo-org/tinygo
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6727 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
tinygo-org/tinygo#6711 ·
I maintainer di solito rispondono entro 1 giorno
-
Builds are not reproducible: cgo snippet paths in debug infoForse già presa @tridev-tej l’ha presa 1 giorno fa. Apertaenhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6619 ·
I maintainer di solito rispondono entro 1 giorno
-
Fix the targets that tinygo build -target rejectsForse già presa @narguis l’ha presa 2 giorni fa. Apertabug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
tinygo-org/tinygo#6617 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
tinygo-org/tinygo#6312 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tinygo-org/tinygo
Issue simili
-
release
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
github/gh-aw-mcpg#17603 ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
oras-project/oras-go#1827 ·
I maintainer di solito rispondono entro 1 giorno
-
docs: database/sql Sessions example never commits its batch, and its "Full Example" link is a 404Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
ClickHouse/clickhouse-go#2185 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs triage receiver/podman
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
open-telemetry/opentelemetry-collector-contrib#53700 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
tagvalue.Read fails with "token too long" on lines over 64 KiBForse già presa @G26karthik l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
spdx/tools-golang#319 ·