Commit c5f21c0d authored by Russ Cox's avatar Russ Cox

* 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
parent 9795c9e7
...@@ -542,6 +542,10 @@ objfile(char *file) ...@@ -542,6 +542,10 @@ objfile(char *file)
goto bad; goto bad;
if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag))) if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
goto bad; goto bad;
l = SARNAME;
while(l > 0 && arhdr.name[l-1] == ' ')
l--;
sprint(pname, "%s(%.*s)", file, l, arhdr.name);
l = atolwhex(arhdr.size); l = atolwhex(arhdr.size);
ldobj(f, l, pname); ldobj(f, l, pname);
if(s->type == SXREF) { if(s->type == SXREF) {
...@@ -635,9 +639,9 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -635,9 +639,9 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
} }
void void
addlib(char *obj) addlib(char *src, char *obj)
{ {
char name[1024], comp[256], *p; char name[1024], comp[256], *p, *q;
int i; int i;
if(histfrogp <= 0) if(histfrogp <= 0)
...@@ -685,6 +689,23 @@ addlib(char *obj) ...@@ -685,6 +689,23 @@ addlib(char *obj)
strcat(name, "/"); strcat(name, "/");
strcat(name, comp); 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++) for(i=0; i<libraryp; i++)
if(strcmp(name, library[i]) == 0) if(strcmp(name, library[i]) == 0)
return; return;
...@@ -702,6 +723,22 @@ addlib(char *obj) ...@@ -702,6 +723,22 @@ addlib(char *obj)
libraryp++; libraryp++;
} }
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 void
addhist(int32 line, int type) addhist(int32 line, int type)
{ {
...@@ -800,7 +837,9 @@ ldobj(Biobuf *f, int64 len, char *pn) ...@@ -800,7 +837,9 @@ ldobj(Biobuf *f, int64 len, char *pn)
int ntext, n, c1, c2, c3; int ntext, n, c1, c2, c3;
vlong eof; vlong eof;
vlong import0, import1; vlong import0, import1;
char src[1024];
src[0] = '\0';
eof = Boffset(f) + len; eof = Boffset(f) + len;
ntext = 0; ntext = 0;
...@@ -938,10 +977,12 @@ loop: ...@@ -938,10 +977,12 @@ loop:
switch(p->as) { switch(p->as) {
case AHISTORY: case AHISTORY:
if(p->to.offset == -1) { if(p->to.offset == -1) {
addlib(pn); addlib(src, pn);
histfrogp = 0; histfrogp = 0;
goto loop; goto loop;
} }
if(src[0] == '\0')
copyhistfrog(src, sizeof src);
addhist(p->line, D_FILE); /* 'z' */ addhist(p->line, D_FILE); /* 'z' */
if(p->to.offset) if(p->to.offset)
addhist(p->to.offset, D_FILE1); /* 'Z' */ addhist(p->to.offset, D_FILE1); /* 'Z' */
......
...@@ -1671,6 +1671,12 @@ getpkgdef(char **datap, int *lenp) ...@@ -1671,6 +1671,12 @@ getpkgdef(char **datap, int *lenp)
char *data, *p; char *data, *p;
Import **all, *x; Import **all, *x;
if(pkgstmt == nil) {
*datap = nil;
*lenp = 0;
return;
}
// make a list of all the exports and count string sizes // make a list of all the exports and count string sizes
all = armalloc(nimport*sizeof all[0]); all = armalloc(nimport*sizeof all[0]);
j = 0; j = 0;
......
...@@ -52,6 +52,8 @@ run(char **argv, int showoutput) ...@@ -52,6 +52,8 @@ run(char **argv, int showoutput)
if(!showoutput){ if(!showoutput){
dup(devnull, 1); dup(devnull, 1);
dup(devnull, 2); dup(devnull, 2);
}else{
dup(2, 1);
} }
if(devnull > 2) if(devnull > 2)
close(devnull); close(devnull);
...@@ -173,15 +175,17 @@ char preamble[] = ...@@ -173,15 +175,17 @@ char preamble[] =
"AS=$(O)a\n" "AS=$(O)a\n"
"AR=$(O)ar\n" "AR=$(O)ar\n"
"\n" "\n"
"PKG=$(GOROOT)/pkg/%s.a\n" "PKG=%s.a\n"
"PKGDIR=$(GOROOT)/pkg%s\n"
"\n" "\n"
"install: $(PKG)\n" "install: $(PKG)\n"
"\tmv $(PKG) $(PKGDIR)/$(PKG)\n"
"\n" "\n"
"nuke: clean\n" "nuke: clean\n"
"\trm -f $(PKG)\n" "\trm -f $(PKGDIR)/$(PKG)\n"
"\n" "\n"
"clean:\n" "clean:\n"
"\trm -f *.$O *.a\n" "\trm -f *.$O *.a $(PKG)\n"
"\n" "\n"
"%%.$O: %%.go\n" "%%.$O: %%.go\n"
"\t$(GC) $*.go\n" "\t$(GC) $*.go\n"
...@@ -198,7 +202,7 @@ void ...@@ -198,7 +202,7 @@ void
main(int argc, char **argv) main(int argc, char **argv)
{ {
int i, o, p, n, pass, nar, njob, nthis, nnext, oargc; int i, o, p, n, pass, nar, njob, nthis, nnext, oargc;
char **ar, **next, **this, **tmp, *goroot, *pkgname, *pkgpath, **oargv; char **ar, **next, **this, **tmp, *goroot, *pkgname, *pkgpath, *pkgdir, **oargv, *q;
Job *job; Job *job;
Biobuf bout; Biobuf bout;
...@@ -241,7 +245,17 @@ main(int argc, char **argv) ...@@ -241,7 +245,17 @@ main(int argc, char **argv)
usage(); usage();
} }
pkgpath = smprint("%s/pkg/%s.a", goroot, pkgname); q = strrchr(pkgname, '/');
if(q) {
pkgdir = pkgname;
*q++ = '\0';
pkgname = q;
pkgdir = smprint("/%s", pkgdir);
} else {
pkgdir = "";
}
pkgpath = smprint("%s.a", pkgname);
unlink(pkgpath); unlink(pkgpath);
if(chatty) if(chatty)
fprint(2, "pkg %s\n", pkgpath); fprint(2, "pkg %s\n", pkgpath);
...@@ -275,6 +289,9 @@ main(int argc, char **argv) ...@@ -275,6 +289,9 @@ main(int argc, char **argv)
ar[0] = smprint("%sar", thechar); ar[0] = smprint("%sar", thechar);
ar[1] = "grc"; ar[1] = "grc";
ar[2] = pkgpath; ar[2] = pkgpath;
ar[3] = nil;
if(run(ar, 1) < 0)
sysfatal("ar: %r");
njob = 0; njob = 0;
...@@ -333,7 +350,7 @@ main(int argc, char **argv) ...@@ -333,7 +350,7 @@ main(int argc, char **argv)
Bprint(&bout, " %s", oargv[i]); Bprint(&bout, " %s", oargv[i]);
} }
Bprint(&bout, "\n"); Bprint(&bout, "\n");
Bprint(&bout, preamble, thechar, pkgname); Bprint(&bout, preamble, thechar, pkgname, pkgdir);
// O2=\ // O2=\
// os_file.$O\ // os_file.$O\
......
...@@ -12,15 +12,17 @@ CC=$(O)c -w ...@@ -12,15 +12,17 @@ CC=$(O)c -w
AS=$(O)a AS=$(O)a
AR=$(O)ar AR=$(O)ar
PKG=$(GOROOT)/pkg/math.a PKG=math.a
PKGDIR=$(GOROOT)/pkg
install: $(PKG) install: $(PKG)
mv $(PKG) $(PKGDIR)/$(PKG)
nuke: clean nuke: clean
rm -f $(PKG) rm -f $(PKGDIR)/$(PKG)
clean: clean:
rm -f *.$O *.a rm -f *.$O *.a $(PKG)
%.$O: %.go %.$O: %.go
$(GC) $*.go $(GC) $*.go
...@@ -59,12 +61,16 @@ O4=\ ...@@ -59,12 +61,16 @@ O4=\
$(PKG): a1 a2 a3 a4 $(PKG): a1 a2 a3 a4
a1: $(O1) a1: $(O1)
$(AR) grc $(PKG) $(O1) $(AR) grc $(PKG) $(O1)
rm -f $(O1)
a2: $(O2) a2: $(O2)
$(AR) grc $(PKG) $(O2) $(AR) grc $(PKG) $(O2)
rm -f $(O2)
a3: $(O3) a3: $(O3)
$(AR) grc $(PKG) $(O3) $(AR) grc $(PKG) $(O3)
rm -f $(O3)
a4: $(O4) a4: $(O4)
$(AR) grc $(PKG) $(O4) $(AR) grc $(PKG) $(O4)
rm -f $(O4)
$(O1): nuke $(O1): nuke
$(O2): a1 $(O2): a1
......
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// $G $F.go && $L $F.$A && (./$A.out || echo BUG: math fails)
package main package main
import math "math" import (
"fmt";
"math";
)
const length = 10; const length = 10;
...@@ -57,7 +61,7 @@ ck(a,b float64) ...@@ -57,7 +61,7 @@ ck(a,b float64)
d = -d; d = -d;
} }
e := 1e-14; e := float64(1e-13);
if a != 0 { if a != 0 {
e = e*a; e = e*a;
if e < 0 { if e < 0 {
...@@ -66,7 +70,7 @@ ck(a,b float64) ...@@ -66,7 +70,7 @@ ck(a,b float64)
} }
if d > e { if d > e {
panic(a, " ", b, "\n"); panic(fmt.sprintf("%.17g %.17g", a, b));
} }
} }
......
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