aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj/objfile.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-09-27 13:39:43 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-09-28 03:21:58 +0000
commit534dfb2aeb0721eeedb847e0d60785da8ac13315 (patch)
treee06642aa89ca821b620719d8c271729d11a07557 /src/cmd/internal/obj/objfile.go
parent850a4ffb6346dd53f6f5624c13410d99e6509cae (diff)
downloadgo-534dfb2aeb0721eeedb847e0d60785da8ac13315.tar.xz
cmd/internal/obj: refactor code to separate content-addressable symbols by section
The goal of this change is to improve the documentation and make it easier to keep Link.NumberSyms and writer.contentHash aligned. No functional changes. A subsequent change will add conditions to contentHashSection. Change-Id: I0a274f6974459d34d5a8553081f33ea4cd87f248 Reviewed-on: https://go-review.googlesource.com/c/go/+/352669 Trust: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/obj/objfile.go')
-rw-r--r--src/cmd/internal/obj/objfile.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 3e5cf0e243..1a8a9635d6 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -381,7 +381,26 @@ func (w *writer) Hash(s *LSym) {
w.Bytes(b[:])
}
+// contentHashSection returns a mnemonic for s's section.
+// The goal is to prevent content-addressability from moving symbols between sections.
+// contentHashSection only distinguishes between sets of sections for which this matters.
+// Allowing flexibility increases the effectiveness of content-addressibility.
+// But in some cases, such as doing addressing based on a base symbol,
+// we need to ensure that a symbol is always in a prticular section.
+// Some of these conditions are duplicated in cmd/link/internal/ld.(*Link).symtab.
+// TODO: instead of duplicating them, have the compiler decide where symbols go.
+func contentHashSection(s *LSym) byte {
+ name := s.Name
+ if strings.HasPrefix(name, "type.") {
+ return 'T'
+ }
+ return 0
+}
+
func contentHash64(s *LSym) goobj.Hash64Type {
+ if contentHashSection(s) != 0 {
+ panic("short hash of non-default-section sym " + s.Name)
+ }
var b goobj.Hash64Type
copy(b[:], s.P)
return b
@@ -416,15 +435,10 @@ func (w *writer) contentHash(s *LSym) goobj.HashType {
// In this case, if the smaller symbol is alive, the larger is not kept unless
// needed.
binary.LittleEndian.PutUint64(tmp[:8], uint64(s.Size))
- h.Write(tmp[:8])
+ // Some symbols require being in separate sections.
+ tmp[8] = contentHashSection(s)
+ h.Write(tmp[:9])
- // Don't dedup type symbols with others, as they are in a different
- // section.
- if strings.HasPrefix(s.Name, "type.") {
- h.Write([]byte{'T'})
- } else {
- h.Write([]byte{0})
- }
// The compiler trims trailing zeros _sometimes_. We just do
// it always.
h.Write(bytes.TrimRight(s.P, "\x00"))