mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: fix duplicated "undefined reloc" errors
For given program with 2 undefined relocations (main and undefined):
package main
func undefined()
func defined() int {
undefined()
undefined()
return 0
}
var x = defined()
"go tool link" produces these errors:
main.defined: relocation target main.undefined not defined
main.defined: relocation target main.undefined not defined
runtime.main_main·f: relocation target main.main not defined
main.defined: undefined: "main.undefined"
main.defined: undefined: "main.undefined"
runtime.main_main·f: undefined: "main.main"
After this CL is applied:
main.defined: relocation target main.undefined not defined
runtime.main_main·f: function main is undeclared in the main package
Fixes #10978
Improved error message for main proposed in #24809.
Change-Id: I4ba8547b1e143bbebeb4d6e29ea05d932124f037
Reviewed-on: https://go-review.googlesource.com/113955
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
0e934dd90e
commit
2c01b7d632
5 changed files with 131 additions and 2 deletions
|
|
@ -2199,6 +2199,18 @@ func undefsym(ctxt *Link, s *sym.Symbol) {
|
|||
}
|
||||
|
||||
func (ctxt *Link) undef() {
|
||||
// undefsym performs checks (almost) identical to checks
|
||||
// that report undefined relocations in relocsym.
|
||||
// Both undefsym and relocsym can report same symbol as undefined,
|
||||
// which results in error message duplication (see #10978).
|
||||
//
|
||||
// The undef is run after Arch.Asmb and could detect some
|
||||
// programming errors there, but if object being linked is already
|
||||
// failed with errors, it is better to avoid duplicated errors.
|
||||
if nerrors > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, s := range ctxt.Textp {
|
||||
undefsym(ctxt, s)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue