aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts/target.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-09-22 00:26:53 +0200
committerRon Evans <[email protected]>2021-09-28 18:44:11 +0200
commitbf9dab36f757eafbf5858784d14e4c0e96fbca9d (patch)
tree9825c5e97909610957509ea34af6f0f6fa5d2cb4 /compileopts/target.go
parent6234bf9a88e26636f8867ff71ca986be952ea780 (diff)
downloadtinygo-bf9dab36f757eafbf5858784d14e4c0e96fbca9d.tar.gz
tinygo-bf9dab36f757eafbf5858784d14e4c0e96fbca9d.zip
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.
Diffstat (limited to 'compileopts/target.go')
-rw-r--r--compileopts/target.go14
1 files changed, 4 insertions, 10 deletions
diff --git a/compileopts/target.go b/compileopts/target.go
index a84896c9b..df3b5d3ff 100644
--- a/compileopts/target.go
+++ b/compileopts/target.go
@@ -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",
}