build: normalize target triples to match Clang

This commit changes a target triple like "armv6m-none-eabi" to
"armv6m-unknown-unknow-eabi". The reason is that while the former is
correctly parsed in Clang (due to normalization), it wasn't parsed
correctly in LLVM meaning that the environment wasn't set to EABI.

This change normalizes all target triples and uses the EABI environment
(-eabi in the triple) for Cortex-M targets.

This change also drops the `--target=` flag in the target JSON files,
the flag is now added implicitly in `(*compileopts.Config).CFlags()`.
This removes some duplication in target JSON files.

Unfortunately, this change also increases code size for Cortex-M
targets. It looks like LLVM now emits calls like __aeabi_memmove instead
of memmove, which pull in slightly more code (they basically just call
the regular C functions) and the calls themself don't seem to be as
efficient as they could be. Perhaps this is a LLVM bug that will be
fixed in the future, as this is a very common occurrence.
This commit is contained in:
Ayke van Laethem
2021-09-22 00:26:53 +02:00
committed by Ron Evans
parent 6234bf9a88
commit bf9dab36f7
32 changed files with 44 additions and 67 deletions
+9 -9
View File
@@ -470,9 +470,9 @@ build/release: tinygo gen-device wasi-libc
@mkdir -p build/release/tinygo/lib/nrfx
@mkdir -p build/release/tinygo/lib/picolibc/newlib/libc
@mkdir -p build/release/tinygo/lib/wasi-libc
@mkdir -p build/release/tinygo/pkg/armv6m-none-eabi
@mkdir -p build/release/tinygo/pkg/armv7m-none-eabi
@mkdir -p build/release/tinygo/pkg/armv7em-none-eabi
@mkdir -p build/release/tinygo/pkg/armv6m-unknown-unknown-eabi
@mkdir -p build/release/tinygo/pkg/armv7m-unknown-unknown-eabi
@mkdir -p build/release/tinygo/pkg/armv7em-unknown-unknown-eabi
@echo copying source files
@cp -p build/tinygo$(EXE) build/release/tinygo/bin
@cp -p $(abspath $(CLANG_SRC))/lib/Headers/*.h build/release/tinygo/lib/clang/include
@@ -491,12 +491,12 @@ build/release: tinygo gen-device wasi-libc
@cp -rp lib/wasi-libc/sysroot build/release/tinygo/lib/wasi-libc/sysroot
@cp -rp src build/release/tinygo/src
@cp -rp targets build/release/tinygo/targets
./build/tinygo build-library -target=armv6m-none-eabi -o build/release/tinygo/pkg/armv6m-none-eabi/compiler-rt.a compiler-rt
./build/tinygo build-library -target=armv7m-none-eabi -o build/release/tinygo/pkg/armv7m-none-eabi/compiler-rt.a compiler-rt
./build/tinygo build-library -target=armv7em-none-eabi -o build/release/tinygo/pkg/armv7em-none-eabi/compiler-rt.a compiler-rt
./build/tinygo build-library -target=armv6m-none-eabi -o build/release/tinygo/pkg/armv6m-none-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv7m-none-eabi -o build/release/tinygo/pkg/armv7m-none-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv7em-none-eabi -o build/release/tinygo/pkg/armv7em-none-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv6m-unknown-unknown-eabi -o build/release/tinygo/pkg/armv6m-unknown-unknown-eabi/compiler-rt.a compiler-rt
./build/tinygo build-library -target=armv7m-unknown-unknown-eabi -o build/release/tinygo/pkg/armv7m-unknown-unknown-eabi/compiler-rt.a compiler-rt
./build/tinygo build-library -target=armv7em-unknown-unknown-eabi -o build/release/tinygo/pkg/armv7em-unknown-unknown-eabi/compiler-rt.a compiler-rt
./build/tinygo build-library -target=armv6m-unknown-unknown-eabi -o build/release/tinygo/pkg/armv6m-unknown-unknown-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv7m-unknown-unknown-eabi -o build/release/tinygo/pkg/armv7m-unknown-unknown-eabi/picolibc.a picolibc
./build/tinygo build-library -target=armv7em-unknown-unknown-eabi -o build/release/tinygo/pkg/armv7em-unknown-unknown-eabi/picolibc.a picolibc
release: build/release
tar -czf build/release.tar.gz -C build/release tinygo
+1 -1
View File
@@ -28,7 +28,7 @@ func normalizeResult(result string) string {
}
func TestCGo(t *testing.T) {
var cflags = []string{"--target=armv6m-none-eabi"}
var cflags = []string{"--target=armv6m-unknown-unknown-eabi"}
for _, name := range []string{"basic", "errors", "types", "flags", "const"} {
name := name // avoid a race condition
+3 -1
View File
@@ -21,7 +21,7 @@ type Config struct {
TestConfig TestConfig
}
// Triple returns the LLVM target triple, like armv6m-none-eabi.
// Triple returns the LLVM target triple, like armv6m-unknown-unknown-eabi.
func (c *Config) Triple() string {
return c.Target.Triple
}
@@ -213,6 +213,8 @@ func (c *Config) CFlags() []string {
cflags = append(cflags, "-g")
// Use the same optimization level as TinyGo.
cflags = append(cflags, "-O"+c.Options.Opt)
// Set the LLVM target triple.
cflags = append(cflags, "--target="+c.Triple())
return cflags
}
+4 -10
View File
@@ -177,7 +177,10 @@ func LoadTarget(target string) (*TargetSpec, error) {
if llvmarch == "" {
llvmarch = goarch
}
target = llvmarch + "--" + llvmos
// Target triples (which actually have four components, but are called
// triples for historical reasons) have the form:
// arch-vendor-os-environment
target = llvmarch + "-unknown-" + llvmos
if goarch == "arm" {
target += "-gnueabihf"
}
@@ -207,14 +210,6 @@ func LoadTarget(target string) (*TargetSpec, error) {
if len(tripleSplit) < 3 {
return nil, errors.New("expected a full LLVM target or a custom target in -target flag")
}
if tripleSplit[0] == "arm" {
// LLVM and Clang have a different idea of what "arm" means, so
// upgrade to a slightly more modern ARM. In fact, when you pass
// --target=arm--linux-gnueabihf to Clang, it will convert that
// internally to armv7-unknown-linux-gnueabihf. Changing the
// architecture to armv7 will keep things consistent.
tripleSplit[0] = "armv7"
}
goos := tripleSplit[2]
if strings.HasPrefix(goos, "darwin") {
goos = "darwin"
@@ -250,7 +245,6 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
Scheduler: "tasks",
Linker: "cc",
DefaultStackSize: 1024 * 64, // 64kB
CFlags: []string{"--target=" + triple},
GDB: []string{"gdb"},
PortReset: "false",
}
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'basic.go'
source_filename = "basic.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
%main.kv = type { float }
%main.kv.0 = type { i8 }
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'channel.go'
source_filename = "channel.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
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 } }
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'float.go'
source_filename = "float.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*)
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'func.go'
source_filename = "func.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
%runtime.funcValueWithSignature = type { i32, i8* }
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'go1.17.go'
source_filename = "go1.17.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*)
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'goroutine.go'
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 = "armv7m-none-eabi"
target triple = "armv7m-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 } }
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'goroutine.go'
source_filename = "goroutine.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
%runtime.funcValueWithSignature = type { i32, i8* }
%runtime.channel = type { i32, i32, i8, %runtime.channelBlockedList*, i32, i32, i32, i8* }
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'interface.go'
source_filename = "interface.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID* }
%runtime.interfaceMethodInfo = type { i8*, i32 }
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'intrinsics.go'
source_filename = "intrinsics.go"
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv7m-none-eabi"
target triple = "armv7m-unknown-unknown-eabi"
declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*)
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'intrinsics.go'
source_filename = "intrinsics.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*)
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'pointer.go'
source_filename = "pointer.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*)
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'pragma.go'
source_filename = "pragma.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
@extern_global = external global [0 x i8], align 1
@main.alignedGlobal = hidden global [4 x i32] zeroinitializer, align 32
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'slice.go'
source_filename = "slice.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*)
+1 -1
View File
@@ -1,7 +1,7 @@
; ModuleID = 'string.go'
source_filename = "string.go"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32--wasi"
target triple = "wasm32-unknown-wasi"
%runtime._string = type { i8*, i32 }
+3 -3
View File
@@ -95,13 +95,13 @@ func TestCompiler(t *testing.T) {
if runtime.GOOS == "linux" {
t.Run("X86Linux", func(t *testing.T) {
runPlatTests("i386--linux-gnu", tests, t)
runPlatTests("i386-unknown-linux", tests, t)
})
t.Run("ARMLinux", func(t *testing.T) {
runPlatTests("arm--linux-gnueabihf", tests, t)
runPlatTests("armv7-unknown-linux-gnueabihf", tests, t)
})
t.Run("ARM64Linux", func(t *testing.T) {
runPlatTests("aarch64--linux-gnu", tests, t)
runPlatTests("aarch64-unknown-linux", tests, t)
})
t.Run("WebAssembly", func(t *testing.T) {
runPlatTests("wasm", tests, t)
+1 -2
View File
@@ -1,5 +1,5 @@
{
"llvm-target": "avr-unknown-unknown",
"llvm-target": "avr",
"build-tags": ["avr", "baremetal", "linux", "arm"],
"goos": "linux",
"goarch": "arm",
@@ -8,7 +8,6 @@
"scheduler": "none",
"default-stack-size": 256,
"cflags": [
"--target=avr-unknown-unknown",
"-Werror"
],
"ldflags": [
+1 -4
View File
@@ -1,7 +1,4 @@
{
"inherits": ["cortex-m"],
"llvm-target": "armv6m-none-eabi",
"cflags": [
"--target=armv6m-none-eabi"
]
"llvm-target": "armv6m-unknown-unknown-eabi"
}
+1 -4
View File
@@ -1,7 +1,4 @@
{
"inherits": ["cortex-m"],
"llvm-target": "armv6m-none-eabi",
"cflags": [
"--target=armv6m-none-eabi"
]
"llvm-target": "armv6m-unknown-unknown-eabi"
}
+1 -4
View File
@@ -1,7 +1,4 @@
{
"inherits": ["cortex-m"],
"llvm-target": "armv7m-none-eabi",
"cflags": [
"--target=armv7m-none-eabi"
]
"llvm-target": "armv7m-unknown-unknown-eabi"
}
+1 -2
View File
@@ -1,8 +1,7 @@
{
"inherits": ["cortex-m"],
"llvm-target": "armv7m-none-eabi",
"llvm-target": "armv7m-unknown-unknown-eabi",
"cflags": [
"--target=armv7m-none-eabi",
"-mfloat-abi=soft"
]
}
+1 -2
View File
@@ -1,8 +1,7 @@
{
"inherits": ["cortex-m"],
"llvm-target": "armv7em-none-eabi",
"llvm-target": "armv7em-unknown-unknown-eabi",
"cflags": [
"--target=armv7em-none-eabi",
"-mfloat-abi=soft"
]
}
+1 -2
View File
@@ -1,9 +1,8 @@
{
"inherits": ["cortex-m"],
"llvm-target": "armv7em-none-eabi",
"llvm-target": "armv7em-unknown-unknown-eabi",
"cpu": "cortex-m7",
"cflags": [
"--target=armv7em-none-eabi",
"-mcpu=cortex-m7",
"-mfloat-abi=soft"
]
+1 -2
View File
@@ -1,5 +1,5 @@
{
"llvm-target": "arm4-none-eabi",
"llvm-target": "arm4-unknown-unknown-eabi",
"cpu": "arm7tdmi",
"build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"],
"goos": "linux",
@@ -8,7 +8,6 @@
"rtlib": "compiler-rt",
"libc": "picolibc",
"cflags": [
"--target=arm4-none-eabi",
"-mcpu=arm7tdmi",
"-Werror",
"-fshort-enums",
-1
View File
@@ -3,7 +3,6 @@
"llvm-target": "riscv32--none",
"build-tags": ["tinygo.riscv32"],
"cflags": [
"--target=riscv32--none",
"-march=rv32imac",
"-mabi=ilp32"
],
-1
View File
@@ -3,7 +3,6 @@
"llvm-target": "riscv64--none",
"build-tags": ["tinygo.riscv64"],
"cflags": [
"--target=riscv64--none",
"-march=rv64gc",
"-mabi=lp64"
],
+1 -2
View File
@@ -1,12 +1,11 @@
{
"llvm-target": "wasm32--wasi",
"llvm-target": "wasm32-unknown-wasi",
"build-tags": ["tinygo.wasm", "wasi"],
"goos": "linux",
"goarch": "arm",
"linker": "wasm-ld",
"libc": "wasi-libc",
"cflags": [
"--target=wasm32--wasi",
"--sysroot={root}/lib/wasi-libc/sysroot"
],
"ldflags": [
+1 -2
View File
@@ -1,12 +1,11 @@
{
"llvm-target": "wasm32--wasi",
"llvm-target": "wasm32-unknown-wasi",
"build-tags": ["tinygo.wasm"],
"goos": "js",
"goarch": "wasm",
"linker": "wasm-ld",
"libc": "wasi-libc",
"cflags": [
"--target=wasm32--wasi",
"--sysroot={root}/lib/wasi-libc/sysroot"
],
"ldflags": [
-1
View File
@@ -6,7 +6,6 @@
"gc": "conservative",
"scheduler": "none",
"cflags": [
"--target=xtensa",
"-Werror",
"-fshort-enums",
"-Wno-macro-redefined",