Skip to content

Commit

Permalink
cmd/link/internal/ld: fix c-archive mach-o compatibility
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
tmm1 authored and ianlancetaylor committed Apr 11, 2019
1 parent 7b33b62 commit 3cb92fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/cmd/link/dwarf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"bytes"
cmddwarf "cmd/internal/dwarf"
"cmd/internal/objfile"
"debug/dwarf"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions src/cmd/link/internal/ld/macho.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 3cb92fc

Please sign in to comment.