From: Hiroshi Ioka Date: Thu, 1 Jun 2017 07:23:40 +0000 (+0900) Subject: cmd/link: don't link the same dylib multiple times X-Git-Tag: go1.10beta1~1598 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1f8433c66ae945f6d1e4a6bc8c6c5efebeae0dbe;p=gostls13.git cmd/link: don't link the same dylib multiple times Also, unexport Machoadddynlib n=`go test -c crypto/x509 && otool -l x509.test | grep libSystem | wc -l` Before this CL, n = 3. After this CL, n = 1. on my environment. Change-Id: Ic7b8157435cc85086404860dc6c84eb0aecc5d19 Reviewed-on: https://go-review.googlesource.com/44771 Reviewed-by: Ian Lance Taylor Reviewed-by: Avelino Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/link/internal/ld/go.go b/src/cmd/link/internal/ld/go.go index 2930a6b24f..56d2f3f42e 100644 --- a/src/cmd/link/internal/ld/go.go +++ b/src/cmd/link/internal/ld/go.go @@ -175,7 +175,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { havedynamic = 1 if Headtype == objabi.Hdarwin { - Machoadddynlib(lib) + machoadddynlib(lib) } else { dynlib = append(dynlib, lib) } diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go index ef4d1552f6..161833f357 100644 --- a/src/cmd/link/internal/ld/macho.go +++ b/src/cmd/link/internal/ld/macho.go @@ -380,7 +380,12 @@ func (ctxt *Link) domacho() { } } -func Machoadddynlib(lib string) { +func machoadddynlib(lib string) { + if seenlib[lib] || Linkmode == LinkExternal { + return + } + seenlib[lib] = true + // Will need to store the library name rounded up // and 24 bytes of header metadata. If not enough // space, grab another page of initial space at the