]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: avoid duplicate file name symbols
authorDavid Lazar <lazard@golang.org>
Fri, 17 Feb 2017 21:20:52 +0000 (16:20 -0500)
committerDavid Lazar <lazard@golang.org>
Fri, 3 Mar 2017 21:29:36 +0000 (21:29 +0000)
The meaning of Version=1 was overloaded: it was reserved for file name
symbols (to avoid conflicts with non-file name symbols), but was also
used to mean "give me a fresh version number for this symbol."

With the new inlining tree, the same file name symbol can appear in
multiple entries, but each one would become a distinct symbol with its
own version number.

Now, we avoid duplicating symbols by using Version=0 for file name
symbols and we avoid conflicts with other symbols by prefixing the
symbol name with "gofile..".

Change-Id: I8d0374053b8cdb6a9ca7fb71871b69b4dd369a9c
Reviewed-on: https://go-review.googlesource.com/37234
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/obj/line.go
src/cmd/internal/obj/line_test.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/sym.go
src/cmd/link/internal/ld/pcln.go

index c0a66ba84de71b6111f645b7816902c3c4e672f1..be6b36da418e8830fdbb7ff4bff0bf8a815815af 100644 (file)
@@ -74,14 +74,16 @@ func (ctxt *Link) AddImport(pkg string) {
        ctxt.Imports = append(ctxt.Imports, pkg)
 }
 
+const FileSymPrefix = "gofile.."
+
 func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f *LSym, l int32) {
        pos := ctxt.PosTable.Pos(xpos)
        filename := pos.AbsFilename()
        if !pos.IsKnown() || filename == "" {
-               return Linklookup(ctxt, "??", HistVersion), 0
+               return Linklookup(ctxt, FileSymPrefix+"??", 0), 0
        }
        // TODO(gri) Should this use relative or absolute line number?
-       return Linklookup(ctxt, filename, HistVersion), int32(pos.RelLine())
+       return Linklookup(ctxt, FileSymPrefix+filename, 0), int32(pos.RelLine())
 }
 
 func fieldtrack(ctxt *Link, cursym *LSym) {
index 0f9585ed714d65628b7373ce05573b72e1bb6604..928a0080016ef2f0302ed17da512fd1e93230635 100644 (file)
@@ -32,7 +32,7 @@ func TestLinkgetlineFromPos(t *testing.T) {
        for _, test := range tests {
                f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos))
                got := fmt.Sprintf("%s:%d", f.Name, l)
-               if got != test.want {
+               if got != FileSymPrefix+test.want {
                        t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want)
                }
        }
index 2b066cef34d6d2e568ca5bb0227e2c89f43ace9a..9de26a5a032561700530f83627e2af01da8ec92f 100644 (file)
@@ -708,12 +708,6 @@ type Pcdata struct {
        P []byte
 }
 
-// symbol version, incremented each time a file is loaded.
-// version==1 is reserved for savehist.
-const (
-       HistVersion = 1
-)
-
 // Link holds the context for writing object code from a compiler
 // to be linker input or for reading that input into the linker.
 type Link struct {
index 8dd6e8f1777e57e995a10f9dbe13c09865b9769c..0527397749c3ad519898019f83b32b8054ef6991 100644 (file)
@@ -53,7 +53,7 @@ func Linknew(arch *LinkArch) *Link {
        ctxt := new(Link)
        ctxt.Hash = make(map[SymVer]*LSym)
        ctxt.Arch = arch
-       ctxt.Version = HistVersion
+       ctxt.Version = 0
        ctxt.Pathname = WorkingDir()
 
        ctxt.Headtype.Set(GOOS)
index a1e28c1536b75db6802acf24c4855d8ce0801746..c944da9f2866115bb4306073d80601ef630e9a5f 100644 (file)
@@ -114,7 +114,8 @@ func numberfile(ctxt *Link, file *Symbol) {
                ctxt.Filesyms = append(ctxt.Filesyms, file)
                file.Value = int64(len(ctxt.Filesyms))
                file.Type = obj.SFILEPATH
-               file.Name = expandGoroot(file.Name)
+               path := file.Name[len(obj.FileSymPrefix):]
+               file.Name = expandGoroot(path)
        }
 }