From 0f8dffd0aa71ed996d32e77701ac5ec0bc7cde01 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sat, 8 May 2021 00:45:06 +0700 Subject: 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 Run-TryBot: Cuong Manh Le Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/internal/dwarf/dwarf.go | 6 +-- src/cmd/internal/goobj/builtinlist.go | 72 +++++++++++++++++------------------ src/cmd/internal/goobj/mkbuiltin.go | 6 +-- src/cmd/internal/obj/objfile.go | 14 +++---- 4 files changed, 49 insertions(+), 49 deletions(-) (limited to 'src/cmd/internal') diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go index 8ba57371e6..4821efa963 100644 --- a/src/cmd/internal/dwarf/dwarf.go +++ b/src/cmd/internal/dwarf/dwarf.go @@ -21,15 +21,15 @@ import ( ) // InfoPrefix is the prefix for all the symbols containing DWARF info entries. -const InfoPrefix = "go.info." +const InfoPrefix = "go:info." // ConstInfoPrefix is the prefix for all symbols containing DWARF info // entries that contain constants. -const ConstInfoPrefix = "go.constinfo." +const ConstInfoPrefix = "go:constinfo." // CUInfoPrefix is the prefix for symbols containing information to // populate the DWARF compilation unit info entries. -const CUInfoPrefix = "go.cuinfo." +const CUInfoPrefix = "go:cuinfo." // Used to form the symbol name assigned to the DWARF 'abstract subprogram" // info entry for a function diff --git a/src/cmd/internal/goobj/builtinlist.go b/src/cmd/internal/goobj/builtinlist.go index 2d13222984..ae2e6cc004 100644 --- a/src/cmd/internal/goobj/builtinlist.go +++ b/src/cmd/internal/goobj/builtinlist.go @@ -214,40 +214,40 @@ var builtins = [...]struct { {"runtime.morestack", 0}, {"runtime.morestackc", 0}, {"runtime.morestack_noctxt", 0}, - {"type.int8", 0}, - {"type.*int8", 0}, - {"type.uint8", 0}, - {"type.*uint8", 0}, - {"type.int16", 0}, - {"type.*int16", 0}, - {"type.uint16", 0}, - {"type.*uint16", 0}, - {"type.int32", 0}, - {"type.*int32", 0}, - {"type.uint32", 0}, - {"type.*uint32", 0}, - {"type.int64", 0}, - {"type.*int64", 0}, - {"type.uint64", 0}, - {"type.*uint64", 0}, - {"type.float32", 0}, - {"type.*float32", 0}, - {"type.float64", 0}, - {"type.*float64", 0}, - {"type.complex64", 0}, - {"type.*complex64", 0}, - {"type.complex128", 0}, - {"type.*complex128", 0}, - {"type.unsafe.Pointer", 0}, - {"type.*unsafe.Pointer", 0}, - {"type.uintptr", 0}, - {"type.*uintptr", 0}, - {"type.bool", 0}, - {"type.*bool", 0}, - {"type.string", 0}, - {"type.*string", 0}, - {"type.error", 0}, - {"type.*error", 0}, - {"type.func(error) string", 0}, - {"type.*func(error) string", 0}, + {"type:int8", 0}, + {"type:*int8", 0}, + {"type:uint8", 0}, + {"type:*uint8", 0}, + {"type:int16", 0}, + {"type:*int16", 0}, + {"type:uint16", 0}, + {"type:*uint16", 0}, + {"type:int32", 0}, + {"type:*int32", 0}, + {"type:uint32", 0}, + {"type:*uint32", 0}, + {"type:int64", 0}, + {"type:*int64", 0}, + {"type:uint64", 0}, + {"type:*uint64", 0}, + {"type:float32", 0}, + {"type:*float32", 0}, + {"type:float64", 0}, + {"type:*float64", 0}, + {"type:complex64", 0}, + {"type:*complex64", 0}, + {"type:complex128", 0}, + {"type:*complex128", 0}, + {"type:unsafe.Pointer", 0}, + {"type:*unsafe.Pointer", 0}, + {"type:uintptr", 0}, + {"type:*uintptr", 0}, + {"type:bool", 0}, + {"type:*bool", 0}, + {"type:string", 0}, + {"type:*string", 0}, + {"type:error", 0}, + {"type:*error", 0}, + {"type:func(error) string", 0}, + {"type:*func(error) string", 0}, } diff --git a/src/cmd/internal/goobj/mkbuiltin.go b/src/cmd/internal/goobj/mkbuiltin.go index c9995fcede..d9db63ad44 100644 --- a/src/cmd/internal/goobj/mkbuiltin.go +++ b/src/cmd/internal/goobj/mkbuiltin.go @@ -105,7 +105,7 @@ func mkbuiltin(w io.Writer) { extras := append(fextras[:], enumerateBasicTypes()...) for _, b := range extras { prefix := "" - if !strings.HasPrefix(b.name, "type.") { + if !strings.HasPrefix(b.name, "type:") { prefix = pkg + "." } name := prefix + b.name @@ -130,8 +130,8 @@ func enumerateBasicTypes() []extra { "func(error) string"} result := []extra{} for _, n := range names { - result = append(result, extra{"type." + n, 0}) - result = append(result, extra{"type.*" + n, 0}) + result = append(result, extra{"type:" + n, 0}) + result = append(result, extra{"type:*" + n, 0}) } return result } diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index 89339b0147..ec699a7951 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -321,14 +321,14 @@ func (w *writer) Sym(s *LSym) { if s.ReflectMethod() { flag |= goobj.SymFlagReflectMethod } - if strings.HasPrefix(s.Name, "type.") && s.Name[5] != '.' && s.Type == objabi.SRODATA { + if strings.HasPrefix(s.Name, "type:") && s.Name[5] != '.' && s.Type == objabi.SRODATA { flag |= goobj.SymFlagGoType } flag2 := uint8(0) if s.UsedInIface() { flag2 |= goobj.SymFlagUsedInIface } - if strings.HasPrefix(s.Name, "go.itab.") && s.Type == objabi.SRODATA { + if strings.HasPrefix(s.Name, "go:itab.") && s.Type == objabi.SRODATA { flag2 |= goobj.SymFlagItab } if strings.HasPrefix(s.Name, w.ctxt.Pkgpath) && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath):], ".") && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath)+1:], objabi.GlobalDictPrefix) { @@ -351,9 +351,9 @@ func (w *writer) Sym(s *LSym) { // TODO: maybe the compiler could set the alignment for all // data symbols more carefully. switch { - case strings.HasPrefix(s.Name, "go.string."), - strings.HasPrefix(name, "type..namedata."), - strings.HasPrefix(name, "type..importpath."), + case strings.HasPrefix(s.Name, "go:string."), + strings.HasPrefix(name, "type:.namedata."), + strings.HasPrefix(name, "type:.importpath."), strings.HasPrefix(name, "runtime.gcbits."), strings.HasSuffix(name, ".opendefer"), strings.HasSuffix(name, ".arginfo0"), @@ -430,9 +430,9 @@ func contentHashSection(s *LSym) byte { strings.HasSuffix(name, ".wrapinfo") || strings.HasSuffix(name, ".args_stackmap") || strings.HasSuffix(name, ".stkobj") { - return 'F' // go.func.* or go.funcrel.* + return 'F' // go:func.* or go:funcrel.* } - if strings.HasPrefix(name, "type.") { + if strings.HasPrefix(name, "type:") { return 'T' } return 0 -- cgit v1.3