On Android and Dragonfly, don't use -lresolv. It doesn't exist there.
On Linux, use res_search instead of res_nsearch.
glibc makes res_search thread-safe by having a per-thread __res.
It still also provides res_nsearch.
musl makes res_search thread-safe by ignoring __res completely.
It does not provide res_nsearch at all.
Changing to res_search on Linux will fix builds on musl-based systems
while keeping glibc-based systems working.
Fixes #56657.
Fixes #56660.
Change-Id: Id87dde6c8bbf6c0d34543c09782f3871489c8712
Reviewed-on: https://go-review.googlesource.com/c/go/+/448797
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
// res_search, for cgo systems where that is thread-safe.
-//go:build cgo && !netgo && (android || openbsd)
+//go:build cgo && !netgo && (linux || openbsd)
package net
#include <arpa/nameser.h>
#include <resolv.h>
-#cgo !openbsd LDFLAGS: -lresolv
+#cgo !android,!openbsd LDFLAGS: -lresolv
*/
import "C"
// res_nsearch, for cgo systems where that's available.
-//go:build cgo && !netgo && unix && !(android || darwin || openbsd)
+//go:build cgo && !netgo && unix && !(darwin || linux || openbsd)
package net
#include <arpa/nameser.h>
#include <resolv.h>
-#cgo !aix,!freebsd LDFLAGS: -lresolv
+#cgo !aix,!dragonfly,!freebsd LDFLAGS: -lresolv
*/
import "C"