aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld/data.c
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2011-06-28 22:28:30 +0100
committerGustavo Niemeyer <gustavo@niemeyer.net>2011-06-28 22:28:30 +0100
commitcf143e9dbf6e3c5b0b2a97c76980b6d5bd5cc40f (patch)
treea8472d59b38c48c0601d1617fbe97227c1234b91 /src/cmd/ld/data.c
parentd0ac84fe404d345e25571ab0ee7596fc358d8b84 (diff)
downloadgo-cf143e9dbf6e3c5b0b2a97c76980b6d5bd5cc40f.tar.xz
ld: fix ELF strip by removing overlap of sections
The gosymtab and gopclntab sections were pointing to the proper data, but that data was already owned by the rodata section. Some ELF references explicitly prohibit multiple sections from owning the same data, and strip behaves accordingly. The data for these sections was moved to after rodata, and the gosymtab and gopclntab sections now own their respective ranges. This change makes strip happy both with and without -s being provided at link time. Note that it won't remove these sections because they are still allocated, and that's by design since they are necessary at runtime for generating proper backtraces and similar introspection operations. Unlike the previous behavior, -s will now maintain zero-sized gosymtab and gopclntab sections. This makes the implementation slightly cleaner. Fixes #1242. NOTE: Tested on Linux amd64/386/arm only. R=ality, rsc CC=golang-dev https://golang.org/cl/4639077
Diffstat (limited to 'src/cmd/ld/data.c')
-rw-r--r--src/cmd/ld/data.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/cmd/ld/data.c b/src/cmd/ld/data.c
index bdad58ff9a..f1132fc8bb 100644
--- a/src/cmd/ld/data.c
+++ b/src/cmd/ld/data.c
@@ -789,14 +789,34 @@ dodata(void)
sect->vaddr = 0;
datsize = 0;
s = datap;
- for(; s != nil && s->type < SDATA; s = s->next) {
+ for(; s != nil && s->type < SSYMTAB; s = s->next) {
s->type = SRODATA;
t = rnd(s->size, PtrSize);
s->value = datsize;
datsize += t;
}
sect->len = datsize - sect->vaddr;
-
+
+ /* gosymtab */
+ sect = addsection(&segtext, ".gosymtab", 04);
+ sect->vaddr = datsize;
+ for(; s != nil && s->type < SPCLNTAB; s = s->next) {
+ s->type = SRODATA;
+ s->value = datsize;
+ datsize += s->size;
+ }
+ sect->len = datsize - sect->vaddr;
+
+ /* gopclntab */
+ sect = addsection(&segtext, ".gopclntab", 04);
+ sect->vaddr = datsize;
+ for(; s != nil && s->type < SDATA; s = s->next) {
+ s->type = SRODATA;
+ s->value = datsize;
+ datsize += s->size;
+ }
+ sect->len = datsize - sect->vaddr;
+
/* data */
datsize = 0;
sect = addsection(&segdata, ".data", 06);
@@ -890,7 +910,7 @@ textaddress(void)
void
address(void)
{
- Section *s, *text, *data, *rodata;
+ Section *s, *text, *data, *rodata, *symtab, *pclntab;
Sym *sym, *sub;
uvlong va;
@@ -921,7 +941,9 @@ address(void)
segdata.filelen = segdata.sect->len; // assume .data is first
text = segtext.sect;
- rodata = segtext.sect->next;
+ rodata = text->next;
+ symtab = rodata->next;
+ pclntab = symtab->next;
data = segdata.sect;
for(sym = datap; sym != nil; sym = sym->next) {
@@ -938,12 +960,11 @@ address(void)
xdefine("etext", STEXT, text->vaddr + text->len);
xdefine("rodata", SRODATA, rodata->vaddr);
xdefine("erodata", SRODATA, rodata->vaddr + rodata->len);
+ xdefine("symtab", SRODATA, symtab->vaddr);
+ xdefine("esymtab", SRODATA, symtab->vaddr + symtab->len);
+ xdefine("pclntab", SRODATA, pclntab->vaddr);
+ xdefine("epclntab", SRODATA, pclntab->vaddr + pclntab->len);
xdefine("data", SBSS, data->vaddr);
xdefine("edata", SBSS, data->vaddr + data->len);
xdefine("end", SBSS, segdata.vaddr + segdata.len);
-
- sym = lookup("pclntab", 0);
- xdefine("epclntab", SRODATA, sym->value + sym->size);
- sym = lookup("symtab", 0);
- xdefine("esymtab", SRODATA, sym->value + sym->size);
}