1
0
mirror of https://github.com/golang/go synced 2024-11-25 18:17:56 -07:00

cmd/ld: correct assignment of sizes to mach-o symbols

If you compute the size by subtraction from the address
of the next symbol, it helps to wait until the symbols have
been sorted by address.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/11143043
This commit is contained in:
Russ Cox 2013-07-10 22:06:52 -04:00
parent e430eb8bd7
commit a2c30fe648

View File

@ -432,7 +432,7 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
int64 base;
MachoSect *sect;
MachoRel *rel;
Sym *s, *outer;
Sym *s, *s1, *outer;
MachoCmd *c;
MachoSymtab *symtab;
MachoDysymtab *dsymtab;
@ -635,10 +635,6 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
outer->sub = s;
s->outer = outer;
s->value = sym->value - sect->addr;
if(i+1 < symtab->nsym)
s->size = (sym+1)->value - sym->value;
else
s->size = sect->addr + sect->size - sym->value;
if(!(s->cgoexport & CgoExportDynamic))
s->dynimplib = nil; // satisfy dynimport
if(outer->type == STEXT) {
@ -668,17 +664,26 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
sect = &c->seg.sect[i];
if((s = sect->sym) == S)
continue;
if(s->sub)
if(s->sub) {
s->sub = listsort(s->sub, valuecmp, offsetof(Sym, sub));
// assign sizes, now that we know symbols in sorted order.
for(s1 = s->sub; s1 != S; s1 = s1->sub) {
if(s1->sub)
s1->size = s1->sub->value - s1->value;
else
s1->size = s->value + s->size - s1->value;
}
}
if(s->type == STEXT) {
if(etextp)
etextp->next = s;
else
textp = s;
etextp = s;
for(s = s->sub; s != S; s = s->sub) {
etextp->next = s;
etextp = s;
for(s1 = s->sub; s1 != S; s1 = s1->sub) {
etextp->next = s1;
etextp = s1;
}
}
}