Skip to content

Commit 3cb92fc

Browse files
tmm1ianlancetaylor
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 7b33b62 commit 3cb92fc

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
cmddwarf "cmd/internal/dwarf"
910
"cmd/internal/objfile"
1011
"debug/dwarf"
@@ -86,6 +87,22 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
8687
}
8788
exe = filepath.Join(tmpDir, "go.o")
8889
}
90+
91+
if runtime.GOOS == "darwin" {
92+
if _, err = exec.LookPath("symbols"); err == nil {
93+
// Ensure Apple's tooling can parse our object for symbols.
94+
out, err = exec.Command("symbols", exe).CombinedOutput()
95+
if err != nil {
96+
t.Fatal(err)
97+
} else {
98+
if bytes.HasPrefix(out, []byte("Unable to find file")) {
99+
// This failure will cause the App Store to reject our binaries.
100+
t.Fatalf("/usr/bin/symbols %v: failed to parse file", filepath.Base(exe))
101+
}
102+
}
103+
}
104+
}
105+
89106
f, err := objfile.Open(exe)
90107
if err != nil {
91108
t.Fatal(err)
@@ -148,6 +165,9 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
148165

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

153173
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
@@ -560,12 +560,8 @@ func Asmbmacho(ctxt *Link) {
560560
ms = newMachoSeg("", 40)
561561

562562
ms.fileoffset = Segtext.Fileoff
563-
if ctxt.Arch.Family == sys.ARM || ctxt.BuildMode == BuildModeCArchive {
564-
ms.filesize = Segdata.Fileoff + Segdata.Filelen - Segtext.Fileoff
565-
} else {
566-
ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff
567-
ms.vsize = Segdwarf.Vaddr + Segdwarf.Length - Segtext.Vaddr
568-
}
563+
ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff
564+
ms.vsize = Segdwarf.Vaddr + Segdwarf.Length - Segtext.Vaddr
569565
}
570566

571567
/* segment for zero page */

0 commit comments

Comments
 (0)