aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2024-09-17 12:08:24 -0700
committerRon Evans <[email protected]>2024-09-18 08:05:25 +0200
commit892efaec973aa7fe5442ca0f16f05f4951ac73a3 (patch)
tree7a59fe67c7d9438b4427e56795bf2cee62d8c7a4
parent84048f299f172af5e5cd77227b1464695ed1c738 (diff)
downloadtinygo-892efaec973aa7fe5442ca0f16f05f4951ac73a3.tar.gz
tinygo-892efaec973aa7fe5442ca0f16f05f4951ac73a3.zip
support -extldflags
Fixes #4320
-rw-r--r--compileopts/config.go10
-rw-r--r--compileopts/options.go1
-rw-r--r--main.go2
3 files changed, 13 insertions, 0 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index 18d3c9e4d..cc1f4d61c 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -395,6 +395,16 @@ 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...)
+ }
+
return ldflags
}
diff --git a/compileopts/options.go b/compileopts/options.go
index 9601ae322..980097200 100644
--- a/compileopts/options.go
+++ b/compileopts/options.go
@@ -56,6 +56,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
}
// 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 6109c00bf..64d022fb9 100644
--- a/main.go
+++ b/main.go
@@ -1388,6 +1388,7 @@ func main() {
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
monitor := flag.Bool("monitor", false, "enable serial monitor")
baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor")
+ extLDFlags := flag.String("extldflags", "", "additional flags to pass to external linker")
// Internal flags, that are only intended for TinyGo development.
printIR := flag.Bool("internal-printir", false, "print LLVM IR")
@@ -1503,6 +1504,7 @@ func main() {
Timeout: *timeout,
WITPackage: witPackage,
WITWorld: witWorld,
+ ExtLDFlags: *extLDFlags,
}
if *printCommands {
options.PrintCommands = printCommand