Skip to content

Commit 7ee2622

Browse files
committed
cmd/link: link dynamic library automatically
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 <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a22ec6e commit 7ee2622

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
183183
hostObjSyms[s] = struct{}{}
184184
}
185185
havedynamic = 1
186+
if lib != "" && ctxt.IsDarwin() {
187+
machoadddynlib(lib, ctxt.LinkMode)
188+
}
186189
}
187190

188191
continue

src/runtime/sys_darwin.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,3 @@ func setNonblock(fd int32) {
489489
//go:cgo_import_dynamic libc_pthread_cond_wait pthread_cond_wait "/usr/lib/libSystem.B.dylib"
490490
//go:cgo_import_dynamic libc_pthread_cond_timedwait_relative_np pthread_cond_timedwait_relative_np "/usr/lib/libSystem.B.dylib"
491491
//go:cgo_import_dynamic libc_pthread_cond_signal pthread_cond_signal "/usr/lib/libSystem.B.dylib"
492-
493-
// Magic incantation to get libSystem and friends actually dynamically linked.
494-
// TODO: Why does the code require this? See cmd/link/internal/ld/go.go
495-
//go:cgo_import_dynamic _ _ "/usr/lib/libSystem.B.dylib"
496-
//go:cgo_import_dynamic _ _ "/System/Library/Frameworks/Security.framework/Versions/A/Security"
497-
//go:cgo_import_dynamic _ _ "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"

0 commit comments

Comments
 (0)