mirror of
https://github.com/golang/go
synced 2024-11-11 19:51:37 -07:00
cmd/link: pass arch-specific flags to external linker when testing supported flag
When testing if a flag (e.g. "-no-pie") is supported by the external linker, pass arch-specific flags (like "-marm"). In particular, on the ARM builder, if CGO_LDFLAGS=-march=armv6 is set, the C toolchain fails to build if -marm is not passed. # cc -march=armv6 1.c 1.c: In function 'main': 1.c:3:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI int main() { ^~~ This makes the Go linker think "-no-pie" is not supported when it actually is. Passing -marm makes it work. Fixes #43202. Change-Id: I4e8b71f08818993cbbcb2494b310c68d812d6b50 Reviewed-on: https://go-review.googlesource.com/c/go/+/278592 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
f4e7a6b905
commit
a318d56c1e
@ -1458,7 +1458,7 @@ func (ctxt *Link) hostlink() {
|
||||
}
|
||||
|
||||
const compressDWARF = "-Wl,--compress-debug-sections=zlib-gnu"
|
||||
if ctxt.compressDWARF && linkerFlagSupported(argv[0], altLinker, compressDWARF) {
|
||||
if ctxt.compressDWARF && linkerFlagSupported(ctxt.Arch, argv[0], altLinker, compressDWARF) {
|
||||
argv = append(argv, compressDWARF)
|
||||
}
|
||||
|
||||
@ -1548,7 +1548,7 @@ func (ctxt *Link) hostlink() {
|
||||
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared && !(ctxt.IsDarwin() && ctxt.IsARM64()) {
|
||||
// GCC uses -no-pie, clang uses -nopie.
|
||||
for _, nopie := range []string{"-no-pie", "-nopie"} {
|
||||
if linkerFlagSupported(argv[0], altLinker, nopie) {
|
||||
if linkerFlagSupported(ctxt.Arch, argv[0], altLinker, nopie) {
|
||||
argv = append(argv, nopie)
|
||||
break
|
||||
}
|
||||
@ -1657,7 +1657,7 @@ func (ctxt *Link) hostlink() {
|
||||
|
||||
var createTrivialCOnce sync.Once
|
||||
|
||||
func linkerFlagSupported(linker, altLinker, flag string) bool {
|
||||
func linkerFlagSupported(arch *sys.Arch, linker, altLinker, flag string) bool {
|
||||
createTrivialCOnce.Do(func() {
|
||||
src := filepath.Join(*flagTmpdir, "trivial.c")
|
||||
if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil {
|
||||
@ -1691,7 +1691,7 @@ func linkerFlagSupported(linker, altLinker, flag string) bool {
|
||||
"-target",
|
||||
}
|
||||
|
||||
var flags []string
|
||||
flags := hostlinkArchArgs(arch)
|
||||
keep := false
|
||||
skip := false
|
||||
extldflags := strings.Fields(*flagExtldflags)
|
||||
|
Loading…
Reference in New Issue
Block a user