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).
Этот коммит содержится в:
родитель
184175378f
коммит
b40f250530
11 изменённых файлов: 86 добавлений и 15 удалений
|
@ -424,12 +424,12 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- test-linux:
|
- test-linux:
|
||||||
llvm: "10"
|
llvm: "10"
|
||||||
test-llvm10-go115:
|
test-llvm11-go115:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/golang:1.15-buster
|
- image: circleci/golang:1.15-buster
|
||||||
steps:
|
steps:
|
||||||
- test-linux:
|
- test-linux:
|
||||||
llvm: "10"
|
llvm: "11"
|
||||||
assert-test-linux:
|
assert-test-linux:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/golang:1.14-stretch
|
- image: circleci/golang:1.14-stretch
|
||||||
|
@ -461,7 +461,7 @@ workflows:
|
||||||
- test-llvm10-go112
|
- test-llvm10-go112
|
||||||
- test-llvm10-go113
|
- test-llvm10-go113
|
||||||
- test-llvm10-go114
|
- test-llvm10-go114
|
||||||
- test-llvm10-go115
|
- test-llvm11-go115
|
||||||
- build-linux
|
- build-linux
|
||||||
- build-macos
|
- build-macos
|
||||||
- assert-test-linux
|
- assert-test-linux
|
||||||
|
|
|
@ -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
|
// Make sure stack sizes are loaded from a separate section so they can be
|
||||||
// modified after linking.
|
// modified after linking.
|
||||||
var stackSizeLoads []string
|
var stackSizeLoads []string
|
||||||
|
|
|
@ -61,7 +61,7 @@ func extractROM(path string) (uint64, []byte, error) {
|
||||||
|
|
||||||
progs := make(progSlice, 0, 2)
|
progs := make(progSlice, 0, 2)
|
||||||
for _, prog := range f.Progs {
|
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
|
continue
|
||||||
}
|
}
|
||||||
progs = append(progs, prog)
|
progs = append(progs, prog)
|
||||||
|
@ -73,6 +73,12 @@ func extractROM(path string) (uint64, []byte, error) {
|
||||||
|
|
||||||
var rom []byte
|
var rom []byte
|
||||||
for _, prog := range progs {
|
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)) {
|
if prog.Paddr != progs[0].Paddr+uint64(len(rom)) {
|
||||||
diff := prog.Paddr - (progs[0].Paddr + uint64(len(rom)))
|
diff := prog.Paddr - (progs[0].Paddr + uint64(len(rom)))
|
||||||
if diff > maxPadBytes {
|
if diff > maxPadBytes {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// +build !byollvm
|
// +build !byollvm
|
||||||
// +build !llvm9
|
// +build !llvm9,!llvm11
|
||||||
|
|
||||||
package cgo
|
package cgo
|
||||||
|
|
||||||
|
|
14
cgo/libclang_config_llvm11.go
Обычный файл
14
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"
|
2
go.mod
2
go.mod
|
@ -10,5 +10,5 @@ require (
|
||||||
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892
|
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892
|
||||||
go.bug.st/serial v1.0.0
|
go.bug.st/serial v1.0.0
|
||||||
golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2
|
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
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -44,5 +44,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=
|
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/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=
|
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-20200503224449-70c558526021 h1:d8T98WXGjrTgDmMXgxa6nb9EAYXGXwnzXygnJl6d+ac=
|
||||||
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/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE=
|
||||||
|
|
|
@ -3,6 +3,7 @@ package interp
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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
|
// fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly
|
||||||
// equal. That means, only relevant lines are compared (excluding comments
|
// equal. That means, only relevant lines are compared (excluding comments
|
||||||
// etc.).
|
// etc.).
|
||||||
|
@ -75,8 +78,18 @@ func fuzzyEqualIR(s1, s2 string) bool {
|
||||||
if len(lines1) != len(lines2) {
|
if len(lines1) != len(lines2) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i, line := range lines1 {
|
for i, line1 := range lines1 {
|
||||||
if line != lines2[i] {
|
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
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ SECTIONS
|
||||||
{
|
{
|
||||||
KEEP (*(.init))
|
KEEP (*(.init))
|
||||||
*(.text)
|
*(.text)
|
||||||
|
*(.text.*)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ SECTIONS
|
||||||
{
|
{
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
*(.rodata)
|
*(.rodata)
|
||||||
*(.rodata*)
|
*(.rodata.*)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ SECTIONS
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_sdata = .; /* used by startup code */
|
_sdata = .; /* used by startup code */
|
||||||
*(.data)
|
*(.data)
|
||||||
*(.data*)
|
*(.data.*)
|
||||||
*(.iwram .iwram.*)
|
*(.iwram .iwram.*)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_edata = .; /* used by startup code */
|
_edata = .; /* used by startup code */
|
||||||
|
@ -63,7 +64,7 @@ SECTIONS
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_sbss = .; /* used by startup code */
|
_sbss = .; /* used by startup code */
|
||||||
*(.bss)
|
*(.bss)
|
||||||
*(.bss*)
|
*(.bss.*)
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_ebss = .; /* used by startup code */
|
_ebss = .; /* used by startup code */
|
||||||
|
|
|
@ -31,3 +31,17 @@ func NonConstGlobals(mod llvm.Module) {
|
||||||
global = llvm.NextGlobal(global)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
// fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly
|
||||||
// equal. That means, only relevant lines are compared (excluding comments
|
// equal. That means, only relevant lines are compared (excluding comments
|
||||||
// etc.).
|
// etc.).
|
||||||
|
@ -70,8 +72,18 @@ func fuzzyEqualIR(s1, s2 string) bool {
|
||||||
if len(lines1) != len(lines2) {
|
if len(lines1) != len(lines2) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i, line := range lines1 {
|
for i, line1 := range lines1 {
|
||||||
if line != lines2[i] {
|
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
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче