liblink, cmd/link: add version number to object file
There are changes we know we want to make, but not before Go 1.3
Add a version number so that we can make them more easily later.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/87670043
diff --git a/src/cmd/link/testdata/Makefile b/src/cmd/link/testdata/Makefile
index 1d5810a..3b1b15f 100644
--- a/src/cmd/link/testdata/Makefile
+++ b/src/cmd/link/testdata/Makefile
@@ -1,10 +1,15 @@
-all: hello.6 pclntab.6
+ALL=\
+ autosection.6\
+ autoweak.6\
+ dead.6\
+ hello.6\
+ layout.6\
+ pclntab.6\
-hello.6: hello.s
- go tool 6a hello.s
+all: $(ALL)
-pclntab.6: pclntab.s
- go tool 6a pclntab.s
+%.6: %.s
+ go tool 6a $*.s
pclntab.s: genpcln.go
go run genpcln.go >pclntab.s
diff --git a/src/cmd/link/testdata/autosection.6 b/src/cmd/link/testdata/autosection.6
index 62619a7..9962680 100644
--- a/src/cmd/link/testdata/autosection.6
+++ b/src/cmd/link/testdata/autosection.6
Binary files differ
diff --git a/src/cmd/link/testdata/autoweak.6 b/src/cmd/link/testdata/autoweak.6
index f7e9e69..7bf428b 100644
--- a/src/cmd/link/testdata/autoweak.6
+++ b/src/cmd/link/testdata/autoweak.6
Binary files differ
diff --git a/src/cmd/link/testdata/dead.6 b/src/cmd/link/testdata/dead.6
index f8eaf7a..a512543 100644
--- a/src/cmd/link/testdata/dead.6
+++ b/src/cmd/link/testdata/dead.6
Binary files differ
diff --git a/src/cmd/link/testdata/hello.6 b/src/cmd/link/testdata/hello.6
index 26a04a20..c6435a5 100644
--- a/src/cmd/link/testdata/hello.6
+++ b/src/cmd/link/testdata/hello.6
Binary files differ
diff --git a/src/cmd/link/testdata/layout.6 b/src/cmd/link/testdata/layout.6
index b19491e..0a600d7 100644
--- a/src/cmd/link/testdata/layout.6
+++ b/src/cmd/link/testdata/layout.6
Binary files differ
diff --git a/src/cmd/link/testdata/link.hello.darwin.amd64 b/src/cmd/link/testdata/link.hello.darwin.amd64
index 5d94af1..b1f0a93 100644
--- a/src/cmd/link/testdata/link.hello.darwin.amd64
+++ b/src/cmd/link/testdata/link.hello.darwin.amd64
@@ -49,8 +49,8 @@
00001080 02 20 00 04 20 00 06 05 02 05 02 05 02 05 02 02 |. .. ...........|
00001090 02 02 02 05 02 02 02 01 00 00 00 00 00 00 00 00 |................|
000010a0 02 00 00 00 88 00 00 00 2f 55 73 65 72 73 2f 72 |......../Users/r|
-000010b0 73 63 2f 72 73 63 67 6f 2f 73 72 63 2f 63 6d 64 |sc/rscgo/src/cmd|
-000010c0 2f 6c 64 32 2f 74 65 73 74 64 61 74 61 2f 68 65 |/ld2/testdata/he|
+000010b0 73 63 2f 67 2f 67 6f 2f 73 72 63 2f 63 6d 64 2f |sc/g/go/src/cmd/|
+000010c0 6c 69 6e 6b 2f 74 65 73 74 64 61 74 61 2f 68 65 |link/testdata/he|
000010d0 6c 6c 6f 2e 73 00 00 00 00 00 00 00 00 00 00 00 |llo.s...........|
*
00002000 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a |hello world.|
diff --git a/src/cmd/link/testdata/pclntab.6 b/src/cmd/link/testdata/pclntab.6
index bc889c9..722a7f8 100644
--- a/src/cmd/link/testdata/pclntab.6
+++ b/src/cmd/link/testdata/pclntab.6
Binary files differ
diff --git a/src/liblink/objfile.c b/src/liblink/objfile.c
index b602536..f0f3f76 100644
--- a/src/liblink/objfile.c
+++ b/src/liblink/objfile.c
@@ -16,6 +16,7 @@
// The file format is:
//
// - magic header: "\x00\x00go13ld"
+// - byte 1 - version number
// - sequence of strings giving dependencies (imported packages)
// - empty string (marks end of sequence)
// - sequence of defined symbols
@@ -248,7 +249,8 @@
Bputc(b, 0);
Bputc(b, 0);
Bprint(b, "go13ld");
-
+ Bputc(b, 1); // version
+
// Emit autolib.
for(h = ctxt->hist; h != nil; h = h->link)
if(h->offset < 0)
@@ -453,6 +455,8 @@
Bread(f, buf, sizeof buf);
if(memcmp(buf, startmagic, sizeof buf) != 0)
sysfatal("%s: invalid file start %x %x %x %x %x %x %x %x", pn, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ if((c = Bgetc(f)) != 1)
+ sysfatal("%s: invalid file version number %d", pn, c);
for(;;) {
lib = rdstring(f);
diff --git a/src/pkg/debug/goobj/read.go b/src/pkg/debug/goobj/read.go
index f65abb6..8882eae 100644
--- a/src/pkg/debug/goobj/read.go
+++ b/src/pkg/debug/goobj/read.go
@@ -573,6 +573,11 @@
return r.error(errCorruptObject)
}
+ b := r.readByte()
+ if b != 1 {
+ return r.error(errCorruptObject)
+ }
+
// Direct package dependencies.
for {
s := r.readString()