mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
22f4280b9a
commit
5f5168e004
5 changed files with 45 additions and 24 deletions
|
|
@ -89,7 +89,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, a
|
||||||
gcargs = append(gcargs, "-buildid", a.buildID)
|
gcargs = append(gcargs, "-buildid", a.buildID)
|
||||||
}
|
}
|
||||||
platform := cfg.Goos + "/" + cfg.Goarch
|
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")
|
gcargs = append(gcargs, "-dwarf=false")
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(runtimeVersion, "go1") && !strings.Contains(os.Args[0], "go_bootstrap") {
|
if strings.HasPrefix(runtimeVersion, "go1") && !strings.Contains(os.Args[0], "go_bootstrap") {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDWARF(t *testing.T) {
|
func testDWARF(t *testing.T, env ...string) {
|
||||||
testenv.MustHaveCGO(t)
|
testenv.MustHaveCGO(t)
|
||||||
testenv.MustHaveGoBuild(t)
|
testenv.MustHaveGoBuild(t)
|
||||||
|
|
||||||
|
|
@ -48,7 +48,11 @@ func TestDWARF(t *testing.T) {
|
||||||
t.Run(prog, func(t *testing.T) {
|
t.Run(prog, func(t *testing.T) {
|
||||||
exe := filepath.Join(tmpDir, prog+".exe")
|
exe := filepath.Join(tmpDir, prog+".exe")
|
||||||
dir := "../../runtime/testdata/" + prog
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("go build -o %v %v: %v\n%s", exe, dir, err, out)
|
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")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,6 @@ func archinit(ctxt *ld.Link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case objabi.Hdarwin: /* apple MACH */
|
case objabi.Hdarwin: /* apple MACH */
|
||||||
*ld.FlagW = true // disable DWARF generation
|
|
||||||
ld.HEADR = ld.INITIAL_MACHO_HEADR
|
ld.HEADR = ld.INITIAL_MACHO_HEADR
|
||||||
if *ld.FlagTextAddr == -1 {
|
if *ld.FlagTextAddr == -1 {
|
||||||
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
|
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,6 @@ func archinit(ctxt *ld.Link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case objabi.Hdarwin: /* apple MACH */
|
case objabi.Hdarwin: /* apple MACH */
|
||||||
*ld.FlagW = true // disable DWARF generation
|
|
||||||
ld.HEADR = ld.INITIAL_MACHO_HEADR
|
ld.HEADR = ld.INITIAL_MACHO_HEADR
|
||||||
if *ld.FlagTextAddr == -1 {
|
if *ld.FlagTextAddr == -1 {
|
||||||
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
|
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
|
||||||
|
|
|
||||||
|
|
@ -1333,8 +1333,6 @@ func (ctxt *Link) hostlink() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !*FlagS && !*FlagW && !debug_s && ctxt.HeadType == objabi.Hdarwin {
|
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")
|
dsym := filepath.Join(*flagTmpdir, "go.dwarf")
|
||||||
if out, err := exec.Command("dsymutil", "-f", *flagOutfile, "-o", dsym).CombinedOutput(); err != nil {
|
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)
|
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
|
||||||
|
|
@ -1354,7 +1352,6 @@ func (ctxt *Link) hostlink() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// hostlinkArchArgs returns arguments to pass to the external linker
|
// hostlinkArchArgs returns arguments to pass to the external linker
|
||||||
// based on the architecture.
|
// based on the architecture.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue