Commit 0e8de61d authored by Russ Cox's avatar Russ Cox

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
parent 071a0f4d
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
......@@ -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.|
......
......@@ -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 @@ linkwriteobj(Link *ctxt, Biobuf *b)
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 @@ ldobjfile(Link *ctxt, Biobuf *f, char *pkg, int64 len, char *pn)
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);
......
......@@ -573,6 +573,11 @@ func (r *objReader) parseObject(prefix []byte) error {
return r.error(errCorruptObject)
}
b := r.readByte()
if b != 1 {
return r.error(errCorruptObject)
}
// Direct package dependencies.
for {
s := r.readString()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment