From: Russ Cox Date: Mon, 14 Apr 2014 17:20:51 +0000 (-0400) Subject: liblink, cmd/link: add version number to object file X-Git-Tag: go1.3beta1~95 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0e8de61d7311d6bc74fc244de44df9be452a112b;p=gostls13.git 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 1d5810a800..3b1b15f731 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 62619a7ea3..996268061b 100644 Binary files a/src/cmd/link/testdata/autosection.6 and b/src/cmd/link/testdata/autosection.6 differ diff --git a/src/cmd/link/testdata/autoweak.6 b/src/cmd/link/testdata/autoweak.6 index f7e9e69713..7bf428b51d 100644 Binary files a/src/cmd/link/testdata/autoweak.6 and b/src/cmd/link/testdata/autoweak.6 differ diff --git a/src/cmd/link/testdata/dead.6 b/src/cmd/link/testdata/dead.6 index f8eaf7ab8d..a512543cba 100644 Binary files a/src/cmd/link/testdata/dead.6 and b/src/cmd/link/testdata/dead.6 differ diff --git a/src/cmd/link/testdata/hello.6 b/src/cmd/link/testdata/hello.6 index 26a04a2016..c6435a5e6f 100644 Binary files a/src/cmd/link/testdata/hello.6 and b/src/cmd/link/testdata/hello.6 differ diff --git a/src/cmd/link/testdata/layout.6 b/src/cmd/link/testdata/layout.6 index b19491efc5..0a600d7c74 100644 Binary files a/src/cmd/link/testdata/layout.6 and b/src/cmd/link/testdata/layout.6 differ diff --git a/src/cmd/link/testdata/link.hello.darwin.amd64 b/src/cmd/link/testdata/link.hello.darwin.amd64 index 5d94af1d9c..b1f0a93b21 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 bc889c964a..722a7f806e 100644 Binary files a/src/cmd/link/testdata/pclntab.6 and b/src/cmd/link/testdata/pclntab.6 differ diff --git a/src/liblink/objfile.c b/src/liblink/objfile.c index b602536251..f0f3f76223 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 @@ 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); diff --git a/src/pkg/debug/goobj/read.go b/src/pkg/debug/goobj/read.go index f65abb6c27..8882eae534 100644 --- a/src/pkg/debug/goobj/read.go +++ b/src/pkg/debug/goobj/read.go @@ -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()