}
}
+ var altLinker string
if ctxt.IsELF && ctxt.DynlinkingGo() {
// We force all symbol resolution to be done at program startup
// because lazy PLT resolution can use large amounts of stack at
// generating COPY relocations.
//
// In both cases, switch to gold.
- argv = append(argv, "-fuse-ld=gold")
+ altLinker = "gold"
// If gold is not installed, gcc will silently switch
// back to ld.bfd. So we parse the version information
}
}
}
-
if ctxt.Arch.Family == sys.ARM64 && objabi.GOOS == "freebsd" {
// Switch to ld.bfd on freebsd/arm64.
- argv = append(argv, "-fuse-ld=bfd")
+ altLinker = "bfd"
// Provide a useful error if ld.bfd is missing.
cmd := exec.Command(*flagExtld, "-fuse-ld=bfd", "-Wl,--version")
}
}
}
+ if altLinker != "" {
+ argv = append(argv, "-fuse-ld="+altLinker)
+ }
if ctxt.IsELF && len(buildinfo) > 0 {
argv = append(argv, fmt.Sprintf("-Wl,--build-id=0x%x", buildinfo))
}
const compressDWARF = "-Wl,--compress-debug-sections=zlib-gnu"
- if ctxt.compressDWARF && linkerFlagSupported(argv[0], compressDWARF) {
+ if ctxt.compressDWARF && linkerFlagSupported(argv[0], altLinker, compressDWARF) {
argv = append(argv, compressDWARF)
}
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared {
// GCC uses -no-pie, clang uses -nopie.
for _, nopie := range []string{"-no-pie", "-nopie"} {
- if linkerFlagSupported(argv[0], nopie) {
+ if linkerFlagSupported(argv[0], altLinker, nopie) {
argv = append(argv, nopie)
break
}
var createTrivialCOnce sync.Once
-func linkerFlagSupported(linker, flag string) bool {
+func linkerFlagSupported(linker, altLinker, flag string) bool {
createTrivialCOnce.Do(func() {
src := filepath.Join(*flagTmpdir, "trivial.c")
if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil {
}
}
+ if altLinker != "" {
+ flags = append(flags, "-fuse-ld="+altLinker)
+ }
flags = append(flags, flag, "trivial.c")
cmd := exec.Command(linker, flags...)