runtime: only initialize os.runtime_args when needed

This generally means that code size is reduced, especially when the os
package is not imported.

Specifically:

  - On Linux (which currently statically links musl), it avoids calling
    malloc, which avoids including the musl C heap for small programs
    saving around 1.6kB.
  - On WASI, it avoids initializing the args slice when the os package
    is not used. This reduces binary size by around 1kB.
This commit is contained in:
Ayke van Laethem
2021-11-04 20:57:43 +01:00
committed by Ron Evans
parent 670fcf59d8
commit fb33f3813d
4 changed files with 67 additions and 52 deletions
+8
View File
@@ -11,6 +11,14 @@ package runtime
// The primary use case is `tinygo test`, which takes some parameters (such as
// -test.v).
// This is the default set of arguments, if nothing else has been set.
var args = []string{"/proc/self/exe"}
//go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string {
return args
}
var env []string
//go:linkname syscall_runtime_envs syscall.runtime_envs