diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-05-08 00:45:06 +0700 |
|---|---|---|
| committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-08-09 11:28:56 +0000 |
| commit | 0f8dffd0aa71ed996d32e77701ac5ec0bc7cde01 (patch) | |
| tree | 9840e8c7e2abac7674a9dfaa6b0c73655124f0fa /src/cmd/link/internal/loader | |
| parent | 5639fcae7fee2cf04c1b87e9a81155ee3bb6ed71 (diff) | |
| download | go-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/cmd/link/internal/loader')
| -rw-r--r-- | src/cmd/link/internal/loader/loader.go | 12 | ||||
| -rw-r--r-- | src/cmd/link/internal/loader/loader_test.go | 10 |
2 files changed, 11 insertions, 11 deletions
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 diff --git a/src/cmd/link/internal/loader/loader_test.go b/src/cmd/link/internal/loader/loader_test.go index b22e2136bb..7d1031e9dc 100644 --- a/src/cmd/link/internal/loader/loader_test.go +++ b/src/cmd/link/internal/loader/loader_test.go @@ -39,9 +39,9 @@ func TestAddMaterializedSymbol(t *testing.T) { or := &dummyOreader // Create some syms from a dummy object file symbol to get things going. - ts1 := addDummyObjSym(t, ldr, or, "type.uint8") + ts1 := addDummyObjSym(t, ldr, or, "type:uint8") ts2 := addDummyObjSym(t, ldr, or, "mumble") - ts3 := addDummyObjSym(t, ldr, or, "type.string") + ts3 := addDummyObjSym(t, ldr, or, "type:string") // Create some external symbols. es1 := ldr.LookupOrCreateSym("extnew1", 0) @@ -52,7 +52,7 @@ func TestAddMaterializedSymbol(t *testing.T) { if es1x != es1 { t.Fatalf("LookupOrCreateSym lookup: expected %d got %d for second lookup", es1, es1x) } - es2 := ldr.LookupOrCreateSym("go.info.type.uint8", 0) + es2 := ldr.LookupOrCreateSym("go:info.type.uint8", 0) if es2 == 0 { t.Fatalf("LookupOrCreateSym failed for go.info.type.uint8") } @@ -252,7 +252,7 @@ func TestAddDataMethods(t *testing.T) { or := &dummyOreader // Populate loader with some symbols. - addDummyObjSym(t, ldr, or, "type.uint8") + addDummyObjSym(t, ldr, or, "type:uint8") ldr.LookupOrCreateSym("hello", 0) arch := sys.ArchAMD64 @@ -371,7 +371,7 @@ func TestOuterSub(t *testing.T) { or := &dummyOreader // Populate loader with some symbols. - addDummyObjSym(t, ldr, or, "type.uint8") + addDummyObjSym(t, ldr, or, "type:uint8") es1 := ldr.LookupOrCreateSym("outer", 0) ldr.MakeSymbolUpdater(es1).SetSize(101) es2 := ldr.LookupOrCreateSym("sub1", 0) |
