]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.19] 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:48 +0000 (19:45 +0000)
commit2094fd07d3fde8d08b22acd7e772c6aacb7dcaed
treed43138841bdbfc360e657e6d822651a4fbc164c8
parent3a50af126c1817a8285b3342f5fff4e039c7469b
[release-branch.go1.19] 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 #59050.
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/+/476576
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/script_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