summaryrefslogtreecommitdiff
path: root/sys/src/cmd/7l
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-05-12 22:04:30 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2020-05-12 22:04:30 +0200
commitecdf3f921e2a2ec768807bb09e0e7da995612565 (patch)
tree0b9b0a2b009a4d60d3e80b6a04e267e1819cbd6f /sys/src/cmd/7l
parent73f38fc5460cb68662dd237022bda636ad734045 (diff)
?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).
Diffstat (limited to 'sys/src/cmd/7l')
-rw-r--r--sys/src/cmd/7l/l.h1
-rw-r--r--sys/src/cmd/7l/obj.c38
2 files changed, 6 insertions, 33 deletions
diff --git a/sys/src/cmd/7l/l.h b/sys/src/cmd/7l/l.h
index c72202b8a..55ff29b8d 100644
--- a/sys/src/cmd/7l/l.h
+++ b/sys/src/cmd/7l/l.h
@@ -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*);
diff --git a/sys/src/cmd/7l/obj.c b/sys/src/cmd/7l/obj.c
index 985d2e0c2..35dfc5766 100644
--- a/sys/src/cmd/7l/obj.c
+++ b/sys/src/cmd/7l/obj.c
@@ -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)
{