summaryrefslogtreecommitdiff
path: root/output/outelf64.c
diff options
context:
space:
mode:
Diffstat (limited to 'output/outelf64.c')
-rw-r--r--output/outelf64.c81
1 files changed, 36 insertions, 45 deletions
diff --git a/output/outelf64.c b/output/outelf64.c
index 9807c2a..9776972 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -155,11 +155,11 @@ struct symlininfo {
};
struct linelist {
- struct symlininfo info;
- int line;
- char *filename;
struct linelist *next;
struct linelist *last;
+ struct symlininfo info;
+ char *filename;
+ int line;
};
struct sectlist {
@@ -308,25 +308,21 @@ static int elf_make_section(char *name, int type, int flags, int align)
{
struct Section *s;
- s = nasm_malloc(sizeof(*s));
+ s = nasm_zalloc(sizeof(*s));
if (type != SHT_NOBITS)
s->data = saa_init(1L);
- s->head = NULL;
s->tail = &s->head;
- s->len = s->size = 0;
- s->nrelocs = 0;
if (!strcmp(name, ".text"))
s->index = def_seg;
else
s->index = seg_alloc();
add_sectname("", name);
- s->name = nasm_malloc(1 + strlen(name));
- strcpy(s->name, name);
- s->type = type;
- s->flags = flags;
- s->align = align;
- s->gsyms = NULL;
+
+ s->name = nasm_strdup(name);
+ s->type = type;
+ s->flags = flags;
+ s->align = align;
if (nsects >= sectlen)
sects = nasm_realloc(sects, (sectlen += SECT_DELTA) * sizeof(*sects));
@@ -614,17 +610,15 @@ static void elf_add_reloc(struct Section *sect, int32_t segment,
int64_t offset, int type)
{
struct Reloc *r;
- r = *sect->tail = nasm_malloc(sizeof(struct Reloc));
+
+ r = *sect->tail = nasm_zalloc(sizeof(struct Reloc));
sect->tail = &r->next;
- r->next = NULL;
r->address = sect->len;
r->offset = offset;
- if (segment == NO_SEG)
- r->symbol = 0;
- else {
+
+ if (segment != NO_SEG) {
int i;
- r->symbol = 0;
for (i = 0; i < nsects; i++)
if (segment == sects[i]->index)
r->symbol = i + 2;
@@ -715,13 +709,11 @@ static void elf_out(int32_t segto, const void *data,
int32_t segment, int32_t wrt)
{
struct Section *s;
- int64_t addr, zero;
+ int64_t addr;
int reltype, bytes;
int i;
static struct symlininfo sinfo;
- zero = 0;
-
#if defined(DEBUG) && DEBUG>2
if (data)
nasm_error(ERR_DEBUG,
@@ -1414,6 +1406,7 @@ static void elf_sect_write(struct 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)
{
saa_writeaddr(sect->data, data, len);
@@ -1452,7 +1445,7 @@ static int elf_directive(enum directives directive, char *value, int pass)
switch (directive) {
case D_OSABI:
if (pass == 2)
- return 1; /* ignore in pass 2 */
+ return 1; /* ignore in pass 2 */
n = readnum(value, &err);
if (err) {
@@ -1692,9 +1685,7 @@ static void stabs64_generate(void)
ptr = stabslines;
- allfiles = (char **)nasm_malloc(numlinestabs * sizeof(char *));
- for (i = 0; i < numlinestabs; i++)
- allfiles[i] = 0;
+ allfiles = (char **)nasm_zalloc(numlinestabs * sizeof(char *));
numfiles = 0;
while (ptr) {
if (numfiles == 0) {
@@ -2068,26 +2059,26 @@ static void dwarf64_generate(void)
/* build line section */
/* prolog */
plines = saa_init(1L);
- saa_write8(plines,1); /* Minimum Instruction Length */
- saa_write8(plines,1); /* Initial value of 'is_stmt' */
- saa_write8(plines,line_base); /* Line Base */
- saa_write8(plines,line_range); /* Line Range */
- saa_write8(plines,opcode_base); /* Opcode Base */
+ saa_write8(plines,1); /* Minimum Instruction Length */
+ saa_write8(plines,1); /* Initial value of 'is_stmt' */
+ saa_write8(plines,line_base); /* Line Base */
+ saa_write8(plines,line_range); /* Line Range */
+ saa_write8(plines,opcode_base); /* Opcode Base */
/* standard opcode lengths (# of LEB128u operands) */
- saa_write8(plines,0); /* Std opcode 1 length */
- saa_write8(plines,1); /* Std opcode 2 length */
- saa_write8(plines,1); /* Std opcode 3 length */
- saa_write8(plines,1); /* Std opcode 4 length */
- saa_write8(plines,1); /* Std opcode 5 length */
- saa_write8(plines,0); /* Std opcode 6 length */
- saa_write8(plines,0); /* Std opcode 7 length */
- saa_write8(plines,0); /* Std opcode 8 length */
- saa_write8(plines,1); /* Std opcode 9 length */
- saa_write8(plines,0); /* Std opcode 10 length */
- saa_write8(plines,0); /* Std opcode 11 length */
- saa_write8(plines,1); /* Std opcode 12 length */
- /* Directory Table */
- saa_write8(plines,0); /* End of table */
+ saa_write8(plines,0); /* Std opcode 1 length */
+ saa_write8(plines,1); /* Std opcode 2 length */
+ saa_write8(plines,1); /* Std opcode 3 length */
+ saa_write8(plines,1); /* Std opcode 4 length */
+ saa_write8(plines,1); /* Std opcode 5 length */
+ saa_write8(plines,0); /* Std opcode 6 length */
+ saa_write8(plines,0); /* Std opcode 7 length */
+ saa_write8(plines,0); /* Std opcode 8 length */
+ saa_write8(plines,1); /* Std opcode 9 length */
+ saa_write8(plines,0); /* Std opcode 10 length */
+ saa_write8(plines,0); /* Std opcode 11 length */
+ saa_write8(plines,1); /* Std opcode 12 length */
+ /* Directory Table */
+ saa_write8(plines,0); /* End of table */
/* File Name Table */
ftentry = dwarf_flist;
for (indx = 0;indx<dwarf_numfiles;indx++)