mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
builder,loader: fix -ldflags -X not overriding variables with default values
When a string variable already had a source-level default value, the -ldflags "-X" flag was silently ignored and the variable remained the default value at runtime. Fix by stripping the InitOrder entry for each -X variable before LoadSSA() is called. With no entry in InitOrder, go/ssa emits no init store, so the global stays zero-valued in the IR. makeGlobalsModule still injects the actual -X values at final link time. The -X values remain out of the per-package build cache with only the variable names appearing in the cache key. Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
// This global has a default value. It should be overridable via
|
||||
// -ldflags="-X main.someGlobal=value" just like an uninitialized global.
|
||||
var someGlobal = "default"
|
||||
|
||||
func main() {
|
||||
println("someGlobal:", someGlobal)
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
someGlobal: foobar
|
||||
Vendored
+1
-2
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
// These globals can be changed using -ldflags="-X main.someGlobal=value".
|
||||
// At the moment, only globals without an initializer can be replaced this way.
|
||||
// This global can be changed using -ldflags="-X main.someGlobal=value".
|
||||
var someGlobal string
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user