diff --git a/0001-Use-Fedora-command-names.patch b/0001-Use-Fedora-command-names.patch index 9dd124a..9499d67 100644 --- a/0001-Use-Fedora-command-names.patch +++ b/0001-Use-Fedora-command-names.patch @@ -1,7 +1,7 @@ From 845a1e4c9d7456d2a914e540ad6c8a7f9d684aa6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 7 Jun 2019 20:55:25 -0400 -Subject: [PATCH 1/4] Use Fedora command names. +Subject: [PATCH 1/5] Use Fedora command names. Signed-off-by: Elliott Sales de Andrade --- diff --git a/0002-Skip-ARM-Linux-tests.patch b/0002-Skip-ARM-Linux-tests.patch index ba0645d..08440fb 100644 --- a/0002-Skip-ARM-Linux-tests.patch +++ b/0002-Skip-ARM-Linux-tests.patch @@ -1,7 +1,7 @@ From 483c57eee834fb9cf19426d35f31cdb21a94044f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Jun 2019 04:28:55 -0400 -Subject: [PATCH 2/4] Skip ARM Linux tests. +Subject: [PATCH 2/5] Skip ARM Linux tests. We don't have the C library to do this. diff --git a/0003-Skip-STM32-tests.patch b/0003-Skip-STM32-tests.patch index 1f02c7d..fbc9827 100644 --- a/0003-Skip-STM32-tests.patch +++ b/0003-Skip-STM32-tests.patch @@ -1,7 +1,7 @@ From b93a578d1ca1538ada696ccb6d75f4c8c7858b14 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Jun 2019 02:50:40 -0400 -Subject: [PATCH 3/4] Skip STM32 tests. +Subject: [PATCH 3/5] Skip STM32 tests. We can't ship the STM32 .svd files due to their odd license. diff --git a/0004-Also-check-lib64-for-clang-include-path.patch b/0004-Also-check-lib64-for-clang-include-path.patch index c3e0552..4d3887c 100644 --- a/0004-Also-check-lib64-for-clang-include-path.patch +++ b/0004-Also-check-lib64-for-clang-include-path.patch @@ -1,7 +1,7 @@ From 22bbf4dc4f002d1a9178d45f92e5f81bac8593a4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 19 Sep 2020 23:11:08 -0400 -Subject: [PATCH 4/4] Also check lib64 for clang include path. +Subject: [PATCH 4/5] Also check lib64 for clang include path. On 64-bit Fedora, `lib64` is where the clang headers are, not `lib`. For multiarch systems, both will exist, but it's likely you want 64-bit, so diff --git a/0005-main-add-initial-support-for-in-development-LLVM-11.patch b/0005-main-add-initial-support-for-in-development-LLVM-11.patch new file mode 100644 index 0000000..04645cf --- /dev/null +++ b/0005-main-add-initial-support-for-in-development-LLVM-11.patch @@ -0,0 +1,270 @@ +From 91f8baf2d104ab29ff11e62bde456899083db319 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Tue, 14 Apr 2020 22:43:32 +0200 +Subject: [PATCH 5/5] main: add initial support for (in-development) LLVM 11 + +This can be useful to test improvements in LLVM master and to make it +possible to support LLVM 11 for the most part already before the next +release. That also allows catching LLVM bugs early to fix them upstream. + +Note that tests do not yet pass for this LLVM version, but the TinyGo +compiler can be built with the binaries from apt.llvm.org (at the time +of making this commit). + +Signed-off-by: Elliott Sales de Andrade +--- + builder/build.go | 11 +++++++++++ + builder/objcopy.go | 8 +++++++- + cgo/libclang_config.go | 2 +- + cgo/libclang_config_llvm11.go | 14 ++++++++++++++ + go.mod | 2 +- + go.sum | 4 ++-- + interp/interp_test.go | 17 +++++++++++++++-- + targets/gameboy-advance.ld | 7 ++++--- + transform/globals.go | 14 ++++++++++++++ + transform/transform_test.go | 16 ++++++++++++++-- + 10 files changed, 83 insertions(+), 12 deletions(-) + create mode 100644 cgo/libclang_config_llvm11.go + +diff --git a/builder/build.go b/builder/build.go +index 67c09df..e59fec4 100644 +--- a/builder/build.go ++++ b/builder/build.go +@@ -129,6 +129,17 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil + } + } + ++ // LLVM 11 by default tries to emit tail calls (even with the target feature ++ // disabled) unless it is explicitly disabled with a function attribute. ++ // This is a problem, as it tries to emit them and prints an error when it ++ // can't with this feature disabled. ++ // Because as of september 2020 tail calls are not yet widely supported, ++ // they need to be disabled until they are widely supported (at which point ++ // the +tail-call target feautre can be set). ++ if strings.HasPrefix(config.Triple(), "wasm") { ++ transform.DisableTailCalls(mod) ++ } ++ + // Make sure stack sizes are loaded from a separate section so they can be + // modified after linking. + var stackSizeLoads []string +diff --git a/builder/objcopy.go b/builder/objcopy.go +index a8a76af..991bceb 100644 +--- a/builder/objcopy.go ++++ b/builder/objcopy.go +@@ -61,7 +61,7 @@ func extractROM(path string) (uint64, []byte, error) { + + progs := make(progSlice, 0, 2) + for _, prog := range f.Progs { +- if prog.Type != elf.PT_LOAD || prog.Filesz == 0 { ++ if prog.Type != elf.PT_LOAD || prog.Filesz == 0 || prog.Off == 0 { + continue + } + progs = append(progs, prog) +@@ -73,6 +73,12 @@ func extractROM(path string) (uint64, []byte, error) { + + var rom []byte + for _, prog := range progs { ++ romEnd := progs[0].Paddr + uint64(len(rom)) ++ if prog.Paddr > romEnd && prog.Paddr < romEnd+16 { ++ // Sometimes, the linker seems to insert a bit of padding between ++ // segments. Simply zero-fill these parts. ++ rom = append(rom, make([]byte, prog.Paddr-romEnd)...) ++ } + if prog.Paddr != progs[0].Paddr+uint64(len(rom)) { + diff := prog.Paddr - (progs[0].Paddr + uint64(len(rom))) + if diff > maxPadBytes { +diff --git a/cgo/libclang_config.go b/cgo/libclang_config.go +index ec65d8a..24b9501 100644 +--- a/cgo/libclang_config.go ++++ b/cgo/libclang_config.go +@@ -1,5 +1,5 @@ + // +build !byollvm +-// +build !llvm9 ++// +build !llvm9,!llvm11 + + package cgo + +diff --git a/cgo/libclang_config_llvm11.go b/cgo/libclang_config_llvm11.go +new file mode 100644 +index 0000000..6fab82b +--- /dev/null ++++ b/cgo/libclang_config_llvm11.go +@@ -0,0 +1,14 @@ ++// +build !byollvm ++// +build llvm11 ++ ++package cgo ++ ++/* ++#cgo linux CFLAGS: -I/usr/lib/llvm-11/include ++#cgo darwin CFLAGS: -I/usr/local/opt/llvm@11/include ++#cgo freebsd CFLAGS: -I/usr/local/llvm11/include ++#cgo linux LDFLAGS: -L/usr/lib/llvm-11/lib -lclang ++#cgo darwin LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi ++#cgo freebsd LDFLAGS: -L/usr/local/llvm11/lib -lclang ++*/ ++import "C" +diff --git a/go.mod b/go.mod +index 6887936..98a2ab9 100644 +--- a/go.mod ++++ b/go.mod +@@ -10,5 +10,5 @@ require ( + github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 + go.bug.st/serial v1.0.0 + golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 +- tinygo.org/x/go-llvm v0.0.0-20200503225853-345b2947b59d ++ tinygo.org/x/go-llvm v0.0.0-20200503224449-70c558526021 + ) +diff --git a/go.sum b/go.sum +index c24491e..9ceebac 100644 +--- a/go.sum ++++ b/go.sum +@@ -46,5 +46,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbO + golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= + gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +-tinygo.org/x/go-llvm v0.0.0-20200503225853-345b2947b59d h1:hcX7vpB067GWM/EH4sGGOti0PMgIx+0bbZwUXctOIvE= +-tinygo.org/x/go-llvm v0.0.0-20200503225853-345b2947b59d/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= ++tinygo.org/x/go-llvm v0.0.0-20200503224449-70c558526021 h1:d8T98WXGjrTgDmMXgxa6nb9EAYXGXwnzXygnJl6d+ac= ++tinygo.org/x/go-llvm v0.0.0-20200503224449-70c558526021/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= +diff --git a/interp/interp_test.go b/interp/interp_test.go +index 6b0cc38..dba7387 100644 +--- a/interp/interp_test.go ++++ b/interp/interp_test.go +@@ -3,6 +3,7 @@ package interp + import ( + "io/ioutil" + "os" ++ "regexp" + "strings" + "testing" + +@@ -66,6 +67,8 @@ func runTest(t *testing.T, pathPrefix string) { + } + } + ++var alignRegexp = regexp.MustCompile(", align [0-9]+$") ++ + // fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly + // equal. That means, only relevant lines are compared (excluding comments + // etc.). +@@ -75,8 +78,18 @@ func fuzzyEqualIR(s1, s2 string) bool { + if len(lines1) != len(lines2) { + return false + } +- for i, line := range lines1 { +- if line != lines2[i] { ++ for i, line1 := range lines1 { ++ line2 := lines2[i] ++ match1 := alignRegexp.MatchString(line1) ++ match2 := alignRegexp.MatchString(line2) ++ if match1 != match2 { ++ // Only one of the lines has the align keyword. Remove it. ++ // This is a change to make the test work in both LLVM 10 and LLVM ++ // 11 (LLVM 11 appears to automatically add alignment everywhere). ++ line1 = alignRegexp.ReplaceAllString(line1, "") ++ line2 = alignRegexp.ReplaceAllString(line2, "") ++ } ++ if line1 != line2 { + return false + } + } +diff --git a/targets/gameboy-advance.ld b/targets/gameboy-advance.ld +index 8b35042..566f78e 100644 +--- a/targets/gameboy-advance.ld ++++ b/targets/gameboy-advance.ld +@@ -19,6 +19,7 @@ SECTIONS + { + KEEP (*(.init)) + *(.text) ++ *(.text.*) + . = ALIGN(4); + } >rom + +@@ -26,7 +27,7 @@ SECTIONS + { + . = ALIGN(4); + *(.rodata) +- *(.rodata*) ++ *(.rodata.*) + . = ALIGN(4); + } >rom + +@@ -51,7 +52,7 @@ SECTIONS + . = ALIGN(4); + _sdata = .; /* used by startup code */ + *(.data) +- *(.data*) ++ *(.data.*) + *(.iwram .iwram.*) + . = ALIGN(4); + _edata = .; /* used by startup code */ +@@ -63,7 +64,7 @@ SECTIONS + . = ALIGN(4); + _sbss = .; /* used by startup code */ + *(.bss) +- *(.bss*) ++ *(.bss.*) + *(COMMON) + . = ALIGN(4); + _ebss = .; /* used by startup code */ +diff --git a/transform/globals.go b/transform/globals.go +index 89386fd..7a29683 100644 +--- a/transform/globals.go ++++ b/transform/globals.go +@@ -31,3 +31,17 @@ func NonConstGlobals(mod llvm.Module) { + global = llvm.NextGlobal(global) + } + } ++ ++// DisableTailCalls adds the "disable-tail-calls"="true" function attribute to ++// all functions. This may be necessary, in particular to avoid an error with ++// WebAssembly in LLVM 11. ++func DisableTailCalls(mod llvm.Module) { ++ attribute := mod.Context().CreateStringAttribute("disable-tail-calls", "true") ++ llvmFn := mod.FirstFunction() ++ for !llvmFn.IsNil() { ++ if !llvmFn.IsDeclaration() { ++ llvmFn.AddFunctionAttr(attribute) ++ } ++ llvmFn = llvm.NextFunction(llvmFn) ++ } ++} +diff --git a/transform/transform_test.go b/transform/transform_test.go +index 7a607f1..28faf86 100644 +--- a/transform/transform_test.go ++++ b/transform/transform_test.go +@@ -61,6 +61,8 @@ func testTransform(t *testing.T, pathPrefix string, transform func(mod llvm.Modu + } + } + ++var alignRegexp = regexp.MustCompile(", align [0-9]+$") ++ + // fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly + // equal. That means, only relevant lines are compared (excluding comments + // etc.). +@@ -70,8 +72,18 @@ func fuzzyEqualIR(s1, s2 string) bool { + if len(lines1) != len(lines2) { + return false + } +- for i, line := range lines1 { +- if line != lines2[i] { ++ for i, line1 := range lines1 { ++ line2 := lines2[i] ++ match1 := alignRegexp.MatchString(line1) ++ match2 := alignRegexp.MatchString(line2) ++ if match1 != match2 { ++ // Only one of the lines has the align keyword. Remove it. ++ // This is a change to make the test work in both LLVM 10 and LLVM ++ // 11 (LLVM 11 appears to automatically add alignment everywhere). ++ line1 = alignRegexp.ReplaceAllString(line1, "") ++ line2 = alignRegexp.ReplaceAllString(line2, "") ++ } ++ if line1 != line2 { + return false + } + } +-- +2.26.2 + diff --git a/tinygo.spec b/tinygo.spec index 7b3dee6..013559c 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,11 +10,15 @@ Version: 0.15.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%if %{fedora} > 32 +%global clang_version 11 +%else %if %{fedora} > 31 %global clang_version 10 %else %global clang_version 9 %endif +%endif %global cmsis_svd_commit d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd %global compiler_rt_version 9.0.0 %global nrfx_commit 3ab39a9d457bfe627473ed0e03a7f1161d9e4f27 @@ -66,6 +70,8 @@ Patch0002: 0002-Skip-ARM-Linux-tests.patch Patch0003: 0003-Skip-STM32-tests.patch # https://github.com/tinygo-org/tinygo/pull/1399 Patch0004: 0004-Also-check-lib64-for-clang-include-path.patch +# https://github.com/tinygo-org/tinygo/pull/1056 +Patch0005: 0005-main-add-initial-support-for-in-development-LLVM-11.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -112,6 +118,7 @@ Recommends: qemu-system-arm-core %patch0002 -p1 %patch0003 -p1 %patch0004 -p1 +%patch0005 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS