summaryrefslogtreecommitdiff
path: root/src/cmd/ld/lib.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-02-03 13:51:43 -0500
committerRuss Cox <rsc@golang.org>2011-02-03 13:51:43 -0500
commitb844793155965a73646513b5bdef0276e4f25877 (patch)
tree4e74be1edf2e33aa49c0fc0f50f43dfc82c08929 /src/cmd/ld/lib.c
parent2e043e542ff9e92590c5de14ed36675c8c87be0f (diff)
downloadgo-b844793155965a73646513b5bdef0276e4f25877.tar.gz
gc, ld: detect stale or incompatible object files
The object files begin with a header that is $GOARCH on a line by itself. This CL changes that header to go object $GOOS $GOARCH release.2011-01-01 4567+ where the final two fields are the most recent release tag and the current hg version number. All objects imported into a Go compilation or linked into an executable must have the same header line, and that header line must match the compiler and linker versions. The effect of this will be that if you update and run all.bash and then try to link in objects compiled with an earlier version of the compiler (or invoke the wrong version of the compiler), you will get an error showing the different headers instead of perhaps silent incompatibility. Normal usage with all.bash should be unaffected, because all.bash deletes all the object files in $GOROOT/pkg/$GOOS_$GOARCH and cleans all intermediate object files before starting. This change is intended to diagnose stale objects arising when users maintaining alternate installation directories forget to rebuild some of their files after updating. It should help make the adoption of $GOPATH (CL 3780043) less error-prone. R=ken2, r CC=golang-dev http://codereview.appspot.com/4023063
Diffstat (limited to 'src/cmd/ld/lib.c')
-rw-r--r--src/cmd/ld/lib.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c
index b1a62f25e..0c9ea0b7c 100644
--- a/src/cmd/ld/lib.c
+++ b/src/cmd/ld/lib.c
@@ -378,10 +378,10 @@ ldobj(Biobuf *f, char *pkg, int64 len, char *pn, int whence)
int n, c1, c2, c3, c4;
uint32 magic;
vlong import0, import1, eof;
- char src[1024];
+ char *fld[10], *s, *t;
+ int nfld;
eof = Boffset(f) + len;
- src[0] = '\0';
pn = strdup(pn);
@@ -415,22 +415,34 @@ ldobj(Biobuf *f, char *pkg, int64 len, char *pn, int whence)
line = Brdline(f, '\n');
if(line == nil) {
if(Blinelen(f) > 0) {
- diag("%s: malformed object file", pn);
+ diag("%s: not an object file", pn);
return;
}
goto eof;
}
n = Blinelen(f) - 1;
- if(n != strlen(thestring) || strncmp(line, thestring, n) != 0) {
- if(line)
- line[n] = '\0';
+ line[n] = '\0';
+ if(strncmp(line, "go object ", 10) != 0) {
if(strlen(pn) > 3 && strcmp(pn+strlen(pn)-3, ".go") == 0) {
print("%cl: input %s is not .%c file (use %cg to compile .go files)\n", thechar, pn, thechar, thechar);
errorexit();
}
- diag("file not %s [%s]\n", thestring, line);
+ if(strcmp(line, thestring) == 0) {
+ // old header format: just $GOOS
+ diag("%s: stale object file", pn);
+ return;
+ }
+ diag("%s: not an object file", pn);
+ return;
+ }
+ t = smprint("%s %s %s", getgoos(), thestring, getgoversion());
+ if(strcmp(line+10, t) != 0) {
+ diag("%s: object is [%s] expected [%s]", pn, line+10, t);
+ free(t);
return;
}
+ free(t);
+ line[n] = '\n';
/* skip over exports and other info -- ends with \n!\n */
import0 = Boffset(f);