From e021d895623b058b43e78cc78617e8968c189418 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 25 Oct 2024 15:32:20 +0200 Subject: [PATCH] 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. --- compileopts/config.go | 10 +--------- compileopts/options.go | 2 +- main.go | 9 ++++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compileopts/config.go b/compileopts/config.go index 44d3b005cc..76215b1817 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 b83f6f63ba..bc462b29bd 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 fe8a3fb15a..6bbfd35d2f 100644 --- a/main.go +++ b/main.go @@ -1639,12 +1639,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())