cmd/cgo: accept weak dynamic imports
cmd/cgo: accept weak dynamic imports

cgo produces dynamic imports for Go binaries by scanning the dynamic
imports table of a binary produced by the system C compiler and
linker. Currently, since it uses elf.File.ImportedSymbols, it only
reads global symbols. Unfortunately, recent versions of lld emit weak
symbol imports for several pthread symbols, which means the cgo tool
doesn't emit dynamic imports for them, which ultimately causes linking
of cgo binaries to fail.

Fix this by using elf.File.DynamicSymbols instead and filtering down
to both global and weak symbols.

Fixes #31912.

Change-Id: If346a7eca6733e3bfa2cccf74a9cda02a3e81d38
Reviewed-on: https://go-review.googlesource.com/c/go/+/184100
Run-TryBot: Austin Clements <7ea35d812706d9213868749011af1ed4fa2f6aa0@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: Ian Lance Taylor <87e9c6d529889242b7e184afb632328636553ab4@golang.org>

akutz/go,akutz/go,golang/go,akutz/go,akutz/go,nawawi/go,CAFxX/go,nawawi/go,CAFxX/go,cloudflare/go,CAFxX/go,CAFxX/go,cloudflare/go,nawawi/go,cloudflare/go,golang/go,cloudflare/go,nawawi/go,cloudflare/go,nawawi/go,CAFxX/go,cloudflare/go,akutz/go,golang/go,CAFxX/go,akutz/go,akutz/go,golang/go,nawawi/go,cloudflare/go,CAFxX/go,golang/go,CAFxX/go,golang/go,nawawi/go,cloudflare/go,nawawi/go,akutz/go,golang/go,golang/go