Blame 0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch

000c237
From 0321eecc6d29d5b571930ed97f392623fe80a2e5 Mon Sep 17 00:00:00 2001
000c237
From: Ayke van Laethem <aykevanlaethem@gmail.com>
000c237
Date: Sat, 23 Sep 2023 14:57:25 +0200
000c237
Subject: [PATCH 6/7] avr: don't compile large parts of picolibc (math, stdio)
000c237
000c237
These parts aren't critical and lead to crashes on small chips without
000c237
long jumps (like the attiny85) with LLVM 17. (Older LLVM versions would
000c237
emit long jumps regardless, even if the chip didn't support those).
000c237
000c237
For more information, see: https://github.com/llvm/llvm-project/issues/67042
000c237
000c237
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
000c237
---
000c237
 builder/picolibc.go | 172 ++++++++++++++++++++++++--------------------
000c237
 1 file changed, 93 insertions(+), 79 deletions(-)
000c237
000c237
diff --git a/builder/picolibc.go b/builder/picolibc.go
000c237
index 1b7c748b..91ad27be 100644
000c237
--- a/builder/picolibc.go
000c237
+++ b/builder/picolibc.go
000c237
@@ -3,6 +3,7 @@ package builder
000c237
 import (
000c237
 	"os"
000c237
 	"path/filepath"
000c237
+	"strings"
000c237
 
000c237
 	"github.com/tinygo-org/tinygo/goenv"
000c237
 )
000c237
@@ -41,91 +42,23 @@ var Picolibc = Library{
000c237
 	},
000c237
 	sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib") },
000c237
 	librarySources: func(target string) ([]string, error) {
000c237
-		return picolibcSources, nil
000c237
+		sources := append([]string(nil), picolibcSources...)
000c237
+		if !strings.HasPrefix(target, "avr") {
000c237
+			// Small chips without long jumps can't compile many files (printf,
000c237
+			// pow, etc). Therefore exclude those source files for those chips.
000c237
+			// Unfortunately it's difficult to exclude only some chips, so this
000c237
+			// excludes those files on all AVR chips for now.
000c237
+			// More information:
000c237
+			// https://github.com/llvm/llvm-project/issues/67042
000c237
+			sources = append(sources, picolibcSourcesLarge...)
000c237
+		}
000c237
+		return sources, nil
000c237
 	},
000c237
 }
000c237
 
000c237
 var picolibcSources = []string{
000c237
 	"../../picolibc-stdio.c",
000c237
 
000c237
-	// srcs_tinystdio
000c237
-	"libc/tinystdio/asprintf.c",
000c237
-	"libc/tinystdio/bufio.c",
000c237
-	"libc/tinystdio/clearerr.c",
000c237
-	"libc/tinystdio/ecvt_r.c",
000c237
-	"libc/tinystdio/ecvt.c",
000c237
-	"libc/tinystdio/ecvtf_r.c",
000c237
-	"libc/tinystdio/ecvtf.c",
000c237
-	"libc/tinystdio/fcvt.c",
000c237
-	"libc/tinystdio/fcvt_r.c",
000c237
-	"libc/tinystdio/fcvtf.c",
000c237
-	"libc/tinystdio/fcvtf_r.c",
000c237
-	"libc/tinystdio/gcvt.c",
000c237
-	"libc/tinystdio/gcvtf.c",
000c237
-	"libc/tinystdio/fclose.c",
000c237
-	"libc/tinystdio/fdevopen.c",
000c237
-	"libc/tinystdio/feof.c",
000c237
-	"libc/tinystdio/ferror.c",
000c237
-	"libc/tinystdio/fflush.c",
000c237
-	"libc/tinystdio/fgetc.c",
000c237
-	"libc/tinystdio/fgets.c",
000c237
-	"libc/tinystdio/fileno.c",
000c237
-	"libc/tinystdio/filestrget.c",
000c237
-	"libc/tinystdio/filestrput.c",
000c237
-	"libc/tinystdio/filestrputalloc.c",
000c237
-	"libc/tinystdio/fmemopen.c",
000c237
-	"libc/tinystdio/fprintf.c",
000c237
-	"libc/tinystdio/fputc.c",
000c237
-	"libc/tinystdio/fputs.c",
000c237
-	"libc/tinystdio/fread.c",
000c237
-	//"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369
000c237
-	"libc/tinystdio/fscanf.c",
000c237
-	"libc/tinystdio/fseek.c",
000c237
-	"libc/tinystdio/fseeko.c",
000c237
-	"libc/tinystdio/ftell.c",
000c237
-	"libc/tinystdio/ftello.c",
000c237
-	"libc/tinystdio/fwrite.c",
000c237
-	"libc/tinystdio/getchar.c",
000c237
-	"libc/tinystdio/gets.c",
000c237
-	"libc/tinystdio/matchcaseprefix.c",
000c237
-	"libc/tinystdio/mktemp.c",
000c237
-	"libc/tinystdio/perror.c",
000c237
-	"libc/tinystdio/printf.c",
000c237
-	"libc/tinystdio/putchar.c",
000c237
-	"libc/tinystdio/puts.c",
000c237
-	"libc/tinystdio/rewind.c",
000c237
-	"libc/tinystdio/scanf.c",
000c237
-	"libc/tinystdio/setbuf.c",
000c237
-	"libc/tinystdio/setbuffer.c",
000c237
-	"libc/tinystdio/setlinebuf.c",
000c237
-	"libc/tinystdio/setvbuf.c",
000c237
-	"libc/tinystdio/snprintf.c",
000c237
-	"libc/tinystdio/sprintf.c",
000c237
-	"libc/tinystdio/snprintfd.c",
000c237
-	"libc/tinystdio/snprintff.c",
000c237
-	"libc/tinystdio/sprintff.c",
000c237
-	"libc/tinystdio/sprintfd.c",
000c237
-	"libc/tinystdio/sscanf.c",
000c237
-	"libc/tinystdio/strfromf.c",
000c237
-	"libc/tinystdio/strfromd.c",
000c237
-	"libc/tinystdio/strtof.c",
000c237
-	"libc/tinystdio/strtof_l.c",
000c237
-	"libc/tinystdio/strtod.c",
000c237
-	"libc/tinystdio/strtod_l.c",
000c237
-	"libc/tinystdio/ungetc.c",
000c237
-	"libc/tinystdio/vasprintf.c",
000c237
-	"libc/tinystdio/vfiprintf.c",
000c237
-	"libc/tinystdio/vfprintf.c",
000c237
-	"libc/tinystdio/vfprintff.c",
000c237
-	"libc/tinystdio/vfscanf.c",
000c237
-	"libc/tinystdio/vfiscanf.c",
000c237
-	"libc/tinystdio/vfscanff.c",
000c237
-	"libc/tinystdio/vprintf.c",
000c237
-	"libc/tinystdio/vscanf.c",
000c237
-	"libc/tinystdio/vsscanf.c",
000c237
-	"libc/tinystdio/vsnprintf.c",
000c237
-	"libc/tinystdio/vsprintf.c",
000c237
-
000c237
 	"libc/string/bcmp.c",
000c237
 	"libc/string/bcopy.c",
000c237
 	"libc/string/bzero.c",
000c237
@@ -229,6 +162,87 @@ var picolibcSources = []string{
000c237
 	"libc/string/wmempcpy.c",
000c237
 	"libc/string/wmemset.c",
000c237
 	"libc/string/xpg_strerror_r.c",
000c237
+}
000c237
+
000c237
+// Parts of picolibc that are too large for small AVRs.
000c237
+var picolibcSourcesLarge = []string{
000c237
+	// srcs_tinystdio
000c237
+	"libc/tinystdio/asprintf.c",
000c237
+	"libc/tinystdio/bufio.c",
000c237
+	"libc/tinystdio/clearerr.c",
000c237
+	"libc/tinystdio/ecvt_r.c",
000c237
+	"libc/tinystdio/ecvt.c",
000c237
+	"libc/tinystdio/ecvtf_r.c",
000c237
+	"libc/tinystdio/ecvtf.c",
000c237
+	"libc/tinystdio/fcvt.c",
000c237
+	"libc/tinystdio/fcvt_r.c",
000c237
+	"libc/tinystdio/fcvtf.c",
000c237
+	"libc/tinystdio/fcvtf_r.c",
000c237
+	"libc/tinystdio/gcvt.c",
000c237
+	"libc/tinystdio/gcvtf.c",
000c237
+	"libc/tinystdio/fclose.c",
000c237
+	"libc/tinystdio/fdevopen.c",
000c237
+	"libc/tinystdio/feof.c",
000c237
+	"libc/tinystdio/ferror.c",
000c237
+	"libc/tinystdio/fflush.c",
000c237
+	"libc/tinystdio/fgetc.c",
000c237
+	"libc/tinystdio/fgets.c",
000c237
+	"libc/tinystdio/fileno.c",
000c237
+	"libc/tinystdio/filestrget.c",
000c237
+	"libc/tinystdio/filestrput.c",
000c237
+	"libc/tinystdio/filestrputalloc.c",
000c237
+	"libc/tinystdio/fmemopen.c",
000c237
+	"libc/tinystdio/fprintf.c",
000c237
+	"libc/tinystdio/fputc.c",
000c237
+	"libc/tinystdio/fputs.c",
000c237
+	"libc/tinystdio/fread.c",
000c237
+	//"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369
000c237
+	"libc/tinystdio/fscanf.c",
000c237
+	"libc/tinystdio/fseek.c",
000c237
+	"libc/tinystdio/fseeko.c",
000c237
+	"libc/tinystdio/ftell.c",
000c237
+	"libc/tinystdio/ftello.c",
000c237
+	"libc/tinystdio/fwrite.c",
000c237
+	"libc/tinystdio/getchar.c",
000c237
+	"libc/tinystdio/gets.c",
000c237
+	"libc/tinystdio/matchcaseprefix.c",
000c237
+	"libc/tinystdio/mktemp.c",
000c237
+	"libc/tinystdio/perror.c",
000c237
+	"libc/tinystdio/printf.c",
000c237
+	"libc/tinystdio/putchar.c",
000c237
+	"libc/tinystdio/puts.c",
000c237
+	"libc/tinystdio/rewind.c",
000c237
+	"libc/tinystdio/scanf.c",
000c237
+	"libc/tinystdio/setbuf.c",
000c237
+	"libc/tinystdio/setbuffer.c",
000c237
+	"libc/tinystdio/setlinebuf.c",
000c237
+	"libc/tinystdio/setvbuf.c",
000c237
+	"libc/tinystdio/snprintf.c",
000c237
+	"libc/tinystdio/sprintf.c",
000c237
+	"libc/tinystdio/snprintfd.c",
000c237
+	"libc/tinystdio/snprintff.c",
000c237
+	"libc/tinystdio/sprintff.c",
000c237
+	"libc/tinystdio/sprintfd.c",
000c237
+	"libc/tinystdio/sscanf.c",
000c237
+	"libc/tinystdio/strfromf.c",
000c237
+	"libc/tinystdio/strfromd.c",
000c237
+	"libc/tinystdio/strtof.c",
000c237
+	"libc/tinystdio/strtof_l.c",
000c237
+	"libc/tinystdio/strtod.c",
000c237
+	"libc/tinystdio/strtod_l.c",
000c237
+	"libc/tinystdio/ungetc.c",
000c237
+	"libc/tinystdio/vasprintf.c",
000c237
+	"libc/tinystdio/vfiprintf.c",
000c237
+	"libc/tinystdio/vfprintf.c",
000c237
+	"libc/tinystdio/vfprintff.c",
000c237
+	"libc/tinystdio/vfscanf.c",
000c237
+	"libc/tinystdio/vfiscanf.c",
000c237
+	"libc/tinystdio/vfscanff.c",
000c237
+	"libc/tinystdio/vprintf.c",
000c237
+	"libc/tinystdio/vscanf.c",
000c237
+	"libc/tinystdio/vsscanf.c",
000c237
+	"libc/tinystdio/vsnprintf.c",
000c237
+	"libc/tinystdio/vsprintf.c",
000c237
 
000c237
 	"libm/common/sf_finite.c",
000c237
 	"libm/common/sf_copysign.c",
000c237
-- 
000c237
2.41.0
000c237