aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/link/internal/ld/util.go')
-rw-r--r--src/cmd/link/internal/ld/util.go37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/cmd/link/internal/ld/util.go b/src/cmd/link/internal/ld/util.go
index 9d236db766..9f257b8fc0 100644
--- a/src/cmd/link/internal/ld/util.go
+++ b/src/cmd/link/internal/ld/util.go
@@ -5,6 +5,7 @@
package ld
import (
+ "cmd/link/internal/loader"
"cmd/link/internal/sym"
"encoding/binary"
"fmt"
@@ -38,6 +39,18 @@ func Exitf(format string, a ...interface{}) {
Exit(2)
}
+// afterErrorAction updates 'nerrors' on error and invokes exit or
+// panics in the proper circumstances.
+func afterErrorAction() {
+ nerrors++
+ if *flagH {
+ panic("error")
+ }
+ if nerrors > 20 {
+ Exitf("too many errors")
+ }
+}
+
// Errorf logs an error message.
//
// If more than 20 errors have been printed, exit with an error.
@@ -50,13 +63,25 @@ func Errorf(s *sym.Symbol, format string, args ...interface{}) {
}
format += "\n"
fmt.Fprintf(os.Stderr, format, args...)
- nerrors++
- if *flagH {
- panic("error")
- }
- if nerrors > 20 {
- Exitf("too many errors")
+ afterErrorAction()
+}
+
+// Errorf method logs an error message.
+//
+// If more than 20 errors have been printed, exit with an error.
+//
+// Logging an error means that on exit cmd/link will delete any
+// output file and return a non-zero error code.
+func (ctxt *Link) Errorf(s loader.Sym, format string, args ...interface{}) {
+ if s != 0 && ctxt.loader != nil {
+ sn := ctxt.loader.SymName(s)
+ format = sn + ": " + format
+ } else {
+ format = fmt.Sprintf("sym %d: %s", s, format)
}
+ format += "\n"
+ fmt.Fprintf(os.Stderr, format, args...)
+ afterErrorAction()
}
func artrim(x []byte) string {