mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: enable DWARF combining on macOS ARM64
It appears the machoCalcStart function is meant to align the segment, but it doesn't. Replace it with an actual alignment calculation. Also, use the alignment from the configuration, instead of hardcode. With this fix we could enable DWARF combining on macOS ARM64. Change-Id: I19ec771b77d752b83a54c53b6ee65af78a31b8ae Reviewed-on: https://go-review.googlesource.com/c/go/+/253558 Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
a52a5d8a43
commit
1e6ad65b43
3 changed files with 5 additions and 18 deletions
|
|
@ -105,7 +105,7 @@ func archinit(ctxt *ld.Link) {
|
||||||
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
|
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
|
||||||
}
|
}
|
||||||
if *ld.FlagRound == -1 {
|
if *ld.FlagRound == -1 {
|
||||||
*ld.FlagRound = 4096
|
*ld.FlagRound = 16384 // 16K page alignment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1240,11 +1240,11 @@ func (ctxt *Link) hostlink() {
|
||||||
|
|
||||||
// On darwin, whether to combine DWARF into executable.
|
// On darwin, whether to combine DWARF into executable.
|
||||||
// Only macOS supports unmapped segments such as our __DWARF segment.
|
// Only macOS supports unmapped segments such as our __DWARF segment.
|
||||||
combineDwarf := ctxt.IsDarwin() && !*FlagS && !*FlagW && !debug_s && machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64()
|
combineDwarf := ctxt.IsDarwin() && !*FlagS && !*FlagW && !debug_s && machoPlatform == PLATFORM_MACOS
|
||||||
|
|
||||||
switch ctxt.HeadType {
|
switch ctxt.HeadType {
|
||||||
case objabi.Hdarwin:
|
case objabi.Hdarwin:
|
||||||
if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
|
if combineDwarf {
|
||||||
// Leave room for DWARF combining.
|
// Leave room for DWARF combining.
|
||||||
// -headerpad is incompatible with -fembed-bitcode.
|
// -headerpad is incompatible with -fembed-bitcode.
|
||||||
argv = append(argv, "-Wl,-headerpad,1144")
|
argv = append(argv, "-Wl,-headerpad,1144")
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
pageAlign = 12 // 4096 = 1 << 12
|
|
||||||
)
|
|
||||||
|
|
||||||
type loadCmd struct {
|
type loadCmd struct {
|
||||||
Cmd macho.LoadCmd
|
Cmd macho.LoadCmd
|
||||||
Len uint32
|
Len uint32
|
||||||
|
|
@ -138,7 +134,7 @@ func machoCombineDwarf(ctxt *Link, exef *os.File, exem *macho.File, dsym, outexe
|
||||||
// Now copy the dwarf data into the output.
|
// Now copy the dwarf data into the output.
|
||||||
// Kernel requires all loaded segments to be page-aligned in the file,
|
// Kernel requires all loaded segments to be page-aligned in the file,
|
||||||
// even though we mark this one as being 0 bytes of virtual address space.
|
// even though we mark this one as being 0 bytes of virtual address space.
|
||||||
dwarfstart := machoCalcStart(realdwarf.Offset, linkseg.Offset, pageAlign)
|
dwarfstart := Rnd(int64(linkseg.Offset), int64(*FlagRound))
|
||||||
if _, err := outf.Seek(dwarfstart, 0); err != nil {
|
if _, err := outf.Seek(dwarfstart, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +162,7 @@ func machoCombineDwarf(ctxt *Link, exef *os.File, exem *macho.File, dsym, outexe
|
||||||
if _, err := exef.Seek(int64(linkseg.Offset), 0); err != nil {
|
if _, err := exef.Seek(int64(linkseg.Offset), 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
linkstart := machoCalcStart(linkseg.Offset, uint64(dwarfstart)+dwarfsize, pageAlign)
|
linkstart := Rnd(dwarfstart+int64(dwarfsize), int64(*FlagRound))
|
||||||
if _, err := outf.Seek(linkstart, 0); err != nil {
|
if _, err := outf.Seek(linkstart, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -432,12 +428,3 @@ func machoUpdateLoadCommand(r loadCmdReader, linkseg *macho.Segment, linkoffset
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func machoCalcStart(origAddr, newAddr uint64, alignExp uint32) int64 {
|
|
||||||
align := uint64(1 << alignExp)
|
|
||||||
origMod, newMod := origAddr%align, newAddr%align
|
|
||||||
if origMod == newMod {
|
|
||||||
return int64(newAddr)
|
|
||||||
}
|
|
||||||
return int64(newAddr + align + origMod - newMod)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue