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
-10
View File
@@ -23,16 +23,6 @@ func GOROOT() string {
return "/usr/local/go"
}
// This is the default set of arguments, if nothing else has been set.
// This may be overriden by modifying this global at runtime init (for example,
// on Linux where there are real command line arguments).
var args = []string{"/proc/self/exe"}
//go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string {
return args
}
// Copy size bytes from src to dst. The memory areas must not overlap.
// Calls to this function are converted to LLVM intrinsic calls such as
// llvm.memcpy.p0i8.p0i8.i32(dst, src, size, false).