You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(208) |
Jun
(43) |
Jul
|
Aug
(2) |
Sep
(17) |
Oct
|
Nov
(4) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
(11) |
Mar
(3) |
Apr
(2) |
May
|
Jun
(3) |
Jul
(29) |
Aug
(29) |
Sep
(48) |
Oct
|
Nov
|
Dec
(5) |
2004 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2005 |
Jan
(12) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(1) |
Dec
(2) |
2006 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(21) |
Nov
(25) |
Dec
(16) |
2007 |
Jan
(26) |
Feb
(26) |
Mar
(18) |
Apr
(51) |
May
(45) |
Jun
(26) |
Jul
(6) |
Aug
(85) |
Sep
(161) |
Oct
(111) |
Nov
(83) |
Dec
(18) |
2008 |
Jan
(31) |
Feb
(27) |
Mar
|
Apr
(16) |
May
(142) |
Jun
(136) |
Jul
(51) |
Aug
(21) |
Sep
(47) |
Oct
(428) |
Nov
(19) |
Dec
(6) |
2009 |
Jan
(11) |
Feb
(37) |
Mar
(17) |
Apr
(15) |
May
(13) |
Jun
(61) |
Jul
(127) |
Aug
(15) |
Sep
(22) |
Oct
(28) |
Nov
(37) |
Dec
(10) |
2010 |
Jan
(18) |
Feb
(22) |
Mar
(10) |
Apr
(41) |
May
|
Jun
(48) |
Jul
(61) |
Aug
(54) |
Sep
(34) |
Oct
(15) |
Nov
(49) |
Dec
(11) |
2011 |
Jan
|
Feb
(24) |
Mar
(10) |
Apr
(9) |
May
|
Jun
(33) |
Jul
(41) |
Aug
(20) |
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
(86) |
Mar
(12) |
Apr
|
May
(10) |
Jun
|
Jul
(9) |
Aug
(4) |
Sep
(11) |
Oct
(3) |
Nov
(3) |
Dec
(10) |
2013 |
Jan
(1) |
Feb
(23) |
Mar
(15) |
Apr
(7) |
May
(20) |
Jun
(3) |
Jul
(15) |
Aug
|
Sep
(29) |
Oct
(16) |
Nov
(69) |
Dec
(18) |
2014 |
Jan
|
Feb
(8) |
Mar
|
Apr
|
May
(16) |
Jun
(7) |
Jul
|
Aug
(5) |
Sep
(2) |
Oct
(4) |
Nov
(25) |
Dec
(8) |
2015 |
Jan
(6) |
Feb
(6) |
Mar
|
Apr
(1) |
May
(2) |
Jun
(1) |
Jul
(7) |
Aug
|
Sep
(2) |
Oct
(1) |
Nov
(6) |
Dec
|
2016 |
Jan
(12) |
Feb
(97) |
Mar
(57) |
Apr
(52) |
May
(33) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
(3) |
Nov
(3) |
Dec
|
2017 |
Jan
(4) |
Feb
|
Mar
(23) |
Apr
(5) |
May
|
Jun
(2) |
Jul
(3) |
Aug
(2) |
Sep
|
Oct
(6) |
Nov
(3) |
Dec
(3) |
2018 |
Jan
(4) |
Feb
(11) |
Mar
|
Apr
(1) |
May
(3) |
Jun
(6) |
Jul
|
Aug
(5) |
Sep
(5) |
Oct
(36) |
Nov
(128) |
Dec
(18) |
2019 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(24) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-17 01:57:38
|
Commit-ID: 2c4a4d5810d0a59b033a07876a2648ef5d4c2859 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=2c4a4d5810d0a59b033a07876a2648ef5d4c2859 Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 17:37:18 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 17:37:18 -0800 Simplify handling of segments and segalign Slightly simplify the handling of segment number allocation. If we are in absolute space, never push a segalign down to the backend. Signed-off-by: H. Peter Anvin <hp...@li...> --- nasm.c | 6 +++--- nasmlib.c | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/nasm.c b/nasm.c index 55c7a2a..a176f25 100644 --- a/nasm.c +++ b/nasm.c @@ -343,8 +343,6 @@ int main(int argc, char **argv) preproc = &nasmpp; operating_mode = OP_NORMAL; - seg_init(); - /* Define some macros dependent on the runtime, but not on the command line. */ define_macros_early(); @@ -1291,8 +1289,10 @@ static void assemble_file(char *fname, StrList **depend_ptr) "segment alignment `%s' is not power of two", value); } + /* callee should be able to handle all details */ - ofmt->sectalign(location.segment, align); + if (location.segment != NO_SEG) + ofmt->sectalign(location.segment, align); } } break; diff --git a/nasmlib.c b/nasmlib.c index 656350d..cf39468 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -391,16 +391,14 @@ int64_t readstrnum(char *str, int length, bool *warn) return charconst; } -static int32_t next_seg; - -void seg_init(void) -{ - next_seg = 0; -} - int32_t seg_alloc(void) { - return (next_seg += 2) - 2; + static int32_t next_seg = 0; + int32_t this_seg = next_seg; + + next_seg += 2; + + return this_seg; } #ifdef WORDS_LITTLEENDIAN |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-17 01:57:21
|
Commit-ID: 6fc2b123afaaf57577581a7680aa41fe101fd86b Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=6fc2b123afaaf57577581a7680aa41fe101fd86b Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 12:56:27 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 12:56:27 -0800 outmacho: if .rodata contains no relocations, change it to __TEXT,__const If we specify .rodata as opposed to the explicit __DATA,__const, and we end up with no relocations, change it to __TEXT,__const per the Mach-O ABI. However, it is generally better for the programmer to explicitly specify the items that should go into __TEXT,__const as otherwise a single relocatable item will force the whole thing into __DATA. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmacho.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index e39d655..6872a7b 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -114,6 +114,7 @@ struct section { int32_t index; struct reloc *relocs; int align; + bool by_name; /* This section was specified by full MachO name */ /* data that goes into the file */ char sectname[16]; /* what this section is called */ @@ -248,7 +249,6 @@ static uint64_t seg_vmsize = 0; static uint32_t seg_nsects = 0; static uint64_t rel_padcnt = 0; - #define xstrncpy(xdst, xsrc) \ memset(xdst, '\0', sizeof(xdst)); /* zero out whole buffer */ \ strncpy(xdst, xsrc, sizeof(xdst)); /* copy over string */ \ @@ -632,14 +632,14 @@ static int32_t macho_section(char *name, int pass, int *bits) len = strlen(segment); if (len == 0) { nasm_error(ERR_NONFATAL, "empty segment name\n"); - } else if (len > 16) { + } else if (len >= 16) { nasm_error(ERR_NONFATAL, "segment name %s too long\n", segment); } len = strlen(section); if (len == 0) { nasm_error(ERR_NONFATAL, "empty section name\n"); - } else if (len > 16) { + } else if (len >= 16) { nasm_error(ERR_NONFATAL, "section name %s too long\n", section); } @@ -682,6 +682,7 @@ static int32_t macho_section(char *name, int pass, int *bits) s->align = -1; s->pad = -1; s->offset = -1; + s->by_name = false; xstrncpy(s->segname, segment); xstrncpy(s->sectname, section); @@ -697,6 +698,8 @@ static int32_t macho_section(char *name, int pass, int *bits) if (comma) *comma = ','; /* Restore comma */ + s->by_name = s->by_name || comma; /* Was specified by name */ + flags = (uint32_t)-1; while ((NULL != sectionAttributes) @@ -1114,6 +1117,17 @@ static uint32_t macho_write_segment (uint64_t offset) s->flags |= S_ATTR_LOC_RELOC; if (s->extreloc) s->flags |= S_ATTR_EXT_RELOC; + } else if (!strcmp(s->segname, "__DATA") && + !strcmp(s->sectname, "__const") && + !s->by_name && + !get_section_by_name("__TEXT", "__const")) { + /* + * The MachO equivalent to .rodata can be either + * __DATA,__const or __TEXT,__const; the latter only if + * there are no relocations. However, when mixed it is + * better to specify the segments explicitly. + */ + xstrncpy(s->segname, "__TEXT"); } fwriteint32_t(s->flags, ofile); /* flags */ |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-17 01:57:19
|
Commit-ID: ec62791d8c815cdeaf9fe0889787111d58e3535e Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ec62791d8c815cdeaf9fe0889787111d58e3535e Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 17:38:58 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 17:38:58 -0800 outmacho: sanitize the handling of sections Sanitize the handling of sections in outmacho somewhat. This should bring further performance improvements. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmacho.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 6872a7b..24b4338 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -112,6 +112,7 @@ struct section { struct section *next; struct SAA *data; int32_t index; + int32_t fileindex; struct reloc *relocs; int align; bool by_name; /* This section was specified by full MachO name */ @@ -291,14 +292,9 @@ static struct section *get_section_by_index(const int32_t index) static uint8_t get_section_fileindex_by_index(const int32_t index) { - struct section *s; - uint8_t i = 1; - - for (s = sects; s != NULL; s = s->next, ++i) - if (index == s->index) - return i; + struct section *s = get_section_by_index(index); - return NO_SECT; + return s ? s->fileindex : NO_SECT; } /* @@ -426,13 +422,13 @@ static int64_t add_reloc(struct section *sect, int32_t section, case RL_GOT: r->pcrel = 1; r->type = 4; // X86_64_RELOC_GOT - r->snum = macho_gotpcrel_sect; + r->snum = macho_gotpcrel_sect; /* WTF? */ break; case RL_GOTLOAD: r->pcrel = 1; r->type = 3; // X86_64_RELOC_GOT_LOAD - r->snum = macho_gotpcrel_sect; + r->snum = macho_gotpcrel_sect; /* WTF? */ break; } @@ -596,7 +592,6 @@ static void macho_output(int32_t secto, const void *data, static int32_t macho_section(char *name, int pass, int *bits) { - int32_t index; char *sectionAttributes; struct sectmap *sm; struct section *s; @@ -657,6 +652,7 @@ static int32_t macho_section(char *name, int pass, int *bits) if (!strcmp(name, sm->nasmsect)) { segment = sm->segname; section = sm->sectname; + flags = sm->flags; goto found; } } @@ -678,6 +674,7 @@ static int32_t macho_section(char *name, int pass, int *bits) s->data = saa_init(1L); s->index = seg_alloc(); + s->fileindex = ++seg_nsects; s->relocs = NULL; s->align = -1; s->pad = -1; @@ -689,8 +686,6 @@ static int32_t macho_section(char *name, int pass, int *bits) s->size = 0; s->nreloc = 0; s->flags = flags; - - index = s->index; } else { new_seg = false; } @@ -713,19 +708,17 @@ static int32_t macho_section(char *name, int pass, int *bits) newAlignment = alignlog2_32(value); if (0 != *end) { - nasm_error(ERR_FATAL, + nasm_error(ERR_NONFATAL, "unknown or missing alignment value \"%s\" " "specified for section \"%s\"", currentAttribute + 6, name); - return NO_SEG; } else if (0 > newAlignment) { - nasm_error(ERR_FATAL, + nasm_error(ERR_NONFATAL, "alignment of %d (for section \"%s\") is not " "a power of two", value, name); - return NO_SEG; } if (s->align < newAlignment) @@ -758,7 +751,7 @@ static int32_t macho_section(char *name, int pass, int *bits) } } - return index; + return s->index; } static void macho_symdef(char *name, int32_t section, int64_t offset, @@ -803,7 +796,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, /* external and common symbols get N_EXT */ if (is_global != 0) { sym->type |= N_EXT; - } + } if (section == NO_SEG) { /* symbols in no section get absolute */ @@ -815,16 +808,15 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, /* get the in-file index of the section the symbol was defined in */ sym->sect = get_section_fileindex_by_index(section); - /* track the initially allocated symbol number for use in future fix-ups */ - sym->initial_snum = nsyms; + /* track the initially allocated symbol number for use in future fix-ups */ + sym->initial_snum = nsyms; if (sym->sect == NO_SECT) { - /* remember symbol number of references to external ** symbols, this works because every external symbol gets ** its own section number allocated internally by nasm and ** can so be used as a key */ - extsyms = raa_write(extsyms, section, nsyms); + extsyms = raa_write(extsyms, section, nsyms); switch (is_global) { case 1: @@ -839,8 +831,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, /* give an error on unfound section if it's not an ** external or common symbol (assemble_file() does a ** seg_alloc() on every call for them) */ - nasm_error(ERR_PANIC, "in-file index for section %d not found", - section); + nasm_panic(0, "in-file index for section %d not found, is_global = %d", section, is_global); } } } @@ -852,10 +843,9 @@ static void macho_sectalign(int32_t seg, unsigned int value) struct section *s; int align; - list_for_each(s, sects) { - if (s->index == seg) - break; - } + nasm_assert(!(seg & 1)); + + s = get_section_by_index(seg); if (!s || !is_power2(value)) return; @@ -1016,8 +1006,6 @@ static void macho_calculate_sizes (void) s->offset = seg_filesize + s->pad; seg_filesize += s->size + s->pad; } - - ++seg_nsects; } /* calculate size of all headers, load commands and sections to |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-17 01:57:19
|
Commit-ID: d1da074b837cd8f56f2eca3e622cdfe2de20dbec Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=d1da074b837cd8f56f2eca3e622cdfe2de20dbec Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 12:39:26 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 12:39:26 -0800 outmacho: Allow arbitrary MachO sections, avoid bss lookup Allow specifying sections with arbitary MachO segment and section names, as opposed to having a fixed list of supported sections (especially __DATA,__const is wrong in some cases.) Furthermore, we do a completely unnecessary lookup of the bss section *for every call to macho_output()* which is just plain crazy. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmacho.c | 259 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 151 insertions(+), 108 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index f8122f0..e39d655 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -289,29 +289,6 @@ static struct section *get_section_by_index(const int32_t index) return s; } -static int32_t get_section_index_by_name(const char *segname, - const char *sectname) -{ - struct section *s; - - for (s = sects; s != NULL; s = s->next) - if (!strcmp(s->segname, segname) && !strcmp(s->sectname, sectname)) - return s->index; - - return -1; -} - -static char *get_section_name_by_index(const int32_t index) -{ - struct section *s; - - for (s = sects; s != NULL; s = s->next) - if (index == s->index) - return s->sectname; - - return NULL; -} - static uint8_t get_section_fileindex_by_index(const int32_t index) { struct section *s; @@ -467,9 +444,10 @@ static void macho_output(int32_t secto, const void *data, enum out_type type, uint64_t size, int32_t section, int32_t wrt) { - struct section *s, *sbss; + struct section *s; int64_t addr; uint8_t mydata[16], *p, gotload; + bool is_bss; if (secto == NO_SEG) { if (type != OUT_RESERVE) @@ -488,14 +466,14 @@ static void macho_output(int32_t secto, const void *data, /* should never happen */ if (s == NULL) - nasm_error(ERR_PANIC, "text section not found"); + nasm_panic(0, "text section not found"); } - sbss = get_section_by_name("__DATA", "__bss"); + is_bss = (s->flags & SECTION_TYPE) == S_ZEROFILL; - if (s == sbss && type != OUT_RESERVE) { - nasm_error(ERR_WARNING, "attempt to initialize memory in the" - " BSS section: ignored"); + if (is_bss && type != OUT_RESERVE) { + nasm_error(ERR_WARNING, "attempt to initialize memory in " + "BSS section: ignored"); s->size += realsize(type, size); return; } @@ -504,10 +482,9 @@ static void macho_output(int32_t secto, const void *data, switch (type) { case OUT_RESERVE: - if (s != sbss) { + if (!is_bss) { nasm_error(ERR_WARNING, "uninitialized space declared in" - " %s section: zeroing", - get_section_name_by_index(secto)); + " %s,%s section: zeroing", s->segname, s->sectname); sect_write(s, NULL, size); } else @@ -517,7 +494,7 @@ static void macho_output(int32_t secto, const void *data, case OUT_RAWDATA: if (section != NO_SEG) - nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_panic(0, "OUT_RAWDATA with other than NO_SEG"); sect_write(s, data, size); break; @@ -533,7 +510,8 @@ static void macho_output(int32_t secto, const void *data, " section base references"); } else if (wrt == NO_SEG) { if (fmt->ptrsize == 8 && asize != 8) { - nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support" + nasm_error(ERR_NONFATAL, + "Mach-O 64-bit format does not support" " 32-bit absolute addresses"); } else { add_reloc(s, section, RL_ABS, asize); @@ -622,6 +600,11 @@ static int32_t macho_section(char *name, int pass, int *bits) char *sectionAttributes; struct sectmap *sm; struct section *s; + const char *section, *segment; + uint32_t flags; + char *currentAttribute; + char *comma; + bool new_seg; (void)pass; @@ -635,84 +618,144 @@ static int32_t macho_section(char *name, int pass, int *bits) name = nasm_strsep(§ionAttributes, " \t"); } - for (sm = sectmap; sm->nasmsect != NULL; ++sm) { - /* make lookup into section name translation table */ - if (!strcmp(name, sm->nasmsect)) { - char *currentAttribute; - - /* try to find section with that name */ - index = get_section_index_by_name(sm->segname, sm->sectname); - - /* create it if it doesn't exist yet */ - if (index == -1) { - s = *sectstail = nasm_malloc(sizeof(struct section)); - s->next = NULL; - sectstail = &s->next; - - s->data = saa_init(1L); - s->index = seg_alloc(); - s->relocs = NULL; - s->align = -1; - s->pad = -1; - s->offset = -1; - - xstrncpy(s->segname, sm->segname); - xstrncpy(s->sectname, sm->sectname); - s->size = 0; - s->nreloc = 0; - s->flags = sm->flags; - - index = s->index; - } else { - s = get_section_by_index(index); - } + section = segment = NULL; + flags = 0; - while ((NULL != sectionAttributes) - && (currentAttribute = nasm_strsep(§ionAttributes, " \t"))) { - if (0 != *currentAttribute) { - if (!nasm_strnicmp("align=", currentAttribute, 6)) { - char *end; - int newAlignment, value; - - value = strtoul(currentAttribute + 6, (char**)&end, 0); - newAlignment = alignlog2_32(value); - - if (0 != *end) { - nasm_error(ERR_FATAL, - "unknown or missing alignment value \"%s\" " - "specified for section \"%s\"", - currentAttribute + 6, - name); - return NO_SEG; - } else if (0 > newAlignment) { - nasm_error(ERR_FATAL, - "alignment of %d (for section \"%s\") is not " - "a power of two", - value, - name); - return NO_SEG; - } - - if (s->align < newAlignment) - s->align = newAlignment; - } else if (!nasm_stricmp("data", currentAttribute)) { - /* Do nothing; 'data' is implicit */ - } else { - nasm_error(ERR_FATAL, - "unknown section attribute %s for section %s", - currentAttribute, - name); - return NO_SEG; - } - } - } + comma = strchr(name, ','); + if (comma) { + int len; - return index; - } + *comma = '\0'; + segment = name; + section = comma+1; + + len = strlen(segment); + if (len == 0) { + nasm_error(ERR_NONFATAL, "empty segment name\n"); + } else if (len > 16) { + nasm_error(ERR_NONFATAL, "segment name %s too long\n", segment); + } + + len = strlen(section); + if (len == 0) { + nasm_error(ERR_NONFATAL, "empty section name\n"); + } else if (len > 16) { + nasm_error(ERR_NONFATAL, "section name %s too long\n", section); + } + + if (!strcmp(segment, "__TEXT")) { + flags = S_REGULAR | S_ATTR_SOME_INSTRUCTIONS | + S_ATTR_PURE_INSTRUCTIONS; + } else if (!strcmp(segment, "__DATA") && !strcmp(section, "__bss")) { + flags = S_ZEROFILL; + } else { + flags = S_REGULAR; + } + } else { + for (sm = sectmap; sm->nasmsect != NULL; ++sm) { + /* make lookup into section name translation table */ + if (!strcmp(name, sm->nasmsect)) { + segment = sm->segname; + section = sm->sectname; + goto found; + } + } + nasm_error(ERR_NONFATAL, "unknown section name\n"); + return NO_SEG; + } + + found: + /* try to find section with that name */ + s = get_section_by_name(segment, section); + + /* create it if it doesn't exist yet */ + if (!s) { + new_seg = true; + + s = *sectstail = nasm_malloc(sizeof(struct section)); + s->next = NULL; + sectstail = &s->next; + + s->data = saa_init(1L); + s->index = seg_alloc(); + s->relocs = NULL; + s->align = -1; + s->pad = -1; + s->offset = -1; + + xstrncpy(s->segname, segment); + xstrncpy(s->sectname, section); + s->size = 0; + s->nreloc = 0; + s->flags = flags; + + index = s->index; + } else { + new_seg = false; + } + + if (comma) + *comma = ','; /* Restore comma */ + + flags = (uint32_t)-1; + + while ((NULL != sectionAttributes) + && (currentAttribute = nasm_strsep(§ionAttributes, " \t"))) { + if (0 != *currentAttribute) { + if (!nasm_strnicmp("align=", currentAttribute, 6)) { + char *end; + int newAlignment, value; + + value = strtoul(currentAttribute + 6, (char**)&end, 0); + newAlignment = alignlog2_32(value); + + if (0 != *end) { + nasm_error(ERR_FATAL, + "unknown or missing alignment value \"%s\" " + "specified for section \"%s\"", + currentAttribute + 6, + name); + return NO_SEG; + } else if (0 > newAlignment) { + nasm_error(ERR_FATAL, + "alignment of %d (for section \"%s\") is not " + "a power of two", + value, + name); + return NO_SEG; + } + + if (s->align < newAlignment) + s->align = newAlignment; + } else if (!nasm_stricmp("data", currentAttribute)) { + flags = S_REGULAR; + } else if (!nasm_stricmp("code", currentAttribute)) { + flags = S_REGULAR | S_ATTR_SOME_INSTRUCTIONS | + S_ATTR_PURE_INSTRUCTIONS; + } else if (!nasm_stricmp("mixed", currentAttribute)) { + flags = S_REGULAR | S_ATTR_SOME_INSTRUCTIONS; + } else if (!nasm_stricmp("bss", currentAttribute)) { + flags = S_ZEROFILL; + } else { + nasm_error(ERR_NONFATAL, + "unknown section attribute %s for section %s", + currentAttribute, + name); + } + } + + if (flags != (uint32_t)-1) { + if (!new_seg && s->flags != flags) { + nasm_error(ERR_NONFATAL, + "inconsistent section attributes for section %s\n", + name); + } else { + s->flags = flags; + } + } } - nasm_error(ERR_FATAL, "invalid section name %s", name); - return NO_SEG; + return index; } static void macho_symdef(char *name, int32_t section, int64_t offset, |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-17 01:57:18
|
Commit-ID: 615ef1a6f848d33cf90f70c77e7934fbd56fcd42 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=615ef1a6f848d33cf90f70c77e7934fbd56fcd42 Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 11:42:13 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 11:42:13 -0800 outmacho: Only test for MAX_SECT at the point sections are laid out Exceeding MAX_SECT is not a warning, it is a fatal error. However, there is no point to test for it until we already process all the sections. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmacho.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 60b6f0c..f8122f0 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -317,14 +317,10 @@ static uint8_t get_section_fileindex_by_index(const int32_t index) struct section *s; uint8_t i = 1; - for (s = sects; s != NULL && i < MAX_SECT; s = s->next, ++i) + for (s = sects; s != NULL; s = s->next, ++i) if (index == s->index) return i; - if (i == MAX_SECT) - nasm_error(ERR_WARNING, - "too many sections (>255) - clipped by fileindex"); - return NO_SECT; } @@ -990,6 +986,11 @@ static void macho_calculate_sizes (void) head_sizeofcmds += MACHO_SYMCMD_SIZE; } + if (seg_nsects > MAX_SECT) { + nasm_error(ERR_FATAL, "MachO output is limited to %d sections\n", + MAX_SECT); + } + /* Create a table of sections by file index to avoid linear search */ sectstab = nasm_malloc((seg_nsects + 1) * sizeof(*sectstab)); sectstab[0] = NULL; |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-16 19:36:38
|
Commit-ID: e1eb7b88803014a67f0c10478bb4a11d15ffb5a5 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=e1eb7b88803014a67f0c10478bb4a11d15ffb5a5 Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 11:30:54 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 11:30:54 -0800 outmacho: Fix the computation of non-external relocation offsets When we clear the ext bit, creating section-relative relocations, the resulting value is computed somewhat differently; we need to adjust for that. TODO: Need to make sure we do the right thing for ALL relocations. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmacho.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 98e1a42..60b6f0c 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -370,11 +370,12 @@ enum reltype { RL_GOTLOAD, /* X86_64_RELOC_GOT_LOAD */ }; -static void add_reloc(struct section *sect, int32_t section, - enum reltype reltype, int bytes) +static int64_t add_reloc(struct section *sect, int32_t section, + enum reltype reltype, int bytes) { struct reloc *r; int32_t fi; + int64_t adjust; /* NeXT as puts relocs in reversed order (address-wise) into the ** files, so we do the same, doesn't seem to make much of a @@ -389,6 +390,7 @@ static void add_reloc(struct section *sect, int32_t section, ** bit by accident */ r->addr = sect->size & ~R_SCATTERED; r->ext = 1; + adjust = bytes; /* match byte count 1, 2, 4, 8 to length codes 0, 1, 2, 3 respectively */ r->length = ilog2_32(bytes); @@ -415,6 +417,7 @@ static void add_reloc(struct section *sect, int32_t section, /* local */ r->ext = 0; r->snum = fi; + adjust = -sect->size; } } break; @@ -437,6 +440,7 @@ static void add_reloc(struct section *sect, int32_t section, /* local */ r->ext = 0; r->snum = fi; + adjust = -sect->size; } } break; @@ -460,6 +464,7 @@ static void add_reloc(struct section *sect, int32_t section, } ++sect->nreloc; + return adjust; } static void macho_output(int32_t secto, const void *data, @@ -553,7 +558,7 @@ static void macho_output(int32_t secto, const void *data, nasm_assert(section != secto); p = mydata; - addr = *(int64_t *)data + 2 - size; + addr = *(int64_t *)data - size; if (section != NO_SEG && section % 2) { nasm_error(ERR_NONFATAL, "Mach-O format does not support" @@ -566,7 +571,7 @@ static void macho_output(int32_t secto, const void *data, " this use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } else { - add_reloc(s, section, RL_REL, 2); + addr += add_reloc(s, section, RL_REL, 2); } WRITESHORT(p, addr); @@ -577,14 +582,14 @@ static void macho_output(int32_t secto, const void *data, nasm_assert(section != secto); p = mydata; - addr = *(int64_t *)data + 4 - size; + addr = *(int64_t *)data - size; if (section != NO_SEG && section % 2) { nasm_error(ERR_NONFATAL, "Mach-O format does not support" " section base references"); } else if (wrt == NO_SEG) { /* Plain relative relocation */ - add_reloc(s, section, RL_REL, 4); + addr += add_reloc(s, section, RL_REL, 4); } else if (wrt == macho_gotpcrel_sect) { if (s->data->datalen > 1) { /* Retrieve instruction opcode */ @@ -594,10 +599,10 @@ static void macho_output(int32_t secto, const void *data, } if (gotload == 0x8B) { /* Check for MOVQ Opcode -> X86_64_RELOC_GOT_LOAD */ - add_reloc(s, section, RL_GOTLOAD, 4); + addr += add_reloc(s, section, RL_GOTLOAD, 4); } else { /* X86_64_RELOC_GOT */ - add_reloc(s, section, RL_GOT, 4); + addr += add_reloc(s, section, RL_GOT, 4); } } else { nasm_error(ERR_NONFATAL, "Mach-O format does not support" @@ -965,6 +970,7 @@ static void macho_calculate_sizes (void) * perhaps aligning to pointer size would be better. */ s->pad = ALIGN(seg_filesize, 4) - seg_filesize; + // s->pad = ALIGN(seg_filesize, 1U << s->align) - seg_filesize; s->offset = seg_filesize + s->pad; seg_filesize += s->size + s->pad; } @@ -1100,9 +1106,9 @@ static void macho_write_relocs (struct reloc *r) /* Write out the section data. */ static void macho_write_section (void) { - struct section *s, *s2; + struct section *s; struct reloc *r; - uint8_t fi, *p; + uint8_t *p; int32_t len; int64_t l; union offset { |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-16 08:33:19
|
Commit-ID: 4e5fbcb81bc9ee65d2b6aa826e1a26c94701e1e9 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=4e5fbcb81bc9ee65d2b6aa826e1a26c94701e1e9 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Tue, 16 Feb 2016 00:29:48 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Tue, 16 Feb 2016 00:29:48 -0800 outmacho: use section table lookup for local symbol references When generating local symbol references, don't loop over all the sections like we used to... Signed-off-by: H. Peter Anvin <hp...@zy...> --- output/outmacho.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 378fe6d..98e1a42 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -425,7 +425,7 @@ static void add_reloc(struct section *sect, int32_t section, /* intra-section */ r->type = 1; // X86_64_RELOC_SIGNED } else { - /* inter-section */ + /* inter-section */ r->type = 1; // X86_64_RELOC_SIGNED fi = get_section_fileindex_by_index(section); @@ -1145,14 +1145,9 @@ static void macho_write_section (void) offset which we already have. The linker takes care of the rest of the address. */ if (!r->ext) { - /* generate final address by section address and offset */ - for (s2 = sects, fi = 1; - s2 != NULL; s2 = s2->next, fi++) { - if (fi == r->snum) { - l += s2->addr; - break; - } - } + /* generate final address by section address and offset */ + nasm_assert(r->snum <= seg_nsects); + l += sectstab[r->snum]->addr; } /* write new offset back */ |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-16 07:48:17
|
Commit-ID: ddf424758c7db547e76c1739c67e5bc5a0a0ff1b Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ddf424758c7db547e76c1739c67e5bc5a0a0ff1b Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 12 Feb 2016 21:24:32 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 12 Feb 2016 21:24:32 -0800 NASM 2.12rc3 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index e697fe6..ffda82f 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12rc2 +2.12rc3 |
From: nasm-bot f. O. S. <se...@us...> - 2016-02-13 08:00:41
|
Commit-ID: ec3d426e363d07c8a582ff7cf5a31b5e99576ec3 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ec3d426e363d07c8a582ff7cf5a31b5e99576ec3 Author: Ozkan Sezer <se...@us...> AuthorDate: Fri, 12 Feb 2016 23:49:49 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 23:49:56 -0800 configure.in: Add -Werror flags last (BR 2292332) configure.in: Add the -Werror flags as the last thing. Otherwise, with development versions of autoconf, all AC_CHECK_FUNCS calls fails with: conftest.c:49: error: function declaration isn't a prototype conftest.c:49: warning: conflicting types for built-in function 'strcspn' Signed-off-by: Ozkan Sezer <se...@us...> Signed-off-by: H. Peter Anvin <hp...@zy...> --- configure.in | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/configure.in b/configure.in index f327426..023bd24 100644 --- a/configure.in +++ b/configure.in @@ -78,17 +78,6 @@ dnl If we have gcc, add appropriate options PA_ADD_CFLAGS([-W]) PA_ADD_CFLAGS([-Wall]) PA_ADD_CFLAGS([-std=c99]) -PA_ADD_CFLAGS([-pedantic]) -PA_ADD_CFLAGS([-Werror=implicit]) -PA_ADD_CFLAGS([-Werror=missing-braces]) -PA_ADD_CFLAGS([-Werror=return-type]) -PA_ADD_CFLAGS([-Werror=trigraphs]) -PA_ADD_CFLAGS([-Werror=pointer-arith]) -PA_ADD_CFLAGS([-Werror=strict-prototypes]) -PA_ADD_CFLAGS([-Werror=missing-prototypes]) -PA_ADD_CFLAGS([-Werror=missing-declarations]) -PA_ADD_CFLAGS([-Werror=comment]) -PA_ADD_CFLAGS([-Werror=vla]) dnl Look for programs... AC_CHECK_PROGS(NROFF, nroff, false) @@ -192,5 +181,17 @@ AC_ARG_WITH([ccache], [CC="ccache $CC"], []) +PA_ADD_CFLAGS([-pedantic]) +PA_ADD_CFLAGS([-Werror=implicit]) +PA_ADD_CFLAGS([-Werror=missing-braces]) +PA_ADD_CFLAGS([-Werror=return-type]) +PA_ADD_CFLAGS([-Werror=trigraphs]) +PA_ADD_CFLAGS([-Werror=pointer-arith]) +PA_ADD_CFLAGS([-Werror=strict-prototypes]) +PA_ADD_CFLAGS([-Werror=missing-prototypes]) +PA_ADD_CFLAGS([-Werror=missing-declarations]) +PA_ADD_CFLAGS([-Werror=comment]) +PA_ADD_CFLAGS([-Werror=vla]) + AC_OUTPUT_COMMANDS([mkdir -p output]) AC_OUTPUT(Makefile rdoff/Makefile doc/Makefile) |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-13 05:24:16
|
Commit-ID: 2bc798a96877eaf11b3ccce1340f34e46a93f1b9 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=2bc798a96877eaf11b3ccce1340f34e46a93f1b9 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 12 Feb 2016 21:21:57 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 12 Feb 2016 21:21:57 -0800 rdflib: actually get the time sizeof(t = time(NULL)) doesn't ever actually call time(). Signed-off-by: H. Peter Anvin <hp...@li...> --- rdoff/rdflib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rdoff/rdflib.c b/rdoff/rdflib.c index 1490396..06cce3c 100644 --- a/rdoff/rdflib.c +++ b/rdoff/rdflib.c @@ -180,7 +180,8 @@ int main(int argc, char **argv) } fwrite(sig_modname, 1, strlen(sig_modname) + 1, fp); fwrite(rdl_signature, 1, strlen(rdl_signature), fp); - l = sizeof(t = time(NULL)); + t = time(NULL); + l = sizeof(t); fwrite(&l, sizeof(l), 1, fp); fwrite(&t, 1, l, fp); fclose(fp); |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-13 05:21:20
|
Commit-ID: 99276cc7d9e8d3f39af22582bfae115fed5bb997 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=99276cc7d9e8d3f39af22582bfae115fed5bb997 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 12 Feb 2016 21:18:12 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 12 Feb 2016 21:19:13 -0800 outmacho: rename outmac.c to outmacho.c We already have outmacho.mac, so name this file outmacho.c. Signed-off-by: H. Peter Anvin <hp...@li...> --- Makefile.in | 8 ++++---- Mkfiles/msvc.mak | 8 ++++---- Mkfiles/netware.mak | 7 ++++--- Mkfiles/openwcom.mak | 8 ++++---- Mkfiles/owlinux.mak | 8 ++++---- output/{outmac.c => outmacho.c} | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Makefile.in b/Makefile.in index ac5521a..6ee17b4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,7 +84,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ - output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) \ + output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \ md5c.$(O) output/codeview.$(O) \ preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ @@ -403,9 +403,9 @@ output/outieee.$(O): output/outieee.c compiler.h config.h directiv.h \ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h \ tables.h -output/outmac.$(O): output/outmac.c compiler.h config.h directiv.h insnsi.h \ - nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h +output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h \ + insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ + pptok.h preproc.h raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ pptok.h preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index b220a0d..a1bfd5e 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -55,7 +55,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ - output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) \ + output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \ md5c.$(O) output/codeview.$(O) \ preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ @@ -319,9 +319,9 @@ output/outieee.$(O): output/outieee.c compiler.h directiv.h insnsi.h nasm.h \ regs.h tables.h output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h -output/outmac.$(O): output/outmac.c compiler.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \ - raa.h regs.h saa.h tables.h +output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \ + nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ + preproc.h raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 66e1115..d897f44 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -42,7 +42,7 @@ NASM = nasm.o nasmlib.o ver.o \ outelf.o outelf32.o outelf64.o \ outelfx32.o \ outobj.o outas86.o outrdf2.o \ - outdbg.o outieee.o outmac.o \ + outdbg.o outieee.o outmacho.o \ md5c.o codeview.o \ preproc.o quote.o pptok.o \ macros.o listing.o eval.o exprlib.o stdscan.o \ @@ -223,8 +223,9 @@ outieee.o: outieee.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h tables.h outlib.o: outlib.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h outlib.h pptok.h preproc.h regs.h tables.h -outmac.o: outmac.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \ - opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h tables.h +outmacho.o: outmacho.c compiler.h config.h directiv.h insnsi.h nasm.h \ + nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \ + tables.h outobj.o: outobj.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h \ tables.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index c673c47..351df72 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -58,7 +58,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) & output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) & output/outelfx32.$(O) & output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) & - output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) & + output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) & md5c.$(O) output/codeview.$(O) & preproc.$(O) quote.$(O) pptok.$(O) & macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) & @@ -370,9 +370,9 @@ output/outieee.$(O): output/outieee.c compiler.h config.h directiv.h & output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h & nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h & tables.h -output/outmac.$(O): output/outmac.c compiler.h config.h directiv.h insnsi.h & - nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h & - preproc.h raa.h regs.h saa.h tables.h +output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h & + insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & + pptok.h preproc.h raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h & insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & pptok.h preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 2a6f899..256abba 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -69,7 +69,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ - output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) \ + output/outdbg.$(O) output/outieee.$(O) output/outmacho.$(O) \ md5c.$(O) output/codeview.$(O) \ preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ @@ -333,9 +333,9 @@ output/outieee.$(O): output/outieee.c compiler.h directiv.h insnsi.h nasm.h \ regs.h tables.h output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h -output/outmac.$(O): output/outmac.c compiler.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \ - raa.h regs.h saa.h tables.h +output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \ + nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ + preproc.h raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h diff --git a/output/outmac.c b/output/outmacho.c similarity index 99% rename from output/outmac.c rename to output/outmacho.c index a2209c6..378fe6d 100644 --- a/output/outmac.c +++ b/output/outmacho.c @@ -32,7 +32,7 @@ * ----------------------------------------------------------------------- */ /* - * outmac.c output routines for the Netwide Assembler to produce + * outmacho.c output routines for the Netwide Assembler to produce * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files */ |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-13 05:21:20
|
Commit-ID: 941356b2ca5499469ec31427b18019b5456b7606 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=941356b2ca5499469ec31427b18019b5456b7606 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 12 Feb 2016 15:06:23 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 12 Feb 2016 15:06:23 -0800 outmac: generate section-relative relocations for local symbols We generate section-relative relocations for local symbols for all the other output formats, and we should do the same for MachO; this was done in MachO-32 but not in MachO-64, presumably because the MachO spec implies that such relocations shouldn't exist in 64-bit code. They are indeed rare, but that is a programmer's decision, and the spec is clear that they are legal. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmac.c | 55 +++++++++++++------------------------------------------ 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/output/outmac.c b/output/outmac.c index dc1111d..a2209c6 100644 --- a/output/outmac.c +++ b/output/outmac.c @@ -328,26 +328,6 @@ static uint8_t get_section_fileindex_by_index(const int32_t index) return NO_SECT; } -static struct symbol *get_closest_section_symbol_by_offset(uint8_t fileindex, int64_t offset) -{ - struct symbol *nearest = NULL; - struct symbol *sym; - - for (sym = syms; sym; sym = sym->next) { - if ((sym->sect != NO_SECT) && (sym->sect == fileindex)) { - if ((int64_t)sym->value > offset) - break; - nearest = sym; - } - } - - if (!nearest) - nasm_error(ERR_FATAL, "No section for index %x offset %llx found\n", - fileindex, (long long)offset); - - return nearest; -} - /* * Special section numbers which are used to define Mach-O special * symbols, which can be used with WRT to provide PIC relocation @@ -390,16 +370,11 @@ enum reltype { RL_GOTLOAD, /* X86_64_RELOC_GOT_LOAD */ }; -static int32_t add_reloc(struct section *sect, int32_t section, - enum reltype reltype, int bytes, int64_t reloff) +static void add_reloc(struct section *sect, int32_t section, + enum reltype reltype, int bytes) { struct reloc *r; - struct symbol *sym; int32_t fi; - int32_t adjustment = 0; - - if (section == NO_SEG) - return 0; /* NeXT as puts relocs in reversed order (address-wise) into the ** files, so we do the same, doesn't seem to make much of a @@ -427,20 +402,19 @@ static int32_t add_reloc(struct section *sect, int32_t section, switch (reltype) { case RL_ABS: if (section == NO_SEG) { - /* intra-section */ + /* absolute (can this even happen?) */ + r->ext = 0; r->snum = R_ABS; } else { /* inter-section */ fi = get_section_fileindex_by_index(section); - if (fi == NO_SECT) { /* external */ r->snum = raa_read(extsyms, section); } else { /* local */ - sym = get_closest_section_symbol_by_offset(fi, reloff); - r->snum = sym->initial_snum; - adjustment = sym->value; + r->ext = 0; + r->snum = fi; } } break; @@ -461,9 +435,8 @@ static int32_t add_reloc(struct section *sect, int32_t section, r->snum = raa_read(extsyms, section); } else { /* local */ - sym = get_closest_section_symbol_by_offset(fi, reloff); - r->snum = sym->initial_snum; - adjustment = sym->value; + r->ext = 0; + r->snum = fi; } } break; @@ -487,8 +460,6 @@ static int32_t add_reloc(struct section *sect, int32_t section, } ++sect->nreloc; - - return adjustment; } static void macho_output(int32_t secto, const void *data, @@ -564,7 +535,7 @@ static void macho_output(int32_t secto, const void *data, nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support" " 32-bit absolute addresses"); } else { - addr -= add_reloc(s, section, RL_ABS, asize, addr); + add_reloc(s, section, RL_ABS, asize); } } else { nasm_error(ERR_NONFATAL, "Mach-O format does not support" @@ -595,7 +566,7 @@ static void macho_output(int32_t secto, const void *data, " this use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } else { - addr -= add_reloc(s, section, RL_REL, 2, addr); + add_reloc(s, section, RL_REL, 2); } WRITESHORT(p, addr); @@ -613,7 +584,7 @@ static void macho_output(int32_t secto, const void *data, " section base references"); } else if (wrt == NO_SEG) { /* Plain relative relocation */ - addr -= add_reloc(s, section, RL_REL, 4, addr); + add_reloc(s, section, RL_REL, 4); } else if (wrt == macho_gotpcrel_sect) { if (s->data->datalen > 1) { /* Retrieve instruction opcode */ @@ -623,10 +594,10 @@ static void macho_output(int32_t secto, const void *data, } if (gotload == 0x8B) { /* Check for MOVQ Opcode -> X86_64_RELOC_GOT_LOAD */ - addr -= add_reloc(s, section, RL_GOTLOAD, 4, addr); + add_reloc(s, section, RL_GOTLOAD, 4); } else { /* X86_64_RELOC_GOT */ - addr -= add_reloc(s, section, RL_GOT, 4, addr); + add_reloc(s, section, RL_GOT, 4); } } else { nasm_error(ERR_NONFATAL, "Mach-O format does not support" |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-12 21:51:37
|
Commit-ID: ca351fa1756a47d70b9fa7db6fe6ad8c9ab0d8c6 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ca351fa1756a47d70b9fa7db6fe6ad8c9ab0d8c6 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 12 Feb 2016 13:46:39 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 12 Feb 2016 13:49:45 -0800 assemble.c: when converting an address to RAWDATA, need to update size When converting an address to RAWDATA we have to copy the address size into the size variable, as the size variable may be negative. Signed-off-by: H. Peter Anvin <hp...@li...> --- assemble.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assemble.c b/assemble.c index acaf24b..ed8b9f8 100644 --- a/assemble.c +++ b/assemble.c @@ -357,7 +357,7 @@ static void out(int64_t offset, int32_t segto, const void *data, WRITEADDR(q, *(int64_t *)data, asize); data = p; type = OUT_RAWDATA; - + size = asize; asize = 0; /* No longer an address */ } @@ -380,12 +380,13 @@ static void out(int64_t offset, int32_t segto, const void *data, errfunc(ERR_NONFATAL, "%d-bit signed relocation unsupported by output format %s\n", asize << 3, outfmt->shortname); + size = asize; } else { errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC, "%d-bit unsigned relocation zero-extended from %d bits\n", asize << 3, outfmt->maxbits); outfmt->output(segto, data, type, amax, segment, wrt); - size -= amax; + size = asize - amax; } data = zero_buffer; type = OUT_RAWDATA; |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-12 21:39:17
|
Commit-ID: fc1a7ad66296e13652ea6faca009bbd9ce5c26f6 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=fc1a7ad66296e13652ea6faca009bbd9ce5c26f6 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 12 Feb 2016 13:36:37 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 12 Feb 2016 13:36:37 -0800 outmac: correct the format name for macho32 The name for the macho32 output format was incorrectly set to macho64, which means neither macho32 nor macho64 worked correctly. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmac.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/output/outmac.c b/output/outmac.c index 18bbf49..dc1111d 100644 --- a/output/outmac.c +++ b/output/outmac.c @@ -32,8 +32,8 @@ * ----------------------------------------------------------------------- */ /* - * outmac64.c output routines for the Netwide Assembler to produce - * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files + * outmac.c output routines for the Netwide Assembler to produce + * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files */ /* Most of this file is, like Mach-O itself, based on a.out. For more @@ -1499,7 +1499,7 @@ static void macho32_init(void) struct ofmt of_macho32 = { "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files", - "macho64", + "macho32", 0, 32, null_debug_arr, |
From: nasm-bot f. C. G. <gor...@gm...> - 2016-02-12 18:54:20
|
Commit-ID: f8d52b655eee94fd6620010a25cba068245bd689 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=f8d52b655eee94fd6620010a25cba068245bd689 Author: Cyrill Gorcunov <gor...@gm...> AuthorDate: Fri, 12 Feb 2016 21:50:38 +0300 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Fri, 12 Feb 2016 21:50:38 +0300 output: outmac -- Fix few nits during merge - typo in @if statement - unused @originalIndex Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- output/outmac.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/output/outmac.c b/output/outmac.c index 9c6e935..18bbf49 100644 --- a/output/outmac.c +++ b/output/outmac.c @@ -646,7 +646,7 @@ static void macho_output(int32_t secto, const void *data, static int32_t macho_section(char *name, int pass, int *bits) { - int32_t index, originalIndex; + int32_t index; char *sectionAttributes; struct sectmap *sm; struct section *s; @@ -669,8 +669,7 @@ static int32_t macho_section(char *name, int pass, int *bits) char *currentAttribute; /* try to find section with that name */ - originalIndex = index = get_section_index_by_name(sm->segname, - sm->sectname); + index = get_section_index_by_name(sm->segname, sm->sectname); /* create it if it doesn't exist yet */ if (index == -1) { @@ -844,7 +843,7 @@ static void macho_sectalign(int32_t seg, unsigned int value) return; align = alignlog2_32(value); - if (s->align < align); + if (s->align < align) s->align = align; } |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 11:27:17
|
Commit-ID: b13df02490700899de69b062d0704e97d0798543 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=b13df02490700899de69b062d0704e97d0798543 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 03:23:25 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 03:23:25 -0800 outmac: allow section alignment to be declared more than once Allow section alignment to be declared more than once, with different values. The strictest alignment value via either a section or sectalign directive becomes the controlling parameter. Signed-off-by: H. Peter Anvin <hp...@zy...> --- output/outmac.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/output/outmac.c b/output/outmac.c index 1a1896d..9c6e935 100644 --- a/output/outmac.c +++ b/output/outmac.c @@ -707,14 +707,14 @@ static int32_t macho_section(char *name, int pass, int *bits) newAlignment = alignlog2_32(value); if (0 != *end) { - nasm_error(ERR_PANIC, + nasm_error(ERR_FATAL, "unknown or missing alignment value \"%s\" " "specified for section \"%s\"", currentAttribute + 6, name); return NO_SEG; } else if (0 > newAlignment) { - nasm_error(ERR_PANIC, + nasm_error(ERR_FATAL, "alignment of %d (for section \"%s\") is not " "a power of two", value, @@ -722,24 +722,12 @@ static int32_t macho_section(char *name, int pass, int *bits) return NO_SEG; } - if ((-1 != originalIndex) - && (s->align != newAlignment) - && (s->align != -1)) { - nasm_error(ERR_PANIC, - "section \"%s\" has already been specified " - "with alignment %d, conflicts with new " - "alignment of %d", - name, - (1 << s->align), - value); - return NO_SEG; - } - - s->align = newAlignment; + if (s->align < newAlignment) + s->align = newAlignment; } else if (!nasm_stricmp("data", currentAttribute)) { /* Do nothing; 'data' is implicit */ } else { - nasm_error(ERR_PANIC, + nasm_error(ERR_FATAL, "unknown section attribute %s for section %s", currentAttribute, name); @@ -752,7 +740,7 @@ static int32_t macho_section(char *name, int pass, int *bits) } } - nasm_error(ERR_PANIC, "invalid section name %s", name); + nasm_error(ERR_FATAL, "invalid section name %s", name); return NO_SEG; } @@ -845,6 +833,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, static void macho_sectalign(int32_t seg, unsigned int value) { struct section *s; + int align; list_for_each(s, sects) { if (s->index == seg) @@ -854,9 +843,9 @@ static void macho_sectalign(int32_t seg, unsigned int value) if (!s || !is_power2(value)) return; - value = alignlog2_32(value); - if (s->align < (int)value) - s->align = value; + align = alignlog2_32(value); + if (s->align < align); + s->align = align; } static int32_t macho_segbase(int32_t section) |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 11:18:15
|
Commit-ID: 7dcd1a154921d8cce393e276aea643d3439bcef7 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=7dcd1a154921d8cce393e276aea643d3439bcef7 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 03:16:02 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 03:16:02 -0800 outmac: default to bits 32 for macho32 output format Default to 32 bits for macho32; default to 64 bits for macho64. Signed-off-by: H. Peter Anvin <hp...@zy...> --- output/outmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/output/outmac.c b/output/outmac.c index 1df45a3..1a1896d 100644 --- a/output/outmac.c +++ b/output/outmac.c @@ -653,9 +653,9 @@ static int32_t macho_section(char *name, int pass, int *bits) (void)pass; - /* Default to 64 bits. */ + /* Default to the appropriate number of bits. */ if (!name) { - *bits = 64; + *bits = fmt->ptrsize << 3; name = ".text"; sectionAttributes = NULL; } else { |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 11:15:25
|
Commit-ID: c635497870ade8eb5c028e68278581879b04d52e Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=c635497870ade8eb5c028e68278581879b04d52e Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 03:04:41 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 03:04:41 -0800 Merge the macho32 and macho64 (outmac32/64) backends Merge the two Mach-O backends for cleanliness and maintainability. This should also make the recent fixes to MachO-64 available in MachO-32. Signed-off-by: H. Peter Anvin <hp...@zy...> --- Makefile.in | 12 +- Mkfiles/msvc.mak | 12 +- Mkfiles/netware.mak | 11 +- Mkfiles/openwcom.mak | 12 +- Mkfiles/owlinux.mak | 12 +- output/{outmac64.c => outmac.c} | 577 +++++++++-------- output/outmac32.c | 1330 --------------------------------------- 7 files changed, 340 insertions(+), 1626 deletions(-) diff --git a/Makefile.in b/Makefile.in index e788547..ac5521a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,8 +84,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ - output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \ - output/outmac64.$(O) \ + output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) \ md5c.$(O) output/codeview.$(O) \ preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ @@ -404,12 +403,9 @@ output/outieee.$(O): output/outieee.c compiler.h config.h directiv.h \ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h \ tables.h -output/outmac32.$(O): output/outmac32.c compiler.h config.h directiv.h \ - eval.h insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ - pptok.h preproc.h raa.h regs.h saa.h tables.h -output/outmac64.$(O): output/outmac64.c compiler.h config.h directiv.h \ - insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ - pptok.h preproc.h raa.h regs.h saa.h tables.h +output/outmac.$(O): output/outmac.c compiler.h config.h directiv.h insnsi.h \ + nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ + preproc.h raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ pptok.h preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index f7d78b3..b220a0d 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -55,8 +55,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ - output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \ - output/outmac64.$(O) \ + output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) \ md5c.$(O) output/codeview.$(O) \ preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ @@ -320,12 +319,9 @@ output/outieee.$(O): output/outieee.c compiler.h directiv.h insnsi.h nasm.h \ regs.h tables.h output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h -output/outmac32.$(O): output/outmac32.c compiler.h directiv.h eval.h \ - insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ - pptok.h preproc.h raa.h regs.h saa.h tables.h -output/outmac64.$(O): output/outmac64.c compiler.h directiv.h insnsi.h \ - nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h +output/outmac.$(O): output/outmac.c compiler.h directiv.h insnsi.h nasm.h \ + nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \ + raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 68741ba..66e1115 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -42,8 +42,7 @@ NASM = nasm.o nasmlib.o ver.o \ outelf.o outelf32.o outelf64.o \ outelfx32.o \ outobj.o outas86.o outrdf2.o \ - outdbg.o outieee.o outmac32.o \ - outmac64.o \ + outdbg.o outieee.o outmac.o \ md5c.o codeview.o \ preproc.o quote.o pptok.o \ macros.o listing.o eval.o exprlib.o stdscan.o \ @@ -224,12 +223,8 @@ outieee.o: outieee.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h tables.h outlib.o: outlib.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h outlib.h pptok.h preproc.h regs.h tables.h -outmac32.o: outmac32.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \ - nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \ - tables.h -outmac64.o: outmac64.c compiler.h config.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \ - tables.h +outmac.o: outmac.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \ + opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h tables.h outobj.o: outobj.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h \ tables.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 91a7d2f..c673c47 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -58,8 +58,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) & output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) & output/outelfx32.$(O) & output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) & - output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) & - output/outmac64.$(O) & + output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) & md5c.$(O) output/codeview.$(O) & preproc.$(O) quote.$(O) pptok.$(O) & macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) & @@ -371,12 +370,9 @@ output/outieee.$(O): output/outieee.c compiler.h config.h directiv.h & output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h & nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h & tables.h -output/outmac32.$(O): output/outmac32.c compiler.h config.h directiv.h & - eval.h insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & - pptok.h preproc.h raa.h regs.h saa.h tables.h -output/outmac64.$(O): output/outmac64.c compiler.h config.h directiv.h & - insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & - pptok.h preproc.h raa.h regs.h saa.h tables.h +output/outmac.$(O): output/outmac.c compiler.h config.h directiv.h insnsi.h & + nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h & + preproc.h raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h & insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & pptok.h preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index a7d0d18..2a6f899 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -69,8 +69,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelf.$(O) output/outelf32.$(O) output/outelf64.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ - output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \ - output/outmac64.$(O) \ + output/outdbg.$(O) output/outieee.$(O) output/outmac.$(O) \ md5c.$(O) output/codeview.$(O) \ preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ @@ -334,12 +333,9 @@ output/outieee.$(O): output/outieee.c compiler.h directiv.h insnsi.h nasm.h \ regs.h tables.h output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h -output/outmac32.$(O): output/outmac32.c compiler.h directiv.h eval.h \ - insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ - pptok.h preproc.h raa.h regs.h saa.h tables.h -output/outmac64.$(O): output/outmac64.c compiler.h directiv.h insnsi.h \ - nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h +output/outmac.$(O): output/outmac.c compiler.h directiv.h insnsi.h nasm.h \ + nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h preproc.h \ + raa.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h diff --git a/output/outmac64.c b/output/outmac.c similarity index 80% rename from output/outmac64.c rename to output/outmac.c index cc8f6ba..75a7838 100644 --- a/output/outmac64.c +++ b/output/outmac.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -54,26 +54,32 @@ #include "output/outform.h" #include "output/outlib.h" -#if defined(OF_MACHO64) +#if defined(OF_MACHO) || defined(OF_MACHO64) /* Mach-O in-file header structure sizes */ -#define MACHO_HEADER64_SIZE (32) -#define MACHO_SEGCMD64_SIZE (72) -#define MACHO_SECTCMD64_SIZE (80) -#define MACHO_SYMCMD_SIZE (24) -#define MACHO_NLIST64_SIZE (16) -#define MACHO_RELINFO64_SIZE (8) -#define MACHO_DATA_IN_CODE_CMD_SIZE (16) +#define MACHO_HEADER_SIZE 28 +#define MACHO_SEGCMD_SIZE 56 +#define MACHO_SECTCMD_SIZE 68 +#define MACHO_SYMCMD_SIZE 24 +#define MACHO_NLIST_SIZE 12 +#define MACHO_RELINFO_SIZE 8 + +#define MACHO_HEADER64_SIZE 32 +#define MACHO_SEGCMD64_SIZE 72 +#define MACHO_SECTCMD64_SIZE 80 +#define MACHO_NLIST64_SIZE 16 /* Mach-O file header values */ -#define MH_MAGIC_64 (0xfeedfacf) -#define CPU_TYPE_X86_64 (0x01000007) /* x86-64 platform */ -#define CPU_SUBTYPE_I386_ALL (3) /* all-x86 compatible */ -#define MH_OBJECT (0x1) /* object file */ +#define MH_MAGIC 0xfeedface +#define MH_MAGIC_64 0xfeedfacf +#define CPU_TYPE_I386 7 /* x86 platform */ +#define CPU_TYPE_X86_64 0x01000007 /* x86-64 platform */ +#define CPU_SUBTYPE_I386_ALL 3 /* all-x86 compatible */ +#define MH_OBJECT 0x1 /* object file */ -#define LC_SEGMENT_64 (0x19) /* segment load command */ -#define LC_SYMTAB (0x2) /* symbol table load command */ -#define LC_DATA_IN_CODE (0x29) /* data in code command */ +#define LC_SEGMENT 0x1 /* 32-bit segment load cmd */ +#define LC_SEGMENT_64 0x19 /* 64-bit segment load cmd */ +#define LC_SYMTAB 0x2 /* symbol table load command */ #define VM_PROT_NONE (0x00) #define VM_PROT_READ (0x01) @@ -83,6 +89,46 @@ #define VM_PROT_DEFAULT (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE) #define VM_PROT_ALL (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE) +struct macho_fmt { + uint32_t ptrsize; /* Pointer size in bytes */ + uint32_t mh_magic; /* Which magic number to use */ + uint32_t cpu_type; /* Which CPU type */ + uint32_t lc_segment; /* Which segment load command */ + uint32_t header_size; /* Header size */ + uint32_t segcmd_size; /* Segment command size */ + uint32_t sectcmd_size; /* Section command size */ + uint32_t nlist_size; /* Nlist (symbol) size */ +}; + +static const struct macho_fmt macho32_fmt = { + 4, + MH_MAGIC, + CPU_TYPE_I386, + LC_SEGMENT, + MACHO_HEADER_SIZE, + MACHO_SEGCMD_SIZE, + MACHO_SECTCMD_SIZE, + MACHO_NLIST_SIZE +}; + +static const struct macho_fmt macho64_fmt = { + 8, + MH_MAGIC_64, + CPU_TYPE_X86_64, + LC_SEGMENT_64, + MACHO_HEADER64_SIZE, + MACHO_SEGCMD64_SIZE, + MACHO_SECTCMD64_SIZE, + MACHO_NLIST64_SIZE +}; + +static const struct macho_fmt *fmt; + +static void fwriteptr(uint64_t data, FILE * fp) +{ + fwriteaddr(data, fmt->ptrsize, fp); +} + struct section { /* nasm internal data */ struct section *next; @@ -231,10 +277,13 @@ static uint64_t rel_padcnt = 0; xdst[sizeof(xdst) - 1] = '\0'; /* proper null-termination */ #define alignint32_t(x) \ - ALIGN(x, sizeof(int32_t)) /* align x to int32_t boundary */ + ALIGN(x, sizeof(int32_t)) /* align x to int32_t boundary */ #define alignint64_t(x) \ - ALIGN(x, sizeof(int64_t)) /* align x to int64_t boundary */ + ALIGN(x, sizeof(int64_t)) /* align x to int64_t boundary */ + +#define alignptr(x) \ + ALIGN(x, fmt->ptrsize) /* align x to output format width */ static void debug_reloc (struct reloc *); static void debug_section_relocs (struct section *) _unused; @@ -330,8 +379,6 @@ static int32_t macho_gotpcrel_sect; static void macho_init(void) { - char zero = 0; - sects = NULL; sectstail = §s; @@ -345,14 +392,9 @@ static void macho_init(void) extsyms = raa_init(); strs = saa_init(1L); - /* string table starts with a zero byte - don't ask why */ - saa_wbytes(strs, &zero, sizeof(char)); + /* string table starts with a zero byte so index 0 is an empty string */ + saa_wbytes(strs, zero_buffer, 1); strslen = 1; - - /* add special symbol for ..gotpcrel */ - macho_gotpcrel_sect = seg_alloc(); - macho_gotpcrel_sect++; - define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false); } static void sect_write(struct section *sect, @@ -362,14 +404,25 @@ static void sect_write(struct section *sect, sect->size += len; } +enum reltype { + RL_ABS, /* Absolute relocation */ + RL_REL, /* Relative relocation */ + RL_SUB, /* X86_64_RELOC_SUBTRACT */ + RL_GOT, /* X86_64_RELOC_GOT */ + RL_GOTLOAD, /* X86_64_RELOC_GOT_LOAD */ +}; + static int32_t add_reloc(struct section *sect, int32_t section, - int pcrel, int bytes, int64_t reloff) + enum reltype reltype, int bytes, int64_t reloff) { struct reloc *r; struct symbol *sym; int32_t fi; int32_t adjustment = 0; + if (section == NO_SEG) + return 0; + /* NeXT as puts relocs in reversed order (address-wise) into the ** files, so we do the same, doesn't seem to make much of a ** difference either way */ @@ -383,97 +436,81 @@ static int32_t add_reloc(struct section *sect, int32_t section, ** bit by accident */ r->addr = sect->size & ~R_SCATTERED; r->ext = 1; - r->pcrel = (pcrel ? 1 : 0); /* match byte count 1, 2, 4, 8 to length codes 0, 1, 2, 3 respectively */ - switch(bytes){ - case 1: - r->length = 0; - break; - case 2: - r->length = 1; - break; - case 4: - r->length = 2; - break; - case 8: - r->length = 3; - break; - default: - break; - } + r->length = ilog2_32(bytes); /* set default relocation values */ - r->type = 0; // X86_64_RELOC_UNSIGNED - r->snum = R_ABS; // Absolute Symbol (indicates no relocation) - - /* absolute relocation */ - if (pcrel == 0) { - - /* intra-section */ - if (section == NO_SEG) { - // r->snum = R_ABS; // Set above - + r->type = 0; + r->pcrel = 0; + r->snum = R_ABS; + + /* absolute relocation */ + switch (reltype) { + case RL_ABS: + if (section == NO_SEG) { + /* intra-section */ + r->snum = R_ABS; + } else { + /* inter-section */ + fi = get_section_fileindex_by_index(section); + + if (fi == NO_SECT) { + /* external */ + r->snum = raa_read(extsyms, section); + } else { + /* local */ + sym = get_closest_section_symbol_by_offset(fi, reloff); + r->snum = sym->initial_snum; + adjustment = sym->value; + } + } + break; + + case RL_REL: + r->pcrel = 1; + if (section == NO_SEG) { + /* intra-section */ + r->type = 1; // X86_64_RELOC_SIGNED + } else { /* inter-section */ - } else { - fi = get_section_fileindex_by_index(section); - - /* external */ - if (fi == NO_SECT) { - r->snum = raa_read(extsyms, section); - - /* local */ - } else { - sym = get_closest_section_symbol_by_offset(fi, reloff); - r->snum = sym->initial_snum; - adjustment = sym->value; - } - } - - /* relative relocation */ - } else if (pcrel == 1) { + r->type = 1; // X86_64_RELOC_SIGNED + fi = get_section_fileindex_by_index(section); - /* intra-section */ - if (section == NO_SEG) { - r->type = 1; // X86_64_RELOC_SIGNED - - /* inter-section */ - } else { - r->type = 1; // X86_64_RELOC_SIGNED - fi = get_section_fileindex_by_index(section); - - /* external */ - if (fi == NO_SECT) { - sect->extreloc = 1; - r->snum = raa_read(extsyms, section); - - /* local */ - } else { - sym = get_closest_section_symbol_by_offset(fi, reloff); - r->snum = sym->initial_snum; - adjustment = sym->value; - } - } - - /* subtractor */ - } else if (pcrel == 2) { - r->pcrel = 0; - r->type = 5; // X86_64_RELOC_SUBTRACTOR - - /* gotpcrel */ - } else if (pcrel == 3) { - r->type = 4; // X86_64_RELOC_GOT - r->snum = macho_gotpcrel_sect; - - /* gotpcrel MOVQ load */ - } else if (pcrel == 4) { - r->type = 3; // X86_64_RELOC_GOT_LOAD - r->snum = macho_gotpcrel_sect; + if (fi == NO_SECT) { + /* external */ + sect->extreloc = 1; + r->snum = raa_read(extsyms, section); + } else { + /* local */ + sym = get_closest_section_symbol_by_offset(fi, reloff); + r->snum = sym->initial_snum; + adjustment = sym->value; + } } + break; + + case RL_SUB: + r->pcrel = 0; + r->type = 5; // X86_64_RELOC_SUBTRACTOR + break; + + case RL_GOT: + r->pcrel = 1; + r->type = 4; // X86_64_RELOC_GOT + r->snum = macho_gotpcrel_sect; + break; + + case RL_GOTLOAD: + r->pcrel = 1; + r->type = 3; // X86_64_RELOC_GOT_LOAD + r->snum = macho_gotpcrel_sect; + break; + } - ++sect->nreloc; + ++sect->nreloc; - return adjustment; + return adjustment; } static void macho_output(int32_t secto, const void *data, @@ -544,25 +581,18 @@ static void macho_output(int32_t secto, const void *data, if (section % 2) { nasm_error(ERR_NONFATAL, "Mach-O format does not support" " section base references"); - } else { - if (wrt == NO_SEG) { - if (asize < 8) { - nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support" - " 32-bit absolute addresses"); - /* - Seemingly, Mach-O's X86_64_RELOC_SUBTRACTOR would require - pre-determined knowledge of where the image base would be, - making it impractical for use in intermediate object files - */ - } else { - addr -= add_reloc(s, section, 0, asize, addr); // X86_64_RELOC_UNSIGNED - } - } else { - nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " this use of WRT"); - } - } + } else if (wrt == NO_SEG) { + if (fmt->ptrsize == 8 && asize != 8) { + nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support" + " 32-bit absolute addresses"); + } else { + addr -= add_reloc(s, section, RL_ABS, asize, addr); } + } else { + nasm_error(ERR_NONFATAL, "Mach-O format does not support" + " this use of WRT"); + } + } p = mydata; WRITEADDR(p, addr, asize); @@ -571,62 +601,67 @@ static void macho_output(int32_t secto, const void *data, } case OUT_REL2ADR: - p = mydata; - WRITESHORT(p, *(int64_t *)data); + nasm_assert(section != secto); - if (section == secto) - nasm_error(ERR_PANIC, "intra-section OUT_REL2ADR"); + p = mydata; + addr = *(int64_t *)data + 2 - size; - if (section == NO_SEG) { - /* Do nothing */ - } else if (section % 2) { + if (section != NO_SEG && section % 2) { nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " section base references"); - } else { - nasm_error(ERR_NONFATAL, "Unsupported non-32-bit" - " Macho-O relocation [2]"); - } + " section base references"); + } else if (fmt->ptrsize == 8) { + nasm_error(ERR_NONFATAL, "Unsupported non-32-bit" + " Macho-O relocation [2]"); + } else if (wrt != NO_SEG) { + nasm_error(ERR_NONFATAL, "Mach-O format does not support" + " this use of WRT"); + wrt = NO_SEG; /* we can at least _try_ to continue */ + } else { + addr -= add_reloc(s, section, RL_REL, 2, addr); + } - sect_write(s, mydata, 2L); + WRITESHORT(p, addr); + sect_write(s, mydata, 2); break; case OUT_REL4ADR: + nasm_assert(section != secto); + p = mydata; addr = *(int64_t *)data + 4 - size; - if (section == secto) - nasm_error(ERR_PANIC, "intra-section OUT_REL4ADR"); - if (section != NO_SEG && section % 2) { nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " section base references"); - } else { - if (wrt == NO_SEG) { - addr -= add_reloc(s, section, 1, 4, addr); // X86_64_RELOC_SIGNED/BRANCH - } else if (wrt == macho_gotpcrel_sect) { - if (s->data->datalen > 1) { - saa_fread(s->data, s->data->datalen-2, &gotload, 1); // Retrieve Instruction Opcode - } else { - gotload = 0; - } - if (gotload == 0x8B) { // Check for MOVQ Opcode - addr -= add_reloc(s, section, 4, 4, addr); // X86_64_GOT_LOAD (MOVQ load) - } else { - addr -= add_reloc(s, section, 3, 4, addr); // X86_64_GOT - } - } else { - nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " this use of WRT"); - wrt = NO_SEG; /* we can at least _try_ to continue */ - } - } + " section base references"); + } else if (wrt == NO_SEG) { + /* Plain relative relocation */ + addr -= add_reloc(s, section, RL_REL, 4, addr); + } else if (wrt == macho_gotpcrel_sect) { + if (s->data->datalen > 1) { + /* Retrieve instruction opcode */ + saa_fread(s->data, s->data->datalen-2, &gotload, 1); + } else { + gotload = 0; + } + if (gotload == 0x8B) { + /* Check for MOVQ Opcode -> X86_64_RELOC_GOT_LOAD */ + addr -= add_reloc(s, section, RL_GOTLOAD, 4, addr); + } else { + /* X86_64_RELOC_GOT */ + addr -= add_reloc(s, section, RL_GOT, 4, addr); + } + } else { + nasm_error(ERR_NONFATAL, "Mach-O format does not support" + " this use of WRT"); + wrt = NO_SEG; /* we can at least _try_ to continue */ + } WRITELONG(p, addr); - sect_write(s, mydata, 4L); + sect_write(s, mydata, 4); break; default: - nasm_error(ERR_PANIC, "unknown output type?"); + nasm_error(ERR_NONFATAL, "Unrepresentable relocation in Mach-O"); break; } } @@ -796,7 +831,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset, /* get the in-file index of the section the symbol was defined in */ sym->sect = get_section_fileindex_by_index(section); - + /* track the initially allocated symbol number for use in future fix-ups */ sym->initial_snum = nsyms; @@ -1004,8 +1039,7 @@ static void macho_calculate_sizes (void) ** get a pointer to the start of all the raw data */ if (seg_nsects > 0) { ++head_ncmds; - head_sizeofcmds += - MACHO_SEGCMD64_SIZE + seg_nsects * MACHO_SECTCMD64_SIZE; + head_sizeofcmds += fmt->segcmd_size + seg_nsects * fmt->sectcmd_size; } if (nsyms > 0) { @@ -1024,49 +1058,48 @@ static void macho_calculate_sizes (void) static void macho_write_header (void) { - fwriteint32_t(MH_MAGIC_64, ofile); /* magic */ - fwriteint32_t(CPU_TYPE_X86_64, ofile); /* CPU type */ + fwriteint32_t(fmt->mh_magic, ofile); /* magic */ + fwriteint32_t(fmt->cpu_type, ofile); /* CPU type */ fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile); /* CPU subtype */ fwriteint32_t(MH_OBJECT, ofile); /* Mach-O file type */ fwriteint32_t(head_ncmds, ofile); /* number of load commands */ fwriteint32_t(head_sizeofcmds, ofile); /* size of load commands */ - fwriteint32_t(0, ofile); /* no flags */ - fwriteint32_t(0, ofile); /* reserved for future use */ + fwriteint32_t(0, ofile); /* no flags */ + fwritezero(fmt->header_size - 7*4, ofile); /* reserved fields */ } /* Write out the segment load command at offset. */ static uint32_t macho_write_segment (uint64_t offset) { - uint64_t rel_base = alignint64_t (offset + seg_filesize); + uint64_t rel_base = alignptr(offset + seg_filesize); uint32_t s_reloff = 0; struct section *s; - fwriteint32_t(LC_SEGMENT_64, ofile); /* cmd == LC_SEGMENT_64 */ + fwriteint32_t(fmt->lc_segment, ofile); /* cmd == LC_SEGMENT_64 */ /* size of load command including section load commands */ - fwriteint32_t(MACHO_SEGCMD64_SIZE + - seg_nsects * MACHO_SECTCMD64_SIZE, + fwriteint32_t(fmt->segcmd_size + seg_nsects * fmt->sectcmd_size, ofile); /* in an MH_OBJECT file all sections are in one unnamed (name ** all zeros) segment */ fwritezero(16, ofile); - fwriteint64_t(0, ofile); /* in-memory offset */ - fwriteint64_t(seg_vmsize, ofile); /* in-memory size */ - fwriteint64_t(offset, ofile); /* in-file offset to data */ - fwriteint64_t(seg_filesize, ofile); /* in-file size */ + fwriteptr(0, ofile); /* in-memory offset */ + fwriteptr(seg_vmsize, ofile); /* in-memory size */ + fwriteptr(offset, ofile); /* in-file offset to data */ + fwriteptr(seg_filesize, ofile); /* in-file size */ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* maximum vm protection */ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* initial vm protection */ fwriteint32_t(seg_nsects, ofile); /* number of sections */ - fwriteint32_t(0, ofile); /* no flags */ + fwriteint32_t(0, ofile); /* no flags */ /* emit section headers */ for (s = sects; s != NULL; s = s->next) { nasm_write(s->sectname, sizeof(s->sectname), ofile); nasm_write(s->segname, sizeof(s->segname), ofile); - fwriteint64_t(s->addr, ofile); - fwriteint64_t(s->size, ofile); + fwriteptr(s->addr, ofile); + fwriteptr(s->size, ofile); /* dummy data for zerofill sections or proper values */ if ((s->flags & SECTION_TYPE) != S_ZEROFILL) { @@ -1076,33 +1109,29 @@ static uint32_t macho_write_segment (uint64_t offset) offset += s->size; /* Write out section alignment, as a power of two. e.g. 32-bit word alignment would be 2 (2^2 = 4). */ - if (s->align == -1) - s->align = DEFAULT_SECTION_ALIGNMENT; fwriteint32_t(s->align, ofile); /* To be compatible with cctools as we emit a zero reloff if we have no relocations. */ fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile); fwriteint32_t(s->nreloc, ofile); - s_reloff += s->nreloc * MACHO_RELINFO64_SIZE; + s_reloff += s->nreloc * MACHO_RELINFO_SIZE; } else { fwriteint32_t(0, ofile); - fwriteint32_t(0, ofile); /* No alignment?! */ + fwriteint32_t(s->align, ofile); fwriteint32_t(0, ofile); fwriteint32_t(0, ofile); } - - if (s->nreloc) { - s->flags |= S_ATTR_LOC_RELOC; - if (s->extreloc) - s->flags |= S_ATTR_EXT_RELOC; - } + + if (s->nreloc) { + s->flags |= S_ATTR_LOC_RELOC; + if (s->extreloc) + s->flags |= S_ATTR_EXT_RELOC; + } fwriteint32_t(s->flags, ofile); /* flags */ fwriteint32_t(0, ofile); /* reserved */ - fwriteint32_t(0, ofile); /* reserved */ - - fwriteint32_t(0, ofile); /* align */ + fwriteptr(0, ofile); /* reserved */ } rel_padcnt = rel_base - offset; @@ -1136,9 +1165,13 @@ static void macho_write_section (void) { struct section *s, *s2; struct reloc *r; - uint8_t fi, *p, *q, blk[8]; - int32_t len; + uint8_t fi, *p; + int32_t len; int64_t l; + union offset { + uint64_t val; + uint8_t buf[8]; + } blk; for (s = sects; s != NULL; s = s->next) { if ((s->flags & SECTION_TYPE) == S_ZEROFILL) @@ -1150,31 +1183,26 @@ static void macho_write_section (void) * for more information. */ saa_rewind(s->data); for (r = s->relocs; r != NULL; r = r->next) { - len = (int32_t)r->length << 1; - if(len > 4) len = 8; - saa_fread(s->data, r->addr, blk, len); - p = q = blk; - l = *p++; + len = (uint32_t)1 << r->length; + if (len > 4) /* Can this ever be an issue?! */ + len = 8; + blk.val = 0; + saa_fread(s->data, r->addr, blk.buf, len); /* get offset based on relocation type */ - if (r->length > 0) { - l += ((int64_t)*p++) << 8; - - if (r->length > 1) { - l += ((int64_t)*p++) << 16; - l += ((int64_t)*p++) << 24; - } - - if (r->length > 2) { - l += ((int64_t)*p++) << 32; - l += ((int64_t)*p++) << 40; - l += ((int64_t)*p++) << 48; - l += ((int64_t)*p++) << 56; - } - - - } - +#ifdef WORDS_LITTLEENDIAN + l = blk.val; +#else + l = blk.buf[0]; + l += ((int64_t)blk.buf[1]) << 8; + l += ((int64_t)blk.buf[2]) << 16; + l += ((int64_t)blk.buf[3]) << 24; + l += ((int64_t)blk.buf[4]) << 32; + l += ((int64_t)blk.buf[5]) << 40; + l += ((int64_t)blk.buf[6]) << 48; + l += ((int64_t)blk.buf[7]) << 56; +#endif + /* If the relocation is internal add to the current section offset. Otherwise the only value we need is the symbol offset which we already have. The linker takes care @@ -1191,16 +1219,9 @@ static void macho_write_section (void) } /* write new offset back */ - if (r->length == 3) - WRITEDLONG(q, l); - else if (r->length == 2) - WRITELONG(q, l); - else if (r->length == 1) - WRITESHORT(q, l); - else - *q++ = l & 0xFF; - - saa_fwrite(s->data, r->addr, blk, len); + p = blk.buf; + WRITEDLONG(p, l); + saa_fwrite(s->data, r->addr, blk.buf, len); } /* dump the section data to file */ @@ -1208,7 +1229,7 @@ static void macho_write_section (void) saa_fpwrite(s->data, ofile); } - /* pad last section up to reloc entries on int64_t boundary */ + /* pad last section up to reloc entries on pointer boundary */ fwritezero(rel_padcnt, ofile); /* emit relocation entries */ @@ -1239,7 +1260,7 @@ static void macho_write_symtab (void) sym->value += sectstab[sym->sect]->addr; } - fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */ + fwriteptr(sym->value, ofile); /* value (i.e. offset) */ } } @@ -1257,7 +1278,7 @@ static void macho_write_symtab (void) sym->value += sectstab[sym->sect]->addr; } - fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */ + fwriteptr(sym->value, ofile); /* value (i.e. offset) */ } for (i = 0; i < nundefsym; i++) { @@ -1267,13 +1288,14 @@ static void macho_write_symtab (void) nasm_write(&sym->sect, 1, ofile); /* section */ fwriteint16_t(sym->desc, ofile); /* description */ - // Fix up the symbol value now that we know the final section sizes. + /* Fix up the symbol value now that we know the final section + sizes. */ if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) { nasm_assert(sym->sect <= seg_nsects); sym->value += sectstab[sym->sect]->addr; } - fwriteint64_t(sym->value, ofile); // value (i.e. offset) + fwriteptr(sym->value, ofile); /* value (i.e. offset) */ } } @@ -1286,12 +1308,12 @@ static void macho_fixup_relocs (struct reloc *r) while (r != NULL) { if (r->ext) { - for (sym = syms; sym != NULL; sym = sym->next) { + for (sym = syms; sym != NULL; sym = sym->next) { if (sym->initial_snum == r->snum) { - r->snum = sym->snum; - break; + r->snum = sym->snum; + break; } - } + } } r = r->next; } @@ -1316,14 +1338,14 @@ static void macho_write (void) ** uint32_t flags ** ** segment command - ** uint32_t command type == LC_SEGMENT_64 + ** uint32_t command type == LC_SEGMENT[_64] ** uint32_t size of load command ** (including section load commands) ** char[16] segment name - ** uint64_t in-memory offset - ** uint64_t in-memory size - ** uint64_t in-file offset to data area - ** uint64_t in-file size + ** pointer in-memory offset + ** pointer in-memory size + ** pointer in-file offset to data area + ** pointer in-file size ** (in-memory size excluding zerofill sections) ** int maximum vm protection ** int initial vm protection @@ -1333,8 +1355,8 @@ static void macho_write (void) ** section commands ** char[16] section name ** char[16] segment name - ** uint64_t in-memory offset - ** uint64_t in-memory size + ** pointer in-memory offset + ** pointer in-memory size ** uint32_t in-file offset ** uint32_t alignment ** (irrelevant in MH_OBJECT) @@ -1354,7 +1376,7 @@ static void macho_write (void) ** ** raw section data ** - ** padding to int64_t boundary + ** padding to pointer boundary ** ** relocation data (struct reloc) ** int32_t offset @@ -1370,7 +1392,7 @@ static void macho_write (void) ** [type == extern]) ** int16_t description ** (for stab debugging format) - ** uint64_t value (i.e. file offset) of symbol or stab offset + ** pointer value (i.e. file offset) of symbol or stab offset ** ** string table data ** list of null-terminated strings @@ -1379,7 +1401,7 @@ static void macho_write (void) /* Emit the Mach-O header. */ macho_write_header(); - offset = MACHO_HEADER64_SIZE + head_sizeofcmds; + offset = fmt->header_size + head_sizeofcmds; /* emit the segment load command */ if (seg_nsects > 0) @@ -1394,7 +1416,7 @@ static void macho_write (void) fwriteint32_t(offset, ofile); /* symbol table offset */ fwriteint32_t(nsyms, ofile); /* number of symbol ** table entries */ - offset += nsyms * MACHO_NLIST64_SIZE; + offset += nsyms * fmt->nlist_size; fwriteint32_t(offset, ofile); /* string table offset */ fwriteint32_t(strslen, ofile); /* string table size */ } @@ -1407,7 +1429,7 @@ static void macho_write (void) if (nsyms > 0) macho_write_symtab (); - /* we don't need to pad here since MACHO_NLIST64_SIZE == 16 */ + /* we don't need to pad here, we are already aligned */ /* emit string table */ saa_fpwrite(strs, ofile); @@ -1489,6 +1511,48 @@ static void debug_section_relocs (struct section *s) } } +#ifdef OF_MACHO32 +static void macho32_init(void) +{ + fmt = &macho32_fmt; + macho_init(); + + macho_gotpcrel_sect = NO_SEG; +} + +struct ofmt of_macho32 = { + "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files", + "macho64", + 0, + 32, + null_debug_arr, + &null_debug_form, + macho_stdmac, + macho32_init, + null_setinfo, + macho_output, + macho_symdef, + macho_section, + macho_sectalign, + macho_segbase, + null_directive, + macho_filename, + macho_cleanup +}; +#endif + +#ifdef OF_MACHO64 +static void macho64_init(void) +{ + fmt = &macho64_fmt; + macho_init(); + + /* add special symbol for ..gotpcrel */ + macho_gotpcrel_sect = seg_alloc(); + macho_gotpcrel_sect++; + define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false); +} + struct ofmt of_macho64 = { "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files", "macho64", @@ -1497,7 +1561,7 @@ struct ofmt of_macho64 = { null_debug_arr, &null_debug_form, macho_stdmac, - macho_init, + macho64_init, null_setinfo, macho_output, macho_symdef, @@ -1508,6 +1572,7 @@ struct ofmt of_macho64 = { macho_filename, macho_cleanup }; +#endif #endif diff --git a/output/outmac32.c b/output/outmac32.c deleted file mode 100644 index 0f54510..0000000 --- a/output/outmac32.c +++ /dev/null @@ -1,1330 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 1996-2013 The NASM Authors - All Rights Reserved - * See the file AUTHORS included with the NASM distribution for - * the specific copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following - * conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ----------------------------------------------------------------------- */ - -/* - * outmacho.c output routines for the Netwide Assembler to produce - * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files - */ - -/* Most of this file is, like Mach-O itself, based on a.out. For more - * guidelines see outaout.c. */ - -#include "compiler.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <inttypes.h> - -#include "nasm.h" -#include "nasmlib.h" -#include "saa.h" -#include "raa.h" -#include "eval.h" -#include "output/outform.h" -#include "output/outlib.h" - -#if defined(OF_MACHO32) - -/* Mach-O in-file header structure sizes */ -#define MACHO_HEADER_SIZE (28) -#define MACHO_SEGCMD_SIZE (56) -#define MACHO_SECTCMD_SIZE (68) -#define MACHO_SYMCMD_SIZE (24) -#define MACHO_NLIST_SIZE (12) -#define MACHO_RELINFO_SIZE (8) - -/* Mach-O file header values */ -#define MH_MAGIC (0xfeedface) -#define CPU_TYPE_I386 (7) /* x86 platform */ -#define CPU_SUBTYPE_I386_ALL (3) /* all-x86 compatible */ -#define MH_OBJECT (0x1) /* object file */ - -#define LC_SEGMENT (0x1) /* segment load command */ -#define LC_SYMTAB (0x2) /* symbol table load command */ - -#define VM_PROT_NONE (0x00) -#define VM_PROT_READ (0x01) -#define VM_PROT_WRITE (0x02) -#define VM_PROT_EXECUTE (0x04) - -#define VM_PROT_DEFAULT (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE) -#define VM_PROT_ALL (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE) - -struct section { - /* nasm internal data */ - struct section *next; - struct SAA *data; - int32_t index; - struct reloc *relocs; - int align; - - /* data that goes into the file */ - char sectname[16]; /* what this section is called */ - char segname[16]; /* segment this section will be in */ - uint32_t addr; /* in-memory address (subject to alignment) */ - uint32_t size; /* in-memory and -file size */ - uint32_t nreloc; /* relocation entry count */ - uint32_t flags; /* type and attributes (masked) */ -}; - -#define SECTION_TYPE 0x000000ff /* section type mask */ - -#define S_REGULAR (0x0) /* standard section */ -#define S_ZEROFILL (0x1) /* zerofill, in-memory only */ - -#define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */ -#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some - machine instructions */ -#define S_ATTR_EXT_RELOC 0x00000200 /* section has external - relocation entries */ -#define S_ATTR_LOC_RELOC 0x00000100 /* section has local - relocation entries */ - - -static struct sectmap { - const char *nasmsect; - const char *segname; - const char *sectname; - const int32_t flags; -} sectmap[] = { - {".text", "__TEXT", "__text", S_REGULAR|S_ATTR_SOME_INSTRUCTIONS}, - {".data", "__DATA", "__data", S_REGULAR}, - {".rodata", "__DATA", "__const", S_REGULAR}, - {".bss", "__DATA", "__bss", S_ZEROFILL}, - {NULL, NULL, NULL, 0} -}; - -struct reloc { - /* nasm internal data */ - struct reloc *next; - - /* data that goes into the file */ - int32_t addr; /* op's offset in section */ - unsigned int snum:24, /* contains symbol index if - ** ext otherwise in-file - ** section number */ - pcrel:1, /* relative relocation */ - length:2, /* 0=byte, 1=word, 2=int32_t */ - ext:1, /* external symbol referenced */ - type:4; /* reloc type, 0 for us */ -}; - -#define R_ABS 0 /* absolute relocation */ -#define R_SCATTERED 0x80000000 /* reloc entry is scattered if - ** highest bit == 1 */ - -struct symbol { - /* nasm internal data */ - struct symbol *next; /* next symbol in the list */ - char *name; /* name of this symbol */ - int32_t initial_snum; /* symbol number used above in - reloc */ - int32_t snum; /* true snum for reloc */ - - /* data that goes into the file */ - int32_t strx; /* string table index */ - uint8_t type; /* symbol type */ - uint8_t sect; /* NO_SECT or section number */ - int16_t desc; /* for stab debugging, 0 for us */ - uint32_t value; /* offset of symbol in section */ -}; - -/* symbol type bits */ -#define N_EXT 0x01 /* global or external symbol */ - -#define N_UNDF 0x0 /* undefined symbol | n_sect == */ -#define N_ABS 0x2 /* absolute symbol | NO_SECT */ -#define N_SECT 0xe /* defined symbol, n_sect holds - ** section number */ - -#define N_TYPE 0x0e /* type bit mask */ - -#define DEFAULT_SECTION_ALIGNMENT 0 /* byte (i.e. no) alignment */ - -/* special section number values */ -#define NO_SECT 0 /* no section, invalid */ -#define MAX_SECT 255 /* maximum number of sections */ - -static struct section *sects, **sectstail; -static struct symbol *syms, **symstail; -static uint32_t nsyms; - -/* These variables are set by macho_layout_symbols() to organize - the symbol table and string table in order the dynamic linker - expects. They are then used in macho_write() to put out the - symbols and strings in that order. - - The order of the symbol table is: - local symbols - defined external symbols (sorted by name) - undefined external symbols (sorted by name) - - The order of the string table is: - strings for external symbols - strings for local symbols - */ -static uint32_t ilocalsym = 0; -static uint32_t iextdefsym = 0; -static uint32_t iundefsym = 0; -static uint32_t nlocalsym; -static uint32_t nextdefsym; -static uint32_t nundefsym; -static struct symbol **extdefsyms = NULL; -static struct symbol **undefsyms = NULL; - -static struct RAA *extsyms; -static struct SAA *strs; -static uint32_t strslen; - -/* Global file information. This should be cleaned up into either - a structure or as function arguments. */ -static uint32_t head_ncmds = 0; -static uint32_t head_sizeofcmds = 0; -static uint32_t seg_filesize = 0; -static uint32_t seg_vmsize = 0; -static uint32_t seg_nsects = 0; -static uint32_t rel_padcnt = 0; - - -#define xstrncpy(xdst, xsrc) \ - memset(xdst, '\0', sizeof(xdst)); /* zero out whole buffer */ \ - strncpy(xdst, xsrc, sizeof(xdst)); /* copy over string */ \ - xdst[sizeof(xdst) - 1] = '\0'; /* proper null-termination */ - -#define alignint32_t(x) \ - ALIGN(x, sizeof(int32_t)) /* align x to int32_t boundary */ - -static void debug_reloc (struct reloc *); -static void debug_section_relocs (struct section *) _unused; - -static struct section *get_section_by_name(const char *segname, - const char *sectname) -{ - struct section *s; - - for (s = sects; s != NULL; s = s->next) - if (!strcmp(s->segname, segname) && !strcmp(s->sectname, sectname)) - break; - - return s; -} - -static struct section *get_section_by_index(const int32_t index) -{ - struct section *s; - - for (s = sects; s != NULL; s = s->next) - if (index == s->index) - break; - - return s; -} - -static int32_t get_section_index_by_name(const char *segname, - const char *sectname) -{ - struct section *s; - - for (s = sects; s != NULL; s = s->next) - if (!strcmp(s->segname, segname) && !strcmp(s->sectname, sectname)) - return s->index; - - return -1; -} - -static char *get_section_name_by_index(const int32_t index) -{ - struct section *s; - - for (s = sects; s != NULL; s = s->next) - if (index == s->index) - return s->sectname; - - return NULL; -} - -static uint8_t get_section_fileindex_by_index(const int32_t index) -{ - struct section *s; - uint8_t i = 1; - - for (s = sects; s != NULL && i < MAX_SECT; s = s->next, ++i) - if (index == s->index) - return i; - - if (i == MAX_SECT) - nasm_error(ERR_WARNING, - "too many sections (>255) - clipped by fileindex"); - - return NO_SECT; -} - -static void macho_init(void) -{ - char zero = 0; - - sects = NULL; - sectstail = §s; - - syms = NULL; - symstail = &syms; - nsyms = 0; - nlocalsym = 0; - nextdefsym = 0; - nundefsym = 0; - - extsyms = raa_init(); - strs = saa_init(1L); - - /* string table starts with a zero byte - don't ask why */ - saa_wbytes(strs, &zero, sizeof(char)); - strslen = 1; -} - -static void sect_write(struct section *sect, - const uint8_t *data, uint32_t len) -{ - saa_wbytes(sect->data, data, len); - sect->size += len; -} - -static void add_reloc(struct section *sect, int32_t section, - int pcrel, int bytes) -{ - struct reloc *r; - int32_t fi; - - /* NeXT as puts relocs in reversed order (address-wise) into the - ** files, so we do the same, doesn't seem to make much of a - ** difference either way */ - r = nasm_malloc(sizeof(struct reloc)); - r->next = sect->relocs; - sect->relocs = r; - - /* the current end of the section will be the symbol's address for - ** now, might have to be fixed by macho_fixup_relocs() later on. make - ** sure we don't make the symbol scattered by setting the highest - ** bit by accident */ - r->addr = sect->size & ~R_SCATTERED; - r->ext = 0; - r->pcrel = pcrel; - - /* match byte count 1, 2, 4 to length codes 0, 1, 2 respectively */ - r->length = bytes >> 1; - - /* vanilla relocation (GENERIC_RELOC_VANILLA) */ - r->type = 0; - - if (section == NO_SEG) { - /* absolute local symbol if no section index given */ - r->snum = R_ABS; - } else { - fi = get_section_fileindex_by_index(section); - - if (fi == NO_SECT) { - /* external symbol if no section with that index known, - ** symbol number was saved in macho_symdef() */ - r->snum = raa_read(extsyms, section); - r->ext = 1; - } else { - /* local symbol in section fi */ - r->snum = fi; - } - } - - ++sect->nreloc; -} - -static void macho_output(int32_t secto, const void *data, - enum out_type type, uint64_t size, - int32_t section, int32_t wrt) -{ - struct section *s, *sbss; - int32_t addr; - uint8_t mydata[8], *p; - - if (wrt != NO_SEG) { - wrt = NO_SEG; - nasm_error(ERR_NONFATAL, "WRT not supported by Mach-O output format"); - /* continue to do _something_ */ - } - - if (secto == NO_SEG) { - if (type != OUT_RESERVE) - nasm_error(ERR_NONFATAL, "attempt to assemble code in " - "[ABSOLUTE] space"); - - return; - } - - s = get_section_by_index(secto); - - if (s == NULL) { - nasm_error(ERR_WARNING, "attempt to assemble code in" - " section %d: defaulting to `.text'", secto); - s = get_section_by_name("__TEXT", "__text"); - - /* should never happen */ - if (s == NULL) - nasm_error(ERR_PANIC, "text section not found"); - } - - sbss = get_section_by_name("__DATA", "__bss"); - - if (s == sbss && type != OUT_RESERVE) { - nasm_error(ERR_WARNING, "attempt to initialize memory in the" - " BSS section: ignored"); - s->size += realsize(type, size); - return; - } - - memset(mydata, 0, sizeof(mydata)); - - switch (type) { - case OUT_RESERVE: - if (s != sbss) { - nasm_error(ERR_WARNING, "uninitialized space declared in" - " %s section: zeroing", - get_section_name_by_index(secto)); - - sect_write(s, NULL, size); - } else - s->size += size; - - break; - - case OUT_RAWDATA: - if (section != NO_SEG) - nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); - - sect_write(s, data, size); - break; - - case OUT_ADDRESS: - { - int asize = abs((int)size); - - addr = *(int64_t *)data; - - if (section != NO_SEG) { - if (section % 2) { - nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " section base references"); - } else - add_reloc(s, section, 0, asize); - } - - p = mydata; - WRITEADDR(p, addr, asize); - sect_write(s, mydata, asize); - break; - } - - case OUT_REL2ADR: - if (section == secto) - nasm_error(ERR_PANIC, "intra-section OUT_REL2ADR"); - - if (section != NO_SEG && section % 2) { - nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " section base references"); - } else - add_reloc(s, section, 1, 2); - - p = mydata; - WRITESHORT(p, *(int32_t *)data - (size + s->size)); - sect_write(s, mydata, 2L); - break; - - case OUT_REL4ADR: - if (section == secto) - nasm_error(ERR_PANIC, "intra-section OUT_REL4ADR"); - - if (section != NO_SEG && section % 2) { - nasm_error(ERR_NONFATAL, "Mach-O format does not support" - " section base references"); - } else - add_reloc(s, section, 1, 4); - - p = mydata; - WRITELONG(p, *(int32_t *)data - (size + s->size)); - sect_write(s, mydata, 4L); - break; - - default: - nasm_error(ERR_PANIC, "unknown output type?"); - break; - } -} - -static int32_t macho_section(char *name, int pass, int *bits) -{ - int32_t index, originalIndex; - char *sectionAttributes; - struct sectmap *sm; - struct section *s; - - (void)pass; - - /* Default to 32 bits. */ - if (!name) { - *bits = 32; - name = ".text"; - sectionAttributes = NULL; - } else { - sectionAttributes = name; - name = nasm_strsep(§ionAttributes, " \t"); - } - - for (sm = sectmap; sm->nasmsect != NULL; ++sm) { - /* make lookup into section name translation table */ - if (!strcmp(name, sm->nasmsect)) { - char *currentAttribute; - - /* try to find section with that name */ - originalIndex = index = get_section_index_by_name(sm->segname, - sm->sectname); - - /* create it if it doesn't exist yet */ - if (index == -1) { - s = *sectstail = nasm_malloc(sizeof(struct section)); - s->next = NULL; - sectstail = &s->next; - - s->data = saa_init(1L); - s->index = seg_alloc(); - s->relocs = NULL; - s->align = -1; - - xstrncpy(s->segname, sm->segname); - xstrncpy(s->sectname, sm->sectname); - s->size = 0; - s->nreloc = 0; - s->flags = sm->flags; - - index = s->index; - } else { - s = get_section_by_index(index); - } - - while ((NULL != sectionAttributes) - && (currentAttribute = nasm_strsep(§ionAttributes, " \t"))) { - if (0 != *currentAttribute) { - if (!nasm_strnicmp("align=", currentAttribute, 6)) { - char *end; - int newAlignment, value; - - value = strtoul(currentAttribute + 6, (char**)&end, 0); - newAlignment = alignlog2_32(value); - - if (0 != *end) { - nasm_error(ERR_PANIC, - "unknown or missing alignment value \"%s\" " - "specified for section \"%s\"", - currentAttribute + 6, - name); - return NO_SEG; - } else if (0 > newAlignment) { - nasm_error(ERR_PANIC, - "alignment of %d (for section \"%s\") is not " - "a power of two", - value, - name); - return NO_SEG; - } - - if ((-1 != originalIndex) - && (s->align != newAlignment) - && (s->align != -1)) { - nasm_error(ERR_PANIC, - "section \"%s\" has already been specified " - "with alignment %d, conflicts with new " - "alignment of %d", - name, - (1 << s->align), - value); - return NO_SEG; - } - - s->align = newAlignment; - } else if (!nasm_stricmp("data", currentAttribute)) { - /* Do nothing; 'data' is implicit */ - } else { - nasm_error(ERR_PANIC, - "unknown section attribute %s for section %s", - currentAttribute, - name); - return NO_SEG; - } - } - } - - return index; - } - } - - nasm_error(ERR_PANIC, "invalid section name %s", name); - return NO_SEG; -} - -static void macho_symdef(char *name, int32_t section, int64_t offset, - int is_global, char *special) -{ - struct symbol *sym; - - if (special) { - nasm_error(ERR_NONFATAL, "The Mach-O output format does " - "not support any special symbol types"); - return; - } - - if (is_global == 3) { - nasm_error(ERR_NONFATAL, "The Mach-O format does not " - "(yet) support forward reference fixups."); - return; - } - - sym = *symstail = nasm_malloc(sizeof(struct symbol)); - sym->next = NULL; - symstail = &sym->next; - - sym->name = name; - sym->strx = strslen; - sym->type = 0; - sym->desc = 0; - sym->value = offset; - sym->initial_snum = -1; - - /* external and common symbols get N_EXT */ - if (is_global != 0) - sym->type |= N_EXT; - - if (section == NO_SEG) { - /* symbols in no section get absolute */ - sym->type |= N_ABS; - sym->sect = NO_SECT; - } else { - sym->type |= N_SECT; - - /* get the in-file index of the section the symbol was defined in */ - sym->sect = get_section_fileindex_by_index(section); - - if (sym->sect == NO_SECT) { - /* remember symbol number of references to external - ** symbols, this works because every external symbol gets - ** its own section number allocated internally by nasm and - ** can so be used as a key */ - extsyms = raa_write(extsyms, section, nsyms); - sym->initial_snum = nsyms; - - switch (is_global) { - case 1: - case 2: - /* there isn't actually a difference between global - ** and common symbols, both even have their size in - ** sym->value */ - sym->type = N_EXT; - break; - - default: - /* give an error on unfound section if it's not an - ** external or common symbol (assemble_file() does a - ** seg_alloc() on every call for them) */ - nasm_error(ERR_PANIC, "in-file index for section %d not found", - section); - } - } - } - - ++nsyms; -} - -static void macho_sectalign(int32_t seg, unsigned int value) -{ - struct section *s; - - list_for_each(s, sects) { - if (s->index == seg) - break; - } - - if (!s || !is_power2(value)) - return; - - value = alignlog2_32(value); - if (s->align < (int)value) - s->align = value; -} - -static int32_t macho_segbase(int32_t section) -{ - return section; -} - -static void macho_filename(char *inname, char *outname) -{ - standard_extension(inname, outname, ".o"); -} - -extern macros_t macho_stdmac[]; - -/* Comparison function for qsort symbol layout. */ -static int layout_compare (const struct symbol **s1, - const struct symbol **s2) -{ - return (strcmp ((*s1)->name, (*s2)->name)); -} - -/* The native assembler does a few things in a similar function - - * Remove temporary labels - * Sort symbols according to local, external, undefined (by name) - * Order the string table - - We do not remove temporary labels right now. - - numsyms is the total number of symbols we have. strtabsize is the - number entries in the string table. */ - -static void macho_layout_symbols (uint32_t *numsyms, - uint32_t *strtabsize) -{ - struct symbol *sym, **symp; - uint32_t i,j; - - *numsyms = 0; - *strtabsize = sizeof (char); - - symp = &syms; - - while ((sym = *symp)) { - /* Undefined symbols are now external. */ - if (sym->type == N_UNDF) - sym->type |= N_EXT; - - if ((sym->type & N_EXT) == 0) { - sym->snum = *numsyms; - *numsyms = *numsyms + 1; - nlocalsym++; - } - else { - if ((sym->type & N_TYPE) != N_UNDF) - nextdefsym++; - else - nundefsym++; - - /* If we handle debug info we'll want - to check for it here instead of just - adding the symbol to the string table. */ - sym->strx = *strtabsize; - ... [truncated message content] |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 11:15:17
|
Commit-ID: 09b56b421a01863679a9c43e94cc5a675b9add81 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=09b56b421a01863679a9c43e94cc5a675b9add81 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 03:13:00 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 03:13:00 -0800 outmac: move the format definitions down to the format-specific code Move the format definitions down the to where the format-specific initialization code lives. Signed-off-by: H. Peter Anvin <hp...@zy...> --- output/outmac.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/output/outmac.c b/output/outmac.c index 75a7838..1df45a3 100644 --- a/output/outmac.c +++ b/output/outmac.c @@ -100,28 +100,6 @@ struct macho_fmt { uint32_t nlist_size; /* Nlist (symbol) size */ }; -static const struct macho_fmt macho32_fmt = { - 4, - MH_MAGIC, - CPU_TYPE_I386, - LC_SEGMENT, - MACHO_HEADER_SIZE, - MACHO_SEGCMD_SIZE, - MACHO_SECTCMD_SIZE, - MACHO_NLIST_SIZE -}; - -static const struct macho_fmt macho64_fmt = { - 8, - MH_MAGIC_64, - CPU_TYPE_X86_64, - LC_SEGMENT_64, - MACHO_HEADER64_SIZE, - MACHO_SEGCMD64_SIZE, - MACHO_SECTCMD64_SIZE, - MACHO_NLIST64_SIZE -}; - static const struct macho_fmt *fmt; static void fwriteptr(uint64_t data, FILE * fp) @@ -1512,6 +1490,17 @@ static void debug_section_relocs (struct section *s) } #ifdef OF_MACHO32 +static const struct macho_fmt macho32_fmt = { + 4, + MH_MAGIC, + CPU_TYPE_I386, + LC_SEGMENT, + MACHO_HEADER_SIZE, + MACHO_SEGCMD_SIZE, + MACHO_SECTCMD_SIZE, + MACHO_NLIST_SIZE +}; + static void macho32_init(void) { fmt = &macho32_fmt; @@ -1542,6 +1531,17 @@ struct ofmt of_macho32 = { #endif #ifdef OF_MACHO64 +static const struct macho_fmt macho64_fmt = { + 8, + MH_MAGIC_64, + CPU_TYPE_X86_64, + LC_SEGMENT_64, + MACHO_HEADER64_SIZE, + MACHO_SEGCMD64_SIZE, + MACHO_SECTCMD64_SIZE, + MACHO_NLIST64_SIZE +}; + static void macho64_init(void) { fmt = &macho64_fmt; |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 11:12:17
|
Commit-ID: d7043da28199f2a98c202a025c8bccf93329deb9 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=d7043da28199f2a98c202a025c8bccf93329deb9 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 01:32:57 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 01:32:57 -0800 realpath: prefer the buffer size given by pathconf() If realpath(..., NULL) doesn't work, we have to allocate a buffer blindly. Use the value returned from pathconf() in preference from compile-time constants. Signed-off-by: H. Peter Anvin <hp...@zy...> --- realpath.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/realpath.c b/realpath.c index 82adfc9..48b685a 100644 --- a/realpath.c +++ b/realpath.c @@ -80,15 +80,19 @@ char *nasm_realpath(const char *rel_path) int path_max = -1; char *buf; -# ifdef PATH_MAX - path_max = PATH_MAX; /* SUSv2 */ -# elif defined(MAXPATHLEN) - path_max = MAXPATHLEN; /* Solaris */ -# elif defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX) - path_max = pathconf(path, _PC_PATH_MAX); /* POSIX */ -# endif - if (path_max < 0) +#if defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX) + path_max = pathconf(rel_path, _PC_PATH_MAX); /* POSIX */ +#endif + + if (path_max < 0) { +#ifdef PATH_MAX + path_max = PATH_MAX; /* SUSv2 */ +#elif defined(MAXPATHLEN) + path_max = MAXPATHLEN; /* Solaris */ +#else path_max = 65536; /* Crazily high, we hope */ +#endif + } buf = nasm_malloc(path_max); |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 09:30:19
|
Commit-ID: 67db8184b152b7bb734f4298361416c8340b9db3 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=67db8184b152b7bb734f4298361416c8340b9db3 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 01:23:53 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 01:23:53 -0800 macho64: remove -64 suffix from static variables When the macho64 backend was forked, instead of fixing variables which ought to have been static all along, the porter added a -64 suffix to prevent namespace conflict. Fix it by making those variables static. Signed-off-by: H. Peter Anvin <hp...@zy...> --- output/outmac64.c | 68 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index cd045f5..cc8f6ba 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -217,12 +217,12 @@ extern struct ofmt of_macho64; /* Global file information. This should be cleaned up into either a structure or as function arguments. */ -static uint32_t head_ncmds64 = 0; -static uint32_t head_sizeofcmds64 = 0; -static uint64_t seg_filesize64 = 0; -static uint64_t seg_vmsize64 = 0; -static uint32_t seg_nsects64 = 0; -static uint64_t rel_padcnt64 = 0; +static uint32_t head_ncmds = 0; +static uint32_t head_sizeofcmds = 0; +static uint64_t seg_filesize = 0; +static uint64_t seg_vmsize = 0; +static uint32_t seg_nsects = 0; +static uint64_t rel_padcnt = 0; #define xstrncpy(xdst, xsrc) \ @@ -974,7 +974,7 @@ static void macho_calculate_sizes (void) uint64_t newaddr; /* recalculate segment address based on alignment and vm size */ - s->addr = seg_vmsize64; + s->addr = seg_vmsize; /* we need section alignment to calculate final section address */ if (s->align == -1) @@ -983,7 +983,7 @@ static void macho_calculate_sizes (void) newaddr = ALIGN(s->addr, 1 << s->align); s->addr = newaddr; - seg_vmsize64 = newaddr + s->size; + seg_vmsize = newaddr + s->size; /* zerofill sections aren't actually written to the file */ if ((s->flags & SECTION_TYPE) != S_ZEROFILL) { @@ -992,29 +992,29 @@ static void macho_calculate_sizes (void) * bytes; there is a comment in the LLVM source code that * perhaps aligning to pointer size would be better. */ - s->pad = ALIGN(seg_filesize64, 4) - seg_filesize64; - s->offset = seg_filesize64 + s->pad; - seg_filesize64 += s->size + s->pad; + s->pad = ALIGN(seg_filesize, 4) - seg_filesize; + s->offset = seg_filesize + s->pad; + seg_filesize += s->size + s->pad; } - ++seg_nsects64; + ++seg_nsects; } /* calculate size of all headers, load commands and sections to ** get a pointer to the start of all the raw data */ - if (seg_nsects64 > 0) { - ++head_ncmds64; - head_sizeofcmds64 += - MACHO_SEGCMD64_SIZE + seg_nsects64 * MACHO_SECTCMD64_SIZE; + if (seg_nsects > 0) { + ++head_ncmds; + head_sizeofcmds += + MACHO_SEGCMD64_SIZE + seg_nsects * MACHO_SECTCMD64_SIZE; } if (nsyms > 0) { - ++head_ncmds64; - head_sizeofcmds64 += MACHO_SYMCMD_SIZE; + ++head_ncmds; + head_sizeofcmds += MACHO_SYMCMD_SIZE; } /* Create a table of sections by file index to avoid linear search */ - sectstab = nasm_malloc((seg_nsects64 + 1) * sizeof(*sectstab)); + sectstab = nasm_malloc((seg_nsects + 1) * sizeof(*sectstab)); sectstab[0] = NULL; for (s = sects, fi = 1; s != NULL; s = s->next, fi++) sectstab[fi] = s; @@ -1028,8 +1028,8 @@ static void macho_write_header (void) fwriteint32_t(CPU_TYPE_X86_64, ofile); /* CPU type */ fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile); /* CPU subtype */ fwriteint32_t(MH_OBJECT, ofile); /* Mach-O file type */ - fwriteint32_t(head_ncmds64, ofile); /* number of load commands */ - fwriteint32_t(head_sizeofcmds64, ofile); /* size of load commands */ + fwriteint32_t(head_ncmds, ofile); /* number of load commands */ + fwriteint32_t(head_sizeofcmds, ofile); /* size of load commands */ fwriteint32_t(0, ofile); /* no flags */ fwriteint32_t(0, ofile); /* reserved for future use */ } @@ -1038,7 +1038,7 @@ static void macho_write_header (void) static uint32_t macho_write_segment (uint64_t offset) { - uint64_t rel_base = alignint64_t (offset + seg_filesize64); + uint64_t rel_base = alignint64_t (offset + seg_filesize); uint32_t s_reloff = 0; struct section *s; @@ -1046,19 +1046,19 @@ static uint32_t macho_write_segment (uint64_t offset) /* size of load command including section load commands */ fwriteint32_t(MACHO_SEGCMD64_SIZE + - seg_nsects64 * MACHO_SECTCMD64_SIZE, + seg_nsects * MACHO_SECTCMD64_SIZE, ofile); /* in an MH_OBJECT file all sections are in one unnamed (name ** all zeros) segment */ fwritezero(16, ofile); fwriteint64_t(0, ofile); /* in-memory offset */ - fwriteint64_t(seg_vmsize64, ofile); /* in-memory size */ + fwriteint64_t(seg_vmsize, ofile); /* in-memory size */ fwriteint64_t(offset, ofile); /* in-file offset to data */ - fwriteint64_t(seg_filesize64, ofile); /* in-file size */ + fwriteint64_t(seg_filesize, ofile); /* in-file size */ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* maximum vm protection */ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* initial vm protection */ - fwriteint32_t(seg_nsects64, ofile); /* number of sections */ + fwriteint32_t(seg_nsects, ofile); /* number of sections */ fwriteint32_t(0, ofile); /* no flags */ /* emit section headers */ @@ -1105,7 +1105,7 @@ static uint32_t macho_write_segment (uint64_t offset) fwriteint32_t(0, ofile); /* align */ } - rel_padcnt64 = rel_base - offset; + rel_padcnt = rel_base - offset; offset = rel_base + s_reloff; return offset; @@ -1209,7 +1209,7 @@ static void macho_write_section (void) } /* pad last section up to reloc entries on int64_t boundary */ - fwritezero(rel_padcnt64, ofile); + fwritezero(rel_padcnt, ofile); /* emit relocation entries */ for (s = sects; s != NULL; s = s->next) @@ -1235,7 +1235,7 @@ static void macho_write_symtab (void) /* Fix up the symbol value now that we know the final section sizes. */ if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) { - nasm_assert(sym->sect <= seg_nsects64); + nasm_assert(sym->sect <= seg_nsects); sym->value += sectstab[sym->sect]->addr; } @@ -1253,7 +1253,7 @@ static void macho_write_symtab (void) /* Fix up the symbol value now that we know the final section sizes. */ if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) { - nasm_assert(sym->sect <= seg_nsects64); + nasm_assert(sym->sect <= seg_nsects); sym->value += sectstab[sym->sect]->addr; } @@ -1269,7 +1269,7 @@ static void macho_write_symtab (void) // Fix up the symbol value now that we know the final section sizes. if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) { - nasm_assert(sym->sect <= seg_nsects64); + nasm_assert(sym->sect <= seg_nsects); sym->value += sectstab[sym->sect]->addr; } @@ -1379,10 +1379,10 @@ static void macho_write (void) /* Emit the Mach-O header. */ macho_write_header(); - offset = MACHO_HEADER64_SIZE + head_sizeofcmds64; + offset = MACHO_HEADER64_SIZE + head_sizeofcmds; /* emit the segment load command */ - if (seg_nsects64 > 0) + if (seg_nsects > 0) offset = macho_write_segment (offset); else nasm_error(ERR_WARNING, "no sections?"); @@ -1400,7 +1400,7 @@ static void macho_write (void) } /* emit section data */ - if (seg_nsects64 > 0) + if (seg_nsects > 0) macho_write_section (); /* emit symbol table if we have symbols */ |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 09:30:18
|
Commit-ID: 797dc4f01ee8f25708a96e1c8779d463959b73c8 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=797dc4f01ee8f25708a96e1c8779d463959b73c8 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Fri, 12 Feb 2016 01:21:15 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Fri, 12 Feb 2016 01:21:15 -0800 macho: make a bunch of global variables static These variables should never have been anything but static in the first place. Signed-off-by: H. Peter Anvin <hp...@zy...> --- output/outmac32.c | 12 ++++++------ output/outmac64.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/output/outmac32.c b/output/outmac32.c index 8014b7c..0f54510 100644 --- a/output/outmac32.c +++ b/output/outmac32.c @@ -210,12 +210,12 @@ static uint32_t strslen; /* Global file information. This should be cleaned up into either a structure or as function arguments. */ -uint32_t head_ncmds = 0; -uint32_t head_sizeofcmds = 0; -uint32_t seg_filesize = 0; -uint32_t seg_vmsize = 0; -uint32_t seg_nsects = 0; -uint32_t rel_padcnt = 0; +static uint32_t head_ncmds = 0; +static uint32_t head_sizeofcmds = 0; +static uint32_t seg_filesize = 0; +static uint32_t seg_vmsize = 0; +static uint32_t seg_nsects = 0; +static uint32_t rel_padcnt = 0; #define xstrncpy(xdst, xsrc) \ diff --git a/output/outmac64.c b/output/outmac64.c index a12a167..cd045f5 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -217,12 +217,12 @@ extern struct ofmt of_macho64; /* Global file information. This should be cleaned up into either a structure or as function arguments. */ -uint32_t head_ncmds64 = 0; -uint32_t head_sizeofcmds64 = 0; -uint64_t seg_filesize64 = 0; -uint64_t seg_vmsize64 = 0; -uint32_t seg_nsects64 = 0; -uint64_t rel_padcnt64 = 0; +static uint32_t head_ncmds64 = 0; +static uint32_t head_sizeofcmds64 = 0; +static uint64_t seg_filesize64 = 0; +static uint64_t seg_vmsize64 = 0; +static uint32_t seg_nsects64 = 0; +static uint64_t rel_padcnt64 = 0; #define xstrncpy(xdst, xsrc) \ |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 05:16:14
|
Commit-ID: b03d91e6ab7686f5dee77c1e550fda9fd7abbb68 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=b03d91e6ab7686f5dee77c1e550fda9fd7abbb68 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Thu, 11 Feb 2016 21:13:54 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Thu, 11 Feb 2016 21:13:54 -0800 assemble.c: fix the handling of zero-extending unsigned relocations First of all we printed the wrong error message, and second of all we need to set the segments to NO_SEG before passing them to the output format generator. Signed-off-by: H. Peter Anvin <hp...@zy...> --- assemble.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assemble.c b/assemble.c index b1e6821..acaf24b 100644 --- a/assemble.c +++ b/assemble.c @@ -383,12 +383,13 @@ static void out(int64_t offset, int32_t segto, const void *data, } else { errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC, "%d-bit unsigned relocation zero-extended from %d bits\n", - asize << 4, outfmt->maxbits); + asize << 3, outfmt->maxbits); outfmt->output(segto, data, type, amax, segment, wrt); size -= amax; } data = zero_buffer; type = OUT_RAWDATA; + segment = wrt = NO_SEG; } outfmt->output(segto, data, type, size, segment, wrt); |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 05:12:20
|
Commit-ID: b64125022d9743df8428d2fa925b36632b8ffc2a Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=b64125022d9743df8428d2fa925b36632b8ffc2a Author: H. Peter Anvin <hp...@zy...> AuthorDate: Thu, 11 Feb 2016 21:07:40 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Thu, 11 Feb 2016 21:07:40 -0800 assemble.c: handle oversized relative relocations Handle the case of oversized (larger than permitted by the output format) relative relocations. Relative relocations are always signed, and quite likely to actually have the sign bits set, so zero-extending them is not an option. Fortunately oversized relative relocations are rare, as no CPU instruction support 64-bit relative addresses. Signed-off-by: H. Peter Anvin <hp...@zy...> --- assemble.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/assemble.c b/assemble.c index 0535944..b1e6821 100644 --- a/assemble.c +++ b/assemble.c @@ -306,6 +306,27 @@ static void warn_overflow_opd(const struct operand *o, int size) } /* + * Size of an address relocation, or zero if not an address + */ +static int addrsize(enum out_type type, uint64_t size) +{ + switch (type) { + case OUT_ADDRESS: + return abs((int)size); + case OUT_REL1ADR: + return 1; + case OUT_REL2ADR: + return 2; + case OUT_REL4ADR: + return 4; + case OUT_REL8ADR: + return 8; + default: + return 0; + } +} + +/* * This routine wrappers the real output format's output routine, * in order to pass a copy of the data off to the listing file * generator at the same time, flatten unnecessary relocations, @@ -318,7 +339,7 @@ static void out(int64_t offset, int32_t segto, const void *data, static int32_t lineno = 0; /* static!!! */ static char *lnfname = NULL; uint8_t p[8]; - const int asize = abs((int)size); /* True address size */ + int asize = addrsize(type, size); /* Address size in bytes */ const int amax = outfmt->maxbits >> 3; /* Maximum address size in bytes */ if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) { @@ -336,6 +357,8 @@ static void out(int64_t offset, int32_t segto, const void *data, WRITEADDR(q, *(int64_t *)data, asize); data = p; type = OUT_RAWDATA; + + asize = 0; /* No longer an address */ } list->output(offset, data, type, size); @@ -352,8 +375,8 @@ static void out(int64_t offset, int32_t segto, const void *data, if (src_get(&lineno, &lnfname)) outfmt->current_dfmt->linenum(lnfname, lineno, segto); - if (type == OUT_ADDRESS && asize > amax) { - if (asize < 0) { + if (asize && asize > amax) { + if (type != OUT_ADDRESS || (int)size < 0) { errfunc(ERR_NONFATAL, "%d-bit signed relocation unsupported by output format %s\n", asize << 3, outfmt->shortname); |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-12 04:42:18
|
Commit-ID: 33814133bdc8db9fcbdc1be097f7b4a226d8e143 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=33814133bdc8db9fcbdc1be097f7b4a226d8e143 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Thu, 11 Feb 2016 20:40:07 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Thu, 11 Feb 2016 20:40:07 -0800 Replace global maxbits variable with field in struct ofmt maxbits is strictly a property of the output format, so get rid of this ad hoc method of reporting. Signed-off-by: H. Peter Anvin <hp...@zy...> --- assemble.c | 9 ++++----- nasm.c | 1 - nasm.h | 5 +++-- output/outaout.c | 2 ++ output/outas86.c | 1 + output/outbin.c | 6 ++++-- output/outcoff.c | 4 +++- output/outdbg.c | 1 + output/outelf32.c | 1 + output/outelf64.c | 2 +- output/outelfx32.c | 2 +- output/outieee.c | 1 + output/outmac32.c | 1 + output/outmac64.c | 3 +-- output/outobj.c | 1 + output/outrdf2.c | 3 +-- 16 files changed, 26 insertions(+), 17 deletions(-) diff --git a/assemble.c b/assemble.c index 1d8c3c1..0535944 100644 --- a/assemble.c +++ b/assemble.c @@ -319,8 +319,7 @@ static void out(int64_t offset, int32_t segto, const void *data, static char *lnfname = NULL; uint8_t p[8]; const int asize = abs((int)size); /* True address size */ - const int abits = asize << 3; /* Address size in bits */ - const int amax = maxbits >> 3; /* Maximum address size in bytes */ + const int amax = outfmt->maxbits >> 3; /* Maximum address size in bytes */ if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) { /* @@ -353,15 +352,15 @@ static void out(int64_t offset, int32_t segto, const void *data, if (src_get(&lineno, &lnfname)) outfmt->current_dfmt->linenum(lnfname, lineno, segto); - if (type == OUT_ADDRESS && abits > maxbits) { + if (type == OUT_ADDRESS && asize > amax) { if (asize < 0) { errfunc(ERR_NONFATAL, "%d-bit signed relocation unsupported by output format %s\n", - abits, outfmt->shortname); + asize << 3, outfmt->shortname); } else { errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC, "%d-bit unsigned relocation zero-extended from %d bits\n", - abits, maxbits); + asize << 4, outfmt->maxbits); outfmt->output(segto, data, type, amax, segment, wrt); size -= amax; } diff --git a/nasm.c b/nasm.c index bb62d17..55c7a2a 100644 --- a/nasm.c +++ b/nasm.c @@ -87,7 +87,6 @@ static void usage(void); static int using_debug_info, opt_verbose_info; bool tasm_compatible_mode = false; int pass0, passn; -int maxbits = 0; int globalrel = 0; int globalbnd = 0; diff --git a/nasm.h b/nasm.h index bd1f290..f0cc346 100644 --- a/nasm.h +++ b/nasm.h @@ -738,9 +738,11 @@ struct ofmt { /* * Output format flags. */ -#define OFMT_TEXT 1 /* Text file format */ +#define OFMT_TEXT 1 /* Text file format */ unsigned int flags; + int maxbits; /* Maximum segment bits supported */ + /* * this is a pointer to the first element of the debug information */ @@ -1181,7 +1183,6 @@ extern int optimizing; extern int globalbits; /* 16, 32 or 64-bit mode */ extern int globalrel; /* default to relative addressing? */ extern int globalbnd; /* default to using bnd prefix? */ -extern int maxbits; /* max bits supported by output */ /* * NASM version strings, defined in ver.c diff --git a/output/outaout.c b/output/outaout.c index 1b2b219..360f549 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -913,6 +913,7 @@ struct ofmt of_aout = { "Linux a.out object files", "aout", 0, + 32, null_debug_arr, &null_debug_form, aout_stdmac, @@ -936,6 +937,7 @@ struct ofmt of_aoutb = { "NetBSD/FreeBSD a.out object files", "aoutb", 0, + 32, null_debug_arr, &null_debug_form, aout_stdmac, diff --git a/output/outas86.c b/output/outas86.c index 892362b..43108c4 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -633,6 +633,7 @@ struct ofmt of_as86 = { "Linux as86 (bin86 version 0.3) object files", "as86", 0, + 32, null_debug_arr, &null_debug_form, as86_stdmac, diff --git a/output/outbin.c b/output/outbin.c index c64daaa..71c7bcd 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -1431,7 +1431,6 @@ static void srec_init(void) static void binfmt_init(void) { - maxbits = 64; /* Support 64-bit Segments */ relocs = NULL; reloctail = &relocs; origin_defined = 0; @@ -1660,6 +1659,7 @@ struct ofmt of_bin = { "flat-form binary files (e.g. DOS .COM, .SYS)", "bin", 0, + 64, null_debug_arr, &null_debug_form, bin_stdmac, @@ -1679,6 +1679,7 @@ struct ofmt of_ith = { "Intel hex", "ith", OFMT_TEXT, + 64, null_debug_arr, &null_debug_form, bin_stdmac, @@ -1697,7 +1698,8 @@ struct ofmt of_ith = { struct ofmt of_srec = { "Motorola S-records", "srec", - 0, + OFMT_TEXT, + 64, null_debug_arr, &null_debug_form, bin_stdmac, diff --git a/output/outcoff.c b/output/outcoff.c index 73ba13e..a712f95 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -196,7 +196,6 @@ static void coff_win32_init(void) static void coff_win64_init(void) { - maxbits = 64; win32 = false; win64 = true; coff_gen_init(); @@ -1173,6 +1172,7 @@ struct ofmt of_coff = { "COFF (i386) object files (e.g. DJGPP for DOS)", "coff", 0, + 32, null_debug_arr, &null_debug_form, coff_stdmac, @@ -1200,6 +1200,7 @@ struct ofmt of_win32 = { "Microsoft Win32 (i386) object files", "win32", 0, + 32, win32_debug_arr, &df_cv8, coff_stdmac, @@ -1225,6 +1226,7 @@ struct ofmt of_win64 = { "Microsoft Win64 (x86-64) object files", "win64", 0, + 64, win64_debug_arr, &df_cv8, coff_stdmac, diff --git a/output/outdbg.c b/output/outdbg.c index 155dbd1..034a615 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -264,6 +264,7 @@ struct ofmt of_dbg = { "Trace of all info passed to output stage", "dbg", OFMT_TEXT, + 64, debug_debug_arr, &debug_debug_form, NULL, diff --git a/output/outelf32.c b/output/outelf32.c index 7ac7805..e4971ed 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -1366,6 +1366,7 @@ struct ofmt of_elf32 = { "ELF32 (i386) object files (e.g. Linux)", "elf32", 0, + 32, elf32_debugs_arr, &df_stabs, elf_stdmac, diff --git a/output/outelf64.c b/output/outelf64.c index 3c3e921..f2a192a 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -191,7 +191,6 @@ static int32_t elf_gottpoff_sect; static void elf_init(void) { - maxbits = 64; sects = NULL; nsects = sectlen = 0; syms = saa_init((int32_t)sizeof(struct elf_symbol)); @@ -1457,6 +1456,7 @@ struct ofmt of_elf64 = { "ELF64 (x86_64) object files (e.g. Linux)", "elf64", 0, + 64, elf64_debugs_arr, &df_stabs, elf_stdmac, diff --git a/output/outelfx32.c b/output/outelfx32.c index 33972b4..c217c7b 100644 --- a/output/outelfx32.c +++ b/output/outelfx32.c @@ -190,7 +190,6 @@ static int32_t elf_gottpoff_sect; static void elf_init(void) { - maxbits = 64; sects = NULL; nsects = sectlen = 0; syms = saa_init((int32_t)sizeof(struct elf_symbol)); @@ -1416,6 +1415,7 @@ struct ofmt of_elfx32 = { "ELFX32 (x86_64) object files (e.g. Linux)", "elfx32", 0, + 64, elfx32_debugs_arr, &df_stabs, elf_stdmac, diff --git a/output/outieee.c b/output/outieee.c index d42a6fd..42f0fb6 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -1517,6 +1517,7 @@ struct ofmt of_ieee = { "IEEE-695 (LADsoft variant) object file format", "ieee", OFMT_TEXT, + 32, ladsoft_debug_arr, &ladsoft_debug_form, NULL, diff --git a/output/outmac32.c b/output/outmac32.c index 873ed7e..8014b7c 100644 --- a/output/outmac32.c +++ b/output/outmac32.c @@ -1303,6 +1303,7 @@ struct ofmt of_macho32 = { "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files", "macho32", 0, + 32, null_debug_arr, &null_debug_form, macho_stdmac, diff --git a/output/outmac64.c b/output/outmac64.c index 5c8a0dc..a12a167 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -332,8 +332,6 @@ static void macho_init(void) { char zero = 0; - maxbits = 64; - sects = NULL; sectstail = §s; @@ -1495,6 +1493,7 @@ struct ofmt of_macho64 = { "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files", "macho64", 0, + 64, null_debug_arr, &null_debug_form, macho_stdmac, diff --git a/output/outobj.c b/output/outobj.c index c9f4009..ff03664 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -2627,6 +2627,7 @@ struct ofmt of_obj = { "MS-DOS 16-bit/32-bit OMF object files", "obj", 0, + 32, borland_debug_arr, &borland_debug_form, obj_stdmac, diff --git a/output/outrdf2.c b/output/outrdf2.c index 884cdf4..4dcae83 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -114,8 +114,6 @@ static void rdf2_init(void) { int segtext, segdata, segbss; - maxbits = 64; - /* set up the initial segments */ segments[0].segname = ".text"; segments[0].segnumber = 0; @@ -781,6 +779,7 @@ struct ofmt of_rdf2 = { "Relocatable Dynamic Object File Format v2.0", "rdf", 0, + 64, null_debug_arr, &null_debug_form, rdf2_stdmac, |