summaryrefslogtreecommitdiff
path: root/src/cmd/8l/asm.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
commit2610a4f5aebb688e04276e118dcc6e627f82d067 (patch)
tree2905ad3f4e42163f59521163f2801930d5f13128 /src/cmd/8l/asm.c
parent71fad73fcac7d1cb62e3c6d09152896b2174a9f1 (diff)
downloadgo-2610a4f5aebb688e04276e118dcc6e627f82d067.tar.gz
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 issue 1242. NOTE: Tested on Linux amd64/386/arm only. R=ality, rsc CC=golang-dev http://codereview.appspot.com/4639077
Diffstat (limited to 'src/cmd/8l/asm.c')
-rw-r--r--src/cmd/8l/asm.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c
index a9a720af1..e1ccfb8a3 100644
--- a/src/cmd/8l/asm.c
+++ b/src/cmd/8l/asm.c
@@ -83,9 +83,6 @@ enum {
ElfStrText,
ElfStrData,
ElfStrBss,
- ElfStrGosymcounts,
- ElfStrGosymtab,
- ElfStrGopclntab,
ElfStrShstrtab,
ElfStrSymtab,
ElfStrStrtab,
@@ -531,10 +528,9 @@ doelf(void)
elfstr[ElfStrBss] = addstring(shstrtab, ".bss");
addstring(shstrtab, ".elfdata");
addstring(shstrtab, ".rodata");
+ addstring(shstrtab, ".gosymtab");
+ addstring(shstrtab, ".gopclntab");
if(!debug['s']) {
- elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts");
- elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab");
- elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab");
elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab");
elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab");
dwarfaddshstrings(shstrtab);
@@ -679,10 +675,11 @@ asmb(void)
seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
codeblk(sect->vaddr, sect->len);
- /* output read-only data in text segment */
- sect = segtext.sect->next;
- seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
- datblk(sect->vaddr, sect->len);
+ /* output read-only data in text segment (rodata, gosymtab and pclntab) */
+ for(sect = sect->next; sect != nil; sect = sect->next) {
+ seek(cout, sect->vaddr - segtext.vaddr + segtext.fileoff, 0);
+ datblk(sect->vaddr, sect->len);
+ }
if(debug['v'])
Bprint(&bso, "%5.2f datblk\n", cputime());
@@ -1083,18 +1080,6 @@ asmb(void)
elfshbits(sect);
if (!debug['s']) {
- sh = newElfShdr(elfstr[ElfStrGosymtab]);
- sh->type = SHT_PROGBITS;
- sh->flags = SHF_ALLOC;
- sh->addralign = 1;
- shsym(sh, lookup("symtab", 0));
-
- sh = newElfShdr(elfstr[ElfStrGopclntab]);
- sh->type = SHT_PROGBITS;
- sh->flags = SHF_ALLOC;
- sh->addralign = 1;
- shsym(sh, lookup("pclntab", 0));
-
sh = newElfShdr(elfstr[ElfStrSymtab]);
sh->type = SHT_SYMTAB;
sh->off = symo;