aboutsummaryrefslogtreecommitdiff
path: root/src/debug/gosym/symtab.go
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-05-08 00:45:06 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2022-08-09 11:28:56 +0000
commit0f8dffd0aa71ed996d32e77701ac5ec0bc7cde01 (patch)
tree9840e8c7e2abac7674a9dfaa6b0c73655124f0fa /src/debug/gosym/symtab.go
parent5639fcae7fee2cf04c1b87e9a81155ee3bb6ed71 (diff)
downloadgo-0f8dffd0aa71ed996d32e77701ac5ec0bc7cde01.tar.xz
all: use ":" for compiler generated symbols
As it can't appear in user package paths. There is a hack for handling "go:buildid" and "type:*" on windows/386. Previously, windows/386 requires underscore prefix on external symbols, but that's only applied for SHOSTOBJ/SUNDEFEXT or cgo export symbols. "go.buildid" is STEXT, "type.*" is STYPE, thus they are not prefixed with underscore. In external linking mode, the external linker can't resolve them as external symbols. But we are lucky that they have "." in their name, so the external linker see them as Forwarder RVA exports. See: - https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#export-address-table - https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/pe-dll.c;h=e7b82ba6ffadf74dc1b9ee71dc13d48336941e51;hb=HEAD#l972) This CL changes "." to ":" in symbols name, so theses symbols can not be found by external linker anymore. So a hacky way is adding the underscore prefix for these 2 symbols. I don't have enough knowledge to verify whether adding the underscore for all STEXT/STYPE symbols are fine, even if it could be, that would be done in future CL. Fixes #37762 Change-Id: I92eaaf24c0820926a36e0530fdb07b07af1fcc35 Reviewed-on: https://go-review.googlesource.com/c/go/+/317917 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/debug/gosym/symtab.go')
-rw-r--r--src/debug/gosym/symtab.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/debug/gosym/symtab.go b/src/debug/gosym/symtab.go
index afc67198c3..d87b312b56 100644
--- a/src/debug/gosym/symtab.go
+++ b/src/debug/gosym/symtab.go
@@ -27,6 +27,8 @@ type Sym struct {
GoType uint64
// If this symbol is a function symbol, the corresponding Func
Func *Func
+
+ goVersion version
}
// Static reports whether this symbol is static (not visible outside its file).
@@ -55,9 +57,16 @@ func (s *Sym) nameWithoutInst() string {
func (s *Sym) PackageName() string {
name := s.nameWithoutInst()
- // A prefix of "type." and "go." is a compiler-generated symbol that doesn't belong to any package.
- // See variable reservedimports in cmd/compile/internal/gc/subr.go
- if strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.") {
+ // Since go1.20, a prefix of "type:" and "go:" is a compiler-generated symbol,
+ // they do not belong to any package.
+ //
+ // See cmd/compile/internal/base/link.go:ReservedImports variable.
+ if s.goVersion >= ver120 && (strings.HasPrefix(name, "go:") || strings.HasPrefix(name, "type:")) {
+ return ""
+ }
+
+ // For go1.18 and below, the prefix are "type." and "go." instead.
+ if s.goVersion <= ver118 && (strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.")) {
return ""
}
@@ -350,6 +359,7 @@ func NewTable(symtab []byte, pcln *LineTable) (*Table, error) {
ts.Type = s.typ
ts.Value = s.value
ts.GoType = s.gotype
+ ts.goVersion = pcln.version
switch s.typ {
default:
// rewrite name to use . instead of ยท (c2 b7)