diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2014-09-15 01:43:22 +0400 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2014-09-21 13:05:03 +0400 |
commit | 8a076f426013415296a4fb5841d5932053de8ada (patch) | |
tree | 1e6c24606afc2100496b1e9b517b6c295f8ac631 | |
parent | c24568b0b0e5ca91e6326bbba5d02c90458fde86 (diff) | |
download | nasm-8a076f426013415296a4fb5841d5932053de8ada.tar.gz |
output: elf -- Use common elf_ structures
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r-- | output/outelf32.c | 86 | ||||
-rw-r--r-- | output/outelf64.c | 90 | ||||
-rw-r--r-- | output/outelfx32.c | 89 |
3 files changed, 77 insertions, 188 deletions
diff --git a/output/outelf32.c b/output/outelf32.c index 462e5bcb..af0547af 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -61,44 +61,8 @@ #ifdef OF_ELF32 -/* - * Relocation types. - */ -struct Reloc { - struct Reloc *next; - int32_t address; /* relative to _start_ of section */ - int32_t symbol; /* symbol index */ - int type; /* type of relocation */ -}; - -struct Symbol { - struct rbtree symv; /* symbol value and symbol rbtree */ - int32_t strpos; /* string table position of name */ - int32_t section; /* section ID of the symbol */ - int type; /* symbol type */ - int other; /* symbol visibility */ - int32_t size; /* size of symbol */ - int32_t globnum; /* symbol table offset if global */ - struct Symbol *nextfwd; /* list of unresolved-size symbols */ - char *name; /* used temporarily if in above list */ -}; - -struct Section { - struct SAA *data; - uint32_t len, size, nrelocs; - int32_t index; - int type; /* SHT_PROGBITS or SHT_NOBITS */ - uint32_t align; /* alignment: power of two */ - uint32_t flags; /* section flags */ - char *name; - struct SAA *rel; - int32_t rellen; - struct Reloc *head, **tail; - struct rbtree *gsyms; /* global symbols in section */ -}; - #define SECT_DELTA 32 -static struct Section **sects; +static struct elf_section **sects; static int nsects, sectlen; #define SHSTR_DELTA 256 @@ -115,7 +79,7 @@ static struct RAA *bsym; static struct SAA *strs; static uint32_t strslen; -static struct Symbol *fwds; +static struct elf_symbol *fwds; static char elf_module[FILENAME_MAX]; @@ -130,13 +94,13 @@ static int elf_nsect, nsections; static int32_t elf_foffs; static void elf_write(void); -static void elf_sect_write(struct Section *, const uint8_t *, +static void elf_sect_write(struct elf_section *, const uint8_t *, uint32_t); static void elf_section_header(int, int, int, void *, bool, int32_t, int, int, int, int); static void elf_write_sections(void); static struct SAA *elf_build_symtab(int32_t *, int32_t *); -static struct SAA *elf_build_reltab(int32_t *, struct Reloc *); +static struct SAA *elf_build_reltab(uint64_t *, struct elf_reloc *); static void add_sectname(char *, char *); struct erel { @@ -191,7 +155,7 @@ static int32_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; static struct dfmt df_dwarf; static struct dfmt df_stabs; -static struct Symbol *lastsym; +static struct elf_symbol *lastsym; /* common debugging routines */ static void debug32_typevalue(int32_t); @@ -226,7 +190,7 @@ static void elf_init(void) { sects = NULL; nsects = sectlen = 0; - syms = saa_init((int32_t)sizeof(struct Symbol)); + syms = saa_init((int32_t)sizeof(struct elf_symbol)); nlocals = nglobs = ndebugs = 0; bsym = raa_init(); strs = saa_init(1L); @@ -257,7 +221,7 @@ static void elf_init(void) static void elf_cleanup(int debuginfo) { - struct Reloc *r; + struct elf_reloc *r; int i; (void)debuginfo; @@ -295,7 +259,7 @@ static void add_sectname(char *firsthalf, char *secondhalf) static int elf_make_section(char *name, int type, int flags, int align) { - struct Section *s; + struct elf_section *s; s = nasm_zalloc(sizeof(*s)); @@ -383,7 +347,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { int pos = strslen; - struct Symbol *sym; + struct elf_symbol *sym; bool special_used = false; #if defined(DEBUG) && DEBUG>2 @@ -405,7 +369,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, } if (is_global == 3) { - struct Symbol **s; + struct elf_symbol **s; /* * Fix up a forward-reference symbol size from the first * pass. @@ -595,11 +559,11 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } -static void elf_add_reloc(struct Section *sect, int32_t segment, int type) +static void elf_add_reloc(struct elf_section *sect, int32_t segment, int type) { - struct Reloc *r; + struct elf_reloc *r; - r = *sect->tail = nasm_zalloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_zalloc(sizeof(struct elf_reloc)); sect->tail = &r->next; r->address = sect->len; @@ -638,13 +602,13 @@ static void elf_add_reloc(struct Section *sect, int32_t segment, int type) * Inefficiency: we search, currently, using a linked list which * isn't even necessarily sorted. */ -static int32_t elf_add_gsym_reloc(struct Section *sect, +static int32_t elf_add_gsym_reloc(struct elf_section *sect, int32_t segment, uint32_t offset, int type, bool exact) { - struct Reloc *r; - struct Section *s; - struct Symbol *sym; + struct elf_reloc *r; + struct elf_section *s; + struct elf_symbol *sym; struct rbtree *srb; int i; @@ -677,9 +641,9 @@ static int32_t elf_add_gsym_reloc(struct Section *sect, " for this reference"); return 0; } - sym = container_of(srb, struct Symbol, symv); + sym = container_of(srb, struct elf_symbol, symv); - r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_malloc(sizeof(struct elf_reloc)); sect->tail = &r->next; r->next = NULL; @@ -696,7 +660,7 @@ static void elf_out(int32_t segto, const void *data, enum out_type type, uint64_t size, int32_t segment, int32_t wrt) { - struct Section *s; + struct elf_section *s; int32_t addr; uint8_t mydata[8], *p; int reltype, bytes; @@ -1001,7 +965,7 @@ static void elf_write(void) for (i = 0; i < nsects; i++) if (sects[i]->head) sects[i]->rel = elf_build_reltab(§s[i]->rellen, - sects[i]->head); + sects[i]->head); /* * Now output the section header table. @@ -1132,7 +1096,7 @@ static void elf_write(void) static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) { struct SAA *s = saa_init(1L); - struct Symbol *sym; + struct elf_symbol *sym; uint8_t entry[16], *p; int i; @@ -1251,7 +1215,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) return s; } -static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r) +static struct SAA *elf_build_reltab(uint64_t *len, struct elf_reloc *r) { struct SAA *s; uint8_t *p, entry[8]; @@ -1327,7 +1291,7 @@ static void elf_write_sections(void) } } -static void elf_sect_write(struct Section *sect, +static void elf_sect_write(struct elf_section *sect, const uint8_t *data, uint32_t len) { saa_wbytes(sect->data, data, len); @@ -1336,7 +1300,7 @@ static void elf_sect_write(struct Section *sect, static void elf_sectalign(int32_t seg, unsigned int value) { - struct Section *s = NULL; + struct elf_section *s = NULL; int i; for (i = 0; i < nsects; i++) { diff --git a/output/outelf64.c b/output/outelf64.c index 537d3a5b..0e6b6bc3 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -60,46 +60,8 @@ #ifdef OF_ELF64 -/* - * Relocation types. - */ -struct Reloc { - struct Reloc *next; - int64_t address; /* relative to _start_ of section */ - int64_t symbol; /* symbol index */ - int64_t offset; /* symbol addend */ - int type; /* type of relocation */ -}; - -struct Symbol { - struct rbtree symv; /* symbol value and rbtree of globals */ - int32_t strpos; /* string table position of name */ - int32_t section; /* section ID of the symbol */ - int type; /* symbol type */ - int other; /* symbol visibility */ - int32_t size; /* size of symbol */ - int32_t globnum; /* symbol table offset if global */ - struct Symbol *nextfwd; /* list of unresolved-size symbols */ - char *name; /* used temporarily if in above list */ -}; - -struct Section { - struct SAA *data; - uint64_t len, size; - uint32_t nrelocs; - int32_t index; /* index into sects array */ - int type; /* SHT_PROGBITS or SHT_NOBITS */ - uint64_t align; /* alignment: power of two */ - uint64_t flags; /* section flags */ - char *name; - struct SAA *rel; - uint64_t rellen; - struct Reloc *head, **tail; - struct rbtree *gsyms; /* global symbols in section */ -}; - #define SECT_DELTA 32 -static struct Section **sects; +static struct elf_section **sects; static int nsects, sectlen; #define SHSTR_DELTA 256 @@ -116,7 +78,7 @@ static struct RAA *bsym; static struct SAA *strs; static uint32_t strslen; -static struct Symbol *fwds; +static struct elf_symbol *fwds; static char elf_module[FILENAME_MAX]; @@ -131,13 +93,13 @@ static int elf_nsect, nsections; static int64_t elf_foffs; static void elf_write(void); -static void elf_sect_write(struct Section *, const void *, size_t); -static void elf_sect_writeaddr(struct Section *, int64_t, size_t); +static void elf_sect_write(struct elf_section *, const void *, size_t); +static void elf_sect_writeaddr(struct elf_section *, int64_t, size_t); static void elf_section_header(int, int, uint64_t, void *, bool, uint64_t, int, int, int, int); static void elf_write_sections(void); static struct SAA *elf_build_symtab(int32_t *, int32_t *); -static struct SAA *elf_build_reltab(uint64_t *, struct Reloc *); +static struct SAA *elf_build_reltab(uint64_t *, struct elf_reloc *); static void add_sectname(char *, char *); struct erel { @@ -195,7 +157,7 @@ static int64_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; static struct dfmt df_dwarf; static struct dfmt df_stabs; -static struct Symbol *lastsym; +static struct elf_symbol *lastsym; /* common debugging routines */ static void debug64_typevalue(int32_t); @@ -232,7 +194,7 @@ static void elf_init(void) maxbits = 64; sects = NULL; nsects = sectlen = 0; - syms = saa_init((int32_t)sizeof(struct Symbol)); + syms = saa_init((int32_t)sizeof(struct elf_symbol)); nlocals = nglobs = ndebugs = 0; bsym = raa_init(); strs = saa_init(1L); @@ -264,7 +226,7 @@ static void elf_init(void) static void elf_cleanup(int debuginfo) { - struct Reloc *r; + struct elf_reloc *r; int i; (void)debuginfo; @@ -303,7 +265,7 @@ static void add_sectname(char *firsthalf, char *secondhalf) static int elf_make_section(char *name, int type, int flags, int align) { - struct Section *s; + struct elf_section *s; s = nasm_zalloc(sizeof(*s)); @@ -391,7 +353,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { int pos = strslen; - struct Symbol *sym; + struct elf_symbol *sym; bool special_used = false; #if defined(DEBUG) && DEBUG>2 @@ -413,7 +375,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, } if (is_global == 3) { - struct Symbol **s; + struct elf_symbol **s; /* * Fix up a forward-reference symbol size from the first * pass. @@ -603,12 +565,12 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } -static void elf_add_reloc(struct Section *sect, int32_t segment, +static void elf_add_reloc(struct elf_section *sect, int32_t segment, int64_t offset, int type) { - struct Reloc *r; + struct elf_reloc *r; - r = *sect->tail = nasm_zalloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_zalloc(sizeof(struct elf_reloc)); sect->tail = &r->next; r->address = sect->len; @@ -649,13 +611,13 @@ static void elf_add_reloc(struct Section *sect, int32_t segment, * Inefficiency: we search, currently, using a linked list which * isn't even necessarily sorted. */ -static void elf_add_gsym_reloc(struct Section *sect, +static void elf_add_gsym_reloc(struct elf_section *sect, int32_t segment, uint64_t offset, int64_t pcrel, int type, bool exact) { - struct Reloc *r; - struct Section *s; - struct Symbol *sym; + struct elf_reloc *r; + struct elf_section *s; + struct elf_symbol *sym; struct rbtree *srb; int i; @@ -687,9 +649,9 @@ static void elf_add_gsym_reloc(struct Section *sect, " for this reference"); return; } - sym = container_of(srb, struct Symbol, symv); + sym = container_of(srb, struct elf_symbol, symv); - r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_malloc(sizeof(struct elf_reloc)); sect->tail = &r->next; r->next = NULL; @@ -705,7 +667,7 @@ static void elf_out(int32_t segto, const void *data, enum out_type type, uint64_t size, int32_t segment, int32_t wrt) { - struct Section *s; + struct elf_section *s; int64_t addr; int reltype, bytes; int i; @@ -1220,7 +1182,7 @@ static void elf_write(void) static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) { struct SAA *s = saa_init(1L); - struct Symbol *sym; + struct elf_symbol *sym; uint8_t entry[24], *p; int i; @@ -1339,7 +1301,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) return s; } -static struct SAA *elf_build_reltab(uint64_t *len, struct Reloc *r) +static struct SAA *elf_build_reltab(uint64_t *len, struct elf_reloc *r) { struct SAA *s; uint8_t *p, entry[24]; @@ -1417,13 +1379,13 @@ static void elf_write_sections(void) } } -static void elf_sect_write(struct Section *sect, const void *data, size_t len) +static void elf_sect_write(struct elf_section *sect, const void *data, size_t len) { saa_wbytes(sect->data, data, len); sect->len += len; } -static void elf_sect_writeaddr(struct Section *sect, int64_t data, size_t len) +static void elf_sect_writeaddr(struct elf_section *sect, int64_t data, size_t len) { saa_writeaddr(sect->data, data, len); sect->len += len; @@ -1431,7 +1393,7 @@ static void elf_sect_writeaddr(struct Section *sect, int64_t data, size_t len) static void elf_sectalign(int32_t seg, unsigned int value) { - struct Section *s = NULL; + struct elf_section *s = NULL; int i; for (i = 0; i < nsects; i++) { diff --git a/output/outelfx32.c b/output/outelfx32.c index ccb022db..6b352a22 100644 --- a/output/outelfx32.c +++ b/output/outelfx32.c @@ -60,45 +60,8 @@ #ifdef OF_ELFX32 -/* - * Relocation types. - */ -struct Reloc { - struct Reloc *next; - int32_t address; /* relative to _start_ of section */ - int32_t symbol; /* symbol index */ - int32_t offset; /* symbol addend */ - int type; /* type of relocation */ -}; - -struct Symbol { - struct rbtree symv; /* symbol value and rbtree of globals */ - int32_t strpos; /* string table position of name */ - int32_t section; /* section ID of the symbol */ - int type; /* symbol type */ - int other; /* symbol visibility */ - int32_t size; /* size of symbol */ - int32_t globnum; /* symbol table offset if global */ - struct Symbol *nextfwd; /* list of unresolved-size symbols */ - char *name; /* used temporarily if in above list */ -}; - -struct Section { - struct SAA *data; - uint32_t len, size, nrelocs; - int32_t index; /* index into sects array */ - int type; /* SHT_PROGBITS or SHT_NOBITS */ - uint32_t align; /* alignment: power of two */ - uint32_t flags; /* section flags */ - char *name; - struct SAA *rel; - uint32_t rellen; - struct Reloc *head, **tail; - struct rbtree *gsyms; /* global symbols in section */ -}; - #define SECT_DELTA 32 -static struct Section **sects; +static struct elf_section **sects; static int nsects, sectlen; #define SHSTR_DELTA 256 @@ -115,7 +78,7 @@ static struct RAA *bsym; static struct SAA *strs; static uint32_t strslen; -static struct Symbol *fwds; +static struct elf_symbol *fwds; static char elf_module[FILENAME_MAX]; @@ -130,13 +93,13 @@ static int elf_nsect, nsections; static int32_t elf_foffs; static void elf_write(void); -static void elf_sect_write(struct Section *, const void *, size_t); -static void elf_sect_writeaddr(struct Section *, int32_t, size_t); +static void elf_sect_write(struct elf_section *, const void *, size_t); +static void elf_sect_writeaddr(struct elf_section *, int32_t, size_t); static void elf_section_header(int, int, uint32_t, void *, bool, uint32_t, int, int, int, int); static void elf_write_sections(void); static struct SAA *elf_build_symtab(int32_t *, int32_t *); -static struct SAA *elf_build_reltab(uint32_t *, struct Reloc *); +static struct SAA *elf_build_reltab(uint64_t *, struct elf_reloc *); static void add_sectname(char *, char *); struct erel { @@ -193,7 +156,7 @@ static int32_t dwarf_infosym, dwarf_abbrevsym, dwarf_linesym; static struct dfmt df_dwarf; static struct dfmt df_stabs; -static struct Symbol *lastsym; +static struct elf_symbol *lastsym; /* common debugging routines */ static void debugx32_typevalue(int32_t); @@ -230,7 +193,7 @@ static void elf_init(void) maxbits = 64; sects = NULL; nsects = sectlen = 0; - syms = saa_init((int32_t)sizeof(struct Symbol)); + syms = saa_init((int32_t)sizeof(struct elf_symbol)); nlocals = nglobs = ndebugs = 0; bsym = raa_init(); strs = saa_init(1L); @@ -262,7 +225,7 @@ static void elf_init(void) static void elf_cleanup(int debuginfo) { - struct Reloc *r; + struct elf_reloc *r; int i; (void)debuginfo; @@ -301,7 +264,7 @@ static void add_sectname(char *firsthalf, char *secondhalf) static int elf_make_section(char *name, int type, int flags, int align) { - struct Section *s; + struct elf_section *s; s = nasm_zalloc(sizeof(*s)); @@ -389,7 +352,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { int pos = strslen; - struct Symbol *sym; + struct elf_symbol *sym; bool special_used = false; #if defined(DEBUG) && DEBUG>2 @@ -411,7 +374,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, } if (is_global == 3) { - struct Symbol **s; + struct elf_symbol **s; /* * Fix up a forward-reference symbol size from the first * pass. @@ -601,12 +564,12 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } -static void elf_add_reloc(struct Section *sect, int32_t segment, +static void elf_add_reloc(struct elf_section *sect, int32_t segment, int32_t offset, int type) { - struct Reloc *r; + struct elf_reloc *r; - r = *sect->tail = nasm_zalloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_zalloc(sizeof(struct elf_reloc)); sect->tail = &r->next; r->address = sect->len; @@ -647,13 +610,13 @@ static void elf_add_reloc(struct Section *sect, int32_t segment, * Inefficiency: we search, currently, using a linked list which * isn't even necessarily sorted. */ -static void elf_add_gsym_reloc(struct Section *sect, +static void elf_add_gsym_reloc(struct elf_section *sect, int32_t segment, uint32_t offset, int32_t pcrel, int type, bool exact) { - struct Reloc *r; - struct Section *s; - struct Symbol *sym; + struct elf_reloc *r; + struct elf_section *s; + struct elf_symbol *sym; struct rbtree *srb; int i; @@ -685,9 +648,9 @@ static void elf_add_gsym_reloc(struct Section *sect, " for this reference"); return; } - sym = container_of(srb, struct Symbol, symv); + sym = container_of(srb, struct elf_symbol, symv); - r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_malloc(sizeof(struct elf_reloc)); sect->tail = &r->next; r->next = NULL; @@ -703,7 +666,7 @@ static void elf_out(int32_t segto, const void *data, enum out_type type, uint64_t size, int32_t segment, int32_t wrt) { - struct Section *s; + struct elf_section *s; int32_t addr; int reltype, bytes; int i; @@ -1180,7 +1143,7 @@ static void elf_write(void) static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) { struct SAA *s = saa_init(1L); - struct Symbol *sym; + struct elf_symbol *sym; uint8_t entry[24], *p; int i; @@ -1299,7 +1262,7 @@ static struct SAA *elf_build_symtab(int32_t *len, int32_t *local) return s; } -static struct SAA *elf_build_reltab(uint32_t *len, struct Reloc *r) +static struct SAA *elf_build_reltab(uint64_t *len, struct elf_reloc *r) { struct SAA *s; uint8_t *p, entry[12]; @@ -1376,12 +1339,12 @@ static void elf_write_sections(void) } } -static void elf_sect_write(struct Section *sect, const void *data, size_t len) +static void elf_sect_write(struct elf_section *sect, const void *data, size_t len) { saa_wbytes(sect->data, data, len); sect->len += len; } -static void elf_sect_writeaddr(struct Section *sect, int32_t data, size_t len) +static void elf_sect_writeaddr(struct elf_section *sect, int32_t data, size_t len) { saa_writeaddr(sect->data, data, len); sect->len += len; @@ -1389,7 +1352,7 @@ static void elf_sect_writeaddr(struct Section *sect, int32_t data, size_t len) static void elf_sectalign(int32_t seg, unsigned int value) { - struct Section *s = NULL; + struct elf_section *s = NULL; int i; for (i = 0; i < nsects; i++) { |