From: Aman Gupta Date: Tue, 2 Apr 2019 11:35:50 +0000 (-0700) Subject: cmd/link/internal/ld: fix c-archive mach-o compatibility X-Git-Tag: go1.13beta1~735 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3cb92fcba71f9c0d64b3b714fc92870065848345;p=gostls13.git cmd/link/internal/ld: fix c-archive mach-o compatibility These workarounds predate proper DWARF support and are no longer necessary. Before this patch, running `/usr/bin/symbols go.o` using the object in the c-archive would fail, causing App Store rejections. Fixes #31022 #28997 Change-Id: I6a210b6369c13038777c6e21e874e81afcb50c2f Reviewed-on: https://go-review.googlesource.com/c/go/+/170377 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/link/dwarf_test.go b/src/cmd/link/dwarf_test.go index ecc96019be..235db39dda 100644 --- a/src/cmd/link/dwarf_test.go +++ b/src/cmd/link/dwarf_test.go @@ -5,6 +5,7 @@ package main import ( + "bytes" cmddwarf "cmd/internal/dwarf" "cmd/internal/objfile" "debug/dwarf" @@ -86,6 +87,22 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string) } exe = filepath.Join(tmpDir, "go.o") } + + if runtime.GOOS == "darwin" { + if _, err = exec.LookPath("symbols"); err == nil { + // Ensure Apple's tooling can parse our object for symbols. + out, err = exec.Command("symbols", exe).CombinedOutput() + if err != nil { + t.Fatal(err) + } else { + if bytes.HasPrefix(out, []byte("Unable to find file")) { + // This failure will cause the App Store to reject our binaries. + t.Fatalf("/usr/bin/symbols %v: failed to parse file", filepath.Base(exe)) + } + } + } + } + f, err := objfile.Open(exe) if err != nil { t.Fatal(err) @@ -148,6 +165,9 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string) func TestDWARF(t *testing.T) { testDWARF(t, "", true) + if runtime.GOOS == "darwin" { + testDWARF(t, "c-archive", true) + } } func TestDWARFiOS(t *testing.T) { diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go index d13857081a..6ebae160b1 100644 --- a/src/cmd/link/internal/ld/macho.go +++ b/src/cmd/link/internal/ld/macho.go @@ -560,12 +560,8 @@ func Asmbmacho(ctxt *Link) { ms = newMachoSeg("", 40) ms.fileoffset = Segtext.Fileoff - if ctxt.Arch.Family == sys.ARM || ctxt.BuildMode == BuildModeCArchive { - ms.filesize = Segdata.Fileoff + Segdata.Filelen - Segtext.Fileoff - } else { - ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff - ms.vsize = Segdwarf.Vaddr + Segdwarf.Length - Segtext.Vaddr - } + ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff + ms.vsize = Segdwarf.Vaddr + Segdwarf.Length - Segtext.Vaddr } /* segment for zero page */