summaryrefslogtreecommitdiff
path: root/src/cmd/6l/obj.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-11-13 13:42:26 -0800
committerRuss Cox <rsc@golang.org>2008-11-13 13:42:26 -0800
commit6d2bb9028988105daea084b1c93efe8b32bbc3ae (patch)
tree049c73b2438e48a5ec7c86166d5fa7ce7b9328a5 /src/cmd/6l/obj.c
parenta8f921a193aae6dba4ab59a6c06186fff93b1719 (diff)
downloadgolang-6d2bb9028988105daea084b1c93efe8b32bbc3ae.tar.gz
* 6l:
if an object in an archive tries to refer to a file in its original source directory, ignore it. * 6ar: fix bug if archive is empty. * gobuild: build archive in current directory. * math: use new gobuild Makefile. * test/math.go: rename to mathest.go, add // run line, make it run. R=r DELTA=494 (277 added, 203 deleted, 14 changed) OCL=19090 CL=19171
Diffstat (limited to 'src/cmd/6l/obj.c')
-rw-r--r--src/cmd/6l/obj.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/cmd/6l/obj.c b/src/cmd/6l/obj.c
index bc7413fe1..9777cdf42 100644
--- a/src/cmd/6l/obj.c
+++ b/src/cmd/6l/obj.c
@@ -542,6 +542,10 @@ objfile(char *file)
goto bad;
if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
goto bad;
+ l = SARNAME;
+ while(l > 0 && arhdr.name[l-1] == ' ')
+ l--;
+ sprint(pname, "%s(%.*s)", file, l, arhdr.name);
l = atolwhex(arhdr.size);
ldobj(f, l, pname);
if(s->type == SXREF) {
@@ -635,9 +639,9 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
}
void
-addlib(char *obj)
+addlib(char *src, char *obj)
{
- char name[1024], comp[256], *p;
+ char name[1024], comp[256], *p, *q;
int i;
if(histfrogp <= 0)
@@ -685,6 +689,23 @@ addlib(char *obj)
strcat(name, "/");
strcat(name, comp);
}
+ if(debug['v'])
+ Bprint(&bso, "%5.2f addlib: %s %s pulls in %s\n", cputime(), obj, src, name);
+
+ p = strrchr(src, '/');
+ q = strrchr(name, '/');
+ if(p != nil && q != nil && p - src == q - name && memcmp(src, name, p - src) == 0) {
+ // leading paths are the same.
+ // if the source file refers to an object in its own directory
+ // and we are inside an archive, ignore the reference, in the hope
+ // that the archive contains that object too.
+ if(strchr(obj, '(')) {
+ if(debug['v'])
+ Bprint(&bso, "%5.2f ignored srcdir object %s\n", cputime(), name);
+ return;
+ }
+ }
+
for(i=0; i<libraryp; i++)
if(strcmp(name, library[i]) == 0)
return;
@@ -703,6 +724,22 @@ addlib(char *obj)
}
void
+copyhistfrog(char *buf, int nbuf)
+{
+ char *p, *ep;
+ int i;
+
+ p = buf;
+ ep = buf + nbuf;
+ i = 0;
+ for(i=0; i<histfrogp; i++) {
+ p = seprint(p, ep, "%s", histfrog[i]->name+1);
+ if(i+1<histfrogp && (p == buf || p[-1] != '/'))
+ p = seprint(p, ep, "/");
+ }
+}
+
+void
addhist(int32 line, int type)
{
Auto *u;
@@ -800,7 +837,9 @@ ldobj(Biobuf *f, int64 len, char *pn)
int ntext, n, c1, c2, c3;
vlong eof;
vlong import0, import1;
+ char src[1024];
+ src[0] = '\0';
eof = Boffset(f) + len;
ntext = 0;
@@ -938,10 +977,12 @@ loop:
switch(p->as) {
case AHISTORY:
if(p->to.offset == -1) {
- addlib(pn);
+ addlib(src, pn);
histfrogp = 0;
goto loop;
}
+ if(src[0] == '\0')
+ copyhistfrog(src, sizeof src);
addhist(p->line, D_FILE); /* 'z' */
if(p->to.offset)
addhist(p->to.offset, D_FILE1); /* 'Z' */