diff options
author | Keith Randall <khr@golang.org> | 2021-10-21 18:28:50 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-10-25 20:41:00 +0000 |
commit | f92c8f07ace7ae67b95e59bbb6ae6928dd6e4773 (patch) | |
tree | 0d3bec4706629748e4ab529111f1451e82fbcf3d /src/cmd/link | |
parent | 72b6a89ca5cd3c3bfd13b9b17be976e8feb91ecc (diff) | |
download | go-f92c8f07ace7ae67b95e59bbb6ae6928dd6e4773.tar.gz go-f92c8f07ace7ae67b95e59bbb6ae6928dd6e4773.zip |
cmd/link: escape % characters in symbols when reporting errors
Generic function symbols sometimes have % in them, like:
main.B2[%2eshape.string_0].m2·f
Which confuses this code because it doesn't esacpe % when
using this string as a format string, instead of a format argument.
Or could we get rid of the . -> %2e rewrite somehow?
I think it comes from LinkString.
Change-Id: I3275501f44cf30485e9d4577e0dfa77996d4939e
Reviewed-on: https://go-review.googlesource.com/c/go/+/357837
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/link')
-rw-r--r-- | src/cmd/link/internal/loader/loader.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 9b7888e940..34c1c6a4c8 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -2592,7 +2592,9 @@ type ErrorReporter struct { // func (reporter *ErrorReporter) Errorf(s Sym, format string, args ...interface{}) { if s != 0 && reporter.ldr.SymName(s) != "" { - format = reporter.ldr.SymName(s) + ": " + format + // Note: Replace is needed here because symbol names might have % in them, + // due to the use of LinkString for names of instantiating types. + format = strings.Replace(reporter.ldr.SymName(s), "%", "%%", -1) + ": " + format } else { format = fmt.Sprintf("sym %d: %s", s, format) } |