#include "../../pkg/runtime/mgc0.h"
void dynreloc(void);
-static vlong addaddrplus4(Sym *s, Sym *t, int32 add);
+static vlong addaddrplus4(Sym *s, Sym *t, vlong add);
/*
* divide-and-conquer list-link
cursym = s;
diag("bad reloc size %#ux for %s", siz, r->sym->name);
case 4:
+ if(o != (int32)o) {
+ cursym = S;
+ diag("relocation address is too big: %#llx", o);
+ }
fl = o;
cast = (uchar*)&fl;
for(i=0; i<4; i++)
}
vlong
-setuintxx(Sym *s, vlong off, uint64 v, int wid)
+setuintxx(Sym *s, vlong off, uint64 v, vlong wid)
{
int32 i, fl;
vlong o;
vlong
adduintxx(Sym *s, uint64 v, int wid)
{
- int32 off;
+ vlong off;
off = s->size;
setuintxx(s, off, v, wid);
}
vlong
-addaddrplus(Sym *s, Sym *t, int32 add)
+addaddrplus(Sym *s, Sym *t, vlong add)
{
vlong i;
Reloc *r;
}
static vlong
-addaddrplus4(Sym *s, Sym *t, int32 add)
+addaddrplus4(Sym *s, Sym *t, vlong add)
{
vlong i;
Reloc *r;
}
vlong
-addpcrelplus(Sym *s, Sym *t, int32 add)
+addpcrelplus(Sym *s, Sym *t, vlong add)
{
vlong i;
Reloc *r;
}
vlong
-setaddrplus(Sym *s, vlong off, Sym *t, int32 add)
+setaddrplus(Sym *s, vlong off, Sym *t, vlong add)
{
Reloc *r;
return align;
}
-static int32
-aligndatsize(int32 datsize, Sym *s)
+static vlong
+aligndatsize(vlong datsize, Sym *s)
{
return rnd(datsize, symalign(s));
}
}
static void
-gcaddsym(Sym *gc, Sym *s, int32 off)
+gcaddsym(Sym *gc, Sym *s, vlong off)
{
- int32 a;
+ vlong a;
Sym *gotype;
if(s->size < PtrSize)
}
}
+void
+growdatsize(vlong *datsizep, Sym *s)
+{
+ vlong datsize;
+
+ datsize = *datsizep;
+ if(s->size < 0)
+ diag("negative size (datsize = %lld, s->size = %lld)", datsize, s->size);
+ if(datsize + s->size < datsize)
+ diag("symbol too large (datsize = %lld, s->size = %lld)", datsize, s->size);
+ *datsizep = datsize + s->size;
+}
+
void
dodata(void)
{
- int32 n, datsize;
+ int32 n;
+ vlong datsize;
Section *sect;
Sym *s, *last, **l;
Sym *gcdata1, *gcbss1;
s->sect = sect;
s->type = SDATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
sect->len = datsize - sect->vaddr;
}
s->sect = sect;
s->type = SDATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
s->sect = sect;
s->type = SDATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
}
datsize = aligndatsize(datsize, s);
s->value = datsize;
gcaddsym(gcdata1, s, datsize - sect->vaddr); // gc
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
datsize = aligndatsize(datsize, s);
s->value = datsize;
gcaddsym(gcbss1, s, datsize - sect->vaddr); // gc
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
datsize = aligndatsize(datsize, s);
s->sect = sect;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
lookup("end", 0)->sect = sect;
+
+ // 6g uses 4-byte relocation offsets, so the entire segment must fit in 32 bits.
+ if(datsize != (uint32)datsize) {
+ diag("data or bss segment too large");
+ }
if(iself && linkmode == LinkExternal && s != nil && s->type == STLSBSS && HEADTYPE != Hopenbsd) {
sect = addsection(&segdata, ".tbss", 06);
datsize = aligndatsize(datsize, s);
s->sect = sect;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize;
}
s->sect = sect;
s->type = SRODATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
s->sect = sect;
s->type = SRODATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
s->sect = sect;
s->type = SRODATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
s->sect = sect;
s->type = SRODATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
}
sect->len = datsize - sect->vaddr;
s->sect = sect;
s->type = SRODATA;
s->value = datsize;
- datsize += s->size;
+ growdatsize(&datsize, s);
sect->len = datsize - sect->vaddr;
}
+
+ // 6g uses 4-byte relocation offsets, so the entire segment must fit in 32 bits.
+ if(datsize != (uint32)datsize) {
+ diag("text segment too large");
+ }
/* number the sections */
n = 1;
vlong adduint64(Sym*, uint64);
vlong adduintxx(Sym*, uint64, int);
vlong addaddr(Sym*, Sym*);
-vlong addaddrplus(Sym*, Sym*, int32);
-vlong addpcrelplus(Sym*, Sym*, int32);
+vlong addaddrplus(Sym*, Sym*, vlong);
+vlong addpcrelplus(Sym*, Sym*, vlong);
vlong addsize(Sym*, Sym*);
-vlong setaddrplus(Sym*, vlong, Sym*, int32);
+vlong setaddrplus(Sym*, vlong, Sym*, vlong);
vlong setaddr(Sym*, vlong, Sym*);
void setuint8(Sym*, vlong, uint8);
void setuint16(Sym*, vlong, uint16);