Commit bd43a2d9 authored by Russ Cox's avatar Russ Cox

ld: defend against some broken object files

Fixes #1698.
Fixes #1699.

R=ken2
CC=golang-dev
https://golang.org/cl/4419041
parent 36713a2a
......@@ -581,7 +581,7 @@ loop:
diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
errorexit();
}
savedata(s, p);
savedata(s, p, pn);
unmal(p, sizeof *p);
break;
......
......@@ -356,6 +356,15 @@ zaddr(char *pn, Biobuf *f, Adr *a, Sym *h[])
return;
}
}
switch(t) {
case D_FILE:
case D_FILE1:
case D_AUTO:
case D_PARAM:
if(s == S)
mangle(pn);
}
u = mal(sizeof(*u));
u->link = curauto;
......@@ -559,7 +568,7 @@ loop:
diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
errorexit();
}
savedata(s, p);
savedata(s, p, pn);
unmal(p, sizeof *p);
goto loop;
......
......@@ -600,7 +600,7 @@ loop:
diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
errorexit();
}
savedata(s, p);
savedata(s, p, pn);
unmal(p, sizeof *p);
goto loop;
......
......@@ -312,7 +312,7 @@ symgrow(Sym *s, int32 siz)
}
void
savedata(Sym *s, Prog *p)
savedata(Sym *s, Prog *p, char *pn)
{
int32 off, siz, i, fl;
uchar *cast;
......@@ -321,8 +321,10 @@ savedata(Sym *s, Prog *p)
off = p->from.offset;
siz = p->datasize;
if(off < 0 || siz < 0 || off >= 1<<30 || siz >= 100)
mangle(pn);
symgrow(s, off+siz);
switch(p->to.type) {
default:
diag("bad data: %P", p);
......
......@@ -438,7 +438,7 @@ ldobj(Biobuf *f, char *pkg, int64 len, char *pn, int whence)
return;
}
t = smprint("%s %s %s", getgoos(), thestring, getgoversion());
if(strcmp(line+10, t) != 0) {
if(strcmp(line+10, t) != 0 && !debug['f']) {
diag("%s: object is [%s] expected [%s]", pn, line+10, t);
free(t);
return;
......
......@@ -173,7 +173,7 @@ void datblk(int32, int32);
Sym* datsort(Sym*);
void reloc(void);
void relocsym(Sym*);
void savedata(Sym*, Prog*);
void savedata(Sym*, Prog*, char*);
void symgrow(Sym*, int32);
vlong addstring(Sym*, char*);
vlong adduint32(Sym*, uint32);
......
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