Commit a2c30fe6 authored by Russ Cox's avatar Russ Cox

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