aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-04 20:35:13 +0100
committerRon Evans <[email protected]>2021-11-05 08:50:36 +0100
commit670fcf59d8c8cb97f8aa1e113a9614564f377bb3 (patch)
tree5a0fabb4882abda12ab8a3f186a42a937c8edb4b
parentcceb6558743ee62f3580ed7586564373978b29f1 (diff)
downloadtinygo-670fcf59d8c8cb97f8aa1e113a9614564f377bb3.tar.gz
tinygo-670fcf59d8c8cb97f8aa1e113a9614564f377bb3.zip
linux: reduce binary size in the common case
This commit changes the runtime.putchar implementation to directly call the `write` system call. This reduces the binary size by around 2.7kB.
-rw-r--r--src/runtime/runtime_unix.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/runtime/runtime_unix.go b/src/runtime/runtime_unix.go
index e53ff3573..684063b45 100644
--- a/src/runtime/runtime_unix.go
+++ b/src/runtime/runtime_unix.go
@@ -7,8 +7,8 @@ import (
"unsafe"
)
-//export putchar
-func _putchar(c int) int
+//export write
+func libc_write(fd int32, buf unsafe.Pointer, count uint) int
//export usleep
func usleep(usec uint) int
@@ -145,7 +145,8 @@ func syscall_runtime_envs() []string {
}
func putchar(c byte) {
- _putchar(int(c))
+ buf := [1]byte{c}
+ libc_write(1, unsafe.Pointer(&buf[0]), 1)
}
func ticksToNanoseconds(ticks timeUnit) int64 {