?l: remove direct hunk manipulation from linkers, just call malloc()
as with recent changes, cc's malloc() could make the hunk pointer misaligned. in the the compilers, the hunk pointer is used directly by the lexer with no effort to to keep the hunk pointer aligned. alloc/malloc still return aligned pointers, but hunk itself can be on a odd address after allocation of a odd sized amount of bytes. however, in the linkers, this assumption appears to be differnet. as most allocations mostly allocate padded structures. however, symbol lookup allocates strings on byte-size ganularity and the cc's malloc would misalign the hunk pointer after the malloc() call. while the rest of the code assumed hunk pointer was always aligned. this change removes all the hunk pointer fiddling from the linker, and we just call malloc() (which will use the fast implmenentation of cc, and should not really make much of a performance difference).
This commit is contained in:
parent
73f38fc546
commit
ecdf3f921e
10 changed files with 40 additions and 259 deletions
|
@ -498,12 +498,7 @@ dosym:
|
|||
}
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Auto))
|
||||
gethunk();
|
||||
u = (Auto*)hunk;
|
||||
nhunk -= sizeof(Auto);
|
||||
hunk += sizeof(Auto);
|
||||
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -760,12 +755,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
|
||||
p->back = 2;
|
||||
|
@ -1025,12 +1015,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l + 1);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1046,14 +1031,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = (Prog*)malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -513,12 +513,7 @@ dosym:
|
|||
}
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Auto))
|
||||
gethunk();
|
||||
u = (Auto*)hunk;
|
||||
nhunk -= sizeof(Auto);
|
||||
hunk += sizeof(Auto);
|
||||
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -775,12 +770,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
|
||||
p->back = 2;
|
||||
|
@ -1049,12 +1039,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l + 1);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1070,14 +1055,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -484,23 +484,13 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
break;
|
||||
|
||||
case D_SCONST:
|
||||
while(nhunk < NSNAME)
|
||||
gethunk();
|
||||
a->sval = (char*)hunk;
|
||||
nhunk -= NSNAME;
|
||||
hunk += NSNAME;
|
||||
|
||||
a->sval = malloc(NSNAME);
|
||||
memmove(a->sval, p+4, NSNAME);
|
||||
c += NSNAME;
|
||||
break;
|
||||
|
||||
case D_FCONST:
|
||||
while(nhunk < sizeof(Ieee))
|
||||
gethunk();
|
||||
a->ieee = (Ieee*)hunk;
|
||||
nhunk -= NSNAME;
|
||||
hunk += NSNAME;
|
||||
|
||||
a->ieee = malloc(sizeof(Ieee));
|
||||
a->ieee->l = p[4] | (p[5]<<8) |
|
||||
(p[6]<<16) | (p[7]<<24);
|
||||
a->ieee->h = p[8] | (p[9]<<8) |
|
||||
|
@ -524,12 +514,7 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
return c;
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Auto))
|
||||
gethunk();
|
||||
u = (Auto*)hunk;
|
||||
nhunk -= sizeof(Auto);
|
||||
hunk += sizeof(Auto);
|
||||
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -814,12 +799,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
if(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->scond = bloc[1];
|
||||
p->reg = bloc[2];
|
||||
|
@ -1101,12 +1081,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1123,14 +1098,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -560,12 +560,7 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
}
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Auto))
|
||||
gethunk();
|
||||
u = (Auto*)hunk;
|
||||
nhunk -= sizeof(Auto);
|
||||
hunk += sizeof(Auto);
|
||||
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -856,12 +851,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
|
||||
p->back = 2;
|
||||
|
@ -1147,12 +1137,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l + 1);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1170,14 +1155,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -373,7 +373,6 @@ void errorexit(void);
|
|||
void export(void);
|
||||
void follow(void);
|
||||
void histtoauto(void);
|
||||
void* halloc(usize);
|
||||
int isnop(Prog*);
|
||||
double ieeedtod(Ieee*);
|
||||
long ieeedtof(Ieee*);
|
||||
|
|
|
@ -460,13 +460,13 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
break;
|
||||
|
||||
case D_SCONST:
|
||||
a->sval = halloc(NSNAME);
|
||||
a->sval = malloc(NSNAME);
|
||||
memmove(a->sval, p+4, NSNAME);
|
||||
c += NSNAME;
|
||||
break;
|
||||
|
||||
case D_FCONST:
|
||||
a->ieee = halloc(sizeof(Ieee));
|
||||
a->ieee = malloc(sizeof(Ieee));
|
||||
a->ieee->l = p[4] | (p[5]<<8) |
|
||||
(p[6]<<16) | (p[7]<<24);
|
||||
a->ieee->h = p[8] | (p[9]<<8) |
|
||||
|
@ -490,7 +490,7 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
return c;
|
||||
}
|
||||
|
||||
u = halloc(sizeof(Auto));
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -785,7 +785,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
p = halloc(sizeof(Prog));
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->reg = bloc[2] & 0x3F;
|
||||
if(bloc[2] & 0x80)
|
||||
|
@ -1113,12 +1113,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1135,32 +1130,11 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = malloc(sizeof(Sym));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
||||
void*
|
||||
halloc(usize n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
n = (n+7)&~7;
|
||||
while(nhunk < n)
|
||||
gethunk();
|
||||
p = hunk;
|
||||
nhunk -= n;
|
||||
hunk += n;
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
doprof1(void)
|
||||
{
|
||||
|
|
|
@ -548,12 +548,7 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
}
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Auto))
|
||||
gethunk();
|
||||
u = (Auto*)hunk;
|
||||
nhunk -= sizeof(Auto);
|
||||
hunk += sizeof(Auto);
|
||||
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -843,12 +838,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
|
||||
p->back = 2;
|
||||
|
@ -1122,12 +1112,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l + 1);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1145,14 +1130,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -683,12 +683,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
if(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->reg = bloc[1] & 0x7f;
|
||||
if(bloc[1] & 0x80)
|
||||
|
@ -940,12 +935,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l + 1);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -961,17 +951,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
int n;
|
||||
|
||||
n = (sizeof(Prog) + 3) & ~3;
|
||||
while(nhunk < n)
|
||||
gethunk();
|
||||
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= n;
|
||||
hunk += n;
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -791,12 +791,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
if(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->reg = bloc[2] & 0x3f;
|
||||
if(bloc[2] & 0x80)
|
||||
|
@ -1073,12 +1068,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l + 1);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1095,17 +1085,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
int n;
|
||||
|
||||
n = (sizeof(Prog) + 3) & ~3;
|
||||
while(nhunk < n)
|
||||
gethunk();
|
||||
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= n;
|
||||
hunk += n;
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -439,23 +439,13 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
break;
|
||||
|
||||
case D_SCONST:
|
||||
while(nhunk < NSNAME)
|
||||
gethunk();
|
||||
a->sval = (char*)hunk;
|
||||
nhunk -= NSNAME;
|
||||
hunk += NSNAME;
|
||||
|
||||
a->sval = malloc(NSNAME);
|
||||
memmove(a->sval, p+4, NSNAME);
|
||||
c += NSNAME;
|
||||
break;
|
||||
|
||||
case D_FCONST:
|
||||
while(nhunk < sizeof(Ieee))
|
||||
gethunk();
|
||||
a->ieee = (Ieee*)hunk;
|
||||
nhunk -= NSNAME;
|
||||
hunk += NSNAME;
|
||||
|
||||
a->ieee = malloc(sizeof(Ieee));
|
||||
a->ieee->l = p[4] | (p[5]<<8) |
|
||||
(p[6]<<16) | (p[7]<<24);
|
||||
a->ieee->h = p[8] | (p[9]<<8) |
|
||||
|
@ -479,12 +469,7 @@ zaddr(uchar *p, Adr *a, Sym *h[])
|
|||
return c;
|
||||
}
|
||||
|
||||
while(nhunk < sizeof(Auto))
|
||||
gethunk();
|
||||
u = (Auto*)hunk;
|
||||
nhunk -= sizeof(Auto);
|
||||
hunk += sizeof(Auto);
|
||||
|
||||
u = malloc(sizeof(Auto));
|
||||
u->link = curauto;
|
||||
curauto = u;
|
||||
u->asym = s;
|
||||
|
@ -748,12 +733,7 @@ loop:
|
|||
goto loop;
|
||||
}
|
||||
|
||||
if(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
p = malloc(sizeof(Prog));
|
||||
p->as = o;
|
||||
p->reg = bloc[1] & 0x7f;
|
||||
if(bloc[1] & 0x80)
|
||||
|
@ -1025,12 +1005,7 @@ lookup(char *symb, int v)
|
|||
if(memcmp(s->name, symb, l) == 0)
|
||||
return s;
|
||||
|
||||
while(nhunk < sizeof(Sym))
|
||||
gethunk();
|
||||
s = (Sym*)hunk;
|
||||
nhunk -= sizeof(Sym);
|
||||
hunk += sizeof(Sym);
|
||||
|
||||
s = malloc(sizeof(Sym));
|
||||
s->name = malloc(l);
|
||||
memmove(s->name, symb, l);
|
||||
|
||||
|
@ -1046,14 +1021,7 @@ lookup(char *symb, int v)
|
|||
Prog*
|
||||
prg(void)
|
||||
{
|
||||
Prog *p;
|
||||
|
||||
while(nhunk < sizeof(Prog))
|
||||
gethunk();
|
||||
p = (Prog*)hunk;
|
||||
nhunk -= sizeof(Prog);
|
||||
hunk += sizeof(Prog);
|
||||
|
||||
Prog *p = malloc(sizeof(Prog));
|
||||
*p = zprg;
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue