aboutsummaryrefslogtreecommitdiffhomepage
path: root/builder
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-02-12 01:34:22 +0100
committerRon Evans <[email protected]>2022-05-18 15:20:09 +0200
commit109b5298c4b2e068a00de5376d9552ace4a5cda4 (patch)
tree224d2f72ec5c0cfae7cc0a88f7082dd11f5f9006 /builder
parenta94e03eff26792effe80ec3accb8c251d165681e (diff)
downloadtinygo-109b5298c4b2e068a00de5376d9552ace4a5cda4.tar.gz
tinygo-109b5298c4b2e068a00de5376d9552ace4a5cda4.zip
avr: use compiler-rt
This change adds support for compiler-rt, which supports float64 (unlike libgcc for AVR). This gets a number of tests to pass that require float64 support. We're still using libgcc with this change, but libgcc will probably be removed eventually once AVR support in compiler-rt is a bit more mature. I've also pushed a fix for a small regression in our xtensa_release_14.0.0-patched LLVM branch that has also been merged upstream. Without it, a floating point comparison against zero always returns true which is certainly a bug. It is necessary to correctly print floating point values.
Diffstat (limited to 'builder')
-rw-r--r--builder/builtins.go10
-rw-r--r--builder/library.go9
2 files changed, 17 insertions, 2 deletions
diff --git a/builder/builtins.go b/builder/builtins.go
index 479b541d5..121398fac 100644
--- a/builder/builtins.go
+++ b/builder/builtins.go
@@ -40,7 +40,6 @@ var genericBuiltins = []string{
"divdf3.c",
"divdi3.c",
"divmoddi4.c",
- "divmodsi4.c",
"divsc3.c",
"divsf3.c",
"divsi3.c",
@@ -127,7 +126,6 @@ var genericBuiltins = []string{
"ucmpti2.c",
"udivdi3.c",
"udivmoddi4.c",
- "udivmodsi4.c",
"udivmodti4.c",
"udivsi3.c",
"udivti3.c",
@@ -154,6 +152,14 @@ var aeabiBuiltins = []string{
"arm/aeabi_memset.S",
"arm/aeabi_uidivmod.S",
"arm/aeabi_uldivmod.S",
+
+ // These two are not technically EABI builtins but are used by them and only
+ // seem to be used on ARM. LLVM seems to use __divsi3 and __modsi3 on most
+ // other architectures.
+ // Most importantly, they have a different calling convention on AVR so
+ // should not be used on AVR.
+ "divmodsi4.c",
+ "udivmodsi4.c",
}
// CompilerRT is a library with symbols required by programs compiled with LLVM.
diff --git a/builder/library.go b/builder/library.go
index 01c5ebd14..1a2ed61c2 100644
--- a/builder/library.go
+++ b/builder/library.go
@@ -148,6 +148,8 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
// However, ARM has not done this.
if strings.HasPrefix(target, "i386") || strings.HasPrefix(target, "x86_64") {
args = append(args, "-march="+cpu)
+ } else if strings.HasPrefix(target, "avr") {
+ args = append(args, "-mmcu="+cpu)
} else {
args = append(args, "-mcpu="+cpu)
}
@@ -155,6 +157,13 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables")
}
+ if strings.HasPrefix(target, "avr") {
+ // AVR defaults to C float and double both being 32-bit. This deviates
+ // from what most code (and certainly compiler-rt) expects. So we need
+ // to force the compiler to use 64-bit floating point numbers for
+ // double.
+ args = append(args, "-mdouble=64")
+ }
if strings.HasPrefix(target, "riscv32-") {
args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128")
}