1
0
mirror of https://github.com/golang/go synced 2024-11-26 17:46:57 -07:00

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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Cherry Zhang 2018-04-19 15:09:34 -04:00
parent 22f4280b9a
commit 5f5168e004
5 changed files with 45 additions and 24 deletions

View File

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

View File

@ -19,7 +19,7 @@ import (
"testing"
)
func TestDWARF(t *testing.T) {
func testDWARF(t *testing.T, env ...string) {
testenv.MustHaveCGO(t)
testenv.MustHaveGoBuild(t)
@ -48,7 +48,11 @@ func TestDWARF(t *testing.T) {
t.Run(prog, func(t *testing.T) {
exe := filepath.Join(tmpDir, prog+".exe")
dir := "../../runtime/testdata/" + prog
out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, dir).CombinedOutput()
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, dir)
if env != nil {
cmd.Env = append(os.Environ(), env...)
}
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("go build -o %v %v: %v\n%s", exe, dir, err, out)
}
@ -122,3 +126,25 @@ func TestDWARF(t *testing.T) {
})
}
}
func TestDWARF(t *testing.T) {
testDWARF(t)
}
func TestDWARFiOS(t *testing.T) {
// Normally we run TestDWARF on native platform. But on iOS we don't have
// go build, so we do this test with a cross build.
// Only run this on darwin/amd64, where we can cross build for iOS.
if testing.Short() {
t.Skip("skipping in short mode")
}
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
t.Skip("skipping on non-darwin/amd64 platform")
}
if err := exec.Command("xcrun", "--help").Run(); err != nil {
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
}
cc := "CC=" + runtime.GOROOT() + "/misc/ios/clangwrap.sh"
testDWARF(t, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm", "GOARM=7")
testDWARF(t, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm64")
}

View File

@ -120,7 +120,6 @@ func archinit(ctxt *ld.Link) {
}
case objabi.Hdarwin: /* apple MACH */
*ld.FlagW = true // disable DWARF generation
ld.HEADR = ld.INITIAL_MACHO_HEADR
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)

View File

@ -101,7 +101,6 @@ func archinit(ctxt *ld.Link) {
}
case objabi.Hdarwin: /* apple MACH */
*ld.FlagW = true // disable DWARF generation
ld.HEADR = ld.INITIAL_MACHO_HEADR
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)

View File

@ -1333,25 +1333,22 @@ func (ctxt *Link) hostlink() {
}
if !*FlagS && !*FlagW && !debug_s && ctxt.HeadType == objabi.Hdarwin {
// Skip combining dwarf on arm.
if !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
dsym := filepath.Join(*flagTmpdir, "go.dwarf")
if out, err := exec.Command("dsymutil", "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil {
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
}
// Skip combining if `dsymutil` didn't generate a file. See #11994.
if _, err := os.Stat(dsym); os.IsNotExist(err) {
return
}
// For os.Rename to work reliably, must be in same directory as outfile.
combinedOutput := *flagOutfile + "~"
if err := machoCombineDwarf(*flagOutfile, dsym, combinedOutput, ctxt.BuildMode); err != nil {
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
}
os.Remove(*flagOutfile)
if err := os.Rename(combinedOutput, *flagOutfile); err != nil {
Exitf("%s: %v", os.Args[0], err)
}
dsym := filepath.Join(*flagTmpdir, "go.dwarf")
if out, err := exec.Command("dsymutil", "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil {
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
}
// Skip combining if `dsymutil` didn't generate a file. See #11994.
if _, err := os.Stat(dsym); os.IsNotExist(err) {
return
}
// For os.Rename to work reliably, must be in same directory as outfile.
combinedOutput := *flagOutfile + "~"
if err := machoCombineDwarf(*flagOutfile, dsym, combinedOutput, ctxt.BuildMode); err != nil {
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
}
os.Remove(*flagOutfile)
if err := os.Rename(combinedOutput, *flagOutfile); err != nil {
Exitf("%s: %v", os.Args[0], err)
}
}
}