runtime: avoid getg in preinit on Android
runtime: avoid getg in preinit on Android

sigaction is called as part of library mode initializers
(_rt0_*_lib). Sigaction in turn calls getg, but on Android the TLS
offset for g has not been initialized and getg might return garbage.

Add a check for initialization before calling getg.

Fixes the golang.org/x/mobile/bind/java tests on amd64 and 386.

Fixes #31476

Change-Id: Id2c41fdc983239eca039b49a54b8853c5669d127
Reviewed-on: https://go-review.googlesource.com/c/go/+/172158
Reviewed-by: Ian Lance Taylor <87e9c6d529889242b7e184afb632328636553ab4@golang.org>

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