From d348d8b4cfc572e34b8b3bb0f9ff6b638d422fbd Mon Sep 17 00:00:00 2001 From: Pat Whittingslow Date: Tue, 26 May 2026 10:27:32 -0300 Subject: [PATCH] rp2040: fix `-gc=leaking/none` --- GNUmakefile | 2 ++ src/machine/machine_rp2040_usb.go | 2 +- src/machine/machine_rp2_usb.go | 2 +- src/runtime/gc_leaking.go | 5 +++++ src/runtime/gc_none.go | 4 ++++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 57abe1839..450323a8b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -784,6 +784,8 @@ endif @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=pico examples/blinky1 @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=pico -gc=leaking examples/blinky1 + @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=nano-33-ble examples/blinky1 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=nano-rp2040 examples/blinky1 diff --git a/src/machine/machine_rp2040_usb.go b/src/machine/machine_rp2040_usb.go index 7f8210199..538cb0176 100644 --- a/src/machine/machine_rp2040_usb.go +++ b/src/machine/machine_rp2040_usb.go @@ -128,7 +128,7 @@ func handleUSBSetAddress(setup usb.Setup) bool { const ackTimeout = 570 rp.USBCTRL_REGS.SIE_STATUS.Set(rp.USBCTRL_REGS_SIE_STATUS_ACK_REC) - sendUSBPacket(0, []byte{}) + sendUSBPacket(0, nil) // Wait for transfer to complete with a timeout. t := timer.timeElapsed() diff --git a/src/machine/machine_rp2_usb.go b/src/machine/machine_rp2_usb.go index aa46aa858..36a0aab54 100644 --- a/src/machine/machine_rp2_usb.go +++ b/src/machine/machine_rp2_usb.go @@ -141,7 +141,7 @@ func setEPDataPID(ep uint32, dataOne bool) { } func SendZlp() { - sendUSBPacket(0, []byte{}) + sendUSBPacket(0, nil) } func sendViaEPIn(ep uint32, data []byte, count int) { diff --git a/src/runtime/gc_leaking.go b/src/runtime/gc_leaking.go index 24eea44bb..51ae247f7 100644 --- a/src/runtime/gc_leaking.go +++ b/src/runtime/gc_leaking.go @@ -8,11 +8,16 @@ package runtime import ( "internal/task" + "sync/atomic" "unsafe" ) const needsStaticHeap = true +var gcScanState atomic.Uint32 + +func scanCurrentStack() {} + // Ever-incrementing pointer: no memory is freed. var heapptr uintptr diff --git a/src/runtime/gc_none.go b/src/runtime/gc_none.go index b9e3155e4..3c092c65c 100644 --- a/src/runtime/gc_none.go +++ b/src/runtime/gc_none.go @@ -7,6 +7,7 @@ package runtime // targets that have far too little RAM even for the leaking memory allocator. import ( + "sync/atomic" "unsafe" ) @@ -15,6 +16,9 @@ const needsStaticHeap = false var gcTotalAlloc uint64 // for runtime.MemStats var gcMallocs uint64 var gcFrees uint64 +var gcScanState atomic.Uint32 + +func scanCurrentStack() {} func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer