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/compile/internal/reflectdata | |
| 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/compile/internal/reflectdata')
| -rw-r--r-- | src/cmd/compile/internal/reflectdata/reflect.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 8fb2d50c40..5833c71f4c 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -411,7 +411,7 @@ func dimportpath(p *types.Pkg) { return } - s := base.Ctxt.Lookup("type..importpath." + p.Prefix + ".") + s := base.Ctxt.Lookup("type:.importpath." + p.Prefix + ".") ot := dnameData(s, 0, p.Path, "", nil, false, false) objw.Global(s, int32(ot), obj.DUPOK|obj.RODATA) s.Set(obj.AttrContentAddressable, true) @@ -426,10 +426,10 @@ func dgopkgpath(s *obj.LSym, ot int, pkg *types.Pkg) int { if pkg == types.LocalPkg && base.Ctxt.Pkgpath == "" { // If we don't know the full import path of the package being compiled // (i.e. -p was not passed on the compiler command line), emit a reference to - // type..importpath.""., which the linker will rewrite using the correct import path. + // type:.importpath.""., which the linker will rewrite using the correct import path. // Every package that imports this one directly defines the symbol. // See also https://groups.google.com/forum/#!topic/golang-dev/myb9s53HxGQ. - ns := base.Ctxt.Lookup(`type..importpath."".`) + ns := base.Ctxt.Lookup(`type:.importpath."".`) return objw.SymPtr(s, ot, ns, 0) } @@ -445,10 +445,10 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int { if pkg == types.LocalPkg && base.Ctxt.Pkgpath == "" { // If we don't know the full import path of the package being compiled // (i.e. -p was not passed on the compiler command line), emit a reference to - // type..importpath.""., which the linker will rewrite using the correct import path. + // type:.importpath.""., which the linker will rewrite using the correct import path. // Every package that imports this one directly defines the symbol. // See also https://groups.google.com/forum/#!topic/golang-dev/myb9s53HxGQ. - ns := base.Ctxt.Lookup(`type..importpath."".`) + ns := base.Ctxt.Lookup(`type:.importpath."".`) return objw.SymPtrOff(s, ot, ns) } @@ -517,11 +517,11 @@ var dnameCount int // dname creates a reflect.name for a struct field or method. func dname(name, tag string, pkg *types.Pkg, exported, embedded bool) *obj.LSym { - // Write out data as "type.." to signal two things to the + // Write out data as "type:." to signal two things to the // linker, first that when dynamically linking, the symbol // should be moved to a relro section, and second that the // contents should not be decoded as a type. - sname := "type..namedata." + sname := "type:.namedata." if pkg == nil { // In the common case, share data with other packages. if name == "" { @@ -798,7 +798,7 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int { // TrackSym returns the symbol for tracking use of field/method f, assumed // to be a member of struct/interface type t. func TrackSym(t *types.Type, f *types.Field) *obj.LSym { - return base.PkgLinksym("go.track", t.LinkString()+"."+f.Sym.Name, obj.ABI0) + return base.PkgLinksym("go:track", t.LinkString()+"."+f.Sym.Name, obj.ABI0) } func TypeSymPrefix(prefix string, t *types.Type) *types.Sym { @@ -1358,7 +1358,7 @@ func WriteTabs() { // process ptabs if types.LocalPkg.Name == "main" && len(ptabs) > 0 { ot := 0 - s := base.Ctxt.Lookup("go.plugin.tabs") + s := base.Ctxt.Lookup("go:plugin.tabs") for _, p := range ptabs { // Dump ptab symbol into go.pluginsym package. // @@ -1381,7 +1381,7 @@ func WriteTabs() { objw.Global(s, int32(ot), int16(obj.RODATA)) ot = 0 - s = base.Ctxt.Lookup("go.plugin.exports") + s = base.Ctxt.Lookup("go:plugin.exports") for _, p := range ptabs { ot = objw.SymPtr(s, ot, p.Linksym(), 0) } @@ -1715,7 +1715,7 @@ func ZeroAddr(size int64) ir.Node { if ZeroSize < size { ZeroSize = size } - lsym := base.PkgLinksym("go.map", "zero", obj.ABI0) + lsym := base.PkgLinksym("go:map", "zero", obj.ABI0) x := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8]) return typecheck.Expr(typecheck.NodAddr(x)) } |
