Commit 69e244a1 authored by Russ Cox's avatar Russ Cox

ld: do not load the same object file multiple times.

eliminates spurious multiple initialization errors.

give more information in the multiple init errors that remain.

Fixes #87.

R=r
CC=golang-dev
https://golang.org/cl/194052
parent 34191d94
......@@ -659,6 +659,12 @@ loop:
if(s != S) {
p->dlink = s->data;
s->data = p;
if(s->file == nil)
s->file = pn;
else if(s->file != pn) {
diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
errorexit();
}
}
if(edatap == P)
datap = p;
......
......@@ -692,6 +692,12 @@ loop:
if(s != S) {
p->dlink = s->data;
s->data = p;
if(s->file == nil)
s->file = pn;
else if(s->file != pn) {
diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
errorexit();
}
}
if(edatap == P)
datap = p;
......
......@@ -729,6 +729,12 @@ loop:
if(s != S) {
p->dlink = s->data;
s->data = p;
if(s->file == nil)
s->file = pn;
else if(s->file != pn) {
diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
errorexit();
}
}
if(edatap == P)
datap = p;
......
......@@ -338,13 +338,21 @@ ldobj(Biobuf *f, char *pkg, int64 len, char *pn)
static int files;
static char **filen;
char **nfilen, *line;
int n, c1, c2, c3;
int i, n, c1, c2, c3;
vlong import0, import1, eof;
char src[1024];
eof = Boffset(f) + len;
src[0] = '\0';
// don't load individual object more than once.
// happens with import of .6 files because of loop in xresolv.
// doesn't happen with .a because SYMDEF is consulted
// first to decide whether each individual object file is needed.
for(i=0; i<files; i++)
if(strcmp(filen[i], pn) == 0)
return;
if((files&15) == 0){
nfilen = malloc((files+16)*sizeof(char*));
memmove(nfilen, filen, files*sizeof(char*));
......@@ -354,7 +362,6 @@ ldobj(Biobuf *f, char *pkg, int64 len, char *pn)
pn = strdup(pn);
filen[files++] = pn;
/* check the header */
line = Brdline(f, '\n');
if(line == nil) {
......@@ -390,7 +397,6 @@ ldobj(Biobuf *f, char *pkg, int64 len, char *pn)
ldpkg(f, pkg, import1 - import0 - 2, pn); // -2 for !\n
Bseek(f, import1, 0);
// PGNS: Should be using import path, not pkg.
ldobj1(f, pkg, eof - Boffset(f), pn);
return;
......
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