diff --git a/main.go b/main.go index 84fdd16c..2b772a08 100644 --- a/main.go +++ b/main.go @@ -89,7 +89,8 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool // Link the object file with the system compiler. executable := filepath.Join(dir, "main") - cmd := exec.Command("cc", "-o", executable, objfile) + args := append(spec.PreLinkArgs, "-o", executable, objfile) + cmd := exec.Command(spec.Linker, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err = cmd.Run() diff --git a/target.go b/target.go index 476cc8f0..ef37deb1 100644 --- a/target.go +++ b/target.go @@ -14,8 +14,10 @@ import ( // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html // https://github.com/shepmaster/rust-arduino-blink-led-no-core-with-cargo/blob/master/blink/arduino.json type TargetSpec struct { - Triple string `json:"llvm-target"` - BuildTags []string `json:"build-tags"` + Triple string `json:"llvm-target"` + BuildTags []string `json:"build-tags"` + Linker string `json:"linker"` + PreLinkArgs []string `json:"pre-link-args"` } // Load a target specification @@ -23,6 +25,7 @@ func LoadTarget(target string) (*TargetSpec, error) { spec := &TargetSpec{ Triple: target, BuildTags: []string{runtime.GOOS, runtime.GOARCH}, + Linker: "cc", } // See whether there is a target specification for this target (e.g. diff --git a/targets/arduino.json b/targets/arduino.json index 5ba6d38f..a490c825 100644 --- a/targets/arduino.json +++ b/targets/arduino.json @@ -1,4 +1,6 @@ { "llvm-target": "avr-atmel-none", - "build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"] + "build-tags": ["avr", "avr8", "atmega", "atmega328p", "js", "wasm"], + "linker": "avr-gcc", + "pre-link-args": ["-nostdlib", "-T", "avr.ld", "-Wl,--gc-sections", "avr.S"] }