]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: link dynamic library automatically
authorCherry Zhang <cherryyz@google.com>
Thu, 13 Aug 2020 00:27:57 +0000 (20:27 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 17 Aug 2020 14:50:17 +0000 (14:50 +0000)
cgo_import_dynamic pragma indicates a symbol is imported from a
dynamic library. Currently, the linker does not actually link
against the dynamic library, so we have to "force" it by using

//go:cgo_import_dynamic _ _ "dylib"

syntax, which links in the library unconditionally.

This CL changes it to link in the library automatically when a
symbol is imported from the library, without using the "force"
syntax. (The "force" syntax is still supported.)

Remove the unconditional imports in the runtime. Now,
Security.framework and CoreFoundation.framework are only linked
when the x509 package is imported (or otherwise specified).

Fixes #40727.

Change-Id: Ied36b1f621cdcc5dc4a8f497cdf1c554a182d0e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/248333
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/link/internal/ld/go.go
src/runtime/sys_darwin.go

index bf5c9ca1bab0c44a3f620bd6ebf6e008c53ada4b..b3541c46c0df457b8e5ac68ff1c07600cb21e861 100644 (file)
@@ -183,6 +183,9 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
                                        hostObjSyms[s] = struct{}{}
                                }
                                havedynamic = 1
+                               if lib != "" && ctxt.IsDarwin() {
+                                       machoadddynlib(lib, ctxt.LinkMode)
+                               }
                        }
 
                        continue
index 06474434c9a68893841a210b1028f0f880ad5a45..e4f19bbf41f84bf85957d03a1d1c53bbe901712f 100644 (file)
@@ -489,9 +489,3 @@ func setNonblock(fd int32) {
 //go:cgo_import_dynamic libc_pthread_cond_wait pthread_cond_wait "/usr/lib/libSystem.B.dylib"
 //go:cgo_import_dynamic libc_pthread_cond_timedwait_relative_np pthread_cond_timedwait_relative_np "/usr/lib/libSystem.B.dylib"
 //go:cgo_import_dynamic libc_pthread_cond_signal pthread_cond_signal "/usr/lib/libSystem.B.dylib"
-
-// Magic incantation to get libSystem and friends actually dynamically linked.
-// TODO: Why does the code require this?  See cmd/link/internal/ld/go.go
-//go:cgo_import_dynamic _ _ "/usr/lib/libSystem.B.dylib"
-//go:cgo_import_dynamic _ _ "/System/Library/Frameworks/Security.framework/Versions/A/Security"
-//go:cgo_import_dynamic _ _ "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"