mirror of
https://github.com/golang/go
synced 2024-11-27 03:11:19 -07:00
cmd/link: improve error message and debugging
Correct an error message to missing section, not unreachable symbol. Also, under -v >= 2, dump symbol info on error for debugging. Updates #58966. Change-Id: I0f832c517d64f4b672b313a8b9be2d028744f945 Reviewed-on: https://go-review.googlesource.com/c/go/+/476735 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
5f1a0320b9
commit
f24afeef9a
@ -7,7 +7,7 @@
|
||||
|
||||
! go build -ldflags='-linkmode=external' .
|
||||
! stderr 'panic'
|
||||
stderr '^.*unreachable sym in relocation.*'
|
||||
stderr '^.*undefined symbol in relocation.*'
|
||||
|
||||
-- go.mod --
|
||||
|
||||
|
@ -444,14 +444,21 @@ func (st *relocSymState) relocsym(s loader.Sym, P []byte) {
|
||||
if weak && !ldr.AttrReachable(rs) {
|
||||
continue
|
||||
}
|
||||
if ldr.SymSect(rs) == nil {
|
||||
st.err.Errorf(s, "unreachable sym in relocation: %s", ldr.SymName(rs))
|
||||
sect := ldr.SymSect(rs)
|
||||
if sect == nil {
|
||||
if rst == sym.SDYNIMPORT {
|
||||
st.err.Errorf(s, "cannot target DYNIMPORT sym in section-relative reloc: %s", ldr.SymName(rs))
|
||||
} else if rst == sym.SUNDEFEXT {
|
||||
st.err.Errorf(s, "undefined symbol in relocation: %s", ldr.SymName(rs))
|
||||
} else {
|
||||
st.err.Errorf(s, "missing section for relocation target %s", ldr.SymName(rs))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// The method offset tables using this relocation expect the offset to be relative
|
||||
// to the start of the first text section, even if there are multiple.
|
||||
if ldr.SymSect(rs).Name == ".text" {
|
||||
if sect.Name == ".text" {
|
||||
o = ldr.SymValue(rs) - int64(Segtext.Sections[0].Vaddr) + r.Add()
|
||||
} else {
|
||||
o = ldr.SymValue(rs) - int64(ldr.SymSect(rs).Vaddr) + r.Add()
|
||||
|
@ -159,6 +159,14 @@ func Main(arch *sys.Arch, theArch Arch) {
|
||||
// dump symbol info on crash
|
||||
defer func() { ctxt.loader.Dump() }()
|
||||
}
|
||||
if ctxt.Debugvlog > 1 {
|
||||
// dump symbol info on error
|
||||
AtExit(func() {
|
||||
if nerrors > 0 {
|
||||
ctxt.loader.Dump()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
switch *flagHeadType {
|
||||
case "":
|
||||
|
Loading…
Reference in New Issue
Block a user