diff options
author | Ayke van Laethem <[email protected]> | 2021-11-14 01:39:34 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-11-15 11:53:44 +0100 |
commit | 7cb44fb37324d9d369d04a66bb3a6f43e7c11d0e (patch) | |
tree | 99aa7928814b1581a82766bb161a0fd1a484579c /compileopts/target.go | |
parent | 73ad825b67c4ab74f28e42a75782c1c49ba33a88 (diff) | |
download | tinygo-7cb44fb37324d9d369d04a66bb3a6f43e7c11d0e.tar.gz tinygo-7cb44fb37324d9d369d04a66bb3a6f43e7c11d0e.zip |
all: add support for GOARM
This environment variable can be set to 5, 6, or 7 and controls which
ARM version (ARMv5, ARMv6, ARMv7) is used when compiling for GOARCH=arm.
I have picked the default value ARMv6, which I believe is supported on
most common single board computers including all Raspberry Pis. The
difference in code size is pretty big.
We could even go further and support ARMv4 if anybody is interested. It
should be pretty simple to add this if needed.
Diffstat (limited to 'compileopts/target.go')
-rw-r--r-- | compileopts/target.go | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/compileopts/target.go b/compileopts/target.go index 0c8ce1d93..5440536dc 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -5,6 +5,7 @@ package compileopts import ( "encoding/json" "errors" + "fmt" "io" "os" "os/exec" @@ -165,13 +166,26 @@ func LoadTarget(options *Options) (*TargetSpec, error) { if options.Target == "" { // Configure based on GOOS/GOARCH environment variables (falling back to // runtime.GOOS/runtime.GOARCH), and generate a LLVM target based on it. - llvmarch := map[string]string{ - "386": "i386", - "amd64": "x86_64", - "arm64": "aarch64", - "arm": "armv7", - }[options.GOARCH] - if llvmarch == "" { + var llvmarch string + switch options.GOARCH { + case "386": + llvmarch = "i386" + case "amd64": + llvmarch = "x86_64" + case "arm64": + llvmarch = "aarch64" + case "arm": + switch options.GOARM { + case "5": + llvmarch = "armv5" + case "6": + llvmarch = "armv6" + case "7": + llvmarch = "armv7" + default: + return nil, fmt.Errorf("invalid GOARM=%s, must be 5, 6, or 7", options.GOARM) + } + default: llvmarch = options.GOARCH } llvmos := options.GOOS @@ -245,7 +259,14 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { spec.Features = "+cx8,+fxsr,+mmx,+sse,+sse2,+x87" case "arm": spec.CPU = "generic" - spec.Features = "+armv7-a,+dsp,+fp64,+vfp2,+vfp2sp,+vfp3d16,+vfp3d16sp,-thumb-mode" + switch strings.Split(triple, "-")[0] { + case "armv5": + spec.Features = "+armv5t,+strict-align,-thumb-mode" + 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" + } case "arm64": spec.CPU = "generic" spec.Features = "+neon" |