From 52b73ed7f4072490f2eeb3abaec7f68ef69243f0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Nov 29 2021 10:44:16 +0000 Subject: Support multi-LLVM build from golang-tinygo-x-llvm --- 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}