Blob Blame History Raw
From a0ebf57f6164d5f795b7022fa26ac8bb66bee9e8 Mon Sep 17 00:00:00 2001
From: Ayke van Laethem <aykevanlaethem@gmail.com>
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 <quantum.analyst@gmail.com>
---
 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