]> Cypherpunks.ru repositories - gostls13.git/commit
[release-branch.go1.20] cmd/go,cmd/link: prefer external linking when strange cgo...
authorThan McIntosh <thanm@google.com>
Fri, 10 Mar 2023 15:29:38 +0000 (10:29 -0500)
committerCherry Mui <cherryyz@google.com>
Fri, 17 Mar 2023 19:45:27 +0000 (19:45 +0000)
commit3ff6dbdf5b65e4c9da1a2020e45a56a7ae48cc91
tree242783f473f205892a336286022c3123300fe335
parentfa42da156a166ecf81ab7d72f53619ad9e6f134a
[release-branch.go1.20] cmd/go,cmd/link: prefer external linking when strange cgo flags seen

This patch changes the Go command to examine the set of compiler
flags feeding into the C compiler when packages that use cgo are built.
If any of a specific set of strange/dangerous flags are in use,
then the Go command generates a token file ("preferlinkext") and
embeds it into the compiled package's archive.

When the Go linker reads the archives of the packages feeding into the
link and detects a "preferlinkext" token, it will then use external
linking for the program by default (although this default can be
overridden with an explicit "-linkmode" flag).

The intent here is to avoid having to teach the Go linker's host object
reader to grok/understand the various odd symbols/sections/types that
can result from boutique flag use, but rather to just boot the objects
in question over to the C linker instead.

Fixes #59051.
Updates #58619.
Updates #58620.
Updates #58848.

Change-Id: I56382dd305de8dac3841a7a7e664277826061eaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/475375
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit 035db07d7c5f1b90ebc9bae03cab694685acebb8)
Reviewed-on: https://go-review.googlesource.com/c/go/+/476577
src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/security.go
src/cmd/go/internal/work/security_test.go
src/cmd/go/scriptconds_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt [new file with mode: 0644]
src/cmd/link/internal/ld/config.go
src/cmd/link/internal/ld/lib.go
src/internal/platform/supported.go