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...@zy...> - 2016-02-12 04:33:17
|
Commit-ID: ecc9e0ecd732c66918a880b8f225cc26b7cd83ba Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ecc9e0ecd732c66918a880b8f225cc26b7cd83ba Author: H. Peter Anvin <hp...@zy...> AuthorDate: Thu, 11 Feb 2016 20:29:34 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Thu, 11 Feb 2016 20:29:34 -0800 Set warning name to zext-reloc and fix the warning message Adjustment to the warning about zero-extended relocations. Signed-off-by: H. Peter Anvin <hp...@zy...> --- assemble.c | 2 +- nasm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assemble.c b/assemble.c index 8382b89..1d8c3c1 100644 --- a/assemble.c +++ b/assemble.c @@ -360,7 +360,7 @@ static void out(int64_t offset, int32_t segto, const void *data, abits, outfmt->shortname); } else { errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC, - "%d-bit unsigned relocation zeroq-padded from %d bits\n", + "%d-bit unsigned relocation zero-extended from %d bits\n", abits, maxbits); outfmt->output(segto, data, type, amax, segment, wrt); size -= amax; diff --git a/nasm.c b/nasm.c index e48f0a9..bb62d17 100644 --- a/nasm.c +++ b/nasm.c @@ -168,7 +168,7 @@ static const struct warning { {"lock", "lock prefix on unlockable instructions", true}, {"hle", "invalid hle prefixes", true}, {"bnd", "invalid bnd prefixes", true}, - {"zero-reloc", "relocation zero-extended to match output format", true}, + {"zext-reloc", "relocation zero-extended to match output format", true}, }; static bool want_usage; |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-12 04:24:17
|
Commit-ID: f30d96d1c025d1a9c9453ed225f78d6b156da5f9 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=f30d96d1c025d1a9c9453ed225f78d6b156da5f9 Author: H. Peter Anvin <hp...@li...> AuthorDate: Thu, 11 Feb 2016 20:20:10 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Thu, 11 Feb 2016 20:20:10 -0800 outmac64.c: Fix memory clobber bug, clean up memory free Fix an array that was way too small resulting in memory overwrite errors, and free a few more dynamic data structures. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmac64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index 76fa7ad..5c8a0dc 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -1016,7 +1016,7 @@ static void macho_calculate_sizes (void) } /* Create a table of sections by file index to avoid linear search */ - sectstab = nasm_malloc(seg_nsects64 + 1); + sectstab = nasm_malloc((seg_nsects64 + 1) * sizeof(*sectstab)); sectstab[0] = NULL; for (s = sects, fi = 1; s != NULL; s = s->next, fi++) sectstab[fi] = s; @@ -1456,14 +1456,15 @@ static void macho_cleanup(int debuginfo) saa_free(strs); raa_free(extsyms); - if (syms) { - while (syms->next) { + while (syms) { sym = syms; syms = syms->next; - nasm_free (sym); } -} + + nasm_free(extdefsyms); + nasm_free(undefsyms); + nasm_free(sectstab); } /* Debugging routines. */ |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-12 03:27:16
|
Commit-ID: 97577e82d7230e5b3ef0947c8d62b9a3326fe4a1 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=97577e82d7230e5b3ef0947c8d62b9a3326fe4a1 Author: H. Peter Anvin <hp...@li...> AuthorDate: Thu, 11 Feb 2016 19:25:33 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Thu, 11 Feb 2016 19:25:33 -0800 macho64: remove LC_DATA_IN_CODE, change reloc type to 1 Change the relocation type to SIGNED instead of BRANCH, this is probably more correct. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmac64.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index 16e3774..76fa7ad 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -441,7 +441,7 @@ static int32_t add_reloc(struct section *sect, int32_t section, /* inter-section */ } else { - r->type = 2; // X86_64_RELOC_BRANCH + r->type = 1; // X86_64_RELOC_SIGNED fi = get_section_fileindex_by_index(section); /* external */ @@ -1015,9 +1015,6 @@ static void macho_calculate_sizes (void) head_sizeofcmds64 += MACHO_SYMCMD_SIZE; } - ++head_ncmds64; /* LC_DATA_IN_CODE */ - head_sizeofcmds64 += MACHO_DATA_IN_CODE_CMD_SIZE; - /* Create a table of sections by file index to avoid linear search */ sectstab = nasm_malloc(seg_nsects64 + 1); sectstab[0] = NULL; @@ -1404,12 +1401,6 @@ static void macho_write (void) fwriteint32_t(strslen, ofile); /* string table size */ } - /* emit dummy data in code command */ - fwriteint32_t(LC_DATA_IN_CODE, ofile); - fwriteint32_t(MACHO_DATA_IN_CODE_CMD_SIZE, ofile); - fwriteint32_t(offset, ofile); - fwriteint32_t(0, ofile); /* no actual DATA_IN_CODE */ - /* emit section data */ if (seg_nsects64 > 0) macho_write_section (); |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-12 02:00:18
|
Commit-ID: 5eebc6bc2bdb5e4607075f39edfe62d8b9d699f6 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=5eebc6bc2bdb5e4607075f39edfe62d8b9d699f6 Author: H. Peter Anvin <hp...@li...> AuthorDate: Thu, 11 Feb 2016 17:51:37 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Thu, 11 Feb 2016 17:51:37 -0800 macho64: fix alignment problems, add LC_DATA_IN_CODE Hopefully actually fix the issues with alignment this time. Avoid a linear search of segments for each symbol emitted. Issue an empty LC_DATA_IN_CODE command since that seems to be expected. With this, ffmpeg builds but still crashes on startup, which seems very strange. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmac64.c | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index 9a4fb4b..16e3774 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -59,10 +59,11 @@ /* Mach-O in-file header structure sizes */ #define MACHO_HEADER64_SIZE (32) #define MACHO_SEGCMD64_SIZE (72) -#define MACHO_SECTCMD64_SIZE (80) +#define MACHO_SECTCMD64_SIZE (80) #define MACHO_SYMCMD_SIZE (24) #define MACHO_NLIST64_SIZE (16) -#define MACHO_RELINFO64_SIZE (8) +#define MACHO_RELINFO64_SIZE (8) +#define MACHO_DATA_IN_CODE_CMD_SIZE (16) /* Mach-O file header values */ #define MH_MAGIC_64 (0xfeedfacf) @@ -72,6 +73,7 @@ #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 VM_PROT_NONE (0x00) #define VM_PROT_READ (0x01) @@ -94,6 +96,7 @@ struct section { char segname[16]; /* segment this section will be in */ uint64_t addr; /* in-memory address (subject to alignment) */ uint64_t size; /* in-memory and -file size */ + uint64_t offset; /* in-file offset */ uint32_t pad; /* padding bytes before section */ uint32_t nreloc; /* relocation entry count */ uint32_t flags; /* type and attributes (masked) */ @@ -179,7 +182,7 @@ struct symbol { #define NO_SECT 0 /* no section, invalid */ #define MAX_SECT 255 /* maximum number of sections */ -static struct section *sects, **sectstail; +static struct section *sects, **sectstail, **sectstab; static struct symbol *syms, **symstail; static uint32_t nsyms; @@ -669,6 +672,7 @@ static int32_t macho_section(char *name, int pass, int *bits) s->relocs = NULL; s->align = -1; s->pad = -1; + s->offset = -1; xstrncpy(s->segname, sm->segname); xstrncpy(s->sectname, sm->sectname); @@ -965,6 +969,7 @@ static void macho_layout_symbols (uint32_t *numsyms, static void macho_calculate_sizes (void) { struct section *s; + int fi; /* count sections and calculate in-memory and in-file offsets */ for (s = sects; s != NULL; s = s->next) { @@ -990,6 +995,7 @@ static void macho_calculate_sizes (void) * 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; } @@ -1008,6 +1014,15 @@ static void macho_calculate_sizes (void) ++head_ncmds64; head_sizeofcmds64 += MACHO_SYMCMD_SIZE; } + + ++head_ncmds64; /* LC_DATA_IN_CODE */ + head_sizeofcmds64 += MACHO_DATA_IN_CODE_CMD_SIZE; + + /* Create a table of sections by file index to avoid linear search */ + sectstab = nasm_malloc(seg_nsects64 + 1); + sectstab[0] = NULL; + for (s = sects, fi = 1; s != NULL; s = s->next, fi++) + sectstab[fi] = s; } /* Write out the header information for the file. */ @@ -1035,8 +1050,9 @@ static uint32_t macho_write_segment (uint64_t offset) fwriteint32_t(LC_SEGMENT_64, ofile); /* cmd == LC_SEGMENT_64 */ /* size of load command including section load commands */ - fwriteint32_t(MACHO_SEGCMD64_SIZE + seg_nsects64 * - MACHO_SECTCMD64_SIZE, ofile); + fwriteint32_t(MACHO_SEGCMD64_SIZE + + seg_nsects64 * MACHO_SECTCMD64_SIZE, + ofile); /* in an MH_OBJECT file all sections are in one unnamed (name ** all zeros) segment */ @@ -1210,8 +1226,6 @@ static void macho_write_section (void) static void macho_write_symtab (void) { struct symbol *sym; - struct section *s; - int64_t fi; uint64_t i; /* we don't need to pad here since MACHO_RELINFO_SIZE == 8 */ @@ -1226,12 +1240,8 @@ 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)) { - for (s = sects, fi = 1; s != NULL; s = s->next, fi++) { - if (fi == sym->sect) { - sym->value += s->addr; - break; - } - } + nasm_assert(sym->sect <= seg_nsects64); + sym->value += sectstab[sym->sect]->addr; } fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */ @@ -1248,9 +1258,8 @@ 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)) { - for (s = sects, fi = 1; - s != NULL && fi < sym->sect; s = s->next, ++fi) - sym->value += s->size; + nasm_assert(sym->sect <= seg_nsects64); + sym->value += sectstab[sym->sect]->addr; } fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */ @@ -1265,9 +1274,8 @@ 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)) { - for (s = sects, fi = 1; - s != NULL && fi < sym->sect; s = s->next, ++fi) - sym->value += s->size; + nasm_assert(sym->sect <= seg_nsects64); + sym->value += sectstab[sym->sect]->addr; } fwriteint64_t(sym->value, ofile); // value (i.e. offset) @@ -1391,12 +1399,17 @@ 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; fwriteint32_t(offset, ofile); /* string table offset */ fwriteint32_t(strslen, ofile); /* string table size */ } + /* emit dummy data in code command */ + fwriteint32_t(LC_DATA_IN_CODE, ofile); + fwriteint32_t(MACHO_DATA_IN_CODE_CMD_SIZE, ofile); + fwriteint32_t(offset, ofile); + fwriteint32_t(0, ofile); /* no actual DATA_IN_CODE */ + /* emit section data */ if (seg_nsects64 > 0) macho_write_section (); |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-11 22:48:17
|
Commit-ID: def81d5c71838aa1510340540c2efb4501180d0a Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=def81d5c71838aa1510340540c2efb4501180d0a Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 2 Feb 2016 17:15:03 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 5 Feb 2016 11:19:29 -0800 outmac64: Fix the handling of section data alignment Fix a number of places which failed to account for padding to alignment of section data. Also, fix confusion between aligning section data in the linkable object code and final address alignment; LLVM/Xcode always align section data to 4 bytes (with a comment saying that it probably should be 8 bytes for 64-bit output) independent of the section alignment. This will need to be ported to the macho32 backend, as well; ideally the two should be merged as they are really very similar and we don't want to have these kinds of cross-porting problems. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmac64.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index b4a46d8..d1a0a5c 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2013 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -94,9 +94,10 @@ struct section { char segname[16]; /* segment this section will be in */ uint64_t addr; /* in-memory address (subject to alignment) */ uint64_t size; /* in-memory and -file size */ + uint32_t pad; /* padding bytes before section */ uint32_t nreloc; /* relocation entry count */ uint32_t flags; /* type and attributes (masked) */ - uint32_t extreloc; /* external relocations */ + uint32_t extreloc; /* external relocations */ }; #define SECTION_TYPE 0x000000ff /* section type mask */ @@ -667,6 +668,7 @@ static int32_t macho_section(char *name, int pass, int *bits) s->index = seg_alloc(); s->relocs = NULL; s->align = -1; + s->pad = -1; xstrncpy(s->segname, sm->segname); xstrncpy(s->sectname, sm->sectname); @@ -966,24 +968,31 @@ static void macho_calculate_sizes (void) /* count sections and calculate in-memory and in-file offsets */ for (s = sects; s != NULL; s = s->next) { - uint64_t pad = 0; - - /* zerofill sections aren't actually written to the file */ - if ((s->flags & SECTION_TYPE) != S_ZEROFILL) - seg_filesize64 += s->size; + uint64_t newaddr; /* recalculate segment address based on alignment and vm size */ s->addr = seg_vmsize64; + /* we need section alignment to calculate final section address */ if (s->align == -1) s->align = DEFAULT_SECTION_ALIGNMENT; - if(s->align) { - uint64_t newaddr = ALIGN(s->addr, 1 << s->align); - pad = newaddr - s->addr; - s->addr = newaddr; - } - seg_vmsize64 += s->size + pad; + newaddr = ALIGN(s->addr, 1 << s->align); + s->addr = newaddr; + + seg_vmsize64 = newaddr + s->size; + + /* zerofill sections aren't actually written to the file */ + if ((s->flags & SECTION_TYPE) != S_ZEROFILL) { + /* + * LLVM/Xcode as always aligns the section data to 4 + * 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; + seg_filesize64 += s->size + s->pad; + } + ++seg_nsects64; } @@ -1050,7 +1059,10 @@ static uint32_t macho_write_segment (uint64_t offset) /* dummy data for zerofill sections or proper values */ if ((s->flags & SECTION_TYPE) != S_ZEROFILL) { + nasm_assert(s->pad != (uint32_t)-1); + offset += s->pad; fwriteint32_t(offset, ofile); + 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) @@ -1061,11 +1073,10 @@ static uint32_t macho_write_segment (uint64_t offset) fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile); fwriteint32_t(s->nreloc, ofile); - offset += s->size; s_reloff += s->nreloc * MACHO_RELINFO64_SIZE; } else { fwriteint32_t(0, ofile); - fwriteint32_t(0, ofile); + fwriteint32_t(0, ofile); /* No alignment?! */ fwriteint32_t(0, ofile); fwriteint32_t(0, ofile); } @@ -1077,10 +1088,10 @@ static uint32_t macho_write_segment (uint64_t offset) } fwriteint32_t(s->flags, ofile); /* flags */ - fwriteint32_t(0, ofile); /* reserved */ - fwriteint32_t(0, ofile); /* reserved */ + fwriteint32_t(0, ofile); /* reserved */ + fwriteint32_t(0, ofile); /* reserved */ - fwriteint32_t(0, ofile); /* align */ + fwriteint32_t(0, ofile); /* align */ } rel_padcnt64 = rel_base - offset; @@ -1122,8 +1133,6 @@ static void macho_write_section (void) if ((s->flags & SECTION_TYPE) == S_ZEROFILL) continue; - /* no padding needs to be done to the sections */ - /* Like a.out Mach-O references things in the data or bss * sections by addresses which are actually relative to the * start of the _text_ section, in the _file_. See outaout.c @@ -1184,6 +1193,7 @@ static void macho_write_section (void) } /* dump the section data to file */ + fwritezero(s->pad, ofile); saa_fpwrite(s->data, ofile); } |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-11 22:48:17
|
Commit-ID: ae01785d872d3271d749a0866031d2d867120234 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ae01785d872d3271d749a0866031d2d867120234 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 5 Feb 2016 11:34:07 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 5 Feb 2016 11:34:07 -0800 LLVM portability fix for abs(size) size is actually an uint64_t, and LLVM drops the abs() on the principle that the uint64_t should always be positive. Make it explicit that we are converting to a signed integer first, by using abs((int)size) instead. Signed-off-by: H. Peter Anvin <hp...@li...> --- listing.c | 2 +- output/outaout.c | 2 +- output/outas86.c | 2 +- output/outbin.c | 2 +- output/outcoff.c | 4 ++-- output/outelf32.c | 2 +- output/outelf64.c | 2 +- output/outelfx32.c | 2 +- output/outieee.c | 2 +- output/outmac32.c | 2 +- output/outmac64.c | 2 +- output/outobj.c | 2 +- output/outrdf2.c | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/listing.c b/listing.c index 18e949b..49f5e15 100644 --- a/listing.c +++ b/listing.c @@ -216,7 +216,7 @@ static void list_output(int32_t offset, const void *data, break; } case OUT_ADDRESS: - list_address(offset, "[]", *(int64_t *)data, abs(size)); + list_address(offset, "[]", *(int64_t *)data, abs((int)size)); break; case OUT_REL1ADR: list_address(offset, "()", *(int64_t *)data, 1); diff --git a/output/outaout.c b/output/outaout.c index 575089c..1b2b219 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -634,7 +634,7 @@ static void aout_out(int32_t segto, const void *data, nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); aout_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { - int asize = abs(size); + int asize = abs((int)size); addr = *(int64_t *)data; if (segment != NO_SEG) { if (segment % 2) { diff --git a/output/outas86.c b/output/outas86.c index a800e90..892362b 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -347,7 +347,7 @@ static void as86_out(int32_t segto, const void *data, as86_sect_write(s, data, size); as86_add_piece(s, 0, 0L, 0L, size, 0); } else if (type == OUT_ADDRESS) { - int asize = abs(size); + int asize = abs((int)size); if (segment != NO_SEG) { if (segment % 2) { nasm_error(ERR_NONFATAL, "as86 format does not support" diff --git a/output/outbin.c b/output/outbin.c index 77a9778..c64daaa 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -765,7 +765,7 @@ static void bin_out(int32_t segto, const void *data, switch (type) { case OUT_ADDRESS: { - int asize = abs(size); + int asize = abs((int)size); if (segment != NO_SEG && !find_section_by_index(segment)) { if (segment % 2) diff --git a/output/outcoff.c b/output/outcoff.c index b45e4f1..73ba13e 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -611,7 +611,7 @@ static void coff_out(int32_t segto, const void *data, dinfo.section = s; if (type == OUT_ADDRESS) - dinfo.size = abs(size); + dinfo.size = abs((int)size); else dinfo.size = realsize(type, size); @@ -630,7 +630,7 @@ static void coff_out(int32_t segto, const void *data, nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); coff_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { - int asize = abs(size); + int asize = abs((int)size); if (!win64) { if (asize != 4 && (segment != NO_SEG || wrt != NO_SEG)) { nasm_error(ERR_NONFATAL, "COFF format does not support non-32-bit" diff --git a/output/outelf32.c b/output/outelf32.c index 4489d40..7ac7805 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -730,7 +730,7 @@ static void elf_out(int32_t segto, const void *data, case OUT_ADDRESS: { bool gnu16 = false; - int asize = abs(size); + int asize = abs((int)size); addr = *(int64_t *)data; if (segment != NO_SEG) { if (segment % 2) { diff --git a/output/outelf64.c b/output/outelf64.c index 41243b1..3c3e921 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -746,7 +746,7 @@ static void elf_out(int32_t segto, const void *data, case OUT_ADDRESS: { int isize = (int)size; - int asize = abs(size); + int asize = abs((int)size); addr = *(int64_t *)data; if (segment == NO_SEG) { diff --git a/output/outelfx32.c b/output/outelfx32.c index 3eeb224..33972b4 100644 --- a/output/outelfx32.c +++ b/output/outelfx32.c @@ -745,7 +745,7 @@ static void elf_out(int32_t segto, const void *data, case OUT_ADDRESS: { int isize = (int)size; - int asize = abs(size); + int asize = abs((int)size); addr = *(int64_t *)data; if (segment == NO_SEG) { diff --git a/output/outieee.c b/output/outieee.c index 56060db..d42a6fd 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -438,7 +438,7 @@ static void ieee_out(int32_t segto, const void *data, } else if (type == OUT_ADDRESS || type == OUT_REL2ADR || type == OUT_REL4ADR) { if (type == OUT_ADDRESS) - size = abs(size); + size = abs((int)size); else if (segment == NO_SEG) nasm_error(ERR_NONFATAL, "relative call to absolute address not" " supported by IEEE format"); diff --git a/output/outmac32.c b/output/outmac32.c index 0ed88c9..873ed7e 100644 --- a/output/outmac32.c +++ b/output/outmac32.c @@ -434,7 +434,7 @@ static void macho_output(int32_t secto, const void *data, case OUT_ADDRESS: { - int asize = abs(size); + int asize = abs((int)size); addr = *(int64_t *)data; diff --git a/output/outmac64.c b/output/outmac64.c index d1a0a5c..9a4fb4b 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -536,7 +536,7 @@ static void macho_output(int32_t secto, const void *data, case OUT_ADDRESS: { - int asize = abs(size); + int asize = abs((int)size); addr = *(int64_t *)data; if (section != NO_SEG) { diff --git a/output/outobj.c b/output/outobj.c index 6b173eb..c9f4009 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -1087,7 +1087,7 @@ static void obj_out(int32_t segto, const void *data, int rsize; if (type == OUT_ADDRESS) - size = abs(size); + size = abs((int)size); if (segment == NO_SEG && type != OUT_ADDRESS) nasm_error(ERR_NONFATAL, "relative call to absolute address not" diff --git a/output/outrdf2.c b/output/outrdf2.c index fdac5ee..884cdf4 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -583,7 +583,7 @@ static void rdf2_out(int32_t segto, const void *data, membufwrite(segto, data, size); } else if (type == OUT_ADDRESS) { - int asize = abs(size); + int asize = abs((int)size); /* if segment == NO_SEG then we are writing an address of an object within the same segment - do not produce reloc rec. */ |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-11 22:48:16
|
Commit-ID: 5482a15e17cfc80379052253003e5a6b0cd46f14 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=5482a15e17cfc80379052253003e5a6b0cd46f14 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 5 Feb 2016 11:31:46 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 5 Feb 2016 11:31:46 -0800 codeview.c: remove superfluous pointer test A pointer to a field in a structure can never be NULL so remove the test. There is no reason to test the field for an empty string either, since we immediately thereafter do a strcmp(). Signed-off-by: H. Peter Anvin <hp...@li...> --- output/codeview.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/output/codeview.c b/output/codeview.c index 4256e8d..2f5bb69 100644 --- a/output/codeview.c +++ b/output/codeview.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2010 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -402,7 +402,7 @@ static void register_reloc(struct coff_Section *const sect, for (uint32_t i = 0; i < coff_nsyms; i++) { struct coff_Symbol *s = saa_rstruct(coff_syms); r->symbol++; - if (s->strpos == -1 && s->name && !strcmp(sym, s->name)) { + if (s->strpos == -1 && !strcmp(sym, s->name)) { return; } else if (s->strpos != -1) { int res; |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-11 22:48:16
|
Commit-ID: 25e2b40ac2db6663086f98bcba534e8dbb02dd34 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=25e2b40ac2db6663086f98bcba534e8dbb02dd34 Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 5 Feb 2016 11:30:11 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 5 Feb 2016 11:30:11 -0800 nasmlib.h: remove system definitions of ALIGN and ALIGN_MASK Apparently some BSD flavors define these macros in a system header file; this includes MacOS X. Assume we can just #undef them without causing any additional issues; otherwise we may need to rename them. Signed-off-by: H. Peter Anvin <hp...@li...> --- nasmlib.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nasmlib.h b/nasmlib.h index 52eadd8..0d4d21a 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -258,6 +258,8 @@ void standard_extension(char *inname, char *outname, char *extension); /* * Power of 2 align helpers */ +#undef ALIGN_MASK /* Some BSD flavors define these in system headers */ +#undef ALIGN #define ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) #define ALIGN(v, a) ALIGN_MASK(v, (a) - 1) #define IS_ALIGNED(v, a) (((v) & ((a) - 1)) == 0) |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-11 22:45:25
|
Commit-ID: d24dd5fecc2ce71238e6443b84a274a53f73b559 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=d24dd5fecc2ce71238e6443b84a274a53f73b559 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Mon, 8 Feb 2016 10:32:13 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Mon, 8 Feb 2016 10:32:13 -0800 Remove the --allow-64-bits option and make it a warning Remove the --allow-64-bits relocation, and instead make it a suppressible warning in the case of a zero-extended relocation, and an error in the case of a sign-extended relocation. Relocations which can be losslessly represented in the output format do not issue any diagnostic at all, as there is no problem in that case. Signed-off-by: H. Peter Anvin <hp...@zy...> --- assemble.c | 29 ++++++++++++++++++++++++----- doc/nasmdoc.src | 10 ---------- nasm.c | 14 ++------------ nasm.h | 2 +- nasmlib.h | 3 ++- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/assemble.c b/assemble.c index 4976c46..8382b89 100644 --- a/assemble.c +++ b/assemble.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2014 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -308,7 +308,8 @@ static void warn_overflow_opd(const struct operand *o, int size) /* * 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. + * generator at the same time, flatten unnecessary relocations, + * and verify backend compatibility. */ static void out(int64_t offset, int32_t segto, const void *data, enum out_type type, uint64_t size, @@ -317,6 +318,9 @@ 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 */ + const int abits = asize << 3; /* Address size in bits */ + const int amax = maxbits >> 3; /* Maximum address size in bytes */ if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) { /* @@ -325,13 +329,12 @@ static void out(int64_t offset, int32_t segto, const void *data, */ uint8_t *q = p; - size = abs((int)size); - if (size > 8) { + if (asize > 8) { errfunc(ERR_PANIC, "OUT_ADDRESS with size > 8"); return; } - WRITEADDR(q, *(int64_t *)data, size); + WRITEADDR(q, *(int64_t *)data, asize); data = p; type = OUT_RAWDATA; } @@ -350,6 +353,22 @@ 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 (asize < 0) { + errfunc(ERR_NONFATAL, + "%d-bit signed relocation unsupported by output format %s\n", + abits, outfmt->shortname); + } else { + errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC, + "%d-bit unsigned relocation zeroq-padded from %d bits\n", + abits, maxbits); + outfmt->output(segto, data, type, amax, segment, wrt); + size -= amax; + } + data = zero_buffer; + type = OUT_RAWDATA; + } + outfmt->output(segto, data, type, size, segment, wrt); } diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index ec0cfcc..4b5078a 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -1010,16 +1010,6 @@ underscore to all global and external variables, as C requires it in some, but not all, system calling conventions. -\S{opt-allow64bit} The \i\c{--allow-64-bit} Option. - -The \c{--allow-64-bit} option allows using 64-bit instructions in a -32-bit or 16-bit output format. This is useful in a few situations, -such as when writing code switching from 32-bit to 64-bit mode and -linking into a 32-bit module. However, it is important to be aware of -the restriction the output format poses on you in terms of -relocations. Use with caution! - - \S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable If you define an environment variable called \c{NASMENV}, the program diff --git a/nasm.c b/nasm.c index 17ee553..e48f0a9 100644 --- a/nasm.c +++ b/nasm.c @@ -88,7 +88,6 @@ static int using_debug_info, opt_verbose_info; bool tasm_compatible_mode = false; int pass0, passn; int maxbits = 0; -static bool allow_64_bit = false; int globalrel = 0; int globalbnd = 0; @@ -169,6 +168,7 @@ static const struct warning { {"lock", "lock prefix on unlockable instructions", true}, {"hle", "invalid hle prefixes", true}, {"bnd", "invalid bnd prefixes", true}, + {"zero-reloc", "relocation zero-extended to match output format", true}, }; static bool want_usage; @@ -618,12 +618,10 @@ struct textargs { enum text_options { OPT_PREFIX, OPT_POSTFIX, - OPT_ALLOW_64_BIT }; struct textargs textopts[] = { {"prefix", OPT_PREFIX}, {"postfix", OPT_POSTFIX}, - {"allow-64-bit", OPT_ALLOW_64_BIT}, {NULL, 0} }; @@ -981,9 +979,7 @@ set_warning: } break; } - case OPT_ALLOW_64_BIT: - allow_64_bit = true; - break; + default: { nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, @@ -2101,12 +2097,6 @@ static int get_bits(char *value) "cannot specify 64-bit segment on processor below an x86-64"); i = 16; } - if (i != maxbits && !allow_64_bit) { - nasm_error(ERR_NONFATAL, - "%s output format does not support 64-bit code", - ofmt->shortname); - i = 16; - } } else { nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL, "`%s' is not a valid segment size; must be 16, 32 or 64", diff --git a/nasm.h b/nasm.h index 8bc2571..bd1f290 100644 --- a/nasm.h +++ b/nasm.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2014 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * diff --git a/nasmlib.h b/nasmlib.h index 24db573..47e9a0a 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -125,7 +125,8 @@ no_return nasm_panic_from_macro(const char *file, int line); #define ERR_WARN_LOCK WARN(12) /* bad LOCK prefixes */ #define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */ #define ERR_WARN_BND WARN(14) /* bad BND prefixes */ -#define ERR_WARN_MAX 14 /* the highest numbered one */ +#define ERR_WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */ +#define ERR_WARN_MAX 15 /* the highest numbered one */ /* * Wrappers around malloc, realloc and free. nasm_malloc will |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-11 22:45:24
|
Commit-ID: f0d92fd19ad01b99a93a766f482d2ecaa3ca91a8 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=f0d92fd19ad01b99a93a766f482d2ecaa3ca91a8 Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 2 Feb 2016 16:01:43 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 2 Feb 2016 16:01:43 -0800 nasmlib: Add generic panic() macro, and no-return nasm_panic() Add a generic panic() macro which we can simply insert where an internal error happens. Also, create a nasm_panic() function the only purpose of which is to let the compiler know that we will never return after a panic. Signed-off-by: H. Peter Anvin <hp...@li...> --- compiler.h | 9 +++++++++ nasmlib.c | 11 ++++++++++- nasmlib.h | 10 ++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/compiler.h b/compiler.h index de7c0e4..e9022f8 100644 --- a/compiler.h +++ b/compiler.h @@ -188,4 +188,13 @@ char *strsep(char **, const char *); # define no_return void #endif +/* + * How to tell the compiler that a function takes a printf-like string + */ +#ifdef __GNUC__ +# define printf_func(fmt, list) __attribute__((format(printf, fmt, list))) +#else +# define printf_func(fmt, list) +#endif + #endif /* NASM_COMPILER_H */ diff --git a/nasmlib.c b/nasmlib.c index ecd6d8d..3c26546 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2014 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -83,6 +83,15 @@ void nasm_error(int severity, const char *fmt, ...) va_end(ap); } +no_return nasm_panic(int flags, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + nasm_verror(flags | ERR_PANIC, fmt, ap); + abort(); /* We should never get here */ +} + void *nasm_malloc(size_t size) { void *p = malloc(size); diff --git a/nasmlib.h b/nasmlib.h index 9cd417f..52eadd8 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -75,12 +75,10 @@ extern unsigned char nasm_tolower_tab[256]; */ typedef void (*efunc) (int severity, const char *fmt, ...); typedef void (*vefunc) (int severity, const char *fmt, va_list ap); -#ifdef __GNUC__ -void nasm_error(int severity, const char *fmt, ...) __attribute__((format(printf, 2, 3))); -#else -void nasm_error(int severity, const char *fmt, ...); -#endif +void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...); void nasm_set_verror(vefunc); +no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...); +#define panic() nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", __FILE__, __LINE__); /* * These are the error severity codes which get passed as the first |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-11 22:45:23
|
Commit-ID: 1c10ad65feabeb08a9f1bb16f28128c02dfe557e Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=1c10ad65feabeb08a9f1bb16f28128c02dfe557e Author: H. Peter Anvin <hp...@zy...> AuthorDate: Mon, 8 Feb 2016 10:34:09 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Mon, 8 Feb 2016 10:34:09 -0800 nasmdoc.src: update copyright date --- doc/nasmdoc.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 4b5078a..00a1a14 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -35,7 +35,7 @@ \# \M{category}{Programming} \M{title}{NASM - The Netwide Assembler} -\M{year}{1996-2012} +\M{year}{1996-2016} \M{author}{The NASM Development Team} \M{copyright_tail}{-- All Rights Reserved} \M{license}{This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive.} |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-11 22:45:23
|
Commit-ID: 0c11e123b261686f12daf1cea5e7f36d41f4f3de Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=0c11e123b261686f12daf1cea5e7f36d41f4f3de Author: H. Peter Anvin <hp...@zy...> AuthorDate: Mon, 8 Feb 2016 10:12:37 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Mon, 8 Feb 2016 10:12:37 -0800 nasmlib.h: Add #undef for ZERO_BUF_SIZE If we are redefining ZERO_BUF_SIZE, add an #undef to avoid nuisance compiler warnings. Signed-off-by: H. Peter Anvin <hp...@zy...> --- nasmlib.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nasmlib.h b/nasmlib.h index dfce1dd..24db573 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -410,6 +410,7 @@ const char *prefix_name(int); #define ZERO_BUF_SIZE 4096 /* Default value */ #if defined(BUFSIZ) && (BUFSIZ > ZERO_BUF_SIZE) +# undef ZERO_BUF_SIZE # define ZERO_BUF_SIZE BUFSIZ #endif extern const uint8_t zero_buffer[ZERO_BUF_SIZE]; |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-11 22:45:22
|
Commit-ID: 50fe0b5904bce8b00eeb4f6ec7a9ac080e1a823c Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=50fe0b5904bce8b00eeb4f6ec7a9ac080e1a823c Author: H. Peter Anvin <hp...@zy...> AuthorDate: Mon, 8 Feb 2016 10:10:57 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Mon, 8 Feb 2016 10:10:57 -0800 nasmlib: Factor out common code from the panic() macro There is no reason to pass a constant and a string from each call site. Move that into a separate out of line function. Signed-off-by: H. Peter Anvin <hp...@zy...> --- nasmlib.c | 5 +++++ nasmlib.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nasmlib.c b/nasmlib.c index 3c26546..656350d 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -92,6 +92,11 @@ no_return nasm_panic(int flags, const char *fmt, ...) abort(); /* We should never get here */ } +no_return nasm_panic_from_macro(const char *file, int line) +{ + nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line); +} + void *nasm_malloc(size_t size) { void *p = malloc(size); diff --git a/nasmlib.h b/nasmlib.h index f480c06..dfce1dd 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -78,7 +78,8 @@ typedef void (*vefunc) (int severity, const char *fmt, va_list ap); void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...); void nasm_set_verror(vefunc); no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...); -#define panic() nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", __FILE__, __LINE__); +no_return nasm_panic_from_macro(const char *file, int line); +#define panic() nasm_panic_from_macro(__FILE__, __LINE__); /* * These are the error severity codes which get passed as the first |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-11 22:45:22
|
Commit-ID: 5a8c424d0c4b63d14eb1120475ebc3dee38bac8c Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=5a8c424d0c4b63d14eb1120475ebc3dee38bac8c Author: H. Peter Anvin <hp...@li...> AuthorDate: Fri, 29 Jan 2016 12:05:27 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Fri, 29 Jan 2016 12:05:27 -0800 Use a more optimal value for the UNUSED slot Instead of ~1/4 the range we can use ~1/3 the range for better distance. It is possible that using ~1/2 - 1 might be even better, but this is a trivial tweak. Signed-off-by: H. Peter Anvin <hp...@li...> --- directiv.pl | 2 +- macros.pl | 2 +- pptok.pl | 2 +- tokhash.pl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/directiv.pl b/directiv.pl index 51d0ec3..b567aff 100755 --- a/directiv.pl +++ b/directiv.pl @@ -143,7 +143,7 @@ if ($output eq 'h') { # Put a large value in unused slots. This makes it extremely unlikely # that any combination that involves unused slot will pass the range test. # This speeds up rejection of unrecognized tokens, i.e. identifiers. - print C "#define UNUSED 16383\n"; + print C "#define UNUSED (65535/3)\n"; print C " static const int16_t hash1[$n] = {\n"; for ($i = 0; $i < $n; $i++) { diff --git a/macros.pl b/macros.pl index e64fead..67aa08c 100755 --- a/macros.pl +++ b/macros.pl @@ -225,7 +225,7 @@ print OUT " };\n"; # Put a large value in unused slots. This makes it extremely unlikely # that any combination that involves unused slot will pass the range test. # This speeds up rejection of unrecognized tokens, i.e. identifiers. -print OUT "#define UNUSED 16383\n"; +print OUT "#define UNUSED (65535/3)\n"; print OUT " static const int16_t hash1[$n] = {\n"; for ($i = 0; $i < $n; $i++) { diff --git a/pptok.pl b/pptok.pl index 1ea2e7e..2dbf0fe 100755 --- a/pptok.pl +++ b/pptok.pl @@ -207,7 +207,7 @@ if ($what eq 'c') { # Put a large value in unused slots. This makes it extremely unlikely # that any combination that involves unused slot will pass the range test. # This speeds up rejection of unrecognized tokens, i.e. identifiers. - print OUT "#define UNUSED 16383\n"; + print OUT "#define UNUSED (65535/3)\n"; print OUT " static const int16_t hash1[$n] = {\n"; for ($i = 0; $i < $n; $i++) { diff --git a/tokhash.pl b/tokhash.pl index 509520b..07bc6ab 100755 --- a/tokhash.pl +++ b/tokhash.pl @@ -232,7 +232,7 @@ if ($output eq 'h') { # Put a large value in unused slots. This makes it extremely unlikely # that any combination that involves unused slot will pass the range test. # This speeds up rejection of unrecognized tokens, i.e. identifiers. - print "#define UNUSED 16383\n"; + print "#define UNUSED (65535/3)\n"; print " static const int16_t hash1[$n] = {\n"; for ($i = 0; $i < $n; $i++) { |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-02-11 22:45:22
|
Commit-ID: c5123e9482fff0b86b30bda74e94ae2d66ef01bf Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=c5123e9482fff0b86b30bda74e94ae2d66ef01bf Author: H. Peter Anvin <hp...@zy...> AuthorDate: Thu, 28 Jan 2016 20:44:33 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Thu, 28 Jan 2016 20:44:33 -0800 nasmlib.h: If BUFSIZ is bigger than the default ZERO_BUF_SIZE, adjust If BUFSIZ exists and is bigger than the default ZERO_BUF_SIZE, expand ZERO_BUF_SIZE so we don't end up unnecessarily double buffering in the stdio library. Signed-off-by: H. Peter Anvin <hp...@zy...> --- nasmlib.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nasmlib.h b/nasmlib.h index 9cd417f..e8526ab 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -409,7 +409,10 @@ char *nasm_realpath(const char *rel_path); const char *prefix_name(int); -#define ZERO_BUF_SIZE 4096 +#define ZERO_BUF_SIZE 4096 /* Default value */ +#if defined(BUFSIZ) && (BUFSIZ > ZERO_BUF_SIZE) +# define ZERO_BUF_SIZE BUFSIZ +#endif extern const uint8_t zero_buffer[ZERO_BUF_SIZE]; void fwritezero(size_t bytes, FILE *fp); |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-01-27 23:10:40
|
Commit-ID: 02237cbfe8056e48355f97f847ab4b063ffe0b7f Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=02237cbfe8056e48355f97f847ab4b063ffe0b7f Author: H. Peter Anvin <hp...@li...> AuthorDate: Wed, 27 Jan 2016 14:48:04 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Wed, 27 Jan 2016 14:48:04 -0800 NASM 2.12rc2 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 34ed03a..e697fe6 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12rc1 +2.12rc2 |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-01-27 22:33:19
|
Commit-ID: e8677d68186f5faadf30869b22abcd730bc293fc Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=e8677d68186f5faadf30869b22abcd730bc293fc Author: H. Peter Anvin <hp...@li...> AuthorDate: Wed, 27 Jan 2016 14:29:40 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Wed, 27 Jan 2016 14:29:40 -0800 compiler.h: disable __STRICT_ANSI__ for djgpp Undefine __STRICT_ANSI__ for djgpp; it removes the prototypes for non-ANSI functions which is not at all what this symbol is intended for. Signed-off-by: H. Peter Anvin <hp...@li...> --- compiler.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler.h b/compiler.h index 62425c8..de7c0e4 100644 --- a/compiler.h +++ b/compiler.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2007-2009 The NASM Authors - All Rights Reserved + * Copyright 2007-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -43,6 +43,11 @@ #ifndef NASM_COMPILER_H #define NASM_COMPILER_H 1 +#ifdef __DJGPP__ +/* DJGPP has header file problems if __STRICT_ANSI__ is defined */ +# undef __STRICT_ANSI__ +#endif + #ifdef HAVE_CONFIG_H # include "config.h" /* autoconf doesn't define these if they are redundant, but we want to |
From: nasm-bot f. H. P. A. <hp...@li...> - 2016-01-27 22:33:17
|
Commit-ID: 064af69d627f26970b5763dbf984ce7ecd5fe4ea Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=064af69d627f26970b5763dbf984ce7ecd5fe4ea Author: H. Peter Anvin <hp...@li...> AuthorDate: Wed, 27 Jan 2016 14:28:32 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Wed, 27 Jan 2016 14:28:32 -0800 realpath.c: remove testing #ifdef unintentionally left in Remove the #if 0 for canonicalize_file_name(). This was added to test the realpath() code, and inadvertently left in. Signed-off-by: H. Peter Anvin <hp...@li...> --- realpath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realpath.c b/realpath.c index a1c2101..82adfc9 100644 --- a/realpath.c +++ b/realpath.c @@ -49,7 +49,7 @@ #include "nasmlib.h" -#if 0 /* def HAVE_CANONICALIZE_FILE_NAME */ +#ifdef HAVE_CANONICALIZE_FILE_NAME /* * GNU-specific, but avoids the realpath(..., NULL) |
From: nasm-bot f. K. S. O. <bir...@an...> - 2016-01-26 20:36:20
|
Commit-ID: 3c72a1b3b301909548474e0d74b64f6d1383131f Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=3c72a1b3b301909548474e0d74b64f6d1383131f Author: Knut St. Osmundsen <bir...@an...> AuthorDate: Tue, 10 Nov 2015 22:07:20 +0100 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Tue, 26 Jan 2016 12:34:41 -0800 Add option to allow 64-bit code in any output format Add the option --allow-64-bit to permit the generation of 64-bit code even for a 16/32-bit output format. Using NASM to do some boot strapping code and ran into trouble when trying to emit a few 64-bit instructions in the OMF object file doing the mode switching. While I can see how the "error: obj output format does not support 64-bit code" message can be a useful reality check for application programmers, it prevents low-level programmers from doing what they want. It if was just a harmless warning, it wouldn't be so bad, but it turns BITS 64 into BITS 16. The main trick to mixing 64-bit code into OMF and other 32-bit output formats is to avoid 64-bit sized fixups, which normally isn't too hard. [hpa: shortened the option name to --allow-64-bit, minor code cleanups] Signed-off-by: Knut St. Osmundsen <bir...@an...> Signed-off-by: H. Peter Anvin <hp...@zy...> --- doc/nasmdoc.src | 16 +++++++++++++--- nasm.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index e468248..ec0cfcc 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -1,6 +1,6 @@ \# -------------------------------------------------------------------------- \# -\# Copyright 1996-2014 The NASM Authors - All Rights Reserved +\# Copyright 1996-2016 The NASM Authors - All Rights Reserved \# See the file AUTHORS included with the NASM distribution for \# the specific copyright holders. \# @@ -1006,8 +1006,18 @@ is indicated by an asterisk. For example: The \c{--prefix} and \c{--postfix} options prepend or append (respectively) the given argument to all \c{global} or \c{extern} variables. E.g. \c{--prefix _} will prepend the -underscore to all global and external variables, as C sometimes -(but not always) likes it. +underscore to all global and external variables, as C requires it in +some, but not all, system calling conventions. + + +\S{opt-allow64bit} The \i\c{--allow-64-bit} Option. + +The \c{--allow-64-bit} option allows using 64-bit instructions in a +32-bit or 16-bit output format. This is useful in a few situations, +such as when writing code switching from 32-bit to 64-bit mode and +linking into a 32-bit module. However, it is important to be aware of +the restriction the output format poses on you in terms of +relocations. Use with caution! \S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable diff --git a/nasm.c b/nasm.c index 8557b4d..17ee553 100644 --- a/nasm.c +++ b/nasm.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2013 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -88,6 +88,7 @@ static int using_debug_info, opt_verbose_info; bool tasm_compatible_mode = false; int pass0, passn; int maxbits = 0; +static bool allow_64_bit = false; int globalrel = 0; int globalbnd = 0; @@ -614,11 +615,15 @@ struct textargs { int value; }; -#define OPT_PREFIX 0 -#define OPT_POSTFIX 1 +enum text_options { + OPT_PREFIX, + OPT_POSTFIX, + OPT_ALLOW_64_BIT +}; struct textargs textopts[] = { {"prefix", OPT_PREFIX}, {"postfix", OPT_POSTFIX}, + {"allow-64-bit", OPT_ALLOW_64_BIT}, {NULL, 0} }; @@ -804,7 +809,10 @@ static bool process_arg(char *p, char *q) " -h show invocation summary and exit\n\n" "--prefix,--postfix\n" " this options prepend or append the given argument to all\n" - " extern and global variables\n\n" + " extern and global variables\n" + "--allow-64-bit\n" + " do not restrict 64-bit code to 64-bit capable output\n" + " formats (use with care, no complaining)\n\n" "Warnings:\n"); for (i = 0; i <= ERR_WARN_MAX; i++) printf(" %-23s %s (default %s)\n", @@ -959,18 +967,23 @@ set_warning: advance = 1, param = q; } - if (s == OPT_PREFIX) { - strncpy(lprefix, param, PREFIX_MAX - 1); - lprefix[PREFIX_MAX - 1] = 0; + switch (s) { + case OPT_PREFIX: + strlcpy(lprefix, param, PREFIX_MAX); break; - } - if (s == OPT_POSTFIX) { - strncpy(lpostfix, param, POSTFIX_MAX - 1); - lpostfix[POSTFIX_MAX - 1] = 0; + case OPT_POSTFIX: + strlcpy(lpostfix, param, POSTFIX_MAX); + break; + default: + nasm_error(ERR_PANIC | ERR_NOFILE, + "internal error"); break; } break; } + case OPT_ALLOW_64_BIT: + allow_64_bit = true; + break; default: { nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, @@ -2088,7 +2101,7 @@ static int get_bits(char *value) "cannot specify 64-bit segment on processor below an x86-64"); i = 16; } - if (i != maxbits) { + if (i != maxbits && !allow_64_bit) { nasm_error(ERR_NONFATAL, "%s output format does not support 64-bit code", ofmt->shortname); |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-01-26 20:12:16
|
Commit-ID: ad790a2e39219e89a08a49a05d984c38849c5b76 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ad790a2e39219e89a08a49a05d984c38849c5b76 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Tue, 26 Jan 2016 12:07:58 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Tue, 26 Jan 2016 12:07:58 -0800 make alldeps to remove unnecessary dependencies for realpath.c The previous commit contained unnecessary dependencies for realpath.c so run make alldeps to remove those. Signed-off-by: H. Peter Anvin <hp...@zy...> --- Makefile.in | 4 +--- Mkfiles/msvc.mak | 4 +--- Mkfiles/netware.mak | 4 +--- Mkfiles/openwcom.mak | 4 +--- Mkfiles/owlinux.mak | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Makefile.in b/Makefile.in index 568549d..e788547 100644 --- a/Makefile.in +++ b/Makefile.in @@ -429,9 +429,7 @@ preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h -realpath.$(O): realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h \ - insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \ - tables.h tokens.h +realpath.$(O): realpath.c compiler.h config.h nasmlib.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 93e910e..f7d78b3 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -344,9 +344,7 @@ preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h -realpath.$(O): realpath.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ - insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \ - tokens.h +realpath.$(O): realpath.c compiler.h nasmlib.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 68a2118..68741ba 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -248,9 +248,7 @@ preproc.o: preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ quote.o: quote.c compiler.h config.h nasmlib.h quote.h raa.o: raa.c compiler.h config.h nasmlib.h raa.h rbtree.o: rbtree.c compiler.h config.h rbtree.h -realpath.o: realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h \ - insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \ - tables.h tokens.h +realpath.o: realpath.c compiler.h config.h nasmlib.h regdis.o: regdis.c regdis.h regs.h regflags.o: regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 7f69f7d..91a7d2f 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -396,9 +396,7 @@ preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h & quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h -realpath.$(O): realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h & - insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h & - tables.h tokens.h +realpath.$(O): realpath.c compiler.h config.h nasmlib.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h & nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 90c7b35..a7d0d18 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -358,9 +358,7 @@ preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h -realpath.$(O): realpath.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ - insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \ - tokens.h +realpath.$(O): realpath.c compiler.h nasmlib.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h pptok.h preproc.h regs.h tables.h |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-01-26 20:06:23
|
Commit-ID: 4627e695a5f3b79b96578a86ac8273580f506205 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=4627e695a5f3b79b96578a86ac8273580f506205 Author: H. Peter Anvin <hp...@zy...> AuthorDate: Tue, 26 Jan 2016 12:01:34 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Tue, 26 Jan 2016 12:01:34 -0800 Portability improvements to nasm_realpath() Try harder to nasm_realpath() to be as portable as possible. Move it to a separate file since it has gotten complex enough that it is cleaner that way. Signed-off-by: H. Peter Anvin <hp...@zy...> --- Makefile.in | 15 ++++-- Mkfiles/msvc.mak | 18 +++++-- Mkfiles/netware.mak | 12 ++++- Mkfiles/openwcom.mak | 12 ++++- Mkfiles/owlinux.mak | 12 ++++- configure.in | 11 +++++ nasmlib.c | 12 ----- realpath.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 201 insertions(+), 22 deletions(-) diff --git a/Makefile.in b/Makefile.in index 56f3589..568549d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -74,6 +74,7 @@ endif #-- Begin File Lists --# NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ raa.$(O) saa.$(O) rbtree.$(O) \ + realpath.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ directiv.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ @@ -84,15 +85,16 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(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) preproc.$(O) quote.$(O) pptok.$(O) \ + output/outmac64.$(O) \ + md5c.$(O) output/codeview.$(O) \ + preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ - iflag.$(O) \ - md5c.$(O) output/codeview.$(O) + iflag.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ @@ -343,6 +345,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h \ macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h \ tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \ iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \ opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h \ @@ -353,6 +356,9 @@ nasmlib.$(O): nasmlib.c compiler.h config.h directiv.h iflag.h iflaggen.h \ ndisasm.$(O): ndisasm.c compiler.h config.h directiv.h disasm.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \ regs.h sync.h tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h config.h directiv.h \ + insnsi.h md5.h nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h \ + pptok.h preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.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 @@ -423,6 +429,9 @@ preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h +realpath.$(O): realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h \ + insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \ + tables.h tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a2bae67..93e910e 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -25,7 +25,8 @@ CC = cl LD = link CFLAGS = $(CFLAGS) /W2 BUILD_CFLAGS = $(CFLAGS) /I$(srcdir)/inttypes -INTERNAL_CFLAGS = /I$(srcdir) /I. /DHAVE__SNPRINTF /DHAVE__VSNPRINTF +INTERNAL_CFLAGS = /I$(srcdir) /I. \ + /DHAVE__SNPRINTF /DHAVE__VSNPRINTF /DHAVE__FULLPATH ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS) LDFLAGS = $(LDFLAGS) /SUBSYSTEM:CONSOLE LIBS = @@ -44,6 +45,7 @@ X = .exe # Edit in Makefile.in, not here! NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ raa.$(O) saa.$(O) rbtree.$(O) \ + realpath.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ directiv.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ @@ -54,15 +56,16 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(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) preproc.$(O) quote.$(O) pptok.$(O) \ + output/outmac64.$(O) \ + md5c.$(O) output/codeview.$(O) \ + preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ - iflag.$(O) \ - md5c.$(O) output/codeview.$(O) + iflag.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ @@ -263,6 +266,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \ output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -273,6 +277,9 @@ nasmlib.$(O): nasmlib.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h iflag.h iflaggen.h \ insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h \ tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h directiv.h insnsi.h md5.h \ + nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h pptok.h \ + preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.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/nullout.$(O): output/nullout.c compiler.h directiv.h insnsi.h nasm.h \ @@ -337,6 +344,9 @@ preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h +realpath.$(O): realpath.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ + insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \ + tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 0bc23e5..68a2118 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -32,6 +32,7 @@ O = o # Edit in Makefile.in, not here! NASM = nasm.o nasmlib.o ver.o \ raa.o saa.o rbtree.o \ + realpath.o \ float.o insnsa.o insnsb.o \ directiv.o \ assemble.o labels.o hashtbl.o crc64.o parser.o \ @@ -42,7 +43,9 @@ NASM = nasm.o nasmlib.o ver.o \ outelfx32.o \ outobj.o outas86.o outrdf2.o \ outdbg.o outieee.o outmac32.o \ - outmac64.o preproc.o quote.o pptok.o \ + outmac64.o \ + md5c.o codeview.o \ + preproc.o quote.o pptok.o \ macros.o listing.o eval.o exprlib.o stdscan.o \ strfunc.o tokhash.o regvals.o regflags.o \ ilog2.o \ @@ -171,6 +174,7 @@ listing.o: listing.c compiler.h config.h directiv.h insnsi.h listing.h \ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.o: macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h tables.h +md5c.o: md5c.c md5.h nasm.o: nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \ iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \ opflags.h outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -181,6 +185,9 @@ nasmlib.o: nasmlib.c compiler.h config.h directiv.h iflag.h iflaggen.h \ ndisasm.o: ndisasm.c compiler.h config.h directiv.h disasm.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \ regs.h sync.h tables.h tokens.h +codeview.o: codeview.c compiler.h config.h directiv.h insnsi.h md5.h nasm.h \ + nasmlib.h opflags.h outlib.h pecoff.h pptok.h preproc.h regs.h saa.h \ + tables.h version.h nulldbg.o: nulldbg.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 nullout.o: nullout.c compiler.h config.h directiv.h insnsi.h nasm.h \ @@ -241,6 +248,9 @@ preproc.o: preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ quote.o: quote.c compiler.h config.h nasmlib.h quote.h raa.o: raa.c compiler.h config.h nasmlib.h raa.h rbtree.o: rbtree.c compiler.h config.h rbtree.h +realpath.o: realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h \ + insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \ + tables.h tokens.h regdis.o: regdis.c regdis.h regs.h regflags.o: regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 2d85eba..7f69f7d 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -48,6 +48,7 @@ X = .exe # Edit in Makefile.in, not here! NASM = nasm.$(O) nasmlib.$(O) ver.$(O) & raa.$(O) saa.$(O) rbtree.$(O) & + realpath.$(O) & float.$(O) insnsa.$(O) insnsb.$(O) & directiv.$(O) & assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) & @@ -58,7 +59,9 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(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) preproc.$(O) quote.$(O) pptok.$(O) & + output/outmac64.$(O) & + md5c.$(O) output/codeview.$(O) & + preproc.$(O) quote.$(O) pptok.$(O) & macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) & strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) & ilog2.$(O) & @@ -309,6 +312,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h & macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h & nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h & tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h & iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h & opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h & @@ -319,6 +323,9 @@ nasmlib.$(O): nasmlib.c compiler.h config.h directiv.h iflag.h iflaggen.h & ndisasm.$(O): ndisasm.c compiler.h config.h directiv.h disasm.h iflag.h & iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h & regs.h sync.h tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h config.h directiv.h & + insnsi.h md5.h nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h & + pptok.h preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.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 @@ -389,6 +396,9 @@ preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h & quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h +realpath.$(O): realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h & + insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h & + tables.h tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h & nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 85ad1b8..90c7b35 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -59,6 +59,7 @@ X = .exe # Edit in Makefile.in, not here! NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ raa.$(O) saa.$(O) rbtree.$(O) \ + realpath.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ directiv.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ @@ -69,7 +70,9 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(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) preproc.$(O) quote.$(O) pptok.$(O) \ + output/outmac64.$(O) \ + md5c.$(O) output/codeview.$(O) \ + preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ @@ -277,6 +280,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \ output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -287,6 +291,9 @@ nasmlib.$(O): nasmlib.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h iflag.h iflaggen.h \ insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h \ tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h directiv.h insnsi.h md5.h \ + nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h pptok.h \ + preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.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/nullout.$(O): output/nullout.c compiler.h directiv.h insnsi.h nasm.h \ @@ -351,6 +358,9 @@ preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h +realpath.$(O): realpath.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ + insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \ + tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h pptok.h preproc.h regs.h tables.h diff --git a/configure.in b/configure.in index fba5d32..f327426 100644 --- a/configure.in +++ b/configure.in @@ -126,6 +126,12 @@ AC_CHECK_HEADERS(strings.h) dnl Look for <stdbool.h> AC_CHECK_HEADERS(stdbool.h) +dnl Look for <unistd.h> +AC_CHECK_HEADERS(unistd.h) + +dnl Look for <sys/param.h> +AC_CHECK_HEADERS(sys/param.h) + dnl Checks for library functions. AC_SUBST(XOBJS) @@ -155,6 +161,11 @@ AC_CHECK_FUNCS(strlcpy) AC_CHECK_FUNCS(getuid) AC_CHECK_FUNCS(getgid) +AC_CHECK_FUNCS(realpath) +AC_CHECK_FUNCS(canonicalize_file_name) +AC_CHECK_FUNCS(_fullpath) +AC_CHECK_FUNCS(pathconf) + dnl Check for functions that might not be declared in the headers for dnl various idiotic reasons (mostly because of library authors dnl abusing the meaning of __STRICT_ANSI__) diff --git a/nasmlib.c b/nasmlib.c index 9d57adb..ecd6d8d 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -696,18 +696,6 @@ char *nasm_opt_val(char *p, char **val, char **next) return p; } -#ifdef _WIN32 -char *nasm_realpath(const char *rel_path) -{ - return _fullpath(NULL, rel_path, 0); -} -#else -char *nasm_realpath(const char *rel_path) -{ - return realpath(rel_path, NULL); -} -#endif - /* * initialized data bytes length from opcode */ diff --git a/realpath.c b/realpath.c new file mode 100644 index 0000000..a1c2101 --- /dev/null +++ b/realpath.c @@ -0,0 +1,131 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2016 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. + * + * ----------------------------------------------------------------------- */ + +/* + * realpath.c As system-independent as possible implementation of realpath() + */ + +#include "compiler.h" + +#include <stdlib.h> +#include <errno.h> +#include <limits.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif +#ifdef HAVE_SYS_PARAM_H +# include <sys/param.h> +#endif + +#include "nasmlib.h" + +#if 0 /* def HAVE_CANONICALIZE_FILE_NAME */ + +/* + * GNU-specific, but avoids the realpath(..., NULL) + * portability problem if it exists. + */ +char *nasm_realpath(const char *rel_path) +{ + return canonicalize_file_name(rel_path); +} + +#elif defined(HAVE_REALPATH) + +/* + * POSIX.1-2008 defines realpath(..., NULL); POSIX.1-2001 doesn't guarantee + * that a NULL second argument is supported. + */ + +char *nasm_realpath(const char *rel_path) +{ + char *buf; + + buf = realpath(rel_path, NULL); + if (buf) + return buf; + + /* Not all implemetations of realpath() support a NULL second argument */ + if (errno == EINVAL) { + 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) + path_max = 65536; /* Crazily high, we hope */ + + buf = nasm_malloc(path_max); + + if (!realpath(rel_path, buf)) { + nasm_free(buf); + buf = NULL; + } else { + /* On some systems, pathconf() can return a very large value */ + + buf[path_max - 1] = '\0'; /* Just in case overrun is possible */ + buf = nasm_realloc(buf, strlen(buf) + 1); + } + } + + return buf; +} + +#elif defined(HAVE__FULLPATH) + +/* + * win32/win64 API + */ + +char *nasm_realpath(const char *rel_path) +{ + return _fullpath(NULL, rel_path, 0); +} + +#else + +/* + * There is nothing we know how to do here, so hope it just works anyway. + */ + +char *nasm_realpath(const char *rel_path) +{ + return nasm_strdup(rel_path); +} + +#endif |
From: nasm-bot f. H. P. A. <hp...@zy...> - 2016-01-26 20:06:21
|
Commit-ID: 2ad64d697442303834c44375769ae44bdd701f5c Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=2ad64d697442303834c44375769ae44bdd701f5c Author: H. Peter Anvin <hp...@zy...> AuthorDate: Tue, 26 Jan 2016 12:04:49 -0800 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Tue, 26 Jan 2016 12:04:49 -0800 NASM 2.12rc1 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 690b7ad..34ed03a 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.11.09rc2 +2.12rc1 |
From: nasm-bot f. J. K. <jam...@li...> - 2016-01-24 11:18:33
|
Commit-ID: 3115e789d68a3586489a2972f379beb8a012e271 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=3115e789d68a3586489a2972f379beb8a012e271 Author: Jim Kukunas <jam...@li...> AuthorDate: Sat, 23 Jan 2016 23:32:51 -0800 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Sun, 24 Jan 2016 14:14:39 +0300 coff: Add support for the Codeview 8 debug format Codeview is a debug format for win32/win64 PE/COFF files. It adds two sections, .debug$S (symbols) and .debug$T (types), to the generated object file. These sections are then used by the linker to generate a PDB file which can be used by various debuggers (WinDbg, Visual Studio, etc). Signed-off-by: Jim Kukunas <jam...@li...> Acked-by: H. Peter Anvin <hp...@zy...> Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- Makefile.in | 2 +- Mkfiles/msvc.mak | 2 +- output/codeview.c | 720 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ output/outcoff.c | 310 ++++++++++++----------- output/pecoff.h | 55 +++++ 5 files changed, 927 insertions(+), 162 deletions(-) diff --git a/Makefile.in b/Makefile.in index 9894d33..56f3589 100644 --- a/Makefile.in +++ b/Makefile.in @@ -92,7 +92,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ iflag.$(O) \ - md5c.$(O) + md5c.$(O) output/codeview.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a4df3e3..a2bae67 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -62,7 +62,7 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ iflag.$(O) \ - md5c.$(O) + md5c.$(O) output/codeview.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ diff --git a/output/codeview.c b/output/codeview.c new file mode 100644 index 0000000..4256e8d --- /dev/null +++ b/output/codeview.c @@ -0,0 +1,720 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1996-2010 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. + * + * ----------------------------------------------------------------------- */ + +/* + * codeview.c Codeview Debug Format support for COFF + */ + +#include "version.h" +#include "compiler.h" + +#include <stdio.h> +#include <stddef.h> +#include <stdlib.h> + +#include "nasm.h" +#include "nasmlib.h" +#include "saa.h" +#include "output/outlib.h" +#include "output/pecoff.h" +#include "md5.h" + +static void cv8_init(void); +static void cv8_linenum(const char *filename, int32_t linenumber, + int32_t segto); +static void cv8_deflabel(char *name, int32_t segment, int64_t offset, + int is_global, char *special); +static void cv8_typevalue(int32_t type); +static void cv8_output(int type, void *param); +static void cv8_cleanup(void); + +struct dfmt df_cv8 = { + .fullname = "Codeview 8", + .shortname = "cv8", + .init = cv8_init, + .linenum = cv8_linenum, + .debug_deflabel = cv8_deflabel, + .debug_directive = null_debug_directive, + .debug_typevalue = cv8_typevalue, + .debug_output = cv8_output, + .cleanup = cv8_cleanup, +}; + +/******************************************************************************* + * dfmt callbacks + ******************************************************************************/ +struct source_file { + char *name; + unsigned char md5sum[MD5_HASHBYTES]; +}; + +struct linepair { + uint32_t file_offset; + uint32_t linenumber; +}; + +enum symbol_type { + SYMTYPE_CODE, + SYMTYPE_PROC, + SYMTYPE_LDATA, + SYMTYPE_GDATA, + + SYMTYPE_MAX, +}; + +struct cv8_symbol { + enum symbol_type type; + char *name; + + uint32_t secrel; + uint16_t section; + uint32_t size; + uint32_t typeindex; + + enum symtype { + TYPE_UNREGISTERED = 0x0000, /* T_NOTYPE */ + TYPE_BYTE = 0x0020, + TYPE_WORD = 0x0021, + TYPE_DWORD= 0x0022, + TYPE_QUAD = 0x0023, + + TYPE_REAL32 = 0x0040, + TYPE_REAL64 = 0x0041, + TYPE_REAL80 = 0x0042, + TYPE_REAL128= 0x0043, + TYPE_REAL256= 0x0044, + TYPE_REAL512= 0x0045, + } symtype; +}; + +struct cv8_state { + int symbol_sect; + int type_sect; + + uint32_t text_offset; + + struct source_file source_file; + + struct SAA *lines; + uint32_t num_lines; + + struct SAA *symbols; + struct cv8_symbol *last_sym; + unsigned num_syms[SYMTYPE_MAX]; + unsigned symbol_lengths; + unsigned total_syms; + + char *cwd; +}; +struct cv8_state cv8_state; + +static void cv8_init(void) +{ + const uint32_t sect_flags = IMAGE_SCN_MEM_READ | + IMAGE_SCN_MEM_DISCARDABLE | + IMAGE_SCN_CNT_INITIALIZED_DATA | + IMAGE_SCN_ALIGN_1BYTES; + + cv8_state.symbol_sect = coff_make_section(".debug$S", sect_flags); + cv8_state.type_sect = coff_make_section(".debug$T", sect_flags); + + cv8_state.text_offset = 0; + + cv8_state.lines = saa_init(sizeof(struct linepair)); + cv8_state.num_lines = 0; + + cv8_state.symbols = saa_init(sizeof(struct cv8_symbol)); + cv8_state.last_sym = NULL; + + cv8_state.cwd = nasm_realpath("."); +} + +static void register_file(const char *filename); +static struct coff_Section *find_section(int32_t segto); + +static void cv8_linenum(const char *filename, int32_t linenumber, + int32_t segto) +{ + struct coff_Section *s; + struct linepair *li; + + if (cv8_state.source_file.name == NULL) + register_file(filename); + + s = find_section(segto); + if (s == NULL) + return; + + if ((s->flags & IMAGE_SCN_MEM_EXECUTE) == 0) + return; + + li = saa_wstruct(cv8_state.lines); + li->file_offset = cv8_state.text_offset; + li->linenumber = linenumber; + + cv8_state.num_lines++; +} + +static void cv8_deflabel(char *name, int32_t segment, int64_t offset, + int is_global, char *special) +{ + int ret; + size_t len; + struct cv8_symbol *sym; + struct coff_Section *s; + + (void)special; + + s = find_section(segment); + if (s == NULL) + return; + + sym = saa_wstruct(cv8_state.symbols); + + if (s->flags & IMAGE_SCN_MEM_EXECUTE) + sym->type = is_global ? SYMTYPE_PROC : SYMTYPE_CODE; + else + sym->type = is_global ? SYMTYPE_GDATA : SYMTYPE_LDATA; + cv8_state.num_syms[sym->type]++; + cv8_state.total_syms++; + + sym->section = segment; + sym->secrel = offset; + sym->symtype = TYPE_UNREGISTERED; + sym->size = 0; + sym->typeindex = 0; + + /* handle local labels */ + if (name[0] == '.' && cv8_state.last_sym != NULL) { + len = strlen(cv8_state.last_sym->name) + strlen(name); + sym->name = nasm_malloc(len + 1); + ret = snprintf(sym->name, len + 1, "%s%s", + cv8_state.last_sym->name, name); + nasm_assert(ret > 0 && (size_t)ret == len); + } else { + len = strlen(name); + sym->name = nasm_malloc(len + 1); + ret = snprintf(sym->name, len + 1, "%s", name); + nasm_assert(ret > 0 && (size_t)ret == len); + } + + cv8_state.symbol_lengths += len + 1; + + if (cv8_state.last_sym && cv8_state.last_sym->section == segment) + cv8_state.last_sym->size = offset - cv8_state.last_sym->secrel; + cv8_state.last_sym = sym; +} + +static void cv8_typevalue(int32_t type) +{ + if (!cv8_state.last_sym) + return; + if (cv8_state.last_sym->symtype != TYPE_UNREGISTERED) + return; + + switch (TYM_TYPE(type)) { + case TY_BYTE: + cv8_state.last_sym->symtype = TYPE_BYTE; + break; + case TY_WORD: + cv8_state.last_sym->symtype = TYPE_WORD; + break; + case TY_DWORD: + cv8_state.last_sym->symtype = TYPE_DWORD; + break; + case TY_QWORD: + cv8_state.last_sym->symtype = TYPE_QUAD; + break; + case TY_FLOAT: + cv8_state.last_sym->symtype = TYPE_REAL32; + break; + case TY_TBYTE: + cv8_state.last_sym->symtype = TYPE_REAL80; + break; + case TY_OWORD: + cv8_state.last_sym->symtype = TYPE_REAL128; + break; + case TY_YWORD: + cv8_state.last_sym->symtype = TYPE_REAL256; + break; + case TY_UNKNOWN: + break; + case TY_LABEL: + break; + } +} + +static void cv8_output(int type, void *param) +{ + struct coff_DebugInfo *dinfo = param; + + (void)type; + + if (dinfo->section && dinfo->section->name && + !strncmp(dinfo->section->name, ".text", 5)) + cv8_state.text_offset += dinfo->size; +} + +static void build_symbol_table(struct coff_Section *const sect); +static void build_type_table(struct coff_Section *const sect); + +static void cv8_cleanup(void) +{ + struct cv8_symbol *sym; + + struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect]; + struct coff_Section *type_sect = coff_sects[cv8_state.type_sect]; + + build_symbol_table(symbol_sect); + build_type_table(type_sect); + + if (cv8_state.source_file.name != NULL) + free(cv8_state.source_file.name); + + if (cv8_state.cwd != NULL) + free(cv8_state.cwd); + + saa_free(cv8_state.lines); + + saa_rewind(cv8_state.symbols); + while ((sym = saa_rstruct(cv8_state.symbols))) + free(sym->name); + saa_free(cv8_state.symbols); +} + +/******************************************************************************* + * implementation + ******************************************************************************/ +static void calc_md5(const char *const filename, + unsigned char sum[MD5_HASHBYTES]) +{ + int success = 0; + unsigned char *file_buf; + FILE *f; + MD5_CTX ctx; + + f = fopen(filename, "r"); + if (!f) + goto done; + + file_buf = nasm_zalloc(BUFSIZ); + + MD5Init(&ctx); + while (!feof(f)) { + size_t i = fread(file_buf, 1, BUFSIZ, f); + if (ferror(f)) + goto done_0; + else if (i == 0) + break; + MD5Update(&ctx, file_buf, i); + } + MD5Final(sum, &ctx); + + success = 1; +done_0: + nasm_free(file_buf); + fclose(f); +done: + if (!success) { + nasm_error(ERR_NONFATAL, "unable to hash file %s. " + "Debug information may be unavailable.\n", + filename); + } + return; +} + +static void register_file(const char *filename) +{ + cv8_state.source_file.name = nasm_realpath(filename); + memset(cv8_state.source_file.md5sum, 0, MD5_HASHBYTES); + calc_md5(filename, cv8_state.source_file.md5sum); +} + +static struct coff_Section *find_section(int32_t segto) +{ + int i; + + for (i = 0; i < coff_nsects; i++) { + struct coff_Section *sec; + + sec = coff_sects[i]; + if (segto == sec->index) + return sec; + } + return NULL; +} + +static void register_reloc(struct coff_Section *const sect, + char *sym, uint32_t addr, uint16_t type) +{ + struct coff_Reloc *r; + struct coff_Section *sec; + + r = *sect->tail = nasm_malloc(sizeof(struct coff_Reloc)); + sect->tail = &r->next; + r->next = NULL; + sect->nrelocs++; + + r->address = addr; + r->symbase = SECT_SYMBOLS; + r->type = type; + + r->symbol = 0; + for (int i = 0; i < coff_nsects; i++) { + sec = coff_sects[i]; + if (!strcmp(sym, sec->name)) { + return; + } + r->symbol += 2; + } + + saa_rewind(coff_syms); + for (uint32_t i = 0; i < coff_nsyms; i++) { + struct coff_Symbol *s = saa_rstruct(coff_syms); + r->symbol++; + if (s->strpos == -1 && s->name && !strcmp(sym, s->name)) { + return; + } else if (s->strpos != -1) { + int res; + char *symname; + + symname = nasm_malloc(s->namlen + 1); + saa_fread(coff_strs, s->strpos-4, symname, s->namlen); + symname[s->namlen] = '\0'; + res = strcmp(sym, symname); + nasm_free(symname); + if (!res) + return; + } + } + nasm_assert(!"relocation for unregistered symbol"); +} + +static inline void section_write32(struct coff_Section *sect, uint32_t val) +{ + saa_write32(sect->data, val); + sect->len += 4; +} + +static inline void section_write16(struct coff_Section *sect, uint16_t val) +{ + saa_write16(sect->data, val); + sect->len += 2; +} + +static inline void section_write8(struct coff_Section *sect, uint8_t val) +{ + saa_write8(sect->data, val); + sect->len++; +} + +static inline void section_wbytes(struct coff_Section *sect, const void *buf, + size_t len) +{ + saa_wbytes(sect->data, buf, len); + sect->len += len; +} + +static void write_filename_table(struct coff_Section *const sect) +{ + uint32_t field_length = 0; + size_t filename_len = strlen(cv8_state.source_file.name); + + field_length = 1 + filename_len + 1; + + section_write32(sect, 0x000000F3); + section_write32(sect, field_length); + + section_write8(sect, 0); + section_wbytes(sect, cv8_state.source_file.name, filename_len + 1); +} + +static void write_sourcefile_table(struct coff_Section *const sect) +{ + uint32_t field_length = 0; + + field_length = 4 + 2 + MD5_HASHBYTES + 2; + + section_write32(sect, 0x000000F4); + section_write32(sect, field_length); + + section_write32(sect, 1); /* offset of filename in filename str table */ + section_write16(sect, 0x0110); + section_wbytes(sect, cv8_state.source_file.md5sum, MD5_HASHBYTES); + section_write16(sect, 0); +} + +static void write_linenumber_table(struct coff_Section *const sect) +{ + int i; + uint32_t field_length = 0; + size_t field_base; + struct coff_Section *s; + struct linepair *li; + + for (i = 0; i < coff_nsects; i++) { + if (!strncmp(coff_sects[i]->name, ".text", 5)) + break; + } + + if (i == coff_nsects) + return; + s = coff_sects[i]; + + field_length = 12 + 12 + (cv8_state.num_lines * 8); + + section_write32(sect, 0x000000F2); + section_write32(sect, field_length); + + field_base = sect->len; + section_write32(sect, 0); /* SECREL, updated by relocation */ + section_write16(sect, 0); /* SECTION, updated by relocation*/ + section_write16(sect, 0); /* pad */ + section_write32(sect, s->len); + + register_reloc(sect, ".text", field_base, + win64 ? IMAGE_REL_AMD64_SECREL : IMAGE_REL_I386_SECREL); + + register_reloc(sect, ".text", field_base + 4, + win64 ? IMAGE_REL_AMD64_SECTION : IMAGE_REL_I386_SECTION); + + /* 1 or more source mappings (we assume only 1) */ + section_write32(sect, 0); + section_write32(sect, cv8_state.num_lines); + section_write32(sect, 12 + (cv8_state.num_lines * 8)); + + /* the pairs */ + saa_rewind(cv8_state.lines); + while ((li = saa_rstruct(cv8_state.lines))) { + section_write32(sect, li->file_offset); + section_write32(sect, li->linenumber |= 0x80000000); + } +} + +static uint16_t write_symbolinfo_obj(struct coff_Section *sect, + const char sep) +{ + uint16_t obj_len; + + obj_len = 2 + 4 + strlen(cv8_state.cwd)+ 1 + strlen(coff_outfile) +1; + + section_write16(sect, obj_len); + section_write16(sect, 0x1101); + section_write32(sect, 0); /* ASM language */ + section_wbytes(sect, cv8_state.cwd, strlen(cv8_state.cwd)); + section_write8(sect, sep); + section_wbytes(sect, coff_outfile, strlen(coff_outfile)+1); + + return obj_len; +} + +static uint16_t write_symbolinfo_properties(struct coff_Section *sect, + const char *const creator_str) +{ + uint16_t creator_len; + + creator_len = 2 + 4 + 4 + 4 + 4 + strlen(creator_str)+1 + 2; + + section_write16(sect, creator_len); + section_write16(sect, 0x1116); + section_write32(sect, 3); /* language */ + if (win64) + section_write32(sect, 0x000000D0); + else if (win32) + section_write32(sect, 0x00000006); + else + nasm_assert(!"neither win32 nor win64 are set!"); + section_write32(sect, 0); /* flags*/ + section_write32(sect, 8); /* version */ + section_wbytes(sect, creator_str, strlen(creator_str)+1); + /* + * normally there would be key/value pairs here, but they aren't + * necessary. They are terminated by 2B + */ + section_write16(sect, 0); + + return creator_len; +} + +static uint16_t write_symbolinfo_symbols(struct coff_Section *sect) +{ + uint16_t len = 0, field_len; + uint32_t field_base; + struct cv8_symbol *sym; + + saa_rewind(cv8_state.symbols); + while ((sym = saa_rstruct(cv8_state.symbols))) { + switch (sym->type) { + case SYMTYPE_LDATA: + case SYMTYPE_GDATA: + field_len = 12 + strlen(sym->name) + 1; + len += field_len - 2; + section_write16(sect, field_len); + if (sym->type == SYMTYPE_LDATA) + section_write16(sect, 0x110C); + else + section_write16(sect, 0x110D); + section_write32(sect, sym->symtype); + + field_base = sect->len; + section_write32(sect, 0); /* SECREL */ + section_write16(sect, 0); /* SECTION */ + break; + case SYMTYPE_PROC: + case SYMTYPE_CODE: + field_len = 9 + strlen(sym->name) + 1; + len += field_len - 2; + section_write16(sect, field_len); + section_write16(sect, 0x1105); + + field_base = sect->len; + section_write32(sect, 0); /* SECREL */ + section_write16(sect, 0); /* SECTION */ + section_write8(sect, 0); /* FLAG */ + break; + default: + nasm_assert(!"unknown symbol type"); + } + + section_wbytes(sect, sym->name, strlen(sym->name) + 1); + + register_reloc(sect, sym->name, field_base, + win64 ? IMAGE_REL_AMD64_SECREL : + IMAGE_REL_I386_SECREL); + register_reloc(sect, sym->name, field_base + 4, + win64 ? IMAGE_REL_AMD64_SECTION : + IMAGE_REL_I386_SECTION); + } + + return len; +} + +static void write_symbolinfo_table(struct coff_Section *const sect) +{ + const char sep = '\\'; + const char *creator_str = "The Netwide Assembler " NASM_VER; + + + uint16_t obj_length, creator_length, sym_length; + uint32_t field_length = 0, out_len; + + /* signature, language, workingdir / coff_outfile NULL */ + obj_length = 2 + 4 + strlen(cv8_state.cwd)+ 1 + strlen(coff_outfile) +1; + creator_length = 2 + 4 + 4 + 4 + 4 + strlen(creator_str)+1 + 2; + + sym_length = ( cv8_state.num_syms[SYMTYPE_CODE] * 7) + + ( cv8_state.num_syms[SYMTYPE_PROC] * 7) + + ( cv8_state.num_syms[SYMTYPE_LDATA] * 10) + + ( cv8_state.num_syms[SYMTYPE_GDATA] * 10) + + cv8_state.symbol_lengths; + + field_length = 2 + obj_length + + 2 + creator_length + + (4 * cv8_state.total_syms) + sym_length; + + section_write32(sect, 0x000000F1); + section_write32(sect, field_length); + + /* for sub fields, length preceeds type */ + + out_len = write_symbolinfo_obj(sect, sep); + nasm_assert(out_len == obj_length); + + out_len = write_symbolinfo_properties(sect, creator_str); + nasm_assert(out_len == creator_length); + + out_len = write_symbolinfo_symbols(sect); + nasm_assert(out_len == sym_length); +} + +static inline void align4_table(struct coff_Section *const sect) +{ + unsigned diff; + uint32_t zero = 0; + struct SAA *data = sect->data; + + if (data->wptr % 4 == 0) + return; + + diff = 4 - (data->wptr % 4); + if (diff) + section_wbytes(sect, &zero, diff); +} + +static void build_symbol_table(struct coff_Section *const sect) +{ + section_write32(sect, 0x00000004); + + write_filename_table(sect); + align4_table(sect); + write_sourcefile_table(sect); + align4_table(sect); + write_linenumber_table(sect); + align4_table(sect); + write_symbolinfo_table(sect); + align4_table(sect); +} + +static void build_type_table(struct coff_Section *const sect) +{ + uint16_t field_len; + struct cv8_symbol *sym; + + section_write32(sect, 0x00000004); + + saa_rewind(cv8_state.symbols); + while ((sym = saa_rstruct(cv8_state.symbols))) { + if (sym->type != SYMTYPE_PROC) + continue; + + /* proc leaf */ + + field_len = 2 + 4 + 4 + 4 + 2; + section_write16(sect, field_len); + section_write16(sect, 0x1008); /* PROC type */ + + section_write32(sect, 0x00000003); /* return type */ + section_write32(sect, 0); /* calling convention (default) */ + section_write32(sect, sym->typeindex); + section_write16(sect, 0); /* # params */ + + /* arglist */ + + field_len = 2 + 4; + section_write16(sect, field_len); + section_write16(sect, 0x1201); /* ARGLIST */ + section_write32(sect, 0); /*num params */ + } +} + + diff --git a/output/outcoff.c b/output/outcoff.c index 2d55fd0..b45e4f1 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -100,47 +100,13 @@ */ /* Flag which version of COFF we are currently outputting. */ -static bool win32, win64; +bool win32, win64; static int32_t imagebase_sect; #define WRT_IMAGEBASE "..imagebase" -struct Reloc { - struct Reloc *next; - int32_t address; /* relative to _start_ of section */ - int32_t symbol; /* symbol number */ - enum { - SECT_SYMBOLS, - ABS_SYMBOL, - REAL_SYMBOLS - } symbase; /* relocation for symbol number :) */ - int16_t type; -}; - -struct Symbol { - char name[9]; - int32_t strpos; /* string table position of name */ - int32_t value; /* address, or COMMON variable size */ - int section; /* section number where it's defined - * - in COFF codes, not NASM codes */ - bool is_global; /* is it a global symbol or not? */ - int16_t type; /* 0 - notype, 0x20 - function */ - int32_t namlen; /* full name length */ -}; - -static char coff_infile[FILENAME_MAX]; - -struct Section { - struct SAA *data; - uint32_t len; - int nrelocs; - int32_t index; - struct Reloc *head, **tail; - uint32_t flags; /* section flags */ - char *name; - int32_t namepos; /* Offset of name into the strings table */ - int32_t pos, relpos; -}; +char coff_infile[FILENAME_MAX]; +char coff_outfile[FILENAME_MAX]; /* * Some common section flags by default @@ -198,11 +164,12 @@ struct Section { #define RDATA_FLAGS ((win32 | win64) ? RDATA_FLAGS_WIN : RDATA_FLAGS_DOS) #define SECT_DELTA 32 -static struct Section **sects; -static int nsects, sectlen; +struct coff_Section **coff_sects; +static int sectlen; +int coff_nsects; -static struct SAA *syms; -static uint32_t nsyms; +struct SAA *coff_syms; +uint32_t coff_nsyms; static int32_t def_seg; @@ -210,14 +177,14 @@ static int initsym; static struct RAA *bsym, *symval; -static struct SAA *strs; +struct SAA *coff_strs; static uint32_t strslen; static void coff_gen_init(void); -static void coff_sect_write(struct Section *, const uint8_t *, uint32_t); +static void coff_sect_write(struct coff_Section *, const uint8_t *, uint32_t); static void coff_write(void); static void coff_section_header(char *, int32_t, int32_t, int32_t, int32_t, int32_t, int, int32_t); -static void coff_write_relocs(struct Section *); +static void coff_write_relocs(struct coff_Section *); static void coff_write_symbols(void); static void coff_win32_init(void) @@ -246,46 +213,47 @@ static void coff_std_init(void) static void coff_gen_init(void) { - sects = NULL; - nsects = sectlen = 0; - syms = saa_init(sizeof(struct Symbol)); - nsyms = 0; + coff_sects = NULL; + coff_nsects = sectlen = 0; + coff_syms = saa_init(sizeof(struct coff_Symbol)); + coff_nsyms = 0; bsym = raa_init(); symval = raa_init(); - strs = saa_init(1); + coff_strs = saa_init(1); strslen = 0; def_seg = seg_alloc(); } static void coff_cleanup(int debuginfo) { - struct Reloc *r; + struct coff_Reloc *r; int i; - (void)debuginfo; + if (debuginfo && ofmt->current_dfmt->cleanup) + ofmt->current_dfmt->cleanup(); coff_write(); - for (i = 0; i < nsects; i++) { - if (sects[i]->data) - saa_free(sects[i]->data); - while (sects[i]->head) { - r = sects[i]->head; - sects[i]->head = sects[i]->head->next; + for (i = 0; i < coff_nsects; i++) { + if (coff_sects[i]->data) + saa_free(coff_sects[i]->data); + while (coff_sects[i]->head) { + r = coff_sects[i]->head; + coff_sects[i]->head = coff_sects[i]->head->next; nasm_free(r); } - nasm_free(sects[i]->name); - nasm_free(sects[i]); + nasm_free(coff_sects[i]->name); + nasm_free(coff_sects[i]); } - nasm_free(sects); - saa_free(syms); + nasm_free(coff_sects); + saa_free(coff_syms); raa_free(bsym); raa_free(symval); - saa_free(strs); + saa_free(coff_strs); } -static int coff_make_section(char *name, uint32_t flags) +int coff_make_section(char *name, uint32_t flags) { - struct Section *s; + struct coff_Section *s; size_t namelen; s = nasm_zalloc(sizeof(*s)); @@ -302,7 +270,7 @@ static int coff_make_section(char *name, uint32_t flags) if (namelen > 8) { if (win32 || win64) { s->namepos = strslen + 4; - saa_wbytes(strs, name, namelen + 1); + saa_wbytes(coff_strs, name, namelen + 1); strslen += namelen + 1; } else { namelen = 8; @@ -313,13 +281,13 @@ static int coff_make_section(char *name, uint32_t flags) s->name[namelen] = '\0'; s->flags = flags; - if (nsects >= sectlen) { + if (coff_nsects >= sectlen) { sectlen += SECT_DELTA; - sects = nasm_realloc(sects, sectlen * sizeof(*sects)); + coff_sects = nasm_realloc(coff_sects, sectlen * sizeof(*coff_sects)); } - sects[nsects++] = s; + coff_sects[coff_nsects++] = s; - return nsects - 1; + return coff_nsects - 1; } static inline int32_t coff_sectalign_flags(unsigned int align) @@ -418,10 +386,10 @@ static int32_t coff_section_names(char *name, int pass, int *bits) } } - for (i = 0; i < nsects; i++) - if (!strcmp(name, sects[i]->name)) + for (i = 0; i < coff_nsects; i++) + if (!strcmp(name, coff_sects[i]->name)) break; - if (i == nsects) { + if (i == coff_nsects) { if (!flags) { if (!strcmp(name, ".data")) flags = DATA_FLAGS; @@ -438,56 +406,56 @@ static int32_t coff_section_names(char *name, int pass, int *bits) } i = coff_make_section(name, flags); if (flags) - sects[i]->flags = flags; - sects[i]->flags &= align_and; - sects[i]->flags |= align_or; + coff_sects[i]->flags = flags; + coff_sects[i]->flags &= align_and; + coff_sects[i]->flags |= align_or; } else if (pass == 1) { /* Check if any flags are specified */ if (flags) { unsigned int align_flags = flags & IMAGE_SCN_ALIGN_MASK; /* Warn if non-alignment flags differ */ - if ((flags ^ sects[i]->flags) & ~IMAGE_SCN_ALIGN_MASK) { + if ((flags ^ coff_sects[i]->flags) & ~IMAGE_SCN_ALIGN_MASK) { nasm_error(ERR_WARNING, "section attributes ignored on" " redeclaration of section `%s'", name); } /* Check if alignment might be needed */ if (align_flags > IMAGE_SCN_ALIGN_1BYTES) { - unsigned int sect_align_flags = sects[i]->flags & IMAGE_SCN_ALIGN_MASK; + unsigned int sect_align_flags = coff_sects[i]->flags & IMAGE_SCN_ALIGN_MASK; /* Compute the actual alignment */ unsigned int align = 1u << ((align_flags - IMAGE_SCN_ALIGN_1BYTES) >> 20); /* Update section header as needed */ if (align_flags > sect_align_flags) { - sects[i]->flags = (sects[i]->flags & ~IMAGE_SCN_ALIGN_MASK) | align_flags; + coff_sects[i]->flags = (coff_sects[i]->flags & ~IMAGE_SCN_ALIGN_MASK) | align_flags; } /* Check if not already aligned */ - if (sects[i]->len % align) { - unsigned int padding = (align - sects[i]->len) % align; + if (coff_sects[i]->len % align) { + unsigned int padding = (align - coff_sects[i]->len) % align; /* We need to write at most 8095 bytes */ char buffer[8095]; - if (sects[i]->flags & IMAGE_SCN_CNT_CODE) { + if (coff_sects[i]->flags & IMAGE_SCN_CNT_CODE) { /* Fill with INT 3 instructions */ memset(buffer, 0xCC, padding); } else { memset(buffer, 0x00, padding); } - saa_wbytes(sects[i]->data, buffer, padding); - sects[i]->len += padding; + saa_wbytes(coff_sects[i]->data, buffer, padding); + coff_sects[i]->len += padding; } } } } - return sects[i]->index; + return coff_sects[i]->index; } static void coff_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { int pos = strslen + 4; - struct Symbol *sym; + struct coff_Symbol *sym; if (special) nasm_error(ERR_NONFATAL, "COFF format does not support any" @@ -501,12 +469,12 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset, if (strlen(name) > 8) { size_t nlen = strlen(name)+1; - saa_wbytes(strs, name, nlen); + saa_wbytes(coff_strs, name, nlen); strslen += nlen; } else pos = -1; - sym = saa_wstruct(syms); + sym = saa_wstruct(coff_syms); sym->strpos = pos; sym->namlen = strlen(name); @@ -519,8 +487,8 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset, else { int i; sym->section = 0; - for (i = 0; i < nsects; i++) - if (segment == sects[i]->index) { + for (i = 0; i < coff_nsects; i++) + if (segment == coff_sects[i]->index) { sym->section = i + 1; break; } @@ -537,20 +505,20 @@ static void coff_deflabel(char *name, int32_t segment, int64_t offset, * to these symbol records. */ if (sym->section == 0) - bsym = raa_write(bsym, segment, nsyms); + bsym = raa_write(bsym, segment, coff_nsyms); if (segment != NO_SEG) symval = raa_write(symval, segment, sym->section ? 0 : sym->value); - nsyms++; + coff_nsyms++; } -static int32_t coff_add_reloc(struct Section *sect, int32_t segment, +static int32_t coff_add_reloc(struct coff_Section *sect, int32_t segment, int16_t type) { - struct Reloc *r; + struct coff_Reloc *r; - r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); + r = *sect->tail = nasm_malloc(sizeof(struct coff_Reloc)); sect->tail = &r->next; r->next = NULL; @@ -560,8 +528,8 @@ static int32_t coff_add_reloc(struct Section *sect, int32_t segment, } else { int i; r->symbase = REAL_SYMBOLS; - for (i = 0; i < nsects; i++) { - if (segment == sects[i]->index) { + for (i = 0; i < coff_nsects; i++) { + if (segment == coff_sects[i]->index) { r->symbol = i * 2; r->symbase = SECT_SYMBOLS; break; @@ -587,7 +555,7 @@ static void coff_out(int32_t segto, const void *data, enum out_type type, uint64_t size, int32_t segment, int32_t wrt) { - struct Section *s; + struct coff_Section *s; uint8_t mydata[8], *p; int i; @@ -607,9 +575,9 @@ static void coff_out(int32_t segto, const void *data, } s = NULL; - for (i = 0; i < nsects; i++) { - if (segto == sects[i]->index) { - s = sects[i]; + for (i = 0; i < coff_nsects; i++) { + if (segto == coff_sects[i]->index) { + s = coff_sects[i]; break; } } @@ -618,7 +586,7 @@ static void coff_out(int32_t segto, const void *data, if (segto != coff_section_names(".text", 2, &tempint)) nasm_error(ERR_PANIC, "strange segment conditions in COFF driver"); else - s = sects[nsects - 1]; + s = coff_sects[coff_nsects - 1]; } /* magically default to 'wrt ..imagebase' in .pdata and .xdata */ @@ -636,6 +604,20 @@ static void coff_out(int32_t segto, const void *data, memset(mydata, 0, sizeof(mydata)); + if (ofmt->current_dfmt && ofmt->current_dfmt->debug_output) { + struct coff_DebugInfo dinfo; + dinfo.segto = segto; + dinfo.seg = segment; + dinfo.section = s; + + if (type == OUT_ADDRESS) + dinfo.size = abs(size); + else + dinfo.size = realsize(type, size); + + ofmt->current_dfmt->debug_output(type, &dinfo); + } + if (type == OUT_RESERVE) { if (s->data) { nasm_error(ERR_WARNING, "uninitialised space declared in" @@ -717,7 +699,7 @@ static void coff_out(int32_t segto, const void *data, } } -static void coff_sect_write(struct Section *sect, +static void coff_sect_write(struct coff_Section *sect, const uint8_t *data, uint32_t len) { saa_wbytes(sect->data, data, len); @@ -738,7 +720,7 @@ typedef struct tagString { */ static STRING *Exports = NULL; -static struct Section *directive_sec; +static struct coff_Section *directive_sec; static void AddExport(char *name) { STRING *rvp = Exports, *newS; @@ -751,15 +733,15 @@ static void AddExport(char *name) if (rvp == NULL) { int i; - for (i = 0; i < nsects; i++) { - if (!strcmp(EXPORT_SECTION_NAME, sects[i]->name)) + for (i = 0; i < coff_nsects; i++) { + if (!strcmp(EXPORT_SECTION_NAME, coff_sects[i]->name)) break; } - if (i == nsects) + if (i == coff_nsects) i = coff_make_section(EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS); - directive_sec = sects[i]; + directive_sec = coff_sects[i]; Exports = newS; } else { while (rvp->next) { @@ -827,10 +809,10 @@ static int coff_directives(enum directives directive, char *value, int pass) return 0; if (sxseg == -1) { - for (i = 0; i < nsects; i++) - if (!strcmp(".sxdata",sects[i]->name)) + for (i = 0; i < coff_nsects; i++) + if (!strcmp(".sxdata",coff_sects[i]->name)) break; - if (i == nsects) + if (i == coff_nsects) sxseg = coff_make_section(".sxdata", IMAGE_SCN_LNK_INFO); else sxseg = i; @@ -841,9 +823,9 @@ static int coff_directives(enum directives directive, char *value, int pass) */ if (pass0 == 2) { uint32_t n; - saa_rewind(syms); - for (n = 0; n < nsyms; n++) { - struct Symbol *sym = saa_rstruct(syms); + saa_rewind(coff_syms); + for (n = 0; n < coff_nsyms; n++) { + struct coff_Symbol *sym = saa_rstruct(coff_syms); bool equals; /* @@ -852,7 +834,7 @@ static int coff_directives(enum directives directive, char *value, int pass) */ if (sym->strpos >=4) { char *name = nasm_malloc(sym->namlen+1); - saa_fread(strs, sym->strpos-4, name, sym->namlen); + saa_fread(coff_strs, sym->strpos-4, name, sym->namlen); name[sym->namlen] = '\0'; equals = !strcmp(value,name); nasm_free(name); @@ -867,13 +849,13 @@ static int coff_directives(enum directives directive, char *value, int pass) * .absolute and two per each section */ unsigned char value[4],*p=value; - WRITELONG(p,n + 2 + 1 + nsects*2); - coff_sect_write(sects[sxseg],value,4); + WRITELONG(p,n + 2 + 1 + coff_nsects*2); + coff_sect_write(coff_sects[sxseg],value,4); sym->type = 0x20; break; } } - if (n == nsyms) { + if (n == coff_nsyms) { nasm_error(ERR_NONFATAL, "`safeseh' directive requires valid symbol"); } @@ -886,7 +868,7 @@ static int coff_directives(enum directives directive, char *value, int pass) } /* handle relocations storm, valid for win32/64 only */ -static inline void coff_adjust_relocs(struct Section *s) +static inline void coff_adjust_relocs(struct coff_Section *s) { if (s->nrelocs < IMAGE_SCN_MAX_RELOC) return; @@ -916,13 +898,13 @@ static void coff_write(void) /* add default value for @feat.00, this allows to 'link /safeseh' */ uint32_t n; - saa_rewind(syms); - for (n = 0; n < nsyms; n++) { - struct Symbol *sym = saa_rstruct(syms); + saa_rewind(coff_syms); + for (n = 0; n < coff_nsyms; n++) { + struct coff_Symbol *sym = saa_rstruct(coff_syms); if (sym->strpos == -1 && !strcmp("@feat.00",sym->name)) break; } - if (n == nsyms) + if (n == coff_nsyms) coff_deflabel("@feat.00", NO_SEG, 1, 0, NULL); } @@ -931,17 +913,17 @@ static void coff_write(void) * Calculate the start of the `real' symbols at the same time. * Check for massive relocations. */ - pos = 0x14 + 0x28 * nsects; + pos = 0x14 + 0x28 * coff_nsects; initsym = 3; /* two for the file, one absolute */ - for (i = 0; i < nsects; i++) { - if (sects[i]->data) { - coff_adjust_relocs(sects[i]); - sects[i]->pos = pos; - pos += sects[i]->len; - sects[i]->relpos = pos; - pos += 10 * sects[i]->nrelocs; + for (i = 0; i < coff_nsects; i++) { + if (coff_sects[i]->data) { + coff_adjust_relocs(coff_sects[i]); + coff_sects[i]->pos = pos; + pos += coff_sects[i]->len; + coff_sects[i]->relpos = pos; + pos += 10 * coff_sects[i]->nrelocs; } else - sects[i]->pos = sects[i]->relpos = 0L; + coff_sects[i]->pos = coff_sects[i]->relpos = 0L; initsym += 2; /* two for each section */ } sympos = pos; @@ -954,10 +936,10 @@ static void coff_write(void) else i = IMAGE_FILE_MACHINE_I386; fwriteint16_t(i, ofile); /* machine type */ - fwriteint16_t(nsects, ofile); /* number of sections */ + fwriteint16_t(coff_nsects, ofile); /* number of sections */ fwriteint32_t(time(NULL), ofile); /* time stamp */ fwriteint32_t(sympos, ofile); - fwriteint32_t(nsyms + initsym, ofile); + fwriteint32_t(coff_nsyms + initsym, ofile); fwriteint16_t(0, ofile); /* no optional header */ /* Flags: 32-bit, no line numbers. Win32 doesn't even bother with them. */ fwriteint16_t((win32 | win64) ? 0 : 0x104, ofile); @@ -966,20 +948,20 @@ static void coff_write(void) * Output the section headers. */ vsize = 0L; - for (i = 0; i < nsects; i++) { - coff_section_header(sects[i]->name, sects[i]->namepos, vsize, sects[i]->len, - sects[i]->pos, sects[i]->relpos, - sects[i]->nrelocs, sects[i]->flags); - vsize += sects[i]->len; + for (i = 0; i < coff_nsects; i++) { + coff_section_header(coff_sects[i]->name, coff_sects[i]->namepos, vsize, coff_sects[i]->len, + coff_sects[i]->pos, coff_sects[i]->relpos, + coff_sects[i]->nrelocs, coff_sects[i]->flags); + vsize += coff_sects[i]->len; } /* * Output the sections and their relocations. */ - for (i = 0; i < nsects; i++) - if (sects[i]->data) { - saa_fpwrite(sects[i]->data, ofile); - coff_write_relocs(sects[i]); + for (i = 0; i < coff_nsects; i++) + if (coff_sects[i]->data) { + saa_fpwrite(coff_sects[i]->data, ofile); + coff_write_relocs(coff_sects[i]); } /* @@ -987,7 +969,7 @@ static void coff_write(void) */ coff_write_symbols(); fwriteint32_t(strslen + 4, ofile); /* length includes length count */ - saa_fpwrite(strs, ofile); + saa_fpwrite(coff_strs, ofile); } static void coff_section_header(char *name, int32_t namepos, int32_t vsize, @@ -1047,9 +1029,9 @@ static void coff_section_header(char *name, int32_t namepos, int32_t vsize, fwriteint32_t(flags, ofile); } -static void coff_write_relocs(struct Section *s) +static void coff_write_relocs(struct coff_Section *s) { - struct Reloc *r; + struct coff_Reloc *r; /* a real number of relocations if needed */ if (s->flags & IMAGE_SCN_LNK_NRELOC_OVFL) { @@ -1106,10 +1088,10 @@ static void coff_write_symbols(void) */ memset(filename, 0, 18); /* useful zeroed buffer */ - for (i = 0; i < (uint32_t) nsects; i++) { - coff_symbol(sects[i]->name, 0L, 0L, i + 1, 0, 3, 1); - fwriteint32_t(sects[i]->len, ofile); - fwriteint16_t(sects[i]->nrelocs,ofile); + for (i = 0; i < (uint32_t) coff_nsects; i++) { + coff_symbol(coff_sects[i]->name, 0L, 0L, i + 1, 0, 3, 1); + fwriteint32_t(coff_sects[i]->len, ofile); + fwriteint16_t(coff_sects[i]->nrelocs,ofile); nasm_write(filename, 12, ofile); } @@ -1121,9 +1103,9 @@ static void coff_write_symbols(void) /* * The real symbols. */ - saa_rewind(syms); - for (i = 0; i < nsyms; i++) { - struct Symbol *sym = saa_rstruct(syms); + saa_rewind(coff_syms); + for (i = 0; i < coff_nsyms; i++) { + struct coff_Symbol *sym = saa_rstruct(coff_syms); coff_symbol(sym->strpos == -1 ? sym->name : NULL, sym->strpos, sym->value, sym->section, sym->type, sym->is_global ? 2 : 3, 0); @@ -1132,13 +1114,13 @@ static void coff_write_symbols(void) static void coff_sectalign(int32_t seg, unsigned int value) { - struct Section *s = NULL; + struct coff_Section *s = NULL; uint32_t align; int i; - for (i = 0; i < nsects; i++) { - if (sects[i]->index == seg) { - s = sects[i]; + for (i = 0; i < coff_nsects; i++) { + if (coff_sects[i]->index == seg) { + s = coff_sects[i]; break; } } @@ -1165,12 +1147,14 @@ static void coff_std_filename(char *inname, char *outname) { strcpy(coff_infile, inname); standard_extension(inname, outname, ".o"); + strcpy(coff_outfile, outname); } static void coff_win32_filename(char *inname, char *outname) { strcpy(coff_infile, inname); standard_extension(inname, outname, ".obj"); + strcpy(coff_outfile, outname); } extern macros_t coff_stdmac[]; @@ -1206,14 +1190,18 @@ struct ofmt of_coff = { #endif +extern struct dfmt df_cv8; + #ifdef OF_WIN32 +struct dfmt *win32_debug_arr[2] = { &df_cv8, NULL }; + struct ofmt of_win32 = { "Microsoft Win32 (i386) object files", "win32", 0, - null_debug_arr, - &null_debug_form, + win32_debug_arr, + &df_cv8, coff_stdmac, coff_win32_init, coff_set_info, @@ -1231,12 +1219,14 @@ struct ofmt of_win32 = { #ifdef OF_WIN64 +struct dfmt *win64_debug_arr[2] = { &df_cv8, NULL }; + struct ofmt of_win64 = { "Microsoft Win64 (x86-64) object files", "win64", 0, - null_debug_arr, - &null_debug_form, + win64_debug_arr, + &df_cv8, coff_stdmac, coff_win64_init, coff_set_info, diff --git a/output/pecoff.h b/output/pecoff.h index 924ccd8..8b57d6b 100644 --- a/output/pecoff.h +++ b/output/pecoff.h @@ -474,4 +474,59 @@ #define IMPORT_NAME_NOPREFIX 2 #define IMPORT_NAME_UNDECORATE 3 +struct coff_Section { + struct SAA *data; + uint32_t len; + int nrelocs; + int32_t index; + struct coff_Reloc *head, **tail; + uint32_t flags; /* section flags */ + char *name; + int32_t namepos; /* Offset of name into the strings table */ + int32_t pos, relpos; +}; + +struct coff_Reloc { + struct coff_Reloc *next; + int32_t address; /* relative to _start_ of section */ + int32_t symbol; /* symbol number */ + enum { + SECT_SYMBOLS, + ABS_SYMBOL, + REAL_SYMBOLS + } symbase; /* relocation for symbol number :) */ + int16_t type; +}; + +struct coff_Symbol { + char name[9]; + int32_t strpos; /* string table position of name */ + int32_t value; /* address, or COMMON variable size */ + int section; /* section number where it's defined + * - in COFF codes, not NASM codes */ + bool is_global; /* is it a global symbol or not? */ + int16_t type; /* 0 - notype, 0x20 - function */ + int32_t namlen; /* full name length */ +}; + +struct coff_DebugInfo { + int32_t segto; + int32_t seg; + uint64_t size; + struct coff_Section *section; +}; + +extern struct coff_Section **coff_sects; +extern int coff_nsects; +extern struct SAA *coff_syms; +extern uint32_t coff_nsyms; +extern struct SAA *coff_strs; +extern bool win32, win64; + +extern char coff_infile[FILENAME_MAX]; +extern char coff_outfile[FILENAME_MAX]; + +extern int coff_make_section(char *name, uint32_t flags); + + #endif /* PECOFF_H */ |
From: nasm-bot f. J. K. <jam...@li...> - 2016-01-24 11:18:29
|
Commit-ID: ba754eec038dd419d64ada943af4476202d5af25 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=ba754eec038dd419d64ada943af4476202d5af25 Author: Jim Kukunas <jam...@li...> AuthorDate: Sat, 23 Jan 2016 23:32:50 -0800 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Sun, 24 Jan 2016 14:14:00 +0300 Add a MD5 implementation This implementation was written by Colin Plumb and is in the public domain. I've updated it to use stdint.h and the standard C types rather than sys/types.h for portability. Signed-off-by: Jim Kukunas <jam...@li...> Acked-by: H. Peter Anvin <hp...@zy...> Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- Makefile.in | 3 +- Mkfiles/msvc.mak | 3 +- md5.h | 23 ++++++ md5c.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 274 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index ed5f89e..9894d33 100644 --- a/Makefile.in +++ b/Makefile.in @@ -91,7 +91,8 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ - iflag.$(O) + iflag.$(O) \ + md5c.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index b743412..a4df3e3 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -61,7 +61,8 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ - iflag.$(O) + iflag.$(O) \ + md5c.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ diff --git a/md5.h b/md5.h new file mode 100644 index 0000000..147d3dd --- /dev/null +++ b/md5.h @@ -0,0 +1,23 @@ +#ifndef _MD5_H_ +#define _MD5_H_ + +#include <stdint.h> + +#define MD5_HASHBYTES 16 + +typedef struct MD5Context { + uint32_t buf[4]; + uint32_t bits[2]; + unsigned char in[64]; +} MD5_CTX; + +extern void MD5Init(MD5_CTX *context); +extern void MD5Update(MD5_CTX *context, unsigned char const *buf, + unsigned len); +extern void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context); +extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]); +extern char * MD5End(MD5_CTX *, char *); +extern char * MD5File(const char *, char *); +extern char * MD5Data (const unsigned char *, unsigned int, char *); + +#endif /* !_MD5_H_ */ diff --git a/md5c.c b/md5c.c new file mode 100644 index 0000000..2716232 --- /dev/null +++ b/md5c.c @@ -0,0 +1,247 @@ +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + +#include <string.h> /* for memcpy() */ +#include "md5.h" + +#if __BYTE_ORDER == 1234 +#define byteReverse(buf, len) /* Nothing */ +#else +void byteReverse(unsigned char *buf, unsigned longs); + +/* + * Note: this code is harmless on little-endian machines. + */ +void byteReverse(unsigned char *buf, unsigned longs) +{ + uint32_t t; + do { + t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(uint32_t *) buf = t; + buf += 4; + } while (--longs); +} +#endif + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +void MD5Init(MD5_CTX *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) +{ + uint32_t t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *) ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +/* + * Final wrapup - pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +void MD5Final(unsigned char digest[16], MD5_CTX *ctx) +{ + unsigned count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + byteReverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((uint32_t *) ctx->in)[14] = ctx->bits[0]; + ((uint32_t *) ctx->in)[15] = ctx->bits[1]; + + MD5Transform(ctx->buf, (uint32_t *) ctx->in); + byteReverse((unsigned char *) ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset((char *) ctx, 0, sizeof(ctx)); /* In case it's sensitive */ +} + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +void MD5Transform(uint32_t buf[4], uint32_t const in[16]) +{ + register uint32_t a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} |
From: nasm-bot f. J. K. <jam...@li...> - 2016-01-24 11:18:25
|
Commit-ID: c9b3b8af41210528b449e94623ddf4a3bae3c2f2 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=c9b3b8af41210528b449e94623ddf4a3bae3c2f2 Author: Jim Kukunas <jam...@li...> AuthorDate: Sat, 23 Jan 2016 23:32:49 -0800 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Sun, 24 Jan 2016 14:12:56 +0300 nasmlib: Add nasm_realpath() Converts a relative pathname to an absolute pathname. Signed-off-by: Jim Kukunas <jam...@li...> Acked-by: H. Peter Anvin <hp...@zy...> Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- nasmlib.c | 12 ++++++++++++ nasmlib.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/nasmlib.c b/nasmlib.c index ecd6d8d..9d57adb 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -696,6 +696,18 @@ char *nasm_opt_val(char *p, char **val, char **next) return p; } +#ifdef _WIN32 +char *nasm_realpath(const char *rel_path) +{ + return _fullpath(NULL, rel_path, 0); +} +#else +char *nasm_realpath(const char *rel_path) +{ + return realpath(rel_path, NULL); +} +#endif + /* * initialized data bytes length from opcode */ diff --git a/nasmlib.h b/nasmlib.h index a3a8c12..9cd417f 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -400,6 +400,13 @@ char *nasm_trim_spaces(char *p); char *nasm_get_word(char *p, char **tail); char *nasm_opt_val(char *p, char **opt, char **val); +/* + * Converts a relative pathname rel_path into an absolute path name. + * + * The buffer returned must be freed by the caller + */ +char *nasm_realpath(const char *rel_path); + const char *prefix_name(int); #define ZERO_BUF_SIZE 4096 |