]> Cypherpunks repositories - gostls13.git/commitdiff
ld: do not load the same object file multiple times.
authorRuss Cox <rsc@golang.org>
Mon, 25 Jan 2010 16:53:27 +0000 (08:53 -0800)
committerRuss Cox <rsc@golang.org>
Mon, 25 Jan 2010 16:53:27 +0000 (08:53 -0800)
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

src/cmd/5l/obj.c
src/cmd/6l/obj.c
src/cmd/8l/obj.c
src/cmd/ld/lib.c

index 9cfa0c45f4a5eb8a38c8f73f4dbe3bd927c42f21..1ccac71bc1c17ca78a7c948acc884dbdc83a4c1b 100644 (file)
@@ -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;
index e29cdb94725774cd21cd2911ff48efaa4fd06115..ca679737144b3e5d5351b076f8b3e431cba76422 100644 (file)
@@ -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;
index 0d950748b60c5aa33c153ad4215e148e50d72310..b83293496ae64b1be7f10ea98ba31a4a490d6424 100644 (file)
@@ -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;
index 7ede8c89e187c4d50555d4886b20df5773e356d4..550cce32097a590852de8830bc97eb19d96c41d4 100644 (file)
@@ -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;