From eca9120e219ab24caeed5ed254924b5cce9c973d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 28 Jan 2023 18:04:57 +0100 Subject: [PATCH] avr: use precise GC by default AVR is especially sensitive to false positives in the GC for a few reasons: * Pointer values are only two bytes, instead of four on most other microcontrollers. * Pointers are not aligned, so any two-byte value in an object coud be a pointer. * Memory typically starts at a low address, which makes it much more likely to clash with a regular integer value (which tend to be small values). Therefore, use the precise GC (instead of the conservative GC) by default. This increases binary size by around 350 bytes, but I think it's a good tradeoff in most cases: it avoids some runtime errors and generally RAM tends to be a lot more scarce than flash on AVR chips. If this is too much, `-gc=conservative` or `-gc=leaking` can be used instead. --- main_test.go | 4 ---- targets/avr.json | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/main_test.go b/main_test.go index b3e86420f..6c086e85c 100644 --- a/main_test.go +++ b/main_test.go @@ -210,10 +210,6 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { // limited amount of memory. continue - case "gc.go": - // Does not pass due to high mark false positive rate. - continue - case "json.go", "stdlib.go", "testing.go": // Too big for AVR. Doesn't fit in flash/RAM. continue diff --git a/targets/avr.json b/targets/avr.json index 587a3e565..9700f241b 100644 --- a/targets/avr.json +++ b/targets/avr.json @@ -3,7 +3,7 @@ "build-tags": ["avr", "baremetal", "linux", "arm"], "goos": "linux", "goarch": "arm", - "gc": "conservative", + "gc": "precise", "linker": "ld.lld", "scheduler": "none", "rtlib": "compiler-rt",