USB: unexpected heap allocations at -opt=0

Abierto
#6,669 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go
Área
embedded-iot

Línea de trabajo

Reproduce the failure with tinygo build -target=pico -scheduler=none -opt=0 -gc=none -o out.elf ., then inspect src/machine/machine_rp2_usb.go and src/machine/usb/cdc/usbcdc.go around the reported allocations. Check comparable USB implementations on other targets and review the escape-analysis and stack-usage discussion in related issues. Done means the Pico build no longer reports these heap allocations and the broader audit identifies any equivalent cases without excessive stack usage.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

When building for RP2 targets with -opt=0 -gc=none, heap allocations in the USB implementation cause build failures.
The clock initialization part of this was reported in #6613 and fixed by #6635, but the USB-related allocations remain.

Reproduce
package main

func main() {}
$ tinygo build -target=pico -scheduler=none -opt=0 -gc=none -o out.elf .
src/machine/machine_rp2_usb.go:108: object allocated on the heap with -gc=none
src/machine/usb/cdc/usbcdc.go:232: object allocated on the heap with -gc=none
Known allocations
  • src/machine/machine_rp2_usb.go:108: var b [cdcLineInfoSize]byte in ReceiveUSBControlPacket
  • src/machine/usb/cdc/usbcdc.go:232: the array returned by machine.ReceiveUSBControlPacket() in cdcSetup (SET_LINE_CODING)

Both allocations involve local arrays that are sliced (b[:]) and passed to functions. At -opt=0, these allocations are not eliminated because escape analysis is not performed.
For comparison, the GET_LINE_CODING path uses the package-level cdcSetupBuff and does not allocate.

Since similar allocation patterns may exist in USB implementations for other targets, I would like to investigate this separately.

Scope
  • Identify unnecessary heap allocations in USB implementations at -opt=0.
  • Check whether other targets have similar allocations in their USB implementations.
  • Determine an appropriate solution without introducing excessive stack usage.
Relation to #6645

This is related to #6645, but it remains to be determined whether enabling escape analysis at -opt=0 is sufficient to resolve the USB-related issues.
As noted in #6645, enabling escape analysis may also increase stack usage on Cortex-M, so USB-specific changes may still be necessary.

Environment: TinyGo dev (after #6635), target pico

Lenguaje dominante
Go
Estrellas
17.8k
Forks
1.1k
Merge medio
1 d 4 h
PR fusionados (30 d)
380

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tinygo-org/tinygo

Todos los issues de tinygo-org/tinygo

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.