From af84204d2731f66b5d01a640670ae38d71f752d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <clement.chigot@atos.net>
Date: Tue, 9 Nov 2021 10:01:05 +0100
Subject: [PATCH] cmd/link: fix GCC startfiles names on AIX

Since GCC version 11, the 64-bit version of startfiles are now suffixed
by "_64" instead of just being stored without suffix under "ppc64"
multilib directory.
---
 src/cmd/link/internal/ld/lib.go | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 01ab6474b8..f133f92e75 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -1499,8 +1499,18 @@ func (ctxt *Link) hostlink() {
 			}
 			return strings.Trim(string(out), "\n")
 		}
-		argv = append(argv, getPathFile("crtcxa.o"))
-		argv = append(argv, getPathFile("crtdbase.o"))
+		// New GCC versions (>= 11) store 64bit version of start files with
+		// a suffix "_64" even under "-maix64" directory.
+		crtcxa := getPathFile("crtcxa_64.o")
+		if !filepath.IsAbs(crtcxa) {
+			crtcxa = getPathFile("crtcxa.o")
+		}
+		crtdbase := getPathFile("crtdbase_64.o")
+		if !filepath.IsAbs(crtdbase) {
+			crtdbase = getPathFile("crtdbase.o")
+		}
+		argv = append(argv, crtcxa)
+		argv = append(argv, crtdbase)
 	}
 
 	if ctxt.linkShared {
-- 
2.33.1

