From 7252e1e5b6c99189dadb525a0793344ad9d137d5 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 15 Apr 2021 15:50:41 +1200 Subject: [PATCH] cmd/link: convert -I foo to -Wl,--dynamic-linker,foo when externally linking Fixes #22446 Change-Id: Id5b3fbc9cd3a7d6c4bf4e28428b8cb6d45a9ca92 Reviewed-on: https://go-review.googlesource.com/c/go/+/310349 Run-TryBot: Michael Hudson-Doyle TryBot-Result: Go Bot Trust: Michael Knyszek Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/lib.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index b814a277e6b..c840e5ea516 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1431,6 +1431,14 @@ func (ctxt *Link) hostlink() { argv = append(argv, fmt.Sprintf("-Wl,-rpath,%s", rpath.val)) } + if *flagInterpreter != "" { + // Many linkers support both -I and the --dynamic-linker flags + // to set the ELF interpreter, but lld only supports + // --dynamic-linker so prefer that (ld on very old Solaris only + // supports -I but that seems less important). + argv = append(argv, fmt.Sprintf("-Wl,--dynamic-linker,%s", *flagInterpreter)) + } + // Force global symbols to be exported for dlopen, etc. if ctxt.IsELF { argv = append(argv, "-rdynamic")