Skip to content

Commit 5f5168e

Browse files
committed
cmd/link, cmd/go: enable DWARF on darwin/arm and darwin/arm64
Fixes #24883. Change-Id: Iff992ec3f2f31f4d82923d7cc806df4ee58e70b0 Reviewed-on: https://go-review.googlesource.com/108295 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Elias Naur <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 22f4280 commit 5f5168e

File tree

5 files changed

+45
-24
lines changed

5 files changed

+45
-24
lines changed

src/cmd/go/internal/work/gc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, a
8989
gcargs = append(gcargs, "-buildid", a.buildID)
9090
}
9191
platform := cfg.Goos + "/" + cfg.Goarch
92-
if p.Internal.OmitDebug || platform == "nacl/amd64p32" || platform == "darwin/arm" || platform == "darwin/arm64" || cfg.Goos == "plan9" {
92+
if p.Internal.OmitDebug || platform == "nacl/amd64p32" || cfg.Goos == "plan9" {
9393
gcargs = append(gcargs, "-dwarf=false")
9494
}
9595
if strings.HasPrefix(runtimeVersion, "go1") && !strings.Contains(os.Args[0], "go_bootstrap") {

src/cmd/link/dwarf_test.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"testing"
2020
)
2121

22-
func TestDWARF(t *testing.T) {
22+
func testDWARF(t *testing.T, env ...string) {
2323
testenv.MustHaveCGO(t)
2424
testenv.MustHaveGoBuild(t)
2525

@@ -48,7 +48,11 @@ func TestDWARF(t *testing.T) {
4848
t.Run(prog, func(t *testing.T) {
4949
exe := filepath.Join(tmpDir, prog+".exe")
5050
dir := "../../runtime/testdata/" + prog
51-
out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, dir).CombinedOutput()
51+
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, dir)
52+
if env != nil {
53+
cmd.Env = append(os.Environ(), env...)
54+
}
55+
out, err := cmd.CombinedOutput()
5256
if err != nil {
5357
t.Fatalf("go build -o %v %v: %v\n%s", exe, dir, err, out)
5458
}
@@ -122,3 +126,25 @@ func TestDWARF(t *testing.T) {
122126
})
123127
}
124128
}
129+
130+
func TestDWARF(t *testing.T) {
131+
testDWARF(t)
132+
}
133+
134+
func TestDWARFiOS(t *testing.T) {
135+
// Normally we run TestDWARF on native platform. But on iOS we don't have
136+
// go build, so we do this test with a cross build.
137+
// Only run this on darwin/amd64, where we can cross build for iOS.
138+
if testing.Short() {
139+
t.Skip("skipping in short mode")
140+
}
141+
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
142+
t.Skip("skipping on non-darwin/amd64 platform")
143+
}
144+
if err := exec.Command("xcrun", "--help").Run(); err != nil {
145+
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
146+
}
147+
cc := "CC=" + runtime.GOROOT() + "/misc/ios/clangwrap.sh"
148+
testDWARF(t, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm", "GOARM=7")
149+
testDWARF(t, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm64")
150+
}

src/cmd/link/internal/arm/obj.go

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func archinit(ctxt *ld.Link) {
120120
}
121121

122122
case objabi.Hdarwin: /* apple MACH */
123-
*ld.FlagW = true // disable DWARF generation
124123
ld.HEADR = ld.INITIAL_MACHO_HEADR
125124
if *ld.FlagTextAddr == -1 {
126125
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)

src/cmd/link/internal/arm64/obj.go

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ func archinit(ctxt *ld.Link) {
101101
}
102102

103103
case objabi.Hdarwin: /* apple MACH */
104-
*ld.FlagW = true // disable DWARF generation
105104
ld.HEADR = ld.INITIAL_MACHO_HEADR
106105
if *ld.FlagTextAddr == -1 {
107106
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)

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

+16-19
Original file line numberDiff line numberDiff line change
@@ -1333,25 +1333,22 @@ func (ctxt *Link) hostlink() {
13331333
}
13341334

13351335
if !*FlagS && !*FlagW && !debug_s && ctxt.HeadType == objabi.Hdarwin {
1336-
// Skip combining dwarf on arm.
1337-
if !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
1338-
dsym := filepath.Join(*flagTmpdir, "go.dwarf")
1339-
if out, err := exec.Command("dsymutil", "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil {
1340-
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
1341-
}
1342-
// Skip combining if `dsymutil` didn't generate a file. See #11994.
1343-
if _, err := os.Stat(dsym); os.IsNotExist(err) {
1344-
return
1345-
}
1346-
// For os.Rename to work reliably, must be in same directory as outfile.
1347-
combinedOutput := *flagOutfile + "~"
1348-
if err := machoCombineDwarf(*flagOutfile, dsym, combinedOutput, ctxt.BuildMode); err != nil {
1349-
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
1350-
}
1351-
os.Remove(*flagOutfile)
1352-
if err := os.Rename(combinedOutput, *flagOutfile); err != nil {
1353-
Exitf("%s: %v", os.Args[0], err)
1354-
}
1336+
dsym := filepath.Join(*flagTmpdir, "go.dwarf")
1337+
if out, err := exec.Command("dsymutil", "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil {
1338+
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
1339+
}
1340+
// Skip combining if `dsymutil` didn't generate a file. See #11994.
1341+
if _, err := os.Stat(dsym); os.IsNotExist(err) {
1342+
return
1343+
}
1344+
// For os.Rename to work reliably, must be in same directory as outfile.
1345+
combinedOutput := *flagOutfile + "~"
1346+
if err := machoCombineDwarf(*flagOutfile, dsym, combinedOutput, ctxt.BuildMode); err != nil {
1347+
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
1348+
}
1349+
os.Remove(*flagOutfile)
1350+
if err := os.Rename(combinedOutput, *flagOutfile); err != nil {
1351+
Exitf("%s: %v", os.Args[0], err)
13551352
}
13561353
}
13571354
}

0 commit comments

Comments
 (0)