USB: unexpected heap allocations at -opt=0

オープン
#6,669 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go
領域
embedded-iot

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Go
スター
17.8k
フォーク
1.1k
平均マージ
1日 4時間
マージ済み PR(30日)
380

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tinygo-org/tinygo のほかの issue

tinygo-org/tinygo の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。