From 3b5706b423acb900d5135e7010c5747408a80d0b Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Mon, 20 Feb 2023 09:21:32 -0600 Subject: [PATCH] cmd/link: check for power10 support on external linker for PPC64 The external linker will need to support the new PC relative relocations when they are generated by Go in a future patch. If it does not, many unhelpful relocation errors will be generated by the external linker. Use the -mcpu=power10 option as a surrogate for -mpcrel. It most cases, it should indicate whether the underlying linker has support for resolving PC relative relocations. Change-Id: I84b151ce04512ccaeb17835aaf44105a5f6b515b Reviewed-on: https://go-review.googlesource.com/c/go/+/469576 TryBot-Result: Gopher Robot Run-TryBot: Paul Murphy Reviewed-by: Archana Ravindar Reviewed-by: Than McIntosh Reviewed-by: Cherry Mui --- src/cmd/link/internal/ld/lib.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index d96f132256..b64176e35d 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1418,6 +1418,16 @@ func (ctxt *Link) hostlink() { argv = append(argv, "-Wl,-bbigtoc") } + // On PPC64, verify the external toolchain supports Power10. This is needed when + // PC relative relocations might be generated by Go. Only targets compiling ELF + // binaries might generate these relocations. + if ctxt.IsPPC64() && ctxt.IsElf() && buildcfg.GOPPC64 >= 10 { + if !linkerFlagSupported(ctxt.Arch, argv[0], "", "-mcpu=power10") { + Exitf("The external toolchain does not support -mcpu=power10. " + + " This is required to externally link GOPPC64 >= power10") + } + } + // Enable/disable ASLR on Windows. addASLRargs := func(argv []string, val bool) []string { // Old/ancient versions of GCC support "--dynamicbase" and -- 2.50.0