Skip to content

Commit d2016af

Browse files
tmm1steeve
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 241b958 commit d2016af

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/cmd/link/dwarf_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package main
66

77
import (
8+
"bytes"
89
"cmd/internal/objfile"
910
"debug/dwarf"
1011
"internal/testenv"
@@ -70,6 +71,22 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
7071
}
7172
exe = filepath.Join(tmpDir, "go.o")
7273
}
74+
75+
if runtime.GOOS == "darwin" {
76+
if _, err = exec.LookPath("symbols"); err == nil {
77+
// Ensure Apple's tooling can parse our object for symbols.
78+
out, err = exec.Command("symbols", exe).CombinedOutput()
79+
if err != nil {
80+
t.Fatal(err)
81+
} else {
82+
if bytes.HasPrefix(out, []byte("Unable to find file")) {
83+
// This failure will cause the App Store to reject our binaries.
84+
t.Fatalf("/usr/bin/symbols %v: failed to parse file", filepath.Base(exe))
85+
}
86+
}
87+
}
88+
}
89+
7390
f, err := objfile.Open(exe)
7491
if err != nil {
7592
t.Fatal(err)
@@ -149,6 +166,9 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
149166

150167
func TestDWARF(t *testing.T) {
151168
testDWARF(t, "", true)
169+
if runtime.GOOS == "darwin" {
170+
testDWARF(t, "c-archive", true)
171+
}
152172
}
153173

154174
func TestDWARFiOS(t *testing.T) {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,8 @@ func Asmbmacho(ctxt *Link) {
518518
ms = newMachoSeg("", 40)
519519

520520
ms.fileoffset = Segtext.Fileoff
521-
if ctxt.Arch.Family == sys.ARM || ctxt.BuildMode == BuildModeCArchive {
522-
ms.filesize = Segdata.Fileoff + Segdata.Filelen - Segtext.Fileoff
523-
} else {
524-
ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff
525-
ms.vsize = Segdwarf.Vaddr + Segdwarf.Length - Segtext.Vaddr
526-
}
521+
ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff
522+
ms.vsize = Segdwarf.Vaddr + Segdwarf.Length - Segtext.Vaddr
527523
}
528524

529525
/* segment for zero page */

0 commit comments

Comments
 (0)