aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-10-25 15:32:20 +0200
committerAyke <[email protected]>2024-11-01 09:10:49 +0100
commit058f62ac08ace927f01b005e7b0a21b1a41590a7 (patch)
tree2aff4b24813e27f63b49a433dd13ed9d8fa9eb05
parent4e49ba597dc20e0bfd13fc39e0a1c89959576ec5 (diff)
downloadtinygo-058f62ac08ace927f01b005e7b0a21b1a41590a7.tar.gz
tinygo-058f62ac08ace927f01b005e7b0a21b1a41590a7.zip
main: parse extldflags early so we can report the error message
This avoids some weird behavior when the -extldflags flag cannot be parsed by TinyGo.
-rw-r--r--compileopts/config.go10
-rw-r--r--compileopts/options.go2
-rw-r--r--main.go9
3 files changed, 10 insertions, 11 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index 44d3b005c..76215b181 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -406,15 +406,7 @@ func (c *Config) LDFlags() []string {
if c.Target.LinkerScript != "" {
ldflags = append(ldflags, "-T", c.Target.LinkerScript)
}
-
- if c.Options.ExtLDFlags != "" {
- ext, err := shlex.Split(c.Options.ExtLDFlags)
- if err != nil {
- // if shlex can't split it, pass it as-is and let the external linker complain
- ext = []string{c.Options.ExtLDFlags}
- }
- ldflags = append(ldflags, ext...)
- }
+ ldflags = append(ldflags, c.Options.ExtLDFlags...)
return ldflags
}
diff --git a/compileopts/options.go b/compileopts/options.go
index b83f6f63b..bc462b29b 100644
--- a/compileopts/options.go
+++ b/compileopts/options.go
@@ -58,7 +58,7 @@ type Options struct {
Timeout time.Duration
WITPackage string // pass through to wasm-tools component embed invocation
WITWorld string // pass through to wasm-tools component embed -w option
- ExtLDFlags string
+ ExtLDFlags []string
}
// Verify performs a validation on the given options, raising an error if options are not valid.
diff --git a/main.go b/main.go
index 254e140cf..8ae5ce316 100644
--- a/main.go
+++ b/main.go
@@ -1641,12 +1641,19 @@ func main() {
Timeout: *timeout,
WITPackage: witPackage,
WITWorld: witWorld,
- ExtLDFlags: extLDFlags,
}
if *printCommands {
options.PrintCommands = printCommand
}
+ if extLDFlags != "" {
+ options.ExtLDFlags, err = shlex.Split(extLDFlags)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "could not parse -extldflags:", err)
+ os.Exit(1)
+ }
+ }
+
err = options.Verify()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())