Skip to content

Commit a318d56

Browse files
committed
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 <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent f4e7a6b commit a318d56

File tree

1 file changed

+4
-4
lines changed
  • src/cmd/link/internal/ld

1 file changed

+4
-4
lines changed

src/cmd/link/internal/ld/lib.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ func (ctxt *Link) hostlink() {
14581458
}
14591459

14601460
const compressDWARF = "-Wl,--compress-debug-sections=zlib-gnu"
1461-
if ctxt.compressDWARF && linkerFlagSupported(argv[0], altLinker, compressDWARF) {
1461+
if ctxt.compressDWARF && linkerFlagSupported(ctxt.Arch, argv[0], altLinker, compressDWARF) {
14621462
argv = append(argv, compressDWARF)
14631463
}
14641464

@@ -1548,7 +1548,7 @@ func (ctxt *Link) hostlink() {
15481548
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared && !(ctxt.IsDarwin() && ctxt.IsARM64()) {
15491549
// GCC uses -no-pie, clang uses -nopie.
15501550
for _, nopie := range []string{"-no-pie", "-nopie"} {
1551-
if linkerFlagSupported(argv[0], altLinker, nopie) {
1551+
if linkerFlagSupported(ctxt.Arch, argv[0], altLinker, nopie) {
15521552
argv = append(argv, nopie)
15531553
break
15541554
}
@@ -1657,7 +1657,7 @@ func (ctxt *Link) hostlink() {
16571657

16581658
var createTrivialCOnce sync.Once
16591659

1660-
func linkerFlagSupported(linker, altLinker, flag string) bool {
1660+
func linkerFlagSupported(arch *sys.Arch, linker, altLinker, flag string) bool {
16611661
createTrivialCOnce.Do(func() {
16621662
src := filepath.Join(*flagTmpdir, "trivial.c")
16631663
if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil {
@@ -1691,7 +1691,7 @@ func linkerFlagSupported(linker, altLinker, flag string) bool {
16911691
"-target",
16921692
}
16931693

1694-
var flags []string
1694+
flags := hostlinkArchArgs(arch)
16951695
keep := false
16961696
skip := false
16971697
extldflags := strings.Fields(*flagExtldflags)

0 commit comments

Comments
 (0)