From 118877d6c88e966f15d83c56d35bdac7e2eb1a43 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 2 Oct 2020 05:15:25 -0400 Subject: [PATCH 01/78] Skip wasm tests on 32-bit x86. The Chrome driver package is broken and times out. --- tinygo.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index 013559c..b8d53c2 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -76,11 +76,13 @@ Patch0005: 0005-main-add-initial-support-for-in-development-LLVM-11.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x -BuildRequires: chromium BuildRequires: (clang-devel >= %{clang_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_version}')) + 1)}) BuildRequires: golang(github.com/blakesmith/ar) +%ifnarch %{ix86} +BuildRequires: chromium BuildRequires: golang(github.com/chromedp/chromedp) BuildRequires: golang(github.com/chromedp/cdproto/cdp) +%endif BuildRequires: golang(github.com/google/shlex) BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(go.bug.st/serial) @@ -211,8 +213,10 @@ export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off %gocheck -v -d tests/tinygotest make smoketest XTENSA=0 +%ifnarch %{ix86} make wasmtest %endif +%endif %files From 22683d9b428010f9dfc608fe1527dd09df22f48e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 4 Oct 2020 06:26:25 -0400 Subject: [PATCH 02/78] Workaround annobin brokenness on i686. --- 0001-Use-Fedora-command-names.patch | 2 +- 0002-Skip-ARM-Linux-tests.patch | 2 +- 0003-Skip-STM32-tests.patch | 2 +- ...o-check-lib64-for-clang-include-path.patch | 2 +- ...l-support-for-in-development-LLVM-11.patch | 2 +- ...clang-include-path-check-more-robust.patch | 84 +++++++++++++++++++ tinygo.spec | 3 + 7 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 0006-Make-lib64-clang-include-path-check-more-robust.patch diff --git a/0001-Use-Fedora-command-names.patch b/0001-Use-Fedora-command-names.patch index 9499d67..350c952 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/5] Use Fedora command names. +Subject: [PATCH 1/6] 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 08440fb..a2c3dd3 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/5] Skip ARM Linux tests. +Subject: [PATCH 2/6] 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 fbc9827..4449028 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/5] Skip STM32 tests. +Subject: [PATCH 3/6] 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 4d3887c..3e1972f 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/5] Also check lib64 for clang include path. +Subject: [PATCH 4/6] 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 index 04645cf..495b8b0 100644 --- a/0005-main-add-initial-support-for-in-development-LLVM-11.patch +++ b/0005-main-add-initial-support-for-in-development-LLVM-11.patch @@ -1,7 +1,7 @@ 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 +Subject: [PATCH 5/6] 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 diff --git a/0006-Make-lib64-clang-include-path-check-more-robust.patch b/0006-Make-lib64-clang-include-path-check-more-robust.patch new file mode 100644 index 0000000..8aec989 --- /dev/null +++ b/0006-Make-lib64-clang-include-path-check-more-robust.patch @@ -0,0 +1,84 @@ +From b2fa3dbb22aa48cbd8e26487beb2b9312d80eb81 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 4 Oct 2020 02:51:46 -0400 +Subject: [PATCH 6/6] Make lib64 clang include path check more robust. + +On Fedora 33+, there is a buggy package that installs to +`/usr/lib64/clang/{version}/lib`, even on 32-bit systems. The original +code sees the `/usr/lib64/clang/{version}` directory, checks for an +`include` subdirectory, and then gives up because it doesn't exist. + +To be more robust, check both `/usr/lib64/clang/{version}/include` and +`/usr/lib/clang/{version}/include`, sorted by version subdirectory. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/env.go | 42 +++++++++++++++++++++++++++++------------- + 1 file changed, 29 insertions(+), 13 deletions(-) + +diff --git a/builder/env.go b/builder/env.go +index 91bc263..dde3504 100644 +--- a/builder/env.go ++++ b/builder/env.go +@@ -6,6 +6,7 @@ import ( + "os/exec" + "path/filepath" + "sort" ++ "strings" + ) + + // getClangHeaderPath returns the path to the built-in Clang headers. It tries +@@ -43,22 +44,37 @@ func getClangHeaderPath(TINYGOROOT string) string { + // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ + llvmRoot := filepath.Dir(filepath.Dir(binpath)) + clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") +- dirs, err := ioutil.ReadDir(clangVersionRoot) +- if err != nil { +- // Example include path: +- // /usr/lib/llvm-9/lib/clang/9.0.1/include/ +- clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") +- dirs, err = ioutil.ReadDir(clangVersionRoot) +- if err != nil { +- // Unexpected. +- continue +- } ++ dirs64, err64 := ioutil.ReadDir(clangVersionRoot) ++ // Example include path: ++ // /usr/lib/llvm-9/lib/clang/9.0.1/include/ ++ clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") ++ dirs32, err32 := ioutil.ReadDir(clangVersionRoot) ++ if err64 != nil && err32 != nil { ++ // Unexpected. ++ continue + } +- dirnames := make([]string, len(dirs)) +- for i, d := range dirs { ++ dirnames := make([]string, len(dirs64)+len(dirs32)) ++ for i, d := range dirs32 { + dirnames[i] = d.Name() + } +- sort.Strings(dirnames) ++ for i, d := range dirs64 { ++ dirnames[len(dirs32)+i] = d.Name() ++ } ++ sort.SliceStable(dirnames, func(i, j int) bool { ++ // Sort by version directory, normalizing version components to 3 digits; ++ // stable sort ensures that lib64 remains after lib. ++ getNormalizedVersion := func(index int) string { ++ _, version := filepath.Split(dirnames[index]) ++ parts := strings.Split(version, ".") ++ for i := range parts { ++ for len(parts[i]) < 3 { ++ parts[i] = "0" + parts[i] ++ } ++ } ++ return strings.Join(parts, ".") ++ } ++ return getNormalizedVersion(i) < getNormalizedVersion(j) ++ }) + // Check for the highest version first. + for i := len(dirnames) - 1; i >= 0; i-- { + path := filepath.Join(clangVersionRoot, dirnames[i], "include") +-- +2.26.2 + diff --git a/tinygo.spec b/tinygo.spec index b8d53c2..e6d3b4a 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -73,6 +73,8 @@ 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 +Patch0006: 0006-Make-lib64-clang-include-path-check-more-robust.patch + # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -121,6 +123,7 @@ Recommends: qemu-system-arm-core %patch0003 -p1 %patch0004 -p1 %patch0005 -p1 +%patch0006 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS From 4ee622c82b11a5052943da91f555f484795a04f8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 4 Oct 2020 18:33:01 -0400 Subject: [PATCH 03/78] Fix annobin workaround to work properly. --- ...clang-include-path-check-more-robust.patch | 29 +++++++++++-------- tinygo.spec | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/0006-Make-lib64-clang-include-path-check-more-robust.patch b/0006-Make-lib64-clang-include-path-check-more-robust.patch index 8aec989..1587772 100644 --- a/0006-Make-lib64-clang-include-path-check-more-robust.patch +++ b/0006-Make-lib64-clang-include-path-check-more-robust.patch @@ -1,4 +1,4 @@ -From b2fa3dbb22aa48cbd8e26487beb2b9312d80eb81 Mon Sep 17 00:00:00 2001 +From ffd6037f1c765686ea6d02e9f9fb599ed284f5be Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 4 Oct 2020 02:51:46 -0400 Subject: [PATCH 6/6] Make lib64 clang include path check more robust. @@ -13,11 +13,11 @@ To be more robust, check both `/usr/lib64/clang/{version}/include` and Signed-off-by: Elliott Sales de Andrade --- - builder/env.go | 42 +++++++++++++++++++++++++++++------------- - 1 file changed, 29 insertions(+), 13 deletions(-) + builder/env.go | 46 +++++++++++++++++++++++++++++++--------------- + 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/builder/env.go b/builder/env.go -index 91bc263..dde3504 100644 +index 91bc263..c93e988 100644 --- a/builder/env.go +++ b/builder/env.go @@ -6,6 +6,7 @@ import ( @@ -28,7 +28,7 @@ index 91bc263..dde3504 100644 ) // getClangHeaderPath returns the path to the built-in Clang headers. It tries -@@ -43,22 +44,37 @@ func getClangHeaderPath(TINYGOROOT string) string { +@@ -43,25 +44,40 @@ func getClangHeaderPath(TINYGOROOT string) string { // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ llvmRoot := filepath.Dir(filepath.Dir(binpath)) clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") @@ -50,17 +50,18 @@ index 91bc263..dde3504 100644 + if err64 != nil && err32 != nil { + // Unexpected. + continue ++ } ++ dirnames := make([]string, len(dirs64)+len(dirs32)) ++ for i, d := range dirs32 { ++ dirnames[i] = filepath.Join(llvmRoot, "lib", "clang", d.Name()) } - dirnames := make([]string, len(dirs)) - for i, d := range dirs { -+ dirnames := make([]string, len(dirs64)+len(dirs32)) -+ for i, d := range dirs32 { - dirnames[i] = d.Name() +- dirnames[i] = d.Name() ++ for i, d := range dirs64 { ++ dirnames[len(dirs32)+i] = filepath.Join(llvmRoot, "lib64", "clang", d.Name()) } - sort.Strings(dirnames) -+ for i, d := range dirs64 { -+ dirnames[len(dirs32)+i] = d.Name() -+ } + sort.SliceStable(dirnames, func(i, j int) bool { + // Sort by version directory, normalizing version components to 3 digits; + // stable sort ensures that lib64 remains after lib. @@ -78,7 +79,11 @@ index 91bc263..dde3504 100644 + }) // Check for the highest version first. for i := len(dirnames) - 1; i >= 0; i-- { - path := filepath.Join(clangVersionRoot, dirnames[i], "include") +- path := filepath.Join(clangVersionRoot, dirnames[i], "include") ++ path := filepath.Join(dirnames[i], "include") + _, err := os.Stat(filepath.Join(path, "stdint.h")) + if err == nil { + return path -- 2.26.2 diff --git a/tinygo.spec b/tinygo.spec index e6d3b4a..98bd5af 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -72,7 +72,7 @@ Patch0003: 0003-Skip-STM32-tests.patch 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 - +# https://github.com/tinygo-org/tinygo/pull/1424 Patch0006: 0006-Make-lib64-clang-include-path-check-more-robust.patch # Not supported upstream yet. From 6084b0a02166cab734a38036862564a5e375a175 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 30 Oct 2020 03:38:28 -0400 Subject: [PATCH 04/78] Shorten gitignore. --- .gitignore | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6a8bae4..7b822bc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ /cmsis_svd-*-clean.tar.xz /compiler-rt-*.src.tar.xz /nrfx-*.tar.gz +/picolibc-*.tar.gz +/wasi-libc-*.tar.gz /tinygo-0.6.0.tar.gz /tinygo-0.7.0.tar.gz /tinygo-0.7.1.tar.gz @@ -13,11 +15,8 @@ /tinygo-0.10.0.tar.gz /tinygo-0.11.0.tar.gz /tinygo-0.12.0.tar.gz -/wasi-libc-a280fead2ae71b9a230d3b48c1f95867431888e4.tar.gz /tinygo-0.13.0.tar.gz -/picolibc-80528c684b10aaee977397e7eb40c4784e6dc433.tar.gz /tinygo-0.13.1.tar.gz /tinygo-0.14.0.tar.gz /tinygo-0.14.1.tar.gz /tinygo-0.15.0.tar.gz -/wasi-libc-215adc8ac9f91eb055311acc72683fd2eb1ae15a.tar.gz From b854f98fa61e756e1df50e88cfe3bda9b05724aa Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 17 Dec 2020 01:54:18 -0500 Subject: [PATCH 05/78] update to latest version. --- .gitignore | 1 + 0001-Use-Fedora-command-names.patch | 30 +- 0002-Skip-ARM-Linux-tests.patch | 16 +- 0003-Skip-STM32-tests.patch | 16 +- ...o-check-lib64-for-clang-include-path.patch | 45 --- 0004-Skip-WASI-tests.patch | 30 ++ ...l-support-for-in-development-LLVM-11.patch | 270 ------------------ ...clang-include-path-check-more-robust.patch | 89 ------ sources | 2 +- tinygo.spec | 20 +- 10 files changed, 69 insertions(+), 450 deletions(-) delete mode 100644 0004-Also-check-lib64-for-clang-include-path.patch create mode 100644 0004-Skip-WASI-tests.patch delete mode 100644 0005-main-add-initial-support-for-in-development-LLVM-11.patch delete mode 100644 0006-Make-lib64-clang-include-path-check-more-robust.patch diff --git a/.gitignore b/.gitignore index 7b822bc..213c4e6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ /tinygo-0.14.0.tar.gz /tinygo-0.14.1.tar.gz /tinygo-0.15.0.tar.gz +/tinygo-0.16.0.tar.gz diff --git a/0001-Use-Fedora-command-names.patch b/0001-Use-Fedora-command-names.patch index 350c952..ac2d474 100644 --- a/0001-Use-Fedora-command-names.patch +++ b/0001-Use-Fedora-command-names.patch @@ -1,19 +1,19 @@ -From 845a1e4c9d7456d2a914e540ad6c8a7f9d684aa6 Mon Sep 17 00:00:00 2001 +From d12f535f6e41d821d7ddb3f24677ce2b071ba590 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 7 Jun 2019 20:55:25 -0400 -Subject: [PATCH 1/6] Use Fedora command names. +Subject: [PATCH 1/4] Use Fedora command names. Signed-off-by: Elliott Sales de Andrade --- - compileopts/target.go | 10 +++++----- - main_test.go | 2 +- - 2 files changed, 6 insertions(+), 6 deletions(-) + compileopts/target.go | 8 ++++---- + main_test.go | 2 +- + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 6547320..d7f8390 100644 +index 8b3c68f..53b3b61 100644 --- a/compileopts/target.go +++ b/compileopts/target.go -@@ -226,7 +226,7 @@ func LoadTarget(target string) (*TargetSpec, error) { +@@ -174,7 +174,7 @@ func LoadTarget(target string) (*TargetSpec, error) { } target = llvmarch + "--" + llvmos if goarch == "arm" { @@ -22,28 +22,26 @@ index 6547320..d7f8390 100644 } return defaultTarget(goos, goarch, target) } -@@ -302,10 +302,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - if goarch != runtime.GOARCH { +@@ -254,9 +254,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { // Some educated guesses as to how to invoke helper programs. + spec.GDB = "gdb-multiarch" if goarch == "arm" && goos == "linux" { - spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") - spec.Linker = "arm-linux-gnueabihf-gcc" -- spec.GDB = "arm-linux-gnueabihf-gdb" - spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} + spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-none") + spec.Linker = "arm-linux-gnu-gcc" -+ spec.GDB = "arm-linux-gnu-gdb" + spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-none"} } if goarch == "arm64" && goos == "linux" { spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") diff --git a/main_test.go b/main_test.go -index f66117b..3c31e21 100644 +index a7eca14..f8285a2 100644 --- a/main_test.go +++ b/main_test.go -@@ -79,7 +79,7 @@ func TestCompiler(t *testing.T) { - - if runtime.GOOS == "linux" { +@@ -82,7 +82,7 @@ func TestCompiler(t *testing.T) { + runPlatTests("i386--linux-gnu", matches, t) + }) t.Run("ARMLinux", func(t *testing.T) { - runPlatTests("arm--linux-gnueabihf", matches, t) + runPlatTests("arm--linux-none", matches, t) @@ -51,5 +49,5 @@ index f66117b..3c31e21 100644 t.Run("ARM64Linux", func(t *testing.T) { runPlatTests("aarch64--linux-gnu", matches, t) -- -2.26.2 +2.29.2 diff --git a/0002-Skip-ARM-Linux-tests.patch b/0002-Skip-ARM-Linux-tests.patch index a2c3dd3..347c576 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 af52d3bdf25e9f318003c4fc39845fc3e9257a43 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Jun 2019 04:28:55 -0400 -Subject: [PATCH 2/6] Skip ARM Linux tests. +Subject: [PATCH 2/4] Skip ARM Linux tests. We don't have the C library to do this. @@ -11,13 +11,13 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 6 deletions(-) diff --git a/main_test.go b/main_test.go -index 3c31e21..47a0e6b 100644 +index f8285a2..efeb2db 100644 --- a/main_test.go +++ b/main_test.go -@@ -78,12 +78,6 @@ func TestCompiler(t *testing.T) { - } - - if runtime.GOOS == "linux" { +@@ -81,12 +81,6 @@ func TestCompiler(t *testing.T) { + t.Run("X86Linux", func(t *testing.T) { + runPlatTests("i386--linux-gnu", matches, t) + }) - t.Run("ARMLinux", func(t *testing.T) { - runPlatTests("arm--linux-none", matches, t) - }) @@ -28,5 +28,5 @@ index 3c31e21..47a0e6b 100644 if err != nil { t.Error("could not get Go version:", err) -- -2.26.2 +2.29.2 diff --git a/0003-Skip-STM32-tests.patch b/0003-Skip-STM32-tests.patch index 4449028..bdd50fe 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 307770eb5da848e0f62fc8d02ff51b5ea8767bb7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Jun 2019 02:50:40 -0400 -Subject: [PATCH 3/6] Skip STM32 tests. +Subject: [PATCH 3/4] Skip STM32 tests. We can't ship the STM32 .svd files due to their odd license. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Makefile b/Makefile -index e59799c..9e6b571 100644 +index 660975e..ae41b06 100644 --- a/Makefile +++ b/Makefile -@@ -118,7 +118,7 @@ fmt-check: +@@ -103,7 +103,7 @@ fmt-check: @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 @@ -23,7 +23,7 @@ index e59799c..9e6b571 100644 gen-device-avr: @if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi -@@ -257,8 +257,6 @@ smoketest: +@@ -249,8 +249,6 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=pca10031 examples/blinky1 @$(MD5SUM) test.hex @@ -32,7 +32,7 @@ index e59799c..9e6b571 100644 $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky1 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky2 -@@ -275,14 +273,6 @@ smoketest: +@@ -267,14 +265,6 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/blinky1 @$(MD5SUM) test.hex @@ -47,7 +47,7 @@ index e59799c..9e6b571 100644 $(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s -@@ -307,8 +297,6 @@ smoketest: +@@ -299,8 +289,6 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=particle-xenon examples/blinky1 @$(MD5SUM) test.hex @@ -57,5 +57,5 @@ index e59799c..9e6b571 100644 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=x9pro examples/blinky1 -- -2.26.2 +2.29.2 diff --git a/0004-Also-check-lib64-for-clang-include-path.patch b/0004-Also-check-lib64-for-clang-include-path.patch deleted file mode 100644 index 3e1972f..0000000 --- a/0004-Also-check-lib64-for-clang-include-path.patch +++ /dev/null @@ -1,45 +0,0 @@ -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/6] 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 -check that first. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/env.go | 14 ++++++++++---- - 1 file changed, 10 insertions(+), 4 deletions(-) - -diff --git a/builder/env.go b/builder/env.go -index c59f5df..91bc263 100644 ---- a/builder/env.go -+++ b/builder/env.go -@@ -40,13 +40,19 @@ func getClangHeaderPath(TINYGOROOT string) string { - // Example executable: - // /usr/lib/llvm-9/bin/clang - // Example include path: -- // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -+ // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ - llvmRoot := filepath.Dir(filepath.Dir(binpath)) -- clangVersionRoot := filepath.Join(llvmRoot, "lib", "clang") -+ clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") - dirs, err := ioutil.ReadDir(clangVersionRoot) - if err != nil { -- // Unexpected. -- continue -+ // Example include path: -+ // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -+ clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") -+ dirs, err = ioutil.ReadDir(clangVersionRoot) -+ if err != nil { -+ // Unexpected. -+ continue -+ } - } - dirnames := make([]string, len(dirs)) - for i, d := range dirs { --- -2.26.2 - diff --git a/0004-Skip-WASI-tests.patch b/0004-Skip-WASI-tests.patch new file mode 100644 index 0000000..feaaf83 --- /dev/null +++ b/0004-Skip-WASI-tests.patch @@ -0,0 +1,30 @@ +From 82d01abd2fe82e0e19678721388d4068fe0de7d0 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 15 Dec 2020 05:06:04 -0500 +Subject: [PATCH 4/4] Skip WASI tests. + +We do not have wasmtime available. + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/main_test.go b/main_test.go +index efeb2db..d2cbba3 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -95,10 +95,6 @@ func TestCompiler(t *testing.T) { + runPlatTests("wasm", matches, t) + }) + } +- +- t.Run("WASI", func(t *testing.T) { +- runPlatTests("wasi", matches, t) +- }) + } + } + +-- +2.29.2 + 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 deleted file mode 100644 index 495b8b0..0000000 --- a/0005-main-add-initial-support-for-in-development-LLVM-11.patch +++ /dev/null @@ -1,270 +0,0 @@ -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/6] 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/0006-Make-lib64-clang-include-path-check-more-robust.patch b/0006-Make-lib64-clang-include-path-check-more-robust.patch deleted file mode 100644 index 1587772..0000000 --- a/0006-Make-lib64-clang-include-path-check-more-robust.patch +++ /dev/null @@ -1,89 +0,0 @@ -From ffd6037f1c765686ea6d02e9f9fb599ed284f5be Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 4 Oct 2020 02:51:46 -0400 -Subject: [PATCH 6/6] Make lib64 clang include path check more robust. - -On Fedora 33+, there is a buggy package that installs to -`/usr/lib64/clang/{version}/lib`, even on 32-bit systems. The original -code sees the `/usr/lib64/clang/{version}` directory, checks for an -`include` subdirectory, and then gives up because it doesn't exist. - -To be more robust, check both `/usr/lib64/clang/{version}/include` and -`/usr/lib/clang/{version}/include`, sorted by version subdirectory. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/env.go | 46 +++++++++++++++++++++++++++++++--------------- - 1 file changed, 31 insertions(+), 15 deletions(-) - -diff --git a/builder/env.go b/builder/env.go -index 91bc263..c93e988 100644 ---- a/builder/env.go -+++ b/builder/env.go -@@ -6,6 +6,7 @@ import ( - "os/exec" - "path/filepath" - "sort" -+ "strings" - ) - - // getClangHeaderPath returns the path to the built-in Clang headers. It tries -@@ -43,25 +44,40 @@ func getClangHeaderPath(TINYGOROOT string) string { - // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ - llvmRoot := filepath.Dir(filepath.Dir(binpath)) - clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") -- dirs, err := ioutil.ReadDir(clangVersionRoot) -- if err != nil { -- // Example include path: -- // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -- clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") -- dirs, err = ioutil.ReadDir(clangVersionRoot) -- if err != nil { -- // Unexpected. -- continue -- } -+ dirs64, err64 := ioutil.ReadDir(clangVersionRoot) -+ // Example include path: -+ // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -+ clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") -+ dirs32, err32 := ioutil.ReadDir(clangVersionRoot) -+ if err64 != nil && err32 != nil { -+ // Unexpected. -+ continue -+ } -+ dirnames := make([]string, len(dirs64)+len(dirs32)) -+ for i, d := range dirs32 { -+ dirnames[i] = filepath.Join(llvmRoot, "lib", "clang", d.Name()) - } -- dirnames := make([]string, len(dirs)) -- for i, d := range dirs { -- dirnames[i] = d.Name() -+ for i, d := range dirs64 { -+ dirnames[len(dirs32)+i] = filepath.Join(llvmRoot, "lib64", "clang", d.Name()) - } -- sort.Strings(dirnames) -+ sort.SliceStable(dirnames, func(i, j int) bool { -+ // Sort by version directory, normalizing version components to 3 digits; -+ // stable sort ensures that lib64 remains after lib. -+ getNormalizedVersion := func(index int) string { -+ _, version := filepath.Split(dirnames[index]) -+ parts := strings.Split(version, ".") -+ for i := range parts { -+ for len(parts[i]) < 3 { -+ parts[i] = "0" + parts[i] -+ } -+ } -+ return strings.Join(parts, ".") -+ } -+ return getNormalizedVersion(i) < getNormalizedVersion(j) -+ }) - // Check for the highest version first. - for i := len(dirnames) - 1; i >= 0; i-- { -- path := filepath.Join(clangVersionRoot, dirnames[i], "include") -+ path := filepath.Join(dirnames[i], "include") - _, err := os.Stat(filepath.Join(path, "stdint.h")) - if err == nil { - return path --- -2.26.2 - diff --git a/sources b/sources index 2d3ee7a..043e498 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.15.0.tar.gz) = f23b705bdbe8ba9e426aeee1fb6095c74d9e4ed8f55db83475627f9932a64411a167a4cb9b4fb3f4be4ee769ad4b4c61dfc7c4db2adf6adbe0b1162789f4caa6 +SHA512 (tinygo-0.16.0.tar.gz) = fa17cbd92d2c3961df1dcb5e906070f391ce0485111f5190b812dd7b2098a4a86b657bcc4b1edb19cd7fb707824f6fc719d8554669ba806b23e9f38518fd4cc6 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd-clean.tar.xz) = f3040f089e0714aa7d8b234a0becf8ca77934e9aa6510ff56f68add2881ade1f52176b461fbdf6218df077f3bf66505ca4d1ef94d03d28dfad1b53801dbfc88f diff --git a/tinygo.spec b/tinygo.spec index 98bd5af..e95bef4 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,18 +6,14 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.15.0 +Version: 0.16.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 @@ -68,12 +64,8 @@ Patch0001: 0001-Use-Fedora-command-names.patch Patch0002: 0002-Skip-ARM-Linux-tests.patch # We can't include STM32 .svd files because of their weird license. 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 -# https://github.com/tinygo-org/tinygo/pull/1424 -Patch0006: 0006-Make-lib64-clang-include-path-check-more-robust.patch +# We don't have wasmtime to run these. +Patch0004: 0004-Skip-WASI-tests.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -94,6 +86,10 @@ BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: avr-gcc BuildRequires: avr-libc +BuildRequires: glibc-devel +%ifarch x86_64 +BuildRequires: glibc-devel(x86-32) +%endif # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu @@ -122,8 +118,6 @@ Recommends: qemu-system-arm-core %patch0002 -p1 %patch0003 -p1 %patch0004 -p1 -%patch0005 -p1 -%patch0006 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS From f1635eba955402db5190781b3d5bc29e0b9d2e9b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 17 Dec 2020 05:20:50 -0500 Subject: [PATCH 06/78] Only run i386 tests on GOARCH 386 systems. Since koji does not support multilib, we cannot even run this on x86_64. --- 0001-Use-Fedora-command-names.patch | 2 +- 0002-Skip-ARM-Linux-tests.patch | 2 +- 0003-Skip-STM32-tests.patch | 2 +- 0004-Skip-WASI-tests.patch | 2 +- ...run-i386-tests-on-GOARCH-386-systems.patch | 35 +++++++++++++++++++ tinygo.spec | 7 ++-- 6 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 0005-Only-run-i386-tests-on-GOARCH-386-systems.patch diff --git a/0001-Use-Fedora-command-names.patch b/0001-Use-Fedora-command-names.patch index ac2d474..99c17ec 100644 --- a/0001-Use-Fedora-command-names.patch +++ b/0001-Use-Fedora-command-names.patch @@ -1,7 +1,7 @@ From d12f535f6e41d821d7ddb3f24677ce2b071ba590 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 347c576..74cbf61 100644 --- a/0002-Skip-ARM-Linux-tests.patch +++ b/0002-Skip-ARM-Linux-tests.patch @@ -1,7 +1,7 @@ From af52d3bdf25e9f318003c4fc39845fc3e9257a43 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 bdd50fe..99972c6 100644 --- a/0003-Skip-STM32-tests.patch +++ b/0003-Skip-STM32-tests.patch @@ -1,7 +1,7 @@ From 307770eb5da848e0f62fc8d02ff51b5ea8767bb7 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-Skip-WASI-tests.patch b/0004-Skip-WASI-tests.patch index feaaf83..b311522 100644 --- a/0004-Skip-WASI-tests.patch +++ b/0004-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 82d01abd2fe82e0e19678721388d4068fe0de7d0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 4/4] Skip WASI tests. +Subject: [PATCH 4/5] Skip WASI tests. We do not have wasmtime available. diff --git a/0005-Only-run-i386-tests-on-GOARCH-386-systems.patch b/0005-Only-run-i386-tests-on-GOARCH-386-systems.patch new file mode 100644 index 0000000..3eb1bf0 --- /dev/null +++ b/0005-Only-run-i386-tests-on-GOARCH-386-systems.patch @@ -0,0 +1,35 @@ +From 989c5abeeb8fe05bd164b3794f31c470d497ae41 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Thu, 17 Dec 2020 05:05:47 -0500 +Subject: [PATCH 5/5] Only run i386 tests on GOARCH=386 systems. + +Builds on koji do not work for this because it does not support +multilib. + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/main_test.go b/main_test.go +index d2cbba3..524d653 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -78,9 +78,11 @@ func TestCompiler(t *testing.T) { + } + + if runtime.GOOS == "linux" { +- t.Run("X86Linux", func(t *testing.T) { +- runPlatTests("i386--linux-gnu", matches, t) +- }) ++ if runtime.GOARCH == "386" { ++ t.Run("X86Linux", func(t *testing.T) { ++ runPlatTests("i386--linux-gnu", matches, t) ++ }) ++ } + goVersion, err := goenv.GorootVersionString(goenv.Get("GOROOT")) + if err != nil { + t.Error("could not get Go version:", err) +-- +2.29.2 + diff --git a/tinygo.spec b/tinygo.spec index e95bef4..70b0fa1 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -66,6 +66,8 @@ Patch0002: 0002-Skip-ARM-Linux-tests.patch Patch0003: 0003-Skip-STM32-tests.patch # We don't have wasmtime to run these. Patch0004: 0004-Skip-WASI-tests.patch +# koji does not support multilib. +Patch0005: 0005-Only-run-i386-tests-on-GOARCH-386-systems.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -86,10 +88,6 @@ BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: avr-gcc BuildRequires: avr-libc -BuildRequires: glibc-devel -%ifarch x86_64 -BuildRequires: glibc-devel(x86-32) -%endif # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu @@ -118,6 +116,7 @@ Recommends: qemu-system-arm-core %patch0002 -p1 %patch0003 -p1 %patch0004 -p1 +%patch0005 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS From 934e871bb617938c015666371ad53e8d18a7c4cf Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 12 Jan 2021 00:59:34 +0000 Subject: [PATCH 07/78] Add BuildRequires: make https://fedoraproject.org/wiki/Changes/Remove_make_from_BuildRoot --- tinygo.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/tinygo.spec b/tinygo.spec index 70b0fa1..92715dd 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -72,6 +72,7 @@ Patch0005: 0005-Only-run-i386-tests-on-GOARCH-386-systems.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x +BuildRequires: make BuildRequires: (clang-devel >= %{clang_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_version}')) + 1)}) BuildRequires: golang(github.com/blakesmith/ar) %ifnarch %{ix86} From 349460a15384bfa3a297cfd8312c7b01e0b5a40b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 17 Jan 2021 15:15:05 -0500 Subject: [PATCH 08/78] Update to latest version. --- ...tests.patch => 0001-Skip-STM32-tests.patch | 4 +- 0001-Use-Fedora-command-names.patch | 53 ----- 0002-Skip-ARM-Linux-tests.patch | 32 --- ...-tests.patch => 0002-Skip-WASI-tests.patch | 8 +- ...tive-Linux-tests-on-their-own-GOARCH.patch | 54 +++++ 0004-Use-clang-to-do-linking.patch | 51 +++++ ...run-i386-tests-on-GOARCH-386-systems.patch | 35 --- 0005-Update-to-current-chromedp.patch | 108 +++++++++ ...se-httptest-to-serve-wasm-test-files.patch | 210 ++++++++++++++++++ 0007-Add-support-for-Go-1.16.patch | 46 ++++ tinygo.spec | 25 ++- 11 files changed, 491 insertions(+), 135 deletions(-) rename 0003-Skip-STM32-tests.patch => 0001-Skip-STM32-tests.patch (96%) delete mode 100644 0001-Use-Fedora-command-names.patch delete mode 100644 0002-Skip-ARM-Linux-tests.patch rename 0004-Skip-WASI-tests.patch => 0002-Skip-WASI-tests.patch (72%) create mode 100644 0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch create mode 100644 0004-Use-clang-to-do-linking.patch delete mode 100644 0005-Only-run-i386-tests-on-GOARCH-386-systems.patch create mode 100644 0005-Update-to-current-chromedp.patch create mode 100644 0006-Use-httptest-to-serve-wasm-test-files.patch create mode 100644 0007-Add-support-for-Go-1.16.patch diff --git a/0003-Skip-STM32-tests.patch b/0001-Skip-STM32-tests.patch similarity index 96% rename from 0003-Skip-STM32-tests.patch rename to 0001-Skip-STM32-tests.patch index 99972c6..65ac848 100644 --- a/0003-Skip-STM32-tests.patch +++ b/0001-Skip-STM32-tests.patch @@ -1,7 +1,7 @@ -From 307770eb5da848e0f62fc8d02ff51b5ea8767bb7 Mon Sep 17 00:00:00 2001 +From 132dd9354512d0ab47cf3d939dd94ffc492eda5a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Jun 2019 02:50:40 -0400 -Subject: [PATCH 3/5] Skip STM32 tests. +Subject: [PATCH 1/7] Skip STM32 tests. We can't ship the STM32 .svd files due to their odd license. diff --git a/0001-Use-Fedora-command-names.patch b/0001-Use-Fedora-command-names.patch deleted file mode 100644 index 99c17ec..0000000 --- a/0001-Use-Fedora-command-names.patch +++ /dev/null @@ -1,53 +0,0 @@ -From d12f535f6e41d821d7ddb3f24677ce2b071ba590 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Fri, 7 Jun 2019 20:55:25 -0400 -Subject: [PATCH 1/5] Use Fedora command names. - -Signed-off-by: Elliott Sales de Andrade ---- - compileopts/target.go | 8 ++++---- - main_test.go | 2 +- - 2 files changed, 5 insertions(+), 5 deletions(-) - -diff --git a/compileopts/target.go b/compileopts/target.go -index 8b3c68f..53b3b61 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -174,7 +174,7 @@ func LoadTarget(target string) (*TargetSpec, error) { - } - target = llvmarch + "--" + llvmos - if goarch == "arm" { -- target += "-gnueabihf" -+ target += "-none" - } - return defaultTarget(goos, goarch, target) - } -@@ -254,9 +254,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - // Some educated guesses as to how to invoke helper programs. - spec.GDB = "gdb-multiarch" - if goarch == "arm" && goos == "linux" { -- spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") -- spec.Linker = "arm-linux-gnueabihf-gcc" -- spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} -+ spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-none") -+ spec.Linker = "arm-linux-gnu-gcc" -+ spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-none"} - } - if goarch == "arm64" && goos == "linux" { - spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") -diff --git a/main_test.go b/main_test.go -index a7eca14..f8285a2 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -82,7 +82,7 @@ func TestCompiler(t *testing.T) { - runPlatTests("i386--linux-gnu", matches, t) - }) - t.Run("ARMLinux", func(t *testing.T) { -- runPlatTests("arm--linux-gnueabihf", matches, t) -+ runPlatTests("arm--linux-none", matches, t) - }) - t.Run("ARM64Linux", func(t *testing.T) { - runPlatTests("aarch64--linux-gnu", matches, t) --- -2.29.2 - diff --git a/0002-Skip-ARM-Linux-tests.patch b/0002-Skip-ARM-Linux-tests.patch deleted file mode 100644 index 74cbf61..0000000 --- a/0002-Skip-ARM-Linux-tests.patch +++ /dev/null @@ -1,32 +0,0 @@ -From af52d3bdf25e9f318003c4fc39845fc3e9257a43 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Wed, 12 Jun 2019 04:28:55 -0400 -Subject: [PATCH 2/5] Skip ARM Linux tests. - -We don't have the C library to do this. - -Signed-off-by: Elliott Sales de Andrade ---- - main_test.go | 6 ------ - 1 file changed, 6 deletions(-) - -diff --git a/main_test.go b/main_test.go -index f8285a2..efeb2db 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -81,12 +81,6 @@ func TestCompiler(t *testing.T) { - t.Run("X86Linux", func(t *testing.T) { - runPlatTests("i386--linux-gnu", matches, t) - }) -- t.Run("ARMLinux", func(t *testing.T) { -- runPlatTests("arm--linux-none", matches, t) -- }) -- t.Run("ARM64Linux", func(t *testing.T) { -- runPlatTests("aarch64--linux-gnu", matches, t) -- }) - goVersion, err := goenv.GorootVersionString(goenv.Get("GOROOT")) - if err != nil { - t.Error("could not get Go version:", err) --- -2.29.2 - diff --git a/0004-Skip-WASI-tests.patch b/0002-Skip-WASI-tests.patch similarity index 72% rename from 0004-Skip-WASI-tests.patch rename to 0002-Skip-WASI-tests.patch index b311522..1193282 100644 --- a/0004-Skip-WASI-tests.patch +++ b/0002-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 82d01abd2fe82e0e19678721388d4068fe0de7d0 Mon Sep 17 00:00:00 2001 +From 965776292ea372cf2cfd3c0c06c4d9a9e0ca6e03 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 4/5] Skip WASI tests. +Subject: [PATCH 2/7] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 4 deletions(-) diff --git a/main_test.go b/main_test.go -index efeb2db..d2cbba3 100644 +index a7eca14..9c1b6e8 100644 --- a/main_test.go +++ b/main_test.go -@@ -95,10 +95,6 @@ func TestCompiler(t *testing.T) { +@@ -101,10 +101,6 @@ func TestCompiler(t *testing.T) { runPlatTests("wasm", matches, t) }) } diff --git a/0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch new file mode 100644 index 0000000..dd9f532 --- /dev/null +++ b/0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -0,0 +1,54 @@ +From 683e23f406cb59400bc3879eeebef3445666d7bb Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 21 Dec 2020 04:26:02 -0500 +Subject: [PATCH 3/7] Only run native Linux tests on their own GOARCH. + +We don't have the cross-compiled C libraries to do this. Even 386 builds +on koji do not work for this because it does not support multilib. + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 27 ++++++++++++++++++--------- + 1 file changed, 18 insertions(+), 9 deletions(-) + +diff --git a/main_test.go b/main_test.go +index 9c1b6e8..b839cef 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -78,15 +78,24 @@ func TestCompiler(t *testing.T) { + } + + if runtime.GOOS == "linux" { +- t.Run("X86Linux", func(t *testing.T) { +- runPlatTests("i386--linux-gnu", matches, t) +- }) +- t.Run("ARMLinux", func(t *testing.T) { +- runPlatTests("arm--linux-gnueabihf", matches, t) +- }) +- t.Run("ARM64Linux", func(t *testing.T) { +- runPlatTests("aarch64--linux-gnu", matches, t) +- }) ++ switch runtime.GOARCH { ++ case "386": ++ t.Run("X86Linux", func(t *testing.T) { ++ runPlatTests("i386--linux-gnu", matches, t) ++ }) ++ case "amd64": ++ t.Run("AMD64Linux", func(t *testing.T) { ++ runPlatTests("amd64--linux-gnu", matches, t) ++ }) ++ case "arm": ++ t.Run("ARMLinux", func(t *testing.T) { ++ runPlatTests("arm--linux-gnueabihf", matches, t) ++ }) ++ case "arm64": ++ t.Run("ARM64Linux", func(t *testing.T) { ++ runPlatTests("aarch64--linux-gnu", matches, t) ++ }) ++ } + goVersion, err := goenv.GorootVersionString(goenv.Get("GOROOT")) + if err != nil { + t.Error("could not get Go version:", err) +-- +2.29.2 + diff --git a/0004-Use-clang-to-do-linking.patch b/0004-Use-clang-to-do-linking.patch new file mode 100644 index 0000000..ad097f3 --- /dev/null +++ b/0004-Use-clang-to-do-linking.patch @@ -0,0 +1,51 @@ +From 99cad3f2957e1698a0c4ab1330354800dce2abdf Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 21 Dec 2020 04:28:59 -0500 +Subject: [PATCH 4/7] Use clang to do linking. + +This avoids having to guess what the linker name-with-build-triplet is, +as we can just pass the target to it in the same way as the compilation +stage. + +Signed-off-by: Elliott Sales de Andrade +--- + compileopts/target.go | 9 ++------- + 1 file changed, 2 insertions(+), 7 deletions(-) + +diff --git a/compileopts/target.go b/compileopts/target.go +index 8b3c68f..f1aab68 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -237,8 +237,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + GOARCH: goarch, + BuildTags: []string{goos, goarch}, + Compiler: "clang", +- Linker: "cc", + CFlags: []string{"--target=" + triple}, ++ Linker: "clang", ++ LDFlags: []string{"--target=" + triple}, + GDB: "gdb", + PortReset: "false", + } +@@ -255,18 +256,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + spec.GDB = "gdb-multiarch" + if goarch == "arm" && goos == "linux" { + spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") +- spec.Linker = "arm-linux-gnueabihf-gcc" + spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} + } + if goarch == "arm64" && goos == "linux" { + spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") +- spec.Linker = "aarch64-linux-gnu-gcc" + spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"} + } +- if goarch == "386" && runtime.GOARCH == "amd64" { +- spec.CFlags = append(spec.CFlags, "-m32") +- spec.LDFlags = append(spec.LDFlags, "-m32") +- } + } + return &spec, nil + } +-- +2.29.2 + diff --git a/0005-Only-run-i386-tests-on-GOARCH-386-systems.patch b/0005-Only-run-i386-tests-on-GOARCH-386-systems.patch deleted file mode 100644 index 3eb1bf0..0000000 --- a/0005-Only-run-i386-tests-on-GOARCH-386-systems.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 989c5abeeb8fe05bd164b3794f31c470d497ae41 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Thu, 17 Dec 2020 05:05:47 -0500 -Subject: [PATCH 5/5] Only run i386 tests on GOARCH=386 systems. - -Builds on koji do not work for this because it does not support -multilib. - -Signed-off-by: Elliott Sales de Andrade ---- - main_test.go | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) - -diff --git a/main_test.go b/main_test.go -index d2cbba3..524d653 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -78,9 +78,11 @@ func TestCompiler(t *testing.T) { - } - - if runtime.GOOS == "linux" { -- t.Run("X86Linux", func(t *testing.T) { -- runPlatTests("i386--linux-gnu", matches, t) -- }) -+ if runtime.GOARCH == "386" { -+ t.Run("X86Linux", func(t *testing.T) { -+ runPlatTests("i386--linux-gnu", matches, t) -+ }) -+ } - goVersion, err := goenv.GorootVersionString(goenv.Get("GOROOT")) - if err != nil { - t.Error("could not get Go version:", err) --- -2.29.2 - diff --git a/0005-Update-to-current-chromedp.patch b/0005-Update-to-current-chromedp.patch new file mode 100644 index 0000000..da6be99 --- /dev/null +++ b/0005-Update-to-current-chromedp.patch @@ -0,0 +1,108 @@ +From acb8659710b94063baaa0b2e9efe590c0c23f23f Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 22 Dec 2020 05:34:18 -0500 +Subject: [PATCH 5/7] Update to current chromedp. + +Signed-off-by: Elliott Sales de Andrade +--- + go.mod | 5 +++-- + go.sum | 19 +++++++++++++++++++ + tests/wasm/setup_test.go | 3 ++- + 3 files changed, 24 insertions(+), 3 deletions(-) + +diff --git a/go.mod b/go.mod +index bab259a..0d25928 100644 +--- a/go.mod ++++ b/go.mod +@@ -4,9 +4,10 @@ go 1.11 + + require ( + github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 +- github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b +- github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e ++ github.com/chromedp/cdproto v0.0.0-20201009231348-1c6a710e77de ++ github.com/chromedp/chromedp v0.5.4 + github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf ++ github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08 // indirect + 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 +diff --git a/go.sum b/go.sum +index da50204..33a1425 100644 +--- a/go.sum ++++ b/go.sum +@@ -3,24 +3,41 @@ github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAw + github.com/chromedp/cdproto v0.0.0-20200116234248-4da64dd111ac/go.mod h1:PfAWWKJqjlGFYJEidUM6aVIWPr0EpobeyVWEEmplX7g= + github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b h1:LF+GRwyzxrO3MUzPvejv+yBup0lNG+/QdIRrkxOPseA= + github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b/go.mod h1:E6LPWRdIJc11h/di5p0rwvRmUYbhGpBEH7ZbPfzDIOE= ++github.com/chromedp/cdproto v0.0.0-20201009231348-1c6a710e77de h1:cuPPanKjAp5XBwrD1RkeN4ILGRSffUhS69LKkFqKtIA= ++github.com/chromedp/cdproto v0.0.0-20201009231348-1c6a710e77de/go.mod h1:zx0YH7hi8sqkYXAa0LZZxpQLDsU8/a2jzbYbK79dQO8= + github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e h1:Hv0JVyHhbIXb9NiYQe4NsrfgrSofAp0q2FnhhJOXgi8= + github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e/go.mod h1:vmQMRHFZrY3T+Jv51T0n87OK/i6bK+5P9a+Fg5jPwgQ= ++github.com/chromedp/chromedp v0.5.4 h1:hQC6Wj+0mBu2B+HDF4eoAyTkDo0BnL16sz3gAAmZ8fc= ++github.com/chromedp/chromedp v0.5.4/go.mod h1:Jl2gvx3U9zl4lS/dMjDVGXX0jZ4qo/vsGreqYME/lqc= ++github.com/chromedp/sysutil v0.0.0-20201009230539-dc95e7e83e8a/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= ++github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= ++github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= + github.com/creack/goselect v0.1.1 h1:tiSSgKE1eJtxs1h/VgGQWuXUP0YS4CDIFMp6vaI1ls0= + github.com/creack/goselect v0.1.1/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= + github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= + github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= + github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= ++github.com/gobwas/httphead v0.0.0-20200921212729-da3d93bc3c58 h1:YyrUZvJaU8Q0QsoVo+xLFBgWDTam29PKea6GYmwvSiQ= ++github.com/gobwas/httphead v0.0.0-20200921212729-da3d93bc3c58/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= + github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= + github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= ++github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= ++github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= + github.com/gobwas/ws v1.0.3 h1:ZOigqf7iBxkA4jdQ3am7ATzdlOFp9YzA6NmuvEEZc9g= + github.com/gobwas/ws v1.0.3/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= ++github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs= ++github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= + github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= + github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= ++github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= ++github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= + github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08 h1:V0an7KRw92wmJysvFvtqtKMAPmvS5O0jtB0nYo6t+gs= + github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08/go.mod h1:dFWs1zEqDjFtnBXsd1vPOZaLsESovai349994nHx3e0= + github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= + github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8= + github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= ++github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= ++github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= + github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 h1:6J+qramlHVLmiBOgRiBOnQkno8uprqG6YFFQTt6uYIw= + github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M= + github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +@@ -41,6 +58,8 @@ golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX + golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= + golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= + golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= ++golang.org/x/sys v0.0.0-20201202213521-69691e467435 h1:25AvDqqB9PrNqj1FLf2/70I4W0L19qqoaFq3gjNwbKk= ++golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= + golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= + golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 h1:0sfSpGSa544Fwnbot3Oxq/U6SXqjty6Jy/3wRhVS7ig= + golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go +index a38b426..6a84983 100644 +--- a/tests/wasm/setup_test.go ++++ b/tests/wasm/setup_test.go +@@ -16,6 +16,7 @@ import ( + "time" + + "github.com/chromedp/cdproto/cdp" ++ "github.com/chromedp/cdproto/runtime" + "github.com/chromedp/chromedp" + ) + +@@ -166,7 +167,7 @@ func waitInnerTextMatch(sel string, re *regexp.Regexp) chromedp.QueryAction { + + return chromedp.Query(sel, func(s *chromedp.Selector) { + +- chromedp.WaitFunc(func(ctx context.Context, cur *cdp.Frame, ids ...cdp.NodeID) ([]*cdp.Node, error) { ++ chromedp.WaitFunc(func(ctx context.Context, cur *cdp.Frame, execCtx runtime.ExecutionContextID, ids ...cdp.NodeID) ([]*cdp.Node, error) { + + nodes := make([]*cdp.Node, len(ids)) + cur.RLock() +-- +2.29.2 + diff --git a/0006-Use-httptest-to-serve-wasm-test-files.patch b/0006-Use-httptest-to-serve-wasm-test-files.patch new file mode 100644 index 0000000..ddab238 --- /dev/null +++ b/0006-Use-httptest-to-serve-wasm-test-files.patch @@ -0,0 +1,210 @@ +From 6bedea1e36176028452010aeebf5bfcde0e73e6e Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 22 Dec 2020 17:56:53 -0500 +Subject: [PATCH 6/7] Use httptest to serve wasm test files. + +This picks a port automatically, so avoids any conflicts that might +arise from running the tests in parallel. + +Signed-off-by: Elliott Sales de Andrade +--- + tests/wasm/chan_test.go | 5 ++++- + tests/wasm/event_test.go | 5 ++++- + tests/wasm/fmt_test.go | 5 ++++- + tests/wasm/fmtprint_test.go | 5 ++++- + tests/wasm/log_test.go | 5 ++++- + tests/wasm/setup_test.go | 37 ++++++------------------------------- + 6 files changed, 26 insertions(+), 36 deletions(-) + +diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go +index 1cd08e6..c603832 100644 +--- a/tests/wasm/chan_test.go ++++ b/tests/wasm/chan_test.go +@@ -11,6 +11,9 @@ func TestChan(t *testing.T) { + + t.Parallel() + ++ wasmTmpDir, server := startServer(t) ++ defer server.Close() ++ + err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go") + if err != nil { + t.Fatal(err) +@@ -20,7 +23,7 @@ func TestChan(t *testing.T) { + defer cancel() + + err = chromedp.Run(ctx, +- chromedp.Navigate("http://localhost:8826/run?file=chan.wasm"), ++ chromedp.Navigate(server.URL+"/run?file=chan.wasm"), + waitLog(`1 + 2 + 4 +diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go +index d2b8340..6ecc535 100644 +--- a/tests/wasm/event_test.go ++++ b/tests/wasm/event_test.go +@@ -13,6 +13,9 @@ func TestEvent(t *testing.T) { + + t.Parallel() + ++ wasmTmpDir, server := startServer(t) ++ defer server.Close() ++ + err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go") + if err != nil { + t.Fatal(err) +@@ -23,7 +26,7 @@ func TestEvent(t *testing.T) { + + var log1, log2 string + err = chromedp.Run(ctx, +- chromedp.Navigate("http://localhost:8826/run?file=event.wasm"), ++ chromedp.Navigate(server.URL+"/run?file=event.wasm"), + chromedp.WaitVisible("#log"), + chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), +diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go +index 8b4fe8c..0f2b928 100644 +--- a/tests/wasm/fmt_test.go ++++ b/tests/wasm/fmt_test.go +@@ -20,6 +20,9 @@ func TestFmt(t *testing.T) { + + t.Parallel() + ++ wasmTmpDir, server := startServer(t) ++ defer server.Close() ++ + err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go") + if err != nil { + t.Fatal(err) +@@ -30,7 +33,7 @@ func TestFmt(t *testing.T) { + + var log1 string + err = chromedp.Run(ctx, +- chromedp.Navigate("http://localhost:8826/run?file=fmt.wasm"), ++ chromedp.Navigate(server.URL+"/run?file=fmt.wasm"), + chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLog(`did not panic`), +diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go +index ebd1ffa..02e9596 100644 +--- a/tests/wasm/fmtprint_test.go ++++ b/tests/wasm/fmtprint_test.go +@@ -13,6 +13,9 @@ func TestFmtprint(t *testing.T) { + + t.Parallel() + ++ wasmTmpDir, server := startServer(t) ++ defer server.Close() ++ + err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go") + if err != nil { + t.Fatal(err) +@@ -23,7 +26,7 @@ func TestFmtprint(t *testing.T) { + + var log1 string + err = chromedp.Run(ctx, +- chromedp.Navigate("http://localhost:8826/run?file=fmtprint.wasm"), ++ chromedp.Navigate(server.URL+"/run?file=fmtprint.wasm"), + chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLog(`test from fmtprint 1 +diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go +index a9cc1be..655beb0 100644 +--- a/tests/wasm/log_test.go ++++ b/tests/wasm/log_test.go +@@ -13,6 +13,9 @@ func TestLog(t *testing.T) { + + t.Parallel() + ++ wasmTmpDir, server := startServer(t) ++ defer server.Close() ++ + err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go") + if err != nil { + t.Fatal(err) +@@ -23,7 +26,7 @@ func TestLog(t *testing.T) { + + var log1 string + err = chromedp.Run(ctx, +- chromedp.Navigate("http://localhost:8826/run?file=log.wasm"), ++ chromedp.Navigate(server.URL+"/run?file=log.wasm"), + chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLogRe(`^..../../.. ..:..:.. log 1 +diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go +index 6a84983..5120518 100644 +--- a/tests/wasm/setup_test.go ++++ b/tests/wasm/setup_test.go +@@ -3,12 +3,10 @@ package wasm + import ( + "context" + "errors" +- "flag" + "fmt" +- "io/ioutil" + "log" + "net/http" +- "os" ++ "net/http/httptest" + "os/exec" + "regexp" + "strings" +@@ -20,29 +18,6 @@ import ( + "github.com/chromedp/chromedp" + ) + +-var addr = flag.String("addr", ":8826", "Host:port to listen on for wasm test server") +- +-var wasmTmpDir string // set in TestMain to a temp directory for build output +- +-func TestMain(m *testing.M) { +- flag.Parse() +- +- os.Exit(func() int { +- +- var err error +- wasmTmpDir, err = ioutil.TempDir("", "wasm_test") +- if err != nil { +- log.Fatalf("unable to create temp dir: %v", err) +- } +- defer os.RemoveAll(wasmTmpDir) // cleanup even on panic and before os.Exit +- +- startServer(wasmTmpDir) +- +- return m.Run() +- }()) +- +-} +- + func run(cmdline string) error { + args := strings.Fields(cmdline) + return runargs(args...) +@@ -70,8 +45,9 @@ func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) { + return ctx, cancel + } + +-func startServer(tmpDir string) { ++func startServer(t *testing.T) (tmpDir string, server *httptest.Server) { + ++ tmpDir = t.TempDir() + fsh := http.FileServer(http.Dir(tmpDir)) + h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + +@@ -140,11 +116,10 @@ if (wasmSupported) { + fsh.ServeHTTP(w, r) + }) + +- log.Printf("Starting server at %q for dir: %s", *addr, tmpDir) +- go func() { +- log.Fatal(http.ListenAndServe(*addr, h)) +- }() ++ server = httptest.NewServer(h) ++ log.Printf("Started server at %q for dir: %s", server.URL, tmpDir) + ++ return tmpDir, server + } + + // waitLog blocks until the log output equals the text provided (ignoring whitespace before and after) +-- +2.29.2 + diff --git a/0007-Add-support-for-Go-1.16.patch b/0007-Add-support-for-Go-1.16.patch new file mode 100644 index 0000000..b961603 --- /dev/null +++ b/0007-Add-support-for-Go-1.16.patch @@ -0,0 +1,46 @@ +From 87cb1e65c80f62cf0a56c1bf99d8c1258d84aaa5 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 17 Jan 2021 05:07:17 -0500 +Subject: [PATCH 7/7] Add support for Go 1.16. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/config.go | 4 ++-- + cgo/testdata/errors.out.go | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/builder/config.go b/builder/config.go +index 9564386..b145ec5 100644 +--- a/builder/config.go ++++ b/builder/config.go +@@ -25,8 +25,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { + if err != nil { + return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) + } +- if major != 1 || minor < 11 || minor > 15 { +- return nil, fmt.Errorf("requires go version 1.11 through 1.15, got go%d.%d", major, minor) ++ if major != 1 || minor < 11 || minor > 16 { ++ return nil, fmt.Errorf("requires go version 1.11 through 1.16, got go%d.%d", major, minor) + } + clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) + return &compileopts.Config{ +diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go +index ace2390..b5d6978 100644 +--- a/cgo/testdata/errors.out.go ++++ b/cgo/testdata/errors.out.go +@@ -4,10 +4,10 @@ + // testdata/errors.go:13:23: unexpected token ) + + // Type checking errors after CGo processing: +-// testdata/errors.go:102: 2 << 10 (untyped int constant 2048) overflows uint8 ++// testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as uint8 value in variable declaration (overflows) + // testdata/errors.go:105: unknown field z in struct literal + // testdata/errors.go:108: undeclared name: C.SOME_CONST_1 +-// testdata/errors.go:110: C.SOME_CONST_3 (untyped int constant 1234) overflows byte ++// testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows) + + package main + +-- +2.29.2 + diff --git a/tinygo.spec b/tinygo.spec index 92715dd..f39865d 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -58,16 +58,19 @@ Source5: https://releases.llvm.org/%{compiler_rt_version}/compiler-rt-%{c Source6: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz Source7: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz Source8: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz -# Fedora-specific. -Patch0001: 0001-Use-Fedora-command-names.patch -# We don't have ARM glibc to build these. -Patch0002: 0002-Skip-ARM-Linux-tests.patch # We can't include STM32 .svd files because of their weird license. -Patch0003: 0003-Skip-STM32-tests.patch +Patch0001: 0001-Skip-STM32-tests.patch # We don't have wasmtime to run these. -Patch0004: 0004-Skip-WASI-tests.patch -# koji does not support multilib. -Patch0005: 0005-Only-run-i386-tests-on-GOARCH-386-systems.patch +Patch0002: 0002-Skip-WASI-tests.patch +# We don't have cross-compiled glibc to build these. +Patch0003: 0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +# https://github.com/tinygo-org/tinygo/pull/1538 +Patch0004: 0004-Use-clang-to-do-linking.patch +# https://github.com/tinygo-org/tinygo/pull/1540 +Patch0005: 0005-Update-to-current-chromedp.patch +# https://github.com/tinygo-org/tinygo/pull/1542 +Patch0006: 0006-Use-httptest-to-serve-wasm-test-files.patch +Patch0007: 0007-Add-support-for-Go-1.16.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -118,6 +121,10 @@ Recommends: qemu-system-arm-core %patch0003 -p1 %patch0004 -p1 %patch0005 -p1 +%patch0006 -p1 +%if %{fedora} >= 34 +%patch0007 -p1 +%endif tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS @@ -210,7 +217,7 @@ export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off %gocheck -v -d tests/tinygotest make smoketest XTENSA=0 -%ifnarch %{ix86} +%ifnarch %{ix86} aarch64 make wasmtest %endif %endif From 4c79ef677695f1d795231946de102e5fb65f67b5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 22 Jan 2021 06:45:27 -0500 Subject: [PATCH 09/78] Update httptest patch to work with Go 1.14. --- ...se-httptest-to-serve-wasm-test-files.patch | 88 +++++++++++-------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/0006-Use-httptest-to-serve-wasm-test-files.patch b/0006-Use-httptest-to-serve-wasm-test-files.patch index ddab238..d18097c 100644 --- a/0006-Use-httptest-to-serve-wasm-test-files.patch +++ b/0006-Use-httptest-to-serve-wasm-test-files.patch @@ -1,31 +1,31 @@ -From 6bedea1e36176028452010aeebf5bfcde0e73e6e Mon Sep 17 00:00:00 2001 +From 0c9b3f7c9c7041e39bd04e4a99d9ffbac6695d79 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 22 Dec 2020 17:56:53 -0500 -Subject: [PATCH 6/7] Use httptest to serve wasm test files. +Subject: [PATCH] Use httptest to serve wasm test files. This picks a port automatically, so avoids any conflicts that might arise from running the tests in parallel. Signed-off-by: Elliott Sales de Andrade --- - tests/wasm/chan_test.go | 5 ++++- - tests/wasm/event_test.go | 5 ++++- - tests/wasm/fmt_test.go | 5 ++++- - tests/wasm/fmtprint_test.go | 5 ++++- - tests/wasm/log_test.go | 5 ++++- - tests/wasm/setup_test.go | 37 ++++++------------------------------- - 6 files changed, 26 insertions(+), 36 deletions(-) + tests/wasm/chan_test.go | 5 +++- + tests/wasm/event_test.go | 5 +++- + tests/wasm/fmt_test.go | 5 +++- + tests/wasm/fmtprint_test.go | 5 +++- + tests/wasm/log_test.go | 5 +++- + tests/wasm/setup_test.go | 49 +++++++++++++++---------------------- + 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go -index 1cd08e6..c603832 100644 +index 1cd08e6..2faf95b 100644 --- a/tests/wasm/chan_test.go +++ b/tests/wasm/chan_test.go @@ -11,6 +11,9 @@ func TestChan(t *testing.T) { t.Parallel() -+ wasmTmpDir, server := startServer(t) -+ defer server.Close() ++ wasmTmpDir, server, cleanup := startServer(t) ++ defer cleanup() + err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go") if err != nil { @@ -40,15 +40,15 @@ index 1cd08e6..c603832 100644 2 4 diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go -index d2b8340..6ecc535 100644 +index d2b8340..f4ede02 100644 --- a/tests/wasm/event_test.go +++ b/tests/wasm/event_test.go @@ -13,6 +13,9 @@ func TestEvent(t *testing.T) { t.Parallel() -+ wasmTmpDir, server := startServer(t) -+ defer server.Close() ++ wasmTmpDir, server, cleanup := startServer(t) ++ defer cleanup() + err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go") if err != nil { @@ -63,15 +63,15 @@ index d2b8340..6ecc535 100644 chromedp.Sleep(time.Second), chromedp.InnerHTML("#log", &log1), diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go -index 8b4fe8c..0f2b928 100644 +index 8b4fe8c..cac38e7 100644 --- a/tests/wasm/fmt_test.go +++ b/tests/wasm/fmt_test.go @@ -20,6 +20,9 @@ func TestFmt(t *testing.T) { t.Parallel() -+ wasmTmpDir, server := startServer(t) -+ defer server.Close() ++ wasmTmpDir, server, cleanup := startServer(t) ++ defer cleanup() + err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go") if err != nil { @@ -86,15 +86,15 @@ index 8b4fe8c..0f2b928 100644 chromedp.InnerHTML("#log", &log1), waitLog(`did not panic`), diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go -index ebd1ffa..02e9596 100644 +index ebd1ffa..7b4a470 100644 --- a/tests/wasm/fmtprint_test.go +++ b/tests/wasm/fmtprint_test.go @@ -13,6 +13,9 @@ func TestFmtprint(t *testing.T) { t.Parallel() -+ wasmTmpDir, server := startServer(t) -+ defer server.Close() ++ wasmTmpDir, server, cleanup := startServer(t) ++ defer cleanup() + err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go") if err != nil { @@ -109,15 +109,15 @@ index ebd1ffa..02e9596 100644 chromedp.InnerHTML("#log", &log1), waitLog(`test from fmtprint 1 diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go -index a9cc1be..655beb0 100644 +index a9cc1be..ea314e4 100644 --- a/tests/wasm/log_test.go +++ b/tests/wasm/log_test.go @@ -13,6 +13,9 @@ func TestLog(t *testing.T) { t.Parallel() -+ wasmTmpDir, server := startServer(t) -+ defer server.Close() ++ wasmTmpDir, server, cleanup := startServer(t) ++ defer cleanup() + err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go") if err != nil { @@ -132,24 +132,23 @@ index a9cc1be..655beb0 100644 chromedp.InnerHTML("#log", &log1), waitLogRe(`^..../../.. ..:..:.. log 1 diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go -index 6a84983..5120518 100644 +index a38b426..575829b 100644 --- a/tests/wasm/setup_test.go +++ b/tests/wasm/setup_test.go -@@ -3,12 +3,10 @@ package wasm +@@ -3,11 +3,11 @@ package wasm import ( "context" "errors" - "flag" "fmt" -- "io/ioutil" + "io/ioutil" "log" "net/http" -- "os" + "net/http/httptest" + "os" "os/exec" "regexp" - "strings" -@@ -20,29 +18,6 @@ import ( +@@ -19,29 +19,6 @@ import ( "github.com/chromedp/chromedp" ) @@ -179,18 +178,21 @@ index 6a84983..5120518 100644 func run(cmdline string) error { args := strings.Fields(cmdline) return runargs(args...) -@@ -70,8 +45,9 @@ func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) { +@@ -69,7 +46,12 @@ func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) { return ctx, cancel } -func startServer(tmpDir string) { -+func startServer(t *testing.T) (tmpDir string, server *httptest.Server) { ++func startServer(t *testing.T) (string, *httptest.Server, func()) { ++ // In Go 1.15, all this can be replaced by t.TempDir() ++ tmpDir, err := ioutil.TempDir("", "wasm_test") ++ if err != nil { ++ t.Fatalf("unable to create temp dir: %v", err) ++ } -+ tmpDir = t.TempDir() fsh := http.FileServer(http.Dir(tmpDir)) h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - -@@ -140,11 +116,10 @@ if (wasmSupported) { +@@ -139,11 +121,20 @@ if (wasmSupported) { fsh.ServeHTTP(w, r) }) @@ -198,10 +200,20 @@ index 6a84983..5120518 100644 - go func() { - log.Fatal(http.ListenAndServe(*addr, h)) - }() -+ server = httptest.NewServer(h) -+ log.Printf("Started server at %q for dir: %s", server.URL, tmpDir) ++ server := httptest.NewServer(h) ++ t.Logf("Started server at %q for dir: %s", server.URL, tmpDir) ++ ++ // In Go 1.14+, this can be replaced by t.Cleanup() ++ cleanup := func() { ++ err := os.RemoveAll(tmpDir) ++ if err != nil { ++ t.Error(err) ++ } ++ ++ server.Close() ++ } -+ return tmpDir, server ++ return tmpDir, server, cleanup } // waitLog blocks until the log output equals the text provided (ignoring whitespace before and after) From 5106f3645821fd6f312ec2c8283aee3f3d5998be Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Fri, 22 Jan 2021 21:43:32 +0000 Subject: [PATCH 10/78] Rebuild for clang-11.1.0 --- tinygo.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index f39865d..7b82e47 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -36,7 +36,7 @@ tools. Based on LLVM.} #global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} Name: tinygo -Release: 1%{?dist} +Release: 2%{?dist} Summary: Go compiler for small places # Main files: BSD @@ -238,6 +238,9 @@ make wasmtest %changelog +* Fri Jan 22 2021 Tom Stellard - 0.16.0-2 +- Rebuild for clang-11.1.0 + * Sun Sep 20 2020 Elliott Sales de Andrade - 0.15.0-1 - Update to latest version (#1866183) - Loosen up runtime clang requirement From 7494a536a84e5687efab39a20275d029d6f37194 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Wed, 27 Jan 2021 21:59:18 +0000 Subject: [PATCH 11/78] - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- tinygo.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index 7b82e47..3fb1583 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -36,7 +36,7 @@ tools. Based on LLVM.} #global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} Name: tinygo -Release: 2%{?dist} +Release: 3%{?dist} Summary: Go compiler for small places # Main files: BSD @@ -238,6 +238,9 @@ make wasmtest %changelog +* Wed Jan 27 2021 Fedora Release Engineering - 0.16.0-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild + * Fri Jan 22 2021 Tom Stellard - 0.16.0-2 - Rebuild for clang-11.1.0 From bf7dd9ce9c930176c6385ccc9689e58475034363 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 14 Mar 2021 23:26:43 -0400 Subject: [PATCH 12/78] Update to latest version. --- .gitignore | 1 + 0001-Skip-STM32-tests.patch | 61 ----- ...-tests.patch => 0001-Skip-WASI-tests.patch | 13 +- ...tive-Linux-tests-on-their-own-GOARCH.patch | 8 +- ...atch => 0003-Use-clang-to-do-linking.patch | 10 +- 0004-Group-together-STM32-smoke-tests.patch | 106 +++++++++ 0005-Update-to-current-chromedp.patch | 108 --------- ...se-httptest-to-serve-wasm-test-files.patch | 222 ------------------ 0007-Add-support-for-Go-1.16.patch | 46 ---- sources | 4 +- tinygo.spec | 39 ++- 11 files changed, 142 insertions(+), 476 deletions(-) delete mode 100644 0001-Skip-STM32-tests.patch rename 0002-Skip-WASI-tests.patch => 0001-Skip-WASI-tests.patch (57%) rename 0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch => 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch (87%) rename 0004-Use-clang-to-do-linking.patch => 0003-Use-clang-to-do-linking.patch (85%) create mode 100644 0004-Group-together-STM32-smoke-tests.patch delete mode 100644 0005-Update-to-current-chromedp.patch delete mode 100644 0006-Use-httptest-to-serve-wasm-test-files.patch delete mode 100644 0007-Add-support-for-Go-1.16.patch diff --git a/.gitignore b/.gitignore index 213c4e6..ff415fc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ /tinygo-0.14.1.tar.gz /tinygo-0.15.0.tar.gz /tinygo-0.16.0.tar.gz +/tinygo-0.17.0.tar.gz diff --git a/0001-Skip-STM32-tests.patch b/0001-Skip-STM32-tests.patch deleted file mode 100644 index 65ac848..0000000 --- a/0001-Skip-STM32-tests.patch +++ /dev/null @@ -1,61 +0,0 @@ -From 132dd9354512d0ab47cf3d939dd94ffc492eda5a Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Thu, 13 Jun 2019 02:50:40 -0400 -Subject: [PATCH 1/7] Skip STM32 tests. - -We can't ship the STM32 .svd files due to their odd license. - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 14 +------------- - 1 file changed, 1 insertion(+), 13 deletions(-) - -diff --git a/Makefile b/Makefile -index 660975e..ae41b06 100644 ---- a/Makefile -+++ b/Makefile -@@ -103,7 +103,7 @@ fmt-check: - @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 - - --gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-stm32 gen-device-kendryte gen-device-nxp -+gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp - - gen-device-avr: - @if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi -@@ -249,8 +249,6 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=pca10031 examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=bluepill examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky1 - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky2 -@@ -267,14 +265,6 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky1 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky2 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=stm32f4disco-1 examples/blinky1 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=feather-stm32f405 examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1 - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s -@@ -299,8 +289,6 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=particle-xenon examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=nucleo-f103rb examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=pinetime-devkit0 examples/blinky1 - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=x9pro examples/blinky1 --- -2.29.2 - diff --git a/0002-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch similarity index 57% rename from 0002-Skip-WASI-tests.patch rename to 0001-Skip-WASI-tests.patch index 1193282..c366666 100644 --- a/0002-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,26 +1,27 @@ -From 965776292ea372cf2cfd3c0c06c4d9a9e0ca6e03 Mon Sep 17 00:00:00 2001 +From 27457a26211c9868cc8cf1705869d1bfe96d0221 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 2/7] Skip WASI tests. +Subject: [PATCH 1/4] Skip WASI tests. We do not have wasmtime available. Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 4 ---- - 1 file changed, 4 deletions(-) + main_test.go | 5 ----- + 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index a7eca14..9c1b6e8 100644 +index 31ee8c5d..6e55332f 100644 --- a/main_test.go +++ b/main_test.go -@@ -101,10 +101,6 @@ func TestCompiler(t *testing.T) { +@@ -104,11 +104,6 @@ func TestCompiler(t *testing.T) { runPlatTests("wasm", matches, t) }) } - - t.Run("WASI", func(t *testing.T) { - runPlatTests("wasi", matches, t) +- runTest("testdata/libc/env.go", "wasi", t, []string{"ENV1=VALUE1", "ENV2=VALUE2"}...) - }) } } diff --git a/0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch similarity index 87% rename from 0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch rename to 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch index dd9f532..d9eda1a 100644 --- a/0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -1,7 +1,7 @@ -From 683e23f406cb59400bc3879eeebef3445666d7bb Mon Sep 17 00:00:00 2001 +From 8f405abf281efde7d0db5d2f6f63d312f9674d08 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:26:02 -0500 -Subject: [PATCH 3/7] Only run native Linux tests on their own GOARCH. +Subject: [PATCH 2/4] Only run native Linux tests on their own GOARCH. We don't have the cross-compiled C libraries to do this. Even 386 builds on koji do not work for this because it does not support multilib. @@ -12,10 +12,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/main_test.go b/main_test.go -index 9c1b6e8..b839cef 100644 +index 6e55332f..e6344921 100644 --- a/main_test.go +++ b/main_test.go -@@ -78,15 +78,24 @@ func TestCompiler(t *testing.T) { +@@ -81,15 +81,24 @@ func TestCompiler(t *testing.T) { } if runtime.GOOS == "linux" { diff --git a/0004-Use-clang-to-do-linking.patch b/0003-Use-clang-to-do-linking.patch similarity index 85% rename from 0004-Use-clang-to-do-linking.patch rename to 0003-Use-clang-to-do-linking.patch index ad097f3..720bbc6 100644 --- a/0004-Use-clang-to-do-linking.patch +++ b/0003-Use-clang-to-do-linking.patch @@ -1,7 +1,7 @@ -From 99cad3f2957e1698a0c4ab1330354800dce2abdf Mon Sep 17 00:00:00 2001 +From 5288da77fb0953f047a5044a789799fcc42c809a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:28:59 -0500 -Subject: [PATCH 4/7] Use clang to do linking. +Subject: [PATCH 3/4] Use clang to do linking. This avoids having to guess what the linker name-with-build-triplet is, as we can just pass the target to it in the same way as the compilation @@ -13,10 +13,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 8b3c68f..f1aab68 100644 +index 6ca0a0fc..ebd80413 100644 --- a/compileopts/target.go +++ b/compileopts/target.go -@@ -237,8 +237,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { +@@ -238,8 +238,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { GOARCH: goarch, BuildTags: []string{goos, goarch}, Compiler: "clang", @@ -27,7 +27,7 @@ index 8b3c68f..f1aab68 100644 GDB: "gdb", PortReset: "false", } -@@ -255,18 +256,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { +@@ -256,18 +257,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { spec.GDB = "gdb-multiarch" if goarch == "arm" && goos == "linux" { spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") diff --git a/0004-Group-together-STM32-smoke-tests.patch b/0004-Group-together-STM32-smoke-tests.patch new file mode 100644 index 0000000..80f62db --- /dev/null +++ b/0004-Group-together-STM32-smoke-tests.patch @@ -0,0 +1,106 @@ +From 2f8f0eafc72d72f89cc4d964bd09827b4877a8cc Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 14 Mar 2021 19:53:54 -0400 +Subject: [PATCH 4/4] Group together STM32 smoke tests. + +And then allow them to be disabled with one option. + +Signed-off-by: Elliott Sales de Andrade +--- + Makefile | 43 ++++++++++++++++++++++++------------------- + 1 file changed, 24 insertions(+), 19 deletions(-) + +diff --git a/Makefile b/Makefile +index aebf6354..e93ebcb5 100644 +--- a/Makefile ++++ b/Makefile +@@ -107,7 +107,10 @@ fmt-check: + @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 + + +-gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-stm32 gen-device-kendryte gen-device-nxp ++gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp ++ifneq ($(STM32), 0) ++gen-device: gen-device-stm32 ++endif + + gen-device-avr: + @if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi +@@ -257,8 +260,6 @@ smoketest: + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=pca10031 examples/blinky1 + @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=bluepill examples/blinky1 +- @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky1 + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky2 +@@ -275,14 +276,6 @@ smoketest: + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/blinky1 + @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky1 +- @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky2 +- @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=stm32f4disco-1 examples/blinky1 +- @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=feather-stm32f405 examples/blinky1 +- @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1 + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s +@@ -307,12 +300,8 @@ smoketest: + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=particle-xenon examples/blinky1 + @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=nucleo-f103rb examples/blinky1 +- @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=pinetime-devkit0 examples/blinky1 + @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=lgt92 examples/blinky1 +- @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=x9pro examples/blinky1 + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=pca10056-s140v7 examples/blinky1 +@@ -339,10 +328,6 @@ smoketest: + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=teensy36 examples/blinky1 + @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=nucleo-f722ze examples/blinky1 +- @$(MD5SUM) test.hex +- $(TINYGO) build -size short -o test.hex -target=nucleo-l552ze examples/blinky1 +- @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=p1am-100 examples/blinky1 + @$(MD5SUM) test.hex + # test pwm +@@ -354,6 +339,26 @@ smoketest: + @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=pyportal examples/pwm + @$(MD5SUM) test.hex ++ifneq ($(STM32), 0) ++ $(TINYGO) build -size short -o test.hex -target=bluepill examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=feather-stm32f405 examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=lgt92 examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=nucleo-f103rb examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=nucleo-f722ze examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=nucleo-l552ze examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky1 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky2 ++ @$(MD5SUM) test.hex ++ $(TINYGO) build -size short -o test.hex -target=stm32f4disco-1 examples/blinky1 ++ @$(MD5SUM) test.hex ++endif + ifneq ($(AVR), 0) + $(TINYGO) build -size short -o test.hex -target=atmega1284p examples/serial + @$(MD5SUM) test.hex +-- +2.29.2 + diff --git a/0005-Update-to-current-chromedp.patch b/0005-Update-to-current-chromedp.patch deleted file mode 100644 index da6be99..0000000 --- a/0005-Update-to-current-chromedp.patch +++ /dev/null @@ -1,108 +0,0 @@ -From acb8659710b94063baaa0b2e9efe590c0c23f23f Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Tue, 22 Dec 2020 05:34:18 -0500 -Subject: [PATCH 5/7] Update to current chromedp. - -Signed-off-by: Elliott Sales de Andrade ---- - go.mod | 5 +++-- - go.sum | 19 +++++++++++++++++++ - tests/wasm/setup_test.go | 3 ++- - 3 files changed, 24 insertions(+), 3 deletions(-) - -diff --git a/go.mod b/go.mod -index bab259a..0d25928 100644 ---- a/go.mod -+++ b/go.mod -@@ -4,9 +4,10 @@ go 1.11 - - require ( - github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 -- github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b -- github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e -+ github.com/chromedp/cdproto v0.0.0-20201009231348-1c6a710e77de -+ github.com/chromedp/chromedp v0.5.4 - github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf -+ github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08 // indirect - 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 -diff --git a/go.sum b/go.sum -index da50204..33a1425 100644 ---- a/go.sum -+++ b/go.sum -@@ -3,24 +3,41 @@ github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAw - github.com/chromedp/cdproto v0.0.0-20200116234248-4da64dd111ac/go.mod h1:PfAWWKJqjlGFYJEidUM6aVIWPr0EpobeyVWEEmplX7g= - github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b h1:LF+GRwyzxrO3MUzPvejv+yBup0lNG+/QdIRrkxOPseA= - github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b/go.mod h1:E6LPWRdIJc11h/di5p0rwvRmUYbhGpBEH7ZbPfzDIOE= -+github.com/chromedp/cdproto v0.0.0-20201009231348-1c6a710e77de h1:cuPPanKjAp5XBwrD1RkeN4ILGRSffUhS69LKkFqKtIA= -+github.com/chromedp/cdproto v0.0.0-20201009231348-1c6a710e77de/go.mod h1:zx0YH7hi8sqkYXAa0LZZxpQLDsU8/a2jzbYbK79dQO8= - github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e h1:Hv0JVyHhbIXb9NiYQe4NsrfgrSofAp0q2FnhhJOXgi8= - github.com/chromedp/chromedp v0.5.4-0.20200303084119-2bb39134ab9e/go.mod h1:vmQMRHFZrY3T+Jv51T0n87OK/i6bK+5P9a+Fg5jPwgQ= -+github.com/chromedp/chromedp v0.5.4 h1:hQC6Wj+0mBu2B+HDF4eoAyTkDo0BnL16sz3gAAmZ8fc= -+github.com/chromedp/chromedp v0.5.4/go.mod h1:Jl2gvx3U9zl4lS/dMjDVGXX0jZ4qo/vsGreqYME/lqc= -+github.com/chromedp/sysutil v0.0.0-20201009230539-dc95e7e83e8a/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= -+github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= -+github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= - github.com/creack/goselect v0.1.1 h1:tiSSgKE1eJtxs1h/VgGQWuXUP0YS4CDIFMp6vaI1ls0= - github.com/creack/goselect v0.1.1/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= - github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= - github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= - github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= -+github.com/gobwas/httphead v0.0.0-20200921212729-da3d93bc3c58 h1:YyrUZvJaU8Q0QsoVo+xLFBgWDTam29PKea6GYmwvSiQ= -+github.com/gobwas/httphead v0.0.0-20200921212729-da3d93bc3c58/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= - github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= - github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= -+github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= -+github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= - github.com/gobwas/ws v1.0.3 h1:ZOigqf7iBxkA4jdQ3am7ATzdlOFp9YzA6NmuvEEZc9g= - github.com/gobwas/ws v1.0.3/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -+github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs= -+github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= - github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= - github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= -+github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -+github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= - github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08 h1:V0an7KRw92wmJysvFvtqtKMAPmvS5O0jtB0nYo6t+gs= - github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08/go.mod h1:dFWs1zEqDjFtnBXsd1vPOZaLsESovai349994nHx3e0= - github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= - github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8= - github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= -+github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= -+github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= - github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 h1:6J+qramlHVLmiBOgRiBOnQkno8uprqG6YFFQTt6uYIw= - github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M= - github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -@@ -41,6 +58,8 @@ golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX - golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= - golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= - golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -+golang.org/x/sys v0.0.0-20201202213521-69691e467435 h1:25AvDqqB9PrNqj1FLf2/70I4W0L19qqoaFq3gjNwbKk= -+golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= - golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= - golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 h1:0sfSpGSa544Fwnbot3Oxq/U6SXqjty6Jy/3wRhVS7ig= - golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go -index a38b426..6a84983 100644 ---- a/tests/wasm/setup_test.go -+++ b/tests/wasm/setup_test.go -@@ -16,6 +16,7 @@ import ( - "time" - - "github.com/chromedp/cdproto/cdp" -+ "github.com/chromedp/cdproto/runtime" - "github.com/chromedp/chromedp" - ) - -@@ -166,7 +167,7 @@ func waitInnerTextMatch(sel string, re *regexp.Regexp) chromedp.QueryAction { - - return chromedp.Query(sel, func(s *chromedp.Selector) { - -- chromedp.WaitFunc(func(ctx context.Context, cur *cdp.Frame, ids ...cdp.NodeID) ([]*cdp.Node, error) { -+ chromedp.WaitFunc(func(ctx context.Context, cur *cdp.Frame, execCtx runtime.ExecutionContextID, ids ...cdp.NodeID) ([]*cdp.Node, error) { - - nodes := make([]*cdp.Node, len(ids)) - cur.RLock() --- -2.29.2 - diff --git a/0006-Use-httptest-to-serve-wasm-test-files.patch b/0006-Use-httptest-to-serve-wasm-test-files.patch deleted file mode 100644 index d18097c..0000000 --- a/0006-Use-httptest-to-serve-wasm-test-files.patch +++ /dev/null @@ -1,222 +0,0 @@ -From 0c9b3f7c9c7041e39bd04e4a99d9ffbac6695d79 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Tue, 22 Dec 2020 17:56:53 -0500 -Subject: [PATCH] Use httptest to serve wasm test files. - -This picks a port automatically, so avoids any conflicts that might -arise from running the tests in parallel. - -Signed-off-by: Elliott Sales de Andrade ---- - tests/wasm/chan_test.go | 5 +++- - tests/wasm/event_test.go | 5 +++- - tests/wasm/fmt_test.go | 5 +++- - tests/wasm/fmtprint_test.go | 5 +++- - tests/wasm/log_test.go | 5 +++- - tests/wasm/setup_test.go | 49 +++++++++++++++---------------------- - 6 files changed, 40 insertions(+), 34 deletions(-) - -diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go -index 1cd08e6..2faf95b 100644 ---- a/tests/wasm/chan_test.go -+++ b/tests/wasm/chan_test.go -@@ -11,6 +11,9 @@ func TestChan(t *testing.T) { - - t.Parallel() - -+ wasmTmpDir, server, cleanup := startServer(t) -+ defer cleanup() -+ - err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go") - if err != nil { - t.Fatal(err) -@@ -20,7 +23,7 @@ func TestChan(t *testing.T) { - defer cancel() - - err = chromedp.Run(ctx, -- chromedp.Navigate("http://localhost:8826/run?file=chan.wasm"), -+ chromedp.Navigate(server.URL+"/run?file=chan.wasm"), - waitLog(`1 - 2 - 4 -diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go -index d2b8340..f4ede02 100644 ---- a/tests/wasm/event_test.go -+++ b/tests/wasm/event_test.go -@@ -13,6 +13,9 @@ func TestEvent(t *testing.T) { - - t.Parallel() - -+ wasmTmpDir, server, cleanup := startServer(t) -+ defer cleanup() -+ - err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go") - if err != nil { - t.Fatal(err) -@@ -23,7 +26,7 @@ func TestEvent(t *testing.T) { - - var log1, log2 string - err = chromedp.Run(ctx, -- chromedp.Navigate("http://localhost:8826/run?file=event.wasm"), -+ chromedp.Navigate(server.URL+"/run?file=event.wasm"), - chromedp.WaitVisible("#log"), - chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), -diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go -index 8b4fe8c..cac38e7 100644 ---- a/tests/wasm/fmt_test.go -+++ b/tests/wasm/fmt_test.go -@@ -20,6 +20,9 @@ func TestFmt(t *testing.T) { - - t.Parallel() - -+ wasmTmpDir, server, cleanup := startServer(t) -+ defer cleanup() -+ - err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go") - if err != nil { - t.Fatal(err) -@@ -30,7 +33,7 @@ func TestFmt(t *testing.T) { - - var log1 string - err = chromedp.Run(ctx, -- chromedp.Navigate("http://localhost:8826/run?file=fmt.wasm"), -+ chromedp.Navigate(server.URL+"/run?file=fmt.wasm"), - chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLog(`did not panic`), -diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go -index ebd1ffa..7b4a470 100644 ---- a/tests/wasm/fmtprint_test.go -+++ b/tests/wasm/fmtprint_test.go -@@ -13,6 +13,9 @@ func TestFmtprint(t *testing.T) { - - t.Parallel() - -+ wasmTmpDir, server, cleanup := startServer(t) -+ defer cleanup() -+ - err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go") - if err != nil { - t.Fatal(err) -@@ -23,7 +26,7 @@ func TestFmtprint(t *testing.T) { - - var log1 string - err = chromedp.Run(ctx, -- chromedp.Navigate("http://localhost:8826/run?file=fmtprint.wasm"), -+ chromedp.Navigate(server.URL+"/run?file=fmtprint.wasm"), - chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLog(`test from fmtprint 1 -diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go -index a9cc1be..ea314e4 100644 ---- a/tests/wasm/log_test.go -+++ b/tests/wasm/log_test.go -@@ -13,6 +13,9 @@ func TestLog(t *testing.T) { - - t.Parallel() - -+ wasmTmpDir, server, cleanup := startServer(t) -+ defer cleanup() -+ - err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go") - if err != nil { - t.Fatal(err) -@@ -23,7 +26,7 @@ func TestLog(t *testing.T) { - - var log1 string - err = chromedp.Run(ctx, -- chromedp.Navigate("http://localhost:8826/run?file=log.wasm"), -+ chromedp.Navigate(server.URL+"/run?file=log.wasm"), - chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLogRe(`^..../../.. ..:..:.. log 1 -diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go -index a38b426..575829b 100644 ---- a/tests/wasm/setup_test.go -+++ b/tests/wasm/setup_test.go -@@ -3,11 +3,11 @@ package wasm - import ( - "context" - "errors" -- "flag" - "fmt" - "io/ioutil" - "log" - "net/http" -+ "net/http/httptest" - "os" - "os/exec" - "regexp" -@@ -19,29 +19,6 @@ import ( - "github.com/chromedp/chromedp" - ) - --var addr = flag.String("addr", ":8826", "Host:port to listen on for wasm test server") -- --var wasmTmpDir string // set in TestMain to a temp directory for build output -- --func TestMain(m *testing.M) { -- flag.Parse() -- -- os.Exit(func() int { -- -- var err error -- wasmTmpDir, err = ioutil.TempDir("", "wasm_test") -- if err != nil { -- log.Fatalf("unable to create temp dir: %v", err) -- } -- defer os.RemoveAll(wasmTmpDir) // cleanup even on panic and before os.Exit -- -- startServer(wasmTmpDir) -- -- return m.Run() -- }()) -- --} -- - func run(cmdline string) error { - args := strings.Fields(cmdline) - return runargs(args...) -@@ -69,7 +46,12 @@ func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) { - return ctx, cancel - } - --func startServer(tmpDir string) { -+func startServer(t *testing.T) (string, *httptest.Server, func()) { -+ // In Go 1.15, all this can be replaced by t.TempDir() -+ tmpDir, err := ioutil.TempDir("", "wasm_test") -+ if err != nil { -+ t.Fatalf("unable to create temp dir: %v", err) -+ } - - fsh := http.FileServer(http.Dir(tmpDir)) - h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -@@ -139,11 +121,20 @@ if (wasmSupported) { - fsh.ServeHTTP(w, r) - }) - -- log.Printf("Starting server at %q for dir: %s", *addr, tmpDir) -- go func() { -- log.Fatal(http.ListenAndServe(*addr, h)) -- }() -+ server := httptest.NewServer(h) -+ t.Logf("Started server at %q for dir: %s", server.URL, tmpDir) -+ -+ // In Go 1.14+, this can be replaced by t.Cleanup() -+ cleanup := func() { -+ err := os.RemoveAll(tmpDir) -+ if err != nil { -+ t.Error(err) -+ } -+ -+ server.Close() -+ } - -+ return tmpDir, server, cleanup - } - - // waitLog blocks until the log output equals the text provided (ignoring whitespace before and after) --- -2.29.2 - diff --git a/0007-Add-support-for-Go-1.16.patch b/0007-Add-support-for-Go-1.16.patch deleted file mode 100644 index b961603..0000000 --- a/0007-Add-support-for-Go-1.16.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 87cb1e65c80f62cf0a56c1bf99d8c1258d84aaa5 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 17 Jan 2021 05:07:17 -0500 -Subject: [PATCH 7/7] Add support for Go 1.16. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/config.go | 4 ++-- - cgo/testdata/errors.out.go | 4 ++-- - 2 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/builder/config.go b/builder/config.go -index 9564386..b145ec5 100644 ---- a/builder/config.go -+++ b/builder/config.go -@@ -25,8 +25,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { - if err != nil { - return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) - } -- if major != 1 || minor < 11 || minor > 15 { -- return nil, fmt.Errorf("requires go version 1.11 through 1.15, got go%d.%d", major, minor) -+ if major != 1 || minor < 11 || minor > 16 { -+ return nil, fmt.Errorf("requires go version 1.11 through 1.16, got go%d.%d", major, minor) - } - clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) - return &compileopts.Config{ -diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go -index ace2390..b5d6978 100644 ---- a/cgo/testdata/errors.out.go -+++ b/cgo/testdata/errors.out.go -@@ -4,10 +4,10 @@ - // testdata/errors.go:13:23: unexpected token ) - - // Type checking errors after CGo processing: --// testdata/errors.go:102: 2 << 10 (untyped int constant 2048) overflows uint8 -+// testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as uint8 value in variable declaration (overflows) - // testdata/errors.go:105: unknown field z in struct literal - // testdata/errors.go:108: undeclared name: C.SOME_CONST_1 --// testdata/errors.go:110: C.SOME_CONST_3 (untyped int constant 1234) overflows byte -+// testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows) - - package main - --- -2.29.2 - diff --git a/sources b/sources index 043e498..00bb948 100644 --- a/sources +++ b/sources @@ -1,8 +1,8 @@ -SHA512 (tinygo-0.16.0.tar.gz) = fa17cbd92d2c3961df1dcb5e906070f391ce0485111f5190b812dd7b2098a4a86b657bcc4b1edb19cd7fb707824f6fc719d8554669ba806b23e9f38518fd4cc6 +SHA512 (tinygo-0.17.0.tar.gz) = 127cd869913a0279f6065b3d073c044697c980b925d2d28e22cc349ce04cc1cefb5b72f31baaf88d039e4faa1de880a9a9ea5917f8a74b5509a6464e3531ee66 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd-clean.tar.xz) = f3040f089e0714aa7d8b234a0becf8ca77934e9aa6510ff56f68add2881ade1f52176b461fbdf6218df077f3bf66505ca4d1ef94d03d28dfad1b53801dbfc88f SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 -SHA512 (nrfx-3ab39a9d457bfe627473ed0e03a7f1161d9e4f27.tar.gz) = 95b5293c9b707aeb4d8ad13643619c053ba0fa9423053a12f9a65b0ed8febc2aab87cd832e6ac73e9673987b7cb73f85cce68cb85ce4ca5bd607afee1098f9e9 +SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-80528c684b10aaee977397e7eb40c4784e6dc433.tar.gz) = d7cdddf4ba2c4c4a447864e899c9e92674438358e8c1123c80d38b0c1d57cb35fdaaa60a73a16331637884d23207fdc9f06d7f28dc5920c76e25808869e2c7b1 SHA512 (wasi-libc-215adc8ac9f91eb055311acc72683fd2eb1ae15a.tar.gz) = f7e5dd8689d86bd781d2985bcab996018e9fefec7744fbbfcc19215d082f20b1ee84b252c3f905926327da6d6e0465c0f22b94e52f5fdb523317275a6b4bf3e1 diff --git a/tinygo.spec b/tinygo.spec index 3fb1583..c140250 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.16.0 +Version: 0.17.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -17,7 +17,7 @@ Version: 0.16.0 %endif %global cmsis_svd_commit d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd %global compiler_rt_version 9.0.0 -%global nrfx_commit 3ab39a9d457bfe627473ed0e03a7f1161d9e4f27 +%global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit 80528c684b10aaee977397e7eb40c4784e6dc433 %global wasi_libc_commit 215adc8ac9f91eb055311acc72683fd2eb1ae15a @@ -36,7 +36,7 @@ tools. Based on LLVM.} #global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} Name: tinygo -Release: 3%{?dist} +Release: 1%{?dist} Summary: Go compiler for small places # Main files: BSD @@ -58,19 +58,15 @@ Source5: https://releases.llvm.org/%{compiler_rt_version}/compiler-rt-%{c Source6: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz Source7: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz Source8: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz -# We can't include STM32 .svd files because of their weird license. -Patch0001: 0001-Skip-STM32-tests.patch # We don't have wasmtime to run these. -Patch0002: 0002-Skip-WASI-tests.patch +Patch0001: 0001-Skip-WASI-tests.patch # We don't have cross-compiled glibc to build these. -Patch0003: 0003-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +Patch0002: 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch # https://github.com/tinygo-org/tinygo/pull/1538 -Patch0004: 0004-Use-clang-to-do-linking.patch -# https://github.com/tinygo-org/tinygo/pull/1540 -Patch0005: 0005-Update-to-current-chromedp.patch -# https://github.com/tinygo-org/tinygo/pull/1542 -Patch0006: 0006-Use-httptest-to-serve-wasm-test-files.patch -Patch0007: 0007-Add-support-for-Go-1.16.patch +Patch0003: 0003-Use-clang-to-do-linking.patch +# We can't include STM32 .svd files because of their weird license. +# https://github.com/tinygo-org/tinygo/pull/1718 +Patch0004: 0004-Group-together-STM32-smoke-tests.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -80,12 +76,13 @@ BuildRequires: (clang-devel >= %{clang_version} with clang-devel < %{lua: print BuildRequires: golang(github.com/blakesmith/ar) %ifnarch %{ix86} BuildRequires: chromium -BuildRequires: golang(github.com/chromedp/chromedp) +BuildRequires: golang(github.com/chromedp/chromedp) >= 0.6.4 BuildRequires: golang(github.com/chromedp/cdproto/cdp) %endif BuildRequires: golang(github.com/google/shlex) BuildRequires: golang(github.com/marcinbor85/gohex) -BuildRequires: golang(go.bug.st/serial) +BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 +BuildRequires: golang(go.bug.st/serial) >= 1.1.2 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) BuildRequires: golang(golang.org/x/tools/go/ssa) BuildRequires: golang(tinygo.org/x/go-llvm) @@ -120,11 +117,6 @@ Recommends: qemu-system-arm-core %patch0002 -p1 %patch0003 -p1 %patch0004 -p1 -%patch0005 -p1 -%patch0006 -p1 -%if %{fedora} >= 34 -%patch0007 -p1 -%endif tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS @@ -160,7 +152,7 @@ mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc %build export LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} -GO111MODULE=off %make_build gen-device +GO111MODULE=off %make_build gen-device STM32=0 for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do for libc in compiler-rt picolibc; do TINYGOROOT=$PWD \ @@ -216,7 +208,7 @@ export GOPATH=%{buildroot}%{tinygoroot}:%{gopath} export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off %gocheck -v -d tests/tinygotest -make smoketest XTENSA=0 +make smoketest STM32=0 XTENSA=0 %ifnarch %{ix86} aarch64 make wasmtest %endif @@ -238,6 +230,9 @@ make wasmtest %changelog +* Sun Mar 14 2021 Elliott Sales de Andrade - 0.17.0-1 +- Update to latest version (#1936121) + * Wed Jan 27 2021 Fedora Release Engineering - 0.16.0-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild From 164a6e70749e77867020ea9771c8fb9d3d8bc106 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 May 2021 05:50:26 -0400 Subject: [PATCH 13/78] Update to latest version. --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 19 ++-- ...tive-Linux-tests-on-their-own-GOARCH.patch | 22 ++-- 0003-Use-clang-to-do-linking.patch | 31 ++--- 0004-Group-together-STM32-smoke-tests.patch | 106 ------------------ clean_tarballs.sh | 2 +- sources | 4 +- tinygo.spec | 11 +- 8 files changed, 45 insertions(+), 151 deletions(-) delete mode 100644 0004-Group-together-STM32-smoke-tests.patch diff --git a/.gitignore b/.gitignore index ff415fc..10a84f7 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ /tinygo-0.15.0.tar.gz /tinygo-0.16.0.tar.gz /tinygo-0.17.0.tar.gz +/tinygo-0.18.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index c366666..bcdec17 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,31 +1,30 @@ -From 27457a26211c9868cc8cf1705869d1bfe96d0221 Mon Sep 17 00:00:00 2001 +From d3afa56a31a75d0fb5a696a22a52614ec038e89c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/4] Skip WASI tests. +Subject: [PATCH 1/3] Skip WASI tests. We do not have wasmtime available. Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 5 ----- - 1 file changed, 5 deletions(-) + main_test.go | 4 ---- + 1 file changed, 4 deletions(-) diff --git a/main_test.go b/main_test.go -index 31ee8c5d..6e55332f 100644 +index 224a71b0..9a4dbc0f 100644 --- a/main_test.go +++ b/main_test.go -@@ -104,11 +104,6 @@ func TestCompiler(t *testing.T) { - runPlatTests("wasm", matches, t) +@@ -108,10 +108,6 @@ func TestCompiler(t *testing.T) { + runPlatTests("wasm", tests, t) }) } - - t.Run("WASI", func(t *testing.T) { -- runPlatTests("wasi", matches, t) -- runTest("testdata/libc/env.go", "wasi", t, []string{"ENV1=VALUE1", "ENV2=VALUE2"}...) +- runPlatTests("wasi", tests, t) - }) } - } + // Test a few build options. -- 2.29.2 diff --git a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch index d9eda1a..6651302 100644 --- a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -1,7 +1,7 @@ -From 8f405abf281efde7d0db5d2f6f63d312f9674d08 Mon Sep 17 00:00:00 2001 +From 86f8ec3c802ddc08955203de9247e4b697e11f40 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:26:02 -0500 -Subject: [PATCH 2/4] Only run native Linux tests on their own GOARCH. +Subject: [PATCH 2/3] Only run native Linux tests on their own GOARCH. We don't have the cross-compiled C libraries to do this. Even 386 builds on koji do not work for this because it does not support multilib. @@ -12,38 +12,38 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/main_test.go b/main_test.go -index 6e55332f..e6344921 100644 +index 9a4dbc0f..2956d7af 100644 --- a/main_test.go +++ b/main_test.go -@@ -81,15 +81,24 @@ func TestCompiler(t *testing.T) { +@@ -85,15 +85,24 @@ func TestCompiler(t *testing.T) { } if runtime.GOOS == "linux" { - t.Run("X86Linux", func(t *testing.T) { -- runPlatTests("i386--linux-gnu", matches, t) +- runPlatTests("i386--linux-gnu", tests, t) - }) - t.Run("ARMLinux", func(t *testing.T) { -- runPlatTests("arm--linux-gnueabihf", matches, t) +- runPlatTests("arm--linux-gnueabihf", tests, t) - }) - t.Run("ARM64Linux", func(t *testing.T) { -- runPlatTests("aarch64--linux-gnu", matches, t) +- runPlatTests("aarch64--linux-gnu", tests, t) - }) + switch runtime.GOARCH { + case "386": + t.Run("X86Linux", func(t *testing.T) { -+ runPlatTests("i386--linux-gnu", matches, t) ++ runPlatTests("i386--linux-gnu", tests, t) + }) + case "amd64": + t.Run("AMD64Linux", func(t *testing.T) { -+ runPlatTests("amd64--linux-gnu", matches, t) ++ runPlatTests("amd64--linux-gnu", tests, t) + }) + case "arm": + t.Run("ARMLinux", func(t *testing.T) { -+ runPlatTests("arm--linux-gnueabihf", matches, t) ++ runPlatTests("arm--linux-gnueabihf", tests, t) + }) + case "arm64": + t.Run("ARM64Linux", func(t *testing.T) { -+ runPlatTests("aarch64--linux-gnu", matches, t) ++ runPlatTests("aarch64--linux-gnu", tests, t) + }) + } goVersion, err := goenv.GorootVersionString(goenv.Get("GOROOT")) diff --git a/0003-Use-clang-to-do-linking.patch b/0003-Use-clang-to-do-linking.patch index 720bbc6..7a281a3 100644 --- a/0003-Use-clang-to-do-linking.patch +++ b/0003-Use-clang-to-do-linking.patch @@ -1,7 +1,7 @@ -From 5288da77fb0953f047a5044a789799fcc42c809a Mon Sep 17 00:00:00 2001 +From c73218ed03707d7c566abe2105ef2969f2874578 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:28:59 -0500 -Subject: [PATCH 3/4] Use clang to do linking. +Subject: [PATCH 3/3] Use clang to do linking. This avoids having to guess what the linker name-with-build-triplet is, as we can just pass the target to it in the same way as the compilation @@ -13,22 +13,23 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 6ca0a0fc..ebd80413 100644 +index 81de4ed0..f06f97f1 100644 --- a/compileopts/target.go +++ b/compileopts/target.go -@@ -238,8 +238,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - GOARCH: goarch, - BuildTags: []string{goos, goarch}, - Compiler: "clang", -- Linker: "cc", - CFlags: []string{"--target=" + triple}, -+ Linker: "clang", -+ LDFlags: []string{"--target=" + triple}, - GDB: "gdb", - PortReset: "false", +@@ -244,9 +244,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + GOARCH: goarch, + BuildTags: []string{goos, goarch}, + Scheduler: "tasks", +- Linker: "cc", + DefaultStackSize: 1024 * 64, // 64kB + CFlags: []string{"--target=" + triple}, ++ Linker: "clang", ++ LDFlags: []string{"--target=" + triple}, + GDB: []string{"gdb"}, + PortReset: "false", } -@@ -256,18 +257,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - spec.GDB = "gdb-multiarch" +@@ -265,18 +266,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + spec.GDB = []string{"gdb-multiarch"} if goarch == "arm" && goos == "linux" { spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") - spec.Linker = "arm-linux-gnueabihf-gcc" diff --git a/0004-Group-together-STM32-smoke-tests.patch b/0004-Group-together-STM32-smoke-tests.patch deleted file mode 100644 index 80f62db..0000000 --- a/0004-Group-together-STM32-smoke-tests.patch +++ /dev/null @@ -1,106 +0,0 @@ -From 2f8f0eafc72d72f89cc4d964bd09827b4877a8cc Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 14 Mar 2021 19:53:54 -0400 -Subject: [PATCH 4/4] Group together STM32 smoke tests. - -And then allow them to be disabled with one option. - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 43 ++++++++++++++++++++++++------------------- - 1 file changed, 24 insertions(+), 19 deletions(-) - -diff --git a/Makefile b/Makefile -index aebf6354..e93ebcb5 100644 ---- a/Makefile -+++ b/Makefile -@@ -107,7 +107,10 @@ fmt-check: - @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 - - --gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-stm32 gen-device-kendryte gen-device-nxp -+gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp -+ifneq ($(STM32), 0) -+gen-device: gen-device-stm32 -+endif - - gen-device-avr: - @if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi -@@ -257,8 +260,6 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=pca10031 examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=bluepill examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky1 - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky2 -@@ -275,14 +276,6 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky1 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky2 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=stm32f4disco-1 examples/blinky1 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=feather-stm32f405 examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1 - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s -@@ -307,12 +300,8 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=particle-xenon examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=nucleo-f103rb examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=pinetime-devkit0 examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=lgt92 examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=x9pro examples/blinky1 - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=pca10056-s140v7 examples/blinky1 -@@ -339,10 +328,6 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=teensy36 examples/blinky1 - @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=nucleo-f722ze examples/blinky1 -- @$(MD5SUM) test.hex -- $(TINYGO) build -size short -o test.hex -target=nucleo-l552ze examples/blinky1 -- @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=p1am-100 examples/blinky1 - @$(MD5SUM) test.hex - # test pwm -@@ -354,6 +339,26 @@ smoketest: - @$(MD5SUM) test.hex - $(TINYGO) build -size short -o test.hex -target=pyportal examples/pwm - @$(MD5SUM) test.hex -+ifneq ($(STM32), 0) -+ $(TINYGO) build -size short -o test.hex -target=bluepill examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=feather-stm32f405 examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=lgt92 examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=nucleo-f103rb examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=nucleo-f722ze examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=nucleo-l552ze examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky1 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky2 -+ @$(MD5SUM) test.hex -+ $(TINYGO) build -size short -o test.hex -target=stm32f4disco-1 examples/blinky1 -+ @$(MD5SUM) test.hex -+endif - ifneq ($(AVR), 0) - $(TINYGO) build -size short -o test.hex -target=atmega1284p examples/serial - @$(MD5SUM) test.hex --- -2.29.2 - diff --git a/clean_tarballs.sh b/clean_tarballs.sh index 056a6a9..bef8955 100755 --- a/clean_tarballs.sh +++ b/clean_tarballs.sh @@ -1,7 +1,7 @@ #!/bin/bash -e CMSIS_VERSION=9fe411cef1cef5de58e5957b89760759de44e393 -CMSIS_SVD_VERSION=d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd +CMSIS_SVD_VERSION=2fb66c573555cc51e76dc03c003518366714139e if [ -e "cmsis-${CMSIS_VERSION}-clean.tar.xz" ]; then echo "Not downloading cmsis-${CMSIS_VERSION}-clean.tar.xz again!" diff --git a/sources b/sources index 00bb948..81018c2 100644 --- a/sources +++ b/sources @@ -1,7 +1,7 @@ -SHA512 (tinygo-0.17.0.tar.gz) = 127cd869913a0279f6065b3d073c044697c980b925d2d28e22cc349ce04cc1cefb5b72f31baaf88d039e4faa1de880a9a9ea5917f8a74b5509a6464e3531ee66 +SHA512 (tinygo-0.18.0.tar.gz) = 8e070f182b277f442ef64b7069b9a27b62efc44c75a335a2a14438d1740b2df2fe2c719d74b1110b9aa37caf70e74ceec3252e1707dca3506adae4c03a2568fa SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 -SHA512 (cmsis_svd-d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd-clean.tar.xz) = f3040f089e0714aa7d8b234a0becf8ca77934e9aa6510ff56f68add2881ade1f52176b461fbdf6218df077f3bf66505ca4d1ef94d03d28dfad1b53801dbfc88f +SHA512 (cmsis_svd-2fb66c573555cc51e76dc03c003518366714139e-clean.tar.xz) = 09fe3c92537bcea70599f9979a1d6291d22c7b6a6f4ac674d3f19e6b3c18728db4f4f0996803f08b97c4a64206f060a2dd4f46c1cc356ce4add8df6f8838019f SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-80528c684b10aaee977397e7eb40c4784e6dc433.tar.gz) = d7cdddf4ba2c4c4a447864e899c9e92674438358e8c1123c80d38b0c1d57cb35fdaaa60a73a16331637884d23207fdc9f06d7f28dc5920c76e25808869e2c7b1 diff --git a/tinygo.spec b/tinygo.spec index c140250..69f8ae0 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.17.0 +Version: 0.18.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -15,7 +15,7 @@ Version: 0.17.0 %else %global clang_version 10 %endif -%global cmsis_svd_commit d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd +%global cmsis_svd_commit 2fb66c573555cc51e76dc03c003518366714139e %global compiler_rt_version 9.0.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit 80528c684b10aaee977397e7eb40c4784e6dc433 @@ -64,9 +64,6 @@ Patch0001: 0001-Skip-WASI-tests.patch Patch0002: 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch # https://github.com/tinygo-org/tinygo/pull/1538 Patch0003: 0003-Use-clang-to-do-linking.patch -# We can't include STM32 .svd files because of their weird license. -# https://github.com/tinygo-org/tinygo/pull/1718 -Patch0004: 0004-Group-together-STM32-smoke-tests.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -116,7 +113,6 @@ Recommends: qemu-system-arm-core %patch0001 -p1 %patch0002 -p1 %patch0003 -p1 -%patch0004 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS @@ -230,6 +226,9 @@ make wasmtest %changelog +* Thu May 13 2021 Elliott Sales de Andrade - 0.18.0-1 +- Update to latest version (#1960058) + * Sun Mar 14 2021 Elliott Sales de Andrade - 0.17.0-1 - Update to latest version (#1936121) From f19a9cedea9885b98c50d00946c3dd9619ed909b Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Fri, 23 Jul 2021 19:18:32 +0000 Subject: [PATCH 14/78] - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- tinygo.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index 3fb1583..0ca4d80 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -36,7 +36,7 @@ tools. Based on LLVM.} #global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} Name: tinygo -Release: 3%{?dist} +Release: 4%{?dist} Summary: Go compiler for small places # Main files: BSD @@ -238,6 +238,9 @@ make wasmtest %changelog +* Fri Jul 23 2021 Fedora Release Engineering - 0.16.0-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild + * Wed Jan 27 2021 Fedora Release Engineering - 0.16.0-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild From 0818c307caae2b60d408ff71e32b7d50270716b3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 5 Sep 2021 00:17:16 -0400 Subject: [PATCH 15/78] Update to latest version (#1978517) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 6 +++--- ...y-run-native-Linux-tests-on-their-own-GOARCH.patch | 6 +++--- 0003-Use-clang-to-do-linking.patch | 10 +++++----- clean_tarballs.sh | 3 ++- sources | 4 ++-- tinygo.spec | 11 +++++------ 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 10a84f7..5292c88 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ /tinygo-0.16.0.tar.gz /tinygo-0.17.0.tar.gz /tinygo-0.18.0.tar.gz +/tinygo-0.19.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index bcdec17..5f7d4c5 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,4 +1,4 @@ -From d3afa56a31a75d0fb5a696a22a52614ec038e89c Mon Sep 17 00:00:00 2001 +From e5e3be1140751de5175932c2b6c9b7bcf8d550be Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 Subject: [PATCH 1/3] Skip WASI tests. @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 4 deletions(-) diff --git a/main_test.go b/main_test.go -index 224a71b0..9a4dbc0f 100644 +index 51fd21fd..662fca66 100644 --- a/main_test.go +++ b/main_test.go @@ -108,10 +108,6 @@ func TestCompiler(t *testing.T) { @@ -26,5 +26,5 @@ index 224a71b0..9a4dbc0f 100644 // Test a few build options. -- -2.29.2 +2.31.1 diff --git a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch index 6651302..13c2650 100644 --- a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -1,4 +1,4 @@ -From 86f8ec3c802ddc08955203de9247e4b697e11f40 Mon Sep 17 00:00:00 2001 +From 4ac1cf8c54dd56d935bce8dc0b1863ff347345f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:26:02 -0500 Subject: [PATCH 2/3] Only run native Linux tests on their own GOARCH. @@ -12,7 +12,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/main_test.go b/main_test.go -index 9a4dbc0f..2956d7af 100644 +index 662fca66..aa2073fb 100644 --- a/main_test.go +++ b/main_test.go @@ -85,15 +85,24 @@ func TestCompiler(t *testing.T) { @@ -50,5 +50,5 @@ index 9a4dbc0f..2956d7af 100644 if err != nil { t.Error("could not get Go version:", err) -- -2.29.2 +2.31.1 diff --git a/0003-Use-clang-to-do-linking.patch b/0003-Use-clang-to-do-linking.patch index 7a281a3..686422b 100644 --- a/0003-Use-clang-to-do-linking.patch +++ b/0003-Use-clang-to-do-linking.patch @@ -1,4 +1,4 @@ -From c73218ed03707d7c566abe2105ef2969f2874578 Mon Sep 17 00:00:00 2001 +From bc8ebbf8b8f7b4e83f34a7fd90fbf64a8108f539 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:28:59 -0500 Subject: [PATCH 3/3] Use clang to do linking. @@ -13,10 +13,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 81de4ed0..f06f97f1 100644 +index ba5f7382..411d99d9 100644 --- a/compileopts/target.go +++ b/compileopts/target.go -@@ -244,9 +244,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { +@@ -247,9 +247,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { GOARCH: goarch, BuildTags: []string{goos, goarch}, Scheduler: "tasks", @@ -28,7 +28,7 @@ index 81de4ed0..f06f97f1 100644 GDB: []string{"gdb"}, PortReset: "false", } -@@ -265,18 +266,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { +@@ -268,18 +269,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { spec.GDB = []string{"gdb-multiarch"} if goarch == "arm" && goos == "linux" { spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") @@ -48,5 +48,5 @@ index 81de4ed0..f06f97f1 100644 return &spec, nil } -- -2.29.2 +2.31.1 diff --git a/clean_tarballs.sh b/clean_tarballs.sh index bef8955..50598f1 100755 --- a/clean_tarballs.sh +++ b/clean_tarballs.sh @@ -1,7 +1,7 @@ #!/bin/bash -e CMSIS_VERSION=9fe411cef1cef5de58e5957b89760759de44e393 -CMSIS_SVD_VERSION=2fb66c573555cc51e76dc03c003518366714139e +CMSIS_SVD_VERSION=9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce if [ -e "cmsis-${CMSIS_VERSION}-clean.tar.xz" ]; then echo "Not downloading cmsis-${CMSIS_VERSION}-clean.tar.xz again!" @@ -31,6 +31,7 @@ tar cJf cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Kendryte-Community/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/SiFive-Community/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/NXP/M* \ + cmsis-svd-${CMSIS_SVD_VERSION}/data/RaspberryPi/ \ # This has a weird license, so we cannot include it. # cmsis-svd-${CMSIS_SVD_VERSION}/data/STMicro/ rm -r cmsis-svd-${CMSIS_SVD_VERSION}/ diff --git a/sources b/sources index 81018c2..d343345 100644 --- a/sources +++ b/sources @@ -1,7 +1,7 @@ -SHA512 (tinygo-0.18.0.tar.gz) = 8e070f182b277f442ef64b7069b9a27b62efc44c75a335a2a14438d1740b2df2fe2c719d74b1110b9aa37caf70e74ceec3252e1707dca3506adae4c03a2568fa +SHA512 (tinygo-0.19.0.tar.gz) = 2decbf3f74318387b1cf22ca33240c8942237992de145f29bf548bfac04e95c73980c0f722be075f7e65a637d44c9a31fe22a253e5f168046d120d4a55bcfdf7 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 -SHA512 (cmsis_svd-2fb66c573555cc51e76dc03c003518366714139e-clean.tar.xz) = 09fe3c92537bcea70599f9979a1d6291d22c7b6a6f4ac674d3f19e6b3c18728db4f4f0996803f08b97c4a64206f060a2dd4f46c1cc356ce4add8df6f8838019f +SHA512 (cmsis_svd-9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce-clean.tar.xz) = 27e8d725944d15e3fac27154a695d9722062f217c183ac86e28e525c838b969809252f0932f739d205177f73f5ba23ef6467476127edb354b61ddddd7f0885d4 SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-80528c684b10aaee977397e7eb40c4784e6dc433.tar.gz) = d7cdddf4ba2c4c4a447864e899c9e92674438358e8c1123c80d38b0c1d57cb35fdaaa60a73a16331637884d23207fdc9f06d7f28dc5920c76e25808869e2c7b1 diff --git a/tinygo.spec b/tinygo.spec index 69f8ae0..a555fae 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,16 +6,12 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.18.0 +Version: 0.19.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%if %{fedora} > 32 %global clang_version 11 -%else -%global clang_version 10 -%endif -%global cmsis_svd_commit 2fb66c573555cc51e76dc03c003518366714139e +%global cmsis_svd_commit 9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce %global compiler_rt_version 9.0.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit 80528c684b10aaee977397e7eb40c4784e6dc433 @@ -226,6 +222,9 @@ make wasmtest %changelog +* Sun Sep 05 2021 Elliott Sales de Andrade - 0.19.0-1 +- Update to latest version (#1978517) + * Thu May 13 2021 Elliott Sales de Andrade - 0.18.0-1 - Update to latest version (#1960058) From dfb60b5bad8c8bca7c652a4a1b69cafda6010122 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 29 Nov 2021 05:44:00 -0500 Subject: [PATCH 16/78] Convert to rpmautospec --- changelog | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ tinygo.spec | 82 ++--------------------------------------------------- 2 files changed, 81 insertions(+), 80 deletions(-) create mode 100644 changelog diff --git a/changelog b/changelog new file mode 100644 index 0000000..63ea1b9 --- /dev/null +++ b/changelog @@ -0,0 +1,79 @@ +* Sun Sep 05 2021 Elliott Sales de Andrade - 0.19.0-1 +- Update to latest version (#1978517) + +* Fri Jul 23 2021 Fedora Release Engineering - 0.16.0-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild + +* Thu May 13 2021 Elliott Sales de Andrade - 0.18.0-1 +- Update to latest version (#1960058) + +* Sun Mar 14 2021 Elliott Sales de Andrade - 0.17.0-1 +- Update to latest version (#1936121) + +* Wed Jan 27 2021 Fedora Release Engineering - 0.16.0-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild + +* Fri Jan 22 2021 Tom Stellard - 0.16.0-2 +- Rebuild for clang-11.1.0 + +* Sun Sep 20 2020 Elliott Sales de Andrade - 0.15.0-1 +- Update to latest version (#1866183) +- Loosen up runtime clang requirement + +* Sat Aug 22 2020 Elliott Sales de Andrade - 0.14.1-1 +- Update to latest version (#1866183) + +* Sun Aug 02 2020 Elliott Sales de Andrade - 0.13.1-3 +- Patch to allow Go 1.15 + +* Sat Aug 01 2020 Fedora Release Engineering - 0.13.1-3 +- Second attempt - Rebuilt for + https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild + +* Wed Jul 29 2020 Fedora Release Engineering - 0.13.1-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild + +* Thu Apr 30 2020 Elliott Sales de Andrade - 0.13.1-1 +- Update to latest version + +* Mon Apr 20 2020 Elliott Sales de Andrade - 0.13.0-1 +- Update to latest version + +* Sun Apr 19 2020 Elliott Sales de Andrade - 0.12.0-1 +- Update to latest version + +* Wed Mar 04 2020 Elliott Sales de Andrade - 0.11.0-3 +- Update required clang version + +* Tue Feb 11 2020 Elliott Sales de Andrade - 0.11.0-3 +- Enable RISCV tests +- Enable AVR tests +- Add Recommends for AVR dependencies + +* Mon Feb 10 2020 Elliott Sales de Andrade - 0.11.0-2 +- Fix setting of TINYGOROOT to point to packaged version + +* Mon Feb 10 2020 Elliott Sales de Andrade - 0.11.0-1 +- Update to 0.11.0 + +* Mon Feb 10 2020 Elliott Sales de Andrade - 0.10.0-1 +- Update to 0.10.0 + +* Mon Feb 10 2020 Elliott Sales de Andrade - 0.9.0-1 +- Update to 0.9.0 + +* Tue Sep 24 2019 Elliott Sales de Andrade - 0.8.0-1 +- Update to latest version +- Enable x86 build + +* Sun Aug 04 2019 Elliott Sales de Andrade - 0.7.1-1 +- Update to latest version + +* Sat Jul 27 2019 Fedora Release Engineering - 0.7.0-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild + +* Tue Jul 23 2019 Elliott Sales de Andrade - 0.7.0-1 +- Update to latest version + +* Tue Jun 11 01:26:10 EDT 2019 Elliott Sales de Andrade - 0.6.0-1 +- Initial package diff --git a/tinygo.spec b/tinygo.spec index 00de4c2..5ac54b8 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -32,7 +32,7 @@ tools. Based on LLVM.} #global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} Name: tinygo -Release: 1%{?dist} +Release: %autorelease Summary: Go compiler for small places # Main files: BSD @@ -222,82 +222,4 @@ make wasmtest %changelog -* Sun Sep 05 2021 Elliott Sales de Andrade - 0.19.0-1 -- Update to latest version (#1978517) - -* Fri Jul 23 2021 Fedora Release Engineering - 0.16.0-4 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild - -* Thu May 13 2021 Elliott Sales de Andrade - 0.18.0-1 -- Update to latest version (#1960058) - -* Sun Mar 14 2021 Elliott Sales de Andrade - 0.17.0-1 -- Update to latest version (#1936121) - -* Wed Jan 27 2021 Fedora Release Engineering - 0.16.0-3 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild - -* Fri Jan 22 2021 Tom Stellard - 0.16.0-2 -- Rebuild for clang-11.1.0 - -* Sun Sep 20 2020 Elliott Sales de Andrade - 0.15.0-1 -- Update to latest version (#1866183) -- Loosen up runtime clang requirement - -* Sat Aug 22 2020 Elliott Sales de Andrade - 0.14.1-1 -- Update to latest version (#1866183) - -* Sun Aug 02 2020 Elliott Sales de Andrade - 0.13.1-3 -- Patch to allow Go 1.15 - -* Sat Aug 01 2020 Fedora Release Engineering - 0.13.1-3 -- Second attempt - Rebuilt for - https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild - -* Wed Jul 29 2020 Fedora Release Engineering - 0.13.1-2 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild - -* Thu Apr 30 2020 Elliott Sales de Andrade - 0.13.1-1 -- Update to latest version - -* Mon Apr 20 2020 Elliott Sales de Andrade - 0.13.0-1 -- Update to latest version - -* Sun Apr 19 2020 Elliott Sales de Andrade - 0.12.0-1 -- Update to latest version - -* Wed Mar 04 2020 Elliott Sales de Andrade - 0.11.0-3 -- Update required clang version - -* Tue Feb 11 2020 Elliott Sales de Andrade - 0.11.0-3 -- Enable RISCV tests -- Enable AVR tests -- Add Recommends for AVR dependencies - -* Mon Feb 10 2020 Elliott Sales de Andrade - 0.11.0-2 -- Fix setting of TINYGOROOT to point to packaged version - -* Mon Feb 10 2020 Elliott Sales de Andrade - 0.11.0-1 -- Update to 0.11.0 - -* Mon Feb 10 2020 Elliott Sales de Andrade - 0.10.0-1 -- Update to 0.10.0 - -* Mon Feb 10 2020 Elliott Sales de Andrade - 0.9.0-1 -- Update to 0.9.0 - -* Tue Sep 24 2019 Elliott Sales de Andrade - 0.8.0-1 -- Update to latest version -- Enable x86 build - -* Sun Aug 04 2019 Elliott Sales de Andrade - 0.7.1-1 -- Update to latest version - -* Sat Jul 27 2019 Fedora Release Engineering - 0.7.0-2 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild - -* Tue Jul 23 2019 Elliott Sales de Andrade - 0.7.0-1 -- Update to latest version - -* Tue Jun 11 01:26:10 EDT 2019 Elliott Sales de Andrade - 0.6.0-1 -- Initial package +%autochangelog From 52b73ed7f4072490f2eeb3abaec7f68ef69243f0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 29 Nov 2021 05:32:49 -0500 Subject: [PATCH 17/78] Support multi-LLVM build from golang-tinygo-x-llvm --- 0001-Skip-WASI-tests.patch | 2 +- ...tive-Linux-tests-on-their-own-GOARCH.patch | 2 +- 0003-Use-clang-to-do-linking.patch | 2 +- ...row-argument-to-llvm.InlineAsm-calls.patch | 127 ++++++++++++++++++ tinygo.spec | 16 ++- 5 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 5f7d4c5..28d291c 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From e5e3be1140751de5175932c2b6c9b7bcf8d550be Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/3] Skip WASI tests. +Subject: [PATCH 1/4] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch index 13c2650..06764a8 100644 --- a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -1,7 +1,7 @@ From 4ac1cf8c54dd56d935bce8dc0b1863ff347345f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:26:02 -0500 -Subject: [PATCH 2/3] Only run native Linux tests on their own GOARCH. +Subject: [PATCH 2/4] Only run native Linux tests on their own GOARCH. We don't have the cross-compiled C libraries to do this. Even 386 builds on koji do not work for this because it does not support multilib. diff --git a/0003-Use-clang-to-do-linking.patch b/0003-Use-clang-to-do-linking.patch index 686422b..c7927d9 100644 --- a/0003-Use-clang-to-do-linking.patch +++ b/0003-Use-clang-to-do-linking.patch @@ -1,7 +1,7 @@ From bc8ebbf8b8f7b4e83f34a7fd90fbf64a8108f539 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:28:59 -0500 -Subject: [PATCH 3/3] Use clang to do linking. +Subject: [PATCH 3/4] Use clang to do linking. This avoids having to guess what the linker name-with-build-triplet is, as we can just pass the target to it in the same way as the compilation diff --git a/0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch b/0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch new file mode 100644 index 0000000..82511c3 --- /dev/null +++ b/0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch @@ -0,0 +1,127 @@ +From 763a6ed16697dc032fdd125b916bb7e349655b29 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 6 Sep 2021 05:01:19 -0400 +Subject: [PATCH 4/4] Add canThrow argument to llvm.InlineAsm calls + +This is new in LLVM 13, and uses the default `false` which matches the +default in the LLVM-internal `InlineAsm::get`, but I don't know if +that's the right thing here because docs are difficult to find. + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/inlineasm.go | 16 ++++++++-------- + compiler/syscall.go | 8 ++++---- + 2 files changed, 12 insertions(+), 12 deletions(-) + +diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go +index 31312a92..b99b1360 100644 +--- a/compiler/inlineasm.go ++++ b/compiler/inlineasm.go +@@ -24,7 +24,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { + // Magic function: insert inline assembly instead of calling it. + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{}, false) + asm := constant.StringVal(args[0].(*ssa.Const).Value) +- target := llvm.InlineAsm(fnType, asm, "", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "", true, false, 0, false) + return b.CreateCall(target, nil, ""), nil + } + +@@ -116,7 +116,7 @@ func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) + outputType = b.ctx.VoidType() + } + fnType := llvm.FunctionType(outputType, argTypes, false) +- target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0) ++ target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0, false) + result := b.CreateCall(target, args, "") + if hasOutput { + return result, nil +@@ -159,7 +159,7 @@ func (b *builder) emitSVCall(args []ssa.Value) (llvm.Value, error) { + // marked as clobbered. + constraints += ",~{r1},~{r2},~{r3}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) + return b.CreateCall(target, llvmArgs, ""), nil + } + +@@ -197,7 +197,7 @@ func (b *builder) emitSV64Call(args []ssa.Value) (llvm.Value, error) { + // marked as clobbered. + constraints += ",~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) + return b.CreateCall(target, llvmArgs, ""), nil + } + +@@ -222,24 +222,24 @@ func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error) { + // marked as such. + fnType := llvm.FunctionType(b.uintptrType, nil, false) + asm := fmt.Sprintf("csrr $0, %d", csr) +- target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0, false) + return b.CreateCall(target, nil, ""), nil + case "Set": + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrw %d, $0", csr) +- target := llvm.InlineAsm(fnType, asm, "r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "r", true, false, 0, false) + return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + case "SetBits": + // Note: it may be possible to optimize this to csrrsi in many cases. + fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrrs $0, %d, $1", csr) +- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) + return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + case "ClearBits": + // Note: it may be possible to optimize this to csrrci in many cases. + fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrrc $0, %d, $1", csr) +- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) + return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + default: + return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) +diff --git a/compiler/syscall.go b/compiler/syscall.go +index 6a0bd328..582f2c5f 100644 +--- a/compiler/syscall.go ++++ b/compiler/syscall.go +@@ -56,7 +56,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + } + constraints += ",~{rcx},~{r11}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel) ++ target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false) + return b.CreateCall(target, args, ""), nil + case b.GOARCH == "386" && b.GOOS == "linux": + // Sources: +@@ -82,7 +82,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + argTypes = append(argTypes, llvmValue.Type()) + } + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel) ++ target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false) + return b.CreateCall(target, args, ""), nil + case b.GOARCH == "arm" && b.GOOS == "linux": + // Implement the EABI system call convention for Linux. +@@ -114,7 +114,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + constraints += ",~{r" + strconv.Itoa(i) + "}" + } + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) + return b.CreateCall(target, args, ""), nil + case b.GOARCH == "arm64" && b.GOOS == "linux": + // Source: syscall(2) man page. +@@ -146,7 +146,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + } + constraints += ",~{x16},~{x17}" // scratch registers + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) + return b.CreateCall(target, args, ""), nil + default: + return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH) +-- +2.31.1 + diff --git a/tinygo.spec b/tinygo.spec index 5ac54b8..7c8277d 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,7 +10,7 @@ Version: 0.19.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%global clang_version 11 +%global clang_llvm_version 11 %global cmsis_svd_commit 9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce %global compiler_rt_version 9.0.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 @@ -60,12 +60,12 @@ Patch0001: 0001-Skip-WASI-tests.patch Patch0002: 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch # https://github.com/tinygo-org/tinygo/pull/1538 Patch0003: 0003-Use-clang-to-do-linking.patch +Patch0004: 0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x -BuildRequires: make -BuildRequires: (clang-devel >= %{clang_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_version}')) + 1)}) +BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) BuildRequires: golang(github.com/blakesmith/ar) %ifnarch %{ix86} BuildRequires: chromium @@ -79,6 +79,8 @@ BuildRequires: golang(go.bug.st/serial) >= 1.1.2 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) BuildRequires: golang(golang.org/x/tools/go/ssa) BuildRequires: golang(tinygo.org/x/go-llvm) +BuildRequires: llvm-devel(major) = %{clang_llvm_version} +BuildRequires: make BuildRequires: avr-gcc BuildRequires: avr-libc @@ -109,6 +111,7 @@ Recommends: qemu-system-arm-core %patch0001 -p1 %patch0002 -p1 %patch0003 -p1 +%patch0004 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS @@ -142,7 +145,9 @@ mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc %build -export LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " +# Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is +# merged and released. +export BUILDTAGS="llvm%{clang_llvm_version}" LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} GO111MODULE=off %make_build gen-device STM32=0 for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do @@ -152,7 +157,7 @@ for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do build-library -target=$target -o ${target}-${libc}.a ${libc} done done -%make_build wasi-libc CLANG=clang-%{clang_version} LLVM_AR=llvm-ar LLVM_NM=llvm-nm +%make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=llvm-ar LLVM_NM=llvm-nm %install @@ -194,6 +199,7 @@ cp -rp targets %{buildroot}%{tinygoroot}/ %if %{with check} +%global gotestflags %gocompilerflags -tags="llvm%{clang_llvm_version}" %check export TINYGOROOT=%{buildroot}%{tinygoroot} export GOPATH=%{buildroot}%{tinygoroot}:%{gopath} From 4ce2174a9a4835e88ebfa4e48d294aaefad58a63 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 29 Nov 2021 05:49:40 -0500 Subject: [PATCH 18/78] Update to 0.20.0 (#1978517) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 17 ++++++++--------- ...native-Linux-tests-on-their-own-GOARCH.patch | 12 ++++++------ 0003-Use-clang-to-do-linking.patch | 8 ++++---- clean_tarballs.sh | 3 ++- sources | 4 ++-- tinygo.spec | 6 +++--- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 5292c88..dcf20a6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ /tinygo-0.17.0.tar.gz /tinygo-0.18.0.tar.gz /tinygo-0.19.0.tar.gz +/tinygo-0.20.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 28d291c..30f6d29 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,4 +1,4 @@ -From e5e3be1140751de5175932c2b6c9b7bcf8d550be Mon Sep 17 00:00:00 2001 +From 370c2cd8a92ff431503bfb823b15b30478767ffb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 Subject: [PATCH 1/4] Skip WASI tests. @@ -7,18 +7,17 @@ We do not have wasmtime available. Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 4 ---- - 1 file changed, 4 deletions(-) + main_test.go | 3 --- + 1 file changed, 3 deletions(-) diff --git a/main_test.go b/main_test.go -index 51fd21fd..662fca66 100644 +index 7ebf8eb0..cdba1c3f 100644 --- a/main_test.go +++ b/main_test.go -@@ -108,10 +108,6 @@ func TestCompiler(t *testing.T) { - runPlatTests("wasm", tests, t) - }) - } -- +@@ -106,9 +106,6 @@ func TestCompiler(t *testing.T) { + t.Run("WebAssembly", func(t *testing.T) { + runPlatTests("wasm", tests, t) + }) - t.Run("WASI", func(t *testing.T) { - runPlatTests("wasi", tests, t) - }) diff --git a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch index 06764a8..910762a 100644 --- a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -1,4 +1,4 @@ -From 4ac1cf8c54dd56d935bce8dc0b1863ff347345f4 Mon Sep 17 00:00:00 2001 +From 64dc7032e3e942a26a4a3a8f24c6b1fce4f36f04 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:26:02 -0500 Subject: [PATCH 2/4] Only run native Linux tests on their own GOARCH. @@ -12,10 +12,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/main_test.go b/main_test.go -index 662fca66..aa2073fb 100644 +index cdba1c3f..beb65994 100644 --- a/main_test.go +++ b/main_test.go -@@ -85,15 +85,24 @@ func TestCompiler(t *testing.T) { +@@ -94,15 +94,24 @@ func TestCompiler(t *testing.T) { } if runtime.GOOS == "linux" { @@ -46,9 +46,9 @@ index 662fca66..aa2073fb 100644 + runPlatTests("aarch64--linux-gnu", tests, t) + }) + } - goVersion, err := goenv.GorootVersionString(goenv.Get("GOROOT")) - if err != nil { - t.Error("could not get Go version:", err) + t.Run("WebAssembly", func(t *testing.T) { + runPlatTests("wasm", tests, t) + }) -- 2.31.1 diff --git a/0003-Use-clang-to-do-linking.patch b/0003-Use-clang-to-do-linking.patch index c7927d9..02df169 100644 --- a/0003-Use-clang-to-do-linking.patch +++ b/0003-Use-clang-to-do-linking.patch @@ -1,4 +1,4 @@ -From bc8ebbf8b8f7b4e83f34a7fd90fbf64a8108f539 Mon Sep 17 00:00:00 2001 +From ebec9ce9c029ce56820b6b07051cd6ad76988e30 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:28:59 -0500 Subject: [PATCH 3/4] Use clang to do linking. @@ -13,10 +13,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go -index ba5f7382..411d99d9 100644 +index a84896c9..cf654748 100644 --- a/compileopts/target.go +++ b/compileopts/target.go -@@ -247,9 +247,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { +@@ -248,9 +248,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { GOARCH: goarch, BuildTags: []string{goos, goarch}, Scheduler: "tasks", @@ -28,7 +28,7 @@ index ba5f7382..411d99d9 100644 GDB: []string{"gdb"}, PortReset: "false", } -@@ -268,18 +269,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { +@@ -272,18 +273,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { spec.GDB = []string{"gdb-multiarch"} if goarch == "arm" && goos == "linux" { spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") diff --git a/clean_tarballs.sh b/clean_tarballs.sh index 50598f1..84b74a5 100755 --- a/clean_tarballs.sh +++ b/clean_tarballs.sh @@ -1,7 +1,7 @@ #!/bin/bash -e CMSIS_VERSION=9fe411cef1cef5de58e5957b89760759de44e393 -CMSIS_SVD_VERSION=9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce +CMSIS_SVD_VERSION=df75ff974c76a911fc2815e29807f5ecaae06fc2 if [ -e "cmsis-${CMSIS_VERSION}-clean.tar.xz" ]; then echo "Not downloading cmsis-${CMSIS_VERSION}-clean.tar.xz again!" @@ -27,6 +27,7 @@ wget -nc https://github.com/tinygo-org/cmsis-svd/archive/${CMSIS_SVD_VERSION}/cm tar xf cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz tar cJf cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Atmel/ \ + cmsis-svd-${CMSIS_SVD_VERSION}/data/Espressif/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Espressif-Community/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Kendryte-Community/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/SiFive-Community/ \ diff --git a/sources b/sources index d343345..a08cd59 100644 --- a/sources +++ b/sources @@ -1,7 +1,7 @@ -SHA512 (tinygo-0.19.0.tar.gz) = 2decbf3f74318387b1cf22ca33240c8942237992de145f29bf548bfac04e95c73980c0f722be075f7e65a637d44c9a31fe22a253e5f168046d120d4a55bcfdf7 +SHA512 (tinygo-0.20.0.tar.gz) = 6a675c306badf11fe25ff968491693d3d9ac6116df5c99ec4fa32bb484217faf0d7160f9899ce7ac2c78e4eb680fbff20b1b0815c4038987f7becabef9a0a65a SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 -SHA512 (cmsis_svd-9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce-clean.tar.xz) = 27e8d725944d15e3fac27154a695d9722062f217c183ac86e28e525c838b969809252f0932f739d205177f73f5ba23ef6467476127edb354b61ddddd7f0885d4 +SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-80528c684b10aaee977397e7eb40c4784e6dc433.tar.gz) = d7cdddf4ba2c4c4a447864e899c9e92674438358e8c1123c80d38b0c1d57cb35fdaaa60a73a16331637884d23207fdc9f06d7f28dc5920c76e25808869e2c7b1 diff --git a/tinygo.spec b/tinygo.spec index 7c8277d..c15e9fc 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,12 +6,12 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.19.0 +Version: 0.20.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 %global clang_llvm_version 11 -%global cmsis_svd_commit 9c35b6d9df1f9eeecfcc33fc6f98719dbaaa30ce +%global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version 9.0.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit 80528c684b10aaee977397e7eb40c4784e6dc433 @@ -77,7 +77,7 @@ BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 BuildRequires: golang(go.bug.st/serial) >= 1.1.2 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) -BuildRequires: golang(golang.org/x/tools/go/ssa) +BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.7 BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: llvm-devel(major) = %{clang_llvm_version} BuildRequires: make From 33d138a833fa2acf08019cc05573f3d425e53ad1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:52:54 -0500 Subject: [PATCH 19/78] Update to latest version (#1978517) --- .gitignore | 3 + 0001-Skip-WASI-tests.patch | 12 +- ...tive-Linux-tests-on-their-own-GOARCH.patch | 41 ++++-- ...row-argument-to-llvm.InlineAsm-calls.patch | 8 +- 0003-Use-clang-to-do-linking.patch | 52 -------- 0004-Use-system-mingw64-headers-and-crt.patch | 121 ++++++++++++++++++ musl.pub | 30 +++++ sources | 8 +- tinygo.spec | 98 ++++++++++---- 9 files changed, 272 insertions(+), 101 deletions(-) rename 0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch => 0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch (97%) delete mode 100644 0003-Use-clang-to-do-linking.patch create mode 100644 0004-Use-system-mingw64-headers-and-crt.patch create mode 100644 musl.pub diff --git a/.gitignore b/.gitignore index dcf20a6..453f063 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ /tinygo-0.18.0.tar.gz /tinygo-0.19.0.tar.gz /tinygo-0.20.0.tar.gz +/tinygo-0.21.0.tar.gz +/musl-1.2.2.tar.gz +/musl-1.2.2.tar.gz.asc diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 30f6d29..939dd5a 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,4 +1,4 @@ -From 370c2cd8a92ff431503bfb823b15b30478767ffb Mon Sep 17 00:00:00 2001 +From 9b9f5ddc40d838c0141a81f718bb57e546dbc742 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 Subject: [PATCH 1/4] Skip WASI tests. @@ -11,19 +11,19 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 3 deletions(-) diff --git a/main_test.go b/main_test.go -index 7ebf8eb0..cdba1c3f 100644 +index d1ef1964..d74e0d67 100644 --- a/main_test.go +++ b/main_test.go -@@ -106,9 +106,6 @@ func TestCompiler(t *testing.T) { +@@ -144,9 +144,6 @@ func TestCompiler(t *testing.T) { t.Run("WebAssembly", func(t *testing.T) { - runPlatTests("wasm", tests, t) + runPlatTests(optionsFromTarget("wasm"), tests, t) }) - t.Run("WASI", func(t *testing.T) { -- runPlatTests("wasi", tests, t) +- runPlatTests(optionsFromTarget("wasi"), tests, t) - }) } + } - // Test a few build options. -- 2.31.1 diff --git a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch index 910762a..2cc8ab1 100644 --- a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch @@ -1,4 +1,4 @@ -From 64dc7032e3e942a26a4a3a8f24c6b1fce4f36f04 Mon Sep 17 00:00:00 2001 +From 0fb55aa3fbf96a77ac86651cf9649843e0faa831 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 21 Dec 2020 04:26:02 -0500 Subject: [PATCH 2/4] Only run native Linux tests on their own GOARCH. @@ -8,46 +8,61 @@ on koji do not work for this because it does not support multilib. Signed-off-by: Elliott Sales de Andrade --- + Makefile | 2 ++ main_test.go | 27 ++++++++++++++++++--------- - 1 file changed, 18 insertions(+), 9 deletions(-) + 2 files changed, 20 insertions(+), 9 deletions(-) +diff --git a/Makefile b/Makefile +index 5de97014..64d68e2b 100644 +--- a/Makefile ++++ b/Makefile +@@ -479,7 +479,9 @@ endif + @$(MD5SUM) test.nro + $(TINYGO) build -size short -o test.hex -target=pca10040 -opt=0 ./testdata/stdlib.go + @$(MD5SUM) test.hex ++ifeq ($(shell uname -p), aarch64) + GOOS=linux GOARCH=arm $(TINYGO) build -size short -o test.elf ./testdata/cgo ++endif + GOOS=windows GOARCH=amd64 $(TINYGO) build -o test.exe ./testdata/cgo + ifneq ($(OS),Windows_NT) + # TODO: this does not yet work on Windows. Somehow, unused functions are diff --git a/main_test.go b/main_test.go -index cdba1c3f..beb65994 100644 +index d74e0d67..1946ee1b 100644 --- a/main_test.go +++ b/main_test.go -@@ -94,15 +94,24 @@ func TestCompiler(t *testing.T) { - } +@@ -132,15 +132,24 @@ func TestCompiler(t *testing.T) { + }) if runtime.GOOS == "linux" { - t.Run("X86Linux", func(t *testing.T) { -- runPlatTests("i386--linux-gnu", tests, t) +- runPlatTests(optionsFromOSARCH("linux/386"), tests, t) - }) - t.Run("ARMLinux", func(t *testing.T) { -- runPlatTests("arm--linux-gnueabihf", tests, t) +- runPlatTests(optionsFromOSARCH("linux/arm/6"), tests, t) - }) - t.Run("ARM64Linux", func(t *testing.T) { -- runPlatTests("aarch64--linux-gnu", tests, t) +- runPlatTests(optionsFromOSARCH("linux/arm64"), tests, t) - }) + switch runtime.GOARCH { + case "386": + t.Run("X86Linux", func(t *testing.T) { -+ runPlatTests("i386--linux-gnu", tests, t) ++ runPlatTests(optionsFromOSARCH("linux/386"), tests, t) + }) + case "amd64": + t.Run("AMD64Linux", func(t *testing.T) { -+ runPlatTests("amd64--linux-gnu", tests, t) ++ runPlatTests(optionsFromOSARCH("linux/amd64"), tests, t) + }) + case "arm": + t.Run("ARMLinux", func(t *testing.T) { -+ runPlatTests("arm--linux-gnueabihf", tests, t) ++ runPlatTests(optionsFromOSARCH("linux/arm/6"), tests, t) + }) + case "arm64": + t.Run("ARM64Linux", func(t *testing.T) { -+ runPlatTests("aarch64--linux-gnu", tests, t) ++ runPlatTests(optionsFromOSARCH("linux/arm64"), tests, t) + }) + } t.Run("WebAssembly", func(t *testing.T) { - runPlatTests("wasm", tests, t) + runPlatTests(optionsFromTarget("wasm"), tests, t) }) -- 2.31.1 diff --git a/0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch b/0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch similarity index 97% rename from 0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch rename to 0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch index 82511c3..915cae6 100644 --- a/0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +++ b/0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch @@ -1,7 +1,7 @@ -From 763a6ed16697dc032fdd125b916bb7e349655b29 Mon Sep 17 00:00:00 2001 +From c9cdcacd078cec5dc117c1257fa81b7b1f03398a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 6 Sep 2021 05:01:19 -0400 -Subject: [PATCH 4/4] Add canThrow argument to llvm.InlineAsm calls +Subject: [PATCH 3/4] Add canThrow argument to llvm.InlineAsm calls This is new in LLVM 13, and uses the default `false` which matches the default in the LLVM-internal `InlineAsm::get`, but I don't know if @@ -14,7 +14,7 @@ Signed-off-by: Elliott Sales de Andrade 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go -index 31312a92..b99b1360 100644 +index e32a4f39..635aed98 100644 --- a/compiler/inlineasm.go +++ b/compiler/inlineasm.go @@ -24,7 +24,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { @@ -83,7 +83,7 @@ index 31312a92..b99b1360 100644 default: return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) diff --git a/compiler/syscall.go b/compiler/syscall.go -index 6a0bd328..582f2c5f 100644 +index db379d52..37330684 100644 --- a/compiler/syscall.go +++ b/compiler/syscall.go @@ -56,7 +56,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { diff --git a/0003-Use-clang-to-do-linking.patch b/0003-Use-clang-to-do-linking.patch deleted file mode 100644 index 02df169..0000000 --- a/0003-Use-clang-to-do-linking.patch +++ /dev/null @@ -1,52 +0,0 @@ -From ebec9ce9c029ce56820b6b07051cd6ad76988e30 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 21 Dec 2020 04:28:59 -0500 -Subject: [PATCH 3/4] Use clang to do linking. - -This avoids having to guess what the linker name-with-build-triplet is, -as we can just pass the target to it in the same way as the compilation -stage. - -Signed-off-by: Elliott Sales de Andrade ---- - compileopts/target.go | 9 ++------- - 1 file changed, 2 insertions(+), 7 deletions(-) - -diff --git a/compileopts/target.go b/compileopts/target.go -index a84896c9..cf654748 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -248,9 +248,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - GOARCH: goarch, - BuildTags: []string{goos, goarch}, - Scheduler: "tasks", -- Linker: "cc", - DefaultStackSize: 1024 * 64, // 64kB - CFlags: []string{"--target=" + triple}, -+ Linker: "clang", -+ LDFlags: []string{"--target=" + triple}, - GDB: []string{"gdb"}, - PortReset: "false", - } -@@ -272,18 +273,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - spec.GDB = []string{"gdb-multiarch"} - if goarch == "arm" && goos == "linux" { - spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") -- spec.Linker = "arm-linux-gnueabihf-gcc" - spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} - } - if goarch == "arm64" && goos == "linux" { - spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") -- spec.Linker = "aarch64-linux-gnu-gcc" - spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"} - } -- if goarch == "386" && runtime.GOARCH == "amd64" { -- spec.CFlags = append(spec.CFlags, "-m32") -- spec.LDFlags = append(spec.LDFlags, "-m32") -- } - } - return &spec, nil - } --- -2.31.1 - diff --git a/0004-Use-system-mingw64-headers-and-crt.patch b/0004-Use-system-mingw64-headers-and-crt.patch new file mode 100644 index 0000000..656a9c7 --- /dev/null +++ b/0004-Use-system-mingw64-headers-and-crt.patch @@ -0,0 +1,121 @@ +From dcc3645326cc044066bef90b704a3836e335fa00 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 2 Jan 2022 05:47:18 -0500 +Subject: [PATCH 4/4] Use system mingw64 headers and crt + +Signed-off-by: Elliott Sales de Andrade +--- + builder/mingw-w64.go | 66 +++---------------------------------------- + compileopts/config.go | 7 ++--- + 2 files changed, 6 insertions(+), 67 deletions(-) + +diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go +index bdab730f..07ce05c8 100644 +--- a/builder/mingw-w64.go ++++ b/builder/mingw-w64.go +@@ -1,31 +1,11 @@ + package builder + + import ( +- "io" +- "os" +- "path/filepath" +- "strings" +- +- "github.com/tinygo-org/tinygo/goenv" ++ "fmt" + ) + + var MinGW = Library{ + name: "mingw-w64", +- makeHeaders: func(target, includeDir string) error { +- // copy _mingw.h +- srcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib", "mingw-w64") +- outf, err := os.Create(includeDir + "/_mingw.h") +- if err != nil { +- return err +- } +- defer outf.Close() +- inf, err := os.Open(srcDir + "/mingw-w64-headers/crt/_mingw.h.in") +- if err != nil { +- return err +- } +- _, err = io.Copy(outf, inf) +- return err +- }, + cflags: func(target, headerPath string) []string { + // No flags necessary because there are no files to compile. + return nil +@@ -44,47 +24,9 @@ var MinGW = Library{ + // compile these files. + func makeMinGWExtraLibs(tmpdir string) []*compileJob { + var jobs []*compileJob +- root := goenv.Get("TINYGOROOT") +- // Normally all the api-ms-win-crt-*.def files are all compiled to a single +- // .lib file. But to simplify things, we're going to leave them as separate +- // files. +- for _, name := range []string{ +- "kernel32.def.in", +- "api-ms-win-crt-conio-l1-1-0.def", +- "api-ms-win-crt-convert-l1-1-0.def", +- "api-ms-win-crt-environment-l1-1-0.def", +- "api-ms-win-crt-filesystem-l1-1-0.def", +- "api-ms-win-crt-heap-l1-1-0.def", +- "api-ms-win-crt-locale-l1-1-0.def", +- "api-ms-win-crt-math-l1-1-0.def.in", +- "api-ms-win-crt-multibyte-l1-1-0.def", +- "api-ms-win-crt-private-l1-1-0.def.in", +- "api-ms-win-crt-process-l1-1-0.def", +- "api-ms-win-crt-runtime-l1-1-0.def.in", +- "api-ms-win-crt-stdio-l1-1-0.def", +- "api-ms-win-crt-string-l1-1-0.def", +- "api-ms-win-crt-time-l1-1-0.def", +- "api-ms-win-crt-utility-l1-1-0.def", +- } { +- outpath := filepath.Join(tmpdir, filepath.Base(name)+".lib") +- inpath := filepath.Join(root, "lib/mingw-w64/mingw-w64-crt/lib-common/"+name) +- job := &compileJob{ +- description: "create lib file " + inpath, +- result: outpath, +- run: func(job *compileJob) error { +- defpath := inpath +- if strings.HasSuffix(inpath, ".in") { +- // .in files need to be preprocessed by a preprocessor (-E) +- // first. +- defpath = outpath + ".def" +- err := runCCompiler("-E", "-x", "c", "-Wp,-w", "-P", "-DDEF_X64", "-o", defpath, inpath, "-I"+goenv.Get("TINYGOROOT")+"/lib/mingw-w64/mingw-w64-crt/def-include/") +- if err != nil { +- return err +- } +- } +- return link("ld.lld", "-m", "i386pep", "-o", outpath, defpath) +- }, +- } ++ for _, name := range []string{"kernel32", "ucrt"} { ++ outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) ++ job := dummyCompileJob(outpath) + jobs = append(jobs, job) + } + return jobs +diff --git a/compileopts/config.go b/compileopts/config.go +index 22cb676e..1f54e157 100644 +--- a/compileopts/config.go ++++ b/compileopts/config.go +@@ -273,12 +273,9 @@ func (c *Config) CFlags() []string { + root := goenv.Get("TINYGOROOT") + cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") + case "mingw-w64": +- root := goenv.Get("TINYGOROOT") +- path, _ := c.LibcPath("mingw-w64") + cflags = append(cflags, +- "--sysroot="+path, +- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"), +- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"), ++ "--sysroot=/usr/x86_64-w64-mingw32/sys-root", ++ "-Xclang", "-internal-isystem", "-Xclang", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", + "-D_UCRT", + ) + case "": +-- +2.31.1 + diff --git a/musl.pub b/musl.pub new file mode 100644 index 0000000..7b7a8e9 --- /dev/null +++ b/musl.pub @@ -0,0 +1,30 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.12 (GNU/Linux) + +mQENBFNcU8EBCAC3g30bXEEh+YzD06JQ+iG+gr5Nb+tjianh8aJ/ql35lqICVj6F +nitol0KgSB1L3T80+EON3IEmic9rb2dw6EQ0rMl/6mSW91jQC1rGkGBZnlPZXOSW +JznNTBeHaK1NlG6m0shZ+wePWXHoFDtxaEoaMqAzR+E3EkSduLQb9tJJ2vtmIC2X +5SFT625DKpRYOpcUxX/d63U+gSQThTitHS9Me0mljcP+qKhP/HIajesx6s5QTBBe +vOlzih5MpI0FHcwSIbPwhPUWRS2RdFKfJRQZQAQ1ZiOJL0W82eFI1uztDgfudPcf +BbgZcSjqvrKiXaeZxHsj3aguaOqaKdRlkyD1ABEBAAG0GW11c2wgbGliYyA8bXVz +bEBsaWJjLm9yZz6JATcEEwECACEFAlNcU8ECGwMGCwkIBwMCBhUIAgkKCwMWAgEC +HgECF4AACgkQVrzbWTAgRQ91FwgAnxSTh6Yjz8Oj3p5hTA/5t/ueGpf3dgbVrOXB +W0dgIkv+JbpJnpNFzLLz+Yi7J0eDGhW2OXMvZ1AEJmwoNsbsXBvd2rQAMQGUdcDT +EhmM+9bRGvWW3hpRT9xFtVJb9bsj0vs6Tpcb9LmmUxwmrguAVo2eOQLQ3UvVWaFh +oqEbvhfEb7kvhDds4iFuHxpAH11GmK5Q6POtfFBhYXZBhXqbcHzs1hs51vdDWPUg +pcHdpeR9NiP1Ch7lVMHaTuiTmvQcOtCvk9K8OMsG+9z8e7BIis7bXbIjHOTLNVBI +IE+kq4I0/Co9shhdqump1pJ0b7R+CfgkFP3n9GpGKkGTgc3djrkBDQRTXFPBAQgA +y1PIPj4GJD8AAgSsNMkGxgT1Q0lV8cUh+qN4+uHjO6XzxyiX2rULnO25AWVSq4X2 +i4LzZxgfFG9wUPEWdeYsJzEzNQYL5JWJREBc1UO73pbVWykvP0zUlxtGKNIKHETx +7D02vBpkTUErlNXbKWw1jpApyBmhWZhRsCa320t2yL6v6lO/1YxxCZ/VkSYYbCZ3 +Rl/uH+l7CfAsOJLczMSHpLNFg+fl9gYy6S/LUZ1kwHWLFbTYbzTdEaPSm9i+iNJ2 +tMHnvkvDv9GhOhIrixENCzfe3muxd8+8/UxAjZdj24AYphIRhvMSxnLSOUsoGjeP +BWhTvKsr6r2MZGQcCiDNjwARAQABiQEeBBgBAgAJBQJTXFPBAhsMAAoJEFa821kw +IEUPz50H93mm0dQVPDJV075V5eySx8kYgQUwc7aP6zSQdoMZ3GDa8+fpta3PQv09 +CqVFeJf8KUTkJwMKbNu5GUUmuA1WbxdmRkOHp81PalLbZS0vAJh62TNntmHU0sFJ +kp+IviwOmAJaAO64BQAy/arH0D8q+LFAnMLdIFEVWiMuULXUCB1P4D8agbltd0rH +KniPwcWR8Sh0PUcVjUPFzdZz1Qpc+9VYp626p2OZ+tlLO41OZAsbJ24+cWB/fkWu +H6g/nw7y9+2xtX8TIi6YBtLCPx/5IcY8LzrSFC+NFYll5V1SoTiGtdhudSfs0Eb2 +RXdP42mK+kMrgynbOn1RP7p/rfpSlA== +=FgKg +-----END PGP PUBLIC KEY BLOCK----- diff --git a/sources b/sources index a08cd59..a84e639 100644 --- a/sources +++ b/sources @@ -1,8 +1,10 @@ -SHA512 (tinygo-0.20.0.tar.gz) = 6a675c306badf11fe25ff968491693d3d9ac6116df5c99ec4fa32bb484217faf0d7160f9899ce7ac2c78e4eb680fbff20b1b0815c4038987f7becabef9a0a65a +SHA512 (tinygo-0.21.0.tar.gz) = 2c2bff6921db0f8e1b7f16055a640277606d9052437dc8928b4799de76ac3bee24e43322c6d5b9b1edd142d82edd518c22fbd956aea2dcf7810b696d980205dd SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 +SHA512 (musl-1.2.2.tar.gz) = 5344b581bd6463d71af8c13e91792fa51f25a96a1ecbea81e42664b63d90b325aeb421dfbc8c22e187397ca08e84d9296a0c0c299ba04fa2b751d6864914bd82 +SHA512 (musl-1.2.2.tar.gz.asc) = 9d76bd9d88438e21689d37d7c519bc5575fa72b121ddf89c55c1a2246ecf423664d8e5199192720d652f6d08229f9b17b5520465d49b12ed2ba80814d1d8e9d8 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 -SHA512 (picolibc-80528c684b10aaee977397e7eb40c4784e6dc433.tar.gz) = d7cdddf4ba2c4c4a447864e899c9e92674438358e8c1123c80d38b0c1d57cb35fdaaa60a73a16331637884d23207fdc9f06d7f28dc5920c76e25808869e2c7b1 -SHA512 (wasi-libc-215adc8ac9f91eb055311acc72683fd2eb1ae15a.tar.gz) = f7e5dd8689d86bd781d2985bcab996018e9fefec7744fbbfcc19215d082f20b1ee84b252c3f905926327da6d6e0465c0f22b94e52f5fdb523317275a6b4bf3e1 +SHA512 (picolibc-f68b8204f797d6b3bfbc7c4da4d257961fbc8770.tar.gz) = fa58a7ddcb1a40239a220ca701a83895804b9ddc837652fa18e9aed2603bba2825df2074e2fa4fbf8649bb9a21308e877850273ec9d421795e2ae549f331ab13 +SHA512 (wasi-libc-ad5133410f66b93a2381db5b542aad5e0964db96.tar.gz) = 04cb3a25fef7949bf77f262bd939102f5b36e2ae85f28cdbfcd8a8984425fba54fae68049b777974bdbad96882fab383b44203e8f19a776d8a56a55475c4aab6 diff --git a/tinygo.spec b/tinygo.spec index c15e9fc..19f26f6 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,16 +6,17 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.20.0 +Version: 0.21.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 %global clang_llvm_version 11 %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version 9.0.0 +%global musl_version 1.2.2 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 -%global picolibc_commit 80528c684b10aaee977397e7eb40c4784e6dc433 -%global wasi_libc_commit 215adc8ac9f91eb055311acc72683fd2eb1ae15a +%global picolibc_commit f68b8204f797d6b3bfbc7c4da4d257961fbc8770 +%global wasi_libc_commit ad5133410f66b93a2381db5b542aad5e0964db96 # No longer matching regular Go's /usr/share/gocode because it also provides # pre-compiled binaries, and symlinks to arch-specific clang headers. @@ -40,6 +41,7 @@ Summary: Go compiler for small places # avr-mcu: ASL 2.0 (packs) and MIT (Rust code, unused by this package) # cmsis-svd: ASL 2.0 and BSD and ISC and MIT (subsetted) # compiler-rt: NCSA or MIT +# musl: MIT # nrfx: BSD and ASL 2.0 # picolibc: BSD and ISC and MIT and GPLv2 (testing code only, unused by this package) # wasi-libc: BSD and CC0 and ISC and MIT and Public Domain @@ -51,21 +53,24 @@ Source2: cmsis-%{CMSIS_commit}-clean.tar.xz Source3: https://github.com/avr-rust/avr-mcu/archive/%{avr_commit}/avr-%{avr_commit}.tar.gz Source4: cmsis_svd-%{cmsis_svd_commit}-clean.tar.xz Source5: https://releases.llvm.org/%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz -Source6: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz -Source7: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz -Source8: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz +Source60: https://musl.libc.org/releases/musl-%{musl_version}.tar.gz +Source61: https://musl.libc.org/releases/musl-%{musl_version}.tar.gz.asc +Source62: https://musl.libc.org/musl.pub +Source7: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz +Source8: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz +Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz # We don't have wasmtime to run these. Patch0001: 0001-Skip-WASI-tests.patch # We don't have cross-compiled glibc to build these. Patch0002: 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch -# https://github.com/tinygo-org/tinygo/pull/1538 -Patch0003: 0003-Use-clang-to-do-linking.patch -Patch0004: 0004-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +Patch0003: 0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +Patch0004: 0004-Use-system-mingw64-headers-and-crt.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) +BuildRequires: golang(github.com/aykevl/go-wasm) BuildRequires: golang(github.com/blakesmith/ar) %ifnarch %{ix86} BuildRequires: chromium @@ -84,12 +89,20 @@ BuildRequires: make BuildRequires: avr-gcc BuildRequires: avr-libc +BuildRequires: binaryen >= 102 # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu BuildRequires: lld +BuildRequires: mingw64-crt +BuildRequires: mingw64-headers BuildRequires: nodejs BuildRequires: qemu-system-arm-core +BuildRequires: qemu-system-riscv-core +BuildRequires: qemu-user + +# For GPG signature verification +BuildRequires: gnupg2 Requires: golang Requires: lld @@ -98,7 +111,11 @@ Recommends: avr-libc Recommends: clang # Add this when LLVM supports ESP natively. # Recommends: esptool +Recommends: mingw64-crt +Recommends: mingw64-headers Recommends: qemu-system-arm-core +Recommends: qemu-system-riscv-core +Recommends: qemu-user %description %{common_description} @@ -108,10 +125,7 @@ Recommends: qemu-system-arm-core %prep %goprep -%patch0001 -p1 -%patch0002 -p1 -%patch0003 -p1 -%patch0004 -p1 +%autopatch -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS @@ -129,17 +143,23 @@ tar -C lib -xf %{SOURCE5} rmdir lib/compiler-rt mv lib/compiler-rt-%{compiler_rt_version}.src lib/compiler-rt -tar -C lib -xf %{SOURCE6} +# Verify *before* actually unpacking! +%{gpgverify} --keyring='%{SOURCE62}' --signature='%{SOURCE61}' --data='%{SOURCE60}' +tar -C lib -xf %{SOURCE60} +rmdir lib/musl +mv lib/musl-%{musl_version} lib/musl + +tar -C lib -xf %{SOURCE7} rmdir lib/nrfx mv lib/nrfx-%{nrfx_commit} lib/nrfx rm lib/nrfx/.gitignore chmod -x lib/nrfx/doc/generate_html_doc.sh -tar -C lib -xf %{SOURCE7} +tar -C lib -xf %{SOURCE8} rmdir lib/picolibc mv lib/picolibc-%{picolibc_commit} lib/picolibc -tar -C lib -xf %{SOURCE8} +tar -C lib -xf %{SOURCE9} rmdir lib/wasi-libc mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc @@ -150,11 +170,13 @@ mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc export BUILDTAGS="llvm%{clang_llvm_version}" LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} GO111MODULE=off %make_build gen-device STM32=0 -for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do +for arch in armv6m armv7m armv7em; do + target="${arch}-unknown-unknown-eabi" + mkdir -p ${target} for libc in compiler-rt picolibc; do TINYGOROOT=$PWD \ %{gobuilddir}/bin/tinygo \ - build-library -target=$target -o ${target}-${libc}.a ${libc} + build-library -target=${target} -o ${target}/${libc} ${libc} done done %make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=llvm-ar LLVM_NM=llvm-nm @@ -176,6 +198,31 @@ install -vpm 0644 lib/compiler-rt/README.txt %{buildroot}%{tinygoroot}/lib/compi install -vpm 0644 lib/compiler-rt/LICENSE.TXT %{buildroot}%{tinygoroot}/lib/compiler-rt/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/compiler-rt/lib cp -rp lib/compiler-rt/lib/builtins %{buildroot}%{tinygoroot}/lib/compiler-rt/lib/ +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl +cp -rp lib/musl/COPYRIGHT %{buildroot}%{tinygoroot}/lib/musl +cp -rp lib/musl/include %{buildroot}%{tinygoroot}/lib/musl +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl/arch +cp -rp lib/musl/arch/aarch64 %{buildroot}%{tinygoroot}/lib/musl/arch +cp -rp lib/musl/arch/arm %{buildroot}%{tinygoroot}/lib/musl/arch +cp -rp lib/musl/arch/generic %{buildroot}%{tinygoroot}/lib/musl/arch +cp -rp lib/musl/arch/i386 %{buildroot}%{tinygoroot}/lib/musl/arch +cp -rp lib/musl/arch/x86_64 %{buildroot}%{tinygoroot}/lib/musl/arch +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl/crt +cp -rp lib/musl/crt/crt1.c %{buildroot}%{tinygoroot}/lib/musl/crt +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/env %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/errno %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/exit %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/include %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/internal %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/malloc %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/mman %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/signal %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/stdio %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/string %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/thread %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/time %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/unistd %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/nrfx %{buildroot}%{tinygoroot}/lib/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc cp -rp lib/wasi-libc/sysroot %{buildroot}%{tinygoroot}/lib/wasi-libc/ @@ -185,12 +232,15 @@ cp -rp lib/picolibc/newlib/libc/include %{buildroot}%{tinygoroot}/lib/picolibc/n cp -rp lib/picolibc/newlib/libc/locale %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc cp -rp lib/picolibc/newlib/libc/string %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc cp -rp lib/picolibc/newlib/libc/tinystdio %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc -cp -rp lib/picolibc-include %{buildroot}%{tinygoroot}/lib +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm +cp -rp lib/picolibc/newlib/libm/common %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm +cp -rp lib/picolibc-stdio.c %{buildroot}%{tinygoroot}/lib install -vdm 0755 %{buildroot}%{tinygoroot}/pkg -for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do +for arch in armv6m armv7m armv7em; do + target="${arch}-unknown-unknown-eabi" + install -vdm 0755 %{buildroot}%{tinygoroot}/pkg/${target} for libc in compiler-rt picolibc; do - install -vdm 0755 %{buildroot}%{tinygoroot}/pkg/${target} - install -vpm 0644 ${target}-${libc}.a %{buildroot}%{tinygoroot}/pkg/${target}/${libc}.a + cp -rp ${target}/${libc} %{buildroot}%{tinygoroot}/pkg/${target}/ done done cp -rp src %{buildroot}%{tinygoroot}/ @@ -199,12 +249,13 @@ cp -rp targets %{buildroot}%{tinygoroot}/ %if %{with check} -%global gotestflags %gocompilerflags -tags="llvm%{clang_llvm_version}" +%global gotestflags %gocompilerflags -v -tags="llvm%{clang_llvm_version}" %check export TINYGOROOT=%{buildroot}%{tinygoroot} export GOPATH=%{buildroot}%{tinygoroot}:%{gopath} export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off +export XDG_CACHE_HOME="${PWD}/$(mktemp -d tinygo.XXXXXX)" %gocheck -v -d tests/tinygotest make smoketest STM32=0 XTENSA=0 %ifnarch %{ix86} aarch64 @@ -223,6 +274,7 @@ make wasmtest %doc %{tinygoroot}/lib/compiler-rt/README.txt %license %{tinygoroot}/lib/nrfx/LICENSE %doc %{tinygoroot}/lib/nrfx/README.md +%license %{tinygoroot}/lib/musl/COPYRIGHT #gopkgfiles From 6cc53805c66607e42d23a6da8a75aa4043ea7192 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:47:55 -0500 Subject: [PATCH 20/78] Fix arm cross compiling This allows enabling testing of the cross compiler as well, though there are some bugs in qemu that prevent enabling it outright. --- 0001-Skip-WASI-tests.patch | 2 +- ...row-argument-to-llvm.InlineAsm-calls.patch | 4 +- ...tive-Linux-tests-on-their-own-GOARCH.patch | 69 ------------------- ...3-Use-system-mingw64-headers-and-crt.patch | 4 +- ...arm-Explicitly-disable-unwind-tables.patch | 43 ++++++++++++ ...oss-Linux-tests-where-qemu-is-broken.patch | 43 ++++++++++++ tinygo.spec | 14 ++-- 7 files changed, 101 insertions(+), 78 deletions(-) rename 0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch => 0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch (98%) delete mode 100644 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch rename 0004-Use-system-mingw64-headers-and-crt.patch => 0003-Use-system-mingw64-headers-and-crt.patch (97%) create mode 100644 0004-arm-Explicitly-disable-unwind-tables.patch create mode 100644 0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 939dd5a..2f841d8 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 9b9f5ddc40d838c0141a81f718bb57e546dbc742 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/4] Skip WASI tests. +Subject: [PATCH 1/5] Skip WASI tests. We do not have wasmtime available. diff --git a/0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch b/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch similarity index 98% rename from 0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch rename to 0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch index 915cae6..295ecf4 100644 --- a/0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +++ b/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch @@ -1,7 +1,7 @@ -From c9cdcacd078cec5dc117c1257fa81b7b1f03398a Mon Sep 17 00:00:00 2001 +From 2b069365b3d57dc0be1dfc32db62847ff4ae744c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 6 Sep 2021 05:01:19 -0400 -Subject: [PATCH 3/4] Add canThrow argument to llvm.InlineAsm calls +Subject: [PATCH 2/5] Add canThrow argument to llvm.InlineAsm calls This is new in LLVM 13, and uses the default `false` which matches the default in the LLVM-internal `InlineAsm::get`, but I don't know if diff --git a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch b/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch deleted file mode 100644 index 2cc8ab1..0000000 --- a/0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 0fb55aa3fbf96a77ac86651cf9649843e0faa831 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 21 Dec 2020 04:26:02 -0500 -Subject: [PATCH 2/4] Only run native Linux tests on their own GOARCH. - -We don't have the cross-compiled C libraries to do this. Even 386 builds -on koji do not work for this because it does not support multilib. - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 2 ++ - main_test.go | 27 ++++++++++++++++++--------- - 2 files changed, 20 insertions(+), 9 deletions(-) - -diff --git a/Makefile b/Makefile -index 5de97014..64d68e2b 100644 ---- a/Makefile -+++ b/Makefile -@@ -479,7 +479,9 @@ endif - @$(MD5SUM) test.nro - $(TINYGO) build -size short -o test.hex -target=pca10040 -opt=0 ./testdata/stdlib.go - @$(MD5SUM) test.hex -+ifeq ($(shell uname -p), aarch64) - GOOS=linux GOARCH=arm $(TINYGO) build -size short -o test.elf ./testdata/cgo -+endif - GOOS=windows GOARCH=amd64 $(TINYGO) build -o test.exe ./testdata/cgo - ifneq ($(OS),Windows_NT) - # TODO: this does not yet work on Windows. Somehow, unused functions are -diff --git a/main_test.go b/main_test.go -index d74e0d67..1946ee1b 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -132,15 +132,24 @@ func TestCompiler(t *testing.T) { - }) - - if runtime.GOOS == "linux" { -- t.Run("X86Linux", func(t *testing.T) { -- runPlatTests(optionsFromOSARCH("linux/386"), tests, t) -- }) -- t.Run("ARMLinux", func(t *testing.T) { -- runPlatTests(optionsFromOSARCH("linux/arm/6"), tests, t) -- }) -- t.Run("ARM64Linux", func(t *testing.T) { -- runPlatTests(optionsFromOSARCH("linux/arm64"), tests, t) -- }) -+ switch runtime.GOARCH { -+ case "386": -+ t.Run("X86Linux", func(t *testing.T) { -+ runPlatTests(optionsFromOSARCH("linux/386"), tests, t) -+ }) -+ case "amd64": -+ t.Run("AMD64Linux", func(t *testing.T) { -+ runPlatTests(optionsFromOSARCH("linux/amd64"), tests, t) -+ }) -+ case "arm": -+ t.Run("ARMLinux", func(t *testing.T) { -+ runPlatTests(optionsFromOSARCH("linux/arm/6"), tests, t) -+ }) -+ case "arm64": -+ t.Run("ARM64Linux", func(t *testing.T) { -+ runPlatTests(optionsFromOSARCH("linux/arm64"), tests, t) -+ }) -+ } - t.Run("WebAssembly", func(t *testing.T) { - runPlatTests(optionsFromTarget("wasm"), tests, t) - }) --- -2.31.1 - diff --git a/0004-Use-system-mingw64-headers-and-crt.patch b/0003-Use-system-mingw64-headers-and-crt.patch similarity index 97% rename from 0004-Use-system-mingw64-headers-and-crt.patch rename to 0003-Use-system-mingw64-headers-and-crt.patch index 656a9c7..5e4ca3e 100644 --- a/0004-Use-system-mingw64-headers-and-crt.patch +++ b/0003-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ -From dcc3645326cc044066bef90b704a3836e335fa00 Mon Sep 17 00:00:00 2001 +From e26581e0d413b241195b7eee63d6499aa9fca3d5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 4/4] Use system mingw64 headers and crt +Subject: [PATCH 3/5] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-arm-Explicitly-disable-unwind-tables.patch b/0004-arm-Explicitly-disable-unwind-tables.patch new file mode 100644 index 0000000..ccd76cc --- /dev/null +++ b/0004-arm-Explicitly-disable-unwind-tables.patch @@ -0,0 +1,43 @@ +From 4f3e80094626a2b67075efdb6b899f2ab806725c Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 3 Jan 2022 18:40:21 -0500 +Subject: [PATCH 4/5] arm: Explicitly disable unwind tables + +Some clang builds (e.g., Fedora's) enable unwind tables by default. As +tinygo does not need nor support them, that leads to undefined symbols +when linking. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/library.go | 2 +- + compileopts/target.go | 1 + + 2 files changed, 2 insertions(+), 1 deletion(-) + +diff --git a/builder/library.go b/builder/library.go +index 73079785..012e4053 100644 +--- a/builder/library.go ++++ b/builder/library.go +@@ -120,7 +120,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ + } + } + if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { +- args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft") ++ args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft", "-fno-unwind-tables") + } + if strings.HasPrefix(target, "riscv32-") { + args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128") +diff --git a/compileopts/target.go b/compileopts/target.go +index 2e5f5487..829b481e 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -256,6 +256,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + spec.Features = "+cx8,+fxsr,+mmx,+sse,+sse2,+x87" + case "arm": + spec.CPU = "generic" ++ spec.CFlags = append(spec.CFlags, "-fno-unwind-tables") + switch strings.Split(triple, "-")[0] { + case "armv5": + spec.Features = "+armv5t,+strict-align,-thumb-mode" +-- +2.31.1 + diff --git a/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch new file mode 100644 index 0000000..3741d2f --- /dev/null +++ b/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -0,0 +1,43 @@ +From 4681ad345b38e1fa9627614adf3348886fa4a71c Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 3 Jan 2022 22:39:31 -0500 +Subject: [PATCH 5/5] Skip some cross Linux tests where qemu is broken + +The upstream issues will hopefully be fixed soon: + +- https://gitlab.com/qemu-project/qemu/-/issues/447 +- https://gitlab.com/qemu-project/qemu/-/issues/690 + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/main_test.go b/main_test.go +index d74e0d67..8850ef5f 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -297,6 +297,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c + return + } + ++ // Skip running the test executable due to bugs in qemu. ++ // https://gitlab.com/qemu-project/qemu/-/issues/447 ++ // https://gitlab.com/qemu-project/qemu/-/issues/690 ++ switch runtime.GOARCH { ++ case "arm64": ++ if options.GOARCH == "386" || options.GOARCH == "arm" { ++ return ++ } ++ case "386": ++ if options.GOARCH == "arm" { ++ return ++ } ++ } ++ + // Create the test command, taking care of emulators etc. + var cmd *exec.Cmd + if len(spec.Emulator) == 0 { +-- +2.31.1 + diff --git a/tinygo.spec b/tinygo.spec index 19f26f6..08c4568 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -61,10 +61,16 @@ Source8: https://github.com/keith-packard/picolibc/archive/%{picolibc_com Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz # We don't have wasmtime to run these. Patch0001: 0001-Skip-WASI-tests.patch -# We don't have cross-compiled glibc to build these. -Patch0002: 0002-Only-run-native-Linux-tests-on-their-own-GOARCH.patch -Patch0003: 0003-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch -Patch0004: 0004-Use-system-mingw64-headers-and-crt.patch +# Prep for LLVM 13 +Patch0002: 0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +# Unbundling things +Patch0003: 0003-Use-system-mingw64-headers-and-crt.patch +# https://github.com/tinygo-org/tinygo/pull/2482 +Patch0004: 0004-arm-Explicitly-disable-unwind-tables.patch +# Skip testing some things where qemu is broken: +# https://gitlab.com/qemu-project/qemu/-/issues/447 +# https://gitlab.com/qemu-project/qemu/-/issues/690 +Patch0005: 0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 8bc0621c0764205da4c7f614d8ae5ea186e9f070 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 4 Jan 2022 00:40:37 -0500 Subject: [PATCH 21/78] Backport patches for LLVM 12 --- 0001-Skip-WASI-tests.patch | 2 +- ...row-argument-to-llvm.InlineAsm-calls.patch | 2 +- 0003-Use-system-mingw64-headers-and-crt.patch | 2 +- ...arm-Explicitly-disable-unwind-tables.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- ...LLVM-features-to-match-vanilla-Clang.patch | 129 +++++ 0007-all-add-LLVM-12-support.patch | 469 ++++++++++++++++++ tinygo.spec | 7 +- 8 files changed, 609 insertions(+), 6 deletions(-) create mode 100644 0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch create mode 100644 0007-all-add-LLVM-12-support.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 2f841d8..2d236fe 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 9b9f5ddc40d838c0141a81f718bb57e546dbc742 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/5] Skip WASI tests. +Subject: [PATCH 1/7] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch b/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch index 295ecf4..bf348e5 100644 --- a/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +++ b/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch @@ -1,7 +1,7 @@ From 2b069365b3d57dc0be1dfc32db62847ff4ae744c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 6 Sep 2021 05:01:19 -0400 -Subject: [PATCH 2/5] Add canThrow argument to llvm.InlineAsm calls +Subject: [PATCH 2/7] Add canThrow argument to llvm.InlineAsm calls This is new in LLVM 13, and uses the default `false` which matches the default in the LLVM-internal `InlineAsm::get`, but I don't know if diff --git a/0003-Use-system-mingw64-headers-and-crt.patch b/0003-Use-system-mingw64-headers-and-crt.patch index 5e4ca3e..524e404 100644 --- a/0003-Use-system-mingw64-headers-and-crt.patch +++ b/0003-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ From e26581e0d413b241195b7eee63d6499aa9fca3d5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 3/5] Use system mingw64 headers and crt +Subject: [PATCH 3/7] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-arm-Explicitly-disable-unwind-tables.patch b/0004-arm-Explicitly-disable-unwind-tables.patch index ccd76cc..bbd695a 100644 --- a/0004-arm-Explicitly-disable-unwind-tables.patch +++ b/0004-arm-Explicitly-disable-unwind-tables.patch @@ -1,7 +1,7 @@ From 4f3e80094626a2b67075efdb6b899f2ab806725c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 18:40:21 -0500 -Subject: [PATCH 4/5] arm: Explicitly disable unwind tables +Subject: [PATCH 4/7] arm: Explicitly disable unwind tables Some clang builds (e.g., Fedora's) enable unwind tables by default. As tinygo does not need nor support them, that leads to undefined symbols diff --git a/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 3741d2f..6213390 100644 --- a/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From 4681ad345b38e1fa9627614adf3348886fa4a71c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 5/5] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 5/7] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch b/0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch new file mode 100644 index 0000000..d0e418a --- /dev/null +++ b/0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch @@ -0,0 +1,129 @@ +From a0ebf57f6164d5f795b7022fa26ac8bb66bee9e8 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 19 Nov 2021 14:47:55 +0100 +Subject: [PATCH 6/7] targets: change LLVM features to match vanilla Clang + +I mistakenly believed the difference was in LLVM version 11.0.0 vs LLVM +11.1.0. However, the difference is in whether we use the Debian version +of Clang. + +The Debian version has had lots of patches. I'm not sure which is to +blame, but it could be this one: +https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/snapshot/debian/patches/clang-arm-default-vfp3-on-armv7a.patch + +Signed-off-by: Elliott Sales de Andrade +--- + builder/builder_test.go | 19 ++++++++++++------- + compileopts/target.go | 2 +- + targets/cortex-m0.json | 2 +- + targets/cortex-m0plus.json | 2 +- + targets/cortex-m3.json | 2 +- + targets/gameboy-advance.json | 2 +- + 6 files changed, 17 insertions(+), 12 deletions(-) + +diff --git a/builder/builder_test.go b/builder/builder_test.go +index cff43db8..c38d360a 100644 +--- a/builder/builder_test.go ++++ b/builder/builder_test.go +@@ -5,6 +5,7 @@ import ( + "io/ioutil" + "os" + "path/filepath" ++ "runtime" + "testing" + + "github.com/tinygo-org/tinygo/compileopts" +@@ -60,7 +61,11 @@ func TestClangAttributes(t *testing.T) { + {GOOS: "darwin", GOARCH: "arm64"}, + {GOOS: "windows", GOARCH: "amd64"}, + } { +- t.Run("GOOS="+options.GOOS+",GOARCH="+options.GOARCH, func(t *testing.T) { ++ name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH ++ if options.GOARCH == "arm" { ++ name += ",GOARM=" + options.GOARM ++ } ++ t.Run(name, func(t *testing.T) { + testClangAttributes(t, options) + }) + } +@@ -131,12 +136,12 @@ func testClangAttributes(t *testing.T, options *compileopts.Options) { + t.Errorf("target has CPU %#v but Clang makes it CPU %#v", config.CPU(), cpu) + } + if features != config.Features() { +- if llvm.Version != "11.0.0" { +- // This needs to be removed once we switch to LLVM 12. +- // LLVM 11.0.0 uses a different "target-features" string than LLVM +- // 11.1.0 for Thumb targets. The Xtensa fork is still based on LLVM +- // 11.0.0, so we need to skip this check on that version. +- t.Errorf("target has LLVM features %#v but Clang makes it %#v", config.Features(), features) ++ if hasBuiltinTools || runtime.GOOS != "linux" { ++ // Skip this step when using an external Clang invocation on Linux. ++ // The reason is that Debian has patched Clang in a way that ++ // modifies the LLVM features string, changing lots of FPU/float ++ // related flags. We want to test vanilla Clang, not Debian Clang. ++ t.Errorf("target has LLVM features\n\t%#v\nbut Clang makes it\n\t%#v", config.Features(), features) + } + } + } +diff --git a/compileopts/target.go b/compileopts/target.go +index 829b481e..bdd77613 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -263,7 +263,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + case "armv6": + spec.Features = "+armv6,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-thumb-mode" + case "armv7": +- spec.Features = "+armv7-a,+dsp,+fp64,+vfp2,+vfp2sp,+vfp3d16,+vfp3d16sp,-thumb-mode" ++ spec.Features = "+armv7-a,+d32,+dsp,+fp64,+neon,+vfp2,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,-thumb-mode" + } + case "arm64": + spec.CPU = "generic" +diff --git a/targets/cortex-m0.json b/targets/cortex-m0.json +index fe356805..315d6658 100644 +--- a/targets/cortex-m0.json ++++ b/targets/cortex-m0.json +@@ -2,5 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv6m-unknown-unknown-eabi", + "cpu": "cortex-m0", +- "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" ++ "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" + } +diff --git a/targets/cortex-m0plus.json b/targets/cortex-m0plus.json +index a21d06ca..6ac9b531 100644 +--- a/targets/cortex-m0plus.json ++++ b/targets/cortex-m0plus.json +@@ -2,5 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv6m-unknown-unknown-eabi", + "cpu": "cortex-m0plus", +- "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" ++ "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" + } +diff --git a/targets/cortex-m3.json b/targets/cortex-m3.json +index 7b878d52..07d88dfe 100644 +--- a/targets/cortex-m3.json ++++ b/targets/cortex-m3.json +@@ -2,5 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv7m-unknown-unknown-eabi", + "cpu": "cortex-m3", +- "features": "+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" ++ "features": "+armv7-m,+hwdiv,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" + } +diff --git a/targets/gameboy-advance.json b/targets/gameboy-advance.json +index 24e16cda..2467b4b9 100644 +--- a/targets/gameboy-advance.json ++++ b/targets/gameboy-advance.json +@@ -1,7 +1,7 @@ + { + "llvm-target": "armv4t-unknown-unknown-eabi", + "cpu": "arm7tdmi", +- "features": "+armv4t,+soft-float,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", ++ "features": "+armv4t,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2,-thumb-mode", + "build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"], + "goos": "linux", + "goarch": "arm", +-- +2.31.1 + diff --git a/0007-all-add-LLVM-12-support.patch b/0007-all-add-LLVM-12-support.patch new file mode 100644 index 0000000..ff708c7 --- /dev/null +++ b/0007-all-add-LLVM-12-support.patch @@ -0,0 +1,469 @@ +From aefb7735476f11cbe3b7cb2a026afd34ab74d771 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sun, 28 Mar 2021 19:56:03 -0400 +Subject: [PATCH 7/7] all: add LLVM 12 support + +Originally based on a PR by @QuLogic, but extended a lot to get all +tests to pass. + +Signed-off-by: Elliott Sales de Andrade +--- + .circleci/config.yml | 18 +++++++++--------- + .github/workflows/windows.yml | 4 ++-- + Makefile | 14 ++++++-------- + cgo/libclang_config.go | 1 + + cgo/libclang_config_llvm12.go | 14 ++++++++++++++ + compileopts/target.go | 14 ++++++++++++++ + compiler/compiler_test.go | 27 ++++++++++++++++++++++----- + compiler/testdata/channel.ll | 6 +++--- + compiler/testdata/intrinsics-wasm.ll | 6 +++--- + go.mod | 4 ++-- + go.sum | 10 ++++------ + interp/interp_test.go | 1 + + transform/maps_test.go | 1 + + transform/testdata/coroutines.out.ll | 6 +++--- + transform/transform_test.go | 3 ++- + 15 files changed, 87 insertions(+), 42 deletions(-) + create mode 100644 cgo/libclang_config_llvm12.go + +diff --git a/.circleci/config.yml b/.circleci/config.yml +index 61c7e287..50bdd087 100644 +--- a/.circleci/config.yml ++++ b/.circleci/config.yml +@@ -52,12 +52,12 @@ commands: + steps: + - restore_cache: + keys: +- - llvm-source-11-v2 ++ - llvm-source-12-v1 + - run: + name: "Fetch LLVM source" + command: make llvm-source + - save_cache: +- key: llvm-source-11-v2 ++ key: llvm-source-12-v1 + paths: + - llvm-project/clang/lib/Headers + - llvm-project/clang/include +@@ -332,12 +332,12 @@ commands: + - go-cache-macos-v3-{{ checksum "go.mod" }} + - restore_cache: + keys: +- - llvm-source-11-macos-v3 ++ - llvm-source-12-macos-v1 + - run: + name: "Fetch LLVM source" + command: make llvm-source + - save_cache: +- key: llvm-source-11-macos-v3 ++ key: llvm-source-12-macos-v1 + paths: + - llvm-project/clang/lib/Headers + - llvm-project/clang/include +@@ -345,7 +345,7 @@ commands: + - llvm-project/llvm/include + - restore_cache: + keys: +- - llvm-build-11-macos-v5 ++ - llvm-build-12-macos-v1 + - run: + name: "Build LLVM" + command: | +@@ -359,7 +359,7 @@ commands: + find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; + fi + - save_cache: +- key: llvm-build-11-macos-v5 ++ key: llvm-build-12-macos-v1 + paths: + llvm-build + - restore_cache: +@@ -418,12 +418,12 @@ jobs: + steps: + - test-linux: + llvm: "11" +- test-llvm11-go116: ++ test-llvm12-go116: + docker: + - image: circleci/golang:1.16-buster + steps: + - test-linux: +- llvm: "11" ++ llvm: "12" + assert-test-linux: + docker: + - image: circleci/golang:1.17-buster +@@ -451,7 +451,7 @@ workflows: + test-all: + jobs: + - test-llvm11-go115 +- - test-llvm11-go116 ++ - test-llvm12-go116 + - build-linux + - test-linux-build: + requires: +diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml +index 4bc07d59..8649f635 100644 +--- a/.github/workflows/windows.yml ++++ b/.github/workflows/windows.yml +@@ -27,7 +27,7 @@ jobs: + uses: actions/cache@v2 + id: cache-llvm-source + with: +- key: llvm-source-11-windows-v1 ++ key: llvm-source-12-windows-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -40,7 +40,7 @@ jobs: + uses: actions/cache@v2 + id: cache-llvm-build + with: +- key: llvm-build-11-windows-v2 ++ key: llvm-build-12-windows-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +diff --git a/Makefile b/Makefile +index 5de97014..0ebfcd82 100644 +--- a/Makefile ++++ b/Makefile +@@ -59,18 +59,13 @@ ifeq ($(OS),Windows_NT) + + BINARYEN_OPTION += -DCMAKE_EXE_LINKER_FLAGS='-static-libgcc -static-libstdc++' + +- LIBCLANG_NAME = libclang +- + else ifeq ($(shell uname -s),Darwin) + MD5SUM = md5 +- LIBCLANG_NAME = clang + else ifeq ($(shell uname -s),FreeBSD) + MD5SUM = md5 +- LIBCLANG_NAME = clang + START_GROUP = -Wl,--start-group + END_GROUP = -Wl,--end-group + else +- LIBCLANG_NAME = clang + START_GROUP = -Wl,--start-group + END_GROUP = -Wl,--end-group + endif +@@ -86,19 +81,22 @@ LLD_LIBS = $(START_GROUP) $(addprefix -l,$(LLD_LIB_NAMES)) $(END_GROUP) + # Other libraries that are needed to link TinyGo. + EXTRA_LIB_NAMES = LLVMInterpreter + ++# All libraries to be built and linked with the tinygo binary (lib/lib*.a). ++LIB_NAMES = clang $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES) ++ + # These build targets appear to be the only ones necessary to build all TinyGo + # dependencies. Only building a subset significantly speeds up rebuilding LLVM. + # The Makefile rules convert a name like lldELF to lib/liblldELF.a to match the + # library path (for ninja). + # This list also includes a few tools that are necessary as part of the full + # TinyGo build. +-NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(addsuffix .a,$(LIBCLANG_NAME) $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES))) ++NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(addsuffix .a,$(LIB_NAMES))) + + # For static linking. + ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","") + CGO_CPPFLAGS+=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include + CGO_CXXFLAGS=-std=c++14 +- CGO_LDFLAGS+=$(abspath $(LLVM_BUILDDIR))/lib/lib$(LIBCLANG_NAME).a -L$(abspath $(LLVM_BUILDDIR)/lib) $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA) ++ CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA) + endif + + +@@ -162,7 +160,7 @@ gen-device-rp: build/gen-device-svd + + # Get LLVM sources. + $(LLVM_PROJECTDIR)/llvm: +- git clone -b xtensa_release_11.0.0 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) ++ git clone -b xtensa_release_12.0.1 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) + llvm-source: $(LLVM_PROJECTDIR)/llvm + + # Configure LLVM. +diff --git a/cgo/libclang_config.go b/cgo/libclang_config.go +index 4b4ce2db..9f7cdc1c 100644 +--- a/cgo/libclang_config.go ++++ b/cgo/libclang_config.go +@@ -1,4 +1,5 @@ + // +build !byollvm ++// +build !llvm12 + + package cgo + +diff --git a/cgo/libclang_config_llvm12.go b/cgo/libclang_config_llvm12.go +new file mode 100644 +index 00000000..1837cc15 +--- /dev/null ++++ b/cgo/libclang_config_llvm12.go +@@ -0,0 +1,14 @@ ++// +build !byollvm ++// +build llvm12 ++ ++package cgo ++ ++/* ++#cgo linux CFLAGS: -I/usr/lib/llvm-12/include ++#cgo darwin CFLAGS: -I/usr/local/opt/llvm@12/include ++#cgo freebsd CFLAGS: -I/usr/local/llvm12/include ++#cgo linux LDFLAGS: -L/usr/lib/llvm-12/lib -lclang ++#cgo darwin LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi ++#cgo freebsd LDFLAGS: -L/usr/local/llvm12/lib -lclang ++*/ ++import "C" +diff --git a/compileopts/target.go b/compileopts/target.go +index bdd77613..57b5bd84 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -12,9 +12,11 @@ import ( + "path/filepath" + "reflect" + "runtime" ++ "strconv" + "strings" + + "github.com/tinygo-org/tinygo/goenv" ++ "tinygo.org/x/go-llvm" + ) + + // Target specification for a given target. Used for bare metal targets. +@@ -280,6 +282,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + } else if goos == "windows" { + spec.Linker = "ld.lld" + spec.Libc = "mingw-w64" ++ // Note: using a medium code model, low image base and no ASLR ++ // because Go doesn't really need those features. ASLR patches ++ // around issues for unsafe languages like C/C++ that are not ++ // normally present in Go (without explicitly opting in). ++ // For more discussion: ++ // https://groups.google.com/g/Golang-nuts/c/Jd9tlNc6jUE/m/Zo-7zIP_m3MJ?pli=1 + spec.LDFlags = append(spec.LDFlags, + "-m", "i386pep", + "-Bdynamic", +@@ -287,6 +295,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + "--gc-sections", + "--no-insert-timestamp", + ) ++ llvmMajor, _ := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) ++ if llvmMajor >= 12 { ++ // This flag was added in LLVM 12. At the same time, LLVM 12 ++ // switched the default from --dynamicbase to --no-dynamicbase. ++ spec.LDFlags = append(spec.LDFlags, "--no-dynamicbase") ++ } + } else { + spec.LDFlags = append(spec.LDFlags, "-no-pie", "-Wl,--gc-sections") // WARNING: clang < 5.0 requires -nopie + } +diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go +index cbf89fe2..3c978274 100644 +--- a/compiler/compiler_test.go ++++ b/compiler/compiler_test.go +@@ -41,6 +41,13 @@ func TestCompiler(t *testing.T) { + t.Skip("compiler tests require LLVM 11 or above, got LLVM ", llvm.Version) + } + ++ // Determine Go minor version (e.g. 16 in go1.16.3). ++ _, goMinor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) ++ if err != nil { ++ t.Fatal("could not read Go version:", err) ++ } ++ ++ // Determine which tests to run, depending on the Go and LLVM versions. + tests := []testCase{ + {"basic.go", "", ""}, + {"pointer.go", "", ""}, +@@ -58,12 +65,11 @@ func TestCompiler(t *testing.T) { + {"intrinsics.go", "wasm", ""}, + {"gc.go", "", ""}, + } +- +- _, minor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) +- if err != nil { +- t.Fatal("could not read Go version:", err) ++ if llvmMajor >= 12 { ++ tests = append(tests, testCase{"intrinsics.go", "cortex-m-qemu", ""}) ++ tests = append(tests, testCase{"intrinsics.go", "wasm", ""}) + } +- if minor >= 17 { ++ if goMinor >= 17 { + tests = append(tests, testCase{"go1.17.go", "", ""}) + } + +@@ -201,6 +207,12 @@ func fuzzyEqualIR(s1, s2 string) bool { + // stripped out. + func filterIrrelevantIRLines(lines []string) []string { + var out []string ++ llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) ++ if err != nil { ++ // Note: this should never happen and if it does, it will always happen ++ // for a particular build because llvm.Version is a constant. ++ panic(err) ++ } + for _, line := range lines { + line = strings.Split(line, ";")[0] // strip out comments/info + line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments +@@ -210,6 +222,11 @@ func filterIrrelevantIRLines(lines []string) []string { + if strings.HasPrefix(line, "source_filename = ") { + continue + } ++ if llvmVersion < 12 && strings.HasPrefix(line, "attributes ") { ++ // Ignore attribute groups. These may change between LLVM versions. ++ // Right now test outputs are for LLVM 12. ++ continue ++ } + out = append(out, line) + } + return out +diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll +index 04bfa4af..36d7fd96 100644 +--- a/compiler/testdata/channel.ll ++++ b/compiler/testdata/channel.ll +@@ -34,12 +34,12 @@ entry: + ret void + } + +-; Function Attrs: argmemonly nounwind willreturn ++; Function Attrs: argmemonly nofree nosync nounwind willreturn + declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 + + declare void @runtime.chanSend(%runtime.channel* dereferenceable_or_null(32), i8*, %runtime.channelBlockedList* dereferenceable_or_null(24), i8*, i8*) + +-; Function Attrs: argmemonly nounwind willreturn ++; Function Attrs: argmemonly nofree nosync nounwind willreturn + declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 + + ; Function Attrs: nounwind +@@ -119,4 +119,4 @@ select.body: ; preds = %select.next + declare { i32, i1 } @runtime.tryChanSelect(i8*, %runtime.chanSelectState*, i32, i32, i8*, i8*) + + attributes #0 = { nounwind } +-attributes #1 = { argmemonly nounwind willreturn } ++attributes #1 = { argmemonly nofree nosync nounwind willreturn } +diff --git a/compiler/testdata/intrinsics-wasm.ll b/compiler/testdata/intrinsics-wasm.ll +index bebadb08..9e6687d5 100644 +--- a/compiler/testdata/intrinsics-wasm.ll ++++ b/compiler/testdata/intrinsics-wasm.ll +@@ -18,7 +18,7 @@ entry: + ret double %0 + } + +-; Function Attrs: nounwind readnone speculatable willreturn ++; Function Attrs: nofree nosync nounwind readnone speculatable willreturn + declare double @llvm.sqrt.f64(double) #1 + + ; Function Attrs: nounwind +@@ -28,8 +28,8 @@ entry: + ret double %0 + } + +-; Function Attrs: nounwind readnone speculatable willreturn ++; Function Attrs: nofree nosync nounwind readnone speculatable willreturn + declare double @llvm.trunc.f64(double) #1 + + attributes #0 = { nounwind } +-attributes #1 = { nounwind readnone speculatable willreturn } ++attributes #1 = { nofree nosync nounwind readnone speculatable willreturn } +diff --git a/go.mod b/go.mod +index 26a4b027..52dd71c3 100644 +--- a/go.mod ++++ b/go.mod +@@ -3,7 +3,7 @@ module github.com/tinygo-org/tinygo + go 1.15 + + require ( +- github.com/aykevl/go-wasm v0.0.2-0.20211030161413-11881cb9032d // indirect ++ github.com/aykevl/go-wasm v0.0.2-0.20211119014117-0761b1ddcd1a // indirect + github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 + github.com/chromedp/cdproto v0.0.0-20210113043257-dabd2f2e7693 + github.com/chromedp/chromedp v0.6.4 +@@ -13,5 +13,5 @@ require ( + go.bug.st/serial v1.1.3 + golang.org/x/sys v0.0.0-20210510120138-977fb7262007 + golang.org/x/tools v0.1.6-0.20210813165731-45389f592fe9 +- tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c ++ tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be + ) +diff --git a/go.sum b/go.sum +index 1daa9388..73697653 100644 +--- a/go.sum ++++ b/go.sum +@@ -1,5 +1,5 @@ +-github.com/aykevl/go-wasm v0.0.2-0.20211030161413-11881cb9032d h1:JeuI5/546naK5hpOIX+Lq5xE8rvt7uwiTp6iL+pLQgk= +-github.com/aykevl/go-wasm v0.0.2-0.20211030161413-11881cb9032d/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw= ++github.com/aykevl/go-wasm v0.0.2-0.20211119014117-0761b1ddcd1a h1:QPU7APo6y/6VkCDq6HU3WWIUzER8iywSac23+1UQv60= ++github.com/aykevl/go-wasm v0.0.2-0.20211119014117-0761b1ddcd1a/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw= + github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI= + github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI= + github.com/chromedp/cdproto v0.0.0-20210113043257-dabd2f2e7693 h1:11eq/RkpaotwdF6b1TRMcdgQUPNmyFEJOB7zLvh0O/Y= +@@ -68,7 +68,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/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-20210308112806-9ef958b6bed4 h1:CMUHxVTb+UuUePuMf8vkWjZ3gTp9BBK91KrgOCwoNHs= +-tinygo.org/x/go-llvm v0.0.0-20210308112806-9ef958b6bed4/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= +-tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c h1:vn9IPshzYmzZis10UEVrsIBRv9FpykADw6M3/tHHROg= +-tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= ++tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be h1:syIpWbi/yESuoyijF2nhRdgX4422sNfmij+o73B3+vU= ++tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= +diff --git a/interp/interp_test.go b/interp/interp_test.go +index 516fdd11..ae2635af 100644 +--- a/interp/interp_test.go ++++ b/interp/interp_test.go +@@ -71,6 +71,7 @@ func runTest(t *testing.T, pathPrefix string) { + defer pm.Dispose() + pm.AddGlobalOptimizerPass() + pm.AddDeadStoreEliminationPass() ++ pm.AddAggressiveDCEPass() + pm.Run(mod) + + // Read the expected output IR. +diff --git a/transform/maps_test.go b/transform/maps_test.go +index 1f821d4b..e8b11133 100644 +--- a/transform/maps_test.go ++++ b/transform/maps_test.go +@@ -18,6 +18,7 @@ func TestOptimizeMaps(t *testing.T) { + pm := llvm.NewPassManager() + defer pm.Dispose() + pm.AddDeadStoreEliminationPass() ++ pm.AddAggressiveDCEPass() + pm.Run(mod) + }) + } +diff --git a/transform/testdata/coroutines.out.ll b/transform/testdata/coroutines.out.ll +index d4a49a5e..de902884 100644 +--- a/transform/testdata/coroutines.out.ll ++++ b/transform/testdata/coroutines.out.ll +@@ -301,13 +301,13 @@ declare i8* @llvm.coro.free(token, i8* nocapture readonly) #0 + ; Function Attrs: nounwind + declare token @llvm.coro.save(i8*) #2 + +-; Function Attrs: argmemonly nounwind willreturn ++; Function Attrs: argmemonly nofree nosync nounwind willreturn + declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #3 + +-; Function Attrs: argmemonly nounwind willreturn ++; Function Attrs: argmemonly nofree nosync nounwind willreturn + declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #3 + + attributes #0 = { argmemonly nounwind readonly } + attributes #1 = { nounwind readnone } + attributes #2 = { nounwind } +-attributes #3 = { argmemonly nounwind willreturn } ++attributes #3 = { argmemonly nofree nosync nounwind willreturn } +diff --git a/transform/transform_test.go b/transform/transform_test.go +index ae531eeb..935d660b 100644 +--- a/transform/transform_test.go ++++ b/transform/transform_test.go +@@ -116,8 +116,9 @@ func filterIrrelevantIRLines(lines []string) []string { + if strings.HasPrefix(line, "source_filename = ") { + continue + } +- if llvmVersion < 11 && strings.HasPrefix(line, "attributes ") { ++ if llvmVersion < 12 && strings.HasPrefix(line, "attributes ") { + // Ignore attribute groups. These may change between LLVM versions. ++ // Right now test outputs are for LLVM 12. + continue + } + out = append(out, line) +-- +2.31.1 + diff --git a/tinygo.spec b/tinygo.spec index 08c4568..d29017b 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,7 +10,7 @@ Version: 0.21.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%global clang_llvm_version 11 +%global clang_llvm_version 12 %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version 9.0.0 %global musl_version 1.2.2 @@ -71,6 +71,11 @@ Patch0004: 0004-arm-Explicitly-disable-unwind-tables.patch # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 Patch0005: 0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +# Backport support for LLVM 12 +# https://github.com/tinygo-org/tinygo/pull/2291 +Patch0006: 0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch +# https://github.com/tinygo-org/tinygo/pull/2300 +Patch0007: 0007-all-add-LLVM-12-support.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From b12ac02c48db5a187e76e429c13851c07a373a15 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 4 Jan 2022 02:15:10 -0500 Subject: [PATCH 22/78] Make note of bundled libc's --- tinygo.spec | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tinygo.spec b/tinygo.spec index d29017b..8f370b8 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -128,6 +128,12 @@ Recommends: qemu-system-arm-core Recommends: qemu-system-riscv-core Recommends: qemu-user +# Make note of bundled libc's +Provides: bundled(compiler-rt) = %{compiler_rt_version} +Provides: bundled(musl) = %{musl_version} +Provides: bundled(picolibc) = %{picolibc_commit} +Provides: bundled(wasi-libc) = %{wasi_libc_commit} + %description %{common_description} From 03e3a66ed77460fad2ac3376056c8f4482510a2b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 10 Jan 2022 16:31:17 -0500 Subject: [PATCH 23/78] Backport support for LLVM 13 --- 0001-Skip-WASI-tests.patch | 2 +- ...row-argument-to-llvm.InlineAsm-calls.patch | 127 --- ...2-Use-system-mingw64-headers-and-crt.patch | 4 +- ...arm-Explicitly-disable-unwind-tables.patch | 4 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 4 +- ...LLVM-features-to-match-vanilla-Clang.patch | 4 +- ...atch => 0006-all-add-LLVM-12-support.patch | 4 +- 0007-tests-improve-wasm-tests-slightly.patch | 262 +++++ ...ap-stack-chain-when-switching-gorout.patch | 195 ++++ 0009-all-switch-to-LLVM-13.patch | 960 ++++++++++++++++++ tinygo.spec | 23 +- 11 files changed, 1444 insertions(+), 145 deletions(-) delete mode 100644 0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch rename 0003-Use-system-mingw64-headers-and-crt.patch => 0002-Use-system-mingw64-headers-and-crt.patch (97%) rename 0004-arm-Explicitly-disable-unwind-tables.patch => 0003-arm-Explicitly-disable-unwind-tables.patch (92%) rename 0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch => 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch (89%) rename 0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch => 0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch (98%) rename 0007-all-add-LLVM-12-support.patch => 0006-all-add-LLVM-12-support.patch (99%) create mode 100644 0007-tests-improve-wasm-tests-slightly.patch create mode 100644 0008-internal-task-swap-stack-chain-when-switching-gorout.patch create mode 100644 0009-all-switch-to-LLVM-13.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 2d236fe..9c6641f 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 9b9f5ddc40d838c0141a81f718bb57e546dbc742 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/7] Skip WASI tests. +Subject: [PATCH 1/9] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch b/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch deleted file mode 100644 index bf348e5..0000000 --- a/0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch +++ /dev/null @@ -1,127 +0,0 @@ -From 2b069365b3d57dc0be1dfc32db62847ff4ae744c Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 6 Sep 2021 05:01:19 -0400 -Subject: [PATCH 2/7] Add canThrow argument to llvm.InlineAsm calls - -This is new in LLVM 13, and uses the default `false` which matches the -default in the LLVM-internal `InlineAsm::get`, but I don't know if -that's the right thing here because docs are difficult to find. - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/inlineasm.go | 16 ++++++++-------- - compiler/syscall.go | 8 ++++---- - 2 files changed, 12 insertions(+), 12 deletions(-) - -diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go -index e32a4f39..635aed98 100644 ---- a/compiler/inlineasm.go -+++ b/compiler/inlineasm.go -@@ -24,7 +24,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { - // Magic function: insert inline assembly instead of calling it. - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{}, false) - asm := constant.StringVal(args[0].(*ssa.Const).Value) -- target := llvm.InlineAsm(fnType, asm, "", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "", true, false, 0, false) - return b.CreateCall(target, nil, ""), nil - } - -@@ -116,7 +116,7 @@ func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) - outputType = b.ctx.VoidType() - } - fnType := llvm.FunctionType(outputType, argTypes, false) -- target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0) -+ target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0, false) - result := b.CreateCall(target, args, "") - if hasOutput { - return result, nil -@@ -159,7 +159,7 @@ func (b *builder) emitSVCall(args []ssa.Value) (llvm.Value, error) { - // marked as clobbered. - constraints += ",~{r1},~{r2},~{r3}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) - return b.CreateCall(target, llvmArgs, ""), nil - } - -@@ -197,7 +197,7 @@ func (b *builder) emitSV64Call(args []ssa.Value) (llvm.Value, error) { - // marked as clobbered. - constraints += ",~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) - return b.CreateCall(target, llvmArgs, ""), nil - } - -@@ -222,24 +222,24 @@ func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error) { - // marked as such. - fnType := llvm.FunctionType(b.uintptrType, nil, false) - asm := fmt.Sprintf("csrr $0, %d", csr) -- target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0, false) - return b.CreateCall(target, nil, ""), nil - case "Set": - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrw %d, $0", csr) -- target := llvm.InlineAsm(fnType, asm, "r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "r", true, false, 0, false) - return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - case "SetBits": - // Note: it may be possible to optimize this to csrrsi in many cases. - fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrrs $0, %d, $1", csr) -- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) - return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - case "ClearBits": - // Note: it may be possible to optimize this to csrrci in many cases. - fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrrc $0, %d, $1", csr) -- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) - return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - default: - return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) -diff --git a/compiler/syscall.go b/compiler/syscall.go -index db379d52..37330684 100644 ---- a/compiler/syscall.go -+++ b/compiler/syscall.go -@@ -56,7 +56,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - } - constraints += ",~{rcx},~{r11}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel) -+ target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false) - return b.CreateCall(target, args, ""), nil - case b.GOARCH == "386" && b.GOOS == "linux": - // Sources: -@@ -82,7 +82,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - argTypes = append(argTypes, llvmValue.Type()) - } - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel) -+ target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false) - return b.CreateCall(target, args, ""), nil - case b.GOARCH == "arm" && b.GOOS == "linux": - // Implement the EABI system call convention for Linux. -@@ -114,7 +114,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - constraints += ",~{r" + strconv.Itoa(i) + "}" - } - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) - return b.CreateCall(target, args, ""), nil - case b.GOARCH == "arm64" && b.GOOS == "linux": - // Source: syscall(2) man page. -@@ -146,7 +146,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - } - constraints += ",~{x16},~{x17}" // scratch registers - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) - return b.CreateCall(target, args, ""), nil - default: - return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH) --- -2.31.1 - diff --git a/0003-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch similarity index 97% rename from 0003-Use-system-mingw64-headers-and-crt.patch rename to 0002-Use-system-mingw64-headers-and-crt.patch index 524e404..71b83cd 100644 --- a/0003-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ -From e26581e0d413b241195b7eee63d6499aa9fca3d5 Mon Sep 17 00:00:00 2001 +From e981e11100f9cb9c79bfd62a7e57df60929cda7b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 3/7] Use system mingw64 headers and crt +Subject: [PATCH 2/9] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-arm-Explicitly-disable-unwind-tables.patch b/0003-arm-Explicitly-disable-unwind-tables.patch similarity index 92% rename from 0004-arm-Explicitly-disable-unwind-tables.patch rename to 0003-arm-Explicitly-disable-unwind-tables.patch index bbd695a..53bc377 100644 --- a/0004-arm-Explicitly-disable-unwind-tables.patch +++ b/0003-arm-Explicitly-disable-unwind-tables.patch @@ -1,7 +1,7 @@ -From 4f3e80094626a2b67075efdb6b899f2ab806725c Mon Sep 17 00:00:00 2001 +From 599bfa2b29c7d50d0871010e282414d94acaf68f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 18:40:21 -0500 -Subject: [PATCH 4/7] arm: Explicitly disable unwind tables +Subject: [PATCH 3/9] arm: Explicitly disable unwind tables Some clang builds (e.g., Fedora's) enable unwind tables by default. As tinygo does not need nor support them, that leads to undefined symbols diff --git a/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch similarity index 89% rename from 0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename to 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 6213390..804f479 100644 --- a/0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 4681ad345b38e1fa9627614adf3348886fa4a71c Mon Sep 17 00:00:00 2001 +From 6506b2a0081f5bb6a23f2262365fafaed1fa52a6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 5/7] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 4/9] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch b/0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch similarity index 98% rename from 0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch rename to 0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch index d0e418a..345d0e5 100644 --- a/0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch +++ b/0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch @@ -1,7 +1,7 @@ -From a0ebf57f6164d5f795b7022fa26ac8bb66bee9e8 Mon Sep 17 00:00:00 2001 +From 1ab38efdc2f633ee27785f1cd8424fc133097a9e Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 19 Nov 2021 14:47:55 +0100 -Subject: [PATCH 6/7] targets: change LLVM features to match vanilla Clang +Subject: [PATCH 5/9] targets: change LLVM features to match vanilla Clang I mistakenly believed the difference was in LLVM version 11.0.0 vs LLVM 11.1.0. However, the difference is in whether we use the Debian version diff --git a/0007-all-add-LLVM-12-support.patch b/0006-all-add-LLVM-12-support.patch similarity index 99% rename from 0007-all-add-LLVM-12-support.patch rename to 0006-all-add-LLVM-12-support.patch index ff708c7..26e2ddb 100644 --- a/0007-all-add-LLVM-12-support.patch +++ b/0006-all-add-LLVM-12-support.patch @@ -1,7 +1,7 @@ -From aefb7735476f11cbe3b7cb2a026afd34ab74d771 Mon Sep 17 00:00:00 2001 +From cff70b542db4a8b99e4445c555f70dad32337e5c Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 28 Mar 2021 19:56:03 -0400 -Subject: [PATCH 7/7] all: add LLVM 12 support +Subject: [PATCH 6/9] all: add LLVM 12 support Originally based on a PR by @QuLogic, but extended a lot to get all tests to pass. diff --git a/0007-tests-improve-wasm-tests-slightly.patch b/0007-tests-improve-wasm-tests-slightly.patch new file mode 100644 index 0000000..cbac6ae --- /dev/null +++ b/0007-tests-improve-wasm-tests-slightly.patch @@ -0,0 +1,262 @@ +From f5ece39b3353ae389ab3da90163b6a49dda1d4aa Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sat, 20 Nov 2021 01:06:02 +0100 +Subject: [PATCH 7/9] tests: improve wasm tests slightly + +These wasm tests weren't passing in GitHub Actions and also weren't +passing on my laptop. I'm not sure why, I think there are a few race +conditions that are going on. + +This commit attempts to fix this at least to a degree: + + - The context deadline is increased from 5 seconds to 10 seconds. + - The tests are not running in parallel anymore. + - Some `Sleep` calls were removed, they do not appear to be necessary + (and if they were, sleeping is the wrong solution to solve race + conditions). + +Overall the tests are taking a few seconds more, but on the other hand +they seem to be passing more reliable. At least for me, on my laptop +(and hopefully also in CI). + +Signed-off-by: Elliott Sales de Andrade +--- + tests/wasm/chan_test.go | 7 ++----- + tests/wasm/event_test.go | 9 ++------- + tests/wasm/fmt_test.go | 8 ++------ + tests/wasm/fmtprint_test.go | 8 ++------ + tests/wasm/log_test.go | 8 ++------ + tests/wasm/setup_test.go | 13 ++++++------- + 6 files changed, 16 insertions(+), 37 deletions(-) + +diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go +index e44d7ebe..fe981974 100644 +--- a/tests/wasm/chan_test.go ++++ b/tests/wasm/chan_test.go +@@ -2,23 +2,20 @@ package wasm + + import ( + "testing" +- "time" + + "github.com/chromedp/chromedp" + ) + + func TestChan(t *testing.T) { + +- t.Parallel() +- + wasmTmpDir, server := startServer(t) + +- err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go") ++ err := run(t, "tinygo build -o "+wasmTmpDir+"/chan.wasm -target wasm testdata/chan.go") + if err != nil { + t.Fatal(err) + } + +- ctx, cancel := chromectx(5 * time.Second) ++ ctx, cancel := chromectx() + defer cancel() + + err = chromedp.Run(ctx, +diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go +index 038a500a..a29a01c7 100644 +--- a/tests/wasm/event_test.go ++++ b/tests/wasm/event_test.go +@@ -2,35 +2,30 @@ package wasm + + import ( + "testing" +- "time" + + "github.com/chromedp/chromedp" + ) + + func TestEvent(t *testing.T) { + +- t.Parallel() +- + wasmTmpDir, server := startServer(t) + +- err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go") ++ err := run(t, "tinygo build -o "+wasmTmpDir+"/event.wasm -target wasm testdata/event.go") + if err != nil { + t.Fatal(err) + } + +- ctx, cancel := chromectx(5 * time.Second) ++ ctx, cancel := chromectx() + defer cancel() + + var log1, log2 string + err = chromedp.Run(ctx, + chromedp.Navigate(server.URL+"/run?file=event.wasm"), + chromedp.WaitVisible("#log"), +- chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLog(`1 + 4`), + chromedp.Click("#testbtn"), +- chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log2), + waitLog(`1 + 4 +diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go +index f9f2f77b..d3695f07 100644 +--- a/tests/wasm/fmt_test.go ++++ b/tests/wasm/fmt_test.go +@@ -2,29 +2,25 @@ package wasm + + import ( + "testing" +- "time" + + "github.com/chromedp/chromedp" + ) + + func TestFmt(t *testing.T) { + +- t.Parallel() +- + wasmTmpDir, server := startServer(t) + +- err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go") ++ err := run(t, "tinygo build -o "+wasmTmpDir+"/fmt.wasm -target wasm testdata/fmt.go") + if err != nil { + t.Fatal(err) + } + +- ctx, cancel := chromectx(5 * time.Second) ++ ctx, cancel := chromectx() + defer cancel() + + var log1 string + err = chromedp.Run(ctx, + chromedp.Navigate(server.URL+"/run?file=fmt.wasm"), +- chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLog(`did not panic`), + ) +diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go +index 90825ba0..3c750239 100644 +--- a/tests/wasm/fmtprint_test.go ++++ b/tests/wasm/fmtprint_test.go +@@ -2,29 +2,25 @@ package wasm + + import ( + "testing" +- "time" + + "github.com/chromedp/chromedp" + ) + + func TestFmtprint(t *testing.T) { + +- t.Parallel() +- + wasmTmpDir, server := startServer(t) + +- err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go") ++ err := run(t, "tinygo build -o "+wasmTmpDir+"/fmtprint.wasm -target wasm testdata/fmtprint.go") + if err != nil { + t.Fatal(err) + } + +- ctx, cancel := chromectx(5 * time.Second) ++ ctx, cancel := chromectx() + defer cancel() + + var log1 string + err = chromedp.Run(ctx, + chromedp.Navigate(server.URL+"/run?file=fmtprint.wasm"), +- chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLog(`test from fmtprint 1 + test from fmtprint 2 +diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go +index fae4c670..1f6c79fe 100644 +--- a/tests/wasm/log_test.go ++++ b/tests/wasm/log_test.go +@@ -2,29 +2,25 @@ package wasm + + import ( + "testing" +- "time" + + "github.com/chromedp/chromedp" + ) + + func TestLog(t *testing.T) { + +- t.Parallel() +- + wasmTmpDir, server := startServer(t) + +- err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go") ++ err := run(t, "tinygo build -o "+wasmTmpDir+"/log.wasm -target wasm testdata/log.go") + if err != nil { + t.Fatal(err) + } + +- ctx, cancel := chromectx(5 * time.Second) ++ ctx, cancel := chromectx() + defer cancel() + + var log1 string + err = chromedp.Run(ctx, + chromedp.Navigate(server.URL+"/run?file=log.wasm"), +- chromedp.Sleep(time.Second), + chromedp.InnerHTML("#log", &log1), + waitLogRe(`^..../../.. ..:..:.. log 1 + ..../../.. ..:..:.. log 2 +diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go +index 0071076c..e5a18daf 100644 +--- a/tests/wasm/setup_test.go ++++ b/tests/wasm/setup_test.go +@@ -4,7 +4,6 @@ import ( + "context" + "errors" + "fmt" +- "log" + "net/http" + "net/http/httptest" + "os/exec" +@@ -18,29 +17,29 @@ import ( + "github.com/chromedp/chromedp" + ) + +-func run(cmdline string) error { ++func run(t *testing.T, cmdline string) error { + args := strings.Fields(cmdline) +- return runargs(args...) ++ return runargs(t, args...) + } + +-func runargs(args ...string) error { ++func runargs(t *testing.T, args ...string) error { + cmd := exec.Command(args[0], args[1:]...) + b, err := cmd.CombinedOutput() +- log.Printf("Command: %s; err=%v; full output:\n%s", strings.Join(args, " "), err, b) ++ t.Logf("Command: %s; err=%v; full output:\n%s", strings.Join(args, " "), err, b) + if err != nil { + return err + } + return nil + } + +-func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) { ++func chromectx() (context.Context, context.CancelFunc) { + + var ctx context.Context + + // looks for locally installed Chrome + ctx, _ = chromedp.NewContext(context.Background()) + +- ctx, cancel := context.WithTimeout(ctx, timeout) ++ ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + + return ctx, cancel + } +-- +2.31.1 + diff --git a/0008-internal-task-swap-stack-chain-when-switching-gorout.patch b/0008-internal-task-swap-stack-chain-when-switching-gorout.patch new file mode 100644 index 0000000..5cbdbd8 --- /dev/null +++ b/0008-internal-task-swap-stack-chain-when-switching-gorout.patch @@ -0,0 +1,195 @@ +From 1349a7cfc72b3ed0ee6f6d529b8f57ca7d419ecc Mon Sep 17 00:00:00 2001 +From: Nia Waldvogel +Date: Tue, 14 Dec 2021 16:48:11 -0500 +Subject: [PATCH 8/9] internal/task: swap stack chain when switching goroutines + +This change swaps the stack chain when switching goroutines, ensuring that the chain is maintained consistently. +This is only really currently necessary with asyncify on wasm. + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/testdata/channel.ll | 3 ++- + .../testdata/goroutine-cortex-m-qemu-tasks.ll | 3 ++- + compiler/testdata/goroutine-wasm-asyncify.ll | 3 ++- + .../testdata/goroutine-wasm-coroutines.ll | 3 ++- + src/internal/task/gc_stack_chain.go | 19 +++++++++++++++++++ + src/internal/task/gc_stack_noop.go | 9 +++++++++ + src/internal/task/task.go | 3 +++ + src/internal/task/task_asyncify.go | 2 ++ + src/internal/task/task_stack.go | 3 +++ + src/runtime/gc_stack_portable.go | 7 +++++++ + 10 files changed, 51 insertions(+), 4 deletions(-) + create mode 100644 src/internal/task/gc_stack_chain.go + create mode 100644 src/internal/task/gc_stack_noop.go + +diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll +index 36d7fd96..3f4d5235 100644 +--- a/compiler/testdata/channel.ll ++++ b/compiler/testdata/channel.ll +@@ -5,7 +5,8 @@ target triple = "wasm32-unknown-wasi" + + %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } + %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } ++%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } ++%"internal/task.gcData" = type { i8* } + %"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } + %"internal/task.stackState" = type { i32, i32 } + %runtime.chanSelectState = type { %runtime.channel*, i8* } +diff --git a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll +index d34a1eb4..6224f256 100644 +--- a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll ++++ b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll +@@ -5,7 +5,8 @@ target triple = "thumbv7m-unknown-unknown-eabi" + + %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } + %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } ++%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } ++%"internal/task.gcData" = type {} + %"internal/task.state" = type { i32, i32* } + %runtime.chanSelectState = type { %runtime.channel*, i8* } + +diff --git a/compiler/testdata/goroutine-wasm-asyncify.ll b/compiler/testdata/goroutine-wasm-asyncify.ll +index 1ecf0c79..70ec4ef4 100644 +--- a/compiler/testdata/goroutine-wasm-asyncify.ll ++++ b/compiler/testdata/goroutine-wasm-asyncify.ll +@@ -5,7 +5,8 @@ target triple = "wasm32-unknown-wasi" + + %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } + %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } ++%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } ++%"internal/task.gcData" = type { i8* } + %"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } + %"internal/task.stackState" = type { i32, i32 } + %runtime.chanSelectState = type { %runtime.channel*, i8* } +diff --git a/compiler/testdata/goroutine-wasm-coroutines.ll b/compiler/testdata/goroutine-wasm-coroutines.ll +index 6f308247..a0c42991 100644 +--- a/compiler/testdata/goroutine-wasm-coroutines.ll ++++ b/compiler/testdata/goroutine-wasm-coroutines.ll +@@ -6,7 +6,8 @@ target triple = "wasm32-unknown-wasi" + %runtime.funcValueWithSignature = type { i32, i8* } + %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } + %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } ++%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } ++%"internal/task.gcData" = type {} + %"internal/task.state" = type { i8* } + %runtime.chanSelectState = type { %runtime.channel*, i8* } + +diff --git a/src/internal/task/gc_stack_chain.go b/src/internal/task/gc_stack_chain.go +new file mode 100644 +index 00000000..d3e400d3 +--- /dev/null ++++ b/src/internal/task/gc_stack_chain.go +@@ -0,0 +1,19 @@ ++//go:build (gc.conservative || gc.extalloc) && tinygo.wasm && !scheduler.coroutines ++// +build gc.conservative gc.extalloc ++// +build tinygo.wasm ++// +build !scheduler.coroutines ++ ++package task ++ ++import "unsafe" ++ ++//go:linkname swapStackChain runtime.swapStackChain ++func swapStackChain(dst *unsafe.Pointer) ++ ++type gcData struct { ++ stackChain unsafe.Pointer ++} ++ ++func (gcd *gcData) swap() { ++ swapStackChain(&gcd.stackChain) ++} +diff --git a/src/internal/task/gc_stack_noop.go b/src/internal/task/gc_stack_noop.go +new file mode 100644 +index 00000000..63674805 +--- /dev/null ++++ b/src/internal/task/gc_stack_noop.go +@@ -0,0 +1,9 @@ ++//go:build (!gc.conservative && !gc.extalloc) || !tinygo.wasm || scheduler.coroutines ++// +build !gc.conservative,!gc.extalloc !tinygo.wasm scheduler.coroutines ++ ++package task ++ ++type gcData struct{} ++ ++func (gcd *gcData) swap() { ++} +diff --git a/src/internal/task/task.go b/src/internal/task/task.go +index bad501b6..b490a202 100644 +--- a/src/internal/task/task.go ++++ b/src/internal/task/task.go +@@ -15,6 +15,9 @@ type Task struct { + // Data is a field which can be used for storing state information. + Data uint64 + ++ // gcData holds data for the GC. ++ gcData gcData ++ + // state is the underlying running state of the task. + state state + } +diff --git a/src/internal/task/task_asyncify.go b/src/internal/task/task_asyncify.go +index d67f0e1c..939008bc 100644 +--- a/src/internal/task/task_asyncify.go ++++ b/src/internal/task/task_asyncify.go +@@ -104,6 +104,7 @@ func (*stackState) unwind() + func (t *Task) Resume() { + // The current task must be saved and restored because this can nest on WASM with JS. + prevTask := currentTask ++ t.gcData.swap() + currentTask = t + if !t.state.launched { + t.state.launch() +@@ -112,6 +113,7 @@ func (t *Task) Resume() { + t.state.rewind() + } + currentTask = prevTask ++ t.gcData.swap() + if t.state.asyncifysp > t.state.csp { + runtimePanic("stack overflow") + } +diff --git a/src/internal/task/task_stack.go b/src/internal/task/task_stack.go +index a703d10a..59af6503 100644 +--- a/src/internal/task/task_stack.go ++++ b/src/internal/task/task_stack.go +@@ -1,3 +1,4 @@ ++//go:build scheduler.tasks + // +build scheduler.tasks + + package task +@@ -54,7 +55,9 @@ func pause() { + // This may only be called from the scheduler. + func (t *Task) Resume() { + currentTask = t ++ t.gcData.swap() + t.state.resume() ++ t.gcData.swap() + currentTask = nil + } + +diff --git a/src/runtime/gc_stack_portable.go b/src/runtime/gc_stack_portable.go +index d4a04637..1cdd31f3 100644 +--- a/src/runtime/gc_stack_portable.go ++++ b/src/runtime/gc_stack_portable.go +@@ -1,3 +1,4 @@ ++//go:build (gc.conservative || gc.extalloc) && tinygo.wasm + // +build gc.conservative gc.extalloc + // +build tinygo.wasm + +@@ -37,3 +38,9 @@ func markStack() { + // construction. Calls to it are later replaced with regular stack bookkeeping + // code. + func trackPointer(ptr unsafe.Pointer) ++ ++// swapStackChain swaps the stack chain. ++// This is called from internal/task when switching goroutines. ++func swapStackChain(dst **stackChainObject) { ++ *dst, stackChainStart = stackChainStart, *dst ++} +-- +2.31.1 + diff --git a/0009-all-switch-to-LLVM-13.patch b/0009-all-switch-to-LLVM-13.patch new file mode 100644 index 0000000..1f9d50a --- /dev/null +++ b/0009-all-switch-to-LLVM-13.patch @@ -0,0 +1,960 @@ +From b88f3a8bac4ee3daf56bb1a1dda3211974251043 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 9 Dec 2021 02:52:08 +0100 +Subject: [PATCH 9/9] all: switch to LLVM 13 + +This adds support for building with `-tags=llvm13` and switches to LLVM +13 for tinygo binaries that are statically linked against LLVM. + +Some notes on this commit: + + * Added `-mfloat-abi=soft` to all Cortex-M targets because otherwise + nrfx would complain that floating point was enabled on Cortex-M0. + That's not the case, but with `-mfloat-abi=soft` the `__SOFTFP__` + macro is defined which silences this warning. + See: https://reviews.llvm.org/D100372 + * Changed from `--sysroot=` to `-nostdlib -isystem ` for + musl because with Clang 13, even with `--sysroot` some system + libraries are used which we don't want. + * Changed all `-Xclang -internal-isystem -Xclang` to simply + `-isystem`, for consistency with the above change. It appears to + have the same effect. + * Moved WebAssembly function declarations to the top of the file in + task_asyncify_wasm.S because (apparently) the assembler has become + more strict. + +Signed-off-by: Elliott Sales de Andrade +--- + .circleci/config.yml | 12 +-- + .github/workflows/windows.yml | 4 +- + Makefile | 8 +- + builder/cc1as.cpp | 79 ++++++++++--------- + builder/cc1as.h | 2 + + builder/picolibc.go | 2 +- + cgo/libclang_config.go | 2 +- + cgo/libclang_config_llvm13.go | 14 ++++ + compileopts/config.go | 13 +-- + compileopts/target.go | 6 +- + compiler/compiler_test.go | 7 +- + compiler/inlineasm.go | 16 ++-- + compiler/syscall.go | 8 +- + compiler/testdata/basic.ll | 2 +- + compiler/testdata/channel.ll | 2 +- + compiler/testdata/float.ll | 2 +- + compiler/testdata/func-coroutines.ll | 2 +- + compiler/testdata/gc.ll | 2 +- + compiler/testdata/go1.17.ll | 2 +- + compiler/testdata/goroutine-wasm-asyncify.ll | 2 +- + .../testdata/goroutine-wasm-coroutines.ll | 2 +- + compiler/testdata/interface.ll | 2 +- + compiler/testdata/intrinsics-wasm.ll | 2 +- + compiler/testdata/pointer.ll | 2 +- + compiler/testdata/pragma.ll | 2 +- + compiler/testdata/slice.ll | 2 +- + compiler/testdata/string.ll | 2 +- + go.mod | 2 +- + go.sum | 4 +- + loader/loader.go | 2 +- + src/internal/task/task_asyncify_wasm.S | 18 ++--- + targets/cortex-m.json | 1 + + targets/cortex-m0.json | 2 +- + targets/cortex-m0plus.json | 2 +- + targets/cortex-m3.json | 2 +- + targets/cortex-m33.json | 5 +- + targets/cortex-m4.json | 5 +- + targets/cortex-m7.json | 5 +- + targets/gameboy-advance.json | 2 +- + targets/k210.json | 2 +- + transform/optimizer.go | 1 + + 41 files changed, 137 insertions(+), 117 deletions(-) + create mode 100644 cgo/libclang_config_llvm13.go + +diff --git a/.circleci/config.yml b/.circleci/config.yml +index 50bdd087..8005a7bb 100644 +--- a/.circleci/config.yml ++++ b/.circleci/config.yml +@@ -52,12 +52,12 @@ commands: + steps: + - restore_cache: + keys: +- - llvm-source-12-v1 ++ - llvm-source-13-v1 + - run: + name: "Fetch LLVM source" + command: make llvm-source + - save_cache: +- key: llvm-source-12-v1 ++ key: llvm-source-13-v1 + paths: + - llvm-project/clang/lib/Headers + - llvm-project/clang/include +@@ -332,12 +332,12 @@ commands: + - go-cache-macos-v3-{{ checksum "go.mod" }} + - restore_cache: + keys: +- - llvm-source-12-macos-v1 ++ - llvm-source-13-macos-v1 + - run: + name: "Fetch LLVM source" + command: make llvm-source + - save_cache: +- key: llvm-source-12-macos-v1 ++ key: llvm-source-13-macos-v1 + paths: + - llvm-project/clang/lib/Headers + - llvm-project/clang/include +@@ -345,7 +345,7 @@ commands: + - llvm-project/llvm/include + - restore_cache: + keys: +- - llvm-build-12-macos-v1 ++ - llvm-build-13-macos-v1 + - run: + name: "Build LLVM" + command: | +@@ -359,7 +359,7 @@ commands: + find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; + fi + - save_cache: +- key: llvm-build-12-macos-v1 ++ key: llvm-build-13-macos-v1 + paths: + llvm-build + - restore_cache: +diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml +index 8649f635..4aa92532 100644 +--- a/.github/workflows/windows.yml ++++ b/.github/workflows/windows.yml +@@ -27,7 +27,7 @@ jobs: + uses: actions/cache@v2 + id: cache-llvm-source + with: +- key: llvm-source-12-windows-v1 ++ key: llvm-source-13-windows-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -40,7 +40,7 @@ jobs: + uses: actions/cache@v2 + id: cache-llvm-build + with: +- key: llvm-build-12-windows-v1 ++ key: llvm-build-13-windows-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +diff --git a/Makefile b/Makefile +index 0ebfcd82..987376f4 100644 +--- a/Makefile ++++ b/Makefile +@@ -10,9 +10,9 @@ LLD_SRC ?= $(LLVM_PROJECTDIR)/lld + + # Try to autodetect LLVM build tools. + detect = $(shell command -v $(1) 2> /dev/null && echo $(1)) +-CLANG ?= $(word 1,$(abspath $(call detect,llvm-build/bin/clang))$(call detect,clang-11)$(call detect,clang)) +-LLVM_AR ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-ar))$(call detect,llvm-ar-11)$(call detect,llvm-ar)) +-LLVM_NM ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-nm))$(call detect,llvm-nm-11)$(call detect,llvm-nm)) ++CLANG ?= $(word 1,$(abspath $(call detect,llvm-build/bin/clang))$(call detect,clang-13)$(call detect,clang-12)$(call detect,clang-11)$(call detect,clang)) ++LLVM_AR ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-ar))$(call detect,llvm-ar-13)$(call detect,llvm-ar-12)$(call detect,llvm-ar-11)$(call detect,llvm-ar)) ++LLVM_NM ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-nm))$(call detect,llvm-nm-13)$(call detect,llvm-nm-12)$(call detect,llvm-nm-11)$(call detect,llvm-nm)) + + # Go binary and GOROOT to select + GO ?= go +@@ -160,7 +160,7 @@ gen-device-rp: build/gen-device-svd + + # Get LLVM sources. + $(LLVM_PROJECTDIR)/llvm: +- git clone -b xtensa_release_12.0.1 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) ++ git clone -b xtensa_release_13.0.0 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) + llvm-source: $(LLVM_PROJECTDIR)/llvm + + # Configure LLVM. +diff --git a/builder/cc1as.cpp b/builder/cc1as.cpp +index 2553e0e2..ece54124 100644 +--- a/builder/cc1as.cpp ++++ b/builder/cc1as.cpp +@@ -115,29 +115,26 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, + // Any DebugInfoKind implies GenDwarfForAssembly. + Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ); + +- if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections, +- OPT_compress_debug_sections_EQ)) { +- if (A->getOption().getID() == OPT_compress_debug_sections) { +- // TODO: be more clever about the compression type auto-detection +- Opts.CompressDebugSections = llvm::DebugCompressionType::GNU; +- } else { +- Opts.CompressDebugSections = +- llvm::StringSwitch(A->getValue()) +- .Case("none", llvm::DebugCompressionType::None) +- .Case("zlib", llvm::DebugCompressionType::Z) +- .Case("zlib-gnu", llvm::DebugCompressionType::GNU) +- .Default(llvm::DebugCompressionType::None); +- } ++ if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections_EQ)) { ++ Opts.CompressDebugSections = ++ llvm::StringSwitch(A->getValue()) ++ .Case("none", llvm::DebugCompressionType::None) ++ .Case("zlib", llvm::DebugCompressionType::Z) ++ .Case("zlib-gnu", llvm::DebugCompressionType::GNU) ++ .Default(llvm::DebugCompressionType::None); + } + + Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations); ++ if (auto *DwarfFormatArg = Args.getLastArg(OPT_gdwarf64, OPT_gdwarf32)) ++ Opts.Dwarf64 = DwarfFormatArg->getOption().matches(OPT_gdwarf64); + Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags); + Opts.DwarfDebugFlags = + std::string(Args.getLastArgValue(OPT_dwarf_debug_flags)); + Opts.DwarfDebugProducer = + std::string(Args.getLastArgValue(OPT_dwarf_debug_producer)); +- Opts.DebugCompilationDir = +- std::string(Args.getLastArgValue(OPT_fdebug_compilation_dir)); ++ if (const Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, ++ options::OPT_fdebug_compilation_dir_EQ)) ++ Opts.DebugCompilationDir = A->getValue(); + Opts.MainFileName = std::string(Args.getLastArgValue(OPT_main_file_name)); + + for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) { +@@ -219,7 +216,7 @@ getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) { + + std::error_code EC; + auto Out = std::make_unique( +- Path, EC, (Binary ? sys::fs::OF_None : sys::fs::OF_Text)); ++ Path, EC, (Binary ? sys::fs::OF_None : sys::fs::OF_TextWithCRLF)); + if (EC) { + Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message(); + return nullptr; +@@ -228,7 +225,8 @@ getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) { + return Out; + } + +-bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { ++static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, ++ DiagnosticsEngine &Diags) { + // Get the target specific parser. + std::string Error; + const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error); +@@ -236,7 +234,7 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; + + ErrorOr> Buffer = +- MemoryBuffer::getFileOrSTDIN(Opts.InputFile); ++ MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); + + if (std::error_code EC = Buffer.getError()) { + Error = EC.message(); +@@ -277,11 +275,15 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + if (!Opts.SplitDwarfOutput.empty()) + DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary); + +- // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and +- // MCObjectFileInfo needs a MCContext reference in order to initialize itself. +- std::unique_ptr MOFI(new MCObjectFileInfo()); ++ // Build up the feature string from the target feature list. ++ std::string FS = llvm::join(Opts.Features, ","); + +- MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr, &MCOptions); ++ std::unique_ptr STI( ++ TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); ++ assert(STI && "Unable to create subtarget info!"); ++ ++ MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr, ++ &MCOptions); + + bool PIC = false; + if (Opts.RelocationModel == "static") { +@@ -294,7 +296,12 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + PIC = false; + } + +- MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, Ctx); ++ // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and ++ // MCObjectFileInfo needs a MCContext reference in order to initialize itself. ++ std::unique_ptr MOFI( ++ TheTarget->createMCObjectFileInfo(Ctx, PIC)); ++ Ctx.setObjectFileInfo(MOFI.get()); ++ + if (Opts.SaveTemporaryLabels) + Ctx.setAllowTemporaryLabels(false); + if (Opts.GenDwarfForAssembly) +@@ -316,19 +323,16 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + Ctx.addDebugPrefixMapEntry(KV.first, KV.second); + if (!Opts.MainFileName.empty()) + Ctx.setMainFileName(StringRef(Opts.MainFileName)); ++ Ctx.setDwarfFormat(Opts.Dwarf64 ? dwarf::DWARF64 : dwarf::DWARF32); + Ctx.setDwarfVersion(Opts.DwarfVersion); + if (Opts.GenDwarfForAssembly) + Ctx.setGenDwarfRootFile(Opts.InputFile, + SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer()); + +- // Build up the feature string from the target feature list. +- std::string FS = llvm::join(Opts.Features, ","); +- + std::unique_ptr Str; + + std::unique_ptr MCII(TheTarget->createMCInstrInfo()); +- std::unique_ptr STI( +- TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); ++ assert(MCII && "Unable to create instruction info!"); + + raw_pwrite_stream *Out = FDOS.get(); + std::unique_ptr BOS; +@@ -367,6 +371,8 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); + std::unique_ptr MAB( + TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); ++ assert(MAB && "Unable to create asm backend!"); ++ + std::unique_ptr OW = + DwoOS ? MAB->createDwoObjectWriter(*Out, *DwoOS) + : MAB->createObjectWriter(*Out); +@@ -381,8 +387,7 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + + // When -fembed-bitcode is passed to clang_as, a 1-byte marker + // is emitted in __LLVM,__asm section if the object file is MachO format. +- if (Opts.EmbedBitcode && Ctx.getObjectFileInfo()->getObjectFileType() == +- MCObjectFileInfo::IsMachO) { ++ if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) { + MCSection *AsmLabel = Ctx.getMachOSection( + "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); + Str.get()->SwitchSection(AsmLabel); +@@ -419,12 +424,12 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { + Failed = Parser->Run(Opts.NoInitialTextSection); + } + +- // Close Streamer first. +- // It might have a reference to the output stream. +- Str.reset(); +- // Close the output stream early. +- BOS.reset(); +- FDOS.reset(); ++ return Failed; ++} ++ ++bool ExecuteAssembler(AssemblerInvocation &Opts, ++ DiagnosticsEngine &Diags) { ++ bool Failed = ExecuteAssemblerImpl(Opts, Diags); + + // Delete output file if there were errors. + if (Failed) { +@@ -472,7 +477,7 @@ int cc1as_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { + return 1; + + if (Asm.ShowHelp) { +- getDriverOptTable().PrintHelp( ++ getDriverOptTable().printHelp( + llvm::outs(), "clang -cc1as [options] file...", + "Clang Integrated Assembler", + /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0, +diff --git a/builder/cc1as.h b/builder/cc1as.h +index ce9a1781..538e9a26 100644 +--- a/builder/cc1as.h ++++ b/builder/cc1as.h +@@ -39,6 +39,7 @@ struct AssemblerInvocation { + unsigned SaveTemporaryLabels : 1; + unsigned GenDwarfForAssembly : 1; + unsigned RelaxELFRelocations : 1; ++ unsigned Dwarf64 : 1; + unsigned DwarfVersion; + std::string DwarfDebugFlags; + std::string DwarfDebugProducer; +@@ -108,6 +109,7 @@ public: + FatalWarnings = 0; + NoWarn = 0; + IncrementalLinkerCompatible = 0; ++ Dwarf64 = 0; + DwarfVersion = 0; + EmbedBitcode = 0; + } +diff --git a/builder/picolibc.go b/builder/picolibc.go +index 75c93e91..af34f7ef 100644 +--- a/builder/picolibc.go ++++ b/builder/picolibc.go +@@ -28,7 +28,7 @@ var Picolibc = Library{ + "-DHAVE_ALIAS_ATTRIBUTE", + "-DTINY_STDIO", + "-nostdlibinc", +- "-Xclang", "-internal-isystem", "-Xclang", picolibcDir + "/include", ++ "-isystem", picolibcDir + "/include", + "-I" + picolibcDir + "/tinystdio", + "-I" + headerPath, + } +diff --git a/cgo/libclang_config.go b/cgo/libclang_config.go +index 9f7cdc1c..ed929f79 100644 +--- a/cgo/libclang_config.go ++++ b/cgo/libclang_config.go +@@ -1,5 +1,5 @@ + // +build !byollvm +-// +build !llvm12 ++// +build !llvm12,!llvm13 + + package cgo + +diff --git a/cgo/libclang_config_llvm13.go b/cgo/libclang_config_llvm13.go +new file mode 100644 +index 00000000..3c961a3f +--- /dev/null ++++ b/cgo/libclang_config_llvm13.go +@@ -0,0 +1,14 @@ ++// +build !byollvm ++// +build llvm13 ++ ++package cgo ++ ++/* ++#cgo linux CFLAGS: -I/usr/lib/llvm-13/include ++#cgo darwin CFLAGS: -I/usr/local/opt/llvm@13/include ++#cgo freebsd CFLAGS: -I/usr/local/llvm13/include ++#cgo linux LDFLAGS: -L/usr/lib/llvm-13/lib -lclang ++#cgo darwin LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi ++#cgo freebsd LDFLAGS: -L/usr/local/llvm13/lib -lclang ++*/ ++import "C" +diff --git a/compileopts/config.go b/compileopts/config.go +index 1f54e157..6dc44c79 100644 +--- a/compileopts/config.go ++++ b/compileopts/config.go +@@ -257,17 +257,18 @@ func (c *Config) CFlags() []string { + path, _ := c.LibcPath("picolibc") + cflags = append(cflags, + "--sysroot="+path, +- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "include"), +- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "tinystdio"), ++ "-isystem", filepath.Join(picolibcDir, "include"), ++ "-isystem", filepath.Join(picolibcDir, "tinystdio"), + ) + case "musl": + root := goenv.Get("TINYGOROOT") + path, _ := c.LibcPath("musl") + arch := MuslArchitecture(c.Triple()) + cflags = append(cflags, +- "--sysroot="+path, +- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "musl", "arch", arch), +- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "musl", "include"), ++ "-nostdlibinc", ++ "-isystem", filepath.Join(path, "include"), ++ "-isystem", filepath.Join(root, "lib", "musl", "arch", arch), ++ "-isystem", filepath.Join(root, "lib", "musl", "include"), + ) + case "wasi-libc": + root := goenv.Get("TINYGOROOT") +@@ -275,7 +276,7 @@ func (c *Config) CFlags() []string { + case "mingw-w64": + cflags = append(cflags, + "--sysroot=/usr/x86_64-w64-mingw32/sys-root", +- "-Xclang", "-internal-isystem", "-Xclang", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", ++ "-isystem", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", + "-D_UCRT", + ) + case "": +diff --git a/compileopts/target.go b/compileopts/target.go +index 57b5bd84..ffdf7365 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -261,11 +261,11 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + spec.CFlags = append(spec.CFlags, "-fno-unwind-tables") + switch strings.Split(triple, "-")[0] { + case "armv5": +- spec.Features = "+armv5t,+strict-align,-thumb-mode" ++ spec.Features = "+armv5t,+strict-align,-aes,-bf16,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-mve.fp,-neon,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + case "armv6": +- spec.Features = "+armv6,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-thumb-mode" ++ spec.Features = "+armv6,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-aes,-d32,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fullfp16,-neon,-sha2,-thumb-mode,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + case "armv7": +- spec.Features = "+armv7-a,+d32,+dsp,+fp64,+neon,+vfp2,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,-thumb-mode" ++ spec.Features = "+armv7-a,+d32,+dsp,+fp64,+neon,+vfp2,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,-aes,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fullfp16,-sha2,-thumb-mode,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + } + case "arm64": + spec.CPU = "generic" +diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go +index 3c978274..65a1c626 100644 +--- a/compiler/compiler_test.go ++++ b/compiler/compiler_test.go +@@ -224,7 +224,12 @@ func filterIrrelevantIRLines(lines []string) []string { + } + if llvmVersion < 12 && strings.HasPrefix(line, "attributes ") { + // Ignore attribute groups. These may change between LLVM versions. +- // Right now test outputs are for LLVM 12. ++ // Right now test outputs are for LLVM 12 and higher. ++ continue ++ } ++ if llvmVersion < 13 && strings.HasPrefix(line, "target datalayout = ") { ++ // The datalayout string may vary betewen LLVM versions. ++ // Right now test outputs are for LLVM 13 and higher. + continue + } + out = append(out, line) +diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go +index e32a4f39..635aed98 100644 +--- a/compiler/inlineasm.go ++++ b/compiler/inlineasm.go +@@ -24,7 +24,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { + // Magic function: insert inline assembly instead of calling it. + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{}, false) + asm := constant.StringVal(args[0].(*ssa.Const).Value) +- target := llvm.InlineAsm(fnType, asm, "", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "", true, false, 0, false) + return b.CreateCall(target, nil, ""), nil + } + +@@ -116,7 +116,7 @@ func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) + outputType = b.ctx.VoidType() + } + fnType := llvm.FunctionType(outputType, argTypes, false) +- target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0) ++ target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0, false) + result := b.CreateCall(target, args, "") + if hasOutput { + return result, nil +@@ -159,7 +159,7 @@ func (b *builder) emitSVCall(args []ssa.Value) (llvm.Value, error) { + // marked as clobbered. + constraints += ",~{r1},~{r2},~{r3}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) + return b.CreateCall(target, llvmArgs, ""), nil + } + +@@ -197,7 +197,7 @@ func (b *builder) emitSV64Call(args []ssa.Value) (llvm.Value, error) { + // marked as clobbered. + constraints += ",~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) + return b.CreateCall(target, llvmArgs, ""), nil + } + +@@ -222,24 +222,24 @@ func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error) { + // marked as such. + fnType := llvm.FunctionType(b.uintptrType, nil, false) + asm := fmt.Sprintf("csrr $0, %d", csr) +- target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0, false) + return b.CreateCall(target, nil, ""), nil + case "Set": + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrw %d, $0", csr) +- target := llvm.InlineAsm(fnType, asm, "r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "r", true, false, 0, false) + return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + case "SetBits": + // Note: it may be possible to optimize this to csrrsi in many cases. + fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrrs $0, %d, $1", csr) +- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) + return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + case "ClearBits": + // Note: it may be possible to optimize this to csrrci in many cases. + fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrrc $0, %d, $1", csr) +- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) ++ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) + return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + default: + return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) +diff --git a/compiler/syscall.go b/compiler/syscall.go +index db379d52..37330684 100644 +--- a/compiler/syscall.go ++++ b/compiler/syscall.go +@@ -56,7 +56,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + } + constraints += ",~{rcx},~{r11}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel) ++ target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false) + return b.CreateCall(target, args, ""), nil + case b.GOARCH == "386" && b.GOOS == "linux": + // Sources: +@@ -82,7 +82,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + argTypes = append(argTypes, llvmValue.Type()) + } + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel) ++ target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false) + return b.CreateCall(target, args, ""), nil + case b.GOARCH == "arm" && b.GOOS == "linux": + // Implement the EABI system call convention for Linux. +@@ -114,7 +114,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + constraints += ",~{r" + strconv.Itoa(i) + "}" + } + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) + return b.CreateCall(target, args, ""), nil + case b.GOARCH == "arm64" && b.GOOS == "linux": + // Source: syscall(2) man page. +@@ -146,7 +146,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + } + constraints += ",~{x16},~{x17}" // scratch registers + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) +- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) ++ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) + return b.CreateCall(target, args, ""), nil + default: + return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH) +diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll +index 56baf3a7..69b72f27 100644 +--- a/compiler/testdata/basic.ll ++++ b/compiler/testdata/basic.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'basic.go' + source_filename = "basic.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %main.kv = type { float } +diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll +index 3f4d5235..fa80db5d 100644 +--- a/compiler/testdata/channel.ll ++++ b/compiler/testdata/channel.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'channel.go' + source_filename = "channel.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } +diff --git a/compiler/testdata/float.ll b/compiler/testdata/float.ll +index c6964058..e96f8cd7 100644 +--- a/compiler/testdata/float.ll ++++ b/compiler/testdata/float.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'float.go' + source_filename = "float.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) +diff --git a/compiler/testdata/func-coroutines.ll b/compiler/testdata/func-coroutines.ll +index eeefa43c..b88ce514 100644 +--- a/compiler/testdata/func-coroutines.ll ++++ b/compiler/testdata/func-coroutines.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'func.go' + source_filename = "func.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime.funcValueWithSignature = type { i32, i8* } +diff --git a/compiler/testdata/gc.ll b/compiler/testdata/gc.ll +index 375763f3..90e6b6e8 100644 +--- a/compiler/testdata/gc.ll ++++ b/compiler/testdata/gc.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'gc.go' + source_filename = "gc.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +diff --git a/compiler/testdata/go1.17.ll b/compiler/testdata/go1.17.ll +index 5c26166a..1499547f 100644 +--- a/compiler/testdata/go1.17.ll ++++ b/compiler/testdata/go1.17.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'go1.17.go' + source_filename = "go1.17.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) +diff --git a/compiler/testdata/goroutine-wasm-asyncify.ll b/compiler/testdata/goroutine-wasm-asyncify.ll +index 70ec4ef4..0220bd5b 100644 +--- a/compiler/testdata/goroutine-wasm-asyncify.ll ++++ b/compiler/testdata/goroutine-wasm-asyncify.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'goroutine.go' + source_filename = "goroutine.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } +diff --git a/compiler/testdata/goroutine-wasm-coroutines.ll b/compiler/testdata/goroutine-wasm-coroutines.ll +index a0c42991..fe7b89b5 100644 +--- a/compiler/testdata/goroutine-wasm-coroutines.ll ++++ b/compiler/testdata/goroutine-wasm-coroutines.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'goroutine.go' + source_filename = "goroutine.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime.funcValueWithSignature = type { i32, i8* } +diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll +index f5afb0f3..c27142ec 100644 +--- a/compiler/testdata/interface.ll ++++ b/compiler/testdata/interface.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'interface.go' + source_filename = "interface.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +diff --git a/compiler/testdata/intrinsics-wasm.ll b/compiler/testdata/intrinsics-wasm.ll +index 9e6687d5..ce20dfd0 100644 +--- a/compiler/testdata/intrinsics-wasm.ll ++++ b/compiler/testdata/intrinsics-wasm.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'intrinsics.go' + source_filename = "intrinsics.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) +diff --git a/compiler/testdata/pointer.ll b/compiler/testdata/pointer.ll +index 4072816b..7020c0fa 100644 +--- a/compiler/testdata/pointer.ll ++++ b/compiler/testdata/pointer.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'pointer.go' + source_filename = "pointer.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) +diff --git a/compiler/testdata/pragma.ll b/compiler/testdata/pragma.ll +index 31fe6236..943b574d 100644 +--- a/compiler/testdata/pragma.ll ++++ b/compiler/testdata/pragma.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'pragma.go' + source_filename = "pragma.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + @extern_global = external global [0 x i8], align 1 +diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll +index 847d29fb..0cca8970 100644 +--- a/compiler/testdata/slice.ll ++++ b/compiler/testdata/slice.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'slice.go' + source_filename = "slice.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) +diff --git a/compiler/testdata/string.ll b/compiler/testdata/string.ll +index e8d6e631..93f76059 100644 +--- a/compiler/testdata/string.ll ++++ b/compiler/testdata/string.ll +@@ -1,6 +1,6 @@ + ; ModuleID = 'string.go' + source_filename = "string.go" +-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" ++target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + + %runtime._string = type { i8*, i32 } +diff --git a/go.mod b/go.mod +index 52dd71c3..c1df4c2b 100644 +--- a/go.mod ++++ b/go.mod +@@ -13,5 +13,5 @@ require ( + go.bug.st/serial v1.1.3 + golang.org/x/sys v0.0.0-20210510120138-977fb7262007 + golang.org/x/tools v0.1.6-0.20210813165731-45389f592fe9 +- tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be ++ tinygo.org/x/go-llvm v0.0.0-20211230181020-1ddc904f6bf6 + ) +diff --git a/go.sum b/go.sum +index 73697653..4e394e71 100644 +--- a/go.sum ++++ b/go.sum +@@ -68,5 +68,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/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-20210907125547-fd2d62ea06be h1:syIpWbi/yESuoyijF2nhRdgX4422sNfmij+o73B3+vU= +-tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= ++tinygo.org/x/go-llvm v0.0.0-20211230181020-1ddc904f6bf6 h1:p9huJkDeMFLOE5A4puIPRIewaTpQXX6OmjguUmGXJj4= ++tinygo.org/x/go-llvm v0.0.0-20211230181020-1ddc904f6bf6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +diff --git a/loader/loader.go b/loader/loader.go +index 1f43e07e..489ed24f 100644 +--- a/loader/loader.go ++++ b/loader/loader.go +@@ -406,7 +406,7 @@ func (p *Package) parseFiles() ([]*ast.File, error) { + initialCFlags = append(initialCFlags, p.program.config.CFlags()...) + initialCFlags = append(initialCFlags, "-I"+p.Dir) + if p.program.clangHeaders != "" { +- initialCFlags = append(initialCFlags, "-Xclang", "-internal-isystem", "-Xclang", p.program.clangHeaders) ++ initialCFlags = append(initialCFlags, "-isystem", p.program.clangHeaders) + } + generated, headerCode, cflags, ldflags, accessedFiles, errs := cgo.Process(files, p.program.workingDir, p.program.fset, initialCFlags) + p.CFlags = append(initialCFlags, cflags...) +diff --git a/src/internal/task/task_asyncify_wasm.S b/src/internal/task/task_asyncify_wasm.S +index da00dcae..3b00ede1 100644 +--- a/src/internal/task/task_asyncify_wasm.S ++++ b/src/internal/task/task_asyncify_wasm.S +@@ -1,5 +1,14 @@ + .globaltype __stack_pointer, i32 + ++.functype start_unwind (i32) -> () ++.import_module start_unwind, asyncify ++.functype stop_unwind () -> () ++.import_module stop_unwind, asyncify ++.functype start_rewind (i32) -> () ++.import_module start_rewind, asyncify ++.functype stop_rewind () -> () ++.import_module stop_rewind, asyncify ++ + .global tinygo_unwind + .hidden tinygo_unwind + .type tinygo_unwind,@function +@@ -84,15 +93,6 @@ tinygo_rewind: // func (state *state) rewind() + return + end_function + +-.functype start_unwind (i32) -> () +-.import_module start_unwind, asyncify +-.functype stop_unwind () -> () +-.import_module stop_unwind, asyncify +-.functype start_rewind (i32) -> () +-.import_module start_rewind, asyncify +-.functype stop_rewind () -> () +-.import_module stop_rewind, asyncify +- + .hidden tinygo_rewinding # @tinygo_rewinding + .type tinygo_rewinding,@object + .section .bss.tinygo_rewinding,"",@ +diff --git a/targets/cortex-m.json b/targets/cortex-m.json +index c2661393..5c057d61 100644 +--- a/targets/cortex-m.json ++++ b/targets/cortex-m.json +@@ -13,6 +13,7 @@ + "-Werror", + "-fshort-enums", + "-fomit-frame-pointer", ++ "-mfloat-abi=soft", + "-fno-exceptions", "-fno-unwind-tables", + "-ffunction-sections", "-fdata-sections" + ], +diff --git a/targets/cortex-m0.json b/targets/cortex-m0.json +index 315d6658..fe356805 100644 +--- a/targets/cortex-m0.json ++++ b/targets/cortex-m0.json +@@ -2,5 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv6m-unknown-unknown-eabi", + "cpu": "cortex-m0", +- "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" ++ "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + } +diff --git a/targets/cortex-m0plus.json b/targets/cortex-m0plus.json +index 6ac9b531..a21d06ca 100644 +--- a/targets/cortex-m0plus.json ++++ b/targets/cortex-m0plus.json +@@ -2,5 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv6m-unknown-unknown-eabi", + "cpu": "cortex-m0plus", +- "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" ++ "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + } +diff --git a/targets/cortex-m3.json b/targets/cortex-m3.json +index 07d88dfe..7b878d52 100644 +--- a/targets/cortex-m3.json ++++ b/targets/cortex-m3.json +@@ -2,5 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv7m-unknown-unknown-eabi", + "cpu": "cortex-m3", +- "features": "+armv7-m,+hwdiv,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" ++ "features": "+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + } +diff --git a/targets/cortex-m33.json b/targets/cortex-m33.json +index 9b74ad16..6e77c3f2 100644 +--- a/targets/cortex-m33.json ++++ b/targets/cortex-m33.json +@@ -1,7 +1,4 @@ + { + "inherits": ["cortex-m"], +- "llvm-target": "thumbv7m-unknown-unknown-eabi", +- "cflags": [ +- "-mfloat-abi=soft" +- ] ++ "llvm-target": "thumbv7m-unknown-unknown-eabi" + } +diff --git a/targets/cortex-m4.json b/targets/cortex-m4.json +index ce947efb..8bcbf767 100644 +--- a/targets/cortex-m4.json ++++ b/targets/cortex-m4.json +@@ -2,8 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv7em-unknown-unknown-eabi", + "cpu": "cortex-m4", +- "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", +- "cflags": [ +- "-mfloat-abi=soft" +- ] ++ "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + } +diff --git a/targets/cortex-m7.json b/targets/cortex-m7.json +index 43fe532f..3ec505f6 100644 +--- a/targets/cortex-m7.json ++++ b/targets/cortex-m7.json +@@ -2,8 +2,5 @@ + "inherits": ["cortex-m"], + "llvm-target": "thumbv7em-unknown-unknown-eabi", + "cpu": "cortex-m7", +- "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", +- "cflags": [ +- "-mfloat-abi=soft" +- ] ++ "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" + } +diff --git a/targets/gameboy-advance.json b/targets/gameboy-advance.json +index 2467b4b9..fc647702 100644 +--- a/targets/gameboy-advance.json ++++ b/targets/gameboy-advance.json +@@ -1,7 +1,7 @@ + { + "llvm-target": "armv4t-unknown-unknown-eabi", + "cpu": "arm7tdmi", +- "features": "+armv4t,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2,-thumb-mode", ++ "features": "+armv4t,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", + "build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"], + "goos": "linux", + "goarch": "arm", +diff --git a/targets/k210.json b/targets/k210.json +index 2416a593..cc0d2ed4 100644 +--- a/targets/k210.json ++++ b/targets/k210.json +@@ -1,6 +1,6 @@ + { + "inherits": ["riscv64"], +- "features": "+a,+c,+d,+f,+m,-relax,-save-restore", ++ "features": "+64bit,+a,+c,+d,+f,+m,-relax,-save-restore", + "build-tags": ["k210", "kendryte"], + "code-model": "medium" + } +diff --git a/transform/optimizer.go b/transform/optimizer.go +index 64c3d0b5..cd79340c 100644 +--- a/transform/optimizer.go ++++ b/transform/optimizer.go +@@ -59,6 +59,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i + goPasses.AddGlobalDCEPass() + goPasses.AddGlobalOptimizerPass() + goPasses.AddIPSCCPPass() ++ goPasses.AddInstructionCombiningPass() // necessary for OptimizeReflectImplements + goPasses.AddAggressiveDCEPass() + goPasses.AddFunctionAttrsPass() + goPasses.Run(mod) +-- +2.31.1 + diff --git a/tinygo.spec b/tinygo.spec index 8f370b8..741f315 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,7 +10,11 @@ Version: 0.21.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%if %{fedora} > 34 +%global clang_llvm_version 13 +%else %global clang_llvm_version 12 +%endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version 9.0.0 %global musl_version 1.2.2 @@ -61,21 +65,26 @@ Source8: https://github.com/keith-packard/picolibc/archive/%{picolibc_com Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz # We don't have wasmtime to run these. Patch0001: 0001-Skip-WASI-tests.patch -# Prep for LLVM 13 -Patch0002: 0002-Add-canThrow-argument-to-llvm.InlineAsm-calls.patch # Unbundling things -Patch0003: 0003-Use-system-mingw64-headers-and-crt.patch +Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch # https://github.com/tinygo-org/tinygo/pull/2482 -Patch0004: 0004-arm-Explicitly-disable-unwind-tables.patch +Patch0003: 0003-arm-Explicitly-disable-unwind-tables.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0005: 0005-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +Patch0004: 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Backport support for LLVM 12 # https://github.com/tinygo-org/tinygo/pull/2291 -Patch0006: 0006-targets-change-LLVM-features-to-match-vanilla-Clang.patch +Patch0005: 0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch # https://github.com/tinygo-org/tinygo/pull/2300 -Patch0007: 0007-all-add-LLVM-12-support.patch +Patch0006: 0006-all-add-LLVM-12-support.patch +# Backport support for LLVM 13 +# https://github.com/tinygo-org/tinygo/pull/2289 +Patch0007: 0007-tests-improve-wasm-tests-slightly.patch +# https://github.com/tinygo-org/tinygo/pull/2388 +Patch0008: 0008-internal-task-swap-stack-chain-when-switching-gorout.patch +# https://github.com/tinygo-org/tinygo/pull/2365 +Patch0009: 0009-all-switch-to-LLVM-13.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 47756c617f65272c00feb9831247f1a1f1de680e Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 22 Jan 2022 02:44:50 +0000 Subject: [PATCH 24/78] - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- tinygo.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index 0ca4d80..c63a3a6 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -36,7 +36,7 @@ tools. Based on LLVM.} #global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} Name: tinygo -Release: 4%{?dist} +Release: 5%{?dist} Summary: Go compiler for small places # Main files: BSD @@ -238,6 +238,9 @@ make wasmtest %changelog +* Sat Jan 22 2022 Fedora Release Engineering - 0.16.0-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild + * Fri Jul 23 2021 Fedora Release Engineering - 0.16.0-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild From 41a0389334e343983e8d6817f2b4dae59304f978 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 3 Feb 2022 06:39:21 -0500 Subject: [PATCH 25/78] Update to latest version (#1978517) --- .gitignore | 3 + 0001-Skip-WASI-tests.patch | 27 +- 0002-Use-system-mingw64-headers-and-crt.patch | 14 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 14 +- ...arm-Explicitly-disable-unwind-tables.patch | 43 - 0004-Fix-LLVM-build-constraints.patch | 78 ++ ...LLVM-features-to-match-vanilla-Clang.patch | 129 --- 0006-all-add-LLVM-12-support.patch | 469 --------- 0007-tests-improve-wasm-tests-slightly.patch | 262 ----- ...ap-stack-chain-when-switching-gorout.patch | 195 ---- 0009-all-switch-to-LLVM-13.patch | 960 ------------------ sources | 6 +- tinygo.spec | 50 +- 13 files changed, 141 insertions(+), 2109 deletions(-) rename 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch => 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch (71%) delete mode 100644 0003-arm-Explicitly-disable-unwind-tables.patch create mode 100644 0004-Fix-LLVM-build-constraints.patch delete mode 100644 0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch delete mode 100644 0006-all-add-LLVM-12-support.patch delete mode 100644 0007-tests-improve-wasm-tests-slightly.patch delete mode 100644 0008-internal-task-swap-stack-chain-when-switching-gorout.patch delete mode 100644 0009-all-switch-to-LLVM-13.patch diff --git a/.gitignore b/.gitignore index 453f063..8d7bb30 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ /tinygo-0.21.0.tar.gz /musl-1.2.2.tar.gz /musl-1.2.2.tar.gz.asc +/tinygo-0.22.0.tar.gz +/musl-1.2.0.tar.gz +/musl-1.2.0.tar.gz.asc diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 9c6641f..c1032de 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,29 +1,38 @@ -From 9b9f5ddc40d838c0141a81f718bb57e546dbc742 Mon Sep 17 00:00:00 2001 +From 7916f90d20fe95c4facc83d79d2d99056225e375 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/9] Skip WASI tests. +Subject: [PATCH 1/4] Skip WASI tests. We do not have wasmtime available. Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 3 --- - 1 file changed, 3 deletions(-) + main_test.go | 5 ----- + 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index d1ef1964..d74e0d67 100644 +index cf3fc989..316f69fa 100644 --- a/main_test.go +++ b/main_test.go -@@ -144,9 +144,6 @@ func TestCompiler(t *testing.T) { - t.Run("WebAssembly", func(t *testing.T) { - runPlatTests(optionsFromTarget("wasm"), tests, t) +@@ -196,10 +196,6 @@ func TestBuild(t *testing.T) { + t.Parallel() + runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) - t.Run("WASI", func(t *testing.T) { -- runPlatTests(optionsFromTarget("wasi"), tests, t) +- t.Parallel() +- runPlatTests(optionsFromTarget("wasi", sema), tests, t) - }) } } +@@ -490,7 +486,6 @@ func TestTest(t *testing.T) { + + // Node/Wasmtime + targ{"WASM", optionsFromTarget("wasm", sema)}, +- targ{"WASI", optionsFromTarget("wasi", sema)}, + ) + } + for _, targ := range targs { -- 2.31.1 diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index 71b83cd..aaef2ac 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ -From e981e11100f9cb9c79bfd62a7e57df60929cda7b Mon Sep 17 00:00:00 2001 +From d0bd4aaedbbe1cc02af6e3046d813fd5697b6ef0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/9] Use system mingw64 headers and crt +Subject: [PATCH 2/4] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- @@ -98,10 +98,10 @@ index bdab730f..07ce05c8 100644 } return jobs diff --git a/compileopts/config.go b/compileopts/config.go -index 22cb676e..1f54e157 100644 +index f33a4b1a..b8dd4c93 100644 --- a/compileopts/config.go +++ b/compileopts/config.go -@@ -273,12 +273,9 @@ func (c *Config) CFlags() []string { +@@ -248,12 +248,9 @@ func (c *Config) CFlags() []string { root := goenv.Get("TINYGOROOT") cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") case "mingw-w64": @@ -109,10 +109,10 @@ index 22cb676e..1f54e157 100644 - path, _ := c.LibcPath("mingw-w64") cflags = append(cflags, - "--sysroot="+path, -- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"), -- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"), +- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"), +- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"), + "--sysroot=/usr/x86_64-w64-mingw32/sys-root", -+ "-Xclang", "-internal-isystem", "-Xclang", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", ++ "-isystem", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", "-D_UCRT", ) case "": diff --git a/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch similarity index 71% rename from 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename to 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 804f479..b51c233 100644 --- a/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 6506b2a0081f5bb6a23f2262365fafaed1fa52a6 Mon Sep 17 00:00:00 2001 +From f9c9b3633e322ebc3f15216afbb624bd0fb0f188 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 4/9] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 3/4] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 14 insertions(+) diff --git a/main_test.go b/main_test.go -index d74e0d67..8850ef5f 100644 +index 316f69fa..dba5e784 100644 --- a/main_test.go +++ b/main_test.go -@@ -297,6 +297,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -364,6 +364,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } @@ -35,9 +35,9 @@ index d74e0d67..8850ef5f 100644 + } + } + - // Create the test command, taking care of emulators etc. - var cmd *exec.Cmd - if len(spec.Emulator) == 0 { + // Reserve CPU time for the test to run. + // This attempts to ensure that the test is not CPU-starved. + options.Semaphore <- struct{}{} -- 2.31.1 diff --git a/0003-arm-Explicitly-disable-unwind-tables.patch b/0003-arm-Explicitly-disable-unwind-tables.patch deleted file mode 100644 index 53bc377..0000000 --- a/0003-arm-Explicitly-disable-unwind-tables.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 599bfa2b29c7d50d0871010e282414d94acaf68f Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 3 Jan 2022 18:40:21 -0500 -Subject: [PATCH 3/9] arm: Explicitly disable unwind tables - -Some clang builds (e.g., Fedora's) enable unwind tables by default. As -tinygo does not need nor support them, that leads to undefined symbols -when linking. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/library.go | 2 +- - compileopts/target.go | 1 + - 2 files changed, 2 insertions(+), 1 deletion(-) - -diff --git a/builder/library.go b/builder/library.go -index 73079785..012e4053 100644 ---- a/builder/library.go -+++ b/builder/library.go -@@ -120,7 +120,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ - } - } - if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { -- args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft") -+ args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft", "-fno-unwind-tables") - } - if strings.HasPrefix(target, "riscv32-") { - args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128") -diff --git a/compileopts/target.go b/compileopts/target.go -index 2e5f5487..829b481e 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -256,6 +256,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - spec.Features = "+cx8,+fxsr,+mmx,+sse,+sse2,+x87" - case "arm": - spec.CPU = "generic" -+ spec.CFlags = append(spec.CFlags, "-fno-unwind-tables") - switch strings.Split(triple, "-")[0] { - case "armv5": - spec.Features = "+armv5t,+strict-align,-thumb-mode" --- -2.31.1 - diff --git a/0004-Fix-LLVM-build-constraints.patch b/0004-Fix-LLVM-build-constraints.patch new file mode 100644 index 0000000..e7bab69 --- /dev/null +++ b/0004-Fix-LLVM-build-constraints.patch @@ -0,0 +1,78 @@ +From 146b1fd103b0dbc178c1ac8c0ecfcc8b82d632ae Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Wed, 2 Feb 2022 06:54:20 -0500 +Subject: [PATCH 4/4] Fix LLVM build constraints + +Signed-off-by: Elliott Sales de Andrade +--- + cgo/libclang_config_llvm11.go | 8 ++++---- + cgo/libclang_config_llvm12.go | 8 ++++---- + cgo/libclang_config_llvm13.go | 8 ++++---- + 3 files changed, 12 insertions(+), 12 deletions(-) + +diff --git a/cgo/libclang_config_llvm11.go b/cgo/libclang_config_llvm11.go +index 262303fb..1d89c9db 100644 +--- a/cgo/libclang_config_llvm11.go ++++ b/cgo/libclang_config_llvm11.go +@@ -5,12 +5,12 @@ package cgo + + /* + #cgo linux CFLAGS: -I/usr/lib/llvm-11/include +-#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@11/include +-#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include ++#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@11/include ++#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include + #cgo freebsd CFLAGS: -I/usr/local/llvm11/include + #cgo linux LDFLAGS: -L/usr/lib/llvm-11/lib -lclang +-#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi +-#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi ++#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi ++#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm11/lib -lclang + */ + import "C" +diff --git a/cgo/libclang_config_llvm12.go b/cgo/libclang_config_llvm12.go +index 69808d2e..7ccf7141 100644 +--- a/cgo/libclang_config_llvm12.go ++++ b/cgo/libclang_config_llvm12.go +@@ -5,12 +5,12 @@ package cgo + + /* + #cgo linux CFLAGS: -I/usr/lib/llvm-12/include +-#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@12/include +-#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include ++#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@12/include ++#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include + #cgo freebsd CFLAGS: -I/usr/local/llvm12/include + #cgo linux LDFLAGS: -L/usr/lib/llvm-12/lib -lclang +-#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi +-#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi ++#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi ++#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm12/lib -lclang + */ + import "C" +diff --git a/cgo/libclang_config_llvm13.go b/cgo/libclang_config_llvm13.go +index b27b0916..83d3f414 100644 +--- a/cgo/libclang_config_llvm13.go ++++ b/cgo/libclang_config_llvm13.go +@@ -5,12 +5,12 @@ package cgo + + /* + #cgo linux CFLAGS: -I/usr/lib/llvm-13/include +-#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@13/include +-#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include ++#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@13/include ++#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include + #cgo freebsd CFLAGS: -I/usr/local/llvm13/include + #cgo linux LDFLAGS: -L/usr/lib/llvm-13/lib -lclang +-#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi +-#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi ++#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi ++#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm13/lib -lclang + */ + import "C" +-- +2.31.1 + diff --git a/0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch b/0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch deleted file mode 100644 index 345d0e5..0000000 --- a/0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch +++ /dev/null @@ -1,129 +0,0 @@ -From 1ab38efdc2f633ee27785f1cd8424fc133097a9e Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 19 Nov 2021 14:47:55 +0100 -Subject: [PATCH 5/9] targets: change LLVM features to match vanilla Clang - -I mistakenly believed the difference was in LLVM version 11.0.0 vs LLVM -11.1.0. However, the difference is in whether we use the Debian version -of Clang. - -The Debian version has had lots of patches. I'm not sure which is to -blame, but it could be this one: -https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/snapshot/debian/patches/clang-arm-default-vfp3-on-armv7a.patch - -Signed-off-by: Elliott Sales de Andrade ---- - builder/builder_test.go | 19 ++++++++++++------- - compileopts/target.go | 2 +- - targets/cortex-m0.json | 2 +- - targets/cortex-m0plus.json | 2 +- - targets/cortex-m3.json | 2 +- - targets/gameboy-advance.json | 2 +- - 6 files changed, 17 insertions(+), 12 deletions(-) - -diff --git a/builder/builder_test.go b/builder/builder_test.go -index cff43db8..c38d360a 100644 ---- a/builder/builder_test.go -+++ b/builder/builder_test.go -@@ -5,6 +5,7 @@ import ( - "io/ioutil" - "os" - "path/filepath" -+ "runtime" - "testing" - - "github.com/tinygo-org/tinygo/compileopts" -@@ -60,7 +61,11 @@ func TestClangAttributes(t *testing.T) { - {GOOS: "darwin", GOARCH: "arm64"}, - {GOOS: "windows", GOARCH: "amd64"}, - } { -- t.Run("GOOS="+options.GOOS+",GOARCH="+options.GOARCH, func(t *testing.T) { -+ name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH -+ if options.GOARCH == "arm" { -+ name += ",GOARM=" + options.GOARM -+ } -+ t.Run(name, func(t *testing.T) { - testClangAttributes(t, options) - }) - } -@@ -131,12 +136,12 @@ func testClangAttributes(t *testing.T, options *compileopts.Options) { - t.Errorf("target has CPU %#v but Clang makes it CPU %#v", config.CPU(), cpu) - } - if features != config.Features() { -- if llvm.Version != "11.0.0" { -- // This needs to be removed once we switch to LLVM 12. -- // LLVM 11.0.0 uses a different "target-features" string than LLVM -- // 11.1.0 for Thumb targets. The Xtensa fork is still based on LLVM -- // 11.0.0, so we need to skip this check on that version. -- t.Errorf("target has LLVM features %#v but Clang makes it %#v", config.Features(), features) -+ if hasBuiltinTools || runtime.GOOS != "linux" { -+ // Skip this step when using an external Clang invocation on Linux. -+ // The reason is that Debian has patched Clang in a way that -+ // modifies the LLVM features string, changing lots of FPU/float -+ // related flags. We want to test vanilla Clang, not Debian Clang. -+ t.Errorf("target has LLVM features\n\t%#v\nbut Clang makes it\n\t%#v", config.Features(), features) - } - } - } -diff --git a/compileopts/target.go b/compileopts/target.go -index 829b481e..bdd77613 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -263,7 +263,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - case "armv6": - spec.Features = "+armv6,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-thumb-mode" - case "armv7": -- spec.Features = "+armv7-a,+dsp,+fp64,+vfp2,+vfp2sp,+vfp3d16,+vfp3d16sp,-thumb-mode" -+ spec.Features = "+armv7-a,+d32,+dsp,+fp64,+neon,+vfp2,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,-thumb-mode" - } - case "arm64": - spec.CPU = "generic" -diff --git a/targets/cortex-m0.json b/targets/cortex-m0.json -index fe356805..315d6658 100644 ---- a/targets/cortex-m0.json -+++ b/targets/cortex-m0.json -@@ -2,5 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv6m-unknown-unknown-eabi", - "cpu": "cortex-m0", -- "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" -+ "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" - } -diff --git a/targets/cortex-m0plus.json b/targets/cortex-m0plus.json -index a21d06ca..6ac9b531 100644 ---- a/targets/cortex-m0plus.json -+++ b/targets/cortex-m0plus.json -@@ -2,5 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv6m-unknown-unknown-eabi", - "cpu": "cortex-m0plus", -- "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" -+ "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" - } -diff --git a/targets/cortex-m3.json b/targets/cortex-m3.json -index 7b878d52..07d88dfe 100644 ---- a/targets/cortex-m3.json -+++ b/targets/cortex-m3.json -@@ -2,5 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv7m-unknown-unknown-eabi", - "cpu": "cortex-m3", -- "features": "+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" -+ "features": "+armv7-m,+hwdiv,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" - } -diff --git a/targets/gameboy-advance.json b/targets/gameboy-advance.json -index 24e16cda..2467b4b9 100644 ---- a/targets/gameboy-advance.json -+++ b/targets/gameboy-advance.json -@@ -1,7 +1,7 @@ - { - "llvm-target": "armv4t-unknown-unknown-eabi", - "cpu": "arm7tdmi", -- "features": "+armv4t,+soft-float,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", -+ "features": "+armv4t,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2,-thumb-mode", - "build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"], - "goos": "linux", - "goarch": "arm", --- -2.31.1 - diff --git a/0006-all-add-LLVM-12-support.patch b/0006-all-add-LLVM-12-support.patch deleted file mode 100644 index 26e2ddb..0000000 --- a/0006-all-add-LLVM-12-support.patch +++ /dev/null @@ -1,469 +0,0 @@ -From cff70b542db4a8b99e4445c555f70dad32337e5c Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sun, 28 Mar 2021 19:56:03 -0400 -Subject: [PATCH 6/9] all: add LLVM 12 support - -Originally based on a PR by @QuLogic, but extended a lot to get all -tests to pass. - -Signed-off-by: Elliott Sales de Andrade ---- - .circleci/config.yml | 18 +++++++++--------- - .github/workflows/windows.yml | 4 ++-- - Makefile | 14 ++++++-------- - cgo/libclang_config.go | 1 + - cgo/libclang_config_llvm12.go | 14 ++++++++++++++ - compileopts/target.go | 14 ++++++++++++++ - compiler/compiler_test.go | 27 ++++++++++++++++++++++----- - compiler/testdata/channel.ll | 6 +++--- - compiler/testdata/intrinsics-wasm.ll | 6 +++--- - go.mod | 4 ++-- - go.sum | 10 ++++------ - interp/interp_test.go | 1 + - transform/maps_test.go | 1 + - transform/testdata/coroutines.out.ll | 6 +++--- - transform/transform_test.go | 3 ++- - 15 files changed, 87 insertions(+), 42 deletions(-) - create mode 100644 cgo/libclang_config_llvm12.go - -diff --git a/.circleci/config.yml b/.circleci/config.yml -index 61c7e287..50bdd087 100644 ---- a/.circleci/config.yml -+++ b/.circleci/config.yml -@@ -52,12 +52,12 @@ commands: - steps: - - restore_cache: - keys: -- - llvm-source-11-v2 -+ - llvm-source-12-v1 - - run: - name: "Fetch LLVM source" - command: make llvm-source - - save_cache: -- key: llvm-source-11-v2 -+ key: llvm-source-12-v1 - paths: - - llvm-project/clang/lib/Headers - - llvm-project/clang/include -@@ -332,12 +332,12 @@ commands: - - go-cache-macos-v3-{{ checksum "go.mod" }} - - restore_cache: - keys: -- - llvm-source-11-macos-v3 -+ - llvm-source-12-macos-v1 - - run: - name: "Fetch LLVM source" - command: make llvm-source - - save_cache: -- key: llvm-source-11-macos-v3 -+ key: llvm-source-12-macos-v1 - paths: - - llvm-project/clang/lib/Headers - - llvm-project/clang/include -@@ -345,7 +345,7 @@ commands: - - llvm-project/llvm/include - - restore_cache: - keys: -- - llvm-build-11-macos-v5 -+ - llvm-build-12-macos-v1 - - run: - name: "Build LLVM" - command: | -@@ -359,7 +359,7 @@ commands: - find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; - fi - - save_cache: -- key: llvm-build-11-macos-v5 -+ key: llvm-build-12-macos-v1 - paths: - llvm-build - - restore_cache: -@@ -418,12 +418,12 @@ jobs: - steps: - - test-linux: - llvm: "11" -- test-llvm11-go116: -+ test-llvm12-go116: - docker: - - image: circleci/golang:1.16-buster - steps: - - test-linux: -- llvm: "11" -+ llvm: "12" - assert-test-linux: - docker: - - image: circleci/golang:1.17-buster -@@ -451,7 +451,7 @@ workflows: - test-all: - jobs: - - test-llvm11-go115 -- - test-llvm11-go116 -+ - test-llvm12-go116 - - build-linux - - test-linux-build: - requires: -diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml -index 4bc07d59..8649f635 100644 ---- a/.github/workflows/windows.yml -+++ b/.github/workflows/windows.yml -@@ -27,7 +27,7 @@ jobs: - uses: actions/cache@v2 - id: cache-llvm-source - with: -- key: llvm-source-11-windows-v1 -+ key: llvm-source-12-windows-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -40,7 +40,7 @@ jobs: - uses: actions/cache@v2 - id: cache-llvm-build - with: -- key: llvm-build-11-windows-v2 -+ key: llvm-build-12-windows-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -diff --git a/Makefile b/Makefile -index 5de97014..0ebfcd82 100644 ---- a/Makefile -+++ b/Makefile -@@ -59,18 +59,13 @@ ifeq ($(OS),Windows_NT) - - BINARYEN_OPTION += -DCMAKE_EXE_LINKER_FLAGS='-static-libgcc -static-libstdc++' - -- LIBCLANG_NAME = libclang -- - else ifeq ($(shell uname -s),Darwin) - MD5SUM = md5 -- LIBCLANG_NAME = clang - else ifeq ($(shell uname -s),FreeBSD) - MD5SUM = md5 -- LIBCLANG_NAME = clang - START_GROUP = -Wl,--start-group - END_GROUP = -Wl,--end-group - else -- LIBCLANG_NAME = clang - START_GROUP = -Wl,--start-group - END_GROUP = -Wl,--end-group - endif -@@ -86,19 +81,22 @@ LLD_LIBS = $(START_GROUP) $(addprefix -l,$(LLD_LIB_NAMES)) $(END_GROUP) - # Other libraries that are needed to link TinyGo. - EXTRA_LIB_NAMES = LLVMInterpreter - -+# All libraries to be built and linked with the tinygo binary (lib/lib*.a). -+LIB_NAMES = clang $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES) -+ - # These build targets appear to be the only ones necessary to build all TinyGo - # dependencies. Only building a subset significantly speeds up rebuilding LLVM. - # The Makefile rules convert a name like lldELF to lib/liblldELF.a to match the - # library path (for ninja). - # This list also includes a few tools that are necessary as part of the full - # TinyGo build. --NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(addsuffix .a,$(LIBCLANG_NAME) $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES))) -+NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(addsuffix .a,$(LIB_NAMES))) - - # For static linking. - ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","") - CGO_CPPFLAGS+=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include - CGO_CXXFLAGS=-std=c++14 -- CGO_LDFLAGS+=$(abspath $(LLVM_BUILDDIR))/lib/lib$(LIBCLANG_NAME).a -L$(abspath $(LLVM_BUILDDIR)/lib) $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA) -+ CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA) - endif - - -@@ -162,7 +160,7 @@ gen-device-rp: build/gen-device-svd - - # Get LLVM sources. - $(LLVM_PROJECTDIR)/llvm: -- git clone -b xtensa_release_11.0.0 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) -+ git clone -b xtensa_release_12.0.1 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) - llvm-source: $(LLVM_PROJECTDIR)/llvm - - # Configure LLVM. -diff --git a/cgo/libclang_config.go b/cgo/libclang_config.go -index 4b4ce2db..9f7cdc1c 100644 ---- a/cgo/libclang_config.go -+++ b/cgo/libclang_config.go -@@ -1,4 +1,5 @@ - // +build !byollvm -+// +build !llvm12 - - package cgo - -diff --git a/cgo/libclang_config_llvm12.go b/cgo/libclang_config_llvm12.go -new file mode 100644 -index 00000000..1837cc15 ---- /dev/null -+++ b/cgo/libclang_config_llvm12.go -@@ -0,0 +1,14 @@ -+// +build !byollvm -+// +build llvm12 -+ -+package cgo -+ -+/* -+#cgo linux CFLAGS: -I/usr/lib/llvm-12/include -+#cgo darwin CFLAGS: -I/usr/local/opt/llvm@12/include -+#cgo freebsd CFLAGS: -I/usr/local/llvm12/include -+#cgo linux LDFLAGS: -L/usr/lib/llvm-12/lib -lclang -+#cgo darwin LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi -+#cgo freebsd LDFLAGS: -L/usr/local/llvm12/lib -lclang -+*/ -+import "C" -diff --git a/compileopts/target.go b/compileopts/target.go -index bdd77613..57b5bd84 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -12,9 +12,11 @@ import ( - "path/filepath" - "reflect" - "runtime" -+ "strconv" - "strings" - - "github.com/tinygo-org/tinygo/goenv" -+ "tinygo.org/x/go-llvm" - ) - - // Target specification for a given target. Used for bare metal targets. -@@ -280,6 +282,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - } else if goos == "windows" { - spec.Linker = "ld.lld" - spec.Libc = "mingw-w64" -+ // Note: using a medium code model, low image base and no ASLR -+ // because Go doesn't really need those features. ASLR patches -+ // around issues for unsafe languages like C/C++ that are not -+ // normally present in Go (without explicitly opting in). -+ // For more discussion: -+ // https://groups.google.com/g/Golang-nuts/c/Jd9tlNc6jUE/m/Zo-7zIP_m3MJ?pli=1 - spec.LDFlags = append(spec.LDFlags, - "-m", "i386pep", - "-Bdynamic", -@@ -287,6 +295,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - "--gc-sections", - "--no-insert-timestamp", - ) -+ llvmMajor, _ := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) -+ if llvmMajor >= 12 { -+ // This flag was added in LLVM 12. At the same time, LLVM 12 -+ // switched the default from --dynamicbase to --no-dynamicbase. -+ spec.LDFlags = append(spec.LDFlags, "--no-dynamicbase") -+ } - } else { - spec.LDFlags = append(spec.LDFlags, "-no-pie", "-Wl,--gc-sections") // WARNING: clang < 5.0 requires -nopie - } -diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index cbf89fe2..3c978274 100644 ---- a/compiler/compiler_test.go -+++ b/compiler/compiler_test.go -@@ -41,6 +41,13 @@ func TestCompiler(t *testing.T) { - t.Skip("compiler tests require LLVM 11 or above, got LLVM ", llvm.Version) - } - -+ // Determine Go minor version (e.g. 16 in go1.16.3). -+ _, goMinor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) -+ if err != nil { -+ t.Fatal("could not read Go version:", err) -+ } -+ -+ // Determine which tests to run, depending on the Go and LLVM versions. - tests := []testCase{ - {"basic.go", "", ""}, - {"pointer.go", "", ""}, -@@ -58,12 +65,11 @@ func TestCompiler(t *testing.T) { - {"intrinsics.go", "wasm", ""}, - {"gc.go", "", ""}, - } -- -- _, minor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) -- if err != nil { -- t.Fatal("could not read Go version:", err) -+ if llvmMajor >= 12 { -+ tests = append(tests, testCase{"intrinsics.go", "cortex-m-qemu", ""}) -+ tests = append(tests, testCase{"intrinsics.go", "wasm", ""}) - } -- if minor >= 17 { -+ if goMinor >= 17 { - tests = append(tests, testCase{"go1.17.go", "", ""}) - } - -@@ -201,6 +207,12 @@ func fuzzyEqualIR(s1, s2 string) bool { - // stripped out. - func filterIrrelevantIRLines(lines []string) []string { - var out []string -+ llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) -+ if err != nil { -+ // Note: this should never happen and if it does, it will always happen -+ // for a particular build because llvm.Version is a constant. -+ panic(err) -+ } - for _, line := range lines { - line = strings.Split(line, ";")[0] // strip out comments/info - line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments -@@ -210,6 +222,11 @@ func filterIrrelevantIRLines(lines []string) []string { - if strings.HasPrefix(line, "source_filename = ") { - continue - } -+ if llvmVersion < 12 && strings.HasPrefix(line, "attributes ") { -+ // Ignore attribute groups. These may change between LLVM versions. -+ // Right now test outputs are for LLVM 12. -+ continue -+ } - out = append(out, line) - } - return out -diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index 04bfa4af..36d7fd96 100644 ---- a/compiler/testdata/channel.ll -+++ b/compiler/testdata/channel.ll -@@ -34,12 +34,12 @@ entry: - ret void - } - --; Function Attrs: argmemonly nounwind willreturn -+; Function Attrs: argmemonly nofree nosync nounwind willreturn - declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 - - declare void @runtime.chanSend(%runtime.channel* dereferenceable_or_null(32), i8*, %runtime.channelBlockedList* dereferenceable_or_null(24), i8*, i8*) - --; Function Attrs: argmemonly nounwind willreturn -+; Function Attrs: argmemonly nofree nosync nounwind willreturn - declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 - - ; Function Attrs: nounwind -@@ -119,4 +119,4 @@ select.body: ; preds = %select.next - declare { i32, i1 } @runtime.tryChanSelect(i8*, %runtime.chanSelectState*, i32, i32, i8*, i8*) - - attributes #0 = { nounwind } --attributes #1 = { argmemonly nounwind willreturn } -+attributes #1 = { argmemonly nofree nosync nounwind willreturn } -diff --git a/compiler/testdata/intrinsics-wasm.ll b/compiler/testdata/intrinsics-wasm.ll -index bebadb08..9e6687d5 100644 ---- a/compiler/testdata/intrinsics-wasm.ll -+++ b/compiler/testdata/intrinsics-wasm.ll -@@ -18,7 +18,7 @@ entry: - ret double %0 - } - --; Function Attrs: nounwind readnone speculatable willreturn -+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn - declare double @llvm.sqrt.f64(double) #1 - - ; Function Attrs: nounwind -@@ -28,8 +28,8 @@ entry: - ret double %0 - } - --; Function Attrs: nounwind readnone speculatable willreturn -+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn - declare double @llvm.trunc.f64(double) #1 - - attributes #0 = { nounwind } --attributes #1 = { nounwind readnone speculatable willreturn } -+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn } -diff --git a/go.mod b/go.mod -index 26a4b027..52dd71c3 100644 ---- a/go.mod -+++ b/go.mod -@@ -3,7 +3,7 @@ module github.com/tinygo-org/tinygo - go 1.15 - - require ( -- github.com/aykevl/go-wasm v0.0.2-0.20211030161413-11881cb9032d // indirect -+ github.com/aykevl/go-wasm v0.0.2-0.20211119014117-0761b1ddcd1a // indirect - github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 - github.com/chromedp/cdproto v0.0.0-20210113043257-dabd2f2e7693 - github.com/chromedp/chromedp v0.6.4 -@@ -13,5 +13,5 @@ require ( - go.bug.st/serial v1.1.3 - golang.org/x/sys v0.0.0-20210510120138-977fb7262007 - golang.org/x/tools v0.1.6-0.20210813165731-45389f592fe9 -- tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c -+ tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be - ) -diff --git a/go.sum b/go.sum -index 1daa9388..73697653 100644 ---- a/go.sum -+++ b/go.sum -@@ -1,5 +1,5 @@ --github.com/aykevl/go-wasm v0.0.2-0.20211030161413-11881cb9032d h1:JeuI5/546naK5hpOIX+Lq5xE8rvt7uwiTp6iL+pLQgk= --github.com/aykevl/go-wasm v0.0.2-0.20211030161413-11881cb9032d/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw= -+github.com/aykevl/go-wasm v0.0.2-0.20211119014117-0761b1ddcd1a h1:QPU7APo6y/6VkCDq6HU3WWIUzER8iywSac23+1UQv60= -+github.com/aykevl/go-wasm v0.0.2-0.20211119014117-0761b1ddcd1a/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw= - github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI= - github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI= - github.com/chromedp/cdproto v0.0.0-20210113043257-dabd2f2e7693 h1:11eq/RkpaotwdF6b1TRMcdgQUPNmyFEJOB7zLvh0O/Y= -@@ -68,7 +68,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/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-20210308112806-9ef958b6bed4 h1:CMUHxVTb+UuUePuMf8vkWjZ3gTp9BBK91KrgOCwoNHs= --tinygo.org/x/go-llvm v0.0.0-20210308112806-9ef958b6bed4/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= --tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c h1:vn9IPshzYmzZis10UEVrsIBRv9FpykADw6M3/tHHROg= --tinygo.org/x/go-llvm v0.0.0-20210325115028-e7b85195e81c/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= -+tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be h1:syIpWbi/yESuoyijF2nhRdgX4422sNfmij+o73B3+vU= -+tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= -diff --git a/interp/interp_test.go b/interp/interp_test.go -index 516fdd11..ae2635af 100644 ---- a/interp/interp_test.go -+++ b/interp/interp_test.go -@@ -71,6 +71,7 @@ func runTest(t *testing.T, pathPrefix string) { - defer pm.Dispose() - pm.AddGlobalOptimizerPass() - pm.AddDeadStoreEliminationPass() -+ pm.AddAggressiveDCEPass() - pm.Run(mod) - - // Read the expected output IR. -diff --git a/transform/maps_test.go b/transform/maps_test.go -index 1f821d4b..e8b11133 100644 ---- a/transform/maps_test.go -+++ b/transform/maps_test.go -@@ -18,6 +18,7 @@ func TestOptimizeMaps(t *testing.T) { - pm := llvm.NewPassManager() - defer pm.Dispose() - pm.AddDeadStoreEliminationPass() -+ pm.AddAggressiveDCEPass() - pm.Run(mod) - }) - } -diff --git a/transform/testdata/coroutines.out.ll b/transform/testdata/coroutines.out.ll -index d4a49a5e..de902884 100644 ---- a/transform/testdata/coroutines.out.ll -+++ b/transform/testdata/coroutines.out.ll -@@ -301,13 +301,13 @@ declare i8* @llvm.coro.free(token, i8* nocapture readonly) #0 - ; Function Attrs: nounwind - declare token @llvm.coro.save(i8*) #2 - --; Function Attrs: argmemonly nounwind willreturn -+; Function Attrs: argmemonly nofree nosync nounwind willreturn - declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #3 - --; Function Attrs: argmemonly nounwind willreturn -+; Function Attrs: argmemonly nofree nosync nounwind willreturn - declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #3 - - attributes #0 = { argmemonly nounwind readonly } - attributes #1 = { nounwind readnone } - attributes #2 = { nounwind } --attributes #3 = { argmemonly nounwind willreturn } -+attributes #3 = { argmemonly nofree nosync nounwind willreturn } -diff --git a/transform/transform_test.go b/transform/transform_test.go -index ae531eeb..935d660b 100644 ---- a/transform/transform_test.go -+++ b/transform/transform_test.go -@@ -116,8 +116,9 @@ func filterIrrelevantIRLines(lines []string) []string { - if strings.HasPrefix(line, "source_filename = ") { - continue - } -- if llvmVersion < 11 && strings.HasPrefix(line, "attributes ") { -+ if llvmVersion < 12 && strings.HasPrefix(line, "attributes ") { - // Ignore attribute groups. These may change between LLVM versions. -+ // Right now test outputs are for LLVM 12. - continue - } - out = append(out, line) --- -2.31.1 - diff --git a/0007-tests-improve-wasm-tests-slightly.patch b/0007-tests-improve-wasm-tests-slightly.patch deleted file mode 100644 index cbac6ae..0000000 --- a/0007-tests-improve-wasm-tests-slightly.patch +++ /dev/null @@ -1,262 +0,0 @@ -From f5ece39b3353ae389ab3da90163b6a49dda1d4aa Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sat, 20 Nov 2021 01:06:02 +0100 -Subject: [PATCH 7/9] tests: improve wasm tests slightly - -These wasm tests weren't passing in GitHub Actions and also weren't -passing on my laptop. I'm not sure why, I think there are a few race -conditions that are going on. - -This commit attempts to fix this at least to a degree: - - - The context deadline is increased from 5 seconds to 10 seconds. - - The tests are not running in parallel anymore. - - Some `Sleep` calls were removed, they do not appear to be necessary - (and if they were, sleeping is the wrong solution to solve race - conditions). - -Overall the tests are taking a few seconds more, but on the other hand -they seem to be passing more reliable. At least for me, on my laptop -(and hopefully also in CI). - -Signed-off-by: Elliott Sales de Andrade ---- - tests/wasm/chan_test.go | 7 ++----- - tests/wasm/event_test.go | 9 ++------- - tests/wasm/fmt_test.go | 8 ++------ - tests/wasm/fmtprint_test.go | 8 ++------ - tests/wasm/log_test.go | 8 ++------ - tests/wasm/setup_test.go | 13 ++++++------- - 6 files changed, 16 insertions(+), 37 deletions(-) - -diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go -index e44d7ebe..fe981974 100644 ---- a/tests/wasm/chan_test.go -+++ b/tests/wasm/chan_test.go -@@ -2,23 +2,20 @@ package wasm - - import ( - "testing" -- "time" - - "github.com/chromedp/chromedp" - ) - - func TestChan(t *testing.T) { - -- t.Parallel() -- - wasmTmpDir, server := startServer(t) - -- err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go") -+ err := run(t, "tinygo build -o "+wasmTmpDir+"/chan.wasm -target wasm testdata/chan.go") - if err != nil { - t.Fatal(err) - } - -- ctx, cancel := chromectx(5 * time.Second) -+ ctx, cancel := chromectx() - defer cancel() - - err = chromedp.Run(ctx, -diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go -index 038a500a..a29a01c7 100644 ---- a/tests/wasm/event_test.go -+++ b/tests/wasm/event_test.go -@@ -2,35 +2,30 @@ package wasm - - import ( - "testing" -- "time" - - "github.com/chromedp/chromedp" - ) - - func TestEvent(t *testing.T) { - -- t.Parallel() -- - wasmTmpDir, server := startServer(t) - -- err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go") -+ err := run(t, "tinygo build -o "+wasmTmpDir+"/event.wasm -target wasm testdata/event.go") - if err != nil { - t.Fatal(err) - } - -- ctx, cancel := chromectx(5 * time.Second) -+ ctx, cancel := chromectx() - defer cancel() - - var log1, log2 string - err = chromedp.Run(ctx, - chromedp.Navigate(server.URL+"/run?file=event.wasm"), - chromedp.WaitVisible("#log"), -- chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLog(`1 - 4`), - chromedp.Click("#testbtn"), -- chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log2), - waitLog(`1 - 4 -diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go -index f9f2f77b..d3695f07 100644 ---- a/tests/wasm/fmt_test.go -+++ b/tests/wasm/fmt_test.go -@@ -2,29 +2,25 @@ package wasm - - import ( - "testing" -- "time" - - "github.com/chromedp/chromedp" - ) - - func TestFmt(t *testing.T) { - -- t.Parallel() -- - wasmTmpDir, server := startServer(t) - -- err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go") -+ err := run(t, "tinygo build -o "+wasmTmpDir+"/fmt.wasm -target wasm testdata/fmt.go") - if err != nil { - t.Fatal(err) - } - -- ctx, cancel := chromectx(5 * time.Second) -+ ctx, cancel := chromectx() - defer cancel() - - var log1 string - err = chromedp.Run(ctx, - chromedp.Navigate(server.URL+"/run?file=fmt.wasm"), -- chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLog(`did not panic`), - ) -diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go -index 90825ba0..3c750239 100644 ---- a/tests/wasm/fmtprint_test.go -+++ b/tests/wasm/fmtprint_test.go -@@ -2,29 +2,25 @@ package wasm - - import ( - "testing" -- "time" - - "github.com/chromedp/chromedp" - ) - - func TestFmtprint(t *testing.T) { - -- t.Parallel() -- - wasmTmpDir, server := startServer(t) - -- err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go") -+ err := run(t, "tinygo build -o "+wasmTmpDir+"/fmtprint.wasm -target wasm testdata/fmtprint.go") - if err != nil { - t.Fatal(err) - } - -- ctx, cancel := chromectx(5 * time.Second) -+ ctx, cancel := chromectx() - defer cancel() - - var log1 string - err = chromedp.Run(ctx, - chromedp.Navigate(server.URL+"/run?file=fmtprint.wasm"), -- chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLog(`test from fmtprint 1 - test from fmtprint 2 -diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go -index fae4c670..1f6c79fe 100644 ---- a/tests/wasm/log_test.go -+++ b/tests/wasm/log_test.go -@@ -2,29 +2,25 @@ package wasm - - import ( - "testing" -- "time" - - "github.com/chromedp/chromedp" - ) - - func TestLog(t *testing.T) { - -- t.Parallel() -- - wasmTmpDir, server := startServer(t) - -- err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go") -+ err := run(t, "tinygo build -o "+wasmTmpDir+"/log.wasm -target wasm testdata/log.go") - if err != nil { - t.Fatal(err) - } - -- ctx, cancel := chromectx(5 * time.Second) -+ ctx, cancel := chromectx() - defer cancel() - - var log1 string - err = chromedp.Run(ctx, - chromedp.Navigate(server.URL+"/run?file=log.wasm"), -- chromedp.Sleep(time.Second), - chromedp.InnerHTML("#log", &log1), - waitLogRe(`^..../../.. ..:..:.. log 1 - ..../../.. ..:..:.. log 2 -diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go -index 0071076c..e5a18daf 100644 ---- a/tests/wasm/setup_test.go -+++ b/tests/wasm/setup_test.go -@@ -4,7 +4,6 @@ import ( - "context" - "errors" - "fmt" -- "log" - "net/http" - "net/http/httptest" - "os/exec" -@@ -18,29 +17,29 @@ import ( - "github.com/chromedp/chromedp" - ) - --func run(cmdline string) error { -+func run(t *testing.T, cmdline string) error { - args := strings.Fields(cmdline) -- return runargs(args...) -+ return runargs(t, args...) - } - --func runargs(args ...string) error { -+func runargs(t *testing.T, args ...string) error { - cmd := exec.Command(args[0], args[1:]...) - b, err := cmd.CombinedOutput() -- log.Printf("Command: %s; err=%v; full output:\n%s", strings.Join(args, " "), err, b) -+ t.Logf("Command: %s; err=%v; full output:\n%s", strings.Join(args, " "), err, b) - if err != nil { - return err - } - return nil - } - --func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) { -+func chromectx() (context.Context, context.CancelFunc) { - - var ctx context.Context - - // looks for locally installed Chrome - ctx, _ = chromedp.NewContext(context.Background()) - -- ctx, cancel := context.WithTimeout(ctx, timeout) -+ ctx, cancel := context.WithTimeout(ctx, 10*time.Second) - - return ctx, cancel - } --- -2.31.1 - diff --git a/0008-internal-task-swap-stack-chain-when-switching-gorout.patch b/0008-internal-task-swap-stack-chain-when-switching-gorout.patch deleted file mode 100644 index 5cbdbd8..0000000 --- a/0008-internal-task-swap-stack-chain-when-switching-gorout.patch +++ /dev/null @@ -1,195 +0,0 @@ -From 1349a7cfc72b3ed0ee6f6d529b8f57ca7d419ecc Mon Sep 17 00:00:00 2001 -From: Nia Waldvogel -Date: Tue, 14 Dec 2021 16:48:11 -0500 -Subject: [PATCH 8/9] internal/task: swap stack chain when switching goroutines - -This change swaps the stack chain when switching goroutines, ensuring that the chain is maintained consistently. -This is only really currently necessary with asyncify on wasm. - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/testdata/channel.ll | 3 ++- - .../testdata/goroutine-cortex-m-qemu-tasks.ll | 3 ++- - compiler/testdata/goroutine-wasm-asyncify.ll | 3 ++- - .../testdata/goroutine-wasm-coroutines.ll | 3 ++- - src/internal/task/gc_stack_chain.go | 19 +++++++++++++++++++ - src/internal/task/gc_stack_noop.go | 9 +++++++++ - src/internal/task/task.go | 3 +++ - src/internal/task/task_asyncify.go | 2 ++ - src/internal/task/task_stack.go | 3 +++ - src/runtime/gc_stack_portable.go | 7 +++++++ - 10 files changed, 51 insertions(+), 4 deletions(-) - create mode 100644 src/internal/task/gc_stack_chain.go - create mode 100644 src/internal/task/gc_stack_noop.go - -diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index 36d7fd96..3f4d5235 100644 ---- a/compiler/testdata/channel.ll -+++ b/compiler/testdata/channel.ll -@@ -5,7 +5,8 @@ target triple = "wasm32-unknown-wasi" - - %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } - %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } -+%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } -+%"internal/task.gcData" = type { i8* } - %"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } - %"internal/task.stackState" = type { i32, i32 } - %runtime.chanSelectState = type { %runtime.channel*, i8* } -diff --git a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll -index d34a1eb4..6224f256 100644 ---- a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll -+++ b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll -@@ -5,7 +5,8 @@ target triple = "thumbv7m-unknown-unknown-eabi" - - %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } - %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } -+%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } -+%"internal/task.gcData" = type {} - %"internal/task.state" = type { i32, i32* } - %runtime.chanSelectState = type { %runtime.channel*, i8* } - -diff --git a/compiler/testdata/goroutine-wasm-asyncify.ll b/compiler/testdata/goroutine-wasm-asyncify.ll -index 1ecf0c79..70ec4ef4 100644 ---- a/compiler/testdata/goroutine-wasm-asyncify.ll -+++ b/compiler/testdata/goroutine-wasm-asyncify.ll -@@ -5,7 +5,8 @@ target triple = "wasm32-unknown-wasi" - - %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } - %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } -+%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } -+%"internal/task.gcData" = type { i8* } - %"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } - %"internal/task.stackState" = type { i32, i32 } - %runtime.chanSelectState = type { %runtime.channel*, i8* } -diff --git a/compiler/testdata/goroutine-wasm-coroutines.ll b/compiler/testdata/goroutine-wasm-coroutines.ll -index 6f308247..a0c42991 100644 ---- a/compiler/testdata/goroutine-wasm-coroutines.ll -+++ b/compiler/testdata/goroutine-wasm-coroutines.ll -@@ -6,7 +6,8 @@ target triple = "wasm32-unknown-wasi" - %runtime.funcValueWithSignature = type { i32, i8* } - %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } - %runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.state" } -+%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state" } -+%"internal/task.gcData" = type {} - %"internal/task.state" = type { i8* } - %runtime.chanSelectState = type { %runtime.channel*, i8* } - -diff --git a/src/internal/task/gc_stack_chain.go b/src/internal/task/gc_stack_chain.go -new file mode 100644 -index 00000000..d3e400d3 ---- /dev/null -+++ b/src/internal/task/gc_stack_chain.go -@@ -0,0 +1,19 @@ -+//go:build (gc.conservative || gc.extalloc) && tinygo.wasm && !scheduler.coroutines -+// +build gc.conservative gc.extalloc -+// +build tinygo.wasm -+// +build !scheduler.coroutines -+ -+package task -+ -+import "unsafe" -+ -+//go:linkname swapStackChain runtime.swapStackChain -+func swapStackChain(dst *unsafe.Pointer) -+ -+type gcData struct { -+ stackChain unsafe.Pointer -+} -+ -+func (gcd *gcData) swap() { -+ swapStackChain(&gcd.stackChain) -+} -diff --git a/src/internal/task/gc_stack_noop.go b/src/internal/task/gc_stack_noop.go -new file mode 100644 -index 00000000..63674805 ---- /dev/null -+++ b/src/internal/task/gc_stack_noop.go -@@ -0,0 +1,9 @@ -+//go:build (!gc.conservative && !gc.extalloc) || !tinygo.wasm || scheduler.coroutines -+// +build !gc.conservative,!gc.extalloc !tinygo.wasm scheduler.coroutines -+ -+package task -+ -+type gcData struct{} -+ -+func (gcd *gcData) swap() { -+} -diff --git a/src/internal/task/task.go b/src/internal/task/task.go -index bad501b6..b490a202 100644 ---- a/src/internal/task/task.go -+++ b/src/internal/task/task.go -@@ -15,6 +15,9 @@ type Task struct { - // Data is a field which can be used for storing state information. - Data uint64 - -+ // gcData holds data for the GC. -+ gcData gcData -+ - // state is the underlying running state of the task. - state state - } -diff --git a/src/internal/task/task_asyncify.go b/src/internal/task/task_asyncify.go -index d67f0e1c..939008bc 100644 ---- a/src/internal/task/task_asyncify.go -+++ b/src/internal/task/task_asyncify.go -@@ -104,6 +104,7 @@ func (*stackState) unwind() - func (t *Task) Resume() { - // The current task must be saved and restored because this can nest on WASM with JS. - prevTask := currentTask -+ t.gcData.swap() - currentTask = t - if !t.state.launched { - t.state.launch() -@@ -112,6 +113,7 @@ func (t *Task) Resume() { - t.state.rewind() - } - currentTask = prevTask -+ t.gcData.swap() - if t.state.asyncifysp > t.state.csp { - runtimePanic("stack overflow") - } -diff --git a/src/internal/task/task_stack.go b/src/internal/task/task_stack.go -index a703d10a..59af6503 100644 ---- a/src/internal/task/task_stack.go -+++ b/src/internal/task/task_stack.go -@@ -1,3 +1,4 @@ -+//go:build scheduler.tasks - // +build scheduler.tasks - - package task -@@ -54,7 +55,9 @@ func pause() { - // This may only be called from the scheduler. - func (t *Task) Resume() { - currentTask = t -+ t.gcData.swap() - t.state.resume() -+ t.gcData.swap() - currentTask = nil - } - -diff --git a/src/runtime/gc_stack_portable.go b/src/runtime/gc_stack_portable.go -index d4a04637..1cdd31f3 100644 ---- a/src/runtime/gc_stack_portable.go -+++ b/src/runtime/gc_stack_portable.go -@@ -1,3 +1,4 @@ -+//go:build (gc.conservative || gc.extalloc) && tinygo.wasm - // +build gc.conservative gc.extalloc - // +build tinygo.wasm - -@@ -37,3 +38,9 @@ func markStack() { - // construction. Calls to it are later replaced with regular stack bookkeeping - // code. - func trackPointer(ptr unsafe.Pointer) -+ -+// swapStackChain swaps the stack chain. -+// This is called from internal/task when switching goroutines. -+func swapStackChain(dst **stackChainObject) { -+ *dst, stackChainStart = stackChainStart, *dst -+} --- -2.31.1 - diff --git a/0009-all-switch-to-LLVM-13.patch b/0009-all-switch-to-LLVM-13.patch deleted file mode 100644 index 1f9d50a..0000000 --- a/0009-all-switch-to-LLVM-13.patch +++ /dev/null @@ -1,960 +0,0 @@ -From b88f3a8bac4ee3daf56bb1a1dda3211974251043 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 9 Dec 2021 02:52:08 +0100 -Subject: [PATCH 9/9] all: switch to LLVM 13 - -This adds support for building with `-tags=llvm13` and switches to LLVM -13 for tinygo binaries that are statically linked against LLVM. - -Some notes on this commit: - - * Added `-mfloat-abi=soft` to all Cortex-M targets because otherwise - nrfx would complain that floating point was enabled on Cortex-M0. - That's not the case, but with `-mfloat-abi=soft` the `__SOFTFP__` - macro is defined which silences this warning. - See: https://reviews.llvm.org/D100372 - * Changed from `--sysroot=` to `-nostdlib -isystem ` for - musl because with Clang 13, even with `--sysroot` some system - libraries are used which we don't want. - * Changed all `-Xclang -internal-isystem -Xclang` to simply - `-isystem`, for consistency with the above change. It appears to - have the same effect. - * Moved WebAssembly function declarations to the top of the file in - task_asyncify_wasm.S because (apparently) the assembler has become - more strict. - -Signed-off-by: Elliott Sales de Andrade ---- - .circleci/config.yml | 12 +-- - .github/workflows/windows.yml | 4 +- - Makefile | 8 +- - builder/cc1as.cpp | 79 ++++++++++--------- - builder/cc1as.h | 2 + - builder/picolibc.go | 2 +- - cgo/libclang_config.go | 2 +- - cgo/libclang_config_llvm13.go | 14 ++++ - compileopts/config.go | 13 +-- - compileopts/target.go | 6 +- - compiler/compiler_test.go | 7 +- - compiler/inlineasm.go | 16 ++-- - compiler/syscall.go | 8 +- - compiler/testdata/basic.ll | 2 +- - compiler/testdata/channel.ll | 2 +- - compiler/testdata/float.ll | 2 +- - compiler/testdata/func-coroutines.ll | 2 +- - compiler/testdata/gc.ll | 2 +- - compiler/testdata/go1.17.ll | 2 +- - compiler/testdata/goroutine-wasm-asyncify.ll | 2 +- - .../testdata/goroutine-wasm-coroutines.ll | 2 +- - compiler/testdata/interface.ll | 2 +- - compiler/testdata/intrinsics-wasm.ll | 2 +- - compiler/testdata/pointer.ll | 2 +- - compiler/testdata/pragma.ll | 2 +- - compiler/testdata/slice.ll | 2 +- - compiler/testdata/string.ll | 2 +- - go.mod | 2 +- - go.sum | 4 +- - loader/loader.go | 2 +- - src/internal/task/task_asyncify_wasm.S | 18 ++--- - targets/cortex-m.json | 1 + - targets/cortex-m0.json | 2 +- - targets/cortex-m0plus.json | 2 +- - targets/cortex-m3.json | 2 +- - targets/cortex-m33.json | 5 +- - targets/cortex-m4.json | 5 +- - targets/cortex-m7.json | 5 +- - targets/gameboy-advance.json | 2 +- - targets/k210.json | 2 +- - transform/optimizer.go | 1 + - 41 files changed, 137 insertions(+), 117 deletions(-) - create mode 100644 cgo/libclang_config_llvm13.go - -diff --git a/.circleci/config.yml b/.circleci/config.yml -index 50bdd087..8005a7bb 100644 ---- a/.circleci/config.yml -+++ b/.circleci/config.yml -@@ -52,12 +52,12 @@ commands: - steps: - - restore_cache: - keys: -- - llvm-source-12-v1 -+ - llvm-source-13-v1 - - run: - name: "Fetch LLVM source" - command: make llvm-source - - save_cache: -- key: llvm-source-12-v1 -+ key: llvm-source-13-v1 - paths: - - llvm-project/clang/lib/Headers - - llvm-project/clang/include -@@ -332,12 +332,12 @@ commands: - - go-cache-macos-v3-{{ checksum "go.mod" }} - - restore_cache: - keys: -- - llvm-source-12-macos-v1 -+ - llvm-source-13-macos-v1 - - run: - name: "Fetch LLVM source" - command: make llvm-source - - save_cache: -- key: llvm-source-12-macos-v1 -+ key: llvm-source-13-macos-v1 - paths: - - llvm-project/clang/lib/Headers - - llvm-project/clang/include -@@ -345,7 +345,7 @@ commands: - - llvm-project/llvm/include - - restore_cache: - keys: -- - llvm-build-12-macos-v1 -+ - llvm-build-13-macos-v1 - - run: - name: "Build LLVM" - command: | -@@ -359,7 +359,7 @@ commands: - find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; - fi - - save_cache: -- key: llvm-build-12-macos-v1 -+ key: llvm-build-13-macos-v1 - paths: - llvm-build - - restore_cache: -diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml -index 8649f635..4aa92532 100644 ---- a/.github/workflows/windows.yml -+++ b/.github/workflows/windows.yml -@@ -27,7 +27,7 @@ jobs: - uses: actions/cache@v2 - id: cache-llvm-source - with: -- key: llvm-source-12-windows-v1 -+ key: llvm-source-13-windows-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -40,7 +40,7 @@ jobs: - uses: actions/cache@v2 - id: cache-llvm-build - with: -- key: llvm-build-12-windows-v1 -+ key: llvm-build-13-windows-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -diff --git a/Makefile b/Makefile -index 0ebfcd82..987376f4 100644 ---- a/Makefile -+++ b/Makefile -@@ -10,9 +10,9 @@ LLD_SRC ?= $(LLVM_PROJECTDIR)/lld - - # Try to autodetect LLVM build tools. - detect = $(shell command -v $(1) 2> /dev/null && echo $(1)) --CLANG ?= $(word 1,$(abspath $(call detect,llvm-build/bin/clang))$(call detect,clang-11)$(call detect,clang)) --LLVM_AR ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-ar))$(call detect,llvm-ar-11)$(call detect,llvm-ar)) --LLVM_NM ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-nm))$(call detect,llvm-nm-11)$(call detect,llvm-nm)) -+CLANG ?= $(word 1,$(abspath $(call detect,llvm-build/bin/clang))$(call detect,clang-13)$(call detect,clang-12)$(call detect,clang-11)$(call detect,clang)) -+LLVM_AR ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-ar))$(call detect,llvm-ar-13)$(call detect,llvm-ar-12)$(call detect,llvm-ar-11)$(call detect,llvm-ar)) -+LLVM_NM ?= $(word 1,$(abspath $(call detect,llvm-build/bin/llvm-nm))$(call detect,llvm-nm-13)$(call detect,llvm-nm-12)$(call detect,llvm-nm-11)$(call detect,llvm-nm)) - - # Go binary and GOROOT to select - GO ?= go -@@ -160,7 +160,7 @@ gen-device-rp: build/gen-device-svd - - # Get LLVM sources. - $(LLVM_PROJECTDIR)/llvm: -- git clone -b xtensa_release_12.0.1 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) -+ git clone -b xtensa_release_13.0.0 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) - llvm-source: $(LLVM_PROJECTDIR)/llvm - - # Configure LLVM. -diff --git a/builder/cc1as.cpp b/builder/cc1as.cpp -index 2553e0e2..ece54124 100644 ---- a/builder/cc1as.cpp -+++ b/builder/cc1as.cpp -@@ -115,29 +115,26 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, - // Any DebugInfoKind implies GenDwarfForAssembly. - Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ); - -- if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections, -- OPT_compress_debug_sections_EQ)) { -- if (A->getOption().getID() == OPT_compress_debug_sections) { -- // TODO: be more clever about the compression type auto-detection -- Opts.CompressDebugSections = llvm::DebugCompressionType::GNU; -- } else { -- Opts.CompressDebugSections = -- llvm::StringSwitch(A->getValue()) -- .Case("none", llvm::DebugCompressionType::None) -- .Case("zlib", llvm::DebugCompressionType::Z) -- .Case("zlib-gnu", llvm::DebugCompressionType::GNU) -- .Default(llvm::DebugCompressionType::None); -- } -+ if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections_EQ)) { -+ Opts.CompressDebugSections = -+ llvm::StringSwitch(A->getValue()) -+ .Case("none", llvm::DebugCompressionType::None) -+ .Case("zlib", llvm::DebugCompressionType::Z) -+ .Case("zlib-gnu", llvm::DebugCompressionType::GNU) -+ .Default(llvm::DebugCompressionType::None); - } - - Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations); -+ if (auto *DwarfFormatArg = Args.getLastArg(OPT_gdwarf64, OPT_gdwarf32)) -+ Opts.Dwarf64 = DwarfFormatArg->getOption().matches(OPT_gdwarf64); - Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags); - Opts.DwarfDebugFlags = - std::string(Args.getLastArgValue(OPT_dwarf_debug_flags)); - Opts.DwarfDebugProducer = - std::string(Args.getLastArgValue(OPT_dwarf_debug_producer)); -- Opts.DebugCompilationDir = -- std::string(Args.getLastArgValue(OPT_fdebug_compilation_dir)); -+ if (const Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, -+ options::OPT_fdebug_compilation_dir_EQ)) -+ Opts.DebugCompilationDir = A->getValue(); - Opts.MainFileName = std::string(Args.getLastArgValue(OPT_main_file_name)); - - for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) { -@@ -219,7 +216,7 @@ getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) { - - std::error_code EC; - auto Out = std::make_unique( -- Path, EC, (Binary ? sys::fs::OF_None : sys::fs::OF_Text)); -+ Path, EC, (Binary ? sys::fs::OF_None : sys::fs::OF_TextWithCRLF)); - if (EC) { - Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message(); - return nullptr; -@@ -228,7 +225,8 @@ getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) { - return Out; - } - --bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { -+static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, -+ DiagnosticsEngine &Diags) { - // Get the target specific parser. - std::string Error; - const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error); -@@ -236,7 +234,7 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; - - ErrorOr> Buffer = -- MemoryBuffer::getFileOrSTDIN(Opts.InputFile); -+ MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); - - if (std::error_code EC = Buffer.getError()) { - Error = EC.message(); -@@ -277,11 +275,15 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - if (!Opts.SplitDwarfOutput.empty()) - DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary); - -- // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and -- // MCObjectFileInfo needs a MCContext reference in order to initialize itself. -- std::unique_ptr MOFI(new MCObjectFileInfo()); -+ // Build up the feature string from the target feature list. -+ std::string FS = llvm::join(Opts.Features, ","); - -- MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr, &MCOptions); -+ std::unique_ptr STI( -+ TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); -+ assert(STI && "Unable to create subtarget info!"); -+ -+ MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr, -+ &MCOptions); - - bool PIC = false; - if (Opts.RelocationModel == "static") { -@@ -294,7 +296,12 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - PIC = false; - } - -- MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, Ctx); -+ // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and -+ // MCObjectFileInfo needs a MCContext reference in order to initialize itself. -+ std::unique_ptr MOFI( -+ TheTarget->createMCObjectFileInfo(Ctx, PIC)); -+ Ctx.setObjectFileInfo(MOFI.get()); -+ - if (Opts.SaveTemporaryLabels) - Ctx.setAllowTemporaryLabels(false); - if (Opts.GenDwarfForAssembly) -@@ -316,19 +323,16 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - Ctx.addDebugPrefixMapEntry(KV.first, KV.second); - if (!Opts.MainFileName.empty()) - Ctx.setMainFileName(StringRef(Opts.MainFileName)); -+ Ctx.setDwarfFormat(Opts.Dwarf64 ? dwarf::DWARF64 : dwarf::DWARF32); - Ctx.setDwarfVersion(Opts.DwarfVersion); - if (Opts.GenDwarfForAssembly) - Ctx.setGenDwarfRootFile(Opts.InputFile, - SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer()); - -- // Build up the feature string from the target feature list. -- std::string FS = llvm::join(Opts.Features, ","); -- - std::unique_ptr Str; - - std::unique_ptr MCII(TheTarget->createMCInstrInfo()); -- std::unique_ptr STI( -- TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); -+ assert(MCII && "Unable to create instruction info!"); - - raw_pwrite_stream *Out = FDOS.get(); - std::unique_ptr BOS; -@@ -367,6 +371,8 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); - std::unique_ptr MAB( - TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); -+ assert(MAB && "Unable to create asm backend!"); -+ - std::unique_ptr OW = - DwoOS ? MAB->createDwoObjectWriter(*Out, *DwoOS) - : MAB->createObjectWriter(*Out); -@@ -381,8 +387,7 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - - // When -fembed-bitcode is passed to clang_as, a 1-byte marker - // is emitted in __LLVM,__asm section if the object file is MachO format. -- if (Opts.EmbedBitcode && Ctx.getObjectFileInfo()->getObjectFileType() == -- MCObjectFileInfo::IsMachO) { -+ if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) { - MCSection *AsmLabel = Ctx.getMachOSection( - "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); - Str.get()->SwitchSection(AsmLabel); -@@ -419,12 +424,12 @@ bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) { - Failed = Parser->Run(Opts.NoInitialTextSection); - } - -- // Close Streamer first. -- // It might have a reference to the output stream. -- Str.reset(); -- // Close the output stream early. -- BOS.reset(); -- FDOS.reset(); -+ return Failed; -+} -+ -+bool ExecuteAssembler(AssemblerInvocation &Opts, -+ DiagnosticsEngine &Diags) { -+ bool Failed = ExecuteAssemblerImpl(Opts, Diags); - - // Delete output file if there were errors. - if (Failed) { -@@ -472,7 +477,7 @@ int cc1as_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { - return 1; - - if (Asm.ShowHelp) { -- getDriverOptTable().PrintHelp( -+ getDriverOptTable().printHelp( - llvm::outs(), "clang -cc1as [options] file...", - "Clang Integrated Assembler", - /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0, -diff --git a/builder/cc1as.h b/builder/cc1as.h -index ce9a1781..538e9a26 100644 ---- a/builder/cc1as.h -+++ b/builder/cc1as.h -@@ -39,6 +39,7 @@ struct AssemblerInvocation { - unsigned SaveTemporaryLabels : 1; - unsigned GenDwarfForAssembly : 1; - unsigned RelaxELFRelocations : 1; -+ unsigned Dwarf64 : 1; - unsigned DwarfVersion; - std::string DwarfDebugFlags; - std::string DwarfDebugProducer; -@@ -108,6 +109,7 @@ public: - FatalWarnings = 0; - NoWarn = 0; - IncrementalLinkerCompatible = 0; -+ Dwarf64 = 0; - DwarfVersion = 0; - EmbedBitcode = 0; - } -diff --git a/builder/picolibc.go b/builder/picolibc.go -index 75c93e91..af34f7ef 100644 ---- a/builder/picolibc.go -+++ b/builder/picolibc.go -@@ -28,7 +28,7 @@ var Picolibc = Library{ - "-DHAVE_ALIAS_ATTRIBUTE", - "-DTINY_STDIO", - "-nostdlibinc", -- "-Xclang", "-internal-isystem", "-Xclang", picolibcDir + "/include", -+ "-isystem", picolibcDir + "/include", - "-I" + picolibcDir + "/tinystdio", - "-I" + headerPath, - } -diff --git a/cgo/libclang_config.go b/cgo/libclang_config.go -index 9f7cdc1c..ed929f79 100644 ---- a/cgo/libclang_config.go -+++ b/cgo/libclang_config.go -@@ -1,5 +1,5 @@ - // +build !byollvm --// +build !llvm12 -+// +build !llvm12,!llvm13 - - package cgo - -diff --git a/cgo/libclang_config_llvm13.go b/cgo/libclang_config_llvm13.go -new file mode 100644 -index 00000000..3c961a3f ---- /dev/null -+++ b/cgo/libclang_config_llvm13.go -@@ -0,0 +1,14 @@ -+// +build !byollvm -+// +build llvm13 -+ -+package cgo -+ -+/* -+#cgo linux CFLAGS: -I/usr/lib/llvm-13/include -+#cgo darwin CFLAGS: -I/usr/local/opt/llvm@13/include -+#cgo freebsd CFLAGS: -I/usr/local/llvm13/include -+#cgo linux LDFLAGS: -L/usr/lib/llvm-13/lib -lclang -+#cgo darwin LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi -+#cgo freebsd LDFLAGS: -L/usr/local/llvm13/lib -lclang -+*/ -+import "C" -diff --git a/compileopts/config.go b/compileopts/config.go -index 1f54e157..6dc44c79 100644 ---- a/compileopts/config.go -+++ b/compileopts/config.go -@@ -257,17 +257,18 @@ func (c *Config) CFlags() []string { - path, _ := c.LibcPath("picolibc") - cflags = append(cflags, - "--sysroot="+path, -- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "include"), -- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "tinystdio"), -+ "-isystem", filepath.Join(picolibcDir, "include"), -+ "-isystem", filepath.Join(picolibcDir, "tinystdio"), - ) - case "musl": - root := goenv.Get("TINYGOROOT") - path, _ := c.LibcPath("musl") - arch := MuslArchitecture(c.Triple()) - cflags = append(cflags, -- "--sysroot="+path, -- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "musl", "arch", arch), -- "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "musl", "include"), -+ "-nostdlibinc", -+ "-isystem", filepath.Join(path, "include"), -+ "-isystem", filepath.Join(root, "lib", "musl", "arch", arch), -+ "-isystem", filepath.Join(root, "lib", "musl", "include"), - ) - case "wasi-libc": - root := goenv.Get("TINYGOROOT") -@@ -275,7 +276,7 @@ func (c *Config) CFlags() []string { - case "mingw-w64": - cflags = append(cflags, - "--sysroot=/usr/x86_64-w64-mingw32/sys-root", -- "-Xclang", "-internal-isystem", "-Xclang", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", -+ "-isystem", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", - "-D_UCRT", - ) - case "": -diff --git a/compileopts/target.go b/compileopts/target.go -index 57b5bd84..ffdf7365 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -261,11 +261,11 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - spec.CFlags = append(spec.CFlags, "-fno-unwind-tables") - switch strings.Split(triple, "-")[0] { - case "armv5": -- spec.Features = "+armv5t,+strict-align,-thumb-mode" -+ spec.Features = "+armv5t,+strict-align,-aes,-bf16,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-mve.fp,-neon,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - case "armv6": -- spec.Features = "+armv6,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-thumb-mode" -+ spec.Features = "+armv6,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-aes,-d32,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fullfp16,-neon,-sha2,-thumb-mode,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - case "armv7": -- spec.Features = "+armv7-a,+d32,+dsp,+fp64,+neon,+vfp2,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,-thumb-mode" -+ spec.Features = "+armv7-a,+d32,+dsp,+fp64,+neon,+vfp2,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,-aes,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fullfp16,-sha2,-thumb-mode,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - } - case "arm64": - spec.CPU = "generic" -diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index 3c978274..65a1c626 100644 ---- a/compiler/compiler_test.go -+++ b/compiler/compiler_test.go -@@ -224,7 +224,12 @@ func filterIrrelevantIRLines(lines []string) []string { - } - if llvmVersion < 12 && strings.HasPrefix(line, "attributes ") { - // Ignore attribute groups. These may change between LLVM versions. -- // Right now test outputs are for LLVM 12. -+ // Right now test outputs are for LLVM 12 and higher. -+ continue -+ } -+ if llvmVersion < 13 && strings.HasPrefix(line, "target datalayout = ") { -+ // The datalayout string may vary betewen LLVM versions. -+ // Right now test outputs are for LLVM 13 and higher. - continue - } - out = append(out, line) -diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go -index e32a4f39..635aed98 100644 ---- a/compiler/inlineasm.go -+++ b/compiler/inlineasm.go -@@ -24,7 +24,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { - // Magic function: insert inline assembly instead of calling it. - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{}, false) - asm := constant.StringVal(args[0].(*ssa.Const).Value) -- target := llvm.InlineAsm(fnType, asm, "", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "", true, false, 0, false) - return b.CreateCall(target, nil, ""), nil - } - -@@ -116,7 +116,7 @@ func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) - outputType = b.ctx.VoidType() - } - fnType := llvm.FunctionType(outputType, argTypes, false) -- target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0) -+ target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0, false) - result := b.CreateCall(target, args, "") - if hasOutput { - return result, nil -@@ -159,7 +159,7 @@ func (b *builder) emitSVCall(args []ssa.Value) (llvm.Value, error) { - // marked as clobbered. - constraints += ",~{r1},~{r2},~{r3}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) - return b.CreateCall(target, llvmArgs, ""), nil - } - -@@ -197,7 +197,7 @@ func (b *builder) emitSV64Call(args []ssa.Value) (llvm.Value, error) { - // marked as clobbered. - constraints += ",~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) - return b.CreateCall(target, llvmArgs, ""), nil - } - -@@ -222,24 +222,24 @@ func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error) { - // marked as such. - fnType := llvm.FunctionType(b.uintptrType, nil, false) - asm := fmt.Sprintf("csrr $0, %d", csr) -- target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0, false) - return b.CreateCall(target, nil, ""), nil - case "Set": - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrw %d, $0", csr) -- target := llvm.InlineAsm(fnType, asm, "r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "r", true, false, 0, false) - return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - case "SetBits": - // Note: it may be possible to optimize this to csrrsi in many cases. - fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrrs $0, %d, $1", csr) -- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) - return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - case "ClearBits": - // Note: it may be possible to optimize this to csrrci in many cases. - fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrrc $0, %d, $1", csr) -- target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0) -+ target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) - return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - default: - return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) -diff --git a/compiler/syscall.go b/compiler/syscall.go -index db379d52..37330684 100644 ---- a/compiler/syscall.go -+++ b/compiler/syscall.go -@@ -56,7 +56,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - } - constraints += ",~{rcx},~{r11}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel) -+ target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false) - return b.CreateCall(target, args, ""), nil - case b.GOARCH == "386" && b.GOOS == "linux": - // Sources: -@@ -82,7 +82,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - argTypes = append(argTypes, llvmValue.Type()) - } - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel) -+ target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false) - return b.CreateCall(target, args, ""), nil - case b.GOARCH == "arm" && b.GOOS == "linux": - // Implement the EABI system call convention for Linux. -@@ -114,7 +114,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - constraints += ",~{r" + strconv.Itoa(i) + "}" - } - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) - return b.CreateCall(target, args, ""), nil - case b.GOARCH == "arm64" && b.GOOS == "linux": - // Source: syscall(2) man page. -@@ -146,7 +146,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - } - constraints += ",~{x16},~{x17}" // scratch registers - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) -- target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0) -+ target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) - return b.CreateCall(target, args, ""), nil - default: - return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH) -diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll -index 56baf3a7..69b72f27 100644 ---- a/compiler/testdata/basic.ll -+++ b/compiler/testdata/basic.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'basic.go' - source_filename = "basic.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %main.kv = type { float } -diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index 3f4d5235..fa80db5d 100644 ---- a/compiler/testdata/channel.ll -+++ b/compiler/testdata/channel.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'channel.go' - source_filename = "channel.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } -diff --git a/compiler/testdata/float.ll b/compiler/testdata/float.ll -index c6964058..e96f8cd7 100644 ---- a/compiler/testdata/float.ll -+++ b/compiler/testdata/float.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'float.go' - source_filename = "float.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) -diff --git a/compiler/testdata/func-coroutines.ll b/compiler/testdata/func-coroutines.ll -index eeefa43c..b88ce514 100644 ---- a/compiler/testdata/func-coroutines.ll -+++ b/compiler/testdata/func-coroutines.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'func.go' - source_filename = "func.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime.funcValueWithSignature = type { i32, i8* } -diff --git a/compiler/testdata/gc.ll b/compiler/testdata/gc.ll -index 375763f3..90e6b6e8 100644 ---- a/compiler/testdata/gc.ll -+++ b/compiler/testdata/gc.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'gc.go' - source_filename = "gc.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } -diff --git a/compiler/testdata/go1.17.ll b/compiler/testdata/go1.17.ll -index 5c26166a..1499547f 100644 ---- a/compiler/testdata/go1.17.ll -+++ b/compiler/testdata/go1.17.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'go1.17.go' - source_filename = "go1.17.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) -diff --git a/compiler/testdata/goroutine-wasm-asyncify.ll b/compiler/testdata/goroutine-wasm-asyncify.ll -index 70ec4ef4..0220bd5b 100644 ---- a/compiler/testdata/goroutine-wasm-asyncify.ll -+++ b/compiler/testdata/goroutine-wasm-asyncify.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'goroutine.go' - source_filename = "goroutine.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } -diff --git a/compiler/testdata/goroutine-wasm-coroutines.ll b/compiler/testdata/goroutine-wasm-coroutines.ll -index a0c42991..fe7b89b5 100644 ---- a/compiler/testdata/goroutine-wasm-coroutines.ll -+++ b/compiler/testdata/goroutine-wasm-coroutines.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'goroutine.go' - source_filename = "goroutine.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime.funcValueWithSignature = type { i32, i8* } -diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll -index f5afb0f3..c27142ec 100644 ---- a/compiler/testdata/interface.ll -+++ b/compiler/testdata/interface.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'interface.go' - source_filename = "interface.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } -diff --git a/compiler/testdata/intrinsics-wasm.ll b/compiler/testdata/intrinsics-wasm.ll -index 9e6687d5..ce20dfd0 100644 ---- a/compiler/testdata/intrinsics-wasm.ll -+++ b/compiler/testdata/intrinsics-wasm.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'intrinsics.go' - source_filename = "intrinsics.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) -diff --git a/compiler/testdata/pointer.ll b/compiler/testdata/pointer.ll -index 4072816b..7020c0fa 100644 ---- a/compiler/testdata/pointer.ll -+++ b/compiler/testdata/pointer.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'pointer.go' - source_filename = "pointer.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) -diff --git a/compiler/testdata/pragma.ll b/compiler/testdata/pragma.ll -index 31fe6236..943b574d 100644 ---- a/compiler/testdata/pragma.ll -+++ b/compiler/testdata/pragma.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'pragma.go' - source_filename = "pragma.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - @extern_global = external global [0 x i8], align 1 -diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll -index 847d29fb..0cca8970 100644 ---- a/compiler/testdata/slice.ll -+++ b/compiler/testdata/slice.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'slice.go' - source_filename = "slice.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) -diff --git a/compiler/testdata/string.ll b/compiler/testdata/string.ll -index e8d6e631..93f76059 100644 ---- a/compiler/testdata/string.ll -+++ b/compiler/testdata/string.ll -@@ -1,6 +1,6 @@ - ; ModuleID = 'string.go' - source_filename = "string.go" --target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - - %runtime._string = type { i8*, i32 } -diff --git a/go.mod b/go.mod -index 52dd71c3..c1df4c2b 100644 ---- a/go.mod -+++ b/go.mod -@@ -13,5 +13,5 @@ require ( - go.bug.st/serial v1.1.3 - golang.org/x/sys v0.0.0-20210510120138-977fb7262007 - golang.org/x/tools v0.1.6-0.20210813165731-45389f592fe9 -- tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be -+ tinygo.org/x/go-llvm v0.0.0-20211230181020-1ddc904f6bf6 - ) -diff --git a/go.sum b/go.sum -index 73697653..4e394e71 100644 ---- a/go.sum -+++ b/go.sum -@@ -68,5 +68,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/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-20210907125547-fd2d62ea06be h1:syIpWbi/yESuoyijF2nhRdgX4422sNfmij+o73B3+vU= --tinygo.org/x/go-llvm v0.0.0-20210907125547-fd2d62ea06be/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= -+tinygo.org/x/go-llvm v0.0.0-20211230181020-1ddc904f6bf6 h1:p9huJkDeMFLOE5A4puIPRIewaTpQXX6OmjguUmGXJj4= -+tinygo.org/x/go-llvm v0.0.0-20211230181020-1ddc904f6bf6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -diff --git a/loader/loader.go b/loader/loader.go -index 1f43e07e..489ed24f 100644 ---- a/loader/loader.go -+++ b/loader/loader.go -@@ -406,7 +406,7 @@ func (p *Package) parseFiles() ([]*ast.File, error) { - initialCFlags = append(initialCFlags, p.program.config.CFlags()...) - initialCFlags = append(initialCFlags, "-I"+p.Dir) - if p.program.clangHeaders != "" { -- initialCFlags = append(initialCFlags, "-Xclang", "-internal-isystem", "-Xclang", p.program.clangHeaders) -+ initialCFlags = append(initialCFlags, "-isystem", p.program.clangHeaders) - } - generated, headerCode, cflags, ldflags, accessedFiles, errs := cgo.Process(files, p.program.workingDir, p.program.fset, initialCFlags) - p.CFlags = append(initialCFlags, cflags...) -diff --git a/src/internal/task/task_asyncify_wasm.S b/src/internal/task/task_asyncify_wasm.S -index da00dcae..3b00ede1 100644 ---- a/src/internal/task/task_asyncify_wasm.S -+++ b/src/internal/task/task_asyncify_wasm.S -@@ -1,5 +1,14 @@ - .globaltype __stack_pointer, i32 - -+.functype start_unwind (i32) -> () -+.import_module start_unwind, asyncify -+.functype stop_unwind () -> () -+.import_module stop_unwind, asyncify -+.functype start_rewind (i32) -> () -+.import_module start_rewind, asyncify -+.functype stop_rewind () -> () -+.import_module stop_rewind, asyncify -+ - .global tinygo_unwind - .hidden tinygo_unwind - .type tinygo_unwind,@function -@@ -84,15 +93,6 @@ tinygo_rewind: // func (state *state) rewind() - return - end_function - --.functype start_unwind (i32) -> () --.import_module start_unwind, asyncify --.functype stop_unwind () -> () --.import_module stop_unwind, asyncify --.functype start_rewind (i32) -> () --.import_module start_rewind, asyncify --.functype stop_rewind () -> () --.import_module stop_rewind, asyncify -- - .hidden tinygo_rewinding # @tinygo_rewinding - .type tinygo_rewinding,@object - .section .bss.tinygo_rewinding,"",@ -diff --git a/targets/cortex-m.json b/targets/cortex-m.json -index c2661393..5c057d61 100644 ---- a/targets/cortex-m.json -+++ b/targets/cortex-m.json -@@ -13,6 +13,7 @@ - "-Werror", - "-fshort-enums", - "-fomit-frame-pointer", -+ "-mfloat-abi=soft", - "-fno-exceptions", "-fno-unwind-tables", - "-ffunction-sections", "-fdata-sections" - ], -diff --git a/targets/cortex-m0.json b/targets/cortex-m0.json -index 315d6658..fe356805 100644 ---- a/targets/cortex-m0.json -+++ b/targets/cortex-m0.json -@@ -2,5 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv6m-unknown-unknown-eabi", - "cpu": "cortex-m0", -- "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" -+ "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - } -diff --git a/targets/cortex-m0plus.json b/targets/cortex-m0plus.json -index 6ac9b531..a21d06ca 100644 ---- a/targets/cortex-m0plus.json -+++ b/targets/cortex-m0plus.json -@@ -2,5 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv6m-unknown-unknown-eabi", - "cpu": "cortex-m0plus", -- "features": "+armv6-m,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" -+ "features": "+armv6-m,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - } -diff --git a/targets/cortex-m3.json b/targets/cortex-m3.json -index 07d88dfe..7b878d52 100644 ---- a/targets/cortex-m3.json -+++ b/targets/cortex-m3.json -@@ -2,5 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv7m-unknown-unknown-eabi", - "cpu": "cortex-m3", -- "features": "+armv7-m,+hwdiv,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2" -+ "features": "+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - } -diff --git a/targets/cortex-m33.json b/targets/cortex-m33.json -index 9b74ad16..6e77c3f2 100644 ---- a/targets/cortex-m33.json -+++ b/targets/cortex-m33.json -@@ -1,7 +1,4 @@ - { - "inherits": ["cortex-m"], -- "llvm-target": "thumbv7m-unknown-unknown-eabi", -- "cflags": [ -- "-mfloat-abi=soft" -- ] -+ "llvm-target": "thumbv7m-unknown-unknown-eabi" - } -diff --git a/targets/cortex-m4.json b/targets/cortex-m4.json -index ce947efb..8bcbf767 100644 ---- a/targets/cortex-m4.json -+++ b/targets/cortex-m4.json -@@ -2,8 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv7em-unknown-unknown-eabi", - "cpu": "cortex-m4", -- "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", -- "cflags": [ -- "-mfloat-abi=soft" -- ] -+ "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - } -diff --git a/targets/cortex-m7.json b/targets/cortex-m7.json -index 43fe532f..3ec505f6 100644 ---- a/targets/cortex-m7.json -+++ b/targets/cortex-m7.json -@@ -2,8 +2,5 @@ - "inherits": ["cortex-m"], - "llvm-target": "thumbv7em-unknown-unknown-eabi", - "cpu": "cortex-m7", -- "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", -- "cflags": [ -- "-mfloat-abi=soft" -- ] -+ "features": "+armv7e-m,+dsp,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" - } -diff --git a/targets/gameboy-advance.json b/targets/gameboy-advance.json -index 2467b4b9..fc647702 100644 ---- a/targets/gameboy-advance.json -+++ b/targets/gameboy-advance.json -@@ -1,7 +1,7 @@ - { - "llvm-target": "armv4t-unknown-unknown-eabi", - "cpu": "arm7tdmi", -- "features": "+armv4t,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-dotprod,-dsp,-fp16fml,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-ras,-sb,-sha2,-thumb-mode", -+ "features": "+armv4t,+strict-align,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-ras,-sb,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp", - "build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"], - "goos": "linux", - "goarch": "arm", -diff --git a/targets/k210.json b/targets/k210.json -index 2416a593..cc0d2ed4 100644 ---- a/targets/k210.json -+++ b/targets/k210.json -@@ -1,6 +1,6 @@ - { - "inherits": ["riscv64"], -- "features": "+a,+c,+d,+f,+m,-relax,-save-restore", -+ "features": "+64bit,+a,+c,+d,+f,+m,-relax,-save-restore", - "build-tags": ["k210", "kendryte"], - "code-model": "medium" - } -diff --git a/transform/optimizer.go b/transform/optimizer.go -index 64c3d0b5..cd79340c 100644 ---- a/transform/optimizer.go -+++ b/transform/optimizer.go -@@ -59,6 +59,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i - goPasses.AddGlobalDCEPass() - goPasses.AddGlobalOptimizerPass() - goPasses.AddIPSCCPPass() -+ goPasses.AddInstructionCombiningPass() // necessary for OptimizeReflectImplements - goPasses.AddAggressiveDCEPass() - goPasses.AddFunctionAttrsPass() - goPasses.Run(mod) --- -2.31.1 - diff --git a/sources b/sources index a84e639..e668f61 100644 --- a/sources +++ b/sources @@ -1,10 +1,10 @@ -SHA512 (tinygo-0.21.0.tar.gz) = 2c2bff6921db0f8e1b7f16055a640277606d9052437dc8928b4799de76ac3bee24e43322c6d5b9b1edd142d82edd518c22fbd956aea2dcf7810b696d980205dd +SHA512 (tinygo-0.22.0.tar.gz) = 26f2bc2cb580a3ef5de11a0a5001425e1b925b16b321c8d2742ac77399ca4e3b1993201165a1a8c9245e8a76a61f948b4a9740f5daaa6e1696f4cddf0dcaab70 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 -SHA512 (musl-1.2.2.tar.gz) = 5344b581bd6463d71af8c13e91792fa51f25a96a1ecbea81e42664b63d90b325aeb421dfbc8c22e187397ca08e84d9296a0c0c299ba04fa2b751d6864914bd82 -SHA512 (musl-1.2.2.tar.gz.asc) = 9d76bd9d88438e21689d37d7c519bc5575fa72b121ddf89c55c1a2246ecf423664d8e5199192720d652f6d08229f9b17b5520465d49b12ed2ba80814d1d8e9d8 +SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879add4eab283c8692c3b031eb9457ad00d1edd082cfe62fcc0eb5eb1d3bf4f1d749c0efa2a95fec1 +SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-f68b8204f797d6b3bfbc7c4da4d257961fbc8770.tar.gz) = fa58a7ddcb1a40239a220ca701a83895804b9ddc837652fa18e9aed2603bba2825df2074e2fa4fbf8649bb9a21308e877850273ec9d421795e2ae549f331ab13 SHA512 (wasi-libc-ad5133410f66b93a2381db5b542aad5e0964db96.tar.gz) = 04cb3a25fef7949bf77f262bd939102f5b36e2ae85f28cdbfcd8a8984425fba54fae68049b777974bdbad96882fab383b44203e8f19a776d8a56a55475c4aab6 diff --git a/tinygo.spec b/tinygo.spec index 741f315..9fc8868 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.21.0 +Version: 0.22.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -17,7 +17,7 @@ Version: 0.21.0 %endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version 9.0.0 -%global musl_version 1.2.2 +%global musl_version 1.2.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit f68b8204f797d6b3bfbc7c4da4d257961fbc8770 %global wasi_libc_commit ad5133410f66b93a2381db5b542aad5e0964db96 @@ -67,24 +67,11 @@ Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_com Patch0001: 0001-Skip-WASI-tests.patch # Unbundling things Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch -# https://github.com/tinygo-org/tinygo/pull/2482 -Patch0003: 0003-arm-Explicitly-disable-unwind-tables.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0004: 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch -# Backport support for LLVM 12 -# https://github.com/tinygo-org/tinygo/pull/2291 -Patch0005: 0005-targets-change-LLVM-features-to-match-vanilla-Clang.patch -# https://github.com/tinygo-org/tinygo/pull/2300 -Patch0006: 0006-all-add-LLVM-12-support.patch -# Backport support for LLVM 13 -# https://github.com/tinygo-org/tinygo/pull/2289 -Patch0007: 0007-tests-improve-wasm-tests-slightly.patch -# https://github.com/tinygo-org/tinygo/pull/2388 -Patch0008: 0008-internal-task-swap-stack-chain-when-switching-gorout.patch -# https://github.com/tinygo-org/tinygo/pull/2365 -Patch0009: 0009-all-switch-to-LLVM-13.patch +Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +Patch0004: 0004-Fix-LLVM-build-constraints.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -92,18 +79,23 @@ ExcludeArch: armv7hl ppc64le s390x BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) BuildRequires: golang(github.com/aykevl/go-wasm) BuildRequires: golang(github.com/blakesmith/ar) +%if %{fedora} > 35 %ifnarch %{ix86} BuildRequires: chromium -BuildRequires: golang(github.com/chromedp/chromedp) >= 0.6.4 +BuildRequires: golang(github.com/chromedp/chromedp) >= 0.7.6 BuildRequires: golang(github.com/chromedp/cdproto/cdp) %endif +%endif +BuildRequires: golang(github.com/gofrs/flock) >= 0.8.1 BuildRequires: golang(github.com/google/shlex) BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 BuildRequires: golang(go.bug.st/serial) >= 1.1.2 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.7 +BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 BuildRequires: golang(tinygo.org/x/go-llvm) +BuildRequires: golang-tests BuildRequires: llvm-devel(major) = %{clang_llvm_version} BuildRequires: make @@ -124,11 +116,11 @@ BuildRequires: qemu-user # For GPG signature verification BuildRequires: gnupg2 +Requires: clang Requires: golang Requires: lld Recommends: avr-gcc Recommends: avr-libc -Recommends: clang # Add this when LLVM supports ESP natively. # Recommends: esptool Recommends: mingw64-crt @@ -189,6 +181,13 @@ tar -C lib -xf %{SOURCE9} rmdir lib/wasi-libc mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc +# These packages were added in Go 1.17, so we can't test them in older Fedora. +%if %{fedora} && %{fedora} < 36 +sed -i \ + -e 's!crypto/elliptic/internal/fiat !!g' \ + -e 's!net/http/internal/ascii !!g' \ + Makefile +%endif %build # Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is @@ -196,13 +195,12 @@ mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc export BUILDTAGS="llvm%{clang_llvm_version}" LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} GO111MODULE=off %make_build gen-device STM32=0 -for arch in armv6m armv7m armv7em; do - target="${arch}-unknown-unknown-eabi" +for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-eabi-cortex-m0plus thumbv7em-unknown-unknown-eabi-cortex-m4; do mkdir -p ${target} for libc in compiler-rt picolibc; do TINYGOROOT=$PWD \ %{gobuilddir}/bin/tinygo \ - build-library -target=${target} -o ${target}/${libc} ${libc} + build-library -target=${target#*eabi-} -o ${target}/${libc} ${libc} done done %make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=llvm-ar LLVM_NM=llvm-nm @@ -262,8 +260,7 @@ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc/newlib/libm/common %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc-stdio.c %{buildroot}%{tinygoroot}/lib install -vdm 0755 %{buildroot}%{tinygoroot}/pkg -for arch in armv6m armv7m armv7em; do - target="${arch}-unknown-unknown-eabi" +for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-eabi-cortex-m0plus thumbv7em-unknown-unknown-eabi-cortex-m4; do install -vdm 0755 %{buildroot}%{tinygoroot}/pkg/${target} for libc in compiler-rt picolibc; do cp -rp ${target}/${libc} %{buildroot}%{tinygoroot}/pkg/${target}/ @@ -282,12 +279,15 @@ export GOPATH=%{buildroot}%{tinygoroot}:%{gopath} export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off export XDG_CACHE_HOME="${PWD}/$(mktemp -d tinygo.XXXXXX)" -%gocheck -v -d tests/tinygotest +%gocheck -v -t src -d tests/tinygotest make smoketest STM32=0 XTENSA=0 +%if %{fedora} > 35 %ifnarch %{ix86} aarch64 make wasmtest %endif %endif +make tinygo-test +%endif %files From ab77f345e893cad3542ef8f84e8d843d9ab056b4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 04:22:37 -0500 Subject: [PATCH 26/78] Suggest packages to install if missing This is handy if tinygo is installed with Recommends off. --- 0001-Skip-WASI-tests.patch | 2 +- 0002-Use-system-mingw64-headers-and-crt.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- 0004-Fix-LLVM-build-constraints.patch | 2 +- ...ional-packages-to-install-if-missing.patch | 78 +++++++++++++++++++ tinygo.spec | 2 + 6 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 0005-Suggest-optional-packages-to-install-if-missing.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index c1032de..a751eb3 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 7916f90d20fe95c4facc83d79d2d99056225e375 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/4] Skip WASI tests. +Subject: [PATCH 1/5] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index aaef2ac..bd4bbec 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ From d0bd4aaedbbe1cc02af6e3046d813fd5697b6ef0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/4] Use system mingw64 headers and crt +Subject: [PATCH 2/5] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index b51c233..aed9c9b 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From f9c9b3633e322ebc3f15216afbb624bd0fb0f188 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/4] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 3/5] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0004-Fix-LLVM-build-constraints.patch b/0004-Fix-LLVM-build-constraints.patch index e7bab69..de561de 100644 --- a/0004-Fix-LLVM-build-constraints.patch +++ b/0004-Fix-LLVM-build-constraints.patch @@ -1,7 +1,7 @@ From 146b1fd103b0dbc178c1ac8c0ecfcc8b82d632ae Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 2 Feb 2022 06:54:20 -0500 -Subject: [PATCH 4/4] Fix LLVM build constraints +Subject: [PATCH 4/5] Fix LLVM build constraints Signed-off-by: Elliott Sales de Andrade --- diff --git a/0005-Suggest-optional-packages-to-install-if-missing.patch b/0005-Suggest-optional-packages-to-install-if-missing.patch new file mode 100644 index 0000000..03609f8 --- /dev/null +++ b/0005-Suggest-optional-packages-to-install-if-missing.patch @@ -0,0 +1,78 @@ +From a3ef83de0286ef34933d397beec7b0b0808ebfc8 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 6 Feb 2022 03:49:16 -0500 +Subject: [PATCH 5/5] Suggest optional packages to install if missing + +Signed-off-by: Elliott Sales de Andrade +--- + builder/jobs.go | 17 +++++++++++++++++ + builder/mingw-w64.go | 2 +- + builder/tools.go | 6 +++++- + 3 files changed, 23 insertions(+), 2 deletions(-) + +diff --git a/builder/jobs.go b/builder/jobs.go +index 3d510974..d24a4165 100644 +--- a/builder/jobs.go ++++ b/builder/jobs.go +@@ -7,6 +7,7 @@ import ( + "container/heap" + "errors" + "fmt" ++ "os" + "runtime" + "sort" + "strings" +@@ -37,6 +38,22 @@ type compileJob struct { + duration time.Duration // how long it took to run this job (only set after finishing) + } + ++// checkIfPackagedFileExistsJob returns a new *compileJob that checks if a file ++// exists. If the file does not exist, the job will fail with an error ++// suggesting to install the named system packageToInstall. ++func checkIfPackagedFileExistsJob(fileName, packageToInstall string) *compileJob { ++ return &compileJob{ ++ description: fmt.Sprintf("check if %v exists", fileName), ++ result: fileName, ++ run: func(*compileJob) (err error) { ++ if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) { ++ return fmt.Errorf("%v does not exist; please install %v via dnf", fileName, packageToInstall) ++ } ++ return nil ++ }, ++ } ++} ++ + // dummyCompileJob returns a new *compileJob that produces an output without + // doing anything. This can be useful where a *compileJob producing an output is + // expected but nothing needs to be done, for example for a load from a cache. +diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go +index 07ce05c8..76bf5806 100644 +--- a/builder/mingw-w64.go ++++ b/builder/mingw-w64.go +@@ -26,7 +26,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob { + var jobs []*compileJob + for _, name := range []string{"kernel32", "ucrt"} { + outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) +- job := dummyCompileJob(outpath) ++ job := checkIfPackagedFileExistsJob(outpath, "mingw64-crt and mingw64-headers") + jobs = append(jobs, job) + } + return jobs +diff --git a/builder/tools.go b/builder/tools.go +index 53d89bf0..e55719b2 100644 +--- a/builder/tools.go ++++ b/builder/tools.go +@@ -46,5 +46,9 @@ func link(linker string, flags ...string) error { + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Dir = goenv.Get("TINYGOROOT") +- return cmd.Run() ++ err := cmd.Run() ++ if linker == "avr-gcc" && errors.Is(err, exec.ErrNotFound) { ++ return errors.New("avr-gcc not found; please install avr-gcc and avr-libc via dnf") ++ } ++ return err + } +-- +2.31.1 + diff --git a/tinygo.spec b/tinygo.spec index 9fc8868..3988e2e 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -72,6 +72,8 @@ Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch # https://gitlab.com/qemu-project/qemu/-/issues/690 Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch Patch0004: 0004-Fix-LLVM-build-constraints.patch +# Add Fedora specific dnf instructions +Patch0005: 0005-Suggest-optional-packages-to-install-if-missing.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 6ba7946a1e184cf2119d023436f68147820a709c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 7 Feb 2022 01:13:46 -0500 Subject: [PATCH 27/78] Fix cross Linux setup on non amd64 arches --- ...ross-Linux-setup-on-non-amd64-arches.patch | 111 ++++++++++++++++++ ...-tests.patch => 0002-Skip-WASI-tests.patch | 10 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 43 ------- ...3-Use-system-mingw64-headers-and-crt.patch | 4 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 64 ++++++++++ ...h => 0005-Fix-LLVM-build-constraints.patch | 4 +- ...ional-packages-to-install-if-missing.patch | 4 +- tinygo.spec | 12 +- 8 files changed, 193 insertions(+), 59 deletions(-) create mode 100644 0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch rename 0001-Skip-WASI-tests.patch => 0002-Skip-WASI-tests.patch (75%) delete mode 100644 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename 0002-Use-system-mingw64-headers-and-crt.patch => 0003-Use-system-mingw64-headers-and-crt.patch (97%) create mode 100644 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename 0004-Fix-LLVM-build-constraints.patch => 0005-Fix-LLVM-build-constraints.patch (96%) rename 0005-Suggest-optional-packages-to-install-if-missing.patch => 0006-Suggest-optional-packages-to-install-if-missing.patch (95%) diff --git a/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch b/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch new file mode 100644 index 0000000..040ce02 --- /dev/null +++ b/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch @@ -0,0 +1,111 @@ +From a9406dd9dd992c8160372b07b4b0811fb9a6ffad Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 6 Feb 2022 23:26:25 -0500 +Subject: [PATCH 1/6] Fix cross-Linux setup on non-amd64 arches + +In that case, an emulator is needed for amd64, and tests should be run +_for_ amd64 as a cross test. + +Signed-off-by: Elliott Sales de Andrade +--- + compileopts/target.go | 19 ++++++++++++++----- + main_test.go | 39 +++++++++++++++++++++------------------ + 2 files changed, 35 insertions(+), 23 deletions(-) + +diff --git a/compileopts/target.go b/compileopts/target.go +index ffdf7365..9e341537 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -317,11 +317,20 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + if goarch != runtime.GOARCH { + // Some educated guesses as to how to invoke helper programs. + spec.GDB = []string{"gdb-multiarch"} +- if goarch == "arm" && goos == "linux" { +- spec.Emulator = []string{"qemu-arm"} +- } +- if goarch == "arm64" && goos == "linux" { +- spec.Emulator = []string{"qemu-aarch64"} ++ if goos == "linux" { ++ switch goarch { ++ case "386": ++ // amd64 can _usually_ run 32-bit programs, so skip the emulator in that case. ++ if runtime.GOARCH != "amd64" { ++ spec.Emulator = []string{"qemu-i386"} ++ } ++ case "amd64": ++ spec.Emulator = []string{"qemu-x86_64"} ++ case "arm": ++ spec.Emulator = []string{"qemu-arm"} ++ case "arm64": ++ spec.Emulator = []string{"qemu-aarch64"} ++ } + } + } + if goos != runtime.GOOS { +diff --git a/main_test.go b/main_test.go +index cf3fc989..82c0b611 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -31,6 +31,13 @@ const TESTDATA = "testdata" + + var testTarget = flag.String("target", "", "override test target") + ++var supportedLinuxArches = map[string]string{ ++ "AMD64Linux": "linux/amd64", ++ "X86Linux": "linux/386", ++ "ARMLinux": "linux/arm/6", ++ "ARM64Linux": "linux/arm64", ++} ++ + var sema = make(chan struct{}, runtime.NumCPU()) + + func TestBuild(t *testing.T) { +@@ -180,18 +187,14 @@ func TestBuild(t *testing.T) { + }) + + if runtime.GOOS == "linux" { +- t.Run("X86Linux", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromOSARCH("linux/386", sema), tests, t) +- }) +- t.Run("ARMLinux", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromOSARCH("linux/arm/6", sema), tests, t) +- }) +- t.Run("ARM64Linux", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromOSARCH("linux/arm64", sema), tests, t) +- }) ++ for name, osArch := range supportedLinuxArches { ++ options := optionsFromOSARCH(osArch, sema) ++ if options.GOARCH != runtime.GOARCH { // Native architecture already run above. ++ t.Run(name, func(t *testing.T) { ++ runPlatTests(options, tests, t) ++ }) ++ } ++ } + t.Run("WebAssembly", func(t *testing.T) { + t.Parallel() + runPlatTests(optionsFromTarget("wasm", sema), tests, t) +@@ -475,12 +478,12 @@ func TestTest(t *testing.T) { + } + if !testing.Short() { + if runtime.GOOS == "linux" { +- targs = append(targs, +- // Linux +- targ{"X86Linux", optionsFromOSARCH("linux/386", sema)}, +- targ{"ARMLinux", optionsFromOSARCH("linux/arm/6", sema)}, +- targ{"ARM64Linux", optionsFromOSARCH("linux/arm64", sema)}, +- ) ++ for name, osArch := range supportedLinuxArches { ++ options := optionsFromOSARCH(osArch, sema) ++ if options.GOARCH != runtime.GOARCH { // Native architecture already run above. ++ targs = append(targs, targ{name, options}) ++ } ++ } + } + + targs = append(targs, +-- +2.31.1 + diff --git a/0001-Skip-WASI-tests.patch b/0002-Skip-WASI-tests.patch similarity index 75% rename from 0001-Skip-WASI-tests.patch rename to 0002-Skip-WASI-tests.patch index a751eb3..63aa5e6 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0002-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 7916f90d20fe95c4facc83d79d2d99056225e375 Mon Sep 17 00:00:00 2001 +From 64af5a0ac7d93ad931737358c1af852e99fbf647 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/5] Skip WASI tests. +Subject: [PATCH 2/6] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index cf3fc989..316f69fa 100644 +index 82c0b611..d9f440b0 100644 --- a/main_test.go +++ b/main_test.go -@@ -196,10 +196,6 @@ func TestBuild(t *testing.T) { +@@ -199,10 +199,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -25,7 +25,7 @@ index cf3fc989..316f69fa 100644 } } -@@ -490,7 +486,6 @@ func TestTest(t *testing.T) { +@@ -493,7 +489,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch deleted file mode 100644 index aed9c9b..0000000 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ /dev/null @@ -1,43 +0,0 @@ -From f9c9b3633e322ebc3f15216afbb624bd0fb0f188 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/5] Skip some cross Linux tests where qemu is broken - -The upstream issues will hopefully be fixed soon: - -- https://gitlab.com/qemu-project/qemu/-/issues/447 -- https://gitlab.com/qemu-project/qemu/-/issues/690 - -Signed-off-by: Elliott Sales de Andrade ---- - main_test.go | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) - -diff --git a/main_test.go b/main_test.go -index 316f69fa..dba5e784 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -364,6 +364,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c - return - } - -+ // Skip running the test executable due to bugs in qemu. -+ // https://gitlab.com/qemu-project/qemu/-/issues/447 -+ // https://gitlab.com/qemu-project/qemu/-/issues/690 -+ switch runtime.GOARCH { -+ case "arm64": -+ if options.GOARCH == "386" || options.GOARCH == "arm" { -+ return -+ } -+ case "386": -+ if options.GOARCH == "arm" { -+ return -+ } -+ } -+ - // Reserve CPU time for the test to run. - // This attempts to ensure that the test is not CPU-starved. - options.Semaphore <- struct{}{} --- -2.31.1 - diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0003-Use-system-mingw64-headers-and-crt.patch similarity index 97% rename from 0002-Use-system-mingw64-headers-and-crt.patch rename to 0003-Use-system-mingw64-headers-and-crt.patch index bd4bbec..0d27d6f 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0003-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ -From d0bd4aaedbbe1cc02af6e3046d813fd5697b6ef0 Mon Sep 17 00:00:00 2001 +From 3d4375f7d44bfb3c865bdd460ad314ddf3de983d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/5] Use system mingw64 headers and crt +Subject: [PATCH 3/6] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch new file mode 100644 index 0000000..cf4b72f --- /dev/null +++ b/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -0,0 +1,64 @@ +From 8c931c99e52b8dc080bdcb0a062f9ed189f4286d Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 3 Jan 2022 22:39:31 -0500 +Subject: [PATCH 4/6] Skip some cross Linux tests where qemu is broken + +The upstream issues will hopefully be fixed soon: + +- https://gitlab.com/qemu-project/qemu/-/issues/447 +- https://gitlab.com/qemu-project/qemu/-/issues/690 + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 28 ++++++++++++++++++++++++++++ + 1 file changed, 28 insertions(+) + +diff --git a/main_test.go b/main_test.go +index d9f440b0..d3daddc3 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -246,6 +246,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { + } + + func emuCheck(t *testing.T, options compileopts.Options) { ++ // Skip running the test executable due to bugs in qemu. ++ // https://gitlab.com/qemu-project/qemu/-/issues/447 ++ // https://gitlab.com/qemu-project/qemu/-/issues/690 ++ switch runtime.GOARCH { ++ case "arm64": ++ if options.GOARCH == "386" || options.GOARCH == "arm" { ++ t.Skipf("qemu is broken for this host/target architecture combination") ++ } ++ case "386": ++ if options.GOARCH == "arm" { ++ t.Skipf("qemu is broken for this host/target architecture combination") ++ } ++ } ++ + // Check if the emulator is installed. + spec, err := compileopts.LoadTarget(&options) + if err != nil { +@@ -367,6 +381,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c + return + } + ++ // Skip running the test executable due to bugs in qemu. ++ // https://gitlab.com/qemu-project/qemu/-/issues/447 ++ // https://gitlab.com/qemu-project/qemu/-/issues/690 ++ switch runtime.GOARCH { ++ case "arm64": ++ if options.GOARCH == "386" || options.GOARCH == "arm" { ++ return ++ } ++ case "386": ++ if options.GOARCH == "arm" { ++ return ++ } ++ } ++ + // Reserve CPU time for the test to run. + // This attempts to ensure that the test is not CPU-starved. + options.Semaphore <- struct{}{} +-- +2.31.1 + diff --git a/0004-Fix-LLVM-build-constraints.patch b/0005-Fix-LLVM-build-constraints.patch similarity index 96% rename from 0004-Fix-LLVM-build-constraints.patch rename to 0005-Fix-LLVM-build-constraints.patch index de561de..dc5b54f 100644 --- a/0004-Fix-LLVM-build-constraints.patch +++ b/0005-Fix-LLVM-build-constraints.patch @@ -1,7 +1,7 @@ -From 146b1fd103b0dbc178c1ac8c0ecfcc8b82d632ae Mon Sep 17 00:00:00 2001 +From e4522f22aced375f1a80d5075326e66c71c9a524 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 2 Feb 2022 06:54:20 -0500 -Subject: [PATCH 4/5] Fix LLVM build constraints +Subject: [PATCH 5/6] Fix LLVM build constraints Signed-off-by: Elliott Sales de Andrade --- diff --git a/0005-Suggest-optional-packages-to-install-if-missing.patch b/0006-Suggest-optional-packages-to-install-if-missing.patch similarity index 95% rename from 0005-Suggest-optional-packages-to-install-if-missing.patch rename to 0006-Suggest-optional-packages-to-install-if-missing.patch index 03609f8..6ec8b61 100644 --- a/0005-Suggest-optional-packages-to-install-if-missing.patch +++ b/0006-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From a3ef83de0286ef34933d397beec7b0b0808ebfc8 Mon Sep 17 00:00:00 2001 +From ca5254f583341c91a6fc5b77c8a515e00a4f63df Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 5/5] Suggest optional packages to install if missing +Subject: [PATCH 6/6] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/tinygo.spec b/tinygo.spec index 3988e2e..ec8cb02 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -63,17 +63,19 @@ Source62: https://musl.libc.org/musl.pub Source7: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz Source8: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz +# https://github.com/tinygo-org/tinygo/pull/2620 +Patch0001: 0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch # We don't have wasmtime to run these. -Patch0001: 0001-Skip-WASI-tests.patch +Patch0002: 0002-Skip-WASI-tests.patch # Unbundling things -Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch +Patch0003: 0003-Use-system-mingw64-headers-and-crt.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch -Patch0004: 0004-Fix-LLVM-build-constraints.patch +Patch0004: 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +Patch0005: 0005-Fix-LLVM-build-constraints.patch # Add Fedora specific dnf instructions -Patch0005: 0005-Suggest-optional-packages-to-install-if-missing.patch +Patch0006: 0006-Suggest-optional-packages-to-install-if-missing.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 0f7ffa073dbca2ae54d1fc6b251e085e6696a6be Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 7 Feb 2022 02:42:48 -0500 Subject: [PATCH 28/78] Skip slow tests on 32-bit arch They are not only slow, but also seem to OOM. --- tinygo.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinygo.spec b/tinygo.spec index ec8cb02..c937085 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -290,8 +290,12 @@ make smoketest STM32=0 XTENSA=0 make wasmtest %endif %endif +%ifarch %{ix86} +make tinygo-test-fast +%else make tinygo-test %endif +%endif %files From 7c2e2a55ac52b53b681ab20c870c4cd9584a1677 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 7 Feb 2022 04:37:57 -0500 Subject: [PATCH 29/78] Also skip archive/zip on 32-bit arches Because it's extremely slow. --- tinygo.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinygo.spec b/tinygo.spec index c937085..ab9dc69 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -192,6 +192,10 @@ sed -i \ -e 's!net/http/internal/ascii !!g' \ Makefile %endif +# This test is too slow and pretty much freezes. +%ifarch %{ix86} +sed -i -e 's!archive/zip!$(nil)!' Makefile +%endif %build # Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is From e3dd63fec30ed96662191db9fb5895c07af8dd84 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 19 Feb 2022 04:15:38 -0500 Subject: [PATCH 30/78] Fix permissions in tinygoroot --- tinygo.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinygo.spec b/tinygo.spec index ab9dc69..1c6a8be 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -209,6 +209,7 @@ for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-e TINYGOROOT=$PWD \ %{gobuilddir}/bin/tinygo \ build-library -target=${target#*eabi-} -o ${target}/${libc} ${libc} + chmod -R a+rX ${target}/${libc} done done %make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=llvm-ar LLVM_NM=llvm-nm @@ -260,10 +261,13 @@ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc cp -rp lib/wasi-libc/sysroot %{buildroot}%{tinygoroot}/lib/wasi-libc/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc cp -rp lib/picolibc/newlib/libc/ctype %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc +chmod -x %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc/ctype/{mkcaseconv,mkcategories,mkunidata} cp -rp lib/picolibc/newlib/libc/include %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc cp -rp lib/picolibc/newlib/libc/locale %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc cp -rp lib/picolibc/newlib/libc/string %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc +chmod -x %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc/string/{mkunidata,mkwide,mkwidthA,uniset} cp -rp lib/picolibc/newlib/libc/tinystdio %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc +chmod -x %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc/tinystdio/make-dtoa-data install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc/newlib/libm/common %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc-stdio.c %{buildroot}%{tinygoroot}/lib From 174a446d2f555abf9c91dde061bca75f38d01c24 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 10 Apr 2022 17:35:48 -0400 Subject: [PATCH 31/78] Backport support for Go 1.18 --- 2615.patch | 251 ++++++++++++++++++++++++++++++++ 2679.patch | 64 ++++++++ 2715.patch | 130 +++++++++++++++++ 2716.patch | 27 ++++ 2719.patch | 93 ++++++++++++ 2721.patch | 24 +++ 2722.patch | 36 +++++ 2724.patch | 72 +++++++++ 2725.patch | 409 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2727.patch | 25 ++++ 2729.patch | 90 ++++++++++++ 2730.patch | 33 +++++ 2731.patch | 170 ++++++++++++++++++++++ 2753.patch | 280 +++++++++++++++++++++++++++++++++++ 2763.patch | 22 +++ tinygo.spec | 37 ++++- 16 files changed, 1762 insertions(+), 1 deletion(-) create mode 100644 2615.patch create mode 100644 2679.patch create mode 100644 2715.patch create mode 100644 2716.patch create mode 100644 2719.patch create mode 100644 2721.patch create mode 100644 2722.patch create mode 100644 2724.patch create mode 100644 2725.patch create mode 100644 2727.patch create mode 100644 2729.patch create mode 100644 2730.patch create mode 100644 2731.patch create mode 100644 2753.patch create mode 100644 2763.patch diff --git a/2615.patch b/2615.patch new file mode 100644 index 0000000..92525f4 --- /dev/null +++ b/2615.patch @@ -0,0 +1,251 @@ +From 6e233f27d5249752da54697d6cd549467eee241f Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 5 Feb 2022 03:51:57 -0500 +Subject: [PATCH 1/4] Implement all of os.Signal in arch-specific syscall + +This is basically copied from `syscall_js.go` from the Go standard +library, since the existing parts were from there as well. +--- + src/syscall/syscall_libc_darwin.go | 15 +++++++++++++++ + src/syscall/syscall_libc_nintendoswitch.go | 18 ++++++++++++++++++ + src/syscall/syscall_libc_wasi.go | 15 +++++++++++++++ + src/syscall/syscall_nonhosted.go | 18 ++++++++++++++++++ + 4 files changed, 66 insertions(+) + +diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go +index ac89f74e5..d3ec63763 100644 +--- a/src/syscall/syscall_libc_darwin.go ++++ b/src/syscall/syscall_libc_darwin.go +@@ -4,6 +4,7 @@ + package syscall + + import ( ++ "internal/itoa" + "unsafe" + ) + +@@ -82,6 +83,20 @@ const ( + SIGTERM Signal = 0xf + ) + ++func (s Signal) Signal() {} ++ ++func (s Signal) String() string { ++ if 0 <= s && int(s) < len(signals) { ++ str := signals[s] ++ if str != "" { ++ return str ++ } ++ } ++ return "signal " + itoa.Itoa(int(s)) ++} ++ ++var signals = [...]string{} ++ + const ( + Stdin = 0 + Stdout = 1 +diff --git a/src/syscall/syscall_libc_nintendoswitch.go b/src/syscall/syscall_libc_nintendoswitch.go +index 876f125c2..98494643f 100644 +--- a/src/syscall/syscall_libc_nintendoswitch.go ++++ b/src/syscall/syscall_libc_nintendoswitch.go +@@ -3,6 +3,10 @@ + + package syscall + ++import ( ++ "internal/itoa" ++) ++ + // A Signal is a number describing a process signal. + // It implements the os.Signal interface. + type Signal int +@@ -17,6 +21,20 @@ const ( + SIGTERM + ) + ++func (s Signal) Signal() {} ++ ++func (s Signal) String() string { ++ if 0 <= s && int(s) < len(signals) { ++ str := signals[s] ++ if str != "" { ++ return str ++ } ++ } ++ return "signal " + itoa.Itoa(int(s)) ++} ++ ++var signals = [...]string{} ++ + // File system + + const ( +diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go +index a19420d77..c8c5dd0ab 100644 +--- a/src/syscall/syscall_libc_wasi.go ++++ b/src/syscall/syscall_libc_wasi.go +@@ -4,6 +4,7 @@ + package syscall + + import ( ++ "internal/itoa" + "unsafe" + ) + +@@ -20,6 +21,20 @@ const ( + SIGTERM = 15 + ) + ++func (s Signal) Signal() {} ++ ++func (s Signal) String() string { ++ if 0 <= s && int(s) < len(signals) { ++ str := signals[s] ++ if str != "" { ++ return str ++ } ++ } ++ return "signal " + itoa.Itoa(int(s)) ++} ++ ++var signals = [...]string{} ++ + const ( + Stdin = 0 + Stdout = 1 +diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go +index 2f590f2bd..b63dc0b61 100644 +--- a/src/syscall/syscall_nonhosted.go ++++ b/src/syscall/syscall_nonhosted.go +@@ -3,6 +3,10 @@ + + package syscall + ++import ( ++ "internal/itoa" ++) ++ + // Most code here has been copied from the Go sources: + // https://github.com/golang/go/blob/go1.12/src/syscall/syscall_js.go + // It has the following copyright note: +@@ -25,6 +29,20 @@ const ( + SIGTERM + ) + ++func (s Signal) Signal() {} ++ ++func (s Signal) String() string { ++ if 0 <= s && int(s) < len(signals) { ++ str := signals[s] ++ if str != "" { ++ return str ++ } ++ } ++ return "signal " + itoa.Itoa(int(s)) ++} ++ ++var signals = [...]string{} ++ + // File system + + const ( + +From eb32bc54653225424e0c05e7ca5c49a8108c3fa3 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 5 Feb 2022 06:18:33 -0500 +Subject: [PATCH 2/4] Add os Signal aliases + +These are used in Go 1.18's `testing/internal/testdeps`. Though the +comment says they should exist _everywhere_, there is still a build +constraint, but that seems to be fine. +--- + src/os/exec_posix.go | 22 ++++++++++++++++++++++ + 1 file changed, 22 insertions(+) + create mode 100644 src/os/exec_posix.go + +diff --git a/src/os/exec_posix.go b/src/os/exec_posix.go +new file mode 100644 +index 000000000..4d453099b +--- /dev/null ++++ b/src/os/exec_posix.go +@@ -0,0 +1,22 @@ ++// Copyright 2009 The Go Authors. All rights reserved. ++// Use of this source code is governed by a BSD-style ++// license that can be found in the LICENSE file. ++ ++package os ++ ++//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris || windows ++// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris windows ++ ++import ( ++ "syscall" ++) ++ ++// The only signal values guaranteed to be present in the os package on all ++// systems are os.Interrupt (send the process an interrupt) and os.Kill (force ++// the process to exit). On Windows, sending os.Interrupt to a process with ++// os.Process.Signal is not implemented; it will return an error instead of ++// sending a signal. ++var ( ++ Interrupt Signal = syscall.SIGINT ++ Kill Signal = syscall.SIGKILL ++) + +From 6242cb26bffb9890030cc068e3f0920d558e9d8a Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 5 Feb 2022 19:18:38 -0500 +Subject: [PATCH 3/4] Add an empty os.Process.Signal implementation + +This fixes compile of tests in Go 1.18, due to its use in +`src/internal/testenv/testenv.go`. +--- + src/os/exec.go | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/os/exec.go b/src/os/exec.go +index 067be0de1..e78350b36 100644 +--- a/src/os/exec.go ++++ b/src/os/exec.go +@@ -49,3 +49,7 @@ func (p *Process) Wait() (*ProcessState, error) { + func (p *Process) Kill() error { + return ErrNotImplemented + } ++ ++func (p *Process) Signal(sig Signal) error { ++ return ErrNotImplemented ++} + +From 84963ecf4e26b4e063e6fc55abf5297da758877e Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 5 Feb 2022 20:44:26 -0500 +Subject: [PATCH 4/4] Fix type of Signal constants on WASI + +--- + src/syscall/syscall_libc_wasi.go | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go +index c8c5dd0ab..cf556884d 100644 +--- a/src/syscall/syscall_libc_wasi.go ++++ b/src/syscall/syscall_libc_wasi.go +@@ -13,12 +13,12 @@ import ( + type Signal int + + const ( +- SIGCHLD = 16 +- SIGINT = 2 +- SIGKILL = 9 +- SIGTRAP = 5 +- SIGQUIT = 3 +- SIGTERM = 15 ++ SIGCHLD Signal = 16 ++ SIGINT Signal = 2 ++ SIGKILL Signal = 9 ++ SIGTRAP Signal = 5 ++ SIGQUIT Signal = 3 ++ SIGTERM Signal = 15 + ) + + func (s Signal) Signal() {} diff --git a/2679.patch b/2679.patch new file mode 100644 index 0000000..1f61e96 --- /dev/null +++ b/2679.patch @@ -0,0 +1,64 @@ +From eba36ebe0cc3fdd6196c23a6dbaf617921afadf6 Mon Sep 17 00:00:00 2001 +From: ZauberNerd +Date: Fri, 4 Mar 2022 15:31:31 +0000 +Subject: [PATCH] src/os: add stubs for exec.ExitError and + ProcessState.ExitCode + +This commit adds stubs for the `ExitError` struct of the `exec` package +and `ProcessState.ExitCode()` of the `os` package. + +Since the `os/exec` is listed as unsupported, stubbing these methods +and structs should be enough to get programs that use these to compile. +--- + src/os/exec.go | 6 ++++++ + src/os/exec/exec.go | 24 ++++++++++++++++++++++++ + 2 files changed, 30 insertions(+) + create mode 100644 src/os/exec/exec.go + +diff --git a/src/os/exec.go b/src/os/exec.go +index 067be0de1..903daf484 100644 +--- a/src/os/exec.go ++++ b/src/os/exec.go +@@ -34,6 +34,12 @@ func (p *ProcessState) Success() bool { + return false // TODO + } + ++// ExitCode returns the exit code of the exited process, or -1 ++// if the process hasn't exited or was terminated by a signal. ++func (p *ProcessState) ExitCode() int { ++ return -1 // TODO ++} ++ + type Process struct { + Pid int + } +diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go +new file mode 100644 +index 000000000..afb445702 +--- /dev/null ++++ b/src/os/exec/exec.go +@@ -0,0 +1,24 @@ ++package exec ++ ++import "os" ++ ++// An ExitError reports an unsuccessful exit by a command. ++type ExitError struct { ++ *os.ProcessState ++ ++ // Stderr holds a subset of the standard error output from the ++ // Cmd.Output method if standard error was not otherwise being ++ // collected. ++ // ++ // If the error output is long, Stderr may contain only a prefix ++ // and suffix of the output, with the middle replaced with ++ // text about the number of omitted bytes. ++ // ++ // Stderr is provided for debugging, for inclusion in error messages. ++ // Users with other needs should redirect Cmd.Stderr as needed. ++ Stderr []byte ++} ++ ++func (e *ExitError) Error() string { ++ return e.ProcessState.String() ++} diff --git a/2715.patch b/2715.patch new file mode 100644 index 0000000..c7cf943 --- /dev/null +++ b/2715.patch @@ -0,0 +1,130 @@ +From c697d75bc9970145e996686fbca79db7f8e6fb49 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Wed, 12 Jan 2022 01:55:54 -0500 +Subject: [PATCH] Rename reflect.Ptr to reflect.Pointer + +This was done in plain Go for 1.18: +https://github.com/golang/go/commit/17910ed4ff5a3cb3dcf4367d4af23ad5a7fe5809 + +Signed-off-by: Elliott Sales de Andrade +--- + src/reflect/type.go | 29 +++++++++++++++++------------ + 1 file changed, 17 insertions(+), 12 deletions(-) + +diff --git a/src/reflect/type.go b/src/reflect/type.go +index 4ead369b..87ebca5a 100644 +--- a/src/reflect/type.go ++++ b/src/reflect/type.go +@@ -18,7 +18,7 @@ import ( + // if set) and xxx contains the type kind number: + // 0 (0001): Chan + // 1 (0011): Interface +-// 2 (0101): Ptr ++// 2 (0101): Pointer + // 3 (0111): Slice + // 4 (1001): Array + // 5 (1011): Func +@@ -54,7 +54,7 @@ const ( + UnsafePointer + Chan + Interface +- Ptr ++ Pointer + Slice + Array + Func +@@ -62,6 +62,9 @@ const ( + Struct + ) + ++// Ptr is the old name for the Pointer kind. ++const Ptr = Pointer ++ + func (k Kind) String() string { + switch k { + case Bool: +@@ -104,7 +107,7 @@ func (k Kind) String() string { + return "chan" + case Interface: + return "interface" +- case Ptr: ++ case Pointer: + return "ptr" + case Slice: + return "slice" +@@ -223,7 +226,7 @@ type Type interface { + // Chan: ChanDir, Elem + // Func: In, NumIn, Out, NumOut, IsVariadic. + // Map: Key, Elem +- // Ptr: Elem ++ // Pointer: Elem + // Slice: Elem + // Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField + +@@ -251,7 +254,7 @@ type Type interface { + //IsVariadic() bool + + // Elem returns a type's element type. +- // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice. ++ // It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice. + Elem() Type + + // Field returns a struct type's i'th field. +@@ -321,13 +324,15 @@ func TypeOf(i interface{}) Type { + return ValueOf(i).typecode + } + +-func PtrTo(t Type) Type { +- if t.Kind() == Ptr { ++func PtrTo(t Type) Type { return PointerTo(t) } ++ ++func PointerTo(t Type) Type { ++ if t.Kind() == Pointer { + panic("reflect: cannot make **T type") + } + ptrType := t.(rawType)<<5 | 5 // 0b0101 == 5 + if ptrType>>5 != t { +- panic("reflect: PtrTo type does not fit") ++ panic("reflect: PointerTo type does not fit") + } + return ptrType + } +@@ -353,7 +358,7 @@ func (t rawType) Elem() Type { + + func (t rawType) elem() rawType { + switch t.Kind() { +- case Chan, Ptr, Slice: ++ case Chan, Pointer, Slice: + return t.stripPrefix() + case Array: + index := t.stripPrefix() +@@ -537,7 +542,7 @@ func (t rawType) Size() uintptr { + return 16 + case String: + return unsafe.Sizeof("") +- case UnsafePointer, Chan, Map, Ptr: ++ case UnsafePointer, Chan, Map, Pointer: + return unsafe.Sizeof(uintptr(0)) + case Slice: + return unsafe.Sizeof([]int{}) +@@ -586,7 +591,7 @@ func (t rawType) Align() int { + return int(unsafe.Alignof(complex128(0))) + case String: + return int(unsafe.Alignof("")) +- case UnsafePointer, Chan, Map, Ptr: ++ case UnsafePointer, Chan, Map, Pointer: + return int(unsafe.Alignof(uintptr(0))) + case Slice: + return int(unsafe.Alignof([]int(nil))) +@@ -652,7 +657,7 @@ func (t rawType) Comparable() bool { + return true + case Interface: + return true +- case Ptr: ++ case Pointer: + return true + case Slice: + return false +-- +2.35.1 + diff --git a/2716.patch b/2716.patch new file mode 100644 index 0000000..ea1ec5b --- /dev/null +++ b/2716.patch @@ -0,0 +1,27 @@ +From d02fa7ad4d506e6d543c820c2d0dc600170e9068 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 6 Feb 2022 20:22:26 -0500 +Subject: [PATCH] os: Add some exec.ProcessState stubs + +--- + src/os/exec.go | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/os/exec.go b/src/os/exec.go +index e31169241..030979b20 100644 +--- a/src/os/exec.go ++++ b/src/os/exec.go +@@ -34,6 +34,13 @@ func (p *ProcessState) Success() bool { + return false // TODO + } + ++// Sys returns system-dependent exit information about ++// the process. Convert it to the appropriate underlying ++// type, such as syscall.WaitStatus on Unix, to access its contents. ++func (p *ProcessState) Sys() interface{} { ++ return nil // TODO ++} ++ + // ExitCode returns the exit code of the exited process, or -1 + // if the process hasn't exited or was terminated by a signal. + func (p *ProcessState) ExitCode() int { diff --git a/2719.patch b/2719.patch new file mode 100644 index 0000000..ad7da91 --- /dev/null +++ b/2719.patch @@ -0,0 +1,93 @@ +From a33690aefdc8a1fb36f197d08b80e82b96ef872e Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Thu, 17 Mar 2022 09:53:28 -0700 +Subject: [PATCH] Implement getpagesize and munmap. For go 1.18. + +Signed-off-by: Elliott Sales de Andrade +--- + src/syscall/mmap_unix_test.go | 23 +++++++++++++++++++++++ + src/syscall/syscall_libc.go | 20 ++++++++++++++++++++ + 2 files changed, 43 insertions(+) + create mode 100644 src/syscall/mmap_unix_test.go + +diff --git a/src/syscall/mmap_unix_test.go b/src/syscall/mmap_unix_test.go +new file mode 100644 +index 00000000..d1303604 +--- /dev/null ++++ b/src/syscall/mmap_unix_test.go +@@ -0,0 +1,23 @@ ++// Copyright 2014 The Go Authors. All rights reserved. ++// Use of this source code is governed by a BSD-style ++// license that can be found in the LICENSE file. ++ ++//go:build darwin || linux ++// +build darwin linux ++ ++package syscall_test ++ ++import ( ++ "syscall" ++ "testing" ++) ++ ++func TestMmap(t *testing.T) { ++ b, err := syscall.Mmap(-1, 0, syscall.Getpagesize(), syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE) ++ if err != nil { ++ t.Fatalf("Mmap: %v", err) ++ } ++ if err := syscall.Munmap(b); err != nil { ++ t.Fatalf("Munmap: %v", err) ++ } ++} +diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go +index 27c95886..88ecad58 100644 +--- a/src/syscall/syscall_libc.go ++++ b/src/syscall/syscall_libc.go +@@ -217,6 +217,14 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e + return (*[1 << 30]byte)(addr)[:length:length], nil + } + ++func Munmap(b []byte) (err error) { ++ errCode := libc_munmap(unsafe.Pointer(&b[0]), uintptr(len(b))) ++ if errCode != 0 { ++ err = getErrno() ++ } ++ return err ++} ++ + func Mprotect(b []byte, prot int) (err error) { + errCode := libc_mprotect(unsafe.Pointer(&b[0]), uintptr(len(b)), int32(prot)) + if errCode != 0 { +@@ -225,6 +233,10 @@ func Mprotect(b []byte, prot int) (err error) { + return + } + ++func Getpagesize() int { ++ return int(libc_getpagesize()) ++} ++ + func Environ() []string { + environ := libc_environ + var envs []string +@@ -301,10 +313,18 @@ func libc_close(fd int32) int32 + //export mmap + func libc_mmap(addr unsafe.Pointer, length uintptr, prot, flags, fd int32, offset uintptr) unsafe.Pointer + ++// int munmap(void *addr, size_t length); ++//export munmap ++func libc_munmap(addr unsafe.Pointer, length uintptr) int32 ++ + // int mprotect(void *addr, size_t len, int prot); + //export mprotect + func libc_mprotect(addr unsafe.Pointer, len uintptr, prot int32) int32 + ++// int getpagesize(); ++//export getpagesize ++func libc_getpagesize() int32 ++ + // int chdir(const char *pathname, mode_t mode); + //export chdir + func libc_chdir(pathname *byte) int32 +-- +2.35.1 + diff --git a/2721.patch b/2721.patch new file mode 100644 index 0000000..94cfb77 --- /dev/null +++ b/2721.patch @@ -0,0 +1,24 @@ +From 055979e97725bae18bb046ac7ffc791dcf3043aa Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Fri, 18 Mar 2022 08:44:17 -0700 +Subject: [PATCH] compiler.go: createBuiltin: accept alias for slice. Helps + 1.18 tests pass. + +With proper fix by Ayke. +--- + compiler/compiler.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/compiler/compiler.go b/compiler/compiler.go +index 3e8f18da7..a10e51440 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -1233,7 +1233,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + case "cap": + value := argValues[0] + var llvmCap llvm.Value +- switch argTypes[0].(type) { ++ switch argTypes[0].Underlying().(type) { + case *types.Chan: + llvmCap = b.createRuntimeCall("chanCap", []llvm.Value{value}, "cap") + case *types.Slice: diff --git a/2722.patch b/2722.patch new file mode 100644 index 0000000..310bb82 --- /dev/null +++ b/2722.patch @@ -0,0 +1,36 @@ +From 9536bd3dfb178a681cb6134c9fdeff1555d17c8c Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Fri, 18 Mar 2022 09:23:35 -0700 +Subject: [PATCH] syscall: define MAP_SHARED and PROT_READ on wasi + +Makes 1.18 tests a little happier. + +Not sure mmap works on wasi, so these may be somewhat stubby. +--- + src/syscall/syscall_libc_wasi.go | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go +index cf556884d..3d4e8111d 100644 +--- a/src/syscall/syscall_libc_wasi.go ++++ b/src/syscall/syscall_libc_wasi.go +@@ -59,6 +59,19 @@ const ( + O_SYNC = __WASI_FDFLAGS_SYNC + + O_CLOEXEC = 0 ++ ++ // ../../lib/wasi-libc/sysroot/include/sys/mman.h ++ MAP_FILE = 0 ++ MAP_SHARED = 0x01 ++ MAP_PRIVATE = 0x02 ++ MAP_ANON = 0x20 ++ MAP_ANONYMOUS = MAP_ANON ++ ++ // ../../lib/wasi-libc/sysroot/include/sys/mman.h ++ PROT_NONE = 0 ++ PROT_READ = 1 ++ PROT_WRITE = 2 ++ PROT_EXEC = 4 + ) + + //go:extern errno diff --git a/2724.patch b/2724.patch new file mode 100644 index 0000000..691fa19 --- /dev/null +++ b/2724.patch @@ -0,0 +1,72 @@ +From a9c6940f91597525cd6b72cb051d4dd51845b76d Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Sat, 19 Mar 2022 11:22:09 -0700 +Subject: [PATCH] syscall: stub mmap(), munmap(), MAP_SHARED, PROT_READ, + SIGBUS, etc. on nonhosted targets + +Makes 1.18 tests a little happier. + +Works around this error: + +$ make test GOTESTFLAGS="-run TestTest/EmulatedCortexM3/Pass" +... +main_test.go:520: test error: could not compile: /usr/local/go/src/internal/fuzz/sys_posix.go:19:18: PROT_READ not declared by package syscall +--- + src/syscall/syscall_nonhosted.go | 30 ++++++++++++++++++++++++++++++ + 1 file changed, 30 insertions(+) + +diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go +index b63dc0b61..4a5585503 100644 +--- a/src/syscall/syscall_nonhosted.go ++++ b/src/syscall/syscall_nonhosted.go +@@ -27,6 +27,12 @@ const ( + SIGTRAP + SIGQUIT + SIGTERM ++ SIGILL ++ SIGABRT ++ SIGBUS ++ SIGFPE ++ SIGSEGV ++ SIGPIPE + ) + + func (s Signal) Signal() {} +@@ -66,6 +72,22 @@ const ( + O_CLOEXEC = 0 + ) + ++// Dummy values to allow compiling tests ++// Dummy source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/mman.h.auto.html ++const ( ++ PROT_NONE = 0x00 // no permissions ++ PROT_READ = 0x01 // pages can be read ++ PROT_WRITE = 0x02 // pages can be written ++ PROT_EXEC = 0x04 // pages can be executed ++ ++ MAP_SHARED = 0x0001 // share changes ++ MAP_PRIVATE = 0x0002 // changes are private ++ ++ MAP_FILE = 0x0000 // map from file (default) ++ MAP_ANON = 0x1000 // allocated from memory, swap space ++ MAP_ANONYMOUS = MAP_ANON ++) ++ + func runtime_envs() []string + + func Getenv(key string) (value string, found bool) { +@@ -168,6 +190,14 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, + return 0, ENOSYS + } + ++func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { ++ return nil, ENOSYS ++} ++ ++func Munmap(b []byte) (err error) { ++ return ENOSYS ++} ++ + type Timeval struct { + Sec int64 + Usec int64 diff --git a/2725.patch b/2725.patch new file mode 100644 index 0000000..de0048e --- /dev/null +++ b/2725.patch @@ -0,0 +1,409 @@ +From 1fa30d8654e0d140febfeefe539e61f92c19204a Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 5 Feb 2022 03:49:55 -0500 +Subject: [PATCH 1/2] Add a shim for internal/fuzz + +This simply shadows the real code temporarily to see what else is +broken. It only defines a single type to fix testing/internal/testdeps. +--- + loader/goroot.go | 1 + + src/internal/fuzz/fuzz.go | 133 ++++++++++++++++++++++++++++++++ + src/testing/fuzz.go | 143 +++++++++++++++++++++++++++++++++++ + src/testing/testing.go | 9 --- + src/testing/testing_go118.go | 16 ++++ + src/testing/testing_other.go | 16 ++++ + 6 files changed, 309 insertions(+), 9 deletions(-) + create mode 100644 src/internal/fuzz/fuzz.go + create mode 100644 src/testing/fuzz.go + create mode 100644 src/testing/testing_go118.go + create mode 100644 src/testing/testing_other.go + +diff --git a/loader/goroot.go b/loader/goroot.go +index 1ff7fa8d3..a012fc19f 100644 +--- a/loader/goroot.go ++++ b/loader/goroot.go +@@ -230,6 +230,7 @@ func pathsToOverride(needsSyscallPackage bool) map[string]bool { + "device/": false, + "examples/": false, + "internal/": true, ++ "internal/fuzz/": false, + "internal/bytealg/": false, + "internal/reflectlite/": false, + "internal/task/": false, +diff --git a/src/internal/fuzz/fuzz.go b/src/internal/fuzz/fuzz.go +new file mode 100644 +index 000000000..ee6e0544b +--- /dev/null ++++ b/src/internal/fuzz/fuzz.go +@@ -0,0 +1,133 @@ ++// Package fuzz is a shim to allow compilation against Go 1.18. ++// It only defines a single type to work with testing/internal/testdeps, ++// and hide all the other new dependencies from this package. ++package fuzz ++ ++import ( ++ "context" ++ "errors" ++ "io" ++ "reflect" ++ "time" ++) ++ ++// CorpusEntry represents an individual input for fuzzing. ++// ++// We must use an equivalent type in the testing and testing/internal/testdeps ++// packages, but testing can't import this package directly, and we don't want ++// to export this type from testing. Instead, we use the same struct type and ++// use a type alias (not a defined type) for convenience. ++type CorpusEntry = struct { ++ Parent string ++ ++ // Path is the path of the corpus file, if the entry was loaded from disk. ++ // For other entries, including seed values provided by f.Add, Path is the ++ // name of the test, e.g. seed#0 or its hash. ++ Path string ++ ++ // Data is the raw input data. Data should only be populated for seed ++ // values. For on-disk corpus files, Data will be nil, as it will be loaded ++ // from disk using Path. ++ Data []byte ++ ++ // Values is the unmarshaled values from a corpus file. ++ Values []any ++ ++ Generation int ++ ++ // IsSeed indicates whether this entry is part of the seed corpus. ++ IsSeed bool ++} ++ ++// CoordinateFuzzingOpts is a set of arguments for CoordinateFuzzing. ++// The zero value is valid for each field unless specified otherwise. ++type CoordinateFuzzingOpts struct { ++ // Log is a writer for logging progress messages and warnings. ++ // If nil, io.Discard will be used instead. ++ Log io.Writer ++ ++ // Timeout is the amount of wall clock time to spend fuzzing after the corpus ++ // has loaded. If zero, there will be no time limit. ++ Timeout time.Duration ++ ++ // Limit is the number of random values to generate and test. If zero, ++ // there will be no limit on the number of generated values. ++ Limit int64 ++ ++ // MinimizeTimeout is the amount of wall clock time to spend minimizing ++ // after discovering a crasher. If zero, there will be no time limit. If ++ // MinimizeTimeout and MinimizeLimit are both zero, then minimization will ++ // be disabled. ++ MinimizeTimeout time.Duration ++ ++ // MinimizeLimit is the maximum number of calls to the fuzz function to be ++ // made while minimizing after finding a crash. If zero, there will be no ++ // limit. Calls to the fuzz function made when minimizing also count toward ++ // Limit. If MinimizeTimeout and MinimizeLimit are both zero, then ++ // minimization will be disabled. ++ MinimizeLimit int64 ++ ++ // parallel is the number of worker processes to run in parallel. If zero, ++ // CoordinateFuzzing will run GOMAXPROCS workers. ++ Parallel int ++ ++ // Seed is a list of seed values added by the fuzz target with testing.F.Add ++ // and in testdata. ++ Seed []CorpusEntry ++ ++ // Types is the list of types which make up a corpus entry. ++ // Types must be set and must match values in Seed. ++ Types []reflect.Type ++ ++ // CorpusDir is a directory where files containing values that crash the ++ // code being tested may be written. CorpusDir must be set. ++ CorpusDir string ++ ++ // CacheDir is a directory containing additional "interesting" values. ++ // The fuzzer may derive new values from these, and may write new values here. ++ CacheDir string ++} ++ ++// CoordinateFuzzing creates several worker processes and communicates with ++// them to test random inputs that could trigger crashes and expose bugs. ++// The worker processes run the same binary in the same directory with the ++// same environment variables as the coordinator process. Workers also run ++// with the same arguments as the coordinator, except with the -test.fuzzworker ++// flag prepended to the argument list. ++// ++// If a crash occurs, the function will return an error containing information ++// about the crash, which can be reported to the user. ++func CoordinateFuzzing(ctx context.Context, opts CoordinateFuzzingOpts) (err error) { ++ return errors.New("not implemented") ++} ++ ++// ReadCorpus reads the corpus from the provided dir. The returned corpus ++// entries are guaranteed to match the given types. Any malformed files will ++// be saved in a MalformedCorpusError and returned, along with the most recent ++// error. ++func ReadCorpus(dir string, types []reflect.Type) ([]CorpusEntry, error) { ++ return nil, errors.New("not implemented") ++} ++ ++// CheckCorpus verifies that the types in vals match the expected types ++// provided. ++func CheckCorpus(vals []any, types []reflect.Type) error { ++ return errors.New("not implemented") ++} ++ ++func ResetCoverage() {} ++func SnapshotCoverage() {} ++ ++// RunFuzzWorker is called in a worker process to communicate with the ++// coordinator process in order to fuzz random inputs. RunFuzzWorker loops ++// until the coordinator tells it to stop. ++// ++// fn is a wrapper on the fuzz function. It may return an error to indicate ++// a given input "crashed". The coordinator will also record a crasher if ++// the function times out or terminates the process. ++// ++// RunFuzzWorker returns an error if it could not communicate with the ++// coordinator process. ++func RunFuzzWorker(ctx context.Context, fn func(CorpusEntry) error) error { ++ return errors.New("not implemented") ++} +diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go +new file mode 100644 +index 000000000..76ad6d945 +--- /dev/null ++++ b/src/testing/fuzz.go +@@ -0,0 +1,143 @@ ++package testing ++ ++import ( ++ "errors" ++ "fmt" ++ "reflect" ++ "time" ++) ++ ++// InternalFuzzTarget is an internal type but exported because it is ++// cross-package; it is part of the implementation of the "go test" command. ++type InternalFuzzTarget struct { ++ Name string ++ Fn func(f *F) ++} ++ ++// F is a type passed to fuzz tests. ++// ++// Fuzz tests run generated inputs against a provided fuzz target, which can ++// find and report potential bugs in the code being tested. ++// ++// A fuzz test runs the seed corpus by default, which includes entries provided ++// by (*F).Add and entries in the testdata/fuzz/ directory. After ++// any necessary setup and calls to (*F).Add, the fuzz test must then call ++// (*F).Fuzz to provide the fuzz target. See the testing package documentation ++// for an example, and see the F.Fuzz and F.Add method documentation for ++// details. ++// ++// *F methods can only be called before (*F).Fuzz. Once the test is ++// executing the fuzz target, only (*T) methods can be used. The only *F methods ++// that are allowed in the (*F).Fuzz function are (*F).Failed and (*F).Name. ++type F struct { ++ common ++ fuzzContext *fuzzContext ++ testContext *testContext ++ ++ // inFuzzFn is true when the fuzz function is running. Most F methods cannot ++ // be called when inFuzzFn is true. ++ inFuzzFn bool ++ ++ // corpus is a set of seed corpus entries, added with F.Add and loaded ++ // from testdata. ++ corpus []corpusEntry ++ ++ result fuzzResult ++ fuzzCalled bool ++} ++ ++// corpusEntry is an alias to the same type as internal/fuzz.CorpusEntry. ++// We use a type alias because we don't want to export this type, and we can't ++// import internal/fuzz from testing. ++type corpusEntry = struct { ++ Parent string ++ Path string ++ Data []byte ++ Values []interface{} ++ Generation int ++ IsSeed bool ++} ++ ++// Add will add the arguments to the seed corpus for the fuzz test. This will be ++// a no-op if called after or within the fuzz target, and args must match the ++// arguments for the fuzz target. ++func (f *F) Add(args ...interface{}) { ++ var values []interface{} ++ for i := range args { ++ if t := reflect.TypeOf(args[i]); !supportedTypes[t] { ++ panic(fmt.Sprintf("testing: unsupported type to Add %v", t)) ++ } ++ values = append(values, args[i]) ++ } ++ f.corpus = append(f.corpus, corpusEntry{Values: values, IsSeed: true, Path: fmt.Sprintf("seed#%d", len(f.corpus))}) ++} ++ ++// supportedTypes represents all of the supported types which can be fuzzed. ++var supportedTypes = map[reflect.Type]bool{ ++ reflect.TypeOf(([]byte)("")): true, ++ reflect.TypeOf((string)("")): true, ++ reflect.TypeOf((bool)(false)): true, ++ reflect.TypeOf((byte)(0)): true, ++ reflect.TypeOf((rune)(0)): true, ++ reflect.TypeOf((float32)(0)): true, ++ reflect.TypeOf((float64)(0)): true, ++ reflect.TypeOf((int)(0)): true, ++ reflect.TypeOf((int8)(0)): true, ++ reflect.TypeOf((int16)(0)): true, ++ reflect.TypeOf((int32)(0)): true, ++ reflect.TypeOf((int64)(0)): true, ++ reflect.TypeOf((uint)(0)): true, ++ reflect.TypeOf((uint8)(0)): true, ++ reflect.TypeOf((uint16)(0)): true, ++ reflect.TypeOf((uint32)(0)): true, ++ reflect.TypeOf((uint64)(0)): true, ++} ++ ++// Fuzz runs the fuzz function, ff, for fuzz testing. If ff fails for a set of ++// arguments, those arguments will be added to the seed corpus. ++// ++// ff must be a function with no return value whose first argument is *T and ++// whose remaining arguments are the types to be fuzzed. ++// For example: ++// ++// f.Fuzz(func(t *testing.T, b []byte, i int) { ... }) ++// ++// The following types are allowed: []byte, string, bool, byte, rune, float32, ++// float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64. ++// More types may be supported in the future. ++// ++// ff must not call any *F methods, e.g. (*F).Log, (*F).Error, (*F).Skip. Use ++// the corresponding *T method instead. The only *F methods that are allowed in ++// the (*F).Fuzz function are (*F).Failed and (*F).Name. ++// ++// This function should be fast and deterministic, and its behavior should not ++// depend on shared state. No mutatable input arguments, or pointers to them, ++// should be retained between executions of the fuzz function, as the memory ++// backing them may be mutated during a subsequent invocation. ff must not ++// modify the underlying data of the arguments provided by the fuzzing engine. ++// ++// When fuzzing, F.Fuzz does not return until a problem is found, time runs out ++// (set with -fuzztime), or the test process is interrupted by a signal. F.Fuzz ++// should be called exactly once, unless F.Skip or F.Fail is called beforehand. ++func (f *F) Fuzz(ff interface{}) { ++ f.failed = true ++ f.result.N = 0 ++ f.result.T = 0 ++ f.result.Error = errors.New("operation not implemented") ++ return ++} ++ ++// fuzzContext holds fields common to all fuzz tests. ++type fuzzContext struct { ++ deps testDeps ++ mode fuzzMode ++} ++ ++type fuzzMode uint8 ++ ++// fuzzResult contains the results of a fuzz run. ++type fuzzResult struct { ++ N int // The number of iterations. ++ T time.Duration // The total time taken. ++ Error error // Error is the error from the failing input ++} +diff --git a/src/testing/testing.go b/src/testing/testing.go +index 243632354..045ee5beb 100644 +--- a/src/testing/testing.go ++++ b/src/testing/testing.go +@@ -430,15 +430,6 @@ type testDeps interface { + MatchString(pat, str string) (bool, error) + } + +-func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M { +- Init() +- return &M{ +- Tests: tests, +- Benchmarks: benchmarks, +- deps: deps.(testDeps), +- } +-} +- + // Run runs the tests. It returns an exit code to pass to os.Exit. + func (m *M) Run() (code int) { + defer func() { +diff --git a/src/testing/testing_go118.go b/src/testing/testing_go118.go +new file mode 100644 +index 000000000..1c2c835be +--- /dev/null ++++ b/src/testing/testing_go118.go +@@ -0,0 +1,16 @@ ++//go:build go1.18 ++// +build go1.18 ++ ++package testing ++ ++// MainStart is meant for use by tests generated by 'go test'. ++// It is not meant to be called directly and is not subject to the Go 1 compatibility document. ++// It may change signature from release to release. ++func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, fuzzTargets []InternalFuzzTarget, examples []InternalExample) *M { ++ Init() ++ return &M{ ++ Tests: tests, ++ Benchmarks: benchmarks, ++ deps: deps.(testDeps), ++ } ++} +diff --git a/src/testing/testing_other.go b/src/testing/testing_other.go +new file mode 100644 +index 000000000..875115e96 +--- /dev/null ++++ b/src/testing/testing_other.go +@@ -0,0 +1,16 @@ ++//go:build !go1.18 ++// +build !go1.18 ++ ++package testing ++ ++// MainStart is meant for use by tests generated by 'go test'. ++// It is not meant to be called directly and is not subject to the Go 1 compatibility document. ++// It may change signature from release to release. ++func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M { ++ Init() ++ return &M{ ++ Tests: tests, ++ Benchmarks: benchmarks, ++ deps: deps.(testDeps), ++ } ++} + +From e06eb1de7cdb93a1960dcbde70394a8871985f80 Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Fri, 8 Apr 2022 08:20:28 -0700 +Subject: [PATCH 2/2] Allow building with go 1.18 + +--- + builder/config.go | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/builder/config.go b/builder/config.go +index fcfa55483..a19305075 100644 +--- a/builder/config.go ++++ b/builder/config.go +@@ -33,8 +33,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { + if err != nil { + return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) + } +- if major != 1 || minor < 15 || minor > 17 { +- return nil, fmt.Errorf("requires go version 1.15 through 1.17, got go%d.%d", major, minor) ++ if major != 1 || minor < 15 || minor > 18 { ++ return nil, fmt.Errorf("requires go version 1.15 through 1.18, got go%d.%d", major, minor) + } + + clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) diff --git a/2727.patch b/2727.patch new file mode 100644 index 0000000..4648f3d --- /dev/null +++ b/2727.patch @@ -0,0 +1,25 @@ +From beac72a66172b368a02124de2495ecf6663038ae Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 21 Mar 2022 03:29:53 -0400 +Subject: [PATCH] Add reflect.Value.FieldByIndexErr stub + +--- + src/reflect/value.go | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/reflect/value.go b/src/reflect/value.go +index d58ecba61..2ed9e5135 100644 +--- a/src/reflect/value.go ++++ b/src/reflect/value.go +@@ -861,6 +861,11 @@ func (v Value) FieldByIndex(index []int) Value { + panic("unimplemented: (reflect.Value).FieldByIndex()") + } + ++// FieldByIndexErr returns the nested field corresponding to index. ++func (v Value) FieldByIndexErr(index []int) (Value, error) { ++ return Value{}, &ValueError{Method: "FieldByIndexErr"} ++} ++ + func (v Value) FieldByName(name string) Value { + panic("unimplemented: (reflect.Value).FieldByName()") + } diff --git a/2729.patch b/2729.patch new file mode 100644 index 0000000..72b9a04 --- /dev/null +++ b/2729.patch @@ -0,0 +1,90 @@ +From 0ff12d7acf48307e68df2bcfb496e96871bbef08 Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Sat, 19 Mar 2022 13:22:32 -0700 +Subject: [PATCH 1/2] syscall: darwin: more complete list of signals + +Grepped straight out of the appropriate signal.h, with order and comments preserved verbatim. + +Makes 1.18 tests happier. +--- + src/syscall/syscall_libc_darwin.go | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go +index d3ec63763..770e71b58 100644 +--- a/src/syscall/syscall_libc_darwin.go ++++ b/src/syscall/syscall_libc_darwin.go +@@ -74,13 +74,20 @@ const ( + + type Signal int + ++// Source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/signal.h + const ( +- SIGCHLD Signal = 0x14 +- SIGINT Signal = 0x2 +- SIGKILL Signal = 0x9 +- SIGTRAP Signal = 0x5 +- SIGQUIT Signal = 0x3 +- SIGTERM Signal = 0xf ++ SIGINT Signal = 2 /* interrupt */ ++ SIGQUIT Signal = 3 /* quit */ ++ SIGILL Signal = 4 /* illegal instruction (not reset when caught) */ ++ SIGTRAP Signal = 5 /* trace trap (not reset when caught) */ ++ SIGABRT Signal = 6 /* abort() */ ++ SIGFPE Signal = 8 /* floating point exception */ ++ SIGKILL Signal = 9 /* kill (cannot be caught or ignored) */ ++ SIGBUS Signal = 10 /* bus error */ ++ SIGSEGV Signal = 11 /* segmentation violation */ ++ SIGPIPE Signal = 13 /* write on a pipe with no one to read it */ ++ SIGTERM Signal = 15 /* software termination signal from kill */ ++ SIGCHLD Signal = 20 /* to parent on child stop or exit */ + ) + + func (s Signal) Signal() {} + +From ab8581df54dc31c1951c72b62c4578520f4224aa Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Sat, 19 Mar 2022 13:25:30 -0700 +Subject: [PATCH 2/2] syscall: wasi: more complete list of signals + +Grepped straight out of the appropriate signal.h, with order preserved. + +Makes 1.18 tests happier. + +See comment on discrepancy for SIGCHLD. Since wasi doesn't really support signals, this may not matter. +--- + src/syscall/syscall_libc_wasi.go | 14 +++++++++++--- + 1 file changed, 11 insertions(+), 3 deletions(-) + +diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go +index 3d4e8111d..6bfab090f 100644 +--- a/src/syscall/syscall_libc_wasi.go ++++ b/src/syscall/syscall_libc_wasi.go +@@ -9,16 +9,24 @@ import ( + ) + + // https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt ++// disagrees with ../../lib/wasi-libc/libc-top-half/musl/arch/wasm32/bits/signal.h for SIGCHLD? ++// https://github.com/WebAssembly/wasi-libc/issues/271 + + type Signal int + + const ( +- SIGCHLD Signal = 16 + SIGINT Signal = 2 +- SIGKILL Signal = 9 +- SIGTRAP Signal = 5 + SIGQUIT Signal = 3 ++ SIGILL Signal = 4 ++ SIGTRAP Signal = 5 ++ SIGABRT Signal = 6 ++ SIGBUS Signal = 7 ++ SIGFPE Signal = 8 ++ SIGKILL Signal = 9 ++ SIGSEGV Signal = 11 ++ SIGPIPE Signal = 13 + SIGTERM Signal = 15 ++ SIGCHLD Signal = 17 + ) + + func (s Signal) Signal() {} diff --git a/2730.patch b/2730.patch new file mode 100644 index 0000000..455cf86 --- /dev/null +++ b/2730.patch @@ -0,0 +1,33 @@ +From b9f82f0196e081f8fea74520b5ee362b54927474 Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Sat, 19 Mar 2022 13:21:54 -0700 +Subject: [PATCH] syscall: stub WaitStatus + +--- + src/syscall/syscall_libc.go | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go +index c94c29cd1..bbc54888a 100644 +--- a/src/syscall/syscall_libc.go ++++ b/src/syscall/syscall_libc.go +@@ -157,6 +157,19 @@ func Pipe2(p []int, flags int) (err error) { + return ENOSYS // TODO + } + ++// TODO ++type WaitStatus uint32 ++ ++func (w WaitStatus) Exited() bool { return false } ++func (w WaitStatus) ExitStatus() int { return 0 } ++func (w WaitStatus) Signaled() bool { return false } ++func (w WaitStatus) Signal() Signal { return 0 } ++func (w WaitStatus) CoreDump() bool { return false } ++func (w WaitStatus) Stopped() bool { return false } ++func (w WaitStatus) Continued() bool { return false } ++func (w WaitStatus) StopSignal() Signal { return 0 } ++func (w WaitStatus) TrapCause() int { return 0 } ++ + func Getenv(key string) (value string, found bool) { + data := cstring(key) + raw := libc_getenv(&data[0]) diff --git a/2731.patch b/2731.patch new file mode 100644 index 0000000..e8608e2 --- /dev/null +++ b/2731.patch @@ -0,0 +1,170 @@ +From 71a0d01c36c0c01269ea6402f5fa0d7aa9ac8517 Mon Sep 17 00:00:00 2001 +From: Dan Kegel +Date: Sat, 19 Mar 2022 19:56:43 -0700 +Subject: [PATCH] main_test.go: fork testdata/testing.go for go 1.18 + +--- + main_test.go | 6 ++- + testdata/testing_go118.go | 100 +++++++++++++++++++++++++++++++++++++ + testdata/testing_go118.txt | 21 ++++++++ + 3 files changed, 126 insertions(+), 1 deletion(-) + create mode 100644 testdata/testing_go118.go + create mode 100644 testdata/testing_go118.txt + +diff --git a/main_test.go b/main_test.go +index 82c0b6110..b4210fd9b 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -66,7 +66,6 @@ func TestBuild(t *testing.T) { + "stdlib.go", + "string.go", + "structs.go", +- "testing.go", + "zeroalloc.go", + } + _, minor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) +@@ -76,6 +75,11 @@ func TestBuild(t *testing.T) { + if minor >= 17 { + tests = append(tests, "go1.17.go") + } ++ if minor >= 18 { ++ tests = append(tests, "testing_go118.go") ++ } else { ++ tests = append(tests, "testing.go") ++ } + + if *testTarget != "" { + // This makes it possible to run one specific test (instead of all), +diff --git a/testdata/testing_go118.go b/testdata/testing_go118.go +new file mode 100644 +index 000000000..4c1cf44ef +--- /dev/null ++++ b/testdata/testing_go118.go +@@ -0,0 +1,100 @@ ++package main ++ ++// TODO: also test the verbose version. ++ ++import ( ++ "errors" ++ "flag" ++ "io" ++ "strings" ++ "testing" ++) ++ ++func TestFoo(t *testing.T) { ++ t.Log("log Foo.a") ++ t.Log("log Foo.b") ++} ++ ++func TestBar(t *testing.T) { ++ t.Log("log Bar") ++ t.Log("log g\nh\ni\n") ++ t.Run("Bar1", func(t *testing.T) {}) ++ t.Run("Bar2", func(t *testing.T) { ++ t.Log("log Bar2\na\nb\nc") ++ t.Error("failed") ++ t.Log("after failed") ++ }) ++ t.Run("Bar3", func(t *testing.T) {}) ++ t.Log("log Bar end") ++} ++ ++func TestAllLowercase(t *testing.T) { ++ names := []string { ++ "alpha", ++ "BETA", ++ "gamma", ++ "BELTA", ++ } ++ ++ for _, name := range names { ++ t.Run(name, func(t *testing.T) { ++ if 'a' <= name[0] && name[0] <= 'a' { ++ t.Logf("expected lowercase name, and got one, so I'm happy") ++ } else { ++ t.Errorf("expected lowercase name, got %s", name) ++ } ++ }) ++ } ++} ++ ++var tests = []testing.InternalTest{ ++ {"TestFoo", TestFoo}, ++ {"TestBar", TestBar}, ++ {"TestAllLowercase", TestAllLowercase}, ++} ++ ++var benchmarks = []testing.InternalBenchmark{} ++ ++var fuzzes = []testing.InternalFuzzTarget{} ++ ++var examples = []testing.InternalExample{} ++ ++// A fake regexp matcher. ++// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full, ++// and lets tests pass on cortex-m. ++// Must match the one in src/testing/match.go that is substituted on bare-metal platforms, ++// or "make test" will fail there. ++func fakeMatchString(pat, str string) (bool, error) { ++ if pat == ".*" { ++ return true, nil ++ } ++ matched := strings.Contains(str, pat) ++ return matched, nil ++} ++ ++func main() { ++ testing.Init() ++ flag.Set("test.run", ".*/B") ++ m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, fuzzes, examples) ++ ++ exitcode := m.Run() ++ if exitcode != 0 { ++ println("exitcode:", exitcode) ++ } ++} ++ ++var errMain = errors.New("testing: unexpected use of func Main") ++ ++// matchStringOnly is part of upstream, and is used below to provide a dummy deps to pass to MainStart ++// so it can be run with go (tested with go 1.16) to provide a baseline for the regression test. ++// See c56cc9b3b57276. Unfortunately, testdeps is internal, so we can't just use &testdeps.TestDeps{}. ++type matchStringOnly func(pat, str string) (bool, error) ++ ++func (f matchStringOnly) MatchString(pat, str string) (bool, error) { return f(pat, str) } ++func (f matchStringOnly) StartCPUProfile(w io.Writer) error { return errMain } ++func (f matchStringOnly) StopCPUProfile() {} ++func (f matchStringOnly) WriteProfileTo(string, io.Writer, int) error { return errMain } ++func (f matchStringOnly) ImportPath() string { return "" } ++func (f matchStringOnly) StartTestLog(io.Writer) {} ++func (f matchStringOnly) StopTestLog() error { return errMain } ++func (f matchStringOnly) SetPanicOnExit0(bool) {} +diff --git a/testdata/testing_go118.txt b/testdata/testing_go118.txt +new file mode 100644 +index 000000000..6a8ee0591 +--- /dev/null ++++ b/testdata/testing_go118.txt +@@ -0,0 +1,21 @@ ++--- FAIL: TestBar (0.00s) ++ log Bar ++ log g ++ h ++ i ++ ++ --- FAIL: TestBar/Bar2 (0.00s) ++ log Bar2 ++ a ++ b ++ c ++ failed ++ after failed ++ log Bar end ++--- FAIL: TestAllLowercase (0.00s) ++ --- FAIL: TestAllLowercase/BETA (0.00s) ++ expected lowercase name, got BETA ++ --- FAIL: TestAllLowercase/BELTA (0.00s) ++ expected lowercase name, got BELTA ++FAIL ++exitcode: 1 diff --git a/2753.patch b/2753.patch new file mode 100644 index 0000000..da1ad60 --- /dev/null +++ b/2753.patch @@ -0,0 +1,280 @@ +From 0d544bf99353a1b1e2592d40094f6ace05d98e6c Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Wed, 6 Apr 2022 21:22:04 +0200 +Subject: [PATCH] compiler: fix difference in aliases in interface methods + +There used to be a difference between `byte` and `uint8` in interface +methods. These are aliases, so they should be treated the same. +This patch introduces a custom serialization format for types, +circumventing the `Type.String()` method that is slightly wrong for our +purposes. + +This also fixes an issue with the `any` keyword in Go 1.18, which +suffers from the same problem (but this time actually leads to a crash). +--- + compiler/interface.go | 124 +++++++++++++++++++++------------ + compiler/testdata/interface.ll | 2 +- + testdata/interface.go | 11 +++ + testdata/interface.txt | 1 + + transform/reflect.go | 36 +++++----- + 5 files changed, 110 insertions(+), 64 deletions(-) + +diff --git a/compiler/interface.go b/compiler/interface.go +index c8b76039dc..e98285a2a1 100644 +--- a/compiler/interface.go ++++ b/compiler/interface.go +@@ -152,6 +152,27 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { + return structGlobal + } + ++var basicTypes = [...]string{ ++ types.Bool: "bool", ++ types.Int: "int", ++ types.Int8: "int8", ++ types.Int16: "int16", ++ types.Int32: "int32", ++ types.Int64: "int64", ++ types.Uint: "uint", ++ types.Uint8: "uint8", ++ types.Uint16: "uint16", ++ types.Uint32: "uint32", ++ types.Uint64: "uint64", ++ types.Uintptr: "uintptr", ++ types.Float32: "float32", ++ types.Float64: "float64", ++ types.Complex64: "complex64", ++ types.Complex128: "complex128", ++ types.String: "string", ++ types.UnsafePointer: "unsafe.Pointer", ++} ++ + // getTypeCodeName returns a name for this type that can be used in the + // interface lowering pass to assign type codes as expected by the reflect + // package. See getTypeCodeNum. +@@ -162,48 +183,7 @@ func getTypeCodeName(t types.Type) string { + case *types.Array: + return "array:" + strconv.FormatInt(t.Len(), 10) + ":" + getTypeCodeName(t.Elem()) + case *types.Basic: +- var kind string +- switch t.Kind() { +- case types.Bool: +- kind = "bool" +- case types.Int: +- kind = "int" +- case types.Int8: +- kind = "int8" +- case types.Int16: +- kind = "int16" +- case types.Int32: +- kind = "int32" +- case types.Int64: +- kind = "int64" +- case types.Uint: +- kind = "uint" +- case types.Uint8: +- kind = "uint8" +- case types.Uint16: +- kind = "uint16" +- case types.Uint32: +- kind = "uint32" +- case types.Uint64: +- kind = "uint64" +- case types.Uintptr: +- kind = "uintptr" +- case types.Float32: +- kind = "float32" +- case types.Float64: +- kind = "float64" +- case types.Complex64: +- kind = "complex64" +- case types.Complex128: +- kind = "complex128" +- case types.String: +- kind = "string" +- case types.UnsafePointer: +- kind = "unsafeptr" +- default: +- panic("unknown basic type: " + t.Name()) +- } +- return "basic:" + kind ++ return "basic:" + basicTypes[t.Kind()] + case *types.Chan: + return "chan:" + getTypeCodeName(t.Elem()) + case *types.Interface: +@@ -591,23 +571,77 @@ func signature(sig *types.Signature) string { + if i > 0 { + s += ", " + } +- s += sig.Params().At(i).Type().String() ++ s += typestring(sig.Params().At(i).Type()) + } + s += ")" + } + if sig.Results().Len() == 0 { + // keep as-is + } else if sig.Results().Len() == 1 { +- s += " " + sig.Results().At(0).Type().String() ++ s += " " + typestring(sig.Results().At(0).Type()) + } else { + s += " (" + for i := 0; i < sig.Results().Len(); i++ { + if i > 0 { + s += ", " + } +- s += sig.Results().At(i).Type().String() ++ s += typestring(sig.Results().At(i).Type()) + } + s += ")" + } + return s + } ++ ++// typestring returns a stable (human-readable) type string for the given type ++// that can be used for interface equality checks. It is almost (but not ++// exactly) the same as calling t.String(). The main difference is some ++// normalization around `byte` vs `uint8` for example. ++func typestring(t types.Type) string { ++ // See: https://github.com/golang/go/blob/master/src/go/types/typestring.go ++ switch t := t.(type) { ++ case *types.Array: ++ return "[" + strconv.FormatInt(t.Len(), 10) + "]" + typestring(t.Elem()) ++ case *types.Basic: ++ return basicTypes[t.Kind()] ++ case *types.Chan: ++ switch t.Dir() { ++ case types.SendRecv: ++ return "chan (" + typestring(t.Elem()) + ")" ++ case types.SendOnly: ++ return "chan<- (" + typestring(t.Elem()) + ")" ++ case types.RecvOnly: ++ return "<-chan (" + typestring(t.Elem()) + ")" ++ default: ++ panic("unknown channel direction") ++ } ++ case *types.Interface: ++ methods := make([]string, t.NumMethods()) ++ for i := range methods { ++ method := t.Method(i) ++ methods[i] = method.Name() + signature(method.Type().(*types.Signature)) ++ } ++ return "interface{" + strings.Join(methods, ";") + "}" ++ case *types.Map: ++ return "map[" + typestring(t.Key()) + "]" + typestring(t.Elem()) ++ case *types.Named: ++ return t.String() ++ case *types.Pointer: ++ return "*" + typestring(t.Elem()) ++ case *types.Signature: ++ return "func" + signature(t) ++ case *types.Slice: ++ return "[]" + typestring(t.Elem()) ++ case *types.Struct: ++ fields := make([]string, t.NumFields()) ++ for i := range fields { ++ field := t.Field(i) ++ fields[i] = field.Name() + " " + typestring(field.Type()) ++ if tag := t.Tag(i); tag != "" { ++ fields[i] += " " + strconv.Quote(tag) ++ } ++ } ++ return "struct{" + strings.Join(fields, ";") + "}" ++ default: ++ panic("unknown type: " + t.String()) ++ } ++} +diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll +index b53297b7f8..0afbee0300 100644 +--- a/compiler/testdata/interface.ll ++++ b/compiler/testdata/interface.ll +@@ -128,5 +128,5 @@ declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke" + attributes #0 = { nounwind } + attributes #1 = { "tinygo-methods"="reflect/methods.Error() string" } + attributes #2 = { "tinygo-methods"="reflect/methods.String() string" } +-attributes #3 = { "tinygo-invoke"="main.$methods.foo(int) byte" "tinygo-methods"="reflect/methods.String() string; main.$methods.foo(int) byte" } ++attributes #3 = { "tinygo-invoke"="main.$methods.foo(int) uint8" "tinygo-methods"="reflect/methods.String() string; main.$methods.foo(int) uint8" } + attributes #4 = { "tinygo-invoke"="reflect/methods.Error() string" "tinygo-methods"="reflect/methods.Error() string" } +diff --git a/testdata/interface.go b/testdata/interface.go +index 0f66a30e5d..d13399f36b 100644 +--- a/testdata/interface.go ++++ b/testdata/interface.go +@@ -40,6 +40,9 @@ func main() { + // https://github.com/tinygo-org/tinygo/issues/453 + _, _ = itf.(Empty) + ++ var v Byter = FooByte(3) ++ println("Byte(): ", v.Byte()) ++ + var n int + var f float32 + var interfaceEqualTests = []struct { +@@ -266,3 +269,11 @@ type StaticBlocker interface { + } + + type Empty interface{} ++ ++type FooByte int ++ ++func (f FooByte) Byte() byte { return byte(f) } ++ ++type Byter interface { ++ Byte() uint8 ++} +diff --git a/testdata/interface.txt b/testdata/interface.txt +index 2c44269638..04e3fb9eac 100644 +--- a/testdata/interface.txt ++++ b/testdata/interface.txt +@@ -20,6 +20,7 @@ Stringer.String(): foo + Stringer.(*Thing).String(): foo + s has String() method: foo + nested switch: true ++Byte(): 3 + non-blocking call on sometimes-blocking interface + slept 1ms + slept 1ms +diff --git a/transform/reflect.go b/transform/reflect.go +index c4ecae777f..188b0a3c18 100644 +--- a/transform/reflect.go ++++ b/transform/reflect.go +@@ -40,24 +40,24 @@ import ( + // A list of basic types and their numbers. This list should be kept in sync + // with the list of Kind constants of type.go in the reflect package. + var basicTypes = map[string]int64{ +- "bool": 1, +- "int": 2, +- "int8": 3, +- "int16": 4, +- "int32": 5, +- "int64": 6, +- "uint": 7, +- "uint8": 8, +- "uint16": 9, +- "uint32": 10, +- "uint64": 11, +- "uintptr": 12, +- "float32": 13, +- "float64": 14, +- "complex64": 15, +- "complex128": 16, +- "string": 17, +- "unsafeptr": 18, ++ "bool": 1, ++ "int": 2, ++ "int8": 3, ++ "int16": 4, ++ "int32": 5, ++ "int64": 6, ++ "uint": 7, ++ "uint8": 8, ++ "uint16": 9, ++ "uint32": 10, ++ "uint64": 11, ++ "uintptr": 12, ++ "float32": 13, ++ "float64": 14, ++ "complex64": 15, ++ "complex128": 16, ++ "string": 17, ++ "unsafe.Pointer": 18, + } + + // A list of non-basic types. Adding 19 to this number will give the Kind as diff --git a/2763.patch b/2763.patch new file mode 100644 index 0000000..f3edc2b --- /dev/null +++ b/2763.patch @@ -0,0 +1,22 @@ +From a1c58d5d50cbf0a0d37909aa322eda31cfcda4c4 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 10 Apr 2022 16:13:40 -0400 +Subject: [PATCH] Fix incorrect formatting arguments + +--- + compiler/ircheck/check.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/compiler/ircheck/check.go b/compiler/ircheck/check.go +index bbedc6273..30c6ee172 100644 +--- a/compiler/ircheck/check.go ++++ b/compiler/ircheck/check.go +@@ -31,7 +31,7 @@ func (c *checker) checkType(t llvm.Type, checked map[llvm.Type]struct{}, special + return fmt.Errorf("type %q uses global context", t.String()) + default: + // we used some other context by accident +- return fmt.Errorf("type %q uses context %v instead of the main context %v", t.Context(), c.ctx) ++ return fmt.Errorf("type %q uses context %v instead of the main context %v", t.String(), t.Context(), c.ctx) + } + + // if this is a composite type, check the components of the type diff --git a/tinygo.spec b/tinygo.spec index 1c6a8be..37d8691 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -73,9 +73,44 @@ Patch0003: 0003-Use-system-mingw64-headers-and-crt.patch # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 Patch0004: 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +# https://github.com/tinygo-org/tinygo/pull/2608 Patch0005: 0005-Fix-LLVM-build-constraints.patch # Add Fedora specific dnf instructions Patch0006: 0006-Suggest-optional-packages-to-install-if-missing.patch +# Fix incorrect formatting arguments +Patch0007: https://github.com/tinygo-org/tinygo/pull/2763.patch + +# ################################ +# All remaining for fixing Go 1.18 +# ################################ +# Implement some missing Signal bits +Patch0008: https://github.com/tinygo-org/tinygo/pull/2615.patch +# src/os: add stubs for exec.ExitError and ProcessState.ExitCode +Patch0009: https://github.com/tinygo-org/tinygo/pull/2679.patch +# Rename reflect.Ptr to reflect.Pointer +Patch0010: https://github.com/tinygo-org/tinygo/pull/2715.patch +# os: Add some exec.ProcessState stubs +Patch0011: https://github.com/tinygo-org/tinygo/pull/2716.patch +# Implement getpagesize and munmap. For go 1.18. +Patch0012: https://github.com/tinygo-org/tinygo/pull/2719.patch +# compiler.go: createBuiltin: accept alias for slice. +Patch0013: https://github.com/tinygo-org/tinygo/pull/2721.patch +# syscall: define MAP_SHARED and PROT_READ on wasi +Patch0014: https://github.com/tinygo-org/tinygo/pull/2722.patch +# syscall: stub mmap(), MAP_SHARED, PROT_READ, SIGBUS, etc. on nonhosted targets +Patch0015: https://github.com/tinygo-org/tinygo/pull/2724.patch +# Support Go 1.18, updated +Patch0016: https://github.com/tinygo-org/tinygo/pull/2725.patch +# Add reflect.Value.FieldByIndexErr stub +Patch0017: https://github.com/tinygo-org/tinygo/pull/2727.patch +# syscall: define more signal numbers +Patch0018: https://github.com/tinygo-org/tinygo/pull/2729.patch +# syscall: stub WaitStatus +Patch0019: https://github.com/tinygo-org/tinygo/pull/2730.patch +# main_test.go: fork testdata/testing.go for go 1.18 +Patch0020: https://github.com/tinygo-org/tinygo/pull/2731.patch +# compiler: fix difference in aliases in interface methods +Patch0021: https://github.com/tinygo-org/tinygo/pull/2753.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -291,7 +326,7 @@ export GOPATH=%{buildroot}%{tinygoroot}:%{gopath} export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off export XDG_CACHE_HOME="${PWD}/$(mktemp -d tinygo.XXXXXX)" -%gocheck -v -t src -d tests/tinygotest +%gocheck -v -t src -t tests make smoketest STM32=0 XTENSA=0 %if %{fedora} > 35 %ifnarch %{ix86} aarch64 From b22e3707e9b158b7a87406855815df6c12a943a9 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 May 2022 18:19:15 -0400 Subject: [PATCH 32/78] Update to latest version (#2080579) --- .gitignore | 4 + ...ross-Linux-setup-on-non-amd64-arches.patch | 111 ----- ...-tests.patch => 0001-Skip-WASI-tests.patch | 12 +- ...2-Use-system-mingw64-headers-and-crt.patch | 23 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 18 +- ...ional-packages-to-install-if-missing.patch | 10 +- 0005-Fix-LLVM-build-constraints.patch | 78 ---- 0005-Skip-slice-copy-test-for-LLVM-14.patch | 50 +++ 2615.patch | 251 ----------- 2679.patch | 64 --- 2715.patch | 130 ------ 2716.patch | 27 -- 2719.patch | 93 ---- 2721.patch | 24 - 2722.patch | 36 -- 2724.patch | 72 --- 2725.patch | 409 ------------------ 2727.patch | 25 -- 2729.patch | 90 ---- 2730.patch | 33 -- 2731.patch | 170 -------- 2753.patch | 280 ------------ 2763.patch | 22 - sources | 6 +- tinygo.spec | 95 ++-- tstellar-gpg-key.asc | Bin 0 -> 2222 bytes 26 files changed, 125 insertions(+), 2008 deletions(-) delete mode 100644 0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch rename 0002-Skip-WASI-tests.patch => 0001-Skip-WASI-tests.patch (75%) rename 0003-Use-system-mingw64-headers-and-crt.patch => 0002-Use-system-mingw64-headers-and-crt.patch (88%) rename 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch => 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch (75%) rename 0006-Suggest-optional-packages-to-install-if-missing.patch => 0004-Suggest-optional-packages-to-install-if-missing.patch (91%) delete mode 100644 0005-Fix-LLVM-build-constraints.patch create mode 100644 0005-Skip-slice-copy-test-for-LLVM-14.patch delete mode 100644 2615.patch delete mode 100644 2679.patch delete mode 100644 2715.patch delete mode 100644 2716.patch delete mode 100644 2719.patch delete mode 100644 2721.patch delete mode 100644 2722.patch delete mode 100644 2724.patch delete mode 100644 2725.patch delete mode 100644 2727.patch delete mode 100644 2729.patch delete mode 100644 2730.patch delete mode 100644 2731.patch delete mode 100644 2753.patch delete mode 100644 2763.patch create mode 100644 tstellar-gpg-key.asc diff --git a/.gitignore b/.gitignore index 8d7bb30..77fb13a 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ /tinygo-0.22.0.tar.gz /musl-1.2.0.tar.gz /musl-1.2.0.tar.gz.asc +/tinygo-0.23.0.tar.gz +/compiler-rt-13.0.0.src.tar.xz.sig +/macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz +/compiler-rt-12.0.0.src.tar.xz.sig diff --git a/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch b/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch deleted file mode 100644 index 040ce02..0000000 --- a/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch +++ /dev/null @@ -1,111 +0,0 @@ -From a9406dd9dd992c8160372b07b4b0811fb9a6ffad Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 6 Feb 2022 23:26:25 -0500 -Subject: [PATCH 1/6] Fix cross-Linux setup on non-amd64 arches - -In that case, an emulator is needed for amd64, and tests should be run -_for_ amd64 as a cross test. - -Signed-off-by: Elliott Sales de Andrade ---- - compileopts/target.go | 19 ++++++++++++++----- - main_test.go | 39 +++++++++++++++++++++------------------ - 2 files changed, 35 insertions(+), 23 deletions(-) - -diff --git a/compileopts/target.go b/compileopts/target.go -index ffdf7365..9e341537 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -317,11 +317,20 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - if goarch != runtime.GOARCH { - // Some educated guesses as to how to invoke helper programs. - spec.GDB = []string{"gdb-multiarch"} -- if goarch == "arm" && goos == "linux" { -- spec.Emulator = []string{"qemu-arm"} -- } -- if goarch == "arm64" && goos == "linux" { -- spec.Emulator = []string{"qemu-aarch64"} -+ if goos == "linux" { -+ switch goarch { -+ case "386": -+ // amd64 can _usually_ run 32-bit programs, so skip the emulator in that case. -+ if runtime.GOARCH != "amd64" { -+ spec.Emulator = []string{"qemu-i386"} -+ } -+ case "amd64": -+ spec.Emulator = []string{"qemu-x86_64"} -+ case "arm": -+ spec.Emulator = []string{"qemu-arm"} -+ case "arm64": -+ spec.Emulator = []string{"qemu-aarch64"} -+ } - } - } - if goos != runtime.GOOS { -diff --git a/main_test.go b/main_test.go -index cf3fc989..82c0b611 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -31,6 +31,13 @@ const TESTDATA = "testdata" - - var testTarget = flag.String("target", "", "override test target") - -+var supportedLinuxArches = map[string]string{ -+ "AMD64Linux": "linux/amd64", -+ "X86Linux": "linux/386", -+ "ARMLinux": "linux/arm/6", -+ "ARM64Linux": "linux/arm64", -+} -+ - var sema = make(chan struct{}, runtime.NumCPU()) - - func TestBuild(t *testing.T) { -@@ -180,18 +187,14 @@ func TestBuild(t *testing.T) { - }) - - if runtime.GOOS == "linux" { -- t.Run("X86Linux", func(t *testing.T) { -- t.Parallel() -- runPlatTests(optionsFromOSARCH("linux/386", sema), tests, t) -- }) -- t.Run("ARMLinux", func(t *testing.T) { -- t.Parallel() -- runPlatTests(optionsFromOSARCH("linux/arm/6", sema), tests, t) -- }) -- t.Run("ARM64Linux", func(t *testing.T) { -- t.Parallel() -- runPlatTests(optionsFromOSARCH("linux/arm64", sema), tests, t) -- }) -+ for name, osArch := range supportedLinuxArches { -+ options := optionsFromOSARCH(osArch, sema) -+ if options.GOARCH != runtime.GOARCH { // Native architecture already run above. -+ t.Run(name, func(t *testing.T) { -+ runPlatTests(options, tests, t) -+ }) -+ } -+ } - t.Run("WebAssembly", func(t *testing.T) { - t.Parallel() - runPlatTests(optionsFromTarget("wasm", sema), tests, t) -@@ -475,12 +478,12 @@ func TestTest(t *testing.T) { - } - if !testing.Short() { - if runtime.GOOS == "linux" { -- targs = append(targs, -- // Linux -- targ{"X86Linux", optionsFromOSARCH("linux/386", sema)}, -- targ{"ARMLinux", optionsFromOSARCH("linux/arm/6", sema)}, -- targ{"ARM64Linux", optionsFromOSARCH("linux/arm64", sema)}, -- ) -+ for name, osArch := range supportedLinuxArches { -+ options := optionsFromOSARCH(osArch, sema) -+ if options.GOARCH != runtime.GOARCH { // Native architecture already run above. -+ targs = append(targs, targ{name, options}) -+ } -+ } - } - - targs = append(targs, --- -2.31.1 - diff --git a/0002-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch similarity index 75% rename from 0002-Skip-WASI-tests.patch rename to 0001-Skip-WASI-tests.patch index 63aa5e6..f404308 100644 --- a/0002-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 64af5a0ac7d93ad931737358c1af852e99fbf647 Mon Sep 17 00:00:00 2001 +From 8116847a5ef1b2127f8a0f178ae432dc41472454 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 2/6] Skip WASI tests. +Subject: [PATCH 1/5] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index 82c0b611..d9f440b0 100644 +index 3b088ada..dbbf7bfb 100644 --- a/main_test.go +++ b/main_test.go -@@ -199,10 +199,6 @@ func TestBuild(t *testing.T) { +@@ -201,10 +201,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -25,7 +25,7 @@ index 82c0b611..d9f440b0 100644 } } -@@ -493,7 +489,6 @@ func TestTest(t *testing.T) { +@@ -405,7 +401,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, @@ -34,5 +34,5 @@ index 82c0b611..d9f440b0 100644 } for _, targ := range targs { -- -2.31.1 +2.35.1 diff --git a/0003-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch similarity index 88% rename from 0003-Use-system-mingw64-headers-and-crt.patch rename to 0002-Use-system-mingw64-headers-and-crt.patch index 0d27d6f..4073f6c 100644 --- a/0003-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,16 +1,16 @@ -From 3d4375f7d44bfb3c865bdd460ad314ddf3de983d Mon Sep 17 00:00:00 2001 +From 67f561400614dfde114b31f4b08a340fa352939e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 3/6] Use system mingw64 headers and crt +Subject: [PATCH 2/5] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- - builder/mingw-w64.go | 66 +++---------------------------------------- + builder/mingw-w64.go | 68 ++++--------------------------------------- compileopts/config.go | 7 ++--- - 2 files changed, 6 insertions(+), 67 deletions(-) + 2 files changed, 7 insertions(+), 68 deletions(-) diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index bdab730f..07ce05c8 100644 +index 135cae94..d233068d 100644 --- a/builder/mingw-w64.go +++ b/builder/mingw-w64.go @@ -1,31 +1,11 @@ @@ -27,7 +27,7 @@ index bdab730f..07ce05c8 100644 ) var MinGW = Library{ - name: "mingw-w64", +- name: "mingw-w64", - makeHeaders: func(target, includeDir string) error { - // copy _mingw.h - srcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib", "mingw-w64") @@ -43,10 +43,11 @@ index bdab730f..07ce05c8 100644 - _, err = io.Copy(outf, inf) - return err - }, ++ name: "mingw-w64", + sourceDir: func() string { return "" }, // unused cflags: func(target, headerPath string) []string { // No flags necessary because there are no files to compile. - return nil -@@ -44,47 +24,9 @@ var MinGW = Library{ +@@ -45,47 +25,9 @@ var MinGW = Library{ // compile these files. func makeMinGWExtraLibs(tmpdir string) []*compileJob { var jobs []*compileJob @@ -98,10 +99,10 @@ index bdab730f..07ce05c8 100644 } return jobs diff --git a/compileopts/config.go b/compileopts/config.go -index f33a4b1a..b8dd4c93 100644 +index b30e653e..d5bfaa25 100644 --- a/compileopts/config.go +++ b/compileopts/config.go -@@ -248,12 +248,9 @@ func (c *Config) CFlags() []string { +@@ -306,12 +306,9 @@ func (c *Config) CFlags() []string { root := goenv.Get("TINYGOROOT") cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") case "mingw-w64": @@ -117,5 +118,5 @@ index f33a4b1a..b8dd4c93 100644 ) case "": -- -2.31.1 +2.35.1 diff --git a/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch similarity index 75% rename from 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename to 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index cf4b72f..b4b6750 100644 --- a/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 8c931c99e52b8dc080bdcb0a062f9ed189f4286d Mon Sep 17 00:00:00 2001 +From b9ac4d7d45fe7710f7f5264ab182d7a2a10ddace Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 4/6] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 3/5] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 28 insertions(+) diff --git a/main_test.go b/main_test.go -index d9f440b0..d3daddc3 100644 +index dbbf7bfb..4183c6b1 100644 --- a/main_test.go +++ b/main_test.go -@@ -246,6 +246,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -248,6 +248,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -38,7 +38,7 @@ index d9f440b0..d3daddc3 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -367,6 +381,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -334,6 +348,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } @@ -56,9 +56,9 @@ index d9f440b0..d3daddc3 100644 + } + } + - // Reserve CPU time for the test to run. - // This attempts to ensure that the test is not CPU-starved. - options.Semaphore <- struct{}{} + // putchar() prints CRLF, convert it to LF. + actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) + expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows -- -2.31.1 +2.35.1 diff --git a/0006-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch similarity index 91% rename from 0006-Suggest-optional-packages-to-install-if-missing.patch rename to 0004-Suggest-optional-packages-to-install-if-missing.patch index 6ec8b61..040bc2c 100644 --- a/0006-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From ca5254f583341c91a6fc5b77c8a515e00a4f63df Mon Sep 17 00:00:00 2001 +From 12016fd98fe0f0eb818f059a9b88465230817954 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 6/6] Suggest optional packages to install if missing +Subject: [PATCH 4/5] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -46,10 +46,10 @@ index 3d510974..d24a4165 100644 // doing anything. This can be useful where a *compileJob producing an output is // expected but nothing needs to be done, for example for a load from a cache. diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index 07ce05c8..76bf5806 100644 +index d233068d..d2539f6e 100644 --- a/builder/mingw-w64.go +++ b/builder/mingw-w64.go -@@ -26,7 +26,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob { +@@ -27,7 +27,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob { var jobs []*compileJob for _, name := range []string{"kernel32", "ucrt"} { outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) @@ -74,5 +74,5 @@ index 53d89bf0..e55719b2 100644 + return err } -- -2.31.1 +2.35.1 diff --git a/0005-Fix-LLVM-build-constraints.patch b/0005-Fix-LLVM-build-constraints.patch deleted file mode 100644 index dc5b54f..0000000 --- a/0005-Fix-LLVM-build-constraints.patch +++ /dev/null @@ -1,78 +0,0 @@ -From e4522f22aced375f1a80d5075326e66c71c9a524 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Wed, 2 Feb 2022 06:54:20 -0500 -Subject: [PATCH 5/6] Fix LLVM build constraints - -Signed-off-by: Elliott Sales de Andrade ---- - cgo/libclang_config_llvm11.go | 8 ++++---- - cgo/libclang_config_llvm12.go | 8 ++++---- - cgo/libclang_config_llvm13.go | 8 ++++---- - 3 files changed, 12 insertions(+), 12 deletions(-) - -diff --git a/cgo/libclang_config_llvm11.go b/cgo/libclang_config_llvm11.go -index 262303fb..1d89c9db 100644 ---- a/cgo/libclang_config_llvm11.go -+++ b/cgo/libclang_config_llvm11.go -@@ -5,12 +5,12 @@ package cgo - - /* - #cgo linux CFLAGS: -I/usr/lib/llvm-11/include --#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@11/include --#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include -+#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@11/include -+#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include - #cgo freebsd CFLAGS: -I/usr/local/llvm11/include - #cgo linux LDFLAGS: -L/usr/lib/llvm-11/lib -lclang --#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi --#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi -+#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi -+#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi - #cgo freebsd LDFLAGS: -L/usr/local/llvm11/lib -lclang - */ - import "C" -diff --git a/cgo/libclang_config_llvm12.go b/cgo/libclang_config_llvm12.go -index 69808d2e..7ccf7141 100644 ---- a/cgo/libclang_config_llvm12.go -+++ b/cgo/libclang_config_llvm12.go -@@ -5,12 +5,12 @@ package cgo - - /* - #cgo linux CFLAGS: -I/usr/lib/llvm-12/include --#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@12/include --#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include -+#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@12/include -+#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include - #cgo freebsd CFLAGS: -I/usr/local/llvm12/include - #cgo linux LDFLAGS: -L/usr/lib/llvm-12/lib -lclang --#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi --#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi -+#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi -+#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi - #cgo freebsd LDFLAGS: -L/usr/local/llvm12/lib -lclang - */ - import "C" -diff --git a/cgo/libclang_config_llvm13.go b/cgo/libclang_config_llvm13.go -index b27b0916..83d3f414 100644 ---- a/cgo/libclang_config_llvm13.go -+++ b/cgo/libclang_config_llvm13.go -@@ -5,12 +5,12 @@ package cgo - - /* - #cgo linux CFLAGS: -I/usr/lib/llvm-13/include --#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@13/include --#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include -+#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@13/include -+#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include - #cgo freebsd CFLAGS: -I/usr/local/llvm13/include - #cgo linux LDFLAGS: -L/usr/lib/llvm-13/lib -lclang --#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi --#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi -+#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi -+#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi - #cgo freebsd LDFLAGS: -L/usr/local/llvm13/lib -lclang - */ - import "C" --- -2.31.1 - diff --git a/0005-Skip-slice-copy-test-for-LLVM-14.patch b/0005-Skip-slice-copy-test-for-LLVM-14.patch new file mode 100644 index 0000000..17e4c8b --- /dev/null +++ b/0005-Skip-slice-copy-test-for-LLVM-14.patch @@ -0,0 +1,50 @@ +From e9592baa218826ca59faf7086838a923236baccb Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 7 May 2022 19:47:59 -0400 +Subject: [PATCH 5/5] Skip slice-copy test for LLVM < 14 + +Signed-off-by: Elliott Sales de Andrade +--- + interp/interp_test.go | 12 +++++++++++- + 1 file changed, 11 insertions(+), 1 deletion(-) + +diff --git a/interp/interp_test.go b/interp/interp_test.go +index ae2635af..a1bea65e 100644 +--- a/interp/interp_test.go ++++ b/interp/interp_test.go +@@ -3,6 +3,7 @@ package interp + import ( + "io/ioutil" + "os" ++ "strconv" + "strings" + "testing" + +@@ -10,6 +11,12 @@ import ( + ) + + func TestInterp(t *testing.T) { ++ llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) ++ if err != nil { ++ // Note: this should never happen and if it does, it will always happen ++ // for a particular build because llvm.Version is a constant. ++ panic(err) ++ } + for _, name := range []string{ + "basic", + "phi", +@@ -19,7 +26,10 @@ func TestInterp(t *testing.T) { + "revert", + "alloc", + } { +- name := name // make tc local to this closure ++ name := name // make local to this closure ++ if name == "slice-copy" && llvmVersion < 14 { ++ continue ++ } + t.Run(name, func(t *testing.T) { + t.Parallel() + runTest(t, "testdata/"+name) +-- +2.35.1 + diff --git a/2615.patch b/2615.patch deleted file mode 100644 index 92525f4..0000000 --- a/2615.patch +++ /dev/null @@ -1,251 +0,0 @@ -From 6e233f27d5249752da54697d6cd549467eee241f Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 5 Feb 2022 03:51:57 -0500 -Subject: [PATCH 1/4] Implement all of os.Signal in arch-specific syscall - -This is basically copied from `syscall_js.go` from the Go standard -library, since the existing parts were from there as well. ---- - src/syscall/syscall_libc_darwin.go | 15 +++++++++++++++ - src/syscall/syscall_libc_nintendoswitch.go | 18 ++++++++++++++++++ - src/syscall/syscall_libc_wasi.go | 15 +++++++++++++++ - src/syscall/syscall_nonhosted.go | 18 ++++++++++++++++++ - 4 files changed, 66 insertions(+) - -diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go -index ac89f74e5..d3ec63763 100644 ---- a/src/syscall/syscall_libc_darwin.go -+++ b/src/syscall/syscall_libc_darwin.go -@@ -4,6 +4,7 @@ - package syscall - - import ( -+ "internal/itoa" - "unsafe" - ) - -@@ -82,6 +83,20 @@ const ( - SIGTERM Signal = 0xf - ) - -+func (s Signal) Signal() {} -+ -+func (s Signal) String() string { -+ if 0 <= s && int(s) < len(signals) { -+ str := signals[s] -+ if str != "" { -+ return str -+ } -+ } -+ return "signal " + itoa.Itoa(int(s)) -+} -+ -+var signals = [...]string{} -+ - const ( - Stdin = 0 - Stdout = 1 -diff --git a/src/syscall/syscall_libc_nintendoswitch.go b/src/syscall/syscall_libc_nintendoswitch.go -index 876f125c2..98494643f 100644 ---- a/src/syscall/syscall_libc_nintendoswitch.go -+++ b/src/syscall/syscall_libc_nintendoswitch.go -@@ -3,6 +3,10 @@ - - package syscall - -+import ( -+ "internal/itoa" -+) -+ - // A Signal is a number describing a process signal. - // It implements the os.Signal interface. - type Signal int -@@ -17,6 +21,20 @@ const ( - SIGTERM - ) - -+func (s Signal) Signal() {} -+ -+func (s Signal) String() string { -+ if 0 <= s && int(s) < len(signals) { -+ str := signals[s] -+ if str != "" { -+ return str -+ } -+ } -+ return "signal " + itoa.Itoa(int(s)) -+} -+ -+var signals = [...]string{} -+ - // File system - - const ( -diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go -index a19420d77..c8c5dd0ab 100644 ---- a/src/syscall/syscall_libc_wasi.go -+++ b/src/syscall/syscall_libc_wasi.go -@@ -4,6 +4,7 @@ - package syscall - - import ( -+ "internal/itoa" - "unsafe" - ) - -@@ -20,6 +21,20 @@ const ( - SIGTERM = 15 - ) - -+func (s Signal) Signal() {} -+ -+func (s Signal) String() string { -+ if 0 <= s && int(s) < len(signals) { -+ str := signals[s] -+ if str != "" { -+ return str -+ } -+ } -+ return "signal " + itoa.Itoa(int(s)) -+} -+ -+var signals = [...]string{} -+ - const ( - Stdin = 0 - Stdout = 1 -diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go -index 2f590f2bd..b63dc0b61 100644 ---- a/src/syscall/syscall_nonhosted.go -+++ b/src/syscall/syscall_nonhosted.go -@@ -3,6 +3,10 @@ - - package syscall - -+import ( -+ "internal/itoa" -+) -+ - // Most code here has been copied from the Go sources: - // https://github.com/golang/go/blob/go1.12/src/syscall/syscall_js.go - // It has the following copyright note: -@@ -25,6 +29,20 @@ const ( - SIGTERM - ) - -+func (s Signal) Signal() {} -+ -+func (s Signal) String() string { -+ if 0 <= s && int(s) < len(signals) { -+ str := signals[s] -+ if str != "" { -+ return str -+ } -+ } -+ return "signal " + itoa.Itoa(int(s)) -+} -+ -+var signals = [...]string{} -+ - // File system - - const ( - -From eb32bc54653225424e0c05e7ca5c49a8108c3fa3 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 5 Feb 2022 06:18:33 -0500 -Subject: [PATCH 2/4] Add os Signal aliases - -These are used in Go 1.18's `testing/internal/testdeps`. Though the -comment says they should exist _everywhere_, there is still a build -constraint, but that seems to be fine. ---- - src/os/exec_posix.go | 22 ++++++++++++++++++++++ - 1 file changed, 22 insertions(+) - create mode 100644 src/os/exec_posix.go - -diff --git a/src/os/exec_posix.go b/src/os/exec_posix.go -new file mode 100644 -index 000000000..4d453099b ---- /dev/null -+++ b/src/os/exec_posix.go -@@ -0,0 +1,22 @@ -+// Copyright 2009 The Go Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style -+// license that can be found in the LICENSE file. -+ -+package os -+ -+//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris || windows -+// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris windows -+ -+import ( -+ "syscall" -+) -+ -+// The only signal values guaranteed to be present in the os package on all -+// systems are os.Interrupt (send the process an interrupt) and os.Kill (force -+// the process to exit). On Windows, sending os.Interrupt to a process with -+// os.Process.Signal is not implemented; it will return an error instead of -+// sending a signal. -+var ( -+ Interrupt Signal = syscall.SIGINT -+ Kill Signal = syscall.SIGKILL -+) - -From 6242cb26bffb9890030cc068e3f0920d558e9d8a Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 5 Feb 2022 19:18:38 -0500 -Subject: [PATCH 3/4] Add an empty os.Process.Signal implementation - -This fixes compile of tests in Go 1.18, due to its use in -`src/internal/testenv/testenv.go`. ---- - src/os/exec.go | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/os/exec.go b/src/os/exec.go -index 067be0de1..e78350b36 100644 ---- a/src/os/exec.go -+++ b/src/os/exec.go -@@ -49,3 +49,7 @@ func (p *Process) Wait() (*ProcessState, error) { - func (p *Process) Kill() error { - return ErrNotImplemented - } -+ -+func (p *Process) Signal(sig Signal) error { -+ return ErrNotImplemented -+} - -From 84963ecf4e26b4e063e6fc55abf5297da758877e Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 5 Feb 2022 20:44:26 -0500 -Subject: [PATCH 4/4] Fix type of Signal constants on WASI - ---- - src/syscall/syscall_libc_wasi.go | 12 ++++++------ - 1 file changed, 6 insertions(+), 6 deletions(-) - -diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go -index c8c5dd0ab..cf556884d 100644 ---- a/src/syscall/syscall_libc_wasi.go -+++ b/src/syscall/syscall_libc_wasi.go -@@ -13,12 +13,12 @@ import ( - type Signal int - - const ( -- SIGCHLD = 16 -- SIGINT = 2 -- SIGKILL = 9 -- SIGTRAP = 5 -- SIGQUIT = 3 -- SIGTERM = 15 -+ SIGCHLD Signal = 16 -+ SIGINT Signal = 2 -+ SIGKILL Signal = 9 -+ SIGTRAP Signal = 5 -+ SIGQUIT Signal = 3 -+ SIGTERM Signal = 15 - ) - - func (s Signal) Signal() {} diff --git a/2679.patch b/2679.patch deleted file mode 100644 index 1f61e96..0000000 --- a/2679.patch +++ /dev/null @@ -1,64 +0,0 @@ -From eba36ebe0cc3fdd6196c23a6dbaf617921afadf6 Mon Sep 17 00:00:00 2001 -From: ZauberNerd -Date: Fri, 4 Mar 2022 15:31:31 +0000 -Subject: [PATCH] src/os: add stubs for exec.ExitError and - ProcessState.ExitCode - -This commit adds stubs for the `ExitError` struct of the `exec` package -and `ProcessState.ExitCode()` of the `os` package. - -Since the `os/exec` is listed as unsupported, stubbing these methods -and structs should be enough to get programs that use these to compile. ---- - src/os/exec.go | 6 ++++++ - src/os/exec/exec.go | 24 ++++++++++++++++++++++++ - 2 files changed, 30 insertions(+) - create mode 100644 src/os/exec/exec.go - -diff --git a/src/os/exec.go b/src/os/exec.go -index 067be0de1..903daf484 100644 ---- a/src/os/exec.go -+++ b/src/os/exec.go -@@ -34,6 +34,12 @@ func (p *ProcessState) Success() bool { - return false // TODO - } - -+// ExitCode returns the exit code of the exited process, or -1 -+// if the process hasn't exited or was terminated by a signal. -+func (p *ProcessState) ExitCode() int { -+ return -1 // TODO -+} -+ - type Process struct { - Pid int - } -diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go -new file mode 100644 -index 000000000..afb445702 ---- /dev/null -+++ b/src/os/exec/exec.go -@@ -0,0 +1,24 @@ -+package exec -+ -+import "os" -+ -+// An ExitError reports an unsuccessful exit by a command. -+type ExitError struct { -+ *os.ProcessState -+ -+ // Stderr holds a subset of the standard error output from the -+ // Cmd.Output method if standard error was not otherwise being -+ // collected. -+ // -+ // If the error output is long, Stderr may contain only a prefix -+ // and suffix of the output, with the middle replaced with -+ // text about the number of omitted bytes. -+ // -+ // Stderr is provided for debugging, for inclusion in error messages. -+ // Users with other needs should redirect Cmd.Stderr as needed. -+ Stderr []byte -+} -+ -+func (e *ExitError) Error() string { -+ return e.ProcessState.String() -+} diff --git a/2715.patch b/2715.patch deleted file mode 100644 index c7cf943..0000000 --- a/2715.patch +++ /dev/null @@ -1,130 +0,0 @@ -From c697d75bc9970145e996686fbca79db7f8e6fb49 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Wed, 12 Jan 2022 01:55:54 -0500 -Subject: [PATCH] Rename reflect.Ptr to reflect.Pointer - -This was done in plain Go for 1.18: -https://github.com/golang/go/commit/17910ed4ff5a3cb3dcf4367d4af23ad5a7fe5809 - -Signed-off-by: Elliott Sales de Andrade ---- - src/reflect/type.go | 29 +++++++++++++++++------------ - 1 file changed, 17 insertions(+), 12 deletions(-) - -diff --git a/src/reflect/type.go b/src/reflect/type.go -index 4ead369b..87ebca5a 100644 ---- a/src/reflect/type.go -+++ b/src/reflect/type.go -@@ -18,7 +18,7 @@ import ( - // if set) and xxx contains the type kind number: - // 0 (0001): Chan - // 1 (0011): Interface --// 2 (0101): Ptr -+// 2 (0101): Pointer - // 3 (0111): Slice - // 4 (1001): Array - // 5 (1011): Func -@@ -54,7 +54,7 @@ const ( - UnsafePointer - Chan - Interface -- Ptr -+ Pointer - Slice - Array - Func -@@ -62,6 +62,9 @@ const ( - Struct - ) - -+// Ptr is the old name for the Pointer kind. -+const Ptr = Pointer -+ - func (k Kind) String() string { - switch k { - case Bool: -@@ -104,7 +107,7 @@ func (k Kind) String() string { - return "chan" - case Interface: - return "interface" -- case Ptr: -+ case Pointer: - return "ptr" - case Slice: - return "slice" -@@ -223,7 +226,7 @@ type Type interface { - // Chan: ChanDir, Elem - // Func: In, NumIn, Out, NumOut, IsVariadic. - // Map: Key, Elem -- // Ptr: Elem -+ // Pointer: Elem - // Slice: Elem - // Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField - -@@ -251,7 +254,7 @@ type Type interface { - //IsVariadic() bool - - // Elem returns a type's element type. -- // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice. -+ // It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice. - Elem() Type - - // Field returns a struct type's i'th field. -@@ -321,13 +324,15 @@ func TypeOf(i interface{}) Type { - return ValueOf(i).typecode - } - --func PtrTo(t Type) Type { -- if t.Kind() == Ptr { -+func PtrTo(t Type) Type { return PointerTo(t) } -+ -+func PointerTo(t Type) Type { -+ if t.Kind() == Pointer { - panic("reflect: cannot make **T type") - } - ptrType := t.(rawType)<<5 | 5 // 0b0101 == 5 - if ptrType>>5 != t { -- panic("reflect: PtrTo type does not fit") -+ panic("reflect: PointerTo type does not fit") - } - return ptrType - } -@@ -353,7 +358,7 @@ func (t rawType) Elem() Type { - - func (t rawType) elem() rawType { - switch t.Kind() { -- case Chan, Ptr, Slice: -+ case Chan, Pointer, Slice: - return t.stripPrefix() - case Array: - index := t.stripPrefix() -@@ -537,7 +542,7 @@ func (t rawType) Size() uintptr { - return 16 - case String: - return unsafe.Sizeof("") -- case UnsafePointer, Chan, Map, Ptr: -+ case UnsafePointer, Chan, Map, Pointer: - return unsafe.Sizeof(uintptr(0)) - case Slice: - return unsafe.Sizeof([]int{}) -@@ -586,7 +591,7 @@ func (t rawType) Align() int { - return int(unsafe.Alignof(complex128(0))) - case String: - return int(unsafe.Alignof("")) -- case UnsafePointer, Chan, Map, Ptr: -+ case UnsafePointer, Chan, Map, Pointer: - return int(unsafe.Alignof(uintptr(0))) - case Slice: - return int(unsafe.Alignof([]int(nil))) -@@ -652,7 +657,7 @@ func (t rawType) Comparable() bool { - return true - case Interface: - return true -- case Ptr: -+ case Pointer: - return true - case Slice: - return false --- -2.35.1 - diff --git a/2716.patch b/2716.patch deleted file mode 100644 index ea1ec5b..0000000 --- a/2716.patch +++ /dev/null @@ -1,27 +0,0 @@ -From d02fa7ad4d506e6d543c820c2d0dc600170e9068 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 6 Feb 2022 20:22:26 -0500 -Subject: [PATCH] os: Add some exec.ProcessState stubs - ---- - src/os/exec.go | 7 +++++++ - 1 file changed, 7 insertions(+) - -diff --git a/src/os/exec.go b/src/os/exec.go -index e31169241..030979b20 100644 ---- a/src/os/exec.go -+++ b/src/os/exec.go -@@ -34,6 +34,13 @@ func (p *ProcessState) Success() bool { - return false // TODO - } - -+// Sys returns system-dependent exit information about -+// the process. Convert it to the appropriate underlying -+// type, such as syscall.WaitStatus on Unix, to access its contents. -+func (p *ProcessState) Sys() interface{} { -+ return nil // TODO -+} -+ - // ExitCode returns the exit code of the exited process, or -1 - // if the process hasn't exited or was terminated by a signal. - func (p *ProcessState) ExitCode() int { diff --git a/2719.patch b/2719.patch deleted file mode 100644 index ad7da91..0000000 --- a/2719.patch +++ /dev/null @@ -1,93 +0,0 @@ -From a33690aefdc8a1fb36f197d08b80e82b96ef872e Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Thu, 17 Mar 2022 09:53:28 -0700 -Subject: [PATCH] Implement getpagesize and munmap. For go 1.18. - -Signed-off-by: Elliott Sales de Andrade ---- - src/syscall/mmap_unix_test.go | 23 +++++++++++++++++++++++ - src/syscall/syscall_libc.go | 20 ++++++++++++++++++++ - 2 files changed, 43 insertions(+) - create mode 100644 src/syscall/mmap_unix_test.go - -diff --git a/src/syscall/mmap_unix_test.go b/src/syscall/mmap_unix_test.go -new file mode 100644 -index 00000000..d1303604 ---- /dev/null -+++ b/src/syscall/mmap_unix_test.go -@@ -0,0 +1,23 @@ -+// Copyright 2014 The Go Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style -+// license that can be found in the LICENSE file. -+ -+//go:build darwin || linux -+// +build darwin linux -+ -+package syscall_test -+ -+import ( -+ "syscall" -+ "testing" -+) -+ -+func TestMmap(t *testing.T) { -+ b, err := syscall.Mmap(-1, 0, syscall.Getpagesize(), syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE) -+ if err != nil { -+ t.Fatalf("Mmap: %v", err) -+ } -+ if err := syscall.Munmap(b); err != nil { -+ t.Fatalf("Munmap: %v", err) -+ } -+} -diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go -index 27c95886..88ecad58 100644 ---- a/src/syscall/syscall_libc.go -+++ b/src/syscall/syscall_libc.go -@@ -217,6 +217,14 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e - return (*[1 << 30]byte)(addr)[:length:length], nil - } - -+func Munmap(b []byte) (err error) { -+ errCode := libc_munmap(unsafe.Pointer(&b[0]), uintptr(len(b))) -+ if errCode != 0 { -+ err = getErrno() -+ } -+ return err -+} -+ - func Mprotect(b []byte, prot int) (err error) { - errCode := libc_mprotect(unsafe.Pointer(&b[0]), uintptr(len(b)), int32(prot)) - if errCode != 0 { -@@ -225,6 +233,10 @@ func Mprotect(b []byte, prot int) (err error) { - return - } - -+func Getpagesize() int { -+ return int(libc_getpagesize()) -+} -+ - func Environ() []string { - environ := libc_environ - var envs []string -@@ -301,10 +313,18 @@ func libc_close(fd int32) int32 - //export mmap - func libc_mmap(addr unsafe.Pointer, length uintptr, prot, flags, fd int32, offset uintptr) unsafe.Pointer - -+// int munmap(void *addr, size_t length); -+//export munmap -+func libc_munmap(addr unsafe.Pointer, length uintptr) int32 -+ - // int mprotect(void *addr, size_t len, int prot); - //export mprotect - func libc_mprotect(addr unsafe.Pointer, len uintptr, prot int32) int32 - -+// int getpagesize(); -+//export getpagesize -+func libc_getpagesize() int32 -+ - // int chdir(const char *pathname, mode_t mode); - //export chdir - func libc_chdir(pathname *byte) int32 --- -2.35.1 - diff --git a/2721.patch b/2721.patch deleted file mode 100644 index 94cfb77..0000000 --- a/2721.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 055979e97725bae18bb046ac7ffc791dcf3043aa Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Fri, 18 Mar 2022 08:44:17 -0700 -Subject: [PATCH] compiler.go: createBuiltin: accept alias for slice. Helps - 1.18 tests pass. - -With proper fix by Ayke. ---- - compiler/compiler.go | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/compiler/compiler.go b/compiler/compiler.go -index 3e8f18da7..a10e51440 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -1233,7 +1233,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - case "cap": - value := argValues[0] - var llvmCap llvm.Value -- switch argTypes[0].(type) { -+ switch argTypes[0].Underlying().(type) { - case *types.Chan: - llvmCap = b.createRuntimeCall("chanCap", []llvm.Value{value}, "cap") - case *types.Slice: diff --git a/2722.patch b/2722.patch deleted file mode 100644 index 310bb82..0000000 --- a/2722.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 9536bd3dfb178a681cb6134c9fdeff1555d17c8c Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Fri, 18 Mar 2022 09:23:35 -0700 -Subject: [PATCH] syscall: define MAP_SHARED and PROT_READ on wasi - -Makes 1.18 tests a little happier. - -Not sure mmap works on wasi, so these may be somewhat stubby. ---- - src/syscall/syscall_libc_wasi.go | 13 +++++++++++++ - 1 file changed, 13 insertions(+) - -diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go -index cf556884d..3d4e8111d 100644 ---- a/src/syscall/syscall_libc_wasi.go -+++ b/src/syscall/syscall_libc_wasi.go -@@ -59,6 +59,19 @@ const ( - O_SYNC = __WASI_FDFLAGS_SYNC - - O_CLOEXEC = 0 -+ -+ // ../../lib/wasi-libc/sysroot/include/sys/mman.h -+ MAP_FILE = 0 -+ MAP_SHARED = 0x01 -+ MAP_PRIVATE = 0x02 -+ MAP_ANON = 0x20 -+ MAP_ANONYMOUS = MAP_ANON -+ -+ // ../../lib/wasi-libc/sysroot/include/sys/mman.h -+ PROT_NONE = 0 -+ PROT_READ = 1 -+ PROT_WRITE = 2 -+ PROT_EXEC = 4 - ) - - //go:extern errno diff --git a/2724.patch b/2724.patch deleted file mode 100644 index 691fa19..0000000 --- a/2724.patch +++ /dev/null @@ -1,72 +0,0 @@ -From a9c6940f91597525cd6b72cb051d4dd51845b76d Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Sat, 19 Mar 2022 11:22:09 -0700 -Subject: [PATCH] syscall: stub mmap(), munmap(), MAP_SHARED, PROT_READ, - SIGBUS, etc. on nonhosted targets - -Makes 1.18 tests a little happier. - -Works around this error: - -$ make test GOTESTFLAGS="-run TestTest/EmulatedCortexM3/Pass" -... -main_test.go:520: test error: could not compile: /usr/local/go/src/internal/fuzz/sys_posix.go:19:18: PROT_READ not declared by package syscall ---- - src/syscall/syscall_nonhosted.go | 30 ++++++++++++++++++++++++++++++ - 1 file changed, 30 insertions(+) - -diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go -index b63dc0b61..4a5585503 100644 ---- a/src/syscall/syscall_nonhosted.go -+++ b/src/syscall/syscall_nonhosted.go -@@ -27,6 +27,12 @@ const ( - SIGTRAP - SIGQUIT - SIGTERM -+ SIGILL -+ SIGABRT -+ SIGBUS -+ SIGFPE -+ SIGSEGV -+ SIGPIPE - ) - - func (s Signal) Signal() {} -@@ -66,6 +72,22 @@ const ( - O_CLOEXEC = 0 - ) - -+// Dummy values to allow compiling tests -+// Dummy source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/mman.h.auto.html -+const ( -+ PROT_NONE = 0x00 // no permissions -+ PROT_READ = 0x01 // pages can be read -+ PROT_WRITE = 0x02 // pages can be written -+ PROT_EXEC = 0x04 // pages can be executed -+ -+ MAP_SHARED = 0x0001 // share changes -+ MAP_PRIVATE = 0x0002 // changes are private -+ -+ MAP_FILE = 0x0000 // map from file (default) -+ MAP_ANON = 0x1000 // allocated from memory, swap space -+ MAP_ANONYMOUS = MAP_ANON -+) -+ - func runtime_envs() []string - - func Getenv(key string) (value string, found bool) { -@@ -168,6 +190,14 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, - return 0, ENOSYS - } - -+func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { -+ return nil, ENOSYS -+} -+ -+func Munmap(b []byte) (err error) { -+ return ENOSYS -+} -+ - type Timeval struct { - Sec int64 - Usec int64 diff --git a/2725.patch b/2725.patch deleted file mode 100644 index de0048e..0000000 --- a/2725.patch +++ /dev/null @@ -1,409 +0,0 @@ -From 1fa30d8654e0d140febfeefe539e61f92c19204a Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 5 Feb 2022 03:49:55 -0500 -Subject: [PATCH 1/2] Add a shim for internal/fuzz - -This simply shadows the real code temporarily to see what else is -broken. It only defines a single type to fix testing/internal/testdeps. ---- - loader/goroot.go | 1 + - src/internal/fuzz/fuzz.go | 133 ++++++++++++++++++++++++++++++++ - src/testing/fuzz.go | 143 +++++++++++++++++++++++++++++++++++ - src/testing/testing.go | 9 --- - src/testing/testing_go118.go | 16 ++++ - src/testing/testing_other.go | 16 ++++ - 6 files changed, 309 insertions(+), 9 deletions(-) - create mode 100644 src/internal/fuzz/fuzz.go - create mode 100644 src/testing/fuzz.go - create mode 100644 src/testing/testing_go118.go - create mode 100644 src/testing/testing_other.go - -diff --git a/loader/goroot.go b/loader/goroot.go -index 1ff7fa8d3..a012fc19f 100644 ---- a/loader/goroot.go -+++ b/loader/goroot.go -@@ -230,6 +230,7 @@ func pathsToOverride(needsSyscallPackage bool) map[string]bool { - "device/": false, - "examples/": false, - "internal/": true, -+ "internal/fuzz/": false, - "internal/bytealg/": false, - "internal/reflectlite/": false, - "internal/task/": false, -diff --git a/src/internal/fuzz/fuzz.go b/src/internal/fuzz/fuzz.go -new file mode 100644 -index 000000000..ee6e0544b ---- /dev/null -+++ b/src/internal/fuzz/fuzz.go -@@ -0,0 +1,133 @@ -+// Package fuzz is a shim to allow compilation against Go 1.18. -+// It only defines a single type to work with testing/internal/testdeps, -+// and hide all the other new dependencies from this package. -+package fuzz -+ -+import ( -+ "context" -+ "errors" -+ "io" -+ "reflect" -+ "time" -+) -+ -+// CorpusEntry represents an individual input for fuzzing. -+// -+// We must use an equivalent type in the testing and testing/internal/testdeps -+// packages, but testing can't import this package directly, and we don't want -+// to export this type from testing. Instead, we use the same struct type and -+// use a type alias (not a defined type) for convenience. -+type CorpusEntry = struct { -+ Parent string -+ -+ // Path is the path of the corpus file, if the entry was loaded from disk. -+ // For other entries, including seed values provided by f.Add, Path is the -+ // name of the test, e.g. seed#0 or its hash. -+ Path string -+ -+ // Data is the raw input data. Data should only be populated for seed -+ // values. For on-disk corpus files, Data will be nil, as it will be loaded -+ // from disk using Path. -+ Data []byte -+ -+ // Values is the unmarshaled values from a corpus file. -+ Values []any -+ -+ Generation int -+ -+ // IsSeed indicates whether this entry is part of the seed corpus. -+ IsSeed bool -+} -+ -+// CoordinateFuzzingOpts is a set of arguments for CoordinateFuzzing. -+// The zero value is valid for each field unless specified otherwise. -+type CoordinateFuzzingOpts struct { -+ // Log is a writer for logging progress messages and warnings. -+ // If nil, io.Discard will be used instead. -+ Log io.Writer -+ -+ // Timeout is the amount of wall clock time to spend fuzzing after the corpus -+ // has loaded. If zero, there will be no time limit. -+ Timeout time.Duration -+ -+ // Limit is the number of random values to generate and test. If zero, -+ // there will be no limit on the number of generated values. -+ Limit int64 -+ -+ // MinimizeTimeout is the amount of wall clock time to spend minimizing -+ // after discovering a crasher. If zero, there will be no time limit. If -+ // MinimizeTimeout and MinimizeLimit are both zero, then minimization will -+ // be disabled. -+ MinimizeTimeout time.Duration -+ -+ // MinimizeLimit is the maximum number of calls to the fuzz function to be -+ // made while minimizing after finding a crash. If zero, there will be no -+ // limit. Calls to the fuzz function made when minimizing also count toward -+ // Limit. If MinimizeTimeout and MinimizeLimit are both zero, then -+ // minimization will be disabled. -+ MinimizeLimit int64 -+ -+ // parallel is the number of worker processes to run in parallel. If zero, -+ // CoordinateFuzzing will run GOMAXPROCS workers. -+ Parallel int -+ -+ // Seed is a list of seed values added by the fuzz target with testing.F.Add -+ // and in testdata. -+ Seed []CorpusEntry -+ -+ // Types is the list of types which make up a corpus entry. -+ // Types must be set and must match values in Seed. -+ Types []reflect.Type -+ -+ // CorpusDir is a directory where files containing values that crash the -+ // code being tested may be written. CorpusDir must be set. -+ CorpusDir string -+ -+ // CacheDir is a directory containing additional "interesting" values. -+ // The fuzzer may derive new values from these, and may write new values here. -+ CacheDir string -+} -+ -+// CoordinateFuzzing creates several worker processes and communicates with -+// them to test random inputs that could trigger crashes and expose bugs. -+// The worker processes run the same binary in the same directory with the -+// same environment variables as the coordinator process. Workers also run -+// with the same arguments as the coordinator, except with the -test.fuzzworker -+// flag prepended to the argument list. -+// -+// If a crash occurs, the function will return an error containing information -+// about the crash, which can be reported to the user. -+func CoordinateFuzzing(ctx context.Context, opts CoordinateFuzzingOpts) (err error) { -+ return errors.New("not implemented") -+} -+ -+// ReadCorpus reads the corpus from the provided dir. The returned corpus -+// entries are guaranteed to match the given types. Any malformed files will -+// be saved in a MalformedCorpusError and returned, along with the most recent -+// error. -+func ReadCorpus(dir string, types []reflect.Type) ([]CorpusEntry, error) { -+ return nil, errors.New("not implemented") -+} -+ -+// CheckCorpus verifies that the types in vals match the expected types -+// provided. -+func CheckCorpus(vals []any, types []reflect.Type) error { -+ return errors.New("not implemented") -+} -+ -+func ResetCoverage() {} -+func SnapshotCoverage() {} -+ -+// RunFuzzWorker is called in a worker process to communicate with the -+// coordinator process in order to fuzz random inputs. RunFuzzWorker loops -+// until the coordinator tells it to stop. -+// -+// fn is a wrapper on the fuzz function. It may return an error to indicate -+// a given input "crashed". The coordinator will also record a crasher if -+// the function times out or terminates the process. -+// -+// RunFuzzWorker returns an error if it could not communicate with the -+// coordinator process. -+func RunFuzzWorker(ctx context.Context, fn func(CorpusEntry) error) error { -+ return errors.New("not implemented") -+} -diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go -new file mode 100644 -index 000000000..76ad6d945 ---- /dev/null -+++ b/src/testing/fuzz.go -@@ -0,0 +1,143 @@ -+package testing -+ -+import ( -+ "errors" -+ "fmt" -+ "reflect" -+ "time" -+) -+ -+// InternalFuzzTarget is an internal type but exported because it is -+// cross-package; it is part of the implementation of the "go test" command. -+type InternalFuzzTarget struct { -+ Name string -+ Fn func(f *F) -+} -+ -+// F is a type passed to fuzz tests. -+// -+// Fuzz tests run generated inputs against a provided fuzz target, which can -+// find and report potential bugs in the code being tested. -+// -+// A fuzz test runs the seed corpus by default, which includes entries provided -+// by (*F).Add and entries in the testdata/fuzz/ directory. After -+// any necessary setup and calls to (*F).Add, the fuzz test must then call -+// (*F).Fuzz to provide the fuzz target. See the testing package documentation -+// for an example, and see the F.Fuzz and F.Add method documentation for -+// details. -+// -+// *F methods can only be called before (*F).Fuzz. Once the test is -+// executing the fuzz target, only (*T) methods can be used. The only *F methods -+// that are allowed in the (*F).Fuzz function are (*F).Failed and (*F).Name. -+type F struct { -+ common -+ fuzzContext *fuzzContext -+ testContext *testContext -+ -+ // inFuzzFn is true when the fuzz function is running. Most F methods cannot -+ // be called when inFuzzFn is true. -+ inFuzzFn bool -+ -+ // corpus is a set of seed corpus entries, added with F.Add and loaded -+ // from testdata. -+ corpus []corpusEntry -+ -+ result fuzzResult -+ fuzzCalled bool -+} -+ -+// corpusEntry is an alias to the same type as internal/fuzz.CorpusEntry. -+// We use a type alias because we don't want to export this type, and we can't -+// import internal/fuzz from testing. -+type corpusEntry = struct { -+ Parent string -+ Path string -+ Data []byte -+ Values []interface{} -+ Generation int -+ IsSeed bool -+} -+ -+// Add will add the arguments to the seed corpus for the fuzz test. This will be -+// a no-op if called after or within the fuzz target, and args must match the -+// arguments for the fuzz target. -+func (f *F) Add(args ...interface{}) { -+ var values []interface{} -+ for i := range args { -+ if t := reflect.TypeOf(args[i]); !supportedTypes[t] { -+ panic(fmt.Sprintf("testing: unsupported type to Add %v", t)) -+ } -+ values = append(values, args[i]) -+ } -+ f.corpus = append(f.corpus, corpusEntry{Values: values, IsSeed: true, Path: fmt.Sprintf("seed#%d", len(f.corpus))}) -+} -+ -+// supportedTypes represents all of the supported types which can be fuzzed. -+var supportedTypes = map[reflect.Type]bool{ -+ reflect.TypeOf(([]byte)("")): true, -+ reflect.TypeOf((string)("")): true, -+ reflect.TypeOf((bool)(false)): true, -+ reflect.TypeOf((byte)(0)): true, -+ reflect.TypeOf((rune)(0)): true, -+ reflect.TypeOf((float32)(0)): true, -+ reflect.TypeOf((float64)(0)): true, -+ reflect.TypeOf((int)(0)): true, -+ reflect.TypeOf((int8)(0)): true, -+ reflect.TypeOf((int16)(0)): true, -+ reflect.TypeOf((int32)(0)): true, -+ reflect.TypeOf((int64)(0)): true, -+ reflect.TypeOf((uint)(0)): true, -+ reflect.TypeOf((uint8)(0)): true, -+ reflect.TypeOf((uint16)(0)): true, -+ reflect.TypeOf((uint32)(0)): true, -+ reflect.TypeOf((uint64)(0)): true, -+} -+ -+// Fuzz runs the fuzz function, ff, for fuzz testing. If ff fails for a set of -+// arguments, those arguments will be added to the seed corpus. -+// -+// ff must be a function with no return value whose first argument is *T and -+// whose remaining arguments are the types to be fuzzed. -+// For example: -+// -+// f.Fuzz(func(t *testing.T, b []byte, i int) { ... }) -+// -+// The following types are allowed: []byte, string, bool, byte, rune, float32, -+// float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64. -+// More types may be supported in the future. -+// -+// ff must not call any *F methods, e.g. (*F).Log, (*F).Error, (*F).Skip. Use -+// the corresponding *T method instead. The only *F methods that are allowed in -+// the (*F).Fuzz function are (*F).Failed and (*F).Name. -+// -+// This function should be fast and deterministic, and its behavior should not -+// depend on shared state. No mutatable input arguments, or pointers to them, -+// should be retained between executions of the fuzz function, as the memory -+// backing them may be mutated during a subsequent invocation. ff must not -+// modify the underlying data of the arguments provided by the fuzzing engine. -+// -+// When fuzzing, F.Fuzz does not return until a problem is found, time runs out -+// (set with -fuzztime), or the test process is interrupted by a signal. F.Fuzz -+// should be called exactly once, unless F.Skip or F.Fail is called beforehand. -+func (f *F) Fuzz(ff interface{}) { -+ f.failed = true -+ f.result.N = 0 -+ f.result.T = 0 -+ f.result.Error = errors.New("operation not implemented") -+ return -+} -+ -+// fuzzContext holds fields common to all fuzz tests. -+type fuzzContext struct { -+ deps testDeps -+ mode fuzzMode -+} -+ -+type fuzzMode uint8 -+ -+// fuzzResult contains the results of a fuzz run. -+type fuzzResult struct { -+ N int // The number of iterations. -+ T time.Duration // The total time taken. -+ Error error // Error is the error from the failing input -+} -diff --git a/src/testing/testing.go b/src/testing/testing.go -index 243632354..045ee5beb 100644 ---- a/src/testing/testing.go -+++ b/src/testing/testing.go -@@ -430,15 +430,6 @@ type testDeps interface { - MatchString(pat, str string) (bool, error) - } - --func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M { -- Init() -- return &M{ -- Tests: tests, -- Benchmarks: benchmarks, -- deps: deps.(testDeps), -- } --} -- - // Run runs the tests. It returns an exit code to pass to os.Exit. - func (m *M) Run() (code int) { - defer func() { -diff --git a/src/testing/testing_go118.go b/src/testing/testing_go118.go -new file mode 100644 -index 000000000..1c2c835be ---- /dev/null -+++ b/src/testing/testing_go118.go -@@ -0,0 +1,16 @@ -+//go:build go1.18 -+// +build go1.18 -+ -+package testing -+ -+// MainStart is meant for use by tests generated by 'go test'. -+// It is not meant to be called directly and is not subject to the Go 1 compatibility document. -+// It may change signature from release to release. -+func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, fuzzTargets []InternalFuzzTarget, examples []InternalExample) *M { -+ Init() -+ return &M{ -+ Tests: tests, -+ Benchmarks: benchmarks, -+ deps: deps.(testDeps), -+ } -+} -diff --git a/src/testing/testing_other.go b/src/testing/testing_other.go -new file mode 100644 -index 000000000..875115e96 ---- /dev/null -+++ b/src/testing/testing_other.go -@@ -0,0 +1,16 @@ -+//go:build !go1.18 -+// +build !go1.18 -+ -+package testing -+ -+// MainStart is meant for use by tests generated by 'go test'. -+// It is not meant to be called directly and is not subject to the Go 1 compatibility document. -+// It may change signature from release to release. -+func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M { -+ Init() -+ return &M{ -+ Tests: tests, -+ Benchmarks: benchmarks, -+ deps: deps.(testDeps), -+ } -+} - -From e06eb1de7cdb93a1960dcbde70394a8871985f80 Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Fri, 8 Apr 2022 08:20:28 -0700 -Subject: [PATCH 2/2] Allow building with go 1.18 - ---- - builder/config.go | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/builder/config.go b/builder/config.go -index fcfa55483..a19305075 100644 ---- a/builder/config.go -+++ b/builder/config.go -@@ -33,8 +33,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { - if err != nil { - return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) - } -- if major != 1 || minor < 15 || minor > 17 { -- return nil, fmt.Errorf("requires go version 1.15 through 1.17, got go%d.%d", major, minor) -+ if major != 1 || minor < 15 || minor > 18 { -+ return nil, fmt.Errorf("requires go version 1.15 through 1.18, got go%d.%d", major, minor) - } - - clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) diff --git a/2727.patch b/2727.patch deleted file mode 100644 index 4648f3d..0000000 --- a/2727.patch +++ /dev/null @@ -1,25 +0,0 @@ -From beac72a66172b368a02124de2495ecf6663038ae Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 21 Mar 2022 03:29:53 -0400 -Subject: [PATCH] Add reflect.Value.FieldByIndexErr stub - ---- - src/reflect/value.go | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/reflect/value.go b/src/reflect/value.go -index d58ecba61..2ed9e5135 100644 ---- a/src/reflect/value.go -+++ b/src/reflect/value.go -@@ -861,6 +861,11 @@ func (v Value) FieldByIndex(index []int) Value { - panic("unimplemented: (reflect.Value).FieldByIndex()") - } - -+// FieldByIndexErr returns the nested field corresponding to index. -+func (v Value) FieldByIndexErr(index []int) (Value, error) { -+ return Value{}, &ValueError{Method: "FieldByIndexErr"} -+} -+ - func (v Value) FieldByName(name string) Value { - panic("unimplemented: (reflect.Value).FieldByName()") - } diff --git a/2729.patch b/2729.patch deleted file mode 100644 index 72b9a04..0000000 --- a/2729.patch +++ /dev/null @@ -1,90 +0,0 @@ -From 0ff12d7acf48307e68df2bcfb496e96871bbef08 Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Sat, 19 Mar 2022 13:22:32 -0700 -Subject: [PATCH 1/2] syscall: darwin: more complete list of signals - -Grepped straight out of the appropriate signal.h, with order and comments preserved verbatim. - -Makes 1.18 tests happier. ---- - src/syscall/syscall_libc_darwin.go | 19 +++++++++++++------ - 1 file changed, 13 insertions(+), 6 deletions(-) - -diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go -index d3ec63763..770e71b58 100644 ---- a/src/syscall/syscall_libc_darwin.go -+++ b/src/syscall/syscall_libc_darwin.go -@@ -74,13 +74,20 @@ const ( - - type Signal int - -+// Source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/signal.h - const ( -- SIGCHLD Signal = 0x14 -- SIGINT Signal = 0x2 -- SIGKILL Signal = 0x9 -- SIGTRAP Signal = 0x5 -- SIGQUIT Signal = 0x3 -- SIGTERM Signal = 0xf -+ SIGINT Signal = 2 /* interrupt */ -+ SIGQUIT Signal = 3 /* quit */ -+ SIGILL Signal = 4 /* illegal instruction (not reset when caught) */ -+ SIGTRAP Signal = 5 /* trace trap (not reset when caught) */ -+ SIGABRT Signal = 6 /* abort() */ -+ SIGFPE Signal = 8 /* floating point exception */ -+ SIGKILL Signal = 9 /* kill (cannot be caught or ignored) */ -+ SIGBUS Signal = 10 /* bus error */ -+ SIGSEGV Signal = 11 /* segmentation violation */ -+ SIGPIPE Signal = 13 /* write on a pipe with no one to read it */ -+ SIGTERM Signal = 15 /* software termination signal from kill */ -+ SIGCHLD Signal = 20 /* to parent on child stop or exit */ - ) - - func (s Signal) Signal() {} - -From ab8581df54dc31c1951c72b62c4578520f4224aa Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Sat, 19 Mar 2022 13:25:30 -0700 -Subject: [PATCH 2/2] syscall: wasi: more complete list of signals - -Grepped straight out of the appropriate signal.h, with order preserved. - -Makes 1.18 tests happier. - -See comment on discrepancy for SIGCHLD. Since wasi doesn't really support signals, this may not matter. ---- - src/syscall/syscall_libc_wasi.go | 14 +++++++++++--- - 1 file changed, 11 insertions(+), 3 deletions(-) - -diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go -index 3d4e8111d..6bfab090f 100644 ---- a/src/syscall/syscall_libc_wasi.go -+++ b/src/syscall/syscall_libc_wasi.go -@@ -9,16 +9,24 @@ import ( - ) - - // https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt -+// disagrees with ../../lib/wasi-libc/libc-top-half/musl/arch/wasm32/bits/signal.h for SIGCHLD? -+// https://github.com/WebAssembly/wasi-libc/issues/271 - - type Signal int - - const ( -- SIGCHLD Signal = 16 - SIGINT Signal = 2 -- SIGKILL Signal = 9 -- SIGTRAP Signal = 5 - SIGQUIT Signal = 3 -+ SIGILL Signal = 4 -+ SIGTRAP Signal = 5 -+ SIGABRT Signal = 6 -+ SIGBUS Signal = 7 -+ SIGFPE Signal = 8 -+ SIGKILL Signal = 9 -+ SIGSEGV Signal = 11 -+ SIGPIPE Signal = 13 - SIGTERM Signal = 15 -+ SIGCHLD Signal = 17 - ) - - func (s Signal) Signal() {} diff --git a/2730.patch b/2730.patch deleted file mode 100644 index 455cf86..0000000 --- a/2730.patch +++ /dev/null @@ -1,33 +0,0 @@ -From b9f82f0196e081f8fea74520b5ee362b54927474 Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Sat, 19 Mar 2022 13:21:54 -0700 -Subject: [PATCH] syscall: stub WaitStatus - ---- - src/syscall/syscall_libc.go | 13 +++++++++++++ - 1 file changed, 13 insertions(+) - -diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go -index c94c29cd1..bbc54888a 100644 ---- a/src/syscall/syscall_libc.go -+++ b/src/syscall/syscall_libc.go -@@ -157,6 +157,19 @@ func Pipe2(p []int, flags int) (err error) { - return ENOSYS // TODO - } - -+// TODO -+type WaitStatus uint32 -+ -+func (w WaitStatus) Exited() bool { return false } -+func (w WaitStatus) ExitStatus() int { return 0 } -+func (w WaitStatus) Signaled() bool { return false } -+func (w WaitStatus) Signal() Signal { return 0 } -+func (w WaitStatus) CoreDump() bool { return false } -+func (w WaitStatus) Stopped() bool { return false } -+func (w WaitStatus) Continued() bool { return false } -+func (w WaitStatus) StopSignal() Signal { return 0 } -+func (w WaitStatus) TrapCause() int { return 0 } -+ - func Getenv(key string) (value string, found bool) { - data := cstring(key) - raw := libc_getenv(&data[0]) diff --git a/2731.patch b/2731.patch deleted file mode 100644 index e8608e2..0000000 --- a/2731.patch +++ /dev/null @@ -1,170 +0,0 @@ -From 71a0d01c36c0c01269ea6402f5fa0d7aa9ac8517 Mon Sep 17 00:00:00 2001 -From: Dan Kegel -Date: Sat, 19 Mar 2022 19:56:43 -0700 -Subject: [PATCH] main_test.go: fork testdata/testing.go for go 1.18 - ---- - main_test.go | 6 ++- - testdata/testing_go118.go | 100 +++++++++++++++++++++++++++++++++++++ - testdata/testing_go118.txt | 21 ++++++++ - 3 files changed, 126 insertions(+), 1 deletion(-) - create mode 100644 testdata/testing_go118.go - create mode 100644 testdata/testing_go118.txt - -diff --git a/main_test.go b/main_test.go -index 82c0b6110..b4210fd9b 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -66,7 +66,6 @@ func TestBuild(t *testing.T) { - "stdlib.go", - "string.go", - "structs.go", -- "testing.go", - "zeroalloc.go", - } - _, minor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) -@@ -76,6 +75,11 @@ func TestBuild(t *testing.T) { - if minor >= 17 { - tests = append(tests, "go1.17.go") - } -+ if minor >= 18 { -+ tests = append(tests, "testing_go118.go") -+ } else { -+ tests = append(tests, "testing.go") -+ } - - if *testTarget != "" { - // This makes it possible to run one specific test (instead of all), -diff --git a/testdata/testing_go118.go b/testdata/testing_go118.go -new file mode 100644 -index 000000000..4c1cf44ef ---- /dev/null -+++ b/testdata/testing_go118.go -@@ -0,0 +1,100 @@ -+package main -+ -+// TODO: also test the verbose version. -+ -+import ( -+ "errors" -+ "flag" -+ "io" -+ "strings" -+ "testing" -+) -+ -+func TestFoo(t *testing.T) { -+ t.Log("log Foo.a") -+ t.Log("log Foo.b") -+} -+ -+func TestBar(t *testing.T) { -+ t.Log("log Bar") -+ t.Log("log g\nh\ni\n") -+ t.Run("Bar1", func(t *testing.T) {}) -+ t.Run("Bar2", func(t *testing.T) { -+ t.Log("log Bar2\na\nb\nc") -+ t.Error("failed") -+ t.Log("after failed") -+ }) -+ t.Run("Bar3", func(t *testing.T) {}) -+ t.Log("log Bar end") -+} -+ -+func TestAllLowercase(t *testing.T) { -+ names := []string { -+ "alpha", -+ "BETA", -+ "gamma", -+ "BELTA", -+ } -+ -+ for _, name := range names { -+ t.Run(name, func(t *testing.T) { -+ if 'a' <= name[0] && name[0] <= 'a' { -+ t.Logf("expected lowercase name, and got one, so I'm happy") -+ } else { -+ t.Errorf("expected lowercase name, got %s", name) -+ } -+ }) -+ } -+} -+ -+var tests = []testing.InternalTest{ -+ {"TestFoo", TestFoo}, -+ {"TestBar", TestBar}, -+ {"TestAllLowercase", TestAllLowercase}, -+} -+ -+var benchmarks = []testing.InternalBenchmark{} -+ -+var fuzzes = []testing.InternalFuzzTarget{} -+ -+var examples = []testing.InternalExample{} -+ -+// A fake regexp matcher. -+// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full, -+// and lets tests pass on cortex-m. -+// Must match the one in src/testing/match.go that is substituted on bare-metal platforms, -+// or "make test" will fail there. -+func fakeMatchString(pat, str string) (bool, error) { -+ if pat == ".*" { -+ return true, nil -+ } -+ matched := strings.Contains(str, pat) -+ return matched, nil -+} -+ -+func main() { -+ testing.Init() -+ flag.Set("test.run", ".*/B") -+ m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, fuzzes, examples) -+ -+ exitcode := m.Run() -+ if exitcode != 0 { -+ println("exitcode:", exitcode) -+ } -+} -+ -+var errMain = errors.New("testing: unexpected use of func Main") -+ -+// matchStringOnly is part of upstream, and is used below to provide a dummy deps to pass to MainStart -+// so it can be run with go (tested with go 1.16) to provide a baseline for the regression test. -+// See c56cc9b3b57276. Unfortunately, testdeps is internal, so we can't just use &testdeps.TestDeps{}. -+type matchStringOnly func(pat, str string) (bool, error) -+ -+func (f matchStringOnly) MatchString(pat, str string) (bool, error) { return f(pat, str) } -+func (f matchStringOnly) StartCPUProfile(w io.Writer) error { return errMain } -+func (f matchStringOnly) StopCPUProfile() {} -+func (f matchStringOnly) WriteProfileTo(string, io.Writer, int) error { return errMain } -+func (f matchStringOnly) ImportPath() string { return "" } -+func (f matchStringOnly) StartTestLog(io.Writer) {} -+func (f matchStringOnly) StopTestLog() error { return errMain } -+func (f matchStringOnly) SetPanicOnExit0(bool) {} -diff --git a/testdata/testing_go118.txt b/testdata/testing_go118.txt -new file mode 100644 -index 000000000..6a8ee0591 ---- /dev/null -+++ b/testdata/testing_go118.txt -@@ -0,0 +1,21 @@ -+--- FAIL: TestBar (0.00s) -+ log Bar -+ log g -+ h -+ i -+ -+ --- FAIL: TestBar/Bar2 (0.00s) -+ log Bar2 -+ a -+ b -+ c -+ failed -+ after failed -+ log Bar end -+--- FAIL: TestAllLowercase (0.00s) -+ --- FAIL: TestAllLowercase/BETA (0.00s) -+ expected lowercase name, got BETA -+ --- FAIL: TestAllLowercase/BELTA (0.00s) -+ expected lowercase name, got BELTA -+FAIL -+exitcode: 1 diff --git a/2753.patch b/2753.patch deleted file mode 100644 index da1ad60..0000000 --- a/2753.patch +++ /dev/null @@ -1,280 +0,0 @@ -From 0d544bf99353a1b1e2592d40094f6ace05d98e6c Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Wed, 6 Apr 2022 21:22:04 +0200 -Subject: [PATCH] compiler: fix difference in aliases in interface methods - -There used to be a difference between `byte` and `uint8` in interface -methods. These are aliases, so they should be treated the same. -This patch introduces a custom serialization format for types, -circumventing the `Type.String()` method that is slightly wrong for our -purposes. - -This also fixes an issue with the `any` keyword in Go 1.18, which -suffers from the same problem (but this time actually leads to a crash). ---- - compiler/interface.go | 124 +++++++++++++++++++++------------ - compiler/testdata/interface.ll | 2 +- - testdata/interface.go | 11 +++ - testdata/interface.txt | 1 + - transform/reflect.go | 36 +++++----- - 5 files changed, 110 insertions(+), 64 deletions(-) - -diff --git a/compiler/interface.go b/compiler/interface.go -index c8b76039dc..e98285a2a1 100644 ---- a/compiler/interface.go -+++ b/compiler/interface.go -@@ -152,6 +152,27 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { - return structGlobal - } - -+var basicTypes = [...]string{ -+ types.Bool: "bool", -+ types.Int: "int", -+ types.Int8: "int8", -+ types.Int16: "int16", -+ types.Int32: "int32", -+ types.Int64: "int64", -+ types.Uint: "uint", -+ types.Uint8: "uint8", -+ types.Uint16: "uint16", -+ types.Uint32: "uint32", -+ types.Uint64: "uint64", -+ types.Uintptr: "uintptr", -+ types.Float32: "float32", -+ types.Float64: "float64", -+ types.Complex64: "complex64", -+ types.Complex128: "complex128", -+ types.String: "string", -+ types.UnsafePointer: "unsafe.Pointer", -+} -+ - // getTypeCodeName returns a name for this type that can be used in the - // interface lowering pass to assign type codes as expected by the reflect - // package. See getTypeCodeNum. -@@ -162,48 +183,7 @@ func getTypeCodeName(t types.Type) string { - case *types.Array: - return "array:" + strconv.FormatInt(t.Len(), 10) + ":" + getTypeCodeName(t.Elem()) - case *types.Basic: -- var kind string -- switch t.Kind() { -- case types.Bool: -- kind = "bool" -- case types.Int: -- kind = "int" -- case types.Int8: -- kind = "int8" -- case types.Int16: -- kind = "int16" -- case types.Int32: -- kind = "int32" -- case types.Int64: -- kind = "int64" -- case types.Uint: -- kind = "uint" -- case types.Uint8: -- kind = "uint8" -- case types.Uint16: -- kind = "uint16" -- case types.Uint32: -- kind = "uint32" -- case types.Uint64: -- kind = "uint64" -- case types.Uintptr: -- kind = "uintptr" -- case types.Float32: -- kind = "float32" -- case types.Float64: -- kind = "float64" -- case types.Complex64: -- kind = "complex64" -- case types.Complex128: -- kind = "complex128" -- case types.String: -- kind = "string" -- case types.UnsafePointer: -- kind = "unsafeptr" -- default: -- panic("unknown basic type: " + t.Name()) -- } -- return "basic:" + kind -+ return "basic:" + basicTypes[t.Kind()] - case *types.Chan: - return "chan:" + getTypeCodeName(t.Elem()) - case *types.Interface: -@@ -591,23 +571,77 @@ func signature(sig *types.Signature) string { - if i > 0 { - s += ", " - } -- s += sig.Params().At(i).Type().String() -+ s += typestring(sig.Params().At(i).Type()) - } - s += ")" - } - if sig.Results().Len() == 0 { - // keep as-is - } else if sig.Results().Len() == 1 { -- s += " " + sig.Results().At(0).Type().String() -+ s += " " + typestring(sig.Results().At(0).Type()) - } else { - s += " (" - for i := 0; i < sig.Results().Len(); i++ { - if i > 0 { - s += ", " - } -- s += sig.Results().At(i).Type().String() -+ s += typestring(sig.Results().At(i).Type()) - } - s += ")" - } - return s - } -+ -+// typestring returns a stable (human-readable) type string for the given type -+// that can be used for interface equality checks. It is almost (but not -+// exactly) the same as calling t.String(). The main difference is some -+// normalization around `byte` vs `uint8` for example. -+func typestring(t types.Type) string { -+ // See: https://github.com/golang/go/blob/master/src/go/types/typestring.go -+ switch t := t.(type) { -+ case *types.Array: -+ return "[" + strconv.FormatInt(t.Len(), 10) + "]" + typestring(t.Elem()) -+ case *types.Basic: -+ return basicTypes[t.Kind()] -+ case *types.Chan: -+ switch t.Dir() { -+ case types.SendRecv: -+ return "chan (" + typestring(t.Elem()) + ")" -+ case types.SendOnly: -+ return "chan<- (" + typestring(t.Elem()) + ")" -+ case types.RecvOnly: -+ return "<-chan (" + typestring(t.Elem()) + ")" -+ default: -+ panic("unknown channel direction") -+ } -+ case *types.Interface: -+ methods := make([]string, t.NumMethods()) -+ for i := range methods { -+ method := t.Method(i) -+ methods[i] = method.Name() + signature(method.Type().(*types.Signature)) -+ } -+ return "interface{" + strings.Join(methods, ";") + "}" -+ case *types.Map: -+ return "map[" + typestring(t.Key()) + "]" + typestring(t.Elem()) -+ case *types.Named: -+ return t.String() -+ case *types.Pointer: -+ return "*" + typestring(t.Elem()) -+ case *types.Signature: -+ return "func" + signature(t) -+ case *types.Slice: -+ return "[]" + typestring(t.Elem()) -+ case *types.Struct: -+ fields := make([]string, t.NumFields()) -+ for i := range fields { -+ field := t.Field(i) -+ fields[i] = field.Name() + " " + typestring(field.Type()) -+ if tag := t.Tag(i); tag != "" { -+ fields[i] += " " + strconv.Quote(tag) -+ } -+ } -+ return "struct{" + strings.Join(fields, ";") + "}" -+ default: -+ panic("unknown type: " + t.String()) -+ } -+} -diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll -index b53297b7f8..0afbee0300 100644 ---- a/compiler/testdata/interface.ll -+++ b/compiler/testdata/interface.ll -@@ -128,5 +128,5 @@ declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke" - attributes #0 = { nounwind } - attributes #1 = { "tinygo-methods"="reflect/methods.Error() string" } - attributes #2 = { "tinygo-methods"="reflect/methods.String() string" } --attributes #3 = { "tinygo-invoke"="main.$methods.foo(int) byte" "tinygo-methods"="reflect/methods.String() string; main.$methods.foo(int) byte" } -+attributes #3 = { "tinygo-invoke"="main.$methods.foo(int) uint8" "tinygo-methods"="reflect/methods.String() string; main.$methods.foo(int) uint8" } - attributes #4 = { "tinygo-invoke"="reflect/methods.Error() string" "tinygo-methods"="reflect/methods.Error() string" } -diff --git a/testdata/interface.go b/testdata/interface.go -index 0f66a30e5d..d13399f36b 100644 ---- a/testdata/interface.go -+++ b/testdata/interface.go -@@ -40,6 +40,9 @@ func main() { - // https://github.com/tinygo-org/tinygo/issues/453 - _, _ = itf.(Empty) - -+ var v Byter = FooByte(3) -+ println("Byte(): ", v.Byte()) -+ - var n int - var f float32 - var interfaceEqualTests = []struct { -@@ -266,3 +269,11 @@ type StaticBlocker interface { - } - - type Empty interface{} -+ -+type FooByte int -+ -+func (f FooByte) Byte() byte { return byte(f) } -+ -+type Byter interface { -+ Byte() uint8 -+} -diff --git a/testdata/interface.txt b/testdata/interface.txt -index 2c44269638..04e3fb9eac 100644 ---- a/testdata/interface.txt -+++ b/testdata/interface.txt -@@ -20,6 +20,7 @@ Stringer.String(): foo - Stringer.(*Thing).String(): foo - s has String() method: foo - nested switch: true -+Byte(): 3 - non-blocking call on sometimes-blocking interface - slept 1ms - slept 1ms -diff --git a/transform/reflect.go b/transform/reflect.go -index c4ecae777f..188b0a3c18 100644 ---- a/transform/reflect.go -+++ b/transform/reflect.go -@@ -40,24 +40,24 @@ import ( - // A list of basic types and their numbers. This list should be kept in sync - // with the list of Kind constants of type.go in the reflect package. - var basicTypes = map[string]int64{ -- "bool": 1, -- "int": 2, -- "int8": 3, -- "int16": 4, -- "int32": 5, -- "int64": 6, -- "uint": 7, -- "uint8": 8, -- "uint16": 9, -- "uint32": 10, -- "uint64": 11, -- "uintptr": 12, -- "float32": 13, -- "float64": 14, -- "complex64": 15, -- "complex128": 16, -- "string": 17, -- "unsafeptr": 18, -+ "bool": 1, -+ "int": 2, -+ "int8": 3, -+ "int16": 4, -+ "int32": 5, -+ "int64": 6, -+ "uint": 7, -+ "uint8": 8, -+ "uint16": 9, -+ "uint32": 10, -+ "uint64": 11, -+ "uintptr": 12, -+ "float32": 13, -+ "float64": 14, -+ "complex64": 15, -+ "complex128": 16, -+ "string": 17, -+ "unsafe.Pointer": 18, - } - - // A list of non-basic types. Adding 19 to this number will give the Kind as diff --git a/2763.patch b/2763.patch deleted file mode 100644 index f3edc2b..0000000 --- a/2763.patch +++ /dev/null @@ -1,22 +0,0 @@ -From a1c58d5d50cbf0a0d37909aa322eda31cfcda4c4 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 10 Apr 2022 16:13:40 -0400 -Subject: [PATCH] Fix incorrect formatting arguments - ---- - compiler/ircheck/check.go | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/compiler/ircheck/check.go b/compiler/ircheck/check.go -index bbedc6273..30c6ee172 100644 ---- a/compiler/ircheck/check.go -+++ b/compiler/ircheck/check.go -@@ -31,7 +31,7 @@ func (c *checker) checkType(t llvm.Type, checked map[llvm.Type]struct{}, special - return fmt.Errorf("type %q uses global context", t.String()) - default: - // we used some other context by accident -- return fmt.Errorf("type %q uses context %v instead of the main context %v", t.Context(), c.ctx) -+ return fmt.Errorf("type %q uses context %v instead of the main context %v", t.String(), t.Context(), c.ctx) - } - - // if this is a composite type, check the components of the type diff --git a/sources b/sources index e668f61..c396321 100644 --- a/sources +++ b/sources @@ -1,8 +1,10 @@ -SHA512 (tinygo-0.22.0.tar.gz) = 26f2bc2cb580a3ef5de11a0a5001425e1b925b16b321c8d2742ac77399ca4e3b1993201165a1a8c9245e8a76a61f948b4a9740f5daaa6e1696f4cddf0dcaab70 +SHA512 (tinygo-0.23.0.tar.gz) = 88eee87eb206c02adbf077f25f0ac1fb068827137d308cdf2b345fc669f0a1305fa0e95409cbd6d58a2515ab752cdd56b7fde81f124341148754782bfbe05714 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-9.0.0.src.tar.xz) = a7bb0a67165d29317cee58c22ed79f0d6a9cb9279dcd355d4267f3cd6c531a7be455a28267c591d6e2c0f9c56e363d40c10a405391e07d02ab3e30f00ffef2a8 +SHA512 (compiler-rt-12.0.0.src.tar.xz) = 5823c22bca915b393fc57fff1742a4a9d7a6645e87abf89da5a3554c9aaa6039631faa69cc3798bc2dd159f0135ee84d0ed08841e24f007d06dfd284b823b281 +SHA512 (compiler-rt-12.0.0.src.tar.xz.sig) = 669a996d7ea5ed4f556ff2a1db479c5d3c1cb326dcd14b2ac112dfa876fd8928aec9e6c665e27c0f9ab046471229049e80e879867ef26f6cba5592a81f12ccb5 +SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879add4eab283c8692c3b031eb9457ad00d1edd082cfe62fcc0eb5eb1d3bf4f1d749c0efa2a95fec1 SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 diff --git a/tinygo.spec b/tinygo.spec index 37d8691..d141df0 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.22.0 +Version: 0.23.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -16,7 +16,8 @@ Version: 0.22.0 %global clang_llvm_version 12 %endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 -%global compiler_rt_version 9.0.0 +%global compiler_rt_version %{clang_llvm_version}.0.0 +%global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 %global musl_version 1.2.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit f68b8204f797d6b3bfbc7c4da4d257961fbc8770 @@ -45,72 +46,41 @@ Summary: Go compiler for small places # avr-mcu: ASL 2.0 (packs) and MIT (Rust code, unused by this package) # cmsis-svd: ASL 2.0 and BSD and ISC and MIT (subsetted) # compiler-rt: NCSA or MIT +# macos-minimal-sdk: APSL 2.0 and BSD and ISC and Public Domain # musl: MIT # nrfx: BSD and ASL 2.0 # picolibc: BSD and ISC and MIT and GPLv2 (testing code only, unused by this package) # wasi-libc: BSD and CC0 and ISC and MIT and Public Domain -License: BSD and ASL 2.0 and CC0 and ISC and MIT and (NCSA or MIT) and Public Domain +License: BSD and APSL 2.0 and ASL 2.0 and CC0 and ISC and MIT and (NCSA or MIT) and Public Domain URL: %{gourl} Source0: %{gosource} Source1: clean_tarballs.sh Source2: cmsis-%{CMSIS_commit}-clean.tar.xz Source3: https://github.com/avr-rust/avr-mcu/archive/%{avr_commit}/avr-%{avr_commit}.tar.gz Source4: cmsis_svd-%{cmsis_svd_commit}-clean.tar.xz -Source5: https://releases.llvm.org/%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz +Source50: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz +Source51: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz.sig +Source52: tstellar-gpg-key.asc Source60: https://musl.libc.org/releases/musl-%{musl_version}.tar.gz Source61: https://musl.libc.org/releases/musl-%{musl_version}.tar.gz.asc Source62: https://musl.libc.org/musl.pub -Source7: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz -Source8: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz -Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz -# https://github.com/tinygo-org/tinygo/pull/2620 -Patch0001: 0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch +Source7: https://github.com/aykevl/macos-minimal-sdk/archive/%{macos_minsdk_commit}/macos-minimal-sdk-%{macos_minsdk_commit}.tar.gz +Source8: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz +Source9: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz +Source10: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz # We don't have wasmtime to run these. -Patch0002: 0002-Skip-WASI-tests.patch +Patch0001: 0001-Skip-WASI-tests.patch # Unbundling things -Patch0003: 0003-Use-system-mingw64-headers-and-crt.patch +Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0004: 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch -# https://github.com/tinygo-org/tinygo/pull/2608 -Patch0005: 0005-Fix-LLVM-build-constraints.patch +Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions -Patch0006: 0006-Suggest-optional-packages-to-install-if-missing.patch -# Fix incorrect formatting arguments -Patch0007: https://github.com/tinygo-org/tinygo/pull/2763.patch +Patch0004: 0004-Suggest-optional-packages-to-install-if-missing.patch -# ################################ -# All remaining for fixing Go 1.18 -# ################################ -# Implement some missing Signal bits -Patch0008: https://github.com/tinygo-org/tinygo/pull/2615.patch -# src/os: add stubs for exec.ExitError and ProcessState.ExitCode -Patch0009: https://github.com/tinygo-org/tinygo/pull/2679.patch -# Rename reflect.Ptr to reflect.Pointer -Patch0010: https://github.com/tinygo-org/tinygo/pull/2715.patch -# os: Add some exec.ProcessState stubs -Patch0011: https://github.com/tinygo-org/tinygo/pull/2716.patch -# Implement getpagesize and munmap. For go 1.18. -Patch0012: https://github.com/tinygo-org/tinygo/pull/2719.patch -# compiler.go: createBuiltin: accept alias for slice. -Patch0013: https://github.com/tinygo-org/tinygo/pull/2721.patch -# syscall: define MAP_SHARED and PROT_READ on wasi -Patch0014: https://github.com/tinygo-org/tinygo/pull/2722.patch -# syscall: stub mmap(), MAP_SHARED, PROT_READ, SIGBUS, etc. on nonhosted targets -Patch0015: https://github.com/tinygo-org/tinygo/pull/2724.patch -# Support Go 1.18, updated -Patch0016: https://github.com/tinygo-org/tinygo/pull/2725.patch -# Add reflect.Value.FieldByIndexErr stub -Patch0017: https://github.com/tinygo-org/tinygo/pull/2727.patch -# syscall: define more signal numbers -Patch0018: https://github.com/tinygo-org/tinygo/pull/2729.patch -# syscall: stub WaitStatus -Patch0019: https://github.com/tinygo-org/tinygo/pull/2730.patch -# main_test.go: fork testdata/testing.go for go 1.18 -Patch0020: https://github.com/tinygo-org/tinygo/pull/2731.patch -# compiler: fix difference in aliases in interface methods -Patch0021: https://github.com/tinygo-org/tinygo/pull/2753.patch +# https://github.com/tinygo-org/tinygo/pull/2837 +Patch0005: 0005-Skip-slice-copy-test-for-LLVM-14.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -196,9 +166,12 @@ tar -C lib -xf %{SOURCE4} rmdir lib/cmsis-svd mv lib/cmsis-svd-%{cmsis_svd_commit} lib/cmsis-svd -tar -C lib -xf %{SOURCE5} -rmdir lib/compiler-rt -mv lib/compiler-rt-%{compiler_rt_version}.src lib/compiler-rt +# Verify *before* actually unpacking! +%{gpgverify} --keyring='%{SOURCE52}' --signature='%{SOURCE51}' --data='%{SOURCE50}' +tar -C lib -xf %{SOURCE50} +mv lib/compiler-rt-%{compiler_rt_version}.src/lib/builtins lib/compiler-rt-builtins +mv lib/compiler-rt-%{compiler_rt_version}.src/README.txt lib/compiler-rt-builtins/ +mv lib/compiler-rt-%{compiler_rt_version}.src/LICENSE.TXT lib/compiler-rt-builtins/ # Verify *before* actually unpacking! %{gpgverify} --keyring='%{SOURCE62}' --signature='%{SOURCE61}' --data='%{SOURCE60}' @@ -207,16 +180,20 @@ rmdir lib/musl mv lib/musl-%{musl_version} lib/musl tar -C lib -xf %{SOURCE7} +rmdir lib/macos-minimal-sdk +mv lib/macos-minimal-sdk-%{macos_minsdk_commit} lib/macos-minimal-sdk + +tar -C lib -xf %{SOURCE8} rmdir lib/nrfx mv lib/nrfx-%{nrfx_commit} lib/nrfx rm lib/nrfx/.gitignore chmod -x lib/nrfx/doc/generate_html_doc.sh -tar -C lib -xf %{SOURCE8} +tar -C lib -xf %{SOURCE9} rmdir lib/picolibc mv lib/picolibc-%{picolibc_commit} lib/picolibc -tar -C lib -xf %{SOURCE9} +tar -C lib -xf %{SOURCE10} rmdir lib/wasi-libc mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc @@ -261,11 +238,9 @@ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/CMSIS install -vpm 0644 lib/CMSIS/README.md %{buildroot}%{tinygoroot}/lib/CMSIS/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/CMSIS/CMSIS/Include install -vpm 0644 lib/CMSIS/CMSIS/Include/* %{buildroot}%{tinygoroot}/lib/CMSIS/CMSIS/Include/ -install -vdm 0755 %{buildroot}%{tinygoroot}/lib/compiler-rt -install -vpm 0644 lib/compiler-rt/README.txt %{buildroot}%{tinygoroot}/lib/compiler-rt/ -install -vpm 0644 lib/compiler-rt/LICENSE.TXT %{buildroot}%{tinygoroot}/lib/compiler-rt/ -install -vdm 0755 %{buildroot}%{tinygoroot}/lib/compiler-rt/lib -cp -rp lib/compiler-rt/lib/builtins %{buildroot}%{tinygoroot}/lib/compiler-rt/lib/ +cp -rp lib/compiler-rt-builtins %{buildroot}%{tinygoroot}/lib +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/macos-minimal-sdk +cp -rp lib/macos-minimal-sdk/* %{buildroot}%{tinygoroot}/lib/macos-minimal-sdk install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl cp -rp lib/musl/COPYRIGHT %{buildroot}%{tinygoroot}/lib/musl cp -rp lib/musl/include %{buildroot}%{tinygoroot}/lib/musl @@ -347,8 +322,8 @@ make tinygo-test %{_bindir}/tinygo %{tinygoroot} %doc %{tinygoroot}/lib/CMSIS/README.md -%license %{tinygoroot}/lib/compiler-rt/LICENSE.TXT -%doc %{tinygoroot}/lib/compiler-rt/README.txt +%license %{tinygoroot}/lib/compiler-rt-builtins/LICENSE.TXT +%doc %{tinygoroot}/lib/compiler-rt-builtins/README.txt %license %{tinygoroot}/lib/nrfx/LICENSE %doc %{tinygoroot}/lib/nrfx/README.md %license %{tinygoroot}/lib/musl/COPYRIGHT diff --git a/tstellar-gpg-key.asc b/tstellar-gpg-key.asc new file mode 100644 index 0000000000000000000000000000000000000000..eba625c41a5fb1646d8b087acb97a6f079901712 GIT binary patch literal 2222 zcmV;f2vPT$0u2OO>VZ805CFTzjTRs0jjXv;pGugCr`4v#a%GKo$r!Jd->PCt z$y%rpj==vUV}Ir+*R8b>IVmXk+p1pb?8#X&nu=A^mMLf^hWzyKgNi2>hyWLVh=fxY z2uQphyka|M&B_iX7`4E;@VIVye4j+?(eh_~`%yu#&d z*V9fM6W6bny8d9hd1I{mwtG%>CC@J*juZpAErTo`!5xcYL1Aj+mdQryB5UR$E%yF6 z*!s!u));Q?P+9N#0Q6S0jli^^Y40t$(uybAR^$1y6%VyNeBeQ!@oTFdcu?K8u$-I` zKDUMj7UGg4A}({Q;YHV$l=+&0cGG3Hh4_R+d%{rZxYsm$HE!9TA$H#_hM3|NNT^K> zZQU8HH=}vu#c;-9-Jyy=nkH&Ih5=&vyyTF3Oa0+QyQp|o8>g~GALwBu0JFctO)F4By^oR|Q&^+ok_ahpz* zx2{4_^~smFohQB{Cn}OKl!M)6h-Sp7pTRPF)8{xDQnsT*2KBVqzLp^_b}_%Gi3#{7 zPmKinsRK(isAm8X0RRECB2;f}AX9W@Y;0k2WFS0rb97~FY+-Uha%E&_VRSBIZ*4w_ z0zU*30RjLi1p->?fjt5n0|f~I;WK~-3ke7Z0|EgC6$kC|{ ztfg+f-L$-*LG&Y8rEs>Pk0kY2M!#d(HZRxiE0ipTCeAm7F|v6IH9B7Vlm=s3u!P6x zukC3z;PJmJ)xh$MIj*i=cG31 zsr(;uWSlOsz%_4Yz*UkKLqI0&M?pa@7vLxT7E~NOMQpRmC;};m26SlTQ+yR!^FSkd z5X@jE=BH4}c|41ZEr0imr|M~OJc6e@^UU(IF|W<>p1aTajeew-gHXQNys755V(S?e zy&C%siGryJ(2hm;uw^%r#}(W7xEi6^+X#Ec26;Q4R?Bq8H1hLh#VmX*+=kLh#l)OH zuC2P$?)S;hs*FQk8?PUuG{npPBS~7t;@#%(02I5L`it-=nvT%hwBu9Vylt?Rx_WO8 zn;xz3>aTq41Kx`}**s6A$49Kf_AikxBYjpmen!2RxlOtbF<6izL<4CJepUil@?zwT z9--9FX0i_jVtyY+6GeUXY{C6s&jp=gZVLvg0K<2!X;=PL%?gW_4bZMVYaV0@NJs-G zR53P~&$$8(1X}8WJpm8^!P@Z0GUu_8r6%69;^`~$FlQ_sXC1gfPE!ZD7nWV}F8ra9JxN4Hc;rg@5`G`UmNK zQK2H?OT@C(8zIO}kZRe0_IN@oCg4<+qQMIIQ9BTzli>7{__%>7EJKyOXMQt~d~dO#*vR-UpkDf2!SqwMz3;vEnk@ z?=o=Jt#mt#&qQ5T^Djs9 z^4k@B1GCy801*KI0f_=71Q-DV01pKMTIzv40vikk2?60VfB*^!5TeJFsfIzFiUFe# z0I}kKVKh7v)wfS?mcAnLFf2mw>&+IUnN!`^A5o?AROoVE|1Wn*mv*_@{l7RSech<$ z?RLGlpeWdkMhbOTAw|NxrZVM!5o8(5NV^UY>QiIQrC87nWDTTnJfN`ajL|@# zl)Qnlzy(_cGgW866I0m2oMj27)0bsK>19i)o*dAxPI!tSpuQR`^kJnT+%gR}_vkiWGx zBRSn>o||dsUIz{u>`KQ`n~m24dqQqPaip8qJ@%<^y5X6+qY7;4MB$!YUu}^Vz&|fAyIM wpX0lD!)BYGzJZL|-kImy^XM9ph5)K0`p3zNu2XNcRC)Y~P3B_BHh)~2!0gUKHvj+t literal 0 HcmV?d00001 From 95b7509b69ae22be793cfd86013deaa3eb9c6b4c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 May 2022 23:15:18 -0400 Subject: [PATCH 33/78] Use compiler-rt 13 sources --- sources | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources b/sources index c396321..013776d 100644 --- a/sources +++ b/sources @@ -2,8 +2,8 @@ SHA512 (tinygo-0.23.0.tar.gz) = 88eee87eb206c02adbf077f25f0ac1fb068827137d308cdf SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-12.0.0.src.tar.xz) = 5823c22bca915b393fc57fff1742a4a9d7a6645e87abf89da5a3554c9aaa6039631faa69cc3798bc2dd159f0135ee84d0ed08841e24f007d06dfd284b823b281 -SHA512 (compiler-rt-12.0.0.src.tar.xz.sig) = 669a996d7ea5ed4f556ff2a1db479c5d3c1cb326dcd14b2ac112dfa876fd8928aec9e6c665e27c0f9ab046471229049e80e879867ef26f6cba5592a81f12ccb5 +SHA512 (compiler-rt-13.0.0.src.tar.xz) = b35643553d0d3d4deb2f31e2dad8bbac4b772ee3e0c86aa532ce7161da276620fe820193004ee08c62eb8dfd015e04d3853e6a7cc939ac3fb57345702386d583 +SHA512 (compiler-rt-13.0.0.src.tar.xz.sig) = c2626f6b0d813e00fdd9abc2ffcdc30d3a906e192da470ea24c010421ff4cc812b171704899ab15e53edb49ff5dd4ebd447425a2469ff80f9503a77e7ee8cdcd SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879add4eab283c8692c3b031eb9457ad00d1edd082cfe62fcc0eb5eb1d3bf4f1d749c0efa2a95fec1 SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 From e72fffe5c38914488e3a3a4da9a29db809e8fe6f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 May 2022 23:33:11 -0400 Subject: [PATCH 34/78] Use LLVM 14 on F36+ --- .gitignore | 1 + sources | 4 ++-- tinygo.spec | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 77fb13a..c0bae63 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ /compiler-rt-13.0.0.src.tar.xz.sig /macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz /compiler-rt-12.0.0.src.tar.xz.sig +/compiler-rt-14.0.0.src.tar.xz.sig diff --git a/sources b/sources index 013776d..8dc11c7 100644 --- a/sources +++ b/sources @@ -2,8 +2,8 @@ SHA512 (tinygo-0.23.0.tar.gz) = 88eee87eb206c02adbf077f25f0ac1fb068827137d308cdf SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-13.0.0.src.tar.xz) = b35643553d0d3d4deb2f31e2dad8bbac4b772ee3e0c86aa532ce7161da276620fe820193004ee08c62eb8dfd015e04d3853e6a7cc939ac3fb57345702386d583 -SHA512 (compiler-rt-13.0.0.src.tar.xz.sig) = c2626f6b0d813e00fdd9abc2ffcdc30d3a906e192da470ea24c010421ff4cc812b171704899ab15e53edb49ff5dd4ebd447425a2469ff80f9503a77e7ee8cdcd +SHA512 (compiler-rt-14.0.0.src.tar.xz) = 9df73ef3b81f2b70902726e0dc5529c0cc1e976ce75fbfb1c3d7930882d82fc0896934a32d1c9511b08962cac5b409c14f54dc53833fbf0724256b22165c4439 +SHA512 (compiler-rt-14.0.0.src.tar.xz.sig) = 3998c7a7477a95ae36591b8658677a44f5d4c88a57e93df57fc3f4670c38a71fb0e385b7f9b44ef7e97d7ce77551b4ea790c6f63174e79a2ffc9dd678dcf886f SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879add4eab283c8692c3b031eb9457ad00d1edd082cfe62fcc0eb5eb1d3bf4f1d749c0efa2a95fec1 SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 diff --git a/tinygo.spec b/tinygo.spec index d141df0..be6d6bf 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,11 +10,15 @@ Version: 0.23.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%if %{fedora} > 35 +%global clang_llvm_version 14 +%else %if %{fedora} > 34 %global clang_llvm_version 13 %else %global clang_llvm_version 12 %endif +%endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 From 55713f9bab2b0aaf04fce63004163adf6e3a5ac1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 22:44:09 -0400 Subject: [PATCH 35/78] Fix tests on 32-bit systems --- 0001-Skip-WASI-tests.patch | 2 +- 0002-Use-system-mingw64-headers-and-crt.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- ...ional-packages-to-install-if-missing.patch | 2 +- 0005-Skip-slice-copy-test-for-LLVM-14.patch | 2 +- 0006-Skip-TestDirFS-on-32-bit-systems.patch | 30 +++++++++++++++ 0007-Skip-broken-tests-on-i686.patch | 38 +++++++++++++++++++ tinygo.spec | 3 ++ 8 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 0006-Skip-TestDirFS-on-32-bit-systems.patch create mode 100644 0007-Skip-broken-tests-on-i686.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index f404308..6b71d1e 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 8116847a5ef1b2127f8a0f178ae432dc41472454 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/5] Skip WASI tests. +Subject: [PATCH 1/7] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index 4073f6c..c27f56d 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ From 67f561400614dfde114b31f4b08a340fa352939e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/5] Use system mingw64 headers and crt +Subject: [PATCH 2/7] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index b4b6750..ed8514e 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From b9ac4d7d45fe7710f7f5264ab182d7a2a10ddace Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/5] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 3/7] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch index 040bc2c..1e41d76 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From 12016fd98fe0f0eb818f059a9b88465230817954 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 4/5] Suggest optional packages to install if missing +Subject: [PATCH 4/7] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0005-Skip-slice-copy-test-for-LLVM-14.patch b/0005-Skip-slice-copy-test-for-LLVM-14.patch index 17e4c8b..db3e14f 100644 --- a/0005-Skip-slice-copy-test-for-LLVM-14.patch +++ b/0005-Skip-slice-copy-test-for-LLVM-14.patch @@ -1,7 +1,7 @@ From e9592baa218826ca59faf7086838a923236baccb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 May 2022 19:47:59 -0400 -Subject: [PATCH 5/5] Skip slice-copy test for LLVM < 14 +Subject: [PATCH 5/7] Skip slice-copy test for LLVM < 14 Signed-off-by: Elliott Sales de Andrade --- diff --git a/0006-Skip-TestDirFS-on-32-bit-systems.patch b/0006-Skip-TestDirFS-on-32-bit-systems.patch new file mode 100644 index 0000000..96df69d --- /dev/null +++ b/0006-Skip-TestDirFS-on-32-bit-systems.patch @@ -0,0 +1,30 @@ +From a1095b1808280148cbb0f0457bf49899ba007833 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 8 May 2022 04:18:05 -0400 +Subject: [PATCH 6/7] Skip TestDirFS on 32-bit systems + +Because Seek is not fully implemented there. + +Signed-off-by: Elliott Sales de Andrade +--- + src/os/file_go_116_test.go | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/os/file_go_116_test.go b/src/os/file_go_116_test.go +index c218a02d..a7e13003 100644 +--- a/src/os/file_go_116_test.go ++++ b/src/os/file_go_116_test.go +@@ -24,6 +24,10 @@ func TestDirFS(t *testing.T) { + t.Log("TODO: implement Readdir for Windows") + return + } ++ if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { ++ t.Log("TODO: implement seek for 386 and arm") ++ return ++ } + if err := fstest.TestFS(DirFS("./testdata/dirfs"), "a", "b", "dir/x"); err != nil { + t.Fatal(err) + } +-- +2.35.1 + diff --git a/0007-Skip-broken-tests-on-i686.patch b/0007-Skip-broken-tests-on-i686.patch new file mode 100644 index 0000000..ff1fad7 --- /dev/null +++ b/0007-Skip-broken-tests-on-i686.patch @@ -0,0 +1,38 @@ +From 3a2a96984d51beb348a9003ae8221a935a626918 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 8 May 2022 18:39:26 -0400 +Subject: [PATCH 7/7] Skip broken tests on i686 + +* compress/flate runs out of memory +* testing/fstest uses Seek, which is not implemented there + +Signed-off-by: Elliott Sales de Andrade +--- + Makefile | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/Makefile b/Makefile +index dc388c21..359ec8f5 100644 +--- a/Makefile ++++ b/Makefile +@@ -295,12 +295,15 @@ TEST_PACKAGES_FAST = \ + # Additional standard library packages that pass tests on individual platforms + TEST_PACKAGES_LINUX := \ + archive/zip \ +- compress/flate \ + compress/lzw \ + debug/dwarf \ + debug/plan9obj \ +- io/fs \ ++ io/fs ++ifneq ($(shell uname -p),i686) ++TEST_PACKAGES_LINUX += \ ++ compress/flate \ + testing/fstest ++endif + + TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) + +-- +2.35.1 + diff --git a/tinygo.spec b/tinygo.spec index d141df0..931d207 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -81,6 +81,9 @@ Patch0004: 0004-Suggest-optional-packages-to-install-if-missing.patch # https://github.com/tinygo-org/tinygo/pull/2837 Patch0005: 0005-Skip-slice-copy-test-for-LLVM-14.patch +# https://github.com/tinygo-org/tinygo/pull/2840 +Patch0006: 0006-Skip-TestDirFS-on-32-bit-systems.patch +Patch0007: 0007-Skip-broken-tests-on-i686.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 7f243952feb8b0555bfeba09a4cbf6dd62a1d230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert-Andr=C3=A9=20Mauchin?= Date: Sat, 18 Jun 2022 12:23:24 +0200 Subject: [PATCH 36/78] Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327, CVE-2022-27191, CVE-2022-29526, CVE-2022-30629 From 820cb03fbe1f12394ed6a98e21a28dc54933068c Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Tue, 19 Jul 2022 13:59:12 -0500 Subject: [PATCH 37/78] Rebuild for CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in golang From 3a69331208713b35850200d128d97e1a9570ad90 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 21 Jul 2022 02:42:12 -0400 Subject: [PATCH 38/78] Skip test broken by Go 1.18.4 --- 0001-Skip-WASI-tests.patch | 4 +-- 0002-Use-system-mingw64-headers-and-crt.patch | 4 +-- ...oss-Linux-tests-where-qemu-is-broken.patch | 4 +-- ...ional-packages-to-install-if-missing.patch | 4 +-- 0005-Skip-slice-copy-test-for-LLVM-14.patch | 4 +-- 0006-Skip-TestDirFS-on-32-bit-systems.patch | 4 +-- 0007-Skip-broken-tests-on-i686.patch | 4 +-- 0008-Temporarily-skip-io-fs-tests.patch | 27 +++++++++++++++++++ tinygo.spec | 4 +++ 9 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 0008-Temporarily-skip-io-fs-tests.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 6b71d1e..5bbdfdd 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 8116847a5ef1b2127f8a0f178ae432dc41472454 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/7] Skip WASI tests. +Subject: [PATCH 1/8] Skip WASI tests. We do not have wasmtime available. @@ -34,5 +34,5 @@ index 3b088ada..dbbf7bfb 100644 } for _, targ := range targs { -- -2.35.1 +2.36.1 diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index c27f56d..e091f5f 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ From 67f561400614dfde114b31f4b08a340fa352939e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/7] Use system mingw64 headers and crt +Subject: [PATCH 2/8] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- @@ -118,5 +118,5 @@ index b30e653e..d5bfaa25 100644 ) case "": -- -2.35.1 +2.36.1 diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index ed8514e..6e44cad 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From b9ac4d7d45fe7710f7f5264ab182d7a2a10ddace Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/7] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 3/8] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -60,5 +60,5 @@ index dbbf7bfb..4183c6b1 100644 actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows -- -2.35.1 +2.36.1 diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch index 1e41d76..8cf11e8 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From 12016fd98fe0f0eb818f059a9b88465230817954 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 4/7] Suggest optional packages to install if missing +Subject: [PATCH 4/8] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -74,5 +74,5 @@ index 53d89bf0..e55719b2 100644 + return err } -- -2.35.1 +2.36.1 diff --git a/0005-Skip-slice-copy-test-for-LLVM-14.patch b/0005-Skip-slice-copy-test-for-LLVM-14.patch index db3e14f..cda8e85 100644 --- a/0005-Skip-slice-copy-test-for-LLVM-14.patch +++ b/0005-Skip-slice-copy-test-for-LLVM-14.patch @@ -1,7 +1,7 @@ From e9592baa218826ca59faf7086838a923236baccb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 7 May 2022 19:47:59 -0400 -Subject: [PATCH 5/7] Skip slice-copy test for LLVM < 14 +Subject: [PATCH 5/8] Skip slice-copy test for LLVM < 14 Signed-off-by: Elliott Sales de Andrade --- @@ -46,5 +46,5 @@ index ae2635af..a1bea65e 100644 t.Parallel() runTest(t, "testdata/"+name) -- -2.35.1 +2.36.1 diff --git a/0006-Skip-TestDirFS-on-32-bit-systems.patch b/0006-Skip-TestDirFS-on-32-bit-systems.patch index 96df69d..27dd500 100644 --- a/0006-Skip-TestDirFS-on-32-bit-systems.patch +++ b/0006-Skip-TestDirFS-on-32-bit-systems.patch @@ -1,7 +1,7 @@ From a1095b1808280148cbb0f0457bf49899ba007833 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 6/7] Skip TestDirFS on 32-bit systems +Subject: [PATCH 6/8] Skip TestDirFS on 32-bit systems Because Seek is not fully implemented there. @@ -26,5 +26,5 @@ index c218a02d..a7e13003 100644 t.Fatal(err) } -- -2.35.1 +2.36.1 diff --git a/0007-Skip-broken-tests-on-i686.patch b/0007-Skip-broken-tests-on-i686.patch index ff1fad7..ab6deeb 100644 --- a/0007-Skip-broken-tests-on-i686.patch +++ b/0007-Skip-broken-tests-on-i686.patch @@ -1,7 +1,7 @@ From 3a2a96984d51beb348a9003ae8221a935a626918 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 7/7] Skip broken tests on i686 +Subject: [PATCH 7/8] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there @@ -34,5 +34,5 @@ index dc388c21..359ec8f5 100644 TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) -- -2.35.1 +2.36.1 diff --git a/0008-Temporarily-skip-io-fs-tests.patch b/0008-Temporarily-skip-io-fs-tests.patch new file mode 100644 index 0000000..cad82f7 --- /dev/null +++ b/0008-Temporarily-skip-io-fs-tests.patch @@ -0,0 +1,27 @@ +From 7f56024921ef935950f3dbb44067cc47094334d0 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Thu, 21 Jul 2022 02:06:53 -0400 +Subject: [PATCH 8/8] Temporarily skip io/fs tests + +Signed-off-by: Elliott Sales de Andrade +--- + Makefile | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/Makefile b/Makefile +index 359ec8f5..2f4a9bce 100644 +--- a/Makefile ++++ b/Makefile +@@ -297,8 +297,7 @@ TEST_PACKAGES_LINUX := \ + archive/zip \ + compress/lzw \ + debug/dwarf \ +- debug/plan9obj \ +- io/fs ++ debug/plan9obj + ifneq ($(shell uname -p),i686) + TEST_PACKAGES_LINUX += \ + compress/flate \ +-- +2.36.1 + diff --git a/tinygo.spec b/tinygo.spec index 2ff72b5..078d4e0 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -89,6 +89,10 @@ Patch0005: 0005-Skip-slice-copy-test-for-LLVM-14.patch Patch0006: 0006-Skip-TestDirFS-on-32-bit-systems.patch Patch0007: 0007-Skip-broken-tests-on-i686.patch +# https://github.com/tinygo-org/tinygo/issues/3008 +# Broken due to TestCVE202230630 +Patch0008: 0008-Temporarily-skip-io-fs-tests.patch + # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 5756d019212ca1d48fe758d075498f8d02ea26b6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 7 Aug 2022 15:15:36 -0400 Subject: [PATCH 39/78] Update to latest version (#2103764) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 10 ++-- 0002-Use-system-mingw64-headers-and-crt.patch | 8 +-- ...oss-Linux-tests-where-qemu-is-broken.patch | 10 ++-- ...ional-packages-to-install-if-missing.patch | 4 +- 0005-Skip-TestDirFS-on-32-bit-systems.patch | 30 +++++++++++ 0005-Skip-slice-copy-test-for-LLVM-14.patch | 50 ------------------- 0006-Skip-TestDirFS-on-32-bit-systems.patch | 30 ----------- ...ch => 0006-Skip-broken-tests-on-i686.patch | 29 +++++++---- 0008-Temporarily-skip-io-fs-tests.patch | 26 +++++----- 0009-Add-ErrProcessDone-error.patch | 40 +++++++++++++++ 0010-Fix-tinygo-test-with-Go-1.19.patch | 42 ++++++++++++++++ 0011-Fix-tinygo-test-with-Go-1.16.patch | 46 +++++++++++++++++ sources | 4 +- tinygo.spec | 36 ++++++------- 15 files changed, 222 insertions(+), 144 deletions(-) create mode 100644 0005-Skip-TestDirFS-on-32-bit-systems.patch delete mode 100644 0005-Skip-slice-copy-test-for-LLVM-14.patch delete mode 100644 0006-Skip-TestDirFS-on-32-bit-systems.patch rename 0007-Skip-broken-tests-on-i686.patch => 0006-Skip-broken-tests-on-i686.patch (51%) create mode 100644 0009-Add-ErrProcessDone-error.patch create mode 100644 0010-Fix-tinygo-test-with-Go-1.19.patch create mode 100644 0011-Fix-tinygo-test-with-Go-1.16.patch diff --git a/.gitignore b/.gitignore index c0bae63..305c25b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ /macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz /compiler-rt-12.0.0.src.tar.xz.sig /compiler-rt-14.0.0.src.tar.xz.sig +/tinygo-0.25.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 5bbdfdd..5db9255 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 8116847a5ef1b2127f8a0f178ae432dc41472454 Mon Sep 17 00:00:00 2001 +From f62e55a3c636caf2a609a0290701ca7108ab4c46 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/8] Skip WASI tests. +Subject: [PATCH 01/11] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index 3b088ada..dbbf7bfb 100644 +index f620c77d..3e97f481 100644 --- a/main_test.go +++ b/main_test.go -@@ -201,10 +201,6 @@ func TestBuild(t *testing.T) { +@@ -165,10 +165,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -25,7 +25,7 @@ index 3b088ada..dbbf7bfb 100644 } } -@@ -405,7 +401,6 @@ func TestTest(t *testing.T) { +@@ -408,7 +404,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index e091f5f..e8dd0c8 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ -From 67f561400614dfde114b31f4b08a340fa352939e Mon Sep 17 00:00:00 2001 +From 7c10e6e5debde713b52008e1f7476ffa036e2d48 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/8] Use system mingw64 headers and crt +Subject: [PATCH 02/11] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- @@ -99,10 +99,10 @@ index 135cae94..d233068d 100644 } return jobs diff --git a/compileopts/config.go b/compileopts/config.go -index b30e653e..d5bfaa25 100644 +index a006b673..c81a547c 100644 --- a/compileopts/config.go +++ b/compileopts/config.go -@@ -306,12 +306,9 @@ func (c *Config) CFlags() []string { +@@ -297,12 +297,9 @@ func (c *Config) CFlags() []string { root := goenv.Get("TINYGOROOT") cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") case "mingw-w64": diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 6e44cad..789228d 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From b9ac4d7d45fe7710f7f5264ab182d7a2a10ddace Mon Sep 17 00:00:00 2001 +From 09c7cf0930704cc07844e6a926c5f8e667350730 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/8] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 03/11] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 28 insertions(+) diff --git a/main_test.go b/main_test.go -index dbbf7bfb..4183c6b1 100644 +index 3e97f481..44d85249 100644 --- a/main_test.go +++ b/main_test.go -@@ -248,6 +248,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -250,6 +250,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -38,7 +38,7 @@ index dbbf7bfb..4183c6b1 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -334,6 +348,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -336,6 +350,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch index 8cf11e8..14ff89c 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From 12016fd98fe0f0eb818f059a9b88465230817954 Mon Sep 17 00:00:00 2001 +From c995ba5cf2fb21c419dc82afe9968a020aadf182 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 4/8] Suggest optional packages to install if missing +Subject: [PATCH 04/11] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0005-Skip-TestDirFS-on-32-bit-systems.patch b/0005-Skip-TestDirFS-on-32-bit-systems.patch new file mode 100644 index 0000000..877ec55 --- /dev/null +++ b/0005-Skip-TestDirFS-on-32-bit-systems.patch @@ -0,0 +1,30 @@ +From 85a4d526d5109bbd4ca2f56fa00fd1d9fccfe065 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 8 May 2022 04:18:05 -0400 +Subject: [PATCH 05/11] Skip TestDirFS on 32-bit systems + +Because Seek is not fully implemented there. + +Signed-off-by: Elliott Sales de Andrade +--- + src/os/os_anyos_test.go | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/os/os_anyos_test.go b/src/os/os_anyos_test.go +index d8ac01c2..f84a4083 100644 +--- a/src/os/os_anyos_test.go ++++ b/src/os/os_anyos_test.go +@@ -277,6 +277,10 @@ func TestDirFS(t *testing.T) { + t.Log("TODO: implement Readdir for Windows") + return + } ++ if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { ++ t.Log("TODO: implement seek for 386 and arm") ++ return ++ } + if isWASI { + t.Log("TODO: allow foo/bar/. as synonym for path foo/bar on wasi?") + return +-- +2.36.1 + diff --git a/0005-Skip-slice-copy-test-for-LLVM-14.patch b/0005-Skip-slice-copy-test-for-LLVM-14.patch deleted file mode 100644 index cda8e85..0000000 --- a/0005-Skip-slice-copy-test-for-LLVM-14.patch +++ /dev/null @@ -1,50 +0,0 @@ -From e9592baa218826ca59faf7086838a923236baccb Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 7 May 2022 19:47:59 -0400 -Subject: [PATCH 5/8] Skip slice-copy test for LLVM < 14 - -Signed-off-by: Elliott Sales de Andrade ---- - interp/interp_test.go | 12 +++++++++++- - 1 file changed, 11 insertions(+), 1 deletion(-) - -diff --git a/interp/interp_test.go b/interp/interp_test.go -index ae2635af..a1bea65e 100644 ---- a/interp/interp_test.go -+++ b/interp/interp_test.go -@@ -3,6 +3,7 @@ package interp - import ( - "io/ioutil" - "os" -+ "strconv" - "strings" - "testing" - -@@ -10,6 +11,12 @@ import ( - ) - - func TestInterp(t *testing.T) { -+ llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) -+ if err != nil { -+ // Note: this should never happen and if it does, it will always happen -+ // for a particular build because llvm.Version is a constant. -+ panic(err) -+ } - for _, name := range []string{ - "basic", - "phi", -@@ -19,7 +26,10 @@ func TestInterp(t *testing.T) { - "revert", - "alloc", - } { -- name := name // make tc local to this closure -+ name := name // make local to this closure -+ if name == "slice-copy" && llvmVersion < 14 { -+ continue -+ } - t.Run(name, func(t *testing.T) { - t.Parallel() - runTest(t, "testdata/"+name) --- -2.36.1 - diff --git a/0006-Skip-TestDirFS-on-32-bit-systems.patch b/0006-Skip-TestDirFS-on-32-bit-systems.patch deleted file mode 100644 index 27dd500..0000000 --- a/0006-Skip-TestDirFS-on-32-bit-systems.patch +++ /dev/null @@ -1,30 +0,0 @@ -From a1095b1808280148cbb0f0457bf49899ba007833 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 6/8] Skip TestDirFS on 32-bit systems - -Because Seek is not fully implemented there. - -Signed-off-by: Elliott Sales de Andrade ---- - src/os/file_go_116_test.go | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/os/file_go_116_test.go b/src/os/file_go_116_test.go -index c218a02d..a7e13003 100644 ---- a/src/os/file_go_116_test.go -+++ b/src/os/file_go_116_test.go -@@ -24,6 +24,10 @@ func TestDirFS(t *testing.T) { - t.Log("TODO: implement Readdir for Windows") - return - } -+ if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { -+ t.Log("TODO: implement seek for 386 and arm") -+ return -+ } - if err := fstest.TestFS(DirFS("./testdata/dirfs"), "a", "b", "dir/x"); err != nil { - t.Fatal(err) - } --- -2.36.1 - diff --git a/0007-Skip-broken-tests-on-i686.patch b/0006-Skip-broken-tests-on-i686.patch similarity index 51% rename from 0007-Skip-broken-tests-on-i686.patch rename to 0006-Skip-broken-tests-on-i686.patch index ab6deeb..ea1071d 100644 --- a/0007-Skip-broken-tests-on-i686.patch +++ b/0006-Skip-broken-tests-on-i686.patch @@ -1,34 +1,41 @@ -From 3a2a96984d51beb348a9003ae8221a935a626918 Mon Sep 17 00:00:00 2001 +From c645a887a6989e0210c782bb84d4f31200e0d333 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 7/8] Skip broken tests on i686 +Subject: [PATCH 06/11] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there Signed-off-by: Elliott Sales de Andrade --- - Makefile | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) + Makefile | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile -index dc388c21..359ec8f5 100644 +index 60a5a574..cd3cb2f2 100644 --- a/Makefile +++ b/Makefile -@@ -295,12 +295,15 @@ TEST_PACKAGES_FAST = \ +@@ -328,7 +328,6 @@ TEST_PACKAGES_FAST = \ # Additional standard library packages that pass tests on individual platforms TEST_PACKAGES_LINUX := \ archive/zip \ - compress/flate \ compress/lzw \ + crypto/hmac \ debug/dwarf \ - debug/plan9obj \ -- io/fs \ -+ io/fs -+ifneq ($(shell uname -p),i686) +@@ -336,8 +335,15 @@ TEST_PACKAGES_LINUX := \ + io/fs \ + io/ioutil \ + strconv \ +- testing/fstest \ + text/template/parse ++ifneq ($(shell getconf LONG_BIT),32) ++# Some tests are skipped on 32-bit because: ++# compress/flate runs out of memory ++# testing/fstest uses Seek, which is not implemented there +TEST_PACKAGES_LINUX += \ + compress/flate \ - testing/fstest ++ testing/fstest +endif TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) diff --git a/0008-Temporarily-skip-io-fs-tests.patch b/0008-Temporarily-skip-io-fs-tests.patch index cad82f7..6f1c08a 100644 --- a/0008-Temporarily-skip-io-fs-tests.patch +++ b/0008-Temporarily-skip-io-fs-tests.patch @@ -1,27 +1,25 @@ -From 7f56024921ef935950f3dbb44067cc47094334d0 Mon Sep 17 00:00:00 2001 +From 7715588992ca3bd6495fff544a584b2708b1a3f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 21 Jul 2022 02:06:53 -0400 -Subject: [PATCH 8/8] Temporarily skip io/fs tests +Subject: [PATCH 08/11] Temporarily skip io/fs tests Signed-off-by: Elliott Sales de Andrade --- - Makefile | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) + Makefile | 1 - + 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile -index 359ec8f5..2f4a9bce 100644 +index cd3cb2f2..ff59e5e6 100644 --- a/Makefile +++ b/Makefile -@@ -297,8 +297,7 @@ TEST_PACKAGES_LINUX := \ - archive/zip \ - compress/lzw \ +@@ -332,7 +332,6 @@ TEST_PACKAGES_LINUX := \ + crypto/hmac \ debug/dwarf \ -- debug/plan9obj \ -- io/fs -+ debug/plan9obj - ifneq ($(shell uname -p),i686) - TEST_PACKAGES_LINUX += \ - compress/flate \ + debug/plan9obj \ +- io/fs \ + io/ioutil \ + strconv \ + text/template/parse -- 2.36.1 diff --git a/0009-Add-ErrProcessDone-error.patch b/0009-Add-ErrProcessDone-error.patch new file mode 100644 index 0000000..691f13f --- /dev/null +++ b/0009-Add-ErrProcessDone-error.patch @@ -0,0 +1,40 @@ +From 08a9276d4c9140545c5238cc3b9c7e20eadb5f97 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 6 Aug 2022 16:53:48 -0400 +Subject: [PATCH 09/11] Add ErrProcessDone error + +This is used in upstream Go's `os` package now. + +Signed-off-by: Elliott Sales de Andrade +--- + src/os/exec.go | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/os/exec.go b/src/os/exec.go +index 030979b2..a80c4316 100644 +--- a/src/os/exec.go ++++ b/src/os/exec.go +@@ -1,6 +1,9 @@ + package os + +-import "syscall" ++import ( ++ "errors" ++ "syscall" ++) + + type Signal interface { + String() string +@@ -24,6 +27,9 @@ type ProcAttr struct { + Sys *syscall.SysProcAttr + } + ++// ErrProcessDone indicates a Process has finished. ++var ErrProcessDone = errors.New("os: process already finished") ++ + type ProcessState struct { + } + +-- +2.36.1 + diff --git a/0010-Fix-tinygo-test-with-Go-1.19.patch b/0010-Fix-tinygo-test-with-Go-1.19.patch new file mode 100644 index 0000000..97cb453 --- /dev/null +++ b/0010-Fix-tinygo-test-with-Go-1.19.patch @@ -0,0 +1,42 @@ +From 246a99fa9991743651f3e518b873e2ab9b20e575 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 6 Aug 2022 17:25:56 -0400 +Subject: [PATCH 10/11] Fix tinygo-test with Go 1.19 + +One of the internal packages used for tests was moved in that version. + +Signed-off-by: Elliott Sales de Andrade +--- + Makefile | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index ff59e5e6..6876dbb5 100644 +--- a/Makefile ++++ b/Makefile +@@ -280,7 +280,6 @@ TEST_PACKAGES_FAST = \ + container/list \ + container/ring \ + crypto/des \ +- crypto/elliptic/internal/fiat \ + crypto/internal/subtle \ + crypto/md5 \ + crypto/rc4 \ +@@ -317,6 +316,14 @@ TEST_PACKAGES_FAST = \ + unicode \ + unicode/utf16 \ + unicode/utf8 \ ++ $(nil) ++ ++# Assume this will go away before Go2, so only check minor version. ++ifeq ($(filter $(shell $(GO) env GOVERSION | cut -f 2 -d.), 16 17 18), ) ++TEST_PACKAGES_FAST += crypto/internal/nistec/fiat ++else ++TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat ++endif + + # archive/zip requires os.ReadAt, which is not yet supported on windows + # debug/plan9obj requires os.ReadAt, which is not yet supported on windows +-- +2.36.1 + diff --git a/0011-Fix-tinygo-test-with-Go-1.16.patch b/0011-Fix-tinygo-test-with-Go-1.16.patch new file mode 100644 index 0000000..e9791ef --- /dev/null +++ b/0011-Fix-tinygo-test-with-Go-1.16.patch @@ -0,0 +1,46 @@ +From 55856a4dc32934077fb50c9536c33f0eaa0e74cb Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 7 Aug 2022 01:06:32 -0400 +Subject: [PATCH 11/11] Fix tinygo-test with Go 1.16 + +Some of these packages were only added in 1.17 + +Signed-off-by: Elliott Sales de Andrade +--- + Makefile | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/Makefile b/Makefile +index 6876dbb5..3bf6e614 100644 +--- a/Makefile ++++ b/Makefile +@@ -304,7 +304,6 @@ TEST_PACKAGES_FAST = \ + math \ + math/cmplx \ + net \ +- net/http/internal/ascii \ + net/mail \ + os \ + path \ +@@ -319,11 +318,17 @@ TEST_PACKAGES_FAST = \ + $(nil) + + # Assume this will go away before Go2, so only check minor version. +-ifeq ($(filter $(shell $(GO) env GOVERSION | cut -f 2 -d.), 16 17 18), ) ++GO_MINOR_VERSION := $(shell $(GO) env GOVERSION | cut -f 2 -d.) ++# Added in Go 1.17. ++ifeq ($(filter $(GO_MINOR_VERSION), 16), ) ++TEST_PACKAGES_FAST += net/http/internal/ascii ++ifeq ($(filter $(GO_MINOR_VERSION), 16 17 18), ) ++# Renamed fiat in Go 1.19. + TEST_PACKAGES_FAST += crypto/internal/nistec/fiat + else + TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat + endif ++endif + + # archive/zip requires os.ReadAt, which is not yet supported on windows + # debug/plan9obj requires os.ReadAt, which is not yet supported on windows +-- +2.36.1 + diff --git a/sources b/sources index 8dc11c7..c2fdadb 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.23.0.tar.gz) = 88eee87eb206c02adbf077f25f0ac1fb068827137d308cdf2b345fc669f0a1305fa0e95409cbd6d58a2515ab752cdd56b7fde81f124341148754782bfbe05714 +SHA512 (tinygo-0.25.0.tar.gz) = ec3d7e930f1b1aba79d506f236dc2da4ea0b693167eadb9fe36036da62135a468d6c0be3fe8cd4d888a051219107b86e4a2e79ebddcd0af823bb94281832c1b6 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 @@ -9,4 +9,4 @@ SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879a SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-f68b8204f797d6b3bfbc7c4da4d257961fbc8770.tar.gz) = fa58a7ddcb1a40239a220ca701a83895804b9ddc837652fa18e9aed2603bba2825df2074e2fa4fbf8649bb9a21308e877850273ec9d421795e2ae549f331ab13 -SHA512 (wasi-libc-ad5133410f66b93a2381db5b542aad5e0964db96.tar.gz) = 04cb3a25fef7949bf77f262bd939102f5b36e2ae85f28cdbfcd8a8984425fba54fae68049b777974bdbad96882fab383b44203e8f19a776d8a56a55475c4aab6 +SHA512 (wasi-libc-30094b6ed05f19cee102115215863d185f2db4f0.tar.gz) = 17492263fd5dca422f19e0ff8533e1f440e3b7516dc24ef0d16fdc44832cc63ec288c9e930f63b47fb71497144fed55cc313acc74339d067b8d4f5c7c683df0f diff --git a/tinygo.spec b/tinygo.spec index 078d4e0..434ec2d 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,18 +6,14 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.23.0 +Version: 0.25.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 %if %{fedora} > 35 %global clang_llvm_version 14 %else -%if %{fedora} > 34 %global clang_llvm_version 13 -%else -%global clang_llvm_version 12 -%endif %endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 @@ -25,7 +21,7 @@ Version: 0.23.0 %global musl_version 1.2.0 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 %global picolibc_commit f68b8204f797d6b3bfbc7c4da4d257961fbc8770 -%global wasi_libc_commit ad5133410f66b93a2381db5b542aad5e0964db96 +%global wasi_libc_commit 30094b6ed05f19cee102115215863d185f2db4f0 # No longer matching regular Go's /usr/share/gocode because it also provides # pre-compiled binaries, and symlinks to arch-specific clang headers. @@ -83,16 +79,19 @@ Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions Patch0004: 0004-Suggest-optional-packages-to-install-if-missing.patch -# https://github.com/tinygo-org/tinygo/pull/2837 -Patch0005: 0005-Skip-slice-copy-test-for-LLVM-14.patch # https://github.com/tinygo-org/tinygo/pull/2840 -Patch0006: 0006-Skip-TestDirFS-on-32-bit-systems.patch -Patch0007: 0007-Skip-broken-tests-on-i686.patch +Patch0005: 0005-Skip-TestDirFS-on-32-bit-systems.patch +Patch0006: 0006-Skip-broken-tests-on-i686.patch # https://github.com/tinygo-org/tinygo/issues/3008 # Broken due to TestCVE202230630 Patch0008: 0008-Temporarily-skip-io-fs-tests.patch +# https://github.com/tinygo-org/tinygo/pull/3060 +Patch0009: 0009-Add-ErrProcessDone-error.patch +Patch0010: 0010-Fix-tinygo-test-with-Go-1.19.patch +Patch0011: 0011-Fix-tinygo-test-with-Go-1.16.patch + # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -112,7 +111,7 @@ BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 BuildRequires: golang(go.bug.st/serial) >= 1.1.2 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) -BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.7 +BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.11 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: golang-tests @@ -208,13 +207,6 @@ tar -C lib -xf %{SOURCE10} rmdir lib/wasi-libc mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc -# These packages were added in Go 1.17, so we can't test them in older Fedora. -%if %{fedora} && %{fedora} < 36 -sed -i \ - -e 's!crypto/elliptic/internal/fiat !!g' \ - -e 's!net/http/internal/ascii !!g' \ - Makefile -%endif # This test is too slow and pretty much freezes. %ifarch %{ix86} sed -i -e 's!archive/zip!$(nil)!' Makefile @@ -313,16 +305,18 @@ export PATH=%{buildroot}%{_bindir}:$PATH export GO111MODULE=off export XDG_CACHE_HOME="${PWD}/$(mktemp -d tinygo.XXXXXX)" %gocheck -v -t src -t tests -make smoketest STM32=0 XTENSA=0 +( cd _build/src/%{goipath} && GOPATH=%{currentgosourcedir}/_build:$GOPATH make smoketest STM32=0 XTENSA=0 ) %if %{fedora} > 35 %ifnarch %{ix86} aarch64 make wasmtest %endif %endif +# Ignoring errors due to CGo issue: +# https://github.com/tinygo-org/tinygo/issues/3057 %ifarch %{ix86} -make tinygo-test-fast +make tinygo-test-fast || true %else -make tinygo-test +make tinygo-test || true %endif %endif From d515a92b8f611679ce9cf6653548d1132ead9f1f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 7 Aug 2022 18:55:42 -0400 Subject: [PATCH 40/78] Drop support for i686 As suggested in the F37 change: https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval --- tinygo.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tinygo.spec b/tinygo.spec index 434ec2d..6ee3a96 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -94,6 +94,8 @@ Patch0011: 0011-Fix-tinygo-test-with-Go-1.16.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x +# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval +ExcludeArch: %{ix86} BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) BuildRequires: golang(github.com/aykevl/go-wasm) From 544baed7e0bae83a4ef2b7ee622bdfccff305860 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 8 Oct 2022 23:30:40 -0400 Subject: [PATCH 41/78] Fix missing musl directory See https://github.com/tinygo-org/tinygo/issues/3057 --- tinygo.spec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tinygo.spec b/tinygo.spec index 434ec2d..d8fcbd9 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -261,6 +261,7 @@ cp -rp lib/musl/src/errno %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/exit %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/include %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/internal %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/legacy %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/malloc %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/mman %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/signal %{buildroot}%{tinygoroot}/lib/musl/src @@ -314,9 +315,9 @@ make wasmtest # Ignoring errors due to CGo issue: # https://github.com/tinygo-org/tinygo/issues/3057 %ifarch %{ix86} -make tinygo-test-fast || true +make tinygo-test-fast %else -make tinygo-test || true +make tinygo-test %endif %endif From 9b32d8b0ddc883f147dfe150fbeba3c7832147a1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 8 Oct 2022 04:31:34 -0400 Subject: [PATCH 42/78] Update to latest version (#2132066) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 10 ++-- 0002-Use-system-mingw64-headers-and-crt.patch | 12 ++--- ...oss-Linux-tests-where-qemu-is-broken.patch | 10 ++-- ...ional-packages-to-install-if-missing.patch | 4 +- 0005-Skip-TestDirFS-on-32-bit-systems.patch | 6 +-- 0006-Skip-broken-tests-on-i686.patch | 11 ++--- 0008-Temporarily-skip-io-fs-tests.patch | 25 ---------- 0009-Add-ErrProcessDone-error.patch | 40 ---------------- 0010-Fix-tinygo-test-with-Go-1.19.patch | 42 ----------------- 0011-Fix-tinygo-test-with-Go-1.16.patch | 46 ------------------- sources | 2 +- tinygo.spec | 25 +++------- 13 files changed, 34 insertions(+), 200 deletions(-) delete mode 100644 0008-Temporarily-skip-io-fs-tests.patch delete mode 100644 0009-Add-ErrProcessDone-error.patch delete mode 100644 0010-Fix-tinygo-test-with-Go-1.19.patch delete mode 100644 0011-Fix-tinygo-test-with-Go-1.16.patch diff --git a/.gitignore b/.gitignore index 305c25b..0f45ff4 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ /compiler-rt-12.0.0.src.tar.xz.sig /compiler-rt-14.0.0.src.tar.xz.sig /tinygo-0.25.0.tar.gz +/tinygo-0.26.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 5db9255..6ddce34 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From f62e55a3c636caf2a609a0290701ca7108ab4c46 Mon Sep 17 00:00:00 2001 +From 6b50974a6d4972b755a35d40d87e5bdf9c97d925 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 01/11] Skip WASI tests. +Subject: [PATCH 1/6] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index f620c77d..3e97f481 100644 +index 9ddbe52f..79ae2cf2 100644 --- a/main_test.go +++ b/main_test.go -@@ -165,10 +165,6 @@ func TestBuild(t *testing.T) { +@@ -154,10 +154,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -25,7 +25,7 @@ index f620c77d..3e97f481 100644 } } -@@ -408,7 +404,6 @@ func TestTest(t *testing.T) { +@@ -413,7 +409,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index e8dd0c8..187daab 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ -From 7c10e6e5debde713b52008e1f7476ffa036e2d48 Mon Sep 17 00:00:00 2001 +From 76c575659d42187b0c4c15d4f5978c4368800da7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 02/11] Use system mingw64 headers and crt +Subject: [PATCH 2/6] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- @@ -10,7 +10,7 @@ Signed-off-by: Elliott Sales de Andrade 2 files changed, 7 insertions(+), 68 deletions(-) diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index 135cae94..d233068d 100644 +index 27fefee0..d233068d 100644 --- a/builder/mingw-w64.go +++ b/builder/mingw-w64.go @@ -1,31 +1,11 @@ @@ -84,7 +84,7 @@ index 135cae94..d233068d 100644 - // .in files need to be preprocessed by a preprocessor (-E) - // first. - defpath = outpath + ".def" -- err := runCCompiler("-E", "-x", "c", "-Wp,-w", "-P", "-DDEF_X64", "-o", defpath, inpath, "-I"+goenv.Get("TINYGOROOT")+"/lib/mingw-w64/mingw-w64-crt/def-include/") +- err := runCCompiler("-E", "-x", "c", "-Wp,-w", "-P", "-DDEF_X64", "-DDATA", "-o", defpath, inpath, "-I"+goenv.Get("TINYGOROOT")+"/lib/mingw-w64/mingw-w64-crt/def-include/") - if err != nil { - return err - } @@ -99,10 +99,10 @@ index 135cae94..d233068d 100644 } return jobs diff --git a/compileopts/config.go b/compileopts/config.go -index a006b673..c81a547c 100644 +index ebfc5082..cd49283d 100644 --- a/compileopts/config.go +++ b/compileopts/config.go -@@ -297,12 +297,9 @@ func (c *Config) CFlags() []string { +@@ -304,12 +304,9 @@ func (c *Config) CFlags() []string { root := goenv.Get("TINYGOROOT") cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") case "mingw-w64": diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 789228d..b383fce 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 09c7cf0930704cc07844e6a926c5f8e667350730 Mon Sep 17 00:00:00 2001 +From 2a2e35e4565e8ea7f7ac2d34cb9da24000bb6474 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 03/11] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 3/6] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 28 insertions(+) diff --git a/main_test.go b/main_test.go -index 3e97f481..44d85249 100644 +index 79ae2cf2..9359ef0c 100644 --- a/main_test.go +++ b/main_test.go -@@ -250,6 +250,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -252,6 +252,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -38,7 +38,7 @@ index 3e97f481..44d85249 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -336,6 +350,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -341,6 +355,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch index 14ff89c..6f333e2 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From c995ba5cf2fb21c419dc82afe9968a020aadf182 Mon Sep 17 00:00:00 2001 +From 3f935d679870de924aa65d78c23ecdcb483ab4a3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 04/11] Suggest optional packages to install if missing +Subject: [PATCH 4/6] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0005-Skip-TestDirFS-on-32-bit-systems.patch b/0005-Skip-TestDirFS-on-32-bit-systems.patch index 877ec55..cdfca0d 100644 --- a/0005-Skip-TestDirFS-on-32-bit-systems.patch +++ b/0005-Skip-TestDirFS-on-32-bit-systems.patch @@ -1,7 +1,7 @@ -From 85a4d526d5109bbd4ca2f56fa00fd1d9fccfe065 Mon Sep 17 00:00:00 2001 +From 41cbdf1cfe50f24b49beb615f0924ea3255c7e7d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 05/11] Skip TestDirFS on 32-bit systems +Subject: [PATCH 5/6] Skip TestDirFS on 32-bit systems Because Seek is not fully implemented there. @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 4 insertions(+) diff --git a/src/os/os_anyos_test.go b/src/os/os_anyos_test.go -index d8ac01c2..f84a4083 100644 +index dd255fb4..5dc0d860 100644 --- a/src/os/os_anyos_test.go +++ b/src/os/os_anyos_test.go @@ -277,6 +277,10 @@ func TestDirFS(t *testing.T) { diff --git a/0006-Skip-broken-tests-on-i686.patch b/0006-Skip-broken-tests-on-i686.patch index ea1071d..ac4d59f 100644 --- a/0006-Skip-broken-tests-on-i686.patch +++ b/0006-Skip-broken-tests-on-i686.patch @@ -1,7 +1,7 @@ -From c645a887a6989e0210c782bb84d4f31200e0d333 Mon Sep 17 00:00:00 2001 +From a44f31de099aaf6768af2102919f1a8c221ce6f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 06/11] Skip broken tests on i686 +Subject: [PATCH 6/6] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there @@ -12,10 +12,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile -index 60a5a574..cd3cb2f2 100644 +index 99f67c29..1ef11d29 100644 --- a/Makefile +++ b/Makefile -@@ -328,7 +328,6 @@ TEST_PACKAGES_FAST = \ +@@ -338,15 +338,21 @@ endif # Additional standard library packages that pass tests on individual platforms TEST_PACKAGES_LINUX := \ archive/zip \ @@ -23,8 +23,7 @@ index 60a5a574..cd3cb2f2 100644 compress/lzw \ crypto/hmac \ debug/dwarf \ -@@ -336,8 +335,15 @@ TEST_PACKAGES_LINUX := \ - io/fs \ + debug/plan9obj \ io/ioutil \ strconv \ - testing/fstest \ diff --git a/0008-Temporarily-skip-io-fs-tests.patch b/0008-Temporarily-skip-io-fs-tests.patch deleted file mode 100644 index 6f1c08a..0000000 --- a/0008-Temporarily-skip-io-fs-tests.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 7715588992ca3bd6495fff544a584b2708b1a3f4 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Thu, 21 Jul 2022 02:06:53 -0400 -Subject: [PATCH 08/11] Temporarily skip io/fs tests - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/Makefile b/Makefile -index cd3cb2f2..ff59e5e6 100644 ---- a/Makefile -+++ b/Makefile -@@ -332,7 +332,6 @@ TEST_PACKAGES_LINUX := \ - crypto/hmac \ - debug/dwarf \ - debug/plan9obj \ -- io/fs \ - io/ioutil \ - strconv \ - text/template/parse --- -2.36.1 - diff --git a/0009-Add-ErrProcessDone-error.patch b/0009-Add-ErrProcessDone-error.patch deleted file mode 100644 index 691f13f..0000000 --- a/0009-Add-ErrProcessDone-error.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 08a9276d4c9140545c5238cc3b9c7e20eadb5f97 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 6 Aug 2022 16:53:48 -0400 -Subject: [PATCH 09/11] Add ErrProcessDone error - -This is used in upstream Go's `os` package now. - -Signed-off-by: Elliott Sales de Andrade ---- - src/os/exec.go | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/src/os/exec.go b/src/os/exec.go -index 030979b2..a80c4316 100644 ---- a/src/os/exec.go -+++ b/src/os/exec.go -@@ -1,6 +1,9 @@ - package os - --import "syscall" -+import ( -+ "errors" -+ "syscall" -+) - - type Signal interface { - String() string -@@ -24,6 +27,9 @@ type ProcAttr struct { - Sys *syscall.SysProcAttr - } - -+// ErrProcessDone indicates a Process has finished. -+var ErrProcessDone = errors.New("os: process already finished") -+ - type ProcessState struct { - } - --- -2.36.1 - diff --git a/0010-Fix-tinygo-test-with-Go-1.19.patch b/0010-Fix-tinygo-test-with-Go-1.19.patch deleted file mode 100644 index 97cb453..0000000 --- a/0010-Fix-tinygo-test-with-Go-1.19.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 246a99fa9991743651f3e518b873e2ab9b20e575 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 6 Aug 2022 17:25:56 -0400 -Subject: [PATCH 10/11] Fix tinygo-test with Go 1.19 - -One of the internal packages used for tests was moved in that version. - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 9 ++++++++- - 1 file changed, 8 insertions(+), 1 deletion(-) - -diff --git a/Makefile b/Makefile -index ff59e5e6..6876dbb5 100644 ---- a/Makefile -+++ b/Makefile -@@ -280,7 +280,6 @@ TEST_PACKAGES_FAST = \ - container/list \ - container/ring \ - crypto/des \ -- crypto/elliptic/internal/fiat \ - crypto/internal/subtle \ - crypto/md5 \ - crypto/rc4 \ -@@ -317,6 +316,14 @@ TEST_PACKAGES_FAST = \ - unicode \ - unicode/utf16 \ - unicode/utf8 \ -+ $(nil) -+ -+# Assume this will go away before Go2, so only check minor version. -+ifeq ($(filter $(shell $(GO) env GOVERSION | cut -f 2 -d.), 16 17 18), ) -+TEST_PACKAGES_FAST += crypto/internal/nistec/fiat -+else -+TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat -+endif - - # archive/zip requires os.ReadAt, which is not yet supported on windows - # debug/plan9obj requires os.ReadAt, which is not yet supported on windows --- -2.36.1 - diff --git a/0011-Fix-tinygo-test-with-Go-1.16.patch b/0011-Fix-tinygo-test-with-Go-1.16.patch deleted file mode 100644 index e9791ef..0000000 --- a/0011-Fix-tinygo-test-with-Go-1.16.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 55856a4dc32934077fb50c9536c33f0eaa0e74cb Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 7 Aug 2022 01:06:32 -0400 -Subject: [PATCH 11/11] Fix tinygo-test with Go 1.16 - -Some of these packages were only added in 1.17 - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/Makefile b/Makefile -index 6876dbb5..3bf6e614 100644 ---- a/Makefile -+++ b/Makefile -@@ -304,7 +304,6 @@ TEST_PACKAGES_FAST = \ - math \ - math/cmplx \ - net \ -- net/http/internal/ascii \ - net/mail \ - os \ - path \ -@@ -319,11 +318,17 @@ TEST_PACKAGES_FAST = \ - $(nil) - - # Assume this will go away before Go2, so only check minor version. --ifeq ($(filter $(shell $(GO) env GOVERSION | cut -f 2 -d.), 16 17 18), ) -+GO_MINOR_VERSION := $(shell $(GO) env GOVERSION | cut -f 2 -d.) -+# Added in Go 1.17. -+ifeq ($(filter $(GO_MINOR_VERSION), 16), ) -+TEST_PACKAGES_FAST += net/http/internal/ascii -+ifeq ($(filter $(GO_MINOR_VERSION), 16 17 18), ) -+# Renamed fiat in Go 1.19. - TEST_PACKAGES_FAST += crypto/internal/nistec/fiat - else - TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat - endif -+endif - - # archive/zip requires os.ReadAt, which is not yet supported on windows - # debug/plan9obj requires os.ReadAt, which is not yet supported on windows --- -2.36.1 - diff --git a/sources b/sources index c2fdadb..4597e0f 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.25.0.tar.gz) = ec3d7e930f1b1aba79d506f236dc2da4ea0b693167eadb9fe36036da62135a468d6c0be3fe8cd4d888a051219107b86e4a2e79ebddcd0af823bb94281832c1b6 +SHA512 (tinygo-0.26.0.tar.gz) = 7b95f6b4356545b806207092fa315863446227e3f90d05abad1f231b381d402b00654e11ab79472c32d5572ea7183bdd4e5ee34190a13e3aefa668ebcd1042b4 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 diff --git a/tinygo.spec b/tinygo.spec index d8fcbd9..e228822 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,15 +6,11 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.25.0 +Version: 0.26.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%if %{fedora} > 35 %global clang_llvm_version 14 -%else -%global clang_llvm_version 13 -%endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 @@ -83,33 +79,24 @@ Patch0004: 0004-Suggest-optional-packages-to-install-if-missing.patch Patch0005: 0005-Skip-TestDirFS-on-32-bit-systems.patch Patch0006: 0006-Skip-broken-tests-on-i686.patch -# https://github.com/tinygo-org/tinygo/issues/3008 -# Broken due to TestCVE202230630 -Patch0008: 0008-Temporarily-skip-io-fs-tests.patch - -# https://github.com/tinygo-org/tinygo/pull/3060 -Patch0009: 0009-Add-ErrProcessDone-error.patch -Patch0010: 0010-Fix-tinygo-test-with-Go-1.19.patch -Patch0011: 0011-Fix-tinygo-test-with-Go-1.16.patch - # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) BuildRequires: golang(github.com/aykevl/go-wasm) BuildRequires: golang(github.com/blakesmith/ar) -%if %{fedora} > 35 %ifnarch %{ix86} BuildRequires: chromium BuildRequires: golang(github.com/chromedp/chromedp) >= 0.7.6 BuildRequires: golang(github.com/chromedp/cdproto/cdp) %endif -%endif BuildRequires: golang(github.com/gofrs/flock) >= 0.8.1 BuildRequires: golang(github.com/google/shlex) +BuildRequires: golang(github.com/inhies/go-bytesize) BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 -BuildRequires: golang(go.bug.st/serial) >= 1.1.2 +BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 +BuildRequires: golang(go.bug.st/serial) >= 1.3.5 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.11 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 @@ -264,6 +251,7 @@ cp -rp lib/musl/src/internal %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/legacy %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/malloc %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/mman %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/math %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/signal %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/stdio %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/string %{buildroot}%{tinygoroot}/lib/musl/src @@ -284,6 +272,7 @@ cp -rp lib/picolibc/newlib/libc/tinystdio %{buildroot}%{tinygoroot}/lib/picolibc chmod -x %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc/tinystdio/make-dtoa-data install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc/newlib/libm/common %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm +cp -rp lib/picolibc/newlib/libm/math %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc-stdio.c %{buildroot}%{tinygoroot}/lib install -vdm 0755 %{buildroot}%{tinygoroot}/pkg for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-eabi-cortex-m0plus thumbv7em-unknown-unknown-eabi-cortex-m4; do @@ -307,11 +296,9 @@ export GO111MODULE=off export XDG_CACHE_HOME="${PWD}/$(mktemp -d tinygo.XXXXXX)" %gocheck -v -t src -t tests ( cd _build/src/%{goipath} && GOPATH=%{currentgosourcedir}/_build:$GOPATH make smoketest STM32=0 XTENSA=0 ) -%if %{fedora} > 35 %ifnarch %{ix86} aarch64 make wasmtest %endif -%endif # Ignoring errors due to CGo issue: # https://github.com/tinygo-org/tinygo/issues/3057 %ifarch %{ix86} From b0024804f5404a811e4454beaa596a07e8b478db Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 24 Oct 2022 05:50:05 -0400 Subject: [PATCH 43/78] Backport patches for LLVM 15 support --- .gitignore | 4 +- 0001-Skip-WASI-tests.patch | 2 +- 0002-Use-system-mingw64-headers-and-crt.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- ...ional-packages-to-install-if-missing.patch | 2 +- 0005-Skip-TestDirFS-on-32-bit-systems.patch | 2 +- 0006-Skip-broken-tests-on-i686.patch | 2 +- 0007-wasm-fix-GC-scanning-of-allocas.patch | 265 ++ ...a-FunctionType-not-a-PointerType-in-.patch | 52 + ...all-add-type-parameter-to-CreateCall.patch | 993 +++++ ...all-add-type-parameter-to-CreateLoad.patch | 377 ++ ...-all-add-type-parameter-to-GEP-calls.patch | 565 +++ ....Const-calls-with-builder.Create-cal.patch | 578 +++ ...ject.llvmType-to-the-initializer-typ.patch | 79 + ...all-remove-pointer-ElementType-calls.patch | 586 +++ ...ansform-fix-memory-corruption-issues.patch | 31 + 0016-riscv-add-target-abi-metadata-flag.patch | 193 + ...pport-for-constant-icmp-instructions.patch | 195 + 0018-ci-add-support-for-LLVM-15.patch | 3490 +++++++++++++++++ compiler-rt-release-keys.asc | 104 + sources | 4 +- tinygo.spec | 22 +- tstellar-gpg-key.asc | Bin 2222 -> 0 bytes 23 files changed, 7538 insertions(+), 12 deletions(-) create mode 100644 0007-wasm-fix-GC-scanning-of-allocas.patch create mode 100644 0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch create mode 100644 0009-all-add-type-parameter-to-CreateCall.patch create mode 100644 0010-all-add-type-parameter-to-CreateLoad.patch create mode 100644 0011-all-add-type-parameter-to-GEP-calls.patch create mode 100644 0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch create mode 100644 0013-interp-change-object.llvmType-to-the-initializer-typ.patch create mode 100644 0014-all-remove-pointer-ElementType-calls.patch create mode 100644 0015-transform-fix-memory-corruption-issues.patch create mode 100644 0016-riscv-add-target-abi-metadata-flag.patch create mode 100644 0017-interp-add-support-for-constant-icmp-instructions.patch create mode 100644 0018-ci-add-support-for-LLVM-15.patch create mode 100644 compiler-rt-release-keys.asc delete mode 100644 tstellar-gpg-key.asc diff --git a/.gitignore b/.gitignore index 0f45ff4..4ddee71 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /cmsis_svd-*.tar.gz /cmsis_svd-*-clean.tar.xz /compiler-rt-*.src.tar.xz +/compiler-rt-*.src.tar.xz.sig /nrfx-*.tar.gz /picolibc-*.tar.gz /wasi-libc-*.tar.gz @@ -32,9 +33,6 @@ /musl-1.2.0.tar.gz /musl-1.2.0.tar.gz.asc /tinygo-0.23.0.tar.gz -/compiler-rt-13.0.0.src.tar.xz.sig /macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz -/compiler-rt-12.0.0.src.tar.xz.sig -/compiler-rt-14.0.0.src.tar.xz.sig /tinygo-0.25.0.tar.gz /tinygo-0.26.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 6ddce34..1f648df 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 6b50974a6d4972b755a35d40d87e5bdf9c97d925 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/6] Skip WASI tests. +Subject: [PATCH 01/18] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index 187daab..821f09a 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ From 76c575659d42187b0c4c15d4f5978c4368800da7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/6] Use system mingw64 headers and crt +Subject: [PATCH 02/18] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index b383fce..87d5c28 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From 2a2e35e4565e8ea7f7ac2d34cb9da24000bb6474 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/6] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 03/18] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch index 6f333e2..b7f2c2c 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From 3f935d679870de924aa65d78c23ecdcb483ab4a3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 4/6] Suggest optional packages to install if missing +Subject: [PATCH 04/18] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0005-Skip-TestDirFS-on-32-bit-systems.patch b/0005-Skip-TestDirFS-on-32-bit-systems.patch index cdfca0d..9101800 100644 --- a/0005-Skip-TestDirFS-on-32-bit-systems.patch +++ b/0005-Skip-TestDirFS-on-32-bit-systems.patch @@ -1,7 +1,7 @@ From 41cbdf1cfe50f24b49beb615f0924ea3255c7e7d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 5/6] Skip TestDirFS on 32-bit systems +Subject: [PATCH 05/18] Skip TestDirFS on 32-bit systems Because Seek is not fully implemented there. diff --git a/0006-Skip-broken-tests-on-i686.patch b/0006-Skip-broken-tests-on-i686.patch index ac4d59f..98e0acf 100644 --- a/0006-Skip-broken-tests-on-i686.patch +++ b/0006-Skip-broken-tests-on-i686.patch @@ -1,7 +1,7 @@ From a44f31de099aaf6768af2102919f1a8c221ce6f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 6/6] Skip broken tests on i686 +Subject: [PATCH 06/18] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there diff --git a/0007-wasm-fix-GC-scanning-of-allocas.patch b/0007-wasm-fix-GC-scanning-of-allocas.patch new file mode 100644 index 0000000..02da873 --- /dev/null +++ b/0007-wasm-fix-GC-scanning-of-allocas.patch @@ -0,0 +1,265 @@ +From e8f07384a0f5a61351a62931d3fb69bf6c451c1b Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sun, 16 Oct 2022 00:44:38 +0200 +Subject: [PATCH 07/18] wasm: fix GC scanning of allocas + +Scanning of allocas was entirely broken on WebAssembly. The code +intended to do this was never run. There were also no tests. + +Looking into this further, I found that it is actually not really +necessary to do that: the C stack can be scanned conservatively and in +fact this was already done for goroutine stacks (because they live on +the heap and are always referenced). It wasn't done for the system stack +however. + +With these fixes, I believe code should be both faster *and* more +correct. + +I found this in my work to get opaque pointers supported in LLVM 15, +because the code that was never reached now finally got run and was +actually quite buggy. + +Signed-off-by: Elliott Sales de Andrade +--- + src/runtime/arch_tinygowasm.go | 3 +++ + src/runtime/asm_tinygowasm.S | 10 ++++++++++ + src/runtime/gc_stack_portable.go | 34 +++++++++++++++++++++----------- + targets/wasi.json | 3 +++ + targets/wasm.json | 3 +++ + transform/gc.go | 30 ++++++++-------------------- + transform/llvm.go | 28 ++++++++------------------ + 7 files changed, 57 insertions(+), 54 deletions(-) + create mode 100644 src/runtime/asm_tinygowasm.S + +diff --git a/src/runtime/arch_tinygowasm.go b/src/runtime/arch_tinygowasm.go +index 597b2489..f1893d91 100644 +--- a/src/runtime/arch_tinygowasm.go ++++ b/src/runtime/arch_tinygowasm.go +@@ -58,6 +58,8 @@ var ( + + globalsStart = uintptr(unsafe.Pointer(&globalsStartSymbol)) + globalsEnd = uintptr(unsafe.Pointer(&heapStartSymbol)) ++ ++ stackTop = uintptr(unsafe.Pointer(&globalsStartSymbol)) + ) + + func align(ptr uintptr) uintptr { +@@ -67,6 +69,7 @@ func align(ptr uintptr) uintptr { + return (ptr + heapAlign - 1) &^ (heapAlign - 1) + } + ++//export tinygo_getCurrentStackPointer + func getCurrentStackPointer() uintptr + + // growHeap tries to grow the heap size. It returns true if it succeeds, false +diff --git a/src/runtime/asm_tinygowasm.S b/src/runtime/asm_tinygowasm.S +new file mode 100644 +index 00000000..3278a7f6 +--- /dev/null ++++ b/src/runtime/asm_tinygowasm.S +@@ -0,0 +1,10 @@ ++.globaltype __stack_pointer, i32 ++ ++.global tinygo_getCurrentStackPointer ++.hidden tinygo_getCurrentStackPointer ++.type tinygo_getCurrentStackPointer,@function ++tinygo_getCurrentStackPointer: // func getCurrentStackPointer() uintptr ++ .functype tinygo_getCurrentStackPointer() -> (i32) ++ global.get __stack_pointer ++ return ++ end_function +diff --git a/src/runtime/gc_stack_portable.go b/src/runtime/gc_stack_portable.go +index 6ffc35d4..6802de02 100644 +--- a/src/runtime/gc_stack_portable.go ++++ b/src/runtime/gc_stack_portable.go +@@ -4,6 +4,7 @@ + package runtime + + import ( ++ "internal/task" + "unsafe" + ) + +@@ -17,19 +18,28 @@ type stackChainObject struct { + + // markStack marks all root pointers found on the stack. + // +-// This implementation is conservative and relies on the compiler inserting code +-// to manually push/pop stack objects that are stored in a linked list starting +-// with stackChainStart. Manually keeping track of stack values is _much_ more +-// expensive than letting the compiler do it and it inhibits a few important +-// optimizations, but it has the big advantage of being portable to basically +-// any ISA, including WebAssembly. ++// - Goroutine stacks are heap allocated and always reachable in some way ++// (for example through internal/task.currentTask) so they will always be ++// scanned. ++// - The system stack (aka startup stack) is not heap allocated, so even ++// though it may be referenced it will not be scanned by default. ++// ++// Therefore, we only need to scan the system stack. ++// It is relatively easy to scan the system stack while we're on it: we can ++// simply read __stack_pointer and __global_base and scan the area inbetween. ++// Unfortunately, it's hard to get the system stack pointer while we're on a ++// goroutine stack. But when we're on a goroutine stack, the system stack is in ++// the scheduler which means there shouldn't be anything on the system stack ++// anyway. ++// ...I hope this assumption holds, otherwise we will need to store the system ++// stack in a global or something. ++// ++// The compiler also inserts code to store all globals in a chain via ++// stackChainStart. Luckily we don't need to scan these, as these globals are ++// stored on the goroutine stack and are therefore already getting scanned. + func markStack() { +- stackObject := stackChainStart +- for stackObject != nil { +- start := uintptr(unsafe.Pointer(stackObject)) + unsafe.Sizeof(uintptr(0))*2 +- end := start + stackObject.numSlots*unsafe.Alignof(uintptr(0)) +- markRoots(start, end) +- stackObject = stackObject.parent ++ if task.OnSystemStack() { ++ markRoots(getCurrentStackPointer(), stackTop) + } + } + +diff --git a/targets/wasi.json b/targets/wasi.json +index e710b4bb..6cec6be4 100644 +--- a/targets/wasi.json ++++ b/targets/wasi.json +@@ -18,6 +18,9 @@ + "--stack-first", + "--no-demangle" + ], ++ "extra-files": [ ++ "src/runtime/asm_tinygowasm.S" ++ ], + "emulator": "wasmtime {}", + "wasm-abi": "generic" + } +diff --git a/targets/wasm.json b/targets/wasm.json +index 2bcada5f..26494cc4 100644 +--- a/targets/wasm.json ++++ b/targets/wasm.json +@@ -19,6 +19,9 @@ + "--stack-first", + "--no-demangle" + ], ++ "extra-files": [ ++ "src/runtime/asm_tinygowasm.S" ++ ], + "emulator": "node {root}/targets/wasm_exec.js {}", + "wasm-abi": "js" + } +diff --git a/transform/gc.go b/transform/gc.go +index eb3520aa..87dc6e88 100644 +--- a/transform/gc.go ++++ b/transform/gc.go +@@ -139,7 +139,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + } + + // Determine what to do with each call. +- var allocas, pointers []llvm.Value ++ var pointers []llvm.Value + for _, call := range calls { + ptr := call.Operand(0) + call.EraseFromParentAsInstruction() +@@ -189,16 +189,15 @@ func MakeGCStackSlots(mod llvm.Module) bool { + // be optimized if needed. + } + +- if !ptr.IsAAllocaInst().IsNil() { +- if typeHasPointers(ptr.Type().ElementType()) { +- allocas = append(allocas, ptr) +- } +- } else { +- pointers = append(pointers, ptr) ++ if ptr := stripPointerCasts(ptr); !ptr.IsAAllocaInst().IsNil() { ++ // Allocas don't need to be tracked because they are allocated ++ // on the C stack which is scanned separately. ++ continue + } ++ pointers = append(pointers, ptr) + } + +- if len(allocas) == 0 && len(pointers) == 0 { ++ if len(pointers) == 0 { + // This function does not need to keep track of stack pointers. + continue + } +@@ -208,9 +207,6 @@ func MakeGCStackSlots(mod llvm.Module) bool { + stackChainStartType, // Pointer to parent frame. + uintptrType, // Number of elements in this frame. + } +- for _, alloca := range allocas { +- fields = append(fields, alloca.Type().ElementType()) +- } + for _, ptr := range pointers { + fields = append(fields, ptr.Type()) + } +@@ -235,16 +231,6 @@ func MakeGCStackSlots(mod llvm.Module) bool { + stackObjectCast := builder.CreateBitCast(stackObject, stackChainStartType, "") + builder.CreateStore(stackObjectCast, stackChainStart) + +- // Replace all independent allocas with GEPs in the stack object. +- for i, alloca := range allocas { +- gep := builder.CreateGEP(stackObject, []llvm.Value{ +- llvm.ConstInt(ctx.Int32Type(), 0, false), +- llvm.ConstInt(ctx.Int32Type(), uint64(2+i), false), +- }, "") +- alloca.ReplaceAllUsesWith(gep) +- alloca.EraseFromParentAsInstruction() +- } +- + // Do a store to the stack object after each new pointer that is created. + pointerStores := make(map[llvm.Value]struct{}) + for i, ptr := range pointers { +@@ -260,7 +246,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + // Extract a pointer to the appropriate section of the stack object. + gep := builder.CreateGEP(stackObject, []llvm.Value{ + llvm.ConstInt(ctx.Int32Type(), 0, false), +- llvm.ConstInt(ctx.Int32Type(), uint64(2+len(allocas)+i), false), ++ llvm.ConstInt(ctx.Int32Type(), uint64(2+i), false), + }, "") + + // Store the pointer into the stack slot. +diff --git a/transform/llvm.go b/transform/llvm.go +index 90b7a7c7..32ee9560 100644 +--- a/transform/llvm.go ++++ b/transform/llvm.go +@@ -75,26 +75,14 @@ func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) ll + return global + } + +-// typeHasPointers returns whether this type is a pointer or contains pointers. +-// If the type is an aggregate type, it will check whether there is a pointer +-// inside. +-func typeHasPointers(t llvm.Type) bool { +- switch t.TypeKind() { +- case llvm.PointerTypeKind: +- return true +- case llvm.StructTypeKind: +- for _, subType := range t.StructElementTypes() { +- if typeHasPointers(subType) { +- return true +- } ++// stripPointerCasts strips instruction pointer casts (getelementptr and ++// bitcast) and returns the original value without the casts. ++func stripPointerCasts(value llvm.Value) llvm.Value { ++ if !value.IsAInstruction().IsNil() { ++ switch value.InstructionOpcode() { ++ case llvm.GetElementPtr, llvm.BitCast: ++ return stripPointerCasts(value.Operand(0)) + } +- return false +- case llvm.ArrayTypeKind: +- if typeHasPointers(t.ElementType()) { +- return true +- } +- return false +- default: +- return false + } ++ return value + } +-- +2.36.1 + diff --git a/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch b/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch new file mode 100644 index 0000000..77d6ea3 --- /dev/null +++ b/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch @@ -0,0 +1,52 @@ +From 9e64a63d49100e550fad97b390bb01489ed6ca44 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Tue, 20 Sep 2022 23:59:22 +0200 +Subject: [PATCH 08/18] compiler: return a FunctionType (not a PointerType) in + getRawFuncType + +This is necessary for opaque pointer support (in LLVM 15). + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/func.go | 4 ++-- + compiler/interface.go | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/compiler/func.go b/compiler/func.go +index 75656cb7..a8b2874e 100644 +--- a/compiler/func.go ++++ b/compiler/func.go +@@ -62,7 +62,7 @@ func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (f + funcPtr = bitcast.Operand(0) + return + } +- llvmSig := b.getRawFuncType(sig) ++ llvmSig := llvm.PointerType(b.getRawFuncType(sig), b.funcPtrAddrSpace) + funcPtr = b.CreateBitCast(bitcast, llvmSig, "") + return + } +@@ -117,7 +117,7 @@ func (c *compilerContext) getRawFuncType(typ *types.Signature) llvm.Type { + paramTypes = append(paramTypes, c.i8ptrType) // context + + // Make a func type out of the signature. +- return llvm.PointerType(llvm.FunctionType(returnType, paramTypes, false), c.funcPtrAddrSpace) ++ return llvm.FunctionType(returnType, paramTypes, false) + } + + // parseMakeClosure makes a function value (with context) from the given +diff --git a/compiler/interface.go b/compiler/interface.go +index c59a9ade..b0ea71e3 100644 +--- a/compiler/interface.go ++++ b/compiler/interface.go +@@ -465,7 +465,7 @@ func (c *compilerContext) getInvokeFunction(instr *ssa.CallCommon) llvm.Value { + paramTuple = append(paramTuple, sig.Params().At(i)) + } + paramTuple = append(paramTuple, types.NewVar(token.NoPos, nil, "$typecode", types.Typ[types.Uintptr])) +- llvmFnType := c.getRawFuncType(types.NewSignature(sig.Recv(), types.NewTuple(paramTuple...), sig.Results(), false)).ElementType() ++ llvmFnType := c.getRawFuncType(types.NewSignature(sig.Recv(), types.NewTuple(paramTuple...), sig.Results(), false)) + llvmFn = llvm.AddFunction(c.mod, fnName, llvmFnType) + c.addStandardDeclaredAttributes(llvmFn) + llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("tinygo-invoke", c.getMethodSignatureName(instr.Method))) +-- +2.36.1 + diff --git a/0009-all-add-type-parameter-to-CreateCall.patch b/0009-all-add-type-parameter-to-CreateCall.patch new file mode 100644 index 0000000..ca16ea3 --- /dev/null +++ b/0009-all-add-type-parameter-to-CreateCall.patch @@ -0,0 +1,993 @@ +From 8138d69793c00829df45501c35975055ad52d151 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Wed, 21 Sep 2022 00:37:01 +0200 +Subject: [PATCH 09/18] all: add type parameter to CreateCall + +This uses LLVMBuildCall2 in the background, which is the replacement for +the deprecated LLVMBuildCall function. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/build.go | 2 +- + compiler/alias.go | 2 +- + compiler/atomic.go | 4 ++-- + compiler/calls.go | 14 +++++++------- + compiler/compiler.go | 25 ++++++++++++++++--------- + compiler/defer.go | 16 ++++++++++------ + compiler/func.go | 8 +++++--- + compiler/goroutine.go | 33 ++++++++++++++++++--------------- + compiler/inlineasm.go | 16 ++++++++-------- + compiler/interface.go | 17 ++++++++--------- + compiler/interrupt.go | 4 ++-- + compiler/intrinsics.go | 6 +++--- + compiler/llvm.go | 2 +- + compiler/llvmutil/llvm.go | 24 ++++++++++++++---------- + compiler/llvmutil/wordpack.go | 4 ++-- + compiler/symbol.go | 6 +++--- + compiler/syscall.go | 14 +++++++------- + go.mod | 2 +- + go.sum | 4 ++-- + interp/interp.go | 2 +- + interp/interpreter.go | 2 +- + transform/interface-lowering.go | 7 ++++--- + transform/interrupt.go | 2 +- + transform/panic.go | 2 +- + transform/rtcalls.go | 2 +- + transform/wasm-abi.go | 6 +++--- + 26 files changed, 123 insertions(+), 103 deletions(-) + +diff --git a/builder/build.go b/builder/build.go +index 2008c897..28385044 100644 +--- a/builder/build.go ++++ b/builder/build.go +@@ -523,7 +523,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil + if pkgInit.IsNil() { + panic("init not found for " + pkg.Pkg.Path()) + } +- irbuilder.CreateCall(pkgInit, []llvm.Value{llvm.Undef(i8ptrType)}, "") ++ irbuilder.CreateCall(pkgInit.GlobalValueType(), pkgInit, []llvm.Value{llvm.Undef(i8ptrType)}, "") + } + irbuilder.CreateRetVoid() + +diff --git a/compiler/alias.go b/compiler/alias.go +index 9e88e3c6..b16cbce8 100644 +--- a/compiler/alias.go ++++ b/compiler/alias.go +@@ -52,7 +52,7 @@ func (b *builder) createAlias(alias llvm.Value) { + b.CreateUnreachable() + return + } +- result := b.CreateCall(alias, b.llvmFn.Params(), "") ++ result := b.CreateCall(alias.GlobalValueType(), alias, b.llvmFn.Params(), "") + if result.Type().TypeKind() == llvm.VoidTypeKind { + b.CreateRetVoid() + } else { +diff --git a/compiler/atomic.go b/compiler/atomic.go +index f12c6d11..6ba3849c 100644 +--- a/compiler/atomic.go ++++ b/compiler/atomic.go +@@ -25,7 +25,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value { + if fn.IsNil() { + fn = llvm.AddFunction(b.mod, name, llvm.FunctionType(vType, []llvm.Type{ptr.Type(), vType}, false)) + } +- oldVal := b.createCall(fn, []llvm.Value{ptr, val}, "") ++ oldVal := b.createCall(fn.GlobalValueType(), fn, []llvm.Value{ptr, val}, "") + // Return the new value, not the original value returned. + return b.CreateAdd(oldVal, val, "") + } +@@ -78,7 +78,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value { + if fn.IsNil() { + fn = llvm.AddFunction(b.mod, name, llvm.FunctionType(vType, []llvm.Type{ptr.Type(), vType, b.uintptrType}, false)) + } +- b.createCall(fn, []llvm.Value{ptr, val, llvm.ConstInt(b.uintptrType, 5, false)}, "") ++ b.createCall(fn.GlobalValueType(), fn, []llvm.Value{ptr, val, llvm.ConstInt(b.uintptrType, 5, false)}, "") + return llvm.Value{} + } + store := b.CreateStore(val, ptr) +diff --git a/compiler/calls.go b/compiler/calls.go +index aeca518a..b38d770f 100644 +--- a/compiler/calls.go ++++ b/compiler/calls.go +@@ -37,15 +37,15 @@ const ( + // createRuntimeInvoke instead. + func (b *builder) createRuntimeCallCommon(fnName string, args []llvm.Value, name string, isInvoke bool) llvm.Value { + fn := b.program.ImportedPackage("runtime").Members[fnName].(*ssa.Function) +- llvmFn := b.getFunction(fn) ++ fnType, llvmFn := b.getFunction(fn) + if llvmFn.IsNil() { + panic("trying to call non-existent function: " + fn.RelString(nil)) + } + args = append(args, llvm.Undef(b.i8ptrType)) // unused context parameter + if isInvoke { +- return b.createInvoke(llvmFn, args, name) ++ return b.createInvoke(fnType, llvmFn, args, name) + } +- return b.createCall(llvmFn, args, name) ++ return b.createCall(fnType, llvmFn, args, name) + } + + // createRuntimeCall creates a new call to runtime. with the given +@@ -65,22 +65,22 @@ func (b *builder) createRuntimeInvoke(fnName string, args []llvm.Value, name str + + // createCall creates a call to the given function with the arguments possibly + // expanded. +-func (b *builder) createCall(fn llvm.Value, args []llvm.Value, name string) llvm.Value { ++func (b *builder) createCall(fnType llvm.Type, fn llvm.Value, args []llvm.Value, name string) llvm.Value { + expanded := make([]llvm.Value, 0, len(args)) + for _, arg := range args { + fragments := b.expandFormalParam(arg) + expanded = append(expanded, fragments...) + } +- return b.CreateCall(fn, expanded, name) ++ return b.CreateCall(fnType, fn, expanded, name) + } + + // createInvoke is like createCall but continues execution at the landing pad if + // the call resulted in a panic. +-func (b *builder) createInvoke(fn llvm.Value, args []llvm.Value, name string) llvm.Value { ++func (b *builder) createInvoke(fnType llvm.Type, fn llvm.Value, args []llvm.Value, name string) llvm.Value { + if b.hasDeferFrame() { + b.createInvokeCheckpoint() + } +- return b.createCall(fn, args, name) ++ return b.createCall(fnType, fn, args, name) + } + + // Expand an argument type to a list that can be used in a function call +diff --git a/compiler/compiler.go b/compiler/compiler.go +index bbaf6432..b64fddcc 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -131,6 +131,7 @@ type builder struct { + *compilerContext + llvm.Builder + fn *ssa.Function ++ llvmFnType llvm.Type + llvmFn llvm.Value + info functionInfo + locals map[ssa.Value]llvm.Value // local variables +@@ -155,11 +156,13 @@ type builder struct { + } + + func newBuilder(c *compilerContext, irbuilder llvm.Builder, f *ssa.Function) *builder { ++ fnType, fn := c.getFunction(f) + return &builder{ + compilerContext: c, + Builder: irbuilder, + fn: f, +- llvmFn: c.getFunction(f), ++ llvmFnType: fnType, ++ llvmFn: fn, + info: c.getFunctionInfo(f), + locals: make(map[ssa.Value]llvm.Value), + dilocals: make(map[*types.Var]llvm.Metadata), +@@ -711,7 +714,8 @@ func (b *builder) getLocalVariable(variable *types.Var) llvm.Metadata { + // DISubprogram metadata node. + func (c *compilerContext) attachDebugInfo(f *ssa.Function) llvm.Metadata { + pos := c.program.Fset.Position(f.Syntax().Pos()) +- return c.attachDebugInfoRaw(f, c.getFunction(f), "", pos.Filename, pos.Line) ++ _, fn := c.getFunction(f) ++ return c.attachDebugInfoRaw(f, fn, "", pos.Filename, pos.Line) + } + + // attachDebugInfo adds debug info to a function declaration. It returns the +@@ -1654,6 +1658,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) + + // Try to call the function directly for trivially static calls. + var callee, context llvm.Value ++ var calleeType llvm.Type + exported := false + if fn := instr.StaticCallee(); fn != nil { + // Direct function call, either to a named or anonymous (directly +@@ -1684,7 +1689,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) + return b.createInterruptGlobal(instr) + } + +- callee = b.getFunction(fn) ++ calleeType, callee = b.getFunction(fn) + info := b.getFunctionInfo(fn) + if callee.IsNil() { + return llvm.Value{}, b.makeError(instr.Pos(), "undefined function: "+info.linkName) +@@ -1698,8 +1703,8 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) + // Eventually we might be able to eliminate this special case + // entirely. For details, see: + // https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521 +- fnType := llvm.FunctionType(callee.Type().ElementType().ReturnType(), nil, false) +- callee = llvm.ConstBitCast(callee, llvm.PointerType(fnType, b.funcPtrAddrSpace)) ++ calleeType = llvm.FunctionType(callee.Type().ElementType().ReturnType(), nil, false) ++ callee = llvm.ConstBitCast(callee, llvm.PointerType(calleeType, b.funcPtrAddrSpace)) + } + case *ssa.MakeClosure: + // A call on a func value, but the callee is trivial to find. For +@@ -1726,13 +1731,14 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) + params = append([]llvm.Value{value}, params...) + params = append(params, typecode) + callee = b.getInvokeFunction(instr) ++ calleeType = callee.GlobalValueType() + context = llvm.Undef(b.i8ptrType) + } else { + // Function pointer. + value := b.getValue(instr.Value) + // This is a func value, which cannot be called directly. We have to + // extract the function pointer and context first from the func value. +- callee, context = b.decodeFuncValue(value, instr.Value.Type().Underlying().(*types.Signature)) ++ calleeType, callee, context = b.decodeFuncValue(value, instr.Value.Type().Underlying().(*types.Signature)) + b.createNilCheck(instr.Value, callee, "fpcall") + } + +@@ -1742,7 +1748,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) + params = append(params, context) + } + +- return b.createInvoke(callee, params, ""), nil ++ return b.createInvoke(calleeType, callee, params, ""), nil + } + + // getValue returns the LLVM value of a constant, function value, global, or +@@ -1756,7 +1762,8 @@ func (b *builder) getValue(expr ssa.Value) llvm.Value { + b.addError(expr.Pos(), "cannot use an exported function as value: "+expr.String()) + return llvm.Undef(b.getLLVMType(expr.Type())) + } +- return b.createFuncValue(b.getFunction(expr), llvm.Undef(b.i8ptrType), expr.Signature) ++ _, fn := b.getFunction(expr) ++ return b.createFuncValue(fn, llvm.Undef(b.i8ptrType), expr.Signature) + case *ssa.Global: + value := b.getGlobal(expr) + if value.IsNil() { +@@ -3080,7 +3087,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { + // Instead of a load from the global, create a bitcast of the + // function pointer itself. + name := strings.TrimSuffix(unop.X.(*ssa.Global).Name(), "$funcaddr") +- fn := b.getFunction(b.fn.Pkg.Members[name].(*ssa.Function)) ++ _, fn := b.getFunction(b.fn.Pkg.Members[name].(*ssa.Function)) + if fn.IsNil() { + return llvm.Value{}, b.makeError(unop.Pos(), "cgo function not found: "+name) + } +diff --git a/compiler/defer.go b/compiler/defer.go +index 75c1be3d..e82370fa 100644 +--- a/compiler/defer.go ++++ b/compiler/defer.go +@@ -201,7 +201,7 @@ li a0, 0 + } + asmType := llvm.FunctionType(resultType, []llvm.Type{b.deferFrame.Type()}, false) + asm := llvm.InlineAsm(asmType, asmString, constraints, false, false, 0, false) +- result := b.CreateCall(asm, []llvm.Value{b.deferFrame}, "setjmp") ++ result := b.CreateCall(asmType, asm, []llvm.Value{b.deferFrame}, "setjmp") + result.AddCallSiteAttribute(-1, b.ctx.CreateEnumAttribute(llvm.AttributeKindID("returns_twice"), 0)) + isZero := b.CreateICmp(llvm.IntEQ, result, llvm.ConstInt(resultType, 0, false), "setjmp.result") + continueBB := b.insertBasicBlock("") +@@ -492,6 +492,7 @@ func (b *builder) createRunDefers() { + } + + var fnPtr llvm.Value ++ var fnType llvm.Type + + if !callback.IsInvoke() { + // Isolate the func value. +@@ -499,8 +500,8 @@ func (b *builder) createRunDefers() { + forwardParams = forwardParams[1:] + + //Get function pointer and context +- fp, context := b.decodeFuncValue(funcValue, callback.Signature()) +- fnPtr = fp ++ var context llvm.Value ++ fnType, fnPtr, context = b.decodeFuncValue(funcValue, callback.Signature()) + + //Pass context + forwardParams = append(forwardParams, context) +@@ -509,6 +510,7 @@ func (b *builder) createRunDefers() { + // parameters. + forwardParams = append(forwardParams[1:], forwardParams[0]) + fnPtr = b.getInvokeFunction(callback) ++ fnType = fnPtr.GlobalValueType() + + // Add the context parameter. An interface call cannot also be a + // closure but we have to supply the parameter anyway for platforms +@@ -516,7 +518,7 @@ func (b *builder) createRunDefers() { + forwardParams = append(forwardParams, llvm.Undef(b.i8ptrType)) + } + +- b.createCall(fnPtr, forwardParams, "") ++ b.createCall(fnType, fnPtr, forwardParams, "") + + case *ssa.Function: + // Direct call. +@@ -547,7 +549,8 @@ func (b *builder) createRunDefers() { + } + + // Call real function. +- b.createInvoke(b.getFunction(callback), forwardParams, "") ++ fnType, fn := b.getFunction(callback) ++ b.createInvoke(fnType, fn, forwardParams, "") + + case *ssa.MakeClosure: + // Get the real defer struct type and cast to it. +@@ -571,7 +574,8 @@ func (b *builder) createRunDefers() { + } + + // Call deferred function. +- b.createCall(b.getFunction(fn), forwardParams, "") ++ fnType, llvmFn := b.getFunction(fn) ++ b.createCall(fnType, llvmFn, forwardParams, "") + case *ssa.Builtin: + db := b.deferBuiltinFuncs[callback] + +diff --git a/compiler/func.go b/compiler/func.go +index a8b2874e..c6a8802d 100644 +--- a/compiler/func.go ++++ b/compiler/func.go +@@ -55,14 +55,15 @@ func (b *builder) extractFuncContext(funcValue llvm.Value) llvm.Value { + + // decodeFuncValue extracts the context and the function pointer from this func + // value. This may be an expensive operation. +-func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcPtr, context llvm.Value) { ++func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcType llvm.Type, funcPtr, context llvm.Value) { + context = b.CreateExtractValue(funcValue, 0, "") + bitcast := b.CreateExtractValue(funcValue, 1, "") + if !bitcast.IsAConstantExpr().IsNil() && bitcast.Opcode() == llvm.BitCast { + funcPtr = bitcast.Operand(0) + return + } +- llvmSig := llvm.PointerType(b.getRawFuncType(sig), b.funcPtrAddrSpace) ++ funcType = b.getRawFuncType(sig) ++ llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace) + funcPtr = b.CreateBitCast(bitcast, llvmSig, "") + return + } +@@ -141,5 +142,6 @@ func (b *builder) parseMakeClosure(expr *ssa.MakeClosure) (llvm.Value, error) { + context := b.emitPointerPack(boundVars) + + // Create the closure. +- return b.createFuncValue(b.getFunction(f), context, f.Signature), nil ++ _, fn := b.getFunction(f) ++ return b.createFuncValue(fn, context, f.Signature), nil + } +diff --git a/compiler/goroutine.go b/compiler/goroutine.go +index 8d76c89f..ba8ec0f4 100644 +--- a/compiler/goroutine.go ++++ b/compiler/goroutine.go +@@ -22,6 +22,7 @@ func (b *builder) createGo(instr *ssa.Go) { + + var prefix string + var funcPtr llvm.Value ++ var funcPtrType llvm.Type + hasContext := false + if callee := instr.Call.StaticCallee(); callee != nil { + // Static callee is known. This makes it easier to start a new +@@ -42,7 +43,7 @@ func (b *builder) createGo(instr *ssa.Go) { + params = append(params, context) // context parameter + hasContext = true + } +- funcPtr = b.getFunction(callee) ++ funcPtrType, funcPtr = b.getFunction(callee) + } else if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok { + // We cheat. None of the builtins do any long or blocking operation, so + // we might as well run these builtins right away without the program +@@ -80,6 +81,7 @@ func (b *builder) createGo(instr *ssa.Go) { + itfTypeCode := b.CreateExtractValue(itf, 0, "") + itfValue := b.CreateExtractValue(itf, 1, "") + funcPtr = b.getInvokeFunction(&instr.Call) ++ funcPtrType = funcPtr.GlobalValueType() + params = append([]llvm.Value{itfValue}, params...) // start with receiver + params = append(params, itfTypeCode) // end with typecode + } else { +@@ -89,7 +91,7 @@ func (b *builder) createGo(instr *ssa.Go) { + // * The function context, for closures. + // * The function pointer (for tasks). + var context llvm.Value +- funcPtr, context = b.decodeFuncValue(b.getValue(instr.Call.Value), instr.Call.Value.Type().Underlying().(*types.Signature)) ++ funcPtrType, funcPtr, context = b.decodeFuncValue(b.getValue(instr.Call.Value), instr.Call.Value.Type().Underlying().(*types.Signature)) + params = append(params, context, funcPtr) + hasContext = true + prefix = b.fn.RelString(nil) +@@ -97,14 +99,14 @@ func (b *builder) createGo(instr *ssa.Go) { + + paramBundle := b.emitPointerPack(params) + var stackSize llvm.Value +- callee := b.createGoroutineStartWrapper(funcPtr, prefix, hasContext, instr.Pos()) ++ callee := b.createGoroutineStartWrapper(funcPtrType, funcPtr, prefix, hasContext, instr.Pos()) + if b.AutomaticStackSize { + // The stack size is not known until after linking. Call a dummy + // function that will be replaced with a load from a special ELF + // section that contains the stack size (and is modified after + // linking). +- stackSizeFn := b.getFunction(b.program.ImportedPackage("internal/task").Members["getGoroutineStackSize"].(*ssa.Function)) +- stackSize = b.createCall(stackSizeFn, []llvm.Value{callee, llvm.Undef(b.i8ptrType)}, "stacksize") ++ stackSizeFnType, stackSizeFn := b.getFunction(b.program.ImportedPackage("internal/task").Members["getGoroutineStackSize"].(*ssa.Function)) ++ stackSize = b.createCall(stackSizeFnType, stackSizeFn, []llvm.Value{callee, llvm.Undef(b.i8ptrType)}, "stacksize") + } else { + // The stack size is fixed at compile time. By emitting it here as a + // constant, it can be optimized. +@@ -113,8 +115,8 @@ func (b *builder) createGo(instr *ssa.Go) { + } + stackSize = llvm.ConstInt(b.uintptrType, b.DefaultStackSize, false) + } +- start := b.getFunction(b.program.ImportedPackage("internal/task").Members["start"].(*ssa.Function)) +- b.createCall(start, []llvm.Value{callee, paramBundle, stackSize, llvm.Undef(b.i8ptrType)}, "") ++ fnType, start := b.getFunction(b.program.ImportedPackage("internal/task").Members["start"].(*ssa.Function)) ++ b.createCall(fnType, start, []llvm.Value{callee, paramBundle, stackSize, llvm.Undef(b.i8ptrType)}, "") + } + + // createGoroutineStartWrapper creates a wrapper for the task-based +@@ -140,15 +142,16 @@ func (b *builder) createGo(instr *ssa.Go) { + // to last parameter of the function) is used for this wrapper. If hasContext is + // false, the parameter bundle is assumed to have no context parameter and undef + // is passed instead. +-func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix string, hasContext bool, pos token.Pos) llvm.Value { ++func (c *compilerContext) createGoroutineStartWrapper(fnType llvm.Type, fn llvm.Value, prefix string, hasContext bool, pos token.Pos) llvm.Value { + var wrapper llvm.Value + + builder := c.ctx.NewBuilder() + defer builder.Dispose() + + var deadlock llvm.Value ++ var deadlockType llvm.Type + if c.Scheduler == "asyncify" { +- deadlock = c.getFunction(c.program.ImportedPackage("runtime").Members["deadlock"].(*ssa.Function)) ++ deadlockType, deadlock = c.getFunction(c.program.ImportedPackage("runtime").Members["deadlock"].(*ssa.Function)) + } + + if !fn.IsAFunction().IsNil() { +@@ -192,7 +195,7 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri + } + + // Create the list of params for the call. +- paramTypes := fn.Type().ElementType().ParamTypes() ++ paramTypes := fnType.ParamTypes() + if !hasContext { + paramTypes = paramTypes[:len(paramTypes)-1] // strip context parameter + } +@@ -202,10 +205,10 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri + } + + // Create the call. +- builder.CreateCall(fn, params, "") ++ builder.CreateCall(fnType, fn, params, "") + + if c.Scheduler == "asyncify" { +- builder.CreateCall(deadlock, []llvm.Value{ ++ builder.CreateCall(deadlockType, deadlock, []llvm.Value{ + llvm.Undef(c.i8ptrType), + }, "") + } +@@ -261,7 +264,7 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri + } + + // Get the list of parameters, with the extra parameters at the end. +- paramTypes := fn.Type().ElementType().ParamTypes() ++ paramTypes := fnType.ParamTypes() + paramTypes = append(paramTypes, fn.Type()) // the last element is the function pointer + params := llvmutil.EmitPointerUnpack(builder, c.mod, wrapper.Param(0), paramTypes) + +@@ -270,10 +273,10 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri + params = params[:len(params)-1] + + // Create the call. +- builder.CreateCall(fnPtr, params, "") ++ builder.CreateCall(fnType, fnPtr, params, "") + + if c.Scheduler == "asyncify" { +- builder.CreateCall(deadlock, []llvm.Value{ ++ builder.CreateCall(deadlockType, deadlock, []llvm.Value{ + llvm.Undef(c.i8ptrType), + }, "") + } +diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go +index 27b0492b..2afb0a16 100644 +--- a/compiler/inlineasm.go ++++ b/compiler/inlineasm.go +@@ -25,7 +25,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{}, false) + asm := constant.StringVal(args[0].(*ssa.Const).Value) + target := llvm.InlineAsm(fnType, asm, "", true, false, 0, false) +- return b.CreateCall(target, nil, ""), nil ++ return b.CreateCall(fnType, target, nil, ""), nil + } + + // This is a compiler builtin, which allows assembly to be called in a flexible +@@ -120,7 +120,7 @@ func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) + } + fnType := llvm.FunctionType(outputType, argTypes, false) + target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0, false) +- result := b.CreateCall(target, args, "") ++ result := b.CreateCall(fnType, target, args, "") + if hasOutput { + return result, nil + } else { +@@ -163,7 +163,7 @@ func (b *builder) emitSVCall(args []ssa.Value) (llvm.Value, error) { + constraints += ",~{r1},~{r2},~{r3}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) + target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) +- return b.CreateCall(target, llvmArgs, ""), nil ++ return b.CreateCall(fnType, target, llvmArgs, ""), nil + } + + // This is a compiler builtin which emits an inline SVCall instruction. It can +@@ -201,7 +201,7 @@ func (b *builder) emitSV64Call(args []ssa.Value) (llvm.Value, error) { + constraints += ",~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) + target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) +- return b.CreateCall(target, llvmArgs, ""), nil ++ return b.CreateCall(fnType, target, llvmArgs, ""), nil + } + + // This is a compiler builtin which emits CSR instructions. It can be one of: +@@ -226,24 +226,24 @@ func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error) { + fnType := llvm.FunctionType(b.uintptrType, nil, false) + asm := fmt.Sprintf("csrr $0, %d", csr) + target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0, false) +- return b.CreateCall(target, nil, ""), nil ++ return b.CreateCall(fnType, target, nil, ""), nil + case "Set": + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrw %d, $0", csr) + target := llvm.InlineAsm(fnType, asm, "r", true, false, 0, false) +- return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil ++ return b.CreateCall(fnType, target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + case "SetBits": + // Note: it may be possible to optimize this to csrrsi in many cases. + fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrrs $0, %d, $1", csr) + target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) +- return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil ++ return b.CreateCall(fnType, target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + case "ClearBits": + // Note: it may be possible to optimize this to csrrci in many cases. + fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) + asm := fmt.Sprintf("csrrc $0, %d, $1", csr) + target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) +- return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil ++ return b.CreateCall(fnType, target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil + default: + return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) + } +diff --git a/compiler/interface.go b/compiler/interface.go +index b0ea71e3..72f8952d 100644 +--- a/compiler/interface.go ++++ b/compiler/interface.go +@@ -254,12 +254,12 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value { + method := ms.At(i) + signatureGlobal := c.getMethodSignature(method.Obj().(*types.Func)) + fn := c.program.MethodValue(method) +- llvmFn := c.getFunction(fn) ++ llvmFnType, llvmFn := c.getFunction(fn) + if llvmFn.IsNil() { + // compiler error, so panic + panic("cannot find function: " + c.getFunctionInfo(fn).linkName) + } +- wrapper := c.getInterfaceInvokeWrapper(fn, llvmFn) ++ wrapper := c.getInterfaceInvokeWrapper(fn, llvmFnType, llvmFn) + methodInfo := llvm.ConstNamedStruct(interfaceMethodInfoType, []llvm.Value{ + signatureGlobal, + llvm.ConstPtrToInt(wrapper, c.uintptrType), +@@ -361,7 +361,7 @@ func (b *builder) createTypeAssert(expr *ssa.TypeAssert) llvm.Value { + // implements each method of the interface. See: + // https://research.swtch.com/interfaces + fn := b.getInterfaceImplementsFunc(expr.AssertedType) +- commaOk = b.CreateCall(fn, []llvm.Value{actualTypeNum}, "") ++ commaOk = b.CreateCall(fn.GlobalValueType(), fn, []llvm.Value{actualTypeNum}, "") + + } else { + globalName := "reflect/types.typeid:" + getTypeCodeName(expr.AssertedType) +@@ -480,7 +480,7 @@ func (c *compilerContext) getInvokeFunction(instr *ssa.CallCommon) llvm.Value { + // value, dereferences or unpacks it if necessary, and calls the real method. + // If the method to wrap has a pointer receiver, no wrapping is necessary and + // the function is returned directly. +-func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llvm.Value) llvm.Value { ++func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFnType llvm.Type, llvmFn llvm.Value) llvm.Value { + wrapperName := llvmFn.Name() + "$invoke" + wrapper := c.mod.NamedFunction(wrapperName) + if !wrapper.IsNil() { +@@ -505,9 +505,8 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llv + } + + // create wrapper function +- fnType := llvmFn.Type().ElementType() +- paramTypes := append([]llvm.Type{c.i8ptrType}, fnType.ParamTypes()[len(expandedReceiverType):]...) +- wrapFnType := llvm.FunctionType(fnType.ReturnType(), paramTypes, false) ++ paramTypes := append([]llvm.Type{c.i8ptrType}, llvmFnType.ParamTypes()[len(expandedReceiverType):]...) ++ wrapFnType := llvm.FunctionType(llvmFnType.ReturnType(), paramTypes, false) + wrapper = llvm.AddFunction(c.mod, wrapperName, wrapFnType) + c.addStandardAttributes(wrapper) + +@@ -535,10 +534,10 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llv + receiverValue := b.emitPointerUnpack(wrapper.Param(0), []llvm.Type{receiverType})[0] + params := append(b.expandFormalParam(receiverValue), wrapper.Params()[1:]...) + if llvmFn.Type().ElementType().ReturnType().TypeKind() == llvm.VoidTypeKind { +- b.CreateCall(llvmFn, params, "") ++ b.CreateCall(llvmFnType, llvmFn, params, "") + b.CreateRetVoid() + } else { +- ret := b.CreateCall(llvmFn, params, "ret") ++ ret := b.CreateCall(llvmFnType, llvmFn, params, "ret") + b.CreateRet(ret) + } + +diff --git a/compiler/interrupt.go b/compiler/interrupt.go +index bcd407cd..45c7d074 100644 +--- a/compiler/interrupt.go ++++ b/compiler/interrupt.go +@@ -36,7 +36,7 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro + // Fall back to a generic error. + return llvm.Value{}, b.makeError(instr.Pos(), "interrupt function must be constant") + } +- funcRawPtr, funcContext := b.decodeFuncValue(funcValue, nil) ++ _, funcRawPtr, funcContext := b.decodeFuncValue(funcValue, nil) + funcPtr := llvm.ConstPtrToInt(funcRawPtr, b.uintptrType) + + // Create a new global of type runtime/interrupt.handle. Globals of this +@@ -85,7 +85,7 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro + useFnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{interrupt.Type()}, false) + useFn = llvm.AddFunction(b.mod, "runtime/interrupt.use", useFnType) + } +- b.CreateCall(useFn, []llvm.Value{interrupt}, "") ++ b.CreateCall(useFn.GlobalValueType(), useFn, []llvm.Value{interrupt}, "") + } + + return interrupt, nil +diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go +index 0203d441..9fedfbd6 100644 +--- a/compiler/intrinsics.go ++++ b/compiler/intrinsics.go +@@ -55,7 +55,7 @@ func (b *builder) createMemoryCopyImpl() { + params = append(params, b.getValue(param)) + } + params = append(params, llvm.ConstInt(b.ctx.Int1Type(), 0, false)) +- b.CreateCall(llvmFn, params, "") ++ b.CreateCall(llvmFn.GlobalValueType(), llvmFn, params, "") + b.CreateRetVoid() + } + +@@ -76,7 +76,7 @@ func (b *builder) createMemoryZeroImpl() { + b.getValue(b.fn.Params[1]), + llvm.ConstInt(b.ctx.Int1Type(), 0, false), + } +- b.CreateCall(llvmFn, params, "") ++ b.CreateCall(llvmFn.GlobalValueType(), llvmFn, params, "") + b.CreateRetVoid() + } + +@@ -119,6 +119,6 @@ func (b *builder) defineMathOp() { + for i, param := range b.fn.Params { + args[i] = b.getValue(param) + } +- result := b.CreateCall(llvmFn, args, "") ++ result := b.CreateCall(llvmFn.GlobalValueType(), llvmFn, args, "") + b.CreateRet(result) + } +diff --git a/compiler/llvm.go b/compiler/llvm.go +index 0d2ba9da..9540bcc6 100644 +--- a/compiler/llvm.go ++++ b/compiler/llvm.go +@@ -312,5 +312,5 @@ func (b *builder) readStackPointer() llvm.Value { + fnType := llvm.FunctionType(b.i8ptrType, nil, false) + stacksave = llvm.AddFunction(b.mod, "llvm.stacksave", fnType) + } +- return b.CreateCall(stacksave, nil, "") ++ return b.CreateCall(stacksave.GlobalValueType(), stacksave, nil, "") + } +diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go +index 74404a3e..e73b68da 100644 +--- a/compiler/llvmutil/llvm.go ++++ b/compiler/llvmutil/llvm.go +@@ -39,7 +39,8 @@ func CreateTemporaryAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, n + alloca = CreateEntryBlockAlloca(builder, t, name) + bitcast = builder.CreateBitCast(alloca, i8ptrType, name+".bitcast") + size = llvm.ConstInt(ctx.Int64Type(), targetData.TypeAllocSize(t), false) +- builder.CreateCall(getLifetimeStartFunc(mod), []llvm.Value{size, bitcast}, "") ++ fnType, fn := getLifetimeStartFunc(mod) ++ builder.CreateCall(fnType, fn, []llvm.Value{size, bitcast}, "") + return + } + +@@ -54,13 +55,15 @@ func CreateInstructionAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, + builder.SetInsertPointBefore(inst) + bitcast := builder.CreateBitCast(alloca, i8ptrType, name+".bitcast") + size := llvm.ConstInt(ctx.Int64Type(), targetData.TypeAllocSize(t), false) +- builder.CreateCall(getLifetimeStartFunc(mod), []llvm.Value{size, bitcast}, "") ++ fnType, fn := getLifetimeStartFunc(mod) ++ builder.CreateCall(fnType, fn, []llvm.Value{size, bitcast}, "") + if next := llvm.NextInstruction(inst); !next.IsNil() { + builder.SetInsertPointBefore(next) + } else { + builder.SetInsertPointAtEnd(inst.InstructionParent()) + } +- builder.CreateCall(getLifetimeEndFunc(mod), []llvm.Value{size, bitcast}, "") ++ fnType, fn = getLifetimeEndFunc(mod) ++ builder.CreateCall(fnType, fn, []llvm.Value{size, bitcast}, "") + return alloca + } + +@@ -68,33 +71,34 @@ func CreateInstructionAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, + // llvm.lifetime.end intrinsic. It is commonly used together with + // createTemporaryAlloca. + func EmitLifetimeEnd(builder llvm.Builder, mod llvm.Module, ptr, size llvm.Value) { +- builder.CreateCall(getLifetimeEndFunc(mod), []llvm.Value{size, ptr}, "") ++ fnType, fn := getLifetimeEndFunc(mod) ++ builder.CreateCall(fnType, fn, []llvm.Value{size, ptr}, "") + } + + // getLifetimeStartFunc returns the llvm.lifetime.start intrinsic and creates it + // first if it doesn't exist yet. +-func getLifetimeStartFunc(mod llvm.Module) llvm.Value { ++func getLifetimeStartFunc(mod llvm.Module) (llvm.Type, llvm.Value) { + fn := mod.NamedFunction("llvm.lifetime.start.p0i8") + ctx := mod.Context() + i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) ++ fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) + if fn.IsNil() { +- fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) + fn = llvm.AddFunction(mod, "llvm.lifetime.start.p0i8", fnType) + } +- return fn ++ return fnType, fn + } + + // getLifetimeEndFunc returns the llvm.lifetime.end intrinsic and creates it + // first if it doesn't exist yet. +-func getLifetimeEndFunc(mod llvm.Module) llvm.Value { ++func getLifetimeEndFunc(mod llvm.Module) (llvm.Type, llvm.Value) { + fn := mod.NamedFunction("llvm.lifetime.end.p0i8") + ctx := mod.Context() + i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) ++ fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) + if fn.IsNil() { +- fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) + fn = llvm.AddFunction(mod, "llvm.lifetime.end.p0i8", fnType) + } +- return fn ++ return fnType, fn + } + + // SplitBasicBlock splits a LLVM basic block into two parts. All instructions +diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go +index 41d4c581..73b1e27e 100644 +--- a/compiler/llvmutil/wordpack.go ++++ b/compiler/llvmutil/wordpack.go +@@ -95,14 +95,14 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs + // Packed data is bigger than a pointer, so allocate it on the heap. + sizeValue := llvm.ConstInt(uintptrType, size, false) + alloc := mod.NamedFunction("runtime.alloc") +- packedHeapAlloc := builder.CreateCall(alloc, []llvm.Value{ ++ packedHeapAlloc := builder.CreateCall(alloc.GlobalValueType(), alloc, []llvm.Value{ + sizeValue, + llvm.ConstNull(i8ptrType), + llvm.Undef(i8ptrType), // unused context parameter + }, "") + if needsStackObjects { + trackPointer := mod.NamedFunction("runtime.trackPointer") +- builder.CreateCall(trackPointer, []llvm.Value{ ++ builder.CreateCall(trackPointer.GlobalValueType(), trackPointer, []llvm.Value{ + packedHeapAlloc, + llvm.Undef(i8ptrType), // unused context parameter + }, "") +diff --git a/compiler/symbol.go b/compiler/symbol.go +index c4ce6f21..83fe050b 100644 +--- a/compiler/symbol.go ++++ b/compiler/symbol.go +@@ -53,11 +53,11 @@ const ( + + // getFunction returns the LLVM function for the given *ssa.Function, creating + // it if needed. It can later be filled with compilerContext.createFunction(). +-func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value { ++func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) { + info := c.getFunctionInfo(fn) + llvmFn := c.mod.NamedFunction(info.linkName) + if !llvmFn.IsNil() { +- return llvmFn ++ return llvmFn.GlobalValueType(), llvmFn + } + + var retType llvm.Type +@@ -202,7 +202,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value { + llvmFn.SetUnnamedAddr(true) + } + +- return llvmFn ++ return fnType, llvmFn + } + + // getFunctionInfo returns information about a function that is not directly +diff --git a/compiler/syscall.go b/compiler/syscall.go +index 0c5f1246..66baf826 100644 +--- a/compiler/syscall.go ++++ b/compiler/syscall.go +@@ -44,7 +44,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + constraints += ",~{rcx},~{r11}" + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) + target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false) +- return b.CreateCall(target, args, ""), nil ++ return b.CreateCall(fnType, target, args, ""), nil + case b.GOARCH == "386" && b.GOOS == "linux": + // Sources: + // syscall(2) man page +@@ -70,7 +70,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + } + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) + target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false) +- return b.CreateCall(target, args, ""), nil ++ return b.CreateCall(fnType, target, args, ""), nil + case b.GOARCH == "arm" && b.GOOS == "linux": + // Implement the EABI system call convention for Linux. + // Source: syscall(2) man page. +@@ -102,7 +102,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + } + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) + target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) +- return b.CreateCall(target, args, ""), nil ++ return b.CreateCall(fnType, target, args, ""), nil + case b.GOARCH == "arm64" && b.GOOS == "linux": + // Source: syscall(2) man page. + args := []llvm.Value{} +@@ -134,7 +134,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { + constraints += ",~{x16},~{x17}" // scratch registers + fnType := llvm.FunctionType(b.uintptrType, argTypes, false) + target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) +- return b.CreateCall(target, args, ""), nil ++ return b.CreateCall(fnType, target, args, ""), nil + default: + return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH) + } +@@ -205,9 +205,9 @@ func (b *builder) createSyscall(call *ssa.CallCommon) (llvm.Value, error) { + // Note that SetLastError/GetLastError could be replaced with direct + // access to the thread control block, which is probably smaller and + // faster. The Go runtime does this in assembly. +- b.CreateCall(setLastError, []llvm.Value{llvm.ConstNull(b.ctx.Int32Type())}, "") +- syscallResult := b.CreateCall(fnPtr, params, "") +- errResult := b.CreateCall(getLastError, nil, "err") ++ b.CreateCall(setLastError.GlobalValueType(), setLastError, []llvm.Value{llvm.ConstNull(b.ctx.Int32Type())}, "") ++ syscallResult := b.CreateCall(llvmType, fnPtr, params, "") ++ errResult := b.CreateCall(getLastError.GlobalValueType(), getLastError, nil, "err") + if b.uintptrType != b.ctx.Int32Type() { + errResult = b.CreateZExt(errResult, b.uintptrType, "err.uintptr") + } +diff --git a/go.mod b/go.mod +index fdf686d4..4af10427 100644 +--- a/go.mod ++++ b/go.mod +@@ -17,7 +17,7 @@ require ( + golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 + golang.org/x/tools v0.1.11 + gopkg.in/yaml.v2 v2.4.0 +- tinygo.org/x/go-llvm v0.0.0-20220802112859-5bb0b77907a7 ++ tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 + ) + + require ( +diff --git a/go.sum b/go.sum +index 3fc9cac1..401de3be 100644 +--- a/go.sum ++++ b/go.sum +@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +-tinygo.org/x/go-llvm v0.0.0-20220802112859-5bb0b77907a7 h1:nSLR52mUw7DPQQVA3ZJFH63zjU4ME84fKiin6mdnYWc= +-tinygo.org/x/go-llvm v0.0.0-20220802112859-5bb0b77907a7/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= ++tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 h1:JxtI6P/lyWHAcs/4QJWeWIbh4HntxPFONMVWvx7wf8Y= ++tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +diff --git a/interp/interp.go b/interp/interp.go +index a1f5f507..856f08b1 100644 +--- a/interp/interp.go ++++ b/interp/interp.go +@@ -127,7 +127,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error { + // Create a call to the package initializer (which was + // previously deleted). + i8undef := llvm.Undef(r.i8ptrType) +- r.builder.CreateCall(fn, []llvm.Value{i8undef}, "") ++ r.builder.CreateCall(fn.GlobalValueType(), fn, []llvm.Value{i8undef}, "") + // Make sure that any globals touched by the package + // initializer, won't be accessed by later package initializers. + err := r.markExternalLoad(fn) +diff --git a/interp/interpreter.go b/interp/interpreter.go +index 7cee14bf..4a4553f8 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -977,7 +977,7 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me + } + } + } +- result = r.builder.CreateCall(llvmFn, args, inst.name) ++ result = r.builder.CreateCall(inst.llvmInst.CalledFunctionType(), llvmFn, args, inst.name) + case llvm.Load: + err := mem.markExternalLoad(operands[0]) + if err != nil { +diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go +index 7a01c2ea..f5b29e30 100644 +--- a/transform/interface-lowering.go ++++ b/transform/interface-lowering.go +@@ -493,12 +493,13 @@ func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *inte + paramTypes = append(paramTypes, param.Type()) + } + calledFunctionType := function.Type() +- sig := llvm.PointerType(llvm.FunctionType(returnType, paramTypes, false), calledFunctionType.PointerAddressSpace()) ++ functionType := llvm.FunctionType(returnType, paramTypes, false) ++ sig := llvm.PointerType(functionType, calledFunctionType.PointerAddressSpace()) + if sig != function.Type() { + function = p.builder.CreateBitCast(function, sig, "") + } + +- retval := p.builder.CreateCall(function, append([]llvm.Value{receiver}, params...), "") ++ retval := p.builder.CreateCall(functionType, function, append([]llvm.Value{receiver}, params...), "") + if retval.Type().TypeKind() == llvm.VoidTypeKind { + p.builder.CreateRetVoid() + } else { +@@ -518,7 +519,7 @@ func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *inte + // importantly, it avoids undefined behavior when accidentally calling a + // method on a nil interface. + nilPanic := p.mod.NamedFunction("runtime.nilPanic") +- p.builder.CreateCall(nilPanic, []llvm.Value{ ++ p.builder.CreateCall(nilPanic.GlobalValueType(), nilPanic, []llvm.Value{ + llvm.Undef(llvm.PointerType(p.ctx.Int8Type(), 0)), + }, "") + p.builder.CreateUnreachable() +diff --git a/transform/interrupt.go b/transform/interrupt.go +index 3ffe7048..2c301be0 100644 +--- a/transform/interrupt.go ++++ b/transform/interrupt.go +@@ -91,7 +91,7 @@ func LowerInterrupts(mod llvm.Module) []error { + initializer := handler.Initializer() + context := llvm.ConstExtractValue(initializer, []uint32{0}) + funcPtr := llvm.ConstExtractValue(initializer, []uint32{1}).Operand(0) +- builder.CreateCall(funcPtr, []llvm.Value{ ++ builder.CreateCall(funcPtr.GlobalValueType(), funcPtr, []llvm.Value{ + num, + context, + }, "") +diff --git a/transform/panic.go b/transform/panic.go +index e8e9a1fe..dee3bae0 100644 +--- a/transform/panic.go ++++ b/transform/panic.go +@@ -27,7 +27,7 @@ func ReplacePanicsWithTrap(mod llvm.Module) { + panic("expected use of a panic function to be a call") + } + builder.SetInsertPointBefore(use) +- builder.CreateCall(trap, nil, "") ++ builder.CreateCall(trap.GlobalValueType(), trap, nil, "") + } + } + } +diff --git a/transform/rtcalls.go b/transform/rtcalls.go +index 2edfd655..2f17f815 100644 +--- a/transform/rtcalls.go ++++ b/transform/rtcalls.go +@@ -165,7 +165,7 @@ func OptimizeReflectImplements(mod llvm.Module) { + + // Replace Implements call with the type assert call. + builder.SetInsertPointBefore(call) +- implements := builder.CreateCall(typeAssertFunction, []llvm.Value{ ++ implements := builder.CreateCall(typeAssertFunction.GlobalValueType(), typeAssertFunction, []llvm.Value{ + builder.CreatePtrToInt(call.Operand(0), uintptrType, ""), // typecode to check + }, "") + call.ReplaceAllUsesWith(implements) +diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go +index aeba713d..aedad71d 100644 +--- a/transform/wasm-abi.go ++++ b/transform/wasm-abi.go +@@ -124,12 +124,12 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { + // Pass a stack-allocated pointer as the first parameter + // where the return value should be stored, instead of using + // the regular return value. +- builder.CreateCall(externalFn, callParams, callName) ++ builder.CreateCall(externalFnType, externalFn, callParams, callName) + returnValue := builder.CreateLoad(retvalAlloca, "retval") + call.ReplaceAllUsesWith(returnValue) + call.EraseFromParentAsInstruction() + } else { +- newCall := builder.CreateCall(externalFn, callParams, callName) ++ newCall := builder.CreateCall(externalFnType, externalFn, callParams, callName) + call.ReplaceAllUsesWith(newCall) + call.EraseFromParentAsInstruction() + } +@@ -156,7 +156,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { + } + callParams = append(callParams, paramValue) + } +- retval := builder.CreateCall(fn, callParams, "") ++ retval := builder.CreateCall(fn.GlobalValueType(), fn, callParams, "") + if retval.Type().TypeKind() == llvm.VoidTypeKind { + builder.CreateRetVoid() + } else { +-- +2.36.1 + diff --git a/0010-all-add-type-parameter-to-CreateLoad.patch b/0010-all-add-type-parameter-to-CreateLoad.patch new file mode 100644 index 0000000..2cbfe1b --- /dev/null +++ b/0010-all-add-type-parameter-to-CreateLoad.patch @@ -0,0 +1,377 @@ +From 65a18179d8ff911ba43a3a28ffb2f36c262cff5e Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Wed, 21 Sep 2022 13:55:32 +0200 +Subject: [PATCH 10/18] all: add type parameter to CreateLoad + +This is needed for LLVM 15. + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/atomic.go | 2 +- + compiler/channel.go | 8 ++++---- + compiler/compiler.go | 13 +++++++------ + compiler/defer.go | 19 +++++++++++-------- + compiler/llvmutil/wordpack.go | 4 ++-- + compiler/map.go | 6 +++--- + compiler/volatile.go | 5 ++++- + go.mod | 2 +- + go.sum | 4 ++-- + interp/interpreter.go | 2 +- + transform/gc.go | 2 +- + transform/stacksize.go | 13 +++++++++---- + transform/wasm-abi.go | 4 ++-- + 13 files changed, 48 insertions(+), 36 deletions(-) + +diff --git a/compiler/atomic.go b/compiler/atomic.go +index 6ba3849c..73761be4 100644 +--- a/compiler/atomic.go ++++ b/compiler/atomic.go +@@ -56,7 +56,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value { + return swapped + case "LoadInt32", "LoadInt64", "LoadUint32", "LoadUint64", "LoadUintptr", "LoadPointer": + ptr := b.getValue(b.fn.Params[0]) +- val := b.CreateLoad(ptr, "") ++ val := b.CreateLoad(b.getLLVMType(b.fn.Signature.Results().At(0).Type()), ptr, "") + val.SetOrdering(llvm.AtomicOrderingSequentiallyConsistent) + val.SetAlignment(b.targetData.PrefTypeAlignment(val.Type())) // required + return val +diff --git a/compiler/channel.go b/compiler/channel.go +index a9886e10..5c3b6c59 100644 +--- a/compiler/channel.go ++++ b/compiler/channel.go +@@ -84,7 +84,7 @@ func (b *builder) createChanRecv(unop *ssa.UnOp) llvm.Value { + if isZeroSize { + received = llvm.ConstNull(valueType) + } else { +- received = b.CreateLoad(valueAlloca, "chan.received") ++ received = b.CreateLoad(valueType, valueAlloca, "chan.received") + b.emitLifetimeEnd(valueAllocaCast, valueAllocaSize) + } + b.emitLifetimeEnd(channelBlockedListAllocaCast, channelBlockedListAllocaSize) +@@ -264,8 +264,8 @@ func (b *builder) getChanSelectResult(expr *ssa.Extract) llvm.Value { + // receive can proceed at a time) so we'll get that alloca, bitcast + // it to the correct type, and dereference it. + recvbuf := b.selectRecvBuf[expr.Tuple.(*ssa.Select)] +- typ := llvm.PointerType(b.getLLVMType(expr.Type()), 0) +- ptr := b.CreateBitCast(recvbuf, typ, "") +- return b.CreateLoad(ptr, "") ++ typ := b.getLLVMType(expr.Type()) ++ ptr := b.CreateBitCast(recvbuf, llvm.PointerType(typ, 0), "") ++ return b.CreateLoad(typ, ptr, "") + } + } +diff --git a/compiler/compiler.go b/compiler/compiler.go +index b64fddcc..7ab2fe4e 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -1931,11 +1931,12 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + + // Can't load directly from array (as index is non-constant), so have to + // do it using an alloca+gep+load. +- alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(array.Type(), "index.alloca") ++ arrayType := array.Type() ++ alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(arrayType, "index.alloca") + b.CreateStore(array, alloca) + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + ptr := b.CreateInBoundsGEP(alloca, []llvm.Value{zero, index}, "index.gep") +- result := b.CreateLoad(ptr, "index.load") ++ result := b.CreateLoad(arrayType.ElementType(), ptr, "index.load") + b.emitLifetimeEnd(allocaPtr, allocaSize) + return result, nil + case *ssa.IndexAddr: +@@ -2012,7 +2013,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + // Lookup byte + buf := b.CreateExtractValue(value, 0, "") + bufPtr := b.CreateInBoundsGEP(buf, []llvm.Value{index}, "") +- return b.CreateLoad(bufPtr, ""), nil ++ return b.CreateLoad(b.ctx.Int8Type(), bufPtr, ""), nil + case *types.Map: + valueType := expr.Type() + if expr.CommaOk { +@@ -3076,10 +3077,10 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { + return llvm.Value{}, b.makeError(unop.Pos(), "todo: unknown type for negate: "+unop.X.Type().Underlying().String()) + } + case token.MUL: // *x, dereference pointer +- unop.X.Type().Underlying().(*types.Pointer).Elem() ++ valueType := b.getLLVMType(unop.X.Type().Underlying().(*types.Pointer).Elem()) + if b.targetData.TypeAllocSize(x.Type().ElementType()) == 0 { + // zero-length data +- return llvm.ConstNull(x.Type().ElementType()), nil ++ return llvm.ConstNull(valueType), nil + } else if strings.HasSuffix(unop.X.String(), "$funcaddr") { + // CGo function pointer. The cgo part has rewritten CGo function + // pointers as stub global variables of the form: +@@ -3094,7 +3095,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { + return b.CreateBitCast(fn, b.i8ptrType, ""), nil + } else { + b.createNilCheck(unop.X, x, "deref") +- load := b.CreateLoad(x, "") ++ load := b.CreateLoad(valueType, x, "") + return load, nil + } + case token.XOR: // ^x, toggle all bits in integer +diff --git a/compiler/defer.go b/compiler/defer.go +index e82370fa..1f892e5b 100644 +--- a/compiler/defer.go ++++ b/compiler/defer.go +@@ -249,7 +249,8 @@ func isInLoop(start *ssa.BasicBlock) bool { + func (b *builder) createDefer(instr *ssa.Defer) { + // The pointer to the previous defer struct, which we will replace to + // make a linked list. +- next := b.CreateLoad(b.deferPtr, "defer.next") ++ deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0) ++ next := b.CreateLoad(deferType, b.deferPtr, "defer.next") + + var values []llvm.Value + valueTypes := []llvm.Type{b.uintptrType, next.Type()} +@@ -406,6 +407,8 @@ func (b *builder) createDefer(instr *ssa.Defer) { + + // createRunDefers emits code to run all deferred functions. + func (b *builder) createRunDefers() { ++ deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0) ++ + // Add a loop like the following: + // for stack != nil { + // _stack := stack +@@ -431,7 +434,7 @@ func (b *builder) createRunDefers() { + // Create loop head: + // for stack != nil { + b.SetInsertPointAtEnd(loophead) +- deferData := b.CreateLoad(b.deferPtr, "") ++ deferData := b.CreateLoad(deferType, b.deferPtr, "") + stackIsNil := b.CreateICmp(llvm.IntEQ, deferData, llvm.ConstPointerNull(deferData.Type()), "stackIsNil") + b.CreateCondBr(stackIsNil, end, loop) + +@@ -444,13 +447,13 @@ func (b *builder) createRunDefers() { + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 1, false), // .next field + }, "stack.next.gep") +- nextStack := b.CreateLoad(nextStackGEP, "stack.next") ++ nextStack := b.CreateLoad(deferType, nextStackGEP, "stack.next") + b.CreateStore(nextStack, b.deferPtr) + gep := b.CreateInBoundsGEP(deferData, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 0, false), // .callback field + }, "callback.gep") +- callback := b.CreateLoad(gep, "callback") ++ callback := b.CreateLoad(b.uintptrType, gep, "callback") + sw := b.CreateSwitch(callback, unreachable, len(b.allDeferFuncs)) + + for i, callback := range b.allDeferFuncs { +@@ -487,7 +490,7 @@ func (b *builder) createRunDefers() { + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := 2; i < len(valueTypes); i++ { + gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep") +- forwardParam := b.CreateLoad(gep, "param") ++ forwardParam := b.CreateLoad(valueTypes[i], gep, "param") + forwardParams = append(forwardParams, forwardParam) + } + +@@ -536,7 +539,7 @@ func (b *builder) createRunDefers() { + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := range getParams(callback.Signature) { + gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") +- forwardParam := b.CreateLoad(gep, "param") ++ forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") + forwardParams = append(forwardParams, forwardParam) + } + +@@ -569,7 +572,7 @@ func (b *builder) createRunDefers() { + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := 2; i < len(valueTypes); i++ { + gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "") +- forwardParam := b.CreateLoad(gep, "param") ++ forwardParam := b.CreateLoad(valueTypes[i], gep, "param") + forwardParams = append(forwardParams, forwardParam) + } + +@@ -596,7 +599,7 @@ func (b *builder) createRunDefers() { + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := 0; i < params.Len(); i++ { + gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") +- forwardParam := b.CreateLoad(gep, "param") ++ forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") + argValues = append(argValues, forwardParam) + } + +diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go +index 73b1e27e..97b86045 100644 +--- a/compiler/llvmutil/wordpack.go ++++ b/compiler/llvmutil/wordpack.go +@@ -63,7 +63,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs + } + + // Load value (the *i8) from the alloca. +- result := builder.CreateLoad(packedAlloc, "") ++ result := builder.CreateLoad(i8ptrType, packedAlloc, "") + + // End the lifetime of the alloca, to help the optimizer. + packedPtr := builder.CreateBitCast(packedAlloc, i8ptrType, "") +@@ -171,7 +171,7 @@ func EmitPointerUnpack(builder llvm.Builder, mod llvm.Module, ptr llvm.Value, va + llvm.ConstInt(ctx.Int32Type(), uint64(i), false), + } + gep := builder.CreateInBoundsGEP(packedAlloc, indices, "") +- values[i] = builder.CreateLoad(gep, "") ++ values[i] = builder.CreateLoad(valueType, gep, "") + } + if !packedRawAlloc.IsNil() { + allocPtr := builder.CreateBitCast(packedRawAlloc, i8ptrType, "") +diff --git a/compiler/map.go b/compiler/map.go +index 57a7033a..7655ec70 100644 +--- a/compiler/map.go ++++ b/compiler/map.go +@@ -106,7 +106,7 @@ func (b *builder) createMapLookup(keyType, valueType types.Type, m, key llvm.Val + + // Load the resulting value from the hashmap. The value is set to the zero + // value if the key doesn't exist in the hashmap. +- mapValue := b.CreateLoad(mapValueAlloca, "") ++ mapValue := b.CreateLoad(llvmValueType, mapValueAlloca, "") + b.emitLifetimeEnd(mapValuePtr, mapValueAllocaSize) + + if commaOk { +@@ -217,8 +217,8 @@ func (b *builder) createMapIteratorNext(rangeVal ssa.Value, llvmRangeVal, it llv + mapKeyAlloca, mapKeyPtr, mapKeySize := b.createTemporaryAlloca(llvmStoredKeyType, "range.key") + mapValueAlloca, mapValuePtr, mapValueSize := b.createTemporaryAlloca(llvmValueType, "range.value") + ok := b.createRuntimeCall("hashmapNext", []llvm.Value{llvmRangeVal, it, mapKeyPtr, mapValuePtr}, "range.next") +- mapKey := b.CreateLoad(mapKeyAlloca, "") +- mapValue := b.CreateLoad(mapValueAlloca, "") ++ mapKey := b.CreateLoad(llvmStoredKeyType, mapKeyAlloca, "") ++ mapValue := b.CreateLoad(llvmValueType, mapValueAlloca, "") + + if isKeyStoredAsInterface { + // The key is stored as an interface but it isn't of interface type. +diff --git a/compiler/volatile.go b/compiler/volatile.go +index 143eff28..3d3a67fa 100644 +--- a/compiler/volatile.go ++++ b/compiler/volatile.go +@@ -1,5 +1,7 @@ + package compiler + ++import "go/types" ++ + // This file implements volatile loads/stores in runtime/volatile.LoadT and + // runtime/volatile.StoreT as compiler builtins. + +@@ -9,7 +11,8 @@ func (b *builder) createVolatileLoad() { + b.createFunctionStart(true) + addr := b.getValue(b.fn.Params[0]) + b.createNilCheck(b.fn.Params[0], addr, "deref") +- val := b.CreateLoad(addr, "") ++ valType := b.getLLVMType(b.fn.Params[0].Type().(*types.Pointer).Elem()) ++ val := b.CreateLoad(valType, addr, "") + val.SetVolatile(true) + b.CreateRet(val) + } +diff --git a/go.mod b/go.mod +index 4af10427..26707a96 100644 +--- a/go.mod ++++ b/go.mod +@@ -17,7 +17,7 @@ require ( + golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 + golang.org/x/tools v0.1.11 + gopkg.in/yaml.v2 v2.4.0 +- tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 ++ tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 + ) + + require ( +diff --git a/go.sum b/go.sum +index 401de3be..e5c734cd 100644 +--- a/go.sum ++++ b/go.sum +@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +-tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 h1:JxtI6P/lyWHAcs/4QJWeWIbh4HntxPFONMVWvx7wf8Y= +-tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= ++tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 h1:bJYUpmJrVm7Uluxh80qSivfeU3d9D4JNg5oJ+h9U+xc= ++tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +diff --git a/interp/interpreter.go b/interp/interpreter.go +index 4a4553f8..2c7fd8c3 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -983,7 +983,7 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me + if err != nil { + return r.errorAt(inst, err) + } +- result = r.builder.CreateLoad(operands[0], inst.name) ++ result = r.builder.CreateLoad(inst.llvmInst.Type(), operands[0], inst.name) + if inst.llvmInst.IsVolatile() { + result.SetVolatile(true) + } +diff --git a/transform/gc.go b/transform/gc.go +index 87dc6e88..7a4e99ac 100644 +--- a/transform/gc.go ++++ b/transform/gc.go +@@ -222,7 +222,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + builder.CreateStore(initialStackObject, stackObject) + + // Update stack start. +- parent := builder.CreateLoad(stackChainStart, "") ++ parent := builder.CreateLoad(stackChainStartType, stackChainStart, "") + gep := builder.CreateGEP(stackObject, []llvm.Value{ + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), 0, false), +diff --git a/transform/stacksize.go b/transform/stacksize.go +index 7be49238..f1a3c93d 100644 +--- a/transform/stacksize.go ++++ b/transform/stacksize.go +@@ -34,6 +34,11 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string + return nil + } + ++ ctx := mod.Context() ++ targetData := llvm.NewTargetData(mod.DataLayout()) ++ defer targetData.Dispose() ++ uintptrType := ctx.IntType(targetData.PointerSize() * 8) ++ + // Create the new global with stack sizes, that will be put in a new section + // just for itself. + stackSizesGlobalType := llvm.ArrayType(functions[0].Type(), len(functions)) +@@ -50,16 +55,16 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string + appendToUsedGlobals(mod, append([]llvm.Value{stackSizesGlobal}, functionValues...)...) + + // Replace the calls with loads from the new global with stack sizes. +- irbuilder := mod.Context().NewBuilder() ++ irbuilder := ctx.NewBuilder() + defer irbuilder.Dispose() + for i, function := range functions { + for _, use := range functionMap[function] { + ptr := llvm.ConstGEP(stackSizesGlobal, []llvm.Value{ +- llvm.ConstInt(mod.Context().Int32Type(), 0, false), +- llvm.ConstInt(mod.Context().Int32Type(), uint64(i), false), ++ llvm.ConstInt(ctx.Int32Type(), 0, false), ++ llvm.ConstInt(ctx.Int32Type(), uint64(i), false), + }) + irbuilder.SetInsertPointBefore(use) +- stacksize := irbuilder.CreateLoad(ptr, "stacksize") ++ stacksize := irbuilder.CreateLoad(uintptrType, ptr, "stacksize") + use.ReplaceAllUsesWith(stacksize) + use.EraseFromParentAsInstruction() + } +diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go +index aedad71d..064e38f4 100644 +--- a/transform/wasm-abi.go ++++ b/transform/wasm-abi.go +@@ -125,7 +125,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { + // where the return value should be stored, instead of using + // the regular return value. + builder.CreateCall(externalFnType, externalFn, callParams, callName) +- returnValue := builder.CreateLoad(retvalAlloca, "retval") ++ returnValue := builder.CreateLoad(int64Type, retvalAlloca, "retval") + call.ReplaceAllUsesWith(returnValue) + call.EraseFromParentAsInstruction() + } else { +@@ -152,7 +152,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { + for i, origParam := range fn.Params() { + paramValue := externalFn.Param(i) + if origParam.Type() == int64Type { +- paramValue = builder.CreateLoad(paramValue, "i64") ++ paramValue = builder.CreateLoad(int64Type, paramValue, "i64") + } + callParams = append(callParams, paramValue) + } +-- +2.36.1 + diff --git a/0011-all-add-type-parameter-to-GEP-calls.patch b/0011-all-add-type-parameter-to-GEP-calls.patch new file mode 100644 index 0000000..866f9fb --- /dev/null +++ b/0011-all-add-type-parameter-to-GEP-calls.patch @@ -0,0 +1,565 @@ +From dd4f1c594ef0fadb59fa418f1049542f86237800 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Wed, 21 Sep 2022 17:00:09 +0200 +Subject: [PATCH 11/18] all: add type parameter to *GEP calls + +This is necessary for LLVM 15. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/build.go | 2 +- + compiler/channel.go | 8 +++--- + compiler/compiler.go | 46 ++++++++++++++++++++--------------- + compiler/defer.go | 19 ++++++++------- + compiler/interface.go | 16 ++++++------ + compiler/llvm.go | 6 ++--- + compiler/llvmutil/wordpack.go | 6 ++--- + go.mod | 2 +- + go.sum | 4 +-- + interp/memory.go | 4 +-- + transform/gc.go | 4 +-- + transform/llvm.go | 10 ++++---- + transform/stacksize.go | 2 +- + 13 files changed, 69 insertions(+), 60 deletions(-) + +diff --git a/builder/build.go b/builder/build.go +index 28385044..7a7dd9ac 100644 +--- a/builder/build.go ++++ b/builder/build.go +@@ -1153,7 +1153,7 @@ func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) erro + + // Create the string value, which is a {ptr, len} pair. + zero := llvm.ConstInt(mod.Context().Int32Type(), 0, false) +- ptr := llvm.ConstGEP(buf, []llvm.Value{zero, zero}) ++ ptr := llvm.ConstGEP(bufInitializer.Type(), buf, []llvm.Value{zero, zero}) + if ptr.Type() != elementTypes[0] { + return fmt.Errorf("%s: not a string", globalName) + } +diff --git a/compiler/channel.go b/compiler/channel.go +index 5c3b6c59..81f84565 100644 +--- a/compiler/channel.go ++++ b/compiler/channel.go +@@ -173,7 +173,7 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value { + allocaType := llvm.ArrayType(b.ctx.Int8Type(), int(recvbufSize)) + recvbufAlloca, _, _ := b.createTemporaryAlloca(allocaType, "select.recvbuf.alloca") + recvbufAlloca.SetAlignment(recvbufAlign) +- recvbuf = b.CreateGEP(recvbufAlloca, []llvm.Value{ ++ recvbuf = b.CreateGEP(allocaType, recvbufAlloca, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + }, "select.recvbuf") +@@ -184,13 +184,13 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value { + statesAlloca, statesI8, statesSize := b.createTemporaryAlloca(statesAllocaType, "select.states.alloca") + for i, state := range selectStates { + // Set each slice element to the appropriate channel. +- gep := b.CreateGEP(statesAlloca, []llvm.Value{ ++ gep := b.CreateGEP(statesAllocaType, statesAlloca, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false), + }, "") + b.CreateStore(state, gep) + } +- statesPtr := b.CreateGEP(statesAlloca, []llvm.Value{ ++ statesPtr := b.CreateGEP(statesAllocaType, statesAlloca, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + }, "select.states") +@@ -204,7 +204,7 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value { + chBlockAllocaType := llvm.ArrayType(b.getLLVMRuntimeType("channelBlockedList"), len(selectStates)) + chBlockAlloca, chBlockAllocaPtr, chBlockSize := b.createTemporaryAlloca(chBlockAllocaType, "select.block.alloca") + chBlockLen := llvm.ConstInt(b.uintptrType, uint64(len(selectStates)), false) +- chBlockPtr := b.CreateGEP(chBlockAlloca, []llvm.Value{ ++ chBlockPtr := b.CreateGEP(chBlockAllocaType, chBlockAlloca, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + }, "select.block") +diff --git a/compiler/compiler.go b/compiler/compiler.go +index 7ab2fe4e..c93b2e56 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -918,7 +918,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu + bufferGlobal.SetInitializer(bufferValue) + bufferGlobal.SetLinkage(llvm.InternalLinkage) + bufferGlobal.SetAlignment(1) +- slicePtr := llvm.ConstInBoundsGEP(bufferGlobal, []llvm.Value{ ++ slicePtr := llvm.ConstInBoundsGEP(bufferValue.Type(), bufferGlobal, []llvm.Value{ + llvm.ConstInt(c.uintptrType, 0, false), + llvm.ConstInt(c.uintptrType, 0, false), + }) +@@ -990,7 +990,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu + // Create the slice object itself. + // Because embed.FS refers to it as *[]embed.file instead of a plain + // []embed.file, we have to store this as a global. +- slicePtr := llvm.ConstInBoundsGEP(sliceDataGlobal, []llvm.Value{ ++ slicePtr := llvm.ConstInBoundsGEP(sliceDataInitializer.Type(), sliceDataGlobal, []llvm.Value{ + llvm.ConstInt(c.uintptrType, 0, false), + llvm.ConstInt(c.uintptrType, 0, false), + }) +@@ -1018,11 +1018,11 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu + func (c *compilerContext) getEmbedFileString(file *loader.EmbedFile) llvm.Value { + dataGlobalName := "embed/file_" + file.Hash + dataGlobal := c.mod.NamedGlobal(dataGlobalName) ++ dataGlobalType := llvm.ArrayType(c.ctx.Int8Type(), int(file.Size)) + if dataGlobal.IsNil() { +- dataGlobalType := llvm.ArrayType(c.ctx.Int8Type(), int(file.Size)) + dataGlobal = llvm.AddGlobal(c.mod, dataGlobalType, dataGlobalName) + } +- strPtr := llvm.ConstInBoundsGEP(dataGlobal, []llvm.Value{ ++ strPtr := llvm.ConstInBoundsGEP(dataGlobalType, dataGlobal, []llvm.Value{ + llvm.ConstInt(c.uintptrType, 0, false), + llvm.ConstInt(c.uintptrType, 0, false), + }) +@@ -1601,7 +1601,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + // Note: the pointer is always of type *i8. + ptr := argValues[0] + len := argValues[1] +- return b.CreateGEP(ptr, []llvm.Value{len}, ""), nil ++ return b.CreateGEP(b.ctx.Int8Type(), ptr, []llvm.Value{len}, ""), nil + case "Alignof": // unsafe.Alignof + align := b.targetData.ABITypeAlignment(argValues[0].Type()) + return llvm.ConstInt(b.uintptrType, uint64(align), false), nil +@@ -1911,7 +1911,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), uint64(expr.Field), false), + } +- return b.CreateInBoundsGEP(val, indices, ""), nil ++ elementType := b.getLLVMType(expr.X.Type().Underlying().(*types.Pointer).Elem()) ++ return b.CreateInBoundsGEP(elementType, val, indices, ""), nil + case *ssa.Function: + panic("function is not an expression") + case *ssa.Global: +@@ -1935,7 +1936,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(arrayType, "index.alloca") + b.CreateStore(array, alloca) + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) +- ptr := b.CreateInBoundsGEP(alloca, []llvm.Value{zero, index}, "index.gep") ++ ptr := b.CreateInBoundsGEP(arrayType, alloca, []llvm.Value{zero, index}, "index.gep") + result := b.CreateLoad(arrayType.ElementType(), ptr, "index.load") + b.emitLifetimeEnd(allocaPtr, allocaSize) + return result, nil +@@ -1945,13 +1946,15 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + + // Get buffer pointer and length + var bufptr, buflen llvm.Value ++ var bufType llvm.Type + switch ptrTyp := expr.X.Type().Underlying().(type) { + case *types.Pointer: +- typ := expr.X.Type().Underlying().(*types.Pointer).Elem().Underlying() ++ typ := ptrTyp.Elem().Underlying() + switch typ := typ.(type) { + case *types.Array: + bufptr = val + buflen = llvm.ConstInt(b.uintptrType, uint64(typ.Len()), false) ++ bufType = b.getLLVMType(typ) + // Check for nil pointer before calculating the address, from + // the spec: + // > For an operand x of type T, the address operation &x +@@ -1965,6 +1968,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + case *types.Slice: + bufptr = b.CreateExtractValue(val, 0, "indexaddr.ptr") + buflen = b.CreateExtractValue(val, 1, "indexaddr.len") ++ bufType = b.getLLVMType(ptrTyp.Elem()) + default: + return llvm.Value{}, b.makeError(expr.Pos(), "todo: indexaddr: "+ptrTyp.String()) + } +@@ -1982,9 +1986,9 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + index, + } +- return b.CreateInBoundsGEP(bufptr, indices, ""), nil ++ return b.CreateInBoundsGEP(bufType, bufptr, indices, ""), nil + case *types.Slice: +- return b.CreateInBoundsGEP(bufptr, []llvm.Value{index}, ""), nil ++ return b.CreateInBoundsGEP(bufType, bufptr, []llvm.Value{index}, ""), nil + default: + panic("unreachable") + } +@@ -2012,8 +2016,9 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + + // Lookup byte + buf := b.CreateExtractValue(value, 0, "") +- bufPtr := b.CreateInBoundsGEP(buf, []llvm.Value{index}, "") +- return b.CreateLoad(b.ctx.Int8Type(), bufPtr, ""), nil ++ bufElemType := b.ctx.Int8Type() ++ bufPtr := b.CreateInBoundsGEP(bufElemType, buf, []llvm.Value{index}, "") ++ return b.CreateLoad(bufElemType, bufPtr, ""), nil + case *types.Map: + valueType := expr.Type() + if expr.CommaOk { +@@ -2146,7 +2151,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + switch typ := expr.X.Type().Underlying().(type) { + case *types.Pointer: // pointer to array + // slice an array +- length := typ.Elem().Underlying().(*types.Array).Len() ++ arrayType := typ.Elem().Underlying().(*types.Array) ++ length := arrayType.Len() + llvmLen := llvm.ConstInt(b.uintptrType, uint64(length), false) + if high.IsNil() { + high = llvmLen +@@ -2175,7 +2181,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + } + + sliceLen := b.CreateSub(high, low, "slice.len") +- slicePtr := b.CreateInBoundsGEP(value, indices, "slice.ptr") ++ slicePtr := b.CreateInBoundsGEP(b.getLLVMType(arrayType), value, indices, "slice.ptr") + sliceCap := b.CreateSub(max, low, "slice.cap") + + slice := b.ctx.ConstStruct([]llvm.Value{ +@@ -2214,7 +2220,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + max = b.CreateTrunc(max, b.uintptrType, "") + } + +- newPtr := b.CreateInBoundsGEP(oldPtr, []llvm.Value{low}, "") ++ ptrElemType := b.getLLVMType(typ.Elem()) ++ newPtr := b.CreateInBoundsGEP(ptrElemType, oldPtr, []llvm.Value{low}, "") + newLen := b.CreateSub(high, low, "") + newCap := b.CreateSub(max, low, "") + slice := b.ctx.ConstStruct([]llvm.Value{ +@@ -2254,7 +2261,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { + high = b.CreateTrunc(high, b.uintptrType, "") + } + +- newPtr := b.CreateInBoundsGEP(oldPtr, []llvm.Value{low}, "") ++ newPtr := b.CreateInBoundsGEP(b.ctx.Int8Type(), oldPtr, []llvm.Value{low}, "") + newLen := b.CreateSub(high, low, "") + str := llvm.Undef(b.getLLVMRuntimeType("_string")) + str = b.CreateInsertValue(str, newPtr, 0, "") +@@ -2717,14 +2724,15 @@ func (c *compilerContext) createConst(expr *ssa.Const) llvm.Value { + var strPtr llvm.Value + if str != "" { + objname := c.pkg.Path() + "$string" +- global := llvm.AddGlobal(c.mod, llvm.ArrayType(c.ctx.Int8Type(), len(str)), objname) ++ globalType := llvm.ArrayType(c.ctx.Int8Type(), len(str)) ++ global := llvm.AddGlobal(c.mod, globalType, objname) + global.SetInitializer(c.ctx.ConstString(str, false)) + global.SetLinkage(llvm.InternalLinkage) + global.SetGlobalConstant(true) + global.SetUnnamedAddr(true) + global.SetAlignment(1) + zero := llvm.ConstInt(c.ctx.Int32Type(), 0, false) +- strPtr = llvm.ConstInBoundsGEP(global, []llvm.Value{zero, zero}) ++ strPtr = llvm.ConstInBoundsGEP(globalType, global, []llvm.Value{zero, zero}) + } else { + strPtr = llvm.ConstNull(c.i8ptrType) + } +@@ -2844,7 +2852,7 @@ func (b *builder) createConvert(typeFrom, typeTo types.Type, value llvm.Value, p + // create a GEP that is not in bounds. However, we're + // talking about unsafe code here so the programmer has to + // be careful anyway. +- return b.CreateInBoundsGEP(origptr, []llvm.Value{index}, ""), nil ++ return b.CreateInBoundsGEP(b.ctx.Int8Type(), origptr, []llvm.Value{index}, ""), nil + } + } + } +diff --git a/compiler/defer.go b/compiler/defer.go +index 1f892e5b..27e90331 100644 +--- a/compiler/defer.go ++++ b/compiler/defer.go +@@ -407,7 +407,8 @@ func (b *builder) createDefer(instr *ssa.Defer) { + + // createRunDefers emits code to run all deferred functions. + func (b *builder) createRunDefers() { +- deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0) ++ deferType := b.getLLVMRuntimeType("_defer") ++ deferPtrType := llvm.PointerType(deferType, 0) + + // Add a loop like the following: + // for stack != nil { +@@ -434,7 +435,7 @@ func (b *builder) createRunDefers() { + // Create loop head: + // for stack != nil { + b.SetInsertPointAtEnd(loophead) +- deferData := b.CreateLoad(deferType, b.deferPtr, "") ++ deferData := b.CreateLoad(deferPtrType, b.deferPtr, "") + stackIsNil := b.CreateICmp(llvm.IntEQ, deferData, llvm.ConstPointerNull(deferData.Type()), "stackIsNil") + b.CreateCondBr(stackIsNil, end, loop) + +@@ -443,13 +444,13 @@ func (b *builder) createRunDefers() { + // stack = stack.next + // switch stack.callback { + b.SetInsertPointAtEnd(loop) +- nextStackGEP := b.CreateInBoundsGEP(deferData, []llvm.Value{ ++ nextStackGEP := b.CreateInBoundsGEP(deferType, deferData, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 1, false), // .next field + }, "stack.next.gep") +- nextStack := b.CreateLoad(deferType, nextStackGEP, "stack.next") ++ nextStack := b.CreateLoad(deferPtrType, nextStackGEP, "stack.next") + b.CreateStore(nextStack, b.deferPtr) +- gep := b.CreateInBoundsGEP(deferData, []llvm.Value{ ++ gep := b.CreateInBoundsGEP(deferType, deferData, []llvm.Value{ + llvm.ConstInt(b.ctx.Int32Type(), 0, false), + llvm.ConstInt(b.ctx.Int32Type(), 0, false), // .callback field + }, "callback.gep") +@@ -489,7 +490,7 @@ func (b *builder) createRunDefers() { + forwardParams := []llvm.Value{} + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := 2; i < len(valueTypes); i++ { +- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep") ++ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep") + forwardParam := b.CreateLoad(valueTypes[i], gep, "param") + forwardParams = append(forwardParams, forwardParam) + } +@@ -538,7 +539,7 @@ func (b *builder) createRunDefers() { + forwardParams := []llvm.Value{} + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := range getParams(callback.Signature) { +- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") ++ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") + forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") + forwardParams = append(forwardParams, forwardParam) + } +@@ -571,7 +572,7 @@ func (b *builder) createRunDefers() { + forwardParams := []llvm.Value{} + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := 2; i < len(valueTypes); i++ { +- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "") ++ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "") + forwardParam := b.CreateLoad(valueTypes[i], gep, "param") + forwardParams = append(forwardParams, forwardParam) + } +@@ -598,7 +599,7 @@ func (b *builder) createRunDefers() { + var argValues []llvm.Value + zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) + for i := 0; i < params.Len(); i++ { +- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") ++ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") + forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") + argValues = append(argValues, forwardParam) + } +diff --git a/compiler/interface.go b/compiler/interface.go +index 72f8952d..acb474f5 100644 +--- a/compiler/interface.go ++++ b/compiler/interface.go +@@ -122,19 +122,19 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { + for i := 0; i < typ.NumFields(); i++ { + fieldGlobalValue := llvm.ConstNull(runtimeStructField) + fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0}) +- fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) ++ fieldNameType, fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) + fieldName.SetLinkage(llvm.PrivateLinkage) + fieldName.SetUnnamedAddr(true) +- fieldName = llvm.ConstGEP(fieldName, []llvm.Value{ ++ fieldName = llvm.ConstGEP(fieldNameType, fieldName, []llvm.Value{ + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + }) + fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) + if typ.Tag(i) != "" { +- fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) ++ fieldTagType, fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) + fieldTag.SetLinkage(llvm.PrivateLinkage) + fieldTag.SetUnnamedAddr(true) +- fieldTag = llvm.ConstGEP(fieldTag, []llvm.Value{ ++ fieldTag = llvm.ConstGEP(fieldTagType, fieldTag, []llvm.Value{ + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + }) +@@ -239,7 +239,7 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value { + zero := llvm.ConstInt(c.ctx.Int32Type(), 0, false) + if !global.IsNil() { + // the method set already exists +- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) ++ return llvm.ConstGEP(global.GlobalValueType(), global, []llvm.Value{zero, zero}) + } + + ms := c.program.MethodSets.MethodSet(typ) +@@ -272,7 +272,7 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value { + global.SetInitializer(value) + global.SetGlobalConstant(true) + global.SetLinkage(llvm.LinkOnceODRLinkage) +- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) ++ return llvm.ConstGEP(arrayType, global, []llvm.Value{zero, zero}) + } + + // getInterfaceMethodSet returns a global variable with the method set of the +@@ -288,7 +288,7 @@ func (c *compilerContext) getInterfaceMethodSet(typ types.Type) llvm.Value { + zero := llvm.ConstInt(c.ctx.Int32Type(), 0, false) + if !global.IsNil() { + // method set already exist, return it +- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) ++ return llvm.ConstGEP(global.GlobalValueType(), global, []llvm.Value{zero, zero}) + } + + // Every method is a *i8 reference indicating the signature of this method. +@@ -303,7 +303,7 @@ func (c *compilerContext) getInterfaceMethodSet(typ types.Type) llvm.Value { + global.SetInitializer(value) + global.SetGlobalConstant(true) + global.SetLinkage(llvm.LinkOnceODRLinkage) +- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) ++ return llvm.ConstGEP(value.Type(), global, []llvm.Value{zero, zero}) + } + + // getMethodSignatureName returns a unique name (that can be used as the name of +diff --git a/compiler/llvm.go b/compiler/llvm.go +index 9540bcc6..686d4d2b 100644 +--- a/compiler/llvm.go ++++ b/compiler/llvm.go +@@ -61,10 +61,10 @@ func (b *builder) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []ll + } + + // makeGlobalArray creates a new LLVM global with the given name and integers as +-// contents, and returns the global. ++// contents, and returns the global and initializer type. + // Note that it is left with the default linkage etc., you should set + // linkage/constant/etc properties yourself. +-func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType llvm.Type) llvm.Value { ++func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType llvm.Type) (llvm.Type, llvm.Value) { + globalType := llvm.ArrayType(elementType, len(buf)) + global := llvm.AddGlobal(c.mod, globalType, name) + value := llvm.Undef(globalType) +@@ -73,7 +73,7 @@ func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType l + value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) + } + global.SetInitializer(value) +- return global ++ return globalType, global + } + + // createObjectLayout returns a LLVM value (of type i8*) that describes where +diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go +index 97b86045..2a4607c8 100644 +--- a/compiler/llvmutil/wordpack.go ++++ b/compiler/llvmutil/wordpack.go +@@ -58,7 +58,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), uint64(i), false), + } +- gep := builder.CreateInBoundsGEP(packedAllocCast, indices, "") ++ gep := builder.CreateInBoundsGEP(packedType, packedAllocCast, indices, "") + builder.CreateStore(value, gep) + } + +@@ -115,7 +115,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), uint64(i), false), + } +- gep := builder.CreateInBoundsGEP(packedAlloc, indices, "") ++ gep := builder.CreateInBoundsGEP(packedType, packedAlloc, indices, "") + builder.CreateStore(value, gep) + } + +@@ -170,7 +170,7 @@ func EmitPointerUnpack(builder llvm.Builder, mod llvm.Module, ptr llvm.Value, va + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), uint64(i), false), + } +- gep := builder.CreateInBoundsGEP(packedAlloc, indices, "") ++ gep := builder.CreateInBoundsGEP(packedType, packedAlloc, indices, "") + values[i] = builder.CreateLoad(valueType, gep, "") + } + if !packedRawAlloc.IsNil() { +diff --git a/go.mod b/go.mod +index 26707a96..feb4e0d6 100644 +--- a/go.mod ++++ b/go.mod +@@ -17,7 +17,7 @@ require ( + golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 + golang.org/x/tools v0.1.11 + gopkg.in/yaml.v2 v2.4.0 +- tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 ++ tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 + ) + + require ( +diff --git a/go.sum b/go.sum +index e5c734cd..907364f9 100644 +--- a/go.sum ++++ b/go.sum +@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +-tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 h1:bJYUpmJrVm7Uluxh80qSivfeU3d9D4JNg5oJ+h9U+xc= +-tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= ++tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 h1:hihbmHkJjalV4kGshoCF03P/G4IjoXcNAbzLblXLa/M= ++tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +diff --git a/interp/memory.go b/interp/memory.go +index 3a16b875..2fa6f5cb 100644 +--- a/interp/memory.go ++++ b/interp/memory.go +@@ -646,8 +646,8 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val + if llvmValue.Type() != mem.r.i8ptrType { + llvmValue = llvm.ConstBitCast(llvmValue, mem.r.i8ptrType) + } +- llvmValue = llvm.ConstInBoundsGEP(llvmValue, []llvm.Value{ +- llvm.ConstInt(llvmValue.Type().Context().Int32Type(), uint64(v.offset()), false), ++ llvmValue = llvm.ConstInBoundsGEP(mem.r.mod.Context().Int8Type(), llvmValue, []llvm.Value{ ++ llvm.ConstInt(mem.r.mod.Context().Int32Type(), uint64(v.offset()), false), + }) + } + +diff --git a/transform/gc.go b/transform/gc.go +index 7a4e99ac..3870a6b6 100644 +--- a/transform/gc.go ++++ b/transform/gc.go +@@ -223,7 +223,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + + // Update stack start. + parent := builder.CreateLoad(stackChainStartType, stackChainStart, "") +- gep := builder.CreateGEP(stackObject, []llvm.Value{ ++ gep := builder.CreateGEP(stackObjectType, stackObject, []llvm.Value{ + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), 0, false), + }, "") +@@ -244,7 +244,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + builder.SetInsertPointBefore(insertionPoint) + + // Extract a pointer to the appropriate section of the stack object. +- gep := builder.CreateGEP(stackObject, []llvm.Value{ ++ gep := builder.CreateGEP(stackObjectType, stackObject, []llvm.Value{ + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), uint64(2+i), false), + }, "") +diff --git a/transform/llvm.go b/transform/llvm.go +index 32ee9560..6716dd63 100644 +--- a/transform/llvm.go ++++ b/transform/llvm.go +@@ -31,10 +31,10 @@ func hasUses(value llvm.Value) bool { + } + + // makeGlobalArray creates a new LLVM global with the given name and integers as +-// contents, and returns the global. ++// contents, and returns the global and initializer type. + // Note that it is left with the default linkage etc., you should set + // linkage/constant/etc properties yourself. +-func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) llvm.Value { ++func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) (llvm.Type, llvm.Value) { + buf := reflect.ValueOf(bufItf) + globalType := llvm.ArrayType(elementType, buf.Len()) + global := llvm.AddGlobal(mod, globalType, name) +@@ -44,7 +44,7 @@ func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementTy + value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) + } + global.SetInitializer(value) +- return global ++ return globalType, global + } + + // getGlobalBytes returns the slice contained in the array of the provided +@@ -64,8 +64,8 @@ func getGlobalBytes(global llvm.Value) []byte { + // function used for creating reflection sidetables, for example. + func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) llvm.Value { + oldGlobal := mod.NamedGlobal(name) +- global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.Type().ElementType()) +- gep := llvm.ConstGEP(global, []llvm.Value{ ++ globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.Type().ElementType()) ++ gep := llvm.ConstGEP(globalType, global, []llvm.Value{ + llvm.ConstInt(mod.Context().Int32Type(), 0, false), + llvm.ConstInt(mod.Context().Int32Type(), 0, false), + }) +diff --git a/transform/stacksize.go b/transform/stacksize.go +index f1a3c93d..169f1454 100644 +--- a/transform/stacksize.go ++++ b/transform/stacksize.go +@@ -59,7 +59,7 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string + defer irbuilder.Dispose() + for i, function := range functions { + for _, use := range functionMap[function] { +- ptr := llvm.ConstGEP(stackSizesGlobal, []llvm.Value{ ++ ptr := llvm.ConstGEP(stackSizesGlobalType, stackSizesGlobal, []llvm.Value{ + llvm.ConstInt(ctx.Int32Type(), 0, false), + llvm.ConstInt(ctx.Int32Type(), uint64(i), false), + }) +-- +2.36.1 + diff --git a/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch b/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch new file mode 100644 index 0000000..a730ef6 --- /dev/null +++ b/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch @@ -0,0 +1,578 @@ +From 6053c1c8528c63a669d070550bacd43f2f6a68e1 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Tue, 20 Sep 2022 23:26:49 +0200 +Subject: [PATCH 12/18] all: replace llvm.Const* calls with builder.Create* + calls + +A number of llvm.Const* functions (in particular extractvalue and +insertvalue) were removed in LLVM 15, so we have to use a builder +instead. This builder will create the same constant values, it simply +uses a different API. + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/asserts.go | 2 +- + compiler/compiler.go | 23 ++++++++++++++++------- + compiler/interface.go | 20 ++++++++++---------- + compiler/interrupt.go | 8 +++++--- + compiler/llvm.go | 2 +- + interp/interpreter.go | 13 +++++++------ + interp/memory.go | 8 ++++---- + transform/gc.go | 2 +- + transform/interface-lowering.go | 14 +++++++------- + transform/interrupt.go | 7 ++++--- + transform/llvm.go | 16 +++++++++------- + transform/reflect.go | 32 +++++++++++++++++++------------- + transform/rtcalls.go | 4 ++-- + 13 files changed, 86 insertions(+), 65 deletions(-) + +diff --git a/compiler/asserts.go b/compiler/asserts.go +index 8d9efdde..2a5265e9 100644 +--- a/compiler/asserts.go ++++ b/compiler/asserts.go +@@ -145,7 +145,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value, + } + // Make the maxBufSize actually the maximum allowed value (in number of + // elements in the channel buffer). +- maxBufSize = llvm.ConstUDiv(maxBufSize, llvm.ConstInt(b.uintptrType, elementSize, false)) ++ maxBufSize = b.CreateUDiv(maxBufSize, llvm.ConstInt(b.uintptrType, elementSize, false), "") + + // Make sure maxBufSize has the same type as bufSize. + if maxBufSize.Type() != bufSize.Type() { +diff --git a/compiler/compiler.go b/compiler/compiler.go +index c93b2e56..3d29628c 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -63,6 +63,7 @@ type compilerContext struct { + DumpSSA bool + mod llvm.Module + ctx llvm.Context ++ builder llvm.Builder // only used for constant operations + dibuilder *llvm.DIBuilder + cu llvm.Metadata + difiles map[string]llvm.Metadata +@@ -98,6 +99,7 @@ func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *C + } + + c.ctx = llvm.NewContext() ++ c.builder = c.ctx.NewBuilder() + c.mod = c.ctx.NewModule(moduleName) + c.mod.SetTarget(config.Triple) + c.mod.SetDataLayout(c.targetData.String()) +@@ -126,6 +128,12 @@ func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *C + return c + } + ++// Dispose everything related to the context, _except_ for the IR module (and ++// the associated context). ++func (c *compilerContext) dispose() { ++ c.builder.Dispose() ++} ++ + // builder contains all information relevant to build a single function. + type builder struct { + *compilerContext +@@ -256,6 +264,7 @@ func Sizes(machine llvm.TargetMachine) types.Sizes { + // CompilePackage compiles a single package to a LLVM module. + func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, machine llvm.TargetMachine, config *Config, dumpSSA bool) (llvm.Module, []error) { + c := newCompilerContext(moduleName, machine, config, dumpSSA) ++ defer c.dispose() + c.packageDir = pkg.OriginalDir() + c.embedGlobals = pkg.EmbedGlobals + c.pkg = pkg.Pkg +@@ -972,10 +981,10 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu + for _, file := range allFiles { + fileStruct := llvm.ConstNull(embedFileStructType) + name := c.createConst(ssa.NewConst(constant.MakeString(file.Name), types.Typ[types.String])) +- fileStruct = llvm.ConstInsertValue(fileStruct, name, []uint32{0}) // "name" field ++ fileStruct = c.builder.CreateInsertValue(fileStruct, name, 0, "") // "name" field + if file.Hash != "" { + data := c.getEmbedFileString(file) +- fileStruct = llvm.ConstInsertValue(fileStruct, data, []uint32{1}) // "data" field ++ fileStruct = c.builder.CreateInsertValue(fileStruct, data, 1, "") // "data" field + } + fileStructs = append(fileStructs, fileStruct) + } +@@ -1006,7 +1015,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu + // Define the embed.FS struct. It has only one field: the files (as a + // *[]embed.file). + globalInitializer := llvm.ConstNull(c.getLLVMType(member.Type().(*types.Pointer).Elem())) +- globalInitializer = llvm.ConstInsertValue(globalInitializer, sliceGlobal, []uint32{0}) ++ globalInitializer = c.builder.CreateInsertValue(globalInitializer, sliceGlobal, 0, "") + global.SetInitializer(globalInitializer) + global.SetVisibility(llvm.HiddenVisibility) + global.SetAlignment(c.targetData.ABITypeAlignment(globalInitializer.Type())) +@@ -2757,15 +2766,15 @@ func (c *compilerContext) createConst(expr *ssa.Const) llvm.Value { + r := c.createConst(ssa.NewConst(constant.Real(expr.Value), types.Typ[types.Float32])) + i := c.createConst(ssa.NewConst(constant.Imag(expr.Value), types.Typ[types.Float32])) + cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{c.ctx.FloatType(), c.ctx.FloatType()}, false)) +- cplx = llvm.ConstInsertValue(cplx, r, []uint32{0}) +- cplx = llvm.ConstInsertValue(cplx, i, []uint32{1}) ++ cplx = c.builder.CreateInsertValue(cplx, r, 0, "") ++ cplx = c.builder.CreateInsertValue(cplx, i, 1, "") + return cplx + } else if typ.Kind() == types.Complex128 { + r := c.createConst(ssa.NewConst(constant.Real(expr.Value), types.Typ[types.Float64])) + i := c.createConst(ssa.NewConst(constant.Imag(expr.Value), types.Typ[types.Float64])) + cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{c.ctx.DoubleType(), c.ctx.DoubleType()}, false)) +- cplx = llvm.ConstInsertValue(cplx, r, []uint32{0}) +- cplx = llvm.ConstInsertValue(cplx, i, []uint32{1}) ++ cplx = c.builder.CreateInsertValue(cplx, r, 0, "") ++ cplx = c.builder.CreateInsertValue(cplx, i, 1, "") + return cplx + } else { + panic("unknown constant of basic type: " + expr.String()) +diff --git a/compiler/interface.go b/compiler/interface.go +index acb474f5..106c327a 100644 +--- a/compiler/interface.go ++++ b/compiler/interface.go +@@ -88,20 +88,20 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value { + } + globalValue := llvm.ConstNull(global.Type().ElementType()) + if !references.IsNil() { +- globalValue = llvm.ConstInsertValue(globalValue, references, []uint32{0}) ++ globalValue = c.builder.CreateInsertValue(globalValue, references, 0, "") + } + if length != 0 { + lengthValue := llvm.ConstInt(c.uintptrType, uint64(length), false) +- globalValue = llvm.ConstInsertValue(globalValue, lengthValue, []uint32{1}) ++ globalValue = c.builder.CreateInsertValue(globalValue, lengthValue, 1, "") + } + if !methodSet.IsNil() { +- globalValue = llvm.ConstInsertValue(globalValue, methodSet, []uint32{2}) ++ globalValue = c.builder.CreateInsertValue(globalValue, methodSet, 2, "") + } + if !ptrTo.IsNil() { +- globalValue = llvm.ConstInsertValue(globalValue, ptrTo, []uint32{3}) ++ globalValue = c.builder.CreateInsertValue(globalValue, ptrTo, 3, "") + } + if !typeAssert.IsNil() { +- globalValue = llvm.ConstInsertValue(globalValue, typeAssert, []uint32{4}) ++ globalValue = c.builder.CreateInsertValue(globalValue, typeAssert, 4, "") + } + global.SetInitializer(globalValue) + global.SetLinkage(llvm.LinkOnceODRLinkage) +@@ -121,7 +121,7 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { + structGlobalValue := llvm.ConstNull(structGlobalType) + for i := 0; i < typ.NumFields(); i++ { + fieldGlobalValue := llvm.ConstNull(runtimeStructField) +- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0}) ++ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), 0, "") + fieldNameType, fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) + fieldName.SetLinkage(llvm.PrivateLinkage) + fieldName.SetUnnamedAddr(true) +@@ -129,7 +129,7 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + }) +- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) ++ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldName, 1, "") + if typ.Tag(i) != "" { + fieldTagType, fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) + fieldTag.SetLinkage(llvm.PrivateLinkage) +@@ -138,13 +138,13 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + }) +- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldTag, []uint32{2}) ++ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldTag, 2, "") + } + if typ.Field(i).Embedded() { + fieldEmbedded := llvm.ConstInt(c.ctx.Int1Type(), 1, false) +- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldEmbedded, []uint32{3}) ++ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldEmbedded, 3, "") + } +- structGlobalValue = llvm.ConstInsertValue(structGlobalValue, fieldGlobalValue, []uint32{uint32(i)}) ++ structGlobalValue = c.builder.CreateInsertValue(structGlobalValue, fieldGlobalValue, i, "") + } + structGlobal.SetInitializer(structGlobalValue) + structGlobal.SetUnnamedAddr(true) +diff --git a/compiler/interrupt.go b/compiler/interrupt.go +index 45c7d074..c1f7d69f 100644 +--- a/compiler/interrupt.go ++++ b/compiler/interrupt.go +@@ -49,9 +49,11 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro + global.SetGlobalConstant(true) + global.SetUnnamedAddr(true) + initializer := llvm.ConstNull(globalLLVMType) +- initializer = llvm.ConstInsertValue(initializer, funcContext, []uint32{0}) +- initializer = llvm.ConstInsertValue(initializer, funcPtr, []uint32{1}) +- initializer = llvm.ConstInsertValue(initializer, llvm.ConstInt(b.intType, uint64(id.Int64()), true), []uint32{2, 0}) ++ initializer = b.CreateInsertValue(initializer, funcContext, 0, "") ++ initializer = b.CreateInsertValue(initializer, funcPtr, 1, "") ++ initializer = b.CreateInsertValue(initializer, llvm.ConstNamedStruct(globalLLVMType.StructElementTypes()[2], []llvm.Value{ ++ llvm.ConstInt(b.intType, uint64(id.Int64()), true), ++ }), 2, "") + global.SetInitializer(initializer) + + // Add debug info to the interrupt global. +diff --git a/compiler/llvm.go b/compiler/llvm.go +index 686d4d2b..8b80869b 100644 +--- a/compiler/llvm.go ++++ b/compiler/llvm.go +@@ -70,7 +70,7 @@ func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType l + value := llvm.Undef(globalType) + for i := 0; i < len(buf); i++ { + ch := uint64(buf[i]) +- value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) ++ value = c.builder.CreateInsertValue(value, llvm.ConstInt(elementType, ch, false), i, "") + } + global.SetInitializer(value) + return globalType, global +diff --git a/interp/interpreter.go b/interp/interpreter.go +index 2c7fd8c3..d029aa33 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -408,7 +408,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + // Elem() is only valid for certain type classes. + switch class { + case "chan", "pointer", "slice", "array": +- elementType := llvm.ConstExtractValue(typecodeID.Initializer(), []uint32{0}) ++ elementType := r.builder.CreateExtractValue(typecodeID.Initializer(), 0, "") + uintptrType := r.mod.Context().IntType(int(mem.r.pointerSize) * 8) + locals[inst.localIndex] = r.getValue(llvm.ConstPtrToInt(elementType, uintptrType)) + default: +@@ -461,8 +461,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + // easier checking in the next step. + concreteTypeMethods := map[string]struct{}{} + for i := 0; i < methodSet.Type().ArrayLength(); i++ { +- methodInfo := llvm.ConstExtractValue(methodSet, []uint32{uint32(i)}) +- name := llvm.ConstExtractValue(methodInfo, []uint32{0}).Name() ++ methodInfo := r.builder.CreateExtractValue(methodSet, i, "") ++ name := r.builder.CreateExtractValue(methodInfo, 0, "").Name() + concreteTypeMethods[name] = struct{}{} + } + +@@ -496,7 +496,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + typecodeID := typecodeIDBitCast.Operand(0).Initializer() + + // Load the method set, which is part of the typecodeID object. +- methodSet := llvm.ConstExtractValue(typecodeID, []uint32{2}).Operand(0).Initializer() ++ methodSet := r.builder.CreateExtractValue(typecodeID, 2, "").Operand(0).Initializer() + + // We don't need to load the interface method set. + +@@ -511,9 +511,10 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + numMethods := methodSet.Type().ArrayLength() + var method llvm.Value + for i := 0; i < numMethods; i++ { +- methodSignature := llvm.ConstExtractValue(methodSet, []uint32{uint32(i), 0}) ++ methodSignatureAgg := r.builder.CreateExtractValue(methodSet, i, "") ++ methodSignature := r.builder.CreateExtractValue(methodSignatureAgg, 0, "") + if methodSignature == signature { +- method = llvm.ConstExtractValue(methodSet, []uint32{uint32(i), 1}).Operand(0) ++ method = r.builder.CreateExtractValue(methodSignatureAgg, 1, "").Operand(0) + } + } + if method.IsNil() { +diff --git a/interp/memory.go b/interp/memory.go +index 2fa6f5cb..583f9355 100644 +--- a/interp/memory.go ++++ b/interp/memory.go +@@ -215,7 +215,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error { + case llvm.StructTypeKind: + numElements := llvmType.StructElementTypesCount() + for i := 0; i < numElements; i++ { +- element := llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}) ++ element := mv.r.builder.CreateExtractValue(llvmValue, i, "") + err := mv.markExternal(element, mark) + if err != nil { + return err +@@ -224,7 +224,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error { + case llvm.ArrayTypeKind: + numElements := llvmType.ArrayLength() + for i := 0; i < numElements; i++ { +- element := llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}) ++ element := mv.r.builder.CreateExtractValue(llvmValue, i, "") + err := mv.markExternal(element, mark) + if err != nil { + return err +@@ -1074,7 +1074,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { + field := rawValue{ + buf: v.buf[offset:], + } +- field.set(llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}), r) ++ field.set(r.builder.CreateExtractValue(llvmValue, i, ""), r) + } + case llvm.ArrayTypeKind: + numElements := llvmType.ArrayLength() +@@ -1085,7 +1085,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { + field := rawValue{ + buf: v.buf[offset:], + } +- field.set(llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}), r) ++ field.set(r.builder.CreateExtractValue(llvmValue, i, ""), r) + } + case llvm.DoubleTypeKind: + f, _ := llvmValue.DoubleValue() +diff --git a/transform/gc.go b/transform/gc.go +index 3870a6b6..514fb1bf 100644 +--- a/transform/gc.go ++++ b/transform/gc.go +@@ -218,7 +218,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + initialStackObject := llvm.ConstNull(stackObjectType) + numSlots := (targetData.TypeAllocSize(stackObjectType) - uint64(targetData.PointerSize())*2) / uint64(targetData.ABITypeAlignment(uintptrType)) + numSlotsValue := llvm.ConstInt(uintptrType, numSlots, false) +- initialStackObject = llvm.ConstInsertValue(initialStackObject, numSlotsValue, []uint32{1}) ++ initialStackObject = builder.CreateInsertValue(initialStackObject, numSlotsValue, 1, "") + builder.CreateStore(initialStackObject, stackObject) + + // Update stack start. +diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go +index f5b29e30..f28443dc 100644 +--- a/transform/interface-lowering.go ++++ b/transform/interface-lowering.go +@@ -154,7 +154,7 @@ func (p *lowerInterfacesPass) run() error { + if initializer.IsNil() { + continue + } +- methodSet := llvm.ConstExtractValue(initializer, []uint32{2}) ++ methodSet := p.builder.CreateExtractValue(initializer, 2, "") + p.addTypeMethods(t, methodSet) + } + } +@@ -288,9 +288,9 @@ func (p *lowerInterfacesPass) run() error { + zeroUintptr := llvm.ConstNull(p.uintptrType) + for _, t := range p.types { + initializer := t.typecode.Initializer() +- methodSet := llvm.ConstExtractValue(initializer, []uint32{2}) +- initializer = llvm.ConstInsertValue(initializer, llvm.ConstNull(methodSet.Type()), []uint32{2}) +- initializer = llvm.ConstInsertValue(initializer, zeroUintptr, []uint32{4}) ++ methodSet := p.builder.CreateExtractValue(initializer, 2, "") ++ initializer = p.builder.CreateInsertValue(initializer, llvm.ConstNull(methodSet.Type()), 2, "") ++ initializer = p.builder.CreateInsertValue(initializer, zeroUintptr, 4, "") + t.typecode.SetInitializer(initializer) + } + +@@ -311,10 +311,10 @@ func (p *lowerInterfacesPass) addTypeMethods(t *typeInfo, methodSet llvm.Value) + t.methodSet = methodSet + set := methodSet.Initializer() // get value from global + for i := 0; i < set.Type().ArrayLength(); i++ { +- methodData := llvm.ConstExtractValue(set, []uint32{uint32(i)}) +- signatureGlobal := llvm.ConstExtractValue(methodData, []uint32{0}) ++ methodData := p.builder.CreateExtractValue(set, i, "") ++ signatureGlobal := p.builder.CreateExtractValue(methodData, 0, "") + signatureName := signatureGlobal.Name() +- function := llvm.ConstExtractValue(methodData, []uint32{1}).Operand(0) ++ function := p.builder.CreateExtractValue(methodData, 1, "").Operand(0) + signature := p.getSignature(signatureName) + method := &methodInfo{ + function: function, +diff --git a/transform/interrupt.go b/transform/interrupt.go +index 2c301be0..b15ff8a9 100644 +--- a/transform/interrupt.go ++++ b/transform/interrupt.go +@@ -44,7 +44,8 @@ func LowerInterrupts(mod llvm.Module) []error { + + // Get the interrupt number from the initializer + initializer := global.Initializer() +- num := llvm.ConstExtractValue(initializer, []uint32{2, 0}).SExtValue() ++ interrupt := builder.CreateExtractValue(initializer, 2, "") ++ num := builder.CreateExtractValue(interrupt, 0, "").SExtValue() + pkg := packageFromInterruptHandle(global) + + handles, exists := handleMap[num] +@@ -89,8 +90,8 @@ func LowerInterrupts(mod llvm.Module) []error { + builder.SetInsertPointBefore(call) + for _, handler := range handlers { + initializer := handler.Initializer() +- context := llvm.ConstExtractValue(initializer, []uint32{0}) +- funcPtr := llvm.ConstExtractValue(initializer, []uint32{1}).Operand(0) ++ context := builder.CreateExtractValue(initializer, 0, "") ++ funcPtr := builder.CreateExtractValue(initializer, 1, "").Operand(0) + builder.CreateCall(funcPtr.GlobalValueType(), funcPtr, []llvm.Value{ + num, + context, +diff --git a/transform/llvm.go b/transform/llvm.go +index 6716dd63..17968f8a 100644 +--- a/transform/llvm.go ++++ b/transform/llvm.go +@@ -36,25 +36,27 @@ func hasUses(value llvm.Value) bool { + // linkage/constant/etc properties yourself. + func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) (llvm.Type, llvm.Value) { + buf := reflect.ValueOf(bufItf) +- globalType := llvm.ArrayType(elementType, buf.Len()) +- global := llvm.AddGlobal(mod, globalType, name) +- value := llvm.Undef(globalType) ++ var values []llvm.Value + for i := 0; i < buf.Len(); i++ { + ch := buf.Index(i).Uint() +- value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) ++ values = append(values, llvm.ConstInt(elementType, ch, false)) + } ++ value := llvm.ConstArray(elementType, values) ++ global := llvm.AddGlobal(mod, value.Type(), name) + global.SetInitializer(value) +- return globalType, global ++ return value.Type(), global + } + + // getGlobalBytes returns the slice contained in the array of the provided + // global. It can recover the bytes originally created using makeGlobalArray, if + // makeGlobalArray was given a byte slice. +-func getGlobalBytes(global llvm.Value) []byte { ++// ++// The builder parameter is only used for constant operations. ++func getGlobalBytes(global llvm.Value, builder llvm.Builder) []byte { + value := global.Initializer() + buf := make([]byte, value.Type().ArrayLength()) + for i := range buf { +- buf[i] = byte(llvm.ConstExtractValue(value, []uint32{uint32(i)}).ZExtValue()) ++ buf[i] = byte(builder.CreateExtractValue(value, i, "").ZExtValue()) + } + return buf + } +diff --git a/transform/reflect.go b/transform/reflect.go +index fd70ccb7..68beba9b 100644 +--- a/transform/reflect.go ++++ b/transform/reflect.go +@@ -76,6 +76,10 @@ var nonBasicTypes = map[string]int64{ + // typeCodeAssignmentState keeps some global state around for type code + // assignments, used to assign one unique type code to each Go type. + type typeCodeAssignmentState struct { ++ // Builder used purely for constant operations (because LLVM 15 removed many ++ // llvm.Const* functions). ++ builder llvm.Builder ++ + // An integer that's incremented each time it's used to give unique IDs to + // type codes that are not yet fully supported otherwise by the reflect + // package (or are simply unused in the compiled program). +@@ -165,6 +169,7 @@ func LowerReflect(mod llvm.Module) { + defer targetData.Dispose() + uintptrType := mod.Context().IntType(targetData.PointerSize() * 8) + state := typeCodeAssignmentState{ ++ builder: mod.Context().NewBuilder(), + fallbackIndex: 1, + uintptrLen: targetData.PointerSize() * 8, + namedBasicTypes: make(map[string]int), +@@ -177,6 +182,7 @@ func LowerReflect(mod llvm.Module) { + needsStructNamesSidetable: len(getUses(mod.NamedGlobal("reflect.structNamesSidetable"))) != 0, + needsArrayTypesSidetable: len(getUses(mod.NamedGlobal("reflect.arrayTypesSidetable"))) != 0, + } ++ defer state.builder.Dispose() + for _, t := range types { + num := state.getTypeCodeNum(t.typecode) + if num.BitLen() > state.uintptrLen || !num.IsUint64() { +@@ -238,7 +244,7 @@ func LowerReflect(mod llvm.Module) { + // It also cleans up the IR for testing. + for _, typ := range types { + initializer := typ.typecode.Initializer() +- references := llvm.ConstExtractValue(initializer, []uint32{0}) ++ references := state.builder.CreateExtractValue(initializer, 0, "") + typ.typecode.SetInitializer(llvm.ConstNull(initializer.Type())) + if strings.HasPrefix(typ.name, "reflect/types.type:struct:") { + // Structs have a 'references' field that is not a typecode but +@@ -260,7 +266,7 @@ func (state *typeCodeAssignmentState) getTypeCodeNum(typecode llvm.Value) *big.I + name := "" + if class == "named" { + name = value +- typecode = llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}) ++ typecode = state.builder.CreateExtractValue(typecode.Initializer(), 0, "") + class, value = getClassAndValueFromTypeCode(typecode) + } + if class == "basic" { +@@ -344,7 +350,7 @@ func (state *typeCodeAssignmentState) getNonBasicTypeCode(class string, typecode + switch class { + case "chan", "pointer", "slice": + // Prefix-style type kinds. The upper bits contain the element type. +- sub := llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}) ++ sub := state.builder.CreateExtractValue(typecode.Initializer(), 0, "") + return state.getTypeCodeNum(sub) + case "array": + // An array is basically a pair of (typecode, length) stored in a +@@ -416,7 +422,7 @@ func (state *typeCodeAssignmentState) getArrayTypeNum(typecode llvm.Value) int { + return num + } + +- elemTypeCode := llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}) ++ elemTypeCode := state.builder.CreateExtractValue(typecode.Initializer(), 0, "") + elemTypeNum := state.getTypeCodeNum(elemTypeCode) + if elemTypeNum.BitLen() > state.uintptrLen || !elemTypeNum.IsUint64() { + // TODO: make this a regular error +@@ -424,7 +430,7 @@ func (state *typeCodeAssignmentState) getArrayTypeNum(typecode llvm.Value) int { + } + + // The array side table is a sequence of {element type, array length}. +- arrayLength := llvm.ConstExtractValue(typecode.Initializer(), []uint32{1}).ZExtValue() ++ arrayLength := state.builder.CreateExtractValue(typecode.Initializer(), 1, "").ZExtValue() + buf := makeVarint(elemTypeNum.Uint64()) + buf = append(buf, makeVarint(arrayLength)...) + +@@ -454,7 +460,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int + + // Get the fields this struct type contains. + // The struct number will be the start index of +- structTypeGlobal := llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}).Operand(0).Initializer() ++ structTypeGlobal := state.builder.CreateExtractValue(typecode.Initializer(), 0, "").Operand(0).Initializer() + numFields := structTypeGlobal.Type().ArrayLength() + + // The first data that is stored in the struct sidetable is the number of +@@ -471,28 +477,28 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int + // the sidetable bigger. + for i := 0; i < numFields; i++ { + // Collect some information about this field. +- field := llvm.ConstExtractValue(structTypeGlobal, []uint32{uint32(i)}) ++ field := state.builder.CreateExtractValue(structTypeGlobal, i, "") + +- nameGlobal := llvm.ConstExtractValue(field, []uint32{1}) ++ nameGlobal := state.builder.CreateExtractValue(field, 1, "") + if nameGlobal == llvm.ConstPointerNull(nameGlobal.Type()) { + panic("compiler: no name for this struct field") + } +- fieldNameBytes := getGlobalBytes(nameGlobal.Operand(0)) ++ fieldNameBytes := getGlobalBytes(nameGlobal.Operand(0), state.builder) + fieldNameNumber := state.getStructNameNumber(fieldNameBytes) + + // See whether this struct field has an associated tag, and if so, + // store that tag in the tags sidetable. +- tagGlobal := llvm.ConstExtractValue(field, []uint32{2}) ++ tagGlobal := state.builder.CreateExtractValue(field, 2, "") + hasTag := false + tagNumber := 0 + if tagGlobal != llvm.ConstPointerNull(tagGlobal.Type()) { + hasTag = true +- tagBytes := getGlobalBytes(tagGlobal.Operand(0)) ++ tagBytes := getGlobalBytes(tagGlobal.Operand(0), state.builder) + tagNumber = state.getStructNameNumber(tagBytes) + } + + // The 'embedded' or 'anonymous' flag for this field. +- embedded := llvm.ConstExtractValue(field, []uint32{3}).ZExtValue() != 0 ++ embedded := state.builder.CreateExtractValue(field, 3, "").ZExtValue() != 0 + + // The first byte in the struct types sidetable is a flags byte with + // two bits in it. +@@ -510,7 +516,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int + + // Get the type number and add it to the buffer. + // All fields have a type, so include it directly here. +- typeNum := state.getTypeCodeNum(llvm.ConstExtractValue(field, []uint32{0})) ++ typeNum := state.getTypeCodeNum(state.builder.CreateExtractValue(field, 0, "")) + if typeNum.BitLen() > state.uintptrLen || !typeNum.IsUint64() { + // TODO: make this a regular error + panic("struct field has a type code that is too big") +diff --git a/transform/rtcalls.go b/transform/rtcalls.go +index 2f17f815..d70bc626 100644 +--- a/transform/rtcalls.go ++++ b/transform/rtcalls.go +@@ -149,7 +149,7 @@ func OptimizeReflectImplements(mod llvm.Module) { + interfaceType := interfaceTypeBitCast.Operand(0) + if strings.HasPrefix(interfaceType.Name(), "reflect/types.type:named:") { + // Get the underlying type. +- interfaceType = llvm.ConstExtractValue(interfaceType.Initializer(), []uint32{0}) ++ interfaceType = builder.CreateExtractValue(interfaceType.Initializer(), 0, "") + } + if !strings.HasPrefix(interfaceType.Name(), "reflect/types.type:interface:") { + // This is an error. The Type passed to Implements should be of +@@ -161,7 +161,7 @@ func OptimizeReflectImplements(mod llvm.Module) { + // Interface is unknown at compile time. This can't be optimized. + continue + } +- typeAssertFunction := llvm.ConstExtractValue(interfaceType.Initializer(), []uint32{4}).Operand(0) ++ typeAssertFunction := builder.CreateExtractValue(interfaceType.Initializer(), 4, "").Operand(0) + + // Replace Implements call with the type assert call. + builder.SetInsertPointBefore(call) +-- +2.36.1 + diff --git a/0013-interp-change-object.llvmType-to-the-initializer-typ.patch b/0013-interp-change-object.llvmType-to-the-initializer-typ.patch new file mode 100644 index 0000000..4ef130d --- /dev/null +++ b/0013-interp-change-object.llvmType-to-the-initializer-typ.patch @@ -0,0 +1,79 @@ +From 1004deaafd70d4eb94196977c20a5b1a17cded81 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 22 Sep 2022 01:06:40 +0200 +Subject: [PATCH 13/18] interp: change object.llvmType to the initializer type + +Previously it was a pointer type, which won't work with opaque pointers. +Instead, use the global initializer type instead. + +Signed-off-by: Elliott Sales de Andrade +--- + go.mod | 2 +- + go.sum | 4 ++-- + interp/interpreter.go | 2 +- + interp/memory.go | 4 ++-- + 4 files changed, 6 insertions(+), 6 deletions(-) + +diff --git a/go.mod b/go.mod +index feb4e0d6..a50f1174 100644 +--- a/go.mod ++++ b/go.mod +@@ -17,7 +17,7 @@ require ( + golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 + golang.org/x/tools v0.1.11 + gopkg.in/yaml.v2 v2.4.0 +- tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 ++ tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec + ) + + require ( +diff --git a/go.sum b/go.sum +index 907364f9..4af03408 100644 +--- a/go.sum ++++ b/go.sum +@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +-tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 h1:hihbmHkJjalV4kGshoCF03P/G4IjoXcNAbzLblXLa/M= +-tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= ++tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec h1:FYtAFrw/YQPc644uNN65dW50FrEuVNaPBf70x23ApY4= ++tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +diff --git a/interp/interpreter.go b/interp/interpreter.go +index d029aa33..8c783a70 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -637,7 +637,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + // Create the new object. + size := operands[0].(literalValue).value.(uint64) + alloca := object{ +- llvmType: inst.llvmInst.Type(), ++ llvmType: inst.llvmInst.AllocatedType(), + globalName: r.pkgName + "$alloca", + buffer: newRawValue(uint32(size)), + size: uint32(size), +diff --git a/interp/memory.go b/interp/memory.go +index 583f9355..6a537bad 100644 +--- a/interp/memory.go ++++ b/interp/memory.go +@@ -37,7 +37,7 @@ import ( + // ability to roll back interpreting a function. + type object struct { + llvmGlobal llvm.Value +- llvmType llvm.Type // must match llvmGlobal.Type() if both are set, may be unset if llvmGlobal is set ++ llvmType llvm.Type // must match llvmGlobal.GlobalValueType() if both are set, may be unset if llvmGlobal is set + llvmLayoutType llvm.Type // LLVM type based on runtime.alloc layout parameter, if available + globalName string // name, if not yet created (not guaranteed to be the final name) + buffer value // buffer with value as given by interp, nil if external +@@ -594,7 +594,7 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val + var globalType llvm.Type + if !obj.llvmType.IsNil() { + // The exact type is known. +- globalType = obj.llvmType.ElementType() ++ globalType = obj.llvmType + } else { // !obj.llvmLayoutType.IsNil() + // The exact type isn't known, but the object layout is known. + globalType = obj.llvmLayoutType +-- +2.36.1 + diff --git a/0014-all-remove-pointer-ElementType-calls.patch b/0014-all-remove-pointer-ElementType-calls.patch new file mode 100644 index 0000000..36f0818 --- /dev/null +++ b/0014-all-remove-pointer-ElementType-calls.patch @@ -0,0 +1,586 @@ +From 0cdaa0f6db40e372db24d945b557d03b97ff92e9 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 22 Sep 2022 13:33:00 +0200 +Subject: [PATCH 14/18] all: remove pointer ElementType calls + +This is needed for opaque pointers, which are enabled by default in +LLVM 15. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/build.go | 4 +-- + compiler/asserts.go | 4 +-- + compiler/calls.go | 58 ++++++++++++++------------------- + compiler/compiler.go | 15 +++++---- + compiler/func.go | 2 +- + compiler/interface.go | 4 +-- + compiler/ircheck/check.go | 5 +-- + compiler/symbol.go | 15 ++------- + interp/compiler.go | 21 ++++++++---- + interp/interp.go | 10 +++--- + interp/interpreter.go | 2 +- + interp/memory.go | 23 +++++++------ + transform/allocs.go | 2 +- + transform/gc.go | 4 +-- + transform/interface-lowering.go | 2 +- + transform/llvm.go | 2 +- + transform/wasm-abi.go | 2 +- + 17 files changed, 82 insertions(+), 93 deletions(-) + +diff --git a/builder/build.go b/builder/build.go +index 7a7dd9ac..488ee823 100644 +--- a/builder/build.go ++++ b/builder/build.go +@@ -418,7 +418,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil + return errors.New("global not found: " + globalName) + } + name := global.Name() +- newGlobal := llvm.AddGlobal(mod, global.Type().ElementType(), name+".tmp") ++ newGlobal := llvm.AddGlobal(mod, global.GlobalValueType(), name+".tmp") + global.ReplaceAllUsesWith(newGlobal) + global.EraseFromParentAsGlobal() + newGlobal.SetName(name) +@@ -1134,7 +1134,7 @@ func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) erro + + // A strin is a {ptr, len} pair. We need these types to build the + // initializer. +- initializerType := global.Type().ElementType() ++ initializerType := global.GlobalValueType() + if initializerType.TypeKind() != llvm.StructTypeKind || initializerType.StructName() == "" { + return fmt.Errorf("%s: not a string", globalName) + } +diff --git a/compiler/asserts.go b/compiler/asserts.go +index 2a5265e9..ba482494 100644 +--- a/compiler/asserts.go ++++ b/compiler/asserts.go +@@ -91,7 +91,7 @@ func (b *builder) createSliceToArrayPointerCheck(sliceLen llvm.Value, arrayLen i + + // createUnsafeSliceCheck inserts a runtime check used for unsafe.Slice. This + // function must panic if the ptr/len parameters are invalid. +-func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, lenType *types.Basic) { ++func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, elementType llvm.Type, lenType *types.Basic) { + // From the documentation of unsafe.Slice: + // > At run time, if len is negative, or if ptr is nil and len is not + // > zero, a run-time panic occurs. +@@ -105,7 +105,7 @@ func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, lenType *types.Bas + + // Determine the maximum slice size, and therefore the maximum value of the + // len parameter. +- maxSize := b.maxSliceSize(ptr.Type().ElementType()) ++ maxSize := b.maxSliceSize(elementType) + maxSizeValue := llvm.ConstInt(len.Type(), maxSize, false) + + // Do the check. By using unsigned greater than for the length check, signed +diff --git a/compiler/calls.go b/compiler/calls.go +index b38d770f..b122f0c8 100644 +--- a/compiler/calls.go ++++ b/compiler/calls.go +@@ -20,7 +20,7 @@ const maxFieldsPerParam = 3 + type paramInfo struct { + llvmType llvm.Type + name string // name, possibly with suffixes for e.g. struct fields +- flags paramFlags ++ elemSize uint64 // size of pointer element type, or 0 if this isn't a pointer + } + + // paramFlags identifies parameter attributes for flags. Most importantly, it +@@ -96,13 +96,7 @@ func (c *compilerContext) expandFormalParamType(t llvm.Type, name string, goType + // failed to expand this parameter: too many fields + } + // TODO: split small arrays +- return []paramInfo{ +- { +- llvmType: t, +- name: name, +- flags: getTypeFlags(goType), +- }, +- } ++ return []paramInfo{c.getParamInfo(t, name, goType)} + } + + // expandFormalParamOffsets returns a list of offsets from the start of an +@@ -152,7 +146,6 @@ func (b *builder) expandFormalParam(v llvm.Value) []llvm.Value { + // Try to flatten a struct type to a list of types. Returns a 1-element slice + // with the passed in type if this is not possible. + func (c *compilerContext) flattenAggregateType(t llvm.Type, name string, goType types.Type) []paramInfo { +- typeFlags := getTypeFlags(goType) + switch t.TypeKind() { + case llvm.StructTypeKind: + var paramInfos []paramInfo +@@ -183,40 +176,37 @@ func (c *compilerContext) flattenAggregateType(t llvm.Type, name string, goType + } + } + subInfos := c.flattenAggregateType(subfield, name+"."+suffix, extractSubfield(goType, i)) +- for i := range subInfos { +- subInfos[i].flags |= typeFlags +- } + paramInfos = append(paramInfos, subInfos...) + } + return paramInfos + default: +- return []paramInfo{ +- { +- llvmType: t, +- name: name, +- flags: typeFlags, +- }, +- } ++ return []paramInfo{c.getParamInfo(t, name, goType)} + } + } + +-// getTypeFlags returns the type flags for a given type. It will not recurse +-// into sub-types (such as in structs). +-func getTypeFlags(t types.Type) paramFlags { +- if t == nil { +- return 0 ++// getParamInfo collects information about a parameter. For example, if this ++// parameter is pointer-like, it will also store the element type for the ++// dereferenceable_or_null attribute. ++func (c *compilerContext) getParamInfo(t llvm.Type, name string, goType types.Type) paramInfo { ++ info := paramInfo{ ++ llvmType: t, ++ name: name, + } +- switch t.Underlying().(type) { +- case *types.Pointer: +- // Pointers in Go must either point to an object or be nil. +- return paramIsDeferenceableOrNull +- case *types.Chan, *types.Map: +- // Channels and maps are implemented as pointers pointing to some +- // object, and follow the same rules as *types.Pointer. +- return paramIsDeferenceableOrNull +- default: +- return 0 ++ if goType != nil { ++ switch underlying := goType.Underlying().(type) { ++ case *types.Pointer: ++ // Pointers in Go must either point to an object or be nil. ++ info.elemSize = c.targetData.TypeAllocSize(c.getLLVMType(underlying.Elem())) ++ case *types.Chan: ++ // Channels are implemented simply as a *runtime.channel. ++ info.elemSize = c.targetData.TypeAllocSize(c.getLLVMRuntimeType("channel")) ++ case *types.Map: ++ // Maps are similar to channels: they are implemented as a ++ // *runtime.hashmap. ++ info.elemSize = c.targetData.TypeAllocSize(c.getLLVMRuntimeType("hashmap")) ++ } + } ++ return info + } + + // extractSubfield extracts a field from a struct, or returns null if this is +diff --git a/compiler/compiler.go b/compiler/compiler.go +index 3d29628c..fc47c29c 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -862,7 +862,7 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package + if files, ok := c.embedGlobals[member.Name()]; ok { + c.createEmbedGlobal(member, global, files) + } else if !info.extern { +- global.SetInitializer(llvm.ConstNull(global.Type().ElementType())) ++ global.SetInitializer(llvm.ConstNull(global.GlobalValueType())) + global.SetVisibility(llvm.HiddenVisibility) + if info.section != "" { + global.SetSection(info.section) +@@ -1405,7 +1405,7 @@ func (b *builder) createInstruction(instr ssa.Instruction) { + b.CreateRet(b.getValue(instr.Results[0])) + } else { + // Multiple return values. Put them all in a struct. +- retVal := llvm.ConstNull(b.llvmFn.Type().ElementType().ReturnType()) ++ retVal := llvm.ConstNull(b.llvmFn.GlobalValueType().ReturnType()) + for i, result := range instr.Results { + val := b.getValue(result) + retVal = b.CreateInsertValue(retVal, val, i, "") +@@ -1444,7 +1444,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + elemsBuf := b.CreateExtractValue(elems, 0, "append.elemsBuf") + elemsPtr := b.CreateBitCast(elemsBuf, b.i8ptrType, "append.srcPtr") + elemsLen := b.CreateExtractValue(elems, 1, "append.elemsLen") +- elemType := srcBuf.Type().ElementType() ++ elemType := b.getLLVMType(argTypes[0].Underlying().(*types.Slice).Elem()) + elemSize := llvm.ConstInt(b.uintptrType, b.targetData.TypeAllocSize(elemType), false) + result := b.createRuntimeCall("sliceAppend", []llvm.Value{srcPtr, elemsPtr, srcLen, srcCap, elemsLen, elemSize}, "append.new") + newPtr := b.CreateExtractValue(result, 0, "append.newPtr") +@@ -1497,7 +1497,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + srcLen := b.CreateExtractValue(src, 1, "copy.srcLen") + dstBuf := b.CreateExtractValue(dst, 0, "copy.dstArray") + srcBuf := b.CreateExtractValue(src, 0, "copy.srcArray") +- elemType := dstBuf.Type().ElementType() ++ elemType := b.getLLVMType(argTypes[0].Underlying().(*types.Slice).Elem()) + dstBuf = b.CreateBitCast(dstBuf, b.i8ptrType, "copy.dstPtr") + srcBuf = b.CreateBitCast(srcBuf, b.i8ptrType, "copy.srcPtr") + elemSize := llvm.ConstInt(b.uintptrType, b.targetData.TypeAllocSize(elemType), false) +@@ -1637,7 +1637,8 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + b.uintptrType, + b.uintptrType, + }, false)) +- b.createUnsafeSliceCheck(ptr, len, argTypes[1].Underlying().(*types.Basic)) ++ elementType := b.getLLVMType(argTypes[0].Underlying().(*types.Pointer).Elem()) ++ b.createUnsafeSliceCheck(ptr, len, elementType, argTypes[1].Underlying().(*types.Basic)) + if len.Type().IntTypeWidth() < b.uintptrType.IntTypeWidth() { + // Too small, zero-extend len. + len = b.CreateZExt(len, b.uintptrType, "") +@@ -1712,7 +1713,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) + // Eventually we might be able to eliminate this special case + // entirely. For details, see: + // https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521 +- calleeType = llvm.FunctionType(callee.Type().ElementType().ReturnType(), nil, false) ++ calleeType = llvm.FunctionType(callee.GlobalValueType().ReturnType(), nil, false) + callee = llvm.ConstBitCast(callee, llvm.PointerType(calleeType, b.funcPtrAddrSpace)) + } + case *ssa.MakeClosure: +@@ -3095,7 +3096,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { + } + case token.MUL: // *x, dereference pointer + valueType := b.getLLVMType(unop.X.Type().Underlying().(*types.Pointer).Elem()) +- if b.targetData.TypeAllocSize(x.Type().ElementType()) == 0 { ++ if b.targetData.TypeAllocSize(valueType) == 0 { + // zero-length data + return llvm.ConstNull(valueType), nil + } else if strings.HasSuffix(unop.X.String(), "$funcaddr") { +diff --git a/compiler/func.go b/compiler/func.go +index c6a8802d..4203fdf7 100644 +--- a/compiler/func.go ++++ b/compiler/func.go +@@ -73,7 +73,7 @@ func (c *compilerContext) getFuncType(typ *types.Signature) llvm.Type { + return c.ctx.StructType([]llvm.Type{c.i8ptrType, c.rawVoidFuncType}, false) + } + +-// getRawFuncType returns a LLVM function pointer type for a given signature. ++// getRawFuncType returns a LLVM function type for a given signature. + func (c *compilerContext) getRawFuncType(typ *types.Signature) llvm.Type { + // Get the return type. + var returnType llvm.Type +diff --git a/compiler/interface.go b/compiler/interface.go +index 106c327a..2007b7d7 100644 +--- a/compiler/interface.go ++++ b/compiler/interface.go +@@ -86,7 +86,7 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value { + if _, ok := typ.Underlying().(*types.Pointer); !ok { + ptrTo = c.getTypeCode(types.NewPointer(typ)) + } +- globalValue := llvm.ConstNull(global.Type().ElementType()) ++ globalValue := llvm.ConstNull(global.GlobalValueType()) + if !references.IsNil() { + globalValue = c.builder.CreateInsertValue(globalValue, references, 0, "") + } +@@ -533,7 +533,7 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFnType + + receiverValue := b.emitPointerUnpack(wrapper.Param(0), []llvm.Type{receiverType})[0] + params := append(b.expandFormalParam(receiverValue), wrapper.Params()[1:]...) +- if llvmFn.Type().ElementType().ReturnType().TypeKind() == llvm.VoidTypeKind { ++ if llvmFnType.ReturnType().TypeKind() == llvm.VoidTypeKind { + b.CreateCall(llvmFnType, llvmFn, params, "") + b.CreateRetVoid() + } else { +diff --git a/compiler/ircheck/check.go b/compiler/ircheck/check.go +index 30c6ee17..e2b7ed51 100644 +--- a/compiler/ircheck/check.go ++++ b/compiler/ircheck/check.go +@@ -70,10 +70,7 @@ func (c *checker) checkType(t llvm.Type, checked map[llvm.Type]struct{}, special + return fmt.Errorf("failed to verify element type of array type %s: %s", t.String(), err.Error()) + } + case llvm.PointerTypeKind: +- // check underlying type +- if err := c.checkType(t.ElementType(), checked, specials); err != nil { +- return fmt.Errorf("failed to verify underlying type of pointer type %s: %s", t.String(), err.Error()) +- } ++ // Pointers can't be checked in an opaque pointer world. + case llvm.VectorTypeKind: + // check element type + if err := c.checkType(t.ElementType(), checked, specials); err != nil { +diff --git a/compiler/symbol.go b/compiler/symbol.go +index 83fe050b..01b3fc37 100644 +--- a/compiler/symbol.go ++++ b/compiler/symbol.go +@@ -83,7 +83,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) + // Add an extra parameter as the function context. This context is used in + // closures and bound methods, but should be optimized away when not used. + if !info.exported { +- paramInfos = append(paramInfos, paramInfo{llvmType: c.i8ptrType, name: "context", flags: 0}) ++ paramInfos = append(paramInfos, paramInfo{llvmType: c.i8ptrType, name: "context", elemSize: 0}) + } + + var paramTypes []llvm.Type +@@ -112,17 +112,8 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) + + dereferenceableOrNullKind := llvm.AttributeKindID("dereferenceable_or_null") + for i, info := range paramInfos { +- if info.flags¶mIsDeferenceableOrNull == 0 { +- continue +- } +- if info.llvmType.TypeKind() == llvm.PointerTypeKind { +- el := info.llvmType.ElementType() +- size := c.targetData.TypeAllocSize(el) +- if size == 0 { +- // dereferenceable_or_null(0) appears to be illegal in LLVM. +- continue +- } +- dereferenceableOrNull := c.ctx.CreateEnumAttribute(dereferenceableOrNullKind, size) ++ if info.elemSize != 0 { ++ dereferenceableOrNull := c.ctx.CreateEnumAttribute(dereferenceableOrNullKind, info.elemSize) + llvmFn.AddAttributeAtIndex(i+1, dereferenceableOrNull) + } + } +diff --git a/interp/compiler.go b/interp/compiler.go +index 20723c64..ffef69e5 100644 +--- a/interp/compiler.go ++++ b/interp/compiler.go +@@ -209,7 +209,7 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { + case llvm.Alloca: + // Alloca allocates stack space for local variables. + numElements := r.getValue(inst.llvmInst.Operand(0)).(literalValue).value.(uint32) +- elementSize := r.targetData.TypeAllocSize(inst.llvmInst.Type().ElementType()) ++ elementSize := r.targetData.TypeAllocSize(inst.llvmInst.AllocatedType()) + inst.operands = []value{ + literalValue{elementSize * uint64(numElements)}, + } +@@ -218,17 +218,17 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { + inst.name = llvmInst.Name() + ptr := llvmInst.Operand(0) + n := llvmInst.OperandsCount() +- elementType := ptr.Type().ElementType() ++ elementType := llvmInst.GEPSourceElementType() + // gep: [source ptr, dest value size, pairs of indices...] + inst.operands = []value{ + r.getValue(ptr), +- literalValue{r.targetData.TypeAllocSize(llvmInst.Type().ElementType())}, + r.getValue(llvmInst.Operand(1)), + literalValue{r.targetData.TypeAllocSize(elementType)}, + } + for i := 2; i < n; i++ { + operand := r.getValue(llvmInst.Operand(i)) +- if elementType.TypeKind() == llvm.StructTypeKind { ++ switch elementType.TypeKind() { ++ case llvm.StructTypeKind: + index := operand.(literalValue).value.(uint32) + elementOffset := r.targetData.ElementOffset(elementType, int(index)) + // Encode operands in a special way. The elementOffset +@@ -242,12 +242,15 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { + // runtime. + inst.operands = append(inst.operands, literalValue{elementOffset}, literalValue{^uint64(index)}) + elementType = elementType.StructElementTypes()[index] +- } else { ++ case llvm.ArrayTypeKind: + elementType = elementType.ElementType() + elementSize := r.targetData.TypeAllocSize(elementType) + elementSizeOperand := literalValue{elementSize} + // Add operand * elementSizeOperand bytes to the pointer. + inst.operands = append(inst.operands, operand, elementSizeOperand) ++ default: ++ // This should be unreachable. ++ panic("unknown type: " + elementType.String()) + } + } + case llvm.BitCast, llvm.IntToPtr, llvm.PtrToInt: +@@ -267,10 +270,12 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { + case llvm.StructTypeKind: + offset += r.targetData.ElementOffset(indexingType, int(index)) + indexingType = indexingType.StructElementTypes()[index] +- default: // ArrayTypeKind ++ case llvm.ArrayTypeKind: + indexingType = indexingType.ElementType() + elementSize := r.targetData.TypeAllocSize(indexingType) + offset += elementSize * uint64(index) ++ default: ++ panic("unknown type kind") // unreachable + } + } + size := r.targetData.TypeAllocSize(inst.llvmInst.Type()) +@@ -290,10 +295,12 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { + case llvm.StructTypeKind: + offset += r.targetData.ElementOffset(indexingType, int(index)) + indexingType = indexingType.StructElementTypes()[index] +- default: // ArrayTypeKind ++ case llvm.ArrayTypeKind: + indexingType = indexingType.ElementType() + elementSize := r.targetData.TypeAllocSize(indexingType) + offset += elementSize * uint64(index) ++ default: ++ panic("unknown type kind") // unreachable + } + } + // insertvalue [agg, elt, byteOffset] +diff --git a/interp/interp.go b/interp/interp.go +index 856f08b1..7833dfe9 100644 +--- a/interp/interp.go ++++ b/interp/interp.go +@@ -156,7 +156,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error { + if obj.constant { + continue // constant buffers can't have been modified + } +- initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.Type().ElementType(), &mem) ++ initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.GlobalValueType(), &mem) + if err == errInvalidPtrToIntSize { + // This can happen when a previous interp run did not have the + // correct LLVM type for a global and made something up. In that +@@ -190,7 +190,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error { + if err != nil { + return err + } +- if checks && initializer.Type() != obj.llvmGlobal.Type().ElementType() { ++ if checks && initializer.Type() != obj.llvmGlobal.GlobalValueType() { + panic("initializer type mismatch") + } + obj.llvmGlobal.SetInitializer(initializer) +@@ -213,7 +213,7 @@ func RunFunc(fn llvm.Value, timeout time.Duration, debug bool) error { + r.pkgName = initName[:len(initName)-len(".init")] + + // Create new function with the interp result. +- newFn := llvm.AddFunction(mod, fn.Name()+".tmp", fn.Type().ElementType()) ++ newFn := llvm.AddFunction(mod, fn.Name()+".tmp", fn.GlobalValueType()) + newFn.SetLinkage(fn.Linkage()) + newFn.SetVisibility(fn.Visibility()) + entry := mod.Context().AddBasicBlock(newFn, "entry") +@@ -263,11 +263,11 @@ func RunFunc(fn llvm.Value, timeout time.Duration, debug bool) error { + if obj.constant { + continue // constant, so can't have been modified + } +- initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.Type().ElementType(), &mem) ++ initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.GlobalValueType(), &mem) + if err != nil { + return err + } +- if checks && initializer.Type() != obj.llvmGlobal.Type().ElementType() { ++ if checks && initializer.Type() != obj.llvmGlobal.GlobalValueType() { + panic("initializer type mismatch") + } + obj.llvmGlobal.SetInitializer(initializer) +diff --git a/interp/interpreter.go b/interp/interpreter.go +index 8c783a70..c438b4b6 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -655,7 +655,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + // GetElementPtr does pointer arithmetic, changing the offset of the + // pointer into the underlying object. + var offset uint64 +- for i := 2; i < len(operands); i += 2 { ++ for i := 1; i < len(operands); i += 2 { + index := operands[i].Uint() + elementSize := operands[i+1].Uint() + if int64(elementSize) < 0 { +diff --git a/interp/memory.go b/interp/memory.go +index 6a537bad..82ab716d 100644 +--- a/interp/memory.go ++++ b/interp/memory.go +@@ -808,14 +808,17 @@ func (v rawValue) rawLLVMValue(mem *memoryView) (llvm.Value, error) { + if err != nil { + return llvm.Value{}, err + } +- elementType := field.Type().ElementType() +- if elementType.TypeKind() == llvm.StructTypeKind { +- // There are some special pointer types that should be used as a +- // ptrtoint, so that they can be used in certain optimizations. +- name := elementType.StructName() +- if name == "runtime.typecodeID" || name == "runtime.funcValueWithSignature" { +- uintptrType := ctx.IntType(int(mem.r.pointerSize) * 8) +- field = llvm.ConstPtrToInt(field, uintptrType) ++ if !field.IsAGlobalVariable().IsNil() { ++ elementType := field.GlobalValueType() ++ if elementType.TypeKind() == llvm.StructTypeKind { ++ // There are some special pointer types that should be used ++ // as a ptrtoint, so that they can be used in certain ++ // optimizations. ++ name := elementType.StructName() ++ if name == "runtime.typecodeID" || name == "runtime.funcValueWithSignature" { ++ uintptrType := ctx.IntType(int(mem.r.pointerSize) * 8) ++ field = llvm.ConstPtrToInt(field, uintptrType) ++ } + } + } + structFields = append(structFields, field) +@@ -998,7 +1001,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { + ptr := llvmValue.Operand(0) + index := llvmValue.Operand(1) + numOperands := llvmValue.OperandsCount() +- elementType := ptr.Type().ElementType() ++ elementType := llvmValue.GEPSourceElementType() + totalOffset := r.targetData.TypeAllocSize(elementType) * index.ZExtValue() + for i := 2; i < numOperands; i++ { + indexValue := llvmValue.Operand(i) +@@ -1173,7 +1176,7 @@ func (r *runner) getValue(llvmValue llvm.Value) value { + r.globals[llvmValue] = index + r.objects = append(r.objects, obj) + if !llvmValue.IsAGlobalVariable().IsNil() { +- obj.size = uint32(r.targetData.TypeAllocSize(llvmValue.Type().ElementType())) ++ obj.size = uint32(r.targetData.TypeAllocSize(llvmValue.GlobalValueType())) + if initializer := llvmValue.Initializer(); !initializer.IsNil() { + obj.buffer = r.getValue(initializer) + obj.constant = llvmValue.IsGlobalConstant() +diff --git a/transform/allocs.go b/transform/allocs.go +index af7c70b2..5be7df2d 100644 +--- a/transform/allocs.go ++++ b/transform/allocs.go +@@ -124,7 +124,7 @@ func OptimizeAllocs(mod llvm.Module, printAllocs *regexp.Regexp, logger func(tok + alloca.SetAlignment(alignment) + + // Zero the allocation inside the block where the value was originally allocated. +- zero := llvm.ConstNull(alloca.Type().ElementType()) ++ zero := llvm.ConstNull(alloca.AllocatedType()) + builder.SetInsertPointBefore(bitcast) + store := builder.CreateStore(zero, alloca) + store.SetAlignment(alignment) +diff --git a/transform/gc.go b/transform/gc.go +index 514fb1bf..e2d23987 100644 +--- a/transform/gc.go ++++ b/transform/gc.go +@@ -18,7 +18,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + stackChainStart := mod.NamedGlobal("runtime.stackChainStart") + if !stackChainStart.IsNil() { + stackChainStart.SetLinkage(llvm.InternalLinkage) +- stackChainStart.SetInitializer(llvm.ConstNull(stackChainStart.Type().ElementType())) ++ stackChainStart.SetInitializer(llvm.ConstNull(stackChainStart.GlobalValueType())) + stackChainStart.SetGlobalConstant(true) + } + return false +@@ -96,7 +96,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { + return false + } + stackChainStart.SetLinkage(llvm.InternalLinkage) +- stackChainStartType := stackChainStart.Type().ElementType() ++ stackChainStartType := stackChainStart.GlobalValueType() + stackChainStart.SetInitializer(llvm.ConstNull(stackChainStartType)) + + // Iterate until runtime.trackPointer has no uses left. +diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go +index f28443dc..9e2ffa90 100644 +--- a/transform/interface-lowering.go ++++ b/transform/interface-lowering.go +@@ -423,7 +423,7 @@ func (p *lowerInterfacesPass) defineInterfaceImplementsFunc(fn llvm.Value, itf * + func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *interfaceInfo, signature *signatureInfo) { + context := fn.LastParam() + actualType := llvm.PrevParam(context) +- returnType := fn.Type().ElementType().ReturnType() ++ returnType := fn.GlobalValueType().ReturnType() + context.SetName("context") + actualType.SetName("actualType") + fn.SetLinkage(llvm.InternalLinkage) +diff --git a/transform/llvm.go b/transform/llvm.go +index 17968f8a..7042b32d 100644 +--- a/transform/llvm.go ++++ b/transform/llvm.go +@@ -66,7 +66,7 @@ func getGlobalBytes(global llvm.Value, builder llvm.Builder) []byte { + // function used for creating reflection sidetables, for example. + func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) llvm.Value { + oldGlobal := mod.NamedGlobal(name) +- globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.Type().ElementType()) ++ globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.GlobalValueType()) + gep := llvm.ConstGEP(globalType, global, []llvm.Value{ + llvm.ConstInt(mod.Context().Int32Type(), 0, false), + llvm.ConstInt(mod.Context().Int32Type(), 0, false), +diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go +index 064e38f4..83a16d85 100644 +--- a/transform/wasm-abi.go ++++ b/transform/wasm-abi.go +@@ -50,7 +50,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { + paramTypes := []llvm.Type{} + + // Check return type for 64-bit integer. +- fnType := fn.Type().ElementType() ++ fnType := fn.GlobalValueType() + returnType := fnType.ReturnType() + if returnType == int64Type { + hasInt64 = true +-- +2.36.1 + diff --git a/0015-transform-fix-memory-corruption-issues.patch b/0015-transform-fix-memory-corruption-issues.patch new file mode 100644 index 0000000..d209b69 --- /dev/null +++ b/0015-transform-fix-memory-corruption-issues.patch @@ -0,0 +1,31 @@ +From 6bf7aa1623b6d7d9a269df876453af22b1c54c2d Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Wed, 12 Oct 2022 21:46:50 +0200 +Subject: [PATCH 15/18] transform: fix memory corruption issues + +There was a bug in the wasm ABI lowering pass (found using +AddressSanitizer on LLVM 15) that resulted in a rather subtle memory +corruption. This commit fixes this issues. + +Signed-off-by: Elliott Sales de Andrade +--- + transform/wasm-abi.go | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go +index 83a16d85..08122a3e 100644 +--- a/transform/wasm-abi.go ++++ b/transform/wasm-abi.go +@@ -88,8 +88,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { + // Update all users to call the external function. + // The old $i64wrapper function could be removed, but it may as well + // be left in place. +- for use := fn.FirstUse(); !use.IsNil(); use = use.NextUse() { +- call := use.User() ++ for _, call := range getUses(fn) { + entryBlockBuilder.SetInsertPointBefore(call.InstructionParent().Parent().EntryBasicBlock().FirstInstruction()) + builder.SetInsertPointBefore(call) + callParams := []llvm.Value{} +-- +2.36.1 + diff --git a/0016-riscv-add-target-abi-metadata-flag.patch b/0016-riscv-add-target-abi-metadata-flag.patch new file mode 100644 index 0000000..e194223 --- /dev/null +++ b/0016-riscv-add-target-abi-metadata-flag.patch @@ -0,0 +1,193 @@ +From 003963ddc796960ce498361409a9d121366b1c42 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Wed, 12 Oct 2022 22:05:38 +0000 +Subject: [PATCH 16/18] riscv: add "target-abi" metadata flag + +This flag is necessary in LLVM 15 because it appears that LLVM 15 has +changed the default target ABI from lp64 to lp64d. This results in a +linker failure. Setting the "target-abi" forces the RISC-V backend to +use the intended target ABI. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/build.go | 1 + + builder/library.go | 7 +++++-- + compileopts/config.go | 13 +++++++++++++ + compileopts/target.go | 1 + + compiler/compiler.go | 13 +++++++++++++ + compiler/compiler_test.go | 1 + + targets/riscv32.json | 4 ++-- + targets/riscv64.json | 4 ++-- + 8 files changed, 38 insertions(+), 6 deletions(-) + +diff --git a/builder/build.go b/builder/build.go +index 488ee823..4818185f 100644 +--- a/builder/build.go ++++ b/builder/build.go +@@ -170,6 +170,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil + Triple: config.Triple(), + CPU: config.CPU(), + Features: config.Features(), ++ ABI: config.ABI(), + GOOS: config.GOOS(), + GOARCH: config.GOARCH(), + CodeModel: config.CodeModel(), +diff --git a/builder/library.go b/builder/library.go +index 385f1610..87822d15 100644 +--- a/builder/library.go ++++ b/builder/library.go +@@ -155,6 +155,9 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ + args = append(args, "-mcpu="+cpu) + } + } ++ if config.ABI() != "" { ++ args = append(args, "-mabi="+config.ABI()) ++ } + if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { + if strings.Split(target, "-")[2] == "linux" { + args = append(args, "-fno-unwind-tables", "-fno-asynchronous-unwind-tables") +@@ -170,10 +173,10 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ + args = append(args, "-mdouble=64") + } + if strings.HasPrefix(target, "riscv32-") { +- args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128") ++ args = append(args, "-march=rv32imac", "-fforce-enable-int128") + } + if strings.HasPrefix(target, "riscv64-") { +- args = append(args, "-march=rv64gc", "-mabi=lp64") ++ args = append(args, "-march=rv64gc") + } + if strings.HasPrefix(target, "xtensa") { + // Hack to work around an issue in the Xtensa port: +diff --git a/compileopts/config.go b/compileopts/config.go +index cd49283d..80ea8cff 100644 +--- a/compileopts/config.go ++++ b/compileopts/config.go +@@ -47,6 +47,12 @@ func (c *Config) Features() string { + return c.Target.Features + "," + c.Options.LLVMFeatures + } + ++// ABI returns the -mabi= flag for this target (like -mabi=lp64). A zero-length ++// string is returned if the target doesn't specify an ABI. ++func (c *Config) ABI() string { ++ return c.Target.ABI ++} ++ + // GOOS returns the GOOS of the target. This might not always be the actual OS: + // for example, bare-metal targets will usually pretend to be linux to get the + // standard library to compile. +@@ -230,6 +236,9 @@ func (c *Config) LibcPath(name string) (path string, precompiled bool) { + if c.CPU() != "" { + archname += "-" + c.CPU() + } ++ if c.ABI() != "" { ++ archname += "-" + c.ABI() ++ } + + // Try to load a precompiled library. + precompiledDir := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", archname, name) +@@ -335,6 +344,10 @@ func (c *Config) CFlags() []string { + cflags = append(cflags, "-mcpu="+c.Target.CPU) + } + } ++ // Set the -mabi flag, if needed. ++ if c.ABI() != "" { ++ cflags = append(cflags, "-mabi="+c.ABI()) ++ } + return cflags + } + +diff --git a/compileopts/target.go b/compileopts/target.go +index 865b8afe..c26c870e 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -26,6 +26,7 @@ type TargetSpec struct { + Inherits []string `json:"inherits"` + Triple string `json:"llvm-target"` + CPU string `json:"cpu"` ++ ABI string `json:"target-abi"` // rougly equivalent to -mabi= flag + Features string `json:"features"` + GOOS string `json:"goos"` + GOARCH string `json:"goarch"` +diff --git a/compiler/compiler.go b/compiler/compiler.go +index fc47c29c..8b6e8661 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -41,6 +41,7 @@ type Config struct { + Triple string + CPU string + Features string ++ ABI string + GOOS string + GOARCH string + CodeModel string +@@ -321,6 +322,18 @@ func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, + c.dibuilder.Destroy() + } + ++ // Add the "target-abi" flag, which is necessary on RISC-V otherwise it will ++ // pick one that doesn't match the -mabi Clang flag. ++ if c.ABI != "" { ++ c.mod.AddNamedMetadataOperand("llvm.module.flags", ++ c.ctx.MDNode([]llvm.Metadata{ ++ llvm.ConstInt(c.ctx.Int32Type(), 1, false).ConstantAsMetadata(), // Error on mismatch ++ c.ctx.MDString("target-abi"), ++ c.ctx.MDString(c.ABI), ++ }), ++ ) ++ } ++ + return c.mod, c.diagnostics + } + +diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go +index 2ed26921..a5cd9c6b 100644 +--- a/compiler/compiler_test.go ++++ b/compiler/compiler_test.go +@@ -73,6 +73,7 @@ func TestCompiler(t *testing.T) { + compilerConfig := &Config{ + Triple: config.Triple(), + Features: config.Features(), ++ ABI: config.ABI(), + GOOS: config.GOOS(), + GOARCH: config.GOARCH(), + CodeModel: config.CodeModel(), +diff --git a/targets/riscv32.json b/targets/riscv32.json +index c3c8dff5..a2878089 100644 +--- a/targets/riscv32.json ++++ b/targets/riscv32.json +@@ -1,12 +1,12 @@ + { + "inherits": ["riscv"], + "llvm-target": "riscv32-unknown-none", ++ "target-abi": "ilp32", + "build-tags": ["tinygo.riscv32"], + "scheduler": "tasks", + "default-stack-size": 2048, + "cflags": [ +- "-march=rv32imac", +- "-mabi=ilp32" ++ "-march=rv32imac" + ], + "ldflags": [ + "-melf32lriscv" +diff --git a/targets/riscv64.json b/targets/riscv64.json +index c2378e97..fc45c91c 100644 +--- a/targets/riscv64.json ++++ b/targets/riscv64.json +@@ -1,10 +1,10 @@ + { + "inherits": ["riscv"], + "llvm-target": "riscv64-unknown-none", ++ "target-abi": "lp64", + "build-tags": ["tinygo.riscv64"], + "cflags": [ +- "-march=rv64gc", +- "-mabi=lp64" ++ "-march=rv64gc" + ], + "ldflags": [ + "-melf64lriscv" +-- +2.36.1 + diff --git a/0017-interp-add-support-for-constant-icmp-instructions.patch b/0017-interp-add-support-for-constant-icmp-instructions.patch new file mode 100644 index 0000000..500803c --- /dev/null +++ b/0017-interp-add-support-for-constant-icmp-instructions.patch @@ -0,0 +1,195 @@ +From 76f42a3fac44ac6d07c53b10ddadb683ca019684 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Tue, 18 Oct 2022 23:16:36 +0000 +Subject: [PATCH 17/18] interp: add support for constant icmp instructions + +These instructions sometimes pop up in LLVM 15, but they never occured +in LLVM 14. Implementing them is relatively straightforward: simply +generalize the code that already exists for llvm.ICmp interpreting. + +Signed-off-by: Elliott Sales de Andrade +--- + interp/interpreter.go | 84 +++++++++++++++++--------------- + interp/memory.go | 11 +++++ + interp/testdata/consteval.ll | 15 ++++++ + interp/testdata/consteval.out.ll | 1 + + 4 files changed, 73 insertions(+), 38 deletions(-) + +diff --git a/interp/interpreter.go b/interp/interpreter.go +index c438b4b6..83fd2cd9 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -723,46 +723,9 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + locals[inst.localIndex] = newagg + case llvm.ICmp: + predicate := llvm.IntPredicate(operands[2].(literalValue).value.(uint8)) +- var result bool + lhs := operands[0] + rhs := operands[1] +- switch predicate { +- case llvm.IntEQ, llvm.IntNE: +- lhsPointer, lhsErr := lhs.asPointer(r) +- rhsPointer, rhsErr := rhs.asPointer(r) +- if (lhsErr == nil) != (rhsErr == nil) { +- // Fast path: only one is a pointer, so they can't be equal. +- result = false +- } else if lhsErr == nil { +- // Both must be nil, so both are pointers. +- // Compare them directly. +- result = lhsPointer.equal(rhsPointer) +- } else { +- // Fall back to generic comparison. +- result = lhs.asRawValue(r).equal(rhs.asRawValue(r)) +- } +- if predicate == llvm.IntNE { +- result = !result +- } +- case llvm.IntUGT: +- result = lhs.Uint() > rhs.Uint() +- case llvm.IntUGE: +- result = lhs.Uint() >= rhs.Uint() +- case llvm.IntULT: +- result = lhs.Uint() < rhs.Uint() +- case llvm.IntULE: +- result = lhs.Uint() <= rhs.Uint() +- case llvm.IntSGT: +- result = lhs.Int() > rhs.Int() +- case llvm.IntSGE: +- result = lhs.Int() >= rhs.Int() +- case llvm.IntSLT: +- result = lhs.Int() < rhs.Int() +- case llvm.IntSLE: +- result = lhs.Int() <= rhs.Int() +- default: +- return nil, mem, r.errorAt(inst, errors.New("interp: unsupported icmp")) +- } ++ result := r.interpretICmp(lhs, rhs, predicate) + if result { + locals[inst.localIndex] = literalValue{uint8(1)} + } else { +@@ -948,6 +911,51 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + return nil, mem, r.errorAt(bb.instructions[len(bb.instructions)-1], errors.New("interp: reached end of basic block without terminator")) + } + ++// Interpret an icmp instruction. Doesn't have side effects, only returns the ++// output of the comparison. ++func (r *runner) interpretICmp(lhs, rhs value, predicate llvm.IntPredicate) bool { ++ switch predicate { ++ case llvm.IntEQ, llvm.IntNE: ++ var result bool ++ lhsPointer, lhsErr := lhs.asPointer(r) ++ rhsPointer, rhsErr := rhs.asPointer(r) ++ if (lhsErr == nil) != (rhsErr == nil) { ++ // Fast path: only one is a pointer, so they can't be equal. ++ result = false ++ } else if lhsErr == nil { ++ // Both must be nil, so both are pointers. ++ // Compare them directly. ++ result = lhsPointer.equal(rhsPointer) ++ } else { ++ // Fall back to generic comparison. ++ result = lhs.asRawValue(r).equal(rhs.asRawValue(r)) ++ } ++ if predicate == llvm.IntNE { ++ result = !result ++ } ++ return result ++ case llvm.IntUGT: ++ return lhs.Uint() > rhs.Uint() ++ case llvm.IntUGE: ++ return lhs.Uint() >= rhs.Uint() ++ case llvm.IntULT: ++ return lhs.Uint() < rhs.Uint() ++ case llvm.IntULE: ++ return lhs.Uint() <= rhs.Uint() ++ case llvm.IntSGT: ++ return lhs.Int() > rhs.Int() ++ case llvm.IntSGE: ++ return lhs.Int() >= rhs.Int() ++ case llvm.IntSLT: ++ return lhs.Int() < rhs.Int() ++ case llvm.IntSLE: ++ return lhs.Int() <= rhs.Int() ++ default: ++ // _should_ be unreachable, until LLVM adds new icmp operands (unlikely) ++ panic("interp: unsupported icmp") ++ } ++} ++ + func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, mem *memoryView, indent string) *Error { + numOperands := inst.llvmInst.OperandsCount() + operands := make([]llvm.Value, numOperands) +diff --git a/interp/memory.go b/interp/memory.go +index 82ab716d..248825f6 100644 +--- a/interp/memory.go ++++ b/interp/memory.go +@@ -1031,6 +1031,17 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { + for i := uint32(0); i < ptrSize; i++ { + v.buf[i] = ptrValue.pointer + } ++ case llvm.ICmp: ++ size := r.targetData.TypeAllocSize(llvmValue.Operand(0).Type()) ++ lhs := newRawValue(uint32(size)) ++ rhs := newRawValue(uint32(size)) ++ lhs.set(llvmValue.Operand(0), r) ++ rhs.set(llvmValue.Operand(1), r) ++ if r.interpretICmp(lhs, rhs, llvmValue.IntPredicate()) { ++ v.buf[0] = 1 // result is true ++ } else { ++ v.buf[0] = 0 // result is false ++ } + default: + llvmValue.Dump() + println() +diff --git a/interp/testdata/consteval.ll b/interp/testdata/consteval.ll +index 9afb9ff7..d0c0e3b6 100644 +--- a/interp/testdata/consteval.ll ++++ b/interp/testdata/consteval.ll +@@ -3,6 +3,7 @@ target triple = "x86_64--linux" + + @intToPtrResult = global i8 0 + @ptrToIntResult = global i8 0 ++@icmpResult = global i8 0 + @someArray = internal global {i16, i8, i8} zeroinitializer + @someArrayPointer = global i8* zeroinitializer + +@@ -15,6 +16,7 @@ define internal void @main.init() { + call void @testIntToPtr() + call void @testPtrToInt() + call void @testConstGEP() ++ call void @testICmp() + ret void + } + +@@ -48,3 +50,16 @@ define internal void @testConstGEP() { + store i8* getelementptr inbounds (i8, i8* bitcast ({i16, i8, i8}* @someArray to i8*), i32 2), i8** @someArrayPointer + ret void + } ++ ++define internal void @testICmp() { ++ br i1 icmp eq (i64 ptrtoint (i8* @ptrToIntResult to i64), i64 0), label %equal, label %unequal ++equal: ++ ; should not be reached ++ store i8 1, i8* @icmpResult ++ ret void ++unequal: ++ ; should be reached ++ store i8 2, i8* @icmpResult ++ ret void ++ ret void ++} +diff --git a/interp/testdata/consteval.out.ll b/interp/testdata/consteval.out.ll +index 5fac449e..08d74c85 100644 +--- a/interp/testdata/consteval.out.ll ++++ b/interp/testdata/consteval.out.ll +@@ -3,6 +3,7 @@ target triple = "x86_64--linux" + + @intToPtrResult = local_unnamed_addr global i8 2 + @ptrToIntResult = local_unnamed_addr global i8 2 ++@icmpResult = local_unnamed_addr global i8 2 + @someArray = internal global { i16, i8, i8 } zeroinitializer + @someArrayPointer = local_unnamed_addr global i8* getelementptr inbounds ({ i16, i8, i8 }, { i16, i8, i8 }* @someArray, i64 0, i32 1) + +-- +2.36.1 + diff --git a/0018-ci-add-support-for-LLVM-15.patch b/0018-ci-add-support-for-LLVM-15.patch new file mode 100644 index 0000000..7c17787 --- /dev/null +++ b/0018-ci-add-support-for-LLVM-15.patch @@ -0,0 +1,3490 @@ +From 6557b534a1c2195cb7f2a465f8dc36662525f764 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 22 Sep 2022 13:39:51 +0200 +Subject: [PATCH 18/18] ci: add support for LLVM 15 + +This commit switches to LLVM 15 everywhere by default, while still +keeping LLVM 14 support. + +Signed-off-by: Elliott Sales de Andrade +--- + .github/workflows/build-macos.yml | 6 +- + .github/workflows/linux.yml | 16 +- + .github/workflows/windows.yml | 4 +- + Makefile | 6 +- + builder/cc1as.cpp | 21 +- + builder/cc1as.h | 7 + + builder/musl.go | 10 +- + cgo/libclang_config_llvm14.go | 4 +- + cgo/libclang_config_llvm15.go | 16 ++ + compiler/func.go | 15 +- + compiler/intrinsics.go | 11 +- + compiler/llvmutil/llvm.go | 33 ++- + compiler/symbol.go | 11 +- + compiler/testdata/basic.go | 12 +- + compiler/testdata/basic.ll | 69 +++-- + compiler/testdata/channel.ll | 110 +++----- + compiler/testdata/defer-cortex-m-qemu.ll | 267 +++++++++--------- + compiler/testdata/float.ll | 22 +- + compiler/testdata/func.ll | 23 +- + compiler/testdata/gc.ll | 176 ++++++------ + .../testdata/goroutine-cortex-m-qemu-tasks.ll | 189 ++++++------- + compiler/testdata/goroutine-wasm-asyncify.ll | 206 ++++++-------- + compiler/testdata/interface.ll | 83 +++--- + compiler/testdata/pointer.ll | 68 +++-- + compiler/testdata/pragma.ll | 18 +- + compiler/testdata/slice.ll | 264 ++++++++--------- + compiler/testdata/string.ll | 50 ++-- + go.mod | 2 +- + go.sum | 4 +- + interp/interpreter.go | 16 +- + src/runtime/runtime.go | 6 +- + targets/esp32c3.json | 2 +- + targets/fe310.json | 2 +- + targets/k210.json | 2 +- + targets/riscv-qemu.json | 2 +- + transform/interface-lowering.go | 4 +- + transform/interrupt.go | 3 +- + transform/llvm.go | 6 + + transform/reflect.go | 11 +- + transform/rtcalls.go | 5 +- + 40 files changed, 898 insertions(+), 884 deletions(-) + create mode 100644 cgo/libclang_config_llvm15.go + +diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml +index 2059574a..9197ea3c 100644 +--- a/.github/workflows/build-macos.yml ++++ b/.github/workflows/build-macos.yml +@@ -40,7 +40,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-source + with: +- key: llvm-source-14-macos-v1 ++ key: llvm-source-15-macos-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -54,7 +54,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-build + with: +- key: llvm-build-14-macos-v1 ++ key: llvm-build-15-macos-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +@@ -108,7 +108,7 @@ jobs: + - name: Install LLVM + shell: bash + run: | +- HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@14 ++ HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@15 + - name: Checkout + uses: actions/checkout@v2 + - name: Install Go +diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml +index 8fc52717..cf26a4f2 100644 +--- a/.github/workflows/linux.yml ++++ b/.github/workflows/linux.yml +@@ -43,7 +43,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-source + with: +- key: llvm-source-14-linux-alpine-v1 ++ key: llvm-source-15-linux-alpine-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -57,7 +57,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-build + with: +- key: llvm-build-14-linux-alpine-v1 ++ key: llvm-build-15-linux-alpine-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +@@ -185,7 +185,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-source + with: +- key: llvm-source-14-linux-asserts-v2 ++ key: llvm-source-15-linux-asserts-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -199,7 +199,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-build + with: +- key: llvm-build-14-linux-asserts-v1 ++ key: llvm-build-15-linux-asserts-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +@@ -277,7 +277,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-source + with: +- key: llvm-source-14-linux-v2 ++ key: llvm-source-15-linux-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -291,7 +291,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-build + with: +- key: llvm-build-14-linux-arm-v1 ++ key: llvm-build-15-linux-arm-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +@@ -377,7 +377,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-source + with: +- key: llvm-source-14-linux-v1 ++ key: llvm-source-15-linux-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -391,7 +391,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-build + with: +- key: llvm-build-14-linux-arm64-v1 ++ key: llvm-build-15-linux-arm64-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml +index 76c010cf..2ea1dc8c 100644 +--- a/.github/workflows/windows.yml ++++ b/.github/workflows/windows.yml +@@ -35,7 +35,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-source + with: +- key: llvm-source-14-windows-v2 ++ key: llvm-source-15-windows-v1 + path: | + llvm-project/clang/lib/Headers + llvm-project/clang/include +@@ -49,7 +49,7 @@ jobs: + uses: actions/cache@v3 + id: cache-llvm-build + with: +- key: llvm-build-14-windows-v2 ++ key: llvm-build-15-windows-v1 + path: llvm-build + - name: Build LLVM + if: steps.cache-llvm-build.outputs.cache-hit != 'true' +diff --git a/Makefile b/Makefile +index 1ef11d29..89927961 100644 +--- a/Makefile ++++ b/Makefile +@@ -107,7 +107,7 @@ endif + + .PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp + +-LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsmanifest ++LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest + + ifeq ($(OS),Windows_NT) + EXE = .exe +@@ -142,7 +142,7 @@ else + endif + + # Libraries that should be linked in for the statically linked Clang. +-CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions ++CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions + CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++ + + # Libraries that should be linked in for the statically linked LLD. +@@ -230,7 +230,7 @@ gen-device-rp: build/gen-device-svd + + # Get LLVM sources. + $(LLVM_PROJECTDIR)/llvm: +- git clone -b xtensa_release_14.0.0-patched --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) ++ git clone -b xtensa_release_15.x --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR) + llvm-source: $(LLVM_PROJECTDIR)/llvm + + # Configure LLVM. +diff --git a/builder/cc1as.cpp b/builder/cc1as.cpp +index 11500121..cd3229ad 100644 +--- a/builder/cc1as.cpp ++++ b/builder/cc1as.cpp +@@ -101,6 +101,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, + + // Target Options + Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); ++ if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple)) ++ Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue()); ++ + Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu)); + Opts.Features = Args.getAllArgValues(OPT_target_feature); + +@@ -203,6 +206,14 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, + .Default(0); + } + ++ if (auto *A = Args.getLastArg(OPT_femit_dwarf_unwind_EQ)) { ++ Opts.EmitDwarfUnwind = ++ llvm::StringSwitch(A->getValue()) ++ .Case("always", EmitDwarfUnwindType::Always) ++ .Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind) ++ .Case("default", EmitDwarfUnwindType::Default); ++ } ++ + return Success; + } + +@@ -253,6 +264,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, + assert(MRI && "Unable to create target register info!"); + + MCTargetOptions MCOptions; ++ MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; ++ + std::unique_ptr MAI( + TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions)); + assert(MAI && "Unable to create target asm info!"); +@@ -299,6 +312,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, + // MCObjectFileInfo needs a MCContext reference in order to initialize itself. + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, PIC)); ++ if (Opts.DarwinTargetVariantTriple) ++ MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple); + Ctx.setObjectFileInfo(MOFI.get()); + + if (Opts.SaveTemporaryLabels) +@@ -347,7 +362,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, + + std::unique_ptr CE; + if (Opts.ShowEncoding) +- CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); ++ CE.reset(TheTarget->createMCCodeEmitter(*MCII, Ctx)); + std::unique_ptr MAB( + TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); + +@@ -367,7 +382,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, + } + + std::unique_ptr CE( +- TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); ++ TheTarget->createMCCodeEmitter(*MCII, Ctx)); + std::unique_ptr MAB( + TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); + assert(MAB && "Unable to create asm backend!"); +@@ -389,7 +404,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, + if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) { + MCSection *AsmLabel = Ctx.getMachOSection( + "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); +- Str.get()->SwitchSection(AsmLabel); ++ Str.get()->switchSection(AsmLabel); + Str.get()->emitZeros(1); + } + +diff --git a/builder/cc1as.h b/builder/cc1as.h +index 538e9a26..150d6f14 100644 +--- a/builder/cc1as.h ++++ b/builder/cc1as.h +@@ -85,6 +85,9 @@ struct AssemblerInvocation { + unsigned IncrementalLinkerCompatible : 1; + unsigned EmbedBitcode : 1; + ++ /// Whether to emit DWARF unwind info. ++ EmitDwarfUnwindType EmitDwarfUnwind; ++ + /// The name of the relocation model to use. + std::string RelocationModel; + +@@ -92,6 +95,9 @@ struct AssemblerInvocation { + /// otherwise. + std::string TargetABI; + ++ /// Darwin target variant triple, the variant of the deployment target ++ /// for which the code is being compiled. ++ llvm::Optional DarwinTargetVariantTriple; + /// @} + + public: +@@ -112,6 +118,7 @@ public: + Dwarf64 = 0; + DwarfVersion = 0; + EmbedBitcode = 0; ++ EmitDwarfUnwind = EmitDwarfUnwindType::Default; + } + + static bool CreateFromArgs(AssemblerInvocation &Res, +diff --git a/builder/musl.go b/builder/musl.go +index a1967e37..c266898d 100644 +--- a/builder/musl.go ++++ b/builder/musl.go +@@ -6,10 +6,12 @@ import ( + "os" + "path/filepath" + "regexp" ++ "strconv" + "strings" + + "github.com/tinygo-org/tinygo/compileopts" + "github.com/tinygo-org/tinygo/goenv" ++ "tinygo.org/x/go-llvm" + ) + + var Musl = Library{ +@@ -77,7 +79,7 @@ var Musl = Library{ + cflags: func(target, headerPath string) []string { + arch := compileopts.MuslArchitecture(target) + muslDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl") +- return []string{ ++ cflags := []string{ + "-std=c99", // same as in musl + "-D_XOPEN_SOURCE=700", // same as in musl + // Musl triggers some warnings and we don't want to show any +@@ -103,6 +105,12 @@ var Musl = Library{ + "-I" + muslDir + "/include", + "-fno-stack-protector", + } ++ llvmMajor, _ := strconv.Atoi(strings.SplitN(llvm.Version, ".", 2)[0]) ++ if llvmMajor >= 15 { ++ // This flag was added in Clang 15. It is not present in LLVM 14. ++ cflags = append(cflags, "-Wno-deprecated-non-prototype") ++ } ++ return cflags + }, + sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl/src") }, + librarySources: func(target string) []string { +diff --git a/cgo/libclang_config_llvm14.go b/cgo/libclang_config_llvm14.go +index 0553bd50..953ce8e2 100644 +--- a/cgo/libclang_config_llvm14.go ++++ b/cgo/libclang_config_llvm14.go +@@ -1,5 +1,5 @@ +-//go:build !byollvm +-// +build !byollvm ++//go:build !byollvm && llvm14 ++// +build !byollvm,llvm14 + + package cgo + +diff --git a/cgo/libclang_config_llvm15.go b/cgo/libclang_config_llvm15.go +new file mode 100644 +index 00000000..e918a473 +--- /dev/null ++++ b/cgo/libclang_config_llvm15.go +@@ -0,0 +1,16 @@ ++//go:build !byollvm && !llvm14 ++// +build !byollvm,!llvm14 ++ ++package cgo ++ ++/* ++#cgo linux CFLAGS: -I/usr/lib/llvm-15/include ++#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@15/include ++#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@15/include ++#cgo freebsd CFLAGS: -I/usr/local/llvm15/include ++#cgo linux LDFLAGS: -L/usr/lib/llvm-15/lib -lclang ++#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -lclang -lffi ++#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -lclang -lffi ++#cgo freebsd LDFLAGS: -L/usr/local/llvm15/lib -lclang ++*/ ++import "C" +diff --git a/compiler/func.go b/compiler/func.go +index 4203fdf7..404c7316 100644 +--- a/compiler/func.go ++++ b/compiler/func.go +@@ -57,14 +57,15 @@ func (b *builder) extractFuncContext(funcValue llvm.Value) llvm.Value { + // value. This may be an expensive operation. + func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcType llvm.Type, funcPtr, context llvm.Value) { + context = b.CreateExtractValue(funcValue, 0, "") +- bitcast := b.CreateExtractValue(funcValue, 1, "") +- if !bitcast.IsAConstantExpr().IsNil() && bitcast.Opcode() == llvm.BitCast { +- funcPtr = bitcast.Operand(0) +- return ++ funcPtr = b.CreateExtractValue(funcValue, 1, "") ++ if !funcPtr.IsAConstantExpr().IsNil() && funcPtr.Opcode() == llvm.BitCast { ++ funcPtr = funcPtr.Operand(0) // needed for LLVM 14 (no opaque pointers) ++ } ++ if sig != nil { ++ funcType = b.getRawFuncType(sig) ++ llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace) ++ funcPtr = b.CreateBitCast(funcPtr, llvmSig, "") + } +- funcType = b.getRawFuncType(sig) +- llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace) +- funcPtr = b.CreateBitCast(bitcast, llvmSig, "") + return + } + +diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go +index 9fedfbd6..a511e518 100644 +--- a/compiler/intrinsics.go ++++ b/compiler/intrinsics.go +@@ -7,6 +7,7 @@ import ( + "strconv" + "strings" + ++ "github.com/tinygo-org/tinygo/compiler/llvmutil" + "tinygo.org/x/go-llvm" + ) + +@@ -44,7 +45,10 @@ func (b *builder) defineIntrinsicFunction() { + // and will otherwise be lowered to regular libc memcpy/memmove calls. + func (b *builder) createMemoryCopyImpl() { + b.createFunctionStart(true) +- fnName := "llvm." + b.fn.Name() + ".p0i8.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) ++ fnName := "llvm." + b.fn.Name() + ".p0.p0.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) ++ if llvmutil.Major() < 15 { // compatibility with LLVM 14 ++ fnName = "llvm." + b.fn.Name() + ".p0i8.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) ++ } + llvmFn := b.mod.NamedFunction(fnName) + if llvmFn.IsNil() { + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.i8ptrType, b.i8ptrType, b.uintptrType, b.ctx.Int1Type()}, false) +@@ -64,7 +68,10 @@ func (b *builder) createMemoryCopyImpl() { + // regular libc memset calls if they aren't optimized out in a different way. + func (b *builder) createMemoryZeroImpl() { + b.createFunctionStart(true) +- fnName := "llvm.memset.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) ++ fnName := "llvm.memset.p0.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) ++ if llvmutil.Major() < 15 { // compatibility with LLVM 14 ++ fnName = "llvm.memset.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) ++ } + llvmFn := b.mod.NamedFunction(fnName) + if llvmFn.IsNil() { + fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.i8ptrType, b.ctx.Int8Type(), b.uintptrType, b.ctx.Int1Type()}, false) +diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go +index e73b68da..ca277765 100644 +--- a/compiler/llvmutil/llvm.go ++++ b/compiler/llvmutil/llvm.go +@@ -7,7 +7,22 @@ + // places would be a big risk if only one of them is updated. + package llvmutil + +-import "tinygo.org/x/go-llvm" ++import ( ++ "strconv" ++ "strings" ++ ++ "tinygo.org/x/go-llvm" ++) ++ ++// Major returns the LLVM major version. ++func Major() int { ++ llvmMajor, err := strconv.Atoi(strings.SplitN(llvm.Version, ".", 2)[0]) ++ if err != nil { ++ // sanity check, should be unreachable ++ panic("could not parse LLVM version: " + err.Error()) ++ } ++ return llvmMajor ++} + + // CreateEntryBlockAlloca creates a new alloca in the entry block, even though + // the IR builder is located elsewhere. It assumes that the insert point is +@@ -78,12 +93,16 @@ func EmitLifetimeEnd(builder llvm.Builder, mod llvm.Module, ptr, size llvm.Value + // getLifetimeStartFunc returns the llvm.lifetime.start intrinsic and creates it + // first if it doesn't exist yet. + func getLifetimeStartFunc(mod llvm.Module) (llvm.Type, llvm.Value) { +- fn := mod.NamedFunction("llvm.lifetime.start.p0i8") ++ fnName := "llvm.lifetime.start.p0" ++ if Major() < 15 { // compatibility with LLVM 14 ++ fnName = "llvm.lifetime.start.p0i8" ++ } ++ fn := mod.NamedFunction(fnName) + ctx := mod.Context() + i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) + fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) + if fn.IsNil() { +- fn = llvm.AddFunction(mod, "llvm.lifetime.start.p0i8", fnType) ++ fn = llvm.AddFunction(mod, fnName, fnType) + } + return fnType, fn + } +@@ -91,12 +110,16 @@ func getLifetimeStartFunc(mod llvm.Module) (llvm.Type, llvm.Value) { + // getLifetimeEndFunc returns the llvm.lifetime.end intrinsic and creates it + // first if it doesn't exist yet. + func getLifetimeEndFunc(mod llvm.Module) (llvm.Type, llvm.Value) { +- fn := mod.NamedFunction("llvm.lifetime.end.p0i8") ++ fnName := "llvm.lifetime.end.p0" ++ if Major() < 15 { ++ fnName = "llvm.lifetime.end.p0i8" ++ } ++ fn := mod.NamedFunction(fnName) + ctx := mod.Context() + i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) + fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) + if fn.IsNil() { +- fn = llvm.AddFunction(mod, "llvm.lifetime.end.p0i8", fnType) ++ fn = llvm.AddFunction(mod, fnName, fnType) + } + return fnType, fn + } +diff --git a/compiler/symbol.go b/compiler/symbol.go +index 01b3fc37..61ca4473 100644 +--- a/compiler/symbol.go ++++ b/compiler/symbol.go +@@ -10,6 +10,7 @@ import ( + "strconv" + "strings" + ++ "github.com/tinygo-org/tinygo/compiler/llvmutil" + "github.com/tinygo-org/tinygo/loader" + "golang.org/x/tools/go/ssa" + "tinygo.org/x/go-llvm" +@@ -353,7 +354,15 @@ func (c *compilerContext) addStandardDefinedAttributes(llvmFn llvm.Value) { + llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nounwind"), 0)) + if strings.Split(c.Triple, "-")[0] == "x86_64" { + // Required by the ABI. +- llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 0)) ++ if llvmutil.Major() < 15 { ++ // Needed for LLVM 14 support. ++ llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 0)) ++ } else { ++ // The uwtable has two possible values: sync (1) or async (2). We ++ // use sync because we currently don't use async unwind tables. ++ // For details, see: https://llvm.org/docs/LangRef.html#function-attributes ++ llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 1)) ++ } + } + } + +diff --git a/compiler/testdata/basic.go b/compiler/testdata/basic.go +index e9fcbad3..d2b4a96d 100644 +--- a/compiler/testdata/basic.go ++++ b/compiler/testdata/basic.go +@@ -75,14 +75,18 @@ func complexMul(x, y complex64) complex64 { + // A type 'kv' also exists in function foo. Test that these two types don't + // conflict with each other. + type kv struct { +- v float32 ++ v float32 ++ x, y, z int + } + +-func foo(a *kv) { ++var kvGlobal kv ++ ++func foo() { + // Define a new 'kv' type. + type kv struct { +- v byte ++ v byte ++ x, y, z int + } + // Use this type. +- func(b *kv) {}(nil) ++ func(b kv) {}(kv{}) + } +diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll +index 4d88f66f..6ef0dc92 100644 +--- a/compiler/testdata/basic.ll ++++ b/compiler/testdata/basic.ll +@@ -3,35 +3,37 @@ source_filename = "basic.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-%main.kv = type { float } +-%main.kv.0 = type { i8 } ++%main.kv = type { float, i32, i32, i32 } ++%main.kv.0 = type { i8, i32, i32, i32 } + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++@main.kvGlobal = hidden global %main.kv zeroinitializer, align 4 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 ++ ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden i32 @main.addInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.addInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { + entry: + %0 = add i32 %x, %y + ret i32 %0 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.equalInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.equalInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp eq i32 %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden i32 @main.divInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.divInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp eq i32 %y, 0 + br i1 %0, label %divbyzero.throw, label %divbyzero.next +@@ -45,14 +47,14 @@ divbyzero.next: ; preds = %entry + ret i32 %5 + + divbyzero.throw: ; preds = %entry +- call void @runtime.divideByZeroPanic(i8* undef) #2 ++ call void @runtime.divideByZeroPanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.divideByZeroPanic(i8*) #0 ++declare void @runtime.divideByZeroPanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden i32 @main.divUint(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.divUint(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp eq i32 %y, 0 + br i1 %0, label %divbyzero.throw, label %divbyzero.next +@@ -62,12 +64,12 @@ divbyzero.next: ; preds = %entry + ret i32 %1 + + divbyzero.throw: ; preds = %entry +- call void @runtime.divideByZeroPanic(i8* undef) #2 ++ call void @runtime.divideByZeroPanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden i32 @main.remInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.remInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp eq i32 %y, 0 + br i1 %0, label %divbyzero.throw, label %divbyzero.next +@@ -81,12 +83,12 @@ divbyzero.next: ; preds = %entry + ret i32 %5 + + divbyzero.throw: ; preds = %entry +- call void @runtime.divideByZeroPanic(i8* undef) #2 ++ call void @runtime.divideByZeroPanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden i32 @main.remUint(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.remUint(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp eq i32 %y, 0 + br i1 %0, label %divbyzero.throw, label %divbyzero.next +@@ -96,66 +98,66 @@ divbyzero.next: ; preds = %entry + ret i32 %1 + + divbyzero.throw: ; preds = %entry +- call void @runtime.divideByZeroPanic(i8* undef) #2 ++ call void @runtime.divideByZeroPanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden i1 @main.floatEQ(float %x, float %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.floatEQ(float %x, float %y, ptr %context) unnamed_addr #1 { + entry: + %0 = fcmp oeq float %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.floatNE(float %x, float %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.floatNE(float %x, float %y, ptr %context) unnamed_addr #1 { + entry: + %0 = fcmp une float %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.floatLower(float %x, float %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.floatLower(float %x, float %y, ptr %context) unnamed_addr #1 { + entry: + %0 = fcmp olt float %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.floatLowerEqual(float %x, float %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.floatLowerEqual(float %x, float %y, ptr %context) unnamed_addr #1 { + entry: + %0 = fcmp ole float %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.floatGreater(float %x, float %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.floatGreater(float %x, float %y, ptr %context) unnamed_addr #1 { + entry: + %0 = fcmp ogt float %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.floatGreaterEqual(float %x, float %y, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.floatGreaterEqual(float %x, float %y, ptr %context) unnamed_addr #1 { + entry: + %0 = fcmp oge float %x, %y + ret i1 %0 + } + + ; Function Attrs: nounwind +-define hidden float @main.complexReal(float %x.r, float %x.i, i8* %context) unnamed_addr #1 { ++define hidden float @main.complexReal(float %x.r, float %x.i, ptr %context) unnamed_addr #1 { + entry: + ret float %x.r + } + + ; Function Attrs: nounwind +-define hidden float @main.complexImag(float %x.r, float %x.i, i8* %context) unnamed_addr #1 { ++define hidden float @main.complexImag(float %x.r, float %x.i, ptr %context) unnamed_addr #1 { + entry: + ret float %x.i + } + + ; Function Attrs: nounwind +-define hidden { float, float } @main.complexAdd(float %x.r, float %x.i, float %y.r, float %y.i, i8* %context) unnamed_addr #1 { ++define hidden { float, float } @main.complexAdd(float %x.r, float %x.i, float %y.r, float %y.i, ptr %context) unnamed_addr #1 { + entry: + %0 = fadd float %x.r, %y.r + %1 = fadd float %x.i, %y.i +@@ -165,7 +167,7 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden { float, float } @main.complexSub(float %x.r, float %x.i, float %y.r, float %y.i, i8* %context) unnamed_addr #1 { ++define hidden { float, float } @main.complexSub(float %x.r, float %x.i, float %y.r, float %y.i, ptr %context) unnamed_addr #1 { + entry: + %0 = fsub float %x.r, %y.r + %1 = fsub float %x.i, %y.i +@@ -175,7 +177,7 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden { float, float } @main.complexMul(float %x.r, float %x.i, float %y.r, float %y.i, i8* %context) unnamed_addr #1 { ++define hidden { float, float } @main.complexMul(float %x.r, float %x.i, float %y.r, float %y.i, ptr %context) unnamed_addr #1 { + entry: + %0 = fmul float %x.r, %y.r + %1 = fmul float %x.i, %y.i +@@ -189,15 +191,22 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden void @main.foo(%main.kv* dereferenceable_or_null(4) %a, i8* %context) unnamed_addr #1 { ++define hidden void @main.foo(ptr %context) unnamed_addr #1 { + entry: +- call void @"main.foo$1"(%main.kv.0* null, i8* undef) ++ %complit = alloca %main.kv.0, align 8 ++ store %main.kv.0 zeroinitializer, ptr %complit, align 8 ++ call void @runtime.trackPointer(ptr nonnull %complit, ptr undef) #2 ++ call void @"main.foo$1"(%main.kv.0 zeroinitializer, ptr undef) + ret void + } + + ; Function Attrs: nounwind +-define internal void @"main.foo$1"(%main.kv.0* dereferenceable_or_null(1) %b, i8* %context) unnamed_addr #1 { ++define internal void @"main.foo$1"(%main.kv.0 %b, ptr %context) unnamed_addr #1 { + entry: ++ %b1 = alloca %main.kv.0, align 8 ++ store %main.kv.0 zeroinitializer, ptr %b1, align 8 ++ call void @runtime.trackPointer(ptr nonnull %b1, ptr undef) #2 ++ store %main.kv.0 %b, ptr %b1, align 8 + ret void + } + +diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll +index ec3dd6b9..8f4ed74e 100644 +--- a/compiler/testdata/channel.ll ++++ b/compiler/testdata/channel.ll +@@ -3,110 +3,94 @@ source_filename = "channel.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } +-%runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state", i8* } +-%"internal/task.gcData" = type { i8* } +-%"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } +-%"internal/task.stackState" = type { i32, i32 } +-%runtime.chanSelectState = type { %runtime.channel*, i8* } ++%runtime.channelBlockedList = type { ptr, ptr, ptr, { ptr, i32, i32 } } ++%runtime.chanSelectState = type { ptr, ptr } + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.chanIntSend(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { ++define hidden void @main.chanIntSend(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { + entry: + %chan.blockedList = alloca %runtime.channelBlockedList, align 8 + %chan.value = alloca i32, align 4 +- %chan.value.bitcast = bitcast i32* %chan.value to i8* +- call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %chan.value.bitcast) +- store i32 3, i32* %chan.value, align 4 +- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* +- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) +- call void @runtime.chanSend(%runtime.channel* %ch, i8* nonnull %chan.value.bitcast, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 +- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) +- call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %chan.value.bitcast) ++ call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %chan.value) ++ store i32 3, ptr %chan.value, align 4 ++ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) ++ call void @runtime.chanSend(ptr %ch, ptr nonnull %chan.value, ptr nonnull %chan.blockedList, ptr undef) #3 ++ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) ++ call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %chan.value) + ret void + } + +-; Function Attrs: argmemonly nofree nosync nounwind willreturn +-declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2 ++; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn ++declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2 + +-declare void @runtime.chanSend(%runtime.channel* dereferenceable_or_null(32), i8*, %runtime.channelBlockedList* dereferenceable_or_null(24), i8*) #0 ++declare void @runtime.chanSend(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #0 + +-; Function Attrs: argmemonly nofree nosync nounwind willreturn +-declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2 ++; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn ++declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2 + + ; Function Attrs: nounwind +-define hidden void @main.chanIntRecv(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { ++define hidden void @main.chanIntRecv(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { + entry: + %chan.blockedList = alloca %runtime.channelBlockedList, align 8 + %chan.value = alloca i32, align 4 +- %chan.value.bitcast = bitcast i32* %chan.value to i8* +- call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %chan.value.bitcast) +- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* +- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) +- %0 = call i1 @runtime.chanRecv(%runtime.channel* %ch, i8* nonnull %chan.value.bitcast, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 +- call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %chan.value.bitcast) +- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) ++ call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %chan.value) ++ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) ++ %0 = call i1 @runtime.chanRecv(ptr %ch, ptr nonnull %chan.value, ptr nonnull %chan.blockedList, ptr undef) #3 ++ call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %chan.value) ++ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) + ret void + } + +-declare i1 @runtime.chanRecv(%runtime.channel* dereferenceable_or_null(32), i8*, %runtime.channelBlockedList* dereferenceable_or_null(24), i8*) #0 ++declare i1 @runtime.chanRecv(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.chanZeroSend(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { ++define hidden void @main.chanZeroSend(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { + entry: + %complit = alloca {}, align 8 + %chan.blockedList = alloca %runtime.channelBlockedList, align 8 +- %0 = bitcast {}* %complit to i8* +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #3 +- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* +- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) +- call void @runtime.chanSend(%runtime.channel* %ch, i8* null, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 +- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) ++ call void @runtime.trackPointer(ptr nonnull %complit, ptr undef) #3 ++ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) ++ call void @runtime.chanSend(ptr %ch, ptr null, ptr nonnull %chan.blockedList, ptr undef) #3 ++ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.chanZeroRecv(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { ++define hidden void @main.chanZeroRecv(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { + entry: + %chan.blockedList = alloca %runtime.channelBlockedList, align 8 +- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* +- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) +- %0 = call i1 @runtime.chanRecv(%runtime.channel* %ch, i8* null, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 +- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) ++ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) ++ %0 = call i1 @runtime.chanRecv(ptr %ch, ptr null, ptr nonnull %chan.blockedList, ptr undef) #3 ++ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.selectZeroRecv(%runtime.channel* dereferenceable_or_null(32) %ch1, %runtime.channel* dereferenceable_or_null(32) %ch2, i8* %context) unnamed_addr #1 { ++define hidden void @main.selectZeroRecv(ptr dereferenceable_or_null(32) %ch1, ptr dereferenceable_or_null(32) %ch2, ptr %context) unnamed_addr #1 { + entry: + %select.states.alloca = alloca [2 x %runtime.chanSelectState], align 8 + %select.send.value = alloca i32, align 4 +- store i32 1, i32* %select.send.value, align 4 +- %select.states.alloca.bitcast = bitcast [2 x %runtime.chanSelectState]* %select.states.alloca to i8* +- call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %select.states.alloca.bitcast) +- %.repack = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 0, i32 0 +- store %runtime.channel* %ch1, %runtime.channel** %.repack, align 8 +- %.repack1 = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 0, i32 1 +- %0 = bitcast i8** %.repack1 to i32** +- store i32* %select.send.value, i32** %0, align 4 +- %.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 1, i32 0 +- store %runtime.channel* %ch2, %runtime.channel** %.repack3, align 8 +- %.repack4 = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 1, i32 1 +- store i8* null, i8** %.repack4, align 4 +- %select.states = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 0 +- %select.result = call { i32, i1 } @runtime.tryChanSelect(i8* undef, %runtime.chanSelectState* nonnull %select.states, i32 2, i32 2, i8* undef) #3 +- call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %select.states.alloca.bitcast) ++ store i32 1, ptr %select.send.value, align 4 ++ call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %select.states.alloca) ++ store ptr %ch1, ptr %select.states.alloca, align 8 ++ %select.states.alloca.repack1 = getelementptr inbounds %runtime.chanSelectState, ptr %select.states.alloca, i32 0, i32 1 ++ store ptr %select.send.value, ptr %select.states.alloca.repack1, align 4 ++ %0 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1 ++ store ptr %ch2, ptr %0, align 8 ++ %.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1, i32 1 ++ store ptr null, ptr %.repack3, align 4 ++ %select.result = call { i32, i1 } @runtime.tryChanSelect(ptr undef, ptr nonnull %select.states.alloca, i32 2, i32 2, ptr undef) #3 ++ call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %select.states.alloca) + %1 = extractvalue { i32, i1 } %select.result, 0 + %2 = icmp eq i32 %1, 0 + br i1 %2, label %select.done, label %select.next +@@ -122,9 +106,9 @@ select.body: ; preds = %select.next + br label %select.done + } + +-declare { i32, i1 } @runtime.tryChanSelect(i8*, %runtime.chanSelectState*, i32, i32, i8*) #0 ++declare { i32, i1 } @runtime.tryChanSelect(ptr, ptr, i32, i32, ptr) #0 + + attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +-attributes #2 = { argmemonly nofree nosync nounwind willreturn } ++attributes #2 = { argmemonly nocallback nofree nosync nounwind willreturn } + attributes #3 = { nounwind } +diff --git a/compiler/testdata/defer-cortex-m-qemu.ll b/compiler/testdata/defer-cortex-m-qemu.ll +index 693f1b07..0841e255 100644 +--- a/compiler/testdata/defer-cortex-m-qemu.ll ++++ b/compiler/testdata/defer-cortex-m-qemu.ll +@@ -3,103 +3,99 @@ source_filename = "defer.go" + target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "thumbv7m-unknown-unknown-eabi" + +-%runtime._defer = type { i32, %runtime._defer* } +-%runtime.deferFrame = type { i8*, i8*, [0 x i8*], %runtime.deferFrame*, i1, %runtime._interface } +-%runtime._interface = type { i32, i8* } ++%runtime.deferFrame = type { ptr, ptr, [0 x ptr], ptr, i1, %runtime._interface } ++%runtime._interface = type { i32, ptr } ++%runtime._defer = type { i32, ptr } + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + +-declare void @main.external(i8*) #0 ++declare void @main.external(ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.deferSimple(i8* %context) unnamed_addr #1 { ++define hidden void @main.deferSimple(ptr %context) unnamed_addr #1 { + entry: +- %defer.alloca = alloca { i32, %runtime._defer* }, align 4 +- %deferPtr = alloca %runtime._defer*, align 4 +- store %runtime._defer* null, %runtime._defer** %deferPtr, align 4 ++ %defer.alloca = alloca { i32, ptr }, align 4 ++ %deferPtr = alloca ptr, align 4 ++ store ptr null, ptr %deferPtr, align 4 + %deferframe.buf = alloca %runtime.deferFrame, align 4 +- %0 = call i8* @llvm.stacksave() +- call void @runtime.setupDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* %0, i8* undef) #3 +- %defer.alloca.repack = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 0 +- store i32 0, i32* %defer.alloca.repack, align 4 +- %defer.alloca.repack16 = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 1 +- store %runtime._defer* null, %runtime._defer** %defer.alloca.repack16, align 4 +- %1 = bitcast %runtime._defer** %deferPtr to { i32, %runtime._defer* }** +- store { i32, %runtime._defer* }* %defer.alloca, { i32, %runtime._defer* }** %1, align 4 +- %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 ++ %0 = call ptr @llvm.stacksave() ++ call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #3 ++ store i32 0, ptr %defer.alloca, align 4 ++ %defer.alloca.repack15 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1 ++ store ptr null, ptr %defer.alloca.repack15, align 4 ++ store ptr %defer.alloca, ptr %deferPtr, align 4 ++ %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 + %setjmp.result = icmp eq i32 %setjmp, 0 +- br i1 %setjmp.result, label %2, label %lpad ++ br i1 %setjmp.result, label %1, label %lpad + +-2: ; preds = %entry +- call void @main.external(i8* undef) #3 ++1: ; preds = %entry ++ call void @main.external(ptr undef) #3 + br label %rundefers.loophead + +-rundefers.loophead: ; preds = %4, %2 +- %3 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 +- %stackIsNil = icmp eq %runtime._defer* %3, null ++rundefers.loophead: ; preds = %3, %1 ++ %2 = load ptr, ptr %deferPtr, align 4 ++ %stackIsNil = icmp eq ptr %2, null + br i1 %stackIsNil, label %rundefers.end, label %rundefers.loop + + rundefers.loop: ; preds = %rundefers.loophead +- %stack.next.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %3, i32 0, i32 1 +- %stack.next = load %runtime._defer*, %runtime._defer** %stack.next.gep, align 4 +- store %runtime._defer* %stack.next, %runtime._defer** %deferPtr, align 4 +- %callback.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %3, i32 0, i32 0 +- %callback = load i32, i32* %callback.gep, align 4 ++ %stack.next.gep = getelementptr inbounds %runtime._defer, ptr %2, i32 0, i32 1 ++ %stack.next = load ptr, ptr %stack.next.gep, align 4 ++ store ptr %stack.next, ptr %deferPtr, align 4 ++ %callback = load i32, ptr %2, align 4 + switch i32 %callback, label %rundefers.default [ + i32 0, label %rundefers.callback0 + ] + + rundefers.callback0: ; preds = %rundefers.loop +- %setjmp1 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 ++ %setjmp1 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 + %setjmp.result2 = icmp eq i32 %setjmp1, 0 +- br i1 %setjmp.result2, label %4, label %lpad ++ br i1 %setjmp.result2, label %3, label %lpad + +-4: ; preds = %rundefers.callback0 +- call void @"main.deferSimple$1"(i8* undef) ++3: ; preds = %rundefers.callback0 ++ call void @"main.deferSimple$1"(ptr undef) + br label %rundefers.loophead + + rundefers.default: ; preds = %rundefers.loop + unreachable + + rundefers.end: ; preds = %rundefers.loophead +- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 ++ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 + ret void + + recover: ; preds = %rundefers.end3 +- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 ++ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 + ret void + + lpad: ; preds = %rundefers.callback012, %rundefers.callback0, %entry + br label %rundefers.loophead6 + +-rundefers.loophead6: ; preds = %6, %lpad +- %5 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 +- %stackIsNil7 = icmp eq %runtime._defer* %5, null ++rundefers.loophead6: ; preds = %5, %lpad ++ %4 = load ptr, ptr %deferPtr, align 4 ++ %stackIsNil7 = icmp eq ptr %4, null + br i1 %stackIsNil7, label %rundefers.end3, label %rundefers.loop5 + + rundefers.loop5: ; preds = %rundefers.loophead6 +- %stack.next.gep8 = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 1 +- %stack.next9 = load %runtime._defer*, %runtime._defer** %stack.next.gep8, align 4 +- store %runtime._defer* %stack.next9, %runtime._defer** %deferPtr, align 4 +- %callback.gep10 = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 0 +- %callback11 = load i32, i32* %callback.gep10, align 4 ++ %stack.next.gep8 = getelementptr inbounds %runtime._defer, ptr %4, i32 0, i32 1 ++ %stack.next9 = load ptr, ptr %stack.next.gep8, align 4 ++ store ptr %stack.next9, ptr %deferPtr, align 4 ++ %callback11 = load i32, ptr %4, align 4 + switch i32 %callback11, label %rundefers.default4 [ + i32 0, label %rundefers.callback012 + ] + + rundefers.callback012: ; preds = %rundefers.loop5 +- %setjmp14 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 +- %setjmp.result15 = icmp eq i32 %setjmp14, 0 +- br i1 %setjmp.result15, label %6, label %lpad ++ %setjmp13 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 ++ %setjmp.result14 = icmp eq i32 %setjmp13, 0 ++ br i1 %setjmp.result14, label %5, label %lpad + +-6: ; preds = %rundefers.callback012 +- call void @"main.deferSimple$1"(i8* undef) ++5: ; preds = %rundefers.callback012 ++ call void @"main.deferSimple$1"(ptr undef) + br label %rundefers.loophead6 + + rundefers.default4: ; preds = %rundefers.loop5 +@@ -109,158 +105,151 @@ rundefers.end3: ; preds = %rundefers.loophead6 + br label %recover + } + +-; Function Attrs: nofree nosync nounwind willreturn +-declare i8* @llvm.stacksave() #2 ++; Function Attrs: nocallback nofree nosync nounwind willreturn ++declare ptr @llvm.stacksave() #2 + +-declare void @runtime.setupDeferFrame(%runtime.deferFrame* dereferenceable_or_null(24), i8*, i8*) #0 ++declare void @runtime.setupDeferFrame(ptr dereferenceable_or_null(24), ptr, ptr) #0 + + ; Function Attrs: nounwind +-define internal void @"main.deferSimple$1"(i8* %context) unnamed_addr #1 { ++define internal void @"main.deferSimple$1"(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.printint32(i32 3, i8* undef) #3 ++ call void @runtime.printint32(i32 3, ptr undef) #3 + ret void + } + +-declare void @runtime.destroyDeferFrame(%runtime.deferFrame* dereferenceable_or_null(24), i8*) #0 ++declare void @runtime.destroyDeferFrame(ptr dereferenceable_or_null(24), ptr) #0 + +-declare void @runtime.printint32(i32, i8*) #0 ++declare void @runtime.printint32(i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.deferMultiple(i8* %context) unnamed_addr #1 { ++define hidden void @main.deferMultiple(ptr %context) unnamed_addr #1 { + entry: +- %defer.alloca2 = alloca { i32, %runtime._defer* }, align 4 +- %defer.alloca = alloca { i32, %runtime._defer* }, align 4 +- %deferPtr = alloca %runtime._defer*, align 4 +- store %runtime._defer* null, %runtime._defer** %deferPtr, align 4 ++ %defer.alloca2 = alloca { i32, ptr }, align 4 ++ %defer.alloca = alloca { i32, ptr }, align 4 ++ %deferPtr = alloca ptr, align 4 ++ store ptr null, ptr %deferPtr, align 4 + %deferframe.buf = alloca %runtime.deferFrame, align 4 +- %0 = call i8* @llvm.stacksave() +- call void @runtime.setupDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* %0, i8* undef) #3 +- %defer.alloca.repack = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 0 +- store i32 0, i32* %defer.alloca.repack, align 4 +- %defer.alloca.repack26 = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 1 +- store %runtime._defer* null, %runtime._defer** %defer.alloca.repack26, align 4 +- %1 = bitcast %runtime._defer** %deferPtr to { i32, %runtime._defer* }** +- store { i32, %runtime._defer* }* %defer.alloca, { i32, %runtime._defer* }** %1, align 4 +- %defer.alloca2.repack = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca2, i32 0, i32 0 +- store i32 1, i32* %defer.alloca2.repack, align 4 +- %defer.alloca2.repack27 = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca2, i32 0, i32 1 +- %2 = bitcast %runtime._defer** %defer.alloca2.repack27 to { i32, %runtime._defer* }** +- store { i32, %runtime._defer* }* %defer.alloca, { i32, %runtime._defer* }** %2, align 4 +- %3 = bitcast %runtime._defer** %deferPtr to { i32, %runtime._defer* }** +- store { i32, %runtime._defer* }* %defer.alloca2, { i32, %runtime._defer* }** %3, align 4 +- %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 ++ %0 = call ptr @llvm.stacksave() ++ call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #3 ++ store i32 0, ptr %defer.alloca, align 4 ++ %defer.alloca.repack22 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1 ++ store ptr null, ptr %defer.alloca.repack22, align 4 ++ store ptr %defer.alloca, ptr %deferPtr, align 4 ++ store i32 1, ptr %defer.alloca2, align 4 ++ %defer.alloca2.repack23 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca2, i32 0, i32 1 ++ store ptr %defer.alloca, ptr %defer.alloca2.repack23, align 4 ++ store ptr %defer.alloca2, ptr %deferPtr, align 4 ++ %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 + %setjmp.result = icmp eq i32 %setjmp, 0 +- br i1 %setjmp.result, label %4, label %lpad ++ br i1 %setjmp.result, label %1, label %lpad + +-4: ; preds = %entry +- call void @main.external(i8* undef) #3 ++1: ; preds = %entry ++ call void @main.external(ptr undef) #3 + br label %rundefers.loophead + +-rundefers.loophead: ; preds = %7, %6, %4 +- %5 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 +- %stackIsNil = icmp eq %runtime._defer* %5, null ++rundefers.loophead: ; preds = %4, %3, %1 ++ %2 = load ptr, ptr %deferPtr, align 4 ++ %stackIsNil = icmp eq ptr %2, null + br i1 %stackIsNil, label %rundefers.end, label %rundefers.loop + + rundefers.loop: ; preds = %rundefers.loophead +- %stack.next.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 1 +- %stack.next = load %runtime._defer*, %runtime._defer** %stack.next.gep, align 4 +- store %runtime._defer* %stack.next, %runtime._defer** %deferPtr, align 4 +- %callback.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 0 +- %callback = load i32, i32* %callback.gep, align 4 ++ %stack.next.gep = getelementptr inbounds %runtime._defer, ptr %2, i32 0, i32 1 ++ %stack.next = load ptr, ptr %stack.next.gep, align 4 ++ store ptr %stack.next, ptr %deferPtr, align 4 ++ %callback = load i32, ptr %2, align 4 + switch i32 %callback, label %rundefers.default [ + i32 0, label %rundefers.callback0 + i32 1, label %rundefers.callback1 + ] + + rundefers.callback0: ; preds = %rundefers.loop +- %setjmp4 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 +- %setjmp.result5 = icmp eq i32 %setjmp4, 0 +- br i1 %setjmp.result5, label %6, label %lpad ++ %setjmp3 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 ++ %setjmp.result4 = icmp eq i32 %setjmp3, 0 ++ br i1 %setjmp.result4, label %3, label %lpad + +-6: ; preds = %rundefers.callback0 +- call void @"main.deferMultiple$1"(i8* undef) ++3: ; preds = %rundefers.callback0 ++ call void @"main.deferMultiple$1"(ptr undef) + br label %rundefers.loophead + + rundefers.callback1: ; preds = %rundefers.loop +- %setjmp7 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 +- %setjmp.result8 = icmp eq i32 %setjmp7, 0 +- br i1 %setjmp.result8, label %7, label %lpad ++ %setjmp5 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 ++ %setjmp.result6 = icmp eq i32 %setjmp5, 0 ++ br i1 %setjmp.result6, label %4, label %lpad + +-7: ; preds = %rundefers.callback1 +- call void @"main.deferMultiple$2"(i8* undef) ++4: ; preds = %rundefers.callback1 ++ call void @"main.deferMultiple$2"(ptr undef) + br label %rundefers.loophead + + rundefers.default: ; preds = %rundefers.loop + unreachable + + rundefers.end: ; preds = %rundefers.loophead +- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 ++ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 + ret void + +-recover: ; preds = %rundefers.end9 +- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 ++recover: ; preds = %rundefers.end7 ++ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 + ret void + +-lpad: ; preds = %rundefers.callback122, %rundefers.callback018, %rundefers.callback1, %rundefers.callback0, %entry +- br label %rundefers.loophead12 +- +-rundefers.loophead12: ; preds = %10, %9, %lpad +- %8 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 +- %stackIsNil13 = icmp eq %runtime._defer* %8, null +- br i1 %stackIsNil13, label %rundefers.end9, label %rundefers.loop11 +- +-rundefers.loop11: ; preds = %rundefers.loophead12 +- %stack.next.gep14 = getelementptr inbounds %runtime._defer, %runtime._defer* %8, i32 0, i32 1 +- %stack.next15 = load %runtime._defer*, %runtime._defer** %stack.next.gep14, align 4 +- store %runtime._defer* %stack.next15, %runtime._defer** %deferPtr, align 4 +- %callback.gep16 = getelementptr inbounds %runtime._defer, %runtime._defer* %8, i32 0, i32 0 +- %callback17 = load i32, i32* %callback.gep16, align 4 +- switch i32 %callback17, label %rundefers.default10 [ +- i32 0, label %rundefers.callback018 +- i32 1, label %rundefers.callback122 ++lpad: ; preds = %rundefers.callback119, %rundefers.callback016, %rundefers.callback1, %rundefers.callback0, %entry ++ br label %rundefers.loophead10 ++ ++rundefers.loophead10: ; preds = %7, %6, %lpad ++ %5 = load ptr, ptr %deferPtr, align 4 ++ %stackIsNil11 = icmp eq ptr %5, null ++ br i1 %stackIsNil11, label %rundefers.end7, label %rundefers.loop9 ++ ++rundefers.loop9: ; preds = %rundefers.loophead10 ++ %stack.next.gep12 = getelementptr inbounds %runtime._defer, ptr %5, i32 0, i32 1 ++ %stack.next13 = load ptr, ptr %stack.next.gep12, align 4 ++ store ptr %stack.next13, ptr %deferPtr, align 4 ++ %callback15 = load i32, ptr %5, align 4 ++ switch i32 %callback15, label %rundefers.default8 [ ++ i32 0, label %rundefers.callback016 ++ i32 1, label %rundefers.callback119 + ] + +-rundefers.callback018: ; preds = %rundefers.loop11 +- %setjmp20 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 +- %setjmp.result21 = icmp eq i32 %setjmp20, 0 +- br i1 %setjmp.result21, label %9, label %lpad ++rundefers.callback016: ; preds = %rundefers.loop9 ++ %setjmp17 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 ++ %setjmp.result18 = icmp eq i32 %setjmp17, 0 ++ br i1 %setjmp.result18, label %6, label %lpad + +-9: ; preds = %rundefers.callback018 +- call void @"main.deferMultiple$1"(i8* undef) +- br label %rundefers.loophead12 ++6: ; preds = %rundefers.callback016 ++ call void @"main.deferMultiple$1"(ptr undef) ++ br label %rundefers.loophead10 + +-rundefers.callback122: ; preds = %rundefers.loop11 +- %setjmp24 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 +- %setjmp.result25 = icmp eq i32 %setjmp24, 0 +- br i1 %setjmp.result25, label %10, label %lpad ++rundefers.callback119: ; preds = %rundefers.loop9 ++ %setjmp20 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 ++ %setjmp.result21 = icmp eq i32 %setjmp20, 0 ++ br i1 %setjmp.result21, label %7, label %lpad + +-10: ; preds = %rundefers.callback122 +- call void @"main.deferMultiple$2"(i8* undef) +- br label %rundefers.loophead12 ++7: ; preds = %rundefers.callback119 ++ call void @"main.deferMultiple$2"(ptr undef) ++ br label %rundefers.loophead10 + +-rundefers.default10: ; preds = %rundefers.loop11 ++rundefers.default8: ; preds = %rundefers.loop9 + unreachable + +-rundefers.end9: ; preds = %rundefers.loophead12 ++rundefers.end7: ; preds = %rundefers.loophead10 + br label %recover + } + + ; Function Attrs: nounwind +-define internal void @"main.deferMultiple$1"(i8* %context) unnamed_addr #1 { ++define internal void @"main.deferMultiple$1"(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.printint32(i32 3, i8* undef) #3 ++ call void @runtime.printint32(i32 3, ptr undef) #3 + ret void + } + + ; Function Attrs: nounwind +-define internal void @"main.deferMultiple$2"(i8* %context) unnamed_addr #1 { ++define internal void @"main.deferMultiple$2"(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.printint32(i32 5, i8* undef) #3 ++ call void @runtime.printint32(i32 5, ptr undef) #3 + ret void + } + + attributes #0 = { "target-features"="+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-pacbti,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" } + attributes #1 = { nounwind "target-features"="+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-pacbti,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" } +-attributes #2 = { nofree nosync nounwind willreturn } ++attributes #2 = { nocallback nofree nosync nounwind willreturn } + attributes #3 = { nounwind } + attributes #4 = { nounwind returns_twice } +diff --git a/compiler/testdata/float.ll b/compiler/testdata/float.ll +index 0ecd21e9..2acc2ed4 100644 +--- a/compiler/testdata/float.ll ++++ b/compiler/testdata/float.ll +@@ -3,18 +3,18 @@ source_filename = "float.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden i32 @main.f32tou32(float %v, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.f32tou32(float %v, ptr %context) unnamed_addr #1 { + entry: + %positive = fcmp oge float %v, 0.000000e+00 + %withinmax = fcmp ole float %v, 0x41EFFFFFC0000000 +@@ -26,25 +26,25 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden float @main.maxu32f(i8* %context) unnamed_addr #1 { ++define hidden float @main.maxu32f(ptr %context) unnamed_addr #1 { + entry: + ret float 0x41F0000000000000 + } + + ; Function Attrs: nounwind +-define hidden i32 @main.maxu32tof32(i8* %context) unnamed_addr #1 { ++define hidden i32 @main.maxu32tof32(ptr %context) unnamed_addr #1 { + entry: + ret i32 -1 + } + + ; Function Attrs: nounwind +-define hidden { i32, i32, i32, i32 } @main.inftoi32(i8* %context) unnamed_addr #1 { ++define hidden { i32, i32, i32, i32 } @main.inftoi32(ptr %context) unnamed_addr #1 { + entry: + ret { i32, i32, i32, i32 } { i32 -1, i32 0, i32 2147483647, i32 -2147483648 } + } + + ; Function Attrs: nounwind +-define hidden i32 @main.u32tof32tou32(i32 %v, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.u32tof32tou32(i32 %v, ptr %context) unnamed_addr #1 { + entry: + %0 = uitofp i32 %v to float + %withinmax = fcmp ole float %0, 0x41EFFFFFC0000000 +@@ -54,7 +54,7 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden float @main.f32tou32tof32(float %v, i8* %context) unnamed_addr #1 { ++define hidden float @main.f32tou32tof32(float %v, ptr %context) unnamed_addr #1 { + entry: + %positive = fcmp oge float %v, 0.000000e+00 + %withinmax = fcmp ole float %v, 0x41EFFFFFC0000000 +@@ -67,7 +67,7 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden i8 @main.f32tou8(float %v, i8* %context) unnamed_addr #1 { ++define hidden i8 @main.f32tou8(float %v, ptr %context) unnamed_addr #1 { + entry: + %positive = fcmp oge float %v, 0.000000e+00 + %withinmax = fcmp ole float %v, 2.550000e+02 +@@ -79,7 +79,7 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden i8 @main.f32toi8(float %v, i8* %context) unnamed_addr #1 { ++define hidden i8 @main.f32toi8(float %v, ptr %context) unnamed_addr #1 { + entry: + %abovemin = fcmp oge float %v, -1.280000e+02 + %belowmax = fcmp ole float %v, 1.270000e+02 +diff --git a/compiler/testdata/func.ll b/compiler/testdata/func.ll +index 2ed16eaf..227e52c1 100644 +--- a/compiler/testdata/func.ll ++++ b/compiler/testdata/func.ll +@@ -3,43 +3,42 @@ source_filename = "func.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.foo(i8* %callback.context, void ()* %callback.funcptr, i8* %context) unnamed_addr #1 { ++define hidden void @main.foo(ptr %callback.context, ptr %callback.funcptr, ptr %context) unnamed_addr #1 { + entry: +- %0 = icmp eq void ()* %callback.funcptr, null ++ %0 = icmp eq ptr %callback.funcptr, null + br i1 %0, label %fpcall.throw, label %fpcall.next + + fpcall.next: ; preds = %entry +- %1 = bitcast void ()* %callback.funcptr to void (i32, i8*)* +- call void %1(i32 3, i8* %callback.context) #2 ++ call void %callback.funcptr(i32 3, ptr %callback.context) #2 + ret void + + fpcall.throw: ; preds = %entry +- call void @runtime.nilPanic(i8* undef) #2 ++ call void @runtime.nilPanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.nilPanic(i8*) #0 ++declare void @runtime.nilPanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.bar(i8* %context) unnamed_addr #1 { ++define hidden void @main.bar(ptr %context) unnamed_addr #1 { + entry: +- call void @main.foo(i8* undef, void ()* bitcast (void (i32, i8*)* @main.someFunc to void ()*), i8* undef) ++ call void @main.foo(ptr undef, ptr nonnull @main.someFunc, ptr undef) + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.someFunc(i32 %arg0, i8* %context) unnamed_addr #1 { ++define hidden void @main.someFunc(i32 %arg0, ptr %context) unnamed_addr #1 { + entry: + ret void + } +diff --git a/compiler/testdata/gc.ll b/compiler/testdata/gc.ll +index 26bc4c24..e54b207d 100644 +--- a/compiler/testdata/gc.ll ++++ b/compiler/testdata/gc.ll +@@ -3,133 +3,129 @@ source_filename = "gc.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +-%runtime.interfaceMethodInfo = type { i8*, i32 } +-%runtime._interface = type { i32, i8* } ++%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } ++%runtime._interface = type { i32, ptr } + +-@main.scalar1 = hidden global i8* null, align 4 +-@main.scalar2 = hidden global i32* null, align 4 +-@main.scalar3 = hidden global i64* null, align 4 +-@main.scalar4 = hidden global float* null, align 4 +-@main.array1 = hidden global [3 x i8]* null, align 4 +-@main.array2 = hidden global [71 x i8]* null, align 4 +-@main.array3 = hidden global [3 x i8*]* null, align 4 +-@main.struct1 = hidden global {}* null, align 4 +-@main.struct2 = hidden global { i32, i32 }* null, align 4 +-@main.struct3 = hidden global { i8*, [60 x i32], i8* }* null, align 4 +-@main.struct4 = hidden global { i8*, [61 x i32] }* null, align 4 +-@main.slice1 = hidden global { i8*, i32, i32 } zeroinitializer, align 8 +-@main.slice2 = hidden global { i32**, i32, i32 } zeroinitializer, align 8 +-@main.slice3 = hidden global { { i8*, i32, i32 }*, i32, i32 } zeroinitializer, align 8 ++@main.scalar1 = hidden global ptr null, align 4 ++@main.scalar2 = hidden global ptr null, align 4 ++@main.scalar3 = hidden global ptr null, align 4 ++@main.scalar4 = hidden global ptr null, align 4 ++@main.array1 = hidden global ptr null, align 4 ++@main.array2 = hidden global ptr null, align 4 ++@main.array3 = hidden global ptr null, align 4 ++@main.struct1 = hidden global ptr null, align 4 ++@main.struct2 = hidden global ptr null, align 4 ++@main.struct3 = hidden global ptr null, align 4 ++@main.struct4 = hidden global ptr null, align 4 ++@main.slice1 = hidden global { ptr, i32, i32 } zeroinitializer, align 8 ++@main.slice2 = hidden global { ptr, i32, i32 } zeroinitializer, align 8 ++@main.slice3 = hidden global { ptr, i32, i32 } zeroinitializer, align 8 + @"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c" \00\00\00\00\00\00\01" } + @"runtime/gc.layout:62-0001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\00\00\00\00\00\00\00\01" } +-@"reflect/types.type:basic:complex128" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* null, i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:basic:complex128", i32 0 } +-@"reflect/types.type:pointer:basic:complex128" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:complex128", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } ++@"reflect/types.type:basic:complex128" = linkonce_odr constant %runtime.typecodeID { ptr null, i32 0, ptr null, ptr @"reflect/types.type:pointer:basic:complex128", i32 0 } ++@"reflect/types.type:pointer:basic:complex128" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:complex128", i32 0, ptr null, ptr null, i32 0 } + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.newScalar(i8* %context) unnamed_addr #1 { ++define hidden void @main.newScalar(ptr %context) unnamed_addr #1 { + entry: +- %new = call i8* @runtime.alloc(i32 1, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 +- store i8* %new, i8** @main.scalar1, align 4 +- %new1 = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new1, i8* undef) #2 +- store i8* %new1, i8** bitcast (i32** @main.scalar2 to i8**), align 4 +- %new2 = call i8* @runtime.alloc(i32 8, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new2, i8* undef) #2 +- store i8* %new2, i8** bitcast (i64** @main.scalar3 to i8**), align 4 +- %new3 = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new3, i8* undef) #2 +- store i8* %new3, i8** bitcast (float** @main.scalar4 to i8**), align 4 ++ %new = call ptr @runtime.alloc(i32 1, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 ++ store ptr %new, ptr @main.scalar1, align 4 ++ %new1 = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new1, ptr undef) #2 ++ store ptr %new1, ptr @main.scalar2, align 4 ++ %new2 = call ptr @runtime.alloc(i32 8, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new2, ptr undef) #2 ++ store ptr %new2, ptr @main.scalar3, align 4 ++ %new3 = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new3, ptr undef) #2 ++ store ptr %new3, ptr @main.scalar4, align 4 + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.newArray(i8* %context) unnamed_addr #1 { ++define hidden void @main.newArray(ptr %context) unnamed_addr #1 { + entry: +- %new = call i8* @runtime.alloc(i32 3, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 +- store i8* %new, i8** bitcast ([3 x i8]** @main.array1 to i8**), align 4 +- %new1 = call i8* @runtime.alloc(i32 71, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new1, i8* undef) #2 +- store i8* %new1, i8** bitcast ([71 x i8]** @main.array2 to i8**), align 4 +- %new2 = call i8* @runtime.alloc(i32 12, i8* nonnull inttoptr (i32 67 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new2, i8* undef) #2 +- store i8* %new2, i8** bitcast ([3 x i8*]** @main.array3 to i8**), align 4 ++ %new = call ptr @runtime.alloc(i32 3, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 ++ store ptr %new, ptr @main.array1, align 4 ++ %new1 = call ptr @runtime.alloc(i32 71, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new1, ptr undef) #2 ++ store ptr %new1, ptr @main.array2, align 4 ++ %new2 = call ptr @runtime.alloc(i32 12, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new2, ptr undef) #2 ++ store ptr %new2, ptr @main.array3, align 4 + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.newStruct(i8* %context) unnamed_addr #1 { ++define hidden void @main.newStruct(ptr %context) unnamed_addr #1 { + entry: +- %new = call i8* @runtime.alloc(i32 0, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 +- store i8* %new, i8** bitcast ({}** @main.struct1 to i8**), align 4 +- %new1 = call i8* @runtime.alloc(i32 8, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new1, i8* undef) #2 +- store i8* %new1, i8** bitcast ({ i32, i32 }** @main.struct2 to i8**), align 4 +- %new2 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-2000000000000001" to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new2, i8* undef) #2 +- store i8* %new2, i8** bitcast ({ i8*, [60 x i32], i8* }** @main.struct3 to i8**), align 4 +- %new3 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-0001" to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %new3, i8* undef) #2 +- store i8* %new3, i8** bitcast ({ i8*, [61 x i32] }** @main.struct4 to i8**), align 4 ++ %new = call ptr @runtime.alloc(i32 0, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 ++ store ptr %new, ptr @main.struct1, align 4 ++ %new1 = call ptr @runtime.alloc(i32 8, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new1, ptr undef) #2 ++ store ptr %new1, ptr @main.struct2, align 4 ++ %new2 = call ptr @runtime.alloc(i32 248, ptr nonnull @"runtime/gc.layout:62-2000000000000001", ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new2, ptr undef) #2 ++ store ptr %new2, ptr @main.struct3, align 4 ++ %new3 = call ptr @runtime.alloc(i32 248, ptr nonnull @"runtime/gc.layout:62-0001", ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new3, ptr undef) #2 ++ store ptr %new3, ptr @main.struct4, align 4 + ret void + } + + ; Function Attrs: nounwind +-define hidden { i8*, void ()* }* @main.newFuncValue(i8* %context) unnamed_addr #1 { ++define hidden ptr @main.newFuncValue(ptr %context) unnamed_addr #1 { + entry: +- %new = call i8* @runtime.alloc(i32 8, i8* nonnull inttoptr (i32 197 to i8*), i8* undef) #2 +- %0 = bitcast i8* %new to { i8*, void ()* }* +- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 +- ret { i8*, void ()* }* %0 ++ %new = call ptr @runtime.alloc(i32 8, ptr nonnull inttoptr (i32 197 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 ++ ret ptr %new + } + + ; Function Attrs: nounwind +-define hidden void @main.makeSlice(i8* %context) unnamed_addr #1 { ++define hidden void @main.makeSlice(ptr %context) unnamed_addr #1 { + entry: +- %makeslice = call i8* @runtime.alloc(i32 5, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %makeslice, i8* undef) #2 +- store i8* %makeslice, i8** getelementptr inbounds ({ i8*, i32, i32 }, { i8*, i32, i32 }* @main.slice1, i32 0, i32 0), align 8 +- store i32 5, i32* getelementptr inbounds ({ i8*, i32, i32 }, { i8*, i32, i32 }* @main.slice1, i32 0, i32 1), align 4 +- store i32 5, i32* getelementptr inbounds ({ i8*, i32, i32 }, { i8*, i32, i32 }* @main.slice1, i32 0, i32 2), align 8 +- %makeslice1 = call i8* @runtime.alloc(i32 20, i8* nonnull inttoptr (i32 67 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %makeslice1, i8* undef) #2 +- store i8* %makeslice1, i8** bitcast ({ i32**, i32, i32 }* @main.slice2 to i8**), align 8 +- store i32 5, i32* getelementptr inbounds ({ i32**, i32, i32 }, { i32**, i32, i32 }* @main.slice2, i32 0, i32 1), align 4 +- store i32 5, i32* getelementptr inbounds ({ i32**, i32, i32 }, { i32**, i32, i32 }* @main.slice2, i32 0, i32 2), align 8 +- %makeslice3 = call i8* @runtime.alloc(i32 60, i8* nonnull inttoptr (i32 71 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %makeslice3, i8* undef) #2 +- store i8* %makeslice3, i8** bitcast ({ { i8*, i32, i32 }*, i32, i32 }* @main.slice3 to i8**), align 8 +- store i32 5, i32* getelementptr inbounds ({ { i8*, i32, i32 }*, i32, i32 }, { { i8*, i32, i32 }*, i32, i32 }* @main.slice3, i32 0, i32 1), align 4 +- store i32 5, i32* getelementptr inbounds ({ { i8*, i32, i32 }*, i32, i32 }, { { i8*, i32, i32 }*, i32, i32 }* @main.slice3, i32 0, i32 2), align 8 ++ %makeslice = call ptr @runtime.alloc(i32 5, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice, ptr undef) #2 ++ store ptr %makeslice, ptr @main.slice1, align 8 ++ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 1), align 4 ++ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 2), align 8 ++ %makeslice1 = call ptr @runtime.alloc(i32 20, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice1, ptr undef) #2 ++ store ptr %makeslice1, ptr @main.slice2, align 8 ++ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 1), align 4 ++ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 2), align 8 ++ %makeslice3 = call ptr @runtime.alloc(i32 60, ptr nonnull inttoptr (i32 71 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice3, ptr undef) #2 ++ store ptr %makeslice3, ptr @main.slice3, align 8 ++ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 1), align 4 ++ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 2), align 8 + ret void + } + + ; Function Attrs: nounwind +-define hidden %runtime._interface @main.makeInterface(double %v.r, double %v.i, i8* %context) unnamed_addr #1 { ++define hidden %runtime._interface @main.makeInterface(double %v.r, double %v.i, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 +- %.repack = bitcast i8* %0 to double* +- store double %v.r, double* %.repack, align 8 +- %.repack1 = getelementptr inbounds i8, i8* %0, i32 8 +- %1 = bitcast i8* %.repack1 to double* +- store double %v.i, double* %1, align 8 +- %2 = insertvalue %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:complex128" to i32), i8* undef }, i8* %0, 1 +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 +- ret %runtime._interface %2 ++ %0 = call ptr @runtime.alloc(i32 16, ptr null, ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 ++ store double %v.r, ptr %0, align 8 ++ %.repack1 = getelementptr inbounds { double, double }, ptr %0, i32 0, i32 1 ++ store double %v.i, ptr %.repack1, align 8 ++ %1 = insertvalue %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:basic:complex128" to i32), ptr undef }, ptr %0, 1 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 ++ ret %runtime._interface %1 + } + + attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +diff --git a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll +index edd4d666..ac1adaff 100644 +--- a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll ++++ b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll +@@ -3,201 +3,176 @@ source_filename = "goroutine.go" + target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "thumbv7m-unknown-unknown-eabi" + +-%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } +-%runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state", i8* } +-%"internal/task.gcData" = type {} +-%"internal/task.state" = type { i32, i32* } +-%runtime.chanSelectState = type { %runtime.channel*, i8* } ++%runtime._string = type { ptr, i32 } + + @"main$string" = internal unnamed_addr constant [4 x i8] c"test", align 1 + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.regularFunctionGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.regularFunctionGoroutine(ptr %context) unnamed_addr #1 { + entry: +- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"main.regularFunction$gowrapper" to i32), i8* undef) #8 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.regularFunction$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 %stacksize, i8* undef) #8 ++ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"main.regularFunction$gowrapper" to i32), ptr undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.regularFunction$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 %stacksize, ptr undef) #8 + ret void + } + +-declare void @main.regularFunction(i32, i8*) #0 ++declare void @main.regularFunction(i32, ptr) #0 + + ; Function Attrs: nounwind +-define linkonce_odr void @"main.regularFunction$gowrapper"(i8* %0) unnamed_addr #2 { ++define linkonce_odr void @"main.regularFunction$gowrapper"(ptr %0) unnamed_addr #2 { + entry: +- %unpack.int = ptrtoint i8* %0 to i32 +- call void @main.regularFunction(i32 %unpack.int, i8* undef) #8 ++ %unpack.int = ptrtoint ptr %0 to i32 ++ call void @main.regularFunction(i32 %unpack.int, ptr undef) #8 + ret void + } + +-declare i32 @"internal/task.getGoroutineStackSize"(i32, i8*) #0 ++declare i32 @"internal/task.getGoroutineStackSize"(i32, ptr) #0 + +-declare void @"internal/task.start"(i32, i8*, i32, i8*) #0 ++declare void @"internal/task.start"(i32, ptr, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.inlineFunctionGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.inlineFunctionGoroutine(ptr %context) unnamed_addr #1 { + entry: +- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"main.inlineFunctionGoroutine$1$gowrapper" to i32), i8* undef) #8 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.inlineFunctionGoroutine$1$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 %stacksize, i8* undef) #8 ++ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"main.inlineFunctionGoroutine$1$gowrapper" to i32), ptr undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.inlineFunctionGoroutine$1$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 %stacksize, ptr undef) #8 + ret void + } + + ; Function Attrs: nounwind +-define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { ++define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #3 { ++define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #3 { + entry: +- %unpack.int = ptrtoint i8* %0 to i32 +- call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, i8* undef) ++ %unpack.int = ptrtoint ptr %0 to i32 ++ call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, ptr undef) + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.closureFunctionGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.closureFunctionGoroutine(ptr %context) unnamed_addr #1 { + entry: +- %n = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #8 +- %0 = bitcast i8* %n to i32* +- store i32 3, i32* %0, align 4 +- %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef) #8 +- %2 = bitcast i8* %1 to i32* +- store i32 5, i32* %2, align 4 +- %3 = getelementptr inbounds i8, i8* %1, i32 4 +- %4 = bitcast i8* %3 to i8** +- store i8* %n, i8** %4, align 4 +- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"main.closureFunctionGoroutine$1$gowrapper" to i32), i8* undef) #8 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.closureFunctionGoroutine$1$gowrapper" to i32), i8* nonnull %1, i32 %stacksize, i8* undef) #8 +- %5 = load i32, i32* %0, align 4 +- call void @runtime.printint32(i32 %5, i8* undef) #8 ++ %n = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #8 ++ store i32 3, ptr %n, align 4 ++ %0 = call ptr @runtime.alloc(i32 8, ptr null, ptr undef) #8 ++ store i32 5, ptr %0, align 4 ++ %1 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 ++ store ptr %n, ptr %1, align 4 ++ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"main.closureFunctionGoroutine$1$gowrapper" to i32), ptr undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.closureFunctionGoroutine$1$gowrapper" to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #8 ++ %2 = load i32, ptr %n, align 4 ++ call void @runtime.printint32(i32 %2, ptr undef) #8 + ret void + } + + ; Function Attrs: nounwind +-define internal void @"main.closureFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { ++define internal void @"main.closureFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { + entry: +- %unpack.ptr = bitcast i8* %context to i32* +- store i32 7, i32* %unpack.ptr, align 4 ++ store i32 7, ptr %context, align 4 + ret void + } + + ; Function Attrs: nounwind +-define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #4 { ++define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #4 { + entry: +- %1 = bitcast i8* %0 to i32* +- %2 = load i32, i32* %1, align 4 +- %3 = getelementptr inbounds i8, i8* %0, i32 4 +- %4 = bitcast i8* %3 to i8** +- %5 = load i8*, i8** %4, align 4 +- call void @"main.closureFunctionGoroutine$1"(i32 %2, i8* %5) ++ %1 = load i32, ptr %0, align 4 ++ %2 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 ++ %3 = load ptr, ptr %2, align 4 ++ call void @"main.closureFunctionGoroutine$1"(i32 %1, ptr %3) + ret void + } + +-declare void @runtime.printint32(i32, i8*) #0 ++declare void @runtime.printint32(i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.funcGoroutine(i8* %fn.context, void ()* %fn.funcptr, i8* %context) unnamed_addr #1 { ++define hidden void @main.funcGoroutine(ptr %fn.context, ptr %fn.funcptr, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i8* @runtime.alloc(i32 12, i8* null, i8* undef) #8 +- %1 = bitcast i8* %0 to i32* +- store i32 5, i32* %1, align 4 +- %2 = getelementptr inbounds i8, i8* %0, i32 4 +- %3 = bitcast i8* %2 to i8** +- store i8* %fn.context, i8** %3, align 4 +- %4 = getelementptr inbounds i8, i8* %0, i32 8 +- %5 = bitcast i8* %4 to void ()** +- store void ()* %fn.funcptr, void ()** %5, align 4 +- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @main.funcGoroutine.gowrapper to i32), i8* undef) #8 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @main.funcGoroutine.gowrapper to i32), i8* nonnull %0, i32 %stacksize, i8* undef) #8 ++ %0 = call ptr @runtime.alloc(i32 12, ptr null, ptr undef) #8 ++ store i32 5, ptr %0, align 4 ++ %1 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 ++ store ptr %fn.context, ptr %1, align 4 ++ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 ++ store ptr %fn.funcptr, ptr %2, align 4 ++ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @main.funcGoroutine.gowrapper to i32), ptr undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @main.funcGoroutine.gowrapper to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #8 + ret void + } + + ; Function Attrs: nounwind +-define linkonce_odr void @main.funcGoroutine.gowrapper(i8* %0) unnamed_addr #5 { ++define linkonce_odr void @main.funcGoroutine.gowrapper(ptr %0) unnamed_addr #5 { + entry: +- %1 = bitcast i8* %0 to i32* +- %2 = load i32, i32* %1, align 4 +- %3 = getelementptr inbounds i8, i8* %0, i32 4 +- %4 = bitcast i8* %3 to i8** +- %5 = load i8*, i8** %4, align 4 +- %6 = getelementptr inbounds i8, i8* %0, i32 8 +- %7 = bitcast i8* %6 to void (i32, i8*)** +- %8 = load void (i32, i8*)*, void (i32, i8*)** %7, align 4 +- call void %8(i32 %2, i8* %5) #8 ++ %1 = load i32, ptr %0, align 4 ++ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 ++ %3 = load ptr, ptr %2, align 4 ++ %4 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 ++ %5 = load ptr, ptr %4, align 4 ++ call void %5(i32 %1, ptr %3) #8 + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.recoverBuiltinGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.recoverBuiltinGoroutine(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.copyBuiltinGoroutine(i8* %dst.data, i32 %dst.len, i32 %dst.cap, i8* %src.data, i32 %src.len, i32 %src.cap, i8* %context) unnamed_addr #1 { ++define hidden void @main.copyBuiltinGoroutine(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #1 { + entry: +- %copy.n = call i32 @runtime.sliceCopy(i8* %dst.data, i8* %src.data, i32 %dst.len, i32 %src.len, i32 1, i8* undef) #8 ++ %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 1, ptr undef) #8 + ret void + } + +-declare i32 @runtime.sliceCopy(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i32, i8*) #0 ++declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.closeBuiltinGoroutine(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { ++define hidden void @main.closeBuiltinGoroutine(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.chanClose(%runtime.channel* %ch, i8* undef) #8 ++ call void @runtime.chanClose(ptr %ch, ptr undef) #8 + ret void + } + +-declare void @runtime.chanClose(%runtime.channel* dereferenceable_or_null(32), i8*) #0 ++declare void @runtime.chanClose(ptr dereferenceable_or_null(32), ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.startInterfaceMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden void @main.startInterfaceMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef) #8 +- %1 = bitcast i8* %0 to i8** +- store i8* %itf.value, i8** %1, align 4 +- %2 = getelementptr inbounds i8, i8* %0, i32 4 +- %.repack = bitcast i8* %2 to i8** +- store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"main$string", i32 0, i32 0), i8** %.repack, align 4 +- %.repack1 = getelementptr inbounds i8, i8* %0, i32 8 +- %3 = bitcast i8* %.repack1 to i32* +- store i32 4, i32* %3, align 4 +- %4 = getelementptr inbounds i8, i8* %0, i32 12 +- %5 = bitcast i8* %4 to i32* +- store i32 %itf.typecode, i32* %5, align 4 +- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), i8* undef) #8 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), i8* nonnull %0, i32 %stacksize, i8* undef) #8 ++ %0 = call ptr @runtime.alloc(i32 16, ptr null, ptr undef) #8 ++ store ptr %itf.value, ptr %0, align 4 ++ %1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1 ++ store ptr @"main$string", ptr %1, align 4 ++ %.repack1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1, i32 1 ++ store i32 4, ptr %.repack1, align 4 ++ %2 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 2 ++ store i32 %itf.typecode, ptr %2, align 4 ++ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #8 + ret void + } + +-declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8*, i8*, i32, i32, i8*) #6 ++declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr, ptr, i32, i32, ptr) #6 + + ; Function Attrs: nounwind +-define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(i8* %0) unnamed_addr #7 { ++define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(ptr %0) unnamed_addr #7 { + entry: +- %1 = bitcast i8* %0 to i8** +- %2 = load i8*, i8** %1, align 4 +- %3 = getelementptr inbounds i8, i8* %0, i32 4 +- %4 = bitcast i8* %3 to i8** +- %5 = load i8*, i8** %4, align 4 +- %6 = getelementptr inbounds i8, i8* %0, i32 8 +- %7 = bitcast i8* %6 to i32* +- %8 = load i32, i32* %7, align 4 +- %9 = getelementptr inbounds i8, i8* %0, i32 12 +- %10 = bitcast i8* %9 to i32* +- %11 = load i32, i32* %10, align 4 +- call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8* %2, i8* %5, i32 %8, i32 %11, i8* undef) #8 ++ %1 = load ptr, ptr %0, align 4 ++ %2 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 1 ++ %3 = load ptr, ptr %2, align 4 ++ %4 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 2 ++ %5 = load i32, ptr %4, align 4 ++ %6 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 3 ++ %7 = load i32, ptr %6, align 4 ++ call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr %1, ptr %3, i32 %5, i32 %7, ptr undef) #8 + ret void + } + +diff --git a/compiler/testdata/goroutine-wasm-asyncify.ll b/compiler/testdata/goroutine-wasm-asyncify.ll +index 21da7477..280f216a 100644 +--- a/compiler/testdata/goroutine-wasm-asyncify.ll ++++ b/compiler/testdata/goroutine-wasm-asyncify.ll +@@ -3,210 +3,184 @@ source_filename = "goroutine.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } +-%runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } +-%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state", i8* } +-%"internal/task.gcData" = type { i8* } +-%"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } +-%"internal/task.stackState" = type { i32, i32 } +-%runtime.chanSelectState = type { %runtime.channel*, i8* } ++%runtime._string = type { ptr, i32 } + + @"main$string" = internal unnamed_addr constant [4 x i8] c"test", align 1 + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.regularFunctionGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.regularFunctionGoroutine(ptr %context) unnamed_addr #1 { + entry: +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.regularFunction$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 16384, i8* undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.regularFunction$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 16384, ptr undef) #8 + ret void + } + +-declare void @main.regularFunction(i32, i8*) #0 ++declare void @main.regularFunction(i32, ptr) #0 + +-declare void @runtime.deadlock(i8*) #0 ++declare void @runtime.deadlock(ptr) #0 + + ; Function Attrs: nounwind +-define linkonce_odr void @"main.regularFunction$gowrapper"(i8* %0) unnamed_addr #2 { ++define linkonce_odr void @"main.regularFunction$gowrapper"(ptr %0) unnamed_addr #2 { + entry: +- %unpack.int = ptrtoint i8* %0 to i32 +- call void @main.regularFunction(i32 %unpack.int, i8* undef) #8 +- call void @runtime.deadlock(i8* undef) #8 ++ %unpack.int = ptrtoint ptr %0 to i32 ++ call void @main.regularFunction(i32 %unpack.int, ptr undef) #8 ++ call void @runtime.deadlock(ptr undef) #8 + unreachable + } + +-declare void @"internal/task.start"(i32, i8*, i32, i8*) #0 ++declare void @"internal/task.start"(i32, ptr, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.inlineFunctionGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.inlineFunctionGoroutine(ptr %context) unnamed_addr #1 { + entry: +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.inlineFunctionGoroutine$1$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 16384, i8* undef) #8 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.inlineFunctionGoroutine$1$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 16384, ptr undef) #8 + ret void + } + + ; Function Attrs: nounwind +-define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { ++define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #3 { ++define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #3 { + entry: +- %unpack.int = ptrtoint i8* %0 to i32 +- call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, i8* undef) +- call void @runtime.deadlock(i8* undef) #8 ++ %unpack.int = ptrtoint ptr %0 to i32 ++ call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, ptr undef) ++ call void @runtime.deadlock(ptr undef) #8 + unreachable + } + + ; Function Attrs: nounwind +-define hidden void @main.closureFunctionGoroutine(i8* %context) unnamed_addr #1 { +-entry: +- %n = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #8 +- %0 = bitcast i8* %n to i32* +- call void @runtime.trackPointer(i8* nonnull %n, i8* undef) #8 +- store i32 3, i32* %0, align 4 +- call void @runtime.trackPointer(i8* nonnull %n, i8* undef) #8 +- call void @runtime.trackPointer(i8* bitcast (void (i32, i8*)* @"main.closureFunctionGoroutine$1" to i8*), i8* undef) #8 +- %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef) #8 +- call void @runtime.trackPointer(i8* nonnull %1, i8* undef) #8 +- %2 = bitcast i8* %1 to i32* +- store i32 5, i32* %2, align 4 +- %3 = getelementptr inbounds i8, i8* %1, i32 4 +- %4 = bitcast i8* %3 to i8** +- store i8* %n, i8** %4, align 4 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.closureFunctionGoroutine$1$gowrapper" to i32), i8* nonnull %1, i32 16384, i8* undef) #8 +- %5 = load i32, i32* %0, align 4 +- call void @runtime.printint32(i32 %5, i8* undef) #8 ++define hidden void @main.closureFunctionGoroutine(ptr %context) unnamed_addr #1 { ++entry: ++ %n = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #8 ++ call void @runtime.trackPointer(ptr nonnull %n, ptr undef) #8 ++ store i32 3, ptr %n, align 4 ++ call void @runtime.trackPointer(ptr nonnull %n, ptr undef) #8 ++ call void @runtime.trackPointer(ptr nonnull @"main.closureFunctionGoroutine$1", ptr undef) #8 ++ %0 = call ptr @runtime.alloc(i32 8, ptr null, ptr undef) #8 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #8 ++ store i32 5, ptr %0, align 4 ++ %1 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 ++ store ptr %n, ptr %1, align 4 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.closureFunctionGoroutine$1$gowrapper" to i32), ptr nonnull %0, i32 16384, ptr undef) #8 ++ %2 = load i32, ptr %n, align 4 ++ call void @runtime.printint32(i32 %2, ptr undef) #8 + ret void + } + + ; Function Attrs: nounwind +-define internal void @"main.closureFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { ++define internal void @"main.closureFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { + entry: +- %unpack.ptr = bitcast i8* %context to i32* +- store i32 7, i32* %unpack.ptr, align 4 ++ store i32 7, ptr %context, align 4 + ret void + } + + ; Function Attrs: nounwind +-define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #4 { ++define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #4 { + entry: +- %1 = bitcast i8* %0 to i32* +- %2 = load i32, i32* %1, align 4 +- %3 = getelementptr inbounds i8, i8* %0, i32 4 +- %4 = bitcast i8* %3 to i8** +- %5 = load i8*, i8** %4, align 4 +- call void @"main.closureFunctionGoroutine$1"(i32 %2, i8* %5) +- call void @runtime.deadlock(i8* undef) #8 ++ %1 = load i32, ptr %0, align 4 ++ %2 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 ++ %3 = load ptr, ptr %2, align 4 ++ call void @"main.closureFunctionGoroutine$1"(i32 %1, ptr %3) ++ call void @runtime.deadlock(ptr undef) #8 + unreachable + } + +-declare void @runtime.printint32(i32, i8*) #0 ++declare void @runtime.printint32(i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.funcGoroutine(i8* %fn.context, void ()* %fn.funcptr, i8* %context) unnamed_addr #1 { ++define hidden void @main.funcGoroutine(ptr %fn.context, ptr %fn.funcptr, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i8* @runtime.alloc(i32 12, i8* null, i8* undef) #8 +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #8 +- %1 = bitcast i8* %0 to i32* +- store i32 5, i32* %1, align 4 +- %2 = getelementptr inbounds i8, i8* %0, i32 4 +- %3 = bitcast i8* %2 to i8** +- store i8* %fn.context, i8** %3, align 4 +- %4 = getelementptr inbounds i8, i8* %0, i32 8 +- %5 = bitcast i8* %4 to void ()** +- store void ()* %fn.funcptr, void ()** %5, align 4 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @main.funcGoroutine.gowrapper to i32), i8* nonnull %0, i32 16384, i8* undef) #8 ++ %0 = call ptr @runtime.alloc(i32 12, ptr null, ptr undef) #8 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #8 ++ store i32 5, ptr %0, align 4 ++ %1 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 ++ store ptr %fn.context, ptr %1, align 4 ++ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 ++ store ptr %fn.funcptr, ptr %2, align 4 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @main.funcGoroutine.gowrapper to i32), ptr nonnull %0, i32 16384, ptr undef) #8 + ret void + } + + ; Function Attrs: nounwind +-define linkonce_odr void @main.funcGoroutine.gowrapper(i8* %0) unnamed_addr #5 { ++define linkonce_odr void @main.funcGoroutine.gowrapper(ptr %0) unnamed_addr #5 { + entry: +- %1 = bitcast i8* %0 to i32* +- %2 = load i32, i32* %1, align 4 +- %3 = getelementptr inbounds i8, i8* %0, i32 4 +- %4 = bitcast i8* %3 to i8** +- %5 = load i8*, i8** %4, align 4 +- %6 = getelementptr inbounds i8, i8* %0, i32 8 +- %7 = bitcast i8* %6 to void (i32, i8*)** +- %8 = load void (i32, i8*)*, void (i32, i8*)** %7, align 4 +- call void %8(i32 %2, i8* %5) #8 +- call void @runtime.deadlock(i8* undef) #8 ++ %1 = load i32, ptr %0, align 4 ++ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 ++ %3 = load ptr, ptr %2, align 4 ++ %4 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 ++ %5 = load ptr, ptr %4, align 4 ++ call void %5(i32 %1, ptr %3) #8 ++ call void @runtime.deadlock(ptr undef) #8 + unreachable + } + + ; Function Attrs: nounwind +-define hidden void @main.recoverBuiltinGoroutine(i8* %context) unnamed_addr #1 { ++define hidden void @main.recoverBuiltinGoroutine(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.copyBuiltinGoroutine(i8* %dst.data, i32 %dst.len, i32 %dst.cap, i8* %src.data, i32 %src.len, i32 %src.cap, i8* %context) unnamed_addr #1 { ++define hidden void @main.copyBuiltinGoroutine(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #1 { + entry: +- %copy.n = call i32 @runtime.sliceCopy(i8* %dst.data, i8* %src.data, i32 %dst.len, i32 %src.len, i32 1, i8* undef) #8 ++ %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 1, ptr undef) #8 + ret void + } + +-declare i32 @runtime.sliceCopy(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i32, i8*) #0 ++declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.closeBuiltinGoroutine(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { ++define hidden void @main.closeBuiltinGoroutine(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.chanClose(%runtime.channel* %ch, i8* undef) #8 ++ call void @runtime.chanClose(ptr %ch, ptr undef) #8 + ret void + } + +-declare void @runtime.chanClose(%runtime.channel* dereferenceable_or_null(32), i8*) #0 ++declare void @runtime.chanClose(ptr dereferenceable_or_null(32), ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.startInterfaceMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden void @main.startInterfaceMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef) #8 +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #8 +- %1 = bitcast i8* %0 to i8** +- store i8* %itf.value, i8** %1, align 4 +- %2 = getelementptr inbounds i8, i8* %0, i32 4 +- %.repack = bitcast i8* %2 to i8** +- store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"main$string", i32 0, i32 0), i8** %.repack, align 4 +- %.repack1 = getelementptr inbounds i8, i8* %0, i32 8 +- %3 = bitcast i8* %.repack1 to i32* +- store i32 4, i32* %3, align 4 +- %4 = getelementptr inbounds i8, i8* %0, i32 12 +- %5 = bitcast i8* %4 to i32* +- store i32 %itf.typecode, i32* %5, align 4 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), i8* nonnull %0, i32 16384, i8* undef) #8 ++ %0 = call ptr @runtime.alloc(i32 16, ptr null, ptr undef) #8 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #8 ++ store ptr %itf.value, ptr %0, align 4 ++ %1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1 ++ store ptr @"main$string", ptr %1, align 4 ++ %.repack1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1, i32 1 ++ store i32 4, ptr %.repack1, align 4 ++ %2 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 2 ++ store i32 %itf.typecode, ptr %2, align 4 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr nonnull %0, i32 16384, ptr undef) #8 + ret void + } + +-declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8*, i8*, i32, i32, i8*) #6 ++declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr, ptr, i32, i32, ptr) #6 + + ; Function Attrs: nounwind +-define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(i8* %0) unnamed_addr #7 { ++define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(ptr %0) unnamed_addr #7 { + entry: +- %1 = bitcast i8* %0 to i8** +- %2 = load i8*, i8** %1, align 4 +- %3 = getelementptr inbounds i8, i8* %0, i32 4 +- %4 = bitcast i8* %3 to i8** +- %5 = load i8*, i8** %4, align 4 +- %6 = getelementptr inbounds i8, i8* %0, i32 8 +- %7 = bitcast i8* %6 to i32* +- %8 = load i32, i32* %7, align 4 +- %9 = getelementptr inbounds i8, i8* %0, i32 12 +- %10 = bitcast i8* %9 to i32* +- %11 = load i32, i32* %10, align 4 +- call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8* %2, i8* %5, i32 %8, i32 %11, i8* undef) #8 +- call void @runtime.deadlock(i8* undef) #8 ++ %1 = load ptr, ptr %0, align 4 ++ %2 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 1 ++ %3 = load ptr, ptr %2, align 4 ++ %4 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 2 ++ %5 = load i32, ptr %4, align 4 ++ %6 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 3 ++ %7 = load i32, ptr %6, align 4 ++ call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr %1, ptr %3, i32 %5, i32 %7, ptr undef) #8 ++ call void @runtime.deadlock(ptr undef) #8 + unreachable + } + +diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll +index 0b44585a..38d4e567 100644 +--- a/compiler/testdata/interface.ll ++++ b/compiler/testdata/interface.ll +@@ -3,71 +3,70 @@ source_filename = "interface.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +-%runtime.interfaceMethodInfo = type { i8*, i32 } +-%runtime._interface = type { i32, i8* } +-%runtime._string = type { i8*, i32 } +- +-@"reflect/types.type:basic:int" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* null, i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:basic:int", i32 0 } +-@"reflect/types.type:pointer:basic:int" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } +-@"reflect/types.type:pointer:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:named:error", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } +-@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:named:error", i32 ptrtoint (i1 (i32)* @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } +-@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}", i32 ptrtoint (i1 (i32)* @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } ++%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } ++%runtime._interface = type { i32, ptr } ++%runtime._string = type { ptr, i32 } ++ ++@"reflect/types.type:basic:int" = linkonce_odr constant %runtime.typecodeID { ptr null, i32 0, ptr null, ptr @"reflect/types.type:pointer:basic:int", i32 0 } ++@"reflect/types.type:pointer:basic:int" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:int", i32 0, ptr null, ptr null, i32 0 } ++@"reflect/types.type:pointer:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:named:error", i32 0, ptr null, ptr null, i32 0 } ++@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr @"reflect/types.type:pointer:named:error", i32 ptrtoint (ptr @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } ++@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.interface:interface{Error() string}$interface", i32 0, ptr null, ptr @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}", i32 ptrtoint (ptr @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } + @"reflect/methods.Error() string" = linkonce_odr constant i8 0, align 1 +-@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.Error() string"] +-@"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } +-@"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{String:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } +-@"reflect/types.type:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{String() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}", i32 ptrtoint (i1 (i32)* @"interface:{String:func:{}{basic:string}}.$typeassert" to i32) } ++@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.Error() string"] ++@"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 0 } ++@"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{String:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 0 } ++@"reflect/types.type:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.interface:interface{String() string}$interface", i32 0, ptr null, ptr @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}", i32 ptrtoint (ptr @"interface:{String:func:{}{basic:string}}.$typeassert" to i32) } + @"reflect/methods.String() string" = linkonce_odr constant i8 0, align 1 +-@"reflect/types.interface:interface{String() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.String() string"] ++@"reflect/types.interface:interface{String() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.String() string"] + @"reflect/types.typeid:basic:int" = external constant i8 + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden %runtime._interface @main.simpleType(i8* %context) unnamed_addr #1 { ++define hidden %runtime._interface @main.simpleType(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* null, i8* undef) #6 +- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:int" to i32), i8* null } ++ call void @runtime.trackPointer(ptr null, ptr undef) #6 ++ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:basic:int" to i32), ptr null } + } + + ; Function Attrs: nounwind +-define hidden %runtime._interface @main.pointerType(i8* %context) unnamed_addr #1 { ++define hidden %runtime._interface @main.pointerType(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* null, i8* undef) #6 +- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:pointer:basic:int" to i32), i8* null } ++ call void @runtime.trackPointer(ptr null, ptr undef) #6 ++ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:pointer:basic:int" to i32), ptr null } + } + + ; Function Attrs: nounwind +-define hidden %runtime._interface @main.interfaceType(i8* %context) unnamed_addr #1 { ++define hidden %runtime._interface @main.interfaceType(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* null, i8* undef) #6 +- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:pointer:named:error" to i32), i8* null } ++ call void @runtime.trackPointer(ptr null, ptr undef) #6 ++ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:pointer:named:error" to i32), ptr null } + } + + declare i1 @"interface:{Error:func:{}{basic:string}}.$typeassert"(i32) #2 + + ; Function Attrs: nounwind +-define hidden %runtime._interface @main.anonymousInterfaceType(i8* %context) unnamed_addr #1 { ++define hidden %runtime._interface @main.anonymousInterfaceType(ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* null, i8* undef) #6 +- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" to i32), i8* null } ++ call void @runtime.trackPointer(ptr null, ptr undef) #6 ++ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" to i32), ptr null } + } + + declare i1 @"interface:{String:func:{}{basic:string}}.$typeassert"(i32) #3 + + ; Function Attrs: nounwind +-define hidden i1 @main.isInt(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.isInt(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: +- %typecode = call i1 @runtime.typeAssert(i32 %itf.typecode, i8* nonnull @"reflect/types.typeid:basic:int", i8* undef) #6 ++ %typecode = call i1 @runtime.typeAssert(i32 %itf.typecode, ptr nonnull @"reflect/types.typeid:basic:int", ptr undef) #6 + br i1 %typecode, label %typeassert.ok, label %typeassert.next + + typeassert.next: ; preds = %typeassert.ok, %entry +@@ -77,10 +76,10 @@ typeassert.ok: ; preds = %entry + br label %typeassert.next + } + +-declare i1 @runtime.typeAssert(i32, i8* dereferenceable_or_null(1), i8*) #0 ++declare i1 @runtime.typeAssert(i32, ptr dereferenceable_or_null(1), ptr) #0 + + ; Function Attrs: nounwind +-define hidden i1 @main.isError(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.isError(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: + %0 = call i1 @"interface:{Error:func:{}{basic:string}}.$typeassert"(i32 %itf.typecode) #6 + br i1 %0, label %typeassert.ok, label %typeassert.next +@@ -93,7 +92,7 @@ typeassert.ok: ; preds = %entry + } + + ; Function Attrs: nounwind +-define hidden i1 @main.isStringer(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.isStringer(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: + %0 = call i1 @"interface:{String:func:{}{basic:string}}.$typeassert"(i32 %itf.typecode) #6 + br i1 %0, label %typeassert.ok, label %typeassert.next +@@ -106,24 +105,24 @@ typeassert.ok: ; preds = %entry + } + + ; Function Attrs: nounwind +-define hidden i8 @main.callFooMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden i8 @main.callFooMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(i8* %itf.value, i32 3, i32 %itf.typecode, i8* undef) #6 ++ %0 = call i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(ptr %itf.value, i32 3, i32 %itf.typecode, ptr undef) #6 + ret i8 %0 + } + +-declare i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(i8*, i32, i32, i8*) #4 ++declare i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(ptr, i32, i32, ptr) #4 + + ; Function Attrs: nounwind +-define hidden %runtime._string @main.callErrorMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { ++define hidden %runtime._string @main.callErrorMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { + entry: +- %0 = call %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(i8* %itf.value, i32 %itf.typecode, i8* undef) #6 ++ %0 = call %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(ptr %itf.value, i32 %itf.typecode, ptr undef) #6 + %1 = extractvalue %runtime._string %0, 0 +- call void @runtime.trackPointer(i8* %1, i8* undef) #6 ++ call void @runtime.trackPointer(ptr %1, ptr undef) #6 + ret %runtime._string %0 + } + +-declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(i8*, i32, i8*) #5 ++declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(ptr, i32, ptr) #5 + + attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +diff --git a/compiler/testdata/pointer.ll b/compiler/testdata/pointer.ll +index cedea380..9bc8bd35 100644 +--- a/compiler/testdata/pointer.ll ++++ b/compiler/testdata/pointer.ll +@@ -3,76 +3,72 @@ source_filename = "pointer.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden [0 x i32] @main.pointerDerefZero([0 x i32]* %x, i8* %context) unnamed_addr #1 { ++define hidden [0 x i32] @main.pointerDerefZero(ptr %x, ptr %context) unnamed_addr #1 { + entry: + ret [0 x i32] zeroinitializer + } + + ; Function Attrs: nounwind +-define hidden i32* @main.pointerCastFromUnsafe(i8* %x, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.pointerCastFromUnsafe(ptr %x, ptr %context) unnamed_addr #1 { + entry: +- %0 = bitcast i8* %x to i32* +- call void @runtime.trackPointer(i8* %x, i8* undef) #2 +- ret i32* %0 ++ call void @runtime.trackPointer(ptr %x, ptr undef) #2 ++ ret ptr %x + } + + ; Function Attrs: nounwind +-define hidden i8* @main.pointerCastToUnsafe(i32* dereferenceable_or_null(4) %x, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.pointerCastToUnsafe(ptr dereferenceable_or_null(4) %x, ptr %context) unnamed_addr #1 { + entry: +- %0 = bitcast i32* %x to i8* +- call void @runtime.trackPointer(i8* %0, i8* undef) #2 +- ret i8* %0 ++ call void @runtime.trackPointer(ptr %x, ptr undef) #2 ++ ret ptr %x + } + + ; Function Attrs: nounwind +-define hidden i8* @main.pointerCastToUnsafeNoop(i8* dereferenceable_or_null(1) %x, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.pointerCastToUnsafeNoop(ptr dereferenceable_or_null(1) %x, ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* %x, i8* undef) #2 +- ret i8* %x ++ call void @runtime.trackPointer(ptr %x, ptr undef) #2 ++ ret ptr %x + } + + ; Function Attrs: nounwind +-define hidden i8* @main.pointerUnsafeGEPFixedOffset(i8* dereferenceable_or_null(1) %ptr, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.pointerUnsafeGEPFixedOffset(ptr dereferenceable_or_null(1) %ptr, ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* %ptr, i8* undef) #2 +- %0 = getelementptr inbounds i8, i8* %ptr, i32 10 +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 +- ret i8* %0 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ %0 = getelementptr inbounds i8, ptr %ptr, i32 10 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 ++ ret ptr %0 + } + + ; Function Attrs: nounwind +-define hidden i8* @main.pointerUnsafeGEPByteOffset(i8* dereferenceable_or_null(1) %ptr, i32 %offset, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.pointerUnsafeGEPByteOffset(ptr dereferenceable_or_null(1) %ptr, i32 %offset, ptr %context) unnamed_addr #1 { + entry: +- call void @runtime.trackPointer(i8* %ptr, i8* undef) #2 +- %0 = getelementptr inbounds i8, i8* %ptr, i32 %offset +- call void @runtime.trackPointer(i8* %0, i8* undef) #2 +- call void @runtime.trackPointer(i8* %0, i8* undef) #2 +- ret i8* %0 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ %0 = getelementptr inbounds i8, ptr %ptr, i32 %offset ++ call void @runtime.trackPointer(ptr %0, ptr undef) #2 ++ call void @runtime.trackPointer(ptr %0, ptr undef) #2 ++ ret ptr %0 + } + + ; Function Attrs: nounwind +-define hidden i32* @main.pointerUnsafeGEPIntOffset(i32* dereferenceable_or_null(4) %ptr, i32 %offset, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.pointerUnsafeGEPIntOffset(ptr dereferenceable_or_null(4) %ptr, i32 %offset, ptr %context) unnamed_addr #1 { + entry: +- %0 = bitcast i32* %ptr to i8* +- call void @runtime.trackPointer(i8* %0, i8* undef) #2 +- %1 = getelementptr i32, i32* %ptr, i32 %offset +- %2 = bitcast i32* %1 to i8* +- call void @runtime.trackPointer(i8* %2, i8* undef) #2 +- %3 = bitcast i32* %1 to i8* +- call void @runtime.trackPointer(i8* %3, i8* undef) #2 +- ret i32* %1 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ %0 = shl i32 %offset, 2 ++ %1 = getelementptr inbounds i8, ptr %ptr, i32 %0 ++ call void @runtime.trackPointer(ptr %1, ptr undef) #2 ++ call void @runtime.trackPointer(ptr %1, ptr undef) #2 ++ ret ptr %1 + } + + attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +diff --git a/compiler/testdata/pragma.ll b/compiler/testdata/pragma.ll +index b243602d..c49c83bd 100644 +--- a/compiler/testdata/pragma.ll ++++ b/compiler/testdata/pragma.ll +@@ -10,12 +10,12 @@ target triple = "wasm32-unknown-wasi" + @undefinedGlobalNotInSection = external global i32, align 4 + @main.multipleGlobalPragmas = hidden global i32 0, section ".global_section", align 1024 + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } +@@ -27,27 +27,27 @@ entry: + } + + ; Function Attrs: nounwind +-define hidden void @somepkg.someFunction1(i8* %context) unnamed_addr #1 { ++define hidden void @somepkg.someFunction1(ptr %context) unnamed_addr #1 { + entry: + ret void + } + +-declare void @somepkg.someFunction2(i8*) #0 ++declare void @somepkg.someFunction2(ptr) #0 + + ; Function Attrs: inlinehint nounwind +-define hidden void @main.inlineFunc(i8* %context) unnamed_addr #3 { ++define hidden void @main.inlineFunc(ptr %context) unnamed_addr #3 { + entry: + ret void + } + + ; Function Attrs: noinline nounwind +-define hidden void @main.noinlineFunc(i8* %context) unnamed_addr #4 { ++define hidden void @main.noinlineFunc(ptr %context) unnamed_addr #4 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden void @main.functionInSection(i8* %context) unnamed_addr #1 section ".special_function_section" { ++define hidden void @main.functionInSection(ptr %context) unnamed_addr #1 section ".special_function_section" { + entry: + ret void + } +@@ -58,7 +58,7 @@ entry: + ret void + } + +-declare void @main.undefinedFunctionNotInSection(i8*) #0 ++declare void @main.undefinedFunctionNotInSection(ptr) #0 + + attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll +index c2e3ebd9..56e40f5f 100644 +--- a/compiler/testdata/slice.ll ++++ b/compiler/testdata/slice.ll +@@ -3,286 +3,270 @@ source_filename = "slice.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden i32 @main.sliceLen(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.sliceLen(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #1 { + entry: + ret i32 %ints.len + } + + ; Function Attrs: nounwind +-define hidden i32 @main.sliceCap(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.sliceCap(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #1 { + entry: + ret i32 %ints.cap + } + + ; Function Attrs: nounwind +-define hidden i32 @main.sliceElement(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i32 %index, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.sliceElement(ptr %ints.data, i32 %ints.len, i32 %ints.cap, i32 %index, ptr %context) unnamed_addr #1 { + entry: + %.not = icmp ult i32 %index, %ints.len + br i1 %.not, label %lookup.next, label %lookup.throw + + lookup.next: ; preds = %entry +- %0 = getelementptr inbounds i32, i32* %ints.data, i32 %index +- %1 = load i32, i32* %0, align 4 ++ %0 = getelementptr inbounds i32, ptr %ints.data, i32 %index ++ %1 = load i32, ptr %0, align 4 + ret i32 %1 + + lookup.throw: ; preds = %entry +- call void @runtime.lookupPanic(i8* undef) #2 ++ call void @runtime.lookupPanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.lookupPanic(i8*) #0 ++declare void @runtime.lookupPanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden { i32*, i32, i32 } @main.sliceAppendValues(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.sliceAppendValues(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #1 { + entry: +- %varargs = call i8* @runtime.alloc(i32 12, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %varargs, i8* undef) #2 +- %0 = bitcast i8* %varargs to i32* +- store i32 1, i32* %0, align 4 +- %1 = getelementptr inbounds i8, i8* %varargs, i32 4 +- %2 = bitcast i8* %1 to i32* +- store i32 2, i32* %2, align 4 +- %3 = getelementptr inbounds i8, i8* %varargs, i32 8 +- %4 = bitcast i8* %3 to i32* +- store i32 3, i32* %4, align 4 +- %append.srcPtr = bitcast i32* %ints.data to i8* +- %append.new = call { i8*, i32, i32 } @runtime.sliceAppend(i8* %append.srcPtr, i8* nonnull %varargs, i32 %ints.len, i32 %ints.cap, i32 3, i32 4, i8* undef) #2 +- %append.newPtr = extractvalue { i8*, i32, i32 } %append.new, 0 +- %append.newBuf = bitcast i8* %append.newPtr to i32* +- %append.newLen = extractvalue { i8*, i32, i32 } %append.new, 1 +- %append.newCap = extractvalue { i8*, i32, i32 } %append.new, 2 +- %5 = insertvalue { i32*, i32, i32 } undef, i32* %append.newBuf, 0 +- %6 = insertvalue { i32*, i32, i32 } %5, i32 %append.newLen, 1 +- %7 = insertvalue { i32*, i32, i32 } %6, i32 %append.newCap, 2 +- call void @runtime.trackPointer(i8* %append.newPtr, i8* undef) #2 +- ret { i32*, i32, i32 } %7 ++ %varargs = call ptr @runtime.alloc(i32 12, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %varargs, ptr undef) #2 ++ store i32 1, ptr %varargs, align 4 ++ %0 = getelementptr inbounds [3 x i32], ptr %varargs, i32 0, i32 1 ++ store i32 2, ptr %0, align 4 ++ %1 = getelementptr inbounds [3 x i32], ptr %varargs, i32 0, i32 2 ++ store i32 3, ptr %1, align 4 ++ %append.new = call { ptr, i32, i32 } @runtime.sliceAppend(ptr %ints.data, ptr nonnull %varargs, i32 %ints.len, i32 %ints.cap, i32 3, i32 4, ptr undef) #2 ++ %append.newPtr = extractvalue { ptr, i32, i32 } %append.new, 0 ++ %append.newLen = extractvalue { ptr, i32, i32 } %append.new, 1 ++ %append.newCap = extractvalue { ptr, i32, i32 } %append.new, 2 ++ %2 = insertvalue { ptr, i32, i32 } undef, ptr %append.newPtr, 0 ++ %3 = insertvalue { ptr, i32, i32 } %2, i32 %append.newLen, 1 ++ %4 = insertvalue { ptr, i32, i32 } %3, i32 %append.newCap, 2 ++ call void @runtime.trackPointer(ptr %append.newPtr, ptr undef) #2 ++ ret { ptr, i32, i32 } %4 + } + +-declare { i8*, i32, i32 } @runtime.sliceAppend(i8*, i8* nocapture readonly, i32, i32, i32, i32, i8*) #0 ++declare { ptr, i32, i32 } @runtime.sliceAppend(ptr, ptr nocapture readonly, i32, i32, i32, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden { i32*, i32, i32 } @main.sliceAppendSlice(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i32* %added.data, i32 %added.len, i32 %added.cap, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.sliceAppendSlice(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %added.data, i32 %added.len, i32 %added.cap, ptr %context) unnamed_addr #1 { + entry: +- %append.srcPtr = bitcast i32* %ints.data to i8* +- %append.srcPtr1 = bitcast i32* %added.data to i8* +- %append.new = call { i8*, i32, i32 } @runtime.sliceAppend(i8* %append.srcPtr, i8* %append.srcPtr1, i32 %ints.len, i32 %ints.cap, i32 %added.len, i32 4, i8* undef) #2 +- %append.newPtr = extractvalue { i8*, i32, i32 } %append.new, 0 +- %append.newBuf = bitcast i8* %append.newPtr to i32* +- %append.newLen = extractvalue { i8*, i32, i32 } %append.new, 1 +- %append.newCap = extractvalue { i8*, i32, i32 } %append.new, 2 +- %0 = insertvalue { i32*, i32, i32 } undef, i32* %append.newBuf, 0 +- %1 = insertvalue { i32*, i32, i32 } %0, i32 %append.newLen, 1 +- %2 = insertvalue { i32*, i32, i32 } %1, i32 %append.newCap, 2 +- call void @runtime.trackPointer(i8* %append.newPtr, i8* undef) #2 +- ret { i32*, i32, i32 } %2 ++ %append.new = call { ptr, i32, i32 } @runtime.sliceAppend(ptr %ints.data, ptr %added.data, i32 %ints.len, i32 %ints.cap, i32 %added.len, i32 4, ptr undef) #2 ++ %append.newPtr = extractvalue { ptr, i32, i32 } %append.new, 0 ++ %append.newLen = extractvalue { ptr, i32, i32 } %append.new, 1 ++ %append.newCap = extractvalue { ptr, i32, i32 } %append.new, 2 ++ %0 = insertvalue { ptr, i32, i32 } undef, ptr %append.newPtr, 0 ++ %1 = insertvalue { ptr, i32, i32 } %0, i32 %append.newLen, 1 ++ %2 = insertvalue { ptr, i32, i32 } %1, i32 %append.newCap, 2 ++ call void @runtime.trackPointer(ptr %append.newPtr, ptr undef) #2 ++ ret { ptr, i32, i32 } %2 + } + + ; Function Attrs: nounwind +-define hidden i32 @main.sliceCopy(i32* %dst.data, i32 %dst.len, i32 %dst.cap, i32* %src.data, i32 %src.len, i32 %src.cap, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.sliceCopy(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #1 { + entry: +- %copy.dstPtr = bitcast i32* %dst.data to i8* +- %copy.srcPtr = bitcast i32* %src.data to i8* +- %copy.n = call i32 @runtime.sliceCopy(i8* %copy.dstPtr, i8* %copy.srcPtr, i32 %dst.len, i32 %src.len, i32 4, i8* undef) #2 ++ %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 4, ptr undef) #2 + ret i32 %copy.n + } + +-declare i32 @runtime.sliceCopy(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i32, i8*) #0 ++declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden { i8*, i32, i32 } @main.makeByteSlice(i32 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.makeByteSlice(i32 %len, ptr %context) unnamed_addr #1 { + entry: + %slice.maxcap = icmp slt i32 %len, 0 + br i1 %slice.maxcap, label %slice.throw, label %slice.next + + slice.next: ; preds = %entry +- %makeslice.buf = call i8* @runtime.alloc(i32 %len, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- %0 = insertvalue { i8*, i32, i32 } undef, i8* %makeslice.buf, 0 +- %1 = insertvalue { i8*, i32, i32 } %0, i32 %len, 1 +- %2 = insertvalue { i8*, i32, i32 } %1, i32 %len, 2 +- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 +- ret { i8*, i32, i32 } %2 ++ %makeslice.buf = call ptr @runtime.alloc(i32 %len, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 ++ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 ++ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 ++ ret { ptr, i32, i32 } %2 + + slice.throw: ; preds = %entry +- call void @runtime.slicePanic(i8* undef) #2 ++ call void @runtime.slicePanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.slicePanic(i8*) #0 ++declare void @runtime.slicePanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden { i16*, i32, i32 } @main.makeInt16Slice(i32 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.makeInt16Slice(i32 %len, ptr %context) unnamed_addr #1 { + entry: + %slice.maxcap = icmp slt i32 %len, 0 + br i1 %slice.maxcap, label %slice.throw, label %slice.next + + slice.next: ; preds = %entry + %makeslice.cap = shl i32 %len, 1 +- %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- %makeslice.array = bitcast i8* %makeslice.buf to i16* +- %0 = insertvalue { i16*, i32, i32 } undef, i16* %makeslice.array, 0 +- %1 = insertvalue { i16*, i32, i32 } %0, i32 %len, 1 +- %2 = insertvalue { i16*, i32, i32 } %1, i32 %len, 2 +- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 +- ret { i16*, i32, i32 } %2 ++ %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 ++ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 ++ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 ++ ret { ptr, i32, i32 } %2 + + slice.throw: ; preds = %entry +- call void @runtime.slicePanic(i8* undef) #2 ++ call void @runtime.slicePanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden { [3 x i8]*, i32, i32 } @main.makeArraySlice(i32 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.makeArraySlice(i32 %len, ptr %context) unnamed_addr #1 { + entry: + %slice.maxcap = icmp ugt i32 %len, 1431655765 + br i1 %slice.maxcap, label %slice.throw, label %slice.next + + slice.next: ; preds = %entry + %makeslice.cap = mul i32 %len, 3 +- %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- %makeslice.array = bitcast i8* %makeslice.buf to [3 x i8]* +- %0 = insertvalue { [3 x i8]*, i32, i32 } undef, [3 x i8]* %makeslice.array, 0 +- %1 = insertvalue { [3 x i8]*, i32, i32 } %0, i32 %len, 1 +- %2 = insertvalue { [3 x i8]*, i32, i32 } %1, i32 %len, 2 +- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 +- ret { [3 x i8]*, i32, i32 } %2 ++ %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 ++ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 ++ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 ++ ret { ptr, i32, i32 } %2 + + slice.throw: ; preds = %entry +- call void @runtime.slicePanic(i8* undef) #2 ++ call void @runtime.slicePanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden { i32*, i32, i32 } @main.makeInt32Slice(i32 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.makeInt32Slice(i32 %len, ptr %context) unnamed_addr #1 { + entry: + %slice.maxcap = icmp ugt i32 %len, 1073741823 + br i1 %slice.maxcap, label %slice.throw, label %slice.next + + slice.next: ; preds = %entry + %makeslice.cap = shl i32 %len, 2 +- %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- %makeslice.array = bitcast i8* %makeslice.buf to i32* +- %0 = insertvalue { i32*, i32, i32 } undef, i32* %makeslice.array, 0 +- %1 = insertvalue { i32*, i32, i32 } %0, i32 %len, 1 +- %2 = insertvalue { i32*, i32, i32 } %1, i32 %len, 2 +- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 +- ret { i32*, i32, i32 } %2 ++ %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 ++ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 ++ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 ++ ret { ptr, i32, i32 } %2 + + slice.throw: ; preds = %entry +- call void @runtime.slicePanic(i8* undef) #2 ++ call void @runtime.slicePanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden i8* @main.Add32(i8* %p, i32 %len, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.Add32(ptr %p, i32 %len, ptr %context) unnamed_addr #1 { + entry: +- %0 = getelementptr i8, i8* %p, i32 %len +- call void @runtime.trackPointer(i8* %0, i8* undef) #2 +- ret i8* %0 ++ %0 = getelementptr i8, ptr %p, i32 %len ++ call void @runtime.trackPointer(ptr %0, ptr undef) #2 ++ ret ptr %0 + } + + ; Function Attrs: nounwind +-define hidden i8* @main.Add64(i8* %p, i64 %len, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.Add64(ptr %p, i64 %len, ptr %context) unnamed_addr #1 { + entry: + %0 = trunc i64 %len to i32 +- %1 = getelementptr i8, i8* %p, i32 %0 +- call void @runtime.trackPointer(i8* %1, i8* undef) #2 +- ret i8* %1 ++ %1 = getelementptr i8, ptr %p, i32 %0 ++ call void @runtime.trackPointer(ptr %1, ptr undef) #2 ++ ret ptr %1 + } + + ; Function Attrs: nounwind +-define hidden [4 x i32]* @main.SliceToArray(i32* %s.data, i32 %s.len, i32 %s.cap, i8* %context) unnamed_addr #1 { ++define hidden ptr @main.SliceToArray(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp ult i32 %s.len, 4 + br i1 %0, label %slicetoarray.throw, label %slicetoarray.next + + slicetoarray.next: ; preds = %entry +- %1 = bitcast i32* %s.data to [4 x i32]* +- ret [4 x i32]* %1 ++ ret ptr %s.data + + slicetoarray.throw: ; preds = %entry +- call void @runtime.sliceToArrayPointerPanic(i8* undef) #2 ++ call void @runtime.sliceToArrayPointerPanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.sliceToArrayPointerPanic(i8*) #0 ++declare void @runtime.sliceToArrayPointerPanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden [4 x i32]* @main.SliceToArrayConst(i8* %context) unnamed_addr #1 { ++define hidden ptr @main.SliceToArrayConst(ptr %context) unnamed_addr #1 { + entry: +- %makeslice = call i8* @runtime.alloc(i32 24, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 +- call void @runtime.trackPointer(i8* nonnull %makeslice, i8* undef) #2 ++ %makeslice = call ptr @runtime.alloc(i32 24, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 ++ call void @runtime.trackPointer(ptr nonnull %makeslice, ptr undef) #2 + br i1 false, label %slicetoarray.throw, label %slicetoarray.next + + slicetoarray.next: ; preds = %entry +- %0 = bitcast i8* %makeslice to [4 x i32]* +- ret [4 x i32]* %0 ++ ret ptr %makeslice + + slicetoarray.throw: ; preds = %entry + unreachable + } + + ; Function Attrs: nounwind +-define hidden { i32*, i32, i32 } @main.SliceInt(i32* dereferenceable_or_null(4) %ptr, i32 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.SliceInt(ptr dereferenceable_or_null(4) %ptr, i32 %len, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp ugt i32 %len, 1073741823 +- %1 = icmp eq i32* %ptr, null ++ %1 = icmp eq ptr %ptr, null + %2 = icmp ne i32 %len, 0 + %3 = and i1 %1, %2 + %4 = or i1 %3, %0 + br i1 %4, label %unsafe.Slice.throw, label %unsafe.Slice.next + + unsafe.Slice.next: ; preds = %entry +- %5 = insertvalue { i32*, i32, i32 } undef, i32* %ptr, 0 +- %6 = insertvalue { i32*, i32, i32 } %5, i32 %len, 1 +- %7 = insertvalue { i32*, i32, i32 } %6, i32 %len, 2 +- %8 = bitcast i32* %ptr to i8* +- call void @runtime.trackPointer(i8* %8, i8* undef) #2 +- ret { i32*, i32, i32 } %7 ++ %5 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 ++ %6 = insertvalue { ptr, i32, i32 } %5, i32 %len, 1 ++ %7 = insertvalue { ptr, i32, i32 } %6, i32 %len, 2 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ ret { ptr, i32, i32 } %7 + + unsafe.Slice.throw: ; preds = %entry +- call void @runtime.unsafeSlicePanic(i8* undef) #2 ++ call void @runtime.unsafeSlicePanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.unsafeSlicePanic(i8*) #0 ++declare void @runtime.unsafeSlicePanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden { i8*, i32, i32 } @main.SliceUint16(i8* dereferenceable_or_null(1) %ptr, i16 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.SliceUint16(ptr dereferenceable_or_null(1) %ptr, i16 %len, ptr %context) unnamed_addr #1 { + entry: +- %0 = icmp eq i8* %ptr, null ++ %0 = icmp eq ptr %ptr, null + %1 = icmp ne i16 %len, 0 + %2 = and i1 %0, %1 + br i1 %2, label %unsafe.Slice.throw, label %unsafe.Slice.next + + unsafe.Slice.next: ; preds = %entry + %3 = zext i16 %len to i32 +- %4 = insertvalue { i8*, i32, i32 } undef, i8* %ptr, 0 +- %5 = insertvalue { i8*, i32, i32 } %4, i32 %3, 1 +- %6 = insertvalue { i8*, i32, i32 } %5, i32 %3, 2 +- call void @runtime.trackPointer(i8* %ptr, i8* undef) #2 +- ret { i8*, i32, i32 } %6 ++ %4 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 ++ %5 = insertvalue { ptr, i32, i32 } %4, i32 %3, 1 ++ %6 = insertvalue { ptr, i32, i32 } %5, i32 %3, 2 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ ret { ptr, i32, i32 } %6 + + unsafe.Slice.throw: ; preds = %entry +- call void @runtime.unsafeSlicePanic(i8* undef) #2 ++ call void @runtime.unsafeSlicePanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden { i32*, i32, i32 } @main.SliceUint64(i32* dereferenceable_or_null(4) %ptr, i64 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.SliceUint64(ptr dereferenceable_or_null(4) %ptr, i64 %len, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp ugt i64 %len, 1073741823 +- %1 = icmp eq i32* %ptr, null ++ %1 = icmp eq ptr %ptr, null + %2 = icmp ne i64 %len, 0 + %3 = and i1 %1, %2 + %4 = or i1 %3, %0 +@@ -290,23 +274,22 @@ entry: + + unsafe.Slice.next: ; preds = %entry + %5 = trunc i64 %len to i32 +- %6 = insertvalue { i32*, i32, i32 } undef, i32* %ptr, 0 +- %7 = insertvalue { i32*, i32, i32 } %6, i32 %5, 1 +- %8 = insertvalue { i32*, i32, i32 } %7, i32 %5, 2 +- %9 = bitcast i32* %ptr to i8* +- call void @runtime.trackPointer(i8* %9, i8* undef) #2 +- ret { i32*, i32, i32 } %8 ++ %6 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 ++ %7 = insertvalue { ptr, i32, i32 } %6, i32 %5, 1 ++ %8 = insertvalue { ptr, i32, i32 } %7, i32 %5, 2 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ ret { ptr, i32, i32 } %8 + + unsafe.Slice.throw: ; preds = %entry +- call void @runtime.unsafeSlicePanic(i8* undef) #2 ++ call void @runtime.unsafeSlicePanic(ptr undef) #2 + unreachable + } + + ; Function Attrs: nounwind +-define hidden { i32*, i32, i32 } @main.SliceInt64(i32* dereferenceable_or_null(4) %ptr, i64 %len, i8* %context) unnamed_addr #1 { ++define hidden { ptr, i32, i32 } @main.SliceInt64(ptr dereferenceable_or_null(4) %ptr, i64 %len, ptr %context) unnamed_addr #1 { + entry: + %0 = icmp ugt i64 %len, 1073741823 +- %1 = icmp eq i32* %ptr, null ++ %1 = icmp eq ptr %ptr, null + %2 = icmp ne i64 %len, 0 + %3 = and i1 %1, %2 + %4 = or i1 %3, %0 +@@ -314,15 +297,14 @@ entry: + + unsafe.Slice.next: ; preds = %entry + %5 = trunc i64 %len to i32 +- %6 = insertvalue { i32*, i32, i32 } undef, i32* %ptr, 0 +- %7 = insertvalue { i32*, i32, i32 } %6, i32 %5, 1 +- %8 = insertvalue { i32*, i32, i32 } %7, i32 %5, 2 +- %9 = bitcast i32* %ptr to i8* +- call void @runtime.trackPointer(i8* %9, i8* undef) #2 +- ret { i32*, i32, i32 } %8 ++ %6 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 ++ %7 = insertvalue { ptr, i32, i32 } %6, i32 %5, 1 ++ %8 = insertvalue { ptr, i32, i32 } %7, i32 %5, 2 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ ret { ptr, i32, i32 } %8 + + unsafe.Slice.throw: ; preds = %entry +- call void @runtime.unsafeSlicePanic(i8* undef) #2 ++ call void @runtime.unsafeSlicePanic(ptr undef) #2 + unreachable + } + +diff --git a/compiler/testdata/string.ll b/compiler/testdata/string.ll +index 5e1f924c..bd3b8f5a 100644 +--- a/compiler/testdata/string.ll ++++ b/compiler/testdata/string.ll +@@ -3,96 +3,96 @@ source_filename = "string.go" + target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" + target triple = "wasm32-unknown-wasi" + +-%runtime._string = type { i8*, i32 } ++%runtime._string = type { ptr, i32 } + + @"main$string" = internal unnamed_addr constant [3 x i8] c"foo", align 1 + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 + +-declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 + + ; Function Attrs: nounwind +-define hidden void @main.init(i8* %context) unnamed_addr #1 { ++define hidden void @main.init(ptr %context) unnamed_addr #1 { + entry: + ret void + } + + ; Function Attrs: nounwind +-define hidden %runtime._string @main.someString(i8* %context) unnamed_addr #1 { ++define hidden %runtime._string @main.someString(ptr %context) unnamed_addr #1 { + entry: +- ret %runtime._string { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"main$string", i32 0, i32 0), i32 3 } ++ ret %runtime._string { ptr @"main$string", i32 3 } + } + + ; Function Attrs: nounwind +-define hidden %runtime._string @main.zeroLengthString(i8* %context) unnamed_addr #1 { ++define hidden %runtime._string @main.zeroLengthString(ptr %context) unnamed_addr #1 { + entry: + ret %runtime._string zeroinitializer + } + + ; Function Attrs: nounwind +-define hidden i32 @main.stringLen(i8* %s.data, i32 %s.len, i8* %context) unnamed_addr #1 { ++define hidden i32 @main.stringLen(ptr %s.data, i32 %s.len, ptr %context) unnamed_addr #1 { + entry: + ret i32 %s.len + } + + ; Function Attrs: nounwind +-define hidden i8 @main.stringIndex(i8* %s.data, i32 %s.len, i32 %index, i8* %context) unnamed_addr #1 { ++define hidden i8 @main.stringIndex(ptr %s.data, i32 %s.len, i32 %index, ptr %context) unnamed_addr #1 { + entry: + %.not = icmp ult i32 %index, %s.len + br i1 %.not, label %lookup.next, label %lookup.throw + + lookup.next: ; preds = %entry +- %0 = getelementptr inbounds i8, i8* %s.data, i32 %index +- %1 = load i8, i8* %0, align 1 ++ %0 = getelementptr inbounds i8, ptr %s.data, i32 %index ++ %1 = load i8, ptr %0, align 1 + ret i8 %1 + + lookup.throw: ; preds = %entry +- call void @runtime.lookupPanic(i8* undef) #2 ++ call void @runtime.lookupPanic(ptr undef) #2 + unreachable + } + +-declare void @runtime.lookupPanic(i8*) #0 ++declare void @runtime.lookupPanic(ptr) #0 + + ; Function Attrs: nounwind +-define hidden i1 @main.stringCompareEqual(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.stringCompareEqual(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* undef) #2 ++ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr undef) #2 + ret i1 %0 + } + +-declare i1 @runtime.stringEqual(i8*, i32, i8*, i32, i8*) #0 ++declare i1 @runtime.stringEqual(ptr, i32, ptr, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden i1 @main.stringCompareUnequal(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.stringCompareUnequal(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* undef) #2 ++ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr undef) #2 + %1 = xor i1 %0, true + ret i1 %1 + } + + ; Function Attrs: nounwind +-define hidden i1 @main.stringCompareLarger(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* %context) unnamed_addr #1 { ++define hidden i1 @main.stringCompareLarger(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr %context) unnamed_addr #1 { + entry: +- %0 = call i1 @runtime.stringLess(i8* %s2.data, i32 %s2.len, i8* %s1.data, i32 %s1.len, i8* undef) #2 ++ %0 = call i1 @runtime.stringLess(ptr %s2.data, i32 %s2.len, ptr %s1.data, i32 %s1.len, ptr undef) #2 + ret i1 %0 + } + +-declare i1 @runtime.stringLess(i8*, i32, i8*, i32, i8*) #0 ++declare i1 @runtime.stringLess(ptr, i32, ptr, i32, ptr) #0 + + ; Function Attrs: nounwind +-define hidden i8 @main.stringLookup(i8* %s.data, i32 %s.len, i8 %x, i8* %context) unnamed_addr #1 { ++define hidden i8 @main.stringLookup(ptr %s.data, i32 %s.len, i8 %x, ptr %context) unnamed_addr #1 { + entry: + %0 = zext i8 %x to i32 + %.not = icmp ult i32 %0, %s.len + br i1 %.not, label %lookup.next, label %lookup.throw + + lookup.next: ; preds = %entry +- %1 = getelementptr inbounds i8, i8* %s.data, i32 %0 +- %2 = load i8, i8* %1, align 1 ++ %1 = getelementptr inbounds i8, ptr %s.data, i32 %0 ++ %2 = load i8, ptr %1, align 1 + ret i8 %2 + + lookup.throw: ; preds = %entry +- call void @runtime.lookupPanic(i8* undef) #2 ++ call void @runtime.lookupPanic(ptr undef) #2 + unreachable + } + +diff --git a/go.mod b/go.mod +index a50f1174..b985effc 100644 +--- a/go.mod ++++ b/go.mod +@@ -17,7 +17,7 @@ require ( + golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 + golang.org/x/tools v0.1.11 + gopkg.in/yaml.v2 v2.4.0 +- tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec ++ tinygo.org/x/go-llvm v0.0.0-20220922115213-dcb078a26266 + ) + + require ( +diff --git a/go.sum b/go.sum +index 4af03408..d3180085 100644 +--- a/go.sum ++++ b/go.sum +@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +-tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec h1:FYtAFrw/YQPc644uNN65dW50FrEuVNaPBf70x23ApY4= +-tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= ++tinygo.org/x/go-llvm v0.0.0-20220922115213-dcb078a26266 h1:vg4sYKEM+w6epr5S1nXqP/7UhMYcc8nRt7Ohkq28rok= ++tinygo.org/x/go-llvm v0.0.0-20220922115213-dcb078a26266/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +diff --git a/interp/interpreter.go b/interp/interpreter.go +index 83fd2cd9..c61ce7cf 100644 +--- a/interp/interpreter.go ++++ b/interp/interpreter.go +@@ -356,7 +356,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + default: + panic("unknown integer type width") + } +- case strings.HasPrefix(callFn.name, "llvm.memcpy.p0i8.p0i8.") || strings.HasPrefix(callFn.name, "llvm.memmove.p0i8.p0i8."): ++ case strings.HasPrefix(callFn.name, "llvm.memcpy.p0") || strings.HasPrefix(callFn.name, "llvm.memmove.p0"): + // Copy a block of memory from one pointer to another. + dst, err := operands[1].asPointer(r) + if err != nil { +@@ -496,7 +496,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent + typecodeID := typecodeIDBitCast.Operand(0).Initializer() + + // Load the method set, which is part of the typecodeID object. +- methodSet := r.builder.CreateExtractValue(typecodeID, 2, "").Operand(0).Initializer() ++ methodSet := stripPointerCasts(r.builder.CreateExtractValue(typecodeID, 2, "")).Initializer() + + // We don't need to load the interface method set. + +@@ -1095,3 +1095,15 @@ func intPredicateString(predicate llvm.IntPredicate) string { + return "cmp?" + } + } ++ ++// Strip some pointer casts. This is probably unnecessary once support for ++// LLVM 14 (non-opaque pointers) is dropped. ++func stripPointerCasts(value llvm.Value) llvm.Value { ++ if !value.IsAConstantExpr().IsNil() { ++ switch value.Opcode() { ++ case llvm.GetElementPtr, llvm.BitCast: ++ return stripPointerCasts(value.Operand(0)) ++ } ++ } ++ return value ++} +diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go +index cde8e2d9..4e24b923 100644 +--- a/src/runtime/runtime.go ++++ b/src/runtime/runtime.go +@@ -27,18 +27,18 @@ func GOROOT() string { + + // Copy size bytes from src to dst. The memory areas must not overlap. + // This function is implemented by the compiler as a call to a LLVM intrinsic +-// like llvm.memcpy.p0i8.p0i8.i32(dst, src, size, false). ++// like llvm.memcpy.p0.p0.i32(dst, src, size, false). + func memcpy(dst, src unsafe.Pointer, size uintptr) + + // Copy size bytes from src to dst. The memory areas may overlap and will do the + // correct thing. + // This function is implemented by the compiler as a call to a LLVM intrinsic +-// like llvm.memmove.p0i8.p0i8.i32(dst, src, size, false). ++// like llvm.memmove.p0.p0.i32(dst, src, size, false). + func memmove(dst, src unsafe.Pointer, size uintptr) + + // Set the given number of bytes to zero. + // This function is implemented by the compiler as a call to a LLVM intrinsic +-// like llvm.memset.p0i8.i32(ptr, 0, size, false). ++// like llvm.memset.p0.i32(ptr, 0, size, false). + func memzero(ptr unsafe.Pointer, size uintptr) + + // This intrinsic returns the current stack pointer. +diff --git a/targets/esp32c3.json b/targets/esp32c3.json +index d7e3fc71..d377fcec 100644 +--- a/targets/esp32c3.json ++++ b/targets/esp32c3.json +@@ -1,6 +1,6 @@ + { + "inherits": ["riscv32"], +- "features": "+c,+m", ++ "features": "+c,+m,-relax,-save-restore", + "build-tags": ["esp32c3", "esp"], + "serial": "uart", + "rtlib": "compiler-rt", +diff --git a/targets/fe310.json b/targets/fe310.json +index e33308f2..2c9e6b5c 100644 +--- a/targets/fe310.json ++++ b/targets/fe310.json +@@ -1,6 +1,6 @@ + { + "inherits": ["riscv32"], + "cpu": "sifive-e31", +- "features": "+a,+c,+m", ++ "features": "+a,+c,+m,-64bit,-relax,-save-restore", + "build-tags": ["fe310", "sifive"] + } +diff --git a/targets/k210.json b/targets/k210.json +index 41c39f44..cc0d2ed4 100644 +--- a/targets/k210.json ++++ b/targets/k210.json +@@ -1,6 +1,6 @@ + { + "inherits": ["riscv64"], +- "features": "+64bit,+a,+c,+d,+f,+m", ++ "features": "+64bit,+a,+c,+d,+f,+m,-relax,-save-restore", + "build-tags": ["k210", "kendryte"], + "code-model": "medium" + } +diff --git a/targets/riscv-qemu.json b/targets/riscv-qemu.json +index 84050ff6..d55a685c 100644 +--- a/targets/riscv-qemu.json ++++ b/targets/riscv-qemu.json +@@ -1,6 +1,6 @@ + { + "inherits": ["riscv32"], +- "features": "+a,+c,+m", ++ "features": "+a,+c,+m,-relax,-save-restore", + "build-tags": ["virt", "qemu"], + "default-stack-size": 4096, + "linkerscript": "targets/riscv-qemu.ld", +diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go +index 9e2ffa90..55d1af39 100644 +--- a/transform/interface-lowering.go ++++ b/transform/interface-lowering.go +@@ -305,7 +305,9 @@ func (p *lowerInterfacesPass) addTypeMethods(t *typeInfo, methodSet llvm.Value) + // no methods or methods already read + return + } +- methodSet = methodSet.Operand(0) // get global from GEP ++ if !methodSet.IsAConstantExpr().IsNil() && methodSet.Opcode() == llvm.GetElementPtr { ++ methodSet = methodSet.Operand(0) // get global from GEP, for LLVM 14 (non-opaque pointers) ++ } + + // This type has methods, collect all methods of this type. + t.methodSet = methodSet +diff --git a/transform/interrupt.go b/transform/interrupt.go +index b15ff8a9..043eebb8 100644 +--- a/transform/interrupt.go ++++ b/transform/interrupt.go +@@ -36,9 +36,8 @@ func LowerInterrupts(mod llvm.Module) []error { + handleMap := map[int64][]llvm.Value{} + handleType := mod.GetTypeByName("runtime/interrupt.handle") + if !handleType.IsNil() { +- handlePtrType := llvm.PointerType(handleType, 0) + for global := mod.FirstGlobal(); !global.IsNil(); global = llvm.NextGlobal(global) { +- if global.Type() != handlePtrType { ++ if global.GlobalValueType() != handleType { + continue + } + +diff --git a/transform/llvm.go b/transform/llvm.go +index 7042b32d..045bb050 100644 +--- a/transform/llvm.go ++++ b/transform/llvm.go +@@ -80,6 +80,12 @@ func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) ll + // stripPointerCasts strips instruction pointer casts (getelementptr and + // bitcast) and returns the original value without the casts. + func stripPointerCasts(value llvm.Value) llvm.Value { ++ if !value.IsAConstantExpr().IsNil() { ++ switch value.Opcode() { ++ case llvm.GetElementPtr, llvm.BitCast: ++ return stripPointerCasts(value.Operand(0)) ++ } ++ } + if !value.IsAInstruction().IsNil() { + switch value.InstructionOpcode() { + case llvm.GetElementPtr, llvm.BitCast: +diff --git a/transform/reflect.go b/transform/reflect.go +index 68beba9b..b994df61 100644 +--- a/transform/reflect.go ++++ b/transform/reflect.go +@@ -251,7 +251,10 @@ func LowerReflect(mod llvm.Module) { + // a pointer to a runtime.structField array and therefore a + // bitcast. This global should be erased separately, otherwise + // typecode objects cannot be erased. +- structFields := references.Operand(0) ++ structFields := references ++ if !structFields.IsAConstantExpr().IsNil() && structFields.Opcode() == llvm.BitCast { ++ structFields = structFields.Operand(0) // get global from bitcast, for LLVM 14 compatibility (non-opaque pointers) ++ } + structFields.EraseFromParentAsGlobal() + } + } +@@ -460,7 +463,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int + + // Get the fields this struct type contains. + // The struct number will be the start index of +- structTypeGlobal := state.builder.CreateExtractValue(typecode.Initializer(), 0, "").Operand(0).Initializer() ++ structTypeGlobal := stripPointerCasts(state.builder.CreateExtractValue(typecode.Initializer(), 0, "")).Initializer() + numFields := structTypeGlobal.Type().ArrayLength() + + // The first data that is stored in the struct sidetable is the number of +@@ -483,7 +486,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int + if nameGlobal == llvm.ConstPointerNull(nameGlobal.Type()) { + panic("compiler: no name for this struct field") + } +- fieldNameBytes := getGlobalBytes(nameGlobal.Operand(0), state.builder) ++ fieldNameBytes := getGlobalBytes(stripPointerCasts(nameGlobal), state.builder) + fieldNameNumber := state.getStructNameNumber(fieldNameBytes) + + // See whether this struct field has an associated tag, and if so, +@@ -493,7 +496,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int + tagNumber := 0 + if tagGlobal != llvm.ConstPointerNull(tagGlobal.Type()) { + hasTag = true +- tagBytes := getGlobalBytes(tagGlobal.Operand(0), state.builder) ++ tagBytes := getGlobalBytes(stripPointerCasts(tagGlobal), state.builder) + tagNumber = state.getStructNameNumber(tagBytes) + } + +diff --git a/transform/rtcalls.go b/transform/rtcalls.go +index d70bc626..209e15ae 100644 +--- a/transform/rtcalls.go ++++ b/transform/rtcalls.go +@@ -139,14 +139,13 @@ func OptimizeReflectImplements(mod llvm.Module) { + if call.IsACallInst().IsNil() { + continue + } +- interfaceTypeBitCast := call.Operand(2) +- if interfaceTypeBitCast.IsAConstantExpr().IsNil() || interfaceTypeBitCast.Opcode() != llvm.BitCast { ++ interfaceType := stripPointerCasts(call.Operand(2)) ++ if interfaceType.IsAGlobalVariable().IsNil() { + // The asserted interface is not constant, so can't optimize this + // code. + continue + } + +- interfaceType := interfaceTypeBitCast.Operand(0) + if strings.HasPrefix(interfaceType.Name(), "reflect/types.type:named:") { + // Get the underlying type. + interfaceType = builder.CreateExtractValue(interfaceType.Initializer(), 0, "") +-- +2.36.1 + diff --git a/compiler-rt-release-keys.asc b/compiler-rt-release-keys.asc new file mode 100644 index 0000000..0d3789a --- /dev/null +++ b/compiler-rt-release-keys.asc @@ -0,0 +1,104 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQGNBGLtemUBDADClvDIromq0Y4TX+wyRyYCq5WusPQheQuY8dVCXd9KhMpYAv8U +X15E5boH/quGpJ0ZlVkWcf+1WUHIrQWlbzQdIx514CDM7DBgO92CXsnn86kIMDW+ +9S+Hkn8upbizT1fWritlHwzD9osz7ZQRq7ac03PPgw27tqeIizHGuG4VNLyhbbjA +w+0VLFSu3r219eevS+lzBIvR5U9W720jFxWxts4UvaGuD6XW1ErcsTvuhgyCKrrs +gxO5Ma/V7r0+lqRL688ZPr4HxthwsON1YCfpNiMZ6sgxT8rOE0qL/d07ItbnXxz6 +KdcNWIXamTJKJgag6Tl0gYX4KIuUCcivXaRdJtUcFFsveCorkdHkdGNos403XR89 +5u9gq7Ef10Zahsv5GjE2DV5oFCEhXvfIWxvyeJa65iBkJafElb2stgUjkIut2a2u ++XmpKpwpGSFklce1ABLrmazlLjhsYiJVrz5l5ktoT9moE4GaF7Q5LD6JgsxzLE0U +Tzo9/AQPd8qG2REAEQEAAbQeVG9iaWFzIEhpZXRhIDx0b2JpYXNAaGlldGEuc2U+ +iQHUBBMBCAA+FiEE1XS9XR0OmIleO/kARPJIXkXVkEIFAmLtemUCGwMFCRLMAwAF +CwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQRPJIXkXVkEKoNwv+MEMVzdnzJarx +ZJ0OzHrGJJG8/chkuoejTjCLG73li9yWQigy5KmvynB5yW0fk0PAQ90vvp2wr/Hd +mUh0Zda3CwF6sWlO3N6DEDjVA3lZUuofTtvMn/tdGvvOOXYXAP9N+SZfp/7q8dxX +zn5SA1AO87nXq5lrwVzlVzUCdwOeqDlJ+2U9VEqvukP/FdkgaR2bEb8Wm/h+encW +UIQEqPDE+qOyJ9dRaiL0CUI4x+1wXeXB3OA7VybF2LvaZDbMlocdy+vs825iUWfa +n8g3mE2TpV8jkc9UHgGGopzxqNquvkkIB7ZFZm/PSW40W3OeHKhYsZZbHrz9403t +3R4SAzA3ApmMP/P8ue9irsbe24g3rzYMvck1w4C1a4Uy9buT0OCfA+dA16IRAPgV +5SJEIS62cFbUxkw8el3rUK9V+6kwoq4k8Fs8f1U7DEnOKS/v8BJJCNEc1cvimZai +Y5/3r5BeneEmuZFKX4iIIfcn5PmLSDB4aw+gKAIAAus+E2DxBqE+uQGNBGLtemUB +DADBCNyvUdv0OV//6pQ/0YC2bYXL/ElF0rOjFFl4H7O3TRxgIz2C4nQJHUOrXSmo +iL7ldfUjoAMgebcoWDpgE8S2Vjw2Gd+UJBQXj+3J6dPKLBUCjj9CLyb5hwOHITMV +b9UC/E+iwpn4vgTbI6K1O847brkBC+GuDT4g9D3O3sRbja0GjN0n2yZiS8NtRQm1 +MXAVy1IffeXKpGLookAhoUArSN88koMe+4Nx6Qun4/aUcwz0P2QUr5MA5jUzFLy1 +R3M5p1nctX15oLOU33nwCWuyjvqkxAeAfJMlkKDKYX25u1R2RmQ4ju2kAbw0PiiZ +yYft8fGlrwT4/PB3AqfKeSpx8l9Vs15ePvcuJITauo3fhBjJ6Y4WCKlTG1FbDYUl +KvPhyGO8yLhtZJg3+LbA5M/CEHsDmUh7YEQVxM0RTQMTxNBVBF5IG/4y8v/+19DZ +89VdpsQF3ThoPV0yh57YMemTBeIxpF9Swp5N7kUWct4872kBnXOmbp/jhU4MpLj6 +iLEAEQEAAYkBvAQYAQgAJhYhBNV0vV0dDpiJXjv5AETySF5F1ZBCBQJi7XplAhsM +BQkSzAMAAAoJEETySF5F1ZBCdPwL/3Ox6MwrKFzYJNz3NpQFpKFdDrkwhf25D/Qw +vu5e8Lql/q62NIhEKH3jxXXgoFYas2G7r8CSCRehraDqvXygbaiWUIkxSU0xuDTl +lNqHSkCRqIxhi/yxNm1Pk84NVGTLXWW0+CwT9cRwWn5foIPJhoDdZ732zJ7rcY3R +g71SJTe3R6MnGBzIF1LzT7Znwkh7YfcmeTfInareIWXpeNaeKy8KrQmr/0+5AIer +Ax1gu03o8GD5LFDUuGbESgDJU6nVtVyht7C6AlJWqSX6QS3+lPCw5BOCKbxakYNR +/oBNauzyDISdbUwzHM2d+XGCjBsXKRA0Tft2NlG6EC83/PuY2J9MSA2gg3iPHsiN +J5iipbdZNpZ3XL0l8/t/7T60nM7UZDqt3twLMA0eRFRlCnhMjvFE5Zgj5DE7BsJh +w2nCoGWkAcfeuih+jfyEjN24NK+sE/bM+krwVv430ewJwm1bVUqKrbOb9aa6V9gP +9RmlwZlOTFGcWBYl/cfRONn9qi9a6w== +=Lvw+ +-----END PGP PUBLIC KEY BLOCK----- +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBFrqgT0BEAC7xo0WH+eNrLlU5LrCk59KmImn1abFcmWNd8kYr5XfqmJKyVqo +EY7A/yRjf+Yn1621EDkpKPjbql7q7MlZMpqKVdOWKWgmhvz08IOKJxaIABd/iIRT +FwhIvB68YjtmzcoOJRi1wLnwuG55fJ9E69HyZ33jgAlRaWV3bE/YyszoTlZriUOE +RbzC5WzX004cE9evlrr+YLt5Y6z7tntOdSXPLyGOFAO5LYMsHsEdi2JBYWrjlslG +6iJr5iEt9v442PrJ79YYbu5QWe/6APRWtI3AtKBp7y250oon2lbj+bIVD7U9fOBB +n/Frqx54UN22sJycET63hgYW4pIjIi5zq+FF15aU+ZqBdtNltoX4hEN7wlDpuNc0 +ezVu2Z8hdt8thpjiFUioTQ1t3RmsN6N548VwxmHdoYpAmiZqPIYBYvm85JB7S/3h +RLuoeGxufBhXGCpnG8ghTOGtbbdanuLB/UROFXTdyZbTCBN5S6jvwkPSaHG7H35Z +3fazMriTXwL1RGAbKITSWhDe5dXy/yOInWe8emJx+35vwQYCB2L4S8wRyQyRw6x4 +YoXCscW041DUMBX2CC7SjMCcmAC39UX1c3GbTpS3rkJR9cmXt50nviMnKpIwlIPd +ZYhmxKifwTJ70+c4GVK2o0MG9bTYvpYhLnYxv6iJCfgmT40E+qkDSzSoZwARAQAB +tCJUb20gU3RlbGxhcmQgPHRzdGVsbGFyQHJlZGhhdC5jb20+iQI/BBMBAgApBQJa +6oE9AhsDBQkB4TOABwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQoseUqYZB +nYp8Gg//RmX6Nup/Dv05jTL7dKRBSD08MF400tRtTmRhIuAgGv27qO2hbqzprKVu +vd20vKBB9CNZpXC2oY8k9VhGv2PZNi/X7iuULIYmzjeFMbJ5CjU6XvuUBmNasITH +6K/0KLhGebPs5h/DNtd7lbzDm86dLcjxgl6LXUULaSyYvTAKn6YB6mAv5J3qJs2X +lfTmenNh9p7TPFTfcMHcS70ywjqKXlDiH0q9bRKJnSX7xUFlTHjKkNnAcRjlPaGf +wUUhIPrnpDboqfwfcmScLrHANW9nwFWSFkNAJu1HQUEuF+An/RZUHDxFbLPKKAIp +hwZ0aORTfBVZ80AjehDMYCbmp1DJeTyLjC1/94un6mlxPIKnPPPM8rMxr83xnrvP ++Y1+pJaDUL7ZvKnmt2LrGRa9GvsNiYKpCNCORfiwZTeSxxXb+LgaodnbCHvGBnk7 +nlbLdMY08vNlxSx8LNyG0krFxJw/rq260+73yc+qjENeG68fozTEy/4jSVrF4t3m +8AAUu5r6i/Aomo7Q27TjU928bbCVunpvDpserfDqr3zsA96LO9k8T6THR6zC9i+R +LiN9Vjl+Rr2YuU26DjFYkCNEA2kNflYCWPJi5I0eodTPZrIPBWJ+H0YTRX31bMH9 +X88FnWJuCwaqAMN3rWlX/lXNCouWDdCuPWseZApISAMnVDE2mM+JAlYEEwEIAEAC +GwMHCwkIBwMCAQYVCAIJCgsEFgIDAQIeAQIXgBYhBEdOIjFqv0eFqIxujqLHlKmG +QZ2KBQJgkytfBQkJaxEiAAoJEKLHlKmGQZ2Kv8YP/jNPjcMAP0ZTpUcYV46mGKwf +aQ0g5FUMSfxP7uJHtctj2dUckPGpA9SAH+ApiJutVgTQpWqNJKPd2vVxOiu5sywN +iDKCOMlKug5m6lgLX5h3zBvSN90Hpn4I0qHRA3rgENLoPs/UYBxohvFPIhOOjPqO +HIUuSPhAIuIZawxtqlADswHiKPy38Ao5GnWRb60zKfrB+N+ZiOtg7ITrlTGYm2tX +0W9iWUG32gIA/RX2qmFPoLrDFqsk66Eir0Ghk5gppRrmpEl/M1lqA8bxlqWto/8w +V8yDbSEu5fmM3WN3OUcSA23lYJi4j656Q4hS5PU+IWuZbBhcpYwDGexV5+m/ySZb +wtHZMIb4Au+dgJHCvRiSqHgplyfiamxX5CfA0DJVHoGXpBOw8a2geRT0+DrjSbOS ++CDDnlfmQLfHgjEuyQPU8V0Wlb0tJEvnPPqNPmAv0Rv7MC4qmD/zDrgwuddpfr1x +H+nWus2plR8E6p/x9uvPLb3plJ94ri1XjXiJPyPvqzBAwA40Zeg0rE7sTVwCC3E9 +RZa7dHh17exkcZdOIS/vRQ1G/VNaOVUwrcC/vIMgZSe37bCLeOKViMtacAiBJDjo +INC1QJ2F3CYVwktrcgmuz9S8e2WrqdTWwijjConB80EwfHQllz5sp/jU6Bgv297X +UXkgpk1y+ibQ9/syRQpFuQINBFrqgT0BEADB2vDHMuexkaUm3rPi6SvyMGcsHWle +feAWm+UjROKIaV77rHwo0/8ncKbtoQx4ZZjDXdI77M2bXB7tPgyEML90bWDMMGN/ +gnpwWSsiDRWpFIV/+hD6B+l9UaEi4UvEstUbIchOkGrZgPZ4Qism4FSVosEK+FE7 +EKCT4PSS+LiBKSxJZB8/g2uX+3pJvVxYurvcVpTmiNlXvUyll4KMpzy5e0KKa/0y +w9h7SAre5399cSM8E7PDQZQDb1EwbyVyO2yDLgs+p3yzPtRJAydaqRPmT1JbSCYf +hcihTrViMA4EDN5GRjH2EElI37+2HMpgLs4rc6Abz1F4FUVFhqWJXCKUcAIrG17w +A7YUlYg38S6Xws2Xj1VfZ/WP7/qIMJZidYTHZbN9WWCaifCPfLlE5VDNsa8y6Mxm +uFMBAB4PpB1gmmP9pPZsOzV9SmeYt8h2P8cVKDW2f56azpBZvZX6NFn8e0+ZDXS4 +8BQz31G2Xdfa3uOEV0J3JxPXcEbfuPzDHb7OMYP+2Ypjox1TozT1e9zr46SQl9OF +MglOBnwLZJ9baA/IqZkqLq5iu5Oqda44EIVNAntQ3gebi3+q3YG1SvNUseIy2+8y +cNWtdDuWv366Af0okCdrKAdap8+KbREer9uXhamtvxc49RCoWwuKoKfBz0RdVvMv +R/Py2xV8A7PaIQARAQABiQIlBBgBAgAPBQJa6oE9AhsMBQkB4TOAAAoJEKLHlKmG +QZ2KAaMQALHif2E0PBLVt09vlr4i8jAsQvDrzRajmVPd2B9RpfNU6HJe/y93SZd2 +udr9vzgmfd2o5u12vbegKNiMRgp1VyHQDmYlce27jrH5aPuKmos78+o5/p5yPWCv +Rj8zxGKh7le7UPO+7UveKu+bgb3zwTj6bEuHX7fVI+WjGmEH3bbjDGamWxXrpfGc +7+Jr8TN4ZO2OwYBcFOS9U2ZQ6TxrPaCSIm6+j8f+a9HPOuuDc62mMuV/EWQZy0i7 +DhDqU2PNpVjQDWQNpHA8oLDrjNFAoJS8gbHABVsFM1VnwBNT2MKcZQmm05dlQ+ll +S6meHNCvTniKIKC+Giz1Yd5JVGDACZWWPxEz6VhpQW/twkxRqwlUdpFt7UgDquTL +M1beQUCZRt81yJTNdrggbhQ2POxOdIO0CPiQv7U1IzndZp6baedeBw4a7FCbj6GY +cQeHxQCrWpQrwigiseG5uhhS9aiaVFEHja9baSLfXlZu/vsR4MdDG5/iEpier/Xw +h1qnpTSY+r31Uw3lTUlPHzlg47PMgPslaIhCzfVggxh9bTqxcDbuYJ7NuoMho3tN +yWfeofTJ7PhKzoXM2Y/rRFoM5gNh1RVA19ngLT5Jwiof8fPZvHJ/9ZkHn+O7eMNm +m5++gYza3pnn2/PoGpGGAKok+sfJiq5Tb7RUefyJTeZiyTZ/XJrA +=tMzl +-----END PGP PUBLIC KEY BLOCK----- diff --git a/sources b/sources index 4597e0f..7f554f3 100644 --- a/sources +++ b/sources @@ -2,8 +2,8 @@ SHA512 (tinygo-0.26.0.tar.gz) = 7b95f6b4356545b806207092fa315863446227e3f90d05ab SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-14.0.0.src.tar.xz) = 9df73ef3b81f2b70902726e0dc5529c0cc1e976ce75fbfb1c3d7930882d82fc0896934a32d1c9511b08962cac5b409c14f54dc53833fbf0724256b22165c4439 -SHA512 (compiler-rt-14.0.0.src.tar.xz.sig) = 3998c7a7477a95ae36591b8658677a44f5d4c88a57e93df57fc3f4670c38a71fb0e385b7f9b44ef7e97d7ce77551b4ea790c6f63174e79a2ffc9dd678dcf886f +SHA512 (compiler-rt-15.0.0.src.tar.xz) = 25763e581c90923260b7c3a03e220feb4cabb2757e418c4940db0eeb6a17f65b35db0c93d3c1e526adad2f6dc93595bec6d99b1bfb4a1bd13a14a0db5301e6cf +SHA512 (compiler-rt-15.0.0.src.tar.xz.sig) = 94f39d2e30372ccea4db96c3dd4005a5b44c2bf5d22fa0aaf45b86673ef7d3460884689f97bc96470db2d546042fb01fe3ca41bf22b6323abe0cd785b85d76ef SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879add4eab283c8692c3b031eb9457ad00d1edd082cfe62fcc0eb5eb1d3bf4f1d749c0efa2a95fec1 SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 diff --git a/tinygo.spec b/tinygo.spec index df67c75..f358329 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,7 +10,11 @@ Version: 0.26.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%if %{fedora} > 36 +%global clang_llvm_version 15 +%else %global clang_llvm_version 14 +%endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 @@ -56,7 +60,7 @@ Source3: https://github.com/avr-rust/avr-mcu/archive/%{avr_commit}/avr-%{ Source4: cmsis_svd-%{cmsis_svd_commit}-clean.tar.xz Source50: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz Source51: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz.sig -Source52: tstellar-gpg-key.asc +Source52: https://src.fedoraproject.org/rpms/compiler-rt/raw/f8e98d51f0c3fdbaa9ce5d99816930e4fcbe504b/f/release-keys.asc#/compiler-rt-release-keys.asc Source60: https://musl.libc.org/releases/musl-%{musl_version}.tar.gz Source61: https://musl.libc.org/releases/musl-%{musl_version}.tar.gz.asc Source62: https://musl.libc.org/musl.pub @@ -79,6 +83,22 @@ Patch0004: 0004-Suggest-optional-packages-to-install-if-missing.patch Patch0005: 0005-Skip-TestDirFS-on-32-bit-systems.patch Patch0006: 0006-Skip-broken-tests-on-i686.patch +# Backport patches for LLVM 15 support +# https://github.com/tinygo-org/tinygo/pull/3230 +Patch0007: 0007-wasm-fix-GC-scanning-of-allocas.patch +# https://github.com/tinygo-org/tinygo/pull/3189 +Patch0008: 0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch +Patch0009: 0009-all-add-type-parameter-to-CreateCall.patch +Patch0010: 0010-all-add-type-parameter-to-CreateLoad.patch +Patch0011: 0011-all-add-type-parameter-to-GEP-calls.patch +Patch0012: 0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch +Patch0013: 0013-interp-change-object.llvmType-to-the-initializer-typ.patch +Patch0014: 0014-all-remove-pointer-ElementType-calls.patch +Patch0015: 0015-transform-fix-memory-corruption-issues.patch +Patch0016: 0016-riscv-add-target-abi-metadata-flag.patch +Patch0017: 0017-interp-add-support-for-constant-icmp-instructions.patch +Patch0018: 0018-ci-add-support-for-LLVM-15.patch + # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval diff --git a/tstellar-gpg-key.asc b/tstellar-gpg-key.asc deleted file mode 100644 index eba625c41a5fb1646d8b087acb97a6f079901712..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2222 zcmV;f2vPT$0u2OO>VZ805CFTzjTRs0jjXv;pGugCr`4v#a%GKo$r!Jd->PCt z$y%rpj==vUV}Ir+*R8b>IVmXk+p1pb?8#X&nu=A^mMLf^hWzyKgNi2>hyWLVh=fxY z2uQphyka|M&B_iX7`4E;@VIVye4j+?(eh_~`%yu#&d z*V9fM6W6bny8d9hd1I{mwtG%>CC@J*juZpAErTo`!5xcYL1Aj+mdQryB5UR$E%yF6 z*!s!u));Q?P+9N#0Q6S0jli^^Y40t$(uybAR^$1y6%VyNeBeQ!@oTFdcu?K8u$-I` zKDUMj7UGg4A}({Q;YHV$l=+&0cGG3Hh4_R+d%{rZxYsm$HE!9TA$H#_hM3|NNT^K> zZQU8HH=}vu#c;-9-Jyy=nkH&Ih5=&vyyTF3Oa0+QyQp|o8>g~GALwBu0JFctO)F4By^oR|Q&^+ok_ahpz* zx2{4_^~smFohQB{Cn}OKl!M)6h-Sp7pTRPF)8{xDQnsT*2KBVqzLp^_b}_%Gi3#{7 zPmKinsRK(isAm8X0RRECB2;f}AX9W@Y;0k2WFS0rb97~FY+-Uha%E&_VRSBIZ*4w_ z0zU*30RjLi1p->?fjt5n0|f~I;WK~-3ke7Z0|EgC6$kC|{ ztfg+f-L$-*LG&Y8rEs>Pk0kY2M!#d(HZRxiE0ipTCeAm7F|v6IH9B7Vlm=s3u!P6x zukC3z;PJmJ)xh$MIj*i=cG31 zsr(;uWSlOsz%_4Yz*UkKLqI0&M?pa@7vLxT7E~NOMQpRmC;};m26SlTQ+yR!^FSkd z5X@jE=BH4}c|41ZEr0imr|M~OJc6e@^UU(IF|W<>p1aTajeew-gHXQNys755V(S?e zy&C%siGryJ(2hm;uw^%r#}(W7xEi6^+X#Ec26;Q4R?Bq8H1hLh#VmX*+=kLh#l)OH zuC2P$?)S;hs*FQk8?PUuG{npPBS~7t;@#%(02I5L`it-=nvT%hwBu9Vylt?Rx_WO8 zn;xz3>aTq41Kx`}**s6A$49Kf_AikxBYjpmen!2RxlOtbF<6izL<4CJepUil@?zwT z9--9FX0i_jVtyY+6GeUXY{C6s&jp=gZVLvg0K<2!X;=PL%?gW_4bZMVYaV0@NJs-G zR53P~&$$8(1X}8WJpm8^!P@Z0GUu_8r6%69;^`~$FlQ_sXC1gfPE!ZD7nWV}F8ra9JxN4Hc;rg@5`G`UmNK zQK2H?OT@C(8zIO}kZRe0_IN@oCg4<+qQMIIQ9BTzli>7{__%>7EJKyOXMQt~d~dO#*vR-UpkDf2!SqwMz3;vEnk@ z?=o=Jt#mt#&qQ5T^Djs9 z^4k@B1GCy801*KI0f_=71Q-DV01pKMTIzv40vikk2?60VfB*^!5TeJFsfIzFiUFe# z0I}kKVKh7v)wfS?mcAnLFf2mw>&+IUnN!`^A5o?AROoVE|1Wn*mv*_@{l7RSech<$ z?RLGlpeWdkMhbOTAw|NxrZVM!5o8(5NV^UY>QiIQrC87nWDTTnJfN`ajL|@# zl)Qnlzy(_cGgW866I0m2oMj27)0bsK>19i)o*dAxPI!tSpuQR`^kJnT+%gR}_vkiWGx zBRSn>o||dsUIz{u>`KQ`n~m24dqQqPaip8qJ@%<^y5X6+qY7;4MB$!YUu}^Vz&|fAyIM wpX0lD!)BYGzJZL|-kImy^XM9ph5)K0`p3zNu2XNcRC)Y~P3B_BHh)~2!0gUKHvj+t From a9b7fbae8f8198b7eb97fdbec05e25ab58c1ed75 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 21 Jan 2023 05:06:19 +0000 Subject: [PATCH 44/78] Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild Signed-off-by: Fedora Release Engineering From 9b16b76e2f1107b608d3e2ebf611b6f7392d756d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 23 Jan 2023 03:45:52 -0500 Subject: [PATCH 45/78] Backport compatibility for Go 1.20 --- 0001-Skip-WASI-tests.patch | 4 +- 0002-Use-system-mingw64-headers-and-crt.patch | 4 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 4 +- ...ional-packages-to-install-if-missing.patch | 4 +- 0005-Skip-TestDirFS-on-32-bit-systems.patch | 4 +- 0006-Skip-broken-tests-on-i686.patch | 4 +- 0007-wasm-fix-GC-scanning-of-allocas.patch | 4 +- ...a-FunctionType-not-a-PointerType-in-.patch | 4 +- ...all-add-type-parameter-to-CreateCall.patch | 4 +- ...all-add-type-parameter-to-CreateLoad.patch | 4 +- ...-all-add-type-parameter-to-GEP-calls.patch | 4 +- ....Const-calls-with-builder.Create-cal.patch | 4 +- ...ject.llvmType-to-the-initializer-typ.patch | 4 +- ...all-remove-pointer-ElementType-calls.patch | 4 +- ...ansform-fix-memory-corruption-issues.patch | 4 +- 0016-riscv-add-target-abi-metadata-flag.patch | 4 +- ...pport-for-constant-icmp-instructions.patch | 4 +- 0018-ci-add-support-for-LLVM-15.patch | 4 +- ...untime-add-xorshift-based-fastrand64.patch | 40 +++ 0020-testing-implement-t.Setenv.patch | 129 +++++++++ ...port-for-new-unsafe-slice-string-fun.patch | 255 ++++++++++++++++++ ...t-math-rand.fastrand64-to-fix-linker.patch | 35 +++ ...t-internal-godebug.setUpdate-as-a-st.patch | 31 +++ ...ement-setenv-unsetenv-in-the-runtime.patch | 136 ++++++++++ 0025-builder-add-support-for-Go-1.20.patch | 139 ++++++++++ 0026-Skip-archive-zip-tests.patch | 36 +++ tinygo.spec | 13 + 27 files changed, 850 insertions(+), 36 deletions(-) create mode 100644 0019-src-runtime-add-xorshift-based-fastrand64.patch create mode 100644 0020-testing-implement-t.Setenv.patch create mode 100644 0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch create mode 100644 0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch create mode 100644 0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch create mode 100644 0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch create mode 100644 0025-builder-add-support-for-Go-1.20.patch create mode 100644 0026-Skip-archive-zip-tests.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 1f648df..bd9c522 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 6b50974a6d4972b755a35d40d87e5bdf9c97d925 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 01/18] Skip WASI tests. +Subject: [PATCH 01/26] Skip WASI tests. We do not have wasmtime available. @@ -34,5 +34,5 @@ index 9ddbe52f..79ae2cf2 100644 } for _, targ := range targs { -- -2.36.1 +2.38.1 diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch index 821f09a..012aa83 100644 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ b/0002-Use-system-mingw64-headers-and-crt.patch @@ -1,7 +1,7 @@ From 76c575659d42187b0c4c15d4f5978c4368800da7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 02/18] Use system mingw64 headers and crt +Subject: [PATCH 02/26] Use system mingw64 headers and crt Signed-off-by: Elliott Sales de Andrade --- @@ -118,5 +118,5 @@ index ebfc5082..cd49283d 100644 ) case "": -- -2.36.1 +2.38.1 diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 87d5c28..5209323 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From 2a2e35e4565e8ea7f7ac2d34cb9da24000bb6474 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 03/18] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 03/26] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -60,5 +60,5 @@ index 79ae2cf2..9359ef0c 100644 actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows -- -2.36.1 +2.38.1 diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0004-Suggest-optional-packages-to-install-if-missing.patch index b7f2c2c..ab97660 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0004-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From 3f935d679870de924aa65d78c23ecdcb483ab4a3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 04/18] Suggest optional packages to install if missing +Subject: [PATCH 04/26] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -74,5 +74,5 @@ index 53d89bf0..e55719b2 100644 + return err } -- -2.36.1 +2.38.1 diff --git a/0005-Skip-TestDirFS-on-32-bit-systems.patch b/0005-Skip-TestDirFS-on-32-bit-systems.patch index 9101800..dc9acd5 100644 --- a/0005-Skip-TestDirFS-on-32-bit-systems.patch +++ b/0005-Skip-TestDirFS-on-32-bit-systems.patch @@ -1,7 +1,7 @@ From 41cbdf1cfe50f24b49beb615f0924ea3255c7e7d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 05/18] Skip TestDirFS on 32-bit systems +Subject: [PATCH 05/26] Skip TestDirFS on 32-bit systems Because Seek is not fully implemented there. @@ -26,5 +26,5 @@ index dd255fb4..5dc0d860 100644 t.Log("TODO: allow foo/bar/. as synonym for path foo/bar on wasi?") return -- -2.36.1 +2.38.1 diff --git a/0006-Skip-broken-tests-on-i686.patch b/0006-Skip-broken-tests-on-i686.patch index 98e0acf..1c241b5 100644 --- a/0006-Skip-broken-tests-on-i686.patch +++ b/0006-Skip-broken-tests-on-i686.patch @@ -1,7 +1,7 @@ From a44f31de099aaf6768af2102919f1a8c221ce6f4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 06/18] Skip broken tests on i686 +Subject: [PATCH 06/26] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there @@ -40,5 +40,5 @@ index 99f67c29..1ef11d29 100644 TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) -- -2.36.1 +2.38.1 diff --git a/0007-wasm-fix-GC-scanning-of-allocas.patch b/0007-wasm-fix-GC-scanning-of-allocas.patch index 02da873..5397b13 100644 --- a/0007-wasm-fix-GC-scanning-of-allocas.patch +++ b/0007-wasm-fix-GC-scanning-of-allocas.patch @@ -1,7 +1,7 @@ From e8f07384a0f5a61351a62931d3fb69bf6c451c1b Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 16 Oct 2022 00:44:38 +0200 -Subject: [PATCH 07/18] wasm: fix GC scanning of allocas +Subject: [PATCH 07/26] wasm: fix GC scanning of allocas Scanning of allocas was entirely broken on WebAssembly. The code intended to do this was never run. There were also no tests. @@ -261,5 +261,5 @@ index 90b7a7c7..32ee9560 100644 + return value } -- -2.36.1 +2.38.1 diff --git a/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch b/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch index 77d6ea3..9045c40 100644 --- a/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch +++ b/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch @@ -1,7 +1,7 @@ From 9e64a63d49100e550fad97b390bb01489ed6ca44 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 20 Sep 2022 23:59:22 +0200 -Subject: [PATCH 08/18] compiler: return a FunctionType (not a PointerType) in +Subject: [PATCH 08/26] compiler: return a FunctionType (not a PointerType) in getRawFuncType This is necessary for opaque pointer support (in LLVM 15). @@ -48,5 +48,5 @@ index c59a9ade..b0ea71e3 100644 c.addStandardDeclaredAttributes(llvmFn) llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("tinygo-invoke", c.getMethodSignatureName(instr.Method))) -- -2.36.1 +2.38.1 diff --git a/0009-all-add-type-parameter-to-CreateCall.patch b/0009-all-add-type-parameter-to-CreateCall.patch index ca16ea3..acfce69 100644 --- a/0009-all-add-type-parameter-to-CreateCall.patch +++ b/0009-all-add-type-parameter-to-CreateCall.patch @@ -1,7 +1,7 @@ From 8138d69793c00829df45501c35975055ad52d151 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 21 Sep 2022 00:37:01 +0200 -Subject: [PATCH 09/18] all: add type parameter to CreateCall +Subject: [PATCH 09/26] all: add type parameter to CreateCall This uses LLVMBuildCall2 in the background, which is the replacement for the deprecated LLVMBuildCall function. @@ -989,5 +989,5 @@ index aeba713d..aedad71d 100644 builder.CreateRetVoid() } else { -- -2.36.1 +2.38.1 diff --git a/0010-all-add-type-parameter-to-CreateLoad.patch b/0010-all-add-type-parameter-to-CreateLoad.patch index 2cbfe1b..8f4d9f4 100644 --- a/0010-all-add-type-parameter-to-CreateLoad.patch +++ b/0010-all-add-type-parameter-to-CreateLoad.patch @@ -1,7 +1,7 @@ From 65a18179d8ff911ba43a3a28ffb2f36c262cff5e Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 21 Sep 2022 13:55:32 +0200 -Subject: [PATCH 10/18] all: add type parameter to CreateLoad +Subject: [PATCH 10/26] all: add type parameter to CreateLoad This is needed for LLVM 15. @@ -373,5 +373,5 @@ index aedad71d..064e38f4 100644 callParams = append(callParams, paramValue) } -- -2.36.1 +2.38.1 diff --git a/0011-all-add-type-parameter-to-GEP-calls.patch b/0011-all-add-type-parameter-to-GEP-calls.patch index 866f9fb..120c469 100644 --- a/0011-all-add-type-parameter-to-GEP-calls.patch +++ b/0011-all-add-type-parameter-to-GEP-calls.patch @@ -1,7 +1,7 @@ From dd4f1c594ef0fadb59fa418f1049542f86237800 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 21 Sep 2022 17:00:09 +0200 -Subject: [PATCH 11/18] all: add type parameter to *GEP calls +Subject: [PATCH 11/26] all: add type parameter to *GEP calls This is necessary for LLVM 15. @@ -561,5 +561,5 @@ index f1a3c93d..169f1454 100644 llvm.ConstInt(ctx.Int32Type(), uint64(i), false), }) -- -2.36.1 +2.38.1 diff --git a/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch b/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch index a730ef6..d63dd8c 100644 --- a/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch +++ b/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch @@ -1,7 +1,7 @@ From 6053c1c8528c63a669d070550bacd43f2f6a68e1 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 20 Sep 2022 23:26:49 +0200 -Subject: [PATCH 12/18] all: replace llvm.Const* calls with builder.Create* +Subject: [PATCH 12/26] all: replace llvm.Const* calls with builder.Create* calls A number of llvm.Const* functions (in particular extractvalue and @@ -574,5 +574,5 @@ index 2f17f815..d70bc626 100644 // Replace Implements call with the type assert call. builder.SetInsertPointBefore(call) -- -2.36.1 +2.38.1 diff --git a/0013-interp-change-object.llvmType-to-the-initializer-typ.patch b/0013-interp-change-object.llvmType-to-the-initializer-typ.patch index 4ef130d..6cbd134 100644 --- a/0013-interp-change-object.llvmType-to-the-initializer-typ.patch +++ b/0013-interp-change-object.llvmType-to-the-initializer-typ.patch @@ -1,7 +1,7 @@ From 1004deaafd70d4eb94196977c20a5b1a17cded81 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 22 Sep 2022 01:06:40 +0200 -Subject: [PATCH 13/18] interp: change object.llvmType to the initializer type +Subject: [PATCH 13/26] interp: change object.llvmType to the initializer type Previously it was a pointer type, which won't work with opaque pointers. Instead, use the global initializer type instead. @@ -75,5 +75,5 @@ index 583f9355..6a537bad 100644 // The exact type isn't known, but the object layout is known. globalType = obj.llvmLayoutType -- -2.36.1 +2.38.1 diff --git a/0014-all-remove-pointer-ElementType-calls.patch b/0014-all-remove-pointer-ElementType-calls.patch index 36f0818..146b0ab 100644 --- a/0014-all-remove-pointer-ElementType-calls.patch +++ b/0014-all-remove-pointer-ElementType-calls.patch @@ -1,7 +1,7 @@ From 0cdaa0f6db40e372db24d945b557d03b97ff92e9 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 22 Sep 2022 13:33:00 +0200 -Subject: [PATCH 14/18] all: remove pointer ElementType calls +Subject: [PATCH 14/26] all: remove pointer ElementType calls This is needed for opaque pointers, which are enabled by default in LLVM 15. @@ -582,5 +582,5 @@ index 064e38f4..83a16d85 100644 if returnType == int64Type { hasInt64 = true -- -2.36.1 +2.38.1 diff --git a/0015-transform-fix-memory-corruption-issues.patch b/0015-transform-fix-memory-corruption-issues.patch index d209b69..10ea146 100644 --- a/0015-transform-fix-memory-corruption-issues.patch +++ b/0015-transform-fix-memory-corruption-issues.patch @@ -1,7 +1,7 @@ From 6bf7aa1623b6d7d9a269df876453af22b1c54c2d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 12 Oct 2022 21:46:50 +0200 -Subject: [PATCH 15/18] transform: fix memory corruption issues +Subject: [PATCH 15/26] transform: fix memory corruption issues There was a bug in the wasm ABI lowering pass (found using AddressSanitizer on LLVM 15) that resulted in a rather subtle memory @@ -27,5 +27,5 @@ index 83a16d85..08122a3e 100644 builder.SetInsertPointBefore(call) callParams := []llvm.Value{} -- -2.36.1 +2.38.1 diff --git a/0016-riscv-add-target-abi-metadata-flag.patch b/0016-riscv-add-target-abi-metadata-flag.patch index e194223..abc5083 100644 --- a/0016-riscv-add-target-abi-metadata-flag.patch +++ b/0016-riscv-add-target-abi-metadata-flag.patch @@ -1,7 +1,7 @@ From 003963ddc796960ce498361409a9d121366b1c42 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 12 Oct 2022 22:05:38 +0000 -Subject: [PATCH 16/18] riscv: add "target-abi" metadata flag +Subject: [PATCH 16/26] riscv: add "target-abi" metadata flag This flag is necessary in LLVM 15 because it appears that LLVM 15 has changed the default target ABI from lp64 to lp64d. This results in a @@ -189,5 +189,5 @@ index c2378e97..fc45c91c 100644 "ldflags": [ "-melf64lriscv" -- -2.36.1 +2.38.1 diff --git a/0017-interp-add-support-for-constant-icmp-instructions.patch b/0017-interp-add-support-for-constant-icmp-instructions.patch index 500803c..d3d7158 100644 --- a/0017-interp-add-support-for-constant-icmp-instructions.patch +++ b/0017-interp-add-support-for-constant-icmp-instructions.patch @@ -1,7 +1,7 @@ From 76f42a3fac44ac6d07c53b10ddadb683ca019684 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 18 Oct 2022 23:16:36 +0000 -Subject: [PATCH 17/18] interp: add support for constant icmp instructions +Subject: [PATCH 17/26] interp: add support for constant icmp instructions These instructions sometimes pop up in LLVM 15, but they never occured in LLVM 14. Implementing them is relatively straightforward: simply @@ -191,5 +191,5 @@ index 5fac449e..08d74c85 100644 @someArrayPointer = local_unnamed_addr global i8* getelementptr inbounds ({ i16, i8, i8 }, { i16, i8, i8 }* @someArray, i64 0, i32 1) -- -2.36.1 +2.38.1 diff --git a/0018-ci-add-support-for-LLVM-15.patch b/0018-ci-add-support-for-LLVM-15.patch index 7c17787..a947661 100644 --- a/0018-ci-add-support-for-LLVM-15.patch +++ b/0018-ci-add-support-for-LLVM-15.patch @@ -1,7 +1,7 @@ From 6557b534a1c2195cb7f2a465f8dc36662525f764 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 22 Sep 2022 13:39:51 +0200 -Subject: [PATCH 18/18] ci: add support for LLVM 15 +Subject: [PATCH 18/26] ci: add support for LLVM 15 This commit switches to LLVM 15 everywhere by default, while still keeping LLVM 14 support. @@ -3486,5 +3486,5 @@ index d70bc626..209e15ae 100644 // Get the underlying type. interfaceType = builder.CreateExtractValue(interfaceType.Initializer(), 0, "") -- -2.36.1 +2.38.1 diff --git a/0019-src-runtime-add-xorshift-based-fastrand64.patch b/0019-src-runtime-add-xorshift-based-fastrand64.patch new file mode 100644 index 0000000..9323d7a --- /dev/null +++ b/0019-src-runtime-add-xorshift-based-fastrand64.patch @@ -0,0 +1,40 @@ +From 8686fd42351642868970dacc76519fe6ac3f8fac Mon Sep 17 00:00:00 2001 +From: Damian Gryski +Date: Fri, 6 Jan 2023 20:24:34 -0800 +Subject: [PATCH 19/26] src/runtime: add xorshift-based fastrand64 + +Signed-off-by: Elliott Sales de Andrade +--- + src/runtime/algorithm.go | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/src/runtime/algorithm.go b/src/runtime/algorithm.go +index 15487176..35e2e260 100644 +--- a/src/runtime/algorithm.go ++++ b/src/runtime/algorithm.go +@@ -25,6 +25,22 @@ func xorshift32(x uint32) uint32 { + return x + } + ++// This function is used by hash/maphash. ++func fastrand64() uint64 { ++ xorshift64State = xorshiftMult64(xorshift64State) ++ return xorshift64State ++} ++ ++var xorshift64State uint64 = 1 ++ ++// 64-bit xorshift multiply rng from http://vigna.di.unimi.it/ftp/papers/xorshift.pdf ++func xorshiftMult64(x uint64) uint64 { ++ x ^= x >> 12 // a ++ x ^= x << 25 // b ++ x ^= x >> 27 // c ++ return x * 2685821657736338717 ++} ++ + // This function is used by hash/maphash. + func memhash(p unsafe.Pointer, seed, s uintptr) uintptr { + if unsafe.Sizeof(uintptr(0)) > 4 { +-- +2.38.1 + diff --git a/0020-testing-implement-t.Setenv.patch b/0020-testing-implement-t.Setenv.patch new file mode 100644 index 0000000..0627c88 --- /dev/null +++ b/0020-testing-implement-t.Setenv.patch @@ -0,0 +1,129 @@ +From 42d8bf6be8c01504667e858a1b13079956ab53cd Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sat, 14 Jan 2023 19:32:36 +0100 +Subject: [PATCH 20/26] testing: implement t.Setenv + +This method has been added in Go 1.17 and is used in archive/zip +starting with Go 1.20. Therefore, this method is now needed in Go 1.20. + +I've left out the parts that disable parallel execution of tests, +because we don't do that in TinyGo. + +See: +* https://github.com/golang/go/issues/41260 +* https://go-review.googlesource.com/c/go/+/260577 + +Signed-off-by: Elliott Sales de Andrade +--- + src/testing/testing.go | 22 ++++++++++++++ + src/testing/testing_test.go | 57 +++++++++++++++++++++++++++++++++++++ + 2 files changed, 79 insertions(+) + +diff --git a/src/testing/testing.go b/src/testing/testing.go +index a458f267..d5af277e 100644 +--- a/src/testing/testing.go ++++ b/src/testing/testing.go +@@ -117,6 +117,7 @@ type TB interface { + Log(args ...interface{}) + Logf(format string, args ...interface{}) + Name() string ++ Setenv(key, value string) + Skip(args ...interface{}) + SkipNow() + Skipf(format string, args ...interface{}) +@@ -330,6 +331,27 @@ func (c *common) TempDir() string { + return dir + } + ++// Setenv calls os.Setenv(key, value) and uses Cleanup to ++// restore the environment variable to its original value ++// after the test. ++func (c *common) Setenv(key, value string) { ++ prevValue, ok := os.LookupEnv(key) ++ ++ if err := os.Setenv(key, value); err != nil { ++ c.Fatalf("cannot set environment variable: %v", err) ++ } ++ ++ if ok { ++ c.Cleanup(func() { ++ os.Setenv(key, prevValue) ++ }) ++ } else { ++ c.Cleanup(func() { ++ os.Unsetenv(key) ++ }) ++ } ++} ++ + // runCleanup is called at the end of the test. + func (c *common) runCleanup() { + for { +diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go +index 3ab32426..6a8607b2 100644 +--- a/src/testing/testing_test.go ++++ b/src/testing/testing_test.go +@@ -139,3 +139,60 @@ func testTempDir(t *testing.T) { + t.Errorf("unexpected files in TempDir") + } + } ++ ++func TestSetenv(t *testing.T) { ++ tests := []struct { ++ name string ++ key string ++ initialValueExists bool ++ initialValue string ++ newValue string ++ }{ ++ { ++ name: "initial value exists", ++ key: "GO_TEST_KEY_1", ++ initialValueExists: true, ++ initialValue: "111", ++ newValue: "222", ++ }, ++ { ++ name: "initial value exists but empty", ++ key: "GO_TEST_KEY_2", ++ initialValueExists: true, ++ initialValue: "", ++ newValue: "222", ++ }, ++ { ++ name: "initial value is not exists", ++ key: "GO_TEST_KEY_3", ++ initialValueExists: false, ++ initialValue: "", ++ newValue: "222", ++ }, ++ } ++ ++ for _, test := range tests { ++ if test.initialValueExists { ++ if err := os.Setenv(test.key, test.initialValue); err != nil { ++ t.Fatalf("unable to set env: got %v", err) ++ } ++ } else { ++ os.Unsetenv(test.key) ++ } ++ ++ t.Run(test.name, func(t *testing.T) { ++ t.Setenv(test.key, test.newValue) ++ if os.Getenv(test.key) != test.newValue { ++ t.Fatalf("unexpected value after t.Setenv: got %s, want %s", os.Getenv(test.key), test.newValue) ++ } ++ }) ++ ++ got, exists := os.LookupEnv(test.key) ++ if got != test.initialValue { ++ t.Fatalf("unexpected value after t.Setenv cleanup: got %s, want %s", got, test.initialValue) ++ } ++ if exists != test.initialValueExists { ++ t.Fatalf("unexpected value after t.Setenv cleanup: got %t, want %t", exists, test.initialValueExists) ++ } ++ } ++} +-- +2.38.1 + diff --git a/0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch b/0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch new file mode 100644 index 0000000..d349bc6 --- /dev/null +++ b/0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch @@ -0,0 +1,255 @@ +From adf2a54b66083cbe88ee8bbb695d136f2e90fb58 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 13 Jan 2023 17:52:18 +0000 +Subject: [PATCH 21/26] compiler: add support for new unsafe slice/string + functions + +This adds support for unsafe.SliceData, unsafe.String, and +unsafe.SringData that were introduced in Go 1.20. + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/asserts.go | 11 +++---- + compiler/compiler.go | 40 ++++++++++++++++--------- + compiler/compiler_test.go | 10 +++++++ + compiler/testdata/go1.20.go | 15 ++++++++++ + compiler/testdata/go1.20.ll | 58 +++++++++++++++++++++++++++++++++++++ + src/runtime/panic.go | 7 +++-- + 6 files changed, 120 insertions(+), 21 deletions(-) + create mode 100644 compiler/testdata/go1.20.go + create mode 100644 compiler/testdata/go1.20.ll + +diff --git a/compiler/asserts.go b/compiler/asserts.go +index ba482494..0fb112e0 100644 +--- a/compiler/asserts.go ++++ b/compiler/asserts.go +@@ -89,10 +89,11 @@ func (b *builder) createSliceToArrayPointerCheck(sliceLen llvm.Value, arrayLen i + b.createRuntimeAssert(isLess, "slicetoarray", "sliceToArrayPointerPanic") + } + +-// createUnsafeSliceCheck inserts a runtime check used for unsafe.Slice. This +-// function must panic if the ptr/len parameters are invalid. +-func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, elementType llvm.Type, lenType *types.Basic) { +- // From the documentation of unsafe.Slice: ++// createUnsafeSliceStringCheck inserts a runtime check used for unsafe.Slice ++// and unsafe.String. This function must panic if the ptr/len parameters are ++// invalid. ++func (b *builder) createUnsafeSliceStringCheck(name string, ptr, len llvm.Value, elementType llvm.Type, lenType *types.Basic) { ++ // From the documentation of unsafe.Slice and unsafe.String: + // > At run time, if len is negative, or if ptr is nil and len is not + // > zero, a run-time panic occurs. + // However, in practice, it is also necessary to check that the length is +@@ -117,7 +118,7 @@ func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, elementType llvm.T + lenIsNotZero := b.CreateICmp(llvm.IntNE, len, zero, "") + assert := b.CreateAnd(ptrIsNil, lenIsNotZero, "") + assert = b.CreateOr(assert, lenOutOfBounds, "") +- b.createRuntimeAssert(assert, "unsafe.Slice", "unsafeSlicePanic") ++ b.createRuntimeAssert(assert, name, "unsafeSlicePanic") + } + + // createChanBoundsCheck creates a bounds check before creating a new channel to +diff --git a/compiler/compiler.go b/compiler/compiler.go +index 8b6e8661..eda045ab 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -1638,20 +1638,20 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + case "Sizeof": // unsafe.Sizeof + size := b.targetData.TypeAllocSize(argValues[0].Type()) + return llvm.ConstInt(b.uintptrType, size, false), nil +- case "Slice": // unsafe.Slice +- // This creates a slice from a pointer and a length. ++ case "Slice", "String": // unsafe.Slice, unsafe.String ++ // This creates a slice or string from a pointer and a length. + // Note that the exception mentioned in the documentation (if the + // pointer and length are nil, the slice is also nil) is trivially + // already the case. + ptr := argValues[0] + len := argValues[1] +- slice := llvm.Undef(b.ctx.StructType([]llvm.Type{ +- ptr.Type(), +- b.uintptrType, +- b.uintptrType, +- }, false)) +- elementType := b.getLLVMType(argTypes[0].Underlying().(*types.Pointer).Elem()) +- b.createUnsafeSliceCheck(ptr, len, elementType, argTypes[1].Underlying().(*types.Basic)) ++ var elementType llvm.Type ++ if callName == "Slice" { ++ elementType = b.getLLVMType(argTypes[0].Underlying().(*types.Pointer).Elem()) ++ } else { ++ elementType = b.ctx.Int8Type() ++ } ++ b.createUnsafeSliceStringCheck("unsafe."+callName, ptr, len, elementType, argTypes[1].Underlying().(*types.Basic)) + if len.Type().IntTypeWidth() < b.uintptrType.IntTypeWidth() { + // Too small, zero-extend len. + len = b.CreateZExt(len, b.uintptrType, "") +@@ -1659,10 +1659,24 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c + // Too big, truncate len. + len = b.CreateTrunc(len, b.uintptrType, "") + } +- slice = b.CreateInsertValue(slice, ptr, 0, "") +- slice = b.CreateInsertValue(slice, len, 1, "") +- slice = b.CreateInsertValue(slice, len, 2, "") +- return slice, nil ++ if callName == "Slice" { ++ slice := llvm.Undef(b.ctx.StructType([]llvm.Type{ ++ ptr.Type(), ++ b.uintptrType, ++ b.uintptrType, ++ }, false)) ++ slice = b.CreateInsertValue(slice, ptr, 0, "") ++ slice = b.CreateInsertValue(slice, len, 1, "") ++ slice = b.CreateInsertValue(slice, len, 2, "") ++ return slice, nil ++ } else { ++ str := llvm.Undef(b.getLLVMRuntimeType("_string")) ++ str = b.CreateInsertValue(str, argValues[0], 0, "") ++ str = b.CreateInsertValue(str, len, 1, "") ++ return str, nil ++ } ++ case "SliceData", "StringData": // unsafe.SliceData, unsafe.StringData ++ return b.CreateExtractValue(argValues[0], 0, "slice.data"), nil + default: + return llvm.Value{}, b.makeError(pos, "todo: builtin: "+callName) + } +diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go +index a5cd9c6b..f8221a08 100644 +--- a/compiler/compiler_test.go ++++ b/compiler/compiler_test.go +@@ -9,6 +9,7 @@ import ( + "testing" + + "github.com/tinygo-org/tinygo/compileopts" ++ "github.com/tinygo-org/tinygo/goenv" + "github.com/tinygo-org/tinygo/loader" + "tinygo.org/x/go-llvm" + ) +@@ -27,6 +28,12 @@ type testCase struct { + func TestCompiler(t *testing.T) { + t.Parallel() + ++ // Determine Go minor version (e.g. 16 in go1.16.3). ++ _, goMinor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) ++ if err != nil { ++ t.Fatal("could not read Go version:", err) ++ } ++ + // Determine which tests to run, depending on the Go and LLVM versions. + tests := []testCase{ + {"basic.go", "", ""}, +@@ -43,6 +50,9 @@ func TestCompiler(t *testing.T) { + {"channel.go", "", ""}, + {"gc.go", "", ""}, + } ++ if goMinor >= 20 { ++ tests = append(tests, testCase{"go1.20.go", "", ""}) ++ } + + for _, tc := range tests { + name := tc.file +diff --git a/compiler/testdata/go1.20.go b/compiler/testdata/go1.20.go +new file mode 100644 +index 00000000..be65363e +--- /dev/null ++++ b/compiler/testdata/go1.20.go +@@ -0,0 +1,15 @@ ++package main ++ ++import "unsafe" ++ ++func unsafeSliceData(s []int) *int { ++ return unsafe.SliceData(s) ++} ++ ++func unsafeString(ptr *byte, len int16) string { ++ return unsafe.String(ptr, len) ++} ++ ++func unsafeStringData(s string) *byte { ++ return unsafe.StringData(s) ++} +diff --git a/compiler/testdata/go1.20.ll b/compiler/testdata/go1.20.ll +new file mode 100644 +index 00000000..fc66b47c +--- /dev/null ++++ b/compiler/testdata/go1.20.ll +@@ -0,0 +1,58 @@ ++; ModuleID = 'go1.20.go' ++source_filename = "go1.20.go" ++target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" ++target triple = "wasm32-unknown-wasi" ++ ++%runtime._string = type { ptr, i32 } ++ ++declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 ++ ++declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 ++ ++; Function Attrs: nounwind ++define hidden void @main.init(ptr %context) unnamed_addr #1 { ++entry: ++ ret void ++} ++ ++; Function Attrs: nounwind ++define hidden ptr @main.unsafeSliceData(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #1 { ++entry: ++ call void @runtime.trackPointer(ptr %s.data, ptr undef) #2 ++ ret ptr %s.data ++} ++ ++; Function Attrs: nounwind ++define hidden %runtime._string @main.unsafeString(ptr dereferenceable_or_null(1) %ptr, i16 %len, ptr %context) unnamed_addr #1 { ++entry: ++ %0 = icmp slt i16 %len, 0 ++ %1 = icmp eq ptr %ptr, null ++ %2 = icmp ne i16 %len, 0 ++ %3 = and i1 %1, %2 ++ %4 = or i1 %3, %0 ++ br i1 %4, label %unsafe.String.throw, label %unsafe.String.next ++ ++unsafe.String.next: ; preds = %entry ++ %5 = zext i16 %len to i32 ++ %6 = insertvalue %runtime._string undef, ptr %ptr, 0 ++ %7 = insertvalue %runtime._string %6, i32 %5, 1 ++ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 ++ ret %runtime._string %7 ++ ++unsafe.String.throw: ; preds = %entry ++ call void @runtime.unsafeSlicePanic(ptr undef) #2 ++ unreachable ++} ++ ++declare void @runtime.unsafeSlicePanic(ptr) #0 ++ ++; Function Attrs: nounwind ++define hidden ptr @main.unsafeStringData(ptr %s.data, i32 %s.len, ptr %context) unnamed_addr #1 { ++entry: ++ call void @runtime.trackPointer(ptr %s.data, ptr undef) #2 ++ ret ptr %s.data ++} ++ ++attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } ++attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } ++attributes #2 = { nounwind } +diff --git a/src/runtime/panic.go b/src/runtime/panic.go +index d7ba9ded..c9c69363 100644 +--- a/src/runtime/panic.go ++++ b/src/runtime/panic.go +@@ -143,10 +143,11 @@ func sliceToArrayPointerPanic() { + runtimePanic("slice smaller than array") + } + +-// Panic when calling unsafe.Slice() (Go 1.17+) with a len that's too large +-// (which includes if the ptr is nil and len is nonzero). ++// Panic when calling unsafe.Slice() (Go 1.17+) or unsafe.String() (Go 1.20+) ++// with a len that's too large (which includes if the ptr is nil and len is ++// nonzero). + func unsafeSlicePanic() { +- runtimePanic("unsafe.Slice: len out of range") ++ runtimePanic("unsafe.Slice/String: len out of range") + } + + // Panic when trying to create a new channel that is too big. +-- +2.38.1 + diff --git a/0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch b/0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch new file mode 100644 index 0000000..7f4ff02 --- /dev/null +++ b/0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch @@ -0,0 +1,35 @@ +From c6b1937fefc56c73648ba5339420bd9151e63fc8 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 13 Jan 2023 19:54:05 +0100 +Subject: [PATCH 22/26] runtime: implement math/rand.fastrand64 to fix linker + error + +This is needed for Go 1.20 support. + +Signed-off-by: Elliott Sales de Andrade +--- + src/runtime/algorithm.go | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/src/runtime/algorithm.go b/src/runtime/algorithm.go +index 35e2e260..11b39200 100644 +--- a/src/runtime/algorithm.go ++++ b/src/runtime/algorithm.go +@@ -7,6 +7,14 @@ import ( + "unsafe" + ) + ++// This function is needed by math/rand since Go 1.20. ++// See: https://github.com/golang/go/issues/54880 ++// ++//go:linkname rand_fastrand64 math/rand.fastrand64 ++func rand_fastrand64() uint64 { ++ return fastrand64() ++} ++ + // This function is used by hash/maphash. + func fastrand() uint32 { + xorshift32State = xorshift32(xorshift32State) +-- +2.38.1 + diff --git a/0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch b/0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch new file mode 100644 index 0000000..cd73b3f --- /dev/null +++ b/0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch @@ -0,0 +1,31 @@ +From 89e962d18b5d85cad8f6ee14c030aaccdcd89728 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 13 Jan 2023 20:02:54 +0100 +Subject: [PATCH 23/26] runtime: implement internal/godebug.setUpdate as a stub + +This function provides a mechanism to watch for changes to the GODEBUG +environment variable. For now, we'll not implement it. It might be +useful in the future, when it can always be added. + +Signed-off-by: Elliott Sales de Andrade +--- + src/runtime/runtime.go | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go +index 4e24b923..c9df6939 100644 +--- a/src/runtime/runtime.go ++++ b/src/runtime/runtime.go +@@ -87,3 +87,9 @@ func LockOSThread() { + // Stub for now + func UnlockOSThread() { + } ++ ++//go:linkname godebug_setUpdate internal/godebug.setUpdate ++func godebug_setUpdate(update func(string, string)) { ++ // Unimplemented. The 'update' function needs to be called whenever the ++ // GODEBUG environment variable changes (for example, via os.Setenv). ++} +-- +2.38.1 + diff --git a/0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch b/0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch new file mode 100644 index 0000000..791d6a8 --- /dev/null +++ b/0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch @@ -0,0 +1,136 @@ +From cce74aa2f32a29c2dd473b8240680fdc49314486 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sat, 14 Jan 2023 23:10:44 +0100 +Subject: [PATCH 24/26] syscall: implement setenv/unsetenv in the runtime + +This is expected starting with Go 1.20. + +I've also applied the same modification to syscall_libc.go so that +setenv is only called in a single place. + +Signed-off-by: Elliott Sales de Andrade +--- + src/runtime/{env_linux.go => env_unix.go} | 34 +++++++++++++++-------- + src/syscall/syscall_libc.go | 27 ++++-------------- + 2 files changed, 29 insertions(+), 32 deletions(-) + rename src/runtime/{env_linux.go => env_unix.go} (66%) + +diff --git a/src/runtime/env_linux.go b/src/runtime/env_unix.go +similarity index 66% +rename from src/runtime/env_linux.go +rename to src/runtime/env_unix.go +index cfe8c7f8..e05e063a 100644 +--- a/src/runtime/env_linux.go ++++ b/src/runtime/env_unix.go +@@ -1,29 +1,41 @@ +-//go:build linux +-// +build linux ++//go:build linux || darwin ++// +build linux darwin + + package runtime + + // Update the C environment if cgo is loaded. +-// Called from syscall.Setenv. ++// Called from Go 1.20 and above. + // +-//go:linkname syscall_setenv_c syscall.setenv_c +-func syscall_setenv_c(key string, val string) { ++//go:linkname syscallSetenv syscall.runtimeSetenv ++func syscallSetenv(key, value string) { + keydata := cstring(key) +- valdata := cstring(val) ++ valdata := cstring(value) + // ignore any errors + libc_setenv(&keydata[0], &valdata[0], 1) +- return + } + + // Update the C environment if cgo is loaded. +-// Called from syscall.Unsetenv. ++// Called from Go 1.20 and above. + // +-//go:linkname syscall_unsetenv_c syscall.unsetenv_c +-func syscall_unsetenv_c(key string) { ++//go:linkname syscallUnsetenv syscall.runtimeUnsetenv ++func syscallUnsetenv(key string) { + keydata := cstring(key) + // ignore any errors + libc_unsetenv(&keydata[0]) +- return ++} ++ ++// Compatibility with Go 1.19 and below. ++// ++//go:linkname syscall_setenv_c syscall.setenv_c ++func syscall_setenv_c(key string, val string) { ++ syscallSetenv(key, val) ++} ++ ++// Compatibility with Go 1.19 and below. ++// ++//go:linkname syscall_unsetenv_c syscall.unsetenv_c ++func syscall_unsetenv_c(key string) { ++ syscallUnsetenv(key) + } + + // cstring converts a Go string to a C string. +diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go +index 0f10b7fb..1d3d69c7 100644 +--- a/src/syscall/syscall_libc.go ++++ b/src/syscall/syscall_libc.go +@@ -198,21 +198,12 @@ func Setenv(key, val string) (err error) { + return EINVAL + } + } +- keydata := cstring(key) +- valdata := cstring(val) +- errCode := libc_setenv(&keydata[0], &valdata[0], 1) +- if errCode != 0 { +- err = getErrno() +- } ++ runtimeSetenv(key, val) + return + } + + func Unsetenv(key string) (err error) { +- keydata := cstring(key) +- errCode := libc_unsetenv(&keydata[0]) +- if errCode != 0 { +- err = getErrno() +- } ++ runtimeUnsetenv(key) + return + } + +@@ -313,6 +304,10 @@ func splitSlice(p []byte) (buf *byte, len uintptr) { + return slice.buf, slice.len + } + ++// These two functions are provided by the runtime. ++func runtimeSetenv(key, value string) ++func runtimeUnsetenv(key string) ++ + //export strlen + func libc_strlen(ptr unsafe.Pointer) uintptr + +@@ -326,16 +321,6 @@ func libc_write(fd int32, buf *byte, count uint) int + //export getenv + func libc_getenv(name *byte) *byte + +-// int setenv(const char *name, const char *val, int replace); +-// +-//export setenv +-func libc_setenv(name *byte, val *byte, replace int32) int32 +- +-// int unsetenv(const char *name); +-// +-//export unsetenv +-func libc_unsetenv(name *byte) int32 +- + // ssize_t read(int fd, void *buf, size_t count); + // + //export read +-- +2.38.1 + diff --git a/0025-builder-add-support-for-Go-1.20.patch b/0025-builder-add-support-for-Go-1.20.patch new file mode 100644 index 0000000..ef16562 --- /dev/null +++ b/0025-builder-add-support-for-Go-1.20.patch @@ -0,0 +1,139 @@ +From 41d29d766af9aa9251560c48f0591c5fa2ad9886 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 13 Jan 2023 17:53:55 +0000 +Subject: [PATCH 25/26] builder: add support for Go 1.20 + +Not all features work yet, but allow it to compile with this Go version. + +Signed-off-by: Elliott Sales de Andrade +--- + .circleci/config.yml | 8 ++++++++ + Makefile | 1 - + builder/config.go | 4 ++-- + cgo/cgo_test.go | 15 +++++++++++---- + cgo/testdata/errors.out.go | 4 ++-- + testdata/stdlib.go | 2 +- + 6 files changed, 24 insertions(+), 10 deletions(-) + +diff --git a/.circleci/config.yml b/.circleci/config.yml +index 38621258..74217b12 100644 +--- a/.circleci/config.yml ++++ b/.circleci/config.yml +@@ -119,6 +119,13 @@ jobs: + - test-linux: + llvm: "14" + resource_class: large ++ test-llvm15-go120: ++ docker: ++ - image: golang:1.20-rc-buster ++ steps: ++ - test-linux: ++ llvm: "15" ++ resource_class: large + + workflows: + test-all: +@@ -126,3 +133,4 @@ workflows: + # This tests our lowest supported versions of Go and LLVM, to make sure at + # least the smoke tests still pass. + - test-llvm14-go118 ++ - test-llvm15-go120 +diff --git a/Makefile b/Makefile +index 89927961..5253900d 100644 +--- a/Makefile ++++ b/Makefile +@@ -280,7 +280,6 @@ TEST_PACKAGES_FAST = \ + container/list \ + container/ring \ + crypto/des \ +- crypto/internal/subtle \ + crypto/md5 \ + crypto/rc4 \ + crypto/sha1 \ +diff --git a/builder/config.go b/builder/config.go +index c55ce1a2..a7df83f1 100644 +--- a/builder/config.go ++++ b/builder/config.go +@@ -33,8 +33,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { + if err != nil { + return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) + } +- if major != 1 || minor < 18 || minor > 19 { +- return nil, fmt.Errorf("requires go version 1.18 through 1.19, got go%d.%d", major, minor) ++ if major != 1 || minor < 18 || minor > 20 { ++ return nil, fmt.Errorf("requires go version 1.18 through 1.20, got go%d.%d", major, minor) + } + + clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) +diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go +index e25da7a1..a44dd8e1 100644 +--- a/cgo/cgo_test.go ++++ b/cgo/cgo_test.go +@@ -11,6 +11,7 @@ import ( + "go/types" + "os" + "path/filepath" ++ "regexp" + "runtime" + "strings" + "testing" +@@ -21,9 +22,15 @@ var flagUpdate = flag.Bool("update", false, "Update images based on test output. + + // normalizeResult normalizes Go source code that comes out of tests across + // platforms and Go versions. +-func normalizeResult(result string) string { +- actual := strings.ReplaceAll(result, "\r\n", "\n") +- return actual ++func normalizeResult(t *testing.T, result string) string { ++ result = strings.ReplaceAll(result, "\r\n", "\n") ++ ++ // This changed to 'undefined:', in Go 1.20. ++ result = strings.ReplaceAll(result, ": undeclared name:", ": undefined:") ++ // Go 1.20 added a bit more detail ++ result = regexp.MustCompile(`(unknown field z in struct literal).*`).ReplaceAllString(result, "$1") ++ ++ return result + } + + func TestCGo(t *testing.T) { +@@ -88,7 +95,7 @@ func TestCGo(t *testing.T) { + if err != nil { + t.Errorf("could not write out CGo AST: %v", err) + } +- actual := normalizeResult(buf.String()) ++ actual := normalizeResult(t, buf.String()) + + // Read the file with the expected output, to compare against. + outfile := filepath.Join("testdata", name+".out.go") +diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go +index b15a26b6..716fd771 100644 +--- a/cgo/testdata/errors.out.go ++++ b/cgo/testdata/errors.out.go +@@ -8,9 +8,9 @@ + // Type checking errors after CGo processing: + // testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as C.char value in variable declaration (overflows) + // testdata/errors.go:105: unknown field z in struct literal +-// testdata/errors.go:108: undeclared name: C.SOME_CONST_1 ++// testdata/errors.go:108: undefined: C.SOME_CONST_1 + // testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows) +-// testdata/errors.go:112: undeclared name: C.SOME_CONST_4 ++// testdata/errors.go:112: undefined: C.SOME_CONST_4 + + package main + +diff --git a/testdata/stdlib.go b/testdata/stdlib.go +index bc59d20c..f051eaf0 100644 +--- a/testdata/stdlib.go ++++ b/testdata/stdlib.go +@@ -24,7 +24,7 @@ func main() { + syscall.Getppid() + + // package math/rand +- fmt.Println("pseudorandom number:", rand.Int31()) ++ fmt.Println("pseudorandom number:", rand.New(rand.NewSource(1)).Int31()) + + // package strings + fmt.Println("strings.IndexByte:", strings.IndexByte("asdf", 'd')) +-- +2.38.1 + diff --git a/0026-Skip-archive-zip-tests.patch b/0026-Skip-archive-zip-tests.patch new file mode 100644 index 0000000..5ee4b93 --- /dev/null +++ b/0026-Skip-archive-zip-tests.patch @@ -0,0 +1,36 @@ +From 3ab845ff45c17ed5079a1b63e98f217cd0be26aa Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 23 Jan 2023 02:28:27 -0500 +Subject: [PATCH 26/26] Skip archive/zip tests + +Signed-off-by: Elliott Sales de Andrade +--- + Makefile | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 5253900d..8ac92040 100644 +--- a/Makefile ++++ b/Makefile +@@ -336,7 +336,6 @@ endif + + # Additional standard library packages that pass tests on individual platforms + TEST_PACKAGES_LINUX := \ +- archive/zip \ + compress/lzw \ + crypto/hmac \ + debug/dwarf \ +@@ -352,6 +351,10 @@ TEST_PACKAGES_LINUX += \ + compress/flate \ + testing/fstest + endif ++ifeq ($(filter-out $(shell $(GO) env GOVERSION | cut -f 2 -d.), 18 19), ) ++TEST_PACKAGES_LINUX += \ ++ archive/zip ++endif + + TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) + +-- +2.38.1 + diff --git a/tinygo.spec b/tinygo.spec index f358329..08d8ed3 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -98,6 +98,19 @@ Patch0015: 0015-transform-fix-memory-corruption-issues.patch Patch0016: 0016-riscv-add-target-abi-metadata-flag.patch Patch0017: 0017-interp-add-support-for-constant-icmp-instructions.patch Patch0018: 0018-ci-add-support-for-LLVM-15.patch +# Backport patches for Go 1.20 support +# https://github.com/tinygo-org/tinygo/pull/3368 +Patch0019: 0019-src-runtime-add-xorshift-based-fastrand64.patch +# https://github.com/tinygo-org/tinygo/pull/3387 +Patch0020: 0020-testing-implement-t.Setenv.patch +# https://github.com/tinygo-org/tinygo/pull/3391 +Patch0021: 0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch +Patch0022: 0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch +Patch0023: 0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch +Patch0024: 0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch +Patch0025: 0025-builder-add-support-for-Go-1.20.patch +# https://github.com/tinygo-org/tinygo/issues/3408 +Patch0026: 0026-Skip-archive-zip-tests.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x From 35a3896d93ed10089a08a80260e8bb043ff97b7d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 25 Feb 2023 20:42:30 -0500 Subject: [PATCH 46/78] Update to latest version (#2169260) --- .gitignore | 4 + 0001-Skip-WASI-tests.patch | 12 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 12 +- 0002-Use-system-mingw64-headers-and-crt.patch | 122 - ...ional-packages-to-install-if-missing.patch | 40 +- ...004-Skip-TestDirFS-on-32-bit-systems.patch | 10 +- ...ch => 0005-Skip-broken-tests-on-i686.patch | 10 +- 0007-wasm-fix-GC-scanning-of-allocas.patch | 265 -- ...a-FunctionType-not-a-PointerType-in-.patch | 52 - ...all-add-type-parameter-to-CreateCall.patch | 993 ----- ...all-add-type-parameter-to-CreateLoad.patch | 377 -- ...-all-add-type-parameter-to-GEP-calls.patch | 565 --- ....Const-calls-with-builder.Create-cal.patch | 578 --- ...ject.llvmType-to-the-initializer-typ.patch | 79 - ...all-remove-pointer-ElementType-calls.patch | 586 --- ...ansform-fix-memory-corruption-issues.patch | 31 - 0016-riscv-add-target-abi-metadata-flag.patch | 193 - ...pport-for-constant-icmp-instructions.patch | 195 - 0018-ci-add-support-for-LLVM-15.patch | 3490 ----------------- ...untime-add-xorshift-based-fastrand64.patch | 40 - 0020-testing-implement-t.Setenv.patch | 129 - ...port-for-new-unsafe-slice-string-fun.patch | 255 -- ...t-math-rand.fastrand64-to-fix-linker.patch | 35 - ...t-internal-godebug.setUpdate-as-a-st.patch | 31 - ...ement-setenv-unsetenv-in-the-runtime.patch | 136 - 0025-builder-add-support-for-Go-1.20.patch | 139 - 0026-Skip-archive-zip-tests.patch | 36 - sources | 9 +- tinygo.spec | 70 +- 29 files changed, 61 insertions(+), 8433 deletions(-) rename 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch => 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch (85%) delete mode 100644 0002-Use-system-mingw64-headers-and-crt.patch rename 0004-Suggest-optional-packages-to-install-if-missing.patch => 0003-Suggest-optional-packages-to-install-if-missing.patch (51%) rename 0005-Skip-TestDirFS-on-32-bit-systems.patch => 0004-Skip-TestDirFS-on-32-bit-systems.patch (76%) rename 0006-Skip-broken-tests-on-i686.patch => 0005-Skip-broken-tests-on-i686.patch (84%) delete mode 100644 0007-wasm-fix-GC-scanning-of-allocas.patch delete mode 100644 0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch delete mode 100644 0009-all-add-type-parameter-to-CreateCall.patch delete mode 100644 0010-all-add-type-parameter-to-CreateLoad.patch delete mode 100644 0011-all-add-type-parameter-to-GEP-calls.patch delete mode 100644 0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch delete mode 100644 0013-interp-change-object.llvmType-to-the-initializer-typ.patch delete mode 100644 0014-all-remove-pointer-ElementType-calls.patch delete mode 100644 0015-transform-fix-memory-corruption-issues.patch delete mode 100644 0016-riscv-add-target-abi-metadata-flag.patch delete mode 100644 0017-interp-add-support-for-constant-icmp-instructions.patch delete mode 100644 0018-ci-add-support-for-LLVM-15.patch delete mode 100644 0019-src-runtime-add-xorshift-based-fastrand64.patch delete mode 100644 0020-testing-implement-t.Setenv.patch delete mode 100644 0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch delete mode 100644 0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch delete mode 100644 0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch delete mode 100644 0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch delete mode 100644 0025-builder-add-support-for-Go-1.20.patch delete mode 100644 0026-Skip-archive-zip-tests.patch diff --git a/.gitignore b/.gitignore index 4ddee71..3668798 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,7 @@ /macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz /tinygo-0.25.0.tar.gz /tinygo-0.26.0.tar.gz +/tinygo-0.27.0.tar.gz +/musl-1.2.3.tar.gz +/musl-1.2.3.tar.gz.asc +/mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index bd9c522..b1f104f 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 6b50974a6d4972b755a35d40d87e5bdf9c97d925 Mon Sep 17 00:00:00 2001 +From c9fd61dedd6dd52edc9a3058d71923a639e2425f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 01/26] Skip WASI tests. +Subject: [PATCH 1/5] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index 9ddbe52f..79ae2cf2 100644 +index 72f3c4bb..b89ca6b9 100644 --- a/main_test.go +++ b/main_test.go -@@ -154,10 +154,6 @@ func TestBuild(t *testing.T) { +@@ -151,10 +151,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -25,7 +25,7 @@ index 9ddbe52f..79ae2cf2 100644 } } -@@ -413,7 +409,6 @@ func TestTest(t *testing.T) { +@@ -406,7 +402,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, @@ -34,5 +34,5 @@ index 9ddbe52f..79ae2cf2 100644 } for _, targ := range targs { -- -2.38.1 +2.39.2 diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch similarity index 85% rename from 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename to 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 5209323..efb1a31 100644 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 2a2e35e4565e8ea7f7ac2d34cb9da24000bb6474 Mon Sep 17 00:00:00 2001 +From 620ccf53e2a04f77aaae47a818db9bfef76f3104 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 03/26] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/5] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 28 insertions(+) diff --git a/main_test.go b/main_test.go -index 79ae2cf2..9359ef0c 100644 +index b89ca6b9..5168ad39 100644 --- a/main_test.go +++ b/main_test.go -@@ -252,6 +252,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -245,6 +245,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -38,7 +38,7 @@ index 79ae2cf2..9359ef0c 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -341,6 +355,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -334,6 +348,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } @@ -60,5 +60,5 @@ index 79ae2cf2..9359ef0c 100644 actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows -- -2.38.1 +2.39.2 diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch deleted file mode 100644 index 012aa83..0000000 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ /dev/null @@ -1,122 +0,0 @@ -From 76c575659d42187b0c4c15d4f5978c4368800da7 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 02/26] Use system mingw64 headers and crt - -Signed-off-by: Elliott Sales de Andrade ---- - builder/mingw-w64.go | 68 ++++--------------------------------------- - compileopts/config.go | 7 ++--- - 2 files changed, 7 insertions(+), 68 deletions(-) - -diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index 27fefee0..d233068d 100644 ---- a/builder/mingw-w64.go -+++ b/builder/mingw-w64.go -@@ -1,31 +1,11 @@ - package builder - - import ( -- "io" -- "os" -- "path/filepath" -- "strings" -- -- "github.com/tinygo-org/tinygo/goenv" -+ "fmt" - ) - - var MinGW = Library{ -- name: "mingw-w64", -- makeHeaders: func(target, includeDir string) error { -- // copy _mingw.h -- srcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib", "mingw-w64") -- outf, err := os.Create(includeDir + "/_mingw.h") -- if err != nil { -- return err -- } -- defer outf.Close() -- inf, err := os.Open(srcDir + "/mingw-w64-headers/crt/_mingw.h.in") -- if err != nil { -- return err -- } -- _, err = io.Copy(outf, inf) -- return err -- }, -+ name: "mingw-w64", - sourceDir: func() string { return "" }, // unused - cflags: func(target, headerPath string) []string { - // No flags necessary because there are no files to compile. -@@ -45,47 +25,9 @@ var MinGW = Library{ - // compile these files. - func makeMinGWExtraLibs(tmpdir string) []*compileJob { - var jobs []*compileJob -- root := goenv.Get("TINYGOROOT") -- // Normally all the api-ms-win-crt-*.def files are all compiled to a single -- // .lib file. But to simplify things, we're going to leave them as separate -- // files. -- for _, name := range []string{ -- "kernel32.def.in", -- "api-ms-win-crt-conio-l1-1-0.def", -- "api-ms-win-crt-convert-l1-1-0.def", -- "api-ms-win-crt-environment-l1-1-0.def", -- "api-ms-win-crt-filesystem-l1-1-0.def", -- "api-ms-win-crt-heap-l1-1-0.def", -- "api-ms-win-crt-locale-l1-1-0.def", -- "api-ms-win-crt-math-l1-1-0.def.in", -- "api-ms-win-crt-multibyte-l1-1-0.def", -- "api-ms-win-crt-private-l1-1-0.def.in", -- "api-ms-win-crt-process-l1-1-0.def", -- "api-ms-win-crt-runtime-l1-1-0.def.in", -- "api-ms-win-crt-stdio-l1-1-0.def", -- "api-ms-win-crt-string-l1-1-0.def", -- "api-ms-win-crt-time-l1-1-0.def", -- "api-ms-win-crt-utility-l1-1-0.def", -- } { -- outpath := filepath.Join(tmpdir, filepath.Base(name)+".lib") -- inpath := filepath.Join(root, "lib/mingw-w64/mingw-w64-crt/lib-common/"+name) -- job := &compileJob{ -- description: "create lib file " + inpath, -- result: outpath, -- run: func(job *compileJob) error { -- defpath := inpath -- if strings.HasSuffix(inpath, ".in") { -- // .in files need to be preprocessed by a preprocessor (-E) -- // first. -- defpath = outpath + ".def" -- err := runCCompiler("-E", "-x", "c", "-Wp,-w", "-P", "-DDEF_X64", "-DDATA", "-o", defpath, inpath, "-I"+goenv.Get("TINYGOROOT")+"/lib/mingw-w64/mingw-w64-crt/def-include/") -- if err != nil { -- return err -- } -- } -- return link("ld.lld", "-m", "i386pep", "-o", outpath, defpath) -- }, -- } -+ for _, name := range []string{"kernel32", "ucrt"} { -+ outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) -+ job := dummyCompileJob(outpath) - jobs = append(jobs, job) - } - return jobs -diff --git a/compileopts/config.go b/compileopts/config.go -index ebfc5082..cd49283d 100644 ---- a/compileopts/config.go -+++ b/compileopts/config.go -@@ -304,12 +304,9 @@ func (c *Config) CFlags() []string { - root := goenv.Get("TINYGOROOT") - cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") - case "mingw-w64": -- root := goenv.Get("TINYGOROOT") -- path, _ := c.LibcPath("mingw-w64") - cflags = append(cflags, -- "--sysroot="+path, -- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"), -- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"), -+ "--sysroot=/usr/x86_64-w64-mingw32/sys-root", -+ "-isystem", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", - "-D_UCRT", - ) - case "": --- -2.38.1 - diff --git a/0004-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch similarity index 51% rename from 0004-Suggest-optional-packages-to-install-if-missing.patch rename to 0003-Suggest-optional-packages-to-install-if-missing.patch index ab97660..d10f646 100644 --- a/0004-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,14 +1,12 @@ -From 3f935d679870de924aa65d78c23ecdcb483ab4a3 Mon Sep 17 00:00:00 2001 +From eab4bc3acc9b6381b0526049c001d78edc3f6902 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 04/26] Suggest optional packages to install if missing +Subject: [PATCH 3/5] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- - builder/jobs.go | 17 +++++++++++++++++ - builder/mingw-w64.go | 2 +- - builder/tools.go | 6 +++++- - 3 files changed, 23 insertions(+), 2 deletions(-) + builder/jobs.go | 17 +++++++++++++++++ + 1 file changed, 17 insertions(+) diff --git a/builder/jobs.go b/builder/jobs.go index 3d510974..d24a4165 100644 @@ -45,34 +43,6 @@ index 3d510974..d24a4165 100644 // dummyCompileJob returns a new *compileJob that produces an output without // doing anything. This can be useful where a *compileJob producing an output is // expected but nothing needs to be done, for example for a load from a cache. -diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index d233068d..d2539f6e 100644 ---- a/builder/mingw-w64.go -+++ b/builder/mingw-w64.go -@@ -27,7 +27,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob { - var jobs []*compileJob - for _, name := range []string{"kernel32", "ucrt"} { - outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) -- job := dummyCompileJob(outpath) -+ job := checkIfPackagedFileExistsJob(outpath, "mingw64-crt and mingw64-headers") - jobs = append(jobs, job) - } - return jobs -diff --git a/builder/tools.go b/builder/tools.go -index 53d89bf0..e55719b2 100644 ---- a/builder/tools.go -+++ b/builder/tools.go -@@ -46,5 +46,9 @@ func link(linker string, flags ...string) error { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Dir = goenv.Get("TINYGOROOT") -- return cmd.Run() -+ err := cmd.Run() -+ if linker == "avr-gcc" && errors.Is(err, exec.ErrNotFound) { -+ return errors.New("avr-gcc not found; please install avr-gcc and avr-libc via dnf") -+ } -+ return err - } -- -2.38.1 +2.39.2 diff --git a/0005-Skip-TestDirFS-on-32-bit-systems.patch b/0004-Skip-TestDirFS-on-32-bit-systems.patch similarity index 76% rename from 0005-Skip-TestDirFS-on-32-bit-systems.patch rename to 0004-Skip-TestDirFS-on-32-bit-systems.patch index dc9acd5..189e704 100644 --- a/0005-Skip-TestDirFS-on-32-bit-systems.patch +++ b/0004-Skip-TestDirFS-on-32-bit-systems.patch @@ -1,7 +1,7 @@ -From 41cbdf1cfe50f24b49beb615f0924ea3255c7e7d Mon Sep 17 00:00:00 2001 +From 3b851724c839268253ef0c243f379dbef4c0cfd6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 05/26] Skip TestDirFS on 32-bit systems +Subject: [PATCH 4/5] Skip TestDirFS on 32-bit systems Because Seek is not fully implemented there. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 4 insertions(+) diff --git a/src/os/os_anyos_test.go b/src/os/os_anyos_test.go -index dd255fb4..5dc0d860 100644 +index 76bf4f36..97b5cce8 100644 --- a/src/os/os_anyos_test.go +++ b/src/os/os_anyos_test.go -@@ -277,6 +277,10 @@ func TestDirFS(t *testing.T) { +@@ -276,6 +276,10 @@ func TestDirFS(t *testing.T) { t.Log("TODO: implement Readdir for Windows") return } @@ -26,5 +26,5 @@ index dd255fb4..5dc0d860 100644 t.Log("TODO: allow foo/bar/. as synonym for path foo/bar on wasi?") return -- -2.38.1 +2.39.2 diff --git a/0006-Skip-broken-tests-on-i686.patch b/0005-Skip-broken-tests-on-i686.patch similarity index 84% rename from 0006-Skip-broken-tests-on-i686.patch rename to 0005-Skip-broken-tests-on-i686.patch index 1c241b5..413fa53 100644 --- a/0006-Skip-broken-tests-on-i686.patch +++ b/0005-Skip-broken-tests-on-i686.patch @@ -1,7 +1,7 @@ -From a44f31de099aaf6768af2102919f1a8c221ce6f4 Mon Sep 17 00:00:00 2001 +From f432e01f5d2b8c64f74eeebf30dd428a421ee128 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 06/26] Skip broken tests on i686 +Subject: [PATCH 5/5] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there @@ -12,10 +12,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile -index 99f67c29..1ef11d29 100644 +index 452b0171..f04ccbdb 100644 --- a/Makefile +++ b/Makefile -@@ -338,15 +338,21 @@ endif +@@ -343,15 +343,21 @@ endif # Additional standard library packages that pass tests on individual platforms TEST_PACKAGES_LINUX := \ archive/zip \ @@ -40,5 +40,5 @@ index 99f67c29..1ef11d29 100644 TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) -- -2.38.1 +2.39.2 diff --git a/0007-wasm-fix-GC-scanning-of-allocas.patch b/0007-wasm-fix-GC-scanning-of-allocas.patch deleted file mode 100644 index 5397b13..0000000 --- a/0007-wasm-fix-GC-scanning-of-allocas.patch +++ /dev/null @@ -1,265 +0,0 @@ -From e8f07384a0f5a61351a62931d3fb69bf6c451c1b Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sun, 16 Oct 2022 00:44:38 +0200 -Subject: [PATCH 07/26] wasm: fix GC scanning of allocas - -Scanning of allocas was entirely broken on WebAssembly. The code -intended to do this was never run. There were also no tests. - -Looking into this further, I found that it is actually not really -necessary to do that: the C stack can be scanned conservatively and in -fact this was already done for goroutine stacks (because they live on -the heap and are always referenced). It wasn't done for the system stack -however. - -With these fixes, I believe code should be both faster *and* more -correct. - -I found this in my work to get opaque pointers supported in LLVM 15, -because the code that was never reached now finally got run and was -actually quite buggy. - -Signed-off-by: Elliott Sales de Andrade ---- - src/runtime/arch_tinygowasm.go | 3 +++ - src/runtime/asm_tinygowasm.S | 10 ++++++++++ - src/runtime/gc_stack_portable.go | 34 +++++++++++++++++++++----------- - targets/wasi.json | 3 +++ - targets/wasm.json | 3 +++ - transform/gc.go | 30 ++++++++-------------------- - transform/llvm.go | 28 ++++++++------------------ - 7 files changed, 57 insertions(+), 54 deletions(-) - create mode 100644 src/runtime/asm_tinygowasm.S - -diff --git a/src/runtime/arch_tinygowasm.go b/src/runtime/arch_tinygowasm.go -index 597b2489..f1893d91 100644 ---- a/src/runtime/arch_tinygowasm.go -+++ b/src/runtime/arch_tinygowasm.go -@@ -58,6 +58,8 @@ var ( - - globalsStart = uintptr(unsafe.Pointer(&globalsStartSymbol)) - globalsEnd = uintptr(unsafe.Pointer(&heapStartSymbol)) -+ -+ stackTop = uintptr(unsafe.Pointer(&globalsStartSymbol)) - ) - - func align(ptr uintptr) uintptr { -@@ -67,6 +69,7 @@ func align(ptr uintptr) uintptr { - return (ptr + heapAlign - 1) &^ (heapAlign - 1) - } - -+//export tinygo_getCurrentStackPointer - func getCurrentStackPointer() uintptr - - // growHeap tries to grow the heap size. It returns true if it succeeds, false -diff --git a/src/runtime/asm_tinygowasm.S b/src/runtime/asm_tinygowasm.S -new file mode 100644 -index 00000000..3278a7f6 ---- /dev/null -+++ b/src/runtime/asm_tinygowasm.S -@@ -0,0 +1,10 @@ -+.globaltype __stack_pointer, i32 -+ -+.global tinygo_getCurrentStackPointer -+.hidden tinygo_getCurrentStackPointer -+.type tinygo_getCurrentStackPointer,@function -+tinygo_getCurrentStackPointer: // func getCurrentStackPointer() uintptr -+ .functype tinygo_getCurrentStackPointer() -> (i32) -+ global.get __stack_pointer -+ return -+ end_function -diff --git a/src/runtime/gc_stack_portable.go b/src/runtime/gc_stack_portable.go -index 6ffc35d4..6802de02 100644 ---- a/src/runtime/gc_stack_portable.go -+++ b/src/runtime/gc_stack_portable.go -@@ -4,6 +4,7 @@ - package runtime - - import ( -+ "internal/task" - "unsafe" - ) - -@@ -17,19 +18,28 @@ type stackChainObject struct { - - // markStack marks all root pointers found on the stack. - // --// This implementation is conservative and relies on the compiler inserting code --// to manually push/pop stack objects that are stored in a linked list starting --// with stackChainStart. Manually keeping track of stack values is _much_ more --// expensive than letting the compiler do it and it inhibits a few important --// optimizations, but it has the big advantage of being portable to basically --// any ISA, including WebAssembly. -+// - Goroutine stacks are heap allocated and always reachable in some way -+// (for example through internal/task.currentTask) so they will always be -+// scanned. -+// - The system stack (aka startup stack) is not heap allocated, so even -+// though it may be referenced it will not be scanned by default. -+// -+// Therefore, we only need to scan the system stack. -+// It is relatively easy to scan the system stack while we're on it: we can -+// simply read __stack_pointer and __global_base and scan the area inbetween. -+// Unfortunately, it's hard to get the system stack pointer while we're on a -+// goroutine stack. But when we're on a goroutine stack, the system stack is in -+// the scheduler which means there shouldn't be anything on the system stack -+// anyway. -+// ...I hope this assumption holds, otherwise we will need to store the system -+// stack in a global or something. -+// -+// The compiler also inserts code to store all globals in a chain via -+// stackChainStart. Luckily we don't need to scan these, as these globals are -+// stored on the goroutine stack and are therefore already getting scanned. - func markStack() { -- stackObject := stackChainStart -- for stackObject != nil { -- start := uintptr(unsafe.Pointer(stackObject)) + unsafe.Sizeof(uintptr(0))*2 -- end := start + stackObject.numSlots*unsafe.Alignof(uintptr(0)) -- markRoots(start, end) -- stackObject = stackObject.parent -+ if task.OnSystemStack() { -+ markRoots(getCurrentStackPointer(), stackTop) - } - } - -diff --git a/targets/wasi.json b/targets/wasi.json -index e710b4bb..6cec6be4 100644 ---- a/targets/wasi.json -+++ b/targets/wasi.json -@@ -18,6 +18,9 @@ - "--stack-first", - "--no-demangle" - ], -+ "extra-files": [ -+ "src/runtime/asm_tinygowasm.S" -+ ], - "emulator": "wasmtime {}", - "wasm-abi": "generic" - } -diff --git a/targets/wasm.json b/targets/wasm.json -index 2bcada5f..26494cc4 100644 ---- a/targets/wasm.json -+++ b/targets/wasm.json -@@ -19,6 +19,9 @@ - "--stack-first", - "--no-demangle" - ], -+ "extra-files": [ -+ "src/runtime/asm_tinygowasm.S" -+ ], - "emulator": "node {root}/targets/wasm_exec.js {}", - "wasm-abi": "js" - } -diff --git a/transform/gc.go b/transform/gc.go -index eb3520aa..87dc6e88 100644 ---- a/transform/gc.go -+++ b/transform/gc.go -@@ -139,7 +139,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - } - - // Determine what to do with each call. -- var allocas, pointers []llvm.Value -+ var pointers []llvm.Value - for _, call := range calls { - ptr := call.Operand(0) - call.EraseFromParentAsInstruction() -@@ -189,16 +189,15 @@ func MakeGCStackSlots(mod llvm.Module) bool { - // be optimized if needed. - } - -- if !ptr.IsAAllocaInst().IsNil() { -- if typeHasPointers(ptr.Type().ElementType()) { -- allocas = append(allocas, ptr) -- } -- } else { -- pointers = append(pointers, ptr) -+ if ptr := stripPointerCasts(ptr); !ptr.IsAAllocaInst().IsNil() { -+ // Allocas don't need to be tracked because they are allocated -+ // on the C stack which is scanned separately. -+ continue - } -+ pointers = append(pointers, ptr) - } - -- if len(allocas) == 0 && len(pointers) == 0 { -+ if len(pointers) == 0 { - // This function does not need to keep track of stack pointers. - continue - } -@@ -208,9 +207,6 @@ func MakeGCStackSlots(mod llvm.Module) bool { - stackChainStartType, // Pointer to parent frame. - uintptrType, // Number of elements in this frame. - } -- for _, alloca := range allocas { -- fields = append(fields, alloca.Type().ElementType()) -- } - for _, ptr := range pointers { - fields = append(fields, ptr.Type()) - } -@@ -235,16 +231,6 @@ func MakeGCStackSlots(mod llvm.Module) bool { - stackObjectCast := builder.CreateBitCast(stackObject, stackChainStartType, "") - builder.CreateStore(stackObjectCast, stackChainStart) - -- // Replace all independent allocas with GEPs in the stack object. -- for i, alloca := range allocas { -- gep := builder.CreateGEP(stackObject, []llvm.Value{ -- llvm.ConstInt(ctx.Int32Type(), 0, false), -- llvm.ConstInt(ctx.Int32Type(), uint64(2+i), false), -- }, "") -- alloca.ReplaceAllUsesWith(gep) -- alloca.EraseFromParentAsInstruction() -- } -- - // Do a store to the stack object after each new pointer that is created. - pointerStores := make(map[llvm.Value]struct{}) - for i, ptr := range pointers { -@@ -260,7 +246,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - // Extract a pointer to the appropriate section of the stack object. - gep := builder.CreateGEP(stackObject, []llvm.Value{ - llvm.ConstInt(ctx.Int32Type(), 0, false), -- llvm.ConstInt(ctx.Int32Type(), uint64(2+len(allocas)+i), false), -+ llvm.ConstInt(ctx.Int32Type(), uint64(2+i), false), - }, "") - - // Store the pointer into the stack slot. -diff --git a/transform/llvm.go b/transform/llvm.go -index 90b7a7c7..32ee9560 100644 ---- a/transform/llvm.go -+++ b/transform/llvm.go -@@ -75,26 +75,14 @@ func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) ll - return global - } - --// typeHasPointers returns whether this type is a pointer or contains pointers. --// If the type is an aggregate type, it will check whether there is a pointer --// inside. --func typeHasPointers(t llvm.Type) bool { -- switch t.TypeKind() { -- case llvm.PointerTypeKind: -- return true -- case llvm.StructTypeKind: -- for _, subType := range t.StructElementTypes() { -- if typeHasPointers(subType) { -- return true -- } -+// stripPointerCasts strips instruction pointer casts (getelementptr and -+// bitcast) and returns the original value without the casts. -+func stripPointerCasts(value llvm.Value) llvm.Value { -+ if !value.IsAInstruction().IsNil() { -+ switch value.InstructionOpcode() { -+ case llvm.GetElementPtr, llvm.BitCast: -+ return stripPointerCasts(value.Operand(0)) - } -- return false -- case llvm.ArrayTypeKind: -- if typeHasPointers(t.ElementType()) { -- return true -- } -- return false -- default: -- return false - } -+ return value - } --- -2.38.1 - diff --git a/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch b/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch deleted file mode 100644 index 9045c40..0000000 --- a/0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 9e64a63d49100e550fad97b390bb01489ed6ca44 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Tue, 20 Sep 2022 23:59:22 +0200 -Subject: [PATCH 08/26] compiler: return a FunctionType (not a PointerType) in - getRawFuncType - -This is necessary for opaque pointer support (in LLVM 15). - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/func.go | 4 ++-- - compiler/interface.go | 2 +- - 2 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/compiler/func.go b/compiler/func.go -index 75656cb7..a8b2874e 100644 ---- a/compiler/func.go -+++ b/compiler/func.go -@@ -62,7 +62,7 @@ func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (f - funcPtr = bitcast.Operand(0) - return - } -- llvmSig := b.getRawFuncType(sig) -+ llvmSig := llvm.PointerType(b.getRawFuncType(sig), b.funcPtrAddrSpace) - funcPtr = b.CreateBitCast(bitcast, llvmSig, "") - return - } -@@ -117,7 +117,7 @@ func (c *compilerContext) getRawFuncType(typ *types.Signature) llvm.Type { - paramTypes = append(paramTypes, c.i8ptrType) // context - - // Make a func type out of the signature. -- return llvm.PointerType(llvm.FunctionType(returnType, paramTypes, false), c.funcPtrAddrSpace) -+ return llvm.FunctionType(returnType, paramTypes, false) - } - - // parseMakeClosure makes a function value (with context) from the given -diff --git a/compiler/interface.go b/compiler/interface.go -index c59a9ade..b0ea71e3 100644 ---- a/compiler/interface.go -+++ b/compiler/interface.go -@@ -465,7 +465,7 @@ func (c *compilerContext) getInvokeFunction(instr *ssa.CallCommon) llvm.Value { - paramTuple = append(paramTuple, sig.Params().At(i)) - } - paramTuple = append(paramTuple, types.NewVar(token.NoPos, nil, "$typecode", types.Typ[types.Uintptr])) -- llvmFnType := c.getRawFuncType(types.NewSignature(sig.Recv(), types.NewTuple(paramTuple...), sig.Results(), false)).ElementType() -+ llvmFnType := c.getRawFuncType(types.NewSignature(sig.Recv(), types.NewTuple(paramTuple...), sig.Results(), false)) - llvmFn = llvm.AddFunction(c.mod, fnName, llvmFnType) - c.addStandardDeclaredAttributes(llvmFn) - llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("tinygo-invoke", c.getMethodSignatureName(instr.Method))) --- -2.38.1 - diff --git a/0009-all-add-type-parameter-to-CreateCall.patch b/0009-all-add-type-parameter-to-CreateCall.patch deleted file mode 100644 index acfce69..0000000 --- a/0009-all-add-type-parameter-to-CreateCall.patch +++ /dev/null @@ -1,993 +0,0 @@ -From 8138d69793c00829df45501c35975055ad52d151 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Wed, 21 Sep 2022 00:37:01 +0200 -Subject: [PATCH 09/26] all: add type parameter to CreateCall - -This uses LLVMBuildCall2 in the background, which is the replacement for -the deprecated LLVMBuildCall function. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/build.go | 2 +- - compiler/alias.go | 2 +- - compiler/atomic.go | 4 ++-- - compiler/calls.go | 14 +++++++------- - compiler/compiler.go | 25 ++++++++++++++++--------- - compiler/defer.go | 16 ++++++++++------ - compiler/func.go | 8 +++++--- - compiler/goroutine.go | 33 ++++++++++++++++++--------------- - compiler/inlineasm.go | 16 ++++++++-------- - compiler/interface.go | 17 ++++++++--------- - compiler/interrupt.go | 4 ++-- - compiler/intrinsics.go | 6 +++--- - compiler/llvm.go | 2 +- - compiler/llvmutil/llvm.go | 24 ++++++++++++++---------- - compiler/llvmutil/wordpack.go | 4 ++-- - compiler/symbol.go | 6 +++--- - compiler/syscall.go | 14 +++++++------- - go.mod | 2 +- - go.sum | 4 ++-- - interp/interp.go | 2 +- - interp/interpreter.go | 2 +- - transform/interface-lowering.go | 7 ++++--- - transform/interrupt.go | 2 +- - transform/panic.go | 2 +- - transform/rtcalls.go | 2 +- - transform/wasm-abi.go | 6 +++--- - 26 files changed, 123 insertions(+), 103 deletions(-) - -diff --git a/builder/build.go b/builder/build.go -index 2008c897..28385044 100644 ---- a/builder/build.go -+++ b/builder/build.go -@@ -523,7 +523,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil - if pkgInit.IsNil() { - panic("init not found for " + pkg.Pkg.Path()) - } -- irbuilder.CreateCall(pkgInit, []llvm.Value{llvm.Undef(i8ptrType)}, "") -+ irbuilder.CreateCall(pkgInit.GlobalValueType(), pkgInit, []llvm.Value{llvm.Undef(i8ptrType)}, "") - } - irbuilder.CreateRetVoid() - -diff --git a/compiler/alias.go b/compiler/alias.go -index 9e88e3c6..b16cbce8 100644 ---- a/compiler/alias.go -+++ b/compiler/alias.go -@@ -52,7 +52,7 @@ func (b *builder) createAlias(alias llvm.Value) { - b.CreateUnreachable() - return - } -- result := b.CreateCall(alias, b.llvmFn.Params(), "") -+ result := b.CreateCall(alias.GlobalValueType(), alias, b.llvmFn.Params(), "") - if result.Type().TypeKind() == llvm.VoidTypeKind { - b.CreateRetVoid() - } else { -diff --git a/compiler/atomic.go b/compiler/atomic.go -index f12c6d11..6ba3849c 100644 ---- a/compiler/atomic.go -+++ b/compiler/atomic.go -@@ -25,7 +25,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value { - if fn.IsNil() { - fn = llvm.AddFunction(b.mod, name, llvm.FunctionType(vType, []llvm.Type{ptr.Type(), vType}, false)) - } -- oldVal := b.createCall(fn, []llvm.Value{ptr, val}, "") -+ oldVal := b.createCall(fn.GlobalValueType(), fn, []llvm.Value{ptr, val}, "") - // Return the new value, not the original value returned. - return b.CreateAdd(oldVal, val, "") - } -@@ -78,7 +78,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value { - if fn.IsNil() { - fn = llvm.AddFunction(b.mod, name, llvm.FunctionType(vType, []llvm.Type{ptr.Type(), vType, b.uintptrType}, false)) - } -- b.createCall(fn, []llvm.Value{ptr, val, llvm.ConstInt(b.uintptrType, 5, false)}, "") -+ b.createCall(fn.GlobalValueType(), fn, []llvm.Value{ptr, val, llvm.ConstInt(b.uintptrType, 5, false)}, "") - return llvm.Value{} - } - store := b.CreateStore(val, ptr) -diff --git a/compiler/calls.go b/compiler/calls.go -index aeca518a..b38d770f 100644 ---- a/compiler/calls.go -+++ b/compiler/calls.go -@@ -37,15 +37,15 @@ const ( - // createRuntimeInvoke instead. - func (b *builder) createRuntimeCallCommon(fnName string, args []llvm.Value, name string, isInvoke bool) llvm.Value { - fn := b.program.ImportedPackage("runtime").Members[fnName].(*ssa.Function) -- llvmFn := b.getFunction(fn) -+ fnType, llvmFn := b.getFunction(fn) - if llvmFn.IsNil() { - panic("trying to call non-existent function: " + fn.RelString(nil)) - } - args = append(args, llvm.Undef(b.i8ptrType)) // unused context parameter - if isInvoke { -- return b.createInvoke(llvmFn, args, name) -+ return b.createInvoke(fnType, llvmFn, args, name) - } -- return b.createCall(llvmFn, args, name) -+ return b.createCall(fnType, llvmFn, args, name) - } - - // createRuntimeCall creates a new call to runtime. with the given -@@ -65,22 +65,22 @@ func (b *builder) createRuntimeInvoke(fnName string, args []llvm.Value, name str - - // createCall creates a call to the given function with the arguments possibly - // expanded. --func (b *builder) createCall(fn llvm.Value, args []llvm.Value, name string) llvm.Value { -+func (b *builder) createCall(fnType llvm.Type, fn llvm.Value, args []llvm.Value, name string) llvm.Value { - expanded := make([]llvm.Value, 0, len(args)) - for _, arg := range args { - fragments := b.expandFormalParam(arg) - expanded = append(expanded, fragments...) - } -- return b.CreateCall(fn, expanded, name) -+ return b.CreateCall(fnType, fn, expanded, name) - } - - // createInvoke is like createCall but continues execution at the landing pad if - // the call resulted in a panic. --func (b *builder) createInvoke(fn llvm.Value, args []llvm.Value, name string) llvm.Value { -+func (b *builder) createInvoke(fnType llvm.Type, fn llvm.Value, args []llvm.Value, name string) llvm.Value { - if b.hasDeferFrame() { - b.createInvokeCheckpoint() - } -- return b.createCall(fn, args, name) -+ return b.createCall(fnType, fn, args, name) - } - - // Expand an argument type to a list that can be used in a function call -diff --git a/compiler/compiler.go b/compiler/compiler.go -index bbaf6432..b64fddcc 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -131,6 +131,7 @@ type builder struct { - *compilerContext - llvm.Builder - fn *ssa.Function -+ llvmFnType llvm.Type - llvmFn llvm.Value - info functionInfo - locals map[ssa.Value]llvm.Value // local variables -@@ -155,11 +156,13 @@ type builder struct { - } - - func newBuilder(c *compilerContext, irbuilder llvm.Builder, f *ssa.Function) *builder { -+ fnType, fn := c.getFunction(f) - return &builder{ - compilerContext: c, - Builder: irbuilder, - fn: f, -- llvmFn: c.getFunction(f), -+ llvmFnType: fnType, -+ llvmFn: fn, - info: c.getFunctionInfo(f), - locals: make(map[ssa.Value]llvm.Value), - dilocals: make(map[*types.Var]llvm.Metadata), -@@ -711,7 +714,8 @@ func (b *builder) getLocalVariable(variable *types.Var) llvm.Metadata { - // DISubprogram metadata node. - func (c *compilerContext) attachDebugInfo(f *ssa.Function) llvm.Metadata { - pos := c.program.Fset.Position(f.Syntax().Pos()) -- return c.attachDebugInfoRaw(f, c.getFunction(f), "", pos.Filename, pos.Line) -+ _, fn := c.getFunction(f) -+ return c.attachDebugInfoRaw(f, fn, "", pos.Filename, pos.Line) - } - - // attachDebugInfo adds debug info to a function declaration. It returns the -@@ -1654,6 +1658,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) - - // Try to call the function directly for trivially static calls. - var callee, context llvm.Value -+ var calleeType llvm.Type - exported := false - if fn := instr.StaticCallee(); fn != nil { - // Direct function call, either to a named or anonymous (directly -@@ -1684,7 +1689,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) - return b.createInterruptGlobal(instr) - } - -- callee = b.getFunction(fn) -+ calleeType, callee = b.getFunction(fn) - info := b.getFunctionInfo(fn) - if callee.IsNil() { - return llvm.Value{}, b.makeError(instr.Pos(), "undefined function: "+info.linkName) -@@ -1698,8 +1703,8 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) - // Eventually we might be able to eliminate this special case - // entirely. For details, see: - // https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521 -- fnType := llvm.FunctionType(callee.Type().ElementType().ReturnType(), nil, false) -- callee = llvm.ConstBitCast(callee, llvm.PointerType(fnType, b.funcPtrAddrSpace)) -+ calleeType = llvm.FunctionType(callee.Type().ElementType().ReturnType(), nil, false) -+ callee = llvm.ConstBitCast(callee, llvm.PointerType(calleeType, b.funcPtrAddrSpace)) - } - case *ssa.MakeClosure: - // A call on a func value, but the callee is trivial to find. For -@@ -1726,13 +1731,14 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) - params = append([]llvm.Value{value}, params...) - params = append(params, typecode) - callee = b.getInvokeFunction(instr) -+ calleeType = callee.GlobalValueType() - context = llvm.Undef(b.i8ptrType) - } else { - // Function pointer. - value := b.getValue(instr.Value) - // This is a func value, which cannot be called directly. We have to - // extract the function pointer and context first from the func value. -- callee, context = b.decodeFuncValue(value, instr.Value.Type().Underlying().(*types.Signature)) -+ calleeType, callee, context = b.decodeFuncValue(value, instr.Value.Type().Underlying().(*types.Signature)) - b.createNilCheck(instr.Value, callee, "fpcall") - } - -@@ -1742,7 +1748,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) - params = append(params, context) - } - -- return b.createInvoke(callee, params, ""), nil -+ return b.createInvoke(calleeType, callee, params, ""), nil - } - - // getValue returns the LLVM value of a constant, function value, global, or -@@ -1756,7 +1762,8 @@ func (b *builder) getValue(expr ssa.Value) llvm.Value { - b.addError(expr.Pos(), "cannot use an exported function as value: "+expr.String()) - return llvm.Undef(b.getLLVMType(expr.Type())) - } -- return b.createFuncValue(b.getFunction(expr), llvm.Undef(b.i8ptrType), expr.Signature) -+ _, fn := b.getFunction(expr) -+ return b.createFuncValue(fn, llvm.Undef(b.i8ptrType), expr.Signature) - case *ssa.Global: - value := b.getGlobal(expr) - if value.IsNil() { -@@ -3080,7 +3087,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { - // Instead of a load from the global, create a bitcast of the - // function pointer itself. - name := strings.TrimSuffix(unop.X.(*ssa.Global).Name(), "$funcaddr") -- fn := b.getFunction(b.fn.Pkg.Members[name].(*ssa.Function)) -+ _, fn := b.getFunction(b.fn.Pkg.Members[name].(*ssa.Function)) - if fn.IsNil() { - return llvm.Value{}, b.makeError(unop.Pos(), "cgo function not found: "+name) - } -diff --git a/compiler/defer.go b/compiler/defer.go -index 75c1be3d..e82370fa 100644 ---- a/compiler/defer.go -+++ b/compiler/defer.go -@@ -201,7 +201,7 @@ li a0, 0 - } - asmType := llvm.FunctionType(resultType, []llvm.Type{b.deferFrame.Type()}, false) - asm := llvm.InlineAsm(asmType, asmString, constraints, false, false, 0, false) -- result := b.CreateCall(asm, []llvm.Value{b.deferFrame}, "setjmp") -+ result := b.CreateCall(asmType, asm, []llvm.Value{b.deferFrame}, "setjmp") - result.AddCallSiteAttribute(-1, b.ctx.CreateEnumAttribute(llvm.AttributeKindID("returns_twice"), 0)) - isZero := b.CreateICmp(llvm.IntEQ, result, llvm.ConstInt(resultType, 0, false), "setjmp.result") - continueBB := b.insertBasicBlock("") -@@ -492,6 +492,7 @@ func (b *builder) createRunDefers() { - } - - var fnPtr llvm.Value -+ var fnType llvm.Type - - if !callback.IsInvoke() { - // Isolate the func value. -@@ -499,8 +500,8 @@ func (b *builder) createRunDefers() { - forwardParams = forwardParams[1:] - - //Get function pointer and context -- fp, context := b.decodeFuncValue(funcValue, callback.Signature()) -- fnPtr = fp -+ var context llvm.Value -+ fnType, fnPtr, context = b.decodeFuncValue(funcValue, callback.Signature()) - - //Pass context - forwardParams = append(forwardParams, context) -@@ -509,6 +510,7 @@ func (b *builder) createRunDefers() { - // parameters. - forwardParams = append(forwardParams[1:], forwardParams[0]) - fnPtr = b.getInvokeFunction(callback) -+ fnType = fnPtr.GlobalValueType() - - // Add the context parameter. An interface call cannot also be a - // closure but we have to supply the parameter anyway for platforms -@@ -516,7 +518,7 @@ func (b *builder) createRunDefers() { - forwardParams = append(forwardParams, llvm.Undef(b.i8ptrType)) - } - -- b.createCall(fnPtr, forwardParams, "") -+ b.createCall(fnType, fnPtr, forwardParams, "") - - case *ssa.Function: - // Direct call. -@@ -547,7 +549,8 @@ func (b *builder) createRunDefers() { - } - - // Call real function. -- b.createInvoke(b.getFunction(callback), forwardParams, "") -+ fnType, fn := b.getFunction(callback) -+ b.createInvoke(fnType, fn, forwardParams, "") - - case *ssa.MakeClosure: - // Get the real defer struct type and cast to it. -@@ -571,7 +574,8 @@ func (b *builder) createRunDefers() { - } - - // Call deferred function. -- b.createCall(b.getFunction(fn), forwardParams, "") -+ fnType, llvmFn := b.getFunction(fn) -+ b.createCall(fnType, llvmFn, forwardParams, "") - case *ssa.Builtin: - db := b.deferBuiltinFuncs[callback] - -diff --git a/compiler/func.go b/compiler/func.go -index a8b2874e..c6a8802d 100644 ---- a/compiler/func.go -+++ b/compiler/func.go -@@ -55,14 +55,15 @@ func (b *builder) extractFuncContext(funcValue llvm.Value) llvm.Value { - - // decodeFuncValue extracts the context and the function pointer from this func - // value. This may be an expensive operation. --func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcPtr, context llvm.Value) { -+func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcType llvm.Type, funcPtr, context llvm.Value) { - context = b.CreateExtractValue(funcValue, 0, "") - bitcast := b.CreateExtractValue(funcValue, 1, "") - if !bitcast.IsAConstantExpr().IsNil() && bitcast.Opcode() == llvm.BitCast { - funcPtr = bitcast.Operand(0) - return - } -- llvmSig := llvm.PointerType(b.getRawFuncType(sig), b.funcPtrAddrSpace) -+ funcType = b.getRawFuncType(sig) -+ llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace) - funcPtr = b.CreateBitCast(bitcast, llvmSig, "") - return - } -@@ -141,5 +142,6 @@ func (b *builder) parseMakeClosure(expr *ssa.MakeClosure) (llvm.Value, error) { - context := b.emitPointerPack(boundVars) - - // Create the closure. -- return b.createFuncValue(b.getFunction(f), context, f.Signature), nil -+ _, fn := b.getFunction(f) -+ return b.createFuncValue(fn, context, f.Signature), nil - } -diff --git a/compiler/goroutine.go b/compiler/goroutine.go -index 8d76c89f..ba8ec0f4 100644 ---- a/compiler/goroutine.go -+++ b/compiler/goroutine.go -@@ -22,6 +22,7 @@ func (b *builder) createGo(instr *ssa.Go) { - - var prefix string - var funcPtr llvm.Value -+ var funcPtrType llvm.Type - hasContext := false - if callee := instr.Call.StaticCallee(); callee != nil { - // Static callee is known. This makes it easier to start a new -@@ -42,7 +43,7 @@ func (b *builder) createGo(instr *ssa.Go) { - params = append(params, context) // context parameter - hasContext = true - } -- funcPtr = b.getFunction(callee) -+ funcPtrType, funcPtr = b.getFunction(callee) - } else if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok { - // We cheat. None of the builtins do any long or blocking operation, so - // we might as well run these builtins right away without the program -@@ -80,6 +81,7 @@ func (b *builder) createGo(instr *ssa.Go) { - itfTypeCode := b.CreateExtractValue(itf, 0, "") - itfValue := b.CreateExtractValue(itf, 1, "") - funcPtr = b.getInvokeFunction(&instr.Call) -+ funcPtrType = funcPtr.GlobalValueType() - params = append([]llvm.Value{itfValue}, params...) // start with receiver - params = append(params, itfTypeCode) // end with typecode - } else { -@@ -89,7 +91,7 @@ func (b *builder) createGo(instr *ssa.Go) { - // * The function context, for closures. - // * The function pointer (for tasks). - var context llvm.Value -- funcPtr, context = b.decodeFuncValue(b.getValue(instr.Call.Value), instr.Call.Value.Type().Underlying().(*types.Signature)) -+ funcPtrType, funcPtr, context = b.decodeFuncValue(b.getValue(instr.Call.Value), instr.Call.Value.Type().Underlying().(*types.Signature)) - params = append(params, context, funcPtr) - hasContext = true - prefix = b.fn.RelString(nil) -@@ -97,14 +99,14 @@ func (b *builder) createGo(instr *ssa.Go) { - - paramBundle := b.emitPointerPack(params) - var stackSize llvm.Value -- callee := b.createGoroutineStartWrapper(funcPtr, prefix, hasContext, instr.Pos()) -+ callee := b.createGoroutineStartWrapper(funcPtrType, funcPtr, prefix, hasContext, instr.Pos()) - if b.AutomaticStackSize { - // The stack size is not known until after linking. Call a dummy - // function that will be replaced with a load from a special ELF - // section that contains the stack size (and is modified after - // linking). -- stackSizeFn := b.getFunction(b.program.ImportedPackage("internal/task").Members["getGoroutineStackSize"].(*ssa.Function)) -- stackSize = b.createCall(stackSizeFn, []llvm.Value{callee, llvm.Undef(b.i8ptrType)}, "stacksize") -+ stackSizeFnType, stackSizeFn := b.getFunction(b.program.ImportedPackage("internal/task").Members["getGoroutineStackSize"].(*ssa.Function)) -+ stackSize = b.createCall(stackSizeFnType, stackSizeFn, []llvm.Value{callee, llvm.Undef(b.i8ptrType)}, "stacksize") - } else { - // The stack size is fixed at compile time. By emitting it here as a - // constant, it can be optimized. -@@ -113,8 +115,8 @@ func (b *builder) createGo(instr *ssa.Go) { - } - stackSize = llvm.ConstInt(b.uintptrType, b.DefaultStackSize, false) - } -- start := b.getFunction(b.program.ImportedPackage("internal/task").Members["start"].(*ssa.Function)) -- b.createCall(start, []llvm.Value{callee, paramBundle, stackSize, llvm.Undef(b.i8ptrType)}, "") -+ fnType, start := b.getFunction(b.program.ImportedPackage("internal/task").Members["start"].(*ssa.Function)) -+ b.createCall(fnType, start, []llvm.Value{callee, paramBundle, stackSize, llvm.Undef(b.i8ptrType)}, "") - } - - // createGoroutineStartWrapper creates a wrapper for the task-based -@@ -140,15 +142,16 @@ func (b *builder) createGo(instr *ssa.Go) { - // to last parameter of the function) is used for this wrapper. If hasContext is - // false, the parameter bundle is assumed to have no context parameter and undef - // is passed instead. --func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix string, hasContext bool, pos token.Pos) llvm.Value { -+func (c *compilerContext) createGoroutineStartWrapper(fnType llvm.Type, fn llvm.Value, prefix string, hasContext bool, pos token.Pos) llvm.Value { - var wrapper llvm.Value - - builder := c.ctx.NewBuilder() - defer builder.Dispose() - - var deadlock llvm.Value -+ var deadlockType llvm.Type - if c.Scheduler == "asyncify" { -- deadlock = c.getFunction(c.program.ImportedPackage("runtime").Members["deadlock"].(*ssa.Function)) -+ deadlockType, deadlock = c.getFunction(c.program.ImportedPackage("runtime").Members["deadlock"].(*ssa.Function)) - } - - if !fn.IsAFunction().IsNil() { -@@ -192,7 +195,7 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri - } - - // Create the list of params for the call. -- paramTypes := fn.Type().ElementType().ParamTypes() -+ paramTypes := fnType.ParamTypes() - if !hasContext { - paramTypes = paramTypes[:len(paramTypes)-1] // strip context parameter - } -@@ -202,10 +205,10 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri - } - - // Create the call. -- builder.CreateCall(fn, params, "") -+ builder.CreateCall(fnType, fn, params, "") - - if c.Scheduler == "asyncify" { -- builder.CreateCall(deadlock, []llvm.Value{ -+ builder.CreateCall(deadlockType, deadlock, []llvm.Value{ - llvm.Undef(c.i8ptrType), - }, "") - } -@@ -261,7 +264,7 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri - } - - // Get the list of parameters, with the extra parameters at the end. -- paramTypes := fn.Type().ElementType().ParamTypes() -+ paramTypes := fnType.ParamTypes() - paramTypes = append(paramTypes, fn.Type()) // the last element is the function pointer - params := llvmutil.EmitPointerUnpack(builder, c.mod, wrapper.Param(0), paramTypes) - -@@ -270,10 +273,10 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri - params = params[:len(params)-1] - - // Create the call. -- builder.CreateCall(fnPtr, params, "") -+ builder.CreateCall(fnType, fnPtr, params, "") - - if c.Scheduler == "asyncify" { -- builder.CreateCall(deadlock, []llvm.Value{ -+ builder.CreateCall(deadlockType, deadlock, []llvm.Value{ - llvm.Undef(c.i8ptrType), - }, "") - } -diff --git a/compiler/inlineasm.go b/compiler/inlineasm.go -index 27b0492b..2afb0a16 100644 ---- a/compiler/inlineasm.go -+++ b/compiler/inlineasm.go -@@ -25,7 +25,7 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) { - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{}, false) - asm := constant.StringVal(args[0].(*ssa.Const).Value) - target := llvm.InlineAsm(fnType, asm, "", true, false, 0, false) -- return b.CreateCall(target, nil, ""), nil -+ return b.CreateCall(fnType, target, nil, ""), nil - } - - // This is a compiler builtin, which allows assembly to be called in a flexible -@@ -120,7 +120,7 @@ func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) - } - fnType := llvm.FunctionType(outputType, argTypes, false) - target := llvm.InlineAsm(fnType, asmString, strings.Join(constraints, ","), true, false, 0, false) -- result := b.CreateCall(target, args, "") -+ result := b.CreateCall(fnType, target, args, "") - if hasOutput { - return result, nil - } else { -@@ -163,7 +163,7 @@ func (b *builder) emitSVCall(args []ssa.Value) (llvm.Value, error) { - constraints += ",~{r1},~{r2},~{r3}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) - target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) -- return b.CreateCall(target, llvmArgs, ""), nil -+ return b.CreateCall(fnType, target, llvmArgs, ""), nil - } - - // This is a compiler builtin which emits an inline SVCall instruction. It can -@@ -201,7 +201,7 @@ func (b *builder) emitSV64Call(args []ssa.Value) (llvm.Value, error) { - constraints += ",~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) - target := llvm.InlineAsm(fnType, asm, constraints, true, false, 0, false) -- return b.CreateCall(target, llvmArgs, ""), nil -+ return b.CreateCall(fnType, target, llvmArgs, ""), nil - } - - // This is a compiler builtin which emits CSR instructions. It can be one of: -@@ -226,24 +226,24 @@ func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error) { - fnType := llvm.FunctionType(b.uintptrType, nil, false) - asm := fmt.Sprintf("csrr $0, %d", csr) - target := llvm.InlineAsm(fnType, asm, "=r", true, false, 0, false) -- return b.CreateCall(target, nil, ""), nil -+ return b.CreateCall(fnType, target, nil, ""), nil - case "Set": - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrw %d, $0", csr) - target := llvm.InlineAsm(fnType, asm, "r", true, false, 0, false) -- return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil -+ return b.CreateCall(fnType, target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - case "SetBits": - // Note: it may be possible to optimize this to csrrsi in many cases. - fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrrs $0, %d, $1", csr) - target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) -- return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil -+ return b.CreateCall(fnType, target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - case "ClearBits": - // Note: it may be possible to optimize this to csrrci in many cases. - fnType := llvm.FunctionType(b.uintptrType, []llvm.Type{b.uintptrType}, false) - asm := fmt.Sprintf("csrrc $0, %d, $1", csr) - target := llvm.InlineAsm(fnType, asm, "=r,r", true, false, 0, false) -- return b.CreateCall(target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil -+ return b.CreateCall(fnType, target, []llvm.Value{b.getValue(call.Args[1])}, ""), nil - default: - return llvm.Value{}, b.makeError(call.Pos(), "unknown CSR operation: "+name) - } -diff --git a/compiler/interface.go b/compiler/interface.go -index b0ea71e3..72f8952d 100644 ---- a/compiler/interface.go -+++ b/compiler/interface.go -@@ -254,12 +254,12 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value { - method := ms.At(i) - signatureGlobal := c.getMethodSignature(method.Obj().(*types.Func)) - fn := c.program.MethodValue(method) -- llvmFn := c.getFunction(fn) -+ llvmFnType, llvmFn := c.getFunction(fn) - if llvmFn.IsNil() { - // compiler error, so panic - panic("cannot find function: " + c.getFunctionInfo(fn).linkName) - } -- wrapper := c.getInterfaceInvokeWrapper(fn, llvmFn) -+ wrapper := c.getInterfaceInvokeWrapper(fn, llvmFnType, llvmFn) - methodInfo := llvm.ConstNamedStruct(interfaceMethodInfoType, []llvm.Value{ - signatureGlobal, - llvm.ConstPtrToInt(wrapper, c.uintptrType), -@@ -361,7 +361,7 @@ func (b *builder) createTypeAssert(expr *ssa.TypeAssert) llvm.Value { - // implements each method of the interface. See: - // https://research.swtch.com/interfaces - fn := b.getInterfaceImplementsFunc(expr.AssertedType) -- commaOk = b.CreateCall(fn, []llvm.Value{actualTypeNum}, "") -+ commaOk = b.CreateCall(fn.GlobalValueType(), fn, []llvm.Value{actualTypeNum}, "") - - } else { - globalName := "reflect/types.typeid:" + getTypeCodeName(expr.AssertedType) -@@ -480,7 +480,7 @@ func (c *compilerContext) getInvokeFunction(instr *ssa.CallCommon) llvm.Value { - // value, dereferences or unpacks it if necessary, and calls the real method. - // If the method to wrap has a pointer receiver, no wrapping is necessary and - // the function is returned directly. --func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llvm.Value) llvm.Value { -+func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFnType llvm.Type, llvmFn llvm.Value) llvm.Value { - wrapperName := llvmFn.Name() + "$invoke" - wrapper := c.mod.NamedFunction(wrapperName) - if !wrapper.IsNil() { -@@ -505,9 +505,8 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llv - } - - // create wrapper function -- fnType := llvmFn.Type().ElementType() -- paramTypes := append([]llvm.Type{c.i8ptrType}, fnType.ParamTypes()[len(expandedReceiverType):]...) -- wrapFnType := llvm.FunctionType(fnType.ReturnType(), paramTypes, false) -+ paramTypes := append([]llvm.Type{c.i8ptrType}, llvmFnType.ParamTypes()[len(expandedReceiverType):]...) -+ wrapFnType := llvm.FunctionType(llvmFnType.ReturnType(), paramTypes, false) - wrapper = llvm.AddFunction(c.mod, wrapperName, wrapFnType) - c.addStandardAttributes(wrapper) - -@@ -535,10 +534,10 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llv - receiverValue := b.emitPointerUnpack(wrapper.Param(0), []llvm.Type{receiverType})[0] - params := append(b.expandFormalParam(receiverValue), wrapper.Params()[1:]...) - if llvmFn.Type().ElementType().ReturnType().TypeKind() == llvm.VoidTypeKind { -- b.CreateCall(llvmFn, params, "") -+ b.CreateCall(llvmFnType, llvmFn, params, "") - b.CreateRetVoid() - } else { -- ret := b.CreateCall(llvmFn, params, "ret") -+ ret := b.CreateCall(llvmFnType, llvmFn, params, "ret") - b.CreateRet(ret) - } - -diff --git a/compiler/interrupt.go b/compiler/interrupt.go -index bcd407cd..45c7d074 100644 ---- a/compiler/interrupt.go -+++ b/compiler/interrupt.go -@@ -36,7 +36,7 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro - // Fall back to a generic error. - return llvm.Value{}, b.makeError(instr.Pos(), "interrupt function must be constant") - } -- funcRawPtr, funcContext := b.decodeFuncValue(funcValue, nil) -+ _, funcRawPtr, funcContext := b.decodeFuncValue(funcValue, nil) - funcPtr := llvm.ConstPtrToInt(funcRawPtr, b.uintptrType) - - // Create a new global of type runtime/interrupt.handle. Globals of this -@@ -85,7 +85,7 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro - useFnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{interrupt.Type()}, false) - useFn = llvm.AddFunction(b.mod, "runtime/interrupt.use", useFnType) - } -- b.CreateCall(useFn, []llvm.Value{interrupt}, "") -+ b.CreateCall(useFn.GlobalValueType(), useFn, []llvm.Value{interrupt}, "") - } - - return interrupt, nil -diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go -index 0203d441..9fedfbd6 100644 ---- a/compiler/intrinsics.go -+++ b/compiler/intrinsics.go -@@ -55,7 +55,7 @@ func (b *builder) createMemoryCopyImpl() { - params = append(params, b.getValue(param)) - } - params = append(params, llvm.ConstInt(b.ctx.Int1Type(), 0, false)) -- b.CreateCall(llvmFn, params, "") -+ b.CreateCall(llvmFn.GlobalValueType(), llvmFn, params, "") - b.CreateRetVoid() - } - -@@ -76,7 +76,7 @@ func (b *builder) createMemoryZeroImpl() { - b.getValue(b.fn.Params[1]), - llvm.ConstInt(b.ctx.Int1Type(), 0, false), - } -- b.CreateCall(llvmFn, params, "") -+ b.CreateCall(llvmFn.GlobalValueType(), llvmFn, params, "") - b.CreateRetVoid() - } - -@@ -119,6 +119,6 @@ func (b *builder) defineMathOp() { - for i, param := range b.fn.Params { - args[i] = b.getValue(param) - } -- result := b.CreateCall(llvmFn, args, "") -+ result := b.CreateCall(llvmFn.GlobalValueType(), llvmFn, args, "") - b.CreateRet(result) - } -diff --git a/compiler/llvm.go b/compiler/llvm.go -index 0d2ba9da..9540bcc6 100644 ---- a/compiler/llvm.go -+++ b/compiler/llvm.go -@@ -312,5 +312,5 @@ func (b *builder) readStackPointer() llvm.Value { - fnType := llvm.FunctionType(b.i8ptrType, nil, false) - stacksave = llvm.AddFunction(b.mod, "llvm.stacksave", fnType) - } -- return b.CreateCall(stacksave, nil, "") -+ return b.CreateCall(stacksave.GlobalValueType(), stacksave, nil, "") - } -diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go -index 74404a3e..e73b68da 100644 ---- a/compiler/llvmutil/llvm.go -+++ b/compiler/llvmutil/llvm.go -@@ -39,7 +39,8 @@ func CreateTemporaryAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, n - alloca = CreateEntryBlockAlloca(builder, t, name) - bitcast = builder.CreateBitCast(alloca, i8ptrType, name+".bitcast") - size = llvm.ConstInt(ctx.Int64Type(), targetData.TypeAllocSize(t), false) -- builder.CreateCall(getLifetimeStartFunc(mod), []llvm.Value{size, bitcast}, "") -+ fnType, fn := getLifetimeStartFunc(mod) -+ builder.CreateCall(fnType, fn, []llvm.Value{size, bitcast}, "") - return - } - -@@ -54,13 +55,15 @@ func CreateInstructionAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, - builder.SetInsertPointBefore(inst) - bitcast := builder.CreateBitCast(alloca, i8ptrType, name+".bitcast") - size := llvm.ConstInt(ctx.Int64Type(), targetData.TypeAllocSize(t), false) -- builder.CreateCall(getLifetimeStartFunc(mod), []llvm.Value{size, bitcast}, "") -+ fnType, fn := getLifetimeStartFunc(mod) -+ builder.CreateCall(fnType, fn, []llvm.Value{size, bitcast}, "") - if next := llvm.NextInstruction(inst); !next.IsNil() { - builder.SetInsertPointBefore(next) - } else { - builder.SetInsertPointAtEnd(inst.InstructionParent()) - } -- builder.CreateCall(getLifetimeEndFunc(mod), []llvm.Value{size, bitcast}, "") -+ fnType, fn = getLifetimeEndFunc(mod) -+ builder.CreateCall(fnType, fn, []llvm.Value{size, bitcast}, "") - return alloca - } - -@@ -68,33 +71,34 @@ func CreateInstructionAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, - // llvm.lifetime.end intrinsic. It is commonly used together with - // createTemporaryAlloca. - func EmitLifetimeEnd(builder llvm.Builder, mod llvm.Module, ptr, size llvm.Value) { -- builder.CreateCall(getLifetimeEndFunc(mod), []llvm.Value{size, ptr}, "") -+ fnType, fn := getLifetimeEndFunc(mod) -+ builder.CreateCall(fnType, fn, []llvm.Value{size, ptr}, "") - } - - // getLifetimeStartFunc returns the llvm.lifetime.start intrinsic and creates it - // first if it doesn't exist yet. --func getLifetimeStartFunc(mod llvm.Module) llvm.Value { -+func getLifetimeStartFunc(mod llvm.Module) (llvm.Type, llvm.Value) { - fn := mod.NamedFunction("llvm.lifetime.start.p0i8") - ctx := mod.Context() - i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) -+ fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) - if fn.IsNil() { -- fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) - fn = llvm.AddFunction(mod, "llvm.lifetime.start.p0i8", fnType) - } -- return fn -+ return fnType, fn - } - - // getLifetimeEndFunc returns the llvm.lifetime.end intrinsic and creates it - // first if it doesn't exist yet. --func getLifetimeEndFunc(mod llvm.Module) llvm.Value { -+func getLifetimeEndFunc(mod llvm.Module) (llvm.Type, llvm.Value) { - fn := mod.NamedFunction("llvm.lifetime.end.p0i8") - ctx := mod.Context() - i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) -+ fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) - if fn.IsNil() { -- fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) - fn = llvm.AddFunction(mod, "llvm.lifetime.end.p0i8", fnType) - } -- return fn -+ return fnType, fn - } - - // SplitBasicBlock splits a LLVM basic block into two parts. All instructions -diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go -index 41d4c581..73b1e27e 100644 ---- a/compiler/llvmutil/wordpack.go -+++ b/compiler/llvmutil/wordpack.go -@@ -95,14 +95,14 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs - // Packed data is bigger than a pointer, so allocate it on the heap. - sizeValue := llvm.ConstInt(uintptrType, size, false) - alloc := mod.NamedFunction("runtime.alloc") -- packedHeapAlloc := builder.CreateCall(alloc, []llvm.Value{ -+ packedHeapAlloc := builder.CreateCall(alloc.GlobalValueType(), alloc, []llvm.Value{ - sizeValue, - llvm.ConstNull(i8ptrType), - llvm.Undef(i8ptrType), // unused context parameter - }, "") - if needsStackObjects { - trackPointer := mod.NamedFunction("runtime.trackPointer") -- builder.CreateCall(trackPointer, []llvm.Value{ -+ builder.CreateCall(trackPointer.GlobalValueType(), trackPointer, []llvm.Value{ - packedHeapAlloc, - llvm.Undef(i8ptrType), // unused context parameter - }, "") -diff --git a/compiler/symbol.go b/compiler/symbol.go -index c4ce6f21..83fe050b 100644 ---- a/compiler/symbol.go -+++ b/compiler/symbol.go -@@ -53,11 +53,11 @@ const ( - - // getFunction returns the LLVM function for the given *ssa.Function, creating - // it if needed. It can later be filled with compilerContext.createFunction(). --func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value { -+func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) { - info := c.getFunctionInfo(fn) - llvmFn := c.mod.NamedFunction(info.linkName) - if !llvmFn.IsNil() { -- return llvmFn -+ return llvmFn.GlobalValueType(), llvmFn - } - - var retType llvm.Type -@@ -202,7 +202,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value { - llvmFn.SetUnnamedAddr(true) - } - -- return llvmFn -+ return fnType, llvmFn - } - - // getFunctionInfo returns information about a function that is not directly -diff --git a/compiler/syscall.go b/compiler/syscall.go -index 0c5f1246..66baf826 100644 ---- a/compiler/syscall.go -+++ b/compiler/syscall.go -@@ -44,7 +44,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - constraints += ",~{rcx},~{r11}" - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) - target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false) -- return b.CreateCall(target, args, ""), nil -+ return b.CreateCall(fnType, target, args, ""), nil - case b.GOARCH == "386" && b.GOOS == "linux": - // Sources: - // syscall(2) man page -@@ -70,7 +70,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - } - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) - target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false) -- return b.CreateCall(target, args, ""), nil -+ return b.CreateCall(fnType, target, args, ""), nil - case b.GOARCH == "arm" && b.GOOS == "linux": - // Implement the EABI system call convention for Linux. - // Source: syscall(2) man page. -@@ -102,7 +102,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - } - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) - target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) -- return b.CreateCall(target, args, ""), nil -+ return b.CreateCall(fnType, target, args, ""), nil - case b.GOARCH == "arm64" && b.GOOS == "linux": - // Source: syscall(2) man page. - args := []llvm.Value{} -@@ -134,7 +134,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) { - constraints += ",~{x16},~{x17}" // scratch registers - fnType := llvm.FunctionType(b.uintptrType, argTypes, false) - target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false) -- return b.CreateCall(target, args, ""), nil -+ return b.CreateCall(fnType, target, args, ""), nil - default: - return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH) - } -@@ -205,9 +205,9 @@ func (b *builder) createSyscall(call *ssa.CallCommon) (llvm.Value, error) { - // Note that SetLastError/GetLastError could be replaced with direct - // access to the thread control block, which is probably smaller and - // faster. The Go runtime does this in assembly. -- b.CreateCall(setLastError, []llvm.Value{llvm.ConstNull(b.ctx.Int32Type())}, "") -- syscallResult := b.CreateCall(fnPtr, params, "") -- errResult := b.CreateCall(getLastError, nil, "err") -+ b.CreateCall(setLastError.GlobalValueType(), setLastError, []llvm.Value{llvm.ConstNull(b.ctx.Int32Type())}, "") -+ syscallResult := b.CreateCall(llvmType, fnPtr, params, "") -+ errResult := b.CreateCall(getLastError.GlobalValueType(), getLastError, nil, "err") - if b.uintptrType != b.ctx.Int32Type() { - errResult = b.CreateZExt(errResult, b.uintptrType, "err.uintptr") - } -diff --git a/go.mod b/go.mod -index fdf686d4..4af10427 100644 ---- a/go.mod -+++ b/go.mod -@@ -17,7 +17,7 @@ require ( - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 - golang.org/x/tools v0.1.11 - gopkg.in/yaml.v2 v2.4.0 -- tinygo.org/x/go-llvm v0.0.0-20220802112859-5bb0b77907a7 -+ tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 - ) - - require ( -diff --git a/go.sum b/go.sum -index 3fc9cac1..401de3be 100644 ---- a/go.sum -+++ b/go.sum -@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= - gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= --tinygo.org/x/go-llvm v0.0.0-20220802112859-5bb0b77907a7 h1:nSLR52mUw7DPQQVA3ZJFH63zjU4ME84fKiin6mdnYWc= --tinygo.org/x/go-llvm v0.0.0-20220802112859-5bb0b77907a7/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -+tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 h1:JxtI6P/lyWHAcs/4QJWeWIbh4HntxPFONMVWvx7wf8Y= -+tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -diff --git a/interp/interp.go b/interp/interp.go -index a1f5f507..856f08b1 100644 ---- a/interp/interp.go -+++ b/interp/interp.go -@@ -127,7 +127,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error { - // Create a call to the package initializer (which was - // previously deleted). - i8undef := llvm.Undef(r.i8ptrType) -- r.builder.CreateCall(fn, []llvm.Value{i8undef}, "") -+ r.builder.CreateCall(fn.GlobalValueType(), fn, []llvm.Value{i8undef}, "") - // Make sure that any globals touched by the package - // initializer, won't be accessed by later package initializers. - err := r.markExternalLoad(fn) -diff --git a/interp/interpreter.go b/interp/interpreter.go -index 7cee14bf..4a4553f8 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -977,7 +977,7 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me - } - } - } -- result = r.builder.CreateCall(llvmFn, args, inst.name) -+ result = r.builder.CreateCall(inst.llvmInst.CalledFunctionType(), llvmFn, args, inst.name) - case llvm.Load: - err := mem.markExternalLoad(operands[0]) - if err != nil { -diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go -index 7a01c2ea..f5b29e30 100644 ---- a/transform/interface-lowering.go -+++ b/transform/interface-lowering.go -@@ -493,12 +493,13 @@ func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *inte - paramTypes = append(paramTypes, param.Type()) - } - calledFunctionType := function.Type() -- sig := llvm.PointerType(llvm.FunctionType(returnType, paramTypes, false), calledFunctionType.PointerAddressSpace()) -+ functionType := llvm.FunctionType(returnType, paramTypes, false) -+ sig := llvm.PointerType(functionType, calledFunctionType.PointerAddressSpace()) - if sig != function.Type() { - function = p.builder.CreateBitCast(function, sig, "") - } - -- retval := p.builder.CreateCall(function, append([]llvm.Value{receiver}, params...), "") -+ retval := p.builder.CreateCall(functionType, function, append([]llvm.Value{receiver}, params...), "") - if retval.Type().TypeKind() == llvm.VoidTypeKind { - p.builder.CreateRetVoid() - } else { -@@ -518,7 +519,7 @@ func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *inte - // importantly, it avoids undefined behavior when accidentally calling a - // method on a nil interface. - nilPanic := p.mod.NamedFunction("runtime.nilPanic") -- p.builder.CreateCall(nilPanic, []llvm.Value{ -+ p.builder.CreateCall(nilPanic.GlobalValueType(), nilPanic, []llvm.Value{ - llvm.Undef(llvm.PointerType(p.ctx.Int8Type(), 0)), - }, "") - p.builder.CreateUnreachable() -diff --git a/transform/interrupt.go b/transform/interrupt.go -index 3ffe7048..2c301be0 100644 ---- a/transform/interrupt.go -+++ b/transform/interrupt.go -@@ -91,7 +91,7 @@ func LowerInterrupts(mod llvm.Module) []error { - initializer := handler.Initializer() - context := llvm.ConstExtractValue(initializer, []uint32{0}) - funcPtr := llvm.ConstExtractValue(initializer, []uint32{1}).Operand(0) -- builder.CreateCall(funcPtr, []llvm.Value{ -+ builder.CreateCall(funcPtr.GlobalValueType(), funcPtr, []llvm.Value{ - num, - context, - }, "") -diff --git a/transform/panic.go b/transform/panic.go -index e8e9a1fe..dee3bae0 100644 ---- a/transform/panic.go -+++ b/transform/panic.go -@@ -27,7 +27,7 @@ func ReplacePanicsWithTrap(mod llvm.Module) { - panic("expected use of a panic function to be a call") - } - builder.SetInsertPointBefore(use) -- builder.CreateCall(trap, nil, "") -+ builder.CreateCall(trap.GlobalValueType(), trap, nil, "") - } - } - } -diff --git a/transform/rtcalls.go b/transform/rtcalls.go -index 2edfd655..2f17f815 100644 ---- a/transform/rtcalls.go -+++ b/transform/rtcalls.go -@@ -165,7 +165,7 @@ func OptimizeReflectImplements(mod llvm.Module) { - - // Replace Implements call with the type assert call. - builder.SetInsertPointBefore(call) -- implements := builder.CreateCall(typeAssertFunction, []llvm.Value{ -+ implements := builder.CreateCall(typeAssertFunction.GlobalValueType(), typeAssertFunction, []llvm.Value{ - builder.CreatePtrToInt(call.Operand(0), uintptrType, ""), // typecode to check - }, "") - call.ReplaceAllUsesWith(implements) -diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go -index aeba713d..aedad71d 100644 ---- a/transform/wasm-abi.go -+++ b/transform/wasm-abi.go -@@ -124,12 +124,12 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { - // Pass a stack-allocated pointer as the first parameter - // where the return value should be stored, instead of using - // the regular return value. -- builder.CreateCall(externalFn, callParams, callName) -+ builder.CreateCall(externalFnType, externalFn, callParams, callName) - returnValue := builder.CreateLoad(retvalAlloca, "retval") - call.ReplaceAllUsesWith(returnValue) - call.EraseFromParentAsInstruction() - } else { -- newCall := builder.CreateCall(externalFn, callParams, callName) -+ newCall := builder.CreateCall(externalFnType, externalFn, callParams, callName) - call.ReplaceAllUsesWith(newCall) - call.EraseFromParentAsInstruction() - } -@@ -156,7 +156,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { - } - callParams = append(callParams, paramValue) - } -- retval := builder.CreateCall(fn, callParams, "") -+ retval := builder.CreateCall(fn.GlobalValueType(), fn, callParams, "") - if retval.Type().TypeKind() == llvm.VoidTypeKind { - builder.CreateRetVoid() - } else { --- -2.38.1 - diff --git a/0010-all-add-type-parameter-to-CreateLoad.patch b/0010-all-add-type-parameter-to-CreateLoad.patch deleted file mode 100644 index 8f4d9f4..0000000 --- a/0010-all-add-type-parameter-to-CreateLoad.patch +++ /dev/null @@ -1,377 +0,0 @@ -From 65a18179d8ff911ba43a3a28ffb2f36c262cff5e Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Wed, 21 Sep 2022 13:55:32 +0200 -Subject: [PATCH 10/26] all: add type parameter to CreateLoad - -This is needed for LLVM 15. - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/atomic.go | 2 +- - compiler/channel.go | 8 ++++---- - compiler/compiler.go | 13 +++++++------ - compiler/defer.go | 19 +++++++++++-------- - compiler/llvmutil/wordpack.go | 4 ++-- - compiler/map.go | 6 +++--- - compiler/volatile.go | 5 ++++- - go.mod | 2 +- - go.sum | 4 ++-- - interp/interpreter.go | 2 +- - transform/gc.go | 2 +- - transform/stacksize.go | 13 +++++++++---- - transform/wasm-abi.go | 4 ++-- - 13 files changed, 48 insertions(+), 36 deletions(-) - -diff --git a/compiler/atomic.go b/compiler/atomic.go -index 6ba3849c..73761be4 100644 ---- a/compiler/atomic.go -+++ b/compiler/atomic.go -@@ -56,7 +56,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value { - return swapped - case "LoadInt32", "LoadInt64", "LoadUint32", "LoadUint64", "LoadUintptr", "LoadPointer": - ptr := b.getValue(b.fn.Params[0]) -- val := b.CreateLoad(ptr, "") -+ val := b.CreateLoad(b.getLLVMType(b.fn.Signature.Results().At(0).Type()), ptr, "") - val.SetOrdering(llvm.AtomicOrderingSequentiallyConsistent) - val.SetAlignment(b.targetData.PrefTypeAlignment(val.Type())) // required - return val -diff --git a/compiler/channel.go b/compiler/channel.go -index a9886e10..5c3b6c59 100644 ---- a/compiler/channel.go -+++ b/compiler/channel.go -@@ -84,7 +84,7 @@ func (b *builder) createChanRecv(unop *ssa.UnOp) llvm.Value { - if isZeroSize { - received = llvm.ConstNull(valueType) - } else { -- received = b.CreateLoad(valueAlloca, "chan.received") -+ received = b.CreateLoad(valueType, valueAlloca, "chan.received") - b.emitLifetimeEnd(valueAllocaCast, valueAllocaSize) - } - b.emitLifetimeEnd(channelBlockedListAllocaCast, channelBlockedListAllocaSize) -@@ -264,8 +264,8 @@ func (b *builder) getChanSelectResult(expr *ssa.Extract) llvm.Value { - // receive can proceed at a time) so we'll get that alloca, bitcast - // it to the correct type, and dereference it. - recvbuf := b.selectRecvBuf[expr.Tuple.(*ssa.Select)] -- typ := llvm.PointerType(b.getLLVMType(expr.Type()), 0) -- ptr := b.CreateBitCast(recvbuf, typ, "") -- return b.CreateLoad(ptr, "") -+ typ := b.getLLVMType(expr.Type()) -+ ptr := b.CreateBitCast(recvbuf, llvm.PointerType(typ, 0), "") -+ return b.CreateLoad(typ, ptr, "") - } - } -diff --git a/compiler/compiler.go b/compiler/compiler.go -index b64fddcc..7ab2fe4e 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -1931,11 +1931,12 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - - // Can't load directly from array (as index is non-constant), so have to - // do it using an alloca+gep+load. -- alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(array.Type(), "index.alloca") -+ arrayType := array.Type() -+ alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(arrayType, "index.alloca") - b.CreateStore(array, alloca) - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - ptr := b.CreateInBoundsGEP(alloca, []llvm.Value{zero, index}, "index.gep") -- result := b.CreateLoad(ptr, "index.load") -+ result := b.CreateLoad(arrayType.ElementType(), ptr, "index.load") - b.emitLifetimeEnd(allocaPtr, allocaSize) - return result, nil - case *ssa.IndexAddr: -@@ -2012,7 +2013,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - // Lookup byte - buf := b.CreateExtractValue(value, 0, "") - bufPtr := b.CreateInBoundsGEP(buf, []llvm.Value{index}, "") -- return b.CreateLoad(bufPtr, ""), nil -+ return b.CreateLoad(b.ctx.Int8Type(), bufPtr, ""), nil - case *types.Map: - valueType := expr.Type() - if expr.CommaOk { -@@ -3076,10 +3077,10 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { - return llvm.Value{}, b.makeError(unop.Pos(), "todo: unknown type for negate: "+unop.X.Type().Underlying().String()) - } - case token.MUL: // *x, dereference pointer -- unop.X.Type().Underlying().(*types.Pointer).Elem() -+ valueType := b.getLLVMType(unop.X.Type().Underlying().(*types.Pointer).Elem()) - if b.targetData.TypeAllocSize(x.Type().ElementType()) == 0 { - // zero-length data -- return llvm.ConstNull(x.Type().ElementType()), nil -+ return llvm.ConstNull(valueType), nil - } else if strings.HasSuffix(unop.X.String(), "$funcaddr") { - // CGo function pointer. The cgo part has rewritten CGo function - // pointers as stub global variables of the form: -@@ -3094,7 +3095,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { - return b.CreateBitCast(fn, b.i8ptrType, ""), nil - } else { - b.createNilCheck(unop.X, x, "deref") -- load := b.CreateLoad(x, "") -+ load := b.CreateLoad(valueType, x, "") - return load, nil - } - case token.XOR: // ^x, toggle all bits in integer -diff --git a/compiler/defer.go b/compiler/defer.go -index e82370fa..1f892e5b 100644 ---- a/compiler/defer.go -+++ b/compiler/defer.go -@@ -249,7 +249,8 @@ func isInLoop(start *ssa.BasicBlock) bool { - func (b *builder) createDefer(instr *ssa.Defer) { - // The pointer to the previous defer struct, which we will replace to - // make a linked list. -- next := b.CreateLoad(b.deferPtr, "defer.next") -+ deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0) -+ next := b.CreateLoad(deferType, b.deferPtr, "defer.next") - - var values []llvm.Value - valueTypes := []llvm.Type{b.uintptrType, next.Type()} -@@ -406,6 +407,8 @@ func (b *builder) createDefer(instr *ssa.Defer) { - - // createRunDefers emits code to run all deferred functions. - func (b *builder) createRunDefers() { -+ deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0) -+ - // Add a loop like the following: - // for stack != nil { - // _stack := stack -@@ -431,7 +434,7 @@ func (b *builder) createRunDefers() { - // Create loop head: - // for stack != nil { - b.SetInsertPointAtEnd(loophead) -- deferData := b.CreateLoad(b.deferPtr, "") -+ deferData := b.CreateLoad(deferType, b.deferPtr, "") - stackIsNil := b.CreateICmp(llvm.IntEQ, deferData, llvm.ConstPointerNull(deferData.Type()), "stackIsNil") - b.CreateCondBr(stackIsNil, end, loop) - -@@ -444,13 +447,13 @@ func (b *builder) createRunDefers() { - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 1, false), // .next field - }, "stack.next.gep") -- nextStack := b.CreateLoad(nextStackGEP, "stack.next") -+ nextStack := b.CreateLoad(deferType, nextStackGEP, "stack.next") - b.CreateStore(nextStack, b.deferPtr) - gep := b.CreateInBoundsGEP(deferData, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 0, false), // .callback field - }, "callback.gep") -- callback := b.CreateLoad(gep, "callback") -+ callback := b.CreateLoad(b.uintptrType, gep, "callback") - sw := b.CreateSwitch(callback, unreachable, len(b.allDeferFuncs)) - - for i, callback := range b.allDeferFuncs { -@@ -487,7 +490,7 @@ func (b *builder) createRunDefers() { - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := 2; i < len(valueTypes); i++ { - gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep") -- forwardParam := b.CreateLoad(gep, "param") -+ forwardParam := b.CreateLoad(valueTypes[i], gep, "param") - forwardParams = append(forwardParams, forwardParam) - } - -@@ -536,7 +539,7 @@ func (b *builder) createRunDefers() { - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := range getParams(callback.Signature) { - gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") -- forwardParam := b.CreateLoad(gep, "param") -+ forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") - forwardParams = append(forwardParams, forwardParam) - } - -@@ -569,7 +572,7 @@ func (b *builder) createRunDefers() { - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := 2; i < len(valueTypes); i++ { - gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "") -- forwardParam := b.CreateLoad(gep, "param") -+ forwardParam := b.CreateLoad(valueTypes[i], gep, "param") - forwardParams = append(forwardParams, forwardParam) - } - -@@ -596,7 +599,7 @@ func (b *builder) createRunDefers() { - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := 0; i < params.Len(); i++ { - gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") -- forwardParam := b.CreateLoad(gep, "param") -+ forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") - argValues = append(argValues, forwardParam) - } - -diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go -index 73b1e27e..97b86045 100644 ---- a/compiler/llvmutil/wordpack.go -+++ b/compiler/llvmutil/wordpack.go -@@ -63,7 +63,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs - } - - // Load value (the *i8) from the alloca. -- result := builder.CreateLoad(packedAlloc, "") -+ result := builder.CreateLoad(i8ptrType, packedAlloc, "") - - // End the lifetime of the alloca, to help the optimizer. - packedPtr := builder.CreateBitCast(packedAlloc, i8ptrType, "") -@@ -171,7 +171,7 @@ func EmitPointerUnpack(builder llvm.Builder, mod llvm.Module, ptr llvm.Value, va - llvm.ConstInt(ctx.Int32Type(), uint64(i), false), - } - gep := builder.CreateInBoundsGEP(packedAlloc, indices, "") -- values[i] = builder.CreateLoad(gep, "") -+ values[i] = builder.CreateLoad(valueType, gep, "") - } - if !packedRawAlloc.IsNil() { - allocPtr := builder.CreateBitCast(packedRawAlloc, i8ptrType, "") -diff --git a/compiler/map.go b/compiler/map.go -index 57a7033a..7655ec70 100644 ---- a/compiler/map.go -+++ b/compiler/map.go -@@ -106,7 +106,7 @@ func (b *builder) createMapLookup(keyType, valueType types.Type, m, key llvm.Val - - // Load the resulting value from the hashmap. The value is set to the zero - // value if the key doesn't exist in the hashmap. -- mapValue := b.CreateLoad(mapValueAlloca, "") -+ mapValue := b.CreateLoad(llvmValueType, mapValueAlloca, "") - b.emitLifetimeEnd(mapValuePtr, mapValueAllocaSize) - - if commaOk { -@@ -217,8 +217,8 @@ func (b *builder) createMapIteratorNext(rangeVal ssa.Value, llvmRangeVal, it llv - mapKeyAlloca, mapKeyPtr, mapKeySize := b.createTemporaryAlloca(llvmStoredKeyType, "range.key") - mapValueAlloca, mapValuePtr, mapValueSize := b.createTemporaryAlloca(llvmValueType, "range.value") - ok := b.createRuntimeCall("hashmapNext", []llvm.Value{llvmRangeVal, it, mapKeyPtr, mapValuePtr}, "range.next") -- mapKey := b.CreateLoad(mapKeyAlloca, "") -- mapValue := b.CreateLoad(mapValueAlloca, "") -+ mapKey := b.CreateLoad(llvmStoredKeyType, mapKeyAlloca, "") -+ mapValue := b.CreateLoad(llvmValueType, mapValueAlloca, "") - - if isKeyStoredAsInterface { - // The key is stored as an interface but it isn't of interface type. -diff --git a/compiler/volatile.go b/compiler/volatile.go -index 143eff28..3d3a67fa 100644 ---- a/compiler/volatile.go -+++ b/compiler/volatile.go -@@ -1,5 +1,7 @@ - package compiler - -+import "go/types" -+ - // This file implements volatile loads/stores in runtime/volatile.LoadT and - // runtime/volatile.StoreT as compiler builtins. - -@@ -9,7 +11,8 @@ func (b *builder) createVolatileLoad() { - b.createFunctionStart(true) - addr := b.getValue(b.fn.Params[0]) - b.createNilCheck(b.fn.Params[0], addr, "deref") -- val := b.CreateLoad(addr, "") -+ valType := b.getLLVMType(b.fn.Params[0].Type().(*types.Pointer).Elem()) -+ val := b.CreateLoad(valType, addr, "") - val.SetVolatile(true) - b.CreateRet(val) - } -diff --git a/go.mod b/go.mod -index 4af10427..26707a96 100644 ---- a/go.mod -+++ b/go.mod -@@ -17,7 +17,7 @@ require ( - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 - golang.org/x/tools v0.1.11 - gopkg.in/yaml.v2 v2.4.0 -- tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 -+ tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 - ) - - require ( -diff --git a/go.sum b/go.sum -index 401de3be..e5c734cd 100644 ---- a/go.sum -+++ b/go.sum -@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= - gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= --tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 h1:JxtI6P/lyWHAcs/4QJWeWIbh4HntxPFONMVWvx7wf8Y= --tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -+tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 h1:bJYUpmJrVm7Uluxh80qSivfeU3d9D4JNg5oJ+h9U+xc= -+tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -diff --git a/interp/interpreter.go b/interp/interpreter.go -index 4a4553f8..2c7fd8c3 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -983,7 +983,7 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me - if err != nil { - return r.errorAt(inst, err) - } -- result = r.builder.CreateLoad(operands[0], inst.name) -+ result = r.builder.CreateLoad(inst.llvmInst.Type(), operands[0], inst.name) - if inst.llvmInst.IsVolatile() { - result.SetVolatile(true) - } -diff --git a/transform/gc.go b/transform/gc.go -index 87dc6e88..7a4e99ac 100644 ---- a/transform/gc.go -+++ b/transform/gc.go -@@ -222,7 +222,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - builder.CreateStore(initialStackObject, stackObject) - - // Update stack start. -- parent := builder.CreateLoad(stackChainStart, "") -+ parent := builder.CreateLoad(stackChainStartType, stackChainStart, "") - gep := builder.CreateGEP(stackObject, []llvm.Value{ - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), 0, false), -diff --git a/transform/stacksize.go b/transform/stacksize.go -index 7be49238..f1a3c93d 100644 ---- a/transform/stacksize.go -+++ b/transform/stacksize.go -@@ -34,6 +34,11 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string - return nil - } - -+ ctx := mod.Context() -+ targetData := llvm.NewTargetData(mod.DataLayout()) -+ defer targetData.Dispose() -+ uintptrType := ctx.IntType(targetData.PointerSize() * 8) -+ - // Create the new global with stack sizes, that will be put in a new section - // just for itself. - stackSizesGlobalType := llvm.ArrayType(functions[0].Type(), len(functions)) -@@ -50,16 +55,16 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string - appendToUsedGlobals(mod, append([]llvm.Value{stackSizesGlobal}, functionValues...)...) - - // Replace the calls with loads from the new global with stack sizes. -- irbuilder := mod.Context().NewBuilder() -+ irbuilder := ctx.NewBuilder() - defer irbuilder.Dispose() - for i, function := range functions { - for _, use := range functionMap[function] { - ptr := llvm.ConstGEP(stackSizesGlobal, []llvm.Value{ -- llvm.ConstInt(mod.Context().Int32Type(), 0, false), -- llvm.ConstInt(mod.Context().Int32Type(), uint64(i), false), -+ llvm.ConstInt(ctx.Int32Type(), 0, false), -+ llvm.ConstInt(ctx.Int32Type(), uint64(i), false), - }) - irbuilder.SetInsertPointBefore(use) -- stacksize := irbuilder.CreateLoad(ptr, "stacksize") -+ stacksize := irbuilder.CreateLoad(uintptrType, ptr, "stacksize") - use.ReplaceAllUsesWith(stacksize) - use.EraseFromParentAsInstruction() - } -diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go -index aedad71d..064e38f4 100644 ---- a/transform/wasm-abi.go -+++ b/transform/wasm-abi.go -@@ -125,7 +125,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { - // where the return value should be stored, instead of using - // the regular return value. - builder.CreateCall(externalFnType, externalFn, callParams, callName) -- returnValue := builder.CreateLoad(retvalAlloca, "retval") -+ returnValue := builder.CreateLoad(int64Type, retvalAlloca, "retval") - call.ReplaceAllUsesWith(returnValue) - call.EraseFromParentAsInstruction() - } else { -@@ -152,7 +152,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { - for i, origParam := range fn.Params() { - paramValue := externalFn.Param(i) - if origParam.Type() == int64Type { -- paramValue = builder.CreateLoad(paramValue, "i64") -+ paramValue = builder.CreateLoad(int64Type, paramValue, "i64") - } - callParams = append(callParams, paramValue) - } --- -2.38.1 - diff --git a/0011-all-add-type-parameter-to-GEP-calls.patch b/0011-all-add-type-parameter-to-GEP-calls.patch deleted file mode 100644 index 120c469..0000000 --- a/0011-all-add-type-parameter-to-GEP-calls.patch +++ /dev/null @@ -1,565 +0,0 @@ -From dd4f1c594ef0fadb59fa418f1049542f86237800 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Wed, 21 Sep 2022 17:00:09 +0200 -Subject: [PATCH 11/26] all: add type parameter to *GEP calls - -This is necessary for LLVM 15. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/build.go | 2 +- - compiler/channel.go | 8 +++--- - compiler/compiler.go | 46 ++++++++++++++++++++--------------- - compiler/defer.go | 19 ++++++++------- - compiler/interface.go | 16 ++++++------ - compiler/llvm.go | 6 ++--- - compiler/llvmutil/wordpack.go | 6 ++--- - go.mod | 2 +- - go.sum | 4 +-- - interp/memory.go | 4 +-- - transform/gc.go | 4 +-- - transform/llvm.go | 10 ++++---- - transform/stacksize.go | 2 +- - 13 files changed, 69 insertions(+), 60 deletions(-) - -diff --git a/builder/build.go b/builder/build.go -index 28385044..7a7dd9ac 100644 ---- a/builder/build.go -+++ b/builder/build.go -@@ -1153,7 +1153,7 @@ func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) erro - - // Create the string value, which is a {ptr, len} pair. - zero := llvm.ConstInt(mod.Context().Int32Type(), 0, false) -- ptr := llvm.ConstGEP(buf, []llvm.Value{zero, zero}) -+ ptr := llvm.ConstGEP(bufInitializer.Type(), buf, []llvm.Value{zero, zero}) - if ptr.Type() != elementTypes[0] { - return fmt.Errorf("%s: not a string", globalName) - } -diff --git a/compiler/channel.go b/compiler/channel.go -index 5c3b6c59..81f84565 100644 ---- a/compiler/channel.go -+++ b/compiler/channel.go -@@ -173,7 +173,7 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value { - allocaType := llvm.ArrayType(b.ctx.Int8Type(), int(recvbufSize)) - recvbufAlloca, _, _ := b.createTemporaryAlloca(allocaType, "select.recvbuf.alloca") - recvbufAlloca.SetAlignment(recvbufAlign) -- recvbuf = b.CreateGEP(recvbufAlloca, []llvm.Value{ -+ recvbuf = b.CreateGEP(allocaType, recvbufAlloca, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - }, "select.recvbuf") -@@ -184,13 +184,13 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value { - statesAlloca, statesI8, statesSize := b.createTemporaryAlloca(statesAllocaType, "select.states.alloca") - for i, state := range selectStates { - // Set each slice element to the appropriate channel. -- gep := b.CreateGEP(statesAlloca, []llvm.Value{ -+ gep := b.CreateGEP(statesAllocaType, statesAlloca, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false), - }, "") - b.CreateStore(state, gep) - } -- statesPtr := b.CreateGEP(statesAlloca, []llvm.Value{ -+ statesPtr := b.CreateGEP(statesAllocaType, statesAlloca, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - }, "select.states") -@@ -204,7 +204,7 @@ func (b *builder) createSelect(expr *ssa.Select) llvm.Value { - chBlockAllocaType := llvm.ArrayType(b.getLLVMRuntimeType("channelBlockedList"), len(selectStates)) - chBlockAlloca, chBlockAllocaPtr, chBlockSize := b.createTemporaryAlloca(chBlockAllocaType, "select.block.alloca") - chBlockLen := llvm.ConstInt(b.uintptrType, uint64(len(selectStates)), false) -- chBlockPtr := b.CreateGEP(chBlockAlloca, []llvm.Value{ -+ chBlockPtr := b.CreateGEP(chBlockAllocaType, chBlockAlloca, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - }, "select.block") -diff --git a/compiler/compiler.go b/compiler/compiler.go -index 7ab2fe4e..c93b2e56 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -918,7 +918,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu - bufferGlobal.SetInitializer(bufferValue) - bufferGlobal.SetLinkage(llvm.InternalLinkage) - bufferGlobal.SetAlignment(1) -- slicePtr := llvm.ConstInBoundsGEP(bufferGlobal, []llvm.Value{ -+ slicePtr := llvm.ConstInBoundsGEP(bufferValue.Type(), bufferGlobal, []llvm.Value{ - llvm.ConstInt(c.uintptrType, 0, false), - llvm.ConstInt(c.uintptrType, 0, false), - }) -@@ -990,7 +990,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu - // Create the slice object itself. - // Because embed.FS refers to it as *[]embed.file instead of a plain - // []embed.file, we have to store this as a global. -- slicePtr := llvm.ConstInBoundsGEP(sliceDataGlobal, []llvm.Value{ -+ slicePtr := llvm.ConstInBoundsGEP(sliceDataInitializer.Type(), sliceDataGlobal, []llvm.Value{ - llvm.ConstInt(c.uintptrType, 0, false), - llvm.ConstInt(c.uintptrType, 0, false), - }) -@@ -1018,11 +1018,11 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu - func (c *compilerContext) getEmbedFileString(file *loader.EmbedFile) llvm.Value { - dataGlobalName := "embed/file_" + file.Hash - dataGlobal := c.mod.NamedGlobal(dataGlobalName) -+ dataGlobalType := llvm.ArrayType(c.ctx.Int8Type(), int(file.Size)) - if dataGlobal.IsNil() { -- dataGlobalType := llvm.ArrayType(c.ctx.Int8Type(), int(file.Size)) - dataGlobal = llvm.AddGlobal(c.mod, dataGlobalType, dataGlobalName) - } -- strPtr := llvm.ConstInBoundsGEP(dataGlobal, []llvm.Value{ -+ strPtr := llvm.ConstInBoundsGEP(dataGlobalType, dataGlobal, []llvm.Value{ - llvm.ConstInt(c.uintptrType, 0, false), - llvm.ConstInt(c.uintptrType, 0, false), - }) -@@ -1601,7 +1601,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - // Note: the pointer is always of type *i8. - ptr := argValues[0] - len := argValues[1] -- return b.CreateGEP(ptr, []llvm.Value{len}, ""), nil -+ return b.CreateGEP(b.ctx.Int8Type(), ptr, []llvm.Value{len}, ""), nil - case "Alignof": // unsafe.Alignof - align := b.targetData.ABITypeAlignment(argValues[0].Type()) - return llvm.ConstInt(b.uintptrType, uint64(align), false), nil -@@ -1911,7 +1911,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), uint64(expr.Field), false), - } -- return b.CreateInBoundsGEP(val, indices, ""), nil -+ elementType := b.getLLVMType(expr.X.Type().Underlying().(*types.Pointer).Elem()) -+ return b.CreateInBoundsGEP(elementType, val, indices, ""), nil - case *ssa.Function: - panic("function is not an expression") - case *ssa.Global: -@@ -1935,7 +1936,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(arrayType, "index.alloca") - b.CreateStore(array, alloca) - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) -- ptr := b.CreateInBoundsGEP(alloca, []llvm.Value{zero, index}, "index.gep") -+ ptr := b.CreateInBoundsGEP(arrayType, alloca, []llvm.Value{zero, index}, "index.gep") - result := b.CreateLoad(arrayType.ElementType(), ptr, "index.load") - b.emitLifetimeEnd(allocaPtr, allocaSize) - return result, nil -@@ -1945,13 +1946,15 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - - // Get buffer pointer and length - var bufptr, buflen llvm.Value -+ var bufType llvm.Type - switch ptrTyp := expr.X.Type().Underlying().(type) { - case *types.Pointer: -- typ := expr.X.Type().Underlying().(*types.Pointer).Elem().Underlying() -+ typ := ptrTyp.Elem().Underlying() - switch typ := typ.(type) { - case *types.Array: - bufptr = val - buflen = llvm.ConstInt(b.uintptrType, uint64(typ.Len()), false) -+ bufType = b.getLLVMType(typ) - // Check for nil pointer before calculating the address, from - // the spec: - // > For an operand x of type T, the address operation &x -@@ -1965,6 +1968,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - case *types.Slice: - bufptr = b.CreateExtractValue(val, 0, "indexaddr.ptr") - buflen = b.CreateExtractValue(val, 1, "indexaddr.len") -+ bufType = b.getLLVMType(ptrTyp.Elem()) - default: - return llvm.Value{}, b.makeError(expr.Pos(), "todo: indexaddr: "+ptrTyp.String()) - } -@@ -1982,9 +1986,9 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - index, - } -- return b.CreateInBoundsGEP(bufptr, indices, ""), nil -+ return b.CreateInBoundsGEP(bufType, bufptr, indices, ""), nil - case *types.Slice: -- return b.CreateInBoundsGEP(bufptr, []llvm.Value{index}, ""), nil -+ return b.CreateInBoundsGEP(bufType, bufptr, []llvm.Value{index}, ""), nil - default: - panic("unreachable") - } -@@ -2012,8 +2016,9 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - - // Lookup byte - buf := b.CreateExtractValue(value, 0, "") -- bufPtr := b.CreateInBoundsGEP(buf, []llvm.Value{index}, "") -- return b.CreateLoad(b.ctx.Int8Type(), bufPtr, ""), nil -+ bufElemType := b.ctx.Int8Type() -+ bufPtr := b.CreateInBoundsGEP(bufElemType, buf, []llvm.Value{index}, "") -+ return b.CreateLoad(bufElemType, bufPtr, ""), nil - case *types.Map: - valueType := expr.Type() - if expr.CommaOk { -@@ -2146,7 +2151,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - switch typ := expr.X.Type().Underlying().(type) { - case *types.Pointer: // pointer to array - // slice an array -- length := typ.Elem().Underlying().(*types.Array).Len() -+ arrayType := typ.Elem().Underlying().(*types.Array) -+ length := arrayType.Len() - llvmLen := llvm.ConstInt(b.uintptrType, uint64(length), false) - if high.IsNil() { - high = llvmLen -@@ -2175,7 +2181,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - } - - sliceLen := b.CreateSub(high, low, "slice.len") -- slicePtr := b.CreateInBoundsGEP(value, indices, "slice.ptr") -+ slicePtr := b.CreateInBoundsGEP(b.getLLVMType(arrayType), value, indices, "slice.ptr") - sliceCap := b.CreateSub(max, low, "slice.cap") - - slice := b.ctx.ConstStruct([]llvm.Value{ -@@ -2214,7 +2220,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - max = b.CreateTrunc(max, b.uintptrType, "") - } - -- newPtr := b.CreateInBoundsGEP(oldPtr, []llvm.Value{low}, "") -+ ptrElemType := b.getLLVMType(typ.Elem()) -+ newPtr := b.CreateInBoundsGEP(ptrElemType, oldPtr, []llvm.Value{low}, "") - newLen := b.CreateSub(high, low, "") - newCap := b.CreateSub(max, low, "") - slice := b.ctx.ConstStruct([]llvm.Value{ -@@ -2254,7 +2261,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { - high = b.CreateTrunc(high, b.uintptrType, "") - } - -- newPtr := b.CreateInBoundsGEP(oldPtr, []llvm.Value{low}, "") -+ newPtr := b.CreateInBoundsGEP(b.ctx.Int8Type(), oldPtr, []llvm.Value{low}, "") - newLen := b.CreateSub(high, low, "") - str := llvm.Undef(b.getLLVMRuntimeType("_string")) - str = b.CreateInsertValue(str, newPtr, 0, "") -@@ -2717,14 +2724,15 @@ func (c *compilerContext) createConst(expr *ssa.Const) llvm.Value { - var strPtr llvm.Value - if str != "" { - objname := c.pkg.Path() + "$string" -- global := llvm.AddGlobal(c.mod, llvm.ArrayType(c.ctx.Int8Type(), len(str)), objname) -+ globalType := llvm.ArrayType(c.ctx.Int8Type(), len(str)) -+ global := llvm.AddGlobal(c.mod, globalType, objname) - global.SetInitializer(c.ctx.ConstString(str, false)) - global.SetLinkage(llvm.InternalLinkage) - global.SetGlobalConstant(true) - global.SetUnnamedAddr(true) - global.SetAlignment(1) - zero := llvm.ConstInt(c.ctx.Int32Type(), 0, false) -- strPtr = llvm.ConstInBoundsGEP(global, []llvm.Value{zero, zero}) -+ strPtr = llvm.ConstInBoundsGEP(globalType, global, []llvm.Value{zero, zero}) - } else { - strPtr = llvm.ConstNull(c.i8ptrType) - } -@@ -2844,7 +2852,7 @@ func (b *builder) createConvert(typeFrom, typeTo types.Type, value llvm.Value, p - // create a GEP that is not in bounds. However, we're - // talking about unsafe code here so the programmer has to - // be careful anyway. -- return b.CreateInBoundsGEP(origptr, []llvm.Value{index}, ""), nil -+ return b.CreateInBoundsGEP(b.ctx.Int8Type(), origptr, []llvm.Value{index}, ""), nil - } - } - } -diff --git a/compiler/defer.go b/compiler/defer.go -index 1f892e5b..27e90331 100644 ---- a/compiler/defer.go -+++ b/compiler/defer.go -@@ -407,7 +407,8 @@ func (b *builder) createDefer(instr *ssa.Defer) { - - // createRunDefers emits code to run all deferred functions. - func (b *builder) createRunDefers() { -- deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0) -+ deferType := b.getLLVMRuntimeType("_defer") -+ deferPtrType := llvm.PointerType(deferType, 0) - - // Add a loop like the following: - // for stack != nil { -@@ -434,7 +435,7 @@ func (b *builder) createRunDefers() { - // Create loop head: - // for stack != nil { - b.SetInsertPointAtEnd(loophead) -- deferData := b.CreateLoad(deferType, b.deferPtr, "") -+ deferData := b.CreateLoad(deferPtrType, b.deferPtr, "") - stackIsNil := b.CreateICmp(llvm.IntEQ, deferData, llvm.ConstPointerNull(deferData.Type()), "stackIsNil") - b.CreateCondBr(stackIsNil, end, loop) - -@@ -443,13 +444,13 @@ func (b *builder) createRunDefers() { - // stack = stack.next - // switch stack.callback { - b.SetInsertPointAtEnd(loop) -- nextStackGEP := b.CreateInBoundsGEP(deferData, []llvm.Value{ -+ nextStackGEP := b.CreateInBoundsGEP(deferType, deferData, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 1, false), // .next field - }, "stack.next.gep") -- nextStack := b.CreateLoad(deferType, nextStackGEP, "stack.next") -+ nextStack := b.CreateLoad(deferPtrType, nextStackGEP, "stack.next") - b.CreateStore(nextStack, b.deferPtr) -- gep := b.CreateInBoundsGEP(deferData, []llvm.Value{ -+ gep := b.CreateInBoundsGEP(deferType, deferData, []llvm.Value{ - llvm.ConstInt(b.ctx.Int32Type(), 0, false), - llvm.ConstInt(b.ctx.Int32Type(), 0, false), // .callback field - }, "callback.gep") -@@ -489,7 +490,7 @@ func (b *builder) createRunDefers() { - forwardParams := []llvm.Value{} - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := 2; i < len(valueTypes); i++ { -- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep") -+ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep") - forwardParam := b.CreateLoad(valueTypes[i], gep, "param") - forwardParams = append(forwardParams, forwardParam) - } -@@ -538,7 +539,7 @@ func (b *builder) createRunDefers() { - forwardParams := []llvm.Value{} - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := range getParams(callback.Signature) { -- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") -+ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") - forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") - forwardParams = append(forwardParams, forwardParam) - } -@@ -571,7 +572,7 @@ func (b *builder) createRunDefers() { - forwardParams := []llvm.Value{} - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := 2; i < len(valueTypes); i++ { -- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "") -+ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "") - forwardParam := b.CreateLoad(valueTypes[i], gep, "param") - forwardParams = append(forwardParams, forwardParam) - } -@@ -598,7 +599,7 @@ func (b *builder) createRunDefers() { - var argValues []llvm.Value - zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false) - for i := 0; i < params.Len(); i++ { -- gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") -+ gep := b.CreateInBoundsGEP(deferredCallType, deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep") - forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param") - argValues = append(argValues, forwardParam) - } -diff --git a/compiler/interface.go b/compiler/interface.go -index 72f8952d..acb474f5 100644 ---- a/compiler/interface.go -+++ b/compiler/interface.go -@@ -122,19 +122,19 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { - for i := 0; i < typ.NumFields(); i++ { - fieldGlobalValue := llvm.ConstNull(runtimeStructField) - fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0}) -- fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) -+ fieldNameType, fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) - fieldName.SetLinkage(llvm.PrivateLinkage) - fieldName.SetUnnamedAddr(true) -- fieldName = llvm.ConstGEP(fieldName, []llvm.Value{ -+ fieldName = llvm.ConstGEP(fieldNameType, fieldName, []llvm.Value{ - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - }) - fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) - if typ.Tag(i) != "" { -- fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) -+ fieldTagType, fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) - fieldTag.SetLinkage(llvm.PrivateLinkage) - fieldTag.SetUnnamedAddr(true) -- fieldTag = llvm.ConstGEP(fieldTag, []llvm.Value{ -+ fieldTag = llvm.ConstGEP(fieldTagType, fieldTag, []llvm.Value{ - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - }) -@@ -239,7 +239,7 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value { - zero := llvm.ConstInt(c.ctx.Int32Type(), 0, false) - if !global.IsNil() { - // the method set already exists -- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) -+ return llvm.ConstGEP(global.GlobalValueType(), global, []llvm.Value{zero, zero}) - } - - ms := c.program.MethodSets.MethodSet(typ) -@@ -272,7 +272,7 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value { - global.SetInitializer(value) - global.SetGlobalConstant(true) - global.SetLinkage(llvm.LinkOnceODRLinkage) -- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) -+ return llvm.ConstGEP(arrayType, global, []llvm.Value{zero, zero}) - } - - // getInterfaceMethodSet returns a global variable with the method set of the -@@ -288,7 +288,7 @@ func (c *compilerContext) getInterfaceMethodSet(typ types.Type) llvm.Value { - zero := llvm.ConstInt(c.ctx.Int32Type(), 0, false) - if !global.IsNil() { - // method set already exist, return it -- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) -+ return llvm.ConstGEP(global.GlobalValueType(), global, []llvm.Value{zero, zero}) - } - - // Every method is a *i8 reference indicating the signature of this method. -@@ -303,7 +303,7 @@ func (c *compilerContext) getInterfaceMethodSet(typ types.Type) llvm.Value { - global.SetInitializer(value) - global.SetGlobalConstant(true) - global.SetLinkage(llvm.LinkOnceODRLinkage) -- return llvm.ConstGEP(global, []llvm.Value{zero, zero}) -+ return llvm.ConstGEP(value.Type(), global, []llvm.Value{zero, zero}) - } - - // getMethodSignatureName returns a unique name (that can be used as the name of -diff --git a/compiler/llvm.go b/compiler/llvm.go -index 9540bcc6..686d4d2b 100644 ---- a/compiler/llvm.go -+++ b/compiler/llvm.go -@@ -61,10 +61,10 @@ func (b *builder) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []ll - } - - // makeGlobalArray creates a new LLVM global with the given name and integers as --// contents, and returns the global. -+// contents, and returns the global and initializer type. - // Note that it is left with the default linkage etc., you should set - // linkage/constant/etc properties yourself. --func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType llvm.Type) llvm.Value { -+func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType llvm.Type) (llvm.Type, llvm.Value) { - globalType := llvm.ArrayType(elementType, len(buf)) - global := llvm.AddGlobal(c.mod, globalType, name) - value := llvm.Undef(globalType) -@@ -73,7 +73,7 @@ func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType l - value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) - } - global.SetInitializer(value) -- return global -+ return globalType, global - } - - // createObjectLayout returns a LLVM value (of type i8*) that describes where -diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go -index 97b86045..2a4607c8 100644 ---- a/compiler/llvmutil/wordpack.go -+++ b/compiler/llvmutil/wordpack.go -@@ -58,7 +58,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), uint64(i), false), - } -- gep := builder.CreateInBoundsGEP(packedAllocCast, indices, "") -+ gep := builder.CreateInBoundsGEP(packedType, packedAllocCast, indices, "") - builder.CreateStore(value, gep) - } - -@@ -115,7 +115,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), uint64(i), false), - } -- gep := builder.CreateInBoundsGEP(packedAlloc, indices, "") -+ gep := builder.CreateInBoundsGEP(packedType, packedAlloc, indices, "") - builder.CreateStore(value, gep) - } - -@@ -170,7 +170,7 @@ func EmitPointerUnpack(builder llvm.Builder, mod llvm.Module, ptr llvm.Value, va - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), uint64(i), false), - } -- gep := builder.CreateInBoundsGEP(packedAlloc, indices, "") -+ gep := builder.CreateInBoundsGEP(packedType, packedAlloc, indices, "") - values[i] = builder.CreateLoad(valueType, gep, "") - } - if !packedRawAlloc.IsNil() { -diff --git a/go.mod b/go.mod -index 26707a96..feb4e0d6 100644 ---- a/go.mod -+++ b/go.mod -@@ -17,7 +17,7 @@ require ( - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 - golang.org/x/tools v0.1.11 - gopkg.in/yaml.v2 v2.4.0 -- tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 -+ tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 - ) - - require ( -diff --git a/go.sum b/go.sum -index e5c734cd..907364f9 100644 ---- a/go.sum -+++ b/go.sum -@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= - gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= --tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 h1:bJYUpmJrVm7Uluxh80qSivfeU3d9D4JNg5oJ+h9U+xc= --tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -+tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 h1:hihbmHkJjalV4kGshoCF03P/G4IjoXcNAbzLblXLa/M= -+tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -diff --git a/interp/memory.go b/interp/memory.go -index 3a16b875..2fa6f5cb 100644 ---- a/interp/memory.go -+++ b/interp/memory.go -@@ -646,8 +646,8 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val - if llvmValue.Type() != mem.r.i8ptrType { - llvmValue = llvm.ConstBitCast(llvmValue, mem.r.i8ptrType) - } -- llvmValue = llvm.ConstInBoundsGEP(llvmValue, []llvm.Value{ -- llvm.ConstInt(llvmValue.Type().Context().Int32Type(), uint64(v.offset()), false), -+ llvmValue = llvm.ConstInBoundsGEP(mem.r.mod.Context().Int8Type(), llvmValue, []llvm.Value{ -+ llvm.ConstInt(mem.r.mod.Context().Int32Type(), uint64(v.offset()), false), - }) - } - -diff --git a/transform/gc.go b/transform/gc.go -index 7a4e99ac..3870a6b6 100644 ---- a/transform/gc.go -+++ b/transform/gc.go -@@ -223,7 +223,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - - // Update stack start. - parent := builder.CreateLoad(stackChainStartType, stackChainStart, "") -- gep := builder.CreateGEP(stackObject, []llvm.Value{ -+ gep := builder.CreateGEP(stackObjectType, stackObject, []llvm.Value{ - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), 0, false), - }, "") -@@ -244,7 +244,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - builder.SetInsertPointBefore(insertionPoint) - - // Extract a pointer to the appropriate section of the stack object. -- gep := builder.CreateGEP(stackObject, []llvm.Value{ -+ gep := builder.CreateGEP(stackObjectType, stackObject, []llvm.Value{ - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), uint64(2+i), false), - }, "") -diff --git a/transform/llvm.go b/transform/llvm.go -index 32ee9560..6716dd63 100644 ---- a/transform/llvm.go -+++ b/transform/llvm.go -@@ -31,10 +31,10 @@ func hasUses(value llvm.Value) bool { - } - - // makeGlobalArray creates a new LLVM global with the given name and integers as --// contents, and returns the global. -+// contents, and returns the global and initializer type. - // Note that it is left with the default linkage etc., you should set - // linkage/constant/etc properties yourself. --func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) llvm.Value { -+func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) (llvm.Type, llvm.Value) { - buf := reflect.ValueOf(bufItf) - globalType := llvm.ArrayType(elementType, buf.Len()) - global := llvm.AddGlobal(mod, globalType, name) -@@ -44,7 +44,7 @@ func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementTy - value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) - } - global.SetInitializer(value) -- return global -+ return globalType, global - } - - // getGlobalBytes returns the slice contained in the array of the provided -@@ -64,8 +64,8 @@ func getGlobalBytes(global llvm.Value) []byte { - // function used for creating reflection sidetables, for example. - func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) llvm.Value { - oldGlobal := mod.NamedGlobal(name) -- global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.Type().ElementType()) -- gep := llvm.ConstGEP(global, []llvm.Value{ -+ globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.Type().ElementType()) -+ gep := llvm.ConstGEP(globalType, global, []llvm.Value{ - llvm.ConstInt(mod.Context().Int32Type(), 0, false), - llvm.ConstInt(mod.Context().Int32Type(), 0, false), - }) -diff --git a/transform/stacksize.go b/transform/stacksize.go -index f1a3c93d..169f1454 100644 ---- a/transform/stacksize.go -+++ b/transform/stacksize.go -@@ -59,7 +59,7 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string - defer irbuilder.Dispose() - for i, function := range functions { - for _, use := range functionMap[function] { -- ptr := llvm.ConstGEP(stackSizesGlobal, []llvm.Value{ -+ ptr := llvm.ConstGEP(stackSizesGlobalType, stackSizesGlobal, []llvm.Value{ - llvm.ConstInt(ctx.Int32Type(), 0, false), - llvm.ConstInt(ctx.Int32Type(), uint64(i), false), - }) --- -2.38.1 - diff --git a/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch b/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch deleted file mode 100644 index d63dd8c..0000000 --- a/0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch +++ /dev/null @@ -1,578 +0,0 @@ -From 6053c1c8528c63a669d070550bacd43f2f6a68e1 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Tue, 20 Sep 2022 23:26:49 +0200 -Subject: [PATCH 12/26] all: replace llvm.Const* calls with builder.Create* - calls - -A number of llvm.Const* functions (in particular extractvalue and -insertvalue) were removed in LLVM 15, so we have to use a builder -instead. This builder will create the same constant values, it simply -uses a different API. - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/asserts.go | 2 +- - compiler/compiler.go | 23 ++++++++++++++++------- - compiler/interface.go | 20 ++++++++++---------- - compiler/interrupt.go | 8 +++++--- - compiler/llvm.go | 2 +- - interp/interpreter.go | 13 +++++++------ - interp/memory.go | 8 ++++---- - transform/gc.go | 2 +- - transform/interface-lowering.go | 14 +++++++------- - transform/interrupt.go | 7 ++++--- - transform/llvm.go | 16 +++++++++------- - transform/reflect.go | 32 +++++++++++++++++++------------- - transform/rtcalls.go | 4 ++-- - 13 files changed, 86 insertions(+), 65 deletions(-) - -diff --git a/compiler/asserts.go b/compiler/asserts.go -index 8d9efdde..2a5265e9 100644 ---- a/compiler/asserts.go -+++ b/compiler/asserts.go -@@ -145,7 +145,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value, - } - // Make the maxBufSize actually the maximum allowed value (in number of - // elements in the channel buffer). -- maxBufSize = llvm.ConstUDiv(maxBufSize, llvm.ConstInt(b.uintptrType, elementSize, false)) -+ maxBufSize = b.CreateUDiv(maxBufSize, llvm.ConstInt(b.uintptrType, elementSize, false), "") - - // Make sure maxBufSize has the same type as bufSize. - if maxBufSize.Type() != bufSize.Type() { -diff --git a/compiler/compiler.go b/compiler/compiler.go -index c93b2e56..3d29628c 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -63,6 +63,7 @@ type compilerContext struct { - DumpSSA bool - mod llvm.Module - ctx llvm.Context -+ builder llvm.Builder // only used for constant operations - dibuilder *llvm.DIBuilder - cu llvm.Metadata - difiles map[string]llvm.Metadata -@@ -98,6 +99,7 @@ func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *C - } - - c.ctx = llvm.NewContext() -+ c.builder = c.ctx.NewBuilder() - c.mod = c.ctx.NewModule(moduleName) - c.mod.SetTarget(config.Triple) - c.mod.SetDataLayout(c.targetData.String()) -@@ -126,6 +128,12 @@ func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *C - return c - } - -+// Dispose everything related to the context, _except_ for the IR module (and -+// the associated context). -+func (c *compilerContext) dispose() { -+ c.builder.Dispose() -+} -+ - // builder contains all information relevant to build a single function. - type builder struct { - *compilerContext -@@ -256,6 +264,7 @@ func Sizes(machine llvm.TargetMachine) types.Sizes { - // CompilePackage compiles a single package to a LLVM module. - func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, machine llvm.TargetMachine, config *Config, dumpSSA bool) (llvm.Module, []error) { - c := newCompilerContext(moduleName, machine, config, dumpSSA) -+ defer c.dispose() - c.packageDir = pkg.OriginalDir() - c.embedGlobals = pkg.EmbedGlobals - c.pkg = pkg.Pkg -@@ -972,10 +981,10 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu - for _, file := range allFiles { - fileStruct := llvm.ConstNull(embedFileStructType) - name := c.createConst(ssa.NewConst(constant.MakeString(file.Name), types.Typ[types.String])) -- fileStruct = llvm.ConstInsertValue(fileStruct, name, []uint32{0}) // "name" field -+ fileStruct = c.builder.CreateInsertValue(fileStruct, name, 0, "") // "name" field - if file.Hash != "" { - data := c.getEmbedFileString(file) -- fileStruct = llvm.ConstInsertValue(fileStruct, data, []uint32{1}) // "data" field -+ fileStruct = c.builder.CreateInsertValue(fileStruct, data, 1, "") // "data" field - } - fileStructs = append(fileStructs, fileStruct) - } -@@ -1006,7 +1015,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu - // Define the embed.FS struct. It has only one field: the files (as a - // *[]embed.file). - globalInitializer := llvm.ConstNull(c.getLLVMType(member.Type().(*types.Pointer).Elem())) -- globalInitializer = llvm.ConstInsertValue(globalInitializer, sliceGlobal, []uint32{0}) -+ globalInitializer = c.builder.CreateInsertValue(globalInitializer, sliceGlobal, 0, "") - global.SetInitializer(globalInitializer) - global.SetVisibility(llvm.HiddenVisibility) - global.SetAlignment(c.targetData.ABITypeAlignment(globalInitializer.Type())) -@@ -2757,15 +2766,15 @@ func (c *compilerContext) createConst(expr *ssa.Const) llvm.Value { - r := c.createConst(ssa.NewConst(constant.Real(expr.Value), types.Typ[types.Float32])) - i := c.createConst(ssa.NewConst(constant.Imag(expr.Value), types.Typ[types.Float32])) - cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{c.ctx.FloatType(), c.ctx.FloatType()}, false)) -- cplx = llvm.ConstInsertValue(cplx, r, []uint32{0}) -- cplx = llvm.ConstInsertValue(cplx, i, []uint32{1}) -+ cplx = c.builder.CreateInsertValue(cplx, r, 0, "") -+ cplx = c.builder.CreateInsertValue(cplx, i, 1, "") - return cplx - } else if typ.Kind() == types.Complex128 { - r := c.createConst(ssa.NewConst(constant.Real(expr.Value), types.Typ[types.Float64])) - i := c.createConst(ssa.NewConst(constant.Imag(expr.Value), types.Typ[types.Float64])) - cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{c.ctx.DoubleType(), c.ctx.DoubleType()}, false)) -- cplx = llvm.ConstInsertValue(cplx, r, []uint32{0}) -- cplx = llvm.ConstInsertValue(cplx, i, []uint32{1}) -+ cplx = c.builder.CreateInsertValue(cplx, r, 0, "") -+ cplx = c.builder.CreateInsertValue(cplx, i, 1, "") - return cplx - } else { - panic("unknown constant of basic type: " + expr.String()) -diff --git a/compiler/interface.go b/compiler/interface.go -index acb474f5..106c327a 100644 ---- a/compiler/interface.go -+++ b/compiler/interface.go -@@ -88,20 +88,20 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value { - } - globalValue := llvm.ConstNull(global.Type().ElementType()) - if !references.IsNil() { -- globalValue = llvm.ConstInsertValue(globalValue, references, []uint32{0}) -+ globalValue = c.builder.CreateInsertValue(globalValue, references, 0, "") - } - if length != 0 { - lengthValue := llvm.ConstInt(c.uintptrType, uint64(length), false) -- globalValue = llvm.ConstInsertValue(globalValue, lengthValue, []uint32{1}) -+ globalValue = c.builder.CreateInsertValue(globalValue, lengthValue, 1, "") - } - if !methodSet.IsNil() { -- globalValue = llvm.ConstInsertValue(globalValue, methodSet, []uint32{2}) -+ globalValue = c.builder.CreateInsertValue(globalValue, methodSet, 2, "") - } - if !ptrTo.IsNil() { -- globalValue = llvm.ConstInsertValue(globalValue, ptrTo, []uint32{3}) -+ globalValue = c.builder.CreateInsertValue(globalValue, ptrTo, 3, "") - } - if !typeAssert.IsNil() { -- globalValue = llvm.ConstInsertValue(globalValue, typeAssert, []uint32{4}) -+ globalValue = c.builder.CreateInsertValue(globalValue, typeAssert, 4, "") - } - global.SetInitializer(globalValue) - global.SetLinkage(llvm.LinkOnceODRLinkage) -@@ -121,7 +121,7 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { - structGlobalValue := llvm.ConstNull(structGlobalType) - for i := 0; i < typ.NumFields(); i++ { - fieldGlobalValue := llvm.ConstNull(runtimeStructField) -- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0}) -+ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), 0, "") - fieldNameType, fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) - fieldName.SetLinkage(llvm.PrivateLinkage) - fieldName.SetUnnamedAddr(true) -@@ -129,7 +129,7 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - }) -- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) -+ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldName, 1, "") - if typ.Tag(i) != "" { - fieldTagType, fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) - fieldTag.SetLinkage(llvm.PrivateLinkage) -@@ -138,13 +138,13 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - llvm.ConstInt(c.ctx.Int32Type(), 0, false), - }) -- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldTag, []uint32{2}) -+ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldTag, 2, "") - } - if typ.Field(i).Embedded() { - fieldEmbedded := llvm.ConstInt(c.ctx.Int1Type(), 1, false) -- fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldEmbedded, []uint32{3}) -+ fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldEmbedded, 3, "") - } -- structGlobalValue = llvm.ConstInsertValue(structGlobalValue, fieldGlobalValue, []uint32{uint32(i)}) -+ structGlobalValue = c.builder.CreateInsertValue(structGlobalValue, fieldGlobalValue, i, "") - } - structGlobal.SetInitializer(structGlobalValue) - structGlobal.SetUnnamedAddr(true) -diff --git a/compiler/interrupt.go b/compiler/interrupt.go -index 45c7d074..c1f7d69f 100644 ---- a/compiler/interrupt.go -+++ b/compiler/interrupt.go -@@ -49,9 +49,11 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro - global.SetGlobalConstant(true) - global.SetUnnamedAddr(true) - initializer := llvm.ConstNull(globalLLVMType) -- initializer = llvm.ConstInsertValue(initializer, funcContext, []uint32{0}) -- initializer = llvm.ConstInsertValue(initializer, funcPtr, []uint32{1}) -- initializer = llvm.ConstInsertValue(initializer, llvm.ConstInt(b.intType, uint64(id.Int64()), true), []uint32{2, 0}) -+ initializer = b.CreateInsertValue(initializer, funcContext, 0, "") -+ initializer = b.CreateInsertValue(initializer, funcPtr, 1, "") -+ initializer = b.CreateInsertValue(initializer, llvm.ConstNamedStruct(globalLLVMType.StructElementTypes()[2], []llvm.Value{ -+ llvm.ConstInt(b.intType, uint64(id.Int64()), true), -+ }), 2, "") - global.SetInitializer(initializer) - - // Add debug info to the interrupt global. -diff --git a/compiler/llvm.go b/compiler/llvm.go -index 686d4d2b..8b80869b 100644 ---- a/compiler/llvm.go -+++ b/compiler/llvm.go -@@ -70,7 +70,7 @@ func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType l - value := llvm.Undef(globalType) - for i := 0; i < len(buf); i++ { - ch := uint64(buf[i]) -- value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) -+ value = c.builder.CreateInsertValue(value, llvm.ConstInt(elementType, ch, false), i, "") - } - global.SetInitializer(value) - return globalType, global -diff --git a/interp/interpreter.go b/interp/interpreter.go -index 2c7fd8c3..d029aa33 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -408,7 +408,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - // Elem() is only valid for certain type classes. - switch class { - case "chan", "pointer", "slice", "array": -- elementType := llvm.ConstExtractValue(typecodeID.Initializer(), []uint32{0}) -+ elementType := r.builder.CreateExtractValue(typecodeID.Initializer(), 0, "") - uintptrType := r.mod.Context().IntType(int(mem.r.pointerSize) * 8) - locals[inst.localIndex] = r.getValue(llvm.ConstPtrToInt(elementType, uintptrType)) - default: -@@ -461,8 +461,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - // easier checking in the next step. - concreteTypeMethods := map[string]struct{}{} - for i := 0; i < methodSet.Type().ArrayLength(); i++ { -- methodInfo := llvm.ConstExtractValue(methodSet, []uint32{uint32(i)}) -- name := llvm.ConstExtractValue(methodInfo, []uint32{0}).Name() -+ methodInfo := r.builder.CreateExtractValue(methodSet, i, "") -+ name := r.builder.CreateExtractValue(methodInfo, 0, "").Name() - concreteTypeMethods[name] = struct{}{} - } - -@@ -496,7 +496,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - typecodeID := typecodeIDBitCast.Operand(0).Initializer() - - // Load the method set, which is part of the typecodeID object. -- methodSet := llvm.ConstExtractValue(typecodeID, []uint32{2}).Operand(0).Initializer() -+ methodSet := r.builder.CreateExtractValue(typecodeID, 2, "").Operand(0).Initializer() - - // We don't need to load the interface method set. - -@@ -511,9 +511,10 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - numMethods := methodSet.Type().ArrayLength() - var method llvm.Value - for i := 0; i < numMethods; i++ { -- methodSignature := llvm.ConstExtractValue(methodSet, []uint32{uint32(i), 0}) -+ methodSignatureAgg := r.builder.CreateExtractValue(methodSet, i, "") -+ methodSignature := r.builder.CreateExtractValue(methodSignatureAgg, 0, "") - if methodSignature == signature { -- method = llvm.ConstExtractValue(methodSet, []uint32{uint32(i), 1}).Operand(0) -+ method = r.builder.CreateExtractValue(methodSignatureAgg, 1, "").Operand(0) - } - } - if method.IsNil() { -diff --git a/interp/memory.go b/interp/memory.go -index 2fa6f5cb..583f9355 100644 ---- a/interp/memory.go -+++ b/interp/memory.go -@@ -215,7 +215,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error { - case llvm.StructTypeKind: - numElements := llvmType.StructElementTypesCount() - for i := 0; i < numElements; i++ { -- element := llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}) -+ element := mv.r.builder.CreateExtractValue(llvmValue, i, "") - err := mv.markExternal(element, mark) - if err != nil { - return err -@@ -224,7 +224,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error { - case llvm.ArrayTypeKind: - numElements := llvmType.ArrayLength() - for i := 0; i < numElements; i++ { -- element := llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}) -+ element := mv.r.builder.CreateExtractValue(llvmValue, i, "") - err := mv.markExternal(element, mark) - if err != nil { - return err -@@ -1074,7 +1074,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { - field := rawValue{ - buf: v.buf[offset:], - } -- field.set(llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}), r) -+ field.set(r.builder.CreateExtractValue(llvmValue, i, ""), r) - } - case llvm.ArrayTypeKind: - numElements := llvmType.ArrayLength() -@@ -1085,7 +1085,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { - field := rawValue{ - buf: v.buf[offset:], - } -- field.set(llvm.ConstExtractValue(llvmValue, []uint32{uint32(i)}), r) -+ field.set(r.builder.CreateExtractValue(llvmValue, i, ""), r) - } - case llvm.DoubleTypeKind: - f, _ := llvmValue.DoubleValue() -diff --git a/transform/gc.go b/transform/gc.go -index 3870a6b6..514fb1bf 100644 ---- a/transform/gc.go -+++ b/transform/gc.go -@@ -218,7 +218,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - initialStackObject := llvm.ConstNull(stackObjectType) - numSlots := (targetData.TypeAllocSize(stackObjectType) - uint64(targetData.PointerSize())*2) / uint64(targetData.ABITypeAlignment(uintptrType)) - numSlotsValue := llvm.ConstInt(uintptrType, numSlots, false) -- initialStackObject = llvm.ConstInsertValue(initialStackObject, numSlotsValue, []uint32{1}) -+ initialStackObject = builder.CreateInsertValue(initialStackObject, numSlotsValue, 1, "") - builder.CreateStore(initialStackObject, stackObject) - - // Update stack start. -diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go -index f5b29e30..f28443dc 100644 ---- a/transform/interface-lowering.go -+++ b/transform/interface-lowering.go -@@ -154,7 +154,7 @@ func (p *lowerInterfacesPass) run() error { - if initializer.IsNil() { - continue - } -- methodSet := llvm.ConstExtractValue(initializer, []uint32{2}) -+ methodSet := p.builder.CreateExtractValue(initializer, 2, "") - p.addTypeMethods(t, methodSet) - } - } -@@ -288,9 +288,9 @@ func (p *lowerInterfacesPass) run() error { - zeroUintptr := llvm.ConstNull(p.uintptrType) - for _, t := range p.types { - initializer := t.typecode.Initializer() -- methodSet := llvm.ConstExtractValue(initializer, []uint32{2}) -- initializer = llvm.ConstInsertValue(initializer, llvm.ConstNull(methodSet.Type()), []uint32{2}) -- initializer = llvm.ConstInsertValue(initializer, zeroUintptr, []uint32{4}) -+ methodSet := p.builder.CreateExtractValue(initializer, 2, "") -+ initializer = p.builder.CreateInsertValue(initializer, llvm.ConstNull(methodSet.Type()), 2, "") -+ initializer = p.builder.CreateInsertValue(initializer, zeroUintptr, 4, "") - t.typecode.SetInitializer(initializer) - } - -@@ -311,10 +311,10 @@ func (p *lowerInterfacesPass) addTypeMethods(t *typeInfo, methodSet llvm.Value) - t.methodSet = methodSet - set := methodSet.Initializer() // get value from global - for i := 0; i < set.Type().ArrayLength(); i++ { -- methodData := llvm.ConstExtractValue(set, []uint32{uint32(i)}) -- signatureGlobal := llvm.ConstExtractValue(methodData, []uint32{0}) -+ methodData := p.builder.CreateExtractValue(set, i, "") -+ signatureGlobal := p.builder.CreateExtractValue(methodData, 0, "") - signatureName := signatureGlobal.Name() -- function := llvm.ConstExtractValue(methodData, []uint32{1}).Operand(0) -+ function := p.builder.CreateExtractValue(methodData, 1, "").Operand(0) - signature := p.getSignature(signatureName) - method := &methodInfo{ - function: function, -diff --git a/transform/interrupt.go b/transform/interrupt.go -index 2c301be0..b15ff8a9 100644 ---- a/transform/interrupt.go -+++ b/transform/interrupt.go -@@ -44,7 +44,8 @@ func LowerInterrupts(mod llvm.Module) []error { - - // Get the interrupt number from the initializer - initializer := global.Initializer() -- num := llvm.ConstExtractValue(initializer, []uint32{2, 0}).SExtValue() -+ interrupt := builder.CreateExtractValue(initializer, 2, "") -+ num := builder.CreateExtractValue(interrupt, 0, "").SExtValue() - pkg := packageFromInterruptHandle(global) - - handles, exists := handleMap[num] -@@ -89,8 +90,8 @@ func LowerInterrupts(mod llvm.Module) []error { - builder.SetInsertPointBefore(call) - for _, handler := range handlers { - initializer := handler.Initializer() -- context := llvm.ConstExtractValue(initializer, []uint32{0}) -- funcPtr := llvm.ConstExtractValue(initializer, []uint32{1}).Operand(0) -+ context := builder.CreateExtractValue(initializer, 0, "") -+ funcPtr := builder.CreateExtractValue(initializer, 1, "").Operand(0) - builder.CreateCall(funcPtr.GlobalValueType(), funcPtr, []llvm.Value{ - num, - context, -diff --git a/transform/llvm.go b/transform/llvm.go -index 6716dd63..17968f8a 100644 ---- a/transform/llvm.go -+++ b/transform/llvm.go -@@ -36,25 +36,27 @@ func hasUses(value llvm.Value) bool { - // linkage/constant/etc properties yourself. - func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) (llvm.Type, llvm.Value) { - buf := reflect.ValueOf(bufItf) -- globalType := llvm.ArrayType(elementType, buf.Len()) -- global := llvm.AddGlobal(mod, globalType, name) -- value := llvm.Undef(globalType) -+ var values []llvm.Value - for i := 0; i < buf.Len(); i++ { - ch := buf.Index(i).Uint() -- value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) -+ values = append(values, llvm.ConstInt(elementType, ch, false)) - } -+ value := llvm.ConstArray(elementType, values) -+ global := llvm.AddGlobal(mod, value.Type(), name) - global.SetInitializer(value) -- return globalType, global -+ return value.Type(), global - } - - // getGlobalBytes returns the slice contained in the array of the provided - // global. It can recover the bytes originally created using makeGlobalArray, if - // makeGlobalArray was given a byte slice. --func getGlobalBytes(global llvm.Value) []byte { -+// -+// The builder parameter is only used for constant operations. -+func getGlobalBytes(global llvm.Value, builder llvm.Builder) []byte { - value := global.Initializer() - buf := make([]byte, value.Type().ArrayLength()) - for i := range buf { -- buf[i] = byte(llvm.ConstExtractValue(value, []uint32{uint32(i)}).ZExtValue()) -+ buf[i] = byte(builder.CreateExtractValue(value, i, "").ZExtValue()) - } - return buf - } -diff --git a/transform/reflect.go b/transform/reflect.go -index fd70ccb7..68beba9b 100644 ---- a/transform/reflect.go -+++ b/transform/reflect.go -@@ -76,6 +76,10 @@ var nonBasicTypes = map[string]int64{ - // typeCodeAssignmentState keeps some global state around for type code - // assignments, used to assign one unique type code to each Go type. - type typeCodeAssignmentState struct { -+ // Builder used purely for constant operations (because LLVM 15 removed many -+ // llvm.Const* functions). -+ builder llvm.Builder -+ - // An integer that's incremented each time it's used to give unique IDs to - // type codes that are not yet fully supported otherwise by the reflect - // package (or are simply unused in the compiled program). -@@ -165,6 +169,7 @@ func LowerReflect(mod llvm.Module) { - defer targetData.Dispose() - uintptrType := mod.Context().IntType(targetData.PointerSize() * 8) - state := typeCodeAssignmentState{ -+ builder: mod.Context().NewBuilder(), - fallbackIndex: 1, - uintptrLen: targetData.PointerSize() * 8, - namedBasicTypes: make(map[string]int), -@@ -177,6 +182,7 @@ func LowerReflect(mod llvm.Module) { - needsStructNamesSidetable: len(getUses(mod.NamedGlobal("reflect.structNamesSidetable"))) != 0, - needsArrayTypesSidetable: len(getUses(mod.NamedGlobal("reflect.arrayTypesSidetable"))) != 0, - } -+ defer state.builder.Dispose() - for _, t := range types { - num := state.getTypeCodeNum(t.typecode) - if num.BitLen() > state.uintptrLen || !num.IsUint64() { -@@ -238,7 +244,7 @@ func LowerReflect(mod llvm.Module) { - // It also cleans up the IR for testing. - for _, typ := range types { - initializer := typ.typecode.Initializer() -- references := llvm.ConstExtractValue(initializer, []uint32{0}) -+ references := state.builder.CreateExtractValue(initializer, 0, "") - typ.typecode.SetInitializer(llvm.ConstNull(initializer.Type())) - if strings.HasPrefix(typ.name, "reflect/types.type:struct:") { - // Structs have a 'references' field that is not a typecode but -@@ -260,7 +266,7 @@ func (state *typeCodeAssignmentState) getTypeCodeNum(typecode llvm.Value) *big.I - name := "" - if class == "named" { - name = value -- typecode = llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}) -+ typecode = state.builder.CreateExtractValue(typecode.Initializer(), 0, "") - class, value = getClassAndValueFromTypeCode(typecode) - } - if class == "basic" { -@@ -344,7 +350,7 @@ func (state *typeCodeAssignmentState) getNonBasicTypeCode(class string, typecode - switch class { - case "chan", "pointer", "slice": - // Prefix-style type kinds. The upper bits contain the element type. -- sub := llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}) -+ sub := state.builder.CreateExtractValue(typecode.Initializer(), 0, "") - return state.getTypeCodeNum(sub) - case "array": - // An array is basically a pair of (typecode, length) stored in a -@@ -416,7 +422,7 @@ func (state *typeCodeAssignmentState) getArrayTypeNum(typecode llvm.Value) int { - return num - } - -- elemTypeCode := llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}) -+ elemTypeCode := state.builder.CreateExtractValue(typecode.Initializer(), 0, "") - elemTypeNum := state.getTypeCodeNum(elemTypeCode) - if elemTypeNum.BitLen() > state.uintptrLen || !elemTypeNum.IsUint64() { - // TODO: make this a regular error -@@ -424,7 +430,7 @@ func (state *typeCodeAssignmentState) getArrayTypeNum(typecode llvm.Value) int { - } - - // The array side table is a sequence of {element type, array length}. -- arrayLength := llvm.ConstExtractValue(typecode.Initializer(), []uint32{1}).ZExtValue() -+ arrayLength := state.builder.CreateExtractValue(typecode.Initializer(), 1, "").ZExtValue() - buf := makeVarint(elemTypeNum.Uint64()) - buf = append(buf, makeVarint(arrayLength)...) - -@@ -454,7 +460,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int - - // Get the fields this struct type contains. - // The struct number will be the start index of -- structTypeGlobal := llvm.ConstExtractValue(typecode.Initializer(), []uint32{0}).Operand(0).Initializer() -+ structTypeGlobal := state.builder.CreateExtractValue(typecode.Initializer(), 0, "").Operand(0).Initializer() - numFields := structTypeGlobal.Type().ArrayLength() - - // The first data that is stored in the struct sidetable is the number of -@@ -471,28 +477,28 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int - // the sidetable bigger. - for i := 0; i < numFields; i++ { - // Collect some information about this field. -- field := llvm.ConstExtractValue(structTypeGlobal, []uint32{uint32(i)}) -+ field := state.builder.CreateExtractValue(structTypeGlobal, i, "") - -- nameGlobal := llvm.ConstExtractValue(field, []uint32{1}) -+ nameGlobal := state.builder.CreateExtractValue(field, 1, "") - if nameGlobal == llvm.ConstPointerNull(nameGlobal.Type()) { - panic("compiler: no name for this struct field") - } -- fieldNameBytes := getGlobalBytes(nameGlobal.Operand(0)) -+ fieldNameBytes := getGlobalBytes(nameGlobal.Operand(0), state.builder) - fieldNameNumber := state.getStructNameNumber(fieldNameBytes) - - // See whether this struct field has an associated tag, and if so, - // store that tag in the tags sidetable. -- tagGlobal := llvm.ConstExtractValue(field, []uint32{2}) -+ tagGlobal := state.builder.CreateExtractValue(field, 2, "") - hasTag := false - tagNumber := 0 - if tagGlobal != llvm.ConstPointerNull(tagGlobal.Type()) { - hasTag = true -- tagBytes := getGlobalBytes(tagGlobal.Operand(0)) -+ tagBytes := getGlobalBytes(tagGlobal.Operand(0), state.builder) - tagNumber = state.getStructNameNumber(tagBytes) - } - - // The 'embedded' or 'anonymous' flag for this field. -- embedded := llvm.ConstExtractValue(field, []uint32{3}).ZExtValue() != 0 -+ embedded := state.builder.CreateExtractValue(field, 3, "").ZExtValue() != 0 - - // The first byte in the struct types sidetable is a flags byte with - // two bits in it. -@@ -510,7 +516,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int - - // Get the type number and add it to the buffer. - // All fields have a type, so include it directly here. -- typeNum := state.getTypeCodeNum(llvm.ConstExtractValue(field, []uint32{0})) -+ typeNum := state.getTypeCodeNum(state.builder.CreateExtractValue(field, 0, "")) - if typeNum.BitLen() > state.uintptrLen || !typeNum.IsUint64() { - // TODO: make this a regular error - panic("struct field has a type code that is too big") -diff --git a/transform/rtcalls.go b/transform/rtcalls.go -index 2f17f815..d70bc626 100644 ---- a/transform/rtcalls.go -+++ b/transform/rtcalls.go -@@ -149,7 +149,7 @@ func OptimizeReflectImplements(mod llvm.Module) { - interfaceType := interfaceTypeBitCast.Operand(0) - if strings.HasPrefix(interfaceType.Name(), "reflect/types.type:named:") { - // Get the underlying type. -- interfaceType = llvm.ConstExtractValue(interfaceType.Initializer(), []uint32{0}) -+ interfaceType = builder.CreateExtractValue(interfaceType.Initializer(), 0, "") - } - if !strings.HasPrefix(interfaceType.Name(), "reflect/types.type:interface:") { - // This is an error. The Type passed to Implements should be of -@@ -161,7 +161,7 @@ func OptimizeReflectImplements(mod llvm.Module) { - // Interface is unknown at compile time. This can't be optimized. - continue - } -- typeAssertFunction := llvm.ConstExtractValue(interfaceType.Initializer(), []uint32{4}).Operand(0) -+ typeAssertFunction := builder.CreateExtractValue(interfaceType.Initializer(), 4, "").Operand(0) - - // Replace Implements call with the type assert call. - builder.SetInsertPointBefore(call) --- -2.38.1 - diff --git a/0013-interp-change-object.llvmType-to-the-initializer-typ.patch b/0013-interp-change-object.llvmType-to-the-initializer-typ.patch deleted file mode 100644 index 6cbd134..0000000 --- a/0013-interp-change-object.llvmType-to-the-initializer-typ.patch +++ /dev/null @@ -1,79 +0,0 @@ -From 1004deaafd70d4eb94196977c20a5b1a17cded81 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 22 Sep 2022 01:06:40 +0200 -Subject: [PATCH 13/26] interp: change object.llvmType to the initializer type - -Previously it was a pointer type, which won't work with opaque pointers. -Instead, use the global initializer type instead. - -Signed-off-by: Elliott Sales de Andrade ---- - go.mod | 2 +- - go.sum | 4 ++-- - interp/interpreter.go | 2 +- - interp/memory.go | 4 ++-- - 4 files changed, 6 insertions(+), 6 deletions(-) - -diff --git a/go.mod b/go.mod -index feb4e0d6..a50f1174 100644 ---- a/go.mod -+++ b/go.mod -@@ -17,7 +17,7 @@ require ( - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 - golang.org/x/tools v0.1.11 - gopkg.in/yaml.v2 v2.4.0 -- tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 -+ tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec - ) - - require ( -diff --git a/go.sum b/go.sum -index 907364f9..4af03408 100644 ---- a/go.sum -+++ b/go.sum -@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= - gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= --tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634 h1:hihbmHkJjalV4kGshoCF03P/G4IjoXcNAbzLblXLa/M= --tinygo.org/x/go-llvm v0.0.0-20220921144624-dabbe3f30634/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -+tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec h1:FYtAFrw/YQPc644uNN65dW50FrEuVNaPBf70x23ApY4= -+tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -diff --git a/interp/interpreter.go b/interp/interpreter.go -index d029aa33..8c783a70 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -637,7 +637,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - // Create the new object. - size := operands[0].(literalValue).value.(uint64) - alloca := object{ -- llvmType: inst.llvmInst.Type(), -+ llvmType: inst.llvmInst.AllocatedType(), - globalName: r.pkgName + "$alloca", - buffer: newRawValue(uint32(size)), - size: uint32(size), -diff --git a/interp/memory.go b/interp/memory.go -index 583f9355..6a537bad 100644 ---- a/interp/memory.go -+++ b/interp/memory.go -@@ -37,7 +37,7 @@ import ( - // ability to roll back interpreting a function. - type object struct { - llvmGlobal llvm.Value -- llvmType llvm.Type // must match llvmGlobal.Type() if both are set, may be unset if llvmGlobal is set -+ llvmType llvm.Type // must match llvmGlobal.GlobalValueType() if both are set, may be unset if llvmGlobal is set - llvmLayoutType llvm.Type // LLVM type based on runtime.alloc layout parameter, if available - globalName string // name, if not yet created (not guaranteed to be the final name) - buffer value // buffer with value as given by interp, nil if external -@@ -594,7 +594,7 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val - var globalType llvm.Type - if !obj.llvmType.IsNil() { - // The exact type is known. -- globalType = obj.llvmType.ElementType() -+ globalType = obj.llvmType - } else { // !obj.llvmLayoutType.IsNil() - // The exact type isn't known, but the object layout is known. - globalType = obj.llvmLayoutType --- -2.38.1 - diff --git a/0014-all-remove-pointer-ElementType-calls.patch b/0014-all-remove-pointer-ElementType-calls.patch deleted file mode 100644 index 146b0ab..0000000 --- a/0014-all-remove-pointer-ElementType-calls.patch +++ /dev/null @@ -1,586 +0,0 @@ -From 0cdaa0f6db40e372db24d945b557d03b97ff92e9 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 22 Sep 2022 13:33:00 +0200 -Subject: [PATCH 14/26] all: remove pointer ElementType calls - -This is needed for opaque pointers, which are enabled by default in -LLVM 15. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/build.go | 4 +-- - compiler/asserts.go | 4 +-- - compiler/calls.go | 58 ++++++++++++++------------------- - compiler/compiler.go | 15 +++++---- - compiler/func.go | 2 +- - compiler/interface.go | 4 +-- - compiler/ircheck/check.go | 5 +-- - compiler/symbol.go | 15 ++------- - interp/compiler.go | 21 ++++++++---- - interp/interp.go | 10 +++--- - interp/interpreter.go | 2 +- - interp/memory.go | 23 +++++++------ - transform/allocs.go | 2 +- - transform/gc.go | 4 +-- - transform/interface-lowering.go | 2 +- - transform/llvm.go | 2 +- - transform/wasm-abi.go | 2 +- - 17 files changed, 82 insertions(+), 93 deletions(-) - -diff --git a/builder/build.go b/builder/build.go -index 7a7dd9ac..488ee823 100644 ---- a/builder/build.go -+++ b/builder/build.go -@@ -418,7 +418,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil - return errors.New("global not found: " + globalName) - } - name := global.Name() -- newGlobal := llvm.AddGlobal(mod, global.Type().ElementType(), name+".tmp") -+ newGlobal := llvm.AddGlobal(mod, global.GlobalValueType(), name+".tmp") - global.ReplaceAllUsesWith(newGlobal) - global.EraseFromParentAsGlobal() - newGlobal.SetName(name) -@@ -1134,7 +1134,7 @@ func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) erro - - // A strin is a {ptr, len} pair. We need these types to build the - // initializer. -- initializerType := global.Type().ElementType() -+ initializerType := global.GlobalValueType() - if initializerType.TypeKind() != llvm.StructTypeKind || initializerType.StructName() == "" { - return fmt.Errorf("%s: not a string", globalName) - } -diff --git a/compiler/asserts.go b/compiler/asserts.go -index 2a5265e9..ba482494 100644 ---- a/compiler/asserts.go -+++ b/compiler/asserts.go -@@ -91,7 +91,7 @@ func (b *builder) createSliceToArrayPointerCheck(sliceLen llvm.Value, arrayLen i - - // createUnsafeSliceCheck inserts a runtime check used for unsafe.Slice. This - // function must panic if the ptr/len parameters are invalid. --func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, lenType *types.Basic) { -+func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, elementType llvm.Type, lenType *types.Basic) { - // From the documentation of unsafe.Slice: - // > At run time, if len is negative, or if ptr is nil and len is not - // > zero, a run-time panic occurs. -@@ -105,7 +105,7 @@ func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, lenType *types.Bas - - // Determine the maximum slice size, and therefore the maximum value of the - // len parameter. -- maxSize := b.maxSliceSize(ptr.Type().ElementType()) -+ maxSize := b.maxSliceSize(elementType) - maxSizeValue := llvm.ConstInt(len.Type(), maxSize, false) - - // Do the check. By using unsigned greater than for the length check, signed -diff --git a/compiler/calls.go b/compiler/calls.go -index b38d770f..b122f0c8 100644 ---- a/compiler/calls.go -+++ b/compiler/calls.go -@@ -20,7 +20,7 @@ const maxFieldsPerParam = 3 - type paramInfo struct { - llvmType llvm.Type - name string // name, possibly with suffixes for e.g. struct fields -- flags paramFlags -+ elemSize uint64 // size of pointer element type, or 0 if this isn't a pointer - } - - // paramFlags identifies parameter attributes for flags. Most importantly, it -@@ -96,13 +96,7 @@ func (c *compilerContext) expandFormalParamType(t llvm.Type, name string, goType - // failed to expand this parameter: too many fields - } - // TODO: split small arrays -- return []paramInfo{ -- { -- llvmType: t, -- name: name, -- flags: getTypeFlags(goType), -- }, -- } -+ return []paramInfo{c.getParamInfo(t, name, goType)} - } - - // expandFormalParamOffsets returns a list of offsets from the start of an -@@ -152,7 +146,6 @@ func (b *builder) expandFormalParam(v llvm.Value) []llvm.Value { - // Try to flatten a struct type to a list of types. Returns a 1-element slice - // with the passed in type if this is not possible. - func (c *compilerContext) flattenAggregateType(t llvm.Type, name string, goType types.Type) []paramInfo { -- typeFlags := getTypeFlags(goType) - switch t.TypeKind() { - case llvm.StructTypeKind: - var paramInfos []paramInfo -@@ -183,40 +176,37 @@ func (c *compilerContext) flattenAggregateType(t llvm.Type, name string, goType - } - } - subInfos := c.flattenAggregateType(subfield, name+"."+suffix, extractSubfield(goType, i)) -- for i := range subInfos { -- subInfos[i].flags |= typeFlags -- } - paramInfos = append(paramInfos, subInfos...) - } - return paramInfos - default: -- return []paramInfo{ -- { -- llvmType: t, -- name: name, -- flags: typeFlags, -- }, -- } -+ return []paramInfo{c.getParamInfo(t, name, goType)} - } - } - --// getTypeFlags returns the type flags for a given type. It will not recurse --// into sub-types (such as in structs). --func getTypeFlags(t types.Type) paramFlags { -- if t == nil { -- return 0 -+// getParamInfo collects information about a parameter. For example, if this -+// parameter is pointer-like, it will also store the element type for the -+// dereferenceable_or_null attribute. -+func (c *compilerContext) getParamInfo(t llvm.Type, name string, goType types.Type) paramInfo { -+ info := paramInfo{ -+ llvmType: t, -+ name: name, - } -- switch t.Underlying().(type) { -- case *types.Pointer: -- // Pointers in Go must either point to an object or be nil. -- return paramIsDeferenceableOrNull -- case *types.Chan, *types.Map: -- // Channels and maps are implemented as pointers pointing to some -- // object, and follow the same rules as *types.Pointer. -- return paramIsDeferenceableOrNull -- default: -- return 0 -+ if goType != nil { -+ switch underlying := goType.Underlying().(type) { -+ case *types.Pointer: -+ // Pointers in Go must either point to an object or be nil. -+ info.elemSize = c.targetData.TypeAllocSize(c.getLLVMType(underlying.Elem())) -+ case *types.Chan: -+ // Channels are implemented simply as a *runtime.channel. -+ info.elemSize = c.targetData.TypeAllocSize(c.getLLVMRuntimeType("channel")) -+ case *types.Map: -+ // Maps are similar to channels: they are implemented as a -+ // *runtime.hashmap. -+ info.elemSize = c.targetData.TypeAllocSize(c.getLLVMRuntimeType("hashmap")) -+ } - } -+ return info - } - - // extractSubfield extracts a field from a struct, or returns null if this is -diff --git a/compiler/compiler.go b/compiler/compiler.go -index 3d29628c..fc47c29c 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -862,7 +862,7 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package - if files, ok := c.embedGlobals[member.Name()]; ok { - c.createEmbedGlobal(member, global, files) - } else if !info.extern { -- global.SetInitializer(llvm.ConstNull(global.Type().ElementType())) -+ global.SetInitializer(llvm.ConstNull(global.GlobalValueType())) - global.SetVisibility(llvm.HiddenVisibility) - if info.section != "" { - global.SetSection(info.section) -@@ -1405,7 +1405,7 @@ func (b *builder) createInstruction(instr ssa.Instruction) { - b.CreateRet(b.getValue(instr.Results[0])) - } else { - // Multiple return values. Put them all in a struct. -- retVal := llvm.ConstNull(b.llvmFn.Type().ElementType().ReturnType()) -+ retVal := llvm.ConstNull(b.llvmFn.GlobalValueType().ReturnType()) - for i, result := range instr.Results { - val := b.getValue(result) - retVal = b.CreateInsertValue(retVal, val, i, "") -@@ -1444,7 +1444,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - elemsBuf := b.CreateExtractValue(elems, 0, "append.elemsBuf") - elemsPtr := b.CreateBitCast(elemsBuf, b.i8ptrType, "append.srcPtr") - elemsLen := b.CreateExtractValue(elems, 1, "append.elemsLen") -- elemType := srcBuf.Type().ElementType() -+ elemType := b.getLLVMType(argTypes[0].Underlying().(*types.Slice).Elem()) - elemSize := llvm.ConstInt(b.uintptrType, b.targetData.TypeAllocSize(elemType), false) - result := b.createRuntimeCall("sliceAppend", []llvm.Value{srcPtr, elemsPtr, srcLen, srcCap, elemsLen, elemSize}, "append.new") - newPtr := b.CreateExtractValue(result, 0, "append.newPtr") -@@ -1497,7 +1497,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - srcLen := b.CreateExtractValue(src, 1, "copy.srcLen") - dstBuf := b.CreateExtractValue(dst, 0, "copy.dstArray") - srcBuf := b.CreateExtractValue(src, 0, "copy.srcArray") -- elemType := dstBuf.Type().ElementType() -+ elemType := b.getLLVMType(argTypes[0].Underlying().(*types.Slice).Elem()) - dstBuf = b.CreateBitCast(dstBuf, b.i8ptrType, "copy.dstPtr") - srcBuf = b.CreateBitCast(srcBuf, b.i8ptrType, "copy.srcPtr") - elemSize := llvm.ConstInt(b.uintptrType, b.targetData.TypeAllocSize(elemType), false) -@@ -1637,7 +1637,8 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - b.uintptrType, - b.uintptrType, - }, false)) -- b.createUnsafeSliceCheck(ptr, len, argTypes[1].Underlying().(*types.Basic)) -+ elementType := b.getLLVMType(argTypes[0].Underlying().(*types.Pointer).Elem()) -+ b.createUnsafeSliceCheck(ptr, len, elementType, argTypes[1].Underlying().(*types.Basic)) - if len.Type().IntTypeWidth() < b.uintptrType.IntTypeWidth() { - // Too small, zero-extend len. - len = b.CreateZExt(len, b.uintptrType, "") -@@ -1712,7 +1713,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) - // Eventually we might be able to eliminate this special case - // entirely. For details, see: - // https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521 -- calleeType = llvm.FunctionType(callee.Type().ElementType().ReturnType(), nil, false) -+ calleeType = llvm.FunctionType(callee.GlobalValueType().ReturnType(), nil, false) - callee = llvm.ConstBitCast(callee, llvm.PointerType(calleeType, b.funcPtrAddrSpace)) - } - case *ssa.MakeClosure: -@@ -3095,7 +3096,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) { - } - case token.MUL: // *x, dereference pointer - valueType := b.getLLVMType(unop.X.Type().Underlying().(*types.Pointer).Elem()) -- if b.targetData.TypeAllocSize(x.Type().ElementType()) == 0 { -+ if b.targetData.TypeAllocSize(valueType) == 0 { - // zero-length data - return llvm.ConstNull(valueType), nil - } else if strings.HasSuffix(unop.X.String(), "$funcaddr") { -diff --git a/compiler/func.go b/compiler/func.go -index c6a8802d..4203fdf7 100644 ---- a/compiler/func.go -+++ b/compiler/func.go -@@ -73,7 +73,7 @@ func (c *compilerContext) getFuncType(typ *types.Signature) llvm.Type { - return c.ctx.StructType([]llvm.Type{c.i8ptrType, c.rawVoidFuncType}, false) - } - --// getRawFuncType returns a LLVM function pointer type for a given signature. -+// getRawFuncType returns a LLVM function type for a given signature. - func (c *compilerContext) getRawFuncType(typ *types.Signature) llvm.Type { - // Get the return type. - var returnType llvm.Type -diff --git a/compiler/interface.go b/compiler/interface.go -index 106c327a..2007b7d7 100644 ---- a/compiler/interface.go -+++ b/compiler/interface.go -@@ -86,7 +86,7 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value { - if _, ok := typ.Underlying().(*types.Pointer); !ok { - ptrTo = c.getTypeCode(types.NewPointer(typ)) - } -- globalValue := llvm.ConstNull(global.Type().ElementType()) -+ globalValue := llvm.ConstNull(global.GlobalValueType()) - if !references.IsNil() { - globalValue = c.builder.CreateInsertValue(globalValue, references, 0, "") - } -@@ -533,7 +533,7 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFnType - - receiverValue := b.emitPointerUnpack(wrapper.Param(0), []llvm.Type{receiverType})[0] - params := append(b.expandFormalParam(receiverValue), wrapper.Params()[1:]...) -- if llvmFn.Type().ElementType().ReturnType().TypeKind() == llvm.VoidTypeKind { -+ if llvmFnType.ReturnType().TypeKind() == llvm.VoidTypeKind { - b.CreateCall(llvmFnType, llvmFn, params, "") - b.CreateRetVoid() - } else { -diff --git a/compiler/ircheck/check.go b/compiler/ircheck/check.go -index 30c6ee17..e2b7ed51 100644 ---- a/compiler/ircheck/check.go -+++ b/compiler/ircheck/check.go -@@ -70,10 +70,7 @@ func (c *checker) checkType(t llvm.Type, checked map[llvm.Type]struct{}, special - return fmt.Errorf("failed to verify element type of array type %s: %s", t.String(), err.Error()) - } - case llvm.PointerTypeKind: -- // check underlying type -- if err := c.checkType(t.ElementType(), checked, specials); err != nil { -- return fmt.Errorf("failed to verify underlying type of pointer type %s: %s", t.String(), err.Error()) -- } -+ // Pointers can't be checked in an opaque pointer world. - case llvm.VectorTypeKind: - // check element type - if err := c.checkType(t.ElementType(), checked, specials); err != nil { -diff --git a/compiler/symbol.go b/compiler/symbol.go -index 83fe050b..01b3fc37 100644 ---- a/compiler/symbol.go -+++ b/compiler/symbol.go -@@ -83,7 +83,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) - // Add an extra parameter as the function context. This context is used in - // closures and bound methods, but should be optimized away when not used. - if !info.exported { -- paramInfos = append(paramInfos, paramInfo{llvmType: c.i8ptrType, name: "context", flags: 0}) -+ paramInfos = append(paramInfos, paramInfo{llvmType: c.i8ptrType, name: "context", elemSize: 0}) - } - - var paramTypes []llvm.Type -@@ -112,17 +112,8 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) - - dereferenceableOrNullKind := llvm.AttributeKindID("dereferenceable_or_null") - for i, info := range paramInfos { -- if info.flags¶mIsDeferenceableOrNull == 0 { -- continue -- } -- if info.llvmType.TypeKind() == llvm.PointerTypeKind { -- el := info.llvmType.ElementType() -- size := c.targetData.TypeAllocSize(el) -- if size == 0 { -- // dereferenceable_or_null(0) appears to be illegal in LLVM. -- continue -- } -- dereferenceableOrNull := c.ctx.CreateEnumAttribute(dereferenceableOrNullKind, size) -+ if info.elemSize != 0 { -+ dereferenceableOrNull := c.ctx.CreateEnumAttribute(dereferenceableOrNullKind, info.elemSize) - llvmFn.AddAttributeAtIndex(i+1, dereferenceableOrNull) - } - } -diff --git a/interp/compiler.go b/interp/compiler.go -index 20723c64..ffef69e5 100644 ---- a/interp/compiler.go -+++ b/interp/compiler.go -@@ -209,7 +209,7 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { - case llvm.Alloca: - // Alloca allocates stack space for local variables. - numElements := r.getValue(inst.llvmInst.Operand(0)).(literalValue).value.(uint32) -- elementSize := r.targetData.TypeAllocSize(inst.llvmInst.Type().ElementType()) -+ elementSize := r.targetData.TypeAllocSize(inst.llvmInst.AllocatedType()) - inst.operands = []value{ - literalValue{elementSize * uint64(numElements)}, - } -@@ -218,17 +218,17 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { - inst.name = llvmInst.Name() - ptr := llvmInst.Operand(0) - n := llvmInst.OperandsCount() -- elementType := ptr.Type().ElementType() -+ elementType := llvmInst.GEPSourceElementType() - // gep: [source ptr, dest value size, pairs of indices...] - inst.operands = []value{ - r.getValue(ptr), -- literalValue{r.targetData.TypeAllocSize(llvmInst.Type().ElementType())}, - r.getValue(llvmInst.Operand(1)), - literalValue{r.targetData.TypeAllocSize(elementType)}, - } - for i := 2; i < n; i++ { - operand := r.getValue(llvmInst.Operand(i)) -- if elementType.TypeKind() == llvm.StructTypeKind { -+ switch elementType.TypeKind() { -+ case llvm.StructTypeKind: - index := operand.(literalValue).value.(uint32) - elementOffset := r.targetData.ElementOffset(elementType, int(index)) - // Encode operands in a special way. The elementOffset -@@ -242,12 +242,15 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { - // runtime. - inst.operands = append(inst.operands, literalValue{elementOffset}, literalValue{^uint64(index)}) - elementType = elementType.StructElementTypes()[index] -- } else { -+ case llvm.ArrayTypeKind: - elementType = elementType.ElementType() - elementSize := r.targetData.TypeAllocSize(elementType) - elementSizeOperand := literalValue{elementSize} - // Add operand * elementSizeOperand bytes to the pointer. - inst.operands = append(inst.operands, operand, elementSizeOperand) -+ default: -+ // This should be unreachable. -+ panic("unknown type: " + elementType.String()) - } - } - case llvm.BitCast, llvm.IntToPtr, llvm.PtrToInt: -@@ -267,10 +270,12 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { - case llvm.StructTypeKind: - offset += r.targetData.ElementOffset(indexingType, int(index)) - indexingType = indexingType.StructElementTypes()[index] -- default: // ArrayTypeKind -+ case llvm.ArrayTypeKind: - indexingType = indexingType.ElementType() - elementSize := r.targetData.TypeAllocSize(indexingType) - offset += elementSize * uint64(index) -+ default: -+ panic("unknown type kind") // unreachable - } - } - size := r.targetData.TypeAllocSize(inst.llvmInst.Type()) -@@ -290,10 +295,12 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function { - case llvm.StructTypeKind: - offset += r.targetData.ElementOffset(indexingType, int(index)) - indexingType = indexingType.StructElementTypes()[index] -- default: // ArrayTypeKind -+ case llvm.ArrayTypeKind: - indexingType = indexingType.ElementType() - elementSize := r.targetData.TypeAllocSize(indexingType) - offset += elementSize * uint64(index) -+ default: -+ panic("unknown type kind") // unreachable - } - } - // insertvalue [agg, elt, byteOffset] -diff --git a/interp/interp.go b/interp/interp.go -index 856f08b1..7833dfe9 100644 ---- a/interp/interp.go -+++ b/interp/interp.go -@@ -156,7 +156,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error { - if obj.constant { - continue // constant buffers can't have been modified - } -- initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.Type().ElementType(), &mem) -+ initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.GlobalValueType(), &mem) - if err == errInvalidPtrToIntSize { - // This can happen when a previous interp run did not have the - // correct LLVM type for a global and made something up. In that -@@ -190,7 +190,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error { - if err != nil { - return err - } -- if checks && initializer.Type() != obj.llvmGlobal.Type().ElementType() { -+ if checks && initializer.Type() != obj.llvmGlobal.GlobalValueType() { - panic("initializer type mismatch") - } - obj.llvmGlobal.SetInitializer(initializer) -@@ -213,7 +213,7 @@ func RunFunc(fn llvm.Value, timeout time.Duration, debug bool) error { - r.pkgName = initName[:len(initName)-len(".init")] - - // Create new function with the interp result. -- newFn := llvm.AddFunction(mod, fn.Name()+".tmp", fn.Type().ElementType()) -+ newFn := llvm.AddFunction(mod, fn.Name()+".tmp", fn.GlobalValueType()) - newFn.SetLinkage(fn.Linkage()) - newFn.SetVisibility(fn.Visibility()) - entry := mod.Context().AddBasicBlock(newFn, "entry") -@@ -263,11 +263,11 @@ func RunFunc(fn llvm.Value, timeout time.Duration, debug bool) error { - if obj.constant { - continue // constant, so can't have been modified - } -- initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.Type().ElementType(), &mem) -+ initializer, err := obj.buffer.toLLVMValue(obj.llvmGlobal.GlobalValueType(), &mem) - if err != nil { - return err - } -- if checks && initializer.Type() != obj.llvmGlobal.Type().ElementType() { -+ if checks && initializer.Type() != obj.llvmGlobal.GlobalValueType() { - panic("initializer type mismatch") - } - obj.llvmGlobal.SetInitializer(initializer) -diff --git a/interp/interpreter.go b/interp/interpreter.go -index 8c783a70..c438b4b6 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -655,7 +655,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - // GetElementPtr does pointer arithmetic, changing the offset of the - // pointer into the underlying object. - var offset uint64 -- for i := 2; i < len(operands); i += 2 { -+ for i := 1; i < len(operands); i += 2 { - index := operands[i].Uint() - elementSize := operands[i+1].Uint() - if int64(elementSize) < 0 { -diff --git a/interp/memory.go b/interp/memory.go -index 6a537bad..82ab716d 100644 ---- a/interp/memory.go -+++ b/interp/memory.go -@@ -808,14 +808,17 @@ func (v rawValue) rawLLVMValue(mem *memoryView) (llvm.Value, error) { - if err != nil { - return llvm.Value{}, err - } -- elementType := field.Type().ElementType() -- if elementType.TypeKind() == llvm.StructTypeKind { -- // There are some special pointer types that should be used as a -- // ptrtoint, so that they can be used in certain optimizations. -- name := elementType.StructName() -- if name == "runtime.typecodeID" || name == "runtime.funcValueWithSignature" { -- uintptrType := ctx.IntType(int(mem.r.pointerSize) * 8) -- field = llvm.ConstPtrToInt(field, uintptrType) -+ if !field.IsAGlobalVariable().IsNil() { -+ elementType := field.GlobalValueType() -+ if elementType.TypeKind() == llvm.StructTypeKind { -+ // There are some special pointer types that should be used -+ // as a ptrtoint, so that they can be used in certain -+ // optimizations. -+ name := elementType.StructName() -+ if name == "runtime.typecodeID" || name == "runtime.funcValueWithSignature" { -+ uintptrType := ctx.IntType(int(mem.r.pointerSize) * 8) -+ field = llvm.ConstPtrToInt(field, uintptrType) -+ } - } - } - structFields = append(structFields, field) -@@ -998,7 +1001,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { - ptr := llvmValue.Operand(0) - index := llvmValue.Operand(1) - numOperands := llvmValue.OperandsCount() -- elementType := ptr.Type().ElementType() -+ elementType := llvmValue.GEPSourceElementType() - totalOffset := r.targetData.TypeAllocSize(elementType) * index.ZExtValue() - for i := 2; i < numOperands; i++ { - indexValue := llvmValue.Operand(i) -@@ -1173,7 +1176,7 @@ func (r *runner) getValue(llvmValue llvm.Value) value { - r.globals[llvmValue] = index - r.objects = append(r.objects, obj) - if !llvmValue.IsAGlobalVariable().IsNil() { -- obj.size = uint32(r.targetData.TypeAllocSize(llvmValue.Type().ElementType())) -+ obj.size = uint32(r.targetData.TypeAllocSize(llvmValue.GlobalValueType())) - if initializer := llvmValue.Initializer(); !initializer.IsNil() { - obj.buffer = r.getValue(initializer) - obj.constant = llvmValue.IsGlobalConstant() -diff --git a/transform/allocs.go b/transform/allocs.go -index af7c70b2..5be7df2d 100644 ---- a/transform/allocs.go -+++ b/transform/allocs.go -@@ -124,7 +124,7 @@ func OptimizeAllocs(mod llvm.Module, printAllocs *regexp.Regexp, logger func(tok - alloca.SetAlignment(alignment) - - // Zero the allocation inside the block where the value was originally allocated. -- zero := llvm.ConstNull(alloca.Type().ElementType()) -+ zero := llvm.ConstNull(alloca.AllocatedType()) - builder.SetInsertPointBefore(bitcast) - store := builder.CreateStore(zero, alloca) - store.SetAlignment(alignment) -diff --git a/transform/gc.go b/transform/gc.go -index 514fb1bf..e2d23987 100644 ---- a/transform/gc.go -+++ b/transform/gc.go -@@ -18,7 +18,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - stackChainStart := mod.NamedGlobal("runtime.stackChainStart") - if !stackChainStart.IsNil() { - stackChainStart.SetLinkage(llvm.InternalLinkage) -- stackChainStart.SetInitializer(llvm.ConstNull(stackChainStart.Type().ElementType())) -+ stackChainStart.SetInitializer(llvm.ConstNull(stackChainStart.GlobalValueType())) - stackChainStart.SetGlobalConstant(true) - } - return false -@@ -96,7 +96,7 @@ func MakeGCStackSlots(mod llvm.Module) bool { - return false - } - stackChainStart.SetLinkage(llvm.InternalLinkage) -- stackChainStartType := stackChainStart.Type().ElementType() -+ stackChainStartType := stackChainStart.GlobalValueType() - stackChainStart.SetInitializer(llvm.ConstNull(stackChainStartType)) - - // Iterate until runtime.trackPointer has no uses left. -diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go -index f28443dc..9e2ffa90 100644 ---- a/transform/interface-lowering.go -+++ b/transform/interface-lowering.go -@@ -423,7 +423,7 @@ func (p *lowerInterfacesPass) defineInterfaceImplementsFunc(fn llvm.Value, itf * - func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *interfaceInfo, signature *signatureInfo) { - context := fn.LastParam() - actualType := llvm.PrevParam(context) -- returnType := fn.Type().ElementType().ReturnType() -+ returnType := fn.GlobalValueType().ReturnType() - context.SetName("context") - actualType.SetName("actualType") - fn.SetLinkage(llvm.InternalLinkage) -diff --git a/transform/llvm.go b/transform/llvm.go -index 17968f8a..7042b32d 100644 ---- a/transform/llvm.go -+++ b/transform/llvm.go -@@ -66,7 +66,7 @@ func getGlobalBytes(global llvm.Value, builder llvm.Builder) []byte { - // function used for creating reflection sidetables, for example. - func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) llvm.Value { - oldGlobal := mod.NamedGlobal(name) -- globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.Type().ElementType()) -+ globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.GlobalValueType()) - gep := llvm.ConstGEP(globalType, global, []llvm.Value{ - llvm.ConstInt(mod.Context().Int32Type(), 0, false), - llvm.ConstInt(mod.Context().Int32Type(), 0, false), -diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go -index 064e38f4..83a16d85 100644 ---- a/transform/wasm-abi.go -+++ b/transform/wasm-abi.go -@@ -50,7 +50,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { - paramTypes := []llvm.Type{} - - // Check return type for 64-bit integer. -- fnType := fn.Type().ElementType() -+ fnType := fn.GlobalValueType() - returnType := fnType.ReturnType() - if returnType == int64Type { - hasInt64 = true --- -2.38.1 - diff --git a/0015-transform-fix-memory-corruption-issues.patch b/0015-transform-fix-memory-corruption-issues.patch deleted file mode 100644 index 10ea146..0000000 --- a/0015-transform-fix-memory-corruption-issues.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 6bf7aa1623b6d7d9a269df876453af22b1c54c2d Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Wed, 12 Oct 2022 21:46:50 +0200 -Subject: [PATCH 15/26] transform: fix memory corruption issues - -There was a bug in the wasm ABI lowering pass (found using -AddressSanitizer on LLVM 15) that resulted in a rather subtle memory -corruption. This commit fixes this issues. - -Signed-off-by: Elliott Sales de Andrade ---- - transform/wasm-abi.go | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - -diff --git a/transform/wasm-abi.go b/transform/wasm-abi.go -index 83a16d85..08122a3e 100644 ---- a/transform/wasm-abi.go -+++ b/transform/wasm-abi.go -@@ -88,8 +88,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error { - // Update all users to call the external function. - // The old $i64wrapper function could be removed, but it may as well - // be left in place. -- for use := fn.FirstUse(); !use.IsNil(); use = use.NextUse() { -- call := use.User() -+ for _, call := range getUses(fn) { - entryBlockBuilder.SetInsertPointBefore(call.InstructionParent().Parent().EntryBasicBlock().FirstInstruction()) - builder.SetInsertPointBefore(call) - callParams := []llvm.Value{} --- -2.38.1 - diff --git a/0016-riscv-add-target-abi-metadata-flag.patch b/0016-riscv-add-target-abi-metadata-flag.patch deleted file mode 100644 index abc5083..0000000 --- a/0016-riscv-add-target-abi-metadata-flag.patch +++ /dev/null @@ -1,193 +0,0 @@ -From 003963ddc796960ce498361409a9d121366b1c42 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Wed, 12 Oct 2022 22:05:38 +0000 -Subject: [PATCH 16/26] riscv: add "target-abi" metadata flag - -This flag is necessary in LLVM 15 because it appears that LLVM 15 has -changed the default target ABI from lp64 to lp64d. This results in a -linker failure. Setting the "target-abi" forces the RISC-V backend to -use the intended target ABI. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/build.go | 1 + - builder/library.go | 7 +++++-- - compileopts/config.go | 13 +++++++++++++ - compileopts/target.go | 1 + - compiler/compiler.go | 13 +++++++++++++ - compiler/compiler_test.go | 1 + - targets/riscv32.json | 4 ++-- - targets/riscv64.json | 4 ++-- - 8 files changed, 38 insertions(+), 6 deletions(-) - -diff --git a/builder/build.go b/builder/build.go -index 488ee823..4818185f 100644 ---- a/builder/build.go -+++ b/builder/build.go -@@ -170,6 +170,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil - Triple: config.Triple(), - CPU: config.CPU(), - Features: config.Features(), -+ ABI: config.ABI(), - GOOS: config.GOOS(), - GOARCH: config.GOARCH(), - CodeModel: config.CodeModel(), -diff --git a/builder/library.go b/builder/library.go -index 385f1610..87822d15 100644 ---- a/builder/library.go -+++ b/builder/library.go -@@ -155,6 +155,9 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ - args = append(args, "-mcpu="+cpu) - } - } -+ if config.ABI() != "" { -+ args = append(args, "-mabi="+config.ABI()) -+ } - if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { - if strings.Split(target, "-")[2] == "linux" { - args = append(args, "-fno-unwind-tables", "-fno-asynchronous-unwind-tables") -@@ -170,10 +173,10 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ - args = append(args, "-mdouble=64") - } - if strings.HasPrefix(target, "riscv32-") { -- args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128") -+ args = append(args, "-march=rv32imac", "-fforce-enable-int128") - } - if strings.HasPrefix(target, "riscv64-") { -- args = append(args, "-march=rv64gc", "-mabi=lp64") -+ args = append(args, "-march=rv64gc") - } - if strings.HasPrefix(target, "xtensa") { - // Hack to work around an issue in the Xtensa port: -diff --git a/compileopts/config.go b/compileopts/config.go -index cd49283d..80ea8cff 100644 ---- a/compileopts/config.go -+++ b/compileopts/config.go -@@ -47,6 +47,12 @@ func (c *Config) Features() string { - return c.Target.Features + "," + c.Options.LLVMFeatures - } - -+// ABI returns the -mabi= flag for this target (like -mabi=lp64). A zero-length -+// string is returned if the target doesn't specify an ABI. -+func (c *Config) ABI() string { -+ return c.Target.ABI -+} -+ - // GOOS returns the GOOS of the target. This might not always be the actual OS: - // for example, bare-metal targets will usually pretend to be linux to get the - // standard library to compile. -@@ -230,6 +236,9 @@ func (c *Config) LibcPath(name string) (path string, precompiled bool) { - if c.CPU() != "" { - archname += "-" + c.CPU() - } -+ if c.ABI() != "" { -+ archname += "-" + c.ABI() -+ } - - // Try to load a precompiled library. - precompiledDir := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", archname, name) -@@ -335,6 +344,10 @@ func (c *Config) CFlags() []string { - cflags = append(cflags, "-mcpu="+c.Target.CPU) - } - } -+ // Set the -mabi flag, if needed. -+ if c.ABI() != "" { -+ cflags = append(cflags, "-mabi="+c.ABI()) -+ } - return cflags - } - -diff --git a/compileopts/target.go b/compileopts/target.go -index 865b8afe..c26c870e 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -26,6 +26,7 @@ type TargetSpec struct { - Inherits []string `json:"inherits"` - Triple string `json:"llvm-target"` - CPU string `json:"cpu"` -+ ABI string `json:"target-abi"` // rougly equivalent to -mabi= flag - Features string `json:"features"` - GOOS string `json:"goos"` - GOARCH string `json:"goarch"` -diff --git a/compiler/compiler.go b/compiler/compiler.go -index fc47c29c..8b6e8661 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -41,6 +41,7 @@ type Config struct { - Triple string - CPU string - Features string -+ ABI string - GOOS string - GOARCH string - CodeModel string -@@ -321,6 +322,18 @@ func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, - c.dibuilder.Destroy() - } - -+ // Add the "target-abi" flag, which is necessary on RISC-V otherwise it will -+ // pick one that doesn't match the -mabi Clang flag. -+ if c.ABI != "" { -+ c.mod.AddNamedMetadataOperand("llvm.module.flags", -+ c.ctx.MDNode([]llvm.Metadata{ -+ llvm.ConstInt(c.ctx.Int32Type(), 1, false).ConstantAsMetadata(), // Error on mismatch -+ c.ctx.MDString("target-abi"), -+ c.ctx.MDString(c.ABI), -+ }), -+ ) -+ } -+ - return c.mod, c.diagnostics - } - -diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index 2ed26921..a5cd9c6b 100644 ---- a/compiler/compiler_test.go -+++ b/compiler/compiler_test.go -@@ -73,6 +73,7 @@ func TestCompiler(t *testing.T) { - compilerConfig := &Config{ - Triple: config.Triple(), - Features: config.Features(), -+ ABI: config.ABI(), - GOOS: config.GOOS(), - GOARCH: config.GOARCH(), - CodeModel: config.CodeModel(), -diff --git a/targets/riscv32.json b/targets/riscv32.json -index c3c8dff5..a2878089 100644 ---- a/targets/riscv32.json -+++ b/targets/riscv32.json -@@ -1,12 +1,12 @@ - { - "inherits": ["riscv"], - "llvm-target": "riscv32-unknown-none", -+ "target-abi": "ilp32", - "build-tags": ["tinygo.riscv32"], - "scheduler": "tasks", - "default-stack-size": 2048, - "cflags": [ -- "-march=rv32imac", -- "-mabi=ilp32" -+ "-march=rv32imac" - ], - "ldflags": [ - "-melf32lriscv" -diff --git a/targets/riscv64.json b/targets/riscv64.json -index c2378e97..fc45c91c 100644 ---- a/targets/riscv64.json -+++ b/targets/riscv64.json -@@ -1,10 +1,10 @@ - { - "inherits": ["riscv"], - "llvm-target": "riscv64-unknown-none", -+ "target-abi": "lp64", - "build-tags": ["tinygo.riscv64"], - "cflags": [ -- "-march=rv64gc", -- "-mabi=lp64" -+ "-march=rv64gc" - ], - "ldflags": [ - "-melf64lriscv" --- -2.38.1 - diff --git a/0017-interp-add-support-for-constant-icmp-instructions.patch b/0017-interp-add-support-for-constant-icmp-instructions.patch deleted file mode 100644 index d3d7158..0000000 --- a/0017-interp-add-support-for-constant-icmp-instructions.patch +++ /dev/null @@ -1,195 +0,0 @@ -From 76f42a3fac44ac6d07c53b10ddadb683ca019684 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Tue, 18 Oct 2022 23:16:36 +0000 -Subject: [PATCH 17/26] interp: add support for constant icmp instructions - -These instructions sometimes pop up in LLVM 15, but they never occured -in LLVM 14. Implementing them is relatively straightforward: simply -generalize the code that already exists for llvm.ICmp interpreting. - -Signed-off-by: Elliott Sales de Andrade ---- - interp/interpreter.go | 84 +++++++++++++++++--------------- - interp/memory.go | 11 +++++ - interp/testdata/consteval.ll | 15 ++++++ - interp/testdata/consteval.out.ll | 1 + - 4 files changed, 73 insertions(+), 38 deletions(-) - -diff --git a/interp/interpreter.go b/interp/interpreter.go -index c438b4b6..83fd2cd9 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -723,46 +723,9 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - locals[inst.localIndex] = newagg - case llvm.ICmp: - predicate := llvm.IntPredicate(operands[2].(literalValue).value.(uint8)) -- var result bool - lhs := operands[0] - rhs := operands[1] -- switch predicate { -- case llvm.IntEQ, llvm.IntNE: -- lhsPointer, lhsErr := lhs.asPointer(r) -- rhsPointer, rhsErr := rhs.asPointer(r) -- if (lhsErr == nil) != (rhsErr == nil) { -- // Fast path: only one is a pointer, so they can't be equal. -- result = false -- } else if lhsErr == nil { -- // Both must be nil, so both are pointers. -- // Compare them directly. -- result = lhsPointer.equal(rhsPointer) -- } else { -- // Fall back to generic comparison. -- result = lhs.asRawValue(r).equal(rhs.asRawValue(r)) -- } -- if predicate == llvm.IntNE { -- result = !result -- } -- case llvm.IntUGT: -- result = lhs.Uint() > rhs.Uint() -- case llvm.IntUGE: -- result = lhs.Uint() >= rhs.Uint() -- case llvm.IntULT: -- result = lhs.Uint() < rhs.Uint() -- case llvm.IntULE: -- result = lhs.Uint() <= rhs.Uint() -- case llvm.IntSGT: -- result = lhs.Int() > rhs.Int() -- case llvm.IntSGE: -- result = lhs.Int() >= rhs.Int() -- case llvm.IntSLT: -- result = lhs.Int() < rhs.Int() -- case llvm.IntSLE: -- result = lhs.Int() <= rhs.Int() -- default: -- return nil, mem, r.errorAt(inst, errors.New("interp: unsupported icmp")) -- } -+ result := r.interpretICmp(lhs, rhs, predicate) - if result { - locals[inst.localIndex] = literalValue{uint8(1)} - } else { -@@ -948,6 +911,51 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - return nil, mem, r.errorAt(bb.instructions[len(bb.instructions)-1], errors.New("interp: reached end of basic block without terminator")) - } - -+// Interpret an icmp instruction. Doesn't have side effects, only returns the -+// output of the comparison. -+func (r *runner) interpretICmp(lhs, rhs value, predicate llvm.IntPredicate) bool { -+ switch predicate { -+ case llvm.IntEQ, llvm.IntNE: -+ var result bool -+ lhsPointer, lhsErr := lhs.asPointer(r) -+ rhsPointer, rhsErr := rhs.asPointer(r) -+ if (lhsErr == nil) != (rhsErr == nil) { -+ // Fast path: only one is a pointer, so they can't be equal. -+ result = false -+ } else if lhsErr == nil { -+ // Both must be nil, so both are pointers. -+ // Compare them directly. -+ result = lhsPointer.equal(rhsPointer) -+ } else { -+ // Fall back to generic comparison. -+ result = lhs.asRawValue(r).equal(rhs.asRawValue(r)) -+ } -+ if predicate == llvm.IntNE { -+ result = !result -+ } -+ return result -+ case llvm.IntUGT: -+ return lhs.Uint() > rhs.Uint() -+ case llvm.IntUGE: -+ return lhs.Uint() >= rhs.Uint() -+ case llvm.IntULT: -+ return lhs.Uint() < rhs.Uint() -+ case llvm.IntULE: -+ return lhs.Uint() <= rhs.Uint() -+ case llvm.IntSGT: -+ return lhs.Int() > rhs.Int() -+ case llvm.IntSGE: -+ return lhs.Int() >= rhs.Int() -+ case llvm.IntSLT: -+ return lhs.Int() < rhs.Int() -+ case llvm.IntSLE: -+ return lhs.Int() <= rhs.Int() -+ default: -+ // _should_ be unreachable, until LLVM adds new icmp operands (unlikely) -+ panic("interp: unsupported icmp") -+ } -+} -+ - func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, mem *memoryView, indent string) *Error { - numOperands := inst.llvmInst.OperandsCount() - operands := make([]llvm.Value, numOperands) -diff --git a/interp/memory.go b/interp/memory.go -index 82ab716d..248825f6 100644 ---- a/interp/memory.go -+++ b/interp/memory.go -@@ -1031,6 +1031,17 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) { - for i := uint32(0); i < ptrSize; i++ { - v.buf[i] = ptrValue.pointer - } -+ case llvm.ICmp: -+ size := r.targetData.TypeAllocSize(llvmValue.Operand(0).Type()) -+ lhs := newRawValue(uint32(size)) -+ rhs := newRawValue(uint32(size)) -+ lhs.set(llvmValue.Operand(0), r) -+ rhs.set(llvmValue.Operand(1), r) -+ if r.interpretICmp(lhs, rhs, llvmValue.IntPredicate()) { -+ v.buf[0] = 1 // result is true -+ } else { -+ v.buf[0] = 0 // result is false -+ } - default: - llvmValue.Dump() - println() -diff --git a/interp/testdata/consteval.ll b/interp/testdata/consteval.ll -index 9afb9ff7..d0c0e3b6 100644 ---- a/interp/testdata/consteval.ll -+++ b/interp/testdata/consteval.ll -@@ -3,6 +3,7 @@ target triple = "x86_64--linux" - - @intToPtrResult = global i8 0 - @ptrToIntResult = global i8 0 -+@icmpResult = global i8 0 - @someArray = internal global {i16, i8, i8} zeroinitializer - @someArrayPointer = global i8* zeroinitializer - -@@ -15,6 +16,7 @@ define internal void @main.init() { - call void @testIntToPtr() - call void @testPtrToInt() - call void @testConstGEP() -+ call void @testICmp() - ret void - } - -@@ -48,3 +50,16 @@ define internal void @testConstGEP() { - store i8* getelementptr inbounds (i8, i8* bitcast ({i16, i8, i8}* @someArray to i8*), i32 2), i8** @someArrayPointer - ret void - } -+ -+define internal void @testICmp() { -+ br i1 icmp eq (i64 ptrtoint (i8* @ptrToIntResult to i64), i64 0), label %equal, label %unequal -+equal: -+ ; should not be reached -+ store i8 1, i8* @icmpResult -+ ret void -+unequal: -+ ; should be reached -+ store i8 2, i8* @icmpResult -+ ret void -+ ret void -+} -diff --git a/interp/testdata/consteval.out.ll b/interp/testdata/consteval.out.ll -index 5fac449e..08d74c85 100644 ---- a/interp/testdata/consteval.out.ll -+++ b/interp/testdata/consteval.out.ll -@@ -3,6 +3,7 @@ target triple = "x86_64--linux" - - @intToPtrResult = local_unnamed_addr global i8 2 - @ptrToIntResult = local_unnamed_addr global i8 2 -+@icmpResult = local_unnamed_addr global i8 2 - @someArray = internal global { i16, i8, i8 } zeroinitializer - @someArrayPointer = local_unnamed_addr global i8* getelementptr inbounds ({ i16, i8, i8 }, { i16, i8, i8 }* @someArray, i64 0, i32 1) - --- -2.38.1 - diff --git a/0018-ci-add-support-for-LLVM-15.patch b/0018-ci-add-support-for-LLVM-15.patch deleted file mode 100644 index a947661..0000000 --- a/0018-ci-add-support-for-LLVM-15.patch +++ /dev/null @@ -1,3490 +0,0 @@ -From 6557b534a1c2195cb7f2a465f8dc36662525f764 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 22 Sep 2022 13:39:51 +0200 -Subject: [PATCH 18/26] ci: add support for LLVM 15 - -This commit switches to LLVM 15 everywhere by default, while still -keeping LLVM 14 support. - -Signed-off-by: Elliott Sales de Andrade ---- - .github/workflows/build-macos.yml | 6 +- - .github/workflows/linux.yml | 16 +- - .github/workflows/windows.yml | 4 +- - Makefile | 6 +- - builder/cc1as.cpp | 21 +- - builder/cc1as.h | 7 + - builder/musl.go | 10 +- - cgo/libclang_config_llvm14.go | 4 +- - cgo/libclang_config_llvm15.go | 16 ++ - compiler/func.go | 15 +- - compiler/intrinsics.go | 11 +- - compiler/llvmutil/llvm.go | 33 ++- - compiler/symbol.go | 11 +- - compiler/testdata/basic.go | 12 +- - compiler/testdata/basic.ll | 69 +++-- - compiler/testdata/channel.ll | 110 +++----- - compiler/testdata/defer-cortex-m-qemu.ll | 267 +++++++++--------- - compiler/testdata/float.ll | 22 +- - compiler/testdata/func.ll | 23 +- - compiler/testdata/gc.ll | 176 ++++++------ - .../testdata/goroutine-cortex-m-qemu-tasks.ll | 189 ++++++------- - compiler/testdata/goroutine-wasm-asyncify.ll | 206 ++++++-------- - compiler/testdata/interface.ll | 83 +++--- - compiler/testdata/pointer.ll | 68 +++-- - compiler/testdata/pragma.ll | 18 +- - compiler/testdata/slice.ll | 264 ++++++++--------- - compiler/testdata/string.ll | 50 ++-- - go.mod | 2 +- - go.sum | 4 +- - interp/interpreter.go | 16 +- - src/runtime/runtime.go | 6 +- - targets/esp32c3.json | 2 +- - targets/fe310.json | 2 +- - targets/k210.json | 2 +- - targets/riscv-qemu.json | 2 +- - transform/interface-lowering.go | 4 +- - transform/interrupt.go | 3 +- - transform/llvm.go | 6 + - transform/reflect.go | 11 +- - transform/rtcalls.go | 5 +- - 40 files changed, 898 insertions(+), 884 deletions(-) - create mode 100644 cgo/libclang_config_llvm15.go - -diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml -index 2059574a..9197ea3c 100644 ---- a/.github/workflows/build-macos.yml -+++ b/.github/workflows/build-macos.yml -@@ -40,7 +40,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-source - with: -- key: llvm-source-14-macos-v1 -+ key: llvm-source-15-macos-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -54,7 +54,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-build - with: -- key: llvm-build-14-macos-v1 -+ key: llvm-build-15-macos-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -@@ -108,7 +108,7 @@ jobs: - - name: Install LLVM - shell: bash - run: | -- HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@14 -+ HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@15 - - name: Checkout - uses: actions/checkout@v2 - - name: Install Go -diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml -index 8fc52717..cf26a4f2 100644 ---- a/.github/workflows/linux.yml -+++ b/.github/workflows/linux.yml -@@ -43,7 +43,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-source - with: -- key: llvm-source-14-linux-alpine-v1 -+ key: llvm-source-15-linux-alpine-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -57,7 +57,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-build - with: -- key: llvm-build-14-linux-alpine-v1 -+ key: llvm-build-15-linux-alpine-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -@@ -185,7 +185,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-source - with: -- key: llvm-source-14-linux-asserts-v2 -+ key: llvm-source-15-linux-asserts-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -199,7 +199,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-build - with: -- key: llvm-build-14-linux-asserts-v1 -+ key: llvm-build-15-linux-asserts-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -@@ -277,7 +277,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-source - with: -- key: llvm-source-14-linux-v2 -+ key: llvm-source-15-linux-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -291,7 +291,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-build - with: -- key: llvm-build-14-linux-arm-v1 -+ key: llvm-build-15-linux-arm-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -@@ -377,7 +377,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-source - with: -- key: llvm-source-14-linux-v1 -+ key: llvm-source-15-linux-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -391,7 +391,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-build - with: -- key: llvm-build-14-linux-arm64-v1 -+ key: llvm-build-15-linux-arm64-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml -index 76c010cf..2ea1dc8c 100644 ---- a/.github/workflows/windows.yml -+++ b/.github/workflows/windows.yml -@@ -35,7 +35,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-source - with: -- key: llvm-source-14-windows-v2 -+ key: llvm-source-15-windows-v1 - path: | - llvm-project/clang/lib/Headers - llvm-project/clang/include -@@ -49,7 +49,7 @@ jobs: - uses: actions/cache@v3 - id: cache-llvm-build - with: -- key: llvm-build-14-windows-v2 -+ key: llvm-build-15-windows-v1 - path: llvm-build - - name: Build LLVM - if: steps.cache-llvm-build.outputs.cache-hit != 'true' -diff --git a/Makefile b/Makefile -index 1ef11d29..89927961 100644 ---- a/Makefile -+++ b/Makefile -@@ -107,7 +107,7 @@ endif - - .PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp - --LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsmanifest -+LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest - - ifeq ($(OS),Windows_NT) - EXE = .exe -@@ -142,7 +142,7 @@ else - endif - - # Libraries that should be linked in for the statically linked Clang. --CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions -+CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions - CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++ - - # Libraries that should be linked in for the statically linked LLD. -@@ -230,7 +230,7 @@ gen-device-rp: build/gen-device-svd - - # Get LLVM sources. - $(LLVM_PROJECTDIR)/llvm: -- git clone -b xtensa_release_14.0.0-patched --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) -+ git clone -b xtensa_release_15.x --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR) - llvm-source: $(LLVM_PROJECTDIR)/llvm - - # Configure LLVM. -diff --git a/builder/cc1as.cpp b/builder/cc1as.cpp -index 11500121..cd3229ad 100644 ---- a/builder/cc1as.cpp -+++ b/builder/cc1as.cpp -@@ -101,6 +101,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, - - // Target Options - Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); -+ if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple)) -+ Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue()); -+ - Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu)); - Opts.Features = Args.getAllArgValues(OPT_target_feature); - -@@ -203,6 +206,14 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, - .Default(0); - } - -+ if (auto *A = Args.getLastArg(OPT_femit_dwarf_unwind_EQ)) { -+ Opts.EmitDwarfUnwind = -+ llvm::StringSwitch(A->getValue()) -+ .Case("always", EmitDwarfUnwindType::Always) -+ .Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind) -+ .Case("default", EmitDwarfUnwindType::Default); -+ } -+ - return Success; - } - -@@ -253,6 +264,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, - assert(MRI && "Unable to create target register info!"); - - MCTargetOptions MCOptions; -+ MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; -+ - std::unique_ptr MAI( - TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions)); - assert(MAI && "Unable to create target asm info!"); -@@ -299,6 +312,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, - // MCObjectFileInfo needs a MCContext reference in order to initialize itself. - std::unique_ptr MOFI( - TheTarget->createMCObjectFileInfo(Ctx, PIC)); -+ if (Opts.DarwinTargetVariantTriple) -+ MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple); - Ctx.setObjectFileInfo(MOFI.get()); - - if (Opts.SaveTemporaryLabels) -@@ -347,7 +362,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, - - std::unique_ptr CE; - if (Opts.ShowEncoding) -- CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); -+ CE.reset(TheTarget->createMCCodeEmitter(*MCII, Ctx)); - std::unique_ptr MAB( - TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); - -@@ -367,7 +382,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, - } - - std::unique_ptr CE( -- TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); -+ TheTarget->createMCCodeEmitter(*MCII, Ctx)); - std::unique_ptr MAB( - TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); - assert(MAB && "Unable to create asm backend!"); -@@ -389,7 +404,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, - if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) { - MCSection *AsmLabel = Ctx.getMachOSection( - "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); -- Str.get()->SwitchSection(AsmLabel); -+ Str.get()->switchSection(AsmLabel); - Str.get()->emitZeros(1); - } - -diff --git a/builder/cc1as.h b/builder/cc1as.h -index 538e9a26..150d6f14 100644 ---- a/builder/cc1as.h -+++ b/builder/cc1as.h -@@ -85,6 +85,9 @@ struct AssemblerInvocation { - unsigned IncrementalLinkerCompatible : 1; - unsigned EmbedBitcode : 1; - -+ /// Whether to emit DWARF unwind info. -+ EmitDwarfUnwindType EmitDwarfUnwind; -+ - /// The name of the relocation model to use. - std::string RelocationModel; - -@@ -92,6 +95,9 @@ struct AssemblerInvocation { - /// otherwise. - std::string TargetABI; - -+ /// Darwin target variant triple, the variant of the deployment target -+ /// for which the code is being compiled. -+ llvm::Optional DarwinTargetVariantTriple; - /// @} - - public: -@@ -112,6 +118,7 @@ public: - Dwarf64 = 0; - DwarfVersion = 0; - EmbedBitcode = 0; -+ EmitDwarfUnwind = EmitDwarfUnwindType::Default; - } - - static bool CreateFromArgs(AssemblerInvocation &Res, -diff --git a/builder/musl.go b/builder/musl.go -index a1967e37..c266898d 100644 ---- a/builder/musl.go -+++ b/builder/musl.go -@@ -6,10 +6,12 @@ import ( - "os" - "path/filepath" - "regexp" -+ "strconv" - "strings" - - "github.com/tinygo-org/tinygo/compileopts" - "github.com/tinygo-org/tinygo/goenv" -+ "tinygo.org/x/go-llvm" - ) - - var Musl = Library{ -@@ -77,7 +79,7 @@ var Musl = Library{ - cflags: func(target, headerPath string) []string { - arch := compileopts.MuslArchitecture(target) - muslDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl") -- return []string{ -+ cflags := []string{ - "-std=c99", // same as in musl - "-D_XOPEN_SOURCE=700", // same as in musl - // Musl triggers some warnings and we don't want to show any -@@ -103,6 +105,12 @@ var Musl = Library{ - "-I" + muslDir + "/include", - "-fno-stack-protector", - } -+ llvmMajor, _ := strconv.Atoi(strings.SplitN(llvm.Version, ".", 2)[0]) -+ if llvmMajor >= 15 { -+ // This flag was added in Clang 15. It is not present in LLVM 14. -+ cflags = append(cflags, "-Wno-deprecated-non-prototype") -+ } -+ return cflags - }, - sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl/src") }, - librarySources: func(target string) []string { -diff --git a/cgo/libclang_config_llvm14.go b/cgo/libclang_config_llvm14.go -index 0553bd50..953ce8e2 100644 ---- a/cgo/libclang_config_llvm14.go -+++ b/cgo/libclang_config_llvm14.go -@@ -1,5 +1,5 @@ --//go:build !byollvm --// +build !byollvm -+//go:build !byollvm && llvm14 -+// +build !byollvm,llvm14 - - package cgo - -diff --git a/cgo/libclang_config_llvm15.go b/cgo/libclang_config_llvm15.go -new file mode 100644 -index 00000000..e918a473 ---- /dev/null -+++ b/cgo/libclang_config_llvm15.go -@@ -0,0 +1,16 @@ -+//go:build !byollvm && !llvm14 -+// +build !byollvm,!llvm14 -+ -+package cgo -+ -+/* -+#cgo linux CFLAGS: -I/usr/lib/llvm-15/include -+#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@15/include -+#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@15/include -+#cgo freebsd CFLAGS: -I/usr/local/llvm15/include -+#cgo linux LDFLAGS: -L/usr/lib/llvm-15/lib -lclang -+#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -lclang -lffi -+#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -lclang -lffi -+#cgo freebsd LDFLAGS: -L/usr/local/llvm15/lib -lclang -+*/ -+import "C" -diff --git a/compiler/func.go b/compiler/func.go -index 4203fdf7..404c7316 100644 ---- a/compiler/func.go -+++ b/compiler/func.go -@@ -57,14 +57,15 @@ func (b *builder) extractFuncContext(funcValue llvm.Value) llvm.Value { - // value. This may be an expensive operation. - func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcType llvm.Type, funcPtr, context llvm.Value) { - context = b.CreateExtractValue(funcValue, 0, "") -- bitcast := b.CreateExtractValue(funcValue, 1, "") -- if !bitcast.IsAConstantExpr().IsNil() && bitcast.Opcode() == llvm.BitCast { -- funcPtr = bitcast.Operand(0) -- return -+ funcPtr = b.CreateExtractValue(funcValue, 1, "") -+ if !funcPtr.IsAConstantExpr().IsNil() && funcPtr.Opcode() == llvm.BitCast { -+ funcPtr = funcPtr.Operand(0) // needed for LLVM 14 (no opaque pointers) -+ } -+ if sig != nil { -+ funcType = b.getRawFuncType(sig) -+ llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace) -+ funcPtr = b.CreateBitCast(funcPtr, llvmSig, "") - } -- funcType = b.getRawFuncType(sig) -- llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace) -- funcPtr = b.CreateBitCast(bitcast, llvmSig, "") - return - } - -diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go -index 9fedfbd6..a511e518 100644 ---- a/compiler/intrinsics.go -+++ b/compiler/intrinsics.go -@@ -7,6 +7,7 @@ import ( - "strconv" - "strings" - -+ "github.com/tinygo-org/tinygo/compiler/llvmutil" - "tinygo.org/x/go-llvm" - ) - -@@ -44,7 +45,10 @@ func (b *builder) defineIntrinsicFunction() { - // and will otherwise be lowered to regular libc memcpy/memmove calls. - func (b *builder) createMemoryCopyImpl() { - b.createFunctionStart(true) -- fnName := "llvm." + b.fn.Name() + ".p0i8.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) -+ fnName := "llvm." + b.fn.Name() + ".p0.p0.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) -+ if llvmutil.Major() < 15 { // compatibility with LLVM 14 -+ fnName = "llvm." + b.fn.Name() + ".p0i8.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) -+ } - llvmFn := b.mod.NamedFunction(fnName) - if llvmFn.IsNil() { - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.i8ptrType, b.i8ptrType, b.uintptrType, b.ctx.Int1Type()}, false) -@@ -64,7 +68,10 @@ func (b *builder) createMemoryCopyImpl() { - // regular libc memset calls if they aren't optimized out in a different way. - func (b *builder) createMemoryZeroImpl() { - b.createFunctionStart(true) -- fnName := "llvm.memset.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) -+ fnName := "llvm.memset.p0.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) -+ if llvmutil.Major() < 15 { // compatibility with LLVM 14 -+ fnName = "llvm.memset.p0i8.i" + strconv.Itoa(b.uintptrType.IntTypeWidth()) -+ } - llvmFn := b.mod.NamedFunction(fnName) - if llvmFn.IsNil() { - fnType := llvm.FunctionType(b.ctx.VoidType(), []llvm.Type{b.i8ptrType, b.ctx.Int8Type(), b.uintptrType, b.ctx.Int1Type()}, false) -diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go -index e73b68da..ca277765 100644 ---- a/compiler/llvmutil/llvm.go -+++ b/compiler/llvmutil/llvm.go -@@ -7,7 +7,22 @@ - // places would be a big risk if only one of them is updated. - package llvmutil - --import "tinygo.org/x/go-llvm" -+import ( -+ "strconv" -+ "strings" -+ -+ "tinygo.org/x/go-llvm" -+) -+ -+// Major returns the LLVM major version. -+func Major() int { -+ llvmMajor, err := strconv.Atoi(strings.SplitN(llvm.Version, ".", 2)[0]) -+ if err != nil { -+ // sanity check, should be unreachable -+ panic("could not parse LLVM version: " + err.Error()) -+ } -+ return llvmMajor -+} - - // CreateEntryBlockAlloca creates a new alloca in the entry block, even though - // the IR builder is located elsewhere. It assumes that the insert point is -@@ -78,12 +93,16 @@ func EmitLifetimeEnd(builder llvm.Builder, mod llvm.Module, ptr, size llvm.Value - // getLifetimeStartFunc returns the llvm.lifetime.start intrinsic and creates it - // first if it doesn't exist yet. - func getLifetimeStartFunc(mod llvm.Module) (llvm.Type, llvm.Value) { -- fn := mod.NamedFunction("llvm.lifetime.start.p0i8") -+ fnName := "llvm.lifetime.start.p0" -+ if Major() < 15 { // compatibility with LLVM 14 -+ fnName = "llvm.lifetime.start.p0i8" -+ } -+ fn := mod.NamedFunction(fnName) - ctx := mod.Context() - i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) - fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) - if fn.IsNil() { -- fn = llvm.AddFunction(mod, "llvm.lifetime.start.p0i8", fnType) -+ fn = llvm.AddFunction(mod, fnName, fnType) - } - return fnType, fn - } -@@ -91,12 +110,16 @@ func getLifetimeStartFunc(mod llvm.Module) (llvm.Type, llvm.Value) { - // getLifetimeEndFunc returns the llvm.lifetime.end intrinsic and creates it - // first if it doesn't exist yet. - func getLifetimeEndFunc(mod llvm.Module) (llvm.Type, llvm.Value) { -- fn := mod.NamedFunction("llvm.lifetime.end.p0i8") -+ fnName := "llvm.lifetime.end.p0" -+ if Major() < 15 { -+ fnName = "llvm.lifetime.end.p0i8" -+ } -+ fn := mod.NamedFunction(fnName) - ctx := mod.Context() - i8ptrType := llvm.PointerType(ctx.Int8Type(), 0) - fnType := llvm.FunctionType(ctx.VoidType(), []llvm.Type{ctx.Int64Type(), i8ptrType}, false) - if fn.IsNil() { -- fn = llvm.AddFunction(mod, "llvm.lifetime.end.p0i8", fnType) -+ fn = llvm.AddFunction(mod, fnName, fnType) - } - return fnType, fn - } -diff --git a/compiler/symbol.go b/compiler/symbol.go -index 01b3fc37..61ca4473 100644 ---- a/compiler/symbol.go -+++ b/compiler/symbol.go -@@ -10,6 +10,7 @@ import ( - "strconv" - "strings" - -+ "github.com/tinygo-org/tinygo/compiler/llvmutil" - "github.com/tinygo-org/tinygo/loader" - "golang.org/x/tools/go/ssa" - "tinygo.org/x/go-llvm" -@@ -353,7 +354,15 @@ func (c *compilerContext) addStandardDefinedAttributes(llvmFn llvm.Value) { - llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nounwind"), 0)) - if strings.Split(c.Triple, "-")[0] == "x86_64" { - // Required by the ABI. -- llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 0)) -+ if llvmutil.Major() < 15 { -+ // Needed for LLVM 14 support. -+ llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 0)) -+ } else { -+ // The uwtable has two possible values: sync (1) or async (2). We -+ // use sync because we currently don't use async unwind tables. -+ // For details, see: https://llvm.org/docs/LangRef.html#function-attributes -+ llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 1)) -+ } - } - } - -diff --git a/compiler/testdata/basic.go b/compiler/testdata/basic.go -index e9fcbad3..d2b4a96d 100644 ---- a/compiler/testdata/basic.go -+++ b/compiler/testdata/basic.go -@@ -75,14 +75,18 @@ func complexMul(x, y complex64) complex64 { - // A type 'kv' also exists in function foo. Test that these two types don't - // conflict with each other. - type kv struct { -- v float32 -+ v float32 -+ x, y, z int - } - --func foo(a *kv) { -+var kvGlobal kv -+ -+func foo() { - // Define a new 'kv' type. - type kv struct { -- v byte -+ v byte -+ x, y, z int - } - // Use this type. -- func(b *kv) {}(nil) -+ func(b kv) {}(kv{}) - } -diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll -index 4d88f66f..6ef0dc92 100644 ---- a/compiler/testdata/basic.ll -+++ b/compiler/testdata/basic.ll -@@ -3,35 +3,37 @@ source_filename = "basic.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --%main.kv = type { float } --%main.kv.0 = type { i8 } -+%main.kv = type { float, i32, i32, i32 } -+%main.kv.0 = type { i8, i32, i32, i32 } - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+@main.kvGlobal = hidden global %main.kv zeroinitializer, align 4 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 -+ -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden i32 @main.addInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.addInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { - entry: - %0 = add i32 %x, %y - ret i32 %0 - } - - ; Function Attrs: nounwind --define hidden i1 @main.equalInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.equalInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp eq i32 %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden i32 @main.divInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.divInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp eq i32 %y, 0 - br i1 %0, label %divbyzero.throw, label %divbyzero.next -@@ -45,14 +47,14 @@ divbyzero.next: ; preds = %entry - ret i32 %5 - - divbyzero.throw: ; preds = %entry -- call void @runtime.divideByZeroPanic(i8* undef) #2 -+ call void @runtime.divideByZeroPanic(ptr undef) #2 - unreachable - } - --declare void @runtime.divideByZeroPanic(i8*) #0 -+declare void @runtime.divideByZeroPanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden i32 @main.divUint(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.divUint(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp eq i32 %y, 0 - br i1 %0, label %divbyzero.throw, label %divbyzero.next -@@ -62,12 +64,12 @@ divbyzero.next: ; preds = %entry - ret i32 %1 - - divbyzero.throw: ; preds = %entry -- call void @runtime.divideByZeroPanic(i8* undef) #2 -+ call void @runtime.divideByZeroPanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden i32 @main.remInt(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.remInt(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp eq i32 %y, 0 - br i1 %0, label %divbyzero.throw, label %divbyzero.next -@@ -81,12 +83,12 @@ divbyzero.next: ; preds = %entry - ret i32 %5 - - divbyzero.throw: ; preds = %entry -- call void @runtime.divideByZeroPanic(i8* undef) #2 -+ call void @runtime.divideByZeroPanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden i32 @main.remUint(i32 %x, i32 %y, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.remUint(i32 %x, i32 %y, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp eq i32 %y, 0 - br i1 %0, label %divbyzero.throw, label %divbyzero.next -@@ -96,66 +98,66 @@ divbyzero.next: ; preds = %entry - ret i32 %1 - - divbyzero.throw: ; preds = %entry -- call void @runtime.divideByZeroPanic(i8* undef) #2 -+ call void @runtime.divideByZeroPanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden i1 @main.floatEQ(float %x, float %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.floatEQ(float %x, float %y, ptr %context) unnamed_addr #1 { - entry: - %0 = fcmp oeq float %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden i1 @main.floatNE(float %x, float %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.floatNE(float %x, float %y, ptr %context) unnamed_addr #1 { - entry: - %0 = fcmp une float %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden i1 @main.floatLower(float %x, float %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.floatLower(float %x, float %y, ptr %context) unnamed_addr #1 { - entry: - %0 = fcmp olt float %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden i1 @main.floatLowerEqual(float %x, float %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.floatLowerEqual(float %x, float %y, ptr %context) unnamed_addr #1 { - entry: - %0 = fcmp ole float %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden i1 @main.floatGreater(float %x, float %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.floatGreater(float %x, float %y, ptr %context) unnamed_addr #1 { - entry: - %0 = fcmp ogt float %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden i1 @main.floatGreaterEqual(float %x, float %y, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.floatGreaterEqual(float %x, float %y, ptr %context) unnamed_addr #1 { - entry: - %0 = fcmp oge float %x, %y - ret i1 %0 - } - - ; Function Attrs: nounwind --define hidden float @main.complexReal(float %x.r, float %x.i, i8* %context) unnamed_addr #1 { -+define hidden float @main.complexReal(float %x.r, float %x.i, ptr %context) unnamed_addr #1 { - entry: - ret float %x.r - } - - ; Function Attrs: nounwind --define hidden float @main.complexImag(float %x.r, float %x.i, i8* %context) unnamed_addr #1 { -+define hidden float @main.complexImag(float %x.r, float %x.i, ptr %context) unnamed_addr #1 { - entry: - ret float %x.i - } - - ; Function Attrs: nounwind --define hidden { float, float } @main.complexAdd(float %x.r, float %x.i, float %y.r, float %y.i, i8* %context) unnamed_addr #1 { -+define hidden { float, float } @main.complexAdd(float %x.r, float %x.i, float %y.r, float %y.i, ptr %context) unnamed_addr #1 { - entry: - %0 = fadd float %x.r, %y.r - %1 = fadd float %x.i, %y.i -@@ -165,7 +167,7 @@ entry: - } - - ; Function Attrs: nounwind --define hidden { float, float } @main.complexSub(float %x.r, float %x.i, float %y.r, float %y.i, i8* %context) unnamed_addr #1 { -+define hidden { float, float } @main.complexSub(float %x.r, float %x.i, float %y.r, float %y.i, ptr %context) unnamed_addr #1 { - entry: - %0 = fsub float %x.r, %y.r - %1 = fsub float %x.i, %y.i -@@ -175,7 +177,7 @@ entry: - } - - ; Function Attrs: nounwind --define hidden { float, float } @main.complexMul(float %x.r, float %x.i, float %y.r, float %y.i, i8* %context) unnamed_addr #1 { -+define hidden { float, float } @main.complexMul(float %x.r, float %x.i, float %y.r, float %y.i, ptr %context) unnamed_addr #1 { - entry: - %0 = fmul float %x.r, %y.r - %1 = fmul float %x.i, %y.i -@@ -189,15 +191,22 @@ entry: - } - - ; Function Attrs: nounwind --define hidden void @main.foo(%main.kv* dereferenceable_or_null(4) %a, i8* %context) unnamed_addr #1 { -+define hidden void @main.foo(ptr %context) unnamed_addr #1 { - entry: -- call void @"main.foo$1"(%main.kv.0* null, i8* undef) -+ %complit = alloca %main.kv.0, align 8 -+ store %main.kv.0 zeroinitializer, ptr %complit, align 8 -+ call void @runtime.trackPointer(ptr nonnull %complit, ptr undef) #2 -+ call void @"main.foo$1"(%main.kv.0 zeroinitializer, ptr undef) - ret void - } - - ; Function Attrs: nounwind --define internal void @"main.foo$1"(%main.kv.0* dereferenceable_or_null(1) %b, i8* %context) unnamed_addr #1 { -+define internal void @"main.foo$1"(%main.kv.0 %b, ptr %context) unnamed_addr #1 { - entry: -+ %b1 = alloca %main.kv.0, align 8 -+ store %main.kv.0 zeroinitializer, ptr %b1, align 8 -+ call void @runtime.trackPointer(ptr nonnull %b1, ptr undef) #2 -+ store %main.kv.0 %b, ptr %b1, align 8 - ret void - } - -diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index ec3dd6b9..8f4ed74e 100644 ---- a/compiler/testdata/channel.ll -+++ b/compiler/testdata/channel.ll -@@ -3,110 +3,94 @@ source_filename = "channel.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } --%runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state", i8* } --%"internal/task.gcData" = type { i8* } --%"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } --%"internal/task.stackState" = type { i32, i32 } --%runtime.chanSelectState = type { %runtime.channel*, i8* } -+%runtime.channelBlockedList = type { ptr, ptr, ptr, { ptr, i32, i32 } } -+%runtime.chanSelectState = type { ptr, ptr } - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.chanIntSend(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { -+define hidden void @main.chanIntSend(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { - entry: - %chan.blockedList = alloca %runtime.channelBlockedList, align 8 - %chan.value = alloca i32, align 4 -- %chan.value.bitcast = bitcast i32* %chan.value to i8* -- call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %chan.value.bitcast) -- store i32 3, i32* %chan.value, align 4 -- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* -- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -- call void @runtime.chanSend(%runtime.channel* %ch, i8* nonnull %chan.value.bitcast, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 -- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -- call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %chan.value.bitcast) -+ call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %chan.value) -+ store i32 3, ptr %chan.value, align 4 -+ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) -+ call void @runtime.chanSend(ptr %ch, ptr nonnull %chan.value, ptr nonnull %chan.blockedList, ptr undef) #3 -+ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) -+ call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %chan.value) - ret void - } - --; Function Attrs: argmemonly nofree nosync nounwind willreturn --declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2 -+; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn -+declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2 - --declare void @runtime.chanSend(%runtime.channel* dereferenceable_or_null(32), i8*, %runtime.channelBlockedList* dereferenceable_or_null(24), i8*) #0 -+declare void @runtime.chanSend(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #0 - --; Function Attrs: argmemonly nofree nosync nounwind willreturn --declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2 -+; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn -+declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2 - - ; Function Attrs: nounwind --define hidden void @main.chanIntRecv(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { -+define hidden void @main.chanIntRecv(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { - entry: - %chan.blockedList = alloca %runtime.channelBlockedList, align 8 - %chan.value = alloca i32, align 4 -- %chan.value.bitcast = bitcast i32* %chan.value to i8* -- call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %chan.value.bitcast) -- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* -- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -- %0 = call i1 @runtime.chanRecv(%runtime.channel* %ch, i8* nonnull %chan.value.bitcast, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 -- call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %chan.value.bitcast) -- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -+ call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %chan.value) -+ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) -+ %0 = call i1 @runtime.chanRecv(ptr %ch, ptr nonnull %chan.value, ptr nonnull %chan.blockedList, ptr undef) #3 -+ call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %chan.value) -+ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) - ret void - } - --declare i1 @runtime.chanRecv(%runtime.channel* dereferenceable_or_null(32), i8*, %runtime.channelBlockedList* dereferenceable_or_null(24), i8*) #0 -+declare i1 @runtime.chanRecv(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.chanZeroSend(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { -+define hidden void @main.chanZeroSend(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { - entry: - %complit = alloca {}, align 8 - %chan.blockedList = alloca %runtime.channelBlockedList, align 8 -- %0 = bitcast {}* %complit to i8* -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #3 -- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* -- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -- call void @runtime.chanSend(%runtime.channel* %ch, i8* null, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 -- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -+ call void @runtime.trackPointer(ptr nonnull %complit, ptr undef) #3 -+ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) -+ call void @runtime.chanSend(ptr %ch, ptr null, ptr nonnull %chan.blockedList, ptr undef) #3 -+ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.chanZeroRecv(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { -+define hidden void @main.chanZeroRecv(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { - entry: - %chan.blockedList = alloca %runtime.channelBlockedList, align 8 -- %chan.blockedList.bitcast = bitcast %runtime.channelBlockedList* %chan.blockedList to i8* -- call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -- %0 = call i1 @runtime.chanRecv(%runtime.channel* %ch, i8* null, %runtime.channelBlockedList* nonnull %chan.blockedList, i8* undef) #3 -- call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %chan.blockedList.bitcast) -+ call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) -+ %0 = call i1 @runtime.chanRecv(ptr %ch, ptr null, ptr nonnull %chan.blockedList, ptr undef) #3 -+ call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.selectZeroRecv(%runtime.channel* dereferenceable_or_null(32) %ch1, %runtime.channel* dereferenceable_or_null(32) %ch2, i8* %context) unnamed_addr #1 { -+define hidden void @main.selectZeroRecv(ptr dereferenceable_or_null(32) %ch1, ptr dereferenceable_or_null(32) %ch2, ptr %context) unnamed_addr #1 { - entry: - %select.states.alloca = alloca [2 x %runtime.chanSelectState], align 8 - %select.send.value = alloca i32, align 4 -- store i32 1, i32* %select.send.value, align 4 -- %select.states.alloca.bitcast = bitcast [2 x %runtime.chanSelectState]* %select.states.alloca to i8* -- call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %select.states.alloca.bitcast) -- %.repack = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 0, i32 0 -- store %runtime.channel* %ch1, %runtime.channel** %.repack, align 8 -- %.repack1 = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 0, i32 1 -- %0 = bitcast i8** %.repack1 to i32** -- store i32* %select.send.value, i32** %0, align 4 -- %.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 1, i32 0 -- store %runtime.channel* %ch2, %runtime.channel** %.repack3, align 8 -- %.repack4 = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 1, i32 1 -- store i8* null, i8** %.repack4, align 4 -- %select.states = getelementptr inbounds [2 x %runtime.chanSelectState], [2 x %runtime.chanSelectState]* %select.states.alloca, i32 0, i32 0 -- %select.result = call { i32, i1 } @runtime.tryChanSelect(i8* undef, %runtime.chanSelectState* nonnull %select.states, i32 2, i32 2, i8* undef) #3 -- call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %select.states.alloca.bitcast) -+ store i32 1, ptr %select.send.value, align 4 -+ call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %select.states.alloca) -+ store ptr %ch1, ptr %select.states.alloca, align 8 -+ %select.states.alloca.repack1 = getelementptr inbounds %runtime.chanSelectState, ptr %select.states.alloca, i32 0, i32 1 -+ store ptr %select.send.value, ptr %select.states.alloca.repack1, align 4 -+ %0 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1 -+ store ptr %ch2, ptr %0, align 8 -+ %.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1, i32 1 -+ store ptr null, ptr %.repack3, align 4 -+ %select.result = call { i32, i1 } @runtime.tryChanSelect(ptr undef, ptr nonnull %select.states.alloca, i32 2, i32 2, ptr undef) #3 -+ call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %select.states.alloca) - %1 = extractvalue { i32, i1 } %select.result, 0 - %2 = icmp eq i32 %1, 0 - br i1 %2, label %select.done, label %select.next -@@ -122,9 +106,9 @@ select.body: ; preds = %select.next - br label %select.done - } - --declare { i32, i1 } @runtime.tryChanSelect(i8*, %runtime.chanSelectState*, i32, i32, i8*) #0 -+declare { i32, i1 } @runtime.tryChanSelect(ptr, ptr, i32, i32, ptr) #0 - - attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } --attributes #2 = { argmemonly nofree nosync nounwind willreturn } -+attributes #2 = { argmemonly nocallback nofree nosync nounwind willreturn } - attributes #3 = { nounwind } -diff --git a/compiler/testdata/defer-cortex-m-qemu.ll b/compiler/testdata/defer-cortex-m-qemu.ll -index 693f1b07..0841e255 100644 ---- a/compiler/testdata/defer-cortex-m-qemu.ll -+++ b/compiler/testdata/defer-cortex-m-qemu.ll -@@ -3,103 +3,99 @@ source_filename = "defer.go" - target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "thumbv7m-unknown-unknown-eabi" - --%runtime._defer = type { i32, %runtime._defer* } --%runtime.deferFrame = type { i8*, i8*, [0 x i8*], %runtime.deferFrame*, i1, %runtime._interface } --%runtime._interface = type { i32, i8* } -+%runtime.deferFrame = type { ptr, ptr, [0 x ptr], ptr, i1, %runtime._interface } -+%runtime._interface = type { i32, ptr } -+%runtime._defer = type { i32, ptr } - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - --declare void @main.external(i8*) #0 -+declare void @main.external(ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.deferSimple(i8* %context) unnamed_addr #1 { -+define hidden void @main.deferSimple(ptr %context) unnamed_addr #1 { - entry: -- %defer.alloca = alloca { i32, %runtime._defer* }, align 4 -- %deferPtr = alloca %runtime._defer*, align 4 -- store %runtime._defer* null, %runtime._defer** %deferPtr, align 4 -+ %defer.alloca = alloca { i32, ptr }, align 4 -+ %deferPtr = alloca ptr, align 4 -+ store ptr null, ptr %deferPtr, align 4 - %deferframe.buf = alloca %runtime.deferFrame, align 4 -- %0 = call i8* @llvm.stacksave() -- call void @runtime.setupDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* %0, i8* undef) #3 -- %defer.alloca.repack = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 0 -- store i32 0, i32* %defer.alloca.repack, align 4 -- %defer.alloca.repack16 = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 1 -- store %runtime._defer* null, %runtime._defer** %defer.alloca.repack16, align 4 -- %1 = bitcast %runtime._defer** %deferPtr to { i32, %runtime._defer* }** -- store { i32, %runtime._defer* }* %defer.alloca, { i32, %runtime._defer* }** %1, align 4 -- %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -+ %0 = call ptr @llvm.stacksave() -+ call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #3 -+ store i32 0, ptr %defer.alloca, align 4 -+ %defer.alloca.repack15 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1 -+ store ptr null, ptr %defer.alloca.repack15, align 4 -+ store ptr %defer.alloca, ptr %deferPtr, align 4 -+ %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 - %setjmp.result = icmp eq i32 %setjmp, 0 -- br i1 %setjmp.result, label %2, label %lpad -+ br i1 %setjmp.result, label %1, label %lpad - --2: ; preds = %entry -- call void @main.external(i8* undef) #3 -+1: ; preds = %entry -+ call void @main.external(ptr undef) #3 - br label %rundefers.loophead - --rundefers.loophead: ; preds = %4, %2 -- %3 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 -- %stackIsNil = icmp eq %runtime._defer* %3, null -+rundefers.loophead: ; preds = %3, %1 -+ %2 = load ptr, ptr %deferPtr, align 4 -+ %stackIsNil = icmp eq ptr %2, null - br i1 %stackIsNil, label %rundefers.end, label %rundefers.loop - - rundefers.loop: ; preds = %rundefers.loophead -- %stack.next.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %3, i32 0, i32 1 -- %stack.next = load %runtime._defer*, %runtime._defer** %stack.next.gep, align 4 -- store %runtime._defer* %stack.next, %runtime._defer** %deferPtr, align 4 -- %callback.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %3, i32 0, i32 0 -- %callback = load i32, i32* %callback.gep, align 4 -+ %stack.next.gep = getelementptr inbounds %runtime._defer, ptr %2, i32 0, i32 1 -+ %stack.next = load ptr, ptr %stack.next.gep, align 4 -+ store ptr %stack.next, ptr %deferPtr, align 4 -+ %callback = load i32, ptr %2, align 4 - switch i32 %callback, label %rundefers.default [ - i32 0, label %rundefers.callback0 - ] - - rundefers.callback0: ; preds = %rundefers.loop -- %setjmp1 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -+ %setjmp1 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 - %setjmp.result2 = icmp eq i32 %setjmp1, 0 -- br i1 %setjmp.result2, label %4, label %lpad -+ br i1 %setjmp.result2, label %3, label %lpad - --4: ; preds = %rundefers.callback0 -- call void @"main.deferSimple$1"(i8* undef) -+3: ; preds = %rundefers.callback0 -+ call void @"main.deferSimple$1"(ptr undef) - br label %rundefers.loophead - - rundefers.default: ; preds = %rundefers.loop - unreachable - - rundefers.end: ; preds = %rundefers.loophead -- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 -+ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 - ret void - - recover: ; preds = %rundefers.end3 -- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 -+ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 - ret void - - lpad: ; preds = %rundefers.callback012, %rundefers.callback0, %entry - br label %rundefers.loophead6 - --rundefers.loophead6: ; preds = %6, %lpad -- %5 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 -- %stackIsNil7 = icmp eq %runtime._defer* %5, null -+rundefers.loophead6: ; preds = %5, %lpad -+ %4 = load ptr, ptr %deferPtr, align 4 -+ %stackIsNil7 = icmp eq ptr %4, null - br i1 %stackIsNil7, label %rundefers.end3, label %rundefers.loop5 - - rundefers.loop5: ; preds = %rundefers.loophead6 -- %stack.next.gep8 = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 1 -- %stack.next9 = load %runtime._defer*, %runtime._defer** %stack.next.gep8, align 4 -- store %runtime._defer* %stack.next9, %runtime._defer** %deferPtr, align 4 -- %callback.gep10 = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 0 -- %callback11 = load i32, i32* %callback.gep10, align 4 -+ %stack.next.gep8 = getelementptr inbounds %runtime._defer, ptr %4, i32 0, i32 1 -+ %stack.next9 = load ptr, ptr %stack.next.gep8, align 4 -+ store ptr %stack.next9, ptr %deferPtr, align 4 -+ %callback11 = load i32, ptr %4, align 4 - switch i32 %callback11, label %rundefers.default4 [ - i32 0, label %rundefers.callback012 - ] - - rundefers.callback012: ; preds = %rundefers.loop5 -- %setjmp14 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -- %setjmp.result15 = icmp eq i32 %setjmp14, 0 -- br i1 %setjmp.result15, label %6, label %lpad -+ %setjmp13 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 -+ %setjmp.result14 = icmp eq i32 %setjmp13, 0 -+ br i1 %setjmp.result14, label %5, label %lpad - --6: ; preds = %rundefers.callback012 -- call void @"main.deferSimple$1"(i8* undef) -+5: ; preds = %rundefers.callback012 -+ call void @"main.deferSimple$1"(ptr undef) - br label %rundefers.loophead6 - - rundefers.default4: ; preds = %rundefers.loop5 -@@ -109,158 +105,151 @@ rundefers.end3: ; preds = %rundefers.loophead6 - br label %recover - } - --; Function Attrs: nofree nosync nounwind willreturn --declare i8* @llvm.stacksave() #2 -+; Function Attrs: nocallback nofree nosync nounwind willreturn -+declare ptr @llvm.stacksave() #2 - --declare void @runtime.setupDeferFrame(%runtime.deferFrame* dereferenceable_or_null(24), i8*, i8*) #0 -+declare void @runtime.setupDeferFrame(ptr dereferenceable_or_null(24), ptr, ptr) #0 - - ; Function Attrs: nounwind --define internal void @"main.deferSimple$1"(i8* %context) unnamed_addr #1 { -+define internal void @"main.deferSimple$1"(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.printint32(i32 3, i8* undef) #3 -+ call void @runtime.printint32(i32 3, ptr undef) #3 - ret void - } - --declare void @runtime.destroyDeferFrame(%runtime.deferFrame* dereferenceable_or_null(24), i8*) #0 -+declare void @runtime.destroyDeferFrame(ptr dereferenceable_or_null(24), ptr) #0 - --declare void @runtime.printint32(i32, i8*) #0 -+declare void @runtime.printint32(i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.deferMultiple(i8* %context) unnamed_addr #1 { -+define hidden void @main.deferMultiple(ptr %context) unnamed_addr #1 { - entry: -- %defer.alloca2 = alloca { i32, %runtime._defer* }, align 4 -- %defer.alloca = alloca { i32, %runtime._defer* }, align 4 -- %deferPtr = alloca %runtime._defer*, align 4 -- store %runtime._defer* null, %runtime._defer** %deferPtr, align 4 -+ %defer.alloca2 = alloca { i32, ptr }, align 4 -+ %defer.alloca = alloca { i32, ptr }, align 4 -+ %deferPtr = alloca ptr, align 4 -+ store ptr null, ptr %deferPtr, align 4 - %deferframe.buf = alloca %runtime.deferFrame, align 4 -- %0 = call i8* @llvm.stacksave() -- call void @runtime.setupDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* %0, i8* undef) #3 -- %defer.alloca.repack = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 0 -- store i32 0, i32* %defer.alloca.repack, align 4 -- %defer.alloca.repack26 = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca, i32 0, i32 1 -- store %runtime._defer* null, %runtime._defer** %defer.alloca.repack26, align 4 -- %1 = bitcast %runtime._defer** %deferPtr to { i32, %runtime._defer* }** -- store { i32, %runtime._defer* }* %defer.alloca, { i32, %runtime._defer* }** %1, align 4 -- %defer.alloca2.repack = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca2, i32 0, i32 0 -- store i32 1, i32* %defer.alloca2.repack, align 4 -- %defer.alloca2.repack27 = getelementptr inbounds { i32, %runtime._defer* }, { i32, %runtime._defer* }* %defer.alloca2, i32 0, i32 1 -- %2 = bitcast %runtime._defer** %defer.alloca2.repack27 to { i32, %runtime._defer* }** -- store { i32, %runtime._defer* }* %defer.alloca, { i32, %runtime._defer* }** %2, align 4 -- %3 = bitcast %runtime._defer** %deferPtr to { i32, %runtime._defer* }** -- store { i32, %runtime._defer* }* %defer.alloca2, { i32, %runtime._defer* }** %3, align 4 -- %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -+ %0 = call ptr @llvm.stacksave() -+ call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #3 -+ store i32 0, ptr %defer.alloca, align 4 -+ %defer.alloca.repack22 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1 -+ store ptr null, ptr %defer.alloca.repack22, align 4 -+ store ptr %defer.alloca, ptr %deferPtr, align 4 -+ store i32 1, ptr %defer.alloca2, align 4 -+ %defer.alloca2.repack23 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca2, i32 0, i32 1 -+ store ptr %defer.alloca, ptr %defer.alloca2.repack23, align 4 -+ store ptr %defer.alloca2, ptr %deferPtr, align 4 -+ %setjmp = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 - %setjmp.result = icmp eq i32 %setjmp, 0 -- br i1 %setjmp.result, label %4, label %lpad -+ br i1 %setjmp.result, label %1, label %lpad - --4: ; preds = %entry -- call void @main.external(i8* undef) #3 -+1: ; preds = %entry -+ call void @main.external(ptr undef) #3 - br label %rundefers.loophead - --rundefers.loophead: ; preds = %7, %6, %4 -- %5 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 -- %stackIsNil = icmp eq %runtime._defer* %5, null -+rundefers.loophead: ; preds = %4, %3, %1 -+ %2 = load ptr, ptr %deferPtr, align 4 -+ %stackIsNil = icmp eq ptr %2, null - br i1 %stackIsNil, label %rundefers.end, label %rundefers.loop - - rundefers.loop: ; preds = %rundefers.loophead -- %stack.next.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 1 -- %stack.next = load %runtime._defer*, %runtime._defer** %stack.next.gep, align 4 -- store %runtime._defer* %stack.next, %runtime._defer** %deferPtr, align 4 -- %callback.gep = getelementptr inbounds %runtime._defer, %runtime._defer* %5, i32 0, i32 0 -- %callback = load i32, i32* %callback.gep, align 4 -+ %stack.next.gep = getelementptr inbounds %runtime._defer, ptr %2, i32 0, i32 1 -+ %stack.next = load ptr, ptr %stack.next.gep, align 4 -+ store ptr %stack.next, ptr %deferPtr, align 4 -+ %callback = load i32, ptr %2, align 4 - switch i32 %callback, label %rundefers.default [ - i32 0, label %rundefers.callback0 - i32 1, label %rundefers.callback1 - ] - - rundefers.callback0: ; preds = %rundefers.loop -- %setjmp4 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -- %setjmp.result5 = icmp eq i32 %setjmp4, 0 -- br i1 %setjmp.result5, label %6, label %lpad -+ %setjmp3 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 -+ %setjmp.result4 = icmp eq i32 %setjmp3, 0 -+ br i1 %setjmp.result4, label %3, label %lpad - --6: ; preds = %rundefers.callback0 -- call void @"main.deferMultiple$1"(i8* undef) -+3: ; preds = %rundefers.callback0 -+ call void @"main.deferMultiple$1"(ptr undef) - br label %rundefers.loophead - - rundefers.callback1: ; preds = %rundefers.loop -- %setjmp7 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -- %setjmp.result8 = icmp eq i32 %setjmp7, 0 -- br i1 %setjmp.result8, label %7, label %lpad -+ %setjmp5 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 -+ %setjmp.result6 = icmp eq i32 %setjmp5, 0 -+ br i1 %setjmp.result6, label %4, label %lpad - --7: ; preds = %rundefers.callback1 -- call void @"main.deferMultiple$2"(i8* undef) -+4: ; preds = %rundefers.callback1 -+ call void @"main.deferMultiple$2"(ptr undef) - br label %rundefers.loophead - - rundefers.default: ; preds = %rundefers.loop - unreachable - - rundefers.end: ; preds = %rundefers.loophead -- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 -+ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 - ret void - --recover: ; preds = %rundefers.end9 -- call void @runtime.destroyDeferFrame(%runtime.deferFrame* nonnull %deferframe.buf, i8* undef) #3 -+recover: ; preds = %rundefers.end7 -+ call void @runtime.destroyDeferFrame(ptr nonnull %deferframe.buf, ptr undef) #3 - ret void - --lpad: ; preds = %rundefers.callback122, %rundefers.callback018, %rundefers.callback1, %rundefers.callback0, %entry -- br label %rundefers.loophead12 -- --rundefers.loophead12: ; preds = %10, %9, %lpad -- %8 = load %runtime._defer*, %runtime._defer** %deferPtr, align 4 -- %stackIsNil13 = icmp eq %runtime._defer* %8, null -- br i1 %stackIsNil13, label %rundefers.end9, label %rundefers.loop11 -- --rundefers.loop11: ; preds = %rundefers.loophead12 -- %stack.next.gep14 = getelementptr inbounds %runtime._defer, %runtime._defer* %8, i32 0, i32 1 -- %stack.next15 = load %runtime._defer*, %runtime._defer** %stack.next.gep14, align 4 -- store %runtime._defer* %stack.next15, %runtime._defer** %deferPtr, align 4 -- %callback.gep16 = getelementptr inbounds %runtime._defer, %runtime._defer* %8, i32 0, i32 0 -- %callback17 = load i32, i32* %callback.gep16, align 4 -- switch i32 %callback17, label %rundefers.default10 [ -- i32 0, label %rundefers.callback018 -- i32 1, label %rundefers.callback122 -+lpad: ; preds = %rundefers.callback119, %rundefers.callback016, %rundefers.callback1, %rundefers.callback0, %entry -+ br label %rundefers.loophead10 -+ -+rundefers.loophead10: ; preds = %7, %6, %lpad -+ %5 = load ptr, ptr %deferPtr, align 4 -+ %stackIsNil11 = icmp eq ptr %5, null -+ br i1 %stackIsNil11, label %rundefers.end7, label %rundefers.loop9 -+ -+rundefers.loop9: ; preds = %rundefers.loophead10 -+ %stack.next.gep12 = getelementptr inbounds %runtime._defer, ptr %5, i32 0, i32 1 -+ %stack.next13 = load ptr, ptr %stack.next.gep12, align 4 -+ store ptr %stack.next13, ptr %deferPtr, align 4 -+ %callback15 = load i32, ptr %5, align 4 -+ switch i32 %callback15, label %rundefers.default8 [ -+ i32 0, label %rundefers.callback016 -+ i32 1, label %rundefers.callback119 - ] - --rundefers.callback018: ; preds = %rundefers.loop11 -- %setjmp20 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -- %setjmp.result21 = icmp eq i32 %setjmp20, 0 -- br i1 %setjmp.result21, label %9, label %lpad -+rundefers.callback016: ; preds = %rundefers.loop9 -+ %setjmp17 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 -+ %setjmp.result18 = icmp eq i32 %setjmp17, 0 -+ br i1 %setjmp.result18, label %6, label %lpad - --9: ; preds = %rundefers.callback018 -- call void @"main.deferMultiple$1"(i8* undef) -- br label %rundefers.loophead12 -+6: ; preds = %rundefers.callback016 -+ call void @"main.deferMultiple$1"(ptr undef) -+ br label %rundefers.loophead10 - --rundefers.callback122: ; preds = %rundefers.loop11 -- %setjmp24 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(%runtime.deferFrame* nonnull %deferframe.buf) #4 -- %setjmp.result25 = icmp eq i32 %setjmp24, 0 -- br i1 %setjmp.result25, label %10, label %lpad -+rundefers.callback119: ; preds = %rundefers.loop9 -+ %setjmp20 = call i32 asm "\0Amovs r0, #0\0Amov r2, pc\0Astr r2, [r1, #4]", "={r0},{r1},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{lr},~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{cpsr},~{memory}"(ptr nonnull %deferframe.buf) #4 -+ %setjmp.result21 = icmp eq i32 %setjmp20, 0 -+ br i1 %setjmp.result21, label %7, label %lpad - --10: ; preds = %rundefers.callback122 -- call void @"main.deferMultiple$2"(i8* undef) -- br label %rundefers.loophead12 -+7: ; preds = %rundefers.callback119 -+ call void @"main.deferMultiple$2"(ptr undef) -+ br label %rundefers.loophead10 - --rundefers.default10: ; preds = %rundefers.loop11 -+rundefers.default8: ; preds = %rundefers.loop9 - unreachable - --rundefers.end9: ; preds = %rundefers.loophead12 -+rundefers.end7: ; preds = %rundefers.loophead10 - br label %recover - } - - ; Function Attrs: nounwind --define internal void @"main.deferMultiple$1"(i8* %context) unnamed_addr #1 { -+define internal void @"main.deferMultiple$1"(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.printint32(i32 3, i8* undef) #3 -+ call void @runtime.printint32(i32 3, ptr undef) #3 - ret void - } - - ; Function Attrs: nounwind --define internal void @"main.deferMultiple$2"(i8* %context) unnamed_addr #1 { -+define internal void @"main.deferMultiple$2"(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.printint32(i32 5, i8* undef) #3 -+ call void @runtime.printint32(i32 5, ptr undef) #3 - ret void - } - - attributes #0 = { "target-features"="+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-pacbti,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" } - attributes #1 = { nounwind "target-features"="+armv7-m,+hwdiv,+soft-float,+strict-align,+thumb-mode,-aes,-bf16,-cdecp0,-cdecp1,-cdecp2,-cdecp3,-cdecp4,-cdecp5,-cdecp6,-cdecp7,-crc,-crypto,-d32,-dotprod,-dsp,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-hwdiv-arm,-i8mm,-lob,-mve,-mve.fp,-neon,-pacbti,-ras,-sb,-sha2,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" } --attributes #2 = { nofree nosync nounwind willreturn } -+attributes #2 = { nocallback nofree nosync nounwind willreturn } - attributes #3 = { nounwind } - attributes #4 = { nounwind returns_twice } -diff --git a/compiler/testdata/float.ll b/compiler/testdata/float.ll -index 0ecd21e9..2acc2ed4 100644 ---- a/compiler/testdata/float.ll -+++ b/compiler/testdata/float.ll -@@ -3,18 +3,18 @@ source_filename = "float.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden i32 @main.f32tou32(float %v, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.f32tou32(float %v, ptr %context) unnamed_addr #1 { - entry: - %positive = fcmp oge float %v, 0.000000e+00 - %withinmax = fcmp ole float %v, 0x41EFFFFFC0000000 -@@ -26,25 +26,25 @@ entry: - } - - ; Function Attrs: nounwind --define hidden float @main.maxu32f(i8* %context) unnamed_addr #1 { -+define hidden float @main.maxu32f(ptr %context) unnamed_addr #1 { - entry: - ret float 0x41F0000000000000 - } - - ; Function Attrs: nounwind --define hidden i32 @main.maxu32tof32(i8* %context) unnamed_addr #1 { -+define hidden i32 @main.maxu32tof32(ptr %context) unnamed_addr #1 { - entry: - ret i32 -1 - } - - ; Function Attrs: nounwind --define hidden { i32, i32, i32, i32 } @main.inftoi32(i8* %context) unnamed_addr #1 { -+define hidden { i32, i32, i32, i32 } @main.inftoi32(ptr %context) unnamed_addr #1 { - entry: - ret { i32, i32, i32, i32 } { i32 -1, i32 0, i32 2147483647, i32 -2147483648 } - } - - ; Function Attrs: nounwind --define hidden i32 @main.u32tof32tou32(i32 %v, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.u32tof32tou32(i32 %v, ptr %context) unnamed_addr #1 { - entry: - %0 = uitofp i32 %v to float - %withinmax = fcmp ole float %0, 0x41EFFFFFC0000000 -@@ -54,7 +54,7 @@ entry: - } - - ; Function Attrs: nounwind --define hidden float @main.f32tou32tof32(float %v, i8* %context) unnamed_addr #1 { -+define hidden float @main.f32tou32tof32(float %v, ptr %context) unnamed_addr #1 { - entry: - %positive = fcmp oge float %v, 0.000000e+00 - %withinmax = fcmp ole float %v, 0x41EFFFFFC0000000 -@@ -67,7 +67,7 @@ entry: - } - - ; Function Attrs: nounwind --define hidden i8 @main.f32tou8(float %v, i8* %context) unnamed_addr #1 { -+define hidden i8 @main.f32tou8(float %v, ptr %context) unnamed_addr #1 { - entry: - %positive = fcmp oge float %v, 0.000000e+00 - %withinmax = fcmp ole float %v, 2.550000e+02 -@@ -79,7 +79,7 @@ entry: - } - - ; Function Attrs: nounwind --define hidden i8 @main.f32toi8(float %v, i8* %context) unnamed_addr #1 { -+define hidden i8 @main.f32toi8(float %v, ptr %context) unnamed_addr #1 { - entry: - %abovemin = fcmp oge float %v, -1.280000e+02 - %belowmax = fcmp ole float %v, 1.270000e+02 -diff --git a/compiler/testdata/func.ll b/compiler/testdata/func.ll -index 2ed16eaf..227e52c1 100644 ---- a/compiler/testdata/func.ll -+++ b/compiler/testdata/func.ll -@@ -3,43 +3,42 @@ source_filename = "func.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.foo(i8* %callback.context, void ()* %callback.funcptr, i8* %context) unnamed_addr #1 { -+define hidden void @main.foo(ptr %callback.context, ptr %callback.funcptr, ptr %context) unnamed_addr #1 { - entry: -- %0 = icmp eq void ()* %callback.funcptr, null -+ %0 = icmp eq ptr %callback.funcptr, null - br i1 %0, label %fpcall.throw, label %fpcall.next - - fpcall.next: ; preds = %entry -- %1 = bitcast void ()* %callback.funcptr to void (i32, i8*)* -- call void %1(i32 3, i8* %callback.context) #2 -+ call void %callback.funcptr(i32 3, ptr %callback.context) #2 - ret void - - fpcall.throw: ; preds = %entry -- call void @runtime.nilPanic(i8* undef) #2 -+ call void @runtime.nilPanic(ptr undef) #2 - unreachable - } - --declare void @runtime.nilPanic(i8*) #0 -+declare void @runtime.nilPanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.bar(i8* %context) unnamed_addr #1 { -+define hidden void @main.bar(ptr %context) unnamed_addr #1 { - entry: -- call void @main.foo(i8* undef, void ()* bitcast (void (i32, i8*)* @main.someFunc to void ()*), i8* undef) -+ call void @main.foo(ptr undef, ptr nonnull @main.someFunc, ptr undef) - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.someFunc(i32 %arg0, i8* %context) unnamed_addr #1 { -+define hidden void @main.someFunc(i32 %arg0, ptr %context) unnamed_addr #1 { - entry: - ret void - } -diff --git a/compiler/testdata/gc.ll b/compiler/testdata/gc.ll -index 26bc4c24..e54b207d 100644 ---- a/compiler/testdata/gc.ll -+++ b/compiler/testdata/gc.ll -@@ -3,133 +3,129 @@ source_filename = "gc.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } --%runtime.interfaceMethodInfo = type { i8*, i32 } --%runtime._interface = type { i32, i8* } -+%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } -+%runtime._interface = type { i32, ptr } - --@main.scalar1 = hidden global i8* null, align 4 --@main.scalar2 = hidden global i32* null, align 4 --@main.scalar3 = hidden global i64* null, align 4 --@main.scalar4 = hidden global float* null, align 4 --@main.array1 = hidden global [3 x i8]* null, align 4 --@main.array2 = hidden global [71 x i8]* null, align 4 --@main.array3 = hidden global [3 x i8*]* null, align 4 --@main.struct1 = hidden global {}* null, align 4 --@main.struct2 = hidden global { i32, i32 }* null, align 4 --@main.struct3 = hidden global { i8*, [60 x i32], i8* }* null, align 4 --@main.struct4 = hidden global { i8*, [61 x i32] }* null, align 4 --@main.slice1 = hidden global { i8*, i32, i32 } zeroinitializer, align 8 --@main.slice2 = hidden global { i32**, i32, i32 } zeroinitializer, align 8 --@main.slice3 = hidden global { { i8*, i32, i32 }*, i32, i32 } zeroinitializer, align 8 -+@main.scalar1 = hidden global ptr null, align 4 -+@main.scalar2 = hidden global ptr null, align 4 -+@main.scalar3 = hidden global ptr null, align 4 -+@main.scalar4 = hidden global ptr null, align 4 -+@main.array1 = hidden global ptr null, align 4 -+@main.array2 = hidden global ptr null, align 4 -+@main.array3 = hidden global ptr null, align 4 -+@main.struct1 = hidden global ptr null, align 4 -+@main.struct2 = hidden global ptr null, align 4 -+@main.struct3 = hidden global ptr null, align 4 -+@main.struct4 = hidden global ptr null, align 4 -+@main.slice1 = hidden global { ptr, i32, i32 } zeroinitializer, align 8 -+@main.slice2 = hidden global { ptr, i32, i32 } zeroinitializer, align 8 -+@main.slice3 = hidden global { ptr, i32, i32 } zeroinitializer, align 8 - @"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c" \00\00\00\00\00\00\01" } - @"runtime/gc.layout:62-0001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\00\00\00\00\00\00\00\01" } --@"reflect/types.type:basic:complex128" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* null, i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:basic:complex128", i32 0 } --@"reflect/types.type:pointer:basic:complex128" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:complex128", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } -+@"reflect/types.type:basic:complex128" = linkonce_odr constant %runtime.typecodeID { ptr null, i32 0, ptr null, ptr @"reflect/types.type:pointer:basic:complex128", i32 0 } -+@"reflect/types.type:pointer:basic:complex128" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:complex128", i32 0, ptr null, ptr null, i32 0 } - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.newScalar(i8* %context) unnamed_addr #1 { -+define hidden void @main.newScalar(ptr %context) unnamed_addr #1 { - entry: -- %new = call i8* @runtime.alloc(i32 1, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 -- store i8* %new, i8** @main.scalar1, align 4 -- %new1 = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new1, i8* undef) #2 -- store i8* %new1, i8** bitcast (i32** @main.scalar2 to i8**), align 4 -- %new2 = call i8* @runtime.alloc(i32 8, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new2, i8* undef) #2 -- store i8* %new2, i8** bitcast (i64** @main.scalar3 to i8**), align 4 -- %new3 = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new3, i8* undef) #2 -- store i8* %new3, i8** bitcast (float** @main.scalar4 to i8**), align 4 -+ %new = call ptr @runtime.alloc(i32 1, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 -+ store ptr %new, ptr @main.scalar1, align 4 -+ %new1 = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new1, ptr undef) #2 -+ store ptr %new1, ptr @main.scalar2, align 4 -+ %new2 = call ptr @runtime.alloc(i32 8, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new2, ptr undef) #2 -+ store ptr %new2, ptr @main.scalar3, align 4 -+ %new3 = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new3, ptr undef) #2 -+ store ptr %new3, ptr @main.scalar4, align 4 - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.newArray(i8* %context) unnamed_addr #1 { -+define hidden void @main.newArray(ptr %context) unnamed_addr #1 { - entry: -- %new = call i8* @runtime.alloc(i32 3, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 -- store i8* %new, i8** bitcast ([3 x i8]** @main.array1 to i8**), align 4 -- %new1 = call i8* @runtime.alloc(i32 71, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new1, i8* undef) #2 -- store i8* %new1, i8** bitcast ([71 x i8]** @main.array2 to i8**), align 4 -- %new2 = call i8* @runtime.alloc(i32 12, i8* nonnull inttoptr (i32 67 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new2, i8* undef) #2 -- store i8* %new2, i8** bitcast ([3 x i8*]** @main.array3 to i8**), align 4 -+ %new = call ptr @runtime.alloc(i32 3, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 -+ store ptr %new, ptr @main.array1, align 4 -+ %new1 = call ptr @runtime.alloc(i32 71, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new1, ptr undef) #2 -+ store ptr %new1, ptr @main.array2, align 4 -+ %new2 = call ptr @runtime.alloc(i32 12, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new2, ptr undef) #2 -+ store ptr %new2, ptr @main.array3, align 4 - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.newStruct(i8* %context) unnamed_addr #1 { -+define hidden void @main.newStruct(ptr %context) unnamed_addr #1 { - entry: -- %new = call i8* @runtime.alloc(i32 0, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 -- store i8* %new, i8** bitcast ({}** @main.struct1 to i8**), align 4 -- %new1 = call i8* @runtime.alloc(i32 8, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new1, i8* undef) #2 -- store i8* %new1, i8** bitcast ({ i32, i32 }** @main.struct2 to i8**), align 4 -- %new2 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-2000000000000001" to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new2, i8* undef) #2 -- store i8* %new2, i8** bitcast ({ i8*, [60 x i32], i8* }** @main.struct3 to i8**), align 4 -- %new3 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-0001" to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %new3, i8* undef) #2 -- store i8* %new3, i8** bitcast ({ i8*, [61 x i32] }** @main.struct4 to i8**), align 4 -+ %new = call ptr @runtime.alloc(i32 0, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 -+ store ptr %new, ptr @main.struct1, align 4 -+ %new1 = call ptr @runtime.alloc(i32 8, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new1, ptr undef) #2 -+ store ptr %new1, ptr @main.struct2, align 4 -+ %new2 = call ptr @runtime.alloc(i32 248, ptr nonnull @"runtime/gc.layout:62-2000000000000001", ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new2, ptr undef) #2 -+ store ptr %new2, ptr @main.struct3, align 4 -+ %new3 = call ptr @runtime.alloc(i32 248, ptr nonnull @"runtime/gc.layout:62-0001", ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new3, ptr undef) #2 -+ store ptr %new3, ptr @main.struct4, align 4 - ret void - } - - ; Function Attrs: nounwind --define hidden { i8*, void ()* }* @main.newFuncValue(i8* %context) unnamed_addr #1 { -+define hidden ptr @main.newFuncValue(ptr %context) unnamed_addr #1 { - entry: -- %new = call i8* @runtime.alloc(i32 8, i8* nonnull inttoptr (i32 197 to i8*), i8* undef) #2 -- %0 = bitcast i8* %new to { i8*, void ()* }* -- call void @runtime.trackPointer(i8* nonnull %new, i8* undef) #2 -- ret { i8*, void ()* }* %0 -+ %new = call ptr @runtime.alloc(i32 8, ptr nonnull inttoptr (i32 197 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %new, ptr undef) #2 -+ ret ptr %new - } - - ; Function Attrs: nounwind --define hidden void @main.makeSlice(i8* %context) unnamed_addr #1 { -+define hidden void @main.makeSlice(ptr %context) unnamed_addr #1 { - entry: -- %makeslice = call i8* @runtime.alloc(i32 5, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %makeslice, i8* undef) #2 -- store i8* %makeslice, i8** getelementptr inbounds ({ i8*, i32, i32 }, { i8*, i32, i32 }* @main.slice1, i32 0, i32 0), align 8 -- store i32 5, i32* getelementptr inbounds ({ i8*, i32, i32 }, { i8*, i32, i32 }* @main.slice1, i32 0, i32 1), align 4 -- store i32 5, i32* getelementptr inbounds ({ i8*, i32, i32 }, { i8*, i32, i32 }* @main.slice1, i32 0, i32 2), align 8 -- %makeslice1 = call i8* @runtime.alloc(i32 20, i8* nonnull inttoptr (i32 67 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %makeslice1, i8* undef) #2 -- store i8* %makeslice1, i8** bitcast ({ i32**, i32, i32 }* @main.slice2 to i8**), align 8 -- store i32 5, i32* getelementptr inbounds ({ i32**, i32, i32 }, { i32**, i32, i32 }* @main.slice2, i32 0, i32 1), align 4 -- store i32 5, i32* getelementptr inbounds ({ i32**, i32, i32 }, { i32**, i32, i32 }* @main.slice2, i32 0, i32 2), align 8 -- %makeslice3 = call i8* @runtime.alloc(i32 60, i8* nonnull inttoptr (i32 71 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %makeslice3, i8* undef) #2 -- store i8* %makeslice3, i8** bitcast ({ { i8*, i32, i32 }*, i32, i32 }* @main.slice3 to i8**), align 8 -- store i32 5, i32* getelementptr inbounds ({ { i8*, i32, i32 }*, i32, i32 }, { { i8*, i32, i32 }*, i32, i32 }* @main.slice3, i32 0, i32 1), align 4 -- store i32 5, i32* getelementptr inbounds ({ { i8*, i32, i32 }*, i32, i32 }, { { i8*, i32, i32 }*, i32, i32 }* @main.slice3, i32 0, i32 2), align 8 -+ %makeslice = call ptr @runtime.alloc(i32 5, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice, ptr undef) #2 -+ store ptr %makeslice, ptr @main.slice1, align 8 -+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 1), align 4 -+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 2), align 8 -+ %makeslice1 = call ptr @runtime.alloc(i32 20, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice1, ptr undef) #2 -+ store ptr %makeslice1, ptr @main.slice2, align 8 -+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 1), align 4 -+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 2), align 8 -+ %makeslice3 = call ptr @runtime.alloc(i32 60, ptr nonnull inttoptr (i32 71 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice3, ptr undef) #2 -+ store ptr %makeslice3, ptr @main.slice3, align 8 -+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 1), align 4 -+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 2), align 8 - ret void - } - - ; Function Attrs: nounwind --define hidden %runtime._interface @main.makeInterface(double %v.r, double %v.i, i8* %context) unnamed_addr #1 { -+define hidden %runtime._interface @main.makeInterface(double %v.r, double %v.i, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 -- %.repack = bitcast i8* %0 to double* -- store double %v.r, double* %.repack, align 8 -- %.repack1 = getelementptr inbounds i8, i8* %0, i32 8 -- %1 = bitcast i8* %.repack1 to double* -- store double %v.i, double* %1, align 8 -- %2 = insertvalue %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:complex128" to i32), i8* undef }, i8* %0, 1 -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 -- ret %runtime._interface %2 -+ %0 = call ptr @runtime.alloc(i32 16, ptr null, ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 -+ store double %v.r, ptr %0, align 8 -+ %.repack1 = getelementptr inbounds { double, double }, ptr %0, i32 0, i32 1 -+ store double %v.i, ptr %.repack1, align 8 -+ %1 = insertvalue %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:basic:complex128" to i32), ptr undef }, ptr %0, 1 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 -+ ret %runtime._interface %1 - } - - attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } -diff --git a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll -index edd4d666..ac1adaff 100644 ---- a/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll -+++ b/compiler/testdata/goroutine-cortex-m-qemu-tasks.ll -@@ -3,201 +3,176 @@ source_filename = "goroutine.go" - target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "thumbv7m-unknown-unknown-eabi" - --%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } --%runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state", i8* } --%"internal/task.gcData" = type {} --%"internal/task.state" = type { i32, i32* } --%runtime.chanSelectState = type { %runtime.channel*, i8* } -+%runtime._string = type { ptr, i32 } - - @"main$string" = internal unnamed_addr constant [4 x i8] c"test", align 1 - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.regularFunctionGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.regularFunctionGoroutine(ptr %context) unnamed_addr #1 { - entry: -- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"main.regularFunction$gowrapper" to i32), i8* undef) #8 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.regularFunction$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 %stacksize, i8* undef) #8 -+ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"main.regularFunction$gowrapper" to i32), ptr undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.regularFunction$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 %stacksize, ptr undef) #8 - ret void - } - --declare void @main.regularFunction(i32, i8*) #0 -+declare void @main.regularFunction(i32, ptr) #0 - - ; Function Attrs: nounwind --define linkonce_odr void @"main.regularFunction$gowrapper"(i8* %0) unnamed_addr #2 { -+define linkonce_odr void @"main.regularFunction$gowrapper"(ptr %0) unnamed_addr #2 { - entry: -- %unpack.int = ptrtoint i8* %0 to i32 -- call void @main.regularFunction(i32 %unpack.int, i8* undef) #8 -+ %unpack.int = ptrtoint ptr %0 to i32 -+ call void @main.regularFunction(i32 %unpack.int, ptr undef) #8 - ret void - } - --declare i32 @"internal/task.getGoroutineStackSize"(i32, i8*) #0 -+declare i32 @"internal/task.getGoroutineStackSize"(i32, ptr) #0 - --declare void @"internal/task.start"(i32, i8*, i32, i8*) #0 -+declare void @"internal/task.start"(i32, ptr, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.inlineFunctionGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.inlineFunctionGoroutine(ptr %context) unnamed_addr #1 { - entry: -- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"main.inlineFunctionGoroutine$1$gowrapper" to i32), i8* undef) #8 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.inlineFunctionGoroutine$1$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 %stacksize, i8* undef) #8 -+ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"main.inlineFunctionGoroutine$1$gowrapper" to i32), ptr undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.inlineFunctionGoroutine$1$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 %stacksize, ptr undef) #8 - ret void - } - - ; Function Attrs: nounwind --define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { -+define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #3 { -+define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #3 { - entry: -- %unpack.int = ptrtoint i8* %0 to i32 -- call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, i8* undef) -+ %unpack.int = ptrtoint ptr %0 to i32 -+ call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, ptr undef) - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.closureFunctionGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.closureFunctionGoroutine(ptr %context) unnamed_addr #1 { - entry: -- %n = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #8 -- %0 = bitcast i8* %n to i32* -- store i32 3, i32* %0, align 4 -- %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef) #8 -- %2 = bitcast i8* %1 to i32* -- store i32 5, i32* %2, align 4 -- %3 = getelementptr inbounds i8, i8* %1, i32 4 -- %4 = bitcast i8* %3 to i8** -- store i8* %n, i8** %4, align 4 -- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"main.closureFunctionGoroutine$1$gowrapper" to i32), i8* undef) #8 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.closureFunctionGoroutine$1$gowrapper" to i32), i8* nonnull %1, i32 %stacksize, i8* undef) #8 -- %5 = load i32, i32* %0, align 4 -- call void @runtime.printint32(i32 %5, i8* undef) #8 -+ %n = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #8 -+ store i32 3, ptr %n, align 4 -+ %0 = call ptr @runtime.alloc(i32 8, ptr null, ptr undef) #8 -+ store i32 5, ptr %0, align 4 -+ %1 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 -+ store ptr %n, ptr %1, align 4 -+ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"main.closureFunctionGoroutine$1$gowrapper" to i32), ptr undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.closureFunctionGoroutine$1$gowrapper" to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #8 -+ %2 = load i32, ptr %n, align 4 -+ call void @runtime.printint32(i32 %2, ptr undef) #8 - ret void - } - - ; Function Attrs: nounwind --define internal void @"main.closureFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { -+define internal void @"main.closureFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { - entry: -- %unpack.ptr = bitcast i8* %context to i32* -- store i32 7, i32* %unpack.ptr, align 4 -+ store i32 7, ptr %context, align 4 - ret void - } - - ; Function Attrs: nounwind --define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #4 { -+define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #4 { - entry: -- %1 = bitcast i8* %0 to i32* -- %2 = load i32, i32* %1, align 4 -- %3 = getelementptr inbounds i8, i8* %0, i32 4 -- %4 = bitcast i8* %3 to i8** -- %5 = load i8*, i8** %4, align 4 -- call void @"main.closureFunctionGoroutine$1"(i32 %2, i8* %5) -+ %1 = load i32, ptr %0, align 4 -+ %2 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 -+ %3 = load ptr, ptr %2, align 4 -+ call void @"main.closureFunctionGoroutine$1"(i32 %1, ptr %3) - ret void - } - --declare void @runtime.printint32(i32, i8*) #0 -+declare void @runtime.printint32(i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.funcGoroutine(i8* %fn.context, void ()* %fn.funcptr, i8* %context) unnamed_addr #1 { -+define hidden void @main.funcGoroutine(ptr %fn.context, ptr %fn.funcptr, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i8* @runtime.alloc(i32 12, i8* null, i8* undef) #8 -- %1 = bitcast i8* %0 to i32* -- store i32 5, i32* %1, align 4 -- %2 = getelementptr inbounds i8, i8* %0, i32 4 -- %3 = bitcast i8* %2 to i8** -- store i8* %fn.context, i8** %3, align 4 -- %4 = getelementptr inbounds i8, i8* %0, i32 8 -- %5 = bitcast i8* %4 to void ()** -- store void ()* %fn.funcptr, void ()** %5, align 4 -- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @main.funcGoroutine.gowrapper to i32), i8* undef) #8 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @main.funcGoroutine.gowrapper to i32), i8* nonnull %0, i32 %stacksize, i8* undef) #8 -+ %0 = call ptr @runtime.alloc(i32 12, ptr null, ptr undef) #8 -+ store i32 5, ptr %0, align 4 -+ %1 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 -+ store ptr %fn.context, ptr %1, align 4 -+ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 -+ store ptr %fn.funcptr, ptr %2, align 4 -+ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @main.funcGoroutine.gowrapper to i32), ptr undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @main.funcGoroutine.gowrapper to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #8 - ret void - } - - ; Function Attrs: nounwind --define linkonce_odr void @main.funcGoroutine.gowrapper(i8* %0) unnamed_addr #5 { -+define linkonce_odr void @main.funcGoroutine.gowrapper(ptr %0) unnamed_addr #5 { - entry: -- %1 = bitcast i8* %0 to i32* -- %2 = load i32, i32* %1, align 4 -- %3 = getelementptr inbounds i8, i8* %0, i32 4 -- %4 = bitcast i8* %3 to i8** -- %5 = load i8*, i8** %4, align 4 -- %6 = getelementptr inbounds i8, i8* %0, i32 8 -- %7 = bitcast i8* %6 to void (i32, i8*)** -- %8 = load void (i32, i8*)*, void (i32, i8*)** %7, align 4 -- call void %8(i32 %2, i8* %5) #8 -+ %1 = load i32, ptr %0, align 4 -+ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 -+ %3 = load ptr, ptr %2, align 4 -+ %4 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 -+ %5 = load ptr, ptr %4, align 4 -+ call void %5(i32 %1, ptr %3) #8 - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.recoverBuiltinGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.recoverBuiltinGoroutine(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.copyBuiltinGoroutine(i8* %dst.data, i32 %dst.len, i32 %dst.cap, i8* %src.data, i32 %src.len, i32 %src.cap, i8* %context) unnamed_addr #1 { -+define hidden void @main.copyBuiltinGoroutine(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #1 { - entry: -- %copy.n = call i32 @runtime.sliceCopy(i8* %dst.data, i8* %src.data, i32 %dst.len, i32 %src.len, i32 1, i8* undef) #8 -+ %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 1, ptr undef) #8 - ret void - } - --declare i32 @runtime.sliceCopy(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i32, i8*) #0 -+declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.closeBuiltinGoroutine(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { -+define hidden void @main.closeBuiltinGoroutine(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.chanClose(%runtime.channel* %ch, i8* undef) #8 -+ call void @runtime.chanClose(ptr %ch, ptr undef) #8 - ret void - } - --declare void @runtime.chanClose(%runtime.channel* dereferenceable_or_null(32), i8*) #0 -+declare void @runtime.chanClose(ptr dereferenceable_or_null(32), ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.startInterfaceMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden void @main.startInterfaceMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef) #8 -- %1 = bitcast i8* %0 to i8** -- store i8* %itf.value, i8** %1, align 4 -- %2 = getelementptr inbounds i8, i8* %0, i32 4 -- %.repack = bitcast i8* %2 to i8** -- store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"main$string", i32 0, i32 0), i8** %.repack, align 4 -- %.repack1 = getelementptr inbounds i8, i8* %0, i32 8 -- %3 = bitcast i8* %.repack1 to i32* -- store i32 4, i32* %3, align 4 -- %4 = getelementptr inbounds i8, i8* %0, i32 12 -- %5 = bitcast i8* %4 to i32* -- store i32 %itf.typecode, i32* %5, align 4 -- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), i8* undef) #8 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), i8* nonnull %0, i32 %stacksize, i8* undef) #8 -+ %0 = call ptr @runtime.alloc(i32 16, ptr null, ptr undef) #8 -+ store ptr %itf.value, ptr %0, align 4 -+ %1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1 -+ store ptr @"main$string", ptr %1, align 4 -+ %.repack1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1, i32 1 -+ store i32 4, ptr %.repack1, align 4 -+ %2 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 2 -+ store i32 %itf.typecode, ptr %2, align 4 -+ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #8 - ret void - } - --declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8*, i8*, i32, i32, i8*) #6 -+declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr, ptr, i32, i32, ptr) #6 - - ; Function Attrs: nounwind --define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(i8* %0) unnamed_addr #7 { -+define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(ptr %0) unnamed_addr #7 { - entry: -- %1 = bitcast i8* %0 to i8** -- %2 = load i8*, i8** %1, align 4 -- %3 = getelementptr inbounds i8, i8* %0, i32 4 -- %4 = bitcast i8* %3 to i8** -- %5 = load i8*, i8** %4, align 4 -- %6 = getelementptr inbounds i8, i8* %0, i32 8 -- %7 = bitcast i8* %6 to i32* -- %8 = load i32, i32* %7, align 4 -- %9 = getelementptr inbounds i8, i8* %0, i32 12 -- %10 = bitcast i8* %9 to i32* -- %11 = load i32, i32* %10, align 4 -- call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8* %2, i8* %5, i32 %8, i32 %11, i8* undef) #8 -+ %1 = load ptr, ptr %0, align 4 -+ %2 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 1 -+ %3 = load ptr, ptr %2, align 4 -+ %4 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 2 -+ %5 = load i32, ptr %4, align 4 -+ %6 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 3 -+ %7 = load i32, ptr %6, align 4 -+ call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr %1, ptr %3, i32 %5, i32 %7, ptr undef) #8 - ret void - } - -diff --git a/compiler/testdata/goroutine-wasm-asyncify.ll b/compiler/testdata/goroutine-wasm-asyncify.ll -index 21da7477..280f216a 100644 ---- a/compiler/testdata/goroutine-wasm-asyncify.ll -+++ b/compiler/testdata/goroutine-wasm-asyncify.ll -@@ -3,210 +3,184 @@ source_filename = "goroutine.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* } --%runtime.channelBlockedList = type { %runtime.channelBlockedList*, %"internal/task.Task"*, %runtime.chanSelectState*, { %runtime.channelBlockedList*, i32, i32 } } --%"internal/task.Task" = type { %"internal/task.Task"*, i8*, i64, %"internal/task.gcData", %"internal/task.state", i8* } --%"internal/task.gcData" = type { i8* } --%"internal/task.state" = type { i32, i8*, %"internal/task.stackState", i1 } --%"internal/task.stackState" = type { i32, i32 } --%runtime.chanSelectState = type { %runtime.channel*, i8* } -+%runtime._string = type { ptr, i32 } - - @"main$string" = internal unnamed_addr constant [4 x i8] c"test", align 1 - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.regularFunctionGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.regularFunctionGoroutine(ptr %context) unnamed_addr #1 { - entry: -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.regularFunction$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 16384, i8* undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.regularFunction$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 16384, ptr undef) #8 - ret void - } - --declare void @main.regularFunction(i32, i8*) #0 -+declare void @main.regularFunction(i32, ptr) #0 - --declare void @runtime.deadlock(i8*) #0 -+declare void @runtime.deadlock(ptr) #0 - - ; Function Attrs: nounwind --define linkonce_odr void @"main.regularFunction$gowrapper"(i8* %0) unnamed_addr #2 { -+define linkonce_odr void @"main.regularFunction$gowrapper"(ptr %0) unnamed_addr #2 { - entry: -- %unpack.int = ptrtoint i8* %0 to i32 -- call void @main.regularFunction(i32 %unpack.int, i8* undef) #8 -- call void @runtime.deadlock(i8* undef) #8 -+ %unpack.int = ptrtoint ptr %0 to i32 -+ call void @main.regularFunction(i32 %unpack.int, ptr undef) #8 -+ call void @runtime.deadlock(ptr undef) #8 - unreachable - } - --declare void @"internal/task.start"(i32, i8*, i32, i8*) #0 -+declare void @"internal/task.start"(i32, ptr, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.inlineFunctionGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.inlineFunctionGoroutine(ptr %context) unnamed_addr #1 { - entry: -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.inlineFunctionGoroutine$1$gowrapper" to i32), i8* nonnull inttoptr (i32 5 to i8*), i32 16384, i8* undef) #8 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.inlineFunctionGoroutine$1$gowrapper" to i32), ptr nonnull inttoptr (i32 5 to ptr), i32 16384, ptr undef) #8 - ret void - } - - ; Function Attrs: nounwind --define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { -+define internal void @"main.inlineFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #3 { -+define linkonce_odr void @"main.inlineFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #3 { - entry: -- %unpack.int = ptrtoint i8* %0 to i32 -- call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, i8* undef) -- call void @runtime.deadlock(i8* undef) #8 -+ %unpack.int = ptrtoint ptr %0 to i32 -+ call void @"main.inlineFunctionGoroutine$1"(i32 %unpack.int, ptr undef) -+ call void @runtime.deadlock(ptr undef) #8 - unreachable - } - - ; Function Attrs: nounwind --define hidden void @main.closureFunctionGoroutine(i8* %context) unnamed_addr #1 { --entry: -- %n = call i8* @runtime.alloc(i32 4, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #8 -- %0 = bitcast i8* %n to i32* -- call void @runtime.trackPointer(i8* nonnull %n, i8* undef) #8 -- store i32 3, i32* %0, align 4 -- call void @runtime.trackPointer(i8* nonnull %n, i8* undef) #8 -- call void @runtime.trackPointer(i8* bitcast (void (i32, i8*)* @"main.closureFunctionGoroutine$1" to i8*), i8* undef) #8 -- %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef) #8 -- call void @runtime.trackPointer(i8* nonnull %1, i8* undef) #8 -- %2 = bitcast i8* %1 to i32* -- store i32 5, i32* %2, align 4 -- %3 = getelementptr inbounds i8, i8* %1, i32 4 -- %4 = bitcast i8* %3 to i8** -- store i8* %n, i8** %4, align 4 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"main.closureFunctionGoroutine$1$gowrapper" to i32), i8* nonnull %1, i32 16384, i8* undef) #8 -- %5 = load i32, i32* %0, align 4 -- call void @runtime.printint32(i32 %5, i8* undef) #8 -+define hidden void @main.closureFunctionGoroutine(ptr %context) unnamed_addr #1 { -+entry: -+ %n = call ptr @runtime.alloc(i32 4, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #8 -+ call void @runtime.trackPointer(ptr nonnull %n, ptr undef) #8 -+ store i32 3, ptr %n, align 4 -+ call void @runtime.trackPointer(ptr nonnull %n, ptr undef) #8 -+ call void @runtime.trackPointer(ptr nonnull @"main.closureFunctionGoroutine$1", ptr undef) #8 -+ %0 = call ptr @runtime.alloc(i32 8, ptr null, ptr undef) #8 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #8 -+ store i32 5, ptr %0, align 4 -+ %1 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 -+ store ptr %n, ptr %1, align 4 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"main.closureFunctionGoroutine$1$gowrapper" to i32), ptr nonnull %0, i32 16384, ptr undef) #8 -+ %2 = load i32, ptr %n, align 4 -+ call void @runtime.printint32(i32 %2, ptr undef) #8 - ret void - } - - ; Function Attrs: nounwind --define internal void @"main.closureFunctionGoroutine$1"(i32 %x, i8* %context) unnamed_addr #1 { -+define internal void @"main.closureFunctionGoroutine$1"(i32 %x, ptr %context) unnamed_addr #1 { - entry: -- %unpack.ptr = bitcast i8* %context to i32* -- store i32 7, i32* %unpack.ptr, align 4 -+ store i32 7, ptr %context, align 4 - ret void - } - - ; Function Attrs: nounwind --define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(i8* %0) unnamed_addr #4 { -+define linkonce_odr void @"main.closureFunctionGoroutine$1$gowrapper"(ptr %0) unnamed_addr #4 { - entry: -- %1 = bitcast i8* %0 to i32* -- %2 = load i32, i32* %1, align 4 -- %3 = getelementptr inbounds i8, i8* %0, i32 4 -- %4 = bitcast i8* %3 to i8** -- %5 = load i8*, i8** %4, align 4 -- call void @"main.closureFunctionGoroutine$1"(i32 %2, i8* %5) -- call void @runtime.deadlock(i8* undef) #8 -+ %1 = load i32, ptr %0, align 4 -+ %2 = getelementptr inbounds { i32, ptr }, ptr %0, i32 0, i32 1 -+ %3 = load ptr, ptr %2, align 4 -+ call void @"main.closureFunctionGoroutine$1"(i32 %1, ptr %3) -+ call void @runtime.deadlock(ptr undef) #8 - unreachable - } - --declare void @runtime.printint32(i32, i8*) #0 -+declare void @runtime.printint32(i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.funcGoroutine(i8* %fn.context, void ()* %fn.funcptr, i8* %context) unnamed_addr #1 { -+define hidden void @main.funcGoroutine(ptr %fn.context, ptr %fn.funcptr, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i8* @runtime.alloc(i32 12, i8* null, i8* undef) #8 -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #8 -- %1 = bitcast i8* %0 to i32* -- store i32 5, i32* %1, align 4 -- %2 = getelementptr inbounds i8, i8* %0, i32 4 -- %3 = bitcast i8* %2 to i8** -- store i8* %fn.context, i8** %3, align 4 -- %4 = getelementptr inbounds i8, i8* %0, i32 8 -- %5 = bitcast i8* %4 to void ()** -- store void ()* %fn.funcptr, void ()** %5, align 4 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @main.funcGoroutine.gowrapper to i32), i8* nonnull %0, i32 16384, i8* undef) #8 -+ %0 = call ptr @runtime.alloc(i32 12, ptr null, ptr undef) #8 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #8 -+ store i32 5, ptr %0, align 4 -+ %1 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 -+ store ptr %fn.context, ptr %1, align 4 -+ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 -+ store ptr %fn.funcptr, ptr %2, align 4 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @main.funcGoroutine.gowrapper to i32), ptr nonnull %0, i32 16384, ptr undef) #8 - ret void - } - - ; Function Attrs: nounwind --define linkonce_odr void @main.funcGoroutine.gowrapper(i8* %0) unnamed_addr #5 { -+define linkonce_odr void @main.funcGoroutine.gowrapper(ptr %0) unnamed_addr #5 { - entry: -- %1 = bitcast i8* %0 to i32* -- %2 = load i32, i32* %1, align 4 -- %3 = getelementptr inbounds i8, i8* %0, i32 4 -- %4 = bitcast i8* %3 to i8** -- %5 = load i8*, i8** %4, align 4 -- %6 = getelementptr inbounds i8, i8* %0, i32 8 -- %7 = bitcast i8* %6 to void (i32, i8*)** -- %8 = load void (i32, i8*)*, void (i32, i8*)** %7, align 4 -- call void %8(i32 %2, i8* %5) #8 -- call void @runtime.deadlock(i8* undef) #8 -+ %1 = load i32, ptr %0, align 4 -+ %2 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 1 -+ %3 = load ptr, ptr %2, align 4 -+ %4 = getelementptr inbounds { i32, ptr, ptr }, ptr %0, i32 0, i32 2 -+ %5 = load ptr, ptr %4, align 4 -+ call void %5(i32 %1, ptr %3) #8 -+ call void @runtime.deadlock(ptr undef) #8 - unreachable - } - - ; Function Attrs: nounwind --define hidden void @main.recoverBuiltinGoroutine(i8* %context) unnamed_addr #1 { -+define hidden void @main.recoverBuiltinGoroutine(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.copyBuiltinGoroutine(i8* %dst.data, i32 %dst.len, i32 %dst.cap, i8* %src.data, i32 %src.len, i32 %src.cap, i8* %context) unnamed_addr #1 { -+define hidden void @main.copyBuiltinGoroutine(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #1 { - entry: -- %copy.n = call i32 @runtime.sliceCopy(i8* %dst.data, i8* %src.data, i32 %dst.len, i32 %src.len, i32 1, i8* undef) #8 -+ %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 1, ptr undef) #8 - ret void - } - --declare i32 @runtime.sliceCopy(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i32, i8*) #0 -+declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.closeBuiltinGoroutine(%runtime.channel* dereferenceable_or_null(32) %ch, i8* %context) unnamed_addr #1 { -+define hidden void @main.closeBuiltinGoroutine(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.chanClose(%runtime.channel* %ch, i8* undef) #8 -+ call void @runtime.chanClose(ptr %ch, ptr undef) #8 - ret void - } - --declare void @runtime.chanClose(%runtime.channel* dereferenceable_or_null(32), i8*) #0 -+declare void @runtime.chanClose(ptr dereferenceable_or_null(32), ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.startInterfaceMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden void @main.startInterfaceMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef) #8 -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #8 -- %1 = bitcast i8* %0 to i8** -- store i8* %itf.value, i8** %1, align 4 -- %2 = getelementptr inbounds i8, i8* %0, i32 4 -- %.repack = bitcast i8* %2 to i8** -- store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"main$string", i32 0, i32 0), i8** %.repack, align 4 -- %.repack1 = getelementptr inbounds i8, i8* %0, i32 8 -- %3 = bitcast i8* %.repack1 to i32* -- store i32 4, i32* %3, align 4 -- %4 = getelementptr inbounds i8, i8* %0, i32 12 -- %5 = bitcast i8* %4 to i32* -- store i32 %itf.typecode, i32* %5, align 4 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), i8* nonnull %0, i32 16384, i8* undef) #8 -+ %0 = call ptr @runtime.alloc(i32 16, ptr null, ptr undef) #8 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #8 -+ store ptr %itf.value, ptr %0, align 4 -+ %1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1 -+ store ptr @"main$string", ptr %1, align 4 -+ %.repack1 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 1, i32 1 -+ store i32 4, ptr %.repack1, align 4 -+ %2 = getelementptr inbounds { ptr, %runtime._string, i32 }, ptr %0, i32 0, i32 2 -+ store i32 %itf.typecode, ptr %2, align 4 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr nonnull %0, i32 16384, ptr undef) #8 - ret void - } - --declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8*, i8*, i32, i32, i8*) #6 -+declare void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr, ptr, i32, i32, ptr) #6 - - ; Function Attrs: nounwind --define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(i8* %0) unnamed_addr #7 { -+define linkonce_odr void @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper"(ptr %0) unnamed_addr #7 { - entry: -- %1 = bitcast i8* %0 to i8** -- %2 = load i8*, i8** %1, align 4 -- %3 = getelementptr inbounds i8, i8* %0, i32 4 -- %4 = bitcast i8* %3 to i8** -- %5 = load i8*, i8** %4, align 4 -- %6 = getelementptr inbounds i8, i8* %0, i32 8 -- %7 = bitcast i8* %6 to i32* -- %8 = load i32, i32* %7, align 4 -- %9 = getelementptr inbounds i8, i8* %0, i32 12 -- %10 = bitcast i8* %9 to i32* -- %11 = load i32, i32* %10, align 4 -- call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(i8* %2, i8* %5, i32 %8, i32 %11, i8* undef) #8 -- call void @runtime.deadlock(i8* undef) #8 -+ %1 = load ptr, ptr %0, align 4 -+ %2 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 1 -+ %3 = load ptr, ptr %2, align 4 -+ %4 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 2 -+ %5 = load i32, ptr %4, align 4 -+ %6 = getelementptr inbounds { ptr, ptr, i32, i32 }, ptr %0, i32 0, i32 3 -+ %7 = load i32, ptr %6, align 4 -+ call void @"interface:{Print:func:{basic:string}{}}.Print$invoke"(ptr %1, ptr %3, i32 %5, i32 %7, ptr undef) #8 -+ call void @runtime.deadlock(ptr undef) #8 - unreachable - } - -diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll -index 0b44585a..38d4e567 100644 ---- a/compiler/testdata/interface.ll -+++ b/compiler/testdata/interface.ll -@@ -3,71 +3,70 @@ source_filename = "interface.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } --%runtime.interfaceMethodInfo = type { i8*, i32 } --%runtime._interface = type { i32, i8* } --%runtime._string = type { i8*, i32 } -- --@"reflect/types.type:basic:int" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* null, i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:basic:int", i32 0 } --@"reflect/types.type:pointer:basic:int" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } --@"reflect/types.type:pointer:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:named:error", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } --@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:named:error", i32 ptrtoint (i1 (i32)* @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } --@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}", i32 ptrtoint (i1 (i32)* @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } -+%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } -+%runtime._interface = type { i32, ptr } -+%runtime._string = type { ptr, i32 } -+ -+@"reflect/types.type:basic:int" = linkonce_odr constant %runtime.typecodeID { ptr null, i32 0, ptr null, ptr @"reflect/types.type:pointer:basic:int", i32 0 } -+@"reflect/types.type:pointer:basic:int" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:int", i32 0, ptr null, ptr null, i32 0 } -+@"reflect/types.type:pointer:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:named:error", i32 0, ptr null, ptr null, i32 0 } -+@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr @"reflect/types.type:pointer:named:error", i32 ptrtoint (ptr @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } -+@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.interface:interface{Error() string}$interface", i32 0, ptr null, ptr @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}", i32 ptrtoint (ptr @"interface:{Error:func:{}{basic:string}}.$typeassert" to i32) } - @"reflect/methods.Error() string" = linkonce_odr constant i8 0, align 1 --@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.Error() string"] --@"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } --@"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{String:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } --@"reflect/types.type:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{String() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}", i32 ptrtoint (i1 (i32)* @"interface:{String:func:{}{basic:string}}.$typeassert" to i32) } -+@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.Error() string"] -+@"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 0 } -+@"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{String:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 0 } -+@"reflect/types.type:interface:{String:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.interface:interface{String() string}$interface", i32 0, ptr null, ptr @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}", i32 ptrtoint (ptr @"interface:{String:func:{}{basic:string}}.$typeassert" to i32) } - @"reflect/methods.String() string" = linkonce_odr constant i8 0, align 1 --@"reflect/types.interface:interface{String() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.String() string"] -+@"reflect/types.interface:interface{String() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.String() string"] - @"reflect/types.typeid:basic:int" = external constant i8 - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden %runtime._interface @main.simpleType(i8* %context) unnamed_addr #1 { -+define hidden %runtime._interface @main.simpleType(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* null, i8* undef) #6 -- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:int" to i32), i8* null } -+ call void @runtime.trackPointer(ptr null, ptr undef) #6 -+ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:basic:int" to i32), ptr null } - } - - ; Function Attrs: nounwind --define hidden %runtime._interface @main.pointerType(i8* %context) unnamed_addr #1 { -+define hidden %runtime._interface @main.pointerType(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* null, i8* undef) #6 -- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:pointer:basic:int" to i32), i8* null } -+ call void @runtime.trackPointer(ptr null, ptr undef) #6 -+ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:pointer:basic:int" to i32), ptr null } - } - - ; Function Attrs: nounwind --define hidden %runtime._interface @main.interfaceType(i8* %context) unnamed_addr #1 { -+define hidden %runtime._interface @main.interfaceType(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* null, i8* undef) #6 -- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:pointer:named:error" to i32), i8* null } -+ call void @runtime.trackPointer(ptr null, ptr undef) #6 -+ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:pointer:named:error" to i32), ptr null } - } - - declare i1 @"interface:{Error:func:{}{basic:string}}.$typeassert"(i32) #2 - - ; Function Attrs: nounwind --define hidden %runtime._interface @main.anonymousInterfaceType(i8* %context) unnamed_addr #1 { -+define hidden %runtime._interface @main.anonymousInterfaceType(ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* null, i8* undef) #6 -- ret %runtime._interface { i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" to i32), i8* null } -+ call void @runtime.trackPointer(ptr null, ptr undef) #6 -+ ret %runtime._interface { i32 ptrtoint (ptr @"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" to i32), ptr null } - } - - declare i1 @"interface:{String:func:{}{basic:string}}.$typeassert"(i32) #3 - - ; Function Attrs: nounwind --define hidden i1 @main.isInt(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.isInt(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: -- %typecode = call i1 @runtime.typeAssert(i32 %itf.typecode, i8* nonnull @"reflect/types.typeid:basic:int", i8* undef) #6 -+ %typecode = call i1 @runtime.typeAssert(i32 %itf.typecode, ptr nonnull @"reflect/types.typeid:basic:int", ptr undef) #6 - br i1 %typecode, label %typeassert.ok, label %typeassert.next - - typeassert.next: ; preds = %typeassert.ok, %entry -@@ -77,10 +76,10 @@ typeassert.ok: ; preds = %entry - br label %typeassert.next - } - --declare i1 @runtime.typeAssert(i32, i8* dereferenceable_or_null(1), i8*) #0 -+declare i1 @runtime.typeAssert(i32, ptr dereferenceable_or_null(1), ptr) #0 - - ; Function Attrs: nounwind --define hidden i1 @main.isError(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.isError(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: - %0 = call i1 @"interface:{Error:func:{}{basic:string}}.$typeassert"(i32 %itf.typecode) #6 - br i1 %0, label %typeassert.ok, label %typeassert.next -@@ -93,7 +92,7 @@ typeassert.ok: ; preds = %entry - } - - ; Function Attrs: nounwind --define hidden i1 @main.isStringer(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.isStringer(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: - %0 = call i1 @"interface:{String:func:{}{basic:string}}.$typeassert"(i32 %itf.typecode) #6 - br i1 %0, label %typeassert.ok, label %typeassert.next -@@ -106,24 +105,24 @@ typeassert.ok: ; preds = %entry - } - - ; Function Attrs: nounwind --define hidden i8 @main.callFooMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden i8 @main.callFooMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(i8* %itf.value, i32 3, i32 %itf.typecode, i8* undef) #6 -+ %0 = call i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(ptr %itf.value, i32 3, i32 %itf.typecode, ptr undef) #6 - ret i8 %0 - } - --declare i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(i8*, i32, i32, i8*) #4 -+declare i8 @"interface:{String:func:{}{basic:string},main.foo:func:{basic:int}{basic:uint8}}.foo$invoke"(ptr, i32, i32, ptr) #4 - - ; Function Attrs: nounwind --define hidden %runtime._string @main.callErrorMethod(i32 %itf.typecode, i8* %itf.value, i8* %context) unnamed_addr #1 { -+define hidden %runtime._string @main.callErrorMethod(i32 %itf.typecode, ptr %itf.value, ptr %context) unnamed_addr #1 { - entry: -- %0 = call %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(i8* %itf.value, i32 %itf.typecode, i8* undef) #6 -+ %0 = call %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(ptr %itf.value, i32 %itf.typecode, ptr undef) #6 - %1 = extractvalue %runtime._string %0, 0 -- call void @runtime.trackPointer(i8* %1, i8* undef) #6 -+ call void @runtime.trackPointer(ptr %1, ptr undef) #6 - ret %runtime._string %0 - } - --declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(i8*, i32, i8*) #5 -+declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(ptr, i32, ptr) #5 - - attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } -diff --git a/compiler/testdata/pointer.ll b/compiler/testdata/pointer.ll -index cedea380..9bc8bd35 100644 ---- a/compiler/testdata/pointer.ll -+++ b/compiler/testdata/pointer.ll -@@ -3,76 +3,72 @@ source_filename = "pointer.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden [0 x i32] @main.pointerDerefZero([0 x i32]* %x, i8* %context) unnamed_addr #1 { -+define hidden [0 x i32] @main.pointerDerefZero(ptr %x, ptr %context) unnamed_addr #1 { - entry: - ret [0 x i32] zeroinitializer - } - - ; Function Attrs: nounwind --define hidden i32* @main.pointerCastFromUnsafe(i8* %x, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.pointerCastFromUnsafe(ptr %x, ptr %context) unnamed_addr #1 { - entry: -- %0 = bitcast i8* %x to i32* -- call void @runtime.trackPointer(i8* %x, i8* undef) #2 -- ret i32* %0 -+ call void @runtime.trackPointer(ptr %x, ptr undef) #2 -+ ret ptr %x - } - - ; Function Attrs: nounwind --define hidden i8* @main.pointerCastToUnsafe(i32* dereferenceable_or_null(4) %x, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.pointerCastToUnsafe(ptr dereferenceable_or_null(4) %x, ptr %context) unnamed_addr #1 { - entry: -- %0 = bitcast i32* %x to i8* -- call void @runtime.trackPointer(i8* %0, i8* undef) #2 -- ret i8* %0 -+ call void @runtime.trackPointer(ptr %x, ptr undef) #2 -+ ret ptr %x - } - - ; Function Attrs: nounwind --define hidden i8* @main.pointerCastToUnsafeNoop(i8* dereferenceable_or_null(1) %x, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.pointerCastToUnsafeNoop(ptr dereferenceable_or_null(1) %x, ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* %x, i8* undef) #2 -- ret i8* %x -+ call void @runtime.trackPointer(ptr %x, ptr undef) #2 -+ ret ptr %x - } - - ; Function Attrs: nounwind --define hidden i8* @main.pointerUnsafeGEPFixedOffset(i8* dereferenceable_or_null(1) %ptr, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.pointerUnsafeGEPFixedOffset(ptr dereferenceable_or_null(1) %ptr, ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* %ptr, i8* undef) #2 -- %0 = getelementptr inbounds i8, i8* %ptr, i32 10 -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %0, i8* undef) #2 -- ret i8* %0 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ %0 = getelementptr inbounds i8, ptr %ptr, i32 10 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %0, ptr undef) #2 -+ ret ptr %0 - } - - ; Function Attrs: nounwind --define hidden i8* @main.pointerUnsafeGEPByteOffset(i8* dereferenceable_or_null(1) %ptr, i32 %offset, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.pointerUnsafeGEPByteOffset(ptr dereferenceable_or_null(1) %ptr, i32 %offset, ptr %context) unnamed_addr #1 { - entry: -- call void @runtime.trackPointer(i8* %ptr, i8* undef) #2 -- %0 = getelementptr inbounds i8, i8* %ptr, i32 %offset -- call void @runtime.trackPointer(i8* %0, i8* undef) #2 -- call void @runtime.trackPointer(i8* %0, i8* undef) #2 -- ret i8* %0 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ %0 = getelementptr inbounds i8, ptr %ptr, i32 %offset -+ call void @runtime.trackPointer(ptr %0, ptr undef) #2 -+ call void @runtime.trackPointer(ptr %0, ptr undef) #2 -+ ret ptr %0 - } - - ; Function Attrs: nounwind --define hidden i32* @main.pointerUnsafeGEPIntOffset(i32* dereferenceable_or_null(4) %ptr, i32 %offset, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.pointerUnsafeGEPIntOffset(ptr dereferenceable_or_null(4) %ptr, i32 %offset, ptr %context) unnamed_addr #1 { - entry: -- %0 = bitcast i32* %ptr to i8* -- call void @runtime.trackPointer(i8* %0, i8* undef) #2 -- %1 = getelementptr i32, i32* %ptr, i32 %offset -- %2 = bitcast i32* %1 to i8* -- call void @runtime.trackPointer(i8* %2, i8* undef) #2 -- %3 = bitcast i32* %1 to i8* -- call void @runtime.trackPointer(i8* %3, i8* undef) #2 -- ret i32* %1 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ %0 = shl i32 %offset, 2 -+ %1 = getelementptr inbounds i8, ptr %ptr, i32 %0 -+ call void @runtime.trackPointer(ptr %1, ptr undef) #2 -+ call void @runtime.trackPointer(ptr %1, ptr undef) #2 -+ ret ptr %1 - } - - attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } -diff --git a/compiler/testdata/pragma.ll b/compiler/testdata/pragma.ll -index b243602d..c49c83bd 100644 ---- a/compiler/testdata/pragma.ll -+++ b/compiler/testdata/pragma.ll -@@ -10,12 +10,12 @@ target triple = "wasm32-unknown-wasi" - @undefinedGlobalNotInSection = external global i32, align 4 - @main.multipleGlobalPragmas = hidden global i32 0, section ".global_section", align 1024 - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } -@@ -27,27 +27,27 @@ entry: - } - - ; Function Attrs: nounwind --define hidden void @somepkg.someFunction1(i8* %context) unnamed_addr #1 { -+define hidden void @somepkg.someFunction1(ptr %context) unnamed_addr #1 { - entry: - ret void - } - --declare void @somepkg.someFunction2(i8*) #0 -+declare void @somepkg.someFunction2(ptr) #0 - - ; Function Attrs: inlinehint nounwind --define hidden void @main.inlineFunc(i8* %context) unnamed_addr #3 { -+define hidden void @main.inlineFunc(ptr %context) unnamed_addr #3 { - entry: - ret void - } - - ; Function Attrs: noinline nounwind --define hidden void @main.noinlineFunc(i8* %context) unnamed_addr #4 { -+define hidden void @main.noinlineFunc(ptr %context) unnamed_addr #4 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden void @main.functionInSection(i8* %context) unnamed_addr #1 section ".special_function_section" { -+define hidden void @main.functionInSection(ptr %context) unnamed_addr #1 section ".special_function_section" { - entry: - ret void - } -@@ -58,7 +58,7 @@ entry: - ret void - } - --declare void @main.undefinedFunctionNotInSection(i8*) #0 -+declare void @main.undefinedFunctionNotInSection(ptr) #0 - - attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } -diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll -index c2e3ebd9..56e40f5f 100644 ---- a/compiler/testdata/slice.ll -+++ b/compiler/testdata/slice.ll -@@ -3,286 +3,270 @@ source_filename = "slice.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden i32 @main.sliceLen(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.sliceLen(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #1 { - entry: - ret i32 %ints.len - } - - ; Function Attrs: nounwind --define hidden i32 @main.sliceCap(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.sliceCap(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #1 { - entry: - ret i32 %ints.cap - } - - ; Function Attrs: nounwind --define hidden i32 @main.sliceElement(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i32 %index, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.sliceElement(ptr %ints.data, i32 %ints.len, i32 %ints.cap, i32 %index, ptr %context) unnamed_addr #1 { - entry: - %.not = icmp ult i32 %index, %ints.len - br i1 %.not, label %lookup.next, label %lookup.throw - - lookup.next: ; preds = %entry -- %0 = getelementptr inbounds i32, i32* %ints.data, i32 %index -- %1 = load i32, i32* %0, align 4 -+ %0 = getelementptr inbounds i32, ptr %ints.data, i32 %index -+ %1 = load i32, ptr %0, align 4 - ret i32 %1 - - lookup.throw: ; preds = %entry -- call void @runtime.lookupPanic(i8* undef) #2 -+ call void @runtime.lookupPanic(ptr undef) #2 - unreachable - } - --declare void @runtime.lookupPanic(i8*) #0 -+declare void @runtime.lookupPanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden { i32*, i32, i32 } @main.sliceAppendValues(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.sliceAppendValues(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #1 { - entry: -- %varargs = call i8* @runtime.alloc(i32 12, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %varargs, i8* undef) #2 -- %0 = bitcast i8* %varargs to i32* -- store i32 1, i32* %0, align 4 -- %1 = getelementptr inbounds i8, i8* %varargs, i32 4 -- %2 = bitcast i8* %1 to i32* -- store i32 2, i32* %2, align 4 -- %3 = getelementptr inbounds i8, i8* %varargs, i32 8 -- %4 = bitcast i8* %3 to i32* -- store i32 3, i32* %4, align 4 -- %append.srcPtr = bitcast i32* %ints.data to i8* -- %append.new = call { i8*, i32, i32 } @runtime.sliceAppend(i8* %append.srcPtr, i8* nonnull %varargs, i32 %ints.len, i32 %ints.cap, i32 3, i32 4, i8* undef) #2 -- %append.newPtr = extractvalue { i8*, i32, i32 } %append.new, 0 -- %append.newBuf = bitcast i8* %append.newPtr to i32* -- %append.newLen = extractvalue { i8*, i32, i32 } %append.new, 1 -- %append.newCap = extractvalue { i8*, i32, i32 } %append.new, 2 -- %5 = insertvalue { i32*, i32, i32 } undef, i32* %append.newBuf, 0 -- %6 = insertvalue { i32*, i32, i32 } %5, i32 %append.newLen, 1 -- %7 = insertvalue { i32*, i32, i32 } %6, i32 %append.newCap, 2 -- call void @runtime.trackPointer(i8* %append.newPtr, i8* undef) #2 -- ret { i32*, i32, i32 } %7 -+ %varargs = call ptr @runtime.alloc(i32 12, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %varargs, ptr undef) #2 -+ store i32 1, ptr %varargs, align 4 -+ %0 = getelementptr inbounds [3 x i32], ptr %varargs, i32 0, i32 1 -+ store i32 2, ptr %0, align 4 -+ %1 = getelementptr inbounds [3 x i32], ptr %varargs, i32 0, i32 2 -+ store i32 3, ptr %1, align 4 -+ %append.new = call { ptr, i32, i32 } @runtime.sliceAppend(ptr %ints.data, ptr nonnull %varargs, i32 %ints.len, i32 %ints.cap, i32 3, i32 4, ptr undef) #2 -+ %append.newPtr = extractvalue { ptr, i32, i32 } %append.new, 0 -+ %append.newLen = extractvalue { ptr, i32, i32 } %append.new, 1 -+ %append.newCap = extractvalue { ptr, i32, i32 } %append.new, 2 -+ %2 = insertvalue { ptr, i32, i32 } undef, ptr %append.newPtr, 0 -+ %3 = insertvalue { ptr, i32, i32 } %2, i32 %append.newLen, 1 -+ %4 = insertvalue { ptr, i32, i32 } %3, i32 %append.newCap, 2 -+ call void @runtime.trackPointer(ptr %append.newPtr, ptr undef) #2 -+ ret { ptr, i32, i32 } %4 - } - --declare { i8*, i32, i32 } @runtime.sliceAppend(i8*, i8* nocapture readonly, i32, i32, i32, i32, i8*) #0 -+declare { ptr, i32, i32 } @runtime.sliceAppend(ptr, ptr nocapture readonly, i32, i32, i32, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden { i32*, i32, i32 } @main.sliceAppendSlice(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i32* %added.data, i32 %added.len, i32 %added.cap, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.sliceAppendSlice(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %added.data, i32 %added.len, i32 %added.cap, ptr %context) unnamed_addr #1 { - entry: -- %append.srcPtr = bitcast i32* %ints.data to i8* -- %append.srcPtr1 = bitcast i32* %added.data to i8* -- %append.new = call { i8*, i32, i32 } @runtime.sliceAppend(i8* %append.srcPtr, i8* %append.srcPtr1, i32 %ints.len, i32 %ints.cap, i32 %added.len, i32 4, i8* undef) #2 -- %append.newPtr = extractvalue { i8*, i32, i32 } %append.new, 0 -- %append.newBuf = bitcast i8* %append.newPtr to i32* -- %append.newLen = extractvalue { i8*, i32, i32 } %append.new, 1 -- %append.newCap = extractvalue { i8*, i32, i32 } %append.new, 2 -- %0 = insertvalue { i32*, i32, i32 } undef, i32* %append.newBuf, 0 -- %1 = insertvalue { i32*, i32, i32 } %0, i32 %append.newLen, 1 -- %2 = insertvalue { i32*, i32, i32 } %1, i32 %append.newCap, 2 -- call void @runtime.trackPointer(i8* %append.newPtr, i8* undef) #2 -- ret { i32*, i32, i32 } %2 -+ %append.new = call { ptr, i32, i32 } @runtime.sliceAppend(ptr %ints.data, ptr %added.data, i32 %ints.len, i32 %ints.cap, i32 %added.len, i32 4, ptr undef) #2 -+ %append.newPtr = extractvalue { ptr, i32, i32 } %append.new, 0 -+ %append.newLen = extractvalue { ptr, i32, i32 } %append.new, 1 -+ %append.newCap = extractvalue { ptr, i32, i32 } %append.new, 2 -+ %0 = insertvalue { ptr, i32, i32 } undef, ptr %append.newPtr, 0 -+ %1 = insertvalue { ptr, i32, i32 } %0, i32 %append.newLen, 1 -+ %2 = insertvalue { ptr, i32, i32 } %1, i32 %append.newCap, 2 -+ call void @runtime.trackPointer(ptr %append.newPtr, ptr undef) #2 -+ ret { ptr, i32, i32 } %2 - } - - ; Function Attrs: nounwind --define hidden i32 @main.sliceCopy(i32* %dst.data, i32 %dst.len, i32 %dst.cap, i32* %src.data, i32 %src.len, i32 %src.cap, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.sliceCopy(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #1 { - entry: -- %copy.dstPtr = bitcast i32* %dst.data to i8* -- %copy.srcPtr = bitcast i32* %src.data to i8* -- %copy.n = call i32 @runtime.sliceCopy(i8* %copy.dstPtr, i8* %copy.srcPtr, i32 %dst.len, i32 %src.len, i32 4, i8* undef) #2 -+ %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 4, ptr undef) #2 - ret i32 %copy.n - } - --declare i32 @runtime.sliceCopy(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i32, i8*) #0 -+declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden { i8*, i32, i32 } @main.makeByteSlice(i32 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.makeByteSlice(i32 %len, ptr %context) unnamed_addr #1 { - entry: - %slice.maxcap = icmp slt i32 %len, 0 - br i1 %slice.maxcap, label %slice.throw, label %slice.next - - slice.next: ; preds = %entry -- %makeslice.buf = call i8* @runtime.alloc(i32 %len, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- %0 = insertvalue { i8*, i32, i32 } undef, i8* %makeslice.buf, 0 -- %1 = insertvalue { i8*, i32, i32 } %0, i32 %len, 1 -- %2 = insertvalue { i8*, i32, i32 } %1, i32 %len, 2 -- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 -- ret { i8*, i32, i32 } %2 -+ %makeslice.buf = call ptr @runtime.alloc(i32 %len, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 -+ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 -+ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 -+ ret { ptr, i32, i32 } %2 - - slice.throw: ; preds = %entry -- call void @runtime.slicePanic(i8* undef) #2 -+ call void @runtime.slicePanic(ptr undef) #2 - unreachable - } - --declare void @runtime.slicePanic(i8*) #0 -+declare void @runtime.slicePanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden { i16*, i32, i32 } @main.makeInt16Slice(i32 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.makeInt16Slice(i32 %len, ptr %context) unnamed_addr #1 { - entry: - %slice.maxcap = icmp slt i32 %len, 0 - br i1 %slice.maxcap, label %slice.throw, label %slice.next - - slice.next: ; preds = %entry - %makeslice.cap = shl i32 %len, 1 -- %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- %makeslice.array = bitcast i8* %makeslice.buf to i16* -- %0 = insertvalue { i16*, i32, i32 } undef, i16* %makeslice.array, 0 -- %1 = insertvalue { i16*, i32, i32 } %0, i32 %len, 1 -- %2 = insertvalue { i16*, i32, i32 } %1, i32 %len, 2 -- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 -- ret { i16*, i32, i32 } %2 -+ %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 -+ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 -+ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 -+ ret { ptr, i32, i32 } %2 - - slice.throw: ; preds = %entry -- call void @runtime.slicePanic(i8* undef) #2 -+ call void @runtime.slicePanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden { [3 x i8]*, i32, i32 } @main.makeArraySlice(i32 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.makeArraySlice(i32 %len, ptr %context) unnamed_addr #1 { - entry: - %slice.maxcap = icmp ugt i32 %len, 1431655765 - br i1 %slice.maxcap, label %slice.throw, label %slice.next - - slice.next: ; preds = %entry - %makeslice.cap = mul i32 %len, 3 -- %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- %makeslice.array = bitcast i8* %makeslice.buf to [3 x i8]* -- %0 = insertvalue { [3 x i8]*, i32, i32 } undef, [3 x i8]* %makeslice.array, 0 -- %1 = insertvalue { [3 x i8]*, i32, i32 } %0, i32 %len, 1 -- %2 = insertvalue { [3 x i8]*, i32, i32 } %1, i32 %len, 2 -- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 -- ret { [3 x i8]*, i32, i32 } %2 -+ %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 -+ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 -+ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 -+ ret { ptr, i32, i32 } %2 - - slice.throw: ; preds = %entry -- call void @runtime.slicePanic(i8* undef) #2 -+ call void @runtime.slicePanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden { i32*, i32, i32 } @main.makeInt32Slice(i32 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.makeInt32Slice(i32 %len, ptr %context) unnamed_addr #1 { - entry: - %slice.maxcap = icmp ugt i32 %len, 1073741823 - br i1 %slice.maxcap, label %slice.throw, label %slice.next - - slice.next: ; preds = %entry - %makeslice.cap = shl i32 %len, 2 -- %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- %makeslice.array = bitcast i8* %makeslice.buf to i32* -- %0 = insertvalue { i32*, i32, i32 } undef, i32* %makeslice.array, 0 -- %1 = insertvalue { i32*, i32, i32 } %0, i32 %len, 1 -- %2 = insertvalue { i32*, i32, i32 } %1, i32 %len, 2 -- call void @runtime.trackPointer(i8* nonnull %makeslice.buf, i8* undef) #2 -- ret { i32*, i32, i32 } %2 -+ %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 -+ %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 -+ %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr undef) #2 -+ ret { ptr, i32, i32 } %2 - - slice.throw: ; preds = %entry -- call void @runtime.slicePanic(i8* undef) #2 -+ call void @runtime.slicePanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden i8* @main.Add32(i8* %p, i32 %len, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.Add32(ptr %p, i32 %len, ptr %context) unnamed_addr #1 { - entry: -- %0 = getelementptr i8, i8* %p, i32 %len -- call void @runtime.trackPointer(i8* %0, i8* undef) #2 -- ret i8* %0 -+ %0 = getelementptr i8, ptr %p, i32 %len -+ call void @runtime.trackPointer(ptr %0, ptr undef) #2 -+ ret ptr %0 - } - - ; Function Attrs: nounwind --define hidden i8* @main.Add64(i8* %p, i64 %len, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.Add64(ptr %p, i64 %len, ptr %context) unnamed_addr #1 { - entry: - %0 = trunc i64 %len to i32 -- %1 = getelementptr i8, i8* %p, i32 %0 -- call void @runtime.trackPointer(i8* %1, i8* undef) #2 -- ret i8* %1 -+ %1 = getelementptr i8, ptr %p, i32 %0 -+ call void @runtime.trackPointer(ptr %1, ptr undef) #2 -+ ret ptr %1 - } - - ; Function Attrs: nounwind --define hidden [4 x i32]* @main.SliceToArray(i32* %s.data, i32 %s.len, i32 %s.cap, i8* %context) unnamed_addr #1 { -+define hidden ptr @main.SliceToArray(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp ult i32 %s.len, 4 - br i1 %0, label %slicetoarray.throw, label %slicetoarray.next - - slicetoarray.next: ; preds = %entry -- %1 = bitcast i32* %s.data to [4 x i32]* -- ret [4 x i32]* %1 -+ ret ptr %s.data - - slicetoarray.throw: ; preds = %entry -- call void @runtime.sliceToArrayPointerPanic(i8* undef) #2 -+ call void @runtime.sliceToArrayPointerPanic(ptr undef) #2 - unreachable - } - --declare void @runtime.sliceToArrayPointerPanic(i8*) #0 -+declare void @runtime.sliceToArrayPointerPanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden [4 x i32]* @main.SliceToArrayConst(i8* %context) unnamed_addr #1 { -+define hidden ptr @main.SliceToArrayConst(ptr %context) unnamed_addr #1 { - entry: -- %makeslice = call i8* @runtime.alloc(i32 24, i8* nonnull inttoptr (i32 3 to i8*), i8* undef) #2 -- call void @runtime.trackPointer(i8* nonnull %makeslice, i8* undef) #2 -+ %makeslice = call ptr @runtime.alloc(i32 24, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #2 -+ call void @runtime.trackPointer(ptr nonnull %makeslice, ptr undef) #2 - br i1 false, label %slicetoarray.throw, label %slicetoarray.next - - slicetoarray.next: ; preds = %entry -- %0 = bitcast i8* %makeslice to [4 x i32]* -- ret [4 x i32]* %0 -+ ret ptr %makeslice - - slicetoarray.throw: ; preds = %entry - unreachable - } - - ; Function Attrs: nounwind --define hidden { i32*, i32, i32 } @main.SliceInt(i32* dereferenceable_or_null(4) %ptr, i32 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.SliceInt(ptr dereferenceable_or_null(4) %ptr, i32 %len, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp ugt i32 %len, 1073741823 -- %1 = icmp eq i32* %ptr, null -+ %1 = icmp eq ptr %ptr, null - %2 = icmp ne i32 %len, 0 - %3 = and i1 %1, %2 - %4 = or i1 %3, %0 - br i1 %4, label %unsafe.Slice.throw, label %unsafe.Slice.next - - unsafe.Slice.next: ; preds = %entry -- %5 = insertvalue { i32*, i32, i32 } undef, i32* %ptr, 0 -- %6 = insertvalue { i32*, i32, i32 } %5, i32 %len, 1 -- %7 = insertvalue { i32*, i32, i32 } %6, i32 %len, 2 -- %8 = bitcast i32* %ptr to i8* -- call void @runtime.trackPointer(i8* %8, i8* undef) #2 -- ret { i32*, i32, i32 } %7 -+ %5 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 -+ %6 = insertvalue { ptr, i32, i32 } %5, i32 %len, 1 -+ %7 = insertvalue { ptr, i32, i32 } %6, i32 %len, 2 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ ret { ptr, i32, i32 } %7 - - unsafe.Slice.throw: ; preds = %entry -- call void @runtime.unsafeSlicePanic(i8* undef) #2 -+ call void @runtime.unsafeSlicePanic(ptr undef) #2 - unreachable - } - --declare void @runtime.unsafeSlicePanic(i8*) #0 -+declare void @runtime.unsafeSlicePanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden { i8*, i32, i32 } @main.SliceUint16(i8* dereferenceable_or_null(1) %ptr, i16 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.SliceUint16(ptr dereferenceable_or_null(1) %ptr, i16 %len, ptr %context) unnamed_addr #1 { - entry: -- %0 = icmp eq i8* %ptr, null -+ %0 = icmp eq ptr %ptr, null - %1 = icmp ne i16 %len, 0 - %2 = and i1 %0, %1 - br i1 %2, label %unsafe.Slice.throw, label %unsafe.Slice.next - - unsafe.Slice.next: ; preds = %entry - %3 = zext i16 %len to i32 -- %4 = insertvalue { i8*, i32, i32 } undef, i8* %ptr, 0 -- %5 = insertvalue { i8*, i32, i32 } %4, i32 %3, 1 -- %6 = insertvalue { i8*, i32, i32 } %5, i32 %3, 2 -- call void @runtime.trackPointer(i8* %ptr, i8* undef) #2 -- ret { i8*, i32, i32 } %6 -+ %4 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 -+ %5 = insertvalue { ptr, i32, i32 } %4, i32 %3, 1 -+ %6 = insertvalue { ptr, i32, i32 } %5, i32 %3, 2 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ ret { ptr, i32, i32 } %6 - - unsafe.Slice.throw: ; preds = %entry -- call void @runtime.unsafeSlicePanic(i8* undef) #2 -+ call void @runtime.unsafeSlicePanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden { i32*, i32, i32 } @main.SliceUint64(i32* dereferenceable_or_null(4) %ptr, i64 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.SliceUint64(ptr dereferenceable_or_null(4) %ptr, i64 %len, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp ugt i64 %len, 1073741823 -- %1 = icmp eq i32* %ptr, null -+ %1 = icmp eq ptr %ptr, null - %2 = icmp ne i64 %len, 0 - %3 = and i1 %1, %2 - %4 = or i1 %3, %0 -@@ -290,23 +274,22 @@ entry: - - unsafe.Slice.next: ; preds = %entry - %5 = trunc i64 %len to i32 -- %6 = insertvalue { i32*, i32, i32 } undef, i32* %ptr, 0 -- %7 = insertvalue { i32*, i32, i32 } %6, i32 %5, 1 -- %8 = insertvalue { i32*, i32, i32 } %7, i32 %5, 2 -- %9 = bitcast i32* %ptr to i8* -- call void @runtime.trackPointer(i8* %9, i8* undef) #2 -- ret { i32*, i32, i32 } %8 -+ %6 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 -+ %7 = insertvalue { ptr, i32, i32 } %6, i32 %5, 1 -+ %8 = insertvalue { ptr, i32, i32 } %7, i32 %5, 2 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ ret { ptr, i32, i32 } %8 - - unsafe.Slice.throw: ; preds = %entry -- call void @runtime.unsafeSlicePanic(i8* undef) #2 -+ call void @runtime.unsafeSlicePanic(ptr undef) #2 - unreachable - } - - ; Function Attrs: nounwind --define hidden { i32*, i32, i32 } @main.SliceInt64(i32* dereferenceable_or_null(4) %ptr, i64 %len, i8* %context) unnamed_addr #1 { -+define hidden { ptr, i32, i32 } @main.SliceInt64(ptr dereferenceable_or_null(4) %ptr, i64 %len, ptr %context) unnamed_addr #1 { - entry: - %0 = icmp ugt i64 %len, 1073741823 -- %1 = icmp eq i32* %ptr, null -+ %1 = icmp eq ptr %ptr, null - %2 = icmp ne i64 %len, 0 - %3 = and i1 %1, %2 - %4 = or i1 %3, %0 -@@ -314,15 +297,14 @@ entry: - - unsafe.Slice.next: ; preds = %entry - %5 = trunc i64 %len to i32 -- %6 = insertvalue { i32*, i32, i32 } undef, i32* %ptr, 0 -- %7 = insertvalue { i32*, i32, i32 } %6, i32 %5, 1 -- %8 = insertvalue { i32*, i32, i32 } %7, i32 %5, 2 -- %9 = bitcast i32* %ptr to i8* -- call void @runtime.trackPointer(i8* %9, i8* undef) #2 -- ret { i32*, i32, i32 } %8 -+ %6 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 -+ %7 = insertvalue { ptr, i32, i32 } %6, i32 %5, 1 -+ %8 = insertvalue { ptr, i32, i32 } %7, i32 %5, 2 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ ret { ptr, i32, i32 } %8 - - unsafe.Slice.throw: ; preds = %entry -- call void @runtime.unsafeSlicePanic(i8* undef) #2 -+ call void @runtime.unsafeSlicePanic(ptr undef) #2 - unreachable - } - -diff --git a/compiler/testdata/string.ll b/compiler/testdata/string.ll -index 5e1f924c..bd3b8f5a 100644 ---- a/compiler/testdata/string.ll -+++ b/compiler/testdata/string.ll -@@ -3,96 +3,96 @@ source_filename = "string.go" - target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" - target triple = "wasm32-unknown-wasi" - --%runtime._string = type { i8*, i32 } -+%runtime._string = type { ptr, i32 } - - @"main$string" = internal unnamed_addr constant [3 x i8] c"foo", align 1 - --declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) #0 -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 - --declare void @runtime.trackPointer(i8* nocapture readonly, i8*) #0 -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 - - ; Function Attrs: nounwind --define hidden void @main.init(i8* %context) unnamed_addr #1 { -+define hidden void @main.init(ptr %context) unnamed_addr #1 { - entry: - ret void - } - - ; Function Attrs: nounwind --define hidden %runtime._string @main.someString(i8* %context) unnamed_addr #1 { -+define hidden %runtime._string @main.someString(ptr %context) unnamed_addr #1 { - entry: -- ret %runtime._string { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"main$string", i32 0, i32 0), i32 3 } -+ ret %runtime._string { ptr @"main$string", i32 3 } - } - - ; Function Attrs: nounwind --define hidden %runtime._string @main.zeroLengthString(i8* %context) unnamed_addr #1 { -+define hidden %runtime._string @main.zeroLengthString(ptr %context) unnamed_addr #1 { - entry: - ret %runtime._string zeroinitializer - } - - ; Function Attrs: nounwind --define hidden i32 @main.stringLen(i8* %s.data, i32 %s.len, i8* %context) unnamed_addr #1 { -+define hidden i32 @main.stringLen(ptr %s.data, i32 %s.len, ptr %context) unnamed_addr #1 { - entry: - ret i32 %s.len - } - - ; Function Attrs: nounwind --define hidden i8 @main.stringIndex(i8* %s.data, i32 %s.len, i32 %index, i8* %context) unnamed_addr #1 { -+define hidden i8 @main.stringIndex(ptr %s.data, i32 %s.len, i32 %index, ptr %context) unnamed_addr #1 { - entry: - %.not = icmp ult i32 %index, %s.len - br i1 %.not, label %lookup.next, label %lookup.throw - - lookup.next: ; preds = %entry -- %0 = getelementptr inbounds i8, i8* %s.data, i32 %index -- %1 = load i8, i8* %0, align 1 -+ %0 = getelementptr inbounds i8, ptr %s.data, i32 %index -+ %1 = load i8, ptr %0, align 1 - ret i8 %1 - - lookup.throw: ; preds = %entry -- call void @runtime.lookupPanic(i8* undef) #2 -+ call void @runtime.lookupPanic(ptr undef) #2 - unreachable - } - --declare void @runtime.lookupPanic(i8*) #0 -+declare void @runtime.lookupPanic(ptr) #0 - - ; Function Attrs: nounwind --define hidden i1 @main.stringCompareEqual(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.stringCompareEqual(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* undef) #2 -+ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr undef) #2 - ret i1 %0 - } - --declare i1 @runtime.stringEqual(i8*, i32, i8*, i32, i8*) #0 -+declare i1 @runtime.stringEqual(ptr, i32, ptr, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden i1 @main.stringCompareUnequal(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.stringCompareUnequal(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* undef) #2 -+ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr undef) #2 - %1 = xor i1 %0, true - ret i1 %1 - } - - ; Function Attrs: nounwind --define hidden i1 @main.stringCompareLarger(i8* %s1.data, i32 %s1.len, i8* %s2.data, i32 %s2.len, i8* %context) unnamed_addr #1 { -+define hidden i1 @main.stringCompareLarger(ptr %s1.data, i32 %s1.len, ptr %s2.data, i32 %s2.len, ptr %context) unnamed_addr #1 { - entry: -- %0 = call i1 @runtime.stringLess(i8* %s2.data, i32 %s2.len, i8* %s1.data, i32 %s1.len, i8* undef) #2 -+ %0 = call i1 @runtime.stringLess(ptr %s2.data, i32 %s2.len, ptr %s1.data, i32 %s1.len, ptr undef) #2 - ret i1 %0 - } - --declare i1 @runtime.stringLess(i8*, i32, i8*, i32, i8*) #0 -+declare i1 @runtime.stringLess(ptr, i32, ptr, i32, ptr) #0 - - ; Function Attrs: nounwind --define hidden i8 @main.stringLookup(i8* %s.data, i32 %s.len, i8 %x, i8* %context) unnamed_addr #1 { -+define hidden i8 @main.stringLookup(ptr %s.data, i32 %s.len, i8 %x, ptr %context) unnamed_addr #1 { - entry: - %0 = zext i8 %x to i32 - %.not = icmp ult i32 %0, %s.len - br i1 %.not, label %lookup.next, label %lookup.throw - - lookup.next: ; preds = %entry -- %1 = getelementptr inbounds i8, i8* %s.data, i32 %0 -- %2 = load i8, i8* %1, align 1 -+ %1 = getelementptr inbounds i8, ptr %s.data, i32 %0 -+ %2 = load i8, ptr %1, align 1 - ret i8 %2 - - lookup.throw: ; preds = %entry -- call void @runtime.lookupPanic(i8* undef) #2 -+ call void @runtime.lookupPanic(ptr undef) #2 - unreachable - } - -diff --git a/go.mod b/go.mod -index a50f1174..b985effc 100644 ---- a/go.mod -+++ b/go.mod -@@ -17,7 +17,7 @@ require ( - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 - golang.org/x/tools v0.1.11 - gopkg.in/yaml.v2 v2.4.0 -- tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec -+ tinygo.org/x/go-llvm v0.0.0-20220922115213-dcb078a26266 - ) - - require ( -diff --git a/go.sum b/go.sum -index 4af03408..d3180085 100644 ---- a/go.sum -+++ b/go.sum -@@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= - gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= --tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec h1:FYtAFrw/YQPc644uNN65dW50FrEuVNaPBf70x23ApY4= --tinygo.org/x/go-llvm v0.0.0-20220922113433-4b5ad7ff76ec/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -+tinygo.org/x/go-llvm v0.0.0-20220922115213-dcb078a26266 h1:vg4sYKEM+w6epr5S1nXqP/7UhMYcc8nRt7Ohkq28rok= -+tinygo.org/x/go-llvm v0.0.0-20220922115213-dcb078a26266/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -diff --git a/interp/interpreter.go b/interp/interpreter.go -index 83fd2cd9..c61ce7cf 100644 ---- a/interp/interpreter.go -+++ b/interp/interpreter.go -@@ -356,7 +356,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - default: - panic("unknown integer type width") - } -- case strings.HasPrefix(callFn.name, "llvm.memcpy.p0i8.p0i8.") || strings.HasPrefix(callFn.name, "llvm.memmove.p0i8.p0i8."): -+ case strings.HasPrefix(callFn.name, "llvm.memcpy.p0") || strings.HasPrefix(callFn.name, "llvm.memmove.p0"): - // Copy a block of memory from one pointer to another. - dst, err := operands[1].asPointer(r) - if err != nil { -@@ -496,7 +496,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent - typecodeID := typecodeIDBitCast.Operand(0).Initializer() - - // Load the method set, which is part of the typecodeID object. -- methodSet := r.builder.CreateExtractValue(typecodeID, 2, "").Operand(0).Initializer() -+ methodSet := stripPointerCasts(r.builder.CreateExtractValue(typecodeID, 2, "")).Initializer() - - // We don't need to load the interface method set. - -@@ -1095,3 +1095,15 @@ func intPredicateString(predicate llvm.IntPredicate) string { - return "cmp?" - } - } -+ -+// Strip some pointer casts. This is probably unnecessary once support for -+// LLVM 14 (non-opaque pointers) is dropped. -+func stripPointerCasts(value llvm.Value) llvm.Value { -+ if !value.IsAConstantExpr().IsNil() { -+ switch value.Opcode() { -+ case llvm.GetElementPtr, llvm.BitCast: -+ return stripPointerCasts(value.Operand(0)) -+ } -+ } -+ return value -+} -diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go -index cde8e2d9..4e24b923 100644 ---- a/src/runtime/runtime.go -+++ b/src/runtime/runtime.go -@@ -27,18 +27,18 @@ func GOROOT() string { - - // Copy size bytes from src to dst. The memory areas must not overlap. - // This function is implemented by the compiler as a call to a LLVM intrinsic --// like llvm.memcpy.p0i8.p0i8.i32(dst, src, size, false). -+// like llvm.memcpy.p0.p0.i32(dst, src, size, false). - func memcpy(dst, src unsafe.Pointer, size uintptr) - - // Copy size bytes from src to dst. The memory areas may overlap and will do the - // correct thing. - // This function is implemented by the compiler as a call to a LLVM intrinsic --// like llvm.memmove.p0i8.p0i8.i32(dst, src, size, false). -+// like llvm.memmove.p0.p0.i32(dst, src, size, false). - func memmove(dst, src unsafe.Pointer, size uintptr) - - // Set the given number of bytes to zero. - // This function is implemented by the compiler as a call to a LLVM intrinsic --// like llvm.memset.p0i8.i32(ptr, 0, size, false). -+// like llvm.memset.p0.i32(ptr, 0, size, false). - func memzero(ptr unsafe.Pointer, size uintptr) - - // This intrinsic returns the current stack pointer. -diff --git a/targets/esp32c3.json b/targets/esp32c3.json -index d7e3fc71..d377fcec 100644 ---- a/targets/esp32c3.json -+++ b/targets/esp32c3.json -@@ -1,6 +1,6 @@ - { - "inherits": ["riscv32"], -- "features": "+c,+m", -+ "features": "+c,+m,-relax,-save-restore", - "build-tags": ["esp32c3", "esp"], - "serial": "uart", - "rtlib": "compiler-rt", -diff --git a/targets/fe310.json b/targets/fe310.json -index e33308f2..2c9e6b5c 100644 ---- a/targets/fe310.json -+++ b/targets/fe310.json -@@ -1,6 +1,6 @@ - { - "inherits": ["riscv32"], - "cpu": "sifive-e31", -- "features": "+a,+c,+m", -+ "features": "+a,+c,+m,-64bit,-relax,-save-restore", - "build-tags": ["fe310", "sifive"] - } -diff --git a/targets/k210.json b/targets/k210.json -index 41c39f44..cc0d2ed4 100644 ---- a/targets/k210.json -+++ b/targets/k210.json -@@ -1,6 +1,6 @@ - { - "inherits": ["riscv64"], -- "features": "+64bit,+a,+c,+d,+f,+m", -+ "features": "+64bit,+a,+c,+d,+f,+m,-relax,-save-restore", - "build-tags": ["k210", "kendryte"], - "code-model": "medium" - } -diff --git a/targets/riscv-qemu.json b/targets/riscv-qemu.json -index 84050ff6..d55a685c 100644 ---- a/targets/riscv-qemu.json -+++ b/targets/riscv-qemu.json -@@ -1,6 +1,6 @@ - { - "inherits": ["riscv32"], -- "features": "+a,+c,+m", -+ "features": "+a,+c,+m,-relax,-save-restore", - "build-tags": ["virt", "qemu"], - "default-stack-size": 4096, - "linkerscript": "targets/riscv-qemu.ld", -diff --git a/transform/interface-lowering.go b/transform/interface-lowering.go -index 9e2ffa90..55d1af39 100644 ---- a/transform/interface-lowering.go -+++ b/transform/interface-lowering.go -@@ -305,7 +305,9 @@ func (p *lowerInterfacesPass) addTypeMethods(t *typeInfo, methodSet llvm.Value) - // no methods or methods already read - return - } -- methodSet = methodSet.Operand(0) // get global from GEP -+ if !methodSet.IsAConstantExpr().IsNil() && methodSet.Opcode() == llvm.GetElementPtr { -+ methodSet = methodSet.Operand(0) // get global from GEP, for LLVM 14 (non-opaque pointers) -+ } - - // This type has methods, collect all methods of this type. - t.methodSet = methodSet -diff --git a/transform/interrupt.go b/transform/interrupt.go -index b15ff8a9..043eebb8 100644 ---- a/transform/interrupt.go -+++ b/transform/interrupt.go -@@ -36,9 +36,8 @@ func LowerInterrupts(mod llvm.Module) []error { - handleMap := map[int64][]llvm.Value{} - handleType := mod.GetTypeByName("runtime/interrupt.handle") - if !handleType.IsNil() { -- handlePtrType := llvm.PointerType(handleType, 0) - for global := mod.FirstGlobal(); !global.IsNil(); global = llvm.NextGlobal(global) { -- if global.Type() != handlePtrType { -+ if global.GlobalValueType() != handleType { - continue - } - -diff --git a/transform/llvm.go b/transform/llvm.go -index 7042b32d..045bb050 100644 ---- a/transform/llvm.go -+++ b/transform/llvm.go -@@ -80,6 +80,12 @@ func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) ll - // stripPointerCasts strips instruction pointer casts (getelementptr and - // bitcast) and returns the original value without the casts. - func stripPointerCasts(value llvm.Value) llvm.Value { -+ if !value.IsAConstantExpr().IsNil() { -+ switch value.Opcode() { -+ case llvm.GetElementPtr, llvm.BitCast: -+ return stripPointerCasts(value.Operand(0)) -+ } -+ } - if !value.IsAInstruction().IsNil() { - switch value.InstructionOpcode() { - case llvm.GetElementPtr, llvm.BitCast: -diff --git a/transform/reflect.go b/transform/reflect.go -index 68beba9b..b994df61 100644 ---- a/transform/reflect.go -+++ b/transform/reflect.go -@@ -251,7 +251,10 @@ func LowerReflect(mod llvm.Module) { - // a pointer to a runtime.structField array and therefore a - // bitcast. This global should be erased separately, otherwise - // typecode objects cannot be erased. -- structFields := references.Operand(0) -+ structFields := references -+ if !structFields.IsAConstantExpr().IsNil() && structFields.Opcode() == llvm.BitCast { -+ structFields = structFields.Operand(0) // get global from bitcast, for LLVM 14 compatibility (non-opaque pointers) -+ } - structFields.EraseFromParentAsGlobal() - } - } -@@ -460,7 +463,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int - - // Get the fields this struct type contains. - // The struct number will be the start index of -- structTypeGlobal := state.builder.CreateExtractValue(typecode.Initializer(), 0, "").Operand(0).Initializer() -+ structTypeGlobal := stripPointerCasts(state.builder.CreateExtractValue(typecode.Initializer(), 0, "")).Initializer() - numFields := structTypeGlobal.Type().ArrayLength() - - // The first data that is stored in the struct sidetable is the number of -@@ -483,7 +486,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int - if nameGlobal == llvm.ConstPointerNull(nameGlobal.Type()) { - panic("compiler: no name for this struct field") - } -- fieldNameBytes := getGlobalBytes(nameGlobal.Operand(0), state.builder) -+ fieldNameBytes := getGlobalBytes(stripPointerCasts(nameGlobal), state.builder) - fieldNameNumber := state.getStructNameNumber(fieldNameBytes) - - // See whether this struct field has an associated tag, and if so, -@@ -493,7 +496,7 @@ func (state *typeCodeAssignmentState) getStructTypeNum(typecode llvm.Value) int - tagNumber := 0 - if tagGlobal != llvm.ConstPointerNull(tagGlobal.Type()) { - hasTag = true -- tagBytes := getGlobalBytes(tagGlobal.Operand(0), state.builder) -+ tagBytes := getGlobalBytes(stripPointerCasts(tagGlobal), state.builder) - tagNumber = state.getStructNameNumber(tagBytes) - } - -diff --git a/transform/rtcalls.go b/transform/rtcalls.go -index d70bc626..209e15ae 100644 ---- a/transform/rtcalls.go -+++ b/transform/rtcalls.go -@@ -139,14 +139,13 @@ func OptimizeReflectImplements(mod llvm.Module) { - if call.IsACallInst().IsNil() { - continue - } -- interfaceTypeBitCast := call.Operand(2) -- if interfaceTypeBitCast.IsAConstantExpr().IsNil() || interfaceTypeBitCast.Opcode() != llvm.BitCast { -+ interfaceType := stripPointerCasts(call.Operand(2)) -+ if interfaceType.IsAGlobalVariable().IsNil() { - // The asserted interface is not constant, so can't optimize this - // code. - continue - } - -- interfaceType := interfaceTypeBitCast.Operand(0) - if strings.HasPrefix(interfaceType.Name(), "reflect/types.type:named:") { - // Get the underlying type. - interfaceType = builder.CreateExtractValue(interfaceType.Initializer(), 0, "") --- -2.38.1 - diff --git a/0019-src-runtime-add-xorshift-based-fastrand64.patch b/0019-src-runtime-add-xorshift-based-fastrand64.patch deleted file mode 100644 index 9323d7a..0000000 --- a/0019-src-runtime-add-xorshift-based-fastrand64.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 8686fd42351642868970dacc76519fe6ac3f8fac Mon Sep 17 00:00:00 2001 -From: Damian Gryski -Date: Fri, 6 Jan 2023 20:24:34 -0800 -Subject: [PATCH 19/26] src/runtime: add xorshift-based fastrand64 - -Signed-off-by: Elliott Sales de Andrade ---- - src/runtime/algorithm.go | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/src/runtime/algorithm.go b/src/runtime/algorithm.go -index 15487176..35e2e260 100644 ---- a/src/runtime/algorithm.go -+++ b/src/runtime/algorithm.go -@@ -25,6 +25,22 @@ func xorshift32(x uint32) uint32 { - return x - } - -+// This function is used by hash/maphash. -+func fastrand64() uint64 { -+ xorshift64State = xorshiftMult64(xorshift64State) -+ return xorshift64State -+} -+ -+var xorshift64State uint64 = 1 -+ -+// 64-bit xorshift multiply rng from http://vigna.di.unimi.it/ftp/papers/xorshift.pdf -+func xorshiftMult64(x uint64) uint64 { -+ x ^= x >> 12 // a -+ x ^= x << 25 // b -+ x ^= x >> 27 // c -+ return x * 2685821657736338717 -+} -+ - // This function is used by hash/maphash. - func memhash(p unsafe.Pointer, seed, s uintptr) uintptr { - if unsafe.Sizeof(uintptr(0)) > 4 { --- -2.38.1 - diff --git a/0020-testing-implement-t.Setenv.patch b/0020-testing-implement-t.Setenv.patch deleted file mode 100644 index 0627c88..0000000 --- a/0020-testing-implement-t.Setenv.patch +++ /dev/null @@ -1,129 +0,0 @@ -From 42d8bf6be8c01504667e858a1b13079956ab53cd Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sat, 14 Jan 2023 19:32:36 +0100 -Subject: [PATCH 20/26] testing: implement t.Setenv - -This method has been added in Go 1.17 and is used in archive/zip -starting with Go 1.20. Therefore, this method is now needed in Go 1.20. - -I've left out the parts that disable parallel execution of tests, -because we don't do that in TinyGo. - -See: -* https://github.com/golang/go/issues/41260 -* https://go-review.googlesource.com/c/go/+/260577 - -Signed-off-by: Elliott Sales de Andrade ---- - src/testing/testing.go | 22 ++++++++++++++ - src/testing/testing_test.go | 57 +++++++++++++++++++++++++++++++++++++ - 2 files changed, 79 insertions(+) - -diff --git a/src/testing/testing.go b/src/testing/testing.go -index a458f267..d5af277e 100644 ---- a/src/testing/testing.go -+++ b/src/testing/testing.go -@@ -117,6 +117,7 @@ type TB interface { - Log(args ...interface{}) - Logf(format string, args ...interface{}) - Name() string -+ Setenv(key, value string) - Skip(args ...interface{}) - SkipNow() - Skipf(format string, args ...interface{}) -@@ -330,6 +331,27 @@ func (c *common) TempDir() string { - return dir - } - -+// Setenv calls os.Setenv(key, value) and uses Cleanup to -+// restore the environment variable to its original value -+// after the test. -+func (c *common) Setenv(key, value string) { -+ prevValue, ok := os.LookupEnv(key) -+ -+ if err := os.Setenv(key, value); err != nil { -+ c.Fatalf("cannot set environment variable: %v", err) -+ } -+ -+ if ok { -+ c.Cleanup(func() { -+ os.Setenv(key, prevValue) -+ }) -+ } else { -+ c.Cleanup(func() { -+ os.Unsetenv(key) -+ }) -+ } -+} -+ - // runCleanup is called at the end of the test. - func (c *common) runCleanup() { - for { -diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go -index 3ab32426..6a8607b2 100644 ---- a/src/testing/testing_test.go -+++ b/src/testing/testing_test.go -@@ -139,3 +139,60 @@ func testTempDir(t *testing.T) { - t.Errorf("unexpected files in TempDir") - } - } -+ -+func TestSetenv(t *testing.T) { -+ tests := []struct { -+ name string -+ key string -+ initialValueExists bool -+ initialValue string -+ newValue string -+ }{ -+ { -+ name: "initial value exists", -+ key: "GO_TEST_KEY_1", -+ initialValueExists: true, -+ initialValue: "111", -+ newValue: "222", -+ }, -+ { -+ name: "initial value exists but empty", -+ key: "GO_TEST_KEY_2", -+ initialValueExists: true, -+ initialValue: "", -+ newValue: "222", -+ }, -+ { -+ name: "initial value is not exists", -+ key: "GO_TEST_KEY_3", -+ initialValueExists: false, -+ initialValue: "", -+ newValue: "222", -+ }, -+ } -+ -+ for _, test := range tests { -+ if test.initialValueExists { -+ if err := os.Setenv(test.key, test.initialValue); err != nil { -+ t.Fatalf("unable to set env: got %v", err) -+ } -+ } else { -+ os.Unsetenv(test.key) -+ } -+ -+ t.Run(test.name, func(t *testing.T) { -+ t.Setenv(test.key, test.newValue) -+ if os.Getenv(test.key) != test.newValue { -+ t.Fatalf("unexpected value after t.Setenv: got %s, want %s", os.Getenv(test.key), test.newValue) -+ } -+ }) -+ -+ got, exists := os.LookupEnv(test.key) -+ if got != test.initialValue { -+ t.Fatalf("unexpected value after t.Setenv cleanup: got %s, want %s", got, test.initialValue) -+ } -+ if exists != test.initialValueExists { -+ t.Fatalf("unexpected value after t.Setenv cleanup: got %t, want %t", exists, test.initialValueExists) -+ } -+ } -+} --- -2.38.1 - diff --git a/0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch b/0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch deleted file mode 100644 index d349bc6..0000000 --- a/0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch +++ /dev/null @@ -1,255 +0,0 @@ -From adf2a54b66083cbe88ee8bbb695d136f2e90fb58 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 13 Jan 2023 17:52:18 +0000 -Subject: [PATCH 21/26] compiler: add support for new unsafe slice/string - functions - -This adds support for unsafe.SliceData, unsafe.String, and -unsafe.SringData that were introduced in Go 1.20. - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/asserts.go | 11 +++---- - compiler/compiler.go | 40 ++++++++++++++++--------- - compiler/compiler_test.go | 10 +++++++ - compiler/testdata/go1.20.go | 15 ++++++++++ - compiler/testdata/go1.20.ll | 58 +++++++++++++++++++++++++++++++++++++ - src/runtime/panic.go | 7 +++-- - 6 files changed, 120 insertions(+), 21 deletions(-) - create mode 100644 compiler/testdata/go1.20.go - create mode 100644 compiler/testdata/go1.20.ll - -diff --git a/compiler/asserts.go b/compiler/asserts.go -index ba482494..0fb112e0 100644 ---- a/compiler/asserts.go -+++ b/compiler/asserts.go -@@ -89,10 +89,11 @@ func (b *builder) createSliceToArrayPointerCheck(sliceLen llvm.Value, arrayLen i - b.createRuntimeAssert(isLess, "slicetoarray", "sliceToArrayPointerPanic") - } - --// createUnsafeSliceCheck inserts a runtime check used for unsafe.Slice. This --// function must panic if the ptr/len parameters are invalid. --func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, elementType llvm.Type, lenType *types.Basic) { -- // From the documentation of unsafe.Slice: -+// createUnsafeSliceStringCheck inserts a runtime check used for unsafe.Slice -+// and unsafe.String. This function must panic if the ptr/len parameters are -+// invalid. -+func (b *builder) createUnsafeSliceStringCheck(name string, ptr, len llvm.Value, elementType llvm.Type, lenType *types.Basic) { -+ // From the documentation of unsafe.Slice and unsafe.String: - // > At run time, if len is negative, or if ptr is nil and len is not - // > zero, a run-time panic occurs. - // However, in practice, it is also necessary to check that the length is -@@ -117,7 +118,7 @@ func (b *builder) createUnsafeSliceCheck(ptr, len llvm.Value, elementType llvm.T - lenIsNotZero := b.CreateICmp(llvm.IntNE, len, zero, "") - assert := b.CreateAnd(ptrIsNil, lenIsNotZero, "") - assert = b.CreateOr(assert, lenOutOfBounds, "") -- b.createRuntimeAssert(assert, "unsafe.Slice", "unsafeSlicePanic") -+ b.createRuntimeAssert(assert, name, "unsafeSlicePanic") - } - - // createChanBoundsCheck creates a bounds check before creating a new channel to -diff --git a/compiler/compiler.go b/compiler/compiler.go -index 8b6e8661..eda045ab 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -1638,20 +1638,20 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - case "Sizeof": // unsafe.Sizeof - size := b.targetData.TypeAllocSize(argValues[0].Type()) - return llvm.ConstInt(b.uintptrType, size, false), nil -- case "Slice": // unsafe.Slice -- // This creates a slice from a pointer and a length. -+ case "Slice", "String": // unsafe.Slice, unsafe.String -+ // This creates a slice or string from a pointer and a length. - // Note that the exception mentioned in the documentation (if the - // pointer and length are nil, the slice is also nil) is trivially - // already the case. - ptr := argValues[0] - len := argValues[1] -- slice := llvm.Undef(b.ctx.StructType([]llvm.Type{ -- ptr.Type(), -- b.uintptrType, -- b.uintptrType, -- }, false)) -- elementType := b.getLLVMType(argTypes[0].Underlying().(*types.Pointer).Elem()) -- b.createUnsafeSliceCheck(ptr, len, elementType, argTypes[1].Underlying().(*types.Basic)) -+ var elementType llvm.Type -+ if callName == "Slice" { -+ elementType = b.getLLVMType(argTypes[0].Underlying().(*types.Pointer).Elem()) -+ } else { -+ elementType = b.ctx.Int8Type() -+ } -+ b.createUnsafeSliceStringCheck("unsafe."+callName, ptr, len, elementType, argTypes[1].Underlying().(*types.Basic)) - if len.Type().IntTypeWidth() < b.uintptrType.IntTypeWidth() { - // Too small, zero-extend len. - len = b.CreateZExt(len, b.uintptrType, "") -@@ -1659,10 +1659,24 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c - // Too big, truncate len. - len = b.CreateTrunc(len, b.uintptrType, "") - } -- slice = b.CreateInsertValue(slice, ptr, 0, "") -- slice = b.CreateInsertValue(slice, len, 1, "") -- slice = b.CreateInsertValue(slice, len, 2, "") -- return slice, nil -+ if callName == "Slice" { -+ slice := llvm.Undef(b.ctx.StructType([]llvm.Type{ -+ ptr.Type(), -+ b.uintptrType, -+ b.uintptrType, -+ }, false)) -+ slice = b.CreateInsertValue(slice, ptr, 0, "") -+ slice = b.CreateInsertValue(slice, len, 1, "") -+ slice = b.CreateInsertValue(slice, len, 2, "") -+ return slice, nil -+ } else { -+ str := llvm.Undef(b.getLLVMRuntimeType("_string")) -+ str = b.CreateInsertValue(str, argValues[0], 0, "") -+ str = b.CreateInsertValue(str, len, 1, "") -+ return str, nil -+ } -+ case "SliceData", "StringData": // unsafe.SliceData, unsafe.StringData -+ return b.CreateExtractValue(argValues[0], 0, "slice.data"), nil - default: - return llvm.Value{}, b.makeError(pos, "todo: builtin: "+callName) - } -diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index a5cd9c6b..f8221a08 100644 ---- a/compiler/compiler_test.go -+++ b/compiler/compiler_test.go -@@ -9,6 +9,7 @@ import ( - "testing" - - "github.com/tinygo-org/tinygo/compileopts" -+ "github.com/tinygo-org/tinygo/goenv" - "github.com/tinygo-org/tinygo/loader" - "tinygo.org/x/go-llvm" - ) -@@ -27,6 +28,12 @@ type testCase struct { - func TestCompiler(t *testing.T) { - t.Parallel() - -+ // Determine Go minor version (e.g. 16 in go1.16.3). -+ _, goMinor, err := goenv.GetGorootVersion(goenv.Get("GOROOT")) -+ if err != nil { -+ t.Fatal("could not read Go version:", err) -+ } -+ - // Determine which tests to run, depending on the Go and LLVM versions. - tests := []testCase{ - {"basic.go", "", ""}, -@@ -43,6 +50,9 @@ func TestCompiler(t *testing.T) { - {"channel.go", "", ""}, - {"gc.go", "", ""}, - } -+ if goMinor >= 20 { -+ tests = append(tests, testCase{"go1.20.go", "", ""}) -+ } - - for _, tc := range tests { - name := tc.file -diff --git a/compiler/testdata/go1.20.go b/compiler/testdata/go1.20.go -new file mode 100644 -index 00000000..be65363e ---- /dev/null -+++ b/compiler/testdata/go1.20.go -@@ -0,0 +1,15 @@ -+package main -+ -+import "unsafe" -+ -+func unsafeSliceData(s []int) *int { -+ return unsafe.SliceData(s) -+} -+ -+func unsafeString(ptr *byte, len int16) string { -+ return unsafe.String(ptr, len) -+} -+ -+func unsafeStringData(s string) *byte { -+ return unsafe.StringData(s) -+} -diff --git a/compiler/testdata/go1.20.ll b/compiler/testdata/go1.20.ll -new file mode 100644 -index 00000000..fc66b47c ---- /dev/null -+++ b/compiler/testdata/go1.20.ll -@@ -0,0 +1,58 @@ -+; ModuleID = 'go1.20.go' -+source_filename = "go1.20.go" -+target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" -+target triple = "wasm32-unknown-wasi" -+ -+%runtime._string = type { ptr, i32 } -+ -+declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 -+ -+declare void @runtime.trackPointer(ptr nocapture readonly, ptr) #0 -+ -+; Function Attrs: nounwind -+define hidden void @main.init(ptr %context) unnamed_addr #1 { -+entry: -+ ret void -+} -+ -+; Function Attrs: nounwind -+define hidden ptr @main.unsafeSliceData(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #1 { -+entry: -+ call void @runtime.trackPointer(ptr %s.data, ptr undef) #2 -+ ret ptr %s.data -+} -+ -+; Function Attrs: nounwind -+define hidden %runtime._string @main.unsafeString(ptr dereferenceable_or_null(1) %ptr, i16 %len, ptr %context) unnamed_addr #1 { -+entry: -+ %0 = icmp slt i16 %len, 0 -+ %1 = icmp eq ptr %ptr, null -+ %2 = icmp ne i16 %len, 0 -+ %3 = and i1 %1, %2 -+ %4 = or i1 %3, %0 -+ br i1 %4, label %unsafe.String.throw, label %unsafe.String.next -+ -+unsafe.String.next: ; preds = %entry -+ %5 = zext i16 %len to i32 -+ %6 = insertvalue %runtime._string undef, ptr %ptr, 0 -+ %7 = insertvalue %runtime._string %6, i32 %5, 1 -+ call void @runtime.trackPointer(ptr %ptr, ptr undef) #2 -+ ret %runtime._string %7 -+ -+unsafe.String.throw: ; preds = %entry -+ call void @runtime.unsafeSlicePanic(ptr undef) #2 -+ unreachable -+} -+ -+declare void @runtime.unsafeSlicePanic(ptr) #0 -+ -+; Function Attrs: nounwind -+define hidden ptr @main.unsafeStringData(ptr %s.data, i32 %s.len, ptr %context) unnamed_addr #1 { -+entry: -+ call void @runtime.trackPointer(ptr %s.data, ptr undef) #2 -+ ret ptr %s.data -+} -+ -+attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } -+attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } -+attributes #2 = { nounwind } -diff --git a/src/runtime/panic.go b/src/runtime/panic.go -index d7ba9ded..c9c69363 100644 ---- a/src/runtime/panic.go -+++ b/src/runtime/panic.go -@@ -143,10 +143,11 @@ func sliceToArrayPointerPanic() { - runtimePanic("slice smaller than array") - } - --// Panic when calling unsafe.Slice() (Go 1.17+) with a len that's too large --// (which includes if the ptr is nil and len is nonzero). -+// Panic when calling unsafe.Slice() (Go 1.17+) or unsafe.String() (Go 1.20+) -+// with a len that's too large (which includes if the ptr is nil and len is -+// nonzero). - func unsafeSlicePanic() { -- runtimePanic("unsafe.Slice: len out of range") -+ runtimePanic("unsafe.Slice/String: len out of range") - } - - // Panic when trying to create a new channel that is too big. --- -2.38.1 - diff --git a/0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch b/0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch deleted file mode 100644 index 7f4ff02..0000000 --- a/0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch +++ /dev/null @@ -1,35 +0,0 @@ -From c6b1937fefc56c73648ba5339420bd9151e63fc8 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 13 Jan 2023 19:54:05 +0100 -Subject: [PATCH 22/26] runtime: implement math/rand.fastrand64 to fix linker - error - -This is needed for Go 1.20 support. - -Signed-off-by: Elliott Sales de Andrade ---- - src/runtime/algorithm.go | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/src/runtime/algorithm.go b/src/runtime/algorithm.go -index 35e2e260..11b39200 100644 ---- a/src/runtime/algorithm.go -+++ b/src/runtime/algorithm.go -@@ -7,6 +7,14 @@ import ( - "unsafe" - ) - -+// This function is needed by math/rand since Go 1.20. -+// See: https://github.com/golang/go/issues/54880 -+// -+//go:linkname rand_fastrand64 math/rand.fastrand64 -+func rand_fastrand64() uint64 { -+ return fastrand64() -+} -+ - // This function is used by hash/maphash. - func fastrand() uint32 { - xorshift32State = xorshift32(xorshift32State) --- -2.38.1 - diff --git a/0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch b/0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch deleted file mode 100644 index cd73b3f..0000000 --- a/0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 89e962d18b5d85cad8f6ee14c030aaccdcd89728 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 13 Jan 2023 20:02:54 +0100 -Subject: [PATCH 23/26] runtime: implement internal/godebug.setUpdate as a stub - -This function provides a mechanism to watch for changes to the GODEBUG -environment variable. For now, we'll not implement it. It might be -useful in the future, when it can always be added. - -Signed-off-by: Elliott Sales de Andrade ---- - src/runtime/runtime.go | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go -index 4e24b923..c9df6939 100644 ---- a/src/runtime/runtime.go -+++ b/src/runtime/runtime.go -@@ -87,3 +87,9 @@ func LockOSThread() { - // Stub for now - func UnlockOSThread() { - } -+ -+//go:linkname godebug_setUpdate internal/godebug.setUpdate -+func godebug_setUpdate(update func(string, string)) { -+ // Unimplemented. The 'update' function needs to be called whenever the -+ // GODEBUG environment variable changes (for example, via os.Setenv). -+} --- -2.38.1 - diff --git a/0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch b/0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch deleted file mode 100644 index 791d6a8..0000000 --- a/0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch +++ /dev/null @@ -1,136 +0,0 @@ -From cce74aa2f32a29c2dd473b8240680fdc49314486 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sat, 14 Jan 2023 23:10:44 +0100 -Subject: [PATCH 24/26] syscall: implement setenv/unsetenv in the runtime - -This is expected starting with Go 1.20. - -I've also applied the same modification to syscall_libc.go so that -setenv is only called in a single place. - -Signed-off-by: Elliott Sales de Andrade ---- - src/runtime/{env_linux.go => env_unix.go} | 34 +++++++++++++++-------- - src/syscall/syscall_libc.go | 27 ++++-------------- - 2 files changed, 29 insertions(+), 32 deletions(-) - rename src/runtime/{env_linux.go => env_unix.go} (66%) - -diff --git a/src/runtime/env_linux.go b/src/runtime/env_unix.go -similarity index 66% -rename from src/runtime/env_linux.go -rename to src/runtime/env_unix.go -index cfe8c7f8..e05e063a 100644 ---- a/src/runtime/env_linux.go -+++ b/src/runtime/env_unix.go -@@ -1,29 +1,41 @@ --//go:build linux --// +build linux -+//go:build linux || darwin -+// +build linux darwin - - package runtime - - // Update the C environment if cgo is loaded. --// Called from syscall.Setenv. -+// Called from Go 1.20 and above. - // --//go:linkname syscall_setenv_c syscall.setenv_c --func syscall_setenv_c(key string, val string) { -+//go:linkname syscallSetenv syscall.runtimeSetenv -+func syscallSetenv(key, value string) { - keydata := cstring(key) -- valdata := cstring(val) -+ valdata := cstring(value) - // ignore any errors - libc_setenv(&keydata[0], &valdata[0], 1) -- return - } - - // Update the C environment if cgo is loaded. --// Called from syscall.Unsetenv. -+// Called from Go 1.20 and above. - // --//go:linkname syscall_unsetenv_c syscall.unsetenv_c --func syscall_unsetenv_c(key string) { -+//go:linkname syscallUnsetenv syscall.runtimeUnsetenv -+func syscallUnsetenv(key string) { - keydata := cstring(key) - // ignore any errors - libc_unsetenv(&keydata[0]) -- return -+} -+ -+// Compatibility with Go 1.19 and below. -+// -+//go:linkname syscall_setenv_c syscall.setenv_c -+func syscall_setenv_c(key string, val string) { -+ syscallSetenv(key, val) -+} -+ -+// Compatibility with Go 1.19 and below. -+// -+//go:linkname syscall_unsetenv_c syscall.unsetenv_c -+func syscall_unsetenv_c(key string) { -+ syscallUnsetenv(key) - } - - // cstring converts a Go string to a C string. -diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go -index 0f10b7fb..1d3d69c7 100644 ---- a/src/syscall/syscall_libc.go -+++ b/src/syscall/syscall_libc.go -@@ -198,21 +198,12 @@ func Setenv(key, val string) (err error) { - return EINVAL - } - } -- keydata := cstring(key) -- valdata := cstring(val) -- errCode := libc_setenv(&keydata[0], &valdata[0], 1) -- if errCode != 0 { -- err = getErrno() -- } -+ runtimeSetenv(key, val) - return - } - - func Unsetenv(key string) (err error) { -- keydata := cstring(key) -- errCode := libc_unsetenv(&keydata[0]) -- if errCode != 0 { -- err = getErrno() -- } -+ runtimeUnsetenv(key) - return - } - -@@ -313,6 +304,10 @@ func splitSlice(p []byte) (buf *byte, len uintptr) { - return slice.buf, slice.len - } - -+// These two functions are provided by the runtime. -+func runtimeSetenv(key, value string) -+func runtimeUnsetenv(key string) -+ - //export strlen - func libc_strlen(ptr unsafe.Pointer) uintptr - -@@ -326,16 +321,6 @@ func libc_write(fd int32, buf *byte, count uint) int - //export getenv - func libc_getenv(name *byte) *byte - --// int setenv(const char *name, const char *val, int replace); --// --//export setenv --func libc_setenv(name *byte, val *byte, replace int32) int32 -- --// int unsetenv(const char *name); --// --//export unsetenv --func libc_unsetenv(name *byte) int32 -- - // ssize_t read(int fd, void *buf, size_t count); - // - //export read --- -2.38.1 - diff --git a/0025-builder-add-support-for-Go-1.20.patch b/0025-builder-add-support-for-Go-1.20.patch deleted file mode 100644 index ef16562..0000000 --- a/0025-builder-add-support-for-Go-1.20.patch +++ /dev/null @@ -1,139 +0,0 @@ -From 41d29d766af9aa9251560c48f0591c5fa2ad9886 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 13 Jan 2023 17:53:55 +0000 -Subject: [PATCH 25/26] builder: add support for Go 1.20 - -Not all features work yet, but allow it to compile with this Go version. - -Signed-off-by: Elliott Sales de Andrade ---- - .circleci/config.yml | 8 ++++++++ - Makefile | 1 - - builder/config.go | 4 ++-- - cgo/cgo_test.go | 15 +++++++++++---- - cgo/testdata/errors.out.go | 4 ++-- - testdata/stdlib.go | 2 +- - 6 files changed, 24 insertions(+), 10 deletions(-) - -diff --git a/.circleci/config.yml b/.circleci/config.yml -index 38621258..74217b12 100644 ---- a/.circleci/config.yml -+++ b/.circleci/config.yml -@@ -119,6 +119,13 @@ jobs: - - test-linux: - llvm: "14" - resource_class: large -+ test-llvm15-go120: -+ docker: -+ - image: golang:1.20-rc-buster -+ steps: -+ - test-linux: -+ llvm: "15" -+ resource_class: large - - workflows: - test-all: -@@ -126,3 +133,4 @@ workflows: - # This tests our lowest supported versions of Go and LLVM, to make sure at - # least the smoke tests still pass. - - test-llvm14-go118 -+ - test-llvm15-go120 -diff --git a/Makefile b/Makefile -index 89927961..5253900d 100644 ---- a/Makefile -+++ b/Makefile -@@ -280,7 +280,6 @@ TEST_PACKAGES_FAST = \ - container/list \ - container/ring \ - crypto/des \ -- crypto/internal/subtle \ - crypto/md5 \ - crypto/rc4 \ - crypto/sha1 \ -diff --git a/builder/config.go b/builder/config.go -index c55ce1a2..a7df83f1 100644 ---- a/builder/config.go -+++ b/builder/config.go -@@ -33,8 +33,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { - if err != nil { - return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) - } -- if major != 1 || minor < 18 || minor > 19 { -- return nil, fmt.Errorf("requires go version 1.18 through 1.19, got go%d.%d", major, minor) -+ if major != 1 || minor < 18 || minor > 20 { -+ return nil, fmt.Errorf("requires go version 1.18 through 1.20, got go%d.%d", major, minor) - } - - clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) -diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go -index e25da7a1..a44dd8e1 100644 ---- a/cgo/cgo_test.go -+++ b/cgo/cgo_test.go -@@ -11,6 +11,7 @@ import ( - "go/types" - "os" - "path/filepath" -+ "regexp" - "runtime" - "strings" - "testing" -@@ -21,9 +22,15 @@ var flagUpdate = flag.Bool("update", false, "Update images based on test output. - - // normalizeResult normalizes Go source code that comes out of tests across - // platforms and Go versions. --func normalizeResult(result string) string { -- actual := strings.ReplaceAll(result, "\r\n", "\n") -- return actual -+func normalizeResult(t *testing.T, result string) string { -+ result = strings.ReplaceAll(result, "\r\n", "\n") -+ -+ // This changed to 'undefined:', in Go 1.20. -+ result = strings.ReplaceAll(result, ": undeclared name:", ": undefined:") -+ // Go 1.20 added a bit more detail -+ result = regexp.MustCompile(`(unknown field z in struct literal).*`).ReplaceAllString(result, "$1") -+ -+ return result - } - - func TestCGo(t *testing.T) { -@@ -88,7 +95,7 @@ func TestCGo(t *testing.T) { - if err != nil { - t.Errorf("could not write out CGo AST: %v", err) - } -- actual := normalizeResult(buf.String()) -+ actual := normalizeResult(t, buf.String()) - - // Read the file with the expected output, to compare against. - outfile := filepath.Join("testdata", name+".out.go") -diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go -index b15a26b6..716fd771 100644 ---- a/cgo/testdata/errors.out.go -+++ b/cgo/testdata/errors.out.go -@@ -8,9 +8,9 @@ - // Type checking errors after CGo processing: - // testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as C.char value in variable declaration (overflows) - // testdata/errors.go:105: unknown field z in struct literal --// testdata/errors.go:108: undeclared name: C.SOME_CONST_1 -+// testdata/errors.go:108: undefined: C.SOME_CONST_1 - // testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows) --// testdata/errors.go:112: undeclared name: C.SOME_CONST_4 -+// testdata/errors.go:112: undefined: C.SOME_CONST_4 - - package main - -diff --git a/testdata/stdlib.go b/testdata/stdlib.go -index bc59d20c..f051eaf0 100644 ---- a/testdata/stdlib.go -+++ b/testdata/stdlib.go -@@ -24,7 +24,7 @@ func main() { - syscall.Getppid() - - // package math/rand -- fmt.Println("pseudorandom number:", rand.Int31()) -+ fmt.Println("pseudorandom number:", rand.New(rand.NewSource(1)).Int31()) - - // package strings - fmt.Println("strings.IndexByte:", strings.IndexByte("asdf", 'd')) --- -2.38.1 - diff --git a/0026-Skip-archive-zip-tests.patch b/0026-Skip-archive-zip-tests.patch deleted file mode 100644 index 5ee4b93..0000000 --- a/0026-Skip-archive-zip-tests.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 3ab845ff45c17ed5079a1b63e98f217cd0be26aa Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 23 Jan 2023 02:28:27 -0500 -Subject: [PATCH 26/26] Skip archive/zip tests - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/Makefile b/Makefile -index 5253900d..8ac92040 100644 ---- a/Makefile -+++ b/Makefile -@@ -336,7 +336,6 @@ endif - - # Additional standard library packages that pass tests on individual platforms - TEST_PACKAGES_LINUX := \ -- archive/zip \ - compress/lzw \ - crypto/hmac \ - debug/dwarf \ -@@ -352,6 +351,10 @@ TEST_PACKAGES_LINUX += \ - compress/flate \ - testing/fstest - endif -+ifeq ($(filter-out $(shell $(GO) env GOVERSION | cut -f 2 -d.), 18 19), ) -+TEST_PACKAGES_LINUX += \ -+ archive/zip -+endif - - TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) - --- -2.38.1 - diff --git a/sources b/sources index 7f554f3..4290095 100644 --- a/sources +++ b/sources @@ -1,12 +1,13 @@ -SHA512 (tinygo-0.26.0.tar.gz) = 7b95f6b4356545b806207092fa315863446227e3f90d05abad1f231b381d402b00654e11ab79472c32d5572ea7183bdd4e5ee34190a13e3aefa668ebcd1042b4 +SHA512 (tinygo-0.27.0.tar.gz) = b247d799ec99764f34bfd5dff81e0beb454d2b39a178d5618247ba7b9bdf3cc5fd6a20b48be9171168c31a08370ee0c56d76d32925b62fb12789f0ded5b17176 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 SHA512 (compiler-rt-15.0.0.src.tar.xz) = 25763e581c90923260b7c3a03e220feb4cabb2757e418c4940db0eeb6a17f65b35db0c93d3c1e526adad2f6dc93595bec6d99b1bfb4a1bd13a14a0db5301e6cf SHA512 (compiler-rt-15.0.0.src.tar.xz.sig) = 94f39d2e30372ccea4db96c3dd4005a5b44c2bf5d22fa0aaf45b86673ef7d3460884689f97bc96470db2d546042fb01fe3ca41bf22b6323abe0cd785b85d76ef SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 -SHA512 (musl-1.2.0.tar.gz) = 58bd88189a6002356728cea1c6f6605a893fe54f7687595879add4eab283c8692c3b031eb9457ad00d1edd082cfe62fcc0eb5eb1d3bf4f1d749c0efa2a95fec1 -SHA512 (musl-1.2.0.tar.gz.asc) = 1639d1f39f3c587011cc6e1ae44774d20d306f4d18fb394bfa86c40f52af53a882ebd5326553b589a1c5316494b77658dc3310c0187836dfd1fd023ccfedaaf0 +SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c +SHA512 (musl-1.2.3.tar.gz.asc) = 01a857dbc3981c90244d4d1d883efe51986652ca5734a741c9d1a4d06c5a22831e85520ac67212268b70c22049317a8f39b3219be182e7e67741add428ac5bc6 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 -SHA512 (picolibc-f68b8204f797d6b3bfbc7c4da4d257961fbc8770.tar.gz) = fa58a7ddcb1a40239a220ca701a83895804b9ddc837652fa18e9aed2603bba2825df2074e2fa4fbf8649bb9a21308e877850273ec9d421795e2ae549f331ab13 +SHA512 (picolibc-b92edfda8ac6853772d87cadaeeeaa21b78609b6.tar.gz) = 9fb60d81bd98c96264c81e95cab6622ccacb34da285f7f3c137bd3cd8bc6e87cbc065a2e9d9fdfc7b93eec52f33bbfa70b6d0abc1a30551ebec1af351344cc39 SHA512 (wasi-libc-30094b6ed05f19cee102115215863d185f2db4f0.tar.gz) = 17492263fd5dca422f19e0ff8533e1f440e3b7516dc24ef0d16fdc44832cc63ec288c9e930f63b47fb71497144fed55cc313acc74339d067b8d4f5c7c683df0f +SHA512 (mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz) = 723d1ac22d8026f31b59d39328f711f36976798445a82daddcdc9fa6ab4346a5030e9c2efc84ef009439b8f021c5c7c120cfa083a7912a5b0212ac6852c005a7 diff --git a/tinygo.spec b/tinygo.spec index 08d8ed3..6c74cab 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.26.0 +Version: 0.27.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -18,10 +18,11 @@ Version: 0.26.0 %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 -%global musl_version 1.2.0 +%global musl_version 1.2.3 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 -%global picolibc_commit f68b8204f797d6b3bfbc7c4da4d257961fbc8770 +%global picolibc_commit b92edfda8ac6853772d87cadaeeeaa21b78609b6 %global wasi_libc_commit 30094b6ed05f19cee102115215863d185f2db4f0 +%global mingw64_commit 8526cb618269440a94810b94b77f8bd48c5c3396 # No longer matching regular Go's /usr/share/gocode because it also provides # pre-compiled binaries, and symlinks to arch-specific clang headers. @@ -68,49 +69,21 @@ Source7: https://github.com/aykevl/macos-minimal-sdk/archive/%{macos_mins Source8: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz Source9: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz Source10: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz +Source11: https://github.com/mingw-w64/mingw-w64/archive/%{mingw64_commit}/mingw64-%{mingw64_commit}.tar.gz # We don't have wasmtime to run these. Patch0001: 0001-Skip-WASI-tests.patch # Unbundling things -Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch +# Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +Patch0002: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions -Patch0004: 0004-Suggest-optional-packages-to-install-if-missing.patch +Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch # https://github.com/tinygo-org/tinygo/pull/2840 -Patch0005: 0005-Skip-TestDirFS-on-32-bit-systems.patch -Patch0006: 0006-Skip-broken-tests-on-i686.patch - -# Backport patches for LLVM 15 support -# https://github.com/tinygo-org/tinygo/pull/3230 -Patch0007: 0007-wasm-fix-GC-scanning-of-allocas.patch -# https://github.com/tinygo-org/tinygo/pull/3189 -Patch0008: 0008-compiler-return-a-FunctionType-not-a-PointerType-in-.patch -Patch0009: 0009-all-add-type-parameter-to-CreateCall.patch -Patch0010: 0010-all-add-type-parameter-to-CreateLoad.patch -Patch0011: 0011-all-add-type-parameter-to-GEP-calls.patch -Patch0012: 0012-all-replace-llvm.Const-calls-with-builder.Create-cal.patch -Patch0013: 0013-interp-change-object.llvmType-to-the-initializer-typ.patch -Patch0014: 0014-all-remove-pointer-ElementType-calls.patch -Patch0015: 0015-transform-fix-memory-corruption-issues.patch -Patch0016: 0016-riscv-add-target-abi-metadata-flag.patch -Patch0017: 0017-interp-add-support-for-constant-icmp-instructions.patch -Patch0018: 0018-ci-add-support-for-LLVM-15.patch -# Backport patches for Go 1.20 support -# https://github.com/tinygo-org/tinygo/pull/3368 -Patch0019: 0019-src-runtime-add-xorshift-based-fastrand64.patch -# https://github.com/tinygo-org/tinygo/pull/3387 -Patch0020: 0020-testing-implement-t.Setenv.patch -# https://github.com/tinygo-org/tinygo/pull/3391 -Patch0021: 0021-compiler-add-support-for-new-unsafe-slice-string-fun.patch -Patch0022: 0022-runtime-implement-math-rand.fastrand64-to-fix-linker.patch -Patch0023: 0023-runtime-implement-internal-godebug.setUpdate-as-a-st.patch -Patch0024: 0024-syscall-implement-setenv-unsetenv-in-the-runtime.patch -Patch0025: 0025-builder-add-support-for-Go-1.20.patch -# https://github.com/tinygo-org/tinygo/issues/3408 -Patch0026: 0026-Skip-archive-zip-tests.patch +Patch0004: 0004-Skip-TestDirFS-on-32-bit-systems.patch +Patch0005: 0005-Skip-broken-tests-on-i686.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -140,15 +113,13 @@ BuildRequires: golang-tests BuildRequires: llvm-devel(major) = %{clang_llvm_version} BuildRequires: make -BuildRequires: avr-gcc -BuildRequires: avr-libc BuildRequires: binaryen >= 102 # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu BuildRequires: lld -BuildRequires: mingw64-crt -BuildRequires: mingw64-headers +# BuildRequires: mingw64-crt +# BuildRequires: mingw64-headers BuildRequires: nodejs BuildRequires: qemu-system-arm-core BuildRequires: qemu-system-riscv-core @@ -160,12 +131,10 @@ BuildRequires: gnupg2 Requires: clang Requires: golang Requires: lld -Recommends: avr-gcc -Recommends: avr-libc # Add this when LLVM supports ESP natively. # Recommends: esptool -Recommends: mingw64-crt -Recommends: mingw64-headers +# Recommends: mingw64-crt +# Recommends: mingw64-headers Recommends: qemu-system-arm-core Recommends: qemu-system-riscv-core Recommends: qemu-user @@ -229,6 +198,10 @@ tar -C lib -xf %{SOURCE10} rmdir lib/wasi-libc mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc +tar -C lib -xf %{SOURCE11} +rmdir lib/mingw-w64 +mv lib/mingw-w64-%{mingw64_commit} lib/mingw-w64 + # This test is too slow and pretty much freezes. %ifarch %{ix86} sed -i -e 's!archive/zip!$(nil)!' Makefile @@ -266,6 +239,13 @@ install -vpm 0644 lib/CMSIS/CMSIS/Include/* %{buildroot}%{tinygoroot}/lib/CMSIS/ cp -rp lib/compiler-rt-builtins %{buildroot}%{tinygoroot}/lib install -vdm 0755 %{buildroot}%{tinygoroot}/lib/macos-minimal-sdk cp -rp lib/macos-minimal-sdk/* %{buildroot}%{tinygoroot}/lib/macos-minimal-sdk +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common +cp -rp lib/mingw-w64/mingw-w64-crt/def-include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt +cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/api-ms-win-crt-* %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common +cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/kernel32.def.in %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers/defaults +cp -rp lib/mingw-w64/mingw-w64-headers/crt/ %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers +cp -rp lib/mingw-w64/mingw-w64-headers/defaults/include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers/defaults install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl cp -rp lib/musl/COPYRIGHT %{buildroot}%{tinygoroot}/lib/musl cp -rp lib/musl/include %{buildroot}%{tinygoroot}/lib/musl From b3b8eb54cc630d33fd0e9e2e5115b99b9d7714bb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 16 Apr 2023 16:40:31 -0400 Subject: [PATCH 47/78] Add support for LLVM 16 --- 0001-Skip-WASI-tests.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- ...ional-packages-to-install-if-missing.patch | 2 +- 0004-Skip-TestDirFS-on-32-bit-systems.patch | 2 +- 0005-Skip-broken-tests-on-i686.patch | 2 +- ...le-elaborated-typedefs-from-libclang.patch | 42 + 0007-Add-CPU-to-RISCV-targets.patch | 64 + ...rgmemonly-attribute-change-in-LLVM16.patch | 84 + ...transform-tests-with-opaque-pointers.patch | 1722 +++++++++++++++++ ...itch-interp-tests-to-opaque-pointers.patch | 831 ++++++++ ...pdate-types-in-cgo-tests-for-LLVM-16.patch | 200 ++ tinygo.spec | 16 + 12 files changed, 2964 insertions(+), 5 deletions(-) create mode 100644 0006-cgo-Handle-elaborated-typedefs-from-libclang.patch create mode 100644 0007-Add-CPU-to-RISCV-targets.patch create mode 100644 0008-Handle-argmemonly-attribute-change-in-LLVM16.patch create mode 100644 0009-Update-transform-tests-with-opaque-pointers.patch create mode 100644 0010-Switch-interp-tests-to-opaque-pointers.patch create mode 100644 0011-Update-types-in-cgo-tests-for-LLVM-16.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index b1f104f..07b1c20 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From c9fd61dedd6dd52edc9a3058d71923a639e2425f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/5] Skip WASI tests. +Subject: [PATCH 01/11] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index efb1a31..9361e65 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From 620ccf53e2a04f77aaae47a818db9bfef76f3104 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/5] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 02/11] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index d10f646..98e685d 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From eab4bc3acc9b6381b0526049c001d78edc3f6902 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/5] Suggest optional packages to install if missing +Subject: [PATCH 03/11] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-Skip-TestDirFS-on-32-bit-systems.patch b/0004-Skip-TestDirFS-on-32-bit-systems.patch index 189e704..9a6a8e1 100644 --- a/0004-Skip-TestDirFS-on-32-bit-systems.patch +++ b/0004-Skip-TestDirFS-on-32-bit-systems.patch @@ -1,7 +1,7 @@ From 3b851724c839268253ef0c243f379dbef4c0cfd6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 4/5] Skip TestDirFS on 32-bit systems +Subject: [PATCH 04/11] Skip TestDirFS on 32-bit systems Because Seek is not fully implemented there. diff --git a/0005-Skip-broken-tests-on-i686.patch b/0005-Skip-broken-tests-on-i686.patch index 413fa53..3733c2f 100644 --- a/0005-Skip-broken-tests-on-i686.patch +++ b/0005-Skip-broken-tests-on-i686.patch @@ -1,7 +1,7 @@ From f432e01f5d2b8c64f74eeebf30dd428a421ee128 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 5/5] Skip broken tests on i686 +Subject: [PATCH 05/11] Skip broken tests on i686 * compress/flate runs out of memory * testing/fstest uses Seek, which is not implemented there diff --git a/0006-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0006-cgo-Handle-elaborated-typedefs-from-libclang.patch new file mode 100644 index 0000000..8e03381 --- /dev/null +++ b/0006-cgo-Handle-elaborated-typedefs-from-libclang.patch @@ -0,0 +1,42 @@ +From 4d93f7ce0481f884fefeb4a8d3dbb9ca795470d8 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Wed, 12 Apr 2023 04:55:27 -0400 +Subject: [PATCH 06/11] cgo: Handle elaborated typedefs from libclang + +I don't have a reference for this change in LLVM 16, so I just handled +it the same way as other elaborated types. + +Signed-off-by: Elliott Sales de Andrade +--- + cgo/libclang.go | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/cgo/libclang.go b/cgo/libclang.go +index 27ac1b57..95eb554a 100644 +--- a/cgo/libclang.go ++++ b/cgo/libclang.go +@@ -653,6 +653,12 @@ func (p *cgoPackage) addErrorAt(position token.Position, msg string) { + func (f *cgoFile) makeDecayingASTType(typ C.CXType, pos token.Pos) ast.Expr { + // Strip typedefs, if any. + underlyingType := typ ++ if underlyingType.kind == C.CXType_Elaborated { ++ elaboratedType := C.clang_Type_getNamedType(typ) ++ if elaboratedType.kind == C.CXType_Typedef { ++ underlyingType = elaboratedType ++ } ++ } + if underlyingType.kind == C.CXType_Typedef { + c := C.tinygo_clang_getTypeDeclaration(typ) + underlyingType = C.tinygo_clang_getTypedefDeclUnderlyingType(c) +@@ -788,6 +794,8 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr { + return f.makeASTType(underlying, pos) + case C.CXType_Enum: + return f.makeASTType(underlying, pos) ++ case C.CXType_Typedef: ++ return f.makeASTType(underlying, pos) + default: + typeKindSpelling := getString(C.clang_getTypeKindSpelling(underlying.kind)) + f.addError(pos, fmt.Sprintf("unknown elaborated type (libclang type kind %s)", typeKindSpelling)) +-- +2.39.2 + diff --git a/0007-Add-CPU-to-RISCV-targets.patch b/0007-Add-CPU-to-RISCV-targets.patch new file mode 100644 index 0000000..d9c0b92 --- /dev/null +++ b/0007-Add-CPU-to-RISCV-targets.patch @@ -0,0 +1,64 @@ +From 2760ff1337f9311aa806c8b0492cfab1d5f42a64 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Thu, 13 Apr 2023 05:51:10 -0400 +Subject: [PATCH 07/11] Add CPU to RISCV targets + +Signed-off-by: Elliott Sales de Andrade +--- + compileopts/target.go | 7 ++++++- + targets/riscv32.json | 1 + + targets/riscv64.json | 1 + + 3 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/compileopts/target.go b/compileopts/target.go +index 92e9315e..7bab755a 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -14,6 +14,7 @@ import ( + "runtime" + "strings" + ++ "github.com/tinygo-org/tinygo/compiler/llvmutil" + "github.com/tinygo-org/tinygo/goenv" + ) + +@@ -135,7 +136,11 @@ func (spec *TargetSpec) loadFromGivenStr(str string) error { + return err + } + defer fp.Close() +- return spec.load(fp) ++ err = spec.load(fp) ++ if llvmutil.Major() < 16 && (str == "riscv32" || str == "riscv64") { ++ spec.CPU = "" ++ } ++ return err + } + + // resolveInherits loads inherited targets, recursively. +diff --git a/targets/riscv32.json b/targets/riscv32.json +index a2878089..f2be3eab 100644 +--- a/targets/riscv32.json ++++ b/targets/riscv32.json +@@ -1,6 +1,7 @@ + { + "inherits": ["riscv"], + "llvm-target": "riscv32-unknown-none", ++ "cpu": "generic-rv32", + "target-abi": "ilp32", + "build-tags": ["tinygo.riscv32"], + "scheduler": "tasks", +diff --git a/targets/riscv64.json b/targets/riscv64.json +index fc45c91c..8f44ce53 100644 +--- a/targets/riscv64.json ++++ b/targets/riscv64.json +@@ -1,6 +1,7 @@ + { + "inherits": ["riscv"], + "llvm-target": "riscv64-unknown-none", ++ "cpu": "generic-rv64", + "target-abi": "lp64", + "build-tags": ["tinygo.riscv64"], + "cflags": [ +-- +2.39.2 + diff --git a/0008-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0008-Handle-argmemonly-attribute-change-in-LLVM16.patch new file mode 100644 index 0000000..70e97c2 --- /dev/null +++ b/0008-Handle-argmemonly-attribute-change-in-LLVM16.patch @@ -0,0 +1,84 @@ +From 2d93b19a0640af385d9a8f12e9e10252a6b0cf56 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 15 Apr 2023 03:41:21 -0400 +Subject: [PATCH 08/11] Handle argmemonly attribute change in LLVM16 + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/compiler_test.go | 15 ++++++++------- + compiler/testdata/channel.ll | 6 +++--- + 2 files changed, 11 insertions(+), 10 deletions(-) + +diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go +index f8221a08..79dc22e9 100644 +--- a/compiler/compiler_test.go ++++ b/compiler/compiler_test.go +@@ -4,11 +4,11 @@ import ( + "flag" + "go/types" + "os" +- "strconv" + "strings" + "testing" + + "github.com/tinygo-org/tinygo/compileopts" ++ "github.com/tinygo-org/tinygo/compiler/llvmutil" + "github.com/tinygo-org/tinygo/goenv" + "github.com/tinygo-org/tinygo/loader" + "tinygo.org/x/go-llvm" +@@ -191,12 +191,7 @@ func fuzzyEqualIR(s1, s2 string) bool { + // stripped out. + func filterIrrelevantIRLines(lines []string) []string { + var out []string +- llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) +- if err != nil { +- // Note: this should never happen and if it does, it will always happen +- // for a particular build because llvm.Version is a constant. +- panic(err) +- } ++ llvmVersion := llvmutil.Major() + for _, line := range lines { + line = strings.Split(line, ";")[0] // strip out comments/info + line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments +@@ -211,6 +206,12 @@ func filterIrrelevantIRLines(lines []string) []string { + // Right now test outputs are for LLVM 14 and higher. + continue + } ++ if llvmVersion < 16 { ++ if strings.HasSuffix(line, "memory(argmem: readwrite) }") { ++ line = strings.Replace(line, "{ ", "{ argmemonly ", 1) ++ line = strings.Replace(line, "memory(argmem: readwrite) ", "", 1) ++ } ++ } + out = append(out, line) + } + return out +diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll +index 6fdb1407..9cf0882f 100644 +--- a/compiler/testdata/channel.ll ++++ b/compiler/testdata/channel.ll +@@ -30,12 +30,12 @@ entry: + ret void + } + +-; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn ++; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) + declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2 + + declare void @runtime.chanSend(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #0 + +-; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn ++; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) + declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2 + + ; Function Attrs: nounwind +@@ -111,5 +111,5 @@ declare { i32, i1 } @runtime.tryChanSelect(ptr, ptr, i32, i32, ptr) #0 + + attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +-attributes #2 = { argmemonly nocallback nofree nosync nounwind willreturn } ++attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } + attributes #3 = { nounwind } +-- +2.39.2 + diff --git a/0009-Update-transform-tests-with-opaque-pointers.patch b/0009-Update-transform-tests-with-opaque-pointers.patch new file mode 100644 index 0000000..6350f61 --- /dev/null +++ b/0009-Update-transform-tests-with-opaque-pointers.patch @@ -0,0 +1,1722 @@ +From 7bf36c8dbec4488f2b76f85ed48fda6d973d367c Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 16 Mar 2023 19:34:35 +0100 +Subject: [PATCH 09/11] Update transform tests with opaque pointers + +transform: update reflect-implements test to opaque pointers + +transform: update allocs test to opaque pointers + +Also, rename most of the SSA values while we're at it. + +transform: update gc-stackslots test to opaque pointers + +transform: update interface test to opaque pointers + +transform: update interrupt test to opaque pointers + +transform: update maps test to opaque pointers + +transform: update panic test to opaque pointers + +transform: update stacksize test to opaque pointers + +transform: update stringequal test to opaque pointers + +transform: update stringtobytes test to opaque pointers + +transform: update wasm-abi to use opaque pointers +Signed-off-by: Elliott Sales de Andrade +--- + transform/testdata/allocs.ll | 62 ++--- + transform/testdata/allocs.out.ll | 60 ++--- + transform/testdata/gc-stackslots.ll | 125 +++++---- + transform/testdata/gc-stackslots.out.ll | 258 +++++++++---------- + transform/testdata/interface.ll | 40 +-- + transform/testdata/interface.out.ll | 43 ++-- + transform/testdata/interrupt.ll | 37 ++- + transform/testdata/interrupt.out.ll | 27 +- + transform/testdata/maps.ll | 33 +-- + transform/testdata/maps.out.ll | 26 +- + transform/testdata/panic.ll | 10 +- + transform/testdata/panic.out.ll | 10 +- + transform/testdata/reflect-implements.ll | 24 +- + transform/testdata/reflect-implements.out.ll | 24 +- + transform/testdata/stacksize.ll | 10 +- + transform/testdata/stacksize.out.ll | 12 +- + transform/testdata/stringequal.ll | 10 +- + transform/testdata/stringequal.out.ll | 6 +- + transform/testdata/stringtobytes.ll | 26 +- + transform/testdata/stringtobytes.out.ll | 14 +- + transform/testdata/wasm-abi.ll | 10 +- + transform/testdata/wasm-abi.out.ll | 24 +- + 22 files changed, 425 insertions(+), 466 deletions(-) + +diff --git a/transform/testdata/allocs.ll b/transform/testdata/allocs.ll +index 58af2ea8..1c2fdd5a 100644 +--- a/transform/testdata/allocs.ll ++++ b/transform/testdata/allocs.ll +@@ -3,57 +3,51 @@ target triple = "armv7m-none-eabi" + + @runtime.zeroSizedAlloc = internal global i8 0, align 1 + +-declare nonnull i8* @runtime.alloc(i32, i8*) ++declare nonnull ptr @runtime.alloc(i32, ptr) + + ; Test allocating a single int (i32) that should be allocated on the stack. + define void @testInt() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- store i32 5, i32* %2 ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ store i32 5, ptr %alloc + ret void + } + + ; Test allocating an array of 3 i16 values that should be allocated on the + ; stack. + define i16 @testArray() { +- %1 = call i8* @runtime.alloc(i32 6, i8* null) +- %2 = bitcast i8* %1 to i16* +- %3 = getelementptr i16, i16* %2, i32 1 +- store i16 5, i16* %3 +- %4 = getelementptr i16, i16* %2, i32 2 +- %5 = load i16, i16* %4 +- ret i16 %5 ++ %alloc = call ptr @runtime.alloc(i32 6, ptr null) ++ %alloc.1 = getelementptr i16, ptr %alloc, i32 1 ++ store i16 5, ptr %alloc.1 ++ %alloc.2 = getelementptr i16, ptr %alloc, i32 2 ++ %val = load i16, ptr %alloc.2 ++ ret i16 %val + } + + ; Call a function that will let the pointer escape, so the heap-to-stack + ; transform shouldn't be applied. + define void @testEscapingCall() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- %3 = call i32* @escapeIntPtr(i32* %2) ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %val = call ptr @escapeIntPtr(ptr %alloc) + ret void + } + + define void @testEscapingCall2() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- %3 = call i32* @escapeIntPtrSometimes(i32* %2, i32* %2) ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc) + ret void + } + + ; Call a function that doesn't let the pointer escape. + define void @testNonEscapingCall() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- %3 = call i32* @noescapeIntPtr(i32* %2) ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %val = call ptr @noescapeIntPtr(ptr %alloc) + ret void + } + + ; Return the allocated value, which lets it escape. +-define i32* @testEscapingReturn() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- ret i32* %2 ++define ptr @testEscapingReturn() { ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ ret ptr %alloc + } + + ; Do a non-escaping allocation in a loop. +@@ -61,25 +55,23 @@ define void @testNonEscapingLoop() { + entry: + br label %loop + loop: +- %0 = call i8* @runtime.alloc(i32 4, i8* null) +- %1 = bitcast i8* %0 to i32* +- %2 = call i32* @noescapeIntPtr(i32* %1) +- %3 = icmp eq i32* null, %2 +- br i1 %3, label %loop, label %end ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %ptr = call ptr @noescapeIntPtr(ptr %alloc) ++ %result = icmp eq ptr null, %ptr ++ br i1 %result, label %loop, label %end + end: + ret void + } + + ; Test a zero-sized allocation. + define void @testZeroSizedAlloc() { +- %1 = call i8* @runtime.alloc(i32 0, i8* null) +- %2 = bitcast i8* %1 to i32* +- %3 = call i32* @noescapeIntPtr(i32* %2) ++ %alloc = call ptr @runtime.alloc(i32 0, ptr null) ++ %ptr = call ptr @noescapeIntPtr(ptr %alloc) + ret void + } + +-declare i32* @escapeIntPtr(i32*) ++declare ptr @escapeIntPtr(ptr) + +-declare i32* @noescapeIntPtr(i32* nocapture) ++declare ptr @noescapeIntPtr(ptr nocapture) + +-declare i32* @escapeIntPtrSometimes(i32* nocapture, i32*) ++declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr) +diff --git a/transform/testdata/allocs.out.ll b/transform/testdata/allocs.out.ll +index 48f9b768..d1b07e6c 100644 +--- a/transform/testdata/allocs.out.ll ++++ b/transform/testdata/allocs.out.ll +@@ -3,53 +3,47 @@ target triple = "armv7m-none-eabi" + + @runtime.zeroSizedAlloc = internal global i8 0, align 1 + +-declare nonnull i8* @runtime.alloc(i32, i8*) ++declare nonnull ptr @runtime.alloc(i32, ptr) + + define void @testInt() { + %stackalloc.alloca = alloca [4 x i8], align 4 +- store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 +- %stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* +- store i32 5, i32* %stackalloc, align 4 ++ store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4 ++ store i32 5, ptr %stackalloc.alloca, align 4 + ret void + } + + define i16 @testArray() { + %stackalloc.alloca = alloca [6 x i8], align 2 +- store [6 x i8] zeroinitializer, [6 x i8]* %stackalloc.alloca, align 2 +- %stackalloc = bitcast [6 x i8]* %stackalloc.alloca to i16* +- %1 = getelementptr i16, i16* %stackalloc, i32 1 +- store i16 5, i16* %1, align 2 +- %2 = getelementptr i16, i16* %stackalloc, i32 2 +- %3 = load i16, i16* %2, align 2 +- ret i16 %3 ++ store [6 x i8] zeroinitializer, ptr %stackalloc.alloca, align 2 ++ %alloc.1 = getelementptr i16, ptr %stackalloc.alloca, i32 1 ++ store i16 5, ptr %alloc.1, align 2 ++ %alloc.2 = getelementptr i16, ptr %stackalloc.alloca, i32 2 ++ %val = load i16, ptr %alloc.2, align 2 ++ ret i16 %val + } + + define void @testEscapingCall() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- %3 = call i32* @escapeIntPtr(i32* %2) ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %val = call ptr @escapeIntPtr(ptr %alloc) + ret void + } + + define void @testEscapingCall2() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- %3 = call i32* @escapeIntPtrSometimes(i32* %2, i32* %2) ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc) + ret void + } + + define void @testNonEscapingCall() { + %stackalloc.alloca = alloca [4 x i8], align 4 +- store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 +- %stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* +- %1 = call i32* @noescapeIntPtr(i32* %stackalloc) ++ store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4 ++ %val = call ptr @noescapeIntPtr(ptr %stackalloc.alloca) + ret void + } + +-define i32* @testEscapingReturn() { +- %1 = call i8* @runtime.alloc(i32 4, i8* null) +- %2 = bitcast i8* %1 to i32* +- ret i32* %2 ++define ptr @testEscapingReturn() { ++ %alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ ret ptr %alloc + } + + define void @testNonEscapingLoop() { +@@ -58,24 +52,22 @@ entry: + br label %loop + + loop: ; preds = %loop, %entry +- store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 +- %stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* +- %0 = call i32* @noescapeIntPtr(i32* %stackalloc) +- %1 = icmp eq i32* null, %0 +- br i1 %1, label %loop, label %end ++ store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4 ++ %ptr = call ptr @noescapeIntPtr(ptr %stackalloc.alloca) ++ %result = icmp eq ptr null, %ptr ++ br i1 %result, label %loop, label %end + + end: ; preds = %loop + ret void + } + + define void @testZeroSizedAlloc() { +- %1 = bitcast i8* @runtime.zeroSizedAlloc to i32* +- %2 = call i32* @noescapeIntPtr(i32* %1) ++ %ptr = call ptr @noescapeIntPtr(ptr @runtime.zeroSizedAlloc) + ret void + } + +-declare i32* @escapeIntPtr(i32*) ++declare ptr @escapeIntPtr(ptr) + +-declare i32* @noescapeIntPtr(i32* nocapture) ++declare ptr @noescapeIntPtr(ptr nocapture) + +-declare i32* @escapeIntPtrSometimes(i32* nocapture, i32*) ++declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr) +diff --git a/transform/testdata/gc-stackslots.ll b/transform/testdata/gc-stackslots.ll +index c217fb9a..7f196e9b 100644 +--- a/transform/testdata/gc-stackslots.ll ++++ b/transform/testdata/gc-stackslots.ll +@@ -1,101 +1,99 @@ + target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" + target triple = "wasm32-unknown-unknown-wasm" + +-%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 } +- +-@runtime.stackChainStart = external global %runtime.stackChainObject* ++@runtime.stackChainStart = external global ptr + @someGlobal = global i8 3 +-@ptrGlobal = global i8** null ++@ptrGlobal = global ptr null + +-declare void @runtime.trackPointer(i8* nocapture readonly) ++declare void @runtime.trackPointer(ptr nocapture readonly) + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*) ++declare noalias nonnull ptr @runtime.alloc(i32, ptr) + + ; Generic function that returns a pointer (that must be tracked). +-define i8* @getPointer() { +- ret i8* @someGlobal ++define ptr @getPointer() { ++ ret ptr @someGlobal + } + +-define i8* @needsStackSlots() { ++define ptr @needsStackSlots() { + ; Tracked pointer. Although, in this case the value is immediately returned + ; so tracking it is not really necessary. +- %ptr = call i8* @runtime.alloc(i32 4, i8* null) +- call void @runtime.trackPointer(i8* %ptr) ++ %ptr = call ptr @runtime.alloc(i32 4, ptr null) ++ call void @runtime.trackPointer(ptr %ptr) + call void @someArbitraryFunction() +- %val = load i8, i8* @someGlobal +- ret i8* %ptr ++ %val = load i8, ptr @someGlobal ++ ret ptr %ptr + } + + ; Check some edge cases of pointer tracking. +-define i8* @needsStackSlots2() { ++define ptr @needsStackSlots2() { + ; Only one stack slot should be created for this (but at the moment, one is + ; created for each call to runtime.trackPointer). +- %ptr1 = call i8* @getPointer() +- call void @runtime.trackPointer(i8* %ptr1) +- call void @runtime.trackPointer(i8* %ptr1) +- call void @runtime.trackPointer(i8* %ptr1) ++ %ptr1 = call ptr @getPointer() ++ call void @runtime.trackPointer(ptr %ptr1) ++ call void @runtime.trackPointer(ptr %ptr1) ++ call void @runtime.trackPointer(ptr %ptr1) + + ; Create a pointer that does not need to be tracked (but is tracked). +- %ptr2 = getelementptr i8, i8* @someGlobal, i32 0 +- call void @runtime.trackPointer(i8* %ptr2) ++ %ptr2 = getelementptr i8, ptr @someGlobal, i32 0 ++ call void @runtime.trackPointer(ptr %ptr2) + + ; Here is finally the point where an allocation happens. +- %unused = call i8* @runtime.alloc(i32 4, i8* null) +- call void @runtime.trackPointer(i8* %unused) ++ %unused = call ptr @runtime.alloc(i32 4, ptr null) ++ call void @runtime.trackPointer(ptr %unused) + +- ret i8* %ptr1 ++ ret ptr %ptr1 + } + + ; Return a pointer from a caller. Because it doesn't allocate, no stack objects + ; need to be created. +-define i8* @noAllocatingFunction() { +- %ptr = call i8* @getPointer() +- call void @runtime.trackPointer(i8* %ptr) +- ret i8* %ptr ++define ptr @noAllocatingFunction() { ++ %ptr = call ptr @getPointer() ++ call void @runtime.trackPointer(ptr %ptr) ++ ret ptr %ptr + } + +-define i8* @fibNext(i8* %x, i8* %y) { +- %x.val = load i8, i8* %x +- %y.val = load i8, i8* %y ++define ptr @fibNext(ptr %x, ptr %y) { ++ %x.val = load i8, ptr %x ++ %y.val = load i8, ptr %y + %out.val = add i8 %x.val, %y.val +- %out.alloc = call i8* @runtime.alloc(i32 1, i8* null) +- call void @runtime.trackPointer(i8* %out.alloc) +- store i8 %out.val, i8* %out.alloc +- ret i8* %out.alloc ++ %out.alloc = call ptr @runtime.alloc(i32 1, ptr null) ++ call void @runtime.trackPointer(ptr %out.alloc) ++ store i8 %out.val, ptr %out.alloc ++ ret ptr %out.alloc + } + +-define i8* @allocLoop() { ++define ptr @allocLoop() { + entry: +- %entry.x = call i8* @runtime.alloc(i32 1, i8* null) +- call void @runtime.trackPointer(i8* %entry.x) +- %entry.y = call i8* @runtime.alloc(i32 1, i8* null) +- call void @runtime.trackPointer(i8* %entry.y) +- store i8 1, i8* %entry.y ++ %entry.x = call ptr @runtime.alloc(i32 1, ptr null) ++ call void @runtime.trackPointer(ptr %entry.x) ++ %entry.y = call ptr @runtime.alloc(i32 1, ptr null) ++ call void @runtime.trackPointer(ptr %entry.y) ++ store i8 1, ptr %entry.y + br label %loop + + loop: +- %prev.y = phi i8* [ %entry.y, %entry ], [ %prev.x, %loop ] +- %prev.x = phi i8* [ %entry.x, %entry ], [ %next.x, %loop ] +- call void @runtime.trackPointer(i8* %prev.x) +- call void @runtime.trackPointer(i8* %prev.y) +- %next.x = call i8* @fibNext(i8* %prev.x, i8* %prev.y) +- call void @runtime.trackPointer(i8* %next.x) +- %next.x.val = load i8, i8* %next.x ++ %prev.y = phi ptr [ %entry.y, %entry ], [ %prev.x, %loop ] ++ %prev.x = phi ptr [ %entry.x, %entry ], [ %next.x, %loop ] ++ call void @runtime.trackPointer(ptr %prev.x) ++ call void @runtime.trackPointer(ptr %prev.y) ++ %next.x = call ptr @fibNext(ptr %prev.x, ptr %prev.y) ++ call void @runtime.trackPointer(ptr %next.x) ++ %next.x.val = load i8, ptr %next.x + %loop.done = icmp ult i8 40, %next.x.val + br i1 %loop.done, label %end, label %loop + + end: +- ret i8* %next.x ++ ret ptr %next.x + } + +-declare [32 x i8]* @arrayAlloc() ++declare ptr @arrayAlloc() + + define void @testGEPBitcast() { +- %arr = call [32 x i8]* @arrayAlloc() +- %arr.bitcast = getelementptr [32 x i8], [32 x i8]* %arr, i32 0, i32 0 +- call void @runtime.trackPointer(i8* %arr.bitcast) +- %other = call i8* @runtime.alloc(i32 1, i8* null) +- call void @runtime.trackPointer(i8* %other) ++ %arr = call ptr @arrayAlloc() ++ %arr.bitcast = getelementptr [32 x i8], ptr %arr, i32 0, i32 0 ++ call void @runtime.trackPointer(ptr %arr.bitcast) ++ %other = call ptr @runtime.alloc(i32 1, ptr null) ++ call void @runtime.trackPointer(ptr %other) + ret void + } + +@@ -104,18 +102,17 @@ define void @someArbitraryFunction() { + } + + define void @earlyPopRegression() { +- %x.alloc = call i8* @runtime.alloc(i32 4, i8* null) +- call void @runtime.trackPointer(i8* %x.alloc) +- %x = bitcast i8* %x.alloc to i8** ++ %x.alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ call void @runtime.trackPointer(ptr %x.alloc) + ; At this point the pass used to pop the stack chain, resulting in a potential use-after-free during allocAndSave. +- musttail call void @allocAndSave(i8** %x) ++ musttail call void @allocAndSave(ptr %x.alloc) + ret void + } + +-define void @allocAndSave(i8** %x) { +- %y = call i8* @runtime.alloc(i32 4, i8* null) +- call void @runtime.trackPointer(i8* %y) +- store i8* %y, i8** %x +- store i8** %x, i8*** @ptrGlobal ++define void @allocAndSave(ptr %x) { ++ %y = call ptr @runtime.alloc(i32 4, ptr null) ++ call void @runtime.trackPointer(ptr %y) ++ store ptr %y, ptr %x ++ store ptr %x, ptr @ptrGlobal + ret void +-} +\ No newline at end of file ++} +diff --git a/transform/testdata/gc-stackslots.out.ll b/transform/testdata/gc-stackslots.out.ll +index 83d1c841..f80d0c96 100644 +--- a/transform/testdata/gc-stackslots.out.ll ++++ b/transform/testdata/gc-stackslots.out.ll +@@ -1,141 +1,134 @@ + target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" + target triple = "wasm32-unknown-unknown-wasm" + +-%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 } +- +-@runtime.stackChainStart = internal global %runtime.stackChainObject* null ++@runtime.stackChainStart = internal global ptr null + @someGlobal = global i8 3 +-@ptrGlobal = global i8** null ++@ptrGlobal = global ptr null + +-declare void @runtime.trackPointer(i8* nocapture readonly) ++declare void @runtime.trackPointer(ptr nocapture readonly) + +-declare noalias nonnull i8* @runtime.alloc(i32, i8*) ++declare noalias nonnull ptr @runtime.alloc(i32, ptr) + +-define i8* @getPointer() { +- ret i8* @someGlobal ++define ptr @getPointer() { ++ ret ptr @someGlobal + } + +-define i8* @needsStackSlots() { +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 +- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 +- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %ptr = call i8* @runtime.alloc(i32 4, i8* null) +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %ptr, i8** %4, align 4 ++define ptr @needsStackSlots() { ++ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 ++ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 ++ %1 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %1, ptr %2, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %ptr = call ptr @runtime.alloc(i32 4, ptr null) ++ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %ptr, ptr %3, align 4 + call void @someArbitraryFunction() +- %val = load i8, i8* @someGlobal, align 1 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- ret i8* %ptr ++ %val = load i8, ptr @someGlobal, align 1 ++ store ptr %1, ptr @runtime.stackChainStart, align 4 ++ ret ptr %ptr + } + +-define i8* @needsStackSlots2() { +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* } { %runtime.stackChainObject* null, i32 5, i8* null, i8* null, i8* null, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, align 4 +- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %2 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 +- %3 = bitcast { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %ptr1 = call i8* @getPointer() +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 4 +- store i8* %ptr1, i8** %4, align 4 +- %5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 3 +- store i8* %ptr1, i8** %5, align 4 +- %6 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %ptr1, i8** %6, align 4 +- %ptr2 = getelementptr i8, i8* @someGlobal, i32 0 +- %7 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 5 +- store i8* %ptr2, i8** %7, align 4 +- %unused = call i8* @runtime.alloc(i32 4, i8* null) +- %8 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 6 +- store i8* %unused, i8** %8, align 4 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- ret i8* %ptr1 ++define ptr @needsStackSlots2() { ++ %gc.stackobject = alloca { ptr, i32, ptr, ptr, ptr, ptr, ptr }, align 8 ++ store { ptr, i32, ptr, ptr, ptr, ptr, ptr } { ptr null, i32 5, ptr null, ptr null, ptr null, ptr null, ptr null }, ptr %gc.stackobject, align 4 ++ %1 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %2 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %1, ptr %2, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %ptr1 = call ptr @getPointer() ++ %3 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 4 ++ store ptr %ptr1, ptr %3, align 4 ++ %4 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 3 ++ store ptr %ptr1, ptr %4, align 4 ++ %5 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %ptr1, ptr %5, align 4 ++ %ptr2 = getelementptr i8, ptr @someGlobal, i32 0 ++ %6 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 5 ++ store ptr %ptr2, ptr %6, align 4 ++ %unused = call ptr @runtime.alloc(i32 4, ptr null) ++ %7 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 6 ++ store ptr %unused, ptr %7, align 4 ++ store ptr %1, ptr @runtime.stackChainStart, align 4 ++ ret ptr %ptr1 + } + +-define i8* @noAllocatingFunction() { +- %ptr = call i8* @getPointer() +- ret i8* %ptr ++define ptr @noAllocatingFunction() { ++ %ptr = call ptr @getPointer() ++ ret ptr %ptr + } + +-define i8* @fibNext(i8* %x, i8* %y) { +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 +- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 +- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %x.val = load i8, i8* %x, align 1 +- %y.val = load i8, i8* %y, align 1 ++define ptr @fibNext(ptr %x, ptr %y) { ++ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 ++ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 ++ %1 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %1, ptr %2, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %x.val = load i8, ptr %x, align 1 ++ %y.val = load i8, ptr %y, align 1 + %out.val = add i8 %x.val, %y.val +- %out.alloc = call i8* @runtime.alloc(i32 1, i8* null) +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %out.alloc, i8** %4, align 4 +- store i8 %out.val, i8* %out.alloc, align 1 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- ret i8* %out.alloc ++ %out.alloc = call ptr @runtime.alloc(i32 1, ptr null) ++ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %out.alloc, ptr %3, align 4 ++ store i8 %out.val, ptr %out.alloc, align 1 ++ store ptr %1, ptr @runtime.stackChainStart, align 4 ++ ret ptr %out.alloc + } + +-define i8* @allocLoop() { ++define ptr @allocLoop() { + entry: +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* } { %runtime.stackChainObject* null, i32 5, i8* null, i8* null, i8* null, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, align 4 +- %0 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %1 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %0, %runtime.stackChainObject** %1, align 4 +- %2 = bitcast { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %2, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %entry.x = call i8* @runtime.alloc(i32 1, i8* null) +- %3 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %entry.x, i8** %3, align 4 +- %entry.y = call i8* @runtime.alloc(i32 1, i8* null) +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 3 +- store i8* %entry.y, i8** %4, align 4 +- store i8 1, i8* %entry.y, align 1 ++ %gc.stackobject = alloca { ptr, i32, ptr, ptr, ptr, ptr, ptr }, align 8 ++ store { ptr, i32, ptr, ptr, ptr, ptr, ptr } { ptr null, i32 5, ptr null, ptr null, ptr null, ptr null, ptr null }, ptr %gc.stackobject, align 4 ++ %0 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %1 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %0, ptr %1, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %entry.x = call ptr @runtime.alloc(i32 1, ptr null) ++ %2 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %entry.x, ptr %2, align 4 ++ %entry.y = call ptr @runtime.alloc(i32 1, ptr null) ++ %3 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 3 ++ store ptr %entry.y, ptr %3, align 4 ++ store i8 1, ptr %entry.y, align 1 + br label %loop + + loop: ; preds = %loop, %entry +- %prev.y = phi i8* [ %entry.y, %entry ], [ %prev.x, %loop ] +- %prev.x = phi i8* [ %entry.x, %entry ], [ %next.x, %loop ] +- %5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 5 +- store i8* %prev.y, i8** %5, align 4 +- %6 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 4 +- store i8* %prev.x, i8** %6, align 4 +- %next.x = call i8* @fibNext(i8* %prev.x, i8* %prev.y) +- %7 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 6 +- store i8* %next.x, i8** %7, align 4 +- %next.x.val = load i8, i8* %next.x, align 1 ++ %prev.y = phi ptr [ %entry.y, %entry ], [ %prev.x, %loop ] ++ %prev.x = phi ptr [ %entry.x, %entry ], [ %next.x, %loop ] ++ %4 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 5 ++ store ptr %prev.y, ptr %4, align 4 ++ %5 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 4 ++ store ptr %prev.x, ptr %5, align 4 ++ %next.x = call ptr @fibNext(ptr %prev.x, ptr %prev.y) ++ %6 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 6 ++ store ptr %next.x, ptr %6, align 4 ++ %next.x.val = load i8, ptr %next.x, align 1 + %loop.done = icmp ult i8 40, %next.x.val + br i1 %loop.done, label %end, label %loop + + end: ; preds = %loop +- store %runtime.stackChainObject* %0, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- ret i8* %next.x ++ store ptr %0, ptr @runtime.stackChainStart, align 4 ++ ret ptr %next.x + } + +-declare [32 x i8]* @arrayAlloc() ++declare ptr @arrayAlloc() + + define void @testGEPBitcast() { +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8*, i8* } { %runtime.stackChainObject* null, i32 2, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, align 4 +- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %2 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 +- %3 = bitcast { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %arr = call [32 x i8]* @arrayAlloc() +- %arr.bitcast = getelementptr [32 x i8], [32 x i8]* %arr, i32 0, i32 0 +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %arr.bitcast, i8** %4, align 4 +- %other = call i8* @runtime.alloc(i32 1, i8* null) +- %5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, i32 0, i32 3 +- store i8* %other, i8** %5, align 4 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 ++ %gc.stackobject = alloca { ptr, i32, ptr, ptr }, align 8 ++ store { ptr, i32, ptr, ptr } { ptr null, i32 2, ptr null, ptr null }, ptr %gc.stackobject, align 4 ++ %1 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %2 = getelementptr { ptr, i32, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %1, ptr %2, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %arr = call ptr @arrayAlloc() ++ %arr.bitcast = getelementptr [32 x i8], ptr %arr, i32 0, i32 0 ++ %3 = getelementptr { ptr, i32, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %arr.bitcast, ptr %3, align 4 ++ %other = call ptr @runtime.alloc(i32 1, ptr null) ++ %4 = getelementptr { ptr, i32, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 3 ++ store ptr %other, ptr %4, align 4 ++ store ptr %1, ptr @runtime.stackChainStart, align 4 + ret void + } + +@@ -144,35 +137,32 @@ define void @someArbitraryFunction() { + } + + define void @earlyPopRegression() { +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 +- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 +- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %x.alloc = call i8* @runtime.alloc(i32 4, i8* null) +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %x.alloc, i8** %4, align 4 +- %x = bitcast i8* %x.alloc to i8** +- call void @allocAndSave(i8** %x) +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 ++ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 ++ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 ++ %1 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %1, ptr %2, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %x.alloc = call ptr @runtime.alloc(i32 4, ptr null) ++ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %x.alloc, ptr %3, align 4 ++ call void @allocAndSave(ptr %x.alloc) ++ store ptr %1, ptr @runtime.stackChainStart, align 4 + ret void + } + +-define void @allocAndSave(i8** %x) { +- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 +- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 +- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 +- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* +- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 +- %y = call i8* @runtime.alloc(i32 4, i8* null) +- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 +- store i8* %y, i8** %4, align 4 +- store i8* %y, i8** %x, align 4 +- store i8** %x, i8*** @ptrGlobal, align 4 +- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 ++define void @allocAndSave(ptr %x) { ++ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 ++ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 ++ %1 = load ptr, ptr @runtime.stackChainStart, align 4 ++ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 ++ store ptr %1, ptr %2, align 4 ++ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 ++ %y = call ptr @runtime.alloc(i32 4, ptr null) ++ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 ++ store ptr %y, ptr %3, align 4 ++ store ptr %y, ptr %x, align 4 ++ store ptr %x, ptr @ptrGlobal, align 4 ++ store ptr %1, ptr @runtime.stackChainStart, align 4 + ret void + } +diff --git a/transform/testdata/interface.ll b/transform/testdata/interface.ll +index 4d8e818d..4bac5c2d 100644 +--- a/transform/testdata/interface.ll ++++ b/transform/testdata/interface.ll +@@ -1,8 +1,8 @@ + target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7m-none-eabi" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +-%runtime.interfaceMethodInfo = type { i8*, i32 } ++%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } ++%runtime.interfaceMethodInfo = type { ptr, i32 } + + @"reflect/types.type:basic:uint8" = private constant %runtime.typecodeID zeroinitializer + @"reflect/types.typeid:basic:uint8" = external constant i8 +@@ -10,31 +10,31 @@ target triple = "armv7m-none-eabi" + @"reflect/types.type:basic:int" = private constant %runtime.typecodeID zeroinitializer + @"reflect/methods.NeverImplementedMethod()" = linkonce_odr constant i8 0 + @"reflect/methods.Double() int" = linkonce_odr constant i8 0 +-@"Number$methodset" = private constant [1 x %runtime.interfaceMethodInfo] [%runtime.interfaceMethodInfo { i8* @"reflect/methods.Double() int", i32 ptrtoint (i32 (i8*, i8*)* @"(Number).Double$invoke" to i32) }] ++@"Number$methodset" = private constant [1 x %runtime.interfaceMethodInfo] [%runtime.interfaceMethodInfo { ptr @"reflect/methods.Double() int", i32 ptrtoint (i32 (ptr, ptr)* @"(Number).Double$invoke" to i32) }] + @"reflect/types.type:named:Number" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* getelementptr inbounds ([1 x %runtime.interfaceMethodInfo], [1 x %runtime.interfaceMethodInfo]* @"Number$methodset", i32 0, i32 0), %runtime.typecodeID* null, i32 0 } + +-declare i1 @runtime.typeAssert(i32, i8*) ++declare i1 @runtime.typeAssert(i32, ptr) + declare void @runtime.printuint8(i8) + declare void @runtime.printint16(i16) + declare void @runtime.printint32(i32) + declare void @runtime.printptr(i32) + declare void @runtime.printnl() +-declare void @runtime.nilPanic(i8*) ++declare void @runtime.nilPanic(ptr) + + define void @printInterfaces() { +- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:int" to i32), i8* inttoptr (i32 5 to i8*)) +- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), i8* inttoptr (i8 120 to i8*)) +- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32), i8* inttoptr (i32 3 to i8*)) ++ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:int" to i32), ptr inttoptr (i32 5 to ptr)) ++ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:uint8" to i32), ptr inttoptr (i8 120 to ptr)) ++ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:named:Number" to i32), ptr inttoptr (i32 3 to ptr)) + + ret void + } + +-define void @printInterface(i32 %typecode, i8* %value) { ++define void @printInterface(i32 %typecode, ptr %value) { + %isUnmatched = call i1 @Unmatched$typeassert(i32 %typecode) + br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched + + typeswitch.Unmatched: +- %unmatched = ptrtoint i8* %value to i32 ++ %unmatched = ptrtoint ptr %value to i32 + call void @runtime.printptr(i32 %unmatched) + call void @runtime.printnl() + ret void +@@ -44,27 +44,27 @@ typeswitch.notUnmatched: + br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler + + typeswitch.Doubler: +- %doubler.result = call i32 @"Doubler.Double$invoke"(i8* %value, i32 %typecode, i8* undef) ++ %doubler.result = call i32 @"Doubler.Double$invoke"(ptr %value, i32 %typecode, ptr undef) + call void @runtime.printint32(i32 %doubler.result) + ret void + + typeswitch.notDoubler: +- %isByte = call i1 @runtime.typeAssert(i32 %typecode, i8* nonnull @"reflect/types.typeid:basic:uint8") ++ %isByte = call i1 @runtime.typeAssert(i32 %typecode, ptr nonnull @"reflect/types.typeid:basic:uint8") + br i1 %isByte, label %typeswitch.byte, label %typeswitch.notByte + + typeswitch.byte: +- %byte = ptrtoint i8* %value to i8 ++ %byte = ptrtoint ptr %value to i8 + call void @runtime.printuint8(i8 %byte) + call void @runtime.printnl() + ret void + + typeswitch.notByte: + ; this is a type assert that always fails +- %isInt16 = call i1 @runtime.typeAssert(i32 %typecode, i8* nonnull @"reflect/types.typeid:basic:int16") ++ %isInt16 = call i1 @runtime.typeAssert(i32 %typecode, ptr nonnull @"reflect/types.typeid:basic:int16") + br i1 %isInt16, label %typeswitch.int16, label %typeswitch.notInt16 + + typeswitch.int16: +- %int16 = ptrtoint i8* %value to i16 ++ %int16 = ptrtoint ptr %value to i16 + call void @runtime.printint16(i16 %int16) + call void @runtime.printnl() + ret void +@@ -73,18 +73,18 @@ typeswitch.notInt16: + ret void + } + +-define i32 @"(Number).Double"(i32 %receiver, i8* %context) { ++define i32 @"(Number).Double"(i32 %receiver, ptr %context) { + %ret = mul i32 %receiver, 2 + ret i32 %ret + } + +-define i32 @"(Number).Double$invoke"(i8* %receiverPtr, i8* %context) { +- %receiver = ptrtoint i8* %receiverPtr to i32 +- %ret = call i32 @"(Number).Double"(i32 %receiver, i8* undef) ++define i32 @"(Number).Double$invoke"(ptr %receiverPtr, ptr %context) { ++ %receiver = ptrtoint ptr %receiverPtr to i32 ++ %ret = call i32 @"(Number).Double"(i32 %receiver, ptr undef) + ret i32 %ret + } + +-declare i32 @"Doubler.Double$invoke"(i8* %receiver, i32 %typecode, i8* %context) #0 ++declare i32 @"Doubler.Double$invoke"(ptr %receiver, i32 %typecode, ptr %context) #0 + + declare i1 @Doubler$typeassert(i32 %typecode) #1 + +diff --git a/transform/testdata/interface.out.ll b/transform/testdata/interface.out.ll +index 262df210..ef887112 100644 +--- a/transform/testdata/interface.out.ll ++++ b/transform/testdata/interface.out.ll +@@ -1,12 +1,11 @@ + target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7m-none-eabi" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +-%runtime.interfaceMethodInfo = type { i8*, i32 } ++%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } + + @"reflect/types.type:basic:uint8" = private constant %runtime.typecodeID zeroinitializer + @"reflect/types.type:basic:int" = private constant %runtime.typecodeID zeroinitializer +-@"reflect/types.type:named:Number" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } ++@"reflect/types.type:named:Number" = private constant %runtime.typecodeID { ptr @"reflect/types.type:basic:int", i32 0, ptr null, ptr null, i32 0 } + + declare void @runtime.printuint8(i8) + +@@ -18,21 +17,21 @@ declare void @runtime.printptr(i32) + + declare void @runtime.printnl() + +-declare void @runtime.nilPanic(i8*) ++declare void @runtime.nilPanic(ptr) + + define void @printInterfaces() { +- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:int" to i32), i8* inttoptr (i32 5 to i8*)) +- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), i8* inttoptr (i8 120 to i8*)) +- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32), i8* inttoptr (i32 3 to i8*)) ++ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:int" to i32), ptr inttoptr (i32 5 to ptr)) ++ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:uint8" to i32), ptr inttoptr (i8 120 to ptr)) ++ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:named:Number" to i32), ptr inttoptr (i32 3 to ptr)) + ret void + } + +-define void @printInterface(i32 %typecode, i8* %value) { ++define void @printInterface(i32 %typecode, ptr %value) { + %isUnmatched = call i1 @"Unmatched$typeassert"(i32 %typecode) + br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched + + typeswitch.Unmatched: ; preds = %0 +- %unmatched = ptrtoint i8* %value to i32 ++ %unmatched = ptrtoint ptr %value to i32 + call void @runtime.printptr(i32 %unmatched) + call void @runtime.printnl() + ret void +@@ -42,16 +41,16 @@ typeswitch.notUnmatched: ; preds = %0 + br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler + + typeswitch.Doubler: ; preds = %typeswitch.notUnmatched +- %doubler.result = call i32 @"Doubler.Double$invoke"(i8* %value, i32 %typecode, i8* undef) ++ %doubler.result = call i32 @"Doubler.Double$invoke"(ptr %value, i32 %typecode, ptr undef) + call void @runtime.printint32(i32 %doubler.result) + ret void + + typeswitch.notDoubler: ; preds = %typeswitch.notUnmatched +- %typeassert.ok = icmp eq i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), %typecode ++ %typeassert.ok = icmp eq i32 ptrtoint (ptr @"reflect/types.type:basic:uint8" to i32), %typecode + br i1 %typeassert.ok, label %typeswitch.byte, label %typeswitch.notByte + + typeswitch.byte: ; preds = %typeswitch.notDoubler +- %byte = ptrtoint i8* %value to i8 ++ %byte = ptrtoint ptr %value to i8 + call void @runtime.printuint8(i8 %byte) + call void @runtime.printnl() + ret void +@@ -60,7 +59,7 @@ typeswitch.notByte: ; preds = %typeswitch.notDoubl + br i1 false, label %typeswitch.int16, label %typeswitch.notInt16 + + typeswitch.int16: ; preds = %typeswitch.notByte +- %int16 = ptrtoint i8* %value to i16 ++ %int16 = ptrtoint ptr %value to i16 + call void @runtime.printint16(i16 %int16) + call void @runtime.printnl() + ret void +@@ -69,34 +68,34 @@ typeswitch.notInt16: ; preds = %typeswitch.notByte + ret void + } + +-define i32 @"(Number).Double"(i32 %receiver, i8* %context) { ++define i32 @"(Number).Double"(i32 %receiver, ptr %context) { + %ret = mul i32 %receiver, 2 + ret i32 %ret + } + +-define i32 @"(Number).Double$invoke"(i8* %receiverPtr, i8* %context) { +- %receiver = ptrtoint i8* %receiverPtr to i32 +- %ret = call i32 @"(Number).Double"(i32 %receiver, i8* undef) ++define i32 @"(Number).Double$invoke"(ptr %receiverPtr, ptr %context) { ++ %receiver = ptrtoint ptr %receiverPtr to i32 ++ %ret = call i32 @"(Number).Double"(i32 %receiver, ptr undef) + ret i32 %ret + } + +-define internal i32 @"Doubler.Double$invoke"(i8* %receiver, i32 %actualType, i8* %context) unnamed_addr #0 { ++define internal i32 @"Doubler.Double$invoke"(ptr %receiver, i32 %actualType, ptr %context) unnamed_addr #0 { + entry: +- %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32) ++ %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (ptr @"reflect/types.type:named:Number" to i32) + br i1 %"named:Number.icmp", label %"named:Number", label %"named:Number.next" + + "named:Number": ; preds = %entry +- %0 = call i32 @"(Number).Double$invoke"(i8* %receiver, i8* undef) ++ %0 = call i32 @"(Number).Double$invoke"(ptr %receiver, ptr undef) + ret i32 %0 + + "named:Number.next": ; preds = %entry +- call void @runtime.nilPanic(i8* undef) ++ call void @runtime.nilPanic(ptr undef) + unreachable + } + + define internal i1 @"Doubler$typeassert"(i32 %actualType) unnamed_addr #1 { + entry: +- %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32) ++ %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (ptr @"reflect/types.type:named:Number" to i32) + br i1 %"named:Number.icmp", label %then, label %"named:Number.next" + + then: ; preds = %entry +diff --git a/transform/testdata/interrupt.ll b/transform/testdata/interrupt.ll +index 1436827b..f4d2e022 100644 +--- a/transform/testdata/interrupt.ll ++++ b/transform/testdata/interrupt.ll +@@ -1,39 +1,39 @@ + target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7em-none-eabi" + +-%machine.UART = type { %machine.RingBuffer* } ++%machine.UART = type { ptr } + %machine.RingBuffer = type { [128 x %"runtime/volatile.Register8"], %"runtime/volatile.Register8", %"runtime/volatile.Register8" } + %"runtime/volatile.Register8" = type { i8 } +-%"runtime/interrupt.handle" = type { i8*, i32, %"runtime/interrupt.Interrupt" } ++%"runtime/interrupt.handle" = type { ptr, i32, %"runtime/interrupt.Interrupt" } + %"runtime/interrupt.Interrupt" = type { i32 } + +-@"runtime/interrupt.$interrupt2" = private unnamed_addr constant %"runtime/interrupt.handle" { i8* bitcast (%machine.UART* @machine.UART0 to i8*), i32 ptrtoint (void (i32, i8*)* @"(*machine.UART).handleInterrupt$bound" to i32), %"runtime/interrupt.Interrupt" { i32 2 } } +-@machine.UART0 = internal global %machine.UART { %machine.RingBuffer* @"machine$alloc.335" } ++@"runtime/interrupt.$interrupt2" = private unnamed_addr constant %"runtime/interrupt.handle" { ptr @machine.UART0, i32 ptrtoint (ptr @"(*machine.UART).handleInterrupt$bound" to i32), %"runtime/interrupt.Interrupt" { i32 2 } } ++@machine.UART0 = internal global %machine.UART { ptr @"machine$alloc.335" } + @"machine$alloc.335" = internal global %machine.RingBuffer zeroinitializer + +-declare void @"runtime/interrupt.callHandlers"(i32, i8*) local_unnamed_addr ++declare void @"runtime/interrupt.callHandlers"(i32, ptr) local_unnamed_addr + +-declare void @"device/arm.EnableIRQ"(i32, i8* nocapture readnone) ++declare void @"device/arm.EnableIRQ"(i32, ptr nocapture readnone) + +-declare void @"device/arm.SetPriority"(i32, i32, i8* nocapture readnone) ++declare void @"device/arm.SetPriority"(i32, i32, ptr nocapture readnone) + + declare void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt") + +-define void @runtime.initAll(i8* nocapture readnone) unnamed_addr { ++define void @runtime.initAll(ptr nocapture readnone) unnamed_addr { + entry: +- call void @"device/arm.SetPriority"(i32 ptrtoint (%"runtime/interrupt.handle"* @"runtime/interrupt.$interrupt2" to i32), i32 192, i8* undef) +- call void @"device/arm.EnableIRQ"(i32 ptrtoint (%"runtime/interrupt.handle"* @"runtime/interrupt.$interrupt2" to i32), i8* undef) +- call void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt" { i32 ptrtoint (%"runtime/interrupt.handle"* @"runtime/interrupt.$interrupt2" to i32) }) ++ call void @"device/arm.SetPriority"(i32 ptrtoint (ptr @"runtime/interrupt.$interrupt2" to i32), i32 192, ptr undef) ++ call void @"device/arm.EnableIRQ"(i32 ptrtoint (ptr @"runtime/interrupt.$interrupt2" to i32), ptr undef) ++ call void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt" { i32 ptrtoint (ptr @"runtime/interrupt.$interrupt2" to i32) }) + ret void + } + + define void @UARTE0_UART0_IRQHandler() { +- call void @"runtime/interrupt.callHandlers"(i32 2, i8* undef) ++ call void @"runtime/interrupt.callHandlers"(i32 2, ptr undef) + ret void + } + + define void @NFCT_IRQHandler() { +- call void @"runtime/interrupt.callHandlers"(i32 5, i8* undef) ++ call void @"runtime/interrupt.callHandlers"(i32 5, ptr undef) + ret void + } + +@@ -45,22 +45,21 @@ entry: + ] + + switch.body2: +- call void @"runtime/interrupt.callHandlers"(i32 2, i8* undef) ++ call void @"runtime/interrupt.callHandlers"(i32 2, ptr undef) + ret void + + switch.body5: +- call void @"runtime/interrupt.callHandlers"(i32 5, i8* undef) ++ call void @"runtime/interrupt.callHandlers"(i32 5, ptr undef) + ret void + + switch.done: + ret void + } + +-define internal void @"(*machine.UART).handleInterrupt$bound"(i32, i8* nocapture %context) { ++define internal void @"(*machine.UART).handleInterrupt$bound"(i32, ptr nocapture %context) { + entry: +- %unpack.ptr = bitcast i8* %context to %machine.UART* +- call void @"(*machine.UART).handleInterrupt"(%machine.UART* %unpack.ptr, i32 %0, i8* undef) ++ call void @"(*machine.UART).handleInterrupt"(ptr %context, i32 %0, ptr undef) + ret void + } + +-declare void @"(*machine.UART).handleInterrupt"(%machine.UART* nocapture, i32, i8* nocapture readnone) ++declare void @"(*machine.UART).handleInterrupt"(ptr nocapture, i32, ptr nocapture readnone) +diff --git a/transform/testdata/interrupt.out.ll b/transform/testdata/interrupt.out.ll +index 7eb9f0a8..3663c0a3 100644 +--- a/transform/testdata/interrupt.out.ll ++++ b/transform/testdata/interrupt.out.ll +@@ -1,31 +1,31 @@ + target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7em-none-eabi" + +-%machine.UART = type { %machine.RingBuffer* } ++%machine.UART = type { ptr } + %machine.RingBuffer = type { [128 x %"runtime/volatile.Register8"], %"runtime/volatile.Register8", %"runtime/volatile.Register8" } + %"runtime/volatile.Register8" = type { i8 } + %"runtime/interrupt.Interrupt" = type { i32 } + +-@machine.UART0 = internal global %machine.UART { %machine.RingBuffer* @"machine$alloc.335" } ++@machine.UART0 = internal global %machine.UART { ptr @"machine$alloc.335" } + @"machine$alloc.335" = internal global %machine.RingBuffer zeroinitializer + +-declare void @"runtime/interrupt.callHandlers"(i32, i8*) local_unnamed_addr ++declare void @"runtime/interrupt.callHandlers"(i32, ptr) local_unnamed_addr + +-declare void @"device/arm.EnableIRQ"(i32, i8* nocapture readnone) ++declare void @"device/arm.EnableIRQ"(i32, ptr nocapture readnone) + +-declare void @"device/arm.SetPriority"(i32, i32, i8* nocapture readnone) ++declare void @"device/arm.SetPriority"(i32, i32, ptr nocapture readnone) + + declare void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt") + +-define void @runtime.initAll(i8* nocapture readnone %0) unnamed_addr { ++define void @runtime.initAll(ptr nocapture readnone %0) unnamed_addr { + entry: +- call void @"device/arm.SetPriority"(i32 2, i32 192, i8* undef) +- call void @"device/arm.EnableIRQ"(i32 2, i8* undef) ++ call void @"device/arm.SetPriority"(i32 2, i32 192, ptr undef) ++ call void @"device/arm.EnableIRQ"(i32 2, ptr undef) + ret void + } + + define void @UARTE0_UART0_IRQHandler() { +- call void @"(*machine.UART).handleInterrupt$bound"(i32 2, i8* bitcast (%machine.UART* @machine.UART0 to i8*)) ++ call void @"(*machine.UART).handleInterrupt$bound"(i32 2, ptr @machine.UART0) + ret void + } + +@@ -37,7 +37,7 @@ entry: + ] + + switch.body2: ; preds = %entry +- call void @"(*machine.UART).handleInterrupt$bound"(i32 2, i8* bitcast (%machine.UART* @machine.UART0 to i8*)) ++ call void @"(*machine.UART).handleInterrupt$bound"(i32 2, ptr @machine.UART0) + ret void + + switch.body5: ; preds = %entry +@@ -47,11 +47,10 @@ switch.done: ; preds = %entry + ret void + } + +-define internal void @"(*machine.UART).handleInterrupt$bound"(i32 %0, i8* nocapture %context) { ++define internal void @"(*machine.UART).handleInterrupt$bound"(i32 %0, ptr nocapture %context) { + entry: +- %unpack.ptr = bitcast i8* %context to %machine.UART* +- call void @"(*machine.UART).handleInterrupt"(%machine.UART* %unpack.ptr, i32 %0, i8* undef) ++ call void @"(*machine.UART).handleInterrupt"(ptr %context, i32 %0, ptr undef) + ret void + } + +-declare void @"(*machine.UART).handleInterrupt"(%machine.UART* nocapture, i32, i8* nocapture readnone) ++declare void @"(*machine.UART).handleInterrupt"(ptr nocapture, i32, ptr nocapture readnone) +diff --git a/transform/testdata/maps.ll b/transform/testdata/maps.ll +index 0bf00424..78f6819d 100644 +--- a/transform/testdata/maps.ll ++++ b/transform/testdata/maps.ll +@@ -1,28 +1,25 @@ + target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7m-none-eabi" + +-%runtime.hashmap = type { %runtime.hashmap*, i8*, i32, i8, i8, i8 } +- + @answer = constant [6 x i8] c"answer" + + ; func(keySize, valueSize uint8, sizeHint uintptr) *runtime.hashmap +-declare nonnull %runtime.hashmap* @runtime.hashmapMake(i8, i8, i32) ++declare nonnull ptr @runtime.hashmapMake(i8, i8, i32) + + ; func(map[string]int, string, unsafe.Pointer) +-declare void @runtime.hashmapStringSet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture readonly) ++declare void @runtime.hashmapStringSet(ptr nocapture, ptr, i32, ptr nocapture readonly) + + ; func(map[string]int, string, unsafe.Pointer) +-declare i1 @runtime.hashmapStringGet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture) ++declare i1 @runtime.hashmapStringGet(ptr nocapture, ptr, i32, ptr nocapture) + + define void @testUnused() { + ; create the map +- %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) ++ %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) + ; create the value to be stored + %hashmap.value = alloca i32 +- store i32 42, i32* %hashmap.value ++ store i32 42, ptr %hashmap.value + ; store the value +- %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8* +- call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast) ++ call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) + ret void + } + +@@ -30,26 +27,24 @@ define void @testUnused() { + ; return 42), but isn't at the moment. + define i32 @testReadonly() { + ; create the map +- %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) ++ %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) + + ; create the value to be stored + %hashmap.value = alloca i32 +- store i32 42, i32* %hashmap.value ++ store i32 42, ptr %hashmap.value + + ; store the value +- %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8* +- call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast) ++ call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) + + ; load the value back + %hashmap.value2 = alloca i32 +- %hashmap.value2.bitcast = bitcast i32* %hashmap.value2 to i8* +- %commaOk = call i1 @runtime.hashmapStringGet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value2.bitcast) +- %loadedValue = load i32, i32* %hashmap.value2 ++ %commaOk = call i1 @runtime.hashmapStringGet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value2) ++ %loadedValue = load i32, ptr %hashmap.value2 + + ret i32 %loadedValue + } + +-define %runtime.hashmap* @testUsed() { +- %1 = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) +- ret %runtime.hashmap* %1 ++define ptr @testUsed() { ++ %1 = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) ++ ret ptr %1 + } +diff --git a/transform/testdata/maps.out.ll b/transform/testdata/maps.out.ll +index 81f9bada..1bd07439 100644 +--- a/transform/testdata/maps.out.ll ++++ b/transform/testdata/maps.out.ll +@@ -1,34 +1,30 @@ + target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7m-none-eabi" + +-%runtime.hashmap = type { %runtime.hashmap*, i8*, i32, i8, i8, i8 } +- + @answer = constant [6 x i8] c"answer" + +-declare nonnull %runtime.hashmap* @runtime.hashmapMake(i8, i8, i32) ++declare nonnull ptr @runtime.hashmapMake(i8, i8, i32) + +-declare void @runtime.hashmapStringSet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture readonly) ++declare void @runtime.hashmapStringSet(ptr nocapture, ptr, i32, ptr nocapture readonly) + +-declare i1 @runtime.hashmapStringGet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture) ++declare i1 @runtime.hashmapStringGet(ptr nocapture, ptr, i32, ptr nocapture) + + define void @testUnused() { + ret void + } + + define i32 @testReadonly() { +- %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) ++ %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) + %hashmap.value = alloca i32, align 4 +- store i32 42, i32* %hashmap.value, align 4 +- %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8* +- call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast) ++ store i32 42, ptr %hashmap.value, align 4 ++ call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) + %hashmap.value2 = alloca i32, align 4 +- %hashmap.value2.bitcast = bitcast i32* %hashmap.value2 to i8* +- %commaOk = call i1 @runtime.hashmapStringGet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value2.bitcast) +- %loadedValue = load i32, i32* %hashmap.value2, align 4 ++ %commaOk = call i1 @runtime.hashmapStringGet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value2) ++ %loadedValue = load i32, ptr %hashmap.value2, align 4 + ret i32 %loadedValue + } + +-define %runtime.hashmap* @testUsed() { +- %1 = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) +- ret %runtime.hashmap* %1 ++define ptr @testUsed() { ++ %1 = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) ++ ret ptr %1 + } +diff --git a/transform/testdata/panic.ll b/transform/testdata/panic.ll +index 4f0f0a16..660e30f2 100644 +--- a/transform/testdata/panic.ll ++++ b/transform/testdata/panic.ll +@@ -3,12 +3,12 @@ target triple = "armv7m-none-eabi" + + @"runtime.lookupPanic$string" = constant [18 x i8] c"index out of range" + +-declare void @runtime.runtimePanic(i8*, i32) ++declare void @runtime.runtimePanic(ptr, i32) + +-declare void @runtime._panic(i32, i8*) ++declare void @runtime._panic(i32, ptr) + + define void @runtime.lookupPanic() { +- call void @runtime.runtimePanic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"runtime.lookupPanic$string", i64 0, i64 0), i32 18) ++ call void @runtime.runtimePanic(ptr @"runtime.lookupPanic$string", i32 18) + ret void + } + +@@ -16,7 +16,7 @@ define void @runtime.lookupPanic() { + ; func someFunc(x interface{}) { + ; panic(x) + ; } +-define void @someFunc(i32 %typecode, i8* %value) { +- call void @runtime._panic(i32 %typecode, i8* %value) ++define void @someFunc(i32 %typecode, ptr %value) { ++ call void @runtime._panic(i32 %typecode, ptr %value) + unreachable + } +diff --git a/transform/testdata/panic.out.ll b/transform/testdata/panic.out.ll +index 8612ae9a..458e4c24 100644 +--- a/transform/testdata/panic.out.ll ++++ b/transform/testdata/panic.out.ll +@@ -3,19 +3,19 @@ target triple = "armv7m-none-eabi" + + @"runtime.lookupPanic$string" = constant [18 x i8] c"index out of range" + +-declare void @runtime.runtimePanic(i8*, i32) ++declare void @runtime.runtimePanic(ptr, i32) + +-declare void @runtime._panic(i32, i8*) ++declare void @runtime._panic(i32, ptr) + + define void @runtime.lookupPanic() { + call void @llvm.trap() +- call void @runtime.runtimePanic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"runtime.lookupPanic$string", i64 0, i64 0), i32 18) ++ call void @runtime.runtimePanic(ptr @"runtime.lookupPanic$string", i32 18) + ret void + } + +-define void @someFunc(i32 %typecode, i8* %value) { ++define void @someFunc(i32 %typecode, ptr %value) { + call void @llvm.trap() +- call void @runtime._panic(i32 %typecode, i8* %value) ++ call void @runtime._panic(i32 %typecode, ptr %value) + unreachable + } + +diff --git a/transform/testdata/reflect-implements.ll b/transform/testdata/reflect-implements.ll +index ca6dcb8c..e0e2b9a7 100644 +--- a/transform/testdata/reflect-implements.ll ++++ b/transform/testdata/reflect-implements.ll +@@ -1,17 +1,17 @@ + target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" + target triple = "i686--linux" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +-%runtime.interfaceMethodInfo = type { i8*, i32 } ++%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } ++%runtime.interfaceMethodInfo = type { ptr, i32 } + +-@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } +-@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } ++@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } ++@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } + @"reflect/methods.Error() string" = linkonce_odr constant i8 0 +-@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.Error() string"] ++@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.Error() string"] + @"reflect/methods.Align() int" = linkonce_odr constant i8 0 + @"reflect/methods.Implements(reflect.Type) bool" = linkonce_odr constant i8 0 +-@"reflect.Type$interface" = linkonce_odr constant [2 x i8*] [i8* @"reflect/methods.Align() int", i8* @"reflect/methods.Implements(reflect.Type) bool"] +-@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:uintptr", i32 0, %runtime.interfaceMethodInfo* getelementptr inbounds ([20 x %runtime.interfaceMethodInfo], [20 x %runtime.interfaceMethodInfo]* @"reflect.rawType$methodset", i32 0, i32 0), %runtime.typecodeID* null, i32 0 } ++@"reflect.Type$interface" = linkonce_odr constant [2 x ptr] [ptr @"reflect/methods.Align() int", ptr @"reflect/methods.Implements(reflect.Type) bool"] ++@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:uintptr", i32 0, ptr @"reflect.rawType$methodset", ptr null, i32 0 } + @"reflect.rawType$methodset" = linkonce_odr constant [20 x %runtime.interfaceMethodInfo] zeroinitializer + @"reflect/types.type:basic:uintptr" = linkonce_odr constant %runtime.typecodeID zeroinitializer + +@@ -22,9 +22,9 @@ target triple = "i686--linux" + ; The type itself is stored in %typ.value, %typ.typecode just refers to the + ; type of reflect.Type. This function can be optimized because errorType is + ; known at compile time (after the interp pass has run). +-define i1 @main.isError(i32 %typ.typecode, i8* %typ.value, i8* %context) { ++define i1 @main.isError(i32 %typ.typecode, ptr %typ.value, ptr %context) { + entry: +- %result = call i1 @"reflect.Type.Implements$invoke"(i8* %typ.value, i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:reflect.rawType" to i32), i8* bitcast (%runtime.typecodeID* @"reflect/types.type:named:error" to i8*), i32 %typ.typecode, i8* undef) ++ %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, i32 ptrtoint (ptr @"reflect/types.type:named:reflect.rawType" to i32), ptr @"reflect/types.type:named:error", i32 %typ.typecode, ptr undef) + ret i1 %result + } + +@@ -33,13 +33,13 @@ entry: + ; func isUnknown(typ, itf reflect.Type) bool { + ; return typ.Implements(itf) + ; } +-define i1 @main.isUnknown(i32 %typ.typecode, i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i8* %context) { ++define i1 @main.isUnknown(i32 %typ.typecode, ptr %typ.value, i32 %itf.typecode, ptr %itf.value, ptr %context) { + entry: +- %result = call i1 @"reflect.Type.Implements$invoke"(i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i32 %typ.typecode, i8* undef) ++ %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, i32 %itf.typecode, ptr %itf.value, i32 %typ.typecode, ptr undef) + ret i1 %result + } + +-declare i1 @"reflect.Type.Implements$invoke"(i8*, i32, i8*, i32, i8*) #0 ++declare i1 @"reflect.Type.Implements$invoke"(ptr, i32, ptr, i32, ptr) #0 + declare i1 @"error.$typeassert"(i32) #1 + + attributes #0 = { "tinygo-invoke"="reflect/methods.Implements(reflect.Type) bool" "tinygo-methods"="reflect/methods.Align() int; reflect/methods.Implements(reflect.Type) bool" } +diff --git a/transform/testdata/reflect-implements.out.ll b/transform/testdata/reflect-implements.out.ll +index 0093e2b0..29366239 100644 +--- a/transform/testdata/reflect-implements.out.ll ++++ b/transform/testdata/reflect-implements.out.ll +@@ -1,34 +1,34 @@ + target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" + target triple = "i686--linux" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } +-%runtime.interfaceMethodInfo = type { i8*, i32 } ++%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } ++%runtime.interfaceMethodInfo = type { ptr, i32 } + +-@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } +-@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } ++@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 ptrtoint (ptr @"error.$typeassert" to i32) } ++@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.interface:interface{Error() string}$interface", i32 0, ptr null, ptr null, i32 ptrtoint (ptr @"error.$typeassert" to i32) } + @"reflect/methods.Error() string" = linkonce_odr constant i8 0 +-@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.Error() string"] ++@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.Error() string"] + @"reflect/methods.Align() int" = linkonce_odr constant i8 0 + @"reflect/methods.Implements(reflect.Type) bool" = linkonce_odr constant i8 0 +-@"reflect.Type$interface" = linkonce_odr constant [2 x i8*] [i8* @"reflect/methods.Align() int", i8* @"reflect/methods.Implements(reflect.Type) bool"] +-@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:uintptr", i32 0, %runtime.interfaceMethodInfo* getelementptr inbounds ([20 x %runtime.interfaceMethodInfo], [20 x %runtime.interfaceMethodInfo]* @"reflect.rawType$methodset", i32 0, i32 0), %runtime.typecodeID* null, i32 0 } ++@"reflect.Type$interface" = linkonce_odr constant [2 x ptr] [ptr @"reflect/methods.Align() int", ptr @"reflect/methods.Implements(reflect.Type) bool"] ++@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:uintptr", i32 0, ptr @"reflect.rawType$methodset", ptr null, i32 0 } + @"reflect.rawType$methodset" = linkonce_odr constant [20 x %runtime.interfaceMethodInfo] zeroinitializer + @"reflect/types.type:basic:uintptr" = linkonce_odr constant %runtime.typecodeID zeroinitializer + +-define i1 @main.isError(i32 %typ.typecode, i8* %typ.value, i8* %context) { ++define i1 @main.isError(i32 %typ.typecode, ptr %typ.value, ptr %context) { + entry: +- %0 = ptrtoint i8* %typ.value to i32 ++ %0 = ptrtoint ptr %typ.value to i32 + %1 = call i1 @"error.$typeassert"(i32 %0) + ret i1 %1 + } + +-define i1 @main.isUnknown(i32 %typ.typecode, i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i8* %context) { ++define i1 @main.isUnknown(i32 %typ.typecode, ptr %typ.value, i32 %itf.typecode, ptr %itf.value, ptr %context) { + entry: +- %result = call i1 @"reflect.Type.Implements$invoke"(i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i32 %typ.typecode, i8* undef) ++ %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, i32 %itf.typecode, ptr %itf.value, i32 %typ.typecode, ptr undef) + ret i1 %result + } + +-declare i1 @"reflect.Type.Implements$invoke"(i8*, i32, i8*, i32, i8*) #0 ++declare i1 @"reflect.Type.Implements$invoke"(ptr, i32, ptr, i32, ptr) #0 + + declare i1 @"error.$typeassert"(i32) #1 + +diff --git a/transform/testdata/stacksize.ll b/transform/testdata/stacksize.ll +index f80a7121..4df5874a 100644 +--- a/transform/testdata/stacksize.ll ++++ b/transform/testdata/stacksize.ll +@@ -1,15 +1,15 @@ + target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7m-none-eabi" + +-declare i32 @"internal/task.getGoroutineStackSize"(i32, i8*, i8*) ++declare i32 @"internal/task.getGoroutineStackSize"(i32, ptr, ptr) + +-declare void @"runtime.run$1$gowrapper"(i8*) ++declare void @"runtime.run$1$gowrapper"(ptr) + +-declare void @"internal/task.start"(i32, i8*, i32) ++declare void @"internal/task.start"(i32, ptr, i32) + + define void @Reset_Handler() { + entry: +- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"runtime.run$1$gowrapper" to i32), i8* undef, i8* undef) +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"runtime.run$1$gowrapper" to i32), i8* undef, i32 %stacksize) ++ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"runtime.run$1$gowrapper" to i32), ptr undef, ptr undef) ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"runtime.run$1$gowrapper" to i32), ptr undef, i32 %stacksize) + ret void + } +diff --git a/transform/testdata/stacksize.out.ll b/transform/testdata/stacksize.out.ll +index cea820ec..59e824cf 100644 +--- a/transform/testdata/stacksize.out.ll ++++ b/transform/testdata/stacksize.out.ll +@@ -2,17 +2,17 @@ target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + target triple = "armv7m-none-eabi" + + @"internal/task.stackSizes" = global [1 x i32] [i32 1024], section ".tinygo_stacksizes" +-@llvm.used = appending global [2 x i8*] [i8* bitcast ([1 x i32]* @"internal/task.stackSizes" to i8*), i8* bitcast (void (i8*)* @"runtime.run$1$gowrapper" to i8*)] ++@llvm.used = appending global [2 x ptr] [ptr @"internal/task.stackSizes", ptr @"runtime.run$1$gowrapper"] + +-declare i32 @"internal/task.getGoroutineStackSize"(i32, i8*, i8*) ++declare i32 @"internal/task.getGoroutineStackSize"(i32, ptr, ptr) + +-declare void @"runtime.run$1$gowrapper"(i8*) ++declare void @"runtime.run$1$gowrapper"(ptr) + +-declare void @"internal/task.start"(i32, i8*, i32) ++declare void @"internal/task.start"(i32, ptr, i32) + + define void @Reset_Handler() { + entry: +- %stacksize1 = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @"internal/task.stackSizes", i32 0, i32 0), align 4 +- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"runtime.run$1$gowrapper" to i32), i8* undef, i32 %stacksize1) ++ %stacksize1 = load i32, ptr @"internal/task.stackSizes", align 4 ++ call void @"internal/task.start"(i32 ptrtoint (ptr @"runtime.run$1$gowrapper" to i32), ptr undef, i32 %stacksize1) + ret void + } +diff --git a/transform/testdata/stringequal.ll b/transform/testdata/stringequal.ll +index d355fc45..0d6ed7fb 100644 +--- a/transform/testdata/stringequal.ll ++++ b/transform/testdata/stringequal.ll +@@ -3,17 +3,17 @@ target triple = "armv7m-none-eabi" + + @zeroString = constant [0 x i8] zeroinitializer + +-declare i1 @runtime.stringEqual(i8*, i32, i8*, i32, i8*) ++declare i1 @runtime.stringEqual(ptr, i32, ptr, i32, ptr) + +-define i1 @main.stringCompareEqualConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { ++define i1 @main.stringCompareEqualConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { + entry: +- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @zeroString, i32 0, i32 0), i32 0, i8* undef) ++ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr @zeroString, i32 0, ptr undef) + ret i1 %0 + } + +-define i1 @main.stringCompareUnequalConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { ++define i1 @main.stringCompareUnequalConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { + entry: +- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @zeroString, i32 0, i32 0), i32 0, i8* undef) ++ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr @zeroString, i32 0, ptr undef) + %1 = xor i1 %0, true + ret i1 %1 + } +diff --git a/transform/testdata/stringequal.out.ll b/transform/testdata/stringequal.out.ll +index d148c84f..f2aeb95a 100644 +--- a/transform/testdata/stringequal.out.ll ++++ b/transform/testdata/stringequal.out.ll +@@ -3,15 +3,15 @@ target triple = "armv7m-none-eabi" + + @zeroString = constant [0 x i8] zeroinitializer + +-declare i1 @runtime.stringEqual(i8*, i32, i8*, i32, i8*) ++declare i1 @runtime.stringEqual(ptr, i32, ptr, i32, ptr) + +-define i1 @main.stringCompareEqualConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { ++define i1 @main.stringCompareEqualConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { + entry: + %0 = icmp eq i32 %s1.len, 0 + ret i1 %0 + } + +-define i1 @main.stringCompareUnequalConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { ++define i1 @main.stringCompareUnequalConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { + entry: + %0 = icmp eq i32 %s1.len, 0 + %1 = xor i1 %0, true +diff --git a/transform/testdata/stringtobytes.ll b/transform/testdata/stringtobytes.ll +index f3cec823..fa43f3d0 100644 +--- a/transform/testdata/stringtobytes.ll ++++ b/transform/testdata/stringtobytes.ll +@@ -3,30 +3,30 @@ target triple = "x86_64--linux" + + @str = constant [6 x i8] c"foobar" + +-declare { i8*, i64, i64 } @runtime.stringToBytes(i8*, i64) ++declare { ptr, i64, i64 } @runtime.stringToBytes(ptr, i64) + +-declare void @printSlice(i8* nocapture readonly, i64, i64) ++declare void @printSlice(ptr nocapture readonly, i64, i64) + +-declare void @writeToSlice(i8* nocapture, i64, i64) ++declare void @writeToSlice(ptr nocapture, i64, i64) + + ; Test that runtime.stringToBytes can be fully optimized away. + define void @testReadOnly() { + entry: +- %0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6) +- %1 = extractvalue { i8*, i64, i64 } %0, 0 +- %2 = extractvalue { i8*, i64, i64 } %0, 1 +- %3 = extractvalue { i8*, i64, i64 } %0, 2 +- call fastcc void @printSlice(i8* %1, i64 %2, i64 %3) ++ %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) ++ %1 = extractvalue { ptr, i64, i64 } %0, 0 ++ %2 = extractvalue { ptr, i64, i64 } %0, 1 ++ %3 = extractvalue { ptr, i64, i64 } %0, 2 ++ call fastcc void @printSlice(ptr %1, i64 %2, i64 %3) + ret void + } + + ; Test that even though the slice is written to, some values can be propagated. + define void @testReadWrite() { + entry: +- %0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6) +- %1 = extractvalue { i8*, i64, i64 } %0, 0 +- %2 = extractvalue { i8*, i64, i64 } %0, 1 +- %3 = extractvalue { i8*, i64, i64 } %0, 2 +- call fastcc void @writeToSlice(i8* %1, i64 %2, i64 %3) ++ %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) ++ %1 = extractvalue { ptr, i64, i64 } %0, 0 ++ %2 = extractvalue { ptr, i64, i64 } %0, 1 ++ %3 = extractvalue { ptr, i64, i64 } %0, 2 ++ call fastcc void @writeToSlice(ptr %1, i64 %2, i64 %3) + ret void + } +diff --git a/transform/testdata/stringtobytes.out.ll b/transform/testdata/stringtobytes.out.ll +index 49b06581..30aa520a 100644 +--- a/transform/testdata/stringtobytes.out.ll ++++ b/transform/testdata/stringtobytes.out.ll +@@ -3,22 +3,22 @@ target triple = "x86_64--linux" + + @str = constant [6 x i8] c"foobar" + +-declare { i8*, i64, i64 } @runtime.stringToBytes(i8*, i64) ++declare { ptr, i64, i64 } @runtime.stringToBytes(ptr, i64) + +-declare void @printSlice(i8* nocapture readonly, i64, i64) ++declare void @printSlice(ptr nocapture readonly, i64, i64) + +-declare void @writeToSlice(i8* nocapture, i64, i64) ++declare void @writeToSlice(ptr nocapture, i64, i64) + + define void @testReadOnly() { + entry: +- call fastcc void @printSlice(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6, i64 6) ++ call fastcc void @printSlice(ptr @str, i64 6, i64 6) + ret void + } + + define void @testReadWrite() { + entry: +- %0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6) +- %1 = extractvalue { i8*, i64, i64 } %0, 0 +- call fastcc void @writeToSlice(i8* %1, i64 6, i64 6) ++ %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) ++ %1 = extractvalue { ptr, i64, i64 } %0, 0 ++ call fastcc void @writeToSlice(ptr %1, i64 6, i64 6) + ret void + } +diff --git a/transform/testdata/wasm-abi.ll b/transform/testdata/wasm-abi.ll +index 79e25347..ade4b5af 100644 +--- a/transform/testdata/wasm-abi.ll ++++ b/transform/testdata/wasm-abi.ll +@@ -1,19 +1,19 @@ + target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" + target triple = "wasm32-unknown-unknown-wasm" + +-declare i64 @externalCall(i8*, i32, i64) ++declare i64 @externalCall(ptr, i32, i64) + +-define internal i64 @testCall(i8* %ptr, i32 %len, i64 %foo) { +- %val = call i64 @externalCall(i8* %ptr, i32 %len, i64 %foo) ++define internal i64 @testCall(ptr %ptr, i32 %len, i64 %foo) { ++ %val = call i64 @externalCall(ptr %ptr, i32 %len, i64 %foo) + ret i64 %val + } + +-define internal i64 @testCallNonEntry(i8* %ptr, i32 %len) { ++define internal i64 @testCallNonEntry(ptr %ptr, i32 %len) { + entry: + br label %bb1 + + bb1: +- %val = call i64 @externalCall(i8* %ptr, i32 %len, i64 3) ++ %val = call i64 @externalCall(ptr %ptr, i32 %len, i64 3) + ret i64 %val + } + +diff --git a/transform/testdata/wasm-abi.out.ll b/transform/testdata/wasm-abi.out.ll +index cf63c3d7..a1fc7d6a 100644 +--- a/transform/testdata/wasm-abi.out.ll ++++ b/transform/testdata/wasm-abi.out.ll +@@ -1,27 +1,27 @@ + target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" + target triple = "wasm32-unknown-unknown-wasm" + +-declare i64 @"externalCall$i64wrap"(i8*, i32, i64) ++declare i64 @"externalCall$i64wrap"(ptr, i32, i64) + +-define internal i64 @testCall(i8* %ptr, i32 %len, i64 %foo) { ++define internal i64 @testCall(ptr %ptr, i32 %len, i64 %foo) { + %i64asptr = alloca i64, align 8 + %i64asptr1 = alloca i64, align 8 +- store i64 %foo, i64* %i64asptr1, align 8 +- call void @externalCall(i64* %i64asptr, i8* %ptr, i32 %len, i64* %i64asptr1) +- %retval = load i64, i64* %i64asptr, align 8 ++ store i64 %foo, ptr %i64asptr1, align 8 ++ call void @externalCall(ptr %i64asptr, ptr %ptr, i32 %len, ptr %i64asptr1) ++ %retval = load i64, ptr %i64asptr, align 8 + ret i64 %retval + } + +-define internal i64 @testCallNonEntry(i8* %ptr, i32 %len) { ++define internal i64 @testCallNonEntry(ptr %ptr, i32 %len) { + entry: + %i64asptr = alloca i64, align 8 + %i64asptr1 = alloca i64, align 8 + br label %bb1 + + bb1: ; preds = %entry +- store i64 3, i64* %i64asptr1, align 8 +- call void @externalCall(i64* %i64asptr, i8* %ptr, i32 %len, i64* %i64asptr1) +- %retval = load i64, i64* %i64asptr, align 8 ++ store i64 3, ptr %i64asptr1, align 8 ++ call void @externalCall(ptr %i64asptr, ptr %ptr, i32 %len, ptr %i64asptr1) ++ %retval = load i64, ptr %i64asptr, align 8 + ret i64 %retval + } + +@@ -35,11 +35,11 @@ define internal void @callExportedFunction(i64 %foo) { + ret void + } + +-declare void @externalCall(i64*, i8*, i32, i64*) ++declare void @externalCall(ptr, ptr, i32, ptr) + +-define void @exportedFunction(i64* %0) { ++define void @exportedFunction(ptr %0) { + entry: +- %i64 = load i64, i64* %0, align 8 ++ %i64 = load i64, ptr %0, align 8 + call void @"exportedFunction$i64wrap"(i64 %i64) + ret void + } +-- +2.39.2 + diff --git a/0010-Switch-interp-tests-to-opaque-pointers.patch b/0010-Switch-interp-tests-to-opaque-pointers.patch new file mode 100644 index 0000000..8225c59 --- /dev/null +++ b/0010-Switch-interp-tests-to-opaque-pointers.patch @@ -0,0 +1,831 @@ +From 5dbdba87017a1369dd0ffc634042703d28a92889 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 15 Apr 2023 16:42:11 -0400 +Subject: [PATCH 10/11] Switch interp tests to opaque pointers + +Signed-off-by: Elliott Sales de Andrade +--- + interp/testdata/alloc.ll | 56 ++++++++++++------------- + interp/testdata/alloc.out.ll | 28 ++++++------- + interp/testdata/basic.ll | 42 +++++++++---------- + interp/testdata/basic.out.ll | 30 +++++++------- + interp/testdata/consteval.ll | 22 +++++----- + interp/testdata/consteval.out.ll | 2 +- + interp/testdata/interface.ll | 16 +++---- + interp/testdata/phi.ll | 4 +- + interp/testdata/revert.ll | 71 +++++++++++++++----------------- + interp/testdata/revert.out.ll | 55 ++++++++++++------------- + interp/testdata/slice-copy.ll | 67 ++++++++++++++---------------- + 11 files changed, 193 insertions(+), 200 deletions(-) + +diff --git a/interp/testdata/alloc.ll b/interp/testdata/alloc.ll +index 28b0c84e..82fbb5b2 100644 +--- a/interp/testdata/alloc.ll ++++ b/interp/testdata/alloc.ll +@@ -2,17 +2,17 @@ target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" + target triple = "wasm32--wasi" + + @"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00 " } +-@pointerFree12 = global i8* null +-@pointerFree7 = global i8* null +-@pointerFree3 = global i8* null +-@pointerFree0 = global i8* null +-@layout1 = global i8* null +-@layout2 = global i8* null +-@layout3 = global i8* null +-@layout4 = global i8* null +-@bigobj1 = global i8* null ++@pointerFree12 = global ptr null ++@pointerFree7 = global ptr null ++@pointerFree3 = global ptr null ++@pointerFree0 = global ptr null ++@layout1 = global ptr null ++@layout2 = global ptr null ++@layout3 = global ptr null ++@layout4 = global ptr null ++@bigobj1 = global ptr null + +-declare i8* @runtime.alloc(i32, i8*) unnamed_addr ++declare ptr @runtime.alloc(i32, ptr) unnamed_addr + + define void @runtime.initAll() unnamed_addr { + call void @main.init() +@@ -21,33 +21,33 @@ define void @runtime.initAll() unnamed_addr { + + define internal void @main.init() unnamed_addr { + ; Object that's word-aligned. +- %pointerFree12 = call i8* @runtime.alloc(i32 12, i8* inttoptr (i32 3 to i8*)) +- store i8* %pointerFree12, i8** @pointerFree12 ++ %pointerFree12 = call ptr @runtime.alloc(i32 12, ptr inttoptr (i32 3 to ptr)) ++ store ptr %pointerFree12, ptr @pointerFree12 + ; Object larger than a word but not word-aligned. +- %pointerFree7 = call i8* @runtime.alloc(i32 7, i8* inttoptr (i32 3 to i8*)) +- store i8* %pointerFree7, i8** @pointerFree7 ++ %pointerFree7 = call ptr @runtime.alloc(i32 7, ptr inttoptr (i32 3 to ptr)) ++ store ptr %pointerFree7, ptr @pointerFree7 + ; Object smaller than a word (and of course not word-aligned). +- %pointerFree3 = call i8* @runtime.alloc(i32 3, i8* inttoptr (i32 3 to i8*)) +- store i8* %pointerFree3, i8** @pointerFree3 ++ %pointerFree3 = call ptr @runtime.alloc(i32 3, ptr inttoptr (i32 3 to ptr)) ++ store ptr %pointerFree3, ptr @pointerFree3 + ; Zero-sized object. +- %pointerFree0 = call i8* @runtime.alloc(i32 0, i8* inttoptr (i32 3 to i8*)) +- store i8* %pointerFree0, i8** @pointerFree0 ++ %pointerFree0 = call ptr @runtime.alloc(i32 0, ptr inttoptr (i32 3 to ptr)) ++ store ptr %pointerFree0, ptr @pointerFree0 + + ; Object made out of 3 pointers. +- %layout1 = call i8* @runtime.alloc(i32 12, i8* inttoptr (i32 67 to i8*)) +- store i8* %layout1, i8** @layout1 ++ %layout1 = call ptr @runtime.alloc(i32 12, ptr inttoptr (i32 67 to ptr)) ++ store ptr %layout1, ptr @layout1 + ; Array (or slice) of 5 slices. +- %layout2 = call i8* @runtime.alloc(i32 60, i8* inttoptr (i32 71 to i8*)) +- store i8* %layout2, i8** @layout2 ++ %layout2 = call ptr @runtime.alloc(i32 60, ptr inttoptr (i32 71 to ptr)) ++ store ptr %layout2, ptr @layout2 + ; Oddly shaped object, using all bits in the layout integer. +- %layout3 = call i8* @runtime.alloc(i32 104, i8* inttoptr (i32 2467830261 to i8*)) +- store i8* %layout3, i8** @layout3 ++ %layout3 = call ptr @runtime.alloc(i32 104, ptr inttoptr (i32 2467830261 to ptr)) ++ store ptr %layout3, ptr @layout3 + ; ...repeated. +- %layout4 = call i8* @runtime.alloc(i32 312, i8* inttoptr (i32 2467830261 to i8*)) +- store i8* %layout4, i8** @layout4 ++ %layout4 = call ptr @runtime.alloc(i32 312, ptr inttoptr (i32 2467830261 to ptr)) ++ store ptr %layout4, ptr @layout4 + + ; Large object that needs to be stored in a separate global. +- %bigobj1 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-2000000000000001" to i8*)) +- store i8* %bigobj1, i8** @bigobj1 ++ %bigobj1 = call ptr @runtime.alloc(i32 248, ptr @"runtime/gc.layout:62-2000000000000001") ++ store ptr %bigobj1, ptr @bigobj1 + ret void + } +diff --git a/interp/testdata/alloc.out.ll b/interp/testdata/alloc.out.ll +index 6e8f6391..b9da6291 100644 +--- a/interp/testdata/alloc.out.ll ++++ b/interp/testdata/alloc.out.ll +@@ -1,24 +1,24 @@ + target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" + target triple = "wasm32--wasi" + +-@pointerFree12 = local_unnamed_addr global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @"main$alloc", i32 0, i32 0) +-@pointerFree7 = local_unnamed_addr global i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"main$alloc.1", i32 0, i32 0) +-@pointerFree3 = local_unnamed_addr global i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"main$alloc.2", i32 0, i32 0) +-@pointerFree0 = local_unnamed_addr global i8* getelementptr inbounds ([0 x i8], [0 x i8]* @"main$alloc.3", i32 0, i32 0) +-@layout1 = local_unnamed_addr global i8* bitcast ([3 x i8*]* @"main$alloc.4" to i8*) +-@layout2 = local_unnamed_addr global i8* bitcast ([5 x { i8*, i32, i32 }]* @"main$alloc.5" to i8*) +-@layout3 = local_unnamed_addr global i8* bitcast ({ i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }* @"main$alloc.6" to i8*) +-@layout4 = local_unnamed_addr global i8* bitcast ([3 x { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }]* @"main$alloc.7" to i8*) +-@bigobj1 = local_unnamed_addr global i8* bitcast ({ i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* }* @"main$alloc.8" to i8*) ++@pointerFree12 = local_unnamed_addr global ptr @"main$alloc" ++@pointerFree7 = local_unnamed_addr global ptr @"main$alloc.1" ++@pointerFree3 = local_unnamed_addr global ptr @"main$alloc.2" ++@pointerFree0 = local_unnamed_addr global ptr @"main$alloc.3" ++@layout1 = local_unnamed_addr global ptr @"main$alloc.4" ++@layout2 = local_unnamed_addr global ptr @"main$alloc.5" ++@layout3 = local_unnamed_addr global ptr @"main$alloc.6" ++@layout4 = local_unnamed_addr global ptr @"main$alloc.7" ++@bigobj1 = local_unnamed_addr global ptr @"main$alloc.8" + @"main$alloc" = internal global [12 x i8] zeroinitializer, align 4 + @"main$alloc.1" = internal global [7 x i8] zeroinitializer, align 4 + @"main$alloc.2" = internal global [3 x i8] zeroinitializer, align 4 + @"main$alloc.3" = internal global [0 x i8] zeroinitializer, align 4 +-@"main$alloc.4" = internal global [3 x i8*] zeroinitializer, align 4 +-@"main$alloc.5" = internal global [5 x { i8*, i32, i32 }] zeroinitializer, align 4 +-@"main$alloc.6" = internal global { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* } zeroinitializer, align 4 +-@"main$alloc.7" = internal global [3 x { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }] zeroinitializer, align 4 +-@"main$alloc.8" = internal global { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* } zeroinitializer, align 4 ++@"main$alloc.4" = internal global [3 x ptr] zeroinitializer, align 4 ++@"main$alloc.5" = internal global [5 x { ptr, i32, i32 }] zeroinitializer, align 4 ++@"main$alloc.6" = internal global { ptr, ptr, ptr, i32, i32, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, i32, i32, ptr, ptr, i32, i32, ptr, i32, i32, ptr } zeroinitializer, align 4 ++@"main$alloc.7" = internal global [3 x { ptr, ptr, ptr, i32, i32, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, i32, i32, ptr, ptr, i32, i32, ptr, i32, i32, ptr }] zeroinitializer, align 4 ++@"main$alloc.8" = internal global { ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr } zeroinitializer, align 4 + + define void @runtime.initAll() unnamed_addr { + ret void +diff --git a/interp/testdata/basic.ll b/interp/testdata/basic.ll +index 30c0bf08..6d1d010f 100644 +--- a/interp/testdata/basic.ll ++++ b/interp/testdata/basic.ll +@@ -5,7 +5,7 @@ target triple = "x86_64--linux" + @main.nonConst1 = global [4 x i64] zeroinitializer + @main.nonConst2 = global i64 0 + @main.someArray = global [8 x {i16, i32}] zeroinitializer +-@main.exportedValue = global [1 x i16*] [i16* @main.exposedValue1] ++@main.exportedValue = global [1 x ptr] [ptr @main.exposedValue1] + @main.exportedConst = constant i64 42 + @main.exposedValue1 = global i16 0 + @main.exposedValue2 = global i16 0 +@@ -24,7 +24,7 @@ entry: + + define void @main() unnamed_addr { + entry: +- %0 = load i64, i64* @main.v1 ++ %0 = load i64, ptr @main.v1 + call void @runtime.printint64(i64 %0) + call void @runtime.printnl() + ret void +@@ -37,43 +37,43 @@ entry: + + define internal void @main.init() unnamed_addr { + entry: +- store i64 3, i64* @main.v1 ++ store i64 3, ptr @main.v1 + call void @"main.init#1"() + + ; test the following pattern: + ; func someValue() int // extern function + ; var nonConst1 = [4]int{someValue(), 0, 0, 0} + %value1 = call i64 @someValue() +- %gep1 = getelementptr [4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0 +- store i64 %value1, i64* %gep1 ++ %gep1 = getelementptr [4 x i64], ptr @main.nonConst1, i32 0, i32 0 ++ store i64 %value1, ptr %gep1 + + ; Test that the global really is marked dirty: + ; var nonConst2 = nonConst1[0] +- %gep2 = getelementptr [4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0 +- %value2 = load i64, i64* %gep2 +- store i64 %value2, i64* @main.nonConst2 ++ %gep2 = getelementptr [4 x i64], ptr @main.nonConst1, i32 0, i32 0 ++ %value2 = load i64, ptr %gep2 ++ store i64 %value2, ptr @main.nonConst2 + + ; Test that the following GEP works: + ; var someArray + ; modifyExternal(&someArray[3].field1) +- %gep3 = getelementptr [8 x {i16, i32}], [8 x {i16, i32}]* @main.someArray, i32 0, i32 3, i32 1 +- call void @modifyExternal(i32* %gep3) ++ %gep3 = getelementptr [8 x {i16, i32}], ptr @main.someArray, i32 0, i32 3, i32 1 ++ call void @modifyExternal(ptr %gep3) + + ; Test that marking a value as external also marks all referenced values. +- call void @modifyExternal(i32* bitcast ([1 x i16*]* @main.exportedValue to i32*)) +- store i16 5, i16* @main.exposedValue1 ++ call void @modifyExternal(ptr @main.exportedValue) ++ store i16 5, ptr @main.exposedValue1 + + ; Test that marking a constant as external still allows loading from it. +- call void @readExternal(i32* bitcast (i64* @main.exportedConst to i32*)) +- %constLoad = load i64, i64 * @main.exportedConst ++ call void @readExternal(ptr @main.exportedConst) ++ %constLoad = load i64, ptr @main.exportedConst + call void @runtime.printint64(i64 %constLoad) + + ; Test that this even propagates through functions. +- call void @modifyExternal(i32* bitcast (void ()* @willModifyGlobal to i32*)) +- store i16 7, i16* @main.exposedValue2 ++ call void @modifyExternal(ptr @willModifyGlobal) ++ store i16 7, ptr @main.exposedValue2 + + ; Test that inline assembly is ignored. +- call void @modifyExternal(i32* bitcast (void ()* @hasInlineAsm to i32*)) ++ call void @modifyExternal(ptr @hasInlineAsm) + + ; Test switch statement. + %switch1 = call i64 @testSwitch(i64 1) ; 1 returns 6 +@@ -86,7 +86,7 @@ entry: + %elt = extractvalue {i8, i32, {float, {i64, i16}}} %agg, 2, 1, 0 + call void @runtime.printint64(i64 %elt) + %agg2 = insertvalue {i8, i32, {float, {i64, i16}}} %agg, i64 5, 2, 1, 0 +- store {i8, i32, {float, {i64, i16}}} %agg2, {i8, i32, {float, {i64, i16}}}* @main.insertedValue ++ store {i8, i32, {float, {i64, i16}}} %agg2, ptr @main.insertedValue + + ret void + } +@@ -100,16 +100,16 @@ entry: + + declare i64 @someValue() + +-declare void @modifyExternal(i32*) ++declare void @modifyExternal(ptr) + +-declare void @readExternal(i32*) ++declare void @readExternal(ptr) + + ; This function will modify an external value. By passing this function as a + ; function pointer to an external function, @main.exposedValue2 should be + ; marked as external. + define void @willModifyGlobal() { + entry: +- store i16 8, i16* @main.exposedValue2 ++ store i16 8, ptr @main.exposedValue2 + ret void + } + +diff --git a/interp/testdata/basic.out.ll b/interp/testdata/basic.out.ll +index 5c68ec5e..342d4965 100644 +--- a/interp/testdata/basic.out.ll ++++ b/interp/testdata/basic.out.ll +@@ -4,7 +4,7 @@ target triple = "x86_64--linux" + @main.nonConst1 = local_unnamed_addr global [4 x i64] zeroinitializer + @main.nonConst2 = local_unnamed_addr global i64 0 + @main.someArray = global [8 x { i16, i32 }] zeroinitializer +-@main.exportedValue = global [1 x i16*] [i16* @main.exposedValue1] ++@main.exportedValue = global [1 x ptr] [ptr @main.exposedValue1] + @main.exportedConst = constant i64 42 + @main.exposedValue1 = global i16 0 + @main.exposedValue2 = local_unnamed_addr global i16 0 +@@ -19,17 +19,17 @@ entry: + call void @runtime.printint64(i64 5) + call void @runtime.printnl() + %value1 = call i64 @someValue() +- store i64 %value1, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0), align 8 +- %value2 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0), align 8 +- store i64 %value2, i64* @main.nonConst2, align 8 +- call void @modifyExternal(i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ([8 x { i16, i32 }]* @main.someArray to i8*), i32 28) to i32*)) +- call void @modifyExternal(i32* bitcast ([1 x i16*]* @main.exportedValue to i32*)) +- store i16 5, i16* @main.exposedValue1, align 2 +- call void @readExternal(i32* bitcast (i64* @main.exportedConst to i32*)) ++ store i64 %value1, ptr @main.nonConst1, align 8 ++ %value2 = load i64, ptr @main.nonConst1, align 8 ++ store i64 %value2, ptr @main.nonConst2, align 8 ++ call void @modifyExternal(ptr getelementptr inbounds (i8, ptr @main.someArray, i32 28)) ++ call void @modifyExternal(ptr @main.exportedValue) ++ store i16 5, ptr @main.exposedValue1, align 2 ++ call void @readExternal(ptr @main.exportedConst) + call void @runtime.printint64(i64 42) +- call void @modifyExternal(i32* bitcast (void ()* @willModifyGlobal to i32*)) +- store i16 7, i16* @main.exposedValue2, align 2 +- call void @modifyExternal(i32* bitcast (void ()* @hasInlineAsm to i32*)) ++ call void @modifyExternal(ptr @willModifyGlobal) ++ store i16 7, ptr @main.exposedValue2, align 2 ++ call void @modifyExternal(ptr @hasInlineAsm) + call void @runtime.printint64(i64 6) + call void @runtime.printint64(i64 -1) + %agg = call { i8, i32, { float, { i64, i16 } } } @nestedStruct() +@@ -42,7 +42,7 @@ entry: + %agg2.insertvalue2 = insertvalue { i64, i16 } %agg2.agg1, i64 5, 0 + %agg2.insertvalue1 = insertvalue { float, { i64, i16 } } %agg2.agg0, { i64, i16 } %agg2.insertvalue2, 1 + %agg2.insertvalue0 = insertvalue { i8, i32, { float, { i64, i16 } } } %agg, { float, { i64, i16 } } %agg2.insertvalue1, 2 +- store { i8, i32, { float, { i64, i16 } } } %agg2.insertvalue0, { i8, i32, { float, { i64, i16 } } }* @main.insertedValue, align 8 ++ store { i8, i32, { float, { i64, i16 } } } %agg2.insertvalue0, ptr @main.insertedValue, align 8 + ret void + } + +@@ -55,13 +55,13 @@ entry: + + declare i64 @someValue() local_unnamed_addr + +-declare void @modifyExternal(i32*) local_unnamed_addr ++declare void @modifyExternal(ptr) local_unnamed_addr + +-declare void @readExternal(i32*) local_unnamed_addr ++declare void @readExternal(ptr) local_unnamed_addr + + define void @willModifyGlobal() { + entry: +- store i16 8, i16* @main.exposedValue2, align 2 ++ store i16 8, ptr @main.exposedValue2, align 2 + ret void + } + +diff --git a/interp/testdata/consteval.ll b/interp/testdata/consteval.ll +index d0c0e3b6..05d377f1 100644 +--- a/interp/testdata/consteval.ll ++++ b/interp/testdata/consteval.ll +@@ -5,7 +5,7 @@ target triple = "x86_64--linux" + @ptrToIntResult = global i8 0 + @icmpResult = global i8 0 + @someArray = internal global {i16, i8, i8} zeroinitializer +-@someArrayPointer = global i8* zeroinitializer ++@someArrayPointer = global ptr zeroinitializer + + define void @runtime.initAll() { + call void @main.init() +@@ -21,45 +21,45 @@ define internal void @main.init() { + } + + define internal void @testIntToPtr() { +- %nil = icmp eq i8* inttoptr (i64 1024 to i8*), null ++ %nil = icmp eq ptr inttoptr (i64 1024 to ptr), null + br i1 %nil, label %a, label %b + a: + ; should not be reached +- store i8 1, i8* @intToPtrResult ++ store i8 1, ptr @intToPtrResult + ret void + b: + ; should be reached +- store i8 2, i8* @intToPtrResult ++ store i8 2, ptr @intToPtrResult + ret void + } + + define internal void @testPtrToInt() { +- %zero = icmp eq i64 ptrtoint (i8* @ptrToIntResult to i64), 0 ++ %zero = icmp eq i64 ptrtoint (ptr @ptrToIntResult to i64), 0 + br i1 %zero, label %a, label %b + a: + ; should not be reached +- store i8 1, i8* @ptrToIntResult ++ store i8 1, ptr @ptrToIntResult + ret void + b: + ; should be reached +- store i8 2, i8* @ptrToIntResult ++ store i8 2, ptr @ptrToIntResult + ret void + } + + define internal void @testConstGEP() { +- store i8* getelementptr inbounds (i8, i8* bitcast ({i16, i8, i8}* @someArray to i8*), i32 2), i8** @someArrayPointer ++ store ptr getelementptr inbounds (i8, ptr @someArray, i32 2), ptr @someArrayPointer + ret void + } + + define internal void @testICmp() { +- br i1 icmp eq (i64 ptrtoint (i8* @ptrToIntResult to i64), i64 0), label %equal, label %unequal ++ br i1 icmp eq (i64 ptrtoint (ptr @ptrToIntResult to i64), i64 0), label %equal, label %unequal + equal: + ; should not be reached +- store i8 1, i8* @icmpResult ++ store i8 1, ptr @icmpResult + ret void + unequal: + ; should be reached +- store i8 2, i8* @icmpResult ++ store i8 2, ptr @icmpResult + ret void + ret void + } +diff --git a/interp/testdata/consteval.out.ll b/interp/testdata/consteval.out.ll +index 08d74c85..0d0b2884 100644 +--- a/interp/testdata/consteval.out.ll ++++ b/interp/testdata/consteval.out.ll +@@ -5,7 +5,7 @@ target triple = "x86_64--linux" + @ptrToIntResult = local_unnamed_addr global i8 2 + @icmpResult = local_unnamed_addr global i8 2 + @someArray = internal global { i16, i8, i8 } zeroinitializer +-@someArrayPointer = local_unnamed_addr global i8* getelementptr inbounds ({ i16, i8, i8 }, { i16, i8, i8 }* @someArray, i64 0, i32 1) ++@someArrayPointer = local_unnamed_addr global ptr getelementptr inbounds ({ i16, i8, i8 }, ptr @someArray, i64 0, i32 1) + + define void @runtime.initAll() local_unnamed_addr { + ret void +diff --git a/interp/testdata/interface.ll b/interp/testdata/interface.ll +index 6520efc5..2a025151 100644 +--- a/interp/testdata/interface.ll ++++ b/interp/testdata/interface.ll +@@ -1,17 +1,17 @@ + target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + target triple = "x86_64--linux" + +-%runtime.typecodeID = type { %runtime.typecodeID*, i64, %runtime.interfaceMethodInfo* } +-%runtime.interfaceMethodInfo = type { i8*, i64 } ++%runtime.typecodeID = type { ptr, i64, ptr } ++%runtime.interfaceMethodInfo = type { ptr, i64 } + + @main.v1 = global i1 0 + @main.v2 = global i1 0 +-@"reflect/types.type:named:main.foo" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i64 0, %runtime.interfaceMethodInfo* null } ++@"reflect/types.type:named:main.foo" = private constant %runtime.typecodeID { ptr @"reflect/types.type:basic:int", i64 0, ptr null } + @"reflect/types.typeid:named:main.foo" = external constant i8 + @"reflect/types.type:basic:int" = external constant %runtime.typecodeID + + +-declare i1 @runtime.typeAssert(i64, i8*, i8*, i8*) ++declare i1 @runtime.typeAssert(i64, ptr, ptr, ptr) + + define void @runtime.initAll() unnamed_addr { + entry: +@@ -22,9 +22,9 @@ entry: + define internal void @main.init() unnamed_addr { + entry: + ; Test type asserts. +- %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:main.foo" to i64), i8* @"reflect/types.typeid:named:main.foo", i8* undef, i8* null) +- store i1 %typecode, i1* @main.v1 +- %typecode2 = call i1 @runtime.typeAssert(i64 0, i8* @"reflect/types.typeid:named:main.foo", i8* undef, i8* null) +- store i1 %typecode2, i1* @main.v2 ++ %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (ptr @"reflect/types.type:named:main.foo" to i64), ptr @"reflect/types.typeid:named:main.foo", ptr undef, ptr null) ++ store i1 %typecode, ptr @main.v1 ++ %typecode2 = call i1 @runtime.typeAssert(i64 0, ptr @"reflect/types.typeid:named:main.foo", ptr undef, ptr null) ++ store i1 %typecode2, ptr @main.v2 + ret void + } +diff --git a/interp/testdata/phi.ll b/interp/testdata/phi.ll +index 0a0dad72..e2a15b69 100644 +--- a/interp/testdata/phi.ll ++++ b/interp/testdata/phi.ll +@@ -25,7 +25,7 @@ for.loop: + br i1 %icmp, label %for.done, label %for.loop + + for.done: +- store i8 %a, i8* @main.phiNodesResultA +- store i8 %b, i8* @main.phiNodesResultB ++ store i8 %a, ptr @main.phiNodesResultA ++ store i8 %b, ptr @main.phiNodesResultB + ret void + } +diff --git a/interp/testdata/revert.ll b/interp/testdata/revert.ll +index 517c152b..e82c0fb7 100644 +--- a/interp/testdata/revert.ll ++++ b/interp/testdata/revert.ll +@@ -3,7 +3,7 @@ target triple = "x86_64--linux" + + declare void @externalCall(i64) + +-declare i64 @ptrHash(i8* nocapture) ++declare i64 @ptrHash(ptr nocapture) + + @foo.knownAtRuntime = global i64 0 + @bar.knownAtRuntime = global i64 0 +@@ -17,60 +17,60 @@ declare i64 @ptrHash(i8* nocapture) + + define void @runtime.initAll() unnamed_addr { + entry: +- call void @baz.init(i8* undef) +- call void @foo.init(i8* undef) +- call void @bar.init(i8* undef) +- call void @main.init(i8* undef) +- call void @x.init(i8* undef) +- call void @y.init(i8* undef) +- call void @z.init(i8* undef) ++ call void @baz.init(ptr undef) ++ call void @foo.init(ptr undef) ++ call void @bar.init(ptr undef) ++ call void @main.init(ptr undef) ++ call void @x.init(ptr undef) ++ call void @y.init(ptr undef) ++ call void @z.init(ptr undef) + ret void + } + +-define internal void @foo.init(i8* %context) unnamed_addr { +- store i64 5, i64* @foo.knownAtRuntime ++define internal void @foo.init(ptr %context) unnamed_addr { ++ store i64 5, ptr @foo.knownAtRuntime + unreachable ; this triggers a revert of @foo.init. + } + +-define internal void @bar.init(i8* %context) unnamed_addr { +- %val = load i64, i64* @foo.knownAtRuntime +- store i64 %val, i64* @bar.knownAtRuntime ++define internal void @bar.init(ptr %context) unnamed_addr { ++ %val = load i64, ptr @foo.knownAtRuntime ++ store i64 %val, ptr @bar.knownAtRuntime + ret void + } + +-define internal void @baz.init(i8* %context) unnamed_addr { ++define internal void @baz.init(ptr %context) unnamed_addr { + ; Test extractvalue/insertvalue with more than one index. +- %val = load [3 x {i64, i32}], [3 x {i64, i32}]* @baz.someGlobal ++ %val = load [3 x {i64, i32}], ptr @baz.someGlobal + %part = extractvalue [3 x {i64, i32}] %val, 0, 1 + %val2 = insertvalue [3 x {i64, i32}] %val, i32 5, 2, 1 + unreachable ; trigger revert + } + +-define internal void @main.init(i8* %context) unnamed_addr { ++define internal void @main.init(ptr %context) unnamed_addr { + entry: + call void @externalCall(i64 3) + ret void + } + + +-define internal void @x.init(i8* %context) unnamed_addr { ++define internal void @x.init(ptr %context) unnamed_addr { + ; Test atomic and volatile memory accesses. +- store atomic i32 1, i32* @x.atomicNum seq_cst, align 4 +- %x = load atomic i32, i32* @x.atomicNum seq_cst, align 4 +- store i32 %x, i32* @x.atomicNum +- %y = load volatile i32, i32* @x.volatileNum +- store volatile i32 %y, i32* @x.volatileNum ++ store atomic i32 1, ptr @x.atomicNum seq_cst, align 4 ++ %x = load atomic i32, ptr @x.atomicNum seq_cst, align 4 ++ store i32 %x, ptr @x.atomicNum ++ %y = load volatile i32, ptr @x.volatileNum ++ store volatile i32 %y, ptr @x.volatileNum + ret void + } + +-define internal void @y.init(i8* %context) unnamed_addr { ++define internal void @y.init(ptr %context) unnamed_addr { + entry: + br label %loop + + loop: + ; Test a wait-loop. + ; This function must be reverted. +- %val = load atomic i32, i32* @y.ready seq_cst, align 4 ++ %val = load atomic i32, ptr @y.ready seq_cst, align 4 + %ready = icmp eq i32 %val, 1 + br i1 %ready, label %end, label %loop + +@@ -78,27 +78,25 @@ end: + ret void + } + +-define internal void @z.init(i8* %context) unnamed_addr { +- %bloom = bitcast i64* @z.bloom to i8* +- ++define internal void @z.init(ptr %context) unnamed_addr { + ; This can be safely expanded. +- call void @z.setArr(i8* %bloom, i64 1, i8* %bloom) ++ call void @z.setArr(ptr @z.bloom, i64 1, ptr @z.bloom) + + ; This call should be reverted to prevent unrolling. +- call void @z.setArr(i8* bitcast ([32 x i8]* @z.arr to i8*), i64 32, i8* %bloom) ++ call void @z.setArr(ptr @z.arr, i64 32, ptr @z.bloom) + + ret void + } + +-define internal void @z.setArr(i8* %arr, i64 %n, i8* %context) unnamed_addr { ++define internal void @z.setArr(ptr %arr, i64 %n, ptr %context) unnamed_addr { + entry: + br label %loop + + loop: + %prev = phi i64 [ %n, %entry ], [ %idx, %loop ] + %idx = sub i64 %prev, 1 +- %elem = getelementptr i8, i8* %arr, i64 %idx +- call void @z.set(i8* %elem, i8* %context) ++ %elem = getelementptr i8, ptr %arr, i64 %idx ++ call void @z.set(ptr %elem, ptr %context) + %done = icmp eq i64 %idx, 0 + br i1 %done, label %end, label %loop + +@@ -106,14 +104,13 @@ end: + ret void + } + +-define internal void @z.set(i8* %ptr, i8* %context) unnamed_addr { ++define internal void @z.set(ptr %ptr, ptr %context) unnamed_addr { + ; Insert the pointer into the Bloom filter. +- %hash = call i64 @ptrHash(i8* %ptr) ++ %hash = call i64 @ptrHash(ptr %ptr) + %index = lshr i64 %hash, 58 + %bit = shl i64 1, %index +- %bloom = bitcast i8* %context to i64* +- %old = load i64, i64* %bloom ++ %old = load i64, ptr %context + %new = or i64 %old, %bit +- store i64 %new, i64* %bloom ++ store i64 %new, ptr %context + ret void + } +diff --git a/interp/testdata/revert.out.ll b/interp/testdata/revert.out.ll +index edf19b54..db226c26 100644 +--- a/interp/testdata/revert.out.ll ++++ b/interp/testdata/revert.out.ll +@@ -13,41 +13,41 @@ target triple = "x86_64--linux" + + declare void @externalCall(i64) local_unnamed_addr + +-declare i64 @ptrHash(i8* nocapture) local_unnamed_addr ++declare i64 @ptrHash(ptr nocapture) local_unnamed_addr + + define void @runtime.initAll() unnamed_addr { + entry: +- call fastcc void @baz.init(i8* undef) +- call fastcc void @foo.init(i8* undef) +- %val = load i64, i64* @foo.knownAtRuntime, align 8 +- store i64 %val, i64* @bar.knownAtRuntime, align 8 ++ call fastcc void @baz.init(ptr undef) ++ call fastcc void @foo.init(ptr undef) ++ %val = load i64, ptr @foo.knownAtRuntime, align 8 ++ store i64 %val, ptr @bar.knownAtRuntime, align 8 + call void @externalCall(i64 3) +- store atomic i32 1, i32* @x.atomicNum seq_cst, align 4 +- %x = load atomic i32, i32* @x.atomicNum seq_cst, align 4 +- store i32 %x, i32* @x.atomicNum, align 4 +- %y = load volatile i32, i32* @x.volatileNum, align 4 +- store volatile i32 %y, i32* @x.volatileNum, align 4 +- call fastcc void @y.init(i8* undef) +- call fastcc void @z.set(i8* bitcast (i64* @z.bloom to i8*), i8* bitcast (i64* @z.bloom to i8*)) +- call fastcc void @z.setArr(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @z.arr, i32 0, i32 0), i64 32, i8* bitcast (i64* @z.bloom to i8*)) ++ store atomic i32 1, ptr @x.atomicNum seq_cst, align 4 ++ %x = load atomic i32, ptr @x.atomicNum seq_cst, align 4 ++ store i32 %x, ptr @x.atomicNum, align 4 ++ %y = load volatile i32, ptr @x.volatileNum, align 4 ++ store volatile i32 %y, ptr @x.volatileNum, align 4 ++ call fastcc void @y.init(ptr undef) ++ call fastcc void @z.set(ptr @z.bloom, ptr @z.bloom) ++ call fastcc void @z.setArr(ptr @z.arr, i64 32, ptr @z.bloom) + ret void + } + +-define internal fastcc void @foo.init(i8* %context) unnamed_addr { +- store i64 5, i64* @foo.knownAtRuntime, align 8 ++define internal fastcc void @foo.init(ptr %context) unnamed_addr { ++ store i64 5, ptr @foo.knownAtRuntime, align 8 + unreachable + } + +-define internal fastcc void @baz.init(i8* %context) unnamed_addr { ++define internal fastcc void @baz.init(ptr %context) unnamed_addr { + unreachable + } + +-define internal fastcc void @y.init(i8* %context) unnamed_addr { ++define internal fastcc void @y.init(ptr %context) unnamed_addr { + entry: + br label %loop + + loop: ; preds = %loop, %entry +- %val = load atomic i32, i32* @y.ready seq_cst, align 4 ++ %val = load atomic i32, ptr @y.ready seq_cst, align 4 + %ready = icmp eq i32 %val, 1 + br i1 %ready, label %end, label %loop + +@@ -55,15 +55,15 @@ end: ; preds = %loop + ret void + } + +-define internal fastcc void @z.setArr(i8* %arr, i64 %n, i8* %context) unnamed_addr { ++define internal fastcc void @z.setArr(ptr %arr, i64 %n, ptr %context) unnamed_addr { + entry: + br label %loop +- ++ + loop: ; preds = %loop, %entry + %prev = phi i64 [ %n, %entry ], [ %idx, %loop ] + %idx = sub i64 %prev, 1 +- %elem = getelementptr i8, i8* %arr, i64 %idx +- call fastcc void @z.set(i8* %elem, i8* %context) ++ %elem = getelementptr i8, ptr %arr, i64 %idx ++ call fastcc void @z.set(ptr %elem, ptr %context) + %done = icmp eq i64 %idx, 0 + br i1 %done, label %end, label %loop + +@@ -71,13 +71,12 @@ end: ; preds = %loop + ret void + } + +-define internal fastcc void @z.set(i8* %ptr, i8* %context) unnamed_addr { +- %hash = call i64 @ptrHash(i8* %ptr) ++define internal fastcc void @z.set(ptr %ptr, ptr %context) unnamed_addr { ++ %hash = call i64 @ptrHash(ptr %ptr) + %index = lshr i64 %hash, 58 + %bit = shl i64 1, %index +- %bloom = bitcast i8* %context to i64* +- %old = load i64, i64* %bloom, align 8 ++ %old = load i64, ptr %context, align 8 + %new = or i64 %old, %bit +- store i64 %new, i64* %bloom, align 8 ++ store i64 %new, ptr %context, align 8 + ret void +-} +\ No newline at end of file ++} +diff --git a/interp/testdata/slice-copy.ll b/interp/testdata/slice-copy.ll +index 52cbb372..6776d2d6 100644 +--- a/interp/testdata/slice-copy.ll ++++ b/interp/testdata/slice-copy.ll +@@ -2,15 +2,15 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + target triple = "x86_64--linux" + + @main.uint8SliceSrc.buf = internal global [2 x i8] c"\03d" +-@main.uint8SliceSrc = internal unnamed_addr global { i8*, i64, i64 } { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @main.uint8SliceSrc.buf, i32 0, i32 0), i64 2, i64 2 } +-@main.uint8SliceDst = internal unnamed_addr global { i8*, i64, i64 } zeroinitializer ++@main.uint8SliceSrc = internal unnamed_addr global { ptr, i64, i64 } { ptr @main.uint8SliceSrc.buf, i64 2, i64 2 } ++@main.uint8SliceDst = internal unnamed_addr global { ptr, i64, i64 } zeroinitializer + @main.int16SliceSrc.buf = internal global [3 x i16] [i16 5, i16 123, i16 1024] +-@main.int16SliceSrc = internal unnamed_addr global { i16*, i64, i64 } { i16* getelementptr inbounds ([3 x i16], [3 x i16]* @main.int16SliceSrc.buf, i32 0, i32 0), i64 3, i64 3 } +-@main.int16SliceDst = internal unnamed_addr global { i16*, i64, i64 } zeroinitializer ++@main.int16SliceSrc = internal unnamed_addr global { ptr, i64, i64 } { ptr @main.int16SliceSrc.buf, i64 3, i64 3 } ++@main.int16SliceDst = internal unnamed_addr global { ptr, i64, i64 } zeroinitializer + +-declare i64 @runtime.sliceCopy(i8* %dst, i8* %src, i64 %dstLen, i64 %srcLen, i64 %elemSize) unnamed_addr ++declare i64 @runtime.sliceCopy(ptr %dst, ptr %src, i64 %dstLen, i64 %srcLen, i64 %elemSize) unnamed_addr + +-declare i8* @runtime.alloc(i64, i8*) unnamed_addr ++declare ptr @runtime.alloc(i64, ptr) unnamed_addr + + declare void @runtime.printuint8(i8) + +@@ -25,23 +25,23 @@ entry: + define void @main() unnamed_addr { + entry: + ; print(uintSliceSrc[0]) +- %uint8SliceSrc.buf = load i8*, i8** getelementptr inbounds ({ i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceSrc, i64 0, i32 0) +- %uint8SliceSrc.val = load i8, i8* %uint8SliceSrc.buf ++ %uint8SliceSrc.buf = load ptr, ptr @main.uint8SliceSrc ++ %uint8SliceSrc.val = load i8, ptr %uint8SliceSrc.buf + call void @runtime.printuint8(i8 %uint8SliceSrc.val) + + ; print(uintSliceDst[0]) +- %uint8SliceDst.buf = load i8*, i8** getelementptr inbounds ({ i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceDst, i64 0, i32 0) +- %uint8SliceDst.val = load i8, i8* %uint8SliceDst.buf ++ %uint8SliceDst.buf = load ptr, ptr @main.uint8SliceDst ++ %uint8SliceDst.val = load i8, ptr %uint8SliceDst.buf + call void @runtime.printuint8(i8 %uint8SliceDst.val) + + ; print(int16SliceSrc[0]) +- %int16SliceSrc.buf = load i16*, i16** getelementptr inbounds ({ i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceSrc, i64 0, i32 0) +- %int16SliceSrc.val = load i16, i16* %int16SliceSrc.buf ++ %int16SliceSrc.buf = load ptr, ptr @main.int16SliceSrc ++ %int16SliceSrc.val = load i16, ptr %int16SliceSrc.buf + call void @runtime.printint16(i16 %int16SliceSrc.val) + + ; print(int16SliceDst[0]) +- %int16SliceDst.buf = load i16*, i16** getelementptr inbounds ({ i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceDst, i64 0, i32 0) +- %int16SliceDst.val = load i16, i16* %int16SliceDst.buf ++ %int16SliceDst.buf = load ptr, ptr @main.int16SliceDst ++ %int16SliceDst.val = load i16, ptr %int16SliceDst.buf + call void @runtime.printint16(i16 %int16SliceDst.val) + ret void + } +@@ -50,37 +50,34 @@ define internal void @main.init() unnamed_addr { + entry: + ; equivalent of: + ; uint8SliceDst = make([]uint8, len(uint8SliceSrc)) +- %uint8SliceSrc = load { i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceSrc +- %uint8SliceSrc.len = extractvalue { i8*, i64, i64 } %uint8SliceSrc, 1 +- %uint8SliceDst.buf = call i8* @runtime.alloc(i64 %uint8SliceSrc.len, i8* null) +- %0 = insertvalue { i8*, i64, i64 } undef, i8* %uint8SliceDst.buf, 0 +- %1 = insertvalue { i8*, i64, i64 } %0, i64 %uint8SliceSrc.len, 1 +- %2 = insertvalue { i8*, i64, i64 } %1, i64 %uint8SliceSrc.len, 2 +- store { i8*, i64, i64 } %2, { i8*, i64, i64 }* @main.uint8SliceDst ++ %uint8SliceSrc = load { ptr, i64, i64 }, ptr @main.uint8SliceSrc ++ %uint8SliceSrc.len = extractvalue { ptr, i64, i64 } %uint8SliceSrc, 1 ++ %uint8SliceDst.buf = call ptr @runtime.alloc(i64 %uint8SliceSrc.len, ptr null) ++ %0 = insertvalue { ptr, i64, i64 } undef, ptr %uint8SliceDst.buf, 0 ++ %1 = insertvalue { ptr, i64, i64 } %0, i64 %uint8SliceSrc.len, 1 ++ %2 = insertvalue { ptr, i64, i64 } %1, i64 %uint8SliceSrc.len, 2 ++ store { ptr, i64, i64 } %2, ptr @main.uint8SliceDst + + ; equivalent of: + ; copy(uint8SliceDst, uint8SliceSrc) +- %uint8SliceSrc.buf = extractvalue { i8*, i64, i64 } %uint8SliceSrc, 0 +- %copy.n = call i64 @runtime.sliceCopy(i8* %uint8SliceDst.buf, i8* %uint8SliceSrc.buf, i64 %uint8SliceSrc.len, i64 %uint8SliceSrc.len, i64 1) ++ %uint8SliceSrc.buf = extractvalue { ptr, i64, i64 } %uint8SliceSrc, 0 ++ %copy.n = call i64 @runtime.sliceCopy(ptr %uint8SliceDst.buf, ptr %uint8SliceSrc.buf, i64 %uint8SliceSrc.len, i64 %uint8SliceSrc.len, i64 1) + + ; equivalent of: + ; int16SliceDst = make([]int16, len(int16SliceSrc)) +- %int16SliceSrc = load { i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceSrc +- %int16SliceSrc.len = extractvalue { i16*, i64, i64 } %int16SliceSrc, 1 ++ %int16SliceSrc = load { ptr, i64, i64 }, ptr @main.int16SliceSrc ++ %int16SliceSrc.len = extractvalue { ptr, i64, i64 } %int16SliceSrc, 1 + %int16SliceSrc.len.bytes = mul i64 %int16SliceSrc.len, 2 +- %int16SliceDst.buf.raw = call i8* @runtime.alloc(i64 %int16SliceSrc.len.bytes, i8* null) +- %int16SliceDst.buf = bitcast i8* %int16SliceDst.buf.raw to i16* +- %3 = insertvalue { i16*, i64, i64 } undef, i16* %int16SliceDst.buf, 0 +- %4 = insertvalue { i16*, i64, i64 } %3, i64 %int16SliceSrc.len, 1 +- %5 = insertvalue { i16*, i64, i64 } %4, i64 %int16SliceSrc.len, 2 +- store { i16*, i64, i64 } %5, { i16*, i64, i64 }* @main.int16SliceDst ++ %int16SliceDst.buf = call ptr @runtime.alloc(i64 %int16SliceSrc.len.bytes, ptr null) ++ %3 = insertvalue { ptr, i64, i64 } undef, ptr %int16SliceDst.buf, 0 ++ %4 = insertvalue { ptr, i64, i64 } %3, i64 %int16SliceSrc.len, 1 ++ %5 = insertvalue { ptr, i64, i64 } %4, i64 %int16SliceSrc.len, 2 ++ store { ptr, i64, i64 } %5, ptr @main.int16SliceDst + + ; equivalent of: + ; copy(int16SliceDst, int16SliceSrc) +- %int16SliceSrc.buf = extractvalue { i16*, i64, i64 } %int16SliceSrc, 0 +- %int16SliceSrc.buf.i8ptr = bitcast i16* %int16SliceSrc.buf to i8* +- %int16SliceDst.buf.i8ptr = bitcast i16* %int16SliceDst.buf to i8* +- %copy.n2 = call i64 @runtime.sliceCopy(i8* %int16SliceDst.buf.i8ptr, i8* %int16SliceSrc.buf.i8ptr, i64 %int16SliceSrc.len, i64 %int16SliceSrc.len, i64 2) ++ %int16SliceSrc.buf = extractvalue { ptr, i64, i64 } %int16SliceSrc, 0 ++ %copy.n2 = call i64 @runtime.sliceCopy(ptr %int16SliceDst.buf, ptr %int16SliceSrc.buf, i64 %int16SliceSrc.len, i64 %int16SliceSrc.len, i64 2) + + ret void + } +-- +2.39.2 + diff --git a/0011-Update-types-in-cgo-tests-for-LLVM-16.patch b/0011-Update-types-in-cgo-tests-for-LLVM-16.patch new file mode 100644 index 0000000..9c64a73 --- /dev/null +++ b/0011-Update-types-in-cgo-tests-for-LLVM-16.patch @@ -0,0 +1,200 @@ +From 9f0efb001ea0afc109ad24d59fc1b99f09bf852a Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 15 Apr 2023 19:41:18 -0400 +Subject: [PATCH 11/11] Update types in cgo tests for LLVM 16 + +Signed-off-by: Elliott Sales de Andrade +--- + cgo/cgo_test.go | 5 +++ + cgo/testdata/errors.out.go | 4 +-- + cgo/testdata/types.out.go | 70 ++++++++++++++++++-------------------- + 3 files changed, 41 insertions(+), 38 deletions(-) + +diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go +index a44dd8e1..81d03c5d 100644 +--- a/cgo/cgo_test.go ++++ b/cgo/cgo_test.go +@@ -15,6 +15,8 @@ import ( + "runtime" + "strings" + "testing" ++ ++ "github.com/tinygo-org/tinygo/compiler/llvmutil" + ) + + // Pass -update to go test to update the output of the test files. +@@ -107,6 +109,9 @@ func TestCGo(t *testing.T) { + + // Check whether the output is as expected. + if expected != actual { ++ if llvmutil.Major() < 16 && (name == "errors" || name == "types") { ++ return ++ } + // It is not. Test failed. + if *flagUpdate { + // Update the file with the expected data. +diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go +index 716fd771..b1646a2e 100644 +--- a/cgo/testdata/errors.out.go ++++ b/cgo/testdata/errors.out.go +@@ -51,10 +51,10 @@ type ( + C.longlong int64 + C.ulonglong uint64 + ) +-type C._Ctype_struct___0 struct { ++type C.struct_point_t struct { + x C.int + y C.int + } +-type C.point_t = C._Ctype_struct___0 ++type C.point_t = C.struct_point_t + + const C.SOME_CONST_3 = 1234 +diff --git a/cgo/testdata/types.out.go b/cgo/testdata/types.out.go +index bd7b3fc4..4e60715b 100644 +--- a/cgo/testdata/types.out.go ++++ b/cgo/testdata/types.out.go +@@ -38,11 +38,11 @@ type ( + C.ulonglong uint64 + ) + type C.myint = C.int +-type C._Ctype_struct___0 struct { ++type C.struct_point2d_t struct { + x C.int + y C.int + } +-type C.point2d_t = C._Ctype_struct___0 ++type C.point2d_t = C.struct_point2d_t + type C.struct_point3d struct { + x C.int + y C.int +@@ -55,21 +55,19 @@ type C.struct_type1 struct { + ___type C.int + } + type C.struct_type2 struct{ _type C.int } +-type C._Ctype_union___1 struct{ i C.int } +-type C.union1_t = C._Ctype_union___1 +-type C._Ctype_union___2 struct{ $union uint64 } ++type C.union_union1_t struct{ i C.int } ++type C.union1_t = C.union_union1_t ++type C.union_union3_t struct{ $union uint64 } + +-func (union *C._Ctype_union___2) unionfield_i() *C.int { +- return (*C.int)(unsafe.Pointer(&union.$union)) +-} +-func (union *C._Ctype_union___2) unionfield_d() *float64 { ++func (union *C.union_union3_t) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) } ++func (union *C.union_union3_t) unionfield_d() *float64 { + return (*float64)(unsafe.Pointer(&union.$union)) + } +-func (union *C._Ctype_union___2) unionfield_s() *C.short { ++func (union *C.union_union3_t) unionfield_s() *C.short { + return (*C.short)(unsafe.Pointer(&union.$union)) + } + +-type C.union3_t = C._Ctype_union___2 ++type C.union3_t = C.union_union3_t + type C.union_union2d struct{ $union [2]uint64 } + + func (union *C.union_union2d) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) } +@@ -78,50 +76,50 @@ func (union *C.union_union2d) unionfield_d() *[2]float64 { + } + + type C.union2d_t = C.union_union2d +-type C._Ctype_union___3 struct{ arr [10]C.uchar } +-type C.unionarray_t = C._Ctype_union___3 +-type C._Ctype_union___5 struct{ $union [3]uint32 } ++type C.union_unionarray_t struct{ arr [10]C.uchar } ++type C.unionarray_t = C.union_unionarray_t ++type C.union_union (unnamed at testdata/types.go:54:2) struct{ $union [3]uint32 } + +-func (union *C._Ctype_union___5) unionfield_area() *C.point2d_t { ++func (union *C.union_union (unnamed at testdata/types.go:54:2)) unionfield_area() *C.point2d_t { + return (*C.point2d_t)(unsafe.Pointer(&union.$union)) + } +-func (union *C._Ctype_union___5) unionfield_solid() *C.point3d_t { ++func (union *C.union_union (unnamed at testdata/types.go:54:2)) unionfield_solid() *C.point3d_t { + return (*C.point3d_t)(unsafe.Pointer(&union.$union)) + } + +-type C._Ctype_struct___4 struct { ++type C.struct_struct_nested_t struct { + begin C.point2d_t + end C.point2d_t + tag C.int + +- coord C._Ctype_union___5 ++ coord C.union_union (unnamed at testdata/types.go:54:2) + } +-type C.struct_nested_t = C._Ctype_struct___4 +-type C._Ctype_union___6 struct{ $union [2]uint64 } ++type C.struct_nested_t = C.struct_struct_nested_t ++type C.union_union_nested_t struct{ $union [2]uint64 } + +-func (union *C._Ctype_union___6) unionfield_point() *C.point3d_t { ++func (union *C.union_union_nested_t) unionfield_point() *C.point3d_t { + return (*C.point3d_t)(unsafe.Pointer(&union.$union)) + } +-func (union *C._Ctype_union___6) unionfield_array() *C.unionarray_t { ++func (union *C.union_union_nested_t) unionfield_array() *C.unionarray_t { + return (*C.unionarray_t)(unsafe.Pointer(&union.$union)) + } +-func (union *C._Ctype_union___6) unionfield_thing() *C.union3_t { ++func (union *C.union_union_nested_t) unionfield_thing() *C.union3_t { + return (*C.union3_t)(unsafe.Pointer(&union.$union)) + } + +-type C.union_nested_t = C._Ctype_union___6 ++type C.union_nested_t = C.union_union_nested_t + type C.enum_option = C.int + type C.option_t = C.enum_option +-type C._Ctype_enum___7 = C.uint +-type C.option2_t = C._Ctype_enum___7 +-type C._Ctype_struct___8 struct { ++type C.enum_option2_t = C.uint ++type C.option2_t = C.enum_option2_t ++type C.struct_types_t struct { + f float32 + d float64 + ptr *C.int + } +-type C.types_t = C._Ctype_struct___8 ++type C.types_t = C.struct_types_t + type C.myIntArray = [10]C.int +-type C._Ctype_struct___9 struct { ++type C.struct_bitfield_t struct { + start C.uchar + __bitfield_1 C.uchar + +@@ -129,21 +127,21 @@ type C._Ctype_struct___9 struct { + e C.uchar + } + +-func (s *C._Ctype_struct___9) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f } +-func (s *C._Ctype_struct___9) set_bitfield_a(value C.uchar) { ++func (s *C.struct_bitfield_t) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f } ++func (s *C.struct_bitfield_t) set_bitfield_a(value C.uchar) { + s.__bitfield_1 = s.__bitfield_1&^0x1f | value&0x1f<<0 + } +-func (s *C._Ctype_struct___9) bitfield_b() C.uchar { ++func (s *C.struct_bitfield_t) bitfield_b() C.uchar { + return s.__bitfield_1 >> 5 & 0x1 + } +-func (s *C._Ctype_struct___9) set_bitfield_b(value C.uchar) { ++func (s *C.struct_bitfield_t) set_bitfield_b(value C.uchar) { + s.__bitfield_1 = s.__bitfield_1&^0x20 | value&0x1<<5 + } +-func (s *C._Ctype_struct___9) bitfield_c() C.uchar { ++func (s *C.struct_bitfield_t) bitfield_c() C.uchar { + return s.__bitfield_1 >> 6 + } +-func (s *C._Ctype_struct___9) set_bitfield_c(value C.uchar, ++func (s *C.struct_bitfield_t) set_bitfield_c(value C.uchar, + + ) { s.__bitfield_1 = s.__bitfield_1&0x3f | value<<6 } + +-type C.bitfield_t = C._Ctype_struct___9 ++type C.bitfield_t = C.struct_bitfield_t +-- +2.39.2 + diff --git a/tinygo.spec b/tinygo.spec index 6c74cab..e4129ac 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,11 +10,15 @@ Version: 0.27.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%if %{fedora} > 37 +%global clang_llvm_version 16 +%else %if %{fedora} > 36 %global clang_llvm_version 15 %else %global clang_llvm_version 14 %endif +%endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 @@ -85,6 +89,18 @@ Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch Patch0004: 0004-Skip-TestDirFS-on-32-bit-systems.patch Patch0005: 0005-Skip-broken-tests-on-i686.patch +# Support LLVM 16. +# https://github.com/tinygo-org/tinygo/pull/3649 +Patch0006: 0006-cgo-Handle-elaborated-typedefs-from-libclang.patch +Patch0007: 0007-Add-CPU-to-RISCV-targets.patch +Patch0008: 0008-Handle-argmemonly-attribute-change-in-LLVM16.patch +# https://github.com/tinygo-org/tinygo/pull/3566 +Patch0009: 0009-Update-transform-tests-with-opaque-pointers.patch +# https://github.com/tinygo-org/tinygo/pull/3658 +Patch0010: 0010-Switch-interp-tests-to-opaque-pointers.patch +# https://github.com/tinygo-org/tinygo/pull/3649 +Patch0011: 0011-Update-types-in-cgo-tests-for-LLVM-16.patch + # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval From 694d1924a184d51e03d35e5043e21655dfb85048 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 16 Apr 2023 16:45:29 -0400 Subject: [PATCH 48/78] Upload sources [skip changelog] --- sources | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources b/sources index 4290095..6f1fd54 100644 --- a/sources +++ b/sources @@ -2,8 +2,8 @@ SHA512 (tinygo-0.27.0.tar.gz) = b247d799ec99764f34bfd5dff81e0beb454d2b39a178d561 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-15.0.0.src.tar.xz) = 25763e581c90923260b7c3a03e220feb4cabb2757e418c4940db0eeb6a17f65b35db0c93d3c1e526adad2f6dc93595bec6d99b1bfb4a1bd13a14a0db5301e6cf -SHA512 (compiler-rt-15.0.0.src.tar.xz.sig) = 94f39d2e30372ccea4db96c3dd4005a5b44c2bf5d22fa0aaf45b86673ef7d3460884689f97bc96470db2d546042fb01fe3ca41bf22b6323abe0cd785b85d76ef +SHA512 (compiler-rt-16.0.0.src.tar.xz) = 6906964f0aa12bb18b137bee68a562412abf6d0200f8cfece83dc860ad06de41de847d04809fba08d9e2bb61f27e036eadb51fce153e05181f0bd4fecf29727d +SHA512 (compiler-rt-16.0.0.src.tar.xz.sig) = 8c6de41ed7bed40930fa60f2549ba1267d0b6ef6ed05f3febd879066b9bf8a812a7faccbd3bb791c5780a91f13decc3be0cb5e4cbe7d6281e5e96a4e21593119 SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c SHA512 (musl-1.2.3.tar.gz.asc) = 01a857dbc3981c90244d4d1d883efe51986652ca5734a741c9d1a4d06c5a22831e85520ac67212268b70c22049317a8f39b3219be182e7e67741add428ac5bc6 From 0539d75995753754d63d7240255d8eb0d9334f2c Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 22 Jul 2023 16:22:44 +0000 Subject: [PATCH 49/78] Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild Signed-off-by: Fedora Release Engineering From b2c23a4f26d587c5e0f85e39941085c515b3d317 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 7 Aug 2023 20:19:38 -0400 Subject: [PATCH 50/78] Remove outdated arch checks i686 and armv7hl were removed as possible build architectures some time ago. --- 0001-Skip-WASI-tests.patch | 6 +-- ...oss-Linux-tests-where-qemu-is-broken.patch | 38 +++++----------- ...ional-packages-to-install-if-missing.patch | 6 +-- 0004-Skip-TestDirFS-on-32-bit-systems.patch | 30 ------------- ...le-elaborated-typedefs-from-libclang.patch | 6 +-- ...tch => 0005-Add-CPU-to-RISCV-targets.patch | 6 +-- 0005-Skip-broken-tests-on-i686.patch | 44 ------------------- ...rgmemonly-attribute-change-in-LLVM16.patch | 6 +-- ...transform-tests-with-opaque-pointers.patch | 7 +-- ...itch-interp-tests-to-opaque-pointers.patch | 6 +-- ...pdate-types-in-cgo-tests-for-LLVM-16.patch | 6 +-- tinygo.spec | 33 ++++---------- 12 files changed, 45 insertions(+), 149 deletions(-) delete mode 100644 0004-Skip-TestDirFS-on-32-bit-systems.patch rename 0006-cgo-Handle-elaborated-typedefs-from-libclang.patch => 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch (91%) rename 0007-Add-CPU-to-RISCV-targets.patch => 0005-Add-CPU-to-RISCV-targets.patch (93%) delete mode 100644 0005-Skip-broken-tests-on-i686.patch rename 0008-Handle-argmemonly-attribute-change-in-LLVM16.patch => 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch (95%) rename 0009-Update-transform-tests-with-opaque-pointers.patch => 0007-Update-transform-tests-with-opaque-pointers.patch (99%) rename 0010-Switch-interp-tests-to-opaque-pointers.patch => 0008-Switch-interp-tests-to-opaque-pointers.patch (99%) rename 0011-Update-types-in-cgo-tests-for-LLVM-16.patch => 0009-Update-types-in-cgo-tests-for-LLVM-16.patch (98%) diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 07b1c20..b288709 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From c9fd61dedd6dd52edc9a3058d71923a639e2425f Mon Sep 17 00:00:00 2001 +From 29990c461883fbab3d41eae046302f4d0bd67e6c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 01/11] Skip WASI tests. +Subject: [PATCH 1/9] Skip WASI tests. We do not have wasmtime available. @@ -34,5 +34,5 @@ index 72f3c4bb..b89ca6b9 100644 } for _, targ := range targs { -- -2.39.2 +2.41.0 diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 9361e65..324defb 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 620ccf53e2a04f77aaae47a818db9bfef76f3104 Mon Sep 17 00:00:00 2001 +From 2204b7a8f7f19b7dda6a2f4d434ebf660b1126d8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 02/11] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/9] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -10,55 +10,41 @@ The upstream issues will hopefully be fixed soon: Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 28 ++++++++++++++++++++++++++++ - 1 file changed, 28 insertions(+) + main_test.go | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) diff --git a/main_test.go b/main_test.go -index b89ca6b9..5168ad39 100644 +index b89ca6b9..c31764e6 100644 --- a/main_test.go +++ b/main_test.go -@@ -245,6 +245,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -245,6 +245,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { + // Skip running the test executable due to bugs in qemu. + // https://gitlab.com/qemu-project/qemu/-/issues/447 + // https://gitlab.com/qemu-project/qemu/-/issues/690 -+ switch runtime.GOARCH { -+ case "arm64": -+ if options.GOARCH == "386" || options.GOARCH == "arm" { -+ t.Skipf("qemu is broken for this host/target architecture combination") -+ } -+ case "386": -+ if options.GOARCH == "arm" { -+ t.Skipf("qemu is broken for this host/target architecture combination") -+ } ++ if runtime.GOARCH == "arm64" && (options.GOARCH == "386" || options.GOARCH == "arm") { ++ t.Skipf("qemu is broken for this host/target architecture combination") + } + // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -334,6 +348,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -334,6 +341,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } + // Skip running the test executable due to bugs in qemu. + // https://gitlab.com/qemu-project/qemu/-/issues/447 + // https://gitlab.com/qemu-project/qemu/-/issues/690 -+ switch runtime.GOARCH { -+ case "arm64": -+ if options.GOARCH == "386" || options.GOARCH == "arm" { -+ return -+ } -+ case "386": -+ if options.GOARCH == "arm" { -+ return -+ } ++ if runtime.GOARCH == "arm64" && (options.GOARCH == "386" || options.GOARCH == "arm") { ++ return + } + // putchar() prints CRLF, convert it to LF. actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows -- -2.39.2 +2.41.0 diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index 98e685d..3cd2fb7 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From eab4bc3acc9b6381b0526049c001d78edc3f6902 Mon Sep 17 00:00:00 2001 +From f25ed99c4c7e14d40795045311b0f48860e7f68c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 03/11] Suggest optional packages to install if missing +Subject: [PATCH 3/9] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -44,5 +44,5 @@ index 3d510974..d24a4165 100644 // doing anything. This can be useful where a *compileJob producing an output is // expected but nothing needs to be done, for example for a load from a cache. -- -2.39.2 +2.41.0 diff --git a/0004-Skip-TestDirFS-on-32-bit-systems.patch b/0004-Skip-TestDirFS-on-32-bit-systems.patch deleted file mode 100644 index 9a6a8e1..0000000 --- a/0004-Skip-TestDirFS-on-32-bit-systems.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 3b851724c839268253ef0c243f379dbef4c0cfd6 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 8 May 2022 04:18:05 -0400 -Subject: [PATCH 04/11] Skip TestDirFS on 32-bit systems - -Because Seek is not fully implemented there. - -Signed-off-by: Elliott Sales de Andrade ---- - src/os/os_anyos_test.go | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/os/os_anyos_test.go b/src/os/os_anyos_test.go -index 76bf4f36..97b5cce8 100644 ---- a/src/os/os_anyos_test.go -+++ b/src/os/os_anyos_test.go -@@ -276,6 +276,10 @@ func TestDirFS(t *testing.T) { - t.Log("TODO: implement Readdir for Windows") - return - } -+ if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { -+ t.Log("TODO: implement seek for 386 and arm") -+ return -+ } - if isWASI { - t.Log("TODO: allow foo/bar/. as synonym for path foo/bar on wasi?") - return --- -2.39.2 - diff --git a/0006-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch similarity index 91% rename from 0006-cgo-Handle-elaborated-typedefs-from-libclang.patch rename to 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch index 8e03381..d4c5129 100644 --- a/0006-cgo-Handle-elaborated-typedefs-from-libclang.patch +++ b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch @@ -1,7 +1,7 @@ -From 4d93f7ce0481f884fefeb4a8d3dbb9ca795470d8 Mon Sep 17 00:00:00 2001 +From a1d9a3863c6ad128c04120409139d1b6e40361c6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Apr 2023 04:55:27 -0400 -Subject: [PATCH 06/11] cgo: Handle elaborated typedefs from libclang +Subject: [PATCH 4/9] cgo: Handle elaborated typedefs from libclang I don't have a reference for this change in LLVM 16, so I just handled it the same way as other elaborated types. @@ -38,5 +38,5 @@ index 27ac1b57..95eb554a 100644 typeKindSpelling := getString(C.clang_getTypeKindSpelling(underlying.kind)) f.addError(pos, fmt.Sprintf("unknown elaborated type (libclang type kind %s)", typeKindSpelling)) -- -2.39.2 +2.41.0 diff --git a/0007-Add-CPU-to-RISCV-targets.patch b/0005-Add-CPU-to-RISCV-targets.patch similarity index 93% rename from 0007-Add-CPU-to-RISCV-targets.patch rename to 0005-Add-CPU-to-RISCV-targets.patch index d9c0b92..79b8d78 100644 --- a/0007-Add-CPU-to-RISCV-targets.patch +++ b/0005-Add-CPU-to-RISCV-targets.patch @@ -1,7 +1,7 @@ -From 2760ff1337f9311aa806c8b0492cfab1d5f42a64 Mon Sep 17 00:00:00 2001 +From 74a89ed47502237b0df6b4dc75b9fc41a30f99b3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Apr 2023 05:51:10 -0400 -Subject: [PATCH 07/11] Add CPU to RISCV targets +Subject: [PATCH 5/9] Add CPU to RISCV targets Signed-off-by: Elliott Sales de Andrade --- @@ -60,5 +60,5 @@ index fc45c91c..8f44ce53 100644 "build-tags": ["tinygo.riscv64"], "cflags": [ -- -2.39.2 +2.41.0 diff --git a/0005-Skip-broken-tests-on-i686.patch b/0005-Skip-broken-tests-on-i686.patch deleted file mode 100644 index 3733c2f..0000000 --- a/0005-Skip-broken-tests-on-i686.patch +++ /dev/null @@ -1,44 +0,0 @@ -From f432e01f5d2b8c64f74eeebf30dd428a421ee128 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 8 May 2022 18:39:26 -0400 -Subject: [PATCH 05/11] Skip broken tests on i686 - -* compress/flate runs out of memory -* testing/fstest uses Seek, which is not implemented there - -Signed-off-by: Elliott Sales de Andrade ---- - Makefile | 10 ++++++++-- - 1 file changed, 8 insertions(+), 2 deletions(-) - -diff --git a/Makefile b/Makefile -index 452b0171..f04ccbdb 100644 ---- a/Makefile -+++ b/Makefile -@@ -343,15 +343,21 @@ endif - # Additional standard library packages that pass tests on individual platforms - TEST_PACKAGES_LINUX := \ - archive/zip \ -- compress/flate \ - compress/lzw \ - crypto/hmac \ - debug/dwarf \ - debug/plan9obj \ - io/ioutil \ - strconv \ -- testing/fstest \ - text/template/parse -+ifneq ($(shell getconf LONG_BIT),32) -+# Some tests are skipped on 32-bit because: -+# compress/flate runs out of memory -+# testing/fstest uses Seek, which is not implemented there -+TEST_PACKAGES_LINUX += \ -+ compress/flate \ -+ testing/fstest -+endif - - TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) - --- -2.39.2 - diff --git a/0008-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch similarity index 95% rename from 0008-Handle-argmemonly-attribute-change-in-LLVM16.patch rename to 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch index 70e97c2..89b93db 100644 --- a/0008-Handle-argmemonly-attribute-change-in-LLVM16.patch +++ b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch @@ -1,7 +1,7 @@ -From 2d93b19a0640af385d9a8f12e9e10252a6b0cf56 Mon Sep 17 00:00:00 2001 +From d11f440b6c0652789f6093d0aecd0ff30fe1a070 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 03:41:21 -0400 -Subject: [PATCH 08/11] Handle argmemonly attribute change in LLVM16 +Subject: [PATCH 6/9] Handle argmemonly attribute change in LLVM16 Signed-off-by: Elliott Sales de Andrade --- @@ -80,5 +80,5 @@ index 6fdb1407..9cf0882f 100644 +attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } attributes #3 = { nounwind } -- -2.39.2 +2.41.0 diff --git a/0009-Update-transform-tests-with-opaque-pointers.patch b/0007-Update-transform-tests-with-opaque-pointers.patch similarity index 99% rename from 0009-Update-transform-tests-with-opaque-pointers.patch rename to 0007-Update-transform-tests-with-opaque-pointers.patch index 6350f61..5e1fc6b 100644 --- a/0009-Update-transform-tests-with-opaque-pointers.patch +++ b/0007-Update-transform-tests-with-opaque-pointers.patch @@ -1,7 +1,7 @@ -From 7bf36c8dbec4488f2b76f85ed48fda6d973d367c Mon Sep 17 00:00:00 2001 +From e4caa532a5d474209fdb737eab219a4963e1bb1e Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 16 Mar 2023 19:34:35 +0100 -Subject: [PATCH 09/11] Update transform tests with opaque pointers +Subject: [PATCH 7/9] Update transform tests with opaque pointers transform: update reflect-implements test to opaque pointers @@ -26,6 +26,7 @@ transform: update stringequal test to opaque pointers transform: update stringtobytes test to opaque pointers transform: update wasm-abi to use opaque pointers + Signed-off-by: Elliott Sales de Andrade --- transform/testdata/allocs.ll | 62 ++--- @@ -1718,5 +1719,5 @@ index cf63c3d7..a1fc7d6a 100644 ret void } -- -2.39.2 +2.41.0 diff --git a/0010-Switch-interp-tests-to-opaque-pointers.patch b/0008-Switch-interp-tests-to-opaque-pointers.patch similarity index 99% rename from 0010-Switch-interp-tests-to-opaque-pointers.patch rename to 0008-Switch-interp-tests-to-opaque-pointers.patch index 8225c59..1991075 100644 --- a/0010-Switch-interp-tests-to-opaque-pointers.patch +++ b/0008-Switch-interp-tests-to-opaque-pointers.patch @@ -1,7 +1,7 @@ -From 5dbdba87017a1369dd0ffc634042703d28a92889 Mon Sep 17 00:00:00 2001 +From 74b0c98c51d0f8d566393708ab13dc6943782b36 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 16:42:11 -0400 -Subject: [PATCH 10/11] Switch interp tests to opaque pointers +Subject: [PATCH 8/9] Switch interp tests to opaque pointers Signed-off-by: Elliott Sales de Andrade --- @@ -827,5 +827,5 @@ index 52cbb372..6776d2d6 100644 ret void } -- -2.39.2 +2.41.0 diff --git a/0011-Update-types-in-cgo-tests-for-LLVM-16.patch b/0009-Update-types-in-cgo-tests-for-LLVM-16.patch similarity index 98% rename from 0011-Update-types-in-cgo-tests-for-LLVM-16.patch rename to 0009-Update-types-in-cgo-tests-for-LLVM-16.patch index 9c64a73..f4d77c1 100644 --- a/0011-Update-types-in-cgo-tests-for-LLVM-16.patch +++ b/0009-Update-types-in-cgo-tests-for-LLVM-16.patch @@ -1,7 +1,7 @@ -From 9f0efb001ea0afc109ad24d59fc1b99f09bf852a Mon Sep 17 00:00:00 2001 +From c5f4641ed369083b04d1ed0616a7c4bf674845d9 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 19:41:18 -0400 -Subject: [PATCH 11/11] Update types in cgo tests for LLVM 16 +Subject: [PATCH 9/9] Update types in cgo tests for LLVM 16 Signed-off-by: Elliott Sales de Andrade --- @@ -196,5 +196,5 @@ index bd7b3fc4..4e60715b 100644 -type C.bitfield_t = C._Ctype_struct___9 +type C.bitfield_t = C.struct_bitfield_t -- -2.39.2 +2.41.0 diff --git a/tinygo.spec b/tinygo.spec index e4129ac..46685ab 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -85,35 +85,29 @@ Patch0002: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch -# https://github.com/tinygo-org/tinygo/pull/2840 -Patch0004: 0004-Skip-TestDirFS-on-32-bit-systems.patch -Patch0005: 0005-Skip-broken-tests-on-i686.patch - # Support LLVM 16. # https://github.com/tinygo-org/tinygo/pull/3649 -Patch0006: 0006-cgo-Handle-elaborated-typedefs-from-libclang.patch -Patch0007: 0007-Add-CPU-to-RISCV-targets.patch -Patch0008: 0008-Handle-argmemonly-attribute-change-in-LLVM16.patch +Patch0004: 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch +Patch0005: 0005-Add-CPU-to-RISCV-targets.patch +Patch0006: 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch # https://github.com/tinygo-org/tinygo/pull/3566 -Patch0009: 0009-Update-transform-tests-with-opaque-pointers.patch +Patch0007: 0007-Update-transform-tests-with-opaque-pointers.patch # https://github.com/tinygo-org/tinygo/pull/3658 -Patch0010: 0010-Switch-interp-tests-to-opaque-pointers.patch +Patch0008: 0008-Switch-interp-tests-to-opaque-pointers.patch # https://github.com/tinygo-org/tinygo/pull/3649 -Patch0011: 0011-Update-types-in-cgo-tests-for-LLVM-16.patch +Patch0009: 0009-Update-types-in-cgo-tests-for-LLVM-16.patch # Not supported upstream yet. -ExcludeArch: armv7hl ppc64le s390x +ExcludeArch: ppc64le s390x # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval ExcludeArch: %{ix86} BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) BuildRequires: golang(github.com/aykevl/go-wasm) BuildRequires: golang(github.com/blakesmith/ar) -%ifnarch %{ix86} BuildRequires: chromium BuildRequires: golang(github.com/chromedp/chromedp) >= 0.7.6 BuildRequires: golang(github.com/chromedp/cdproto/cdp) -%endif BuildRequires: golang(github.com/gofrs/flock) >= 0.8.1 BuildRequires: golang(github.com/google/shlex) BuildRequires: golang(github.com/inhies/go-bytesize) @@ -218,11 +212,6 @@ tar -C lib -xf %{SOURCE11} rmdir lib/mingw-w64 mv lib/mingw-w64-%{mingw64_commit} lib/mingw-w64 -# This test is too slow and pretty much freezes. -%ifarch %{ix86} -sed -i -e 's!archive/zip!$(nil)!' Makefile -%endif - %build # Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is # merged and released. @@ -327,17 +316,11 @@ export GO111MODULE=off export XDG_CACHE_HOME="${PWD}/$(mktemp -d tinygo.XXXXXX)" %gocheck -v -t src -t tests ( cd _build/src/%{goipath} && GOPATH=%{currentgosourcedir}/_build:$GOPATH make smoketest STM32=0 XTENSA=0 ) -%ifnarch %{ix86} aarch64 +%ifnarch aarch64 make wasmtest %endif -# Ignoring errors due to CGo issue: -# https://github.com/tinygo-org/tinygo/issues/3057 -%ifarch %{ix86} -make tinygo-test-fast -%else make tinygo-test %endif -%endif %files From 81801752303afe873c0d32f09e40f478da8d3158 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 7 Aug 2023 19:30:13 -0400 Subject: [PATCH 51/78] Update to latest version (#2214119) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 8 +-- ...oss-Linux-tests-where-qemu-is-broken.patch | 10 +-- ...ional-packages-to-install-if-missing.patch | 6 +- ...le-elaborated-typedefs-from-libclang.patch | 4 +- 0005-Add-CPU-to-RISCV-targets.patch | 6 +- ...rgmemonly-attribute-change-in-LLVM16.patch | 63 ++++++++++++++----- ...pdate-types-in-cgo-tests-for-LLVM-16.patch | 4 +- sources | 2 +- tinygo.spec | 9 +-- 10 files changed, 70 insertions(+), 43 deletions(-) rename 0009-Update-types-in-cgo-tests-for-LLVM-16.patch => 0007-Update-types-in-cgo-tests-for-LLVM-16.patch (98%) diff --git a/.gitignore b/.gitignore index 3668798..9ce9122 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ /musl-1.2.3.tar.gz /musl-1.2.3.tar.gz.asc /mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz +/tinygo-0.28.1.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index b288709..3a8cc13 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 29990c461883fbab3d41eae046302f4d0bd67e6c Mon Sep 17 00:00:00 2001 +From cbac45f83e2867012c9092024679beb1c9134435 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/9] Skip WASI tests. +Subject: [PATCH 1/7] Skip WASI tests. We do not have wasmtime available. @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index 72f3c4bb..b89ca6b9 100644 +index 59254656..cab523b7 100644 --- a/main_test.go +++ b/main_test.go @@ -151,10 +151,6 @@ func TestBuild(t *testing.T) { @@ -25,7 +25,7 @@ index 72f3c4bb..b89ca6b9 100644 } } -@@ -406,7 +402,6 @@ func TestTest(t *testing.T) { +@@ -403,7 +399,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 324defb..9a3a70d 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 2204b7a8f7f19b7dda6a2f4d434ebf660b1126d8 Mon Sep 17 00:00:00 2001 +From dcd2dcba814f7d910af630a3dd2e760c6fc21dd6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/9] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/7] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 14 insertions(+) diff --git a/main_test.go b/main_test.go -index b89ca6b9..c31764e6 100644 +index cab523b7..798f0ec9 100644 --- a/main_test.go +++ b/main_test.go -@@ -245,6 +245,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -242,6 +242,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -31,7 +31,7 @@ index b89ca6b9..c31764e6 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -334,6 +341,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -331,6 +338,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index 3cd2fb7..8193c76 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From f25ed99c4c7e14d40795045311b0f48860e7f68c Mon Sep 17 00:00:00 2001 +From e3bc238eadcd1d3bad8e10a1496ef496d90090cd Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/9] Suggest optional packages to install if missing +Subject: [PATCH 3/7] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -9,7 +9,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 17 insertions(+) diff --git a/builder/jobs.go b/builder/jobs.go -index 3d510974..d24a4165 100644 +index a23d0753..2380f683 100644 --- a/builder/jobs.go +++ b/builder/jobs.go @@ -7,6 +7,7 @@ import ( diff --git a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch index d4c5129..5731382 100644 --- a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch +++ b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch @@ -1,7 +1,7 @@ -From a1d9a3863c6ad128c04120409139d1b6e40361c6 Mon Sep 17 00:00:00 2001 +From aac3fe147d69800f2b909454815f5b2ed52800eb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Apr 2023 04:55:27 -0400 -Subject: [PATCH 4/9] cgo: Handle elaborated typedefs from libclang +Subject: [PATCH 4/7] cgo: Handle elaborated typedefs from libclang I don't have a reference for this change in LLVM 16, so I just handled it the same way as other elaborated types. diff --git a/0005-Add-CPU-to-RISCV-targets.patch b/0005-Add-CPU-to-RISCV-targets.patch index 79b8d78..7613f14 100644 --- a/0005-Add-CPU-to-RISCV-targets.patch +++ b/0005-Add-CPU-to-RISCV-targets.patch @@ -1,7 +1,7 @@ -From 74a89ed47502237b0df6b4dc75b9fc41a30f99b3 Mon Sep 17 00:00:00 2001 +From 084466294beb16440244374251ac9e6258929f18 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Apr 2023 05:51:10 -0400 -Subject: [PATCH 5/9] Add CPU to RISCV targets +Subject: [PATCH 5/7] Add CPU to RISCV targets Signed-off-by: Elliott Sales de Andrade --- @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 92e9315e..7bab755a 100644 +index 40a1d445..68f12707 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -14,6 +14,7 @@ import ( diff --git a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch index 89b93db..f4e6f85 100644 --- a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch +++ b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch @@ -1,16 +1,17 @@ -From d11f440b6c0652789f6093d0aecd0ff30fe1a070 Mon Sep 17 00:00:00 2001 +From 75e30cb418519e03b50fc64aa3a109376e612af0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 03:41:21 -0400 -Subject: [PATCH 6/9] Handle argmemonly attribute change in LLVM16 +Subject: [PATCH 6/7] Handle argmemonly attribute change in LLVM16 Signed-off-by: Elliott Sales de Andrade --- compiler/compiler_test.go | 15 ++++++++------- compiler/testdata/channel.ll | 6 +++--- - 2 files changed, 11 insertions(+), 10 deletions(-) + compiler/testdata/zeromap.ll | 6 +++--- + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index f8221a08..79dc22e9 100644 +index 6b5fbe13..b8cff5e8 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -4,11 +4,11 @@ import ( @@ -26,7 +27,7 @@ index f8221a08..79dc22e9 100644 "github.com/tinygo-org/tinygo/goenv" "github.com/tinygo-org/tinygo/loader" "tinygo.org/x/go-llvm" -@@ -191,12 +191,7 @@ func fuzzyEqualIR(s1, s2 string) bool { +@@ -151,12 +151,7 @@ func fuzzyEqualIR(s1, s2 string) bool { // stripped out. func filterIrrelevantIRLines(lines []string) []string { var out []string @@ -40,7 +41,7 @@ index f8221a08..79dc22e9 100644 for _, line := range lines { line = strings.Split(line, ";")[0] // strip out comments/info line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments -@@ -211,6 +206,12 @@ func filterIrrelevantIRLines(lines []string) []string { +@@ -171,6 +166,12 @@ func filterIrrelevantIRLines(lines []string) []string { // Right now test outputs are for LLVM 14 and higher. continue } @@ -54,31 +55,59 @@ index f8221a08..79dc22e9 100644 } return out diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index 6fdb1407..9cf0882f 100644 +index 9749effc..8ff64bd4 100644 --- a/compiler/testdata/channel.ll +++ b/compiler/testdata/channel.ll -@@ -30,12 +30,12 @@ entry: +@@ -31,12 +31,12 @@ entry: ret void } -; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn +; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) - declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2 + declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3 - declare void @runtime.chanSend(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #0 + declare void @runtime.chanSend(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #1 -; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn +; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) - declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2 + declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3 ; Function Attrs: nounwind -@@ -111,5 +111,5 @@ declare { i32, i1 } @runtime.tryChanSelect(ptr, ptr, i32, i32, ptr) #0 +@@ -113,5 +113,5 @@ declare { i32, i1 } @runtime.tryChanSelect(ptr, ptr, i32, i32, ptr) #1 + attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #1 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +-attributes #3 = { argmemonly nocallback nofree nosync nounwind willreturn } ++attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } + attributes #4 = { nounwind } +diff --git a/compiler/testdata/zeromap.ll b/compiler/testdata/zeromap.ll +index 69932a1a..6a3d3132 100644 +--- a/compiler/testdata/zeromap.ll ++++ b/compiler/testdata/zeromap.ll +@@ -43,14 +43,14 @@ entry: + ret i32 %6 + } - attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } --attributes #2 = { argmemonly nocallback nofree nosync nounwind willreturn } -+attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } - attributes #3 = { nounwind } +-; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn ++; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) + declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #4 + + declare void @runtime.memzero(ptr, i32, ptr) #1 + + declare i1 @runtime.hashmapBinaryGet(ptr dereferenceable_or_null(40), ptr, ptr, i32, ptr) #1 + +-; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn ++; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) + declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #4 + + ; Function Attrs: noinline nounwind +@@ -168,5 +168,5 @@ attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime + attributes #1 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #3 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +-attributes #4 = { argmemonly nocallback nofree nosync nounwind willreturn } ++attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } + attributes #5 = { nounwind } -- 2.41.0 diff --git a/0009-Update-types-in-cgo-tests-for-LLVM-16.patch b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch similarity index 98% rename from 0009-Update-types-in-cgo-tests-for-LLVM-16.patch rename to 0007-Update-types-in-cgo-tests-for-LLVM-16.patch index f4d77c1..ebfacb5 100644 --- a/0009-Update-types-in-cgo-tests-for-LLVM-16.patch +++ b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch @@ -1,7 +1,7 @@ -From c5f4641ed369083b04d1ed0616a7c4bf674845d9 Mon Sep 17 00:00:00 2001 +From 56388dc66838222c7ffb98e30221ef72f6316dcf Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 19:41:18 -0400 -Subject: [PATCH 9/9] Update types in cgo tests for LLVM 16 +Subject: [PATCH 7/7] Update types in cgo tests for LLVM 16 Signed-off-by: Elliott Sales de Andrade --- diff --git a/sources b/sources index 6f1fd54..571e544 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.27.0.tar.gz) = b247d799ec99764f34bfd5dff81e0beb454d2b39a178d5618247ba7b9bdf3cc5fd6a20b48be9171168c31a08370ee0c56d76d32925b62fb12789f0ded5b17176 +SHA512 (tinygo-0.28.1.tar.gz) = 9dba475997717f41c94511106e5407433f070ec40f84cc7798060ab83f10bd74ee647b2c803c976e1dfb02505708b3431c40d1e2b66b3b2b12d7736187af7fa4 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 diff --git a/tinygo.spec b/tinygo.spec index 46685ab..00100e4 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.27.0 +Version: 0.28.1 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -90,12 +90,8 @@ Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch Patch0004: 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch Patch0005: 0005-Add-CPU-to-RISCV-targets.patch Patch0006: 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch -# https://github.com/tinygo-org/tinygo/pull/3566 -Patch0007: 0007-Update-transform-tests-with-opaque-pointers.patch -# https://github.com/tinygo-org/tinygo/pull/3658 -Patch0008: 0008-Switch-interp-tests-to-opaque-pointers.patch # https://github.com/tinygo-org/tinygo/pull/3649 -Patch0009: 0009-Update-types-in-cgo-tests-for-LLVM-16.patch +Patch0007: 0007-Update-types-in-cgo-tests-for-LLVM-16.patch # Not supported upstream yet. ExcludeArch: ppc64le s390x @@ -114,6 +110,7 @@ BuildRequires: golang(github.com/inhies/go-bytesize) BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 +BuildRequires: golang(github.com/sigurn/crc16) BuildRequires: golang(go.bug.st/serial) >= 1.3.5 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.11 From 5c81169782d8877836324d39a9f0d05593c4e3c0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Aug 2023 20:51:46 -0400 Subject: [PATCH 52/78] Updte to latest version (#2214119) --- 0001-Skip-WASI-tests.patch | 8 ++++---- ...Skip-some-cross-Linux-tests-where-qemu-is-broken.patch | 8 ++++---- ...-Suggest-optional-packages-to-install-if-missing.patch | 2 +- 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch | 2 +- 0005-Add-CPU-to-RISCV-targets.patch | 6 +++--- 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch | 8 ++++---- 0007-Update-types-in-cgo-tests-for-LLVM-16.patch | 2 +- tinygo.spec | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 3a8cc13..cf22b80 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,4 +1,4 @@ -From cbac45f83e2867012c9092024679beb1c9134435 Mon Sep 17 00:00:00 2001 +From 206888b5a100d9ff58008dad4fbb9a45b1265a6b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 Subject: [PATCH 1/7] Skip WASI tests. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 deletions(-) diff --git a/main_test.go b/main_test.go -index 59254656..cab523b7 100644 +index ae7aed56..ac204f0c 100644 --- a/main_test.go +++ b/main_test.go -@@ -151,10 +151,6 @@ func TestBuild(t *testing.T) { +@@ -171,10 +171,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -25,7 +25,7 @@ index 59254656..cab523b7 100644 } } -@@ -403,7 +399,6 @@ func TestTest(t *testing.T) { +@@ -425,7 +421,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 9a3a70d..a324db8 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,4 +1,4 @@ -From dcd2dcba814f7d910af630a3dd2e760c6fc21dd6 Mon Sep 17 00:00:00 2001 +From df546b002b1d2d38e71b8d2e2c0e8f2c419b16c1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 Subject: [PATCH 2/7] Skip some cross Linux tests where qemu is broken @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 14 insertions(+) diff --git a/main_test.go b/main_test.go -index cab523b7..798f0ec9 100644 +index ac204f0c..5407ce09 100644 --- a/main_test.go +++ b/main_test.go -@@ -242,6 +242,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -264,6 +264,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -31,7 +31,7 @@ index cab523b7..798f0ec9 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -331,6 +338,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -353,6 +360,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index 8193c76..df446aa 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,4 +1,4 @@ -From e3bc238eadcd1d3bad8e10a1496ef496d90090cd Mon Sep 17 00:00:00 2001 +From 118b4127ed490d74429759f4fb8bf5a38b528fba Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 Subject: [PATCH 3/7] Suggest optional packages to install if missing diff --git a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch index 5731382..7c99fe0 100644 --- a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch +++ b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch @@ -1,4 +1,4 @@ -From aac3fe147d69800f2b909454815f5b2ed52800eb Mon Sep 17 00:00:00 2001 +From 9c3e5f72d571027689dba37cceb2a592dfcfdb5c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Apr 2023 04:55:27 -0400 Subject: [PATCH 4/7] cgo: Handle elaborated typedefs from libclang diff --git a/0005-Add-CPU-to-RISCV-targets.patch b/0005-Add-CPU-to-RISCV-targets.patch index 7613f14..b574fdb 100644 --- a/0005-Add-CPU-to-RISCV-targets.patch +++ b/0005-Add-CPU-to-RISCV-targets.patch @@ -1,4 +1,4 @@ -From 084466294beb16440244374251ac9e6258929f18 Mon Sep 17 00:00:00 2001 +From 18428dbfd276b19797cd1ec0ba36bd5d370c2477 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Apr 2023 05:51:10 -0400 Subject: [PATCH 5/7] Add CPU to RISCV targets @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 40a1d445..68f12707 100644 +index f83464b2..1e3995bb 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -14,6 +14,7 @@ import ( @@ -22,7 +22,7 @@ index 40a1d445..68f12707 100644 "github.com/tinygo-org/tinygo/goenv" ) -@@ -135,7 +136,11 @@ func (spec *TargetSpec) loadFromGivenStr(str string) error { +@@ -134,7 +135,11 @@ func (spec *TargetSpec) loadFromGivenStr(str string) error { return err } defer fp.Close() diff --git a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch index f4e6f85..83f2411 100644 --- a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch +++ b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch @@ -1,4 +1,4 @@ -From 75e30cb418519e03b50fc64aa3a109376e612af0 Mon Sep 17 00:00:00 2001 +From bb4cd90c053be0a8d2a4ec1ddfb91cef538f5ae1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 03:41:21 -0400 Subject: [PATCH 6/7] Handle argmemonly attribute change in LLVM16 @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index 6b5fbe13..b8cff5e8 100644 +index 92ce31b0..440dcc13 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -4,11 +4,11 @@ import ( @@ -27,7 +27,7 @@ index 6b5fbe13..b8cff5e8 100644 "github.com/tinygo-org/tinygo/goenv" "github.com/tinygo-org/tinygo/loader" "tinygo.org/x/go-llvm" -@@ -151,12 +151,7 @@ func fuzzyEqualIR(s1, s2 string) bool { +@@ -154,12 +154,7 @@ func fuzzyEqualIR(s1, s2 string) bool { // stripped out. func filterIrrelevantIRLines(lines []string) []string { var out []string @@ -41,7 +41,7 @@ index 6b5fbe13..b8cff5e8 100644 for _, line := range lines { line = strings.Split(line, ";")[0] // strip out comments/info line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments -@@ -171,6 +166,12 @@ func filterIrrelevantIRLines(lines []string) []string { +@@ -174,6 +169,12 @@ func filterIrrelevantIRLines(lines []string) []string { // Right now test outputs are for LLVM 14 and higher. continue } diff --git a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch index ebfacb5..41dd054 100644 --- a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch +++ b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch @@ -1,4 +1,4 @@ -From 56388dc66838222c7ffb98e30221ef72f6316dcf Mon Sep 17 00:00:00 2001 +From 2d424012a1000a5e28a777536d32ab1faa8c9fbb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 19:41:18 -0400 Subject: [PATCH 7/7] Update types in cgo tests for LLVM 16 diff --git a/tinygo.spec b/tinygo.spec index 00100e4..eae8cfc 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.28.1 +Version: 0.29.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 From 4d6d12da796ec12c36281146602618efd7476aaa Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Aug 2023 21:03:15 -0400 Subject: [PATCH 53/78] Upload sources and fix dependency [skip changelog] --- .gitignore | 1 + sources | 2 +- tinygo.spec | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9ce9122..921b4da 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ /musl-1.2.3.tar.gz.asc /mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz /tinygo-0.28.1.tar.gz +/tinygo-0.29.0.tar.gz diff --git a/sources b/sources index 571e544..cf6d535 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.28.1.tar.gz) = 9dba475997717f41c94511106e5407433f070ec40f84cc7798060ab83f10bd74ee647b2c803c976e1dfb02505708b3431c40d1e2b66b3b2b12d7736187af7fa4 +SHA512 (tinygo-0.29.0.tar.gz) = 90f2ffd7aedeae7e47acda696d49d352d38a00db5cf7db6cf01c9fcaba8075a461604ce39e58f965e1165d3d0da334be04989dc7811322212bb0ec0bce718168 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 diff --git a/tinygo.spec b/tinygo.spec index eae8cfc..ac6da7b 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -111,7 +111,7 @@ BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 BuildRequires: golang(github.com/sigurn/crc16) -BuildRequires: golang(go.bug.st/serial) >= 1.3.5 +BuildRequires: golang(go.bug.st/serial) >= 1.6.0 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.11 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 From 96c5d0d6c6f04a6f5e4daad8994bb367129ad956 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 28 Aug 2023 20:38:00 -0400 Subject: [PATCH 54/78] Backport patch for golang.org/x/tools 0.12.0 Also, drop some older unused patches. --- 0001-Skip-WASI-tests.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- ...ional-packages-to-install-if-missing.patch | 2 +- ...le-elaborated-typedefs-from-libclang.patch | 2 +- 0005-Add-CPU-to-RISCV-targets.patch | 2 +- ...rgmemonly-attribute-change-in-LLVM16.patch | 65 +- ...transform-tests-with-opaque-pointers.patch | 1723 ----------------- ...pdate-types-in-cgo-tests-for-LLVM-16.patch | 4 +- ...itch-interp-tests-to-opaque-pointers.patch | 831 -------- ...Update-golang.org-x-tools-to-v0.12.0.patch | 240 +++ tinygo.spec | 2 + 11 files changed, 308 insertions(+), 2567 deletions(-) delete mode 100644 0007-Update-transform-tests-with-opaque-pointers.patch delete mode 100644 0008-Switch-interp-tests-to-opaque-pointers.patch create mode 100644 0008-Update-golang.org-x-tools-to-v0.12.0.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index cf22b80..bb80a41 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From 206888b5a100d9ff58008dad4fbb9a45b1265a6b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/7] Skip WASI tests. +Subject: [PATCH 1/8] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index a324db8..7e060fe 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From df546b002b1d2d38e71b8d2e2c0e8f2c419b16c1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/7] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index df446aa..2ddc60a 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From 118b4127ed490d74429759f4fb8bf5a38b528fba Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/7] Suggest optional packages to install if missing +Subject: [PATCH 3/8] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch index 7c99fe0..a73ee38 100644 --- a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch +++ b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch @@ -1,7 +1,7 @@ From 9c3e5f72d571027689dba37cceb2a592dfcfdb5c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Apr 2023 04:55:27 -0400 -Subject: [PATCH 4/7] cgo: Handle elaborated typedefs from libclang +Subject: [PATCH 4/8] cgo: Handle elaborated typedefs from libclang I don't have a reference for this change in LLVM 16, so I just handled it the same way as other elaborated types. diff --git a/0005-Add-CPU-to-RISCV-targets.patch b/0005-Add-CPU-to-RISCV-targets.patch index b574fdb..ff05562 100644 --- a/0005-Add-CPU-to-RISCV-targets.patch +++ b/0005-Add-CPU-to-RISCV-targets.patch @@ -1,7 +1,7 @@ From 18428dbfd276b19797cd1ec0ba36bd5d370c2477 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Apr 2023 05:51:10 -0400 -Subject: [PATCH 5/7] Add CPU to RISCV targets +Subject: [PATCH 5/8] Add CPU to RISCV targets Signed-off-by: Elliott Sales de Andrade --- diff --git a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch index 83f2411..371ffb8 100644 --- a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch +++ b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch @@ -1,17 +1,18 @@ -From bb4cd90c053be0a8d2a4ec1ddfb91cef538f5ae1 Mon Sep 17 00:00:00 2001 +From 541e5c4df0c603fb6149cd5e2607f73e8e4569cf Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 03:41:21 -0400 -Subject: [PATCH 6/7] Handle argmemonly attribute change in LLVM16 +Subject: [PATCH 6/8] Handle argmemonly attribute change in LLVM16 Signed-off-by: Elliott Sales de Andrade --- - compiler/compiler_test.go | 15 ++++++++------- + compiler/compiler_test.go | 22 +++++++++++++++------- compiler/testdata/channel.ll | 6 +++--- + compiler/testdata/go1.21.ll | 16 ++++++++-------- compiler/testdata/zeromap.ll | 6 +++--- - 3 files changed, 14 insertions(+), 13 deletions(-) + 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index 92ce31b0..440dcc13 100644 +index 92ce31b0..d6147b78 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -4,11 +4,11 @@ import ( @@ -41,7 +42,7 @@ index 92ce31b0..440dcc13 100644 for _, line := range lines { line = strings.Split(line, ";")[0] // strip out comments/info line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments -@@ -174,6 +169,12 @@ func filterIrrelevantIRLines(lines []string) []string { +@@ -174,6 +169,19 @@ func filterIrrelevantIRLines(lines []string) []string { // Right now test outputs are for LLVM 14 and higher. continue } @@ -50,6 +51,13 @@ index 92ce31b0..440dcc13 100644 + line = strings.Replace(line, "{ ", "{ argmemonly ", 1) + line = strings.Replace(line, "memory(argmem: readwrite) ", "", 1) + } ++ if strings.HasSuffix(line, "memory(none)") { ++ line = strings.Replace( ++ line, ++ "speculatable willreturn memory(none)", ++ "readnone speculatable willreturn", ++ 1) ++ } + } out = append(out, line) } @@ -80,6 +88,51 @@ index 9749effc..8ff64bd4 100644 -attributes #3 = { argmemonly nocallback nofree nosync nounwind willreturn } +attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } attributes #4 = { nounwind } +diff --git a/compiler/testdata/go1.21.ll b/compiler/testdata/go1.21.ll +index d65c75f4..c677298f 100644 +--- a/compiler/testdata/go1.21.ll ++++ b/compiler/testdata/go1.21.ll +@@ -138,7 +138,7 @@ entry: + ret void + } + +-; Function Attrs: argmemonly nocallback nofree nounwind willreturn writeonly ++; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write) + declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) #3 + + ; Function Attrs: nounwind +@@ -156,24 +156,24 @@ entry: + + declare void @runtime.hashmapClear(ptr dereferenceable_or_null(40), ptr) #1 + +-; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn ++; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) + declare i32 @llvm.smin.i32(i32, i32) #4 + +-; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn ++; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) + declare i8 @llvm.umin.i8(i8, i8) #4 + +-; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn ++; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) + declare i32 @llvm.umin.i32(i32, i32) #4 + +-; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn ++; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) + declare i32 @llvm.smax.i32(i32, i32) #4 + +-; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn ++; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) + declare i32 @llvm.umax.i32(i32, i32) #4 + + attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #1 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } + attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } +-attributes #3 = { argmemonly nocallback nofree nounwind willreturn writeonly } +-attributes #4 = { nocallback nofree nosync nounwind readnone speculatable willreturn } ++attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) } ++attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } + attributes #5 = { nounwind } diff --git a/compiler/testdata/zeromap.ll b/compiler/testdata/zeromap.ll index 69932a1a..6a3d3132 100644 --- a/compiler/testdata/zeromap.ll diff --git a/0007-Update-transform-tests-with-opaque-pointers.patch b/0007-Update-transform-tests-with-opaque-pointers.patch deleted file mode 100644 index 5e1fc6b..0000000 --- a/0007-Update-transform-tests-with-opaque-pointers.patch +++ /dev/null @@ -1,1723 +0,0 @@ -From e4caa532a5d474209fdb737eab219a4963e1bb1e Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 16 Mar 2023 19:34:35 +0100 -Subject: [PATCH 7/9] Update transform tests with opaque pointers - -transform: update reflect-implements test to opaque pointers - -transform: update allocs test to opaque pointers - -Also, rename most of the SSA values while we're at it. - -transform: update gc-stackslots test to opaque pointers - -transform: update interface test to opaque pointers - -transform: update interrupt test to opaque pointers - -transform: update maps test to opaque pointers - -transform: update panic test to opaque pointers - -transform: update stacksize test to opaque pointers - -transform: update stringequal test to opaque pointers - -transform: update stringtobytes test to opaque pointers - -transform: update wasm-abi to use opaque pointers - -Signed-off-by: Elliott Sales de Andrade ---- - transform/testdata/allocs.ll | 62 ++--- - transform/testdata/allocs.out.ll | 60 ++--- - transform/testdata/gc-stackslots.ll | 125 +++++---- - transform/testdata/gc-stackslots.out.ll | 258 +++++++++---------- - transform/testdata/interface.ll | 40 +-- - transform/testdata/interface.out.ll | 43 ++-- - transform/testdata/interrupt.ll | 37 ++- - transform/testdata/interrupt.out.ll | 27 +- - transform/testdata/maps.ll | 33 +-- - transform/testdata/maps.out.ll | 26 +- - transform/testdata/panic.ll | 10 +- - transform/testdata/panic.out.ll | 10 +- - transform/testdata/reflect-implements.ll | 24 +- - transform/testdata/reflect-implements.out.ll | 24 +- - transform/testdata/stacksize.ll | 10 +- - transform/testdata/stacksize.out.ll | 12 +- - transform/testdata/stringequal.ll | 10 +- - transform/testdata/stringequal.out.ll | 6 +- - transform/testdata/stringtobytes.ll | 26 +- - transform/testdata/stringtobytes.out.ll | 14 +- - transform/testdata/wasm-abi.ll | 10 +- - transform/testdata/wasm-abi.out.ll | 24 +- - 22 files changed, 425 insertions(+), 466 deletions(-) - -diff --git a/transform/testdata/allocs.ll b/transform/testdata/allocs.ll -index 58af2ea8..1c2fdd5a 100644 ---- a/transform/testdata/allocs.ll -+++ b/transform/testdata/allocs.ll -@@ -3,57 +3,51 @@ target triple = "armv7m-none-eabi" - - @runtime.zeroSizedAlloc = internal global i8 0, align 1 - --declare nonnull i8* @runtime.alloc(i32, i8*) -+declare nonnull ptr @runtime.alloc(i32, ptr) - - ; Test allocating a single int (i32) that should be allocated on the stack. - define void @testInt() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- store i32 5, i32* %2 -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ store i32 5, ptr %alloc - ret void - } - - ; Test allocating an array of 3 i16 values that should be allocated on the - ; stack. - define i16 @testArray() { -- %1 = call i8* @runtime.alloc(i32 6, i8* null) -- %2 = bitcast i8* %1 to i16* -- %3 = getelementptr i16, i16* %2, i32 1 -- store i16 5, i16* %3 -- %4 = getelementptr i16, i16* %2, i32 2 -- %5 = load i16, i16* %4 -- ret i16 %5 -+ %alloc = call ptr @runtime.alloc(i32 6, ptr null) -+ %alloc.1 = getelementptr i16, ptr %alloc, i32 1 -+ store i16 5, ptr %alloc.1 -+ %alloc.2 = getelementptr i16, ptr %alloc, i32 2 -+ %val = load i16, ptr %alloc.2 -+ ret i16 %val - } - - ; Call a function that will let the pointer escape, so the heap-to-stack - ; transform shouldn't be applied. - define void @testEscapingCall() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- %3 = call i32* @escapeIntPtr(i32* %2) -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %val = call ptr @escapeIntPtr(ptr %alloc) - ret void - } - - define void @testEscapingCall2() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- %3 = call i32* @escapeIntPtrSometimes(i32* %2, i32* %2) -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc) - ret void - } - - ; Call a function that doesn't let the pointer escape. - define void @testNonEscapingCall() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- %3 = call i32* @noescapeIntPtr(i32* %2) -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %val = call ptr @noescapeIntPtr(ptr %alloc) - ret void - } - - ; Return the allocated value, which lets it escape. --define i32* @testEscapingReturn() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- ret i32* %2 -+define ptr @testEscapingReturn() { -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ ret ptr %alloc - } - - ; Do a non-escaping allocation in a loop. -@@ -61,25 +55,23 @@ define void @testNonEscapingLoop() { - entry: - br label %loop - loop: -- %0 = call i8* @runtime.alloc(i32 4, i8* null) -- %1 = bitcast i8* %0 to i32* -- %2 = call i32* @noescapeIntPtr(i32* %1) -- %3 = icmp eq i32* null, %2 -- br i1 %3, label %loop, label %end -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %ptr = call ptr @noescapeIntPtr(ptr %alloc) -+ %result = icmp eq ptr null, %ptr -+ br i1 %result, label %loop, label %end - end: - ret void - } - - ; Test a zero-sized allocation. - define void @testZeroSizedAlloc() { -- %1 = call i8* @runtime.alloc(i32 0, i8* null) -- %2 = bitcast i8* %1 to i32* -- %3 = call i32* @noescapeIntPtr(i32* %2) -+ %alloc = call ptr @runtime.alloc(i32 0, ptr null) -+ %ptr = call ptr @noescapeIntPtr(ptr %alloc) - ret void - } - --declare i32* @escapeIntPtr(i32*) -+declare ptr @escapeIntPtr(ptr) - --declare i32* @noescapeIntPtr(i32* nocapture) -+declare ptr @noescapeIntPtr(ptr nocapture) - --declare i32* @escapeIntPtrSometimes(i32* nocapture, i32*) -+declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr) -diff --git a/transform/testdata/allocs.out.ll b/transform/testdata/allocs.out.ll -index 48f9b768..d1b07e6c 100644 ---- a/transform/testdata/allocs.out.ll -+++ b/transform/testdata/allocs.out.ll -@@ -3,53 +3,47 @@ target triple = "armv7m-none-eabi" - - @runtime.zeroSizedAlloc = internal global i8 0, align 1 - --declare nonnull i8* @runtime.alloc(i32, i8*) -+declare nonnull ptr @runtime.alloc(i32, ptr) - - define void @testInt() { - %stackalloc.alloca = alloca [4 x i8], align 4 -- store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 -- %stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* -- store i32 5, i32* %stackalloc, align 4 -+ store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4 -+ store i32 5, ptr %stackalloc.alloca, align 4 - ret void - } - - define i16 @testArray() { - %stackalloc.alloca = alloca [6 x i8], align 2 -- store [6 x i8] zeroinitializer, [6 x i8]* %stackalloc.alloca, align 2 -- %stackalloc = bitcast [6 x i8]* %stackalloc.alloca to i16* -- %1 = getelementptr i16, i16* %stackalloc, i32 1 -- store i16 5, i16* %1, align 2 -- %2 = getelementptr i16, i16* %stackalloc, i32 2 -- %3 = load i16, i16* %2, align 2 -- ret i16 %3 -+ store [6 x i8] zeroinitializer, ptr %stackalloc.alloca, align 2 -+ %alloc.1 = getelementptr i16, ptr %stackalloc.alloca, i32 1 -+ store i16 5, ptr %alloc.1, align 2 -+ %alloc.2 = getelementptr i16, ptr %stackalloc.alloca, i32 2 -+ %val = load i16, ptr %alloc.2, align 2 -+ ret i16 %val - } - - define void @testEscapingCall() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- %3 = call i32* @escapeIntPtr(i32* %2) -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %val = call ptr @escapeIntPtr(ptr %alloc) - ret void - } - - define void @testEscapingCall2() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- %3 = call i32* @escapeIntPtrSometimes(i32* %2, i32* %2) -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc) - ret void - } - - define void @testNonEscapingCall() { - %stackalloc.alloca = alloca [4 x i8], align 4 -- store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 -- %stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* -- %1 = call i32* @noescapeIntPtr(i32* %stackalloc) -+ store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4 -+ %val = call ptr @noescapeIntPtr(ptr %stackalloc.alloca) - ret void - } - --define i32* @testEscapingReturn() { -- %1 = call i8* @runtime.alloc(i32 4, i8* null) -- %2 = bitcast i8* %1 to i32* -- ret i32* %2 -+define ptr @testEscapingReturn() { -+ %alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ ret ptr %alloc - } - - define void @testNonEscapingLoop() { -@@ -58,24 +52,22 @@ entry: - br label %loop - - loop: ; preds = %loop, %entry -- store [4 x i8] zeroinitializer, [4 x i8]* %stackalloc.alloca, align 4 -- %stackalloc = bitcast [4 x i8]* %stackalloc.alloca to i32* -- %0 = call i32* @noescapeIntPtr(i32* %stackalloc) -- %1 = icmp eq i32* null, %0 -- br i1 %1, label %loop, label %end -+ store [4 x i8] zeroinitializer, ptr %stackalloc.alloca, align 4 -+ %ptr = call ptr @noescapeIntPtr(ptr %stackalloc.alloca) -+ %result = icmp eq ptr null, %ptr -+ br i1 %result, label %loop, label %end - - end: ; preds = %loop - ret void - } - - define void @testZeroSizedAlloc() { -- %1 = bitcast i8* @runtime.zeroSizedAlloc to i32* -- %2 = call i32* @noescapeIntPtr(i32* %1) -+ %ptr = call ptr @noescapeIntPtr(ptr @runtime.zeroSizedAlloc) - ret void - } - --declare i32* @escapeIntPtr(i32*) -+declare ptr @escapeIntPtr(ptr) - --declare i32* @noescapeIntPtr(i32* nocapture) -+declare ptr @noescapeIntPtr(ptr nocapture) - --declare i32* @escapeIntPtrSometimes(i32* nocapture, i32*) -+declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr) -diff --git a/transform/testdata/gc-stackslots.ll b/transform/testdata/gc-stackslots.ll -index c217fb9a..7f196e9b 100644 ---- a/transform/testdata/gc-stackslots.ll -+++ b/transform/testdata/gc-stackslots.ll -@@ -1,101 +1,99 @@ - target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" - target triple = "wasm32-unknown-unknown-wasm" - --%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 } -- --@runtime.stackChainStart = external global %runtime.stackChainObject* -+@runtime.stackChainStart = external global ptr - @someGlobal = global i8 3 --@ptrGlobal = global i8** null -+@ptrGlobal = global ptr null - --declare void @runtime.trackPointer(i8* nocapture readonly) -+declare void @runtime.trackPointer(ptr nocapture readonly) - --declare noalias nonnull i8* @runtime.alloc(i32, i8*) -+declare noalias nonnull ptr @runtime.alloc(i32, ptr) - - ; Generic function that returns a pointer (that must be tracked). --define i8* @getPointer() { -- ret i8* @someGlobal -+define ptr @getPointer() { -+ ret ptr @someGlobal - } - --define i8* @needsStackSlots() { -+define ptr @needsStackSlots() { - ; Tracked pointer. Although, in this case the value is immediately returned - ; so tracking it is not really necessary. -- %ptr = call i8* @runtime.alloc(i32 4, i8* null) -- call void @runtime.trackPointer(i8* %ptr) -+ %ptr = call ptr @runtime.alloc(i32 4, ptr null) -+ call void @runtime.trackPointer(ptr %ptr) - call void @someArbitraryFunction() -- %val = load i8, i8* @someGlobal -- ret i8* %ptr -+ %val = load i8, ptr @someGlobal -+ ret ptr %ptr - } - - ; Check some edge cases of pointer tracking. --define i8* @needsStackSlots2() { -+define ptr @needsStackSlots2() { - ; Only one stack slot should be created for this (but at the moment, one is - ; created for each call to runtime.trackPointer). -- %ptr1 = call i8* @getPointer() -- call void @runtime.trackPointer(i8* %ptr1) -- call void @runtime.trackPointer(i8* %ptr1) -- call void @runtime.trackPointer(i8* %ptr1) -+ %ptr1 = call ptr @getPointer() -+ call void @runtime.trackPointer(ptr %ptr1) -+ call void @runtime.trackPointer(ptr %ptr1) -+ call void @runtime.trackPointer(ptr %ptr1) - - ; Create a pointer that does not need to be tracked (but is tracked). -- %ptr2 = getelementptr i8, i8* @someGlobal, i32 0 -- call void @runtime.trackPointer(i8* %ptr2) -+ %ptr2 = getelementptr i8, ptr @someGlobal, i32 0 -+ call void @runtime.trackPointer(ptr %ptr2) - - ; Here is finally the point where an allocation happens. -- %unused = call i8* @runtime.alloc(i32 4, i8* null) -- call void @runtime.trackPointer(i8* %unused) -+ %unused = call ptr @runtime.alloc(i32 4, ptr null) -+ call void @runtime.trackPointer(ptr %unused) - -- ret i8* %ptr1 -+ ret ptr %ptr1 - } - - ; Return a pointer from a caller. Because it doesn't allocate, no stack objects - ; need to be created. --define i8* @noAllocatingFunction() { -- %ptr = call i8* @getPointer() -- call void @runtime.trackPointer(i8* %ptr) -- ret i8* %ptr -+define ptr @noAllocatingFunction() { -+ %ptr = call ptr @getPointer() -+ call void @runtime.trackPointer(ptr %ptr) -+ ret ptr %ptr - } - --define i8* @fibNext(i8* %x, i8* %y) { -- %x.val = load i8, i8* %x -- %y.val = load i8, i8* %y -+define ptr @fibNext(ptr %x, ptr %y) { -+ %x.val = load i8, ptr %x -+ %y.val = load i8, ptr %y - %out.val = add i8 %x.val, %y.val -- %out.alloc = call i8* @runtime.alloc(i32 1, i8* null) -- call void @runtime.trackPointer(i8* %out.alloc) -- store i8 %out.val, i8* %out.alloc -- ret i8* %out.alloc -+ %out.alloc = call ptr @runtime.alloc(i32 1, ptr null) -+ call void @runtime.trackPointer(ptr %out.alloc) -+ store i8 %out.val, ptr %out.alloc -+ ret ptr %out.alloc - } - --define i8* @allocLoop() { -+define ptr @allocLoop() { - entry: -- %entry.x = call i8* @runtime.alloc(i32 1, i8* null) -- call void @runtime.trackPointer(i8* %entry.x) -- %entry.y = call i8* @runtime.alloc(i32 1, i8* null) -- call void @runtime.trackPointer(i8* %entry.y) -- store i8 1, i8* %entry.y -+ %entry.x = call ptr @runtime.alloc(i32 1, ptr null) -+ call void @runtime.trackPointer(ptr %entry.x) -+ %entry.y = call ptr @runtime.alloc(i32 1, ptr null) -+ call void @runtime.trackPointer(ptr %entry.y) -+ store i8 1, ptr %entry.y - br label %loop - - loop: -- %prev.y = phi i8* [ %entry.y, %entry ], [ %prev.x, %loop ] -- %prev.x = phi i8* [ %entry.x, %entry ], [ %next.x, %loop ] -- call void @runtime.trackPointer(i8* %prev.x) -- call void @runtime.trackPointer(i8* %prev.y) -- %next.x = call i8* @fibNext(i8* %prev.x, i8* %prev.y) -- call void @runtime.trackPointer(i8* %next.x) -- %next.x.val = load i8, i8* %next.x -+ %prev.y = phi ptr [ %entry.y, %entry ], [ %prev.x, %loop ] -+ %prev.x = phi ptr [ %entry.x, %entry ], [ %next.x, %loop ] -+ call void @runtime.trackPointer(ptr %prev.x) -+ call void @runtime.trackPointer(ptr %prev.y) -+ %next.x = call ptr @fibNext(ptr %prev.x, ptr %prev.y) -+ call void @runtime.trackPointer(ptr %next.x) -+ %next.x.val = load i8, ptr %next.x - %loop.done = icmp ult i8 40, %next.x.val - br i1 %loop.done, label %end, label %loop - - end: -- ret i8* %next.x -+ ret ptr %next.x - } - --declare [32 x i8]* @arrayAlloc() -+declare ptr @arrayAlloc() - - define void @testGEPBitcast() { -- %arr = call [32 x i8]* @arrayAlloc() -- %arr.bitcast = getelementptr [32 x i8], [32 x i8]* %arr, i32 0, i32 0 -- call void @runtime.trackPointer(i8* %arr.bitcast) -- %other = call i8* @runtime.alloc(i32 1, i8* null) -- call void @runtime.trackPointer(i8* %other) -+ %arr = call ptr @arrayAlloc() -+ %arr.bitcast = getelementptr [32 x i8], ptr %arr, i32 0, i32 0 -+ call void @runtime.trackPointer(ptr %arr.bitcast) -+ %other = call ptr @runtime.alloc(i32 1, ptr null) -+ call void @runtime.trackPointer(ptr %other) - ret void - } - -@@ -104,18 +102,17 @@ define void @someArbitraryFunction() { - } - - define void @earlyPopRegression() { -- %x.alloc = call i8* @runtime.alloc(i32 4, i8* null) -- call void @runtime.trackPointer(i8* %x.alloc) -- %x = bitcast i8* %x.alloc to i8** -+ %x.alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ call void @runtime.trackPointer(ptr %x.alloc) - ; At this point the pass used to pop the stack chain, resulting in a potential use-after-free during allocAndSave. -- musttail call void @allocAndSave(i8** %x) -+ musttail call void @allocAndSave(ptr %x.alloc) - ret void - } - --define void @allocAndSave(i8** %x) { -- %y = call i8* @runtime.alloc(i32 4, i8* null) -- call void @runtime.trackPointer(i8* %y) -- store i8* %y, i8** %x -- store i8** %x, i8*** @ptrGlobal -+define void @allocAndSave(ptr %x) { -+ %y = call ptr @runtime.alloc(i32 4, ptr null) -+ call void @runtime.trackPointer(ptr %y) -+ store ptr %y, ptr %x -+ store ptr %x, ptr @ptrGlobal - ret void --} -\ No newline at end of file -+} -diff --git a/transform/testdata/gc-stackslots.out.ll b/transform/testdata/gc-stackslots.out.ll -index 83d1c841..f80d0c96 100644 ---- a/transform/testdata/gc-stackslots.out.ll -+++ b/transform/testdata/gc-stackslots.out.ll -@@ -1,141 +1,134 @@ - target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" - target triple = "wasm32-unknown-unknown-wasm" - --%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 } -- --@runtime.stackChainStart = internal global %runtime.stackChainObject* null -+@runtime.stackChainStart = internal global ptr null - @someGlobal = global i8 3 --@ptrGlobal = global i8** null -+@ptrGlobal = global ptr null - --declare void @runtime.trackPointer(i8* nocapture readonly) -+declare void @runtime.trackPointer(ptr nocapture readonly) - --declare noalias nonnull i8* @runtime.alloc(i32, i8*) -+declare noalias nonnull ptr @runtime.alloc(i32, ptr) - --define i8* @getPointer() { -- ret i8* @someGlobal -+define ptr @getPointer() { -+ ret ptr @someGlobal - } - --define i8* @needsStackSlots() { -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 -- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 -- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %ptr = call i8* @runtime.alloc(i32 4, i8* null) -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %ptr, i8** %4, align 4 -+define ptr @needsStackSlots() { -+ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 -+ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 -+ %1 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %1, ptr %2, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %ptr = call ptr @runtime.alloc(i32 4, ptr null) -+ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %ptr, ptr %3, align 4 - call void @someArbitraryFunction() -- %val = load i8, i8* @someGlobal, align 1 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- ret i8* %ptr -+ %val = load i8, ptr @someGlobal, align 1 -+ store ptr %1, ptr @runtime.stackChainStart, align 4 -+ ret ptr %ptr - } - --define i8* @needsStackSlots2() { -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* } { %runtime.stackChainObject* null, i32 5, i8* null, i8* null, i8* null, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, align 4 -- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %2 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 -- %3 = bitcast { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %ptr1 = call i8* @getPointer() -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 4 -- store i8* %ptr1, i8** %4, align 4 -- %5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 3 -- store i8* %ptr1, i8** %5, align 4 -- %6 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %ptr1, i8** %6, align 4 -- %ptr2 = getelementptr i8, i8* @someGlobal, i32 0 -- %7 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 5 -- store i8* %ptr2, i8** %7, align 4 -- %unused = call i8* @runtime.alloc(i32 4, i8* null) -- %8 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 6 -- store i8* %unused, i8** %8, align 4 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- ret i8* %ptr1 -+define ptr @needsStackSlots2() { -+ %gc.stackobject = alloca { ptr, i32, ptr, ptr, ptr, ptr, ptr }, align 8 -+ store { ptr, i32, ptr, ptr, ptr, ptr, ptr } { ptr null, i32 5, ptr null, ptr null, ptr null, ptr null, ptr null }, ptr %gc.stackobject, align 4 -+ %1 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %2 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %1, ptr %2, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %ptr1 = call ptr @getPointer() -+ %3 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 4 -+ store ptr %ptr1, ptr %3, align 4 -+ %4 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 3 -+ store ptr %ptr1, ptr %4, align 4 -+ %5 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %ptr1, ptr %5, align 4 -+ %ptr2 = getelementptr i8, ptr @someGlobal, i32 0 -+ %6 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 5 -+ store ptr %ptr2, ptr %6, align 4 -+ %unused = call ptr @runtime.alloc(i32 4, ptr null) -+ %7 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 6 -+ store ptr %unused, ptr %7, align 4 -+ store ptr %1, ptr @runtime.stackChainStart, align 4 -+ ret ptr %ptr1 - } - --define i8* @noAllocatingFunction() { -- %ptr = call i8* @getPointer() -- ret i8* %ptr -+define ptr @noAllocatingFunction() { -+ %ptr = call ptr @getPointer() -+ ret ptr %ptr - } - --define i8* @fibNext(i8* %x, i8* %y) { -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 -- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 -- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %x.val = load i8, i8* %x, align 1 -- %y.val = load i8, i8* %y, align 1 -+define ptr @fibNext(ptr %x, ptr %y) { -+ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 -+ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 -+ %1 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %1, ptr %2, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %x.val = load i8, ptr %x, align 1 -+ %y.val = load i8, ptr %y, align 1 - %out.val = add i8 %x.val, %y.val -- %out.alloc = call i8* @runtime.alloc(i32 1, i8* null) -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %out.alloc, i8** %4, align 4 -- store i8 %out.val, i8* %out.alloc, align 1 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- ret i8* %out.alloc -+ %out.alloc = call ptr @runtime.alloc(i32 1, ptr null) -+ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %out.alloc, ptr %3, align 4 -+ store i8 %out.val, ptr %out.alloc, align 1 -+ store ptr %1, ptr @runtime.stackChainStart, align 4 -+ ret ptr %out.alloc - } - --define i8* @allocLoop() { -+define ptr @allocLoop() { - entry: -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* } { %runtime.stackChainObject* null, i32 5, i8* null, i8* null, i8* null, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, align 4 -- %0 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %1 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %0, %runtime.stackChainObject** %1, align 4 -- %2 = bitcast { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %2, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %entry.x = call i8* @runtime.alloc(i32 1, i8* null) -- %3 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %entry.x, i8** %3, align 4 -- %entry.y = call i8* @runtime.alloc(i32 1, i8* null) -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 3 -- store i8* %entry.y, i8** %4, align 4 -- store i8 1, i8* %entry.y, align 1 -+ %gc.stackobject = alloca { ptr, i32, ptr, ptr, ptr, ptr, ptr }, align 8 -+ store { ptr, i32, ptr, ptr, ptr, ptr, ptr } { ptr null, i32 5, ptr null, ptr null, ptr null, ptr null, ptr null }, ptr %gc.stackobject, align 4 -+ %0 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %1 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %0, ptr %1, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %entry.x = call ptr @runtime.alloc(i32 1, ptr null) -+ %2 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %entry.x, ptr %2, align 4 -+ %entry.y = call ptr @runtime.alloc(i32 1, ptr null) -+ %3 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 3 -+ store ptr %entry.y, ptr %3, align 4 -+ store i8 1, ptr %entry.y, align 1 - br label %loop - - loop: ; preds = %loop, %entry -- %prev.y = phi i8* [ %entry.y, %entry ], [ %prev.x, %loop ] -- %prev.x = phi i8* [ %entry.x, %entry ], [ %next.x, %loop ] -- %5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 5 -- store i8* %prev.y, i8** %5, align 4 -- %6 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 4 -- store i8* %prev.x, i8** %6, align 4 -- %next.x = call i8* @fibNext(i8* %prev.x, i8* %prev.y) -- %7 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 6 -- store i8* %next.x, i8** %7, align 4 -- %next.x.val = load i8, i8* %next.x, align 1 -+ %prev.y = phi ptr [ %entry.y, %entry ], [ %prev.x, %loop ] -+ %prev.x = phi ptr [ %entry.x, %entry ], [ %next.x, %loop ] -+ %4 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 5 -+ store ptr %prev.y, ptr %4, align 4 -+ %5 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 4 -+ store ptr %prev.x, ptr %5, align 4 -+ %next.x = call ptr @fibNext(ptr %prev.x, ptr %prev.y) -+ %6 = getelementptr { ptr, i32, ptr, ptr, ptr, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 6 -+ store ptr %next.x, ptr %6, align 4 -+ %next.x.val = load i8, ptr %next.x, align 1 - %loop.done = icmp ult i8 40, %next.x.val - br i1 %loop.done, label %end, label %loop - - end: ; preds = %loop -- store %runtime.stackChainObject* %0, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- ret i8* %next.x -+ store ptr %0, ptr @runtime.stackChainStart, align 4 -+ ret ptr %next.x - } - --declare [32 x i8]* @arrayAlloc() -+declare ptr @arrayAlloc() - - define void @testGEPBitcast() { -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8*, i8* } { %runtime.stackChainObject* null, i32 2, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, align 4 -- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %2 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 -- %3 = bitcast { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %arr = call [32 x i8]* @arrayAlloc() -- %arr.bitcast = getelementptr [32 x i8], [32 x i8]* %arr, i32 0, i32 0 -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %arr.bitcast, i8** %4, align 4 -- %other = call i8* @runtime.alloc(i32 1, i8* null) -- %5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8* }* %gc.stackobject, i32 0, i32 3 -- store i8* %other, i8** %5, align 4 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -+ %gc.stackobject = alloca { ptr, i32, ptr, ptr }, align 8 -+ store { ptr, i32, ptr, ptr } { ptr null, i32 2, ptr null, ptr null }, ptr %gc.stackobject, align 4 -+ %1 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %2 = getelementptr { ptr, i32, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %1, ptr %2, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %arr = call ptr @arrayAlloc() -+ %arr.bitcast = getelementptr [32 x i8], ptr %arr, i32 0, i32 0 -+ %3 = getelementptr { ptr, i32, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %arr.bitcast, ptr %3, align 4 -+ %other = call ptr @runtime.alloc(i32 1, ptr null) -+ %4 = getelementptr { ptr, i32, ptr, ptr }, ptr %gc.stackobject, i32 0, i32 3 -+ store ptr %other, ptr %4, align 4 -+ store ptr %1, ptr @runtime.stackChainStart, align 4 - ret void - } - -@@ -144,35 +137,32 @@ define void @someArbitraryFunction() { - } - - define void @earlyPopRegression() { -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 -- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 -- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %x.alloc = call i8* @runtime.alloc(i32 4, i8* null) -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %x.alloc, i8** %4, align 4 -- %x = bitcast i8* %x.alloc to i8** -- call void @allocAndSave(i8** %x) -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -+ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 -+ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 -+ %1 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %1, ptr %2, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %x.alloc = call ptr @runtime.alloc(i32 4, ptr null) -+ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %x.alloc, ptr %3, align 4 -+ call void @allocAndSave(ptr %x.alloc) -+ store ptr %1, ptr @runtime.stackChainStart, align 4 - ret void - } - --define void @allocAndSave(i8** %x) { -- %gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }, align 8 -- store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, align 4 -- %1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2, align 4 -- %3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject* -- store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -- %y = call i8* @runtime.alloc(i32 4, i8* null) -- %4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2 -- store i8* %y, i8** %4, align 4 -- store i8* %y, i8** %x, align 4 -- store i8** %x, i8*** @ptrGlobal, align 4 -- store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart, align 4 -+define void @allocAndSave(ptr %x) { -+ %gc.stackobject = alloca { ptr, i32, ptr }, align 8 -+ store { ptr, i32, ptr } { ptr null, i32 1, ptr null }, ptr %gc.stackobject, align 4 -+ %1 = load ptr, ptr @runtime.stackChainStart, align 4 -+ %2 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 0 -+ store ptr %1, ptr %2, align 4 -+ store ptr %gc.stackobject, ptr @runtime.stackChainStart, align 4 -+ %y = call ptr @runtime.alloc(i32 4, ptr null) -+ %3 = getelementptr { ptr, i32, ptr }, ptr %gc.stackobject, i32 0, i32 2 -+ store ptr %y, ptr %3, align 4 -+ store ptr %y, ptr %x, align 4 -+ store ptr %x, ptr @ptrGlobal, align 4 -+ store ptr %1, ptr @runtime.stackChainStart, align 4 - ret void - } -diff --git a/transform/testdata/interface.ll b/transform/testdata/interface.ll -index 4d8e818d..4bac5c2d 100644 ---- a/transform/testdata/interface.ll -+++ b/transform/testdata/interface.ll -@@ -1,8 +1,8 @@ - target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7m-none-eabi" - --%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } --%runtime.interfaceMethodInfo = type { i8*, i32 } -+%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } -+%runtime.interfaceMethodInfo = type { ptr, i32 } - - @"reflect/types.type:basic:uint8" = private constant %runtime.typecodeID zeroinitializer - @"reflect/types.typeid:basic:uint8" = external constant i8 -@@ -10,31 +10,31 @@ target triple = "armv7m-none-eabi" - @"reflect/types.type:basic:int" = private constant %runtime.typecodeID zeroinitializer - @"reflect/methods.NeverImplementedMethod()" = linkonce_odr constant i8 0 - @"reflect/methods.Double() int" = linkonce_odr constant i8 0 --@"Number$methodset" = private constant [1 x %runtime.interfaceMethodInfo] [%runtime.interfaceMethodInfo { i8* @"reflect/methods.Double() int", i32 ptrtoint (i32 (i8*, i8*)* @"(Number).Double$invoke" to i32) }] -+@"Number$methodset" = private constant [1 x %runtime.interfaceMethodInfo] [%runtime.interfaceMethodInfo { ptr @"reflect/methods.Double() int", i32 ptrtoint (i32 (ptr, ptr)* @"(Number).Double$invoke" to i32) }] - @"reflect/types.type:named:Number" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* getelementptr inbounds ([1 x %runtime.interfaceMethodInfo], [1 x %runtime.interfaceMethodInfo]* @"Number$methodset", i32 0, i32 0), %runtime.typecodeID* null, i32 0 } - --declare i1 @runtime.typeAssert(i32, i8*) -+declare i1 @runtime.typeAssert(i32, ptr) - declare void @runtime.printuint8(i8) - declare void @runtime.printint16(i16) - declare void @runtime.printint32(i32) - declare void @runtime.printptr(i32) - declare void @runtime.printnl() --declare void @runtime.nilPanic(i8*) -+declare void @runtime.nilPanic(ptr) - - define void @printInterfaces() { -- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:int" to i32), i8* inttoptr (i32 5 to i8*)) -- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), i8* inttoptr (i8 120 to i8*)) -- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32), i8* inttoptr (i32 3 to i8*)) -+ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:int" to i32), ptr inttoptr (i32 5 to ptr)) -+ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:uint8" to i32), ptr inttoptr (i8 120 to ptr)) -+ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:named:Number" to i32), ptr inttoptr (i32 3 to ptr)) - - ret void - } - --define void @printInterface(i32 %typecode, i8* %value) { -+define void @printInterface(i32 %typecode, ptr %value) { - %isUnmatched = call i1 @Unmatched$typeassert(i32 %typecode) - br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched - - typeswitch.Unmatched: -- %unmatched = ptrtoint i8* %value to i32 -+ %unmatched = ptrtoint ptr %value to i32 - call void @runtime.printptr(i32 %unmatched) - call void @runtime.printnl() - ret void -@@ -44,27 +44,27 @@ typeswitch.notUnmatched: - br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler - - typeswitch.Doubler: -- %doubler.result = call i32 @"Doubler.Double$invoke"(i8* %value, i32 %typecode, i8* undef) -+ %doubler.result = call i32 @"Doubler.Double$invoke"(ptr %value, i32 %typecode, ptr undef) - call void @runtime.printint32(i32 %doubler.result) - ret void - - typeswitch.notDoubler: -- %isByte = call i1 @runtime.typeAssert(i32 %typecode, i8* nonnull @"reflect/types.typeid:basic:uint8") -+ %isByte = call i1 @runtime.typeAssert(i32 %typecode, ptr nonnull @"reflect/types.typeid:basic:uint8") - br i1 %isByte, label %typeswitch.byte, label %typeswitch.notByte - - typeswitch.byte: -- %byte = ptrtoint i8* %value to i8 -+ %byte = ptrtoint ptr %value to i8 - call void @runtime.printuint8(i8 %byte) - call void @runtime.printnl() - ret void - - typeswitch.notByte: - ; this is a type assert that always fails -- %isInt16 = call i1 @runtime.typeAssert(i32 %typecode, i8* nonnull @"reflect/types.typeid:basic:int16") -+ %isInt16 = call i1 @runtime.typeAssert(i32 %typecode, ptr nonnull @"reflect/types.typeid:basic:int16") - br i1 %isInt16, label %typeswitch.int16, label %typeswitch.notInt16 - - typeswitch.int16: -- %int16 = ptrtoint i8* %value to i16 -+ %int16 = ptrtoint ptr %value to i16 - call void @runtime.printint16(i16 %int16) - call void @runtime.printnl() - ret void -@@ -73,18 +73,18 @@ typeswitch.notInt16: - ret void - } - --define i32 @"(Number).Double"(i32 %receiver, i8* %context) { -+define i32 @"(Number).Double"(i32 %receiver, ptr %context) { - %ret = mul i32 %receiver, 2 - ret i32 %ret - } - --define i32 @"(Number).Double$invoke"(i8* %receiverPtr, i8* %context) { -- %receiver = ptrtoint i8* %receiverPtr to i32 -- %ret = call i32 @"(Number).Double"(i32 %receiver, i8* undef) -+define i32 @"(Number).Double$invoke"(ptr %receiverPtr, ptr %context) { -+ %receiver = ptrtoint ptr %receiverPtr to i32 -+ %ret = call i32 @"(Number).Double"(i32 %receiver, ptr undef) - ret i32 %ret - } - --declare i32 @"Doubler.Double$invoke"(i8* %receiver, i32 %typecode, i8* %context) #0 -+declare i32 @"Doubler.Double$invoke"(ptr %receiver, i32 %typecode, ptr %context) #0 - - declare i1 @Doubler$typeassert(i32 %typecode) #1 - -diff --git a/transform/testdata/interface.out.ll b/transform/testdata/interface.out.ll -index 262df210..ef887112 100644 ---- a/transform/testdata/interface.out.ll -+++ b/transform/testdata/interface.out.ll -@@ -1,12 +1,11 @@ - target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7m-none-eabi" - --%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } --%runtime.interfaceMethodInfo = type { i8*, i32 } -+%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } - - @"reflect/types.type:basic:uint8" = private constant %runtime.typecodeID zeroinitializer - @"reflect/types.type:basic:int" = private constant %runtime.typecodeID zeroinitializer --@"reflect/types.type:named:Number" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 } -+@"reflect/types.type:named:Number" = private constant %runtime.typecodeID { ptr @"reflect/types.type:basic:int", i32 0, ptr null, ptr null, i32 0 } - - declare void @runtime.printuint8(i8) - -@@ -18,21 +17,21 @@ declare void @runtime.printptr(i32) - - declare void @runtime.printnl() - --declare void @runtime.nilPanic(i8*) -+declare void @runtime.nilPanic(ptr) - - define void @printInterfaces() { -- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:int" to i32), i8* inttoptr (i32 5 to i8*)) -- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), i8* inttoptr (i8 120 to i8*)) -- call void @printInterface(i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32), i8* inttoptr (i32 3 to i8*)) -+ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:int" to i32), ptr inttoptr (i32 5 to ptr)) -+ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:basic:uint8" to i32), ptr inttoptr (i8 120 to ptr)) -+ call void @printInterface(i32 ptrtoint (ptr @"reflect/types.type:named:Number" to i32), ptr inttoptr (i32 3 to ptr)) - ret void - } - --define void @printInterface(i32 %typecode, i8* %value) { -+define void @printInterface(i32 %typecode, ptr %value) { - %isUnmatched = call i1 @"Unmatched$typeassert"(i32 %typecode) - br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched - - typeswitch.Unmatched: ; preds = %0 -- %unmatched = ptrtoint i8* %value to i32 -+ %unmatched = ptrtoint ptr %value to i32 - call void @runtime.printptr(i32 %unmatched) - call void @runtime.printnl() - ret void -@@ -42,16 +41,16 @@ typeswitch.notUnmatched: ; preds = %0 - br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler - - typeswitch.Doubler: ; preds = %typeswitch.notUnmatched -- %doubler.result = call i32 @"Doubler.Double$invoke"(i8* %value, i32 %typecode, i8* undef) -+ %doubler.result = call i32 @"Doubler.Double$invoke"(ptr %value, i32 %typecode, ptr undef) - call void @runtime.printint32(i32 %doubler.result) - ret void - - typeswitch.notDoubler: ; preds = %typeswitch.notUnmatched -- %typeassert.ok = icmp eq i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), %typecode -+ %typeassert.ok = icmp eq i32 ptrtoint (ptr @"reflect/types.type:basic:uint8" to i32), %typecode - br i1 %typeassert.ok, label %typeswitch.byte, label %typeswitch.notByte - - typeswitch.byte: ; preds = %typeswitch.notDoubler -- %byte = ptrtoint i8* %value to i8 -+ %byte = ptrtoint ptr %value to i8 - call void @runtime.printuint8(i8 %byte) - call void @runtime.printnl() - ret void -@@ -60,7 +59,7 @@ typeswitch.notByte: ; preds = %typeswitch.notDoubl - br i1 false, label %typeswitch.int16, label %typeswitch.notInt16 - - typeswitch.int16: ; preds = %typeswitch.notByte -- %int16 = ptrtoint i8* %value to i16 -+ %int16 = ptrtoint ptr %value to i16 - call void @runtime.printint16(i16 %int16) - call void @runtime.printnl() - ret void -@@ -69,34 +68,34 @@ typeswitch.notInt16: ; preds = %typeswitch.notByte - ret void - } - --define i32 @"(Number).Double"(i32 %receiver, i8* %context) { -+define i32 @"(Number).Double"(i32 %receiver, ptr %context) { - %ret = mul i32 %receiver, 2 - ret i32 %ret - } - --define i32 @"(Number).Double$invoke"(i8* %receiverPtr, i8* %context) { -- %receiver = ptrtoint i8* %receiverPtr to i32 -- %ret = call i32 @"(Number).Double"(i32 %receiver, i8* undef) -+define i32 @"(Number).Double$invoke"(ptr %receiverPtr, ptr %context) { -+ %receiver = ptrtoint ptr %receiverPtr to i32 -+ %ret = call i32 @"(Number).Double"(i32 %receiver, ptr undef) - ret i32 %ret - } - --define internal i32 @"Doubler.Double$invoke"(i8* %receiver, i32 %actualType, i8* %context) unnamed_addr #0 { -+define internal i32 @"Doubler.Double$invoke"(ptr %receiver, i32 %actualType, ptr %context) unnamed_addr #0 { - entry: -- %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32) -+ %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (ptr @"reflect/types.type:named:Number" to i32) - br i1 %"named:Number.icmp", label %"named:Number", label %"named:Number.next" - - "named:Number": ; preds = %entry -- %0 = call i32 @"(Number).Double$invoke"(i8* %receiver, i8* undef) -+ %0 = call i32 @"(Number).Double$invoke"(ptr %receiver, ptr undef) - ret i32 %0 - - "named:Number.next": ; preds = %entry -- call void @runtime.nilPanic(i8* undef) -+ call void @runtime.nilPanic(ptr undef) - unreachable - } - - define internal i1 @"Doubler$typeassert"(i32 %actualType) unnamed_addr #1 { - entry: -- %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32) -+ %"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (ptr @"reflect/types.type:named:Number" to i32) - br i1 %"named:Number.icmp", label %then, label %"named:Number.next" - - then: ; preds = %entry -diff --git a/transform/testdata/interrupt.ll b/transform/testdata/interrupt.ll -index 1436827b..f4d2e022 100644 ---- a/transform/testdata/interrupt.ll -+++ b/transform/testdata/interrupt.ll -@@ -1,39 +1,39 @@ - target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7em-none-eabi" - --%machine.UART = type { %machine.RingBuffer* } -+%machine.UART = type { ptr } - %machine.RingBuffer = type { [128 x %"runtime/volatile.Register8"], %"runtime/volatile.Register8", %"runtime/volatile.Register8" } - %"runtime/volatile.Register8" = type { i8 } --%"runtime/interrupt.handle" = type { i8*, i32, %"runtime/interrupt.Interrupt" } -+%"runtime/interrupt.handle" = type { ptr, i32, %"runtime/interrupt.Interrupt" } - %"runtime/interrupt.Interrupt" = type { i32 } - --@"runtime/interrupt.$interrupt2" = private unnamed_addr constant %"runtime/interrupt.handle" { i8* bitcast (%machine.UART* @machine.UART0 to i8*), i32 ptrtoint (void (i32, i8*)* @"(*machine.UART).handleInterrupt$bound" to i32), %"runtime/interrupt.Interrupt" { i32 2 } } --@machine.UART0 = internal global %machine.UART { %machine.RingBuffer* @"machine$alloc.335" } -+@"runtime/interrupt.$interrupt2" = private unnamed_addr constant %"runtime/interrupt.handle" { ptr @machine.UART0, i32 ptrtoint (ptr @"(*machine.UART).handleInterrupt$bound" to i32), %"runtime/interrupt.Interrupt" { i32 2 } } -+@machine.UART0 = internal global %machine.UART { ptr @"machine$alloc.335" } - @"machine$alloc.335" = internal global %machine.RingBuffer zeroinitializer - --declare void @"runtime/interrupt.callHandlers"(i32, i8*) local_unnamed_addr -+declare void @"runtime/interrupt.callHandlers"(i32, ptr) local_unnamed_addr - --declare void @"device/arm.EnableIRQ"(i32, i8* nocapture readnone) -+declare void @"device/arm.EnableIRQ"(i32, ptr nocapture readnone) - --declare void @"device/arm.SetPriority"(i32, i32, i8* nocapture readnone) -+declare void @"device/arm.SetPriority"(i32, i32, ptr nocapture readnone) - - declare void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt") - --define void @runtime.initAll(i8* nocapture readnone) unnamed_addr { -+define void @runtime.initAll(ptr nocapture readnone) unnamed_addr { - entry: -- call void @"device/arm.SetPriority"(i32 ptrtoint (%"runtime/interrupt.handle"* @"runtime/interrupt.$interrupt2" to i32), i32 192, i8* undef) -- call void @"device/arm.EnableIRQ"(i32 ptrtoint (%"runtime/interrupt.handle"* @"runtime/interrupt.$interrupt2" to i32), i8* undef) -- call void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt" { i32 ptrtoint (%"runtime/interrupt.handle"* @"runtime/interrupt.$interrupt2" to i32) }) -+ call void @"device/arm.SetPriority"(i32 ptrtoint (ptr @"runtime/interrupt.$interrupt2" to i32), i32 192, ptr undef) -+ call void @"device/arm.EnableIRQ"(i32 ptrtoint (ptr @"runtime/interrupt.$interrupt2" to i32), ptr undef) -+ call void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt" { i32 ptrtoint (ptr @"runtime/interrupt.$interrupt2" to i32) }) - ret void - } - - define void @UARTE0_UART0_IRQHandler() { -- call void @"runtime/interrupt.callHandlers"(i32 2, i8* undef) -+ call void @"runtime/interrupt.callHandlers"(i32 2, ptr undef) - ret void - } - - define void @NFCT_IRQHandler() { -- call void @"runtime/interrupt.callHandlers"(i32 5, i8* undef) -+ call void @"runtime/interrupt.callHandlers"(i32 5, ptr undef) - ret void - } - -@@ -45,22 +45,21 @@ entry: - ] - - switch.body2: -- call void @"runtime/interrupt.callHandlers"(i32 2, i8* undef) -+ call void @"runtime/interrupt.callHandlers"(i32 2, ptr undef) - ret void - - switch.body5: -- call void @"runtime/interrupt.callHandlers"(i32 5, i8* undef) -+ call void @"runtime/interrupt.callHandlers"(i32 5, ptr undef) - ret void - - switch.done: - ret void - } - --define internal void @"(*machine.UART).handleInterrupt$bound"(i32, i8* nocapture %context) { -+define internal void @"(*machine.UART).handleInterrupt$bound"(i32, ptr nocapture %context) { - entry: -- %unpack.ptr = bitcast i8* %context to %machine.UART* -- call void @"(*machine.UART).handleInterrupt"(%machine.UART* %unpack.ptr, i32 %0, i8* undef) -+ call void @"(*machine.UART).handleInterrupt"(ptr %context, i32 %0, ptr undef) - ret void - } - --declare void @"(*machine.UART).handleInterrupt"(%machine.UART* nocapture, i32, i8* nocapture readnone) -+declare void @"(*machine.UART).handleInterrupt"(ptr nocapture, i32, ptr nocapture readnone) -diff --git a/transform/testdata/interrupt.out.ll b/transform/testdata/interrupt.out.ll -index 7eb9f0a8..3663c0a3 100644 ---- a/transform/testdata/interrupt.out.ll -+++ b/transform/testdata/interrupt.out.ll -@@ -1,31 +1,31 @@ - target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7em-none-eabi" - --%machine.UART = type { %machine.RingBuffer* } -+%machine.UART = type { ptr } - %machine.RingBuffer = type { [128 x %"runtime/volatile.Register8"], %"runtime/volatile.Register8", %"runtime/volatile.Register8" } - %"runtime/volatile.Register8" = type { i8 } - %"runtime/interrupt.Interrupt" = type { i32 } - --@machine.UART0 = internal global %machine.UART { %machine.RingBuffer* @"machine$alloc.335" } -+@machine.UART0 = internal global %machine.UART { ptr @"machine$alloc.335" } - @"machine$alloc.335" = internal global %machine.RingBuffer zeroinitializer - --declare void @"runtime/interrupt.callHandlers"(i32, i8*) local_unnamed_addr -+declare void @"runtime/interrupt.callHandlers"(i32, ptr) local_unnamed_addr - --declare void @"device/arm.EnableIRQ"(i32, i8* nocapture readnone) -+declare void @"device/arm.EnableIRQ"(i32, ptr nocapture readnone) - --declare void @"device/arm.SetPriority"(i32, i32, i8* nocapture readnone) -+declare void @"device/arm.SetPriority"(i32, i32, ptr nocapture readnone) - - declare void @"runtime/interrupt.use"(%"runtime/interrupt.Interrupt") - --define void @runtime.initAll(i8* nocapture readnone %0) unnamed_addr { -+define void @runtime.initAll(ptr nocapture readnone %0) unnamed_addr { - entry: -- call void @"device/arm.SetPriority"(i32 2, i32 192, i8* undef) -- call void @"device/arm.EnableIRQ"(i32 2, i8* undef) -+ call void @"device/arm.SetPriority"(i32 2, i32 192, ptr undef) -+ call void @"device/arm.EnableIRQ"(i32 2, ptr undef) - ret void - } - - define void @UARTE0_UART0_IRQHandler() { -- call void @"(*machine.UART).handleInterrupt$bound"(i32 2, i8* bitcast (%machine.UART* @machine.UART0 to i8*)) -+ call void @"(*machine.UART).handleInterrupt$bound"(i32 2, ptr @machine.UART0) - ret void - } - -@@ -37,7 +37,7 @@ entry: - ] - - switch.body2: ; preds = %entry -- call void @"(*machine.UART).handleInterrupt$bound"(i32 2, i8* bitcast (%machine.UART* @machine.UART0 to i8*)) -+ call void @"(*machine.UART).handleInterrupt$bound"(i32 2, ptr @machine.UART0) - ret void - - switch.body5: ; preds = %entry -@@ -47,11 +47,10 @@ switch.done: ; preds = %entry - ret void - } - --define internal void @"(*machine.UART).handleInterrupt$bound"(i32 %0, i8* nocapture %context) { -+define internal void @"(*machine.UART).handleInterrupt$bound"(i32 %0, ptr nocapture %context) { - entry: -- %unpack.ptr = bitcast i8* %context to %machine.UART* -- call void @"(*machine.UART).handleInterrupt"(%machine.UART* %unpack.ptr, i32 %0, i8* undef) -+ call void @"(*machine.UART).handleInterrupt"(ptr %context, i32 %0, ptr undef) - ret void - } - --declare void @"(*machine.UART).handleInterrupt"(%machine.UART* nocapture, i32, i8* nocapture readnone) -+declare void @"(*machine.UART).handleInterrupt"(ptr nocapture, i32, ptr nocapture readnone) -diff --git a/transform/testdata/maps.ll b/transform/testdata/maps.ll -index 0bf00424..78f6819d 100644 ---- a/transform/testdata/maps.ll -+++ b/transform/testdata/maps.ll -@@ -1,28 +1,25 @@ - target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7m-none-eabi" - --%runtime.hashmap = type { %runtime.hashmap*, i8*, i32, i8, i8, i8 } -- - @answer = constant [6 x i8] c"answer" - - ; func(keySize, valueSize uint8, sizeHint uintptr) *runtime.hashmap --declare nonnull %runtime.hashmap* @runtime.hashmapMake(i8, i8, i32) -+declare nonnull ptr @runtime.hashmapMake(i8, i8, i32) - - ; func(map[string]int, string, unsafe.Pointer) --declare void @runtime.hashmapStringSet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture readonly) -+declare void @runtime.hashmapStringSet(ptr nocapture, ptr, i32, ptr nocapture readonly) - - ; func(map[string]int, string, unsafe.Pointer) --declare i1 @runtime.hashmapStringGet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture) -+declare i1 @runtime.hashmapStringGet(ptr nocapture, ptr, i32, ptr nocapture) - - define void @testUnused() { - ; create the map -- %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) -+ %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) - ; create the value to be stored - %hashmap.value = alloca i32 -- store i32 42, i32* %hashmap.value -+ store i32 42, ptr %hashmap.value - ; store the value -- %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8* -- call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast) -+ call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) - ret void - } - -@@ -30,26 +27,24 @@ define void @testUnused() { - ; return 42), but isn't at the moment. - define i32 @testReadonly() { - ; create the map -- %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) -+ %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) - - ; create the value to be stored - %hashmap.value = alloca i32 -- store i32 42, i32* %hashmap.value -+ store i32 42, ptr %hashmap.value - - ; store the value -- %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8* -- call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast) -+ call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) - - ; load the value back - %hashmap.value2 = alloca i32 -- %hashmap.value2.bitcast = bitcast i32* %hashmap.value2 to i8* -- %commaOk = call i1 @runtime.hashmapStringGet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value2.bitcast) -- %loadedValue = load i32, i32* %hashmap.value2 -+ %commaOk = call i1 @runtime.hashmapStringGet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value2) -+ %loadedValue = load i32, ptr %hashmap.value2 - - ret i32 %loadedValue - } - --define %runtime.hashmap* @testUsed() { -- %1 = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) -- ret %runtime.hashmap* %1 -+define ptr @testUsed() { -+ %1 = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) -+ ret ptr %1 - } -diff --git a/transform/testdata/maps.out.ll b/transform/testdata/maps.out.ll -index 81f9bada..1bd07439 100644 ---- a/transform/testdata/maps.out.ll -+++ b/transform/testdata/maps.out.ll -@@ -1,34 +1,30 @@ - target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7m-none-eabi" - --%runtime.hashmap = type { %runtime.hashmap*, i8*, i32, i8, i8, i8 } -- - @answer = constant [6 x i8] c"answer" - --declare nonnull %runtime.hashmap* @runtime.hashmapMake(i8, i8, i32) -+declare nonnull ptr @runtime.hashmapMake(i8, i8, i32) - --declare void @runtime.hashmapStringSet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture readonly) -+declare void @runtime.hashmapStringSet(ptr nocapture, ptr, i32, ptr nocapture readonly) - --declare i1 @runtime.hashmapStringGet(%runtime.hashmap* nocapture, i8*, i32, i8* nocapture) -+declare i1 @runtime.hashmapStringGet(ptr nocapture, ptr, i32, ptr nocapture) - - define void @testUnused() { - ret void - } - - define i32 @testReadonly() { -- %map = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) -+ %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) - %hashmap.value = alloca i32, align 4 -- store i32 42, i32* %hashmap.value, align 4 -- %hashmap.value.bitcast = bitcast i32* %hashmap.value to i8* -- call void @runtime.hashmapStringSet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value.bitcast) -+ store i32 42, ptr %hashmap.value, align 4 -+ call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) - %hashmap.value2 = alloca i32, align 4 -- %hashmap.value2.bitcast = bitcast i32* %hashmap.value2 to i8* -- %commaOk = call i1 @runtime.hashmapStringGet(%runtime.hashmap* %map, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @answer, i32 0, i32 0), i32 6, i8* %hashmap.value2.bitcast) -- %loadedValue = load i32, i32* %hashmap.value2, align 4 -+ %commaOk = call i1 @runtime.hashmapStringGet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value2) -+ %loadedValue = load i32, ptr %hashmap.value2, align 4 - ret i32 %loadedValue - } - --define %runtime.hashmap* @testUsed() { -- %1 = call %runtime.hashmap* @runtime.hashmapMake(i8 4, i8 4, i32 0) -- ret %runtime.hashmap* %1 -+define ptr @testUsed() { -+ %1 = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) -+ ret ptr %1 - } -diff --git a/transform/testdata/panic.ll b/transform/testdata/panic.ll -index 4f0f0a16..660e30f2 100644 ---- a/transform/testdata/panic.ll -+++ b/transform/testdata/panic.ll -@@ -3,12 +3,12 @@ target triple = "armv7m-none-eabi" - - @"runtime.lookupPanic$string" = constant [18 x i8] c"index out of range" - --declare void @runtime.runtimePanic(i8*, i32) -+declare void @runtime.runtimePanic(ptr, i32) - --declare void @runtime._panic(i32, i8*) -+declare void @runtime._panic(i32, ptr) - - define void @runtime.lookupPanic() { -- call void @runtime.runtimePanic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"runtime.lookupPanic$string", i64 0, i64 0), i32 18) -+ call void @runtime.runtimePanic(ptr @"runtime.lookupPanic$string", i32 18) - ret void - } - -@@ -16,7 +16,7 @@ define void @runtime.lookupPanic() { - ; func someFunc(x interface{}) { - ; panic(x) - ; } --define void @someFunc(i32 %typecode, i8* %value) { -- call void @runtime._panic(i32 %typecode, i8* %value) -+define void @someFunc(i32 %typecode, ptr %value) { -+ call void @runtime._panic(i32 %typecode, ptr %value) - unreachable - } -diff --git a/transform/testdata/panic.out.ll b/transform/testdata/panic.out.ll -index 8612ae9a..458e4c24 100644 ---- a/transform/testdata/panic.out.ll -+++ b/transform/testdata/panic.out.ll -@@ -3,19 +3,19 @@ target triple = "armv7m-none-eabi" - - @"runtime.lookupPanic$string" = constant [18 x i8] c"index out of range" - --declare void @runtime.runtimePanic(i8*, i32) -+declare void @runtime.runtimePanic(ptr, i32) - --declare void @runtime._panic(i32, i8*) -+declare void @runtime._panic(i32, ptr) - - define void @runtime.lookupPanic() { - call void @llvm.trap() -- call void @runtime.runtimePanic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"runtime.lookupPanic$string", i64 0, i64 0), i32 18) -+ call void @runtime.runtimePanic(ptr @"runtime.lookupPanic$string", i32 18) - ret void - } - --define void @someFunc(i32 %typecode, i8* %value) { -+define void @someFunc(i32 %typecode, ptr %value) { - call void @llvm.trap() -- call void @runtime._panic(i32 %typecode, i8* %value) -+ call void @runtime._panic(i32 %typecode, ptr %value) - unreachable - } - -diff --git a/transform/testdata/reflect-implements.ll b/transform/testdata/reflect-implements.ll -index ca6dcb8c..e0e2b9a7 100644 ---- a/transform/testdata/reflect-implements.ll -+++ b/transform/testdata/reflect-implements.ll -@@ -1,17 +1,17 @@ - target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" - target triple = "i686--linux" - --%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } --%runtime.interfaceMethodInfo = type { i8*, i32 } -+%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } -+%runtime.interfaceMethodInfo = type { ptr, i32 } - --@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } --@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } -+@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } -+@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } - @"reflect/methods.Error() string" = linkonce_odr constant i8 0 --@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.Error() string"] -+@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.Error() string"] - @"reflect/methods.Align() int" = linkonce_odr constant i8 0 - @"reflect/methods.Implements(reflect.Type) bool" = linkonce_odr constant i8 0 --@"reflect.Type$interface" = linkonce_odr constant [2 x i8*] [i8* @"reflect/methods.Align() int", i8* @"reflect/methods.Implements(reflect.Type) bool"] --@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:uintptr", i32 0, %runtime.interfaceMethodInfo* getelementptr inbounds ([20 x %runtime.interfaceMethodInfo], [20 x %runtime.interfaceMethodInfo]* @"reflect.rawType$methodset", i32 0, i32 0), %runtime.typecodeID* null, i32 0 } -+@"reflect.Type$interface" = linkonce_odr constant [2 x ptr] [ptr @"reflect/methods.Align() int", ptr @"reflect/methods.Implements(reflect.Type) bool"] -+@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:uintptr", i32 0, ptr @"reflect.rawType$methodset", ptr null, i32 0 } - @"reflect.rawType$methodset" = linkonce_odr constant [20 x %runtime.interfaceMethodInfo] zeroinitializer - @"reflect/types.type:basic:uintptr" = linkonce_odr constant %runtime.typecodeID zeroinitializer - -@@ -22,9 +22,9 @@ target triple = "i686--linux" - ; The type itself is stored in %typ.value, %typ.typecode just refers to the - ; type of reflect.Type. This function can be optimized because errorType is - ; known at compile time (after the interp pass has run). --define i1 @main.isError(i32 %typ.typecode, i8* %typ.value, i8* %context) { -+define i1 @main.isError(i32 %typ.typecode, ptr %typ.value, ptr %context) { - entry: -- %result = call i1 @"reflect.Type.Implements$invoke"(i8* %typ.value, i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:reflect.rawType" to i32), i8* bitcast (%runtime.typecodeID* @"reflect/types.type:named:error" to i8*), i32 %typ.typecode, i8* undef) -+ %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, i32 ptrtoint (ptr @"reflect/types.type:named:reflect.rawType" to i32), ptr @"reflect/types.type:named:error", i32 %typ.typecode, ptr undef) - ret i1 %result - } - -@@ -33,13 +33,13 @@ entry: - ; func isUnknown(typ, itf reflect.Type) bool { - ; return typ.Implements(itf) - ; } --define i1 @main.isUnknown(i32 %typ.typecode, i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i8* %context) { -+define i1 @main.isUnknown(i32 %typ.typecode, ptr %typ.value, i32 %itf.typecode, ptr %itf.value, ptr %context) { - entry: -- %result = call i1 @"reflect.Type.Implements$invoke"(i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i32 %typ.typecode, i8* undef) -+ %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, i32 %itf.typecode, ptr %itf.value, i32 %typ.typecode, ptr undef) - ret i1 %result - } - --declare i1 @"reflect.Type.Implements$invoke"(i8*, i32, i8*, i32, i8*) #0 -+declare i1 @"reflect.Type.Implements$invoke"(ptr, i32, ptr, i32, ptr) #0 - declare i1 @"error.$typeassert"(i32) #1 - - attributes #0 = { "tinygo-invoke"="reflect/methods.Implements(reflect.Type) bool" "tinygo-methods"="reflect/methods.Align() int; reflect/methods.Implements(reflect.Type) bool" } -diff --git a/transform/testdata/reflect-implements.out.ll b/transform/testdata/reflect-implements.out.ll -index 0093e2b0..29366239 100644 ---- a/transform/testdata/reflect-implements.out.ll -+++ b/transform/testdata/reflect-implements.out.ll -@@ -1,34 +1,34 @@ - target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" - target triple = "i686--linux" - --%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 } --%runtime.interfaceMethodInfo = type { i8*, i32 } -+%runtime.typecodeID = type { ptr, i32, ptr, ptr, i32 } -+%runtime.interfaceMethodInfo = type { ptr, i32 } - --@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } --@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* bitcast ([1 x i8*]* @"reflect/types.interface:interface{Error() string}$interface" to %runtime.typecodeID*), i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 ptrtoint (i1 (i32)* @"error.$typeassert" to i32) } -+@"reflect/types.type:named:error" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 0, ptr null, ptr null, i32 ptrtoint (ptr @"error.$typeassert" to i32) } -+@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.interface:interface{Error() string}$interface", i32 0, ptr null, ptr null, i32 ptrtoint (ptr @"error.$typeassert" to i32) } - @"reflect/methods.Error() string" = linkonce_odr constant i8 0 --@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.Error() string"] -+@"reflect/types.interface:interface{Error() string}$interface" = linkonce_odr constant [1 x ptr] [ptr @"reflect/methods.Error() string"] - @"reflect/methods.Align() int" = linkonce_odr constant i8 0 - @"reflect/methods.Implements(reflect.Type) bool" = linkonce_odr constant i8 0 --@"reflect.Type$interface" = linkonce_odr constant [2 x i8*] [i8* @"reflect/methods.Align() int", i8* @"reflect/methods.Implements(reflect.Type) bool"] --@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:uintptr", i32 0, %runtime.interfaceMethodInfo* getelementptr inbounds ([20 x %runtime.interfaceMethodInfo], [20 x %runtime.interfaceMethodInfo]* @"reflect.rawType$methodset", i32 0, i32 0), %runtime.typecodeID* null, i32 0 } -+@"reflect.Type$interface" = linkonce_odr constant [2 x ptr] [ptr @"reflect/methods.Align() int", ptr @"reflect/methods.Implements(reflect.Type) bool"] -+@"reflect/types.type:named:reflect.rawType" = linkonce_odr constant %runtime.typecodeID { ptr @"reflect/types.type:basic:uintptr", i32 0, ptr @"reflect.rawType$methodset", ptr null, i32 0 } - @"reflect.rawType$methodset" = linkonce_odr constant [20 x %runtime.interfaceMethodInfo] zeroinitializer - @"reflect/types.type:basic:uintptr" = linkonce_odr constant %runtime.typecodeID zeroinitializer - --define i1 @main.isError(i32 %typ.typecode, i8* %typ.value, i8* %context) { -+define i1 @main.isError(i32 %typ.typecode, ptr %typ.value, ptr %context) { - entry: -- %0 = ptrtoint i8* %typ.value to i32 -+ %0 = ptrtoint ptr %typ.value to i32 - %1 = call i1 @"error.$typeassert"(i32 %0) - ret i1 %1 - } - --define i1 @main.isUnknown(i32 %typ.typecode, i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i8* %context) { -+define i1 @main.isUnknown(i32 %typ.typecode, ptr %typ.value, i32 %itf.typecode, ptr %itf.value, ptr %context) { - entry: -- %result = call i1 @"reflect.Type.Implements$invoke"(i8* %typ.value, i32 %itf.typecode, i8* %itf.value, i32 %typ.typecode, i8* undef) -+ %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, i32 %itf.typecode, ptr %itf.value, i32 %typ.typecode, ptr undef) - ret i1 %result - } - --declare i1 @"reflect.Type.Implements$invoke"(i8*, i32, i8*, i32, i8*) #0 -+declare i1 @"reflect.Type.Implements$invoke"(ptr, i32, ptr, i32, ptr) #0 - - declare i1 @"error.$typeassert"(i32) #1 - -diff --git a/transform/testdata/stacksize.ll b/transform/testdata/stacksize.ll -index f80a7121..4df5874a 100644 ---- a/transform/testdata/stacksize.ll -+++ b/transform/testdata/stacksize.ll -@@ -1,15 +1,15 @@ - target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7m-none-eabi" - --declare i32 @"internal/task.getGoroutineStackSize"(i32, i8*, i8*) -+declare i32 @"internal/task.getGoroutineStackSize"(i32, ptr, ptr) - --declare void @"runtime.run$1$gowrapper"(i8*) -+declare void @"runtime.run$1$gowrapper"(ptr) - --declare void @"internal/task.start"(i32, i8*, i32) -+declare void @"internal/task.start"(i32, ptr, i32) - - define void @Reset_Handler() { - entry: -- %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (void (i8*)* @"runtime.run$1$gowrapper" to i32), i8* undef, i8* undef) -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"runtime.run$1$gowrapper" to i32), i8* undef, i32 %stacksize) -+ %stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"runtime.run$1$gowrapper" to i32), ptr undef, ptr undef) -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"runtime.run$1$gowrapper" to i32), ptr undef, i32 %stacksize) - ret void - } -diff --git a/transform/testdata/stacksize.out.ll b/transform/testdata/stacksize.out.ll -index cea820ec..59e824cf 100644 ---- a/transform/testdata/stacksize.out.ll -+++ b/transform/testdata/stacksize.out.ll -@@ -2,17 +2,17 @@ target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" - target triple = "armv7m-none-eabi" - - @"internal/task.stackSizes" = global [1 x i32] [i32 1024], section ".tinygo_stacksizes" --@llvm.used = appending global [2 x i8*] [i8* bitcast ([1 x i32]* @"internal/task.stackSizes" to i8*), i8* bitcast (void (i8*)* @"runtime.run$1$gowrapper" to i8*)] -+@llvm.used = appending global [2 x ptr] [ptr @"internal/task.stackSizes", ptr @"runtime.run$1$gowrapper"] - --declare i32 @"internal/task.getGoroutineStackSize"(i32, i8*, i8*) -+declare i32 @"internal/task.getGoroutineStackSize"(i32, ptr, ptr) - --declare void @"runtime.run$1$gowrapper"(i8*) -+declare void @"runtime.run$1$gowrapper"(ptr) - --declare void @"internal/task.start"(i32, i8*, i32) -+declare void @"internal/task.start"(i32, ptr, i32) - - define void @Reset_Handler() { - entry: -- %stacksize1 = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @"internal/task.stackSizes", i32 0, i32 0), align 4 -- call void @"internal/task.start"(i32 ptrtoint (void (i8*)* @"runtime.run$1$gowrapper" to i32), i8* undef, i32 %stacksize1) -+ %stacksize1 = load i32, ptr @"internal/task.stackSizes", align 4 -+ call void @"internal/task.start"(i32 ptrtoint (ptr @"runtime.run$1$gowrapper" to i32), ptr undef, i32 %stacksize1) - ret void - } -diff --git a/transform/testdata/stringequal.ll b/transform/testdata/stringequal.ll -index d355fc45..0d6ed7fb 100644 ---- a/transform/testdata/stringequal.ll -+++ b/transform/testdata/stringequal.ll -@@ -3,17 +3,17 @@ target triple = "armv7m-none-eabi" - - @zeroString = constant [0 x i8] zeroinitializer - --declare i1 @runtime.stringEqual(i8*, i32, i8*, i32, i8*) -+declare i1 @runtime.stringEqual(ptr, i32, ptr, i32, ptr) - --define i1 @main.stringCompareEqualConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { -+define i1 @main.stringCompareEqualConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { - entry: -- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @zeroString, i32 0, i32 0), i32 0, i8* undef) -+ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr @zeroString, i32 0, ptr undef) - ret i1 %0 - } - --define i1 @main.stringCompareUnequalConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { -+define i1 @main.stringCompareUnequalConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { - entry: -- %0 = call i1 @runtime.stringEqual(i8* %s1.data, i32 %s1.len, i8* getelementptr inbounds ([0 x i8], [0 x i8]* @zeroString, i32 0, i32 0), i32 0, i8* undef) -+ %0 = call i1 @runtime.stringEqual(ptr %s1.data, i32 %s1.len, ptr @zeroString, i32 0, ptr undef) - %1 = xor i1 %0, true - ret i1 %1 - } -diff --git a/transform/testdata/stringequal.out.ll b/transform/testdata/stringequal.out.ll -index d148c84f..f2aeb95a 100644 ---- a/transform/testdata/stringequal.out.ll -+++ b/transform/testdata/stringequal.out.ll -@@ -3,15 +3,15 @@ target triple = "armv7m-none-eabi" - - @zeroString = constant [0 x i8] zeroinitializer - --declare i1 @runtime.stringEqual(i8*, i32, i8*, i32, i8*) -+declare i1 @runtime.stringEqual(ptr, i32, ptr, i32, ptr) - --define i1 @main.stringCompareEqualConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { -+define i1 @main.stringCompareEqualConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { - entry: - %0 = icmp eq i32 %s1.len, 0 - ret i1 %0 - } - --define i1 @main.stringCompareUnequalConstantZero(i8* %s1.data, i32 %s1.len, i8* %context) { -+define i1 @main.stringCompareUnequalConstantZero(ptr %s1.data, i32 %s1.len, ptr %context) { - entry: - %0 = icmp eq i32 %s1.len, 0 - %1 = xor i1 %0, true -diff --git a/transform/testdata/stringtobytes.ll b/transform/testdata/stringtobytes.ll -index f3cec823..fa43f3d0 100644 ---- a/transform/testdata/stringtobytes.ll -+++ b/transform/testdata/stringtobytes.ll -@@ -3,30 +3,30 @@ target triple = "x86_64--linux" - - @str = constant [6 x i8] c"foobar" - --declare { i8*, i64, i64 } @runtime.stringToBytes(i8*, i64) -+declare { ptr, i64, i64 } @runtime.stringToBytes(ptr, i64) - --declare void @printSlice(i8* nocapture readonly, i64, i64) -+declare void @printSlice(ptr nocapture readonly, i64, i64) - --declare void @writeToSlice(i8* nocapture, i64, i64) -+declare void @writeToSlice(ptr nocapture, i64, i64) - - ; Test that runtime.stringToBytes can be fully optimized away. - define void @testReadOnly() { - entry: -- %0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6) -- %1 = extractvalue { i8*, i64, i64 } %0, 0 -- %2 = extractvalue { i8*, i64, i64 } %0, 1 -- %3 = extractvalue { i8*, i64, i64 } %0, 2 -- call fastcc void @printSlice(i8* %1, i64 %2, i64 %3) -+ %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) -+ %1 = extractvalue { ptr, i64, i64 } %0, 0 -+ %2 = extractvalue { ptr, i64, i64 } %0, 1 -+ %3 = extractvalue { ptr, i64, i64 } %0, 2 -+ call fastcc void @printSlice(ptr %1, i64 %2, i64 %3) - ret void - } - - ; Test that even though the slice is written to, some values can be propagated. - define void @testReadWrite() { - entry: -- %0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6) -- %1 = extractvalue { i8*, i64, i64 } %0, 0 -- %2 = extractvalue { i8*, i64, i64 } %0, 1 -- %3 = extractvalue { i8*, i64, i64 } %0, 2 -- call fastcc void @writeToSlice(i8* %1, i64 %2, i64 %3) -+ %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) -+ %1 = extractvalue { ptr, i64, i64 } %0, 0 -+ %2 = extractvalue { ptr, i64, i64 } %0, 1 -+ %3 = extractvalue { ptr, i64, i64 } %0, 2 -+ call fastcc void @writeToSlice(ptr %1, i64 %2, i64 %3) - ret void - } -diff --git a/transform/testdata/stringtobytes.out.ll b/transform/testdata/stringtobytes.out.ll -index 49b06581..30aa520a 100644 ---- a/transform/testdata/stringtobytes.out.ll -+++ b/transform/testdata/stringtobytes.out.ll -@@ -3,22 +3,22 @@ target triple = "x86_64--linux" - - @str = constant [6 x i8] c"foobar" - --declare { i8*, i64, i64 } @runtime.stringToBytes(i8*, i64) -+declare { ptr, i64, i64 } @runtime.stringToBytes(ptr, i64) - --declare void @printSlice(i8* nocapture readonly, i64, i64) -+declare void @printSlice(ptr nocapture readonly, i64, i64) - --declare void @writeToSlice(i8* nocapture, i64, i64) -+declare void @writeToSlice(ptr nocapture, i64, i64) - - define void @testReadOnly() { - entry: -- call fastcc void @printSlice(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6, i64 6) -+ call fastcc void @printSlice(ptr @str, i64 6, i64 6) - ret void - } - - define void @testReadWrite() { - entry: -- %0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6) -- %1 = extractvalue { i8*, i64, i64 } %0, 0 -- call fastcc void @writeToSlice(i8* %1, i64 6, i64 6) -+ %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) -+ %1 = extractvalue { ptr, i64, i64 } %0, 0 -+ call fastcc void @writeToSlice(ptr %1, i64 6, i64 6) - ret void - } -diff --git a/transform/testdata/wasm-abi.ll b/transform/testdata/wasm-abi.ll -index 79e25347..ade4b5af 100644 ---- a/transform/testdata/wasm-abi.ll -+++ b/transform/testdata/wasm-abi.ll -@@ -1,19 +1,19 @@ - target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" - target triple = "wasm32-unknown-unknown-wasm" - --declare i64 @externalCall(i8*, i32, i64) -+declare i64 @externalCall(ptr, i32, i64) - --define internal i64 @testCall(i8* %ptr, i32 %len, i64 %foo) { -- %val = call i64 @externalCall(i8* %ptr, i32 %len, i64 %foo) -+define internal i64 @testCall(ptr %ptr, i32 %len, i64 %foo) { -+ %val = call i64 @externalCall(ptr %ptr, i32 %len, i64 %foo) - ret i64 %val - } - --define internal i64 @testCallNonEntry(i8* %ptr, i32 %len) { -+define internal i64 @testCallNonEntry(ptr %ptr, i32 %len) { - entry: - br label %bb1 - - bb1: -- %val = call i64 @externalCall(i8* %ptr, i32 %len, i64 3) -+ %val = call i64 @externalCall(ptr %ptr, i32 %len, i64 3) - ret i64 %val - } - -diff --git a/transform/testdata/wasm-abi.out.ll b/transform/testdata/wasm-abi.out.ll -index cf63c3d7..a1fc7d6a 100644 ---- a/transform/testdata/wasm-abi.out.ll -+++ b/transform/testdata/wasm-abi.out.ll -@@ -1,27 +1,27 @@ - target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" - target triple = "wasm32-unknown-unknown-wasm" - --declare i64 @"externalCall$i64wrap"(i8*, i32, i64) -+declare i64 @"externalCall$i64wrap"(ptr, i32, i64) - --define internal i64 @testCall(i8* %ptr, i32 %len, i64 %foo) { -+define internal i64 @testCall(ptr %ptr, i32 %len, i64 %foo) { - %i64asptr = alloca i64, align 8 - %i64asptr1 = alloca i64, align 8 -- store i64 %foo, i64* %i64asptr1, align 8 -- call void @externalCall(i64* %i64asptr, i8* %ptr, i32 %len, i64* %i64asptr1) -- %retval = load i64, i64* %i64asptr, align 8 -+ store i64 %foo, ptr %i64asptr1, align 8 -+ call void @externalCall(ptr %i64asptr, ptr %ptr, i32 %len, ptr %i64asptr1) -+ %retval = load i64, ptr %i64asptr, align 8 - ret i64 %retval - } - --define internal i64 @testCallNonEntry(i8* %ptr, i32 %len) { -+define internal i64 @testCallNonEntry(ptr %ptr, i32 %len) { - entry: - %i64asptr = alloca i64, align 8 - %i64asptr1 = alloca i64, align 8 - br label %bb1 - - bb1: ; preds = %entry -- store i64 3, i64* %i64asptr1, align 8 -- call void @externalCall(i64* %i64asptr, i8* %ptr, i32 %len, i64* %i64asptr1) -- %retval = load i64, i64* %i64asptr, align 8 -+ store i64 3, ptr %i64asptr1, align 8 -+ call void @externalCall(ptr %i64asptr, ptr %ptr, i32 %len, ptr %i64asptr1) -+ %retval = load i64, ptr %i64asptr, align 8 - ret i64 %retval - } - -@@ -35,11 +35,11 @@ define internal void @callExportedFunction(i64 %foo) { - ret void - } - --declare void @externalCall(i64*, i8*, i32, i64*) -+declare void @externalCall(ptr, ptr, i32, ptr) - --define void @exportedFunction(i64* %0) { -+define void @exportedFunction(ptr %0) { - entry: -- %i64 = load i64, i64* %0, align 8 -+ %i64 = load i64, ptr %0, align 8 - call void @"exportedFunction$i64wrap"(i64 %i64) - ret void - } --- -2.41.0 - diff --git a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch index 41dd054..6ae5c1b 100644 --- a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch +++ b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch @@ -1,7 +1,7 @@ -From 2d424012a1000a5e28a777536d32ab1faa8c9fbb Mon Sep 17 00:00:00 2001 +From 0219753a4b88e2cf23b5991f97aca636a965c29f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 19:41:18 -0400 -Subject: [PATCH 7/7] Update types in cgo tests for LLVM 16 +Subject: [PATCH 7/8] Update types in cgo tests for LLVM 16 Signed-off-by: Elliott Sales de Andrade --- diff --git a/0008-Switch-interp-tests-to-opaque-pointers.patch b/0008-Switch-interp-tests-to-opaque-pointers.patch deleted file mode 100644 index 1991075..0000000 --- a/0008-Switch-interp-tests-to-opaque-pointers.patch +++ /dev/null @@ -1,831 +0,0 @@ -From 74b0c98c51d0f8d566393708ab13dc6943782b36 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 15 Apr 2023 16:42:11 -0400 -Subject: [PATCH 8/9] Switch interp tests to opaque pointers - -Signed-off-by: Elliott Sales de Andrade ---- - interp/testdata/alloc.ll | 56 ++++++++++++------------- - interp/testdata/alloc.out.ll | 28 ++++++------- - interp/testdata/basic.ll | 42 +++++++++---------- - interp/testdata/basic.out.ll | 30 +++++++------- - interp/testdata/consteval.ll | 22 +++++----- - interp/testdata/consteval.out.ll | 2 +- - interp/testdata/interface.ll | 16 +++---- - interp/testdata/phi.ll | 4 +- - interp/testdata/revert.ll | 71 +++++++++++++++----------------- - interp/testdata/revert.out.ll | 55 ++++++++++++------------- - interp/testdata/slice-copy.ll | 67 ++++++++++++++---------------- - 11 files changed, 193 insertions(+), 200 deletions(-) - -diff --git a/interp/testdata/alloc.ll b/interp/testdata/alloc.ll -index 28b0c84e..82fbb5b2 100644 ---- a/interp/testdata/alloc.ll -+++ b/interp/testdata/alloc.ll -@@ -2,17 +2,17 @@ target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" - target triple = "wasm32--wasi" - - @"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00 " } --@pointerFree12 = global i8* null --@pointerFree7 = global i8* null --@pointerFree3 = global i8* null --@pointerFree0 = global i8* null --@layout1 = global i8* null --@layout2 = global i8* null --@layout3 = global i8* null --@layout4 = global i8* null --@bigobj1 = global i8* null -+@pointerFree12 = global ptr null -+@pointerFree7 = global ptr null -+@pointerFree3 = global ptr null -+@pointerFree0 = global ptr null -+@layout1 = global ptr null -+@layout2 = global ptr null -+@layout3 = global ptr null -+@layout4 = global ptr null -+@bigobj1 = global ptr null - --declare i8* @runtime.alloc(i32, i8*) unnamed_addr -+declare ptr @runtime.alloc(i32, ptr) unnamed_addr - - define void @runtime.initAll() unnamed_addr { - call void @main.init() -@@ -21,33 +21,33 @@ define void @runtime.initAll() unnamed_addr { - - define internal void @main.init() unnamed_addr { - ; Object that's word-aligned. -- %pointerFree12 = call i8* @runtime.alloc(i32 12, i8* inttoptr (i32 3 to i8*)) -- store i8* %pointerFree12, i8** @pointerFree12 -+ %pointerFree12 = call ptr @runtime.alloc(i32 12, ptr inttoptr (i32 3 to ptr)) -+ store ptr %pointerFree12, ptr @pointerFree12 - ; Object larger than a word but not word-aligned. -- %pointerFree7 = call i8* @runtime.alloc(i32 7, i8* inttoptr (i32 3 to i8*)) -- store i8* %pointerFree7, i8** @pointerFree7 -+ %pointerFree7 = call ptr @runtime.alloc(i32 7, ptr inttoptr (i32 3 to ptr)) -+ store ptr %pointerFree7, ptr @pointerFree7 - ; Object smaller than a word (and of course not word-aligned). -- %pointerFree3 = call i8* @runtime.alloc(i32 3, i8* inttoptr (i32 3 to i8*)) -- store i8* %pointerFree3, i8** @pointerFree3 -+ %pointerFree3 = call ptr @runtime.alloc(i32 3, ptr inttoptr (i32 3 to ptr)) -+ store ptr %pointerFree3, ptr @pointerFree3 - ; Zero-sized object. -- %pointerFree0 = call i8* @runtime.alloc(i32 0, i8* inttoptr (i32 3 to i8*)) -- store i8* %pointerFree0, i8** @pointerFree0 -+ %pointerFree0 = call ptr @runtime.alloc(i32 0, ptr inttoptr (i32 3 to ptr)) -+ store ptr %pointerFree0, ptr @pointerFree0 - - ; Object made out of 3 pointers. -- %layout1 = call i8* @runtime.alloc(i32 12, i8* inttoptr (i32 67 to i8*)) -- store i8* %layout1, i8** @layout1 -+ %layout1 = call ptr @runtime.alloc(i32 12, ptr inttoptr (i32 67 to ptr)) -+ store ptr %layout1, ptr @layout1 - ; Array (or slice) of 5 slices. -- %layout2 = call i8* @runtime.alloc(i32 60, i8* inttoptr (i32 71 to i8*)) -- store i8* %layout2, i8** @layout2 -+ %layout2 = call ptr @runtime.alloc(i32 60, ptr inttoptr (i32 71 to ptr)) -+ store ptr %layout2, ptr @layout2 - ; Oddly shaped object, using all bits in the layout integer. -- %layout3 = call i8* @runtime.alloc(i32 104, i8* inttoptr (i32 2467830261 to i8*)) -- store i8* %layout3, i8** @layout3 -+ %layout3 = call ptr @runtime.alloc(i32 104, ptr inttoptr (i32 2467830261 to ptr)) -+ store ptr %layout3, ptr @layout3 - ; ...repeated. -- %layout4 = call i8* @runtime.alloc(i32 312, i8* inttoptr (i32 2467830261 to i8*)) -- store i8* %layout4, i8** @layout4 -+ %layout4 = call ptr @runtime.alloc(i32 312, ptr inttoptr (i32 2467830261 to ptr)) -+ store ptr %layout4, ptr @layout4 - - ; Large object that needs to be stored in a separate global. -- %bigobj1 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-2000000000000001" to i8*)) -- store i8* %bigobj1, i8** @bigobj1 -+ %bigobj1 = call ptr @runtime.alloc(i32 248, ptr @"runtime/gc.layout:62-2000000000000001") -+ store ptr %bigobj1, ptr @bigobj1 - ret void - } -diff --git a/interp/testdata/alloc.out.ll b/interp/testdata/alloc.out.ll -index 6e8f6391..b9da6291 100644 ---- a/interp/testdata/alloc.out.ll -+++ b/interp/testdata/alloc.out.ll -@@ -1,24 +1,24 @@ - target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" - target triple = "wasm32--wasi" - --@pointerFree12 = local_unnamed_addr global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @"main$alloc", i32 0, i32 0) --@pointerFree7 = local_unnamed_addr global i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"main$alloc.1", i32 0, i32 0) --@pointerFree3 = local_unnamed_addr global i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"main$alloc.2", i32 0, i32 0) --@pointerFree0 = local_unnamed_addr global i8* getelementptr inbounds ([0 x i8], [0 x i8]* @"main$alloc.3", i32 0, i32 0) --@layout1 = local_unnamed_addr global i8* bitcast ([3 x i8*]* @"main$alloc.4" to i8*) --@layout2 = local_unnamed_addr global i8* bitcast ([5 x { i8*, i32, i32 }]* @"main$alloc.5" to i8*) --@layout3 = local_unnamed_addr global i8* bitcast ({ i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }* @"main$alloc.6" to i8*) --@layout4 = local_unnamed_addr global i8* bitcast ([3 x { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }]* @"main$alloc.7" to i8*) --@bigobj1 = local_unnamed_addr global i8* bitcast ({ i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* }* @"main$alloc.8" to i8*) -+@pointerFree12 = local_unnamed_addr global ptr @"main$alloc" -+@pointerFree7 = local_unnamed_addr global ptr @"main$alloc.1" -+@pointerFree3 = local_unnamed_addr global ptr @"main$alloc.2" -+@pointerFree0 = local_unnamed_addr global ptr @"main$alloc.3" -+@layout1 = local_unnamed_addr global ptr @"main$alloc.4" -+@layout2 = local_unnamed_addr global ptr @"main$alloc.5" -+@layout3 = local_unnamed_addr global ptr @"main$alloc.6" -+@layout4 = local_unnamed_addr global ptr @"main$alloc.7" -+@bigobj1 = local_unnamed_addr global ptr @"main$alloc.8" - @"main$alloc" = internal global [12 x i8] zeroinitializer, align 4 - @"main$alloc.1" = internal global [7 x i8] zeroinitializer, align 4 - @"main$alloc.2" = internal global [3 x i8] zeroinitializer, align 4 - @"main$alloc.3" = internal global [0 x i8] zeroinitializer, align 4 --@"main$alloc.4" = internal global [3 x i8*] zeroinitializer, align 4 --@"main$alloc.5" = internal global [5 x { i8*, i32, i32 }] zeroinitializer, align 4 --@"main$alloc.6" = internal global { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* } zeroinitializer, align 4 --@"main$alloc.7" = internal global [3 x { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }] zeroinitializer, align 4 --@"main$alloc.8" = internal global { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* } zeroinitializer, align 4 -+@"main$alloc.4" = internal global [3 x ptr] zeroinitializer, align 4 -+@"main$alloc.5" = internal global [5 x { ptr, i32, i32 }] zeroinitializer, align 4 -+@"main$alloc.6" = internal global { ptr, ptr, ptr, i32, i32, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, i32, i32, ptr, ptr, i32, i32, ptr, i32, i32, ptr } zeroinitializer, align 4 -+@"main$alloc.7" = internal global [3 x { ptr, ptr, ptr, i32, i32, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, i32, i32, ptr, ptr, i32, i32, ptr, i32, i32, ptr }] zeroinitializer, align 4 -+@"main$alloc.8" = internal global { ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr } zeroinitializer, align 4 - - define void @runtime.initAll() unnamed_addr { - ret void -diff --git a/interp/testdata/basic.ll b/interp/testdata/basic.ll -index 30c0bf08..6d1d010f 100644 ---- a/interp/testdata/basic.ll -+++ b/interp/testdata/basic.ll -@@ -5,7 +5,7 @@ target triple = "x86_64--linux" - @main.nonConst1 = global [4 x i64] zeroinitializer - @main.nonConst2 = global i64 0 - @main.someArray = global [8 x {i16, i32}] zeroinitializer --@main.exportedValue = global [1 x i16*] [i16* @main.exposedValue1] -+@main.exportedValue = global [1 x ptr] [ptr @main.exposedValue1] - @main.exportedConst = constant i64 42 - @main.exposedValue1 = global i16 0 - @main.exposedValue2 = global i16 0 -@@ -24,7 +24,7 @@ entry: - - define void @main() unnamed_addr { - entry: -- %0 = load i64, i64* @main.v1 -+ %0 = load i64, ptr @main.v1 - call void @runtime.printint64(i64 %0) - call void @runtime.printnl() - ret void -@@ -37,43 +37,43 @@ entry: - - define internal void @main.init() unnamed_addr { - entry: -- store i64 3, i64* @main.v1 -+ store i64 3, ptr @main.v1 - call void @"main.init#1"() - - ; test the following pattern: - ; func someValue() int // extern function - ; var nonConst1 = [4]int{someValue(), 0, 0, 0} - %value1 = call i64 @someValue() -- %gep1 = getelementptr [4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0 -- store i64 %value1, i64* %gep1 -+ %gep1 = getelementptr [4 x i64], ptr @main.nonConst1, i32 0, i32 0 -+ store i64 %value1, ptr %gep1 - - ; Test that the global really is marked dirty: - ; var nonConst2 = nonConst1[0] -- %gep2 = getelementptr [4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0 -- %value2 = load i64, i64* %gep2 -- store i64 %value2, i64* @main.nonConst2 -+ %gep2 = getelementptr [4 x i64], ptr @main.nonConst1, i32 0, i32 0 -+ %value2 = load i64, ptr %gep2 -+ store i64 %value2, ptr @main.nonConst2 - - ; Test that the following GEP works: - ; var someArray - ; modifyExternal(&someArray[3].field1) -- %gep3 = getelementptr [8 x {i16, i32}], [8 x {i16, i32}]* @main.someArray, i32 0, i32 3, i32 1 -- call void @modifyExternal(i32* %gep3) -+ %gep3 = getelementptr [8 x {i16, i32}], ptr @main.someArray, i32 0, i32 3, i32 1 -+ call void @modifyExternal(ptr %gep3) - - ; Test that marking a value as external also marks all referenced values. -- call void @modifyExternal(i32* bitcast ([1 x i16*]* @main.exportedValue to i32*)) -- store i16 5, i16* @main.exposedValue1 -+ call void @modifyExternal(ptr @main.exportedValue) -+ store i16 5, ptr @main.exposedValue1 - - ; Test that marking a constant as external still allows loading from it. -- call void @readExternal(i32* bitcast (i64* @main.exportedConst to i32*)) -- %constLoad = load i64, i64 * @main.exportedConst -+ call void @readExternal(ptr @main.exportedConst) -+ %constLoad = load i64, ptr @main.exportedConst - call void @runtime.printint64(i64 %constLoad) - - ; Test that this even propagates through functions. -- call void @modifyExternal(i32* bitcast (void ()* @willModifyGlobal to i32*)) -- store i16 7, i16* @main.exposedValue2 -+ call void @modifyExternal(ptr @willModifyGlobal) -+ store i16 7, ptr @main.exposedValue2 - - ; Test that inline assembly is ignored. -- call void @modifyExternal(i32* bitcast (void ()* @hasInlineAsm to i32*)) -+ call void @modifyExternal(ptr @hasInlineAsm) - - ; Test switch statement. - %switch1 = call i64 @testSwitch(i64 1) ; 1 returns 6 -@@ -86,7 +86,7 @@ entry: - %elt = extractvalue {i8, i32, {float, {i64, i16}}} %agg, 2, 1, 0 - call void @runtime.printint64(i64 %elt) - %agg2 = insertvalue {i8, i32, {float, {i64, i16}}} %agg, i64 5, 2, 1, 0 -- store {i8, i32, {float, {i64, i16}}} %agg2, {i8, i32, {float, {i64, i16}}}* @main.insertedValue -+ store {i8, i32, {float, {i64, i16}}} %agg2, ptr @main.insertedValue - - ret void - } -@@ -100,16 +100,16 @@ entry: - - declare i64 @someValue() - --declare void @modifyExternal(i32*) -+declare void @modifyExternal(ptr) - --declare void @readExternal(i32*) -+declare void @readExternal(ptr) - - ; This function will modify an external value. By passing this function as a - ; function pointer to an external function, @main.exposedValue2 should be - ; marked as external. - define void @willModifyGlobal() { - entry: -- store i16 8, i16* @main.exposedValue2 -+ store i16 8, ptr @main.exposedValue2 - ret void - } - -diff --git a/interp/testdata/basic.out.ll b/interp/testdata/basic.out.ll -index 5c68ec5e..342d4965 100644 ---- a/interp/testdata/basic.out.ll -+++ b/interp/testdata/basic.out.ll -@@ -4,7 +4,7 @@ target triple = "x86_64--linux" - @main.nonConst1 = local_unnamed_addr global [4 x i64] zeroinitializer - @main.nonConst2 = local_unnamed_addr global i64 0 - @main.someArray = global [8 x { i16, i32 }] zeroinitializer --@main.exportedValue = global [1 x i16*] [i16* @main.exposedValue1] -+@main.exportedValue = global [1 x ptr] [ptr @main.exposedValue1] - @main.exportedConst = constant i64 42 - @main.exposedValue1 = global i16 0 - @main.exposedValue2 = local_unnamed_addr global i16 0 -@@ -19,17 +19,17 @@ entry: - call void @runtime.printint64(i64 5) - call void @runtime.printnl() - %value1 = call i64 @someValue() -- store i64 %value1, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0), align 8 -- %value2 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0), align 8 -- store i64 %value2, i64* @main.nonConst2, align 8 -- call void @modifyExternal(i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ([8 x { i16, i32 }]* @main.someArray to i8*), i32 28) to i32*)) -- call void @modifyExternal(i32* bitcast ([1 x i16*]* @main.exportedValue to i32*)) -- store i16 5, i16* @main.exposedValue1, align 2 -- call void @readExternal(i32* bitcast (i64* @main.exportedConst to i32*)) -+ store i64 %value1, ptr @main.nonConst1, align 8 -+ %value2 = load i64, ptr @main.nonConst1, align 8 -+ store i64 %value2, ptr @main.nonConst2, align 8 -+ call void @modifyExternal(ptr getelementptr inbounds (i8, ptr @main.someArray, i32 28)) -+ call void @modifyExternal(ptr @main.exportedValue) -+ store i16 5, ptr @main.exposedValue1, align 2 -+ call void @readExternal(ptr @main.exportedConst) - call void @runtime.printint64(i64 42) -- call void @modifyExternal(i32* bitcast (void ()* @willModifyGlobal to i32*)) -- store i16 7, i16* @main.exposedValue2, align 2 -- call void @modifyExternal(i32* bitcast (void ()* @hasInlineAsm to i32*)) -+ call void @modifyExternal(ptr @willModifyGlobal) -+ store i16 7, ptr @main.exposedValue2, align 2 -+ call void @modifyExternal(ptr @hasInlineAsm) - call void @runtime.printint64(i64 6) - call void @runtime.printint64(i64 -1) - %agg = call { i8, i32, { float, { i64, i16 } } } @nestedStruct() -@@ -42,7 +42,7 @@ entry: - %agg2.insertvalue2 = insertvalue { i64, i16 } %agg2.agg1, i64 5, 0 - %agg2.insertvalue1 = insertvalue { float, { i64, i16 } } %agg2.agg0, { i64, i16 } %agg2.insertvalue2, 1 - %agg2.insertvalue0 = insertvalue { i8, i32, { float, { i64, i16 } } } %agg, { float, { i64, i16 } } %agg2.insertvalue1, 2 -- store { i8, i32, { float, { i64, i16 } } } %agg2.insertvalue0, { i8, i32, { float, { i64, i16 } } }* @main.insertedValue, align 8 -+ store { i8, i32, { float, { i64, i16 } } } %agg2.insertvalue0, ptr @main.insertedValue, align 8 - ret void - } - -@@ -55,13 +55,13 @@ entry: - - declare i64 @someValue() local_unnamed_addr - --declare void @modifyExternal(i32*) local_unnamed_addr -+declare void @modifyExternal(ptr) local_unnamed_addr - --declare void @readExternal(i32*) local_unnamed_addr -+declare void @readExternal(ptr) local_unnamed_addr - - define void @willModifyGlobal() { - entry: -- store i16 8, i16* @main.exposedValue2, align 2 -+ store i16 8, ptr @main.exposedValue2, align 2 - ret void - } - -diff --git a/interp/testdata/consteval.ll b/interp/testdata/consteval.ll -index d0c0e3b6..05d377f1 100644 ---- a/interp/testdata/consteval.ll -+++ b/interp/testdata/consteval.ll -@@ -5,7 +5,7 @@ target triple = "x86_64--linux" - @ptrToIntResult = global i8 0 - @icmpResult = global i8 0 - @someArray = internal global {i16, i8, i8} zeroinitializer --@someArrayPointer = global i8* zeroinitializer -+@someArrayPointer = global ptr zeroinitializer - - define void @runtime.initAll() { - call void @main.init() -@@ -21,45 +21,45 @@ define internal void @main.init() { - } - - define internal void @testIntToPtr() { -- %nil = icmp eq i8* inttoptr (i64 1024 to i8*), null -+ %nil = icmp eq ptr inttoptr (i64 1024 to ptr), null - br i1 %nil, label %a, label %b - a: - ; should not be reached -- store i8 1, i8* @intToPtrResult -+ store i8 1, ptr @intToPtrResult - ret void - b: - ; should be reached -- store i8 2, i8* @intToPtrResult -+ store i8 2, ptr @intToPtrResult - ret void - } - - define internal void @testPtrToInt() { -- %zero = icmp eq i64 ptrtoint (i8* @ptrToIntResult to i64), 0 -+ %zero = icmp eq i64 ptrtoint (ptr @ptrToIntResult to i64), 0 - br i1 %zero, label %a, label %b - a: - ; should not be reached -- store i8 1, i8* @ptrToIntResult -+ store i8 1, ptr @ptrToIntResult - ret void - b: - ; should be reached -- store i8 2, i8* @ptrToIntResult -+ store i8 2, ptr @ptrToIntResult - ret void - } - - define internal void @testConstGEP() { -- store i8* getelementptr inbounds (i8, i8* bitcast ({i16, i8, i8}* @someArray to i8*), i32 2), i8** @someArrayPointer -+ store ptr getelementptr inbounds (i8, ptr @someArray, i32 2), ptr @someArrayPointer - ret void - } - - define internal void @testICmp() { -- br i1 icmp eq (i64 ptrtoint (i8* @ptrToIntResult to i64), i64 0), label %equal, label %unequal -+ br i1 icmp eq (i64 ptrtoint (ptr @ptrToIntResult to i64), i64 0), label %equal, label %unequal - equal: - ; should not be reached -- store i8 1, i8* @icmpResult -+ store i8 1, ptr @icmpResult - ret void - unequal: - ; should be reached -- store i8 2, i8* @icmpResult -+ store i8 2, ptr @icmpResult - ret void - ret void - } -diff --git a/interp/testdata/consteval.out.ll b/interp/testdata/consteval.out.ll -index 08d74c85..0d0b2884 100644 ---- a/interp/testdata/consteval.out.ll -+++ b/interp/testdata/consteval.out.ll -@@ -5,7 +5,7 @@ target triple = "x86_64--linux" - @ptrToIntResult = local_unnamed_addr global i8 2 - @icmpResult = local_unnamed_addr global i8 2 - @someArray = internal global { i16, i8, i8 } zeroinitializer --@someArrayPointer = local_unnamed_addr global i8* getelementptr inbounds ({ i16, i8, i8 }, { i16, i8, i8 }* @someArray, i64 0, i32 1) -+@someArrayPointer = local_unnamed_addr global ptr getelementptr inbounds ({ i16, i8, i8 }, ptr @someArray, i64 0, i32 1) - - define void @runtime.initAll() local_unnamed_addr { - ret void -diff --git a/interp/testdata/interface.ll b/interp/testdata/interface.ll -index 6520efc5..2a025151 100644 ---- a/interp/testdata/interface.ll -+++ b/interp/testdata/interface.ll -@@ -1,17 +1,17 @@ - target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" - target triple = "x86_64--linux" - --%runtime.typecodeID = type { %runtime.typecodeID*, i64, %runtime.interfaceMethodInfo* } --%runtime.interfaceMethodInfo = type { i8*, i64 } -+%runtime.typecodeID = type { ptr, i64, ptr } -+%runtime.interfaceMethodInfo = type { ptr, i64 } - - @main.v1 = global i1 0 - @main.v2 = global i1 0 --@"reflect/types.type:named:main.foo" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i64 0, %runtime.interfaceMethodInfo* null } -+@"reflect/types.type:named:main.foo" = private constant %runtime.typecodeID { ptr @"reflect/types.type:basic:int", i64 0, ptr null } - @"reflect/types.typeid:named:main.foo" = external constant i8 - @"reflect/types.type:basic:int" = external constant %runtime.typecodeID - - --declare i1 @runtime.typeAssert(i64, i8*, i8*, i8*) -+declare i1 @runtime.typeAssert(i64, ptr, ptr, ptr) - - define void @runtime.initAll() unnamed_addr { - entry: -@@ -22,9 +22,9 @@ entry: - define internal void @main.init() unnamed_addr { - entry: - ; Test type asserts. -- %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:main.foo" to i64), i8* @"reflect/types.typeid:named:main.foo", i8* undef, i8* null) -- store i1 %typecode, i1* @main.v1 -- %typecode2 = call i1 @runtime.typeAssert(i64 0, i8* @"reflect/types.typeid:named:main.foo", i8* undef, i8* null) -- store i1 %typecode2, i1* @main.v2 -+ %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (ptr @"reflect/types.type:named:main.foo" to i64), ptr @"reflect/types.typeid:named:main.foo", ptr undef, ptr null) -+ store i1 %typecode, ptr @main.v1 -+ %typecode2 = call i1 @runtime.typeAssert(i64 0, ptr @"reflect/types.typeid:named:main.foo", ptr undef, ptr null) -+ store i1 %typecode2, ptr @main.v2 - ret void - } -diff --git a/interp/testdata/phi.ll b/interp/testdata/phi.ll -index 0a0dad72..e2a15b69 100644 ---- a/interp/testdata/phi.ll -+++ b/interp/testdata/phi.ll -@@ -25,7 +25,7 @@ for.loop: - br i1 %icmp, label %for.done, label %for.loop - - for.done: -- store i8 %a, i8* @main.phiNodesResultA -- store i8 %b, i8* @main.phiNodesResultB -+ store i8 %a, ptr @main.phiNodesResultA -+ store i8 %b, ptr @main.phiNodesResultB - ret void - } -diff --git a/interp/testdata/revert.ll b/interp/testdata/revert.ll -index 517c152b..e82c0fb7 100644 ---- a/interp/testdata/revert.ll -+++ b/interp/testdata/revert.ll -@@ -3,7 +3,7 @@ target triple = "x86_64--linux" - - declare void @externalCall(i64) - --declare i64 @ptrHash(i8* nocapture) -+declare i64 @ptrHash(ptr nocapture) - - @foo.knownAtRuntime = global i64 0 - @bar.knownAtRuntime = global i64 0 -@@ -17,60 +17,60 @@ declare i64 @ptrHash(i8* nocapture) - - define void @runtime.initAll() unnamed_addr { - entry: -- call void @baz.init(i8* undef) -- call void @foo.init(i8* undef) -- call void @bar.init(i8* undef) -- call void @main.init(i8* undef) -- call void @x.init(i8* undef) -- call void @y.init(i8* undef) -- call void @z.init(i8* undef) -+ call void @baz.init(ptr undef) -+ call void @foo.init(ptr undef) -+ call void @bar.init(ptr undef) -+ call void @main.init(ptr undef) -+ call void @x.init(ptr undef) -+ call void @y.init(ptr undef) -+ call void @z.init(ptr undef) - ret void - } - --define internal void @foo.init(i8* %context) unnamed_addr { -- store i64 5, i64* @foo.knownAtRuntime -+define internal void @foo.init(ptr %context) unnamed_addr { -+ store i64 5, ptr @foo.knownAtRuntime - unreachable ; this triggers a revert of @foo.init. - } - --define internal void @bar.init(i8* %context) unnamed_addr { -- %val = load i64, i64* @foo.knownAtRuntime -- store i64 %val, i64* @bar.knownAtRuntime -+define internal void @bar.init(ptr %context) unnamed_addr { -+ %val = load i64, ptr @foo.knownAtRuntime -+ store i64 %val, ptr @bar.knownAtRuntime - ret void - } - --define internal void @baz.init(i8* %context) unnamed_addr { -+define internal void @baz.init(ptr %context) unnamed_addr { - ; Test extractvalue/insertvalue with more than one index. -- %val = load [3 x {i64, i32}], [3 x {i64, i32}]* @baz.someGlobal -+ %val = load [3 x {i64, i32}], ptr @baz.someGlobal - %part = extractvalue [3 x {i64, i32}] %val, 0, 1 - %val2 = insertvalue [3 x {i64, i32}] %val, i32 5, 2, 1 - unreachable ; trigger revert - } - --define internal void @main.init(i8* %context) unnamed_addr { -+define internal void @main.init(ptr %context) unnamed_addr { - entry: - call void @externalCall(i64 3) - ret void - } - - --define internal void @x.init(i8* %context) unnamed_addr { -+define internal void @x.init(ptr %context) unnamed_addr { - ; Test atomic and volatile memory accesses. -- store atomic i32 1, i32* @x.atomicNum seq_cst, align 4 -- %x = load atomic i32, i32* @x.atomicNum seq_cst, align 4 -- store i32 %x, i32* @x.atomicNum -- %y = load volatile i32, i32* @x.volatileNum -- store volatile i32 %y, i32* @x.volatileNum -+ store atomic i32 1, ptr @x.atomicNum seq_cst, align 4 -+ %x = load atomic i32, ptr @x.atomicNum seq_cst, align 4 -+ store i32 %x, ptr @x.atomicNum -+ %y = load volatile i32, ptr @x.volatileNum -+ store volatile i32 %y, ptr @x.volatileNum - ret void - } - --define internal void @y.init(i8* %context) unnamed_addr { -+define internal void @y.init(ptr %context) unnamed_addr { - entry: - br label %loop - - loop: - ; Test a wait-loop. - ; This function must be reverted. -- %val = load atomic i32, i32* @y.ready seq_cst, align 4 -+ %val = load atomic i32, ptr @y.ready seq_cst, align 4 - %ready = icmp eq i32 %val, 1 - br i1 %ready, label %end, label %loop - -@@ -78,27 +78,25 @@ end: - ret void - } - --define internal void @z.init(i8* %context) unnamed_addr { -- %bloom = bitcast i64* @z.bloom to i8* -- -+define internal void @z.init(ptr %context) unnamed_addr { - ; This can be safely expanded. -- call void @z.setArr(i8* %bloom, i64 1, i8* %bloom) -+ call void @z.setArr(ptr @z.bloom, i64 1, ptr @z.bloom) - - ; This call should be reverted to prevent unrolling. -- call void @z.setArr(i8* bitcast ([32 x i8]* @z.arr to i8*), i64 32, i8* %bloom) -+ call void @z.setArr(ptr @z.arr, i64 32, ptr @z.bloom) - - ret void - } - --define internal void @z.setArr(i8* %arr, i64 %n, i8* %context) unnamed_addr { -+define internal void @z.setArr(ptr %arr, i64 %n, ptr %context) unnamed_addr { - entry: - br label %loop - - loop: - %prev = phi i64 [ %n, %entry ], [ %idx, %loop ] - %idx = sub i64 %prev, 1 -- %elem = getelementptr i8, i8* %arr, i64 %idx -- call void @z.set(i8* %elem, i8* %context) -+ %elem = getelementptr i8, ptr %arr, i64 %idx -+ call void @z.set(ptr %elem, ptr %context) - %done = icmp eq i64 %idx, 0 - br i1 %done, label %end, label %loop - -@@ -106,14 +104,13 @@ end: - ret void - } - --define internal void @z.set(i8* %ptr, i8* %context) unnamed_addr { -+define internal void @z.set(ptr %ptr, ptr %context) unnamed_addr { - ; Insert the pointer into the Bloom filter. -- %hash = call i64 @ptrHash(i8* %ptr) -+ %hash = call i64 @ptrHash(ptr %ptr) - %index = lshr i64 %hash, 58 - %bit = shl i64 1, %index -- %bloom = bitcast i8* %context to i64* -- %old = load i64, i64* %bloom -+ %old = load i64, ptr %context - %new = or i64 %old, %bit -- store i64 %new, i64* %bloom -+ store i64 %new, ptr %context - ret void - } -diff --git a/interp/testdata/revert.out.ll b/interp/testdata/revert.out.ll -index edf19b54..db226c26 100644 ---- a/interp/testdata/revert.out.ll -+++ b/interp/testdata/revert.out.ll -@@ -13,41 +13,41 @@ target triple = "x86_64--linux" - - declare void @externalCall(i64) local_unnamed_addr - --declare i64 @ptrHash(i8* nocapture) local_unnamed_addr -+declare i64 @ptrHash(ptr nocapture) local_unnamed_addr - - define void @runtime.initAll() unnamed_addr { - entry: -- call fastcc void @baz.init(i8* undef) -- call fastcc void @foo.init(i8* undef) -- %val = load i64, i64* @foo.knownAtRuntime, align 8 -- store i64 %val, i64* @bar.knownAtRuntime, align 8 -+ call fastcc void @baz.init(ptr undef) -+ call fastcc void @foo.init(ptr undef) -+ %val = load i64, ptr @foo.knownAtRuntime, align 8 -+ store i64 %val, ptr @bar.knownAtRuntime, align 8 - call void @externalCall(i64 3) -- store atomic i32 1, i32* @x.atomicNum seq_cst, align 4 -- %x = load atomic i32, i32* @x.atomicNum seq_cst, align 4 -- store i32 %x, i32* @x.atomicNum, align 4 -- %y = load volatile i32, i32* @x.volatileNum, align 4 -- store volatile i32 %y, i32* @x.volatileNum, align 4 -- call fastcc void @y.init(i8* undef) -- call fastcc void @z.set(i8* bitcast (i64* @z.bloom to i8*), i8* bitcast (i64* @z.bloom to i8*)) -- call fastcc void @z.setArr(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @z.arr, i32 0, i32 0), i64 32, i8* bitcast (i64* @z.bloom to i8*)) -+ store atomic i32 1, ptr @x.atomicNum seq_cst, align 4 -+ %x = load atomic i32, ptr @x.atomicNum seq_cst, align 4 -+ store i32 %x, ptr @x.atomicNum, align 4 -+ %y = load volatile i32, ptr @x.volatileNum, align 4 -+ store volatile i32 %y, ptr @x.volatileNum, align 4 -+ call fastcc void @y.init(ptr undef) -+ call fastcc void @z.set(ptr @z.bloom, ptr @z.bloom) -+ call fastcc void @z.setArr(ptr @z.arr, i64 32, ptr @z.bloom) - ret void - } - --define internal fastcc void @foo.init(i8* %context) unnamed_addr { -- store i64 5, i64* @foo.knownAtRuntime, align 8 -+define internal fastcc void @foo.init(ptr %context) unnamed_addr { -+ store i64 5, ptr @foo.knownAtRuntime, align 8 - unreachable - } - --define internal fastcc void @baz.init(i8* %context) unnamed_addr { -+define internal fastcc void @baz.init(ptr %context) unnamed_addr { - unreachable - } - --define internal fastcc void @y.init(i8* %context) unnamed_addr { -+define internal fastcc void @y.init(ptr %context) unnamed_addr { - entry: - br label %loop - - loop: ; preds = %loop, %entry -- %val = load atomic i32, i32* @y.ready seq_cst, align 4 -+ %val = load atomic i32, ptr @y.ready seq_cst, align 4 - %ready = icmp eq i32 %val, 1 - br i1 %ready, label %end, label %loop - -@@ -55,15 +55,15 @@ end: ; preds = %loop - ret void - } - --define internal fastcc void @z.setArr(i8* %arr, i64 %n, i8* %context) unnamed_addr { -+define internal fastcc void @z.setArr(ptr %arr, i64 %n, ptr %context) unnamed_addr { - entry: - br label %loop -- -+ - loop: ; preds = %loop, %entry - %prev = phi i64 [ %n, %entry ], [ %idx, %loop ] - %idx = sub i64 %prev, 1 -- %elem = getelementptr i8, i8* %arr, i64 %idx -- call fastcc void @z.set(i8* %elem, i8* %context) -+ %elem = getelementptr i8, ptr %arr, i64 %idx -+ call fastcc void @z.set(ptr %elem, ptr %context) - %done = icmp eq i64 %idx, 0 - br i1 %done, label %end, label %loop - -@@ -71,13 +71,12 @@ end: ; preds = %loop - ret void - } - --define internal fastcc void @z.set(i8* %ptr, i8* %context) unnamed_addr { -- %hash = call i64 @ptrHash(i8* %ptr) -+define internal fastcc void @z.set(ptr %ptr, ptr %context) unnamed_addr { -+ %hash = call i64 @ptrHash(ptr %ptr) - %index = lshr i64 %hash, 58 - %bit = shl i64 1, %index -- %bloom = bitcast i8* %context to i64* -- %old = load i64, i64* %bloom, align 8 -+ %old = load i64, ptr %context, align 8 - %new = or i64 %old, %bit -- store i64 %new, i64* %bloom, align 8 -+ store i64 %new, ptr %context, align 8 - ret void --} -\ No newline at end of file -+} -diff --git a/interp/testdata/slice-copy.ll b/interp/testdata/slice-copy.ll -index 52cbb372..6776d2d6 100644 ---- a/interp/testdata/slice-copy.ll -+++ b/interp/testdata/slice-copy.ll -@@ -2,15 +2,15 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" - target triple = "x86_64--linux" - - @main.uint8SliceSrc.buf = internal global [2 x i8] c"\03d" --@main.uint8SliceSrc = internal unnamed_addr global { i8*, i64, i64 } { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @main.uint8SliceSrc.buf, i32 0, i32 0), i64 2, i64 2 } --@main.uint8SliceDst = internal unnamed_addr global { i8*, i64, i64 } zeroinitializer -+@main.uint8SliceSrc = internal unnamed_addr global { ptr, i64, i64 } { ptr @main.uint8SliceSrc.buf, i64 2, i64 2 } -+@main.uint8SliceDst = internal unnamed_addr global { ptr, i64, i64 } zeroinitializer - @main.int16SliceSrc.buf = internal global [3 x i16] [i16 5, i16 123, i16 1024] --@main.int16SliceSrc = internal unnamed_addr global { i16*, i64, i64 } { i16* getelementptr inbounds ([3 x i16], [3 x i16]* @main.int16SliceSrc.buf, i32 0, i32 0), i64 3, i64 3 } --@main.int16SliceDst = internal unnamed_addr global { i16*, i64, i64 } zeroinitializer -+@main.int16SliceSrc = internal unnamed_addr global { ptr, i64, i64 } { ptr @main.int16SliceSrc.buf, i64 3, i64 3 } -+@main.int16SliceDst = internal unnamed_addr global { ptr, i64, i64 } zeroinitializer - --declare i64 @runtime.sliceCopy(i8* %dst, i8* %src, i64 %dstLen, i64 %srcLen, i64 %elemSize) unnamed_addr -+declare i64 @runtime.sliceCopy(ptr %dst, ptr %src, i64 %dstLen, i64 %srcLen, i64 %elemSize) unnamed_addr - --declare i8* @runtime.alloc(i64, i8*) unnamed_addr -+declare ptr @runtime.alloc(i64, ptr) unnamed_addr - - declare void @runtime.printuint8(i8) - -@@ -25,23 +25,23 @@ entry: - define void @main() unnamed_addr { - entry: - ; print(uintSliceSrc[0]) -- %uint8SliceSrc.buf = load i8*, i8** getelementptr inbounds ({ i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceSrc, i64 0, i32 0) -- %uint8SliceSrc.val = load i8, i8* %uint8SliceSrc.buf -+ %uint8SliceSrc.buf = load ptr, ptr @main.uint8SliceSrc -+ %uint8SliceSrc.val = load i8, ptr %uint8SliceSrc.buf - call void @runtime.printuint8(i8 %uint8SliceSrc.val) - - ; print(uintSliceDst[0]) -- %uint8SliceDst.buf = load i8*, i8** getelementptr inbounds ({ i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceDst, i64 0, i32 0) -- %uint8SliceDst.val = load i8, i8* %uint8SliceDst.buf -+ %uint8SliceDst.buf = load ptr, ptr @main.uint8SliceDst -+ %uint8SliceDst.val = load i8, ptr %uint8SliceDst.buf - call void @runtime.printuint8(i8 %uint8SliceDst.val) - - ; print(int16SliceSrc[0]) -- %int16SliceSrc.buf = load i16*, i16** getelementptr inbounds ({ i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceSrc, i64 0, i32 0) -- %int16SliceSrc.val = load i16, i16* %int16SliceSrc.buf -+ %int16SliceSrc.buf = load ptr, ptr @main.int16SliceSrc -+ %int16SliceSrc.val = load i16, ptr %int16SliceSrc.buf - call void @runtime.printint16(i16 %int16SliceSrc.val) - - ; print(int16SliceDst[0]) -- %int16SliceDst.buf = load i16*, i16** getelementptr inbounds ({ i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceDst, i64 0, i32 0) -- %int16SliceDst.val = load i16, i16* %int16SliceDst.buf -+ %int16SliceDst.buf = load ptr, ptr @main.int16SliceDst -+ %int16SliceDst.val = load i16, ptr %int16SliceDst.buf - call void @runtime.printint16(i16 %int16SliceDst.val) - ret void - } -@@ -50,37 +50,34 @@ define internal void @main.init() unnamed_addr { - entry: - ; equivalent of: - ; uint8SliceDst = make([]uint8, len(uint8SliceSrc)) -- %uint8SliceSrc = load { i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceSrc -- %uint8SliceSrc.len = extractvalue { i8*, i64, i64 } %uint8SliceSrc, 1 -- %uint8SliceDst.buf = call i8* @runtime.alloc(i64 %uint8SliceSrc.len, i8* null) -- %0 = insertvalue { i8*, i64, i64 } undef, i8* %uint8SliceDst.buf, 0 -- %1 = insertvalue { i8*, i64, i64 } %0, i64 %uint8SliceSrc.len, 1 -- %2 = insertvalue { i8*, i64, i64 } %1, i64 %uint8SliceSrc.len, 2 -- store { i8*, i64, i64 } %2, { i8*, i64, i64 }* @main.uint8SliceDst -+ %uint8SliceSrc = load { ptr, i64, i64 }, ptr @main.uint8SliceSrc -+ %uint8SliceSrc.len = extractvalue { ptr, i64, i64 } %uint8SliceSrc, 1 -+ %uint8SliceDst.buf = call ptr @runtime.alloc(i64 %uint8SliceSrc.len, ptr null) -+ %0 = insertvalue { ptr, i64, i64 } undef, ptr %uint8SliceDst.buf, 0 -+ %1 = insertvalue { ptr, i64, i64 } %0, i64 %uint8SliceSrc.len, 1 -+ %2 = insertvalue { ptr, i64, i64 } %1, i64 %uint8SliceSrc.len, 2 -+ store { ptr, i64, i64 } %2, ptr @main.uint8SliceDst - - ; equivalent of: - ; copy(uint8SliceDst, uint8SliceSrc) -- %uint8SliceSrc.buf = extractvalue { i8*, i64, i64 } %uint8SliceSrc, 0 -- %copy.n = call i64 @runtime.sliceCopy(i8* %uint8SliceDst.buf, i8* %uint8SliceSrc.buf, i64 %uint8SliceSrc.len, i64 %uint8SliceSrc.len, i64 1) -+ %uint8SliceSrc.buf = extractvalue { ptr, i64, i64 } %uint8SliceSrc, 0 -+ %copy.n = call i64 @runtime.sliceCopy(ptr %uint8SliceDst.buf, ptr %uint8SliceSrc.buf, i64 %uint8SliceSrc.len, i64 %uint8SliceSrc.len, i64 1) - - ; equivalent of: - ; int16SliceDst = make([]int16, len(int16SliceSrc)) -- %int16SliceSrc = load { i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceSrc -- %int16SliceSrc.len = extractvalue { i16*, i64, i64 } %int16SliceSrc, 1 -+ %int16SliceSrc = load { ptr, i64, i64 }, ptr @main.int16SliceSrc -+ %int16SliceSrc.len = extractvalue { ptr, i64, i64 } %int16SliceSrc, 1 - %int16SliceSrc.len.bytes = mul i64 %int16SliceSrc.len, 2 -- %int16SliceDst.buf.raw = call i8* @runtime.alloc(i64 %int16SliceSrc.len.bytes, i8* null) -- %int16SliceDst.buf = bitcast i8* %int16SliceDst.buf.raw to i16* -- %3 = insertvalue { i16*, i64, i64 } undef, i16* %int16SliceDst.buf, 0 -- %4 = insertvalue { i16*, i64, i64 } %3, i64 %int16SliceSrc.len, 1 -- %5 = insertvalue { i16*, i64, i64 } %4, i64 %int16SliceSrc.len, 2 -- store { i16*, i64, i64 } %5, { i16*, i64, i64 }* @main.int16SliceDst -+ %int16SliceDst.buf = call ptr @runtime.alloc(i64 %int16SliceSrc.len.bytes, ptr null) -+ %3 = insertvalue { ptr, i64, i64 } undef, ptr %int16SliceDst.buf, 0 -+ %4 = insertvalue { ptr, i64, i64 } %3, i64 %int16SliceSrc.len, 1 -+ %5 = insertvalue { ptr, i64, i64 } %4, i64 %int16SliceSrc.len, 2 -+ store { ptr, i64, i64 } %5, ptr @main.int16SliceDst - - ; equivalent of: - ; copy(int16SliceDst, int16SliceSrc) -- %int16SliceSrc.buf = extractvalue { i16*, i64, i64 } %int16SliceSrc, 0 -- %int16SliceSrc.buf.i8ptr = bitcast i16* %int16SliceSrc.buf to i8* -- %int16SliceDst.buf.i8ptr = bitcast i16* %int16SliceDst.buf to i8* -- %copy.n2 = call i64 @runtime.sliceCopy(i8* %int16SliceDst.buf.i8ptr, i8* %int16SliceSrc.buf.i8ptr, i64 %int16SliceSrc.len, i64 %int16SliceSrc.len, i64 2) -+ %int16SliceSrc.buf = extractvalue { ptr, i64, i64 } %int16SliceSrc, 0 -+ %copy.n2 = call i64 @runtime.sliceCopy(ptr %int16SliceDst.buf, ptr %int16SliceSrc.buf, i64 %int16SliceSrc.len, i64 %int16SliceSrc.len, i64 2) - - ret void - } --- -2.41.0 - diff --git a/0008-Update-golang.org-x-tools-to-v0.12.0.patch b/0008-Update-golang.org-x-tools-to-v0.12.0.patch new file mode 100644 index 0000000..b85485b --- /dev/null +++ b/0008-Update-golang.org-x-tools-to-v0.12.0.patch @@ -0,0 +1,240 @@ +From b2e84ee62753b34c2323bcf520681faa82800095 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 28 Aug 2023 04:19:19 -0400 +Subject: [PATCH 8/8] Update golang.org/x/tools to v0.12.0 + +compiler: Handle nil array and struct constants + +This is necessary for tools 0.9.0, which started lifting those since +https://github.com/golang/tools/commit/71ea8f168c160da91116b4ddbd577a8fc95aa334 + +Signed-off-by: Elliott Sales de Andrade +--- + compiler/compiler.go | 10 +++++++ + compiler/testdata/basic.ll | 9 ------- + compiler/testdata/channel.ll | 3 --- + compiler/testdata/zeromap.ll | 52 +++++++----------------------------- + go.mod | 4 +-- + go.sum | 12 ++++----- + 6 files changed, 27 insertions(+), 63 deletions(-) + +diff --git a/compiler/compiler.go b/compiler/compiler.go +index 6dd43935..cb3a892a 100644 +--- a/compiler/compiler.go ++++ b/compiler/compiler.go +@@ -3005,6 +3005,11 @@ func (c *compilerContext) createConst(expr *ssa.Const, pos token.Pos) llvm.Value + panic("expected nil pointer constant") + } + return llvm.ConstPointerNull(c.getLLVMType(typ)) ++ case *types.Array: ++ if expr.Value != nil { ++ panic("expected nil array constant") ++ } ++ return llvm.ConstNull(c.getLLVMType(expr.Type())) + case *types.Slice: + if expr.Value != nil { + panic("expected nil slice constant") +@@ -3018,6 +3023,11 @@ func (c *compilerContext) createConst(expr *ssa.Const, pos token.Pos) llvm.Value + llvmLen, // cap + }, false) + return slice ++ case *types.Struct: ++ if expr.Value != nil { ++ panic("expected nil struct constant") ++ } ++ return llvm.ConstNull(c.getLLVMType(expr.Type())) + case *types.Map: + if !expr.IsNil() { + // I believe this is not allowed by the Go spec. +diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll +index 355ef1c4..55154762 100644 +--- a/compiler/testdata/basic.ll ++++ b/compiler/testdata/basic.ll +@@ -196,10 +196,6 @@ entry: + ; Function Attrs: nounwind + define hidden void @main.foo(ptr %context) unnamed_addr #2 { + entry: +- %complit = alloca %main.kv.0, align 8 +- %stackalloc = alloca i8, align 1 +- store %main.kv.0 zeroinitializer, ptr %complit, align 8 +- call void @runtime.trackPointer(ptr nonnull %complit, ptr nonnull %stackalloc, ptr undef) #3 + call void @"main.foo$1"(%main.kv.0 zeroinitializer, ptr undef) + ret void + } +@@ -207,11 +203,6 @@ entry: + ; Function Attrs: nounwind + define internal void @"main.foo$1"(%main.kv.0 %b, ptr %context) unnamed_addr #2 { + entry: +- %b1 = alloca %main.kv.0, align 8 +- %stackalloc = alloca i8, align 1 +- store %main.kv.0 zeroinitializer, ptr %b1, align 8 +- call void @runtime.trackPointer(ptr nonnull %b1, ptr nonnull %stackalloc, ptr undef) #3 +- store %main.kv.0 %b, ptr %b1, align 8 + ret void + } + +diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll +index 8ff64bd4..26d2933b 100644 +--- a/compiler/testdata/channel.ll ++++ b/compiler/testdata/channel.ll +@@ -57,10 +57,7 @@ declare i1 @runtime.chanRecv(ptr dereferenceable_or_null(32), ptr, ptr dereferen + ; Function Attrs: nounwind + define hidden void @main.chanZeroSend(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #2 { + entry: +- %complit = alloca {}, align 8 + %chan.blockedList = alloca %runtime.channelBlockedList, align 8 +- %stackalloc = alloca i8, align 1 +- call void @runtime.trackPointer(ptr nonnull %complit, ptr nonnull %stackalloc, ptr undef) #4 + call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) + call void @runtime.chanSend(ptr %ch, ptr null, ptr nonnull %chan.blockedList, ptr undef) #4 + call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) +diff --git a/compiler/testdata/zeromap.ll b/compiler/testdata/zeromap.ll +index 6a3d3132..08c5fc34 100644 +--- a/compiler/testdata/zeromap.ll ++++ b/compiler/testdata/zeromap.ll +@@ -21,14 +21,9 @@ define hidden i32 @main.testZeroGet(ptr dereferenceable_or_null(40) %m, i1 %s.b1 + entry: + %hashmap.key = alloca %main.hasPadding, align 8 + %hashmap.value = alloca i32, align 4 +- %s = alloca %main.hasPadding, align 8 + %0 = insertvalue %main.hasPadding zeroinitializer, i1 %s.b1, 0 + %1 = insertvalue %main.hasPadding %0, i32 %s.i, 1 + %2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2 +- %stackalloc = alloca i8, align 1 +- store %main.hasPadding zeroinitializer, ptr %s, align 8 +- call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #5 +- store %main.hasPadding %2, ptr %s, align 8 + call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) + call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key) + store %main.hasPadding %2, ptr %hashmap.key, align 8 +@@ -58,14 +53,9 @@ define hidden void @main.testZeroSet(ptr dereferenceable_or_null(40) %m, i1 %s.b + entry: + %hashmap.key = alloca %main.hasPadding, align 8 + %hashmap.value = alloca i32, align 4 +- %s = alloca %main.hasPadding, align 8 + %0 = insertvalue %main.hasPadding zeroinitializer, i1 %s.b1, 0 + %1 = insertvalue %main.hasPadding %0, i32 %s.i, 1 + %2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2 +- %stackalloc = alloca i8, align 1 +- store %main.hasPadding zeroinitializer, ptr %s, align 8 +- call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #5 +- store %main.hasPadding %2, ptr %s, align 8 + call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) + store i32 5, ptr %hashmap.value, align 4 + call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key) +@@ -87,24 +77,13 @@ define hidden i32 @main.testZeroArrayGet(ptr dereferenceable_or_null(40) %m, [2 + entry: + %hashmap.key = alloca [2 x %main.hasPadding], align 8 + %hashmap.value = alloca i32, align 4 +- %s1 = alloca [2 x %main.hasPadding], align 8 +- %stackalloc = alloca i8, align 1 +- store %main.hasPadding zeroinitializer, ptr %s1, align 8 +- %s1.repack2 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 +- store %main.hasPadding zeroinitializer, ptr %s1.repack2, align 4 +- call void @runtime.trackPointer(ptr nonnull %s1, ptr nonnull %stackalloc, ptr undef) #5 +- %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 +- store %main.hasPadding %s.elt, ptr %s1, align 8 +- %s1.repack3 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 +- %s.elt4 = extractvalue [2 x %main.hasPadding] %s, 1 +- store %main.hasPadding %s.elt4, ptr %s1.repack3, align 4 + call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) + call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key) +- %s.elt7 = extractvalue [2 x %main.hasPadding] %s, 0 +- store %main.hasPadding %s.elt7, ptr %hashmap.key, align 8 +- %hashmap.key.repack8 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 +- %s.elt9 = extractvalue [2 x %main.hasPadding] %s, 1 +- store %main.hasPadding %s.elt9, ptr %hashmap.key.repack8, align 4 ++ %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 ++ store %main.hasPadding %s.elt, ptr %hashmap.key, align 8 ++ %hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 ++ %s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1 ++ store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4 + %0 = getelementptr inbounds i8, ptr %hashmap.key, i32 1 + call void @runtime.memzero(ptr nonnull %0, i32 3, ptr undef) #5 + %1 = getelementptr inbounds i8, ptr %hashmap.key, i32 9 +@@ -125,25 +104,14 @@ define hidden void @main.testZeroArraySet(ptr dereferenceable_or_null(40) %m, [2 + entry: + %hashmap.key = alloca [2 x %main.hasPadding], align 8 + %hashmap.value = alloca i32, align 4 +- %s1 = alloca [2 x %main.hasPadding], align 8 +- %stackalloc = alloca i8, align 1 +- store %main.hasPadding zeroinitializer, ptr %s1, align 8 +- %s1.repack2 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 +- store %main.hasPadding zeroinitializer, ptr %s1.repack2, align 4 +- call void @runtime.trackPointer(ptr nonnull %s1, ptr nonnull %stackalloc, ptr undef) #5 +- %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 +- store %main.hasPadding %s.elt, ptr %s1, align 8 +- %s1.repack3 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 +- %s.elt4 = extractvalue [2 x %main.hasPadding] %s, 1 +- store %main.hasPadding %s.elt4, ptr %s1.repack3, align 4 + call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) + store i32 5, ptr %hashmap.value, align 4 + call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key) +- %s.elt7 = extractvalue [2 x %main.hasPadding] %s, 0 +- store %main.hasPadding %s.elt7, ptr %hashmap.key, align 8 +- %hashmap.key.repack8 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 +- %s.elt9 = extractvalue [2 x %main.hasPadding] %s, 1 +- store %main.hasPadding %s.elt9, ptr %hashmap.key.repack8, align 4 ++ %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 ++ store %main.hasPadding %s.elt, ptr %hashmap.key, align 8 ++ %hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 ++ %s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1 ++ store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4 + %0 = getelementptr inbounds i8, ptr %hashmap.key, i32 1 + call void @runtime.memzero(ptr nonnull %0, i32 3, ptr undef) #5 + %1 = getelementptr inbounds i8, ptr %hashmap.key, i32 9 +diff --git a/go.mod b/go.mod +index a6d051a8..001840f5 100644 +--- a/go.mod ++++ b/go.mod +@@ -15,8 +15,8 @@ require ( + github.com/mattn/go-tty v0.0.4 + github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 + go.bug.st/serial v1.6.0 +- golang.org/x/sys v0.4.0 +- golang.org/x/tools v0.5.1-0.20230114154351-e035d0c426c8 ++ golang.org/x/sys v0.11.0 ++ golang.org/x/tools v0.12.0 + gopkg.in/yaml.v2 v2.4.0 + tinygo.org/x/go-llvm v0.0.0-20221028183034-8341240c0b32 + ) +diff --git a/go.sum b/go.sum +index 0df04dcf..7f4eab33 100644 +--- a/go.sum ++++ b/go.sum +@@ -12,8 +12,6 @@ github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moA + github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= + github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= + github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +-github.com/deadprogram/go-serial v0.0.0-20230717164825-4529b3232919 h1:Hi7G1bCG70NwlyqGswJKEHoIi4hJVN1SsmfwZ+DQHtw= +-github.com/deadprogram/go-serial v0.0.0-20230717164825-4529b3232919/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= + github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= + github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= + github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= +@@ -50,7 +48,7 @@ github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9 + github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= + go.bug.st/serial v1.6.0 h1:mAbRGN4cKE2J5gMwsMHC2KQisdLRQssO9WSM+rbZJ8A= + go.bug.st/serial v1.6.0/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= +-golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= ++golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= + golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= + golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= + golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +@@ -58,10 +56,10 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w + golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= + golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= + golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +-golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +-golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +-golang.org/x/tools v0.5.1-0.20230114154351-e035d0c426c8 h1:LHoToPgySGSr2NcUHbjENAidHz38RkKaNmmntwn9TjI= +-golang.org/x/tools v0.5.1-0.20230114154351-e035d0c426c8/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= ++golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= ++golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= ++golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= ++golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +-- +2.41.0 + diff --git a/tinygo.spec b/tinygo.spec index ac6da7b..37f1bc1 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -92,6 +92,8 @@ Patch0005: 0005-Add-CPU-to-RISCV-targets.patch Patch0006: 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch # https://github.com/tinygo-org/tinygo/pull/3649 Patch0007: 0007-Update-types-in-cgo-tests-for-LLVM-16.patch +# https://github.com/tinygo-org/tinygo/pull/3883 +Patch0008: 0008-Update-golang.org-x-tools-to-v0.12.0.patch # Not supported upstream yet. ExcludeArch: ppc64le s390x From 1eb5a805d62f8755753e595f7126a3ce0dff59e8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 3 Sep 2023 04:10:56 -0400 Subject: [PATCH 55/78] Skip a broken test [skip changelog] --- ...oss-Linux-tests-where-qemu-is-broken.patch | 24 ++++++++++++++----- ...ional-packages-to-install-if-missing.patch | 2 +- ...le-elaborated-typedefs-from-libclang.patch | 2 +- 0005-Add-CPU-to-RISCV-targets.patch | 2 +- ...rgmemonly-attribute-change-in-LLVM16.patch | 2 +- ...pdate-types-in-cgo-tests-for-LLVM-16.patch | 2 +- ...Update-golang.org-x-tools-to-v0.12.0.patch | 2 +- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 7e060fe..ea03610 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,4 +1,4 @@ -From df546b002b1d2d38e71b8d2e2c0e8f2c419b16c1 Mon Sep 17 00:00:00 2001 +From a16a6a8b23c6aea87cd4823eb4fa990ae14be8e4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken @@ -10,11 +10,11 @@ The upstream issues will hopefully be fixed soon: Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) + main_test.go | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) diff --git a/main_test.go b/main_test.go -index ac204f0c..5407ce09 100644 +index ac204f0c..27344c27 100644 --- a/main_test.go +++ b/main_test.go @@ -264,6 +264,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { @@ -25,13 +25,25 @@ index ac204f0c..5407ce09 100644 + // https://gitlab.com/qemu-project/qemu/-/issues/447 + // https://gitlab.com/qemu-project/qemu/-/issues/690 + if runtime.GOARCH == "arm64" && (options.GOARCH == "386" || options.GOARCH == "arm") { -+ t.Skipf("qemu is broken for this host/target architecture combination") ++ t.Skip("qemu is broken for this host/target architecture combination") + } + // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -353,6 +360,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -342,6 +349,11 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c + t.Fatal(err) + } + ++ if runtime.GOARCH == "arm64" && options.GOARCH == "amd64" && name == "reflect.go" { ++ // https://github.com/tinygo-org/tinygo/issues/3888 ++ t.Skip("qemu is broken for this host/target architecture combination") ++ } ++ + // Build the test binary. + stdout := &bytes.Buffer{} + _, err = buildAndRun("./"+path, config, stdout, cmdArgs, environmentVars, time.Minute, func(cmd *exec.Cmd, result builder.BuildResult) error { +@@ -353,6 +365,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index 2ddc60a..0d0c89d 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,4 +1,4 @@ -From 118b4127ed490d74429759f4fb8bf5a38b528fba Mon Sep 17 00:00:00 2001 +From f6efc9878db72dc7464d753a026993bb076b5e3e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 Subject: [PATCH 3/8] Suggest optional packages to install if missing diff --git a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch index a73ee38..af744c2 100644 --- a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch +++ b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch @@ -1,4 +1,4 @@ -From 9c3e5f72d571027689dba37cceb2a592dfcfdb5c Mon Sep 17 00:00:00 2001 +From f14269bc0794bba67ead58aebe744427879d6247 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Apr 2023 04:55:27 -0400 Subject: [PATCH 4/8] cgo: Handle elaborated typedefs from libclang diff --git a/0005-Add-CPU-to-RISCV-targets.patch b/0005-Add-CPU-to-RISCV-targets.patch index ff05562..85b93bf 100644 --- a/0005-Add-CPU-to-RISCV-targets.patch +++ b/0005-Add-CPU-to-RISCV-targets.patch @@ -1,4 +1,4 @@ -From 18428dbfd276b19797cd1ec0ba36bd5d370c2477 Mon Sep 17 00:00:00 2001 +From b03f1289b1240cb743b20da13535d96bbb614736 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Apr 2023 05:51:10 -0400 Subject: [PATCH 5/8] Add CPU to RISCV targets diff --git a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch index 371ffb8..49ccf00 100644 --- a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch +++ b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch @@ -1,4 +1,4 @@ -From 541e5c4df0c603fb6149cd5e2607f73e8e4569cf Mon Sep 17 00:00:00 2001 +From 68ed5f52759df4d7677edb2c80e6c799377c43f6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 03:41:21 -0400 Subject: [PATCH 6/8] Handle argmemonly attribute change in LLVM16 diff --git a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch index 6ae5c1b..9dd825d 100644 --- a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch +++ b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch @@ -1,4 +1,4 @@ -From 0219753a4b88e2cf23b5991f97aca636a965c29f Mon Sep 17 00:00:00 2001 +From a1fa0b9b2704fefb4b38bf7e527535faf19ca63a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 15 Apr 2023 19:41:18 -0400 Subject: [PATCH 7/8] Update types in cgo tests for LLVM 16 diff --git a/0008-Update-golang.org-x-tools-to-v0.12.0.patch b/0008-Update-golang.org-x-tools-to-v0.12.0.patch index b85485b..a6e987e 100644 --- a/0008-Update-golang.org-x-tools-to-v0.12.0.patch +++ b/0008-Update-golang.org-x-tools-to-v0.12.0.patch @@ -1,4 +1,4 @@ -From b2e84ee62753b34c2323bcf520681faa82800095 Mon Sep 17 00:00:00 2001 +From 16e347a2be6dd0bce9f7b95c91dc08804df16105 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 28 Aug 2023 04:19:19 -0400 Subject: [PATCH 8/8] Update golang.org/x/tools to v0.12.0 From 81c66e60d6feb41e3f3ed5449a9e90a60b5e7325 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 25 Sep 2023 04:08:52 -0400 Subject: [PATCH 56/78] Remove release-specific sources This makes it difficult to build an srpm on a different release. --- tinygo.spec | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tinygo.spec b/tinygo.spec index 37f1bc1..eb8f377 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,15 +10,7 @@ Version: 0.29.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%if %{fedora} > 37 %global clang_llvm_version 16 -%else -%if %{fedora} > 36 -%global clang_llvm_version 15 -%else -%global clang_llvm_version 14 -%endif -%endif %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 %global compiler_rt_version %{clang_llvm_version}.0.0 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 From fa5e9eb9790d6d317b5e15bfd2ab28c42111bc7b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 25 Sep 2023 04:19:31 -0400 Subject: [PATCH 57/78] Update to latest version (#2240155) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 4 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 4 +- ...ional-packages-to-install-if-missing.patch | 4 +- ...le-elaborated-typedefs-from-libclang.patch | 42 --- 0005-Add-CPU-to-RISCV-targets.patch | 64 ----- ...rgmemonly-attribute-change-in-LLVM16.patch | 166 ------------ ...pdate-types-in-cgo-tests-for-LLVM-16.patch | 200 --------------- ...Update-golang.org-x-tools-to-v0.12.0.patch | 240 ------------------ sources | 2 +- tinygo.spec | 14 +- 11 files changed, 10 insertions(+), 731 deletions(-) delete mode 100644 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch delete mode 100644 0005-Add-CPU-to-RISCV-targets.patch delete mode 100644 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch delete mode 100644 0007-Update-types-in-cgo-tests-for-LLVM-16.patch delete mode 100644 0008-Update-golang.org-x-tools-to-v0.12.0.patch diff --git a/.gitignore b/.gitignore index 921b4da..afc1724 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ /mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz /tinygo-0.28.1.tar.gz /tinygo-0.29.0.tar.gz +/tinygo-0.30.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index bb80a41..70040f2 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 206888b5a100d9ff58008dad4fbb9a45b1265a6b Mon Sep 17 00:00:00 2001 +From ee856392109e39cf60e83022441c94adee205447 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/8] Skip WASI tests. +Subject: [PATCH 1/3] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index ea03610..5c12aca 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From a16a6a8b23c6aea87cd4823eb4fa990ae14be8e4 Mon Sep 17 00:00:00 2001 +From 1f60829a1fffdcbe268c1998a560fdeb6029407e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/3] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index 0d0c89d..95e0413 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From f6efc9878db72dc7464d753a026993bb076b5e3e Mon Sep 17 00:00:00 2001 +From 3f6a6f241ab37976f07e792986b5c47fdde20c8a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/8] Suggest optional packages to install if missing +Subject: [PATCH 3/3] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch b/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch deleted file mode 100644 index af744c2..0000000 --- a/0004-cgo-Handle-elaborated-typedefs-from-libclang.patch +++ /dev/null @@ -1,42 +0,0 @@ -From f14269bc0794bba67ead58aebe744427879d6247 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Wed, 12 Apr 2023 04:55:27 -0400 -Subject: [PATCH 4/8] cgo: Handle elaborated typedefs from libclang - -I don't have a reference for this change in LLVM 16, so I just handled -it the same way as other elaborated types. - -Signed-off-by: Elliott Sales de Andrade ---- - cgo/libclang.go | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/cgo/libclang.go b/cgo/libclang.go -index 27ac1b57..95eb554a 100644 ---- a/cgo/libclang.go -+++ b/cgo/libclang.go -@@ -653,6 +653,12 @@ func (p *cgoPackage) addErrorAt(position token.Position, msg string) { - func (f *cgoFile) makeDecayingASTType(typ C.CXType, pos token.Pos) ast.Expr { - // Strip typedefs, if any. - underlyingType := typ -+ if underlyingType.kind == C.CXType_Elaborated { -+ elaboratedType := C.clang_Type_getNamedType(typ) -+ if elaboratedType.kind == C.CXType_Typedef { -+ underlyingType = elaboratedType -+ } -+ } - if underlyingType.kind == C.CXType_Typedef { - c := C.tinygo_clang_getTypeDeclaration(typ) - underlyingType = C.tinygo_clang_getTypedefDeclUnderlyingType(c) -@@ -788,6 +794,8 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr { - return f.makeASTType(underlying, pos) - case C.CXType_Enum: - return f.makeASTType(underlying, pos) -+ case C.CXType_Typedef: -+ return f.makeASTType(underlying, pos) - default: - typeKindSpelling := getString(C.clang_getTypeKindSpelling(underlying.kind)) - f.addError(pos, fmt.Sprintf("unknown elaborated type (libclang type kind %s)", typeKindSpelling)) --- -2.41.0 - diff --git a/0005-Add-CPU-to-RISCV-targets.patch b/0005-Add-CPU-to-RISCV-targets.patch deleted file mode 100644 index 85b93bf..0000000 --- a/0005-Add-CPU-to-RISCV-targets.patch +++ /dev/null @@ -1,64 +0,0 @@ -From b03f1289b1240cb743b20da13535d96bbb614736 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Thu, 13 Apr 2023 05:51:10 -0400 -Subject: [PATCH 5/8] Add CPU to RISCV targets - -Signed-off-by: Elliott Sales de Andrade ---- - compileopts/target.go | 7 ++++++- - targets/riscv32.json | 1 + - targets/riscv64.json | 1 + - 3 files changed, 8 insertions(+), 1 deletion(-) - -diff --git a/compileopts/target.go b/compileopts/target.go -index f83464b2..1e3995bb 100644 ---- a/compileopts/target.go -+++ b/compileopts/target.go -@@ -14,6 +14,7 @@ import ( - "runtime" - "strings" - -+ "github.com/tinygo-org/tinygo/compiler/llvmutil" - "github.com/tinygo-org/tinygo/goenv" - ) - -@@ -134,7 +135,11 @@ func (spec *TargetSpec) loadFromGivenStr(str string) error { - return err - } - defer fp.Close() -- return spec.load(fp) -+ err = spec.load(fp) -+ if llvmutil.Major() < 16 && (str == "riscv32" || str == "riscv64") { -+ spec.CPU = "" -+ } -+ return err - } - - // resolveInherits loads inherited targets, recursively. -diff --git a/targets/riscv32.json b/targets/riscv32.json -index a2878089..f2be3eab 100644 ---- a/targets/riscv32.json -+++ b/targets/riscv32.json -@@ -1,6 +1,7 @@ - { - "inherits": ["riscv"], - "llvm-target": "riscv32-unknown-none", -+ "cpu": "generic-rv32", - "target-abi": "ilp32", - "build-tags": ["tinygo.riscv32"], - "scheduler": "tasks", -diff --git a/targets/riscv64.json b/targets/riscv64.json -index fc45c91c..8f44ce53 100644 ---- a/targets/riscv64.json -+++ b/targets/riscv64.json -@@ -1,6 +1,7 @@ - { - "inherits": ["riscv"], - "llvm-target": "riscv64-unknown-none", -+ "cpu": "generic-rv64", - "target-abi": "lp64", - "build-tags": ["tinygo.riscv64"], - "cflags": [ --- -2.41.0 - diff --git a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch b/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch deleted file mode 100644 index 49ccf00..0000000 --- a/0006-Handle-argmemonly-attribute-change-in-LLVM16.patch +++ /dev/null @@ -1,166 +0,0 @@ -From 68ed5f52759df4d7677edb2c80e6c799377c43f6 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 15 Apr 2023 03:41:21 -0400 -Subject: [PATCH 6/8] Handle argmemonly attribute change in LLVM16 - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/compiler_test.go | 22 +++++++++++++++------- - compiler/testdata/channel.ll | 6 +++--- - compiler/testdata/go1.21.ll | 16 ++++++++-------- - compiler/testdata/zeromap.ll | 6 +++--- - 4 files changed, 29 insertions(+), 21 deletions(-) - -diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index 92ce31b0..d6147b78 100644 ---- a/compiler/compiler_test.go -+++ b/compiler/compiler_test.go -@@ -4,11 +4,11 @@ import ( - "flag" - "go/types" - "os" -- "strconv" - "strings" - "testing" - - "github.com/tinygo-org/tinygo/compileopts" -+ "github.com/tinygo-org/tinygo/compiler/llvmutil" - "github.com/tinygo-org/tinygo/goenv" - "github.com/tinygo-org/tinygo/loader" - "tinygo.org/x/go-llvm" -@@ -154,12 +154,7 @@ func fuzzyEqualIR(s1, s2 string) bool { - // stripped out. - func filterIrrelevantIRLines(lines []string) []string { - var out []string -- llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) -- if err != nil { -- // Note: this should never happen and if it does, it will always happen -- // for a particular build because llvm.Version is a constant. -- panic(err) -- } -+ llvmVersion := llvmutil.Major() - for _, line := range lines { - line = strings.Split(line, ";")[0] // strip out comments/info - line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments -@@ -174,6 +169,19 @@ func filterIrrelevantIRLines(lines []string) []string { - // Right now test outputs are for LLVM 14 and higher. - continue - } -+ if llvmVersion < 16 { -+ if strings.HasSuffix(line, "memory(argmem: readwrite) }") { -+ line = strings.Replace(line, "{ ", "{ argmemonly ", 1) -+ line = strings.Replace(line, "memory(argmem: readwrite) ", "", 1) -+ } -+ if strings.HasSuffix(line, "memory(none)") { -+ line = strings.Replace( -+ line, -+ "speculatable willreturn memory(none)", -+ "readnone speculatable willreturn", -+ 1) -+ } -+ } - out = append(out, line) - } - return out -diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index 9749effc..8ff64bd4 100644 ---- a/compiler/testdata/channel.ll -+++ b/compiler/testdata/channel.ll -@@ -31,12 +31,12 @@ entry: - ret void - } - --; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn -+; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) - declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3 - - declare void @runtime.chanSend(ptr dereferenceable_or_null(32), ptr, ptr dereferenceable_or_null(24), ptr) #1 - --; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn -+; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) - declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3 - - ; Function Attrs: nounwind -@@ -113,5 +113,5 @@ declare { i32, i1 } @runtime.tryChanSelect(ptr, ptr, i32, i32, ptr) #1 - attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #1 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } --attributes #3 = { argmemonly nocallback nofree nosync nounwind willreturn } -+attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } - attributes #4 = { nounwind } -diff --git a/compiler/testdata/go1.21.ll b/compiler/testdata/go1.21.ll -index d65c75f4..c677298f 100644 ---- a/compiler/testdata/go1.21.ll -+++ b/compiler/testdata/go1.21.ll -@@ -138,7 +138,7 @@ entry: - ret void - } - --; Function Attrs: argmemonly nocallback nofree nounwind willreturn writeonly -+; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write) - declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) #3 - - ; Function Attrs: nounwind -@@ -156,24 +156,24 @@ entry: - - declare void @runtime.hashmapClear(ptr dereferenceable_or_null(40), ptr) #1 - --; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn -+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) - declare i32 @llvm.smin.i32(i32, i32) #4 - --; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn -+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) - declare i8 @llvm.umin.i8(i8, i8) #4 - --; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn -+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) - declare i32 @llvm.umin.i32(i32, i32) #4 - --; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn -+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) - declare i32 @llvm.smax.i32(i32, i32) #4 - --; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn -+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) - declare i32 @llvm.umax.i32(i32, i32) #4 - - attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #1 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } --attributes #3 = { argmemonly nocallback nofree nounwind willreturn writeonly } --attributes #4 = { nocallback nofree nosync nounwind readnone speculatable willreturn } -+attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) } -+attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } - attributes #5 = { nounwind } -diff --git a/compiler/testdata/zeromap.ll b/compiler/testdata/zeromap.ll -index 69932a1a..6a3d3132 100644 ---- a/compiler/testdata/zeromap.ll -+++ b/compiler/testdata/zeromap.ll -@@ -43,14 +43,14 @@ entry: - ret i32 %6 - } - --; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn -+; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) - declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #4 - - declare void @runtime.memzero(ptr, i32, ptr) #1 - - declare i1 @runtime.hashmapBinaryGet(ptr dereferenceable_or_null(40), ptr, ptr, i32, ptr) #1 - --; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn -+; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) - declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #4 - - ; Function Attrs: noinline nounwind -@@ -168,5 +168,5 @@ attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime - attributes #1 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } - attributes #3 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } --attributes #4 = { argmemonly nocallback nofree nosync nounwind willreturn } -+attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } - attributes #5 = { nounwind } --- -2.41.0 - diff --git a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch b/0007-Update-types-in-cgo-tests-for-LLVM-16.patch deleted file mode 100644 index 9dd825d..0000000 --- a/0007-Update-types-in-cgo-tests-for-LLVM-16.patch +++ /dev/null @@ -1,200 +0,0 @@ -From a1fa0b9b2704fefb4b38bf7e527535faf19ca63a Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 15 Apr 2023 19:41:18 -0400 -Subject: [PATCH 7/8] Update types in cgo tests for LLVM 16 - -Signed-off-by: Elliott Sales de Andrade ---- - cgo/cgo_test.go | 5 +++ - cgo/testdata/errors.out.go | 4 +-- - cgo/testdata/types.out.go | 70 ++++++++++++++++++-------------------- - 3 files changed, 41 insertions(+), 38 deletions(-) - -diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go -index a44dd8e1..81d03c5d 100644 ---- a/cgo/cgo_test.go -+++ b/cgo/cgo_test.go -@@ -15,6 +15,8 @@ import ( - "runtime" - "strings" - "testing" -+ -+ "github.com/tinygo-org/tinygo/compiler/llvmutil" - ) - - // Pass -update to go test to update the output of the test files. -@@ -107,6 +109,9 @@ func TestCGo(t *testing.T) { - - // Check whether the output is as expected. - if expected != actual { -+ if llvmutil.Major() < 16 && (name == "errors" || name == "types") { -+ return -+ } - // It is not. Test failed. - if *flagUpdate { - // Update the file with the expected data. -diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go -index 716fd771..b1646a2e 100644 ---- a/cgo/testdata/errors.out.go -+++ b/cgo/testdata/errors.out.go -@@ -51,10 +51,10 @@ type ( - C.longlong int64 - C.ulonglong uint64 - ) --type C._Ctype_struct___0 struct { -+type C.struct_point_t struct { - x C.int - y C.int - } --type C.point_t = C._Ctype_struct___0 -+type C.point_t = C.struct_point_t - - const C.SOME_CONST_3 = 1234 -diff --git a/cgo/testdata/types.out.go b/cgo/testdata/types.out.go -index bd7b3fc4..4e60715b 100644 ---- a/cgo/testdata/types.out.go -+++ b/cgo/testdata/types.out.go -@@ -38,11 +38,11 @@ type ( - C.ulonglong uint64 - ) - type C.myint = C.int --type C._Ctype_struct___0 struct { -+type C.struct_point2d_t struct { - x C.int - y C.int - } --type C.point2d_t = C._Ctype_struct___0 -+type C.point2d_t = C.struct_point2d_t - type C.struct_point3d struct { - x C.int - y C.int -@@ -55,21 +55,19 @@ type C.struct_type1 struct { - ___type C.int - } - type C.struct_type2 struct{ _type C.int } --type C._Ctype_union___1 struct{ i C.int } --type C.union1_t = C._Ctype_union___1 --type C._Ctype_union___2 struct{ $union uint64 } -+type C.union_union1_t struct{ i C.int } -+type C.union1_t = C.union_union1_t -+type C.union_union3_t struct{ $union uint64 } - --func (union *C._Ctype_union___2) unionfield_i() *C.int { -- return (*C.int)(unsafe.Pointer(&union.$union)) --} --func (union *C._Ctype_union___2) unionfield_d() *float64 { -+func (union *C.union_union3_t) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) } -+func (union *C.union_union3_t) unionfield_d() *float64 { - return (*float64)(unsafe.Pointer(&union.$union)) - } --func (union *C._Ctype_union___2) unionfield_s() *C.short { -+func (union *C.union_union3_t) unionfield_s() *C.short { - return (*C.short)(unsafe.Pointer(&union.$union)) - } - --type C.union3_t = C._Ctype_union___2 -+type C.union3_t = C.union_union3_t - type C.union_union2d struct{ $union [2]uint64 } - - func (union *C.union_union2d) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) } -@@ -78,50 +76,50 @@ func (union *C.union_union2d) unionfield_d() *[2]float64 { - } - - type C.union2d_t = C.union_union2d --type C._Ctype_union___3 struct{ arr [10]C.uchar } --type C.unionarray_t = C._Ctype_union___3 --type C._Ctype_union___5 struct{ $union [3]uint32 } -+type C.union_unionarray_t struct{ arr [10]C.uchar } -+type C.unionarray_t = C.union_unionarray_t -+type C.union_union (unnamed at testdata/types.go:54:2) struct{ $union [3]uint32 } - --func (union *C._Ctype_union___5) unionfield_area() *C.point2d_t { -+func (union *C.union_union (unnamed at testdata/types.go:54:2)) unionfield_area() *C.point2d_t { - return (*C.point2d_t)(unsafe.Pointer(&union.$union)) - } --func (union *C._Ctype_union___5) unionfield_solid() *C.point3d_t { -+func (union *C.union_union (unnamed at testdata/types.go:54:2)) unionfield_solid() *C.point3d_t { - return (*C.point3d_t)(unsafe.Pointer(&union.$union)) - } - --type C._Ctype_struct___4 struct { -+type C.struct_struct_nested_t struct { - begin C.point2d_t - end C.point2d_t - tag C.int - -- coord C._Ctype_union___5 -+ coord C.union_union (unnamed at testdata/types.go:54:2) - } --type C.struct_nested_t = C._Ctype_struct___4 --type C._Ctype_union___6 struct{ $union [2]uint64 } -+type C.struct_nested_t = C.struct_struct_nested_t -+type C.union_union_nested_t struct{ $union [2]uint64 } - --func (union *C._Ctype_union___6) unionfield_point() *C.point3d_t { -+func (union *C.union_union_nested_t) unionfield_point() *C.point3d_t { - return (*C.point3d_t)(unsafe.Pointer(&union.$union)) - } --func (union *C._Ctype_union___6) unionfield_array() *C.unionarray_t { -+func (union *C.union_union_nested_t) unionfield_array() *C.unionarray_t { - return (*C.unionarray_t)(unsafe.Pointer(&union.$union)) - } --func (union *C._Ctype_union___6) unionfield_thing() *C.union3_t { -+func (union *C.union_union_nested_t) unionfield_thing() *C.union3_t { - return (*C.union3_t)(unsafe.Pointer(&union.$union)) - } - --type C.union_nested_t = C._Ctype_union___6 -+type C.union_nested_t = C.union_union_nested_t - type C.enum_option = C.int - type C.option_t = C.enum_option --type C._Ctype_enum___7 = C.uint --type C.option2_t = C._Ctype_enum___7 --type C._Ctype_struct___8 struct { -+type C.enum_option2_t = C.uint -+type C.option2_t = C.enum_option2_t -+type C.struct_types_t struct { - f float32 - d float64 - ptr *C.int - } --type C.types_t = C._Ctype_struct___8 -+type C.types_t = C.struct_types_t - type C.myIntArray = [10]C.int --type C._Ctype_struct___9 struct { -+type C.struct_bitfield_t struct { - start C.uchar - __bitfield_1 C.uchar - -@@ -129,21 +127,21 @@ type C._Ctype_struct___9 struct { - e C.uchar - } - --func (s *C._Ctype_struct___9) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f } --func (s *C._Ctype_struct___9) set_bitfield_a(value C.uchar) { -+func (s *C.struct_bitfield_t) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f } -+func (s *C.struct_bitfield_t) set_bitfield_a(value C.uchar) { - s.__bitfield_1 = s.__bitfield_1&^0x1f | value&0x1f<<0 - } --func (s *C._Ctype_struct___9) bitfield_b() C.uchar { -+func (s *C.struct_bitfield_t) bitfield_b() C.uchar { - return s.__bitfield_1 >> 5 & 0x1 - } --func (s *C._Ctype_struct___9) set_bitfield_b(value C.uchar) { -+func (s *C.struct_bitfield_t) set_bitfield_b(value C.uchar) { - s.__bitfield_1 = s.__bitfield_1&^0x20 | value&0x1<<5 - } --func (s *C._Ctype_struct___9) bitfield_c() C.uchar { -+func (s *C.struct_bitfield_t) bitfield_c() C.uchar { - return s.__bitfield_1 >> 6 - } --func (s *C._Ctype_struct___9) set_bitfield_c(value C.uchar, -+func (s *C.struct_bitfield_t) set_bitfield_c(value C.uchar, - - ) { s.__bitfield_1 = s.__bitfield_1&0x3f | value<<6 } - --type C.bitfield_t = C._Ctype_struct___9 -+type C.bitfield_t = C.struct_bitfield_t --- -2.41.0 - diff --git a/0008-Update-golang.org-x-tools-to-v0.12.0.patch b/0008-Update-golang.org-x-tools-to-v0.12.0.patch deleted file mode 100644 index a6e987e..0000000 --- a/0008-Update-golang.org-x-tools-to-v0.12.0.patch +++ /dev/null @@ -1,240 +0,0 @@ -From 16e347a2be6dd0bce9f7b95c91dc08804df16105 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 28 Aug 2023 04:19:19 -0400 -Subject: [PATCH 8/8] Update golang.org/x/tools to v0.12.0 - -compiler: Handle nil array and struct constants - -This is necessary for tools 0.9.0, which started lifting those since -https://github.com/golang/tools/commit/71ea8f168c160da91116b4ddbd577a8fc95aa334 - -Signed-off-by: Elliott Sales de Andrade ---- - compiler/compiler.go | 10 +++++++ - compiler/testdata/basic.ll | 9 ------- - compiler/testdata/channel.ll | 3 --- - compiler/testdata/zeromap.ll | 52 +++++++----------------------------- - go.mod | 4 +-- - go.sum | 12 ++++----- - 6 files changed, 27 insertions(+), 63 deletions(-) - -diff --git a/compiler/compiler.go b/compiler/compiler.go -index 6dd43935..cb3a892a 100644 ---- a/compiler/compiler.go -+++ b/compiler/compiler.go -@@ -3005,6 +3005,11 @@ func (c *compilerContext) createConst(expr *ssa.Const, pos token.Pos) llvm.Value - panic("expected nil pointer constant") - } - return llvm.ConstPointerNull(c.getLLVMType(typ)) -+ case *types.Array: -+ if expr.Value != nil { -+ panic("expected nil array constant") -+ } -+ return llvm.ConstNull(c.getLLVMType(expr.Type())) - case *types.Slice: - if expr.Value != nil { - panic("expected nil slice constant") -@@ -3018,6 +3023,11 @@ func (c *compilerContext) createConst(expr *ssa.Const, pos token.Pos) llvm.Value - llvmLen, // cap - }, false) - return slice -+ case *types.Struct: -+ if expr.Value != nil { -+ panic("expected nil struct constant") -+ } -+ return llvm.ConstNull(c.getLLVMType(expr.Type())) - case *types.Map: - if !expr.IsNil() { - // I believe this is not allowed by the Go spec. -diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll -index 355ef1c4..55154762 100644 ---- a/compiler/testdata/basic.ll -+++ b/compiler/testdata/basic.ll -@@ -196,10 +196,6 @@ entry: - ; Function Attrs: nounwind - define hidden void @main.foo(ptr %context) unnamed_addr #2 { - entry: -- %complit = alloca %main.kv.0, align 8 -- %stackalloc = alloca i8, align 1 -- store %main.kv.0 zeroinitializer, ptr %complit, align 8 -- call void @runtime.trackPointer(ptr nonnull %complit, ptr nonnull %stackalloc, ptr undef) #3 - call void @"main.foo$1"(%main.kv.0 zeroinitializer, ptr undef) - ret void - } -@@ -207,11 +203,6 @@ entry: - ; Function Attrs: nounwind - define internal void @"main.foo$1"(%main.kv.0 %b, ptr %context) unnamed_addr #2 { - entry: -- %b1 = alloca %main.kv.0, align 8 -- %stackalloc = alloca i8, align 1 -- store %main.kv.0 zeroinitializer, ptr %b1, align 8 -- call void @runtime.trackPointer(ptr nonnull %b1, ptr nonnull %stackalloc, ptr undef) #3 -- store %main.kv.0 %b, ptr %b1, align 8 - ret void - } - -diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll -index 8ff64bd4..26d2933b 100644 ---- a/compiler/testdata/channel.ll -+++ b/compiler/testdata/channel.ll -@@ -57,10 +57,7 @@ declare i1 @runtime.chanRecv(ptr dereferenceable_or_null(32), ptr, ptr dereferen - ; Function Attrs: nounwind - define hidden void @main.chanZeroSend(ptr dereferenceable_or_null(32) %ch, ptr %context) unnamed_addr #2 { - entry: -- %complit = alloca {}, align 8 - %chan.blockedList = alloca %runtime.channelBlockedList, align 8 -- %stackalloc = alloca i8, align 1 -- call void @runtime.trackPointer(ptr nonnull %complit, ptr nonnull %stackalloc, ptr undef) #4 - call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %chan.blockedList) - call void @runtime.chanSend(ptr %ch, ptr null, ptr nonnull %chan.blockedList, ptr undef) #4 - call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %chan.blockedList) -diff --git a/compiler/testdata/zeromap.ll b/compiler/testdata/zeromap.ll -index 6a3d3132..08c5fc34 100644 ---- a/compiler/testdata/zeromap.ll -+++ b/compiler/testdata/zeromap.ll -@@ -21,14 +21,9 @@ define hidden i32 @main.testZeroGet(ptr dereferenceable_or_null(40) %m, i1 %s.b1 - entry: - %hashmap.key = alloca %main.hasPadding, align 8 - %hashmap.value = alloca i32, align 4 -- %s = alloca %main.hasPadding, align 8 - %0 = insertvalue %main.hasPadding zeroinitializer, i1 %s.b1, 0 - %1 = insertvalue %main.hasPadding %0, i32 %s.i, 1 - %2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2 -- %stackalloc = alloca i8, align 1 -- store %main.hasPadding zeroinitializer, ptr %s, align 8 -- call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #5 -- store %main.hasPadding %2, ptr %s, align 8 - call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) - call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key) - store %main.hasPadding %2, ptr %hashmap.key, align 8 -@@ -58,14 +53,9 @@ define hidden void @main.testZeroSet(ptr dereferenceable_or_null(40) %m, i1 %s.b - entry: - %hashmap.key = alloca %main.hasPadding, align 8 - %hashmap.value = alloca i32, align 4 -- %s = alloca %main.hasPadding, align 8 - %0 = insertvalue %main.hasPadding zeroinitializer, i1 %s.b1, 0 - %1 = insertvalue %main.hasPadding %0, i32 %s.i, 1 - %2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2 -- %stackalloc = alloca i8, align 1 -- store %main.hasPadding zeroinitializer, ptr %s, align 8 -- call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #5 -- store %main.hasPadding %2, ptr %s, align 8 - call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) - store i32 5, ptr %hashmap.value, align 4 - call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key) -@@ -87,24 +77,13 @@ define hidden i32 @main.testZeroArrayGet(ptr dereferenceable_or_null(40) %m, [2 - entry: - %hashmap.key = alloca [2 x %main.hasPadding], align 8 - %hashmap.value = alloca i32, align 4 -- %s1 = alloca [2 x %main.hasPadding], align 8 -- %stackalloc = alloca i8, align 1 -- store %main.hasPadding zeroinitializer, ptr %s1, align 8 -- %s1.repack2 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 -- store %main.hasPadding zeroinitializer, ptr %s1.repack2, align 4 -- call void @runtime.trackPointer(ptr nonnull %s1, ptr nonnull %stackalloc, ptr undef) #5 -- %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 -- store %main.hasPadding %s.elt, ptr %s1, align 8 -- %s1.repack3 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 -- %s.elt4 = extractvalue [2 x %main.hasPadding] %s, 1 -- store %main.hasPadding %s.elt4, ptr %s1.repack3, align 4 - call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) - call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key) -- %s.elt7 = extractvalue [2 x %main.hasPadding] %s, 0 -- store %main.hasPadding %s.elt7, ptr %hashmap.key, align 8 -- %hashmap.key.repack8 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 -- %s.elt9 = extractvalue [2 x %main.hasPadding] %s, 1 -- store %main.hasPadding %s.elt9, ptr %hashmap.key.repack8, align 4 -+ %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 -+ store %main.hasPadding %s.elt, ptr %hashmap.key, align 8 -+ %hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 -+ %s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1 -+ store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4 - %0 = getelementptr inbounds i8, ptr %hashmap.key, i32 1 - call void @runtime.memzero(ptr nonnull %0, i32 3, ptr undef) #5 - %1 = getelementptr inbounds i8, ptr %hashmap.key, i32 9 -@@ -125,25 +104,14 @@ define hidden void @main.testZeroArraySet(ptr dereferenceable_or_null(40) %m, [2 - entry: - %hashmap.key = alloca [2 x %main.hasPadding], align 8 - %hashmap.value = alloca i32, align 4 -- %s1 = alloca [2 x %main.hasPadding], align 8 -- %stackalloc = alloca i8, align 1 -- store %main.hasPadding zeroinitializer, ptr %s1, align 8 -- %s1.repack2 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 -- store %main.hasPadding zeroinitializer, ptr %s1.repack2, align 4 -- call void @runtime.trackPointer(ptr nonnull %s1, ptr nonnull %stackalloc, ptr undef) #5 -- %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 -- store %main.hasPadding %s.elt, ptr %s1, align 8 -- %s1.repack3 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1 -- %s.elt4 = extractvalue [2 x %main.hasPadding] %s, 1 -- store %main.hasPadding %s.elt4, ptr %s1.repack3, align 4 - call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) - store i32 5, ptr %hashmap.value, align 4 - call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key) -- %s.elt7 = extractvalue [2 x %main.hasPadding] %s, 0 -- store %main.hasPadding %s.elt7, ptr %hashmap.key, align 8 -- %hashmap.key.repack8 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 -- %s.elt9 = extractvalue [2 x %main.hasPadding] %s, 1 -- store %main.hasPadding %s.elt9, ptr %hashmap.key.repack8, align 4 -+ %s.elt = extractvalue [2 x %main.hasPadding] %s, 0 -+ store %main.hasPadding %s.elt, ptr %hashmap.key, align 8 -+ %hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 -+ %s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1 -+ store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4 - %0 = getelementptr inbounds i8, ptr %hashmap.key, i32 1 - call void @runtime.memzero(ptr nonnull %0, i32 3, ptr undef) #5 - %1 = getelementptr inbounds i8, ptr %hashmap.key, i32 9 -diff --git a/go.mod b/go.mod -index a6d051a8..001840f5 100644 ---- a/go.mod -+++ b/go.mod -@@ -15,8 +15,8 @@ require ( - github.com/mattn/go-tty v0.0.4 - github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 - go.bug.st/serial v1.6.0 -- golang.org/x/sys v0.4.0 -- golang.org/x/tools v0.5.1-0.20230114154351-e035d0c426c8 -+ golang.org/x/sys v0.11.0 -+ golang.org/x/tools v0.12.0 - gopkg.in/yaml.v2 v2.4.0 - tinygo.org/x/go-llvm v0.0.0-20221028183034-8341240c0b32 - ) -diff --git a/go.sum b/go.sum -index 0df04dcf..7f4eab33 100644 ---- a/go.sum -+++ b/go.sum -@@ -12,8 +12,6 @@ github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moA - github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= - github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= - github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= --github.com/deadprogram/go-serial v0.0.0-20230717164825-4529b3232919 h1:Hi7G1bCG70NwlyqGswJKEHoIi4hJVN1SsmfwZ+DQHtw= --github.com/deadprogram/go-serial v0.0.0-20230717164825-4529b3232919/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= - github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= - github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= - github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= -@@ -50,7 +48,7 @@ github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9 - github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= - go.bug.st/serial v1.6.0 h1:mAbRGN4cKE2J5gMwsMHC2KQisdLRQssO9WSM+rbZJ8A= - go.bug.st/serial v1.6.0/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= --golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= -+golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= - golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= - golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= - golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -@@ -58,10 +56,10 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w - golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= - golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= - golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= --golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= --golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= --golang.org/x/tools v0.5.1-0.20230114154351-e035d0c426c8 h1:LHoToPgySGSr2NcUHbjENAidHz38RkKaNmmntwn9TjI= --golang.org/x/tools v0.5.1-0.20230114154351-e035d0c426c8/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= -+golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -+golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -+golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= -+golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= - gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= - gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= --- -2.41.0 - diff --git a/sources b/sources index cf6d535..80e2c95 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.29.0.tar.gz) = 90f2ffd7aedeae7e47acda696d49d352d38a00db5cf7db6cf01c9fcaba8075a461604ce39e58f965e1165d3d0da334be04989dc7811322212bb0ec0bce718168 +SHA512 (tinygo-0.30.0.tar.gz) = 91c4b6a578d5730e6915d48c69f567b814d5d1201150df053f116b78be5c29553f2fa8bf05f4565ffb7d1acabc58819a1f0ef2beea9830c4cb99d69116ac4fee SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 diff --git a/tinygo.spec b/tinygo.spec index eb8f377..d13baeb 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,7 +6,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.29.0 +Version: 0.30.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -77,16 +77,6 @@ Patch0002: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch -# Support LLVM 16. -# https://github.com/tinygo-org/tinygo/pull/3649 -Patch0004: 0004-cgo-Handle-elaborated-typedefs-from-libclang.patch -Patch0005: 0005-Add-CPU-to-RISCV-targets.patch -Patch0006: 0006-Handle-argmemonly-attribute-change-in-LLVM16.patch -# https://github.com/tinygo-org/tinygo/pull/3649 -Patch0007: 0007-Update-types-in-cgo-tests-for-LLVM-16.patch -# https://github.com/tinygo-org/tinygo/pull/3883 -Patch0008: 0008-Update-golang.org-x-tools-to-v0.12.0.patch - # Not supported upstream yet. ExcludeArch: ppc64le s390x # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval @@ -107,7 +97,7 @@ BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 BuildRequires: golang(github.com/sigurn/crc16) BuildRequires: golang(go.bug.st/serial) >= 1.6.0 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) -BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.1.11 +BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.12 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: golang-tests From 000c23720d0332c073ce13d1102bde26875dc812 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 25 Sep 2023 04:23:42 -0400 Subject: [PATCH 58/78] Backport support for LLVM17 --- 0001-Skip-WASI-tests.patch | 2 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 2 +- ...ional-packages-to-install-if-missing.patch | 2 +- ...g-in-StringToBytes-optimization-pass.patch | 121 +++++ 0005-all-use-the-new-LLVM-pass-manager.patch | 424 ++++++++++++++++++ ...e-large-parts-of-picolibc-math-stdio.patch | 222 +++++++++ 0007-all-add-initial-LLVM-17-support.patch | 157 +++++++ tinygo.spec | 13 +- 8 files changed, 938 insertions(+), 5 deletions(-) create mode 100644 0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch create mode 100644 0005-all-use-the-new-LLVM-pass-manager.patch create mode 100644 0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch create mode 100644 0007-all-add-initial-LLVM-17-support.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 70040f2..63bc8d7 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ From ee856392109e39cf60e83022441c94adee205447 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/3] Skip WASI tests. +Subject: [PATCH 1/7] Skip WASI tests. We do not have wasmtime available. diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 5c12aca..79deaa6 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ From 1f60829a1fffdcbe268c1998a560fdeb6029407e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/3] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/7] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index 95e0413..c09cc88 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ From 3f6a6f241ab37976f07e792986b5c47fdde20c8a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/3] Suggest optional packages to install if missing +Subject: [PATCH 3/7] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch b/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch new file mode 100644 index 0000000..b0c42ec --- /dev/null +++ b/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch @@ -0,0 +1,121 @@ +From bf51015656ff3b1bbe6b41ea1155610178c2961d Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 21 Sep 2023 15:39:06 +0200 +Subject: [PATCH 4/7] transform: fix bug in StringToBytes optimization pass + +Previously, this pass would convert any read-only use of a +runtime.stringToBytes call to use the original string buffer instead. +This is incorrect: if there are any writes to the resulting buffer, none +of the slice buffer pointers can be converted to use the original +read-only string buffer. + +This commit fixes that bug and adds a test to prove the new (correct) +behavior. + +Signed-off-by: Elliott Sales de Andrade +--- + transform/rtcalls.go | 24 ++++++++++++++++++------ + transform/testdata/stringtobytes.ll | 16 ++++++++++++++++ + transform/testdata/stringtobytes.out.ll | 10 ++++++++++ + 3 files changed, 44 insertions(+), 6 deletions(-) + +diff --git a/transform/rtcalls.go b/transform/rtcalls.go +index 36d2853b..0b6feff2 100644 +--- a/transform/rtcalls.go ++++ b/transform/rtcalls.go +@@ -28,32 +28,44 @@ func OptimizeStringToBytes(mod llvm.Module) { + + // strptr is always constant because strings are always constant. + +- convertedAllUses := true ++ var pointerUses []llvm.Value ++ canConvertPointer := true + for _, use := range getUses(call) { + if use.IsAExtractValueInst().IsNil() { + // Expected an extractvalue, but this is something else. +- convertedAllUses = false ++ canConvertPointer = false + continue + } + switch use.Type().TypeKind() { + case llvm.IntegerTypeKind: + // A length (len or cap). Propagate the length value. ++ // This can always be done because the byte slice is always the ++ // same length as the original string. + use.ReplaceAllUsesWith(strlen) + use.EraseFromParentAsInstruction() + case llvm.PointerTypeKind: + // The string pointer itself. + if !isReadOnly(use) { +- convertedAllUses = false ++ // There is a store to the byte slice. This means that none ++ // of the pointer uses can't be propagated. ++ canConvertPointer = false + continue + } +- use.ReplaceAllUsesWith(strptr) +- use.EraseFromParentAsInstruction() ++ // It may be that the pointer value can be propagated, if all of ++ // the pointer uses are readonly. ++ pointerUses = append(pointerUses, use) + default: + // should not happen + panic("unknown return type of runtime.stringToBytes: " + use.Type().String()) + } + } +- if convertedAllUses { ++ if canConvertPointer { ++ // All pointer uses are readonly, so they can be converted. ++ for _, use := range pointerUses { ++ use.ReplaceAllUsesWith(strptr) ++ use.EraseFromParentAsInstruction() ++ } ++ + // Call to runtime.stringToBytes can be eliminated: both the input + // and the output is constant. + call.EraseFromParentAsInstruction() +diff --git a/transform/testdata/stringtobytes.ll b/transform/testdata/stringtobytes.ll +index fa43f3d0..06373a51 100644 +--- a/transform/testdata/stringtobytes.ll ++++ b/transform/testdata/stringtobytes.ll +@@ -30,3 +30,19 @@ entry: + call fastcc void @writeToSlice(ptr %1, i64 %2, i64 %3) + ret void + } ++ ++; Test that pointer values are never propagated if there is even a single write ++; to the pointer value (but len/cap values still can be). ++define void @testReadSome() { ++entry: ++ %s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) ++ %s.ptr = extractvalue { ptr, i64, i64 } %s, 0 ++ %s.len = extractvalue { ptr, i64, i64 } %s, 1 ++ %s.cap = extractvalue { ptr, i64, i64 } %s, 2 ++ call fastcc void @writeToSlice(ptr %s.ptr, i64 %s.len, i64 %s.cap) ++ %s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0 ++ %s.len2 = extractvalue { ptr, i64, i64 } %s, 1 ++ %s.cap2 = extractvalue { ptr, i64, i64 } %s, 2 ++ call fastcc void @printSlice(ptr %s.ptr2, i64 %s.len2, i64 %s.cap2) ++ ret void ++} +diff --git a/transform/testdata/stringtobytes.out.ll b/transform/testdata/stringtobytes.out.ll +index 30aa520a..b33a1755 100644 +--- a/transform/testdata/stringtobytes.out.ll ++++ b/transform/testdata/stringtobytes.out.ll +@@ -22,3 +22,13 @@ entry: + call fastcc void @writeToSlice(ptr %1, i64 6, i64 6) + ret void + } ++ ++define void @testReadSome() { ++entry: ++ %s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) ++ %s.ptr = extractvalue { ptr, i64, i64 } %s, 0 ++ call fastcc void @writeToSlice(ptr %s.ptr, i64 6, i64 6) ++ %s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0 ++ call fastcc void @printSlice(ptr %s.ptr2, i64 6, i64 6) ++ ret void ++} +-- +2.41.0 + diff --git a/0005-all-use-the-new-LLVM-pass-manager.patch b/0005-all-use-the-new-LLVM-pass-manager.patch new file mode 100644 index 0000000..84eadf2 --- /dev/null +++ b/0005-all-use-the-new-LLVM-pass-manager.patch @@ -0,0 +1,424 @@ +From 3dcb55f940011bb9bcb75d98182290da60642e4d Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Tue, 19 Sep 2023 22:37:44 +0200 +Subject: [PATCH 5/7] all: use the new LLVM pass manager + +The old LLVM pass manager is deprecated and should not be used anymore. +Moreover, the pass manager builder (which we used to set up a pass +pipeline) is actually removed from LLVM entirely in LLVM 17: +https://reviews.llvm.org/D145387 +https://reviews.llvm.org/D145835 + +The new pass manager does change the binary size in many cases: both +growing and shrinking it. However, on average the binary size remains +more or less the same. + +This is needed as a preparation for LLVM 17. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/build.go | 19 +++-- + builder/sizes_test.go | 6 +- + compileopts/config.go | 12 ++-- + compiler/compiler_test.go | 12 ++-- + interp/interp_test.go | 9 +-- + transform/allocs_test.go | 11 +-- + transform/interface-lowering_test.go | 10 +-- + transform/maps_test.go | 11 +-- + transform/optimizer.go | 102 +++++++++------------------ + transform/transform.go | 2 +- + 10 files changed, 76 insertions(+), 118 deletions(-) + +diff --git a/builder/build.go b/builder/build.go +index dc360b92..d920a598 100644 +--- a/builder/build.go ++++ b/builder/build.go +@@ -83,8 +83,7 @@ type packageAction struct { + FileHashes map[string]string // hash of every file that's part of the package + EmbeddedFiles map[string]string // hash of all the //go:embed files in the package + Imports map[string]string // map from imported package to action ID hash +- OptLevel int // LLVM optimization level (0-3) +- SizeLevel int // LLVM optimization for size level (0-2) ++ OptLevel string // LLVM optimization level (O0, O1, O2, Os, Oz) + UndefinedGlobals []string // globals that are left as external globals (no initializer) + } + +@@ -158,7 +157,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe + return BuildResult{}, fmt.Errorf("unknown libc: %s", config.Target.Libc) + } + +- optLevel, sizeLevel, _ := config.OptLevels() ++ optLevel, speedLevel, sizeLevel := config.OptLevel() + compilerConfig := &compiler.Config{ + Triple: config.Triple(), + CPU: config.CPU(), +@@ -321,7 +320,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe + EmbeddedFiles: make(map[string]string, len(allFiles)), + Imports: make(map[string]string, len(pkg.Pkg.Imports())), + OptLevel: optLevel, +- SizeLevel: sizeLevel, + UndefinedGlobals: undefinedGlobals, + } + for filePath, hash := range pkg.FileHashes { +@@ -743,17 +741,17 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe + if config.GOOS() == "windows" { + // Options for the MinGW wrapper for the lld COFF linker. + ldflags = append(ldflags, +- "-Xlink=/opt:lldlto="+strconv.Itoa(optLevel), ++ "-Xlink=/opt:lldlto="+strconv.Itoa(speedLevel), + "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto")) + } else if config.GOOS() == "darwin" { + // Options for the ld64-compatible lld linker. + ldflags = append(ldflags, +- "--lto-O"+strconv.Itoa(optLevel), ++ "--lto-O"+strconv.Itoa(speedLevel), + "-cache_path_lto", filepath.Join(cacheDir, "thinlto")) + } else { + // Options for the ELF linker. + ldflags = append(ldflags, +- "--lto-O"+strconv.Itoa(optLevel), ++ "--lto-O"+strconv.Itoa(speedLevel), + "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"), + ) + } +@@ -1066,10 +1064,9 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error { + return err + } + +- // Optimization levels here are roughly the same as Clang, but probably not +- // exactly. +- optLevel, sizeLevel, inlinerThreshold := config.OptLevels() +- errs := transform.Optimize(mod, config, optLevel, sizeLevel, inlinerThreshold) ++ // Run most of the whole-program optimizations (including the whole ++ // O0/O1/O2/Os/Oz optimization pipeline). ++ errs := transform.Optimize(mod, config) + if len(errs) > 0 { + return newMultiError(errs) + } +diff --git a/builder/sizes_test.go b/builder/sizes_test.go +index 7aaab78a..dc45898e 100644 +--- a/builder/sizes_test.go ++++ b/builder/sizes_test.go +@@ -41,9 +41,9 @@ func TestBinarySize(t *testing.T) { + // This is a small number of very diverse targets that we want to test. + tests := []sizeTest{ + // microcontrollers +- {"hifive1b", "examples/echo", 4568, 280, 0, 2252}, +- {"microbit", "examples/serial", 2728, 388, 8, 2256}, +- {"wioterminal", "examples/pininterrupt", 5996, 1484, 116, 6816}, ++ {"hifive1b", "examples/echo", 4484, 280, 0, 2252}, ++ {"microbit", "examples/serial", 2724, 388, 8, 2256}, ++ {"wioterminal", "examples/pininterrupt", 6000, 1484, 116, 6816}, + + // TODO: also check wasm. Right now this is difficult, because + // wasm binaries are run through wasm-opt and therefore the +diff --git a/compileopts/config.go b/compileopts/config.go +index 39fc4f2a..5ad45c60 100644 +--- a/compileopts/config.go ++++ b/compileopts/config.go +@@ -145,18 +145,18 @@ func (c *Config) Serial() string { + + // OptLevels returns the optimization level (0-2), size level (0-2), and inliner + // threshold as used in the LLVM optimization pipeline. +-func (c *Config) OptLevels() (optLevel, sizeLevel int, inlinerThreshold uint) { ++func (c *Config) OptLevel() (level string, speedLevel, sizeLevel int) { + switch c.Options.Opt { + case "none", "0": +- return 0, 0, 0 // -O0 ++ return "O0", 0, 0 + case "1": +- return 1, 0, 0 // -O1 ++ return "O1", 1, 0 + case "2": +- return 2, 0, 225 // -O2 ++ return "O2", 2, 0 + case "s": +- return 2, 1, 225 // -Os ++ return "Os", 2, 1 + case "z": +- return 2, 2, 5 // -Oz, default ++ return "Oz", 2, 2 // default + default: + // This is not shown to the user: valid choices are already checked as + // part of Options.Verify(). It is here as a sanity check. +diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go +index 92ce31b0..147e622a 100644 +--- a/compiler/compiler_test.go ++++ b/compiler/compiler_test.go +@@ -91,14 +91,12 @@ func TestCompiler(t *testing.T) { + } + + // Optimize IR a little. +- funcPasses := llvm.NewFunctionPassManagerForModule(mod) +- defer funcPasses.Dispose() +- funcPasses.AddInstructionCombiningPass() +- funcPasses.InitializeFunc() +- for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { +- funcPasses.RunFunc(fn) ++ passOptions := llvm.NewPassBuilderOptions() ++ defer passOptions.Dispose() ++ err = mod.RunPasses("instcombine", llvm.TargetMachine{}, passOptions) ++ if err != nil { ++ t.Error(err) + } +- funcPasses.FinalizeFunc() + + outFilePrefix := tc.file[:len(tc.file)-3] + if tc.target != "" { +diff --git a/interp/interp_test.go b/interp/interp_test.go +index fc567af2..cac56508 100644 +--- a/interp/interp_test.go ++++ b/interp/interp_test.go +@@ -77,12 +77,9 @@ func runTest(t *testing.T, pathPrefix string) { + } + + // Run some cleanup passes to get easy-to-read outputs. +- pm := llvm.NewPassManager() +- defer pm.Dispose() +- pm.AddGlobalOptimizerPass() +- pm.AddDeadStoreEliminationPass() +- pm.AddAggressiveDCEPass() +- pm.Run(mod) ++ to := llvm.NewPassBuilderOptions() ++ defer to.Dispose() ++ mod.RunPasses("globalopt,dse,adce", llvm.TargetMachine{}, to) + + // Read the expected output IR. + out, err := os.ReadFile(pathPrefix + ".out.ll") +diff --git a/transform/allocs_test.go b/transform/allocs_test.go +index 27bb9706..59a5b14e 100644 +--- a/transform/allocs_test.go ++++ b/transform/allocs_test.go +@@ -38,11 +38,12 @@ func TestAllocs2(t *testing.T) { + mod := compileGoFileForTesting(t, "./testdata/allocs2.go") + + // Run functionattrs pass, which is necessary for escape analysis. +- pm := llvm.NewPassManager() +- defer pm.Dispose() +- pm.AddInstructionCombiningPass() +- pm.AddFunctionAttrsPass() +- pm.Run(mod) ++ po := llvm.NewPassBuilderOptions() ++ defer po.Dispose() ++ err := mod.RunPasses("function(instcombine),function-attrs", llvm.TargetMachine{}, po) ++ if err != nil { ++ t.Error("failed to run passes:", err) ++ } + + // Run heap to stack transform. + var testOutputs []allocsTestOutput +diff --git a/transform/interface-lowering_test.go b/transform/interface-lowering_test.go +index 7bcce605..65f14dd9 100644 +--- a/transform/interface-lowering_test.go ++++ b/transform/interface-lowering_test.go +@@ -15,9 +15,11 @@ func TestInterfaceLowering(t *testing.T) { + t.Error(err) + } + +- pm := llvm.NewPassManager() +- defer pm.Dispose() +- pm.AddGlobalDCEPass() +- pm.Run(mod) ++ po := llvm.NewPassBuilderOptions() ++ defer po.Dispose() ++ err = mod.RunPasses("globaldce", llvm.TargetMachine{}, po) ++ if err != nil { ++ t.Error("failed to run passes:", err) ++ } + }) + } +diff --git a/transform/maps_test.go b/transform/maps_test.go +index e8b11133..329de698 100644 +--- a/transform/maps_test.go ++++ b/transform/maps_test.go +@@ -15,10 +15,11 @@ func TestOptimizeMaps(t *testing.T) { + + // Run an optimization pass, to clean up the result. + // This shows that all code related to the map is really eliminated. +- pm := llvm.NewPassManager() +- defer pm.Dispose() +- pm.AddDeadStoreEliminationPass() +- pm.AddAggressiveDCEPass() +- pm.Run(mod) ++ po := llvm.NewPassBuilderOptions() ++ defer po.Dispose() ++ err := mod.RunPasses("dse,adce", llvm.TargetMachine{}, po) ++ if err != nil { ++ t.Error("failed to run passes:", err) ++ } + }) + } +diff --git a/transform/optimizer.go b/transform/optimizer.go +index 20258ef4..42acc2dd 100644 +--- a/transform/optimizer.go ++++ b/transform/optimizer.go +@@ -14,54 +14,22 @@ import ( + // OptimizePackage runs optimization passes over the LLVM module for the given + // Go package. + func OptimizePackage(mod llvm.Module, config *compileopts.Config) { +- optLevel, sizeLevel, _ := config.OptLevels() +- +- // Run function passes for each function in the module. +- // These passes are intended to be run on each function right +- // after they're created to reduce IR size (and maybe also for +- // cache locality to improve performance), but for now they're +- // run here for each function in turn. Maybe this can be +- // improved in the future. +- builder := llvm.NewPassManagerBuilder() +- defer builder.Dispose() +- builder.SetOptLevel(optLevel) +- builder.SetSizeLevel(sizeLevel) +- funcPasses := llvm.NewFunctionPassManagerForModule(mod) +- defer funcPasses.Dispose() +- builder.PopulateFunc(funcPasses) +- funcPasses.InitializeFunc() +- for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { +- if fn.IsDeclaration() { +- continue +- } +- funcPasses.RunFunc(fn) +- } +- funcPasses.FinalizeFunc() ++ _, speedLevel, _ := config.OptLevel() + + // Run TinyGo-specific optimization passes. +- if optLevel > 0 { ++ if speedLevel > 0 { + OptimizeMaps(mod) + } + } + + // Optimize runs a number of optimization and transformation passes over the + // given module. Some passes are specific to TinyGo, others are generic LLVM +-// passes. You can set a preferred performance (0-3) and size (0-2) level and +-// control the limits of the inliner (higher numbers mean more inlining, set it +-// to 0 to disable entirely). ++// passes. + // + // Please note that some optimizations are not optional, thus Optimize must +-// alwasy be run before emitting machine code. Set all controls (optLevel, +-// sizeLevel, inlinerThreshold) to 0 to reduce the number of optimizations to a +-// minimum. +-func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel int, inlinerThreshold uint) []error { +- builder := llvm.NewPassManagerBuilder() +- defer builder.Dispose() +- builder.SetOptLevel(optLevel) +- builder.SetSizeLevel(sizeLevel) +- if inlinerThreshold != 0 { +- builder.UseInlinerWithThreshold(inlinerThreshold) +- } ++// alwasy be run before emitting machine code. ++func Optimize(mod llvm.Module, config *compileopts.Config) []error { ++ optLevel, speedLevel, _ := config.OptLevel() + + // Make sure these functions are kept in tact during TinyGo transformation passes. + for _, name := range functionsUsedInTransforms { +@@ -84,23 +52,20 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i + } + } + +- if optLevel > 0 { ++ if speedLevel > 0 { + // Run some preparatory passes for the Go optimizer. +- goPasses := llvm.NewPassManager() +- defer goPasses.Dispose() +- goPasses.AddGlobalDCEPass() +- goPasses.AddGlobalOptimizerPass() +- goPasses.AddIPSCCPPass() +- goPasses.AddInstructionCombiningPass() // necessary for OptimizeReflectImplements +- goPasses.AddAggressiveDCEPass() +- goPasses.AddFunctionAttrsPass() +- goPasses.Run(mod) ++ po := llvm.NewPassBuilderOptions() ++ defer po.Dispose() ++ err := mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po) ++ if err != nil { ++ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} ++ } + + // Run TinyGo-specific optimization passes. + OptimizeStringToBytes(mod) + OptimizeReflectImplements(mod) + OptimizeAllocs(mod, nil, nil) +- err := LowerInterfaces(mod, config) ++ err = LowerInterfaces(mod, config) + if err != nil { + return []error{err} + } +@@ -113,7 +78,10 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i + // After interfaces are lowered, there are many more opportunities for + // interprocedural optimizations. To get them to work, function + // attributes have to be updated first. +- goPasses.Run(mod) ++ err = mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po) ++ if err != nil { ++ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} ++ } + + // Run TinyGo-specific interprocedural optimizations. + OptimizeAllocs(mod, config.Options.PrintAllocs, func(pos token.Position, msg string) { +@@ -134,10 +102,12 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i + } + + // Clean up some leftover symbols of the previous transformations. +- goPasses := llvm.NewPassManager() +- defer goPasses.Dispose() +- goPasses.AddGlobalDCEPass() +- goPasses.Run(mod) ++ po := llvm.NewPassBuilderOptions() ++ defer po.Dispose() ++ err = mod.RunPasses("globaldce", llvm.TargetMachine{}, po) ++ if err != nil { ++ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} ++ } + } + + if config.Scheduler() == "none" { +@@ -169,23 +139,15 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i + fn.SetLinkage(llvm.InternalLinkage) + } + +- // Run function passes again, because without it, llvm.coro.size.i32() +- // doesn't get lowered. +- funcPasses := llvm.NewFunctionPassManagerForModule(mod) +- defer funcPasses.Dispose() +- builder.PopulateFunc(funcPasses) +- funcPasses.InitializeFunc() +- for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { +- funcPasses.RunFunc(fn) ++ // Run the default pass pipeline. ++ // TODO: set the PrepareForThinLTO flag somehow. ++ po := llvm.NewPassBuilderOptions() ++ defer po.Dispose() ++ passes := fmt.Sprintf("default<%s>", optLevel) ++ err := mod.RunPasses(passes, llvm.TargetMachine{}, po) ++ if err != nil { ++ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} + } +- funcPasses.FinalizeFunc() +- +- // Run module passes. +- // TODO: somehow set the PrepareForThinLTO flag in the pass manager builder. +- modPasses := llvm.NewPassManager() +- defer modPasses.Dispose() +- builder.Populate(modPasses) +- modPasses.Run(mod) + + hasGCPass := MakeGCStackSlots(mod) + if hasGCPass { +diff --git a/transform/transform.go b/transform/transform.go +index ab08317e..429cbd5f 100644 +--- a/transform/transform.go ++++ b/transform/transform.go +@@ -22,7 +22,7 @@ import ( + // the -opt= compiler flag. + func AddStandardAttributes(fn llvm.Value, config *compileopts.Config) { + ctx := fn.Type().Context() +- _, sizeLevel, _ := config.OptLevels() ++ _, _, sizeLevel := config.OptLevel() + if sizeLevel >= 1 { + fn.AddFunctionAttr(ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0)) + } +-- +2.41.0 + diff --git a/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch b/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch new file mode 100644 index 0000000..36bebd7 --- /dev/null +++ b/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch @@ -0,0 +1,222 @@ +From 0321eecc6d29d5b571930ed97f392623fe80a2e5 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sat, 23 Sep 2023 14:57:25 +0200 +Subject: [PATCH 6/7] avr: don't compile large parts of picolibc (math, stdio) + +These parts aren't critical and lead to crashes on small chips without +long jumps (like the attiny85) with LLVM 17. (Older LLVM versions would +emit long jumps regardless, even if the chip didn't support those). + +For more information, see: https://github.com/llvm/llvm-project/issues/67042 + +Signed-off-by: Elliott Sales de Andrade +--- + builder/picolibc.go | 172 ++++++++++++++++++++++++-------------------- + 1 file changed, 93 insertions(+), 79 deletions(-) + +diff --git a/builder/picolibc.go b/builder/picolibc.go +index 1b7c748b..91ad27be 100644 +--- a/builder/picolibc.go ++++ b/builder/picolibc.go +@@ -3,6 +3,7 @@ package builder + import ( + "os" + "path/filepath" ++ "strings" + + "github.com/tinygo-org/tinygo/goenv" + ) +@@ -41,91 +42,23 @@ var Picolibc = Library{ + }, + sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib") }, + librarySources: func(target string) ([]string, error) { +- return picolibcSources, nil ++ sources := append([]string(nil), picolibcSources...) ++ if !strings.HasPrefix(target, "avr") { ++ // Small chips without long jumps can't compile many files (printf, ++ // pow, etc). Therefore exclude those source files for those chips. ++ // Unfortunately it's difficult to exclude only some chips, so this ++ // excludes those files on all AVR chips for now. ++ // More information: ++ // https://github.com/llvm/llvm-project/issues/67042 ++ sources = append(sources, picolibcSourcesLarge...) ++ } ++ return sources, nil + }, + } + + var picolibcSources = []string{ + "../../picolibc-stdio.c", + +- // srcs_tinystdio +- "libc/tinystdio/asprintf.c", +- "libc/tinystdio/bufio.c", +- "libc/tinystdio/clearerr.c", +- "libc/tinystdio/ecvt_r.c", +- "libc/tinystdio/ecvt.c", +- "libc/tinystdio/ecvtf_r.c", +- "libc/tinystdio/ecvtf.c", +- "libc/tinystdio/fcvt.c", +- "libc/tinystdio/fcvt_r.c", +- "libc/tinystdio/fcvtf.c", +- "libc/tinystdio/fcvtf_r.c", +- "libc/tinystdio/gcvt.c", +- "libc/tinystdio/gcvtf.c", +- "libc/tinystdio/fclose.c", +- "libc/tinystdio/fdevopen.c", +- "libc/tinystdio/feof.c", +- "libc/tinystdio/ferror.c", +- "libc/tinystdio/fflush.c", +- "libc/tinystdio/fgetc.c", +- "libc/tinystdio/fgets.c", +- "libc/tinystdio/fileno.c", +- "libc/tinystdio/filestrget.c", +- "libc/tinystdio/filestrput.c", +- "libc/tinystdio/filestrputalloc.c", +- "libc/tinystdio/fmemopen.c", +- "libc/tinystdio/fprintf.c", +- "libc/tinystdio/fputc.c", +- "libc/tinystdio/fputs.c", +- "libc/tinystdio/fread.c", +- //"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369 +- "libc/tinystdio/fscanf.c", +- "libc/tinystdio/fseek.c", +- "libc/tinystdio/fseeko.c", +- "libc/tinystdio/ftell.c", +- "libc/tinystdio/ftello.c", +- "libc/tinystdio/fwrite.c", +- "libc/tinystdio/getchar.c", +- "libc/tinystdio/gets.c", +- "libc/tinystdio/matchcaseprefix.c", +- "libc/tinystdio/mktemp.c", +- "libc/tinystdio/perror.c", +- "libc/tinystdio/printf.c", +- "libc/tinystdio/putchar.c", +- "libc/tinystdio/puts.c", +- "libc/tinystdio/rewind.c", +- "libc/tinystdio/scanf.c", +- "libc/tinystdio/setbuf.c", +- "libc/tinystdio/setbuffer.c", +- "libc/tinystdio/setlinebuf.c", +- "libc/tinystdio/setvbuf.c", +- "libc/tinystdio/snprintf.c", +- "libc/tinystdio/sprintf.c", +- "libc/tinystdio/snprintfd.c", +- "libc/tinystdio/snprintff.c", +- "libc/tinystdio/sprintff.c", +- "libc/tinystdio/sprintfd.c", +- "libc/tinystdio/sscanf.c", +- "libc/tinystdio/strfromf.c", +- "libc/tinystdio/strfromd.c", +- "libc/tinystdio/strtof.c", +- "libc/tinystdio/strtof_l.c", +- "libc/tinystdio/strtod.c", +- "libc/tinystdio/strtod_l.c", +- "libc/tinystdio/ungetc.c", +- "libc/tinystdio/vasprintf.c", +- "libc/tinystdio/vfiprintf.c", +- "libc/tinystdio/vfprintf.c", +- "libc/tinystdio/vfprintff.c", +- "libc/tinystdio/vfscanf.c", +- "libc/tinystdio/vfiscanf.c", +- "libc/tinystdio/vfscanff.c", +- "libc/tinystdio/vprintf.c", +- "libc/tinystdio/vscanf.c", +- "libc/tinystdio/vsscanf.c", +- "libc/tinystdio/vsnprintf.c", +- "libc/tinystdio/vsprintf.c", +- + "libc/string/bcmp.c", + "libc/string/bcopy.c", + "libc/string/bzero.c", +@@ -229,6 +162,87 @@ var picolibcSources = []string{ + "libc/string/wmempcpy.c", + "libc/string/wmemset.c", + "libc/string/xpg_strerror_r.c", ++} ++ ++// Parts of picolibc that are too large for small AVRs. ++var picolibcSourcesLarge = []string{ ++ // srcs_tinystdio ++ "libc/tinystdio/asprintf.c", ++ "libc/tinystdio/bufio.c", ++ "libc/tinystdio/clearerr.c", ++ "libc/tinystdio/ecvt_r.c", ++ "libc/tinystdio/ecvt.c", ++ "libc/tinystdio/ecvtf_r.c", ++ "libc/tinystdio/ecvtf.c", ++ "libc/tinystdio/fcvt.c", ++ "libc/tinystdio/fcvt_r.c", ++ "libc/tinystdio/fcvtf.c", ++ "libc/tinystdio/fcvtf_r.c", ++ "libc/tinystdio/gcvt.c", ++ "libc/tinystdio/gcvtf.c", ++ "libc/tinystdio/fclose.c", ++ "libc/tinystdio/fdevopen.c", ++ "libc/tinystdio/feof.c", ++ "libc/tinystdio/ferror.c", ++ "libc/tinystdio/fflush.c", ++ "libc/tinystdio/fgetc.c", ++ "libc/tinystdio/fgets.c", ++ "libc/tinystdio/fileno.c", ++ "libc/tinystdio/filestrget.c", ++ "libc/tinystdio/filestrput.c", ++ "libc/tinystdio/filestrputalloc.c", ++ "libc/tinystdio/fmemopen.c", ++ "libc/tinystdio/fprintf.c", ++ "libc/tinystdio/fputc.c", ++ "libc/tinystdio/fputs.c", ++ "libc/tinystdio/fread.c", ++ //"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369 ++ "libc/tinystdio/fscanf.c", ++ "libc/tinystdio/fseek.c", ++ "libc/tinystdio/fseeko.c", ++ "libc/tinystdio/ftell.c", ++ "libc/tinystdio/ftello.c", ++ "libc/tinystdio/fwrite.c", ++ "libc/tinystdio/getchar.c", ++ "libc/tinystdio/gets.c", ++ "libc/tinystdio/matchcaseprefix.c", ++ "libc/tinystdio/mktemp.c", ++ "libc/tinystdio/perror.c", ++ "libc/tinystdio/printf.c", ++ "libc/tinystdio/putchar.c", ++ "libc/tinystdio/puts.c", ++ "libc/tinystdio/rewind.c", ++ "libc/tinystdio/scanf.c", ++ "libc/tinystdio/setbuf.c", ++ "libc/tinystdio/setbuffer.c", ++ "libc/tinystdio/setlinebuf.c", ++ "libc/tinystdio/setvbuf.c", ++ "libc/tinystdio/snprintf.c", ++ "libc/tinystdio/sprintf.c", ++ "libc/tinystdio/snprintfd.c", ++ "libc/tinystdio/snprintff.c", ++ "libc/tinystdio/sprintff.c", ++ "libc/tinystdio/sprintfd.c", ++ "libc/tinystdio/sscanf.c", ++ "libc/tinystdio/strfromf.c", ++ "libc/tinystdio/strfromd.c", ++ "libc/tinystdio/strtof.c", ++ "libc/tinystdio/strtof_l.c", ++ "libc/tinystdio/strtod.c", ++ "libc/tinystdio/strtod_l.c", ++ "libc/tinystdio/ungetc.c", ++ "libc/tinystdio/vasprintf.c", ++ "libc/tinystdio/vfiprintf.c", ++ "libc/tinystdio/vfprintf.c", ++ "libc/tinystdio/vfprintff.c", ++ "libc/tinystdio/vfscanf.c", ++ "libc/tinystdio/vfiscanf.c", ++ "libc/tinystdio/vfscanff.c", ++ "libc/tinystdio/vprintf.c", ++ "libc/tinystdio/vscanf.c", ++ "libc/tinystdio/vsscanf.c", ++ "libc/tinystdio/vsnprintf.c", ++ "libc/tinystdio/vsprintf.c", + + "libm/common/sf_finite.c", + "libm/common/sf_copysign.c", +-- +2.41.0 + diff --git a/0007-all-add-initial-LLVM-17-support.patch b/0007-all-add-initial-LLVM-17-support.patch new file mode 100644 index 0000000..1650c1c --- /dev/null +++ b/0007-all-add-initial-LLVM-17-support.patch @@ -0,0 +1,157 @@ +From 55fd04af5a6a815224b436ee491ed05b0ef4ee7c Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Sat, 23 Sep 2023 15:03:24 +0200 +Subject: [PATCH 7/7] all: add initial LLVM 17 support + +This allows us to test LLVM 17 already, before it's available in +Homebrew etc. + +Full support for LLVM 17 will have to wait until Espressif rebases their +Xtensa fork of LLVM. + +Signed-off-by: Elliott Sales de Andrade +--- + .circleci/config.yml | 13 +++++++++++-- + .github/workflows/build-macos.yml | 16 +++++++++++++--- + cgo/libclang_config_llvm16.go | 2 +- + cgo/libclang_config_llvm17.go | 15 +++++++++++++++ + go.mod | 2 +- + go.sum | 4 ++-- + 6 files changed, 43 insertions(+), 9 deletions(-) + create mode 100644 cgo/libclang_config_llvm17.go + +diff --git a/.circleci/config.yml b/.circleci/config.yml +index 1dff3ba7..86da321d 100644 +--- a/.circleci/config.yml ++++ b/.circleci/config.yml +@@ -55,7 +55,7 @@ commands: + - run: + name: "Install apt dependencies" + command: | +- echo 'deb https://apt.llvm.org/buster/ llvm-toolchain-buster-<> main' > /etc/apt/sources.list.d/llvm.list ++ echo 'deb https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-<> main' > /etc/apt/sources.list.d/llvm.list + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - + apt-get update + apt-get install --no-install-recommends -y \ +@@ -100,11 +100,18 @@ commands: + jobs: + test-llvm14-go118: + docker: +- - image: golang:1.18-buster ++ - image: golang:1.18-bullseye + steps: + - test-linux: + llvm: "14" + resource_class: large ++ test-llvm17-go121: ++ docker: ++ - image: golang:1.21-bullseye ++ steps: ++ - test-linux: ++ llvm: "17" ++ resource_class: large + + workflows: + test-all: +@@ -112,3 +119,5 @@ workflows: + # This tests our lowest supported versions of Go and LLVM, to make sure at + # least the smoke tests still pass. + - test-llvm14-go118 ++ # This tests the upcoming LLVM 17 support. ++ - test-llvm17-go121 +diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml +index 1284a4ed..be8bdb03 100644 +--- a/.github/workflows/build-macos.yml ++++ b/.github/workflows/build-macos.yml +@@ -116,11 +116,15 @@ jobs: + test-macos-homebrew: + name: homebrew-install + runs-on: macos-latest ++ strategy: ++ matrix: ++ version: [16, 17] + steps: ++ - name: Update Homebrew ++ run: brew update + - name: Install LLVM +- shell: bash + run: | +- HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@16 ++ HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@${{ matrix.version }} + - name: Checkout + uses: actions/checkout@v3 + - name: Install Go +@@ -128,7 +132,13 @@ jobs: + with: + go-version: '1.21' + cache: true +- - name: Build TinyGo ++ - name: Build TinyGo (LLVM ${{ matrix.version }}) ++ run: go install -tags=llvm${{ matrix.version }} ++ - name: Check binary ++ run: tinygo version ++ - name: Build TinyGo (default LLVM) ++ if: matrix.version == 16 + run: go install + - name: Check binary ++ if: matrix.version == 16 + run: tinygo version +diff --git a/cgo/libclang_config_llvm16.go b/cgo/libclang_config_llvm16.go +index 79aacd2f..28091701 100644 +--- a/cgo/libclang_config_llvm16.go ++++ b/cgo/libclang_config_llvm16.go +@@ -1,4 +1,4 @@ +-//go:build !byollvm && !llvm14 && !llvm15 ++//go:build !byollvm && !llvm14 && !llvm15 && !llvm17 + + package cgo + +diff --git a/cgo/libclang_config_llvm17.go b/cgo/libclang_config_llvm17.go +new file mode 100644 +index 00000000..fd6d1480 +--- /dev/null ++++ b/cgo/libclang_config_llvm17.go +@@ -0,0 +1,15 @@ ++//go:build !byollvm && llvm17 ++ ++package cgo ++ ++/* ++#cgo linux CFLAGS: -I/usr/include/llvm-17 -I/usr/include/llvm-c-17 -I/usr/lib/llvm-17/include ++#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@17/include ++#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@17/include ++#cgo freebsd CFLAGS: -I/usr/local/llvm17/include ++#cgo linux LDFLAGS: -L/usr/lib/llvm-17/lib -lclang ++#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@17/lib -lclang -lffi ++#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@17/lib -lclang -lffi ++#cgo freebsd LDFLAGS: -L/usr/local/llvm17/lib -lclang ++*/ ++import "C" +diff --git a/go.mod b/go.mod +index 9af3402b..36d601f8 100644 +--- a/go.mod ++++ b/go.mod +@@ -18,7 +18,7 @@ require ( + golang.org/x/sys v0.11.0 + golang.org/x/tools v0.12.0 + gopkg.in/yaml.v2 v2.4.0 +- tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc ++ tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd + ) + + require ( +diff --git a/go.sum b/go.sum +index 587efdf2..1b5ad074 100644 +--- a/go.sum ++++ b/go.sum +@@ -65,5 +65,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 + gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +-tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc h1:IVX1dqCX3c88P7iEMBtz1xCAM4UIqCMgbqHdSefBaWE= +-tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= ++tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd h1:iSVvs8r3ooxYTsmcf7FKCHq83eOSUkWKtmQhnDadDQU= ++tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +-- +2.41.0 + diff --git a/tinygo.spec b/tinygo.spec index d13baeb..c5e7e41 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -10,9 +10,9 @@ Version: 0.30.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%global clang_llvm_version 16 +%global clang_llvm_version 17 %global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 -%global compiler_rt_version %{clang_llvm_version}.0.0 +%global compiler_rt_version %{clang_llvm_version}.0.1 %global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 %global musl_version 1.2.3 %global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 @@ -77,6 +77,15 @@ Patch0002: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch +# Support LLVM 17. +# https://github.com/tinygo-org/tinygo/pull/3923 +Patch0004: 0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch +# https://github.com/tinygo-org/tinygo/pull/3918 +Patch0005: 0005-all-use-the-new-LLVM-pass-manager.patch +# https://github.com/tinygo-org/tinygo/pull/3913 +Patch0006: 0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch +Patch0007: 0007-all-add-initial-LLVM-17-support.patch + # Not supported upstream yet. ExcludeArch: ppc64le s390x # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval From 9a6e0539c2f88cbbcb6becb05fafc9fb2adc5787 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 25 Sep 2023 04:26:22 -0400 Subject: [PATCH 59/78] Upload compiler-rt 17 sources [skip changelog] --- sources | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources b/sources index 80e2c95..92a1b43 100644 --- a/sources +++ b/sources @@ -2,8 +2,8 @@ SHA512 (tinygo-0.30.0.tar.gz) = 91c4b6a578d5730e6915d48c69f567b814d5d1201150df05 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-16.0.0.src.tar.xz) = 6906964f0aa12bb18b137bee68a562412abf6d0200f8cfece83dc860ad06de41de847d04809fba08d9e2bb61f27e036eadb51fce153e05181f0bd4fecf29727d -SHA512 (compiler-rt-16.0.0.src.tar.xz.sig) = 8c6de41ed7bed40930fa60f2549ba1267d0b6ef6ed05f3febd879066b9bf8a812a7faccbd3bb791c5780a91f13decc3be0cb5e4cbe7d6281e5e96a4e21593119 +SHA512 (compiler-rt-17.0.1.src.tar.xz) = a440cca467e51cd7e3484adb8ea189ca1af61f9da928b17fed7ee48ebf3e997a55b4b5e0a8309c02a59b59be6ea8458745e9e898c403cfff83b93ff57fbf922d +SHA512 (compiler-rt-17.0.1.src.tar.xz.sig) = 5f8922e2e660e7b91c9a089caba51e8132c59f8502d39a70889b6508811dbbeece734a06b97ea366e87c023b957d09d6a62a06f7d848539bc894f6841084d61c SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c SHA512 (musl-1.2.3.tar.gz.asc) = 01a857dbc3981c90244d4d1d883efe51986652ca5734a741c9d1a4d06c5a22831e85520ac67212268b70c22049317a8f39b3219be182e7e67741add428ac5bc6 From 1539b445c8fda1739f5b188fd02e6912c6271e38 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 5 Nov 2023 00:56:46 -0400 Subject: [PATCH 60/78] Allow an older version of golang.org/x/tools The requirement is really only on 0.9, as that changed some internals. --- tinygo.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index c5e7e41..e0f96d3 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -106,7 +106,7 @@ BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 BuildRequires: golang(github.com/sigurn/crc16) BuildRequires: golang(go.bug.st/serial) >= 1.6.0 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) -BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.12 +BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.11 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: golang-tests From 6bea1c34db81ce378ad4e26b4de9e5daaf186e3f Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 27 Jan 2024 06:16:52 +0000 Subject: [PATCH 61/78] Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild From 2fb69c2ae85f2339c98f5643f51cfcbc7dcd192f Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sun, 11 Feb 2024 23:40:19 +0000 Subject: [PATCH 62/78] Rebuild for golang 1.22.0 From 62cfc868a2613c27cc73f1d2eb1445b50a3f4f9a Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 20 Jul 2024 07:30:20 +0000 Subject: [PATCH 63/78] Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild From 70df58fba13ee0bf8fe7d97af954aba5019ded11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Such=C3=BD?= Date: Wed, 4 Sep 2024 22:24:17 +0200 Subject: [PATCH 64/78] convert license to SPDX This is part of https://fedoraproject.org/wiki/Changes/SPDX_Licenses_Phase_4 --- tinygo.spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tinygo.spec b/tinygo.spec index e0f96d3..8169f06 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -48,7 +48,8 @@ Summary: Go compiler for small places # nrfx: BSD and ASL 2.0 # picolibc: BSD and ISC and MIT and GPLv2 (testing code only, unused by this package) # wasi-libc: BSD and CC0 and ISC and MIT and Public Domain -License: BSD and APSL 2.0 and ASL 2.0 and CC0 and ISC and MIT and (NCSA or MIT) and Public Domain +# Automatically converted from old format: BSD and APSL 2.0 and ASL 2.0 and CC0 and ISC and MIT and (NCSA or MIT) and Public Domain - review is highly recommended. +License: LicenseRef-Callaway-BSD AND APSL-2.0 AND Apache-2.0 AND CC0-1.0 AND ISC AND LicenseRef-Callaway-MIT AND (NCSA OR LicenseRef-Callaway-MIT) AND LicenseRef-Callaway-Public-Domain URL: %{gourl} Source0: %{gosource} Source1: clean_tarballs.sh From 16bb42b1164efc011f04ab5098edf7228c909a17 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Feb 2024 01:24:23 -0500 Subject: [PATCH 65/78] Switch to SPDX licenses --- clean_tarballs.sh | 31 +++++++++++++++++++++++++------ tinygo.spec | 29 ++++++++++++++++++----------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/clean_tarballs.sh b/clean_tarballs.sh index 84b74a5..3e8e11d 100755 --- a/clean_tarballs.sh +++ b/clean_tarballs.sh @@ -6,8 +6,8 @@ CMSIS_SVD_VERSION=df75ff974c76a911fc2815e29807f5ecaae06fc2 if [ -e "cmsis-${CMSIS_VERSION}-clean.tar.xz" ]; then echo "Not downloading cmsis-${CMSIS_VERSION}-clean.tar.xz again!" else -# The license for this tarball is complicated, but the headers are under a -# simple BSD license, so we only package them. +# The license for this tarball is complicated, but the headers are under the +# BSD-3-Clause license, so we only package them. wget -nc https://github.com/ARM-software/CMSIS/archive/${CMSIS_VERSION}/cmsis-${CMSIS_VERSION}.tar.gz tar xf cmsis-${CMSIS_VERSION}.tar.gz tar cJf cmsis-${CMSIS_VERSION}-clean.tar.xz \ @@ -21,7 +21,28 @@ echo "Not downloading cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz again!" else # This is basically a "collection of random stuff" from various vendors, under # various licenses. Some licenses are non-free and some are actively hostile, -# but we only need a rather small portion under a good license. +# but we only need a rather small portion under a good license: +# - Atmel: Apache-2.0 AND BSD-Source-Code +# - Espressif: Apache-2.0 +# - Espressif-Community: Apache-2.0 OR MIT +# - Kendryte-Community: ISC +# - NXP/L*: Proprietary, so not included. +# - NXP/M*: BSD-3-Clause +# - RaspberryPi: BSD-3-Clause +# - SiFive-Community: ISC +# - STMicro: Proprietary, so not included. +# These directories are not used by TinyGo, so are not kept: +# - ARM_SAMPLE: BSD-3-Clause +# - Cypress: Apache-2.0 +# - Freescale: Proprietary +# - Fujitsu: Proprietary +# - Holtek: Proprietary +# - Nordic: BSD-3-Clause +# - Nuvoton: Unknown +# - SiliconLabs: Unknown +# - Spansion: Proprietary +# - TexasInstruments: Proprietary +# - Toshiba: Unknown #wget https://github.com/posborne/cmsis-svd/archive/${CMSIS_SVD_VERSION}/cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz wget -nc https://github.com/tinygo-org/cmsis-svd/archive/${CMSIS_SVD_VERSION}/cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz tar xf cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz @@ -30,10 +51,8 @@ tar cJf cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Espressif/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Espressif-Community/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/Kendryte-Community/ \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/SiFive-Community/ \ cmsis-svd-${CMSIS_SVD_VERSION}/data/NXP/M* \ cmsis-svd-${CMSIS_SVD_VERSION}/data/RaspberryPi/ \ - # This has a weird license, so we cannot include it. - # cmsis-svd-${CMSIS_SVD_VERSION}/data/STMicro/ + cmsis-svd-${CMSIS_SVD_VERSION}/data/SiFive-Community/ rm -r cmsis-svd-${CMSIS_SVD_VERSION}/ fi diff --git a/tinygo.spec b/tinygo.spec index 8169f06..fac7c13 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -38,18 +38,25 @@ Name: tinygo Release: %autorelease Summary: Go compiler for small places -# Main files: BSD -# CMSIS: BSD (subsetted) -# avr-mcu: ASL 2.0 (packs) and MIT (Rust code, unused by this package) -# cmsis-svd: ASL 2.0 and BSD and ISC and MIT (subsetted) -# compiler-rt: NCSA or MIT -# macos-minimal-sdk: APSL 2.0 and BSD and ISC and Public Domain +# Main files: BSD-3-Clause +# builder/cc1as.*: Apache-2.0 WITH LLVM-exception +# corpus_test.go: MIT +# src/net: BSD-2-Clause +# CMSIS: BSD-3-Clause (subsetted) +# avr-mcu: Apache-2.0 (packs) AND MIT (Rust code, unused by this package) +# cmsis-svd: Apache-2.0 AND (Apache-2.0 OR MIT) AND BSD-3-Clause AND BSD-Source-Code AND ISC AND MIT (subsetted) +# compiler-rt: Apache-2.0 WITH LLVM-exception OR NCSA OR MIT +# macos-minimal-sdk: APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSD-4-Clause-UC AND ISC AND LicenseRef-Fedora-Public-Domain # musl: MIT -# nrfx: BSD and ASL 2.0 -# picolibc: BSD and ISC and MIT and GPLv2 (testing code only, unused by this package) -# wasi-libc: BSD and CC0 and ISC and MIT and Public Domain -# Automatically converted from old format: BSD and APSL 2.0 and ASL 2.0 and CC0 and ISC and MIT and (NCSA or MIT) and Public Domain - review is highly recommended. -License: LicenseRef-Callaway-BSD AND APSL-2.0 AND Apache-2.0 AND CC0-1.0 AND ISC AND LicenseRef-Callaway-MIT AND (NCSA OR LicenseRef-Callaway-MIT) AND LicenseRef-Callaway-Public-Domain +# nrfx: BSD-3-Clause AND Apache-2.0 +# picolibc: BSD-2-Clause AND BSD-2-Clause-FreeBSD AND BSD-3-Clause AND ISC AND SMLNJ AND Spencer-94 AND GPLv2 (testing code only, unused by this package) +# wasi-libc: Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT AND BSD-2-Clause AND CC0-1.0 (dlmalloc implementation, unused by this package) +License: %{shrink: BSD-3-Clause AND Apache-2.0 WITH LLVM-exception AND BSD-2-Clause AND MIT AND + Apache-2.0 AND + (Apache-2.0 OR MIT) AND BSD-Source-Code AND ISC AND + (Apache-2.0 WITH LLVM-exception OR NCSA OR MIT) AND + APSL-2.0 AND BSD-2-Clause AND BSD-4-Clause AND BSD-4-Clause-UC AND LicenseRef-Fedora-Public-Domain AND + BSD-2-Clause-FreeBSD AND SMLNJ AND Spencer-94} URL: %{gourl} Source0: %{gosource} Source1: clean_tarballs.sh From cc972cf7e521c673e2de70f137471b0d7cb03864 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sun, 19 Jan 2025 12:52:48 +0000 Subject: [PATCH 66/78] Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild From 716d8be33296feb8edfdb221d7b681108efe96ad Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Fri, 25 Jul 2025 19:20:17 +0000 Subject: [PATCH 67/78] Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild From b460c7c931ebc8d121eb7b6a259ec8c6beb0ed23 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 28 Oct 2024 01:09:01 -0400 Subject: [PATCH 68/78] Improve build with non-default LLVM/Clang --- 0001-Skip-WASI-tests.patch | 6 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 6 +- ...ional-packages-to-install-if-missing.patch | 6 +- ...g-in-StringToBytes-optimization-pass.patch | 6 +- 0005-all-use-the-new-LLVM-pass-manager.patch | 6 +- ...e-large-parts-of-picolibc-math-stdio.patch | 6 +- 0007-all-add-initial-LLVM-17-support.patch | 6 +- 0008-Set-LLVM-search-paths-for-Fedora.patch | 92 +++++++++++++++++++ tinygo.spec | 23 ++++- 9 files changed, 131 insertions(+), 26 deletions(-) create mode 100644 0008-Set-LLVM-search-paths-for-Fedora.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 63bc8d7..b8c5e6a 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From ee856392109e39cf60e83022441c94adee205447 Mon Sep 17 00:00:00 2001 +From 7bbd6e2f039a54e73bb38cb6dd5397e84c8e851d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/7] Skip WASI tests. +Subject: [PATCH 1/8] Skip WASI tests. We do not have wasmtime available. @@ -34,5 +34,5 @@ index ae7aed56..ac204f0c 100644 } for _, targ := range targs { -- -2.41.0 +2.47.0 diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 79deaa6..40e3bac 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From 1f60829a1fffdcbe268c1998a560fdeb6029407e Mon Sep 17 00:00:00 2001 +From b7e64bf1bbcc720c2081d0f76a722b61d12e5b82 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/7] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -58,5 +58,5 @@ index ac204f0c..27344c27 100644 actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows -- -2.41.0 +2.47.0 diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index c09cc88..a17c44d 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From 3f6a6f241ab37976f07e792986b5c47fdde20c8a Mon Sep 17 00:00:00 2001 +From fe776e032278a66e3e291a91bad59a3e411c9b57 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/7] Suggest optional packages to install if missing +Subject: [PATCH 3/8] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -44,5 +44,5 @@ index a23d0753..2380f683 100644 // doing anything. This can be useful where a *compileJob producing an output is // expected but nothing needs to be done, for example for a load from a cache. -- -2.41.0 +2.47.0 diff --git a/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch b/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch index b0c42ec..7e0a470 100644 --- a/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch +++ b/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch @@ -1,7 +1,7 @@ -From bf51015656ff3b1bbe6b41ea1155610178c2961d Mon Sep 17 00:00:00 2001 +From 930064c95f1cd6c0f7088b4f7785d754fa84cc01 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 21 Sep 2023 15:39:06 +0200 -Subject: [PATCH 4/7] transform: fix bug in StringToBytes optimization pass +Subject: [PATCH 4/8] transform: fix bug in StringToBytes optimization pass Previously, this pass would convert any read-only use of a runtime.stringToBytes call to use the original string buffer instead. @@ -117,5 +117,5 @@ index 30aa520a..b33a1755 100644 + ret void +} -- -2.41.0 +2.47.0 diff --git a/0005-all-use-the-new-LLVM-pass-manager.patch b/0005-all-use-the-new-LLVM-pass-manager.patch index 84eadf2..5816031 100644 --- a/0005-all-use-the-new-LLVM-pass-manager.patch +++ b/0005-all-use-the-new-LLVM-pass-manager.patch @@ -1,7 +1,7 @@ -From 3dcb55f940011bb9bcb75d98182290da60642e4d Mon Sep 17 00:00:00 2001 +From 35221dacbc382c00d57055a3c327b8462282ddbf Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 19 Sep 2023 22:37:44 +0200 -Subject: [PATCH 5/7] all: use the new LLVM pass manager +Subject: [PATCH 5/8] all: use the new LLVM pass manager The old LLVM pass manager is deprecated and should not be used anymore. Moreover, the pass manager builder (which we used to set up a pass @@ -420,5 +420,5 @@ index ab08317e..429cbd5f 100644 fn.AddFunctionAttr(ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0)) } -- -2.41.0 +2.47.0 diff --git a/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch b/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch index 36bebd7..9ec250f 100644 --- a/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch +++ b/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch @@ -1,7 +1,7 @@ -From 0321eecc6d29d5b571930ed97f392623fe80a2e5 Mon Sep 17 00:00:00 2001 +From 2ad6ed3429443910fcb5baacb6a05a1bfe9351ae Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 23 Sep 2023 14:57:25 +0200 -Subject: [PATCH 6/7] avr: don't compile large parts of picolibc (math, stdio) +Subject: [PATCH 6/8] avr: don't compile large parts of picolibc (math, stdio) These parts aren't critical and lead to crashes on small chips without long jumps (like the attiny85) with LLVM 17. (Older LLVM versions would @@ -218,5 +218,5 @@ index 1b7c748b..91ad27be 100644 "libm/common/sf_finite.c", "libm/common/sf_copysign.c", -- -2.41.0 +2.47.0 diff --git a/0007-all-add-initial-LLVM-17-support.patch b/0007-all-add-initial-LLVM-17-support.patch index 1650c1c..37591ba 100644 --- a/0007-all-add-initial-LLVM-17-support.patch +++ b/0007-all-add-initial-LLVM-17-support.patch @@ -1,7 +1,7 @@ -From 55fd04af5a6a815224b436ee491ed05b0ef4ee7c Mon Sep 17 00:00:00 2001 +From d4bda089b8e33050cf05e0d9fce0a73b0b13e014 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 23 Sep 2023 15:03:24 +0200 -Subject: [PATCH 7/7] all: add initial LLVM 17 support +Subject: [PATCH 7/8] all: add initial LLVM 17 support This allows us to test LLVM 17 already, before it's available in Homebrew etc. @@ -153,5 +153,5 @@ index 587efdf2..1b5ad074 100644 +tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd h1:iSVvs8r3ooxYTsmcf7FKCHq83eOSUkWKtmQhnDadDQU= +tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -- -2.41.0 +2.47.0 diff --git a/0008-Set-LLVM-search-paths-for-Fedora.patch b/0008-Set-LLVM-search-paths-for-Fedora.patch new file mode 100644 index 0000000..cdca4f6 --- /dev/null +++ b/0008-Set-LLVM-search-paths-for-Fedora.patch @@ -0,0 +1,92 @@ +From 0e3fa31505241d5317eb61d78c2d3141b179e482 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 27 Oct 2024 23:33:18 -0400 +Subject: [PATCH 8/8] Set LLVM search paths for Fedora + +Signed-off-by: Elliott Sales de Andrade +--- + cgo/libclang_config_llvm15.go | 4 ++-- + cgo/libclang_config_llvm16.go | 4 ++-- + cgo/libclang_config_llvm17.go | 4 ++-- + cgo/libclang_config_llvm18.go | 15 +++++++++++++++ + 4 files changed, 21 insertions(+), 6 deletions(-) + create mode 100644 cgo/libclang_config_llvm18.go + +diff --git a/cgo/libclang_config_llvm15.go b/cgo/libclang_config_llvm15.go +index e105dfe7..7e54fc9e 100644 +--- a/cgo/libclang_config_llvm15.go ++++ b/cgo/libclang_config_llvm15.go +@@ -3,11 +3,11 @@ + package cgo + + /* +-#cgo linux CFLAGS: -I/usr/lib/llvm-15/include ++#cgo linux CFLAGS: -I/usr/lib64/llvm15/include + #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@15/include + #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@15/include + #cgo freebsd CFLAGS: -I/usr/local/llvm15/include +-#cgo linux LDFLAGS: -L/usr/lib/llvm-15/lib -lclang ++#cgo linux LDFLAGS: -L/usr/lib64/llvm15/lib -lclang + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -lclang -lffi + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm15/lib -lclang +diff --git a/cgo/libclang_config_llvm16.go b/cgo/libclang_config_llvm16.go +index 28091701..e78f02ff 100644 +--- a/cgo/libclang_config_llvm16.go ++++ b/cgo/libclang_config_llvm16.go +@@ -9,11 +9,11 @@ package cgo + // ln -sf ../../x86_64-linux-gnu/libclang-16.so.1 /usr/lib/llvm-16/lib/libclang.so + + /* +-#cgo linux CFLAGS: -I/usr/lib/llvm-16/include ++#cgo linux CFLAGS: -I/usr/lib64/llvm16/include + #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@16/include + #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@16/include + #cgo freebsd CFLAGS: -I/usr/local/llvm16/include +-#cgo linux LDFLAGS: -L/usr/lib/llvm-16/lib -lclang ++#cgo linux LDFLAGS: -L/usr/lib64/llvm16/lib -lclang + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@16/lib -lclang -lffi + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@16/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm16/lib -lclang +diff --git a/cgo/libclang_config_llvm17.go b/cgo/libclang_config_llvm17.go +index fd6d1480..fdf72400 100644 +--- a/cgo/libclang_config_llvm17.go ++++ b/cgo/libclang_config_llvm17.go +@@ -3,11 +3,11 @@ + package cgo + + /* +-#cgo linux CFLAGS: -I/usr/include/llvm-17 -I/usr/include/llvm-c-17 -I/usr/lib/llvm-17/include ++#cgo linux CFLAGS: -I/usr/lib64/llvm17/include + #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@17/include + #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@17/include + #cgo freebsd CFLAGS: -I/usr/local/llvm17/include +-#cgo linux LDFLAGS: -L/usr/lib/llvm-17/lib -lclang ++#cgo linux LDFLAGS: -L/usr/lib64/llvm17/lib -lclang + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@17/lib -lclang -lffi + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@17/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm17/lib -lclang +diff --git a/cgo/libclang_config_llvm18.go b/cgo/libclang_config_llvm18.go +new file mode 100644 +index 00000000..18db6c08 +--- /dev/null ++++ b/cgo/libclang_config_llvm18.go +@@ -0,0 +1,15 @@ ++//go:build !byollvm && !llvm15 && !llvm16 && !llvm17 ++ ++package cgo ++ ++/* ++#cgo linux CFLAGS: -I/usr/lib64/llvm18/include ++#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@18/include ++#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@18/include ++#cgo freebsd CFLAGS: -I/usr/local/llvm18/include ++#cgo linux LDFLAGS: -L/usr/lib64/llvm18/lib -lclang ++#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@18/lib -lclang ++#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@18/lib -lclang ++#cgo freebsd LDFLAGS: -L/usr/local/llvm18/lib -lclang ++*/ ++import "C" +-- +2.47.0 + diff --git a/tinygo.spec b/tinygo.spec index fac7c13..0b2794a 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -94,12 +94,15 @@ Patch0005: 0005-all-use-the-new-LLVM-pass-manager.patch Patch0006: 0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch Patch0007: 0007-all-add-initial-LLVM-17-support.patch +# Better search paths for non-default LLVM. +Patch0008: 0008-Set-LLVM-search-paths-for-Fedora.patch + # Not supported upstream yet. ExcludeArch: ppc64le s390x # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval ExcludeArch: %{ix86} -BuildRequires: (clang-devel >= %{clang_llvm_version} with clang-devel < %{lua: print(tonumber(rpm.expand('%{clang_llvm_version}')) + 1)}) +BuildRequires: clang-devel(major) = %{clang_llvm_version} BuildRequires: golang(github.com/aykevl/go-wasm) BuildRequires: golang(github.com/blakesmith/ar) BuildRequires: chromium @@ -125,7 +128,7 @@ BuildRequires: binaryen >= 102 # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu -BuildRequires: lld +BuildRequires: lld(major) = %{clang_llvm_version} # BuildRequires: mingw64-crt # BuildRequires: mingw64-headers BuildRequires: nodejs @@ -136,9 +139,9 @@ BuildRequires: qemu-user # For GPG signature verification BuildRequires: gnupg2 -Requires: clang +Requires: clang(major) = %{clang_llvm_version} Requires: golang -Requires: lld +Requires: lld(major) = %{clang_llvm_version} # Add this when LLVM supports ESP natively. # Recommends: esptool # Recommends: mingw64-crt @@ -225,7 +228,17 @@ for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-e chmod -R a+rX ${target}/${libc} done done -%make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=llvm-ar LLVM_NM=llvm-nm +LLVM_AR=llvm-ar-%{clang_llvm_version} +if ! command -v $LLVM_AR 2>&1 >/dev/null +then +LLVM_AR=llvm-ar +fi +LLVM_NM=llvm-nm-%{clang_llvm_version} +if ! command -v $LLVM_NM 2>&1 >/dev/null +then +LLVM_NM=llvm-ar +fi +%make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=$LLVM_AR LLVM_NM=$LLVM_NM %install From 36b6b72c3d887df5a9ba46ea61a769a868be6871 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 4 Jan 2025 05:12:33 -0500 Subject: [PATCH 69/78] Update to 0.33.0 --- .gitignore | 43 +- 0001-Skip-WASI-tests.patch | 22 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 14 +- ...ional-packages-to-install-if-missing.patch | 4 +- ...ip-tests-that-require-Go-module-mode.patch | 58 +++ ...g-in-StringToBytes-optimization-pass.patch | 121 ----- ...005-Set-LLVM-search-paths-for-Fedora.patch | 64 ++- 0005-all-use-the-new-LLVM-pass-manager.patch | 424 ------------------ ...e-large-parts-of-picolibc-math-stdio.patch | 222 --------- ...ing-of-external-ld.lld-error-message.patch | 45 ++ 0007-all-add-initial-LLVM-17-support.patch | 157 ------- clean_tarballs.sh | 37 +- sources | 15 +- tinygo.spec | 131 +++--- 14 files changed, 269 insertions(+), 1088 deletions(-) create mode 100644 0004-Skip-tests-that-require-Go-module-mode.patch delete mode 100644 0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch rename 0008-Set-LLVM-search-paths-for-Fedora.patch => 0005-Set-LLVM-search-paths-for-Fedora.patch (72%) delete mode 100644 0005-all-use-the-new-LLVM-pass-manager.patch delete mode 100644 0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch create mode 100644 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch delete mode 100644 0007-all-add-initial-LLVM-17-support.patch diff --git a/.gitignore b/.gitignore index afc1724..0e53e41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,45 +1,18 @@ +/tinygo-*.tar.gz /avr-*.tar.gz /cmsis-*.tar.gz /cmsis-*-clean.tar.xz /cmsis_svd-*.tar.gz /cmsis_svd-*-clean.tar.xz +/cmsis_svd_data-*.tar.gz +/cmsis_svd_data-*-clean.tar.xz /compiler-rt-*.src.tar.xz /compiler-rt-*.src.tar.xz.sig +/macos-minimal-sdk-*.tar.gz +/mingw64-*.tar.gz +/musl-*.tar.gz +/musl-*.tar.gz.asc +/net-*.tar.gz /nrfx-*.tar.gz /picolibc-*.tar.gz /wasi-libc-*.tar.gz -/tinygo-0.6.0.tar.gz -/tinygo-0.7.0.tar.gz -/tinygo-0.7.1.tar.gz -/tinygo-0.8.0.tar.gz -/tinygo-0.9.0.tar.gz -/tinygo-0.10.0.tar.gz -/tinygo-0.11.0.tar.gz -/tinygo-0.12.0.tar.gz -/tinygo-0.13.0.tar.gz -/tinygo-0.13.1.tar.gz -/tinygo-0.14.0.tar.gz -/tinygo-0.14.1.tar.gz -/tinygo-0.15.0.tar.gz -/tinygo-0.16.0.tar.gz -/tinygo-0.17.0.tar.gz -/tinygo-0.18.0.tar.gz -/tinygo-0.19.0.tar.gz -/tinygo-0.20.0.tar.gz -/tinygo-0.21.0.tar.gz -/musl-1.2.2.tar.gz -/musl-1.2.2.tar.gz.asc -/tinygo-0.22.0.tar.gz -/musl-1.2.0.tar.gz -/musl-1.2.0.tar.gz.asc -/tinygo-0.23.0.tar.gz -/macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz -/tinygo-0.25.0.tar.gz -/tinygo-0.26.0.tar.gz -/tinygo-0.27.0.tar.gz -/musl-1.2.3.tar.gz -/musl-1.2.3.tar.gz.asc -/mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz -/tinygo-0.28.1.tar.gz -/tinygo-0.29.0.tar.gz -/tinygo-0.30.0.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index b8c5e6a..9b8492d 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,35 +1,39 @@ -From 7bbd6e2f039a54e73bb38cb6dd5397e84c8e851d Mon Sep 17 00:00:00 2001 +From 0395d806d83b1dffc5cd5e2c08c2d3771e585695 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/8] Skip WASI tests. +Subject: [PATCH 1/6] Skip WASI tests. We do not have wasmtime available. Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 5 ----- - 1 file changed, 5 deletions(-) + main_test.go | 9 --------- + 1 file changed, 9 deletions(-) diff --git a/main_test.go b/main_test.go -index ae7aed56..ac204f0c 100644 +index 836a4b17..21618761 100644 --- a/main_test.go +++ b/main_test.go -@@ -171,10 +171,6 @@ func TestBuild(t *testing.T) { +@@ -181,14 +181,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) - t.Run("WASI", func(t *testing.T) { - t.Parallel() -- runPlatTests(optionsFromTarget("wasi", sema), tests, t) +- runPlatTests(optionsFromTarget("wasip1", sema), tests, t) +- }) +- t.Run("WASIp2", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromTarget("wasip2", sema), tests, t) - }) } } -@@ -425,7 +421,6 @@ func TestTest(t *testing.T) { +@@ -535,7 +527,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, -- targ{"WASI", optionsFromTarget("wasi", sema)}, +- targ{"WASI", optionsFromTarget("wasip1", sema)}, ) } for _, targ := range targs { diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 40e3bac..6fe65c2 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From b7e64bf1bbcc720c2081d0f76a722b61d12e5b82 Mon Sep 17 00:00:00 2001 +From e782ed360fb028180e3c0a7f5ce1bac06b7ed035 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/6] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 19 insertions(+) diff --git a/main_test.go b/main_test.go -index ac204f0c..27344c27 100644 +index 21618761..0eae5141 100644 --- a/main_test.go +++ b/main_test.go -@@ -264,6 +264,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -296,6 +296,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -31,7 +31,7 @@ index ac204f0c..27344c27 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -342,6 +349,11 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -385,6 +392,11 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c t.Fatal(err) } @@ -42,8 +42,8 @@ index ac204f0c..27344c27 100644 + // Build the test binary. stdout := &bytes.Buffer{} - _, err = buildAndRun("./"+path, config, stdout, cmdArgs, environmentVars, time.Minute, func(cmd *exec.Cmd, result builder.BuildResult) error { -@@ -353,6 +365,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c + _, err = buildAndRun(pkgName, config, stdout, cmdArgs, environmentVars, time.Minute, func(cmd *exec.Cmd, result builder.BuildResult) error { +@@ -400,6 +412,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index a17c44d..c7894f2 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From fe776e032278a66e3e291a91bad59a3e411c9b57 Mon Sep 17 00:00:00 2001 +From 85d91373b6a302cc1f468adab6413472f56f295a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/8] Suggest optional packages to install if missing +Subject: [PATCH 3/6] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-Skip-tests-that-require-Go-module-mode.patch b/0004-Skip-tests-that-require-Go-module-mode.patch new file mode 100644 index 0000000..0777a68 --- /dev/null +++ b/0004-Skip-tests-that-require-Go-module-mode.patch @@ -0,0 +1,58 @@ +From 74d6f158651bcd5a923aaae31d93e01dbb35e4f7 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Wed, 28 Feb 2024 04:26:40 -0500 +Subject: [PATCH 4/6] Skip tests that require Go module mode + +Signed-off-by: Elliott Sales de Andrade +--- + errors_test.go | 2 +- + main_test.go | 2 +- + testdata/errors/loader-invaliddep.go | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/errors_test.go b/errors_test.go +index 62d5af2c..4a51da59 100644 +--- a/errors_test.go ++++ b/errors_test.go +@@ -34,7 +34,7 @@ func TestErrors(t *testing.T) { + {name: "loader-importcycle"}, + {name: "loader-invaliddep"}, + {name: "loader-invalidpackage"}, +- {name: "loader-nopackage"}, ++ // {name: "loader-nopackage"}, + {name: "optimizer"}, + {name: "syntax"}, + {name: "types"}, +diff --git a/main_test.go b/main_test.go +index 0eae5141..c2d0e088 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -72,7 +72,6 @@ func TestBuild(t *testing.T) { + "json.go", + "map.go", + "math.go", +- "oldgo/", + "print.go", + "reflect.go", + "slice.go", +@@ -668,6 +667,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { + } + + func TestGetListOfPackages(t *testing.T) { ++ t.Skip("Not available in non-module mode") + opts := optionsFromTarget("", sema) + tests := []struct { + pkgs []string +diff --git a/testdata/errors/loader-invaliddep.go b/testdata/errors/loader-invaliddep.go +index 05c2f2d5..719a617b 100644 +--- a/testdata/errors/loader-invaliddep.go ++++ b/testdata/errors/loader-invaliddep.go +@@ -5,4 +5,4 @@ import _ "github.com/tinygo-org/tinygo/testdata/errors/invaliddep" + func main() { + } + +-// ERROR: invaliddep{{[\\/]}}invaliddep.go:1:1: expected 'package', found ppackage ++// ERROR: {{.*}}invaliddep{{[\\/]}}invaliddep.go:1:1: expected 'package', found ppackage +-- +2.47.0 + diff --git a/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch b/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch deleted file mode 100644 index 7e0a470..0000000 --- a/0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch +++ /dev/null @@ -1,121 +0,0 @@ -From 930064c95f1cd6c0f7088b4f7785d754fa84cc01 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 21 Sep 2023 15:39:06 +0200 -Subject: [PATCH 4/8] transform: fix bug in StringToBytes optimization pass - -Previously, this pass would convert any read-only use of a -runtime.stringToBytes call to use the original string buffer instead. -This is incorrect: if there are any writes to the resulting buffer, none -of the slice buffer pointers can be converted to use the original -read-only string buffer. - -This commit fixes that bug and adds a test to prove the new (correct) -behavior. - -Signed-off-by: Elliott Sales de Andrade ---- - transform/rtcalls.go | 24 ++++++++++++++++++------ - transform/testdata/stringtobytes.ll | 16 ++++++++++++++++ - transform/testdata/stringtobytes.out.ll | 10 ++++++++++ - 3 files changed, 44 insertions(+), 6 deletions(-) - -diff --git a/transform/rtcalls.go b/transform/rtcalls.go -index 36d2853b..0b6feff2 100644 ---- a/transform/rtcalls.go -+++ b/transform/rtcalls.go -@@ -28,32 +28,44 @@ func OptimizeStringToBytes(mod llvm.Module) { - - // strptr is always constant because strings are always constant. - -- convertedAllUses := true -+ var pointerUses []llvm.Value -+ canConvertPointer := true - for _, use := range getUses(call) { - if use.IsAExtractValueInst().IsNil() { - // Expected an extractvalue, but this is something else. -- convertedAllUses = false -+ canConvertPointer = false - continue - } - switch use.Type().TypeKind() { - case llvm.IntegerTypeKind: - // A length (len or cap). Propagate the length value. -+ // This can always be done because the byte slice is always the -+ // same length as the original string. - use.ReplaceAllUsesWith(strlen) - use.EraseFromParentAsInstruction() - case llvm.PointerTypeKind: - // The string pointer itself. - if !isReadOnly(use) { -- convertedAllUses = false -+ // There is a store to the byte slice. This means that none -+ // of the pointer uses can't be propagated. -+ canConvertPointer = false - continue - } -- use.ReplaceAllUsesWith(strptr) -- use.EraseFromParentAsInstruction() -+ // It may be that the pointer value can be propagated, if all of -+ // the pointer uses are readonly. -+ pointerUses = append(pointerUses, use) - default: - // should not happen - panic("unknown return type of runtime.stringToBytes: " + use.Type().String()) - } - } -- if convertedAllUses { -+ if canConvertPointer { -+ // All pointer uses are readonly, so they can be converted. -+ for _, use := range pointerUses { -+ use.ReplaceAllUsesWith(strptr) -+ use.EraseFromParentAsInstruction() -+ } -+ - // Call to runtime.stringToBytes can be eliminated: both the input - // and the output is constant. - call.EraseFromParentAsInstruction() -diff --git a/transform/testdata/stringtobytes.ll b/transform/testdata/stringtobytes.ll -index fa43f3d0..06373a51 100644 ---- a/transform/testdata/stringtobytes.ll -+++ b/transform/testdata/stringtobytes.ll -@@ -30,3 +30,19 @@ entry: - call fastcc void @writeToSlice(ptr %1, i64 %2, i64 %3) - ret void - } -+ -+; Test that pointer values are never propagated if there is even a single write -+; to the pointer value (but len/cap values still can be). -+define void @testReadSome() { -+entry: -+ %s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) -+ %s.ptr = extractvalue { ptr, i64, i64 } %s, 0 -+ %s.len = extractvalue { ptr, i64, i64 } %s, 1 -+ %s.cap = extractvalue { ptr, i64, i64 } %s, 2 -+ call fastcc void @writeToSlice(ptr %s.ptr, i64 %s.len, i64 %s.cap) -+ %s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0 -+ %s.len2 = extractvalue { ptr, i64, i64 } %s, 1 -+ %s.cap2 = extractvalue { ptr, i64, i64 } %s, 2 -+ call fastcc void @printSlice(ptr %s.ptr2, i64 %s.len2, i64 %s.cap2) -+ ret void -+} -diff --git a/transform/testdata/stringtobytes.out.ll b/transform/testdata/stringtobytes.out.ll -index 30aa520a..b33a1755 100644 ---- a/transform/testdata/stringtobytes.out.ll -+++ b/transform/testdata/stringtobytes.out.ll -@@ -22,3 +22,13 @@ entry: - call fastcc void @writeToSlice(ptr %1, i64 6, i64 6) - ret void - } -+ -+define void @testReadSome() { -+entry: -+ %s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) -+ %s.ptr = extractvalue { ptr, i64, i64 } %s, 0 -+ call fastcc void @writeToSlice(ptr %s.ptr, i64 6, i64 6) -+ %s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0 -+ call fastcc void @printSlice(ptr %s.ptr2, i64 6, i64 6) -+ ret void -+} --- -2.47.0 - diff --git a/0008-Set-LLVM-search-paths-for-Fedora.patch b/0005-Set-LLVM-search-paths-for-Fedora.patch similarity index 72% rename from 0008-Set-LLVM-search-paths-for-Fedora.patch rename to 0005-Set-LLVM-search-paths-for-Fedora.patch index cdca4f6..38ac98a 100644 --- a/0008-Set-LLVM-search-paths-for-Fedora.patch +++ b/0005-Set-LLVM-search-paths-for-Fedora.patch @@ -1,19 +1,18 @@ -From 0e3fa31505241d5317eb61d78c2d3141b179e482 Mon Sep 17 00:00:00 2001 +From 15f17a3a4b59b199b5935d4da7ba6fcd4b69b765 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Oct 2024 23:33:18 -0400 -Subject: [PATCH 8/8] Set LLVM search paths for Fedora +Subject: [PATCH 5/6] Set LLVM search paths for Fedora Signed-off-by: Elliott Sales de Andrade --- - cgo/libclang_config_llvm15.go | 4 ++-- - cgo/libclang_config_llvm16.go | 4 ++-- - cgo/libclang_config_llvm17.go | 4 ++-- - cgo/libclang_config_llvm18.go | 15 +++++++++++++++ - 4 files changed, 21 insertions(+), 6 deletions(-) - create mode 100644 cgo/libclang_config_llvm18.go + cgo/libclang_config_llvm15.go | 4 ++-- + cgo/libclang_config_llvm16.go | 4 ++-- + cgo/libclang_config_llvm17.go | 4 ++-- + cgo/libclang_config_llvm18.go | 4 ++-- + 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cgo/libclang_config_llvm15.go b/cgo/libclang_config_llvm15.go -index e105dfe7..7e54fc9e 100644 +index edb1128d..0dc87193 100644 --- a/cgo/libclang_config_llvm15.go +++ b/cgo/libclang_config_llvm15.go @@ -3,11 +3,11 @@ @@ -27,11 +26,11 @@ index e105dfe7..7e54fc9e 100644 #cgo freebsd CFLAGS: -I/usr/local/llvm15/include -#cgo linux LDFLAGS: -L/usr/lib/llvm-15/lib -lclang +#cgo linux LDFLAGS: -L/usr/lib64/llvm15/lib -lclang - #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -lclang -lffi - #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -lclang -lffi + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -lclang + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -lclang #cgo freebsd LDFLAGS: -L/usr/local/llvm15/lib -lclang diff --git a/cgo/libclang_config_llvm16.go b/cgo/libclang_config_llvm16.go -index 28091701..e78f02ff 100644 +index ee354e21..4c338678 100644 --- a/cgo/libclang_config_llvm16.go +++ b/cgo/libclang_config_llvm16.go @@ -9,11 +9,11 @@ package cgo @@ -45,11 +44,11 @@ index 28091701..e78f02ff 100644 #cgo freebsd CFLAGS: -I/usr/local/llvm16/include -#cgo linux LDFLAGS: -L/usr/lib/llvm-16/lib -lclang +#cgo linux LDFLAGS: -L/usr/lib64/llvm16/lib -lclang - #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@16/lib -lclang -lffi - #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@16/lib -lclang -lffi + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@16/lib -lclang + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@16/lib -lclang #cgo freebsd LDFLAGS: -L/usr/local/llvm16/lib -lclang diff --git a/cgo/libclang_config_llvm17.go b/cgo/libclang_config_llvm17.go -index fd6d1480..fdf72400 100644 +index 6395d8a3..609b0758 100644 --- a/cgo/libclang_config_llvm17.go +++ b/cgo/libclang_config_llvm17.go @@ -3,11 +3,11 @@ @@ -63,30 +62,27 @@ index fd6d1480..fdf72400 100644 #cgo freebsd CFLAGS: -I/usr/local/llvm17/include -#cgo linux LDFLAGS: -L/usr/lib/llvm-17/lib -lclang +#cgo linux LDFLAGS: -L/usr/lib64/llvm17/lib -lclang - #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@17/lib -lclang -lffi - #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@17/lib -lclang -lffi + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@17/lib -lclang + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@17/lib -lclang #cgo freebsd LDFLAGS: -L/usr/local/llvm17/lib -lclang diff --git a/cgo/libclang_config_llvm18.go b/cgo/libclang_config_llvm18.go -new file mode 100644 -index 00000000..18db6c08 ---- /dev/null +index 3b769c62..18db6c08 100644 +--- a/cgo/libclang_config_llvm18.go +++ b/cgo/libclang_config_llvm18.go -@@ -0,0 +1,15 @@ -+//go:build !byollvm && !llvm15 && !llvm16 && !llvm17 -+ -+package cgo -+ -+/* +@@ -3,11 +3,11 @@ + package cgo + + /* +-#cgo linux CFLAGS: -I/usr/include/llvm-18 -I/usr/include/llvm-c-18 -I/usr/lib/llvm-18/include +#cgo linux CFLAGS: -I/usr/lib64/llvm18/include -+#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@18/include -+#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@18/include -+#cgo freebsd CFLAGS: -I/usr/local/llvm18/include + #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@18/include + #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@18/include + #cgo freebsd CFLAGS: -I/usr/local/llvm18/include +-#cgo linux LDFLAGS: -L/usr/lib/llvm-18/lib -lclang +#cgo linux LDFLAGS: -L/usr/lib64/llvm18/lib -lclang -+#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@18/lib -lclang -+#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@18/lib -lclang -+#cgo freebsd LDFLAGS: -L/usr/local/llvm18/lib -lclang -+*/ -+import "C" + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@18/lib -lclang + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@18/lib -lclang + #cgo freebsd LDFLAGS: -L/usr/local/llvm18/lib -lclang -- 2.47.0 diff --git a/0005-all-use-the-new-LLVM-pass-manager.patch b/0005-all-use-the-new-LLVM-pass-manager.patch deleted file mode 100644 index 5816031..0000000 --- a/0005-all-use-the-new-LLVM-pass-manager.patch +++ /dev/null @@ -1,424 +0,0 @@ -From 35221dacbc382c00d57055a3c327b8462282ddbf Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Tue, 19 Sep 2023 22:37:44 +0200 -Subject: [PATCH 5/8] all: use the new LLVM pass manager - -The old LLVM pass manager is deprecated and should not be used anymore. -Moreover, the pass manager builder (which we used to set up a pass -pipeline) is actually removed from LLVM entirely in LLVM 17: -https://reviews.llvm.org/D145387 -https://reviews.llvm.org/D145835 - -The new pass manager does change the binary size in many cases: both -growing and shrinking it. However, on average the binary size remains -more or less the same. - -This is needed as a preparation for LLVM 17. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/build.go | 19 +++-- - builder/sizes_test.go | 6 +- - compileopts/config.go | 12 ++-- - compiler/compiler_test.go | 12 ++-- - interp/interp_test.go | 9 +-- - transform/allocs_test.go | 11 +-- - transform/interface-lowering_test.go | 10 +-- - transform/maps_test.go | 11 +-- - transform/optimizer.go | 102 +++++++++------------------ - transform/transform.go | 2 +- - 10 files changed, 76 insertions(+), 118 deletions(-) - -diff --git a/builder/build.go b/builder/build.go -index dc360b92..d920a598 100644 ---- a/builder/build.go -+++ b/builder/build.go -@@ -83,8 +83,7 @@ type packageAction struct { - FileHashes map[string]string // hash of every file that's part of the package - EmbeddedFiles map[string]string // hash of all the //go:embed files in the package - Imports map[string]string // map from imported package to action ID hash -- OptLevel int // LLVM optimization level (0-3) -- SizeLevel int // LLVM optimization for size level (0-2) -+ OptLevel string // LLVM optimization level (O0, O1, O2, Os, Oz) - UndefinedGlobals []string // globals that are left as external globals (no initializer) - } - -@@ -158,7 +157,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe - return BuildResult{}, fmt.Errorf("unknown libc: %s", config.Target.Libc) - } - -- optLevel, sizeLevel, _ := config.OptLevels() -+ optLevel, speedLevel, sizeLevel := config.OptLevel() - compilerConfig := &compiler.Config{ - Triple: config.Triple(), - CPU: config.CPU(), -@@ -321,7 +320,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe - EmbeddedFiles: make(map[string]string, len(allFiles)), - Imports: make(map[string]string, len(pkg.Pkg.Imports())), - OptLevel: optLevel, -- SizeLevel: sizeLevel, - UndefinedGlobals: undefinedGlobals, - } - for filePath, hash := range pkg.FileHashes { -@@ -743,17 +741,17 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe - if config.GOOS() == "windows" { - // Options for the MinGW wrapper for the lld COFF linker. - ldflags = append(ldflags, -- "-Xlink=/opt:lldlto="+strconv.Itoa(optLevel), -+ "-Xlink=/opt:lldlto="+strconv.Itoa(speedLevel), - "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto")) - } else if config.GOOS() == "darwin" { - // Options for the ld64-compatible lld linker. - ldflags = append(ldflags, -- "--lto-O"+strconv.Itoa(optLevel), -+ "--lto-O"+strconv.Itoa(speedLevel), - "-cache_path_lto", filepath.Join(cacheDir, "thinlto")) - } else { - // Options for the ELF linker. - ldflags = append(ldflags, -- "--lto-O"+strconv.Itoa(optLevel), -+ "--lto-O"+strconv.Itoa(speedLevel), - "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"), - ) - } -@@ -1066,10 +1064,9 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error { - return err - } - -- // Optimization levels here are roughly the same as Clang, but probably not -- // exactly. -- optLevel, sizeLevel, inlinerThreshold := config.OptLevels() -- errs := transform.Optimize(mod, config, optLevel, sizeLevel, inlinerThreshold) -+ // Run most of the whole-program optimizations (including the whole -+ // O0/O1/O2/Os/Oz optimization pipeline). -+ errs := transform.Optimize(mod, config) - if len(errs) > 0 { - return newMultiError(errs) - } -diff --git a/builder/sizes_test.go b/builder/sizes_test.go -index 7aaab78a..dc45898e 100644 ---- a/builder/sizes_test.go -+++ b/builder/sizes_test.go -@@ -41,9 +41,9 @@ func TestBinarySize(t *testing.T) { - // This is a small number of very diverse targets that we want to test. - tests := []sizeTest{ - // microcontrollers -- {"hifive1b", "examples/echo", 4568, 280, 0, 2252}, -- {"microbit", "examples/serial", 2728, 388, 8, 2256}, -- {"wioterminal", "examples/pininterrupt", 5996, 1484, 116, 6816}, -+ {"hifive1b", "examples/echo", 4484, 280, 0, 2252}, -+ {"microbit", "examples/serial", 2724, 388, 8, 2256}, -+ {"wioterminal", "examples/pininterrupt", 6000, 1484, 116, 6816}, - - // TODO: also check wasm. Right now this is difficult, because - // wasm binaries are run through wasm-opt and therefore the -diff --git a/compileopts/config.go b/compileopts/config.go -index 39fc4f2a..5ad45c60 100644 ---- a/compileopts/config.go -+++ b/compileopts/config.go -@@ -145,18 +145,18 @@ func (c *Config) Serial() string { - - // OptLevels returns the optimization level (0-2), size level (0-2), and inliner - // threshold as used in the LLVM optimization pipeline. --func (c *Config) OptLevels() (optLevel, sizeLevel int, inlinerThreshold uint) { -+func (c *Config) OptLevel() (level string, speedLevel, sizeLevel int) { - switch c.Options.Opt { - case "none", "0": -- return 0, 0, 0 // -O0 -+ return "O0", 0, 0 - case "1": -- return 1, 0, 0 // -O1 -+ return "O1", 1, 0 - case "2": -- return 2, 0, 225 // -O2 -+ return "O2", 2, 0 - case "s": -- return 2, 1, 225 // -Os -+ return "Os", 2, 1 - case "z": -- return 2, 2, 5 // -Oz, default -+ return "Oz", 2, 2 // default - default: - // This is not shown to the user: valid choices are already checked as - // part of Options.Verify(). It is here as a sanity check. -diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go -index 92ce31b0..147e622a 100644 ---- a/compiler/compiler_test.go -+++ b/compiler/compiler_test.go -@@ -91,14 +91,12 @@ func TestCompiler(t *testing.T) { - } - - // Optimize IR a little. -- funcPasses := llvm.NewFunctionPassManagerForModule(mod) -- defer funcPasses.Dispose() -- funcPasses.AddInstructionCombiningPass() -- funcPasses.InitializeFunc() -- for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { -- funcPasses.RunFunc(fn) -+ passOptions := llvm.NewPassBuilderOptions() -+ defer passOptions.Dispose() -+ err = mod.RunPasses("instcombine", llvm.TargetMachine{}, passOptions) -+ if err != nil { -+ t.Error(err) - } -- funcPasses.FinalizeFunc() - - outFilePrefix := tc.file[:len(tc.file)-3] - if tc.target != "" { -diff --git a/interp/interp_test.go b/interp/interp_test.go -index fc567af2..cac56508 100644 ---- a/interp/interp_test.go -+++ b/interp/interp_test.go -@@ -77,12 +77,9 @@ func runTest(t *testing.T, pathPrefix string) { - } - - // Run some cleanup passes to get easy-to-read outputs. -- pm := llvm.NewPassManager() -- defer pm.Dispose() -- pm.AddGlobalOptimizerPass() -- pm.AddDeadStoreEliminationPass() -- pm.AddAggressiveDCEPass() -- pm.Run(mod) -+ to := llvm.NewPassBuilderOptions() -+ defer to.Dispose() -+ mod.RunPasses("globalopt,dse,adce", llvm.TargetMachine{}, to) - - // Read the expected output IR. - out, err := os.ReadFile(pathPrefix + ".out.ll") -diff --git a/transform/allocs_test.go b/transform/allocs_test.go -index 27bb9706..59a5b14e 100644 ---- a/transform/allocs_test.go -+++ b/transform/allocs_test.go -@@ -38,11 +38,12 @@ func TestAllocs2(t *testing.T) { - mod := compileGoFileForTesting(t, "./testdata/allocs2.go") - - // Run functionattrs pass, which is necessary for escape analysis. -- pm := llvm.NewPassManager() -- defer pm.Dispose() -- pm.AddInstructionCombiningPass() -- pm.AddFunctionAttrsPass() -- pm.Run(mod) -+ po := llvm.NewPassBuilderOptions() -+ defer po.Dispose() -+ err := mod.RunPasses("function(instcombine),function-attrs", llvm.TargetMachine{}, po) -+ if err != nil { -+ t.Error("failed to run passes:", err) -+ } - - // Run heap to stack transform. - var testOutputs []allocsTestOutput -diff --git a/transform/interface-lowering_test.go b/transform/interface-lowering_test.go -index 7bcce605..65f14dd9 100644 ---- a/transform/interface-lowering_test.go -+++ b/transform/interface-lowering_test.go -@@ -15,9 +15,11 @@ func TestInterfaceLowering(t *testing.T) { - t.Error(err) - } - -- pm := llvm.NewPassManager() -- defer pm.Dispose() -- pm.AddGlobalDCEPass() -- pm.Run(mod) -+ po := llvm.NewPassBuilderOptions() -+ defer po.Dispose() -+ err = mod.RunPasses("globaldce", llvm.TargetMachine{}, po) -+ if err != nil { -+ t.Error("failed to run passes:", err) -+ } - }) - } -diff --git a/transform/maps_test.go b/transform/maps_test.go -index e8b11133..329de698 100644 ---- a/transform/maps_test.go -+++ b/transform/maps_test.go -@@ -15,10 +15,11 @@ func TestOptimizeMaps(t *testing.T) { - - // Run an optimization pass, to clean up the result. - // This shows that all code related to the map is really eliminated. -- pm := llvm.NewPassManager() -- defer pm.Dispose() -- pm.AddDeadStoreEliminationPass() -- pm.AddAggressiveDCEPass() -- pm.Run(mod) -+ po := llvm.NewPassBuilderOptions() -+ defer po.Dispose() -+ err := mod.RunPasses("dse,adce", llvm.TargetMachine{}, po) -+ if err != nil { -+ t.Error("failed to run passes:", err) -+ } - }) - } -diff --git a/transform/optimizer.go b/transform/optimizer.go -index 20258ef4..42acc2dd 100644 ---- a/transform/optimizer.go -+++ b/transform/optimizer.go -@@ -14,54 +14,22 @@ import ( - // OptimizePackage runs optimization passes over the LLVM module for the given - // Go package. - func OptimizePackage(mod llvm.Module, config *compileopts.Config) { -- optLevel, sizeLevel, _ := config.OptLevels() -- -- // Run function passes for each function in the module. -- // These passes are intended to be run on each function right -- // after they're created to reduce IR size (and maybe also for -- // cache locality to improve performance), but for now they're -- // run here for each function in turn. Maybe this can be -- // improved in the future. -- builder := llvm.NewPassManagerBuilder() -- defer builder.Dispose() -- builder.SetOptLevel(optLevel) -- builder.SetSizeLevel(sizeLevel) -- funcPasses := llvm.NewFunctionPassManagerForModule(mod) -- defer funcPasses.Dispose() -- builder.PopulateFunc(funcPasses) -- funcPasses.InitializeFunc() -- for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { -- if fn.IsDeclaration() { -- continue -- } -- funcPasses.RunFunc(fn) -- } -- funcPasses.FinalizeFunc() -+ _, speedLevel, _ := config.OptLevel() - - // Run TinyGo-specific optimization passes. -- if optLevel > 0 { -+ if speedLevel > 0 { - OptimizeMaps(mod) - } - } - - // Optimize runs a number of optimization and transformation passes over the - // given module. Some passes are specific to TinyGo, others are generic LLVM --// passes. You can set a preferred performance (0-3) and size (0-2) level and --// control the limits of the inliner (higher numbers mean more inlining, set it --// to 0 to disable entirely). -+// passes. - // - // Please note that some optimizations are not optional, thus Optimize must --// alwasy be run before emitting machine code. Set all controls (optLevel, --// sizeLevel, inlinerThreshold) to 0 to reduce the number of optimizations to a --// minimum. --func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel int, inlinerThreshold uint) []error { -- builder := llvm.NewPassManagerBuilder() -- defer builder.Dispose() -- builder.SetOptLevel(optLevel) -- builder.SetSizeLevel(sizeLevel) -- if inlinerThreshold != 0 { -- builder.UseInlinerWithThreshold(inlinerThreshold) -- } -+// alwasy be run before emitting machine code. -+func Optimize(mod llvm.Module, config *compileopts.Config) []error { -+ optLevel, speedLevel, _ := config.OptLevel() - - // Make sure these functions are kept in tact during TinyGo transformation passes. - for _, name := range functionsUsedInTransforms { -@@ -84,23 +52,20 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i - } - } - -- if optLevel > 0 { -+ if speedLevel > 0 { - // Run some preparatory passes for the Go optimizer. -- goPasses := llvm.NewPassManager() -- defer goPasses.Dispose() -- goPasses.AddGlobalDCEPass() -- goPasses.AddGlobalOptimizerPass() -- goPasses.AddIPSCCPPass() -- goPasses.AddInstructionCombiningPass() // necessary for OptimizeReflectImplements -- goPasses.AddAggressiveDCEPass() -- goPasses.AddFunctionAttrsPass() -- goPasses.Run(mod) -+ po := llvm.NewPassBuilderOptions() -+ defer po.Dispose() -+ err := mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po) -+ if err != nil { -+ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} -+ } - - // Run TinyGo-specific optimization passes. - OptimizeStringToBytes(mod) - OptimizeReflectImplements(mod) - OptimizeAllocs(mod, nil, nil) -- err := LowerInterfaces(mod, config) -+ err = LowerInterfaces(mod, config) - if err != nil { - return []error{err} - } -@@ -113,7 +78,10 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i - // After interfaces are lowered, there are many more opportunities for - // interprocedural optimizations. To get them to work, function - // attributes have to be updated first. -- goPasses.Run(mod) -+ err = mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po) -+ if err != nil { -+ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} -+ } - - // Run TinyGo-specific interprocedural optimizations. - OptimizeAllocs(mod, config.Options.PrintAllocs, func(pos token.Position, msg string) { -@@ -134,10 +102,12 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i - } - - // Clean up some leftover symbols of the previous transformations. -- goPasses := llvm.NewPassManager() -- defer goPasses.Dispose() -- goPasses.AddGlobalDCEPass() -- goPasses.Run(mod) -+ po := llvm.NewPassBuilderOptions() -+ defer po.Dispose() -+ err = mod.RunPasses("globaldce", llvm.TargetMachine{}, po) -+ if err != nil { -+ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} -+ } - } - - if config.Scheduler() == "none" { -@@ -169,23 +139,15 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i - fn.SetLinkage(llvm.InternalLinkage) - } - -- // Run function passes again, because without it, llvm.coro.size.i32() -- // doesn't get lowered. -- funcPasses := llvm.NewFunctionPassManagerForModule(mod) -- defer funcPasses.Dispose() -- builder.PopulateFunc(funcPasses) -- funcPasses.InitializeFunc() -- for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { -- funcPasses.RunFunc(fn) -+ // Run the default pass pipeline. -+ // TODO: set the PrepareForThinLTO flag somehow. -+ po := llvm.NewPassBuilderOptions() -+ defer po.Dispose() -+ passes := fmt.Sprintf("default<%s>", optLevel) -+ err := mod.RunPasses(passes, llvm.TargetMachine{}, po) -+ if err != nil { -+ return []error{fmt.Errorf("could not build pass pipeline: %w", err)} - } -- funcPasses.FinalizeFunc() -- -- // Run module passes. -- // TODO: somehow set the PrepareForThinLTO flag in the pass manager builder. -- modPasses := llvm.NewPassManager() -- defer modPasses.Dispose() -- builder.Populate(modPasses) -- modPasses.Run(mod) - - hasGCPass := MakeGCStackSlots(mod) - if hasGCPass { -diff --git a/transform/transform.go b/transform/transform.go -index ab08317e..429cbd5f 100644 ---- a/transform/transform.go -+++ b/transform/transform.go -@@ -22,7 +22,7 @@ import ( - // the -opt= compiler flag. - func AddStandardAttributes(fn llvm.Value, config *compileopts.Config) { - ctx := fn.Type().Context() -- _, sizeLevel, _ := config.OptLevels() -+ _, _, sizeLevel := config.OptLevel() - if sizeLevel >= 1 { - fn.AddFunctionAttr(ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0)) - } --- -2.47.0 - diff --git a/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch b/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch deleted file mode 100644 index 9ec250f..0000000 --- a/0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch +++ /dev/null @@ -1,222 +0,0 @@ -From 2ad6ed3429443910fcb5baacb6a05a1bfe9351ae Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sat, 23 Sep 2023 14:57:25 +0200 -Subject: [PATCH 6/8] avr: don't compile large parts of picolibc (math, stdio) - -These parts aren't critical and lead to crashes on small chips without -long jumps (like the attiny85) with LLVM 17. (Older LLVM versions would -emit long jumps regardless, even if the chip didn't support those). - -For more information, see: https://github.com/llvm/llvm-project/issues/67042 - -Signed-off-by: Elliott Sales de Andrade ---- - builder/picolibc.go | 172 ++++++++++++++++++++++++-------------------- - 1 file changed, 93 insertions(+), 79 deletions(-) - -diff --git a/builder/picolibc.go b/builder/picolibc.go -index 1b7c748b..91ad27be 100644 ---- a/builder/picolibc.go -+++ b/builder/picolibc.go -@@ -3,6 +3,7 @@ package builder - import ( - "os" - "path/filepath" -+ "strings" - - "github.com/tinygo-org/tinygo/goenv" - ) -@@ -41,91 +42,23 @@ var Picolibc = Library{ - }, - sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib") }, - librarySources: func(target string) ([]string, error) { -- return picolibcSources, nil -+ sources := append([]string(nil), picolibcSources...) -+ if !strings.HasPrefix(target, "avr") { -+ // Small chips without long jumps can't compile many files (printf, -+ // pow, etc). Therefore exclude those source files for those chips. -+ // Unfortunately it's difficult to exclude only some chips, so this -+ // excludes those files on all AVR chips for now. -+ // More information: -+ // https://github.com/llvm/llvm-project/issues/67042 -+ sources = append(sources, picolibcSourcesLarge...) -+ } -+ return sources, nil - }, - } - - var picolibcSources = []string{ - "../../picolibc-stdio.c", - -- // srcs_tinystdio -- "libc/tinystdio/asprintf.c", -- "libc/tinystdio/bufio.c", -- "libc/tinystdio/clearerr.c", -- "libc/tinystdio/ecvt_r.c", -- "libc/tinystdio/ecvt.c", -- "libc/tinystdio/ecvtf_r.c", -- "libc/tinystdio/ecvtf.c", -- "libc/tinystdio/fcvt.c", -- "libc/tinystdio/fcvt_r.c", -- "libc/tinystdio/fcvtf.c", -- "libc/tinystdio/fcvtf_r.c", -- "libc/tinystdio/gcvt.c", -- "libc/tinystdio/gcvtf.c", -- "libc/tinystdio/fclose.c", -- "libc/tinystdio/fdevopen.c", -- "libc/tinystdio/feof.c", -- "libc/tinystdio/ferror.c", -- "libc/tinystdio/fflush.c", -- "libc/tinystdio/fgetc.c", -- "libc/tinystdio/fgets.c", -- "libc/tinystdio/fileno.c", -- "libc/tinystdio/filestrget.c", -- "libc/tinystdio/filestrput.c", -- "libc/tinystdio/filestrputalloc.c", -- "libc/tinystdio/fmemopen.c", -- "libc/tinystdio/fprintf.c", -- "libc/tinystdio/fputc.c", -- "libc/tinystdio/fputs.c", -- "libc/tinystdio/fread.c", -- //"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369 -- "libc/tinystdio/fscanf.c", -- "libc/tinystdio/fseek.c", -- "libc/tinystdio/fseeko.c", -- "libc/tinystdio/ftell.c", -- "libc/tinystdio/ftello.c", -- "libc/tinystdio/fwrite.c", -- "libc/tinystdio/getchar.c", -- "libc/tinystdio/gets.c", -- "libc/tinystdio/matchcaseprefix.c", -- "libc/tinystdio/mktemp.c", -- "libc/tinystdio/perror.c", -- "libc/tinystdio/printf.c", -- "libc/tinystdio/putchar.c", -- "libc/tinystdio/puts.c", -- "libc/tinystdio/rewind.c", -- "libc/tinystdio/scanf.c", -- "libc/tinystdio/setbuf.c", -- "libc/tinystdio/setbuffer.c", -- "libc/tinystdio/setlinebuf.c", -- "libc/tinystdio/setvbuf.c", -- "libc/tinystdio/snprintf.c", -- "libc/tinystdio/sprintf.c", -- "libc/tinystdio/snprintfd.c", -- "libc/tinystdio/snprintff.c", -- "libc/tinystdio/sprintff.c", -- "libc/tinystdio/sprintfd.c", -- "libc/tinystdio/sscanf.c", -- "libc/tinystdio/strfromf.c", -- "libc/tinystdio/strfromd.c", -- "libc/tinystdio/strtof.c", -- "libc/tinystdio/strtof_l.c", -- "libc/tinystdio/strtod.c", -- "libc/tinystdio/strtod_l.c", -- "libc/tinystdio/ungetc.c", -- "libc/tinystdio/vasprintf.c", -- "libc/tinystdio/vfiprintf.c", -- "libc/tinystdio/vfprintf.c", -- "libc/tinystdio/vfprintff.c", -- "libc/tinystdio/vfscanf.c", -- "libc/tinystdio/vfiscanf.c", -- "libc/tinystdio/vfscanff.c", -- "libc/tinystdio/vprintf.c", -- "libc/tinystdio/vscanf.c", -- "libc/tinystdio/vsscanf.c", -- "libc/tinystdio/vsnprintf.c", -- "libc/tinystdio/vsprintf.c", -- - "libc/string/bcmp.c", - "libc/string/bcopy.c", - "libc/string/bzero.c", -@@ -229,6 +162,87 @@ var picolibcSources = []string{ - "libc/string/wmempcpy.c", - "libc/string/wmemset.c", - "libc/string/xpg_strerror_r.c", -+} -+ -+// Parts of picolibc that are too large for small AVRs. -+var picolibcSourcesLarge = []string{ -+ // srcs_tinystdio -+ "libc/tinystdio/asprintf.c", -+ "libc/tinystdio/bufio.c", -+ "libc/tinystdio/clearerr.c", -+ "libc/tinystdio/ecvt_r.c", -+ "libc/tinystdio/ecvt.c", -+ "libc/tinystdio/ecvtf_r.c", -+ "libc/tinystdio/ecvtf.c", -+ "libc/tinystdio/fcvt.c", -+ "libc/tinystdio/fcvt_r.c", -+ "libc/tinystdio/fcvtf.c", -+ "libc/tinystdio/fcvtf_r.c", -+ "libc/tinystdio/gcvt.c", -+ "libc/tinystdio/gcvtf.c", -+ "libc/tinystdio/fclose.c", -+ "libc/tinystdio/fdevopen.c", -+ "libc/tinystdio/feof.c", -+ "libc/tinystdio/ferror.c", -+ "libc/tinystdio/fflush.c", -+ "libc/tinystdio/fgetc.c", -+ "libc/tinystdio/fgets.c", -+ "libc/tinystdio/fileno.c", -+ "libc/tinystdio/filestrget.c", -+ "libc/tinystdio/filestrput.c", -+ "libc/tinystdio/filestrputalloc.c", -+ "libc/tinystdio/fmemopen.c", -+ "libc/tinystdio/fprintf.c", -+ "libc/tinystdio/fputc.c", -+ "libc/tinystdio/fputs.c", -+ "libc/tinystdio/fread.c", -+ //"libc/tinystdio/freopen.c", // crashes with AVR, see: https://github.com/picolibc/picolibc/pull/369 -+ "libc/tinystdio/fscanf.c", -+ "libc/tinystdio/fseek.c", -+ "libc/tinystdio/fseeko.c", -+ "libc/tinystdio/ftell.c", -+ "libc/tinystdio/ftello.c", -+ "libc/tinystdio/fwrite.c", -+ "libc/tinystdio/getchar.c", -+ "libc/tinystdio/gets.c", -+ "libc/tinystdio/matchcaseprefix.c", -+ "libc/tinystdio/mktemp.c", -+ "libc/tinystdio/perror.c", -+ "libc/tinystdio/printf.c", -+ "libc/tinystdio/putchar.c", -+ "libc/tinystdio/puts.c", -+ "libc/tinystdio/rewind.c", -+ "libc/tinystdio/scanf.c", -+ "libc/tinystdio/setbuf.c", -+ "libc/tinystdio/setbuffer.c", -+ "libc/tinystdio/setlinebuf.c", -+ "libc/tinystdio/setvbuf.c", -+ "libc/tinystdio/snprintf.c", -+ "libc/tinystdio/sprintf.c", -+ "libc/tinystdio/snprintfd.c", -+ "libc/tinystdio/snprintff.c", -+ "libc/tinystdio/sprintff.c", -+ "libc/tinystdio/sprintfd.c", -+ "libc/tinystdio/sscanf.c", -+ "libc/tinystdio/strfromf.c", -+ "libc/tinystdio/strfromd.c", -+ "libc/tinystdio/strtof.c", -+ "libc/tinystdio/strtof_l.c", -+ "libc/tinystdio/strtod.c", -+ "libc/tinystdio/strtod_l.c", -+ "libc/tinystdio/ungetc.c", -+ "libc/tinystdio/vasprintf.c", -+ "libc/tinystdio/vfiprintf.c", -+ "libc/tinystdio/vfprintf.c", -+ "libc/tinystdio/vfprintff.c", -+ "libc/tinystdio/vfscanf.c", -+ "libc/tinystdio/vfiscanf.c", -+ "libc/tinystdio/vfscanff.c", -+ "libc/tinystdio/vprintf.c", -+ "libc/tinystdio/vscanf.c", -+ "libc/tinystdio/vsscanf.c", -+ "libc/tinystdio/vsnprintf.c", -+ "libc/tinystdio/vsprintf.c", - - "libm/common/sf_finite.c", - "libm/common/sf_copysign.c", --- -2.47.0 - diff --git a/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch b/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch new file mode 100644 index 0000000..ed55301 --- /dev/null +++ b/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch @@ -0,0 +1,45 @@ +From bc0fcf1b16b50738615df96f1f2f7e6e0267da9e Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 5 Jan 2025 02:20:33 -0500 +Subject: [PATCH 6/6] builder: Fix parsing of external ld.lld error messages + +If `ld.lld` is a version-specific binary (e.g., `ld.lld-18`), then its +error messages include the version. The parsing previously incorrectly +assumed it would be unversioned. + +Signed-off-by: Elliott Sales de Andrade +--- + builder/tools.go | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/builder/tools.go b/builder/tools.go +index bd18aa09..65d5c63b 100644 +--- a/builder/tools.go ++++ b/builder/tools.go +@@ -85,8 +85,8 @@ func parseLLDErrors(text string) error { + + // Check for undefined symbols. + // This can happen in some cases like with CGo and //go:linkname tricker. +- if matches := regexp.MustCompile(`^ld.lld: error: undefined symbol: (.*)\n`).FindStringSubmatch(message); matches != nil { +- symbolName := matches[1] ++ if matches := regexp.MustCompile(`^ld.lld(-[0-9]+)?: error: undefined symbol: (.*)\n`).FindStringSubmatch(message); matches != nil { ++ symbolName := matches[2] + for _, line := range strings.Split(message, "\n") { + matches := regexp.MustCompile(`referenced by .* \(((.*):([0-9]+))\)`).FindStringSubmatch(line) + if matches != nil { +@@ -105,9 +105,9 @@ func parseLLDErrors(text string) error { + } + + // Check for flash/RAM overflow. +- if matches := regexp.MustCompile(`^ld.lld: error: section '(.*?)' will not fit in region '(.*?)': overflowed by ([0-9]+) bytes$`).FindStringSubmatch(message); matches != nil { +- region := matches[2] +- n, err := strconv.ParseUint(matches[3], 10, 64) ++ if matches := regexp.MustCompile(`^ld.lld(-[0-9]+)?: error: section '(.*?)' will not fit in region '(.*?)': overflowed by ([0-9]+) bytes$`).FindStringSubmatch(message); matches != nil { ++ region := matches[3] ++ n, err := strconv.ParseUint(matches[4], 10, 64) + if err != nil { + // Should not happen at all (unless it overflows an uint64 for some reason). + continue +-- +2.47.0 + diff --git a/0007-all-add-initial-LLVM-17-support.patch b/0007-all-add-initial-LLVM-17-support.patch deleted file mode 100644 index 37591ba..0000000 --- a/0007-all-add-initial-LLVM-17-support.patch +++ /dev/null @@ -1,157 +0,0 @@ -From d4bda089b8e33050cf05e0d9fce0a73b0b13e014 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Sat, 23 Sep 2023 15:03:24 +0200 -Subject: [PATCH 7/8] all: add initial LLVM 17 support - -This allows us to test LLVM 17 already, before it's available in -Homebrew etc. - -Full support for LLVM 17 will have to wait until Espressif rebases their -Xtensa fork of LLVM. - -Signed-off-by: Elliott Sales de Andrade ---- - .circleci/config.yml | 13 +++++++++++-- - .github/workflows/build-macos.yml | 16 +++++++++++++--- - cgo/libclang_config_llvm16.go | 2 +- - cgo/libclang_config_llvm17.go | 15 +++++++++++++++ - go.mod | 2 +- - go.sum | 4 ++-- - 6 files changed, 43 insertions(+), 9 deletions(-) - create mode 100644 cgo/libclang_config_llvm17.go - -diff --git a/.circleci/config.yml b/.circleci/config.yml -index 1dff3ba7..86da321d 100644 ---- a/.circleci/config.yml -+++ b/.circleci/config.yml -@@ -55,7 +55,7 @@ commands: - - run: - name: "Install apt dependencies" - command: | -- echo 'deb https://apt.llvm.org/buster/ llvm-toolchain-buster-<> main' > /etc/apt/sources.list.d/llvm.list -+ echo 'deb https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-<> main' > /etc/apt/sources.list.d/llvm.list - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - - apt-get update - apt-get install --no-install-recommends -y \ -@@ -100,11 +100,18 @@ commands: - jobs: - test-llvm14-go118: - docker: -- - image: golang:1.18-buster -+ - image: golang:1.18-bullseye - steps: - - test-linux: - llvm: "14" - resource_class: large -+ test-llvm17-go121: -+ docker: -+ - image: golang:1.21-bullseye -+ steps: -+ - test-linux: -+ llvm: "17" -+ resource_class: large - - workflows: - test-all: -@@ -112,3 +119,5 @@ workflows: - # This tests our lowest supported versions of Go and LLVM, to make sure at - # least the smoke tests still pass. - - test-llvm14-go118 -+ # This tests the upcoming LLVM 17 support. -+ - test-llvm17-go121 -diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml -index 1284a4ed..be8bdb03 100644 ---- a/.github/workflows/build-macos.yml -+++ b/.github/workflows/build-macos.yml -@@ -116,11 +116,15 @@ jobs: - test-macos-homebrew: - name: homebrew-install - runs-on: macos-latest -+ strategy: -+ matrix: -+ version: [16, 17] - steps: -+ - name: Update Homebrew -+ run: brew update - - name: Install LLVM -- shell: bash - run: | -- HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@16 -+ HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@${{ matrix.version }} - - name: Checkout - uses: actions/checkout@v3 - - name: Install Go -@@ -128,7 +132,13 @@ jobs: - with: - go-version: '1.21' - cache: true -- - name: Build TinyGo -+ - name: Build TinyGo (LLVM ${{ matrix.version }}) -+ run: go install -tags=llvm${{ matrix.version }} -+ - name: Check binary -+ run: tinygo version -+ - name: Build TinyGo (default LLVM) -+ if: matrix.version == 16 - run: go install - - name: Check binary -+ if: matrix.version == 16 - run: tinygo version -diff --git a/cgo/libclang_config_llvm16.go b/cgo/libclang_config_llvm16.go -index 79aacd2f..28091701 100644 ---- a/cgo/libclang_config_llvm16.go -+++ b/cgo/libclang_config_llvm16.go -@@ -1,4 +1,4 @@ --//go:build !byollvm && !llvm14 && !llvm15 -+//go:build !byollvm && !llvm14 && !llvm15 && !llvm17 - - package cgo - -diff --git a/cgo/libclang_config_llvm17.go b/cgo/libclang_config_llvm17.go -new file mode 100644 -index 00000000..fd6d1480 ---- /dev/null -+++ b/cgo/libclang_config_llvm17.go -@@ -0,0 +1,15 @@ -+//go:build !byollvm && llvm17 -+ -+package cgo -+ -+/* -+#cgo linux CFLAGS: -I/usr/include/llvm-17 -I/usr/include/llvm-c-17 -I/usr/lib/llvm-17/include -+#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@17/include -+#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@17/include -+#cgo freebsd CFLAGS: -I/usr/local/llvm17/include -+#cgo linux LDFLAGS: -L/usr/lib/llvm-17/lib -lclang -+#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@17/lib -lclang -lffi -+#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@17/lib -lclang -lffi -+#cgo freebsd LDFLAGS: -L/usr/local/llvm17/lib -lclang -+*/ -+import "C" -diff --git a/go.mod b/go.mod -index 9af3402b..36d601f8 100644 ---- a/go.mod -+++ b/go.mod -@@ -18,7 +18,7 @@ require ( - golang.org/x/sys v0.11.0 - golang.org/x/tools v0.12.0 - gopkg.in/yaml.v2 v2.4.0 -- tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc -+ tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd - ) - - require ( -diff --git a/go.sum b/go.sum -index 587efdf2..1b5ad074 100644 ---- a/go.sum -+++ b/go.sum -@@ -65,5 +65,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 - gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= - gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= --tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc h1:IVX1dqCX3c88P7iEMBtz1xCAM4UIqCMgbqHdSefBaWE= --tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= -+tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd h1:iSVvs8r3ooxYTsmcf7FKCHq83eOSUkWKtmQhnDadDQU= -+tinygo.org/x/go-llvm v0.0.0-20230923132128-bba3c7009bfd/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= --- -2.47.0 - diff --git a/clean_tarballs.sh b/clean_tarballs.sh index 3e8e11d..6f47204 100755 --- a/clean_tarballs.sh +++ b/clean_tarballs.sh @@ -1,7 +1,7 @@ #!/bin/bash -e CMSIS_VERSION=9fe411cef1cef5de58e5957b89760759de44e393 -CMSIS_SVD_VERSION=df75ff974c76a911fc2815e29807f5ecaae06fc2 +CMSIS_SVD_DATA_VERSION=40327a4d2dff0992682be2872aaa6e096f35d2f4 if [ -e "cmsis-${CMSIS_VERSION}-clean.tar.xz" ]; then echo "Not downloading cmsis-${CMSIS_VERSION}-clean.tar.xz again!" @@ -16,8 +16,8 @@ tar cJf cmsis-${CMSIS_VERSION}-clean.tar.xz \ rm -r CMSIS-${CMSIS_VERSION}/ fi -if [ -e "cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz" ]; then -echo "Not downloading cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz again!" +if [ -e "cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}-clean.tar.xz" ]; then +echo "Not downloading cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}-clean.tar.xz again!" else # This is basically a "collection of random stuff" from various vendors, under # various licenses. Some licenses are non-free and some are actively hostile, @@ -27,32 +27,37 @@ else # - Espressif-Community: Apache-2.0 OR MIT # - Kendryte-Community: ISC # - NXP/L*: Proprietary, so not included. +# - NXP/Q*: Unknown, so not included. # - NXP/M*: BSD-3-Clause # - RaspberryPi: BSD-3-Clause # - SiFive-Community: ISC # - STMicro: Proprietary, so not included. # These directories are not used by TinyGo, so are not kept: # - ARM_SAMPLE: BSD-3-Clause +# - Allwinner-Community: Apache-2.0 OR MIT +# - ArteryTek: BSD-3-Clause # - Cypress: Apache-2.0 # - Freescale: Proprietary # - Fujitsu: Proprietary +# - GigaDevice: Apache-2.0 # - Holtek: Proprietary +# - Infineon: Proprietary # - Nordic: BSD-3-Clause # - Nuvoton: Unknown -# - SiliconLabs: Unknown +# - Renesas: Proprietary +# - SiliconLabs: Zlib # - Spansion: Proprietary # - TexasInstruments: Proprietary # - Toshiba: Unknown -#wget https://github.com/posborne/cmsis-svd/archive/${CMSIS_SVD_VERSION}/cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz -wget -nc https://github.com/tinygo-org/cmsis-svd/archive/${CMSIS_SVD_VERSION}/cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz -tar xf cmsis_svd-${CMSIS_SVD_VERSION}.tar.gz -tar cJf cmsis_svd-${CMSIS_SVD_VERSION}-clean.tar.xz \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/Atmel/ \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/Espressif/ \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/Espressif-Community/ \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/Kendryte-Community/ \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/NXP/M* \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/RaspberryPi/ \ - cmsis-svd-${CMSIS_SVD_VERSION}/data/SiFive-Community/ -rm -r cmsis-svd-${CMSIS_SVD_VERSION}/ +wget -nc https://github.com/cmsis-svd/cmsis-svd-data/archive/${CMSIS_SVD_DATA_VERSION}/cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}.tar.gz +tar xf cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}.tar.gz +tar cJf cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}-clean.tar.xz \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Atmel/ \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Espressif/ \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Espressif-Community/ \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Kendryte-Community/ \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/NXP/M* \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/RaspberryPi/ \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/SiFive-Community/ +rm -r cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/ fi diff --git a/sources b/sources index 92a1b43..43b242a 100644 --- a/sources +++ b/sources @@ -1,13 +1,14 @@ -SHA512 (tinygo-0.30.0.tar.gz) = 91c4b6a578d5730e6915d48c69f567b814d5d1201150df053f116b78be5c29553f2fa8bf05f4565ffb7d1acabc58819a1f0ef2beea9830c4cb99d69116ac4fee +SHA512 (tinygo-0.33.0.tar.gz) = 3f899d7486d71847bb1fc904e8ad8ecb3b3153475bae954df8e486fbc711622e36d9a2fb3b45fe52a9ed62c618cc5a2dd7bf73d2d25d86670636689712f8a5a9 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 -SHA512 (cmsis_svd-df75ff974c76a911fc2815e29807f5ecaae06fc2-clean.tar.xz) = 8abbc6f366aed9571a74a4b6e7065ed2d6a59e0495c3745681d9a654d61edd136319788741f7afc781211adb64ed1faeafe9d6acc6be5a16d9ee48e98c5ddeb1 -SHA512 (compiler-rt-17.0.1.src.tar.xz) = a440cca467e51cd7e3484adb8ea189ca1af61f9da928b17fed7ee48ebf3e997a55b4b5e0a8309c02a59b59be6ea8458745e9e898c403cfff83b93ff57fbf922d -SHA512 (compiler-rt-17.0.1.src.tar.xz.sig) = 5f8922e2e660e7b91c9a089caba51e8132c59f8502d39a70889b6508811dbbeece734a06b97ea366e87c023b957d09d6a62a06f7d848539bc894f6841084d61c -SHA512 (macos-minimal-sdk-ebb736fda2bec7cea38dcda807518b835a539525.tar.gz) = 2f97d5826c79116c851e1efde74faf806de56ac8acc5509d1ab7690d0edf88f6e227b273d2c5ef7d894a8ada2e316e285ef4e58d74ca0c6f91584653154eae10 +SHA512 (cmsis_svd_data-40327a4d2dff0992682be2872aaa6e096f35d2f4-clean.tar.xz) = 851179df0f9fb86b6c8c340659568bd367ffd9ac801f0bbf1a0a10713599c6e78fb5d0cb27ac31c6ea5d8c4f71c52f925bdeef0d49a8a93c63b62ef555423718 +SHA512 (compiler-rt-18.1.8.src.tar.xz) = fb8795bd51c9b005c2ad1975591e9e2715740d6407ccad41379f136ef2e8d24ded8b97b01165a3ae4bd377119a6a1049ca05d3220404fc12bee86114ff2bff0d +SHA512 (compiler-rt-18.1.8.src.tar.xz.sig) = 06d90afa46fb8c7ad6879564d1eb35e45711768593b580cf59e9908ed89efd459a312ae3c317c38119b0142ce0f96bcc0f8e6010ec8b31d9620c5e8f6d2f932e +SHA512 (macos-minimal-sdk-91ac2eabd80f10d95cb4255c78999d9d2c45a3be.tar.gz) = fff681d5dda92a4aa510a99c3f3c72640bcc2cb02fa7e5b506d988aabb3aa0c249f8ab3a7d2635733daabaa57ad35b59dad91af9a64b7d87a57bf1171ccdc6af +SHA512 (mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz) = 723d1ac22d8026f31b59d39328f711f36976798445a82daddcdc9fa6ab4346a5030e9c2efc84ef009439b8f021c5c7c120cfa083a7912a5b0212ac6852c005a7 SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c SHA512 (musl-1.2.3.tar.gz.asc) = 01a857dbc3981c90244d4d1d883efe51986652ca5734a741c9d1a4d06c5a22831e85520ac67212268b70c22049317a8f39b3219be182e7e67741add428ac5bc6 +SHA512 (net-c134160ae47d38b468b1c5ade43e78ad5a1e616d.tar.gz) = 449149af6bca15fa0fe1a9a8b37b3cab3bf83b177dd78d760fcca561bbacb415d6c7f0a355edf8d0de1b934d13fbce9d307c2a4410f1ff1c3bfe71b28e76b228 SHA512 (nrfx-d779b49fc59c7a165e7da1d7cd7d57b28a059f16.tar.gz) = 31c7fc6fd88d4a74e5739b29659cb717a4629480d17d84e491d61c36c435aba16d38ef63d1036e508666a17eeaac5f11a5ff83211f88410f30cc2e152146ee83 SHA512 (picolibc-b92edfda8ac6853772d87cadaeeeaa21b78609b6.tar.gz) = 9fb60d81bd98c96264c81e95cab6622ccacb34da285f7f3c137bd3cd8bc6e87cbc065a2e9d9fdfc7b93eec52f33bbfa70b6d0abc1a30551ebec1af351344cc39 -SHA512 (wasi-libc-30094b6ed05f19cee102115215863d185f2db4f0.tar.gz) = 17492263fd5dca422f19e0ff8533e1f440e3b7516dc24ef0d16fdc44832cc63ec288c9e930f63b47fb71497144fed55cc313acc74339d067b8d4f5c7c683df0f -SHA512 (mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz) = 723d1ac22d8026f31b59d39328f711f36976798445a82daddcdc9fa6ab4346a5030e9c2efc84ef009439b8f021c5c7c120cfa083a7912a5b0212ac6852c005a7 +SHA512 (wasi-libc-wasi-sdk-20.tar.gz) = e264240dc7dbcf6398c8ca09bc108298f4a8aa955af22de5a3015fbcde81cb09dd83cd48349090082d5de0e8a3dbcf746c7b14657c67657b3f2f1ab28bb9cf05 diff --git a/tinygo.spec b/tinygo.spec index 0b2794a..80840e8 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -1,24 +1,29 @@ -# Generated by go2rpm 1 -%bcond_without check +%bcond check 1 +# I'm not sure what this is for, as no tests seem to use it, and it introduces +# some weird license that needs review. +%bcond wasi_cli 0 %global __brp_strip_lto %{nil} %global __brp_strip_static_archive %{nil} # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.30.0 +Version: 0.33.0 -%global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 -%global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 -%global clang_llvm_version 17 -%global cmsis_svd_commit df75ff974c76a911fc2815e29807f5ecaae06fc2 -%global compiler_rt_version %{clang_llvm_version}.0.1 -%global macos_minsdk_commit ebb736fda2bec7cea38dcda807518b835a539525 -%global musl_version 1.2.3 -%global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 -%global picolibc_commit b92edfda8ac6853772d87cadaeeeaa21b78609b6 -%global wasi_libc_commit 30094b6ed05f19cee102115215863d185f2db4f0 -%global mingw64_commit 8526cb618269440a94810b94b77f8bd48c5c3396 +%global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 +%global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%global clang_llvm_version 18 +%global cmsis_svd_data_commit 40327a4d2dff0992682be2872aaa6e096f35d2f4 +%global compiler_rt_version %{clang_llvm_version}.1.8 +%global macos_minsdk_commit 91ac2eabd80f10d95cb4255c78999d9d2c45a3be +%global mingw64_commit 8526cb618269440a94810b94b77f8bd48c5c3396 +%global musl_version 1.2.3 +%global net_commit c134160ae47d38b468b1c5ade43e78ad5a1e616d +%global nrfx_commit d779b49fc59c7a165e7da1d7cd7d57b28a059f16 +%global picolibc_commit b92edfda8ac6853772d87cadaeeeaa21b78609b6 +%global wasi_libc_version 20 +%global wasi_libc_tag wasi-sdk-%{wasi_libc_version} +%global wasi_cli_version 0.2.0 # No longer matching regular Go's /usr/share/gocode because it also provides # pre-compiled binaries, and symlinks to arch-specific clang headers. @@ -41,13 +46,13 @@ Summary: Go compiler for small places # Main files: BSD-3-Clause # builder/cc1as.*: Apache-2.0 WITH LLVM-exception # corpus_test.go: MIT -# src/net: BSD-2-Clause # CMSIS: BSD-3-Clause (subsetted) # avr-mcu: Apache-2.0 (packs) AND MIT (Rust code, unused by this package) # cmsis-svd: Apache-2.0 AND (Apache-2.0 OR MIT) AND BSD-3-Clause AND BSD-Source-Code AND ISC AND MIT (subsetted) # compiler-rt: Apache-2.0 WITH LLVM-exception OR NCSA OR MIT # macos-minimal-sdk: APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSD-4-Clause-UC AND ISC AND LicenseRef-Fedora-Public-Domain # musl: MIT +# net: BSD-2-Clause # nrfx: BSD-3-Clause AND Apache-2.0 # picolibc: BSD-2-Clause AND BSD-2-Clause-FreeBSD AND BSD-3-Clause AND ISC AND SMLNJ AND Spencer-94 AND GPLv2 (testing code only, unused by this package) # wasi-libc: Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT AND BSD-2-Clause AND CC0-1.0 (dlmalloc implementation, unused by this package) @@ -62,7 +67,7 @@ Source0: %{gosource} Source1: clean_tarballs.sh Source2: cmsis-%{CMSIS_commit}-clean.tar.xz Source3: https://github.com/avr-rust/avr-mcu/archive/%{avr_commit}/avr-%{avr_commit}.tar.gz -Source4: cmsis_svd-%{cmsis_svd_commit}-clean.tar.xz +Source4: cmsis_svd_data-%{cmsis_svd_data_commit}-clean.tar.xz Source50: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz Source51: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz.sig Source52: https://src.fedoraproject.org/rpms/compiler-rt/raw/f8e98d51f0c3fdbaa9ce5d99816930e4fcbe504b/f/release-keys.asc#/compiler-rt-release-keys.asc @@ -72,30 +77,29 @@ Source62: https://musl.libc.org/musl.pub Source7: https://github.com/aykevl/macos-minimal-sdk/archive/%{macos_minsdk_commit}/macos-minimal-sdk-%{macos_minsdk_commit}.tar.gz Source8: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz Source9: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz -Source10: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz +Source10: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_tag}/wasi-libc-%{wasi_libc_tag}.tar.gz Source11: https://github.com/mingw-w64/mingw-w64/archive/%{mingw64_commit}/mingw64-%{mingw64_commit}.tar.gz +Source12: https://github.com/tinygo-org/net/archive/%{net_commit}/net-%{net_commit}.tar.gz +%if %{with wasi_cli} +Source13: https://github.com/WebAssembly/wasi-cli/archive/v%{wasi_cli_version}/wasi-cli-%{wasi_cli_version}.tar.gz +%endif + # We don't have wasmtime to run these. -Patch0001: 0001-Skip-WASI-tests.patch +Patch: 0001-Skip-WASI-tests.patch # Unbundling things # Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0002: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +Patch: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch # Add Fedora specific dnf instructions -Patch0003: 0003-Suggest-optional-packages-to-install-if-missing.patch - -# Support LLVM 17. -# https://github.com/tinygo-org/tinygo/pull/3923 -Patch0004: 0004-transform-fix-bug-in-StringToBytes-optimization-pass.patch -# https://github.com/tinygo-org/tinygo/pull/3918 -Patch0005: 0005-all-use-the-new-LLVM-pass-manager.patch -# https://github.com/tinygo-org/tinygo/pull/3913 -Patch0006: 0006-avr-don-t-compile-large-parts-of-picolibc-math-stdio.patch -Patch0007: 0007-all-add-initial-LLVM-17-support.patch - +Patch: 0003-Suggest-optional-packages-to-install-if-missing.patch +# We set GO111MODULE=off during tests, so can't run a few of them. +Patch: 0004-Skip-tests-that-require-Go-module-mode.patch # Better search paths for non-default LLVM. -Patch0008: 0008-Set-LLVM-search-paths-for-Fedora.patch +Patch: 0005-Set-LLVM-search-paths-for-Fedora.patch +# https://github.com/tinygo-org/tinygo/pull/4686 +Patch: 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch # Not supported upstream yet. ExcludeArch: ppc64le s390x @@ -112,26 +116,27 @@ BuildRequires: golang(github.com/gofrs/flock) >= 0.8.1 BuildRequires: golang(github.com/google/shlex) BuildRequires: golang(github.com/inhies/go-bytesize) BuildRequires: golang(github.com/marcinbor85/gohex) -BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.8 +BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.13 BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 +BuildRequires: golang(golang.org/x/net/http/httpguts) >= 0.26 BuildRequires: golang(github.com/sigurn/crc16) BuildRequires: golang(go.bug.st/serial) >= 1.6.0 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) -BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.11 +BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.21 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: golang-tests BuildRequires: llvm-devel(major) = %{clang_llvm_version} BuildRequires: make -BuildRequires: binaryen >= 102 +BuildRequires: binaryen >= 116 # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu BuildRequires: lld(major) = %{clang_llvm_version} # BuildRequires: mingw64-crt # BuildRequires: mingw64-headers -BuildRequires: nodejs +BuildRequires: nodejs >= 18 BuildRequires: qemu-system-arm-core BuildRequires: qemu-system-riscv-core BuildRequires: qemu-user @@ -154,7 +159,7 @@ Recommends: qemu-user Provides: bundled(compiler-rt) = %{compiler_rt_version} Provides: bundled(musl) = %{musl_version} Provides: bundled(picolibc) = %{picolibc_commit} -Provides: bundled(wasi-libc) = %{wasi_libc_commit} +Provides: bundled(wasi-libc) = %{wasi_libc_version} %description %{common_description} @@ -176,7 +181,7 @@ mv lib/avr-mcu-%{avr_commit} lib/avr tar -C lib -xf %{SOURCE4} rmdir lib/cmsis-svd -mv lib/cmsis-svd-%{cmsis_svd_commit} lib/cmsis-svd +mv lib/cmsis-svd-data-%{cmsis_svd_data_commit} lib/cmsis-svd # Verify *before* actually unpacking! %{gpgverify} --keyring='%{SOURCE52}' --signature='%{SOURCE51}' --data='%{SOURCE50}' @@ -207,27 +212,28 @@ mv lib/picolibc-%{picolibc_commit} lib/picolibc tar -C lib -xf %{SOURCE10} rmdir lib/wasi-libc -mv lib/wasi-libc-%{wasi_libc_commit} lib/wasi-libc +mv lib/wasi-libc-%{wasi_libc_tag} lib/wasi-libc tar -C lib -xf %{SOURCE11} rmdir lib/mingw-w64 mv lib/mingw-w64-%{mingw64_commit} lib/mingw-w64 +tar -C src -xf %{SOURCE12} +rmdir src/net +mv src/net-%{net_commit} src/net + +%if %{with wasi_cli} +tar -C lib -xf %{SOURCE13} +rmdir lib/wasi-cli +mv lib/wasi-cli-%{wasi_cli_version} lib/wasi-cli +%endif + %build # Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is # merged and released. export BUILDTAGS="llvm%{clang_llvm_version}" LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} GO111MODULE=off %make_build gen-device STM32=0 -for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-eabi-cortex-m0plus thumbv7em-unknown-unknown-eabi-cortex-m4; do - mkdir -p ${target} - for libc in compiler-rt picolibc; do - TINYGOROOT=$PWD \ - %{gobuilddir}/bin/tinygo \ - build-library -target=${target#*eabi-} -o ${target}/${libc} ${libc} - chmod -R a+rX ${target}/${libc} - done -done LLVM_AR=llvm-ar-%{clang_llvm_version} if ! command -v $LLVM_AR 2>&1 >/dev/null then @@ -259,6 +265,8 @@ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-comm cp -rp lib/mingw-w64/mingw-w64-crt/def-include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/api-ms-win-crt-* %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/kernel32.def.in %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/stdio +cp -rp lib/mingw-w64/mingw-w64-crt/stdio/ucrt_* %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/stdio install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers/defaults cp -rp lib/mingw-w64/mingw-w64-headers/crt/ %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers cp -rp lib/mingw-w64/mingw-w64-headers/defaults/include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers/defaults @@ -270,6 +278,7 @@ cp -rp lib/musl/arch/aarch64 %{buildroot}%{tinygoroot}/lib/musl/arch cp -rp lib/musl/arch/arm %{buildroot}%{tinygoroot}/lib/musl/arch cp -rp lib/musl/arch/generic %{buildroot}%{tinygoroot}/lib/musl/arch cp -rp lib/musl/arch/i386 %{buildroot}%{tinygoroot}/lib/musl/arch +cp -rp lib/musl/arch/mips %{buildroot}%{tinygoroot}/lib/musl/arch cp -rp lib/musl/arch/x86_64 %{buildroot}%{tinygoroot}/lib/musl/arch install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl/crt cp -rp lib/musl/crt/crt1.c %{buildroot}%{tinygoroot}/lib/musl/crt @@ -280,9 +289,12 @@ cp -rp lib/musl/src/exit %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/include %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/internal %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/legacy %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/linux %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/locale %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/malloc %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/mman %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/math %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/multibyte %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/signal %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/stdio %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/string %{buildroot}%{tinygoroot}/lib/musl/src @@ -292,6 +304,24 @@ cp -rp lib/musl/src/unistd %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/nrfx %{buildroot}%{tinygoroot}/lib/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc cp -rp lib/wasi-libc/sysroot %{buildroot}%{tinygoroot}/lib/wasi-libc/ +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half/headers +cp -rp lib/wasi-libc/libc-bottom-half/headers/public %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half/headers +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl +cp -rp lib/wasi-libc/libc-top-half/musl/include %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/arch +cp -rp lib/wasi-libc/libc-top-half/musl/arch/generic %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/arch +cp -rp lib/wasi-libc/libc-top-half/musl/arch/wasm32 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/arch +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/include %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/internal %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/math %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/string %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +%if %{with wasi_cli} +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-cli +cp -rp lib/wasi-cli/wit %{buildroot}%{tinygoroot}/lib/wasi-cli/wit +%endif install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc cp -rp lib/picolibc/newlib/libc/ctype %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc chmod -x %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libc/ctype/{mkcaseconv,mkcategories,mkunidata} @@ -305,13 +335,6 @@ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc/newlib/libm/common %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc/newlib/libm/math %{buildroot}%{tinygoroot}/lib/picolibc/newlib/libm cp -rp lib/picolibc-stdio.c %{buildroot}%{tinygoroot}/lib -install -vdm 0755 %{buildroot}%{tinygoroot}/pkg -for target in thumbv6m-unknown-unknown-eabi-cortex-m0 thumbv6m-unknown-unknown-eabi-cortex-m0plus thumbv7em-unknown-unknown-eabi-cortex-m4; do - install -vdm 0755 %{buildroot}%{tinygoroot}/pkg/${target} - for libc in compiler-rt picolibc; do - cp -rp ${target}/${libc} %{buildroot}%{tinygoroot}/pkg/${target}/ - done -done cp -rp src %{buildroot}%{tinygoroot}/ rm %{buildroot}%{tinygoroot}/src/examples/wasm/.gitignore cp -rp targets %{buildroot}%{tinygoroot}/ From 5f84d1ac7a10f216b8617765976d1f85f9f138cf Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 31 Dec 2024 03:39:09 -0500 Subject: [PATCH 70/78] Update to 0.34.0 --- 0001-Skip-WASI-tests.patch | 10 +++--- ...oss-Linux-tests-where-qemu-is-broken.patch | 18 +++++----- ...ional-packages-to-install-if-missing.patch | 8 ++--- ...ip-tests-that-require-Go-module-mode.patch | 16 ++++----- 0005-Set-LLVM-search-paths-for-Fedora.patch | 4 +-- ...-Add-flag-to-skip-Renesas-SVD-builds.patch | 29 ++++++++++++++++ ...malize-expected-path-for-chdir-tests.patch | 33 +++++++++++++++++++ ...ing-of-external-ld.lld-error-message.patch | 10 +++--- sources | 4 +-- tinygo.spec | 19 ++++++++--- 10 files changed, 112 insertions(+), 39 deletions(-) create mode 100644 0006-Add-flag-to-skip-Renesas-SVD-builds.patch create mode 100644 0007-Normalize-expected-path-for-chdir-tests.patch rename 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch => 0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch (86%) diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 9b8492d..67fb988 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From 0395d806d83b1dffc5cd5e2c08c2d3771e585695 Mon Sep 17 00:00:00 2001 +From f0ed6e6aa02bdb74e0cee40e5ac1b100e0e3fcea Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/6] Skip WASI tests. +Subject: [PATCH 1/8] Skip WASI tests. We do not have wasmtime available. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 9 deletions(-) diff --git a/main_test.go b/main_test.go -index 836a4b17..21618761 100644 +index 136128d5..b48e9eef 100644 --- a/main_test.go +++ b/main_test.go -@@ -181,14 +181,6 @@ func TestBuild(t *testing.T) { +@@ -195,14 +195,6 @@ func TestBuild(t *testing.T) { t.Parallel() runPlatTests(optionsFromTarget("wasm", sema), tests, t) }) @@ -29,7 +29,7 @@ index 836a4b17..21618761 100644 } } -@@ -535,7 +527,6 @@ func TestTest(t *testing.T) { +@@ -809,7 +801,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch index 6fe65c2..db48b94 100644 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -1,7 +1,7 @@ -From e782ed360fb028180e3c0a7f5ce1bac06b7ed035 Mon Sep 17 00:00:00 2001 +From 2df64834032a8224809485cffac7c30ce589753f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/6] Skip some cross Linux tests where qemu is broken +Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken The upstream issues will hopefully be fixed soon: @@ -14,10 +14,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 19 insertions(+) diff --git a/main_test.go b/main_test.go -index 21618761..0eae5141 100644 +index b48e9eef..b5a152ce 100644 --- a/main_test.go +++ b/main_test.go -@@ -296,6 +296,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { +@@ -325,6 +325,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { } func emuCheck(t *testing.T, options compileopts.Options) { @@ -31,7 +31,7 @@ index 21618761..0eae5141 100644 // Check if the emulator is installed. spec, err := compileopts.LoadTarget(&options) if err != nil { -@@ -385,6 +392,11 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -410,6 +417,11 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c t.Fatal(err) } @@ -43,7 +43,7 @@ index 21618761..0eae5141 100644 // Build the test binary. stdout := &bytes.Buffer{} _, err = buildAndRun(pkgName, config, stdout, cmdArgs, environmentVars, time.Minute, func(cmd *exec.Cmd, result builder.BuildResult) error { -@@ -400,6 +412,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c +@@ -425,6 +437,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c return } @@ -54,9 +54,9 @@ index 21618761..0eae5141 100644 + return + } + - // putchar() prints CRLF, convert it to LF. - actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1) - expected = bytes.Replace(expected, []byte{'\r', '\n'}, []byte{'\n'}, -1) // for Windows + actual := stdout.Bytes() + if config.EmulatorName() == "simavr" { + // Strip simavr log formatting. -- 2.47.0 diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch index c7894f2..1c5b4ba 100644 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ b/0003-Suggest-optional-packages-to-install-if-missing.patch @@ -1,7 +1,7 @@ -From 85d91373b6a302cc1f468adab6413472f56f295a Mon Sep 17 00:00:00 2001 +From 19a6901099ee8adbb5f085c5e98334019b9e92e9 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/6] Suggest optional packages to install if missing +Subject: [PATCH 3/8] Suggest optional packages to install if missing Signed-off-by: Elliott Sales de Andrade --- @@ -9,7 +9,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 17 insertions(+) diff --git a/builder/jobs.go b/builder/jobs.go -index a23d0753..2380f683 100644 +index 11688746..cc561763 100644 --- a/builder/jobs.go +++ b/builder/jobs.go @@ -7,6 +7,7 @@ import ( @@ -20,7 +20,7 @@ index a23d0753..2380f683 100644 "runtime" "sort" "strings" -@@ -37,6 +38,22 @@ type compileJob struct { +@@ -29,6 +30,22 @@ type compileJob struct { duration time.Duration // how long it took to run this job (only set after finishing) } diff --git a/0004-Skip-tests-that-require-Go-module-mode.patch b/0004-Skip-tests-that-require-Go-module-mode.patch index 0777a68..1f84e14 100644 --- a/0004-Skip-tests-that-require-Go-module-mode.patch +++ b/0004-Skip-tests-that-require-Go-module-mode.patch @@ -1,7 +1,7 @@ -From 74d6f158651bcd5a923aaae31d93e01dbb35e4f7 Mon Sep 17 00:00:00 2001 +From 31b8b93dea42516caabf904f02172eef9350ff80 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Feb 2024 04:26:40 -0500 -Subject: [PATCH 4/6] Skip tests that require Go module mode +Subject: [PATCH 4/8] Skip tests that require Go module mode Signed-off-by: Elliott Sales de Andrade --- @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/errors_test.go b/errors_test.go -index 62d5af2c..4a51da59 100644 +index fe118616..16421eee 100644 --- a/errors_test.go +++ b/errors_test.go -@@ -34,7 +34,7 @@ func TestErrors(t *testing.T) { +@@ -36,7 +36,7 @@ func TestErrors(t *testing.T) { {name: "loader-importcycle"}, {name: "loader-invaliddep"}, {name: "loader-invalidpackage"}, @@ -24,18 +24,18 @@ index 62d5af2c..4a51da59 100644 {name: "syntax"}, {name: "types"}, diff --git a/main_test.go b/main_test.go -index 0eae5141..c2d0e088 100644 +index b5a152ce..6991b5a1 100644 --- a/main_test.go +++ b/main_test.go -@@ -72,7 +72,6 @@ func TestBuild(t *testing.T) { +@@ -76,7 +76,6 @@ func TestBuild(t *testing.T) { "json.go", "map.go", "math.go", - "oldgo/", "print.go", "reflect.go", - "slice.go", -@@ -668,6 +667,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { + "signal.go", +@@ -942,6 +941,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { } func TestGetListOfPackages(t *testing.T) { diff --git a/0005-Set-LLVM-search-paths-for-Fedora.patch b/0005-Set-LLVM-search-paths-for-Fedora.patch index 38ac98a..6030480 100644 --- a/0005-Set-LLVM-search-paths-for-Fedora.patch +++ b/0005-Set-LLVM-search-paths-for-Fedora.patch @@ -1,7 +1,7 @@ -From 15f17a3a4b59b199b5935d4da7ba6fcd4b69b765 Mon Sep 17 00:00:00 2001 +From 71d2c05e4733c76590443c46d1f32a66fff33a35 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Oct 2024 23:33:18 -0400 -Subject: [PATCH 5/6] Set LLVM search paths for Fedora +Subject: [PATCH 5/8] Set LLVM search paths for Fedora Signed-off-by: Elliott Sales de Andrade --- diff --git a/0006-Add-flag-to-skip-Renesas-SVD-builds.patch b/0006-Add-flag-to-skip-Renesas-SVD-builds.patch new file mode 100644 index 0000000..6662288 --- /dev/null +++ b/0006-Add-flag-to-skip-Renesas-SVD-builds.patch @@ -0,0 +1,29 @@ +From c249a5e2553f6c2d15623d4f1a1e9b09ae729c34 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 31 Dec 2024 00:34:13 -0500 +Subject: [PATCH 6/8] Add flag to skip Renesas SVD builds + +Signed-off-by: Elliott Sales de Andrade +--- + GNUmakefile | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/GNUmakefile b/GNUmakefile +index fd2d282c..f173486c 100644 +--- a/GNUmakefile ++++ b/GNUmakefile +@@ -185,7 +185,10 @@ fmt-check: ## Warn if any source needs reformatting + @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 + + +-gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp gen-device-renesas ## Generate microcontroller-specific sources ++gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp ## Generate microcontroller-specific sources ++ifneq ($(RENESAS), 0) ++gen-device: gen-device-renesas ++endif + ifneq ($(STM32), 0) + gen-device: gen-device-stm32 + endif +-- +2.47.0 + diff --git a/0007-Normalize-expected-path-for-chdir-tests.patch b/0007-Normalize-expected-path-for-chdir-tests.patch new file mode 100644 index 0000000..5880eb7 --- /dev/null +++ b/0007-Normalize-expected-path-for-chdir-tests.patch @@ -0,0 +1,33 @@ +From f3d14b6d0ce2b680f0ca8e298818e2b11817aeaf Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 31 Dec 2024 02:00:17 -0500 +Subject: [PATCH 7/8] Normalize expected path for chdir tests + +The expected path comes from a simple string concatenation in shell, but +`os.Getwd` appears to have the normalized working directory, so this can +fail if any parent directory is a symlink. + +Signed-off-by: Elliott Sales de Andrade +--- + tests/testing/chdir/chdir.go | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/tests/testing/chdir/chdir.go b/tests/testing/chdir/chdir.go +index 75281c21..660b25ac 100644 +--- a/tests/testing/chdir/chdir.go ++++ b/tests/testing/chdir/chdir.go +@@ -20,6 +20,11 @@ func main() { + } + if runtime.GOOS == "windows" { + cwd = filepath.ToSlash(cwd) ++ } else { ++ expectDir, err = filepath.EvalSymlinks(expectDir) ++ if err != nil { ++ log.Fatal(err) ++ } + } + if cwd != expectDir { + log.Fatalf("expected:\"%v\" != os.Getwd():\"%v\"", expectDir, cwd) +-- +2.47.0 + diff --git a/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch b/0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch similarity index 86% rename from 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch rename to 0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch index ed55301..e7d8f9b 100644 --- a/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch +++ b/0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch @@ -1,7 +1,7 @@ -From bc0fcf1b16b50738615df96f1f2f7e6e0267da9e Mon Sep 17 00:00:00 2001 +From 0c8f59a18436d7405ad5977b4ebb607a2d3ef7d1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 5 Jan 2025 02:20:33 -0500 -Subject: [PATCH 6/6] builder: Fix parsing of external ld.lld error messages +Subject: [PATCH 8/8] builder: Fix parsing of external ld.lld error messages If `ld.lld` is a version-specific binary (e.g., `ld.lld-18`), then its error messages include the version. The parsing previously incorrectly @@ -13,10 +13,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builder/tools.go b/builder/tools.go -index bd18aa09..65d5c63b 100644 +index b4087828..1c4214da 100644 --- a/builder/tools.go +++ b/builder/tools.go -@@ -85,8 +85,8 @@ func parseLLDErrors(text string) error { +@@ -98,8 +98,8 @@ func parseLLDErrors(text string) error { // Check for undefined symbols. // This can happen in some cases like with CGo and //go:linkname tricker. @@ -27,7 +27,7 @@ index bd18aa09..65d5c63b 100644 for _, line := range strings.Split(message, "\n") { matches := regexp.MustCompile(`referenced by .* \(((.*):([0-9]+))\)`).FindStringSubmatch(line) if matches != nil { -@@ -105,9 +105,9 @@ func parseLLDErrors(text string) error { +@@ -118,9 +118,9 @@ func parseLLDErrors(text string) error { } // Check for flash/RAM overflow. diff --git a/sources b/sources index 43b242a..b36c23c 100644 --- a/sources +++ b/sources @@ -1,10 +1,10 @@ -SHA512 (tinygo-0.33.0.tar.gz) = 3f899d7486d71847bb1fc904e8ad8ecb3b3153475bae954df8e486fbc711622e36d9a2fb3b45fe52a9ed62c618cc5a2dd7bf73d2d25d86670636689712f8a5a9 +SHA512 (tinygo-0.34.0.tar.gz) = 2c6c4b8b727540c6d83d6429125a8011cc049b9670e92e1fc31a4da74be4c078b19eec8f324b5dd7becb389ef15f613b619a29fa3b1ecc4208ddcb5d662708b5 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd_data-40327a4d2dff0992682be2872aaa6e096f35d2f4-clean.tar.xz) = 851179df0f9fb86b6c8c340659568bd367ffd9ac801f0bbf1a0a10713599c6e78fb5d0cb27ac31c6ea5d8c4f71c52f925bdeef0d49a8a93c63b62ef555423718 SHA512 (compiler-rt-18.1.8.src.tar.xz) = fb8795bd51c9b005c2ad1975591e9e2715740d6407ccad41379f136ef2e8d24ded8b97b01165a3ae4bd377119a6a1049ca05d3220404fc12bee86114ff2bff0d SHA512 (compiler-rt-18.1.8.src.tar.xz.sig) = 06d90afa46fb8c7ad6879564d1eb35e45711768593b580cf59e9908ed89efd459a312ae3c317c38119b0142ce0f96bcc0f8e6010ec8b31d9620c5e8f6d2f932e -SHA512 (macos-minimal-sdk-91ac2eabd80f10d95cb4255c78999d9d2c45a3be.tar.gz) = fff681d5dda92a4aa510a99c3f3c72640bcc2cb02fa7e5b506d988aabb3aa0c249f8ab3a7d2635733daabaa57ad35b59dad91af9a64b7d87a57bf1171ccdc6af +SHA512 (macos-minimal-sdk-4e4113e3b1244b8fdc5e1486577f25e22d63f36e.tar.gz) = 10de6205ee6f7c6079e1120d4f42a72b984e1727a81a8f7fc9c9d4dd16e51c71291ab9d4fd88b36843b2b39a3c981fe4007b93ebaf920627f524417fbfdc823a SHA512 (mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz) = 723d1ac22d8026f31b59d39328f711f36976798445a82daddcdc9fa6ab4346a5030e9c2efc84ef009439b8f021c5c7c120cfa083a7912a5b0212ac6852c005a7 SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c SHA512 (musl-1.2.3.tar.gz.asc) = 01a857dbc3981c90244d4d1d883efe51986652ca5734a741c9d1a4d06c5a22831e85520ac67212268b70c22049317a8f39b3219be182e7e67741add428ac5bc6 diff --git a/tinygo.spec b/tinygo.spec index 80840e8..466597c 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -8,14 +8,14 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.33.0 +Version: 0.34.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 %global clang_llvm_version 18 %global cmsis_svd_data_commit 40327a4d2dff0992682be2872aaa6e096f35d2f4 %global compiler_rt_version %{clang_llvm_version}.1.8 -%global macos_minsdk_commit 91ac2eabd80f10d95cb4255c78999d9d2c45a3be +%global macos_minsdk_commit 4e4113e3b1244b8fdc5e1486577f25e22d63f36e %global mingw64_commit 8526cb618269440a94810b94b77f8bd48c5c3396 %global musl_version 1.2.3 %global net_commit c134160ae47d38b468b1c5ade43e78ad5a1e616d @@ -98,8 +98,12 @@ Patch: 0003-Suggest-optional-packages-to-install-if-missing.patch Patch: 0004-Skip-tests-that-require-Go-module-mode.patch # Better search paths for non-default LLVM. Patch: 0005-Set-LLVM-search-paths-for-Fedora.patch +# We can't include these due to poor licensing. +Patch: 0006-Add-flag-to-skip-Renesas-SVD-builds.patch +#https://github.com/tinygo-org/tinygo/pull/4677 +Patch: 0007-Normalize-expected-path-for-chdir-tests.patch # https://github.com/tinygo-org/tinygo/pull/4686 -Patch: 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch +Patch: 0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch # Not supported upstream yet. ExcludeArch: ppc64le s390x @@ -118,6 +122,7 @@ BuildRequires: golang(github.com/inhies/go-bytesize) BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.13 BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 +BuildRequires: golang(github.com/tetratelabs/wazero) >= 1.6 BuildRequires: golang(golang.org/x/net/http/httpguts) >= 0.26 BuildRequires: golang(github.com/sigurn/crc16) BuildRequires: golang(go.bug.st/serial) >= 1.6.0 @@ -228,12 +233,18 @@ rmdir lib/wasi-cli mv lib/wasi-cli-%{wasi_cli_version} lib/wasi-cli %endif +# Fix permissions +# https://github.com/tinygo-org/tinygo/pull/4676 +chmod -x \ + src/internal/wasi/cli/v0.2.0/command/command.wit \ + src/internal/wasi/*/v0.2.0/*/*.wasm.go + %build # Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is # merged and released. export BUILDTAGS="llvm%{clang_llvm_version}" LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} -GO111MODULE=off %make_build gen-device STM32=0 +GO111MODULE=off %make_build gen-device RENESAS=0 STM32=0 LLVM_AR=llvm-ar-%{clang_llvm_version} if ! command -v $LLVM_AR 2>&1 >/dev/null then From 4bdd7c5cf353d8a2790c6b84943870f643550a50 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 5 Jan 2025 18:40:10 -0500 Subject: [PATCH 71/78] Remove older patches - QEMU is no longer broken for the cases we need. - The optional package suggestion was never fully implemented, so drop it for now. --- 0001-Skip-WASI-tests.patch | 4 +- ...oss-Linux-tests-where-qemu-is-broken.patch | 62 ------------------- ...ip-tests-that-require-Go-module-mode.patch | 8 +-- ...003-Set-LLVM-search-paths-for-Fedora.patch | 4 +- ...ional-packages-to-install-if-missing.patch | 48 -------------- ...-Add-flag-to-skip-Renesas-SVD-builds.patch | 4 +- ...malize-expected-path-for-chdir-tests.patch | 4 +- ...ing-of-external-ld.lld-error-message.patch | 4 +- tinygo.spec | 18 ++---- 9 files changed, 19 insertions(+), 137 deletions(-) delete mode 100644 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch rename 0004-Skip-tests-that-require-Go-module-mode.patch => 0002-Skip-tests-that-require-Go-module-mode.patch (88%) rename 0005-Set-LLVM-search-paths-for-Fedora.patch => 0003-Set-LLVM-search-paths-for-Fedora.patch (97%) delete mode 100644 0003-Suggest-optional-packages-to-install-if-missing.patch rename 0006-Add-flag-to-skip-Renesas-SVD-builds.patch => 0004-Add-flag-to-skip-Renesas-SVD-builds.patch (90%) rename 0007-Normalize-expected-path-for-chdir-tests.patch => 0005-Normalize-expected-path-for-chdir-tests.patch (88%) rename 0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch => 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch (93%) diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 67fb988..a9cd369 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From f0ed6e6aa02bdb74e0cee40e5ac1b100e0e3fcea Mon Sep 17 00:00:00 2001 +From fdea482c9630b297ccdb7232c9a3dc28f753c912 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/8] Skip WASI tests. +Subject: [PATCH 1/6] Skip WASI tests We do not have wasmtime available. diff --git a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch deleted file mode 100644 index db48b94..0000000 --- a/0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 2df64834032a8224809485cffac7c30ce589753f Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 2/8] Skip some cross Linux tests where qemu is broken - -The upstream issues will hopefully be fixed soon: - -- https://gitlab.com/qemu-project/qemu/-/issues/447 -- https://gitlab.com/qemu-project/qemu/-/issues/690 - -Signed-off-by: Elliott Sales de Andrade ---- - main_test.go | 19 +++++++++++++++++++ - 1 file changed, 19 insertions(+) - -diff --git a/main_test.go b/main_test.go -index b48e9eef..b5a152ce 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -325,6 +325,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { - } - - func emuCheck(t *testing.T, options compileopts.Options) { -+ // Skip running the test executable due to bugs in qemu. -+ // https://gitlab.com/qemu-project/qemu/-/issues/447 -+ // https://gitlab.com/qemu-project/qemu/-/issues/690 -+ if runtime.GOARCH == "arm64" && (options.GOARCH == "386" || options.GOARCH == "arm") { -+ t.Skip("qemu is broken for this host/target architecture combination") -+ } -+ - // Check if the emulator is installed. - spec, err := compileopts.LoadTarget(&options) - if err != nil { -@@ -410,6 +417,11 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c - t.Fatal(err) - } - -+ if runtime.GOARCH == "arm64" && options.GOARCH == "amd64" && name == "reflect.go" { -+ // https://github.com/tinygo-org/tinygo/issues/3888 -+ t.Skip("qemu is broken for this host/target architecture combination") -+ } -+ - // Build the test binary. - stdout := &bytes.Buffer{} - _, err = buildAndRun(pkgName, config, stdout, cmdArgs, environmentVars, time.Minute, func(cmd *exec.Cmd, result builder.BuildResult) error { -@@ -425,6 +437,13 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c - return - } - -+ // Skip running the test executable due to bugs in qemu. -+ // https://gitlab.com/qemu-project/qemu/-/issues/447 -+ // https://gitlab.com/qemu-project/qemu/-/issues/690 -+ if runtime.GOARCH == "arm64" && (options.GOARCH == "386" || options.GOARCH == "arm") { -+ return -+ } -+ - actual := stdout.Bytes() - if config.EmulatorName() == "simavr" { - // Strip simavr log formatting. --- -2.47.0 - diff --git a/0004-Skip-tests-that-require-Go-module-mode.patch b/0002-Skip-tests-that-require-Go-module-mode.patch similarity index 88% rename from 0004-Skip-tests-that-require-Go-module-mode.patch rename to 0002-Skip-tests-that-require-Go-module-mode.patch index 1f84e14..f1fdc1a 100644 --- a/0004-Skip-tests-that-require-Go-module-mode.patch +++ b/0002-Skip-tests-that-require-Go-module-mode.patch @@ -1,7 +1,7 @@ -From 31b8b93dea42516caabf904f02172eef9350ff80 Mon Sep 17 00:00:00 2001 +From 791e9bf907c5c968f9e4b38c0d8c9083d42e82dd Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Feb 2024 04:26:40 -0500 -Subject: [PATCH 4/8] Skip tests that require Go module mode +Subject: [PATCH 2/6] Skip tests that require Go module mode Signed-off-by: Elliott Sales de Andrade --- @@ -24,7 +24,7 @@ index fe118616..16421eee 100644 {name: "syntax"}, {name: "types"}, diff --git a/main_test.go b/main_test.go -index b5a152ce..6991b5a1 100644 +index b48e9eef..c7b11229 100644 --- a/main_test.go +++ b/main_test.go @@ -76,7 +76,6 @@ func TestBuild(t *testing.T) { @@ -35,7 +35,7 @@ index b5a152ce..6991b5a1 100644 "print.go", "reflect.go", "signal.go", -@@ -942,6 +941,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { +@@ -923,6 +922,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { } func TestGetListOfPackages(t *testing.T) { diff --git a/0005-Set-LLVM-search-paths-for-Fedora.patch b/0003-Set-LLVM-search-paths-for-Fedora.patch similarity index 97% rename from 0005-Set-LLVM-search-paths-for-Fedora.patch rename to 0003-Set-LLVM-search-paths-for-Fedora.patch index 6030480..a619e68 100644 --- a/0005-Set-LLVM-search-paths-for-Fedora.patch +++ b/0003-Set-LLVM-search-paths-for-Fedora.patch @@ -1,7 +1,7 @@ -From 71d2c05e4733c76590443c46d1f32a66fff33a35 Mon Sep 17 00:00:00 2001 +From d18d696a118fa2078daf4cecb87cf1c64680ccb2 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Oct 2024 23:33:18 -0400 -Subject: [PATCH 5/8] Set LLVM search paths for Fedora +Subject: [PATCH 3/6] Set LLVM search paths for Fedora Signed-off-by: Elliott Sales de Andrade --- diff --git a/0003-Suggest-optional-packages-to-install-if-missing.patch b/0003-Suggest-optional-packages-to-install-if-missing.patch deleted file mode 100644 index 1c5b4ba..0000000 --- a/0003-Suggest-optional-packages-to-install-if-missing.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 19a6901099ee8adbb5f085c5e98334019b9e92e9 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 3/8] Suggest optional packages to install if missing - -Signed-off-by: Elliott Sales de Andrade ---- - builder/jobs.go | 17 +++++++++++++++++ - 1 file changed, 17 insertions(+) - -diff --git a/builder/jobs.go b/builder/jobs.go -index 11688746..cc561763 100644 ---- a/builder/jobs.go -+++ b/builder/jobs.go -@@ -7,6 +7,7 @@ import ( - "container/heap" - "errors" - "fmt" -+ "os" - "runtime" - "sort" - "strings" -@@ -29,6 +30,22 @@ type compileJob struct { - duration time.Duration // how long it took to run this job (only set after finishing) - } - -+// checkIfPackagedFileExistsJob returns a new *compileJob that checks if a file -+// exists. If the file does not exist, the job will fail with an error -+// suggesting to install the named system packageToInstall. -+func checkIfPackagedFileExistsJob(fileName, packageToInstall string) *compileJob { -+ return &compileJob{ -+ description: fmt.Sprintf("check if %v exists", fileName), -+ result: fileName, -+ run: func(*compileJob) (err error) { -+ if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) { -+ return fmt.Errorf("%v does not exist; please install %v via dnf", fileName, packageToInstall) -+ } -+ return nil -+ }, -+ } -+} -+ - // dummyCompileJob returns a new *compileJob that produces an output without - // doing anything. This can be useful where a *compileJob producing an output is - // expected but nothing needs to be done, for example for a load from a cache. --- -2.47.0 - diff --git a/0006-Add-flag-to-skip-Renesas-SVD-builds.patch b/0004-Add-flag-to-skip-Renesas-SVD-builds.patch similarity index 90% rename from 0006-Add-flag-to-skip-Renesas-SVD-builds.patch rename to 0004-Add-flag-to-skip-Renesas-SVD-builds.patch index 6662288..1b2a44e 100644 --- a/0006-Add-flag-to-skip-Renesas-SVD-builds.patch +++ b/0004-Add-flag-to-skip-Renesas-SVD-builds.patch @@ -1,7 +1,7 @@ -From c249a5e2553f6c2d15623d4f1a1e9b09ae729c34 Mon Sep 17 00:00:00 2001 +From 40a1ef5d46b91cf32f09be7e6247ae1c32bd0dbd Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 31 Dec 2024 00:34:13 -0500 -Subject: [PATCH 6/8] Add flag to skip Renesas SVD builds +Subject: [PATCH 4/6] Add flag to skip Renesas SVD builds Signed-off-by: Elliott Sales de Andrade --- diff --git a/0007-Normalize-expected-path-for-chdir-tests.patch b/0005-Normalize-expected-path-for-chdir-tests.patch similarity index 88% rename from 0007-Normalize-expected-path-for-chdir-tests.patch rename to 0005-Normalize-expected-path-for-chdir-tests.patch index 5880eb7..9425503 100644 --- a/0007-Normalize-expected-path-for-chdir-tests.patch +++ b/0005-Normalize-expected-path-for-chdir-tests.patch @@ -1,7 +1,7 @@ -From f3d14b6d0ce2b680f0ca8e298818e2b11817aeaf Mon Sep 17 00:00:00 2001 +From 89167785ea2820fd19444b5c02c937486c6c4ad7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 31 Dec 2024 02:00:17 -0500 -Subject: [PATCH 7/8] Normalize expected path for chdir tests +Subject: [PATCH 5/6] Normalize expected path for chdir tests The expected path comes from a simple string concatenation in shell, but `os.Getwd` appears to have the normalized working directory, so this can diff --git a/0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch b/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch similarity index 93% rename from 0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch rename to 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch index e7d8f9b..c471e58 100644 --- a/0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch +++ b/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch @@ -1,7 +1,7 @@ -From 0c8f59a18436d7405ad5977b4ebb607a2d3ef7d1 Mon Sep 17 00:00:00 2001 +From 7c03dcc9f5b8e632f1d33dc4e09f74853c1951cc Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 5 Jan 2025 02:20:33 -0500 -Subject: [PATCH 8/8] builder: Fix parsing of external ld.lld error messages +Subject: [PATCH 6/6] builder: Fix parsing of external ld.lld error messages If `ld.lld` is a version-specific binary (e.g., `ld.lld-18`), then its error messages include the version. The parsing previously incorrectly diff --git a/tinygo.spec b/tinygo.spec index 466597c..6b0d279 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -86,24 +86,16 @@ Source13: https://github.com/WebAssembly/wasi-cli/archive/v%{wasi_cli_vers # We don't have wasmtime to run these. Patch: 0001-Skip-WASI-tests.patch -# Unbundling things -# Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch -# Skip testing some things where qemu is broken: -# https://gitlab.com/qemu-project/qemu/-/issues/447 -# https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch: 0002-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch -# Add Fedora specific dnf instructions -Patch: 0003-Suggest-optional-packages-to-install-if-missing.patch # We set GO111MODULE=off during tests, so can't run a few of them. -Patch: 0004-Skip-tests-that-require-Go-module-mode.patch +Patch: 0002-Skip-tests-that-require-Go-module-mode.patch # Better search paths for non-default LLVM. -Patch: 0005-Set-LLVM-search-paths-for-Fedora.patch +Patch: 0003-Set-LLVM-search-paths-for-Fedora.patch # We can't include these due to poor licensing. -Patch: 0006-Add-flag-to-skip-Renesas-SVD-builds.patch +Patch: 0004-Add-flag-to-skip-Renesas-SVD-builds.patch #https://github.com/tinygo-org/tinygo/pull/4677 -Patch: 0007-Normalize-expected-path-for-chdir-tests.patch +Patch: 0005-Normalize-expected-path-for-chdir-tests.patch # https://github.com/tinygo-org/tinygo/pull/4686 -Patch: 0008-builder-Fix-parsing-of-external-ld.lld-error-message.patch +Patch: 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch # Not supported upstream yet. ExcludeArch: ppc64le s390x From 98fdc4179f488b2d37157a60ce55bba0b538ffdb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 20 Jul 2025 04:07:35 -0400 Subject: [PATCH 72/78] Update to latest version (#2266297) --- .gitignore | 1 + 0001-Skip-WASI-tests.patch | 32 ++-- ...ip-tests-that-require-Go-module-mode.patch | 14 +- 0003-Set-LLVM-search-paths-for-Fedora.patch | 46 ++++- ...-Add-flag-to-skip-Renesas-SVD-builds.patch | 8 +- ...malize-expected-path-for-chdir-tests.patch | 4 +- 0006-Skip-x86-tests-on-ARM.patch | 44 +++++ ...ing-of-external-ld.lld-error-message.patch | 45 ----- ...312c689a004434cb77f161f65b9615c98036.patch | 69 ++++++++ clean_tarballs.sh | 16 +- musl-cve-2025-26519-1.patch | 38 +++++ musl-cve-2025-26519-2.patch | 38 +++++ sources | 7 +- tinygo.spec | 158 +++++++++++++----- 14 files changed, 395 insertions(+), 125 deletions(-) create mode 100644 0006-Skip-x86-tests-on-ARM.patch delete mode 100644 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch create mode 100644 1b5d312c689a004434cb77f161f65b9615c98036.patch create mode 100644 musl-cve-2025-26519-1.patch create mode 100644 musl-cve-2025-26519-2.patch diff --git a/.gitignore b/.gitignore index 0e53e41..18595d5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ /nrfx-*.tar.gz /picolibc-*.tar.gz /wasi-libc-*.tar.gz +/bdwgc-1166f11f7dee08d7ad369296b24cf8c9582f8789.tar.gz diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index a9cd369..8a26135 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,35 +1,43 @@ -From fdea482c9630b297ccdb7232c9a3dc28f753c912 Mon Sep 17 00:00:00 2001 +From cedd957d01a235fa05957242ea5c291b0fbc2e3d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/6] Skip WASI tests +Subject: [PATCH 1/6] Skip WASI tests. We do not have wasmtime available. Signed-off-by: Elliott Sales de Andrade --- - main_test.go | 9 --------- - 1 file changed, 9 deletions(-) + main_test.go | 17 ----------------- + 1 file changed, 17 deletions(-) diff --git a/main_test.go b/main_test.go -index 136128d5..b48e9eef 100644 +index 5563b7ca..77b93c4d 100644 --- a/main_test.go +++ b/main_test.go -@@ -195,14 +195,6 @@ func TestBuild(t *testing.T) { - t.Parallel() - runPlatTests(optionsFromTarget("wasm", sema), tests, t) +@@ -188,22 +188,6 @@ func TestBuild(t *testing.T) { + runTest("gc.go", optionsBoehm, t, nil, nil) + }) }) -- t.Run("WASI", func(t *testing.T) { +- t.Run("WASIp1", func(t *testing.T) { - t.Parallel() - runPlatTests(optionsFromTarget("wasip1", sema), tests, t) +- +- // Test with -gc=boehm. +- t.Run("gc.go-boehm", func(t *testing.T) { +- t.Parallel() +- optionsBoehm := optionsFromTarget("wasip1", sema) +- optionsBoehm.GC = "boehm" +- runTest("gc.go", optionsBoehm, t, nil, nil) +- }) - }) - t.Run("WASIp2", func(t *testing.T) { - t.Parallel() - runPlatTests(optionsFromTarget("wasip2", sema), tests, t) - }) } - } -@@ -809,7 +801,6 @@ func TestTest(t *testing.T) { + if runtime.GOOS == "linux" { +@@ -921,7 +905,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, @@ -38,5 +46,5 @@ index 136128d5..b48e9eef 100644 } for _, targ := range targs { -- -2.47.0 +2.50.0 diff --git a/0002-Skip-tests-that-require-Go-module-mode.patch b/0002-Skip-tests-that-require-Go-module-mode.patch index f1fdc1a..a4df02a 100644 --- a/0002-Skip-tests-that-require-Go-module-mode.patch +++ b/0002-Skip-tests-that-require-Go-module-mode.patch @@ -1,4 +1,4 @@ -From 791e9bf907c5c968f9e4b38c0d8c9083d42e82dd Mon Sep 17 00:00:00 2001 +From e3af7cfc28d948721d94cf6eafedf731453c50b5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Feb 2024 04:26:40 -0500 Subject: [PATCH 2/6] Skip tests that require Go module mode @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/errors_test.go b/errors_test.go -index fe118616..16421eee 100644 +index 871dc4c0..3d0bb162 100644 --- a/errors_test.go +++ b/errors_test.go -@@ -36,7 +36,7 @@ func TestErrors(t *testing.T) { +@@ -37,7 +37,7 @@ func TestErrors(t *testing.T) { {name: "loader-importcycle"}, {name: "loader-invaliddep"}, {name: "loader-invalidpackage"}, @@ -24,10 +24,10 @@ index fe118616..16421eee 100644 {name: "syntax"}, {name: "types"}, diff --git a/main_test.go b/main_test.go -index b48e9eef..c7b11229 100644 +index 77b93c4d..62153c69 100644 --- a/main_test.go +++ b/main_test.go -@@ -76,7 +76,6 @@ func TestBuild(t *testing.T) { +@@ -78,7 +78,6 @@ func TestBuild(t *testing.T) { "json.go", "map.go", "math.go", @@ -35,7 +35,7 @@ index b48e9eef..c7b11229 100644 "print.go", "reflect.go", "signal.go", -@@ -923,6 +922,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { +@@ -1027,6 +1026,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { } func TestGetListOfPackages(t *testing.T) { @@ -54,5 +54,5 @@ index 05c2f2d5..719a617b 100644 -// ERROR: invaliddep{{[\\/]}}invaliddep.go:1:1: expected 'package', found ppackage +// ERROR: {{.*}}invaliddep{{[\\/]}}invaliddep.go:1:1: expected 'package', found ppackage -- -2.47.0 +2.50.0 diff --git a/0003-Set-LLVM-search-paths-for-Fedora.patch b/0003-Set-LLVM-search-paths-for-Fedora.patch index a619e68..513149c 100644 --- a/0003-Set-LLVM-search-paths-for-Fedora.patch +++ b/0003-Set-LLVM-search-paths-for-Fedora.patch @@ -1,4 +1,4 @@ -From d18d696a118fa2078daf4cecb87cf1c64680ccb2 Mon Sep 17 00:00:00 2001 +From 18c5c78780371a39e79b983f8c3c71b24f5663d1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Oct 2024 23:33:18 -0400 Subject: [PATCH 3/6] Set LLVM search paths for Fedora @@ -9,7 +9,9 @@ Signed-off-by: Elliott Sales de Andrade cgo/libclang_config_llvm16.go | 4 ++-- cgo/libclang_config_llvm17.go | 4 ++-- cgo/libclang_config_llvm18.go | 4 ++-- - 4 files changed, 8 insertions(+), 8 deletions(-) + cgo/libclang_config_llvm19.go | 4 ++-- + cgo/libclang_config_llvm20.go | 4 ++-- + 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cgo/libclang_config_llvm15.go b/cgo/libclang_config_llvm15.go index edb1128d..0dc87193 100644 @@ -66,7 +68,7 @@ index 6395d8a3..609b0758 100644 #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@17/lib -lclang #cgo freebsd LDFLAGS: -L/usr/local/llvm17/lib -lclang diff --git a/cgo/libclang_config_llvm18.go b/cgo/libclang_config_llvm18.go -index 3b769c62..18db6c08 100644 +index da181291..76f23129 100644 --- a/cgo/libclang_config_llvm18.go +++ b/cgo/libclang_config_llvm18.go @@ -3,11 +3,11 @@ @@ -83,6 +85,42 @@ index 3b769c62..18db6c08 100644 #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@18/lib -lclang #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@18/lib -lclang #cgo freebsd LDFLAGS: -L/usr/local/llvm18/lib -lclang +diff --git a/cgo/libclang_config_llvm19.go b/cgo/libclang_config_llvm19.go +index 11a64e72..94c95bcb 100644 +--- a/cgo/libclang_config_llvm19.go ++++ b/cgo/libclang_config_llvm19.go +@@ -3,11 +3,11 @@ + package cgo + + /* +-#cgo linux CFLAGS: -I/usr/include/llvm-19 -I/usr/include/llvm-c-19 -I/usr/lib/llvm-19/include ++#cgo linux CFLAGS: -I/usr/lib64/llvm19/include + #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@19/include + #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@19/include + #cgo freebsd CFLAGS: -I/usr/local/llvm19/include +-#cgo linux LDFLAGS: -L/usr/lib/llvm-19/lib -lclang ++#cgo linux LDFLAGS: -L/usr/lib64/llvm19/lib -lclang + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@19/lib -lclang + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@19/lib -lclang + #cgo freebsd LDFLAGS: -L/usr/local/llvm19/lib -lclang +diff --git a/cgo/libclang_config_llvm20.go b/cgo/libclang_config_llvm20.go +index faa2e54d..947558d6 100644 +--- a/cgo/libclang_config_llvm20.go ++++ b/cgo/libclang_config_llvm20.go +@@ -3,11 +3,11 @@ + package cgo + + /* +-#cgo linux CFLAGS: -I/usr/include/llvm-20 -I/usr/include/llvm-c-20 -I/usr/lib/llvm-20/include ++#cgo linux CFLAGS: -I/usr/lib64/llvm20/include + #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@20/include + #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@20/include + #cgo freebsd CFLAGS: -I/usr/local/llvm20/include +-#cgo linux LDFLAGS: -L/usr/lib/llvm-20/lib -lclang ++#cgo linux LDFLAGS: -L/usr/lib64/llvm20/lib -lclang + #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@20/lib -lclang + #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@20/lib -lclang + #cgo freebsd LDFLAGS: -L/usr/local/llvm20/lib -lclang -- -2.47.0 +2.50.0 diff --git a/0004-Add-flag-to-skip-Renesas-SVD-builds.patch b/0004-Add-flag-to-skip-Renesas-SVD-builds.patch index 1b2a44e..4af0f29 100644 --- a/0004-Add-flag-to-skip-Renesas-SVD-builds.patch +++ b/0004-Add-flag-to-skip-Renesas-SVD-builds.patch @@ -1,4 +1,4 @@ -From 40a1ef5d46b91cf32f09be7e6247ae1c32bd0dbd Mon Sep 17 00:00:00 2001 +From 4a6bd01a01e551ea3ba0c5128628eea2714ba122 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 31 Dec 2024 00:34:13 -0500 Subject: [PATCH 4/6] Add flag to skip Renesas SVD builds @@ -9,10 +9,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile -index fd2d282c..f173486c 100644 +index f078bde5..321444da 100644 --- a/GNUmakefile +++ b/GNUmakefile -@@ -185,7 +185,10 @@ fmt-check: ## Warn if any source needs reformatting +@@ -187,7 +187,10 @@ fmt-check: ## Warn if any source needs reformatting @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 @@ -25,5 +25,5 @@ index fd2d282c..f173486c 100644 gen-device: gen-device-stm32 endif -- -2.47.0 +2.50.0 diff --git a/0005-Normalize-expected-path-for-chdir-tests.patch b/0005-Normalize-expected-path-for-chdir-tests.patch index 9425503..2869273 100644 --- a/0005-Normalize-expected-path-for-chdir-tests.patch +++ b/0005-Normalize-expected-path-for-chdir-tests.patch @@ -1,4 +1,4 @@ -From 89167785ea2820fd19444b5c02c937486c6c4ad7 Mon Sep 17 00:00:00 2001 +From cef23b5da7902eaf69cc621ad384ea7815082e86 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 31 Dec 2024 02:00:17 -0500 Subject: [PATCH 5/6] Normalize expected path for chdir tests @@ -29,5 +29,5 @@ index 75281c21..660b25ac 100644 if cwd != expectDir { log.Fatalf("expected:\"%v\" != os.Getwd():\"%v\"", expectDir, cwd) -- -2.47.0 +2.50.0 diff --git a/0006-Skip-x86-tests-on-ARM.patch b/0006-Skip-x86-tests-on-ARM.patch new file mode 100644 index 0000000..e933ac9 --- /dev/null +++ b/0006-Skip-x86-tests-on-ARM.patch @@ -0,0 +1,44 @@ +From 342403c5c6e1d7d2a38c791c90c0937ecb5713d5 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sat, 2 Aug 2025 18:30:43 -0400 +Subject: [PATCH 6/6] Skip x86 tests on ARM + +They are currently broken: +https://github.com/tinygo-org/tinygo/issues/4969 + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/main_test.go b/main_test.go +index 62153c69..c1de9e72 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -192,7 +192,10 @@ func TestBuild(t *testing.T) { + if runtime.GOOS == "linux" { + for name, osArch := range supportedLinuxArches { + options := optionsFromOSARCH(osArch, sema) +- if options.GOARCH != runtime.GOARCH { // Native architecture already run above. ++ if options.GOARCH == "386" && runtime.GOARCH == "arm64" { ++ // This is currently broken running in qemu. ++ // https://github.com/tinygo-org/tinygo/issues/4969 ++ } else if options.GOARCH != runtime.GOARCH { // Native architecture already run above. + t.Run(name, func(t *testing.T) { + runPlatTests(options, tests, t) + }) +@@ -891,7 +894,10 @@ func TestTest(t *testing.T) { + if runtime.GOOS == "linux" { + for name, osArch := range supportedLinuxArches { + options := optionsFromOSARCH(osArch, sema) +- if options.GOARCH != runtime.GOARCH { // Native architecture already run above. ++ if options.GOARCH == "386" && runtime.GOARCH == "arm64" { ++ // This is currently broken running in qemu. ++ // https://github.com/tinygo-org/tinygo/issues/4969 ++ } else if options.GOARCH != runtime.GOARCH { // Native architecture already run above. + targs = append(targs, targ{name, options}) + } + } +-- +2.50.0 + diff --git a/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch b/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch deleted file mode 100644 index c471e58..0000000 --- a/0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 7c03dcc9f5b8e632f1d33dc4e09f74853c1951cc Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 5 Jan 2025 02:20:33 -0500 -Subject: [PATCH 6/6] builder: Fix parsing of external ld.lld error messages - -If `ld.lld` is a version-specific binary (e.g., `ld.lld-18`), then its -error messages include the version. The parsing previously incorrectly -assumed it would be unversioned. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/tools.go | 10 +++++----- - 1 file changed, 5 insertions(+), 5 deletions(-) - -diff --git a/builder/tools.go b/builder/tools.go -index b4087828..1c4214da 100644 ---- a/builder/tools.go -+++ b/builder/tools.go -@@ -98,8 +98,8 @@ func parseLLDErrors(text string) error { - - // Check for undefined symbols. - // This can happen in some cases like with CGo and //go:linkname tricker. -- if matches := regexp.MustCompile(`^ld.lld: error: undefined symbol: (.*)\n`).FindStringSubmatch(message); matches != nil { -- symbolName := matches[1] -+ if matches := regexp.MustCompile(`^ld.lld(-[0-9]+)?: error: undefined symbol: (.*)\n`).FindStringSubmatch(message); matches != nil { -+ symbolName := matches[2] - for _, line := range strings.Split(message, "\n") { - matches := regexp.MustCompile(`referenced by .* \(((.*):([0-9]+))\)`).FindStringSubmatch(line) - if matches != nil { -@@ -118,9 +118,9 @@ func parseLLDErrors(text string) error { - } - - // Check for flash/RAM overflow. -- if matches := regexp.MustCompile(`^ld.lld: error: section '(.*?)' will not fit in region '(.*?)': overflowed by ([0-9]+) bytes$`).FindStringSubmatch(message); matches != nil { -- region := matches[2] -- n, err := strconv.ParseUint(matches[3], 10, 64) -+ if matches := regexp.MustCompile(`^ld.lld(-[0-9]+)?: error: section '(.*?)' will not fit in region '(.*?)': overflowed by ([0-9]+) bytes$`).FindStringSubmatch(message); matches != nil { -+ region := matches[3] -+ n, err := strconv.ParseUint(matches[4], 10, 64) - if err != nil { - // Should not happen at all (unless it overflows an uint64 for some reason). - continue --- -2.47.0 - diff --git a/1b5d312c689a004434cb77f161f65b9615c98036.patch b/1b5d312c689a004434cb77f161f65b9615c98036.patch new file mode 100644 index 0000000..796bf7c --- /dev/null +++ b/1b5d312c689a004434cb77f161f65b9615c98036.patch @@ -0,0 +1,69 @@ +From 1b5d312c689a004434cb77f161f65b9615c98036 Mon Sep 17 00:00:00 2001 +From: Elias Naur +Date: Thu, 17 Jul 2025 12:58:43 +0200 +Subject: [PATCH] tests: de-flake goroutines test + +--- + main_test.go | 4 ++++ + testdata/goroutines.go | 4 ++++ + 2 files changed, 8 insertions(+) + +diff --git a/main_test.go b/main_test.go +index 5563b7cab2..b07d6aaaa4 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -424,10 +424,12 @@ func optionsFromOSARCH(osarch string, sema chan struct{}) compileopts.Options { + } + + func runTest(name string, options compileopts.Options, t *testing.T, cmdArgs, environmentVars []string) { ++ t.Helper() + runTestWithConfig(name, t, options, cmdArgs, environmentVars) + } + + func runTestWithConfig(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) { ++ t.Helper() + // Get the expected output for this test. + // Note: not using filepath.Join as it strips the path separator at the end + // of the path. +@@ -876,6 +878,7 @@ func TestWasmExit(t *testing.T) { + + // Check whether the output of a test equals the expected output. + func checkOutput(t *testing.T, filename string, actual []byte) { ++ t.Helper() + expectedOutput, err := os.ReadFile(filename) + if err != nil { + t.Fatal("could not read output file:", err) +@@ -884,6 +887,7 @@ func checkOutput(t *testing.T, filename string, actual []byte) { + } + + func checkOutputData(t *testing.T, expectedOutput, actual []byte) { ++ t.Helper() + expectedOutput = bytes.ReplaceAll(expectedOutput, []byte("\r\n"), []byte("\n")) + actual = bytes.ReplaceAll(actual, []byte("\r\n"), []byte("\n")) + +diff --git a/testdata/goroutines.go b/testdata/goroutines.go +index 8653cdb173..7397b5503a 100644 +--- a/testdata/goroutines.go ++++ b/testdata/goroutines.go +@@ -175,10 +175,13 @@ func testGoOnBuiltins() { + + var once sync.Once + ++var waitChan = make(chan struct{}) ++ + func testGoOnInterface(f Itf) { + go f.Nowait() + time.Sleep(time.Millisecond) + go f.Wait() ++ <-waitChan + time.Sleep(time.Millisecond * 2) + println("done with 'go on interface'") + } +@@ -204,6 +207,7 @@ func (f Foo) Nowait() { + + func (f Foo) Wait() { + println("called: Foo.Wait") ++ close(waitChan) + time.Sleep(time.Microsecond) + println(" ...waited") + } diff --git a/clean_tarballs.sh b/clean_tarballs.sh index 6f47204..c3d5ac3 100755 --- a/clean_tarballs.sh +++ b/clean_tarballs.sh @@ -1,7 +1,7 @@ #!/bin/bash -e CMSIS_VERSION=9fe411cef1cef5de58e5957b89760759de44e393 -CMSIS_SVD_DATA_VERSION=40327a4d2dff0992682be2872aaa6e096f35d2f4 +CMSIS_SVD_DATA_VERSION=05a9562ec59b87945a8d7177a4b08b7aa2f2fd58 if [ -e "cmsis-${CMSIS_VERSION}-clean.tar.xz" ]; then echo "Not downloading cmsis-${CMSIS_VERSION}-clean.tar.xz again!" @@ -26,12 +26,14 @@ else # - Espressif: Apache-2.0 # - Espressif-Community: Apache-2.0 OR MIT # - Kendryte-Community: ISC +# - Nordic: BSD-3-Clause # - NXP/L*: Proprietary, so not included. # - NXP/Q*: Unknown, so not included. # - NXP/M*: BSD-3-Clause # - RaspberryPi: BSD-3-Clause -# - SiFive-Community: ISC -# - STMicro: Proprietary, so not included. +# - Renesas: Proprietary +# - SiFive-Community: ISC AND (Apache-2.0 OR MIT) +# - STMicro: Apache-2.0 AND Proprietary, so only a subset included. # These directories are not used by TinyGo, so are not kept: # - ARM_SAMPLE: BSD-3-Clause # - Allwinner-Community: Apache-2.0 OR MIT @@ -42,22 +44,24 @@ else # - GigaDevice: Apache-2.0 # - Holtek: Proprietary # - Infineon: Proprietary -# - Nordic: BSD-3-Clause # - Nuvoton: Unknown -# - Renesas: Proprietary # - SiliconLabs: Zlib # - Spansion: Proprietary # - TexasInstruments: Proprietary # - Toshiba: Unknown wget -nc https://github.com/cmsis-svd/cmsis-svd-data/archive/${CMSIS_SVD_DATA_VERSION}/cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}.tar.gz tar xf cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}.tar.gz +mapfile -t clean_stmicro < <(grep -Rl '^ *SPDX-License-Identifier: Apache-2.0$' \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/STMicro/*.svd) tar cJf cmsis_svd_data-${CMSIS_SVD_DATA_VERSION}-clean.tar.xz \ cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Atmel/ \ cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Espressif/ \ cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Espressif-Community/ \ cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Kendryte-Community/ \ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/Nordic/ \ cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/NXP/M* \ cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/RaspberryPi/ \ - cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/SiFive-Community/ + cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/data/SiFive-Community/ \ + "${clean_stmicro[@]}" rm -r cmsis-svd-data-${CMSIS_SVD_DATA_VERSION}/ fi diff --git a/musl-cve-2025-26519-1.patch b/musl-cve-2025-26519-1.patch new file mode 100644 index 0000000..e62d28d --- /dev/null +++ b/musl-cve-2025-26519-1.patch @@ -0,0 +1,38 @@ +>From e5adcd97b5196e29991b524237381a0202a60659 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Sun, 9 Feb 2025 10:07:19 -0500 +Subject: [PATCH] iconv: fix erroneous input validation in EUC-KR decoder + +as a result of incorrect bounds checking on the lead byte being +decoded, certain invalid inputs which should produce an encoding +error, such as "\xc8\x41", instead produced out-of-bounds loads from +the ksc table. + +in a worst case, the loaded value may not be a valid unicode scalar +value, in which case, if the output encoding was UTF-8, wctomb would +return (size_t)-1, causing an overflow in the output pointer and +remaining buffer size which could clobber memory outside of the output +buffer. + +bug report was submitted in private by Nick Wellnhofer on account of +potential security implications. +--- + src/locale/iconv.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/locale/iconv.c b/src/locale/iconv.c +index 9605c8e9..008c93f0 100644 +--- a/src/locale/iconv.c ++++ b/src/locale/iconv.c +@@ -502,7 +502,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri + if (c >= 93 || d >= 94) { + c += (0xa1-0x81); + d += 0xa1; +- if (c >= 93 || c>=0xc6-0x81 && d>0x52) ++ if (c > 0xc6-0x81 || c==0xc6-0x81 && d>0x52) + goto ilseq; + if (d-'A'<26) d = d-'A'; + else if (d-'a'<26) d = d-'a'+26; +-- +2.21.0 + diff --git a/musl-cve-2025-26519-2.patch b/musl-cve-2025-26519-2.patch new file mode 100644 index 0000000..9b64508 --- /dev/null +++ b/musl-cve-2025-26519-2.patch @@ -0,0 +1,38 @@ +>From c47ad25ea3b484e10326f933e927c0bc8cded3da Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Wed, 12 Feb 2025 17:06:30 -0500 +Subject: [PATCH] iconv: harden UTF-8 output code path against input decoder + bugs + +the UTF-8 output code was written assuming an invariant that iconv's +decoders only emit valid Unicode Scalar Values which wctomb can encode +successfully, thereby always returning a value between 1 and 4. + +if this invariant is not satisfied, wctomb returns (size_t)-1, and the +subsequent adjustments to the output buffer pointer and remaining +output byte count overflow, moving the output position backwards, +potentially past the beginning of the buffer, without storing any +bytes. +--- + src/locale/iconv.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/locale/iconv.c b/src/locale/iconv.c +index 008c93f0..52178950 100644 +--- a/src/locale/iconv.c ++++ b/src/locale/iconv.c +@@ -545,6 +545,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri + if (*outb < k) goto toobig; + memcpy(*out, tmp, k); + } else k = wctomb_utf8(*out, c); ++ /* This failure condition should be unreachable, but ++ * is included to prevent decoder bugs from translating ++ * into advancement outside the output buffer range. */ ++ if (k>4) goto ilseq; + *out += k; + *outb -= k; + break; +-- +2.21.0 + + diff --git a/sources b/sources index b36c23c..b90c8c9 100644 --- a/sources +++ b/sources @@ -1,10 +1,11 @@ -SHA512 (tinygo-0.34.0.tar.gz) = 2c6c4b8b727540c6d83d6429125a8011cc049b9670e92e1fc31a4da74be4c078b19eec8f324b5dd7becb389ef15f613b619a29fa3b1ecc4208ddcb5d662708b5 +SHA512 (tinygo-0.38.0.tar.gz) = 1e7d64caa20c2a12390de36067b50f3cc3b675a3e4818d6fa463816c42cbd94101989863936f5ed38ce1224e99cdf69e3c251debcdb7c9f16daf42876fae2f9e SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 +SHA512 (bdwgc-1166f11f7dee08d7ad369296b24cf8c9582f8789.tar.gz) = 030d5a9a0931915a76b1ec270e7208199cf40973ac6c8141c02e34f118f965bedcadff3bb36481b0e45703df8eb2750d20809f3fde367fd5efed5f8a44ccab32 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 -SHA512 (cmsis_svd_data-40327a4d2dff0992682be2872aaa6e096f35d2f4-clean.tar.xz) = 851179df0f9fb86b6c8c340659568bd367ffd9ac801f0bbf1a0a10713599c6e78fb5d0cb27ac31c6ea5d8c4f71c52f925bdeef0d49a8a93c63b62ef555423718 +SHA512 (cmsis_svd_data-05a9562ec59b87945a8d7177a4b08b7aa2f2fd58-clean.tar.xz) = e8ba9d74fb148dfa8b3ba140d307b243fb38378f69544529455eea5df57d4276b7177d3549228f8acadc4e72c94506456e78025d9b16d606b322fda8ab38327d SHA512 (compiler-rt-18.1.8.src.tar.xz) = fb8795bd51c9b005c2ad1975591e9e2715740d6407ccad41379f136ef2e8d24ded8b97b01165a3ae4bd377119a6a1049ca05d3220404fc12bee86114ff2bff0d SHA512 (compiler-rt-18.1.8.src.tar.xz.sig) = 06d90afa46fb8c7ad6879564d1eb35e45711768593b580cf59e9908ed89efd459a312ae3c317c38119b0142ce0f96bcc0f8e6010ec8b31d9620c5e8f6d2f932e -SHA512 (macos-minimal-sdk-4e4113e3b1244b8fdc5e1486577f25e22d63f36e.tar.gz) = 10de6205ee6f7c6079e1120d4f42a72b984e1727a81a8f7fc9c9d4dd16e51c71291ab9d4fd88b36843b2b39a3c981fe4007b93ebaf920627f524417fbfdc823a +SHA512 (macos-minimal-sdk-e7c72156eac3ebf29c34cc2faa71efcb1296663f.tar.gz) = 44638fa9786e88327eb5a2f5cf06c8f09149f21b2592802bdd2db04cbdf4dfbee1bc9296af1b7745c4e30ac97f26a714e19168b742526a8a1b4f8ce23d8fa789 SHA512 (mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz) = 723d1ac22d8026f31b59d39328f711f36976798445a82daddcdc9fa6ab4346a5030e9c2efc84ef009439b8f021c5c7c120cfa083a7912a5b0212ac6852c005a7 SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c SHA512 (musl-1.2.3.tar.gz.asc) = 01a857dbc3981c90244d4d1d883efe51986652ca5734a741c9d1a4d06c5a22831e85520ac67212268b70c22049317a8f39b3219be182e7e67741add428ac5bc6 diff --git a/tinygo.spec b/tinygo.spec index 6b0d279..c5cceb5 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -8,14 +8,15 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.34.0 +Version: 0.38.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 +%global bdwgc_commit 1166f11f7dee08d7ad369296b24cf8c9582f8789 %global clang_llvm_version 18 -%global cmsis_svd_data_commit 40327a4d2dff0992682be2872aaa6e096f35d2f4 +%global cmsis_svd_data_commit 05a9562ec59b87945a8d7177a4b08b7aa2f2fd58 %global compiler_rt_version %{clang_llvm_version}.1.8 -%global macos_minsdk_commit 4e4113e3b1244b8fdc5e1486577f25e22d63f36e +%global macos_minsdk_commit e7c72156eac3ebf29c34cc2faa71efcb1296663f %global mingw64_commit 8526cb618269440a94810b94b77f8bd48c5c3396 %global musl_version 1.2.3 %global net_commit c134160ae47d38b468b1c5ade43e78ad5a1e616d @@ -35,10 +36,6 @@ Version: 0.34.0 Go compiler for small places. Microcontrollers, WebAssembly, and command-line tools. Based on LLVM.} -#global godocs CHANGELOG.md BUILDING.md CONTRIBUTING.md README.md -#global golicenses LICENSE LICENSE.TXT -#global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S} - Name: tinygo Release: %autorelease Summary: Go compiler for small places @@ -83,6 +80,12 @@ Source12: https://github.com/tinygo-org/net/archive/%{net_commit}/net-%{ne %if %{with wasi_cli} Source13: https://github.com/WebAssembly/wasi-cli/archive/v%{wasi_cli_version}/wasi-cli-%{wasi_cli_version}.tar.gz %endif +Source14: https://github.com/ivmai/bdwgc/archive/%{bdwgc_commit}/bdwgc-%{bdwgc_commit}.tar.gz + +# +# Unnumbered patches are applied to the main source tree. +# Patches that are 1X00-1X99 are applied to the subdirectory for source X. +# # We don't have wasmtime to run these. Patch: 0001-Skip-WASI-tests.patch @@ -91,11 +94,18 @@ Patch: 0002-Skip-tests-that-require-Go-module-mode.patch # Better search paths for non-default LLVM. Patch: 0003-Set-LLVM-search-paths-for-Fedora.patch # We can't include these due to poor licensing. +# https://github.com/tinygo-org/tinygo/pull/4962 Patch: 0004-Add-flag-to-skip-Renesas-SVD-builds.patch #https://github.com/tinygo-org/tinygo/pull/4677 Patch: 0005-Normalize-expected-path-for-chdir-tests.patch -# https://github.com/tinygo-org/tinygo/pull/4686 -Patch: 0006-builder-Fix-parsing-of-external-ld.lld-error-message.patch +# https://github.com/tinygo-org/tinygo/pull/4958 +Patch: https://github.com/tinygo-org/tinygo/commit/1b5d312c689a004434cb77f161f65b9615c98036.patch +# https://github.com/tinygo-org/tinygo/issues/4969 +Patch: 0006-Skip-x86-tests-on-ARM.patch + +# Fix CVE-2025-26519 in musl. +Patch1600: https://www.openwall.com/lists/musl/2025/02/13/1/1#/musl-cve-2025-26519-1.patch +Patch1601: https://www.openwall.com/lists/musl/2025/02/13/1/2#/musl-cve-2025-26519-2.patch # Not supported upstream yet. ExcludeArch: ppc64le s390x @@ -115,11 +125,11 @@ BuildRequires: golang(github.com/marcinbor85/gohex) BuildRequires: golang(github.com/mattn/go-colorable) >= 0.1.13 BuildRequires: golang(github.com/mattn/go-tty) >= 0.0.4 BuildRequires: golang(github.com/tetratelabs/wazero) >= 1.6 -BuildRequires: golang(golang.org/x/net/http/httpguts) >= 0.26 +BuildRequires: golang(golang.org/x/net/http/httpguts) >= 0.35 BuildRequires: golang(github.com/sigurn/crc16) BuildRequires: golang(go.bug.st/serial) >= 1.6.0 BuildRequires: golang(golang.org/x/tools/go/ast/astutil) -BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.21 +BuildRequires: golang(golang.org/x/tools/go/ssa) >= 0.30 BuildRequires: golang(gopkg.in/yaml.v2) >= 2.4.0 BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: golang-tests @@ -153,6 +163,8 @@ Recommends: qemu-system-riscv-core Recommends: qemu-user # Make note of bundled libc's +Provides: bundled(bdwgc) = %{bdwgc_commit} +Provides: bundled(gc) = %{bdwgc_commit} Provides: bundled(compiler-rt) = %{compiler_rt_version} Provides: bundled(musl) = %{musl_version} Provides: bundled(picolibc) = %{picolibc_commit} @@ -161,24 +173,31 @@ Provides: bundled(wasi-libc) = %{wasi_libc_version} %description %{common_description} -#gopkg - %prep %goprep -%autopatch -p1 +%autopatch -q -p1 -M 999 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS mv lib/CMSIS-%{CMSIS_commit} lib/CMSIS +pushd lib/CMSIS +%autopatch -q -p1 -m 1200 -M 1299 +popd tar -C lib -xf %{SOURCE3} rmdir lib/avr mv lib/avr-mcu-%{avr_commit} lib/avr +pushd lib/avr +%autopatch -q -p1 -m 1300 -M 1399 +popd tar -C lib -xf %{SOURCE4} rmdir lib/cmsis-svd mv lib/cmsis-svd-data-%{cmsis_svd_data_commit} lib/cmsis-svd +pushd lib/cmsis-svd +%autopatch -q -p1 -m 1400 -M 1499 +popd # Verify *before* actually unpacking! %{gpgverify} --keyring='%{SOURCE52}' --signature='%{SOURCE51}' --data='%{SOURCE50}' @@ -186,77 +205,93 @@ tar -C lib -xf %{SOURCE50} mv lib/compiler-rt-%{compiler_rt_version}.src/lib/builtins lib/compiler-rt-builtins mv lib/compiler-rt-%{compiler_rt_version}.src/README.txt lib/compiler-rt-builtins/ mv lib/compiler-rt-%{compiler_rt_version}.src/LICENSE.TXT lib/compiler-rt-builtins/ +pushd lib/compiler-rt-builtins +%autopatch -q -p1 -m 1500 -M 1599 +popd # Verify *before* actually unpacking! %{gpgverify} --keyring='%{SOURCE62}' --signature='%{SOURCE61}' --data='%{SOURCE60}' tar -C lib -xf %{SOURCE60} rmdir lib/musl mv lib/musl-%{musl_version} lib/musl +pushd lib/musl +%autopatch -q -p1 -m 1600 -M 1699 +popd tar -C lib -xf %{SOURCE7} rmdir lib/macos-minimal-sdk mv lib/macos-minimal-sdk-%{macos_minsdk_commit} lib/macos-minimal-sdk +pushd lib/macos-minimal-sdk +%autopatch -q -p1 -m 1700 -M 1799 +popd tar -C lib -xf %{SOURCE8} rmdir lib/nrfx mv lib/nrfx-%{nrfx_commit} lib/nrfx rm lib/nrfx/.gitignore chmod -x lib/nrfx/doc/generate_html_doc.sh +pushd lib/nrfx +%autopatch -q -p1 -m 1800 -M 1899 +popd tar -C lib -xf %{SOURCE9} rmdir lib/picolibc mv lib/picolibc-%{picolibc_commit} lib/picolibc +pushd lib/picolibc +%autopatch -q -p1 -m 1900 -M 1999 +popd tar -C lib -xf %{SOURCE10} rmdir lib/wasi-libc mv lib/wasi-libc-%{wasi_libc_tag} lib/wasi-libc +pushd lib/wasi-libc +%autopatch -q -p1 -m 11000 -M 11099 +popd tar -C lib -xf %{SOURCE11} rmdir lib/mingw-w64 mv lib/mingw-w64-%{mingw64_commit} lib/mingw-w64 +pushd lib/mingw-w64 +%autopatch -q -p1 -m 11100 -M 11199 +popd tar -C src -xf %{SOURCE12} rmdir src/net mv src/net-%{net_commit} src/net +pushd src/net +%autopatch -q -p1 -m 11200 -M 11299 +popd %if %{with wasi_cli} tar -C lib -xf %{SOURCE13} rmdir lib/wasi-cli mv lib/wasi-cli-%{wasi_cli_version} lib/wasi-cli +pushd lib/wasi-cli +%autopatch -q -p1 -m 11300 -M 11399 +popd %endif -# Fix permissions -# https://github.com/tinygo-org/tinygo/pull/4676 -chmod -x \ - src/internal/wasi/cli/v0.2.0/command/command.wit \ - src/internal/wasi/*/v0.2.0/*/*.wasm.go +tar -C lib -xf %{SOURCE14} +rmdir lib/bdwgc +mv lib/bdwgc-%{bdwgc_commit} lib/bdwgc +pushd lib/bdwgc +%autopatch -q -p1 -m 11400 -M 11499 +popd %build -# Use only GOBUILDTAGS when https://pagure.io/go-rpm-macros/pull-request/34 is -# merged and released. -export BUILDTAGS="llvm%{clang_llvm_version}" LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " +export GO_BUILDTAGS="llvm%{clang_llvm_version}" GO_LDFLAGS="-X github.com/tinygo-org/tinygo/goenv.TINYGOROOT=%{tinygoroot} " %gobuild -o %{gobuilddir}/bin/tinygo %{goipath} GO111MODULE=off %make_build gen-device RENESAS=0 STM32=0 -LLVM_AR=llvm-ar-%{clang_llvm_version} -if ! command -v $LLVM_AR 2>&1 >/dev/null -then -LLVM_AR=llvm-ar -fi -LLVM_NM=llvm-nm-%{clang_llvm_version} -if ! command -v $LLVM_NM 2>&1 >/dev/null -then -LLVM_NM=llvm-ar -fi -%make_build wasi-libc CLANG=clang-%{clang_llvm_version} LLVM_AR=$LLVM_AR LLVM_NM=$LLVM_NM %install -#gopkginstall install -vdm 0755 %{buildroot}%{_bindir} install -vpm 0755 %{gobuilddir}/bin/* %{buildroot}%{_bindir}/ install -vdm 0755 %{buildroot}%{tinygoroot} install -vdm 0755 %{buildroot}%{tinygoroot}/lib +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/bdwgc +cp -rp lib/bdwgc/* %{buildroot}%{tinygoroot}/lib/bdwgc install -vdm 0755 %{buildroot}%{tinygoroot}/lib/CMSIS install -vpm 0644 lib/CMSIS/README.md %{buildroot}%{tinygoroot}/lib/CMSIS/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/CMSIS/CMSIS/Include @@ -264,14 +299,24 @@ install -vpm 0644 lib/CMSIS/CMSIS/Include/* %{buildroot}%{tinygoroot}/lib/CMSIS/ cp -rp lib/compiler-rt-builtins %{buildroot}%{tinygoroot}/lib install -vdm 0755 %{buildroot}%{tinygoroot}/lib/macos-minimal-sdk cp -rp lib/macos-minimal-sdk/* %{buildroot}%{tinygoroot}/lib/macos-minimal-sdk -install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt cp -rp lib/mingw-w64/mingw-w64-crt/def-include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt +cp -rp lib/mingw-w64/mingw-w64-crt/gdtoa %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt +cp -rp lib/mingw-w64/mingw-w64-crt/include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt +cp -rp lib/mingw-w64/mingw-w64-crt/misc %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt +cp -rp lib/mingw-w64/mingw-w64-crt/stdio %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/crt +cp -rp lib/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/crt +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/math +cp -rp lib/mingw-w64/mingw-w64-crt/math/x86 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/math +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/api-ms-win-crt-* %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common +cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/advapi32.def.in %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/kernel32.def.in %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common -install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/stdio -cp -rp lib/mingw-w64/mingw-w64-crt/stdio/ucrt_* %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/stdio +cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/msvcrt.def.in %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-crt/lib-common install -vdm 0755 %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers/defaults cp -rp lib/mingw-w64/mingw-w64-headers/crt/ %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers +cp -rp lib/mingw-w64/mingw-w64-headers/include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers cp -rp lib/mingw-w64/mingw-w64-headers/defaults/include %{buildroot}%{tinygoroot}/lib/mingw-w64/mingw-w64-headers/defaults install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl cp -rp lib/musl/COPYRIGHT %{buildroot}%{tinygoroot}/lib/musl @@ -286,9 +331,12 @@ cp -rp lib/musl/arch/x86_64 %{buildroot}%{tinygoroot}/lib/musl/arch install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl/crt cp -rp lib/musl/crt/crt1.c %{buildroot}%{tinygoroot}/lib/musl/crt install -vdm 0755 %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/conf %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/ctype %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/env %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/errno %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/exit %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/fcntl %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/include %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/internal %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/legacy %{buildroot}%{tinygoroot}/lib/musl/src @@ -297,30 +345,56 @@ cp -rp lib/musl/src/locale %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/malloc %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/mman %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/math %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/misc %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/multibyte %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/sched %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/signal %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/stdio %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/stdlib %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/string %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/thread %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/time %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/musl/src/unistd %{buildroot}%{tinygoroot}/lib/musl/src +cp -rp lib/musl/src/process %{buildroot}%{tinygoroot}/lib/musl/src cp -rp lib/nrfx %{buildroot}%{tinygoroot}/lib/ install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc -cp -rp lib/wasi-libc/sysroot %{buildroot}%{tinygoroot}/lib/wasi-libc/ +install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/dlmalloc +cp -rp lib/wasi-libc/dlmalloc/src %{buildroot}%{tinygoroot}/lib/wasi-libc/dlmalloc install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half -install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half/headers -cp -rp lib/wasi-libc/libc-bottom-half/headers/public %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half/headers +cp -rp lib/wasi-libc/libc-bottom-half/cloudlibc %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half +cp -rp lib/wasi-libc/libc-bottom-half/headers %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half +cp -rp lib/wasi-libc/libc-bottom-half/sources %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-bottom-half install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half +cp -rp lib/wasi-libc/libc-top-half/headers %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half +cp -rp lib/wasi-libc/libc-top-half/sources %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl cp -rp lib/wasi-libc/libc-top-half/musl/include %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/arch cp -rp lib/wasi-libc/libc-top-half/musl/arch/generic %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/arch cp -rp lib/wasi-libc/libc-top-half/musl/arch/wasm32 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/arch install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/conf %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/dirent %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/env %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/errno %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/exit %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/fcntl %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/fenv %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src cp -rp lib/wasi-libc/libc-top-half/musl/src/include %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src cp -rp lib/wasi-libc/libc-top-half/musl/src/internal %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/legacy %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/locale %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src cp -rp lib/wasi-libc/libc-top-half/musl/src/math %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/misc %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/multibyte %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/network %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/stat %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/stdio %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/stdlib %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src cp -rp lib/wasi-libc/libc-top-half/musl/src/string %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/thread %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/time %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src +cp -rp lib/wasi-libc/libc-top-half/musl/src/unistd %{buildroot}%{tinygoroot}/lib/wasi-libc/libc-top-half/musl/src %if %{with wasi_cli} install -vdm 0755 %{buildroot}%{tinygoroot}/lib/wasi-cli cp -rp lib/wasi-cli/wit %{buildroot}%{tinygoroot}/lib/wasi-cli/wit @@ -365,6 +439,8 @@ make tinygo-test %license LICENSE %{_bindir}/tinygo %{tinygoroot} +%doc %{tinygoroot}/lib/bdwgc/README.md +%license %{tinygoroot}/lib/bdwgc/LICENSE %doc %{tinygoroot}/lib/CMSIS/README.md %license %{tinygoroot}/lib/compiler-rt-builtins/LICENSE.TXT %doc %{tinygoroot}/lib/compiler-rt-builtins/README.txt @@ -372,8 +448,6 @@ make tinygo-test %doc %{tinygoroot}/lib/nrfx/README.md %license %{tinygoroot}/lib/musl/COPYRIGHT -#gopkgfiles - %changelog %autochangelog From dc10663dd3fc5bbd9c8c9f741c954732531cf713 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 20 Jul 2025 04:15:17 -0400 Subject: [PATCH 73/78] Update build to use LLVM 19 --- sources | 4 ++-- tinygo.spec | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sources b/sources index b90c8c9..0a75777 100644 --- a/sources +++ b/sources @@ -3,8 +3,8 @@ SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8 SHA512 (bdwgc-1166f11f7dee08d7ad369296b24cf8c9582f8789.tar.gz) = 030d5a9a0931915a76b1ec270e7208199cf40973ac6c8141c02e34f118f965bedcadff3bb36481b0e45703df8eb2750d20809f3fde367fd5efed5f8a44ccab32 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd_data-05a9562ec59b87945a8d7177a4b08b7aa2f2fd58-clean.tar.xz) = e8ba9d74fb148dfa8b3ba140d307b243fb38378f69544529455eea5df57d4276b7177d3549228f8acadc4e72c94506456e78025d9b16d606b322fda8ab38327d -SHA512 (compiler-rt-18.1.8.src.tar.xz) = fb8795bd51c9b005c2ad1975591e9e2715740d6407ccad41379f136ef2e8d24ded8b97b01165a3ae4bd377119a6a1049ca05d3220404fc12bee86114ff2bff0d -SHA512 (compiler-rt-18.1.8.src.tar.xz.sig) = 06d90afa46fb8c7ad6879564d1eb35e45711768593b580cf59e9908ed89efd459a312ae3c317c38119b0142ce0f96bcc0f8e6010ec8b31d9620c5e8f6d2f932e +SHA512 (compiler-rt-19.1.7.src.tar.xz) = e2e8e6a094525b84184e9e4a4c1a727de518d4ef1a91370515f0c955719dc946fd60e7fabd10f52ab1905ef6d4a86084b8ddfb9b45de838aa1c5ddf3c042748b +SHA512 (compiler-rt-19.1.7.src.tar.xz.sig) = 48550377345331bfa0015d2c5bb6e063507a76e950f8f349a8e6877d35428a11d86bd617ea7a048f1584a42c58da924ef523d622b54ce4ca94eaa12ce290b49c SHA512 (macos-minimal-sdk-e7c72156eac3ebf29c34cc2faa71efcb1296663f.tar.gz) = 44638fa9786e88327eb5a2f5cf06c8f09149f21b2592802bdd2db04cbdf4dfbee1bc9296af1b7745c4e30ac97f26a714e19168b742526a8a1b4f8ce23d8fa789 SHA512 (mingw64-8526cb618269440a94810b94b77f8bd48c5c3396.tar.gz) = 723d1ac22d8026f31b59d39328f711f36976798445a82daddcdc9fa6ab4346a5030e9c2efc84ef009439b8f021c5c7c120cfa083a7912a5b0212ac6852c005a7 SHA512 (musl-1.2.3.tar.gz) = 9332f713d3eb7de4369bc0327d99252275ee52abf523ee34b894b24a387f67579787f7c72a46cf652e090cffdb0bc3719a4e7b84dca66890b6a37f12e8ad089c diff --git a/tinygo.spec b/tinygo.spec index c5cceb5..6c0bd0c 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -13,9 +13,9 @@ Version: 0.38.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 %global bdwgc_commit 1166f11f7dee08d7ad369296b24cf8c9582f8789 -%global clang_llvm_version 18 +%global clang_llvm_version 19 %global cmsis_svd_data_commit 05a9562ec59b87945a8d7177a4b08b7aa2f2fd58 -%global compiler_rt_version %{clang_llvm_version}.1.8 +%global compiler_rt_version %{clang_llvm_version}.1.7 %global macos_minsdk_commit e7c72156eac3ebf29c34cc2faa71efcb1296663f %global mingw64_commit 8526cb618269440a94810b94b77f8bd48c5c3396 %global musl_version 1.2.3 @@ -418,7 +418,7 @@ cp -rp targets %{buildroot}%{tinygoroot}/ %if %{with check} -%global gotestflags %gocompilerflags -v -tags="llvm%{clang_llvm_version}" +%global gotestflags %gocompilerflags -v -tags="llvm%{clang_llvm_version}" -timeout 30m %check export TINYGOROOT=%{buildroot}%{tinygoroot} export GOPATH=%{buildroot}%{tinygoroot}:%{gopath} From 8526125e83d305de378ed7a5778e5d4cfbc8ac26 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 8 Aug 2025 19:35:38 -0400 Subject: [PATCH 74/78] Backport support for Go 1.25 --- 4954.patch | 575 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tinygo.spec | 2 + 2 files changed, 577 insertions(+) create mode 100644 4954.patch diff --git a/4954.patch b/4954.patch new file mode 100644 index 0000000..e1ea046 --- /dev/null +++ b/4954.patch @@ -0,0 +1,575 @@ +From 2c34e1bce5f75ba34a6ba11755801ff0b82fd638 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 11 Jul 2025 09:21:09 +0200 +Subject: [PATCH 1/8] ci: rename some jobs to avoid churn on every Go/LLVM + version bump + +--- + .circleci/config.yml | 15 ++++++++------- + 1 file changed, 8 insertions(+), 7 deletions(-) + +diff --git a/.circleci/config.yml b/.circleci/config.yml +index 5a73dceae2..afa7a73001 100644 +--- a/.circleci/config.yml ++++ b/.circleci/config.yml +@@ -92,14 +92,18 @@ commands: + - /go/pkg/mod + + jobs: +- test-llvm15-go122: ++ test-oldest: ++ # This tests our lowest supported versions of Go and LLVM, to make sure at ++ # least the smoke tests still pass. + docker: + - image: golang:1.22-bullseye + steps: + - test-linux: + llvm: "15" + resource_class: large +- test-llvm20-go124: ++ test-newest: ++ # This tests the latest supported LLVM version when linking against system ++ # libraries. + docker: + - image: golang:1.24-bullseye + steps: +@@ -110,8 +114,5 @@ jobs: + workflows: + test-all: + jobs: +- # This tests our lowest supported versions of Go and LLVM, to make sure at +- # least the smoke tests still pass. +- - test-llvm15-go122 +- # This tests LLVM 20 support when linking against system libraries. +- - test-llvm20-go124 ++ - test-oldest ++ - test-newest + +From 527ebbe6f74eedfc764252740744bcaf0ee6826f Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 11 Jul 2025 15:45:42 +0200 +Subject: [PATCH 2/8] reflect: implement Method.IsExported + +--- + src/reflect/type.go | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/reflect/type.go b/src/reflect/type.go +index 828cf12e27..884f89dc84 100644 +--- a/src/reflect/type.go ++++ b/src/reflect/type.go +@@ -127,6 +127,11 @@ type Method struct { + Index int // index for Type.Method + } + ++// IsExported reports whether the method is exported. ++func (m Method) IsExported() bool { ++ return m.PkgPath == "" ++} ++ + // The following Type type has been copied almost entirely from + // https://github.com/golang/go/blob/go1.15/src/reflect/type.go#L27-L212. + // Some methods have been commented out as they haven't yet been implemented. + +From 63ff828af46555f98d3a7fb0bcd0c53891049835 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 31 Jul 2025 13:44:13 +0200 +Subject: [PATCH 3/8] sync: implement sync.Swap + +--- + src/sync/map.go | 12 ++++++++++++ + src/sync/map_test.go | 19 +++++++++++++++++++ + 2 files changed, 31 insertions(+) + +diff --git a/src/sync/map.go b/src/sync/map.go +index cd8a1967d6..8b5c0cff76 100644 +--- a/src/sync/map.go ++++ b/src/sync/map.go +@@ -70,3 +70,15 @@ func (m *Map) Range(f func(key, value interface{}) bool) { + } + } + } ++ ++// Swap replaces the value for the given key, and returns the old value if any. ++func (m *Map) Swap(key, value any) (previous any, loaded bool) { ++ m.lock.Lock() ++ defer m.lock.Unlock() ++ if m.m == nil { ++ m.m = make(map[interface{}]interface{}) ++ } ++ previous, loaded = m.m[key] ++ m.m[key] = value ++ return ++} +diff --git a/src/sync/map_test.go b/src/sync/map_test.go +index f493bdfb51..a41faa40fd 100644 +--- a/src/sync/map_test.go ++++ b/src/sync/map_test.go +@@ -17,3 +17,22 @@ func TestMapLoadAndDelete(t *testing.T) { + t.Errorf("LoadAndDelete returned %v, %v, want nil, false", v, ok) + } + } ++ ++func TestMapSwap(t *testing.T) { ++ var sm sync.Map ++ sm.Store("present", "value") ++ ++ if v, ok := sm.Swap("present", "value2"); !ok || v != "value" { ++ t.Errorf("Swap returned %v, %v, want value, true", v, ok) ++ } ++ if v, ok := sm.Load("present"); !ok || v != "value2" { ++ t.Errorf("Load after Swap returned %v, %v, want value2, true", v, ok) ++ } ++ ++ if v, ok := sm.Swap("new", "foo"); ok || v != nil { ++ t.Errorf("Swap returned %v, %v, want nil, false", v, ok) ++ } ++ if v, ok := sm.Load("present"); !ok || v != "value2" { ++ t.Errorf("Load after Swap returned %v, %v, want foo, true", v, ok) ++ } ++} + +From 87bed715943b5a8a11aaa5c84e0f2dc8ac8046cf Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Thu, 31 Jul 2025 13:51:17 +0200 +Subject: [PATCH 4/8] runtime: implement dummy AddCleanup + +--- + src/runtime/runtime.go | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go +index 6bd719f548..7ad482a055 100644 +--- a/src/runtime/runtime.go ++++ b/src/runtime/runtime.go +@@ -106,6 +106,25 @@ func UnlockOSThread() { + // point of the call. + func KeepAlive(x interface{}) + ++// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up. ++// ++// We base this on the following loophole in the official runtime.AddCleanup ++// documentation: ++// ++// > The cleanup(arg) call is not always guaranteed to run; in particular it is ++// > not guaranteed to run before program exit. ++// ++// So it's technically correct (the best kind of correct) to not run any ++// cleanups. But of course, this can lead to resource leaks so cleanups may need ++// to be implemented eventually. ++func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup { ++ return Cleanup{} ++} ++ ++type Cleanup struct{} ++ ++func (c Cleanup) Stop() {} ++ + var godebugUpdate func(string, string) + + //go:linkname godebug_setUpdate internal/godebug.setUpdate + +From dd10065061fb3e33bf0f006ef3b4fae53483c019 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Mon, 4 Aug 2025 10:27:41 +0200 +Subject: [PATCH 5/8] compiler: implement internal/abi.Escape + +--- + compiler/intrinsics.go | 23 +++++++++++++++++++++++ + compiler/symbol.go | 17 +++++++++++++++++ + src/internal/abi/escape.go | 7 +++++++ + 3 files changed, 47 insertions(+) + +diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go +index 3c7edd7c95..5f1ba6f7d1 100644 +--- a/compiler/intrinsics.go ++++ b/compiler/intrinsics.go +@@ -121,6 +121,29 @@ func (b *builder) createKeepAliveImpl() { + b.CreateRetVoid() + } + ++// createAbiEscapeImpl implements the generic internal/abi.Escape function. It ++// currently only supports pointer types. ++func (b *builder) createAbiEscapeImpl() { ++ b.createFunctionStart(true) ++ ++ // The first parameter is assumed to be a pointer. This is checked at the ++ // call site of createAbiEscapeImpl. ++ pointerValue := b.getValue(b.fn.Params[0], getPos(b.fn)) ++ ++ // Create an equivalent of the following C code, which is basically just a ++ // nop but ensures the pointerValue is kept alive: ++ // ++ // __asm__ __volatile__("" : : "r"(pointerValue)) ++ // ++ // It should be portable to basically everything as the "r" register type ++ // exists basically everywhere. ++ asmType := llvm.FunctionType(b.dataPtrType, []llvm.Type{b.dataPtrType}, false) ++ asmFn := llvm.InlineAsm(asmType, "", "=r,0", true, false, 0, false) ++ result := b.createCall(asmType, asmFn, []llvm.Value{pointerValue}, "") ++ ++ b.CreateRet(result) ++} ++ + var mathToLLVMMapping = map[string]string{ + "math.Ceil": "llvm.ceil.f64", + "math.Exp": "llvm.exp.f64", +diff --git a/compiler/symbol.go b/compiler/symbol.go +index c56e0792f2..2507b3eedb 100644 +--- a/compiler/symbol.go ++++ b/compiler/symbol.go +@@ -253,6 +253,23 @@ func (c *compilerContext) maybeCreateSyntheticFunction(fn *ssa.Function, llvmFn + // The exception is the package initializer, which does appear in the + // *ssa.Package members and so shouldn't be created here. + if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" && fn.Synthetic != "range-over-func yield" { ++ if origin := fn.Origin(); origin != nil && origin.RelString(nil) == "internal/abi.Escape" { ++ // This is a special implementation or internal/abi.Escape, which ++ // can only really be implemented in the compiler. ++ // For simplicity we'll only implement pointer parameters for now. ++ if _, ok := fn.Params[0].Type().Underlying().(*types.Pointer); ok { ++ irbuilder := c.ctx.NewBuilder() ++ defer irbuilder.Dispose() ++ b := newBuilder(c, irbuilder, fn) ++ b.createAbiEscapeImpl() ++ llvmFn.SetLinkage(llvm.LinkOnceODRLinkage) ++ llvmFn.SetUnnamedAddr(true) ++ } ++ // If the parameter is not of a pointer type, it will be left ++ // unimplemented. This will result in a linker error if the function ++ // is really called, making it clear it needs to be implemented. ++ return ++ } + if len(fn.Blocks) == 0 { + c.addError(fn.Pos(), "missing function body") + return +diff --git a/src/internal/abi/escape.go b/src/internal/abi/escape.go +index 0ecdf80308..1f4c763312 100644 +--- a/src/internal/abi/escape.go ++++ b/src/internal/abi/escape.go +@@ -8,3 +8,10 @@ import "unsafe" + func NoEscape(p unsafe.Pointer) unsafe.Pointer { + return p + } ++ ++func Escape[T any](x T) T { ++ // This function is either implemented in the compiler, or left undefined ++ // for some variation of T. The body of this function should not be compiled ++ // as-is. ++ panic("internal/abi.Escape: unreachable (implemented in the compiler)") ++} + +From 6ea7aa68492ee4de9b9aa4ce0faa8104a5b3f590 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Mon, 4 Aug 2025 10:28:01 +0200 +Subject: [PATCH 6/8] testing: stub out testing.B.Loop + +This gets the path package tests to pass, so we can move ahead with Go +1.25. It should be implemented in the future at some point (that, or +we'll use the upstream testing package instead). +--- + src/testing/benchmark.go | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go +index 53c7fc7b10..2dc59b72fd 100644 +--- a/src/testing/benchmark.go ++++ b/src/testing/benchmark.go +@@ -500,6 +500,10 @@ func (b *B) RunParallel(body func(*PB)) { + return + } + ++func (b *B) Loop() bool { ++ panic("unimplemented: testing.B.Loop") ++} ++ + // Benchmark benchmarks a single function. It is useful for creating + // custom benchmarks that do not use the "go test" command. + // + +From fc6d509c4235a980f0ef40cd30f207e9a1a697d0 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Mon, 4 Aug 2025 10:31:48 +0200 +Subject: [PATCH 7/8] runtime: stub out weak pointer support + +--- + src/runtime/runtime.go | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go +index 7ad482a055..3bd98319e8 100644 +--- a/src/runtime/runtime.go ++++ b/src/runtime/runtime.go +@@ -125,6 +125,14 @@ type Cleanup struct{} + + func (c Cleanup) Stop() {} + ++//go:linkname registerWeakPointer weak.runtime_registerWeakPointer ++func registerWeakPointer(ptr unsafe.Pointer) unsafe.Pointer { ++ // TODO: unimplemented. ++ // I hope not implementing this won't break anything, like packages that ++ // expect weak pointers to be GC'd before they actually are. ++ return ptr ++} ++ + var godebugUpdate func(string, string) + + //go:linkname godebug_setUpdate internal/godebug.setUpdate + +From aae706cae0aec334d4a44ccb760caf9a1d422677 Mon Sep 17 00:00:00 2001 +From: Ayke van Laethem +Date: Fri, 11 Jul 2025 09:34:44 +0200 +Subject: [PATCH 8/8] all: add Go 1.25 support + +--- + .circleci/config.yml | 2 +- + .github/workflows/build-macos.yml | 4 ++-- + .github/workflows/linux.yml | 8 ++++---- + .github/workflows/windows.yml | 8 ++++---- + Dockerfile | 4 ++-- + GNUmakefile | 22 +++++++++++++--------- + builder/config.go | 2 +- + src/crypto/x509/internal/macos/macos.go | 4 ++++ + src/runtime/time.go | 6 ++++++ + 9 files changed, 37 insertions(+), 23 deletions(-) + +diff --git a/.circleci/config.yml b/.circleci/config.yml +index afa7a73001..68a013a253 100644 +--- a/.circleci/config.yml ++++ b/.circleci/config.yml +@@ -105,7 +105,7 @@ jobs: + # This tests the latest supported LLVM version when linking against system + # libraries. + docker: +- - image: golang:1.24-bullseye ++ - image: golang:1.25rc2-bullseye + steps: + - test-linux: + llvm: "20" +diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml +index bda9474327..564978c821 100644 +--- a/.github/workflows/build-macos.yml ++++ b/.github/workflows/build-macos.yml +@@ -39,7 +39,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Restore LLVM source cache + uses: actions/cache/restore@v4 +@@ -134,7 +134,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Build TinyGo (LLVM ${{ matrix.version }}) + run: go install -tags=llvm${{ matrix.version }} +diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml +index 803759892f..52e49eaff2 100644 +--- a/.github/workflows/linux.yml ++++ b/.github/workflows/linux.yml +@@ -18,7 +18,7 @@ jobs: + # statically linked binary. + runs-on: ubuntu-latest + container: +- image: golang:1.24-alpine ++ image: golang:1.25rc2-alpine + outputs: + version: ${{ steps.version.outputs.version }} + steps: +@@ -137,7 +137,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Install wasmtime + uses: bytecodealliance/actions/wasmtime/setup@v1 +@@ -181,7 +181,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Install Node.js + uses: actions/setup-node@v4 +@@ -298,7 +298,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Restore LLVM source cache + uses: actions/cache/restore@v4 +diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml +index 6c428c98c4..ee7fbf1adb 100644 +--- a/.github/workflows/windows.yml ++++ b/.github/workflows/windows.yml +@@ -41,7 +41,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Restore cached LLVM source + uses: actions/cache/restore@v4 +@@ -147,7 +147,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Download TinyGo build + uses: actions/download-artifact@v4 +@@ -177,7 +177,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Download TinyGo build + uses: actions/download-artifact@v4 +@@ -213,7 +213,7 @@ jobs: + - name: Install Go + uses: actions/setup-go@v5 + with: +- go-version: '1.24' ++ go-version: '1.25.0-rc.2' + cache: true + - name: Download TinyGo build + uses: actions/download-artifact@v4 +diff --git a/Dockerfile b/Dockerfile +index 520ad7c9b5..c45dd5d777 100644 +--- a/Dockerfile ++++ b/Dockerfile +@@ -1,5 +1,5 @@ + # tinygo-llvm stage obtains the llvm source for TinyGo +-FROM golang:1.24 AS tinygo-llvm ++FROM golang:1.25rc2 AS tinygo-llvm + + RUN apt-get update && \ + apt-get install -y apt-utils make cmake clang-15 ninja-build && \ +@@ -33,7 +33,7 @@ RUN cd /tinygo/ && \ + + # tinygo-compiler copies the compiler build over to a base Go container (without + # all the build tools etc). +-FROM golang:1.24 AS tinygo-compiler ++FROM golang:1.25rc2 AS tinygo-compiler + + # Copy tinygo build. + COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo +diff --git a/GNUmakefile b/GNUmakefile +index 2b14dd6ac0..61174600eb 100644 +--- a/GNUmakefile ++++ b/GNUmakefile +@@ -460,11 +460,15 @@ TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS) + TEST_IOFS := false + endif + ++TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic' ++ + # Test known-working standard library packages. + # TODO: parallelize, and only show failing tests (no implied -v flag). + .PHONY: tinygo-test + tinygo-test: +- $(TINYGO) test $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW) ++ @# TestExtraMethods: used by many crypto packages and uses reflect.Type.Method which is not implemented. ++ @# TestParseAndBytesRoundTrip/P256/Generic: relies on t.Skip() which is not implemented ++ $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW) + @# io/fs requires os.ReadDir, not yet supported on windows or wasi. It also + @# requires a large stack-size. Hence, io/fs is only run conditionally. + @# For more details, see the comments on issue #3143. +@@ -472,7 +476,7 @@ ifeq ($(TEST_IOFS),true) + $(TINYGO) test -stack-size=6MB io/fs + endif + tinygo-test-fast: +- $(TINYGO) test $(TEST_PACKAGES_HOST) ++ $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST) + tinygo-bench: + $(TINYGO) test -bench . $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW) + tinygo-bench-fast: +@@ -480,18 +484,18 @@ tinygo-bench-fast: + + # Same thing, except for wasi rather than the current platform. + tinygo-test-wasm: +- $(TINYGO) test -target wasm $(TEST_PACKAGES_WASM) ++ $(TINYGO) test -target wasm $(TEST_SKIP_FLAG) $(TEST_PACKAGES_WASM) + tinygo-test-wasi: +- $(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi ++ $(TINYGO) test -target wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi + tinygo-test-wasip1: +- GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi ++ GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi + tinygo-test-wasip1-fast: +- $(TINYGO) test -target=wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi ++ $(TINYGO) test -target=wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi + + tinygo-test-wasip2-slow: +- $(TINYGO) test -target=wasip2 $(TEST_PACKAGES_SLOW) ++ $(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_SLOW) + tinygo-test-wasip2-fast: +- $(TINYGO) test -target=wasip2 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi ++ $(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi + + tinygo-test-wasip2-sum-slow: + TINYGO=$(TINYGO) \ +@@ -517,7 +521,7 @@ tinygo-bench-wasip2-fast: + + # Run tests on riscv-qemu since that one provides a large amount of memory. + tinygo-test-baremetal: +- $(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL) ++ $(TINYGO) test -target riscv-qemu $(TEST_SKIP_FLAG) $(TEST_PACKAGES_BAREMETAL) + + # Test external packages in a large corpus. + test-corpus: +diff --git a/builder/config.go b/builder/config.go +index b36b9333f3..5fb74ee192 100644 +--- a/builder/config.go ++++ b/builder/config.go +@@ -26,7 +26,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { + + // Version range supported by TinyGo. + const minorMin = 19 +- const minorMax = 24 ++ const minorMax = 25 + + // Check that we support this Go toolchain version. + gorootMajor, gorootMinor, err := goenv.GetGorootVersion() +diff --git a/src/crypto/x509/internal/macos/macos.go b/src/crypto/x509/internal/macos/macos.go +index e9ec2ef843..c662acb577 100644 +--- a/src/crypto/x509/internal/macos/macos.go ++++ b/src/crypto/x509/internal/macos/macos.go +@@ -63,6 +63,10 @@ func SecCertificateCopyData(cert CFRef) ([]byte, error) { + return nil, errors.New("not implemented") + } + ++func SecTrustCopyCertificateChain(trustObj CFRef) (CFRef, error) { ++ return 0, errors.New("not implemented") ++} ++ + func SecTrustEvaluateWithError(trustObj CFRef) (int, error) { + return 0, errors.New("not implemented") + } +diff --git a/src/runtime/time.go b/src/runtime/time.go +index 3935b4486e..23a9bf5e2f 100644 +--- a/src/runtime/time.go ++++ b/src/runtime/time.go +@@ -46,3 +46,9 @@ func timerCallback(tn *timerNode, delta int64) { + addTimer(tn) + } + } ++ ++//go:linkname time_runtimeIsBubbled time.runtimeIsBubbled ++func time_runtimeIsBubbled() bool { ++ // We don't currently support bubbles. ++ return false ++} diff --git a/tinygo.spec b/tinygo.spec index 6c0bd0c..2e9fe62 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -102,6 +102,8 @@ Patch: 0005-Normalize-expected-path-for-chdir-tests.patch Patch: https://github.com/tinygo-org/tinygo/commit/1b5d312c689a004434cb77f161f65b9615c98036.patch # https://github.com/tinygo-org/tinygo/issues/4969 Patch: 0006-Skip-x86-tests-on-ARM.patch +# Support for Go 1.25. +Patch: https://github.com/tinygo-org/tinygo/pull/4954.patch # Fix CVE-2025-26519 in musl. Patch1600: https://www.openwall.com/lists/musl/2025/02/13/1/1#/musl-cve-2025-26519-1.patch From 1ba82360fbbef4718c4f37056a19efe9b24cf0c2 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Fri, 15 Aug 2025 18:42:25 -0500 Subject: [PATCH 75/78] Rebuild for golang-1.25.0 From 20e209e6d0474503bf575c1bd1e2e86c4b372299 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 25 Aug 2025 03:25:16 -0400 Subject: [PATCH 76/78] Update to latest version (#2389619) --- 0001-Skip-WASI-tests.patch | 8 +- ...ip-tests-that-require-Go-module-mode.patch | 8 +- 0003-Set-LLVM-search-paths-for-Fedora.patch | 4 +- ...-Add-flag-to-skip-Renesas-SVD-builds.patch | 29 - ...malize-expected-path-for-chdir-tests.patch | 4 +- ....patch => 0005-Skip-x86-tests-on-ARM.patch | 8 +- ...312c689a004434cb77f161f65b9615c98036.patch | 69 --- 4954.patch | 575 ------------------ sources | 2 +- tinygo.spec | 13 +- 10 files changed, 20 insertions(+), 700 deletions(-) delete mode 100644 0004-Add-flag-to-skip-Renesas-SVD-builds.patch rename 0005-Normalize-expected-path-for-chdir-tests.patch => 0004-Normalize-expected-path-for-chdir-tests.patch (88%) rename 0006-Skip-x86-tests-on-ARM.patch => 0005-Skip-x86-tests-on-ARM.patch (89%) delete mode 100644 1b5d312c689a004434cb77f161f65b9615c98036.patch delete mode 100644 4954.patch diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch index 8a26135..32e8ce8 100644 --- a/0001-Skip-WASI-tests.patch +++ b/0001-Skip-WASI-tests.patch @@ -1,7 +1,7 @@ -From cedd957d01a235fa05957242ea5c291b0fbc2e3d Mon Sep 17 00:00:00 2001 +From fdd5322026e4b7b2e7fe6a80628b7239b4c4eb99 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/6] Skip WASI tests. +Subject: [PATCH 1/5] Skip WASI tests. We do not have wasmtime available. @@ -11,7 +11,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 17 deletions(-) diff --git a/main_test.go b/main_test.go -index 5563b7ca..77b93c4d 100644 +index b07d6aaa..ae0a4482 100644 --- a/main_test.go +++ b/main_test.go @@ -188,22 +188,6 @@ func TestBuild(t *testing.T) { @@ -37,7 +37,7 @@ index 5563b7ca..77b93c4d 100644 } if runtime.GOOS == "linux" { -@@ -921,7 +905,6 @@ func TestTest(t *testing.T) { +@@ -925,7 +909,6 @@ func TestTest(t *testing.T) { // Node/Wasmtime targ{"WASM", optionsFromTarget("wasm", sema)}, diff --git a/0002-Skip-tests-that-require-Go-module-mode.patch b/0002-Skip-tests-that-require-Go-module-mode.patch index a4df02a..01dc83c 100644 --- a/0002-Skip-tests-that-require-Go-module-mode.patch +++ b/0002-Skip-tests-that-require-Go-module-mode.patch @@ -1,7 +1,7 @@ -From e3af7cfc28d948721d94cf6eafedf731453c50b5 Mon Sep 17 00:00:00 2001 +From f650ab16b5a3badf48922f77683ceaf791c82d64 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Feb 2024 04:26:40 -0500 -Subject: [PATCH 2/6] Skip tests that require Go module mode +Subject: [PATCH 2/5] Skip tests that require Go module mode Signed-off-by: Elliott Sales de Andrade --- @@ -24,7 +24,7 @@ index 871dc4c0..3d0bb162 100644 {name: "syntax"}, {name: "types"}, diff --git a/main_test.go b/main_test.go -index 77b93c4d..62153c69 100644 +index ae0a4482..ca052821 100644 --- a/main_test.go +++ b/main_test.go @@ -78,7 +78,6 @@ func TestBuild(t *testing.T) { @@ -35,7 +35,7 @@ index 77b93c4d..62153c69 100644 "print.go", "reflect.go", "signal.go", -@@ -1027,6 +1026,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { +@@ -1031,6 +1030,7 @@ func ioLogger(t *testing.T, wg *sync.WaitGroup) io.WriteCloser { } func TestGetListOfPackages(t *testing.T) { diff --git a/0003-Set-LLVM-search-paths-for-Fedora.patch b/0003-Set-LLVM-search-paths-for-Fedora.patch index 513149c..d375623 100644 --- a/0003-Set-LLVM-search-paths-for-Fedora.patch +++ b/0003-Set-LLVM-search-paths-for-Fedora.patch @@ -1,7 +1,7 @@ -From 18c5c78780371a39e79b983f8c3c71b24f5663d1 Mon Sep 17 00:00:00 2001 +From d516beb86673a9b80ca75c41e8fb7cba7e3f126f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 27 Oct 2024 23:33:18 -0400 -Subject: [PATCH 3/6] Set LLVM search paths for Fedora +Subject: [PATCH 3/5] Set LLVM search paths for Fedora Signed-off-by: Elliott Sales de Andrade --- diff --git a/0004-Add-flag-to-skip-Renesas-SVD-builds.patch b/0004-Add-flag-to-skip-Renesas-SVD-builds.patch deleted file mode 100644 index 4af0f29..0000000 --- a/0004-Add-flag-to-skip-Renesas-SVD-builds.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 4a6bd01a01e551ea3ba0c5128628eea2714ba122 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Tue, 31 Dec 2024 00:34:13 -0500 -Subject: [PATCH 4/6] Add flag to skip Renesas SVD builds - -Signed-off-by: Elliott Sales de Andrade ---- - GNUmakefile | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/GNUmakefile b/GNUmakefile -index f078bde5..321444da 100644 ---- a/GNUmakefile -+++ b/GNUmakefile -@@ -187,7 +187,10 @@ fmt-check: ## Warn if any source needs reformatting - @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 - - --gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp gen-device-renesas ## Generate microcontroller-specific sources -+gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp ## Generate microcontroller-specific sources -+ifneq ($(RENESAS), 0) -+gen-device: gen-device-renesas -+endif - ifneq ($(STM32), 0) - gen-device: gen-device-stm32 - endif --- -2.50.0 - diff --git a/0005-Normalize-expected-path-for-chdir-tests.patch b/0004-Normalize-expected-path-for-chdir-tests.patch similarity index 88% rename from 0005-Normalize-expected-path-for-chdir-tests.patch rename to 0004-Normalize-expected-path-for-chdir-tests.patch index 2869273..0285c03 100644 --- a/0005-Normalize-expected-path-for-chdir-tests.patch +++ b/0004-Normalize-expected-path-for-chdir-tests.patch @@ -1,7 +1,7 @@ -From cef23b5da7902eaf69cc621ad384ea7815082e86 Mon Sep 17 00:00:00 2001 +From d83874e6ab92ee4142cc7672da226a9091f7211a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 31 Dec 2024 02:00:17 -0500 -Subject: [PATCH 5/6] Normalize expected path for chdir tests +Subject: [PATCH 4/5] Normalize expected path for chdir tests The expected path comes from a simple string concatenation in shell, but `os.Getwd` appears to have the normalized working directory, so this can diff --git a/0006-Skip-x86-tests-on-ARM.patch b/0005-Skip-x86-tests-on-ARM.patch similarity index 89% rename from 0006-Skip-x86-tests-on-ARM.patch rename to 0005-Skip-x86-tests-on-ARM.patch index e933ac9..aab0e48 100644 --- a/0006-Skip-x86-tests-on-ARM.patch +++ b/0005-Skip-x86-tests-on-ARM.patch @@ -1,7 +1,7 @@ -From 342403c5c6e1d7d2a38c791c90c0937ecb5713d5 Mon Sep 17 00:00:00 2001 +From 9c8cef8d589dfbd2d913010a1211d8a49279c986 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 2 Aug 2025 18:30:43 -0400 -Subject: [PATCH 6/6] Skip x86 tests on ARM +Subject: [PATCH 5/5] Skip x86 tests on ARM They are currently broken: https://github.com/tinygo-org/tinygo/issues/4969 @@ -12,7 +12,7 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main_test.go b/main_test.go -index 62153c69..c1de9e72 100644 +index ca052821..13a40997 100644 --- a/main_test.go +++ b/main_test.go @@ -192,7 +192,10 @@ func TestBuild(t *testing.T) { @@ -27,7 +27,7 @@ index 62153c69..c1de9e72 100644 t.Run(name, func(t *testing.T) { runPlatTests(options, tests, t) }) -@@ -891,7 +894,10 @@ func TestTest(t *testing.T) { +@@ -895,7 +898,10 @@ func TestTest(t *testing.T) { if runtime.GOOS == "linux" { for name, osArch := range supportedLinuxArches { options := optionsFromOSARCH(osArch, sema) diff --git a/1b5d312c689a004434cb77f161f65b9615c98036.patch b/1b5d312c689a004434cb77f161f65b9615c98036.patch deleted file mode 100644 index 796bf7c..0000000 --- a/1b5d312c689a004434cb77f161f65b9615c98036.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 1b5d312c689a004434cb77f161f65b9615c98036 Mon Sep 17 00:00:00 2001 -From: Elias Naur -Date: Thu, 17 Jul 2025 12:58:43 +0200 -Subject: [PATCH] tests: de-flake goroutines test - ---- - main_test.go | 4 ++++ - testdata/goroutines.go | 4 ++++ - 2 files changed, 8 insertions(+) - -diff --git a/main_test.go b/main_test.go -index 5563b7cab2..b07d6aaaa4 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -424,10 +424,12 @@ func optionsFromOSARCH(osarch string, sema chan struct{}) compileopts.Options { - } - - func runTest(name string, options compileopts.Options, t *testing.T, cmdArgs, environmentVars []string) { -+ t.Helper() - runTestWithConfig(name, t, options, cmdArgs, environmentVars) - } - - func runTestWithConfig(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) { -+ t.Helper() - // Get the expected output for this test. - // Note: not using filepath.Join as it strips the path separator at the end - // of the path. -@@ -876,6 +878,7 @@ func TestWasmExit(t *testing.T) { - - // Check whether the output of a test equals the expected output. - func checkOutput(t *testing.T, filename string, actual []byte) { -+ t.Helper() - expectedOutput, err := os.ReadFile(filename) - if err != nil { - t.Fatal("could not read output file:", err) -@@ -884,6 +887,7 @@ func checkOutput(t *testing.T, filename string, actual []byte) { - } - - func checkOutputData(t *testing.T, expectedOutput, actual []byte) { -+ t.Helper() - expectedOutput = bytes.ReplaceAll(expectedOutput, []byte("\r\n"), []byte("\n")) - actual = bytes.ReplaceAll(actual, []byte("\r\n"), []byte("\n")) - -diff --git a/testdata/goroutines.go b/testdata/goroutines.go -index 8653cdb173..7397b5503a 100644 ---- a/testdata/goroutines.go -+++ b/testdata/goroutines.go -@@ -175,10 +175,13 @@ func testGoOnBuiltins() { - - var once sync.Once - -+var waitChan = make(chan struct{}) -+ - func testGoOnInterface(f Itf) { - go f.Nowait() - time.Sleep(time.Millisecond) - go f.Wait() -+ <-waitChan - time.Sleep(time.Millisecond * 2) - println("done with 'go on interface'") - } -@@ -204,6 +207,7 @@ func (f Foo) Nowait() { - - func (f Foo) Wait() { - println("called: Foo.Wait") -+ close(waitChan) - time.Sleep(time.Microsecond) - println(" ...waited") - } diff --git a/4954.patch b/4954.patch deleted file mode 100644 index e1ea046..0000000 --- a/4954.patch +++ /dev/null @@ -1,575 +0,0 @@ -From 2c34e1bce5f75ba34a6ba11755801ff0b82fd638 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 11 Jul 2025 09:21:09 +0200 -Subject: [PATCH 1/8] ci: rename some jobs to avoid churn on every Go/LLVM - version bump - ---- - .circleci/config.yml | 15 ++++++++------- - 1 file changed, 8 insertions(+), 7 deletions(-) - -diff --git a/.circleci/config.yml b/.circleci/config.yml -index 5a73dceae2..afa7a73001 100644 ---- a/.circleci/config.yml -+++ b/.circleci/config.yml -@@ -92,14 +92,18 @@ commands: - - /go/pkg/mod - - jobs: -- test-llvm15-go122: -+ test-oldest: -+ # This tests our lowest supported versions of Go and LLVM, to make sure at -+ # least the smoke tests still pass. - docker: - - image: golang:1.22-bullseye - steps: - - test-linux: - llvm: "15" - resource_class: large -- test-llvm20-go124: -+ test-newest: -+ # This tests the latest supported LLVM version when linking against system -+ # libraries. - docker: - - image: golang:1.24-bullseye - steps: -@@ -110,8 +114,5 @@ jobs: - workflows: - test-all: - jobs: -- # This tests our lowest supported versions of Go and LLVM, to make sure at -- # least the smoke tests still pass. -- - test-llvm15-go122 -- # This tests LLVM 20 support when linking against system libraries. -- - test-llvm20-go124 -+ - test-oldest -+ - test-newest - -From 527ebbe6f74eedfc764252740744bcaf0ee6826f Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 11 Jul 2025 15:45:42 +0200 -Subject: [PATCH 2/8] reflect: implement Method.IsExported - ---- - src/reflect/type.go | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/reflect/type.go b/src/reflect/type.go -index 828cf12e27..884f89dc84 100644 ---- a/src/reflect/type.go -+++ b/src/reflect/type.go -@@ -127,6 +127,11 @@ type Method struct { - Index int // index for Type.Method - } - -+// IsExported reports whether the method is exported. -+func (m Method) IsExported() bool { -+ return m.PkgPath == "" -+} -+ - // The following Type type has been copied almost entirely from - // https://github.com/golang/go/blob/go1.15/src/reflect/type.go#L27-L212. - // Some methods have been commented out as they haven't yet been implemented. - -From 63ff828af46555f98d3a7fb0bcd0c53891049835 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 31 Jul 2025 13:44:13 +0200 -Subject: [PATCH 3/8] sync: implement sync.Swap - ---- - src/sync/map.go | 12 ++++++++++++ - src/sync/map_test.go | 19 +++++++++++++++++++ - 2 files changed, 31 insertions(+) - -diff --git a/src/sync/map.go b/src/sync/map.go -index cd8a1967d6..8b5c0cff76 100644 ---- a/src/sync/map.go -+++ b/src/sync/map.go -@@ -70,3 +70,15 @@ func (m *Map) Range(f func(key, value interface{}) bool) { - } - } - } -+ -+// Swap replaces the value for the given key, and returns the old value if any. -+func (m *Map) Swap(key, value any) (previous any, loaded bool) { -+ m.lock.Lock() -+ defer m.lock.Unlock() -+ if m.m == nil { -+ m.m = make(map[interface{}]interface{}) -+ } -+ previous, loaded = m.m[key] -+ m.m[key] = value -+ return -+} -diff --git a/src/sync/map_test.go b/src/sync/map_test.go -index f493bdfb51..a41faa40fd 100644 ---- a/src/sync/map_test.go -+++ b/src/sync/map_test.go -@@ -17,3 +17,22 @@ func TestMapLoadAndDelete(t *testing.T) { - t.Errorf("LoadAndDelete returned %v, %v, want nil, false", v, ok) - } - } -+ -+func TestMapSwap(t *testing.T) { -+ var sm sync.Map -+ sm.Store("present", "value") -+ -+ if v, ok := sm.Swap("present", "value2"); !ok || v != "value" { -+ t.Errorf("Swap returned %v, %v, want value, true", v, ok) -+ } -+ if v, ok := sm.Load("present"); !ok || v != "value2" { -+ t.Errorf("Load after Swap returned %v, %v, want value2, true", v, ok) -+ } -+ -+ if v, ok := sm.Swap("new", "foo"); ok || v != nil { -+ t.Errorf("Swap returned %v, %v, want nil, false", v, ok) -+ } -+ if v, ok := sm.Load("present"); !ok || v != "value2" { -+ t.Errorf("Load after Swap returned %v, %v, want foo, true", v, ok) -+ } -+} - -From 87bed715943b5a8a11aaa5c84e0f2dc8ac8046cf Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Thu, 31 Jul 2025 13:51:17 +0200 -Subject: [PATCH 4/8] runtime: implement dummy AddCleanup - ---- - src/runtime/runtime.go | 19 +++++++++++++++++++ - 1 file changed, 19 insertions(+) - -diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go -index 6bd719f548..7ad482a055 100644 ---- a/src/runtime/runtime.go -+++ b/src/runtime/runtime.go -@@ -106,6 +106,25 @@ func UnlockOSThread() { - // point of the call. - func KeepAlive(x interface{}) - -+// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up. -+// -+// We base this on the following loophole in the official runtime.AddCleanup -+// documentation: -+// -+// > The cleanup(arg) call is not always guaranteed to run; in particular it is -+// > not guaranteed to run before program exit. -+// -+// So it's technically correct (the best kind of correct) to not run any -+// cleanups. But of course, this can lead to resource leaks so cleanups may need -+// to be implemented eventually. -+func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup { -+ return Cleanup{} -+} -+ -+type Cleanup struct{} -+ -+func (c Cleanup) Stop() {} -+ - var godebugUpdate func(string, string) - - //go:linkname godebug_setUpdate internal/godebug.setUpdate - -From dd10065061fb3e33bf0f006ef3b4fae53483c019 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Mon, 4 Aug 2025 10:27:41 +0200 -Subject: [PATCH 5/8] compiler: implement internal/abi.Escape - ---- - compiler/intrinsics.go | 23 +++++++++++++++++++++++ - compiler/symbol.go | 17 +++++++++++++++++ - src/internal/abi/escape.go | 7 +++++++ - 3 files changed, 47 insertions(+) - -diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go -index 3c7edd7c95..5f1ba6f7d1 100644 ---- a/compiler/intrinsics.go -+++ b/compiler/intrinsics.go -@@ -121,6 +121,29 @@ func (b *builder) createKeepAliveImpl() { - b.CreateRetVoid() - } - -+// createAbiEscapeImpl implements the generic internal/abi.Escape function. It -+// currently only supports pointer types. -+func (b *builder) createAbiEscapeImpl() { -+ b.createFunctionStart(true) -+ -+ // The first parameter is assumed to be a pointer. This is checked at the -+ // call site of createAbiEscapeImpl. -+ pointerValue := b.getValue(b.fn.Params[0], getPos(b.fn)) -+ -+ // Create an equivalent of the following C code, which is basically just a -+ // nop but ensures the pointerValue is kept alive: -+ // -+ // __asm__ __volatile__("" : : "r"(pointerValue)) -+ // -+ // It should be portable to basically everything as the "r" register type -+ // exists basically everywhere. -+ asmType := llvm.FunctionType(b.dataPtrType, []llvm.Type{b.dataPtrType}, false) -+ asmFn := llvm.InlineAsm(asmType, "", "=r,0", true, false, 0, false) -+ result := b.createCall(asmType, asmFn, []llvm.Value{pointerValue}, "") -+ -+ b.CreateRet(result) -+} -+ - var mathToLLVMMapping = map[string]string{ - "math.Ceil": "llvm.ceil.f64", - "math.Exp": "llvm.exp.f64", -diff --git a/compiler/symbol.go b/compiler/symbol.go -index c56e0792f2..2507b3eedb 100644 ---- a/compiler/symbol.go -+++ b/compiler/symbol.go -@@ -253,6 +253,23 @@ func (c *compilerContext) maybeCreateSyntheticFunction(fn *ssa.Function, llvmFn - // The exception is the package initializer, which does appear in the - // *ssa.Package members and so shouldn't be created here. - if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" && fn.Synthetic != "range-over-func yield" { -+ if origin := fn.Origin(); origin != nil && origin.RelString(nil) == "internal/abi.Escape" { -+ // This is a special implementation or internal/abi.Escape, which -+ // can only really be implemented in the compiler. -+ // For simplicity we'll only implement pointer parameters for now. -+ if _, ok := fn.Params[0].Type().Underlying().(*types.Pointer); ok { -+ irbuilder := c.ctx.NewBuilder() -+ defer irbuilder.Dispose() -+ b := newBuilder(c, irbuilder, fn) -+ b.createAbiEscapeImpl() -+ llvmFn.SetLinkage(llvm.LinkOnceODRLinkage) -+ llvmFn.SetUnnamedAddr(true) -+ } -+ // If the parameter is not of a pointer type, it will be left -+ // unimplemented. This will result in a linker error if the function -+ // is really called, making it clear it needs to be implemented. -+ return -+ } - if len(fn.Blocks) == 0 { - c.addError(fn.Pos(), "missing function body") - return -diff --git a/src/internal/abi/escape.go b/src/internal/abi/escape.go -index 0ecdf80308..1f4c763312 100644 ---- a/src/internal/abi/escape.go -+++ b/src/internal/abi/escape.go -@@ -8,3 +8,10 @@ import "unsafe" - func NoEscape(p unsafe.Pointer) unsafe.Pointer { - return p - } -+ -+func Escape[T any](x T) T { -+ // This function is either implemented in the compiler, or left undefined -+ // for some variation of T. The body of this function should not be compiled -+ // as-is. -+ panic("internal/abi.Escape: unreachable (implemented in the compiler)") -+} - -From 6ea7aa68492ee4de9b9aa4ce0faa8104a5b3f590 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Mon, 4 Aug 2025 10:28:01 +0200 -Subject: [PATCH 6/8] testing: stub out testing.B.Loop - -This gets the path package tests to pass, so we can move ahead with Go -1.25. It should be implemented in the future at some point (that, or -we'll use the upstream testing package instead). ---- - src/testing/benchmark.go | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go -index 53c7fc7b10..2dc59b72fd 100644 ---- a/src/testing/benchmark.go -+++ b/src/testing/benchmark.go -@@ -500,6 +500,10 @@ func (b *B) RunParallel(body func(*PB)) { - return - } - -+func (b *B) Loop() bool { -+ panic("unimplemented: testing.B.Loop") -+} -+ - // Benchmark benchmarks a single function. It is useful for creating - // custom benchmarks that do not use the "go test" command. - // - -From fc6d509c4235a980f0ef40cd30f207e9a1a697d0 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Mon, 4 Aug 2025 10:31:48 +0200 -Subject: [PATCH 7/8] runtime: stub out weak pointer support - ---- - src/runtime/runtime.go | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go -index 7ad482a055..3bd98319e8 100644 ---- a/src/runtime/runtime.go -+++ b/src/runtime/runtime.go -@@ -125,6 +125,14 @@ type Cleanup struct{} - - func (c Cleanup) Stop() {} - -+//go:linkname registerWeakPointer weak.runtime_registerWeakPointer -+func registerWeakPointer(ptr unsafe.Pointer) unsafe.Pointer { -+ // TODO: unimplemented. -+ // I hope not implementing this won't break anything, like packages that -+ // expect weak pointers to be GC'd before they actually are. -+ return ptr -+} -+ - var godebugUpdate func(string, string) - - //go:linkname godebug_setUpdate internal/godebug.setUpdate - -From aae706cae0aec334d4a44ccb760caf9a1d422677 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Fri, 11 Jul 2025 09:34:44 +0200 -Subject: [PATCH 8/8] all: add Go 1.25 support - ---- - .circleci/config.yml | 2 +- - .github/workflows/build-macos.yml | 4 ++-- - .github/workflows/linux.yml | 8 ++++---- - .github/workflows/windows.yml | 8 ++++---- - Dockerfile | 4 ++-- - GNUmakefile | 22 +++++++++++++--------- - builder/config.go | 2 +- - src/crypto/x509/internal/macos/macos.go | 4 ++++ - src/runtime/time.go | 6 ++++++ - 9 files changed, 37 insertions(+), 23 deletions(-) - -diff --git a/.circleci/config.yml b/.circleci/config.yml -index afa7a73001..68a013a253 100644 ---- a/.circleci/config.yml -+++ b/.circleci/config.yml -@@ -105,7 +105,7 @@ jobs: - # This tests the latest supported LLVM version when linking against system - # libraries. - docker: -- - image: golang:1.24-bullseye -+ - image: golang:1.25rc2-bullseye - steps: - - test-linux: - llvm: "20" -diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml -index bda9474327..564978c821 100644 ---- a/.github/workflows/build-macos.yml -+++ b/.github/workflows/build-macos.yml -@@ -39,7 +39,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Restore LLVM source cache - uses: actions/cache/restore@v4 -@@ -134,7 +134,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Build TinyGo (LLVM ${{ matrix.version }}) - run: go install -tags=llvm${{ matrix.version }} -diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml -index 803759892f..52e49eaff2 100644 ---- a/.github/workflows/linux.yml -+++ b/.github/workflows/linux.yml -@@ -18,7 +18,7 @@ jobs: - # statically linked binary. - runs-on: ubuntu-latest - container: -- image: golang:1.24-alpine -+ image: golang:1.25rc2-alpine - outputs: - version: ${{ steps.version.outputs.version }} - steps: -@@ -137,7 +137,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Install wasmtime - uses: bytecodealliance/actions/wasmtime/setup@v1 -@@ -181,7 +181,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Install Node.js - uses: actions/setup-node@v4 -@@ -298,7 +298,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Restore LLVM source cache - uses: actions/cache/restore@v4 -diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml -index 6c428c98c4..ee7fbf1adb 100644 ---- a/.github/workflows/windows.yml -+++ b/.github/workflows/windows.yml -@@ -41,7 +41,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Restore cached LLVM source - uses: actions/cache/restore@v4 -@@ -147,7 +147,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Download TinyGo build - uses: actions/download-artifact@v4 -@@ -177,7 +177,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Download TinyGo build - uses: actions/download-artifact@v4 -@@ -213,7 +213,7 @@ jobs: - - name: Install Go - uses: actions/setup-go@v5 - with: -- go-version: '1.24' -+ go-version: '1.25.0-rc.2' - cache: true - - name: Download TinyGo build - uses: actions/download-artifact@v4 -diff --git a/Dockerfile b/Dockerfile -index 520ad7c9b5..c45dd5d777 100644 ---- a/Dockerfile -+++ b/Dockerfile -@@ -1,5 +1,5 @@ - # tinygo-llvm stage obtains the llvm source for TinyGo --FROM golang:1.24 AS tinygo-llvm -+FROM golang:1.25rc2 AS tinygo-llvm - - RUN apt-get update && \ - apt-get install -y apt-utils make cmake clang-15 ninja-build && \ -@@ -33,7 +33,7 @@ RUN cd /tinygo/ && \ - - # tinygo-compiler copies the compiler build over to a base Go container (without - # all the build tools etc). --FROM golang:1.24 AS tinygo-compiler -+FROM golang:1.25rc2 AS tinygo-compiler - - # Copy tinygo build. - COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo -diff --git a/GNUmakefile b/GNUmakefile -index 2b14dd6ac0..61174600eb 100644 ---- a/GNUmakefile -+++ b/GNUmakefile -@@ -460,11 +460,15 @@ TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS) - TEST_IOFS := false - endif - -+TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic' -+ - # Test known-working standard library packages. - # TODO: parallelize, and only show failing tests (no implied -v flag). - .PHONY: tinygo-test - tinygo-test: -- $(TINYGO) test $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW) -+ @# TestExtraMethods: used by many crypto packages and uses reflect.Type.Method which is not implemented. -+ @# TestParseAndBytesRoundTrip/P256/Generic: relies on t.Skip() which is not implemented -+ $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW) - @# io/fs requires os.ReadDir, not yet supported on windows or wasi. It also - @# requires a large stack-size. Hence, io/fs is only run conditionally. - @# For more details, see the comments on issue #3143. -@@ -472,7 +476,7 @@ ifeq ($(TEST_IOFS),true) - $(TINYGO) test -stack-size=6MB io/fs - endif - tinygo-test-fast: -- $(TINYGO) test $(TEST_PACKAGES_HOST) -+ $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST) - tinygo-bench: - $(TINYGO) test -bench . $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW) - tinygo-bench-fast: -@@ -480,18 +484,18 @@ tinygo-bench-fast: - - # Same thing, except for wasi rather than the current platform. - tinygo-test-wasm: -- $(TINYGO) test -target wasm $(TEST_PACKAGES_WASM) -+ $(TINYGO) test -target wasm $(TEST_SKIP_FLAG) $(TEST_PACKAGES_WASM) - tinygo-test-wasi: -- $(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi -+ $(TINYGO) test -target wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi - tinygo-test-wasip1: -- GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi -+ GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi - tinygo-test-wasip1-fast: -- $(TINYGO) test -target=wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi -+ $(TINYGO) test -target=wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi - - tinygo-test-wasip2-slow: -- $(TINYGO) test -target=wasip2 $(TEST_PACKAGES_SLOW) -+ $(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_SLOW) - tinygo-test-wasip2-fast: -- $(TINYGO) test -target=wasip2 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi -+ $(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi - - tinygo-test-wasip2-sum-slow: - TINYGO=$(TINYGO) \ -@@ -517,7 +521,7 @@ tinygo-bench-wasip2-fast: - - # Run tests on riscv-qemu since that one provides a large amount of memory. - tinygo-test-baremetal: -- $(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL) -+ $(TINYGO) test -target riscv-qemu $(TEST_SKIP_FLAG) $(TEST_PACKAGES_BAREMETAL) - - # Test external packages in a large corpus. - test-corpus: -diff --git a/builder/config.go b/builder/config.go -index b36b9333f3..5fb74ee192 100644 ---- a/builder/config.go -+++ b/builder/config.go -@@ -26,7 +26,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { - - // Version range supported by TinyGo. - const minorMin = 19 -- const minorMax = 24 -+ const minorMax = 25 - - // Check that we support this Go toolchain version. - gorootMajor, gorootMinor, err := goenv.GetGorootVersion() -diff --git a/src/crypto/x509/internal/macos/macos.go b/src/crypto/x509/internal/macos/macos.go -index e9ec2ef843..c662acb577 100644 ---- a/src/crypto/x509/internal/macos/macos.go -+++ b/src/crypto/x509/internal/macos/macos.go -@@ -63,6 +63,10 @@ func SecCertificateCopyData(cert CFRef) ([]byte, error) { - return nil, errors.New("not implemented") - } - -+func SecTrustCopyCertificateChain(trustObj CFRef) (CFRef, error) { -+ return 0, errors.New("not implemented") -+} -+ - func SecTrustEvaluateWithError(trustObj CFRef) (int, error) { - return 0, errors.New("not implemented") - } -diff --git a/src/runtime/time.go b/src/runtime/time.go -index 3935b4486e..23a9bf5e2f 100644 ---- a/src/runtime/time.go -+++ b/src/runtime/time.go -@@ -46,3 +46,9 @@ func timerCallback(tn *timerNode, delta int64) { - addTimer(tn) - } - } -+ -+//go:linkname time_runtimeIsBubbled time.runtimeIsBubbled -+func time_runtimeIsBubbled() bool { -+ // We don't currently support bubbles. -+ return false -+} diff --git a/sources b/sources index 0a75777..e96310c 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.38.0.tar.gz) = 1e7d64caa20c2a12390de36067b50f3cc3b675a3e4818d6fa463816c42cbd94101989863936f5ed38ce1224e99cdf69e3c251debcdb7c9f16daf42876fae2f9e +SHA512 (tinygo-0.39.0.tar.gz) = ab9dbe6bfac56470d3703617bd0da152b044e84ced1bfcfb7e7bf6ba8880d07dfac267dca7356ace18bd3ed392ed7031b6cb4a2535ad5f956ab5912ecefe3807 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (bdwgc-1166f11f7dee08d7ad369296b24cf8c9582f8789.tar.gz) = 030d5a9a0931915a76b1ec270e7208199cf40973ac6c8141c02e34f118f965bedcadff3bb36481b0e45703df8eb2750d20809f3fde367fd5efed5f8a44ccab32 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 diff --git a/tinygo.spec b/tinygo.spec index 2e9fe62..0242570 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -8,7 +8,7 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.38.0 +Version: 0.39.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 @@ -93,17 +93,10 @@ Patch: 0001-Skip-WASI-tests.patch Patch: 0002-Skip-tests-that-require-Go-module-mode.patch # Better search paths for non-default LLVM. Patch: 0003-Set-LLVM-search-paths-for-Fedora.patch -# We can't include these due to poor licensing. -# https://github.com/tinygo-org/tinygo/pull/4962 -Patch: 0004-Add-flag-to-skip-Renesas-SVD-builds.patch #https://github.com/tinygo-org/tinygo/pull/4677 -Patch: 0005-Normalize-expected-path-for-chdir-tests.patch -# https://github.com/tinygo-org/tinygo/pull/4958 -Patch: https://github.com/tinygo-org/tinygo/commit/1b5d312c689a004434cb77f161f65b9615c98036.patch +Patch: 0004-Normalize-expected-path-for-chdir-tests.patch # https://github.com/tinygo-org/tinygo/issues/4969 -Patch: 0006-Skip-x86-tests-on-ARM.patch -# Support for Go 1.25. -Patch: https://github.com/tinygo-org/tinygo/pull/4954.patch +Patch: 0005-Skip-x86-tests-on-ARM.patch # Fix CVE-2025-26519 in musl. Patch1600: https://www.openwall.com/lists/musl/2025/02/13/1/1#/musl-cve-2025-26519-1.patch From faf08a188dd9cacdda772a9cb100ea48a6d0bebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1ez?= Date: Fri, 10 Oct 2025 15:13:25 +0200 Subject: [PATCH 77/78] rebuild From da069d072ea5fe63a44329666b4b46f3a2c0c41b Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 11 Oct 2025 21:17:25 -0500 Subject: [PATCH 78/78] Rebuild for golang 1.25.2