From 56dd9fd83d2191b92d7606df3dbbb1ee948a869f Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 4 Jul 2011 00:33:24 +0400 Subject: [PATCH 1/4] output/outbin.c: initialize section attribs upon creation Basically it's backport of commits 11db774a151e9d895fa05f980563a5cafb0f306a 3bc3ff2fb685a645698f9db9cfc903df30e4e555 c13deef255b621ace2130adf55530f3364a40458 e3f47806658de042af0eaccb1cc7896be388b397 They were missed to back-merge in a first place. Reported-by: Keith Kanios Signed-off-by: Cyrill Gorcunov --- output/outbin.c | 61 ++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/output/outbin.c b/output/outbin.c index 97a29a89..21c042db 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -130,7 +130,7 @@ static struct Section { struct bin_label *labels; /* linked-list of label handles for map output. */ struct bin_label **labels_end; /* Holds address of end of labels list. */ - struct Section *ifollows; /* Points to previous section (implicit follows). */ + struct Section *prev; /* Points to previous section (implicit follows). */ struct Section *next; /* This links sections with a defined start address. */ /* The extended bin format allows for sections to have a "virtual" @@ -201,28 +201,22 @@ static struct Section *find_section_by_index(int32_t index) } static struct Section *create_section(char *name) -{ /* Create a new section. */ - last_section->next = nasm_malloc(sizeof(struct Section)); - last_section->next->ifollows = last_section; - last_section = last_section->next; - last_section->labels = NULL; - last_section->labels_end = &(last_section->labels); +{ + struct Section *s = nasm_zalloc(sizeof(*s)); - /* Initialize section attributes. */ - last_section->name = nasm_strdup(name); - last_section->contents = saa_init(1L); - last_section->follows = last_section->vfollows = 0; - last_section->length = 0; - last_section->flags = 0; - last_section->align = 0; - last_section->valign = 0; - last_section->start = 0; - last_section->vstart = 0; - last_section->next = NULL; + s->prev = last_section; + s->name = nasm_strdup(name); + s->labels_end = &(s->labels); + s->contents = saa_init(1L); /* Register our sections with NASM. */ - last_section->vstart_index = seg_alloc(); - last_section->start_index = seg_alloc(); + s->vstart_index = seg_alloc(); + s->start_index = seg_alloc(); + + /* FIXME: Append to a tail, we need some helper */ + last_section->next = s; + last_section = s; + return last_section; } @@ -489,9 +483,9 @@ static void bin_cleanup(int debuginfo) nasm_error(ERR_FATAL|ERR_NOFILE, "section %s vfollows unknown section (%s)", g->name, g->vfollows); - } else if (g->ifollows != NULL) - for (s = sections; s && (s != g->ifollows); s = s->next) ; - /* The .bss section is the only one with ifollows = NULL. + } else if (g->prev != NULL) + for (s = sections; s && (s != g->prev); s = s->next) ; + /* The .bss section is the only one with prev = NULL. In this case we implicitly follow the last progbits section. */ else @@ -1262,7 +1256,7 @@ static int32_t bin_secname(char *name, int pass, int *bits) sec->flags |= TYPE_DEFINED | TYPE_PROGBITS; else if (!strcmp(name, ".bss")) { sec->flags |= TYPE_DEFINED | TYPE_NOBITS; - sec->ifollows = NULL; + sec->prev = NULL; } } @@ -1433,18 +1427,13 @@ static void binfmt_init(void) nsl_tail = &no_seg_labels; /* Create default section (.text). */ - sections = last_section = nasm_malloc(sizeof(struct Section)); - last_section->next = NULL; - last_section->name = nasm_strdup(".text"); - last_section->contents = saa_init(1L); - last_section->follows = last_section->vfollows = 0; - last_section->ifollows = NULL; - last_section->length = 0; - last_section->flags = TYPE_DEFINED | TYPE_PROGBITS; - last_section->labels = NULL; - last_section->labels_end = &(last_section->labels); - last_section->start_index = seg_alloc(); - last_section->vstart_index = seg_alloc(); + sections = last_section = nasm_zalloc(sizeof(struct Section)); + last_section->name = nasm_strdup(".text"); + last_section->contents = saa_init(1L); + last_section->flags = TYPE_DEFINED | TYPE_PROGBITS; + last_section->labels_end = &(last_section->labels); + last_section->start_index = seg_alloc(); + last_section->vstart_index = seg_alloc(); } /* Generate binary file output */ From 52afa0c5d4eb78169dffd1cd8fe5f743a6b80031 Mon Sep 17 00:00:00 2001 From: Keith Kanios Date: Mon, 11 Apr 2011 21:38:50 -0500 Subject: [PATCH 2/4] BR3282788: Fix 64-bit Mach-O bug that crashes NASM due to NULL symbols --- output/outmac64.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index f633db03..6dc0c44a 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -299,16 +299,34 @@ static uint8_t get_section_fileindex_by_index(const int32_t index) static struct symbol *get_closest_section_symbol_by_offset(uint8_t fileindex, int64_t offset) { - struct symbol *sym; + struct symbol *sym; + struct symbol *nearest = NULL; + int64_t sval, nval, sdiff, ndiff; - for (sym = syms; sym != NULL; sym = sym->next) { - if ((sym->sect != NO_SECT) && - (sym->sect == fileindex) && - ((int64_t)sym->value >= offset)) - return sym; - } + for (sym = syms; sym != NULL; sym = sym->next) { + if ((sym->sect != NO_SECT) && (sym->sect == fileindex)){ + if(nearest == NULL){ + nearest = sym; + }else{ + sval = (int64_t)sym->value; + nval = (int64_t)nearest->value; - return NULL; + sdiff = ((sval >= offset) ? (sval - offset) : (offset - sval)); + ndiff = ((nval >= offset) ? (nval - offset) : (offset - nval)); + + if(sdiff <= ndiff){ + nearest = sym; + } + + /* Symbols should be in order, so this optimization should be OK */ + if((int64_t)nearest->value >= offset){ + break; + } + } + } + } + + return nearest; } From 68868b09e3f518c084be72f967228f3c73439a58 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 4 Jul 2011 00:47:08 +0400 Subject: [PATCH 3/4] doc: Describe changes for stable version Signed-off-by: Cyrill Gorcunov --- doc/changes.src | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/changes.src b/doc/changes.src index 71953779..19a48739 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -8,6 +8,13 @@ The NASM 2 series support x86-64, and is the production version of NASM since 2007. +\S{cl-2.09.09} Version 2.09.09 + +\b Fix initialization of section attributes of \c{bin} output format. + +\b Fix \c{mach64} output format bug that crashes NASM due to NULL symbols. + + \S{cl-2.09.08} Version 2.09.08 \b Fix \c{__OUTPUT_FORMAT__} assignment when output driver alias From ffee19a3b2b130c9190014b3c6d3bf5b32d58cd0 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 4 Jul 2011 00:49:03 +0400 Subject: [PATCH 4/4] NASM 2.09.09 Just a few fixes only but serious enough to yield new stable series - Unitialized memory parsing in bin format section attibutes. - MachO NULL dereference Signed-off-by: Cyrill Gorcunov --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 54985aee..aa45e1d1 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.09.08 +2.09.09