Skip to content

Commit

Permalink
proc: fix PIE support on macOS (#3467)
Browse files Browse the repository at this point in the history
Go1.22 switched to emitting PIE by default and also changed some
details of the PIE implementation. This breaks delve entirely on macOS.

Fix how relocations are handled on macOS.
  • Loading branch information
aarzilli committed Aug 14, 2023
1 parent 894ba63 commit ec07c27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1805,11 +1805,17 @@ func loadBinaryInfoMacho(bi *BinaryInfo, image *Image, path string, entryPoint u
}

if entryPoint != 0 {
// This is a little bit hacky. We use the entryPoint variable, but it
// actually holds the address of the mach-o header. We can use this
// to calculate the offset to the non-aslr location of the mach-o header
// (which is 0x100000000)
image.StaticBase = entryPoint - 0x100000000
machoOff := uint64(0x100000000)
for _, ld := range exe.Loads {
if seg, _ := ld.(*macho.Segment); seg != nil {
if seg.Name == "__TEXT" {
machoOff = seg.Addr
break
}
}
}
logflags.DebuggerLogger().Debugf("entryPoint %#x machoOff %#x", entryPoint, machoOff)
image.StaticBase = entryPoint - machoOff
}

image.closer = exe
Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/gdbserial/gdbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func LLDBAttach(pid int, path string, waitFor *proc.WaitFor, debugInfoDirs []str
// debugging PIEs.
func (p *gdbProcess) EntryPoint() (uint64, error) {
var entryPoint uint64
if p.bi.GOOS == "darwin" && p.bi.Arch.Name == "arm64" {
if p.bi.GOOS == "darwin" {
// There is no auxv on darwin, however, we can get the location of the mach-o
// header from the debugserver by going through the loaded libraries, which includes
// the exe itself
Expand Down

0 comments on commit ec07c27

Please sign in to comment.