mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
all: add target-features string to all targets
This makes sure that the LLVM target features match the one generated by
Clang:
- This fixes a bug introduced when setting the target CPU for all
targets: Cortex-M4 would now start using floating point operations
while they were disabled in C.
- This will make it possible in the future to inline C functions in Go
and vice versa. This will need some more work though.
There is a code size impact. Cortex-M4 targets are increased slightly in
binary size while Cortex-M0 targets tend to be reduced a little bit.
Other than that, there is little impact.
This commit is contained in:
committed by
Ron Evans
parent
af4d0fe191
commit
78fec3719f
@@ -136,7 +136,6 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||
DefaultStackSize: config.Target.DefaultStackSize,
|
||||
NeedsStackObjects: config.NeedsStackObjects(),
|
||||
Debug: true,
|
||||
LLVMFeatures: config.LLVMFeatures(),
|
||||
}
|
||||
|
||||
// Load the target machine, which is the LLVM object that contains all
|
||||
|
||||
+18
-4
@@ -12,8 +12,8 @@ import (
|
||||
"tinygo.org/x/go-llvm"
|
||||
)
|
||||
|
||||
// Test whether the Clang generated "target-cpu" attribute matches the CPU
|
||||
// property in TinyGo target files.
|
||||
// Test whether the Clang generated "target-cpu" and "target-features"
|
||||
// attributes match the CPU and Features property in TinyGo target files.
|
||||
func TestClangAttributes(t *testing.T) {
|
||||
var targetNames = []string{
|
||||
// Please keep this list sorted!
|
||||
@@ -112,16 +112,30 @@ func testClangAttributes(t *testing.T, options *compileopts.Options) {
|
||||
t.Errorf("target has LLVM triple %#v but Clang makes it LLVM triple %#v", config.Triple(), mod.Target())
|
||||
}
|
||||
|
||||
// Check the "target-cpu" string attribute of the add function.
|
||||
// Check the "target-cpu" and "target-features" string attribute of the add
|
||||
// function.
|
||||
add := mod.NamedFunction("add")
|
||||
var cpu string
|
||||
var cpu, features string
|
||||
cpuAttr := add.GetStringAttributeAtIndex(-1, "target-cpu")
|
||||
featuresAttr := add.GetStringAttributeAtIndex(-1, "target-features")
|
||||
if !cpuAttr.IsNil() {
|
||||
cpu = cpuAttr.GetStringValue()
|
||||
}
|
||||
if !featuresAttr.IsNil() {
|
||||
features = featuresAttr.GetStringValue()
|
||||
}
|
||||
if cpu != config.CPU() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This TestMain is necessary because TinyGo may also be invoked to run certain
|
||||
|
||||
Reference in New Issue
Block a user