]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld: fix c-archive mach-o compatibility
authorAman Gupta <aman@tmm1.net>
Tue, 2 Apr 2019 11:35:50 +0000 (04:35 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 11 Apr 2019 04:49:51 +0000 (04:49 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/dwarf_test.go
src/cmd/link/internal/ld/macho.go

index ecc96019befe07489a6db091306e9341d22a5576..235db39ddac80edff0d0b1df6b39cbc02791c446 100644 (file)
@@ -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) {
index d13857081a24354e941f6f3fd120ff995830b739..6ebae160b1378ef45d2557947cb8daf155381b33 100644 (file)
@@ -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 */