Commit bf43161c authored by Ian Lance Taylor's avatar Ian Lance Taylor

ld: align ELF data sections

fixes #2506

R=rsc, iant
CC=golang-dev
https://golang.org/cl/5440066
parent 97197a62
......@@ -143,6 +143,7 @@ struct Sym
int32 value;
int32 sig;
int32 size;
int32 align; // if non-zero, required alignment in bytes
uchar special;
uchar fnptr; // used as fn ptr
Sym* hash; // in hash table
......
......@@ -133,6 +133,7 @@ struct Sym
int32 sig;
int32 plt;
int32 got;
int32 align; // if non-zero, required alignment in bytes
Sym* hash; // in hash table
Sym* allsym; // in all symbol list
Sym* next; // in text or data list
......
......@@ -134,6 +134,7 @@ struct Sym
int32 dynid;
int32 plt;
int32 got;
int32 align; // if non-zero, required alignment in bytes
Sym* hash; // in hash table
Sym* allsym; // in all symbol list
Sym* next; // in text or data list
......
......@@ -824,6 +824,8 @@ dodata(void)
datsize = 0;
s = datap;
for(; s != nil && s->type < SSYMTAB; s = s->next) {
if(s->align != 0)
datsize = rnd(datsize, s->align);
s->type = SRODATA;
s->value = datsize;
datsize += rnd(s->size, PtrSize);
......@@ -855,6 +857,8 @@ dodata(void)
/* read-only ELF sections */
for(; s != nil && s->type < SELFSECT; s = s->next) {
sect = addsection(&segtext, s->name, 04);
if(s->align != 0)
datsize = rnd(datsize, s->align);
sect->vaddr = datsize;
s->type = SRODATA;
s->value = datsize;
......@@ -866,6 +870,8 @@ dodata(void)
datsize = 0;
for(; s != nil && s->type < SDATA; s = s->next) {
sect = addsection(&segdata, s->name, 06);
if(s->align != 0)
datsize = rnd(datsize, s->align);
sect->vaddr = datsize;
s->type = SDATA;
s->value = datsize;
......@@ -887,7 +893,9 @@ dodata(void)
t = rnd(t, PtrSize);
else if(t > 2)
t = rnd(t, 4);
if(t & 1) {
if(s->align != 0)
datsize = rnd(datsize, s->align);
else if(t & 1) {
;
} else if(t & 2)
datsize = rnd(datsize, 2);
......@@ -913,7 +921,9 @@ dodata(void)
t = rnd(t, PtrSize);
else if(t > 2)
t = rnd(t, 4);
if(t & 1) {
if(s->align != 0)
datsize = rnd(datsize, s->align);
else if(t & 1) {
;
} else if(t & 2)
datsize = rnd(datsize, 2);
......@@ -947,6 +957,8 @@ textaddress(void)
for(sym = textp; sym != nil; sym = sym->next) {
if(sym->type & SSUB)
continue;
if(sym->align != 0)
va = rnd(va, sym->align);
sym->value = 0;
for(sub = sym; sub != S; sub = sub->sub) {
sub->value += va;
......
......@@ -538,6 +538,7 @@ ldelf(Biobuf *f, char *pkg, int64 len, char *pn)
s->np = sect->size;
}
s->size = sect->size;
s->align = sect->align;
if(s->type == STEXT) {
if(etextp)
etextp->next = s;
......
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