From b0e1d423dd3e174a92a1d7256aec4e9b701ece3c Mon Sep 17 00:00:00 2001 From: Charles Crayne Date: Sun, 21 Oct 2007 14:21:43 -0700 Subject: Clean up elf symbol table section --- output/outelf32.c | 24 ++++++++++++------------ output/outelf64.c | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/output/outelf32.c b/output/outelf32.c index ffd59dbf..9c8d0284 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -46,7 +46,7 @@ enum reloc_type { struct Reloc { struct Reloc *next; int32_t address; /* relative to _start_ of section */ - int32_t symbol; /* ELF symbol info thingy */ + int32_t symbol; /* symbol index */ int type; /* type of relocation */ }; @@ -663,13 +663,13 @@ static void elf_add_reloc(struct Section *sect, int32_t segment, int type) r->address = sect->len; if (segment == NO_SEG) - r->symbol = 2; + r->symbol = 0; else { int i; r->symbol = 0; for (i = 0; i < nsects; i++) if (segment == sects[i]->index) - r->symbol = i + 3; + r->symbol = i + 2; if (!r->symbol) r->symbol = GLOBAL_TEMP_BASE + raa_read(bsym, segment); } @@ -1114,7 +1114,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * Next, an entry for the file name. */ p = entry; - WRITELONG(p, 1); /* we know it's 1st thing in strtab */ + WRITELONG(p, 1); /* we know it's 1st entry in strtab */ WRITELONG(p, 0); /* no value */ WRITELONG(p, 0); /* no size either */ WRITESHORT(p, 4); /* type FILE */ @@ -1127,13 +1127,13 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * Now some standard symbols defining the segments, for relocation * purposes. */ - for (i = 1; i <= nsects + 1; i++) { + for (i = 1; i <= nsects; i++) { p = entry; WRITELONG(p, 0); /* no symbol name */ WRITELONG(p, 0); /* offset zero */ WRITELONG(p, 0); /* size zero */ - WRITESHORT(p, 3); /* local section-type thing */ - WRITESHORT(p, (i == 1 ? SHN_ABS : i - 1)); /* the section id */ + WRITESHORT(p, 3); /* type, binding, and visibility */ + WRITESHORT(p, i); /* section id */ saa_wbytes(s, entry, 16L); *len += 16; (*local)++; @@ -1150,8 +1150,8 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) WRITELONG(p, sym->strpos); WRITELONG(p, sym->value); WRITELONG(p, sym->size); - WRITECHAR(p, sym->type); /* local non-typed thing */ - WRITECHAR(p, sym->other); + WRITECHAR(p, sym->type); /* type and binding */ + WRITECHAR(p, sym->other); /* visibility */ WRITESHORT(p, sym->section); saa_wbytes(s, entry, 16L); *len += 16; @@ -1169,8 +1169,8 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) WRITELONG(p, sym->strpos); WRITELONG(p, sym->value); WRITELONG(p, sym->size); - WRITECHAR(p, sym->type); /* global non-typed thing */ - WRITECHAR(p, sym->other); + WRITECHAR(p, sym->type); /* type and binding */ + WRITECHAR(p, sym->other); /* visibility */ WRITESHORT(p, sym->section); saa_wbytes(s, entry, 16L); *len += 16; @@ -1194,7 +1194,7 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r) int32_t sym = r->symbol; if (sym >= GLOBAL_TEMP_BASE) - sym += -GLOBAL_TEMP_BASE + (nsects + 3) + nlocals; + sym += -GLOBAL_TEMP_BASE + (nsects + 2) + nlocals; p = entry; WRITELONG(p, r->address); diff --git a/output/outelf64.c b/output/outelf64.c index 6ee56343..39da33ff 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -67,7 +67,7 @@ typedef struct struct Reloc { struct Reloc *next; int64_t address; /* relative to _start_ of section */ - int64_t symbol; /* ELF symbol info thingy */ + int64_t symbol; /* symbol index */ int type; /* type of relocation */ }; @@ -676,13 +676,13 @@ static void elf_add_reloc(struct Section *sect, int32_t segment, int type) r->address = sect->len; if (segment == NO_SEG) - r->symbol = 2; + r->symbol = 0; else { int i; r->symbol = 0; for (i = 0; i < nsects; i++) if (segment == sects[i]->index) - r->symbol = i + 3; + r->symbol = i + 2; if (!r->symbol) r->symbol = GLOBAL_TEMP_BASE + raa_read(bsym, segment); } @@ -1145,7 +1145,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * Next, an entry for the file name. */ p = entry; - WRITELONG(p, 1); /* we know it's 1st thing in strtab */ + WRITELONG(p, 1); /* we know it's 1st entry in strtab */ WRITESHORT(p, 4); /* type FILE */ WRITESHORT(p, SHN_ABS); WRITEDLONG(p, (uint64_t) 0); /* no value */ @@ -1158,11 +1158,11 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) * Now some standard symbols defining the segments, for relocation * purposes. */ - for (i = 1; i <= nsects + 1; i++) { + for (i = 1; i <= nsects; i++) { p = entry; WRITELONG(p, 0); /* no symbol name */ - WRITESHORT(p, 3); /* local section-type thing */ - WRITESHORT(p, (i == 1 ? SHN_ABS : i - 1)); /* the section id */ + WRITESHORT(p, 3); /* type, binding, and visibility */ + WRITESHORT(p, i); /* section id */ WRITEDLONG(p, (uint64_t) 0); /* offset zero */ WRITEDLONG(p, (uint64_t) 0); /* size zero */ saa_wbytes(s, entry, 24L); @@ -1179,8 +1179,8 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) continue; p = entry; WRITELONG(p, sym->strpos); - WRITECHAR(p, sym->type); /* local non-typed thing */ - WRITECHAR(p, sym->other); + WRITECHAR(p, sym->type); /* type and binding */ + WRITECHAR(p, sym->other); /* visibility */ WRITESHORT(p, sym->section); WRITEDLONG(p, (int64_t)sym->value); WRITEDLONG(p, (int64_t)sym->size); @@ -1198,8 +1198,8 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) continue; p = entry; WRITELONG(p, sym->strpos); - WRITECHAR(p, sym->type); /* global non-typed thing */ - WRITECHAR(p, sym->other); + WRITECHAR(p, sym->type); /* type and binding */ + WRITECHAR(p, sym->other); /* visibility */ WRITESHORT(p, sym->section); WRITEDLONG(p, (int64_t)sym->value); WRITEDLONG(p, (int64_t)sym->size); @@ -1225,7 +1225,7 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r) int64_t sym = r->symbol; if (sym >= GLOBAL_TEMP_BASE) - sym += -GLOBAL_TEMP_BASE + (nsects + 3) + nlocals; + sym += -GLOBAL_TEMP_BASE + (nsects + 2) + nlocals; p = entry; WRITEDLONG(p, r->address); -- cgit v1.2.1