diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-04-22 19:21:30 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-04-24 17:47:14 +0000 |
commit | e08f10b8b5fbb82ff1e2c263ad57e19d2de1e323 (patch) | |
tree | 1a7332196907af1966807e1664e2734ba6bb41f7 /src/cmd/compile/internal/gc/main.go | |
parent | 880ef2da7b81fe2e4e9fb75f4677377eeba70d1e (diff) | |
download | go-e08f10b8b5fbb82ff1e2c263ad57e19d2de1e323.tar.gz go-e08f10b8b5fbb82ff1e2c263ad57e19d2de1e323.zip |
[dev.link] cmd/internal/goobj2: add index fingerprint to object file
The new object files use indices for symbol references, instead
of names. Fundamental to the design, it requires that the
importing and imported packages have consistent view of symbol
indices. The Go command should already ensure this, when using
"go build". But in case it goes wrong, it could lead to obscure
errors like run-time crashes. It would be better to check the
index consistency at build time.
To do that, we add a fingerprint to each object file, which is
a hash of symbol indices. In the object file it records the
fingerprints of all imported packages, as well as its own
fingerprint. At link time, the linker checks that a package's
fingerprint matches the fingerprint recorded in the importing
packages, and issue an error if they don't match.
This CL does the first part: introducing the fingerprint in the
object file, and propagating fingerprints through
importing/exporting by the compiler. It is not yet used by the
linker. Next CL will do.
Change-Id: I0aa372da652e4afb11f2867cb71689a3e3f9966e
Reviewed-on: https://go-review.googlesource.com/c/go/+/229617
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/gc/main.go')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 2152c619fa..756cdbd3c9 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -14,6 +14,7 @@ import ( "cmd/compile/internal/types" "cmd/internal/bio" "cmd/internal/dwarf" + "cmd/internal/goobj2" "cmd/internal/obj" "cmd/internal/objabi" "cmd/internal/src" @@ -1254,15 +1255,6 @@ func importfile(f *Val) *types.Pkg { } } - // assume files move (get installed) so don't record the full path - if packageFile != nil { - // If using a packageFile map, assume path_ can be recorded directly. - Ctxt.AddImport(path_) - } else { - // For file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a". - Ctxt.AddImport(file[len(file)-len(path_)-len(".a"):]) - } - // In the importfile, if we find: // $$\n (textual format): not supported anymore // $$B\n (binary format) : import directly, then feed the lexer a dummy statement @@ -1287,6 +1279,7 @@ func importfile(f *Val) *types.Pkg { c, _ = imp.ReadByte() } + var fingerprint goobj2.FingerprintType switch c { case '\n': yyerror("cannot import %s: old export format no longer supported (recompile library)", path_) @@ -1310,13 +1303,22 @@ func importfile(f *Val) *types.Pkg { yyerror("import %s: unexpected package format byte: %v", file, c) errorexit() } - iimport(importpkg, imp) + fingerprint = iimport(importpkg, imp) default: yyerror("no import in %q", path_) errorexit() } + // assume files move (get installed) so don't record the full path + if packageFile != nil { + // If using a packageFile map, assume path_ can be recorded directly. + Ctxt.AddImport(path_, fingerprint) + } else { + // For file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a". + Ctxt.AddImport(file[len(file)-len(path_)-len(".a"):], fingerprint) + } + if importpkg.Height >= myheight { myheight = importpkg.Height + 1 } |