USB: unexpected heap allocations at -opt=0

Đang mở
#6,669 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
embedded-iot

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Go
Star
17.8k
Fork
1.1k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
380

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/tinygo

Tất cả issue của tinygo-org/tinygo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.