Skip to content

Commit 892efae

Browse files
dgryskideadprogram
authored andcommitted
support -extldflags
Fixes #4320
1 parent 84048f2 commit 892efae

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

compileopts/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,16 @@ func (c *Config) LDFlags() []string {
395395
if c.Target.LinkerScript != "" {
396396
ldflags = append(ldflags, "-T", c.Target.LinkerScript)
397397
}
398+
399+
if c.Options.ExtLDFlags != "" {
400+
ext, err := shlex.Split(c.Options.ExtLDFlags)
401+
if err != nil {
402+
// if shlex can't split it, pass it as-is and let the external linker complain
403+
ext = []string{c.Options.ExtLDFlags}
404+
}
405+
ldflags = append(ldflags, ext...)
406+
}
407+
398408
return ldflags
399409
}
400410

compileopts/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Options struct {
5656
Timeout time.Duration
5757
WITPackage string // pass through to wasm-tools component embed invocation
5858
WITWorld string // pass through to wasm-tools component embed -w option
59+
ExtLDFlags string
5960
}
6061

6162
// Verify performs a validation on the given options, raising an error if options are not valid.

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ func main() {
13881388
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
13891389
monitor := flag.Bool("monitor", false, "enable serial monitor")
13901390
baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor")
1391+
extLDFlags := flag.String("extldflags", "", "additional flags to pass to external linker")
13911392

13921393
// Internal flags, that are only intended for TinyGo development.
13931394
printIR := flag.Bool("internal-printir", false, "print LLVM IR")
@@ -1503,6 +1504,7 @@ func main() {
15031504
Timeout: *timeout,
15041505
WITPackage: witPackage,
15051506
WITWorld: witWorld,
1507+
ExtLDFlags: *extLDFlags,
15061508
}
15071509
if *printCommands {
15081510
options.PrintCommands = printCommand

0 commit comments

Comments
 (0)