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/link/internal/loader/loader.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/cmd/link/internal/loader/loader.go') diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 664f345ead..52c7d72835 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -722,9 +722,9 @@ func (l *Loader) checkdup(name string, r *oReader, li uint32, dup Sym) { // here is that we get different line numbers on formal // params; I am guessing that the pos is being inherited // from the spot where the wrapper is needed. - allowed := strings.HasPrefix(name, "go.info.go.interface") || - strings.HasPrefix(name, "go.info.go.builtin") || - strings.HasPrefix(name, "go.debuglines") + allowed := strings.HasPrefix(name, "go:info.go.interface") || + strings.HasPrefix(name, "go:info.go.builtin") || + strings.HasPrefix(name, "go:debuglines") if !allowed { l.strictDupMsgs++ } @@ -1704,7 +1704,7 @@ func (l *Loader) OuterSym(i Sym) Sym { // SubSym gets the subsymbol for host object loaded symbols. func (l *Loader) SubSym(i Sym) Sym { // NB: note -- no check for l.isExternal(), since I am pretty sure - // that later phases in the linker set subsym for "type." syms + // that later phases in the linker set subsym for "type:" syms return l.sub[i] } @@ -1717,7 +1717,7 @@ func (l *Loader) SubSym(i Sym) Sym { // emits named string symbols (type SGOSTRING) when compiling a // package; after being deduplicated, these symbols are collected into // a single unit by assigning them a new carrier symbol named -// "go.string.*" (which appears in the final symbol table for the +// "go:string.*" (which appears in the final symbol table for the // output load module). func (l *Loader) SetCarrierSym(s Sym, c Sym) { if c == 0 { @@ -2133,7 +2133,7 @@ func (st *loadState) preloadSyms(r *oReader, kind int) { l.SetAttrUsedInIface(gi, true) } if strings.HasPrefix(name, "runtime.") || - (loadingRuntimePkg && strings.HasPrefix(name, "type.")) { + (loadingRuntimePkg && strings.HasPrefix(name, "type:")) { if bi := goobj.BuiltinIdx(name, int(osym.ABI())); bi != -1 { // This is a definition of a builtin symbol. Record where it is. l.builtinSyms[bi] = gi -- cgit v1.3