mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: set direct fn address in dwarf gen where possible
If we are internal linking a static executable, and address assignment has happened, then when emitting some parts of DWARF we can just emit a function address directly instead of generating a relocation. For external linking or other build modes, we are generating a relocatable binary so we still need to emit relocations. This CL inspired by Cherry's similar CL for pclntab at https://go-review.googlesource.com/c/go/+/228478. Change-Id: Ib03fbe2dd72d0ba746bf46015e0f2d6c3f3d53ab Reviewed-on: https://go-review.googlesource.com/c/go/+/228537 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
4a0bca37d2
commit
da9f383ca1
2 changed files with 29 additions and 2 deletions
|
|
@ -405,3 +405,24 @@ func (sb *SymbolBuilder) AddSize(arch *sys.Arch, tgt Sym) int64 {
|
|||
sb.setReachable()
|
||||
return sb.addSymRef(tgt, 0, objabi.R_SIZE, arch.PtrSize)
|
||||
}
|
||||
|
||||
// GenAddAddrPlusFunc returns a function to be called when capturing
|
||||
// a function symbol's address. In later stages of the link (when
|
||||
// address assignment is done) when doing internal linking and
|
||||
// targeting an executable, we can just emit the address of a function
|
||||
// directly instead of generating a relocation. Clients can call
|
||||
// this function (setting 'internalExec' based on build mode and target)
|
||||
// and then invoke the returned function in roughly the same way that
|
||||
// loader.*SymbolBuilder.AddAddrPlus would be used.
|
||||
func GenAddAddrPlusFunc(internalExec bool) func(s *SymbolBuilder, arch *sys.Arch, tgt Sym, add int64) int64 {
|
||||
if internalExec {
|
||||
return func(s *SymbolBuilder, arch *sys.Arch, tgt Sym, add int64) int64 {
|
||||
if v := s.l.SymValue(tgt); v != 0 {
|
||||
return s.AddUint(arch, uint64(v+add))
|
||||
}
|
||||
return s.AddAddrPlus(arch, tgt, add)
|
||||
}
|
||||
} else {
|
||||
return (*SymbolBuilder).AddAddrPlus
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue