From 4d993a1c03a5371768daacd8a727f232e47ebbb9 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 20 Apr 2017 01:36:57 -0700 Subject: [PATCH 01/20] doc: update links to ABI documents We have a separate namespace for ABI documents. Signed-off-by: H. Peter Anvin --- doc/nasmdoc.src | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 79eb59d0..0988bdcc 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -7754,9 +7754,10 @@ a zero-extended absolute displacement can access from 0 to 4 GB. \H{unix64} Interfacing to 64-bit C Programs (Unix) -On Unix, the 64-bit ABI is defined by the document: +On Unix, the 64-bit ABI as well as the x32 ABI (32-bit ABI with the +CPU in 64-bit mode) is defined by the documents at: -\W{http://www.nasm.us/links/unix64abi}\c{http://www.nasm.us/links/unix64abi} +\W{http://www.nasm.us/abi/unix64}\c{http://www.nasm.us/abi/unix64} Although written for AT&T-syntax assembly, the concepts apply equally well for NASM-style assembly. What follows is a simplified summary. @@ -7786,9 +7787,9 @@ Integer and SSE register arguments are counted separately, so for the case of \H{win64} Interfacing to 64-bit C Programs (Win64) -The Win64 ABI is described at: +The Win64 ABI is described by the document at: -\W{http://www.nasm.us/links/win64abi}\c{http://www.nasm.us/links/win64abi} +\W{http://www.nasm.us/abi/win64}\c{http://www.nasm.us/abi/win64} What follows is a simplified summary. From 32b9824f5c8539f1ca53b36725575a2d96d58ca2 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 20 Apr 2017 02:03:59 -0700 Subject: [PATCH 02/20] doc: formatting fixes to the warnings documentation Formatting and language consistency cleanups to the sections about disabling and enabling warning classes. Signed-off-by: H. Peter Anvin --- doc/nasmdoc.src | 51 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 0988bdcc..361b8f3b 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -791,31 +791,30 @@ disable it by \c{-w-orphan-labels}. The current \i{warning classes} are: \b \i\c{other} specifies any warning not otherwise specified in any -class. +class. Enabled by default. \b \i\c{macro-params} covers warnings about \i{multi-line macros} -being invoked with the wrong number of parameters. This warning -class is enabled by default; see \k{mlmacover} for an example of why +being invoked with the wrong number of parameters. Enabled by default; +see \k{mlmacover} for an example of why you might want to disable it. + +\b \i\c{macro-selfref} warns if a macro references itself. Disabled by +default. + +\b \i\c{macro-defaults} warns when a macro has more default parameters +than optional parameters. Enabled by default; see \k{mlmacdef} for why you might want to disable it. -\b \i\c{macro-selfref} warns if a macro references itself. This -warning class is disabled by default. - -\b\i\c{macro-defaults} warns when a macro has more default -parameters than optional parameters. This warning class -is enabled by default; see \k{mlmacdef} for why you might want to disable it. - \b \i\c{orphan-labels} covers warnings about source lines which contain no instruction but define a label without a trailing colon. NASM warns about this somewhat obscure condition by default; see \k{syntax} for more information. \b \i\c{number-overflow} covers warnings about numeric constants which -don't fit in 64 bits. This warning class is enabled by default. +don't fit in 64 bits. Enabled by default. \b \i\c{gnu-elf-extensions} warns if 8-bit or 16-bit relocations are used in \c{-f elf} format. The GNU extensions allow this. -This warning class is disabled by default. +Disabled by default. \b \i\c{float-overflow} warns about floating point overflow. Enabled by default. @@ -844,11 +843,11 @@ form of jmp instruction becomes jmp short form. Enabled by default. \b \i\c{zext-reloc} warns that a relocation has been zero-extended due -to limitations in the output format. +to limitations in the output format. Enabled by default. \b \i\c\{ptr} warns about keywords used in other assemblers that might indicate a mistake in the source code. Currently only the MASM -\c{PTR} keyword is recognized. +\c{PTR} keyword is recognized. Enabled by default. \b \i\c{bad-pragma} warns about a malformed or otherwise unparsable \c{%pragma} directive. Disabled by default. @@ -862,22 +861,24 @@ implemented. Disabled by default. \b \i\c{unknown-warning} warns about a \c{-w} or \c{-W} option or a \c{[WARNING]} directive that contains an unknown warning name or is -otherwise not possible to process. +otherwise not possible to process. Disabled by default. \b \i\c{all} is an alias for \e{all} suppressible warning classes. Thus, \c{-w+all} enables all available warnings, and \c{-w-all} disables warnings entirely (since NASM 2.13). -Since version 2.00, NASM has also supported the gcc-like syntax +Since version 2.00, NASM has also supported the \c{gcc}-like syntax \c{-Wwarning-class} and \c{-Wno-warning-class} instead of \c{-w+warning-class} and \c{-w-warning-class}, respectively; both syntaxes work identically. The option \c{-w+error} or \i\c{-Werror} can be used to treat warnings as errors. This can be controlled on a per warning class basis -(\c{-w+error=}\e{warning-class}); if no \e{warning-class} is specified -NASM treats it as \c{-w+error=all}; the same applies to \c{-w-error} -or \i\c{-Wno-error}, of course. +(\c{-w+error=}\e{warning-class} or \c{-Werror=}\e{warning-class}); +if no \e{warning-class} is specified NASM treats it as +\c{-w+error=all}; the same applies to \c{-w-error} or +\i\c{-Wno-error}, +of course. In addition, you can control warnings in the source code itself, using the \i\c{[WARNING]} directive. See \k{asmdir-warning}. @@ -4678,9 +4679,15 @@ The \c{[WARNING]} directive can be used to enable or disable classes of warnings in the same way as the \c{-w} option, see \k{opt-w} for more details about warning classes. -Warning classes may be enabled with \c{[warning +]\e{warning-class}\c{]}, disabled -with \c{[warning -}\e{warning-class}\c{]}, or reset to their original value (as -specified on the command line) with \c{[warning *}\e{warning-class}{]}. +\b \c{[warning +}\e{warning-class}\c{]} enables warnings for + \e{warning-class}. + +\b \c{[warning -}\e{warning-class}\c{]} disables warnings for + \e{warning-class}. + +\b \c{[warning *}\e{warning-class}\c{]} restores \e{warning-class} to + the original value, either the default value or as specified on the + command line. The \c{[WARNING]} directive also accepts the \c{all}, \c{error} and \c{error=}\e{warning-class} specifiers. From 16d4db3aab498a89d71b57752fbed3d1b5c039cc Mon Sep 17 00:00:00 2001 From: Henrik Gramner Date: Thu, 20 Apr 2017 16:02:19 +0200 Subject: [PATCH 03/20] Fix ModR/M.mod for EVEX instructions It was incorrectly set to 01b in some cases when where it should be 10b. Fixes BR 3392402. Signed-off-by: Henrik Gramner Signed-off-by: H. Peter Anvin --- asm/assemble.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/asm/assemble.c b/asm/assemble.c index 9c76b0ea..31db516a 100644 --- a/asm/assemble.c +++ b/asm/assemble.c @@ -2426,13 +2426,11 @@ static enum match_result matches(const struct itemplate *itemp, * - offset can fit in a byte when EVEX is not used * - offset can be compressed when EVEX is used */ -#define IS_MOD_01() (input->eaflags & EAF_BYTEOFFS || \ - (o >= -128 && o <= 127 && \ - seg == NO_SEG && !forw_ref && \ - !(input->eaflags & EAF_WORDOFFS) && \ - !(ins->rex & REX_EV)) || \ - (ins->rex & REX_EV && \ - is_disp8n(input, ins, &output->disp8))) +#define IS_MOD_01() (!(input->eaflags & EAF_WORDOFFS) && \ + (ins->rex & REX_EV ? seg == NO_SEG && !forw_ref && \ + is_disp8n(input, ins, &output->disp8) : \ + input->eaflags & EAF_BYTEOFFS || (o >= -128 && \ + o <= 127 && seg == NO_SEG && !forw_ref))) static enum ea_type process_ea(operand *input, ea *output, int bits, int rfield, opflags_t rflags, insn *ins, From 57e08284a63cd464b5bc0aad51a1ba2c3536e1e4 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 20 Apr 2017 18:03:10 -0700 Subject: [PATCH 04/20] doc, html: switch to a columnar layout for a very wide window If we open in a very wide window, split the text into columns so it can actually be conveniently read. Also, change the body margin to 8px, as that seems to be the more common browser default. Signed-off-by: H. Peter Anvin --- doc/nasmdoc.css | 19 +++++++++++++++++-- doc/rdsrc.pl | 5 +++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/nasmdoc.css b/doc/nasmdoc.css index af095273..f989f37b 100644 --- a/doc/nasmdoc.css +++ b/doc/nasmdoc.css @@ -61,11 +61,26 @@ ul.index { color: inherit; } } +@media only screen and (min-width: 90em) { + /* For a very wide screen, go to a columnar layout */ + div.contents { + -webkit-column-count: 2; + -moz-column-count: 2; + column-count: 2; + } +} +@media only screen and (min-width: 135em) { + div.contents { + -webkit-column-count: 3; + -moz-column-count: 3; + column-count: 3; + } +} @media screen { /* Setting an explicit margin to keep the navbar from moving */ body { padding: 0; - margin: 10px; + margin: 8px; } /* Link styles */ @@ -94,7 +109,7 @@ ul.index { ul.navbar { display: block; position: sticky; - top: 10px; + top: 8px; width: 100%; margin: 0; padding: 0; diff --git a/doc/rdsrc.pl b/doc/rdsrc.pl index bc066584..129bb085 100644 --- a/doc/rdsrc.pl +++ b/doc/rdsrc.pl @@ -971,11 +971,12 @@ sub html_preamble { print "

", $metadata{'title'}, "

\n"; print '', $metadata{'subtitle'}, "\n"; print "\n"; + print "
\n"; } sub html_postamble { - # Closing tags - print "\n\n"; + # Common closing tags + print "
\n\n\n"; } sub html_index { From 9f94136c33d4c3e7bb220d5abe7016c946e5916c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 20 Apr 2017 18:04:42 -0700 Subject: [PATCH 05/20] NASM 2.13rc21 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 562d30e4..6d4f8e0c 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.13rc20 +2.13rc21 From 4dfbd9aec56577d7e0dc9398781ea9918dbdcbf6 Mon Sep 17 00:00:00 2001 From: "Chang S. Bae" Date: Sat, 22 Apr 2017 06:40:43 -0700 Subject: [PATCH 06/20] macho: add file path to the dwarf debugging output Apple's linker requires file path along with file name to produce debug notes. Signed-off-by: Chang S. Bae Signed-off-by: H. Peter Anvin --- output/outmacho.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 173706b9..5c259e2f 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -1784,7 +1784,7 @@ static void macho_dbg_generate(void) size_t saa_len = 0, high_addr = 0, total_len = 0; struct section *p_section = NULL; /* calculated at debug_str and referenced at debug_info */ - uint32_t producer_str_offset = 0, module_str_offset = 0; + uint32_t producer_str_offset = 0, module_str_offset = 0, path_str_offset = 0; /* debug section defines */ { @@ -1886,7 +1886,8 @@ static void macho_dbg_generate(void) struct file_list *p_file = dw_head_list; uint32_t idx = 0; struct SAA *p_str = saa_init(1L); - nasm_assert(p_str != NULL); + struct SAA *p_path_str = saa_init(1L); + nasm_assert((p_str != NULL) && (p_path_str != NULL)); p_section = get_section_by_name("__DWARF", "__debug_str"); nasm_assert(p_section != NULL); @@ -1894,19 +1895,33 @@ static void macho_dbg_generate(void) producer_str_offset = 0; saa_wbytes(p_str, nasm_signature, strlen(nasm_signature) + 1); - module_str_offset = producer_str_offset + strlen(nasm_signature) + 1; + module_str_offset = path_str_offset = producer_str_offset + strlen(nasm_signature) + 1; + for(; idx < dw_num_files; idx++) { - saa_wbytes(p_str, p_file->file_name, (int32_t)(strlen(p_file->file_name) + 1)); + size_t cur_file_strlen = strlen(p_file->file_name) + 1; + char *cur_path = nasm_realpath(p_file->file_name); + size_t cur_path_strlen = strlen(cur_path); + + nasm_assert(cur_path_strlen > cur_file_strlen); + cur_path_strlen -= cur_file_strlen; + cur_path[cur_path_strlen] = '\0'; + saa_wbytes(p_str, p_file->file_name, cur_file_strlen); + saa_wbytes(p_path_str, cur_path, cur_path_strlen); + path_str_offset += cur_file_strlen; p_file = p_file->next; } saa_len = p_str->datalen; - p_buf = nasm_malloc(saa_len); saa_rnbytes(p_str, p_buf, saa_len); macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0); - saa_free(p_str); + + saa_len = p_path_str->datalen; + p_buf = nasm_malloc(saa_len); + saa_rnbytes(p_path_str, p_buf, saa_len); + macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0); + saa_free(p_path_str); } /* debug info */ @@ -1927,6 +1942,7 @@ static void macho_dbg_generate(void) saa_write32(p_info, producer_str_offset); /* offset from string table for DW_AT_producer */ saa_write16(p_info, DW_LANG_Mips_Assembler); /* DW_AT_language */ saa_write32(p_info, module_str_offset); /* offset from string table for DW_AT_name */ + saa_write32(p_info, path_str_offset); /* offset from string table for DW_AT_comp_dir */ saa_write32(p_info, 0); /* DW_AT_stmt_list */ if (ofmt == &of_macho64) { @@ -1980,6 +1996,9 @@ static void macho_dbg_generate(void) saa_write8(p_abbrev, DW_AT_name); saa_write8(p_abbrev, DW_FORM_strp); + saa_write8(p_abbrev, DW_AT_comp_dir); + saa_write8(p_abbrev, DW_FORM_strp); + saa_write8(p_abbrev, DW_AT_stmt_list); saa_write8(p_abbrev, DW_FORM_data4); From 3e555483b30c6f0bd4b348861f694f73e487c134 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 17:02:46 -0700 Subject: [PATCH 07/20] labels, outelf: remove casts for allocations Remove casts from allocations. This is simply Not How To Do Things: every cast carries a potential risk of being a toxic type misuse (e.g. pointer as integer) and so any unnecessary cast is actively harmful. Note that a lot of allocations here are completely unnecessary: the core code now guarantees that all filenames are permanently allocated for the duration of the assembly, and so should be turned into const char * without any further allocation. Any remaining malloc+strcpy should be turned into nasm_strdup(), and nasm_new[n]() used whereever possible. Signed-off-by: H. Peter Anvin --- asm/labels.c | 8 ++++---- output/outelf.c | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/asm/labels.c b/asm/labels.c index 8c2223a0..1183151c 100644 --- a/asm/labels.c +++ b/asm/labels.c @@ -186,7 +186,7 @@ static union label *find_label(const char *label, int create, int *created) /* * must allocate a new block */ - lfree->admin.next = (union label *)nasm_malloc(LBLK_SIZE); + lfree->admin.next = nasm_malloc(LBLK_SIZE); lfree = lfree->admin.next; init_block(lfree); } @@ -424,11 +424,11 @@ int init_labels(void) { hash_init(<ab, HASH_LARGE); - ldata = lfree = (union label *)nasm_malloc(LBLK_SIZE); + ldata = lfree = nasm_malloc(LBLK_SIZE); init_block(lfree); perm_head = perm_tail = - (struct permts *)nasm_malloc(sizeof(struct permts)); + nasm_malloc(sizeof(struct permts)); perm_head->next = NULL; perm_head->size = PERMTS_SIZE; @@ -483,7 +483,7 @@ static char *perm_copy(const char *string) if (perm_tail->size - perm_tail->usage < len) { perm_tail->next = - (struct permts *)nasm_malloc(sizeof(struct permts)); + nasm_malloc(sizeof(struct permts)); perm_tail = perm_tail->next; perm_tail->next = NULL; perm_tail->size = PERMTS_SIZE; diff --git a/output/outelf.c b/output/outelf.c index 86cb985c..1ee6dacc 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -2468,7 +2468,7 @@ static void stabs_linenum(const char *filename, int32_t linenumber, int32_t segt { (void)segto; if (!stabs_filename) { - stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); + stabs_filename = nasm_malloc(strlen(filename) + 1); strcpy(stabs_filename, filename); } else { if (strcmp(stabs_filename, filename)) { @@ -2478,7 +2478,7 @@ static void stabs_linenum(const char *filename, int32_t linenumber, int32_t segt /* why not nasm_free(stabs_filename); we're done with the old one */ - stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); + stabs_filename = nasm_malloc(strlen(filename) + 1); strcpy(stabs_filename, filename); } } @@ -2496,7 +2496,7 @@ static void stabs_output(int type, void *param) if (!(sects[s->section]->flags & SHF_EXECINSTR)) return; /* line info is only collected for executable sections */ numlinestabs++; - el = (struct linelist *)nasm_malloc(sizeof(struct linelist)); + el = nasm_malloc(sizeof(struct linelist)); el->info.offset = s->offset; el->info.section = s->section; el->info.name = s->name; @@ -2528,7 +2528,7 @@ static void stabs_generate(void) ptr = stabslines; - allfiles = (char **)nasm_zalloc(numlinestabs * sizeof(char *)); + allfiles = nasm_zalloc(numlinestabs * sizeof(char *)); numfiles = 0; while (ptr) { if (numfiles == 0) { @@ -2547,7 +2547,7 @@ static void stabs_generate(void) ptr = ptr->next; } strsize = 1; - fileidx = (int *)nasm_malloc(numfiles * sizeof(int)); + fileidx = nasm_malloc(numfiles * sizeof(int)); for (i = 0; i < numfiles; i++) { fileidx[i] = strsize; strsize += strlen(allfiles[i]) + 1; @@ -2565,10 +2565,10 @@ static void stabs_generate(void) * the sourcefiles changes each line, which would mean 1 SOL, 1 SYMLIN per line * plus one "ending" entry */ - sbuf = (uint8_t *)nasm_malloc((numlinestabs * 2 + 4) * + sbuf = nasm_malloc((numlinestabs * 2 + 4) * sizeof(struct stabentry)); - ssbuf = (uint8_t *)nasm_malloc(strsize); - rbuf = (uint8_t *)nasm_malloc(numlinestabs * (is_elf64() ? 16 : 8) * (2 + 3)); + ssbuf = nasm_malloc(strsize); + rbuf = nasm_malloc(numlinestabs * (is_elf64() ? 16 : 8) * (2 + 3)); rptr = rbuf; for (i = 0; i < numfiles; i++) @@ -3293,7 +3293,7 @@ static void dwarf_findfile(const char * fname) } /* add file name to end of list */ - dwarf_clist = (struct linelist *)nasm_malloc(sizeof(struct linelist)); + dwarf_clist = nasm_malloc(sizeof(struct linelist)); dwarf_numfiles++; dwarf_clist->line = dwarf_numfiles; dwarf_clist->filename = nasm_malloc(strlen(fname) + 1); @@ -3332,7 +3332,7 @@ static void dwarf_findsect(const int index) } /* add entry to end of list */ - dwarf_csect = (struct sectlist *)nasm_malloc(sizeof(struct sectlist)); + dwarf_csect = nasm_malloc(sizeof(struct sectlist)); dwarf_nsections++; dwarf_csect->psaa = plinep = saa_init(1L); dwarf_csect->line = 1; From cf96845bf645266d7ec6e77a92086c8ed7a7803f Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 18:33:53 -0700 Subject: [PATCH 08/20] nasm.spec: sync with Fedora spec file, auto-generate Perl depends Sync up with how the Fedora spec file has evolved. Auto-generate the Perl build dependencies. Add --enable-lto: it makes especally the rdoff files much smaller. Signed-off-by: H. Peter Anvin --- Makefile.in | 13 +++++++++++-- nasm.spec.in | 46 +++++++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Makefile.in b/Makefile.in index b377b79c..6764f961 100644 --- a/Makefile.in +++ b/Makefile.in @@ -348,6 +348,7 @@ clean: $(RM_F) nasm-*-installer-*.exe $(RM_F) tags TAGS $(RM_F) nsis/arch.nsh + $(RM_F) perlbreq.si $(RM_F) $(RDFPROGS) $(RDF2BINLINKS) distclean: clean @@ -417,8 +418,16 @@ tar: dist spec: nasm.spec -nasm.spec: nasm.spec.in version.sed - sed -f version.sed < nasm.spec.in > nasm.spec +ALLPERLSRC := $(shell find $(srcdir) -type f -name '*.p[lh]') + +perlbreq.si: $(ALLPERLSRC) + sed -n -r -e 's/^use[[:space:]]+([^[:space:];]+).*$$/Build-Requires: perl(\1)/p' $(ALLPERLSRC) | \ + sed -r -e '/perl\((strict|warnings)\)/d' | \ + sort | uniq > perlbreq.si || ( rm -f perlbreq.si ; false ) + +nasm.spec: nasm.spec.in version.sed perlbreq.si + sed -f version.sed -e '/@@PERLBUILDREQS@@/r perlbreq.si' \ + < nasm.spec.in > nasm.spec || ( rm -f nasm.spec ; false ) splint: splint -weak *.c diff --git a/nasm.spec.in b/nasm.spec.in index 9ca198ea..1d1e6d7d 100644 --- a/nasm.spec.in +++ b/nasm.spec.in @@ -3,16 +3,22 @@ Summary: The Netwide Assembler, a portable x86 assembler with Intel-like syntax Name: nasm Version: @@NASM_MANGLED_VER@@ -Release: 0 +Release: 0%{?dist} License: BSD Group: Development/Languages Source: http://www.nasm.us/pub/nasm/releasebuilds/%{nasm_version}/nasm-%{nasm_version}.tar.xz URL: http://www.nasm.us/ BuildRoot: /tmp/rpm-build-nasm Prefix: %{_prefix} -BuildRequires: perl, asciidoc, xmlto, ghostscript, perl-Font-TTF -BuildRequires: adobe-source-sans-pro-fonts, adobe-source-code-pro-fonts -BuildRequires: fontconfig, xz +@@PERLBUILDREQS@@ +BuildRequires: autoconf +BuildRequires: asciidoc +BuildRequires: xmlto +BuildRequires: ghostscript +BuildRequires: fontconfig +BuildRequires: adobe-source-sans-pro-fonts +BuildRequires: adobe-source-code-pro-fonts +BuildRequires: xz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %package doc @@ -41,26 +47,18 @@ include linker, library manager, loader, and information dump. %setup -q -n nasm-%{nasm_version} %build -%configure --disable-pdf-compression +autoreconf +%configure --disable-pdf-compression --enable-lto make %{?_smp_mflags} everything +xz -9ef doc/nasmdoc.pdf %install rm -rf "$RPM_BUILD_ROOT" mkdir -p "$RPM_BUILD_ROOT"/%{_bindir} mkdir -p "$RPM_BUILD_ROOT"/%{_mandir}/man1 -mkdir -p "$RPM_BUILD_ROOT"/usr/tempdoc -%makeinstall install_everything docdir="$RPM_BUILD_ROOT"/usr/tempdoc -cp -a $RPM_BUILD_ROOT/usr/tempdoc/html \ - $RPM_BUILD_ROOT/usr/tempdoc/nasmdoc.pdf . -xz -9ef nasmdoc.pdf -# remove unpackaged files from the buildroot -rm -rf $RPM_BUILD_ROOT%{_prefix}/tempdoc - -%clean -rm -rf "$RPM_BUILD_ROOT" +make INSTALLROOT="$RPM_BUILD_ROOT" install install_rdf %files -%defattr(-,root,root) %doc AUTHORS CHANGES README TODO %{_bindir}/nasm %{_bindir}/ndisasm @@ -68,11 +66,9 @@ rm -rf "$RPM_BUILD_ROOT" %{_mandir}/man1/ndisasm.1* %files doc -%defattr(-,root,root) -%doc html nasmdoc.pdf.xz +%doc doc/html doc/nasmdoc.pdf.xz %files rdoff -%defattr(-,root,root) %{_bindir}/ldrdf %{_bindir}/rdf2bin %{_bindir}/rdf2com @@ -83,11 +79,7 @@ rm -rf "$RPM_BUILD_ROOT" %{_bindir}/rdflib %{_bindir}/rdx %{_mandir}/man1/ldrdf.1* -%{_mandir}/man1/rdf2bin.1* -%{_mandir}/man1/rdf2com.1* -%{_mandir}/man1/rdf2ihx.1* -%{_mandir}/man1/rdf2ith.1* -%{_mandir}/man1/rdf2srec.1* -%{_mandir}/man1/rdfdump.1* -%{_mandir}/man1/rdflib.1* -%{_mandir}/man1/rdx.1* +%{_mandir}/man1/rd*.1* + +# This is the upstream spec file; the change log is in git +%changelog From 16ffec1864e1db49866ecd684ef98a2b2ba4cf3d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 18:52:58 -0700 Subject: [PATCH 09/20] nasm.spec: use a sed file to insert perl dependencies There are just too many ways that an inline sed script can screw up. Signed-off-by: H. Peter Anvin --- .gitignore | 3 +++ Makefile.in | 4 ++-- nasm.spec.sed | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 nasm.spec.sed diff --git a/.gitignore b/.gitignore index 267007b7..14eccf95 100644 --- a/.gitignore +++ b/.gitignore @@ -14,11 +14,13 @@ *.pdb *.rej *.s +*.si *.swp *.xml .*swo *~ \#* +.\#* *.bak *.tmp .git-ignore @@ -54,6 +56,7 @@ TAGS /macros/macros.c /nasm /ndisasm +/nasm.spec /nsis/arch.nsh /nsis/version.nsh /rdoff/Makefile diff --git a/Makefile.in b/Makefile.in index 6764f961..6a4010ef 100644 --- a/Makefile.in +++ b/Makefile.in @@ -425,8 +425,8 @@ perlbreq.si: $(ALLPERLSRC) sed -r -e '/perl\((strict|warnings)\)/d' | \ sort | uniq > perlbreq.si || ( rm -f perlbreq.si ; false ) -nasm.spec: nasm.spec.in version.sed perlbreq.si - sed -f version.sed -e '/@@PERLBUILDREQS@@/r perlbreq.si' \ +nasm.spec: nasm.spec.in nasm.spec.sed version.sed perlbreq.si + sed -f version.sed -f nasm.spec.sed \ < nasm.spec.in > nasm.spec || ( rm -f nasm.spec ; false ) splint: diff --git a/nasm.spec.sed b/nasm.spec.sed new file mode 100644 index 00000000..ae0d039b --- /dev/null +++ b/nasm.spec.sed @@ -0,0 +1,3 @@ +# Replace @@PERLBUILDREQS@@ with the file perlbreq.si +/@@PERLBUILDREQS@@/{r perlbreq.si +d} From 3e019c9197fe37795a33a892ebc1ead2ecfa184c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 18:58:53 -0700 Subject: [PATCH 10/20] nasm.spec: s/Build-Requires/BuildRequires/ Fix incorrectly spelled tag. Signed-off-by: H. Peter Anvin --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 6a4010ef..aadd5678 100644 --- a/Makefile.in +++ b/Makefile.in @@ -421,7 +421,7 @@ spec: nasm.spec ALLPERLSRC := $(shell find $(srcdir) -type f -name '*.p[lh]') perlbreq.si: $(ALLPERLSRC) - sed -n -r -e 's/^use[[:space:]]+([^[:space:];]+).*$$/Build-Requires: perl(\1)/p' $(ALLPERLSRC) | \ + sed -n -r -e 's/^use[[:space:]]+([^[:space:];]+).*$$/BuildRequires: perl(\1)/p' $(ALLPERLSRC) | \ sed -r -e '/perl\((strict|warnings)\)/d' | \ sort | uniq > perlbreq.si || ( rm -f perlbreq.si ; false ) From b8b77e44524079ef8b365687a5211b0d9e51b359 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 21:15:05 -0700 Subject: [PATCH 11/20] nasm.spec: more cleanups, doc is noarch The doc file is noarch, and do some other cleanups. Signed-off-by: H. Peter Anvin --- nasm.spec.in | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/nasm.spec.in b/nasm.spec.in index 1d1e6d7d..2f724f91 100644 --- a/nasm.spec.in +++ b/nasm.spec.in @@ -5,7 +5,6 @@ Name: nasm Version: @@NASM_MANGLED_VER@@ Release: 0%{?dist} License: BSD -Group: Development/Languages Source: http://www.nasm.us/pub/nasm/releasebuilds/%{nasm_version}/nasm-%{nasm_version}.tar.xz URL: http://www.nasm.us/ BuildRoot: /tmp/rpm-build-nasm @@ -14,20 +13,19 @@ Prefix: %{_prefix} BuildRequires: autoconf BuildRequires: asciidoc BuildRequires: xmlto -BuildRequires: ghostscript -BuildRequires: fontconfig -BuildRequires: adobe-source-sans-pro-fonts -BuildRequires: adobe-source-code-pro-fonts BuildRequires: xz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %package doc -Summary: Extensive documentation for NASM -Group: Development/Languages +Summary: Detailed manual for the Netwide Assembler +BuildArch: noarch +BuildRequires: ghostscript +BuildRequires: fontconfig +BuildRequires: adobe-source-sans-pro-fonts +BuildRequires: adobe-source-code-pro-fonts %package rdoff Summary: Tools for the RDOFF binary format, sometimes used with NASM. -Group: Development/Tools %description NASM is the Netwide Assembler, a free portable assembler for the Intel @@ -53,10 +51,10 @@ make %{?_smp_mflags} everything xz -9ef doc/nasmdoc.pdf %install -rm -rf "$RPM_BUILD_ROOT" -mkdir -p "$RPM_BUILD_ROOT"/%{_bindir} -mkdir -p "$RPM_BUILD_ROOT"/%{_mandir}/man1 -make INSTALLROOT="$RPM_BUILD_ROOT" install install_rdf +rm -rf "%{buildroot}" +mkdir -p "%{buildroot}"/%{_bindir} +mkdir -p "%{buildroot}"/%{_mandir}/man1 +make INSTALLROOT="%{buildroot}" install install_rdf %files %doc AUTHORS CHANGES README TODO From 7aae8428103ad65be196a98eb7187e167f3af5ac Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 21:19:09 -0700 Subject: [PATCH 12/20] nasm.spec: LTO breaks debug info, fall back to --enable-sections --enable-lto seems to completely break RPM debug information, so fall back on --enable-sections, which at least allows the linker to do better dead code removal. Signed-off-by: H. Peter Anvin --- nasm.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nasm.spec.in b/nasm.spec.in index 2f724f91..d6102846 100644 --- a/nasm.spec.in +++ b/nasm.spec.in @@ -46,7 +46,7 @@ include linker, library manager, loader, and information dump. %build autoreconf -%configure --disable-pdf-compression --enable-lto +%configure --disable-pdf-compression --enable-sections make %{?_smp_mflags} everything xz -9ef doc/nasmdoc.pdf From d2b7aa8edffb425c6c8b6a1804ae154a36f0e78b Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 21:42:08 -0700 Subject: [PATCH 13/20] aclocal.m4: fix underquoted strings Some strings were underquoted, causing failures. Signed-off-by: H. Peter Anvin --- aclocal.m4 | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index 87ec9112..024484df 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -7,12 +7,12 @@ AC_DEFUN(PA_ADD_CFLAGS, [AC_MSG_CHECKING([if $CC accepts $1]) pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS $1" - AC_TRY_LINK([#include ], + AC_TRY_LINK(AC_INCLUDES_DEFAULT, [printf("Hello, World!\n");], - AC_MSG_RESULT([yes]) - CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])", - AC_MSG_RESULT([no]) - CFLAGS="$pa_add_cflags__old_cflags")]) + [AC_MSG_RESULT([yes]) + CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])"], + [AC_MSG_RESULT([no]) + CFLAGS="$pa_add_cflags__old_cflags"])]) dnl -------------------------------------------------------------------------- dnl PA_ADD_CLDFLAGS() @@ -26,14 +26,14 @@ AC_DEFUN(PA_ADD_CLDFLAGS, CFLAGS="$CFLAGS $1" pa_add_cldflags__old_ldflags="$LDFLAGS" LDFLAGS="$LDFLAGS $1" - AC_TRY_LINK([#include ], + AC_TRY_LINK(AC_INCLUDES_DEFAULT, [printf("Hello, World!\n");], - AC_MSG_RESULT([yes]) - CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])" - LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])", - AC_MSG_RESULT([no]) - CFLAGS="$pa_add_cldflags__old_cflags" - LDFLAGS="$pa_add_cldflags__old_ldflags")]) + [AC_MSG_RESULT([yes]) + CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])" + LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])"], + [AC_MSG_RESULT([no]) + CFLAGS="$pa_add_cldflags__old_cflags" + LDFLAGS="$pa_add_cldflags__old_ldflags"])]) dnl -------------------------------------------------------------------------- dnl PA_HAVE_FUNC @@ -129,13 +129,11 @@ dnl Simpler-to-use versions of AC_ARG_ENABLED, that include the dnl test for $enableval and the AS_HELP_STRING definition dnl -------------------------------------------------------------------------- AC_DEFUN(PA_ARG_ENABLED, -[AC_ARG_ENABLE([$1], - [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no]) - AS_IF([test x"$enableval" != xno], [$3], [$4]) +[AC_ARG_ENABLE([$1], [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no]) + AS_IF([test x"$enableval" != xno], [$3], [$4]) ]) AC_DEFUN(PA_ARG_DISABLED, -[AC_ARG_ENABLE([$1], - [AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes]) - AS_IF([test x"$enableval" = xno], [$3], [$4]) +[AC_ARG_ENABLE([$1],[AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes]) + AS_IF([test x"$enableval" = xno], [$3], [$4]) ]) From 26fad144de7cf0a581b518b86f7608293a2fb2a0 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 21:42:31 -0700 Subject: [PATCH 14/20] configure.ac: fix --enable-sections The --enable-sections option isn't too useful without -Wl,--gc-sections. It's unclear if gcc will provide that option by default. Signed-off-by: H. Peter Anvin --- configure.ac | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 2e8c05a5..bc8a1a2b 100644 --- a/configure.ac +++ b/configure.ac @@ -177,8 +177,9 @@ dnl support function sections dnl PA_ARG_ENABLED([sections], [compile with function/data section support], - [PA_ADD_CFLAGS([-ffunction-sections]), - PA_ADD_CFLAGS([-fdata-sections])], + [PA_ADD_CLDFLAGS([-ffunction-sections]) + PA_ADD_CLDFLAGS([-fdata-sections]) + PA_ADD_CLDFLAGS([-Wl,--gc-sections])], []) dnl dnl support LTO From 0979957e19930407a3b202600aa99ec1fe0bd740 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 22:39:53 -0700 Subject: [PATCH 15/20] nasmlib: add path-splitting functions Some debugging formats may need to be able to split paths into directory name and filename, at least. This is kind of iffy, at least across platforms, but that isn't really expected to be an issue in practice... we hope. Signed-off-by: H. Peter Anvin --- Makefile.in | 26 +++++---- Mkfiles/msvc.mak | 20 ++++--- Mkfiles/openwcom.mak | 20 ++++--- nasmlib/path.c | 131 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 25 deletions(-) create mode 100644 nasmlib/path.c diff --git a/Makefile.in b/Makefile.in index aadd5678..71783af4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -100,7 +100,8 @@ LIBOBJ = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) \ nasmlib/crc64.$(O) nasmlib/malloc.$(O) \ nasmlib/md5c.$(O) nasmlib/string.$(O) \ nasmlib/file.$(O) nasmlib/mmap.$(O) nasmlib/ilog2.$(O) \ - nasmlib/realpath.$(O) nasmlib/filename.$(O) nasmlib/srcfile.$(O) \ + nasmlib/realpath.$(O) nasmlib/path.$(O) \ + nasmlib/filename.$(O) nasmlib/srcfile.$(O) \ nasmlib/zerobuf.$(O) nasmlib/readnum.$(O) nasmlib/bsi.$(O) \ nasmlib/rbtree.$(O) nasmlib/hashtbl.$(O) \ nasmlib/raa.$(O) nasmlib/saa.$(O) \ @@ -628,6 +629,9 @@ nasmlib/md5c.$(O): nasmlib/md5c.c config/config.h config/msvc.h \ nasmlib/mmap.$(O): nasmlib/mmap.c config/config.h config/msvc.h \ config/unknown.h config/watcom.h include/compiler.h include/error.h \ include/nasmint.h include/nasmlib.h nasmlib/file.h +nasmlib/path.$(O): nasmlib/path.c config/config.h config/msvc.h \ + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h nasmlib/perfhash.$(O): nasmlib/perfhash.c config/config.h config/msvc.h \ config/unknown.h config/watcom.h include/compiler.h include/hashtbl.h \ include/nasmint.h include/nasmlib.h include/perfhash.h @@ -741,8 +745,8 @@ output/outmacho.$(O): output/outmacho.c asm/directiv.h asm/pptok.h \ config/watcom.h include/compiler.h include/error.h include/labels.h \ include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \ include/perfhash.h include/raa.h include/rbtree.h include/saa.h \ - include/strlist.h include/tables.h output/outform.h output/outlib.h \ - x86/insnsi.h x86/regs.h + include/strlist.h include/tables.h include/ver.h output/dwarf.h \ + output/outform.h output/outlib.h x86/insnsi.h x86/regs.h output/outobj.$(O): output/outobj.c asm/directiv.h asm/eval.h asm/pptok.h \ asm/preproc.h asm/stdscan.h config/config.h config/msvc.h config/unknown.h \ config/watcom.h include/compiler.h include/error.h include/nasm.h \ @@ -756,13 +760,11 @@ output/outrdf2.$(O): output/outrdf2.c asm/directiv.h asm/pptok.h \ include/rdoff.h include/saa.h include/strlist.h include/tables.h \ output/outform.h output/outlib.h x86/insnsi.h x86/regs.h rdoff/collectn.$(O): rdoff/collectn.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - rdoff/collectn.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/collectn.h \ + rdoff/rdfutils.h rdoff/hash.$(O): rdoff/hash.c config/config.h config/msvc.h config/unknown.h \ config/watcom.h include/compiler.h include/nasmint.h rdoff/hash.h -rdoff/iochk.$(O): rdoff/iochk.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/nasmlib.h rdoff/ldrdf.$(O): rdoff/ldrdf.c config/config.h config/msvc.h \ config/unknown.h config/watcom.h include/compiler.h include/error.h \ include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/collectn.h \ @@ -796,11 +798,13 @@ rdoff/rdx.$(O): rdoff/rdx.c config/config.h config/msvc.h config/unknown.h \ include/nasmlib.h include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h \ rdoff/symtab.h rdoff/segtab.$(O): rdoff/segtab.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h \ rdoff/segtab.h rdoff/symtab.$(O): rdoff/symtab.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - rdoff/hash.h rdoff/symtab.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/hash.h \ + rdoff/rdfutils.h rdoff/symtab.h stdlib/snprintf.$(O): stdlib/snprintf.c config/config.h config/msvc.h \ config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ include/nasmlib.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index d43e76e1..b8b6d3ad 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -73,7 +73,8 @@ LIBOBJ = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) \ nasmlib\crc64.$(O) nasmlib\malloc.$(O) \ nasmlib\md5c.$(O) nasmlib\string.$(O) \ nasmlib\file.$(O) nasmlib\mmap.$(O) nasmlib\ilog2.$(O) \ - nasmlib\realpath.$(O) nasmlib\filename.$(O) nasmlib\srcfile.$(O) \ + nasmlib\realpath.$(O) nasmlib\path.$(O) \ + nasmlib\filename.$(O) nasmlib\srcfile.$(O) \ nasmlib\zerobuf.$(O) nasmlib\readnum.$(O) nasmlib\bsi.$(O) \ nasmlib\rbtree.$(O) nasmlib\hashtbl.$(O) \ nasmlib\raa.$(O) nasmlib\saa.$(O) \ @@ -519,6 +520,9 @@ nasmlib\md5c.$(O): nasmlib\md5c.c config\msvc.h config\unknown.h \ nasmlib\mmap.$(O): nasmlib\mmap.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\error.h include\nasmint.h \ include\nasmlib.h nasmlib\file.h +nasmlib\path.$(O): nasmlib\path.c config\msvc.h config\unknown.h \ + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h nasmlib\perfhash.$(O): nasmlib\perfhash.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\hashtbl.h include\nasmint.h \ include\nasmlib.h include\perfhash.h @@ -627,7 +631,8 @@ output\outmacho.$(O): output\outmacho.c asm\directiv.h asm\pptok.h \ include\compiler.h include\error.h include\labels.h include\nasm.h \ include\nasmint.h include\nasmlib.h include\opflags.h include\perfhash.h \ include\raa.h include\rbtree.h include\saa.h include\strlist.h \ - include\tables.h output\outform.h output\outlib.h x86\insnsi.h x86\regs.h + include\tables.h include\ver.h output\dwarf.h output\outform.h \ + output\outlib.h x86\insnsi.h x86\regs.h output\outobj.$(O): output\outobj.c asm\directiv.h asm\eval.h asm\pptok.h \ asm\preproc.h asm\stdscan.h config\msvc.h config\unknown.h config\watcom.h \ include\compiler.h include\error.h include\nasm.h include\nasmint.h \ @@ -641,11 +646,10 @@ output\outrdf2.$(O): output\outrdf2.c asm\directiv.h asm\pptok.h \ include\saa.h include\strlist.h include\tables.h output\outform.h \ output\outlib.h x86\insnsi.h x86\regs.h rdoff\collectn.$(O): rdoff\collectn.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h rdoff\collectn.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\collectn.h rdoff\rdfutils.h rdoff\hash.$(O): rdoff\hash.c config\msvc.h config\unknown.h config\watcom.h \ include\compiler.h include\nasmint.h rdoff\hash.h -rdoff\iochk.$(O): rdoff\iochk.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h rdoff\ldrdf.$(O): rdoff\ldrdf.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\error.h include\nasmint.h \ include\nasmlib.h include\rdoff.h rdoff\collectn.h rdoff\ldsegs.h \ @@ -676,9 +680,11 @@ rdoff\rdx.$(O): rdoff\rdx.c config\msvc.h config\unknown.h config\watcom.h \ include\compiler.h include\error.h include\nasmint.h include\nasmlib.h \ include\rdoff.h rdoff\rdfload.h rdoff\rdfutils.h rdoff\symtab.h rdoff\segtab.$(O): rdoff\segtab.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h rdoff\segtab.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\rdfutils.h rdoff\segtab.h rdoff\symtab.$(O): rdoff\symtab.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h rdoff\hash.h \ + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\hash.h rdoff\rdfutils.h \ rdoff\symtab.h stdlib\snprintf.$(O): stdlib\snprintf.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index b6468dd6..516c3f03 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -59,7 +59,8 @@ LIBOBJ = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) & nasmlib/crc64.$(O) nasmlib/malloc.$(O) & nasmlib/md5c.$(O) nasmlib/string.$(O) & nasmlib/file.$(O) nasmlib/mmap.$(O) nasmlib/ilog2.$(O) & - nasmlib/realpath.$(O) nasmlib/filename.$(O) nasmlib/srcfile.$(O) & + nasmlib/realpath.$(O) nasmlib/path.$(O) & + nasmlib/filename.$(O) nasmlib/srcfile.$(O) & nasmlib/zerobuf.$(O) nasmlib/readnum.$(O) nasmlib/bsi.$(O) & nasmlib/rbtree.$(O) nasmlib/hashtbl.$(O) & nasmlib/raa.$(O) nasmlib/saa.$(O) & @@ -493,6 +494,9 @@ nasmlib/md5c.$(O): nasmlib/md5c.c config/msvc.h config/unknown.h & nasmlib/mmap.$(O): nasmlib/mmap.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/error.h include/nasmint.h & include/nasmlib.h nasmlib/file.h +nasmlib/path.$(O): nasmlib/path.c config/msvc.h config/unknown.h & + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h nasmlib/perfhash.$(O): nasmlib/perfhash.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/hashtbl.h include/nasmint.h & include/nasmlib.h include/perfhash.h @@ -601,7 +605,8 @@ output/outmacho.$(O): output/outmacho.c asm/directiv.h asm/pptok.h & include/compiler.h include/error.h include/labels.h include/nasm.h & include/nasmint.h include/nasmlib.h include/opflags.h include/perfhash.h & include/raa.h include/rbtree.h include/saa.h include/strlist.h & - include/tables.h output/outform.h output/outlib.h x86/insnsi.h x86/regs.h + include/tables.h include/ver.h output/dwarf.h output/outform.h & + output/outlib.h x86/insnsi.h x86/regs.h output/outobj.$(O): output/outobj.c asm/directiv.h asm/eval.h asm/pptok.h & asm/preproc.h asm/stdscan.h config/msvc.h config/unknown.h config/watcom.h & include/compiler.h include/error.h include/nasm.h include/nasmint.h & @@ -615,11 +620,10 @@ output/outrdf2.$(O): output/outrdf2.c asm/directiv.h asm/pptok.h & include/saa.h include/strlist.h include/tables.h output/outform.h & output/outlib.h x86/insnsi.h x86/regs.h rdoff/collectn.$(O): rdoff/collectn.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h rdoff/collectn.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/rdfutils.h rdoff/hash.$(O): rdoff/hash.c config/msvc.h config/unknown.h config/watcom.h & include/compiler.h include/nasmint.h rdoff/hash.h -rdoff/iochk.$(O): rdoff/iochk.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h rdoff/ldrdf.$(O): rdoff/ldrdf.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/error.h include/nasmint.h & include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h & @@ -650,9 +654,11 @@ rdoff/rdx.$(O): rdoff/rdx.c config/msvc.h config/unknown.h config/watcom.h & include/compiler.h include/error.h include/nasmint.h include/nasmlib.h & include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h rdoff/symtab.h rdoff/segtab.$(O): rdoff/segtab.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h rdoff/segtab.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/segtab.h rdoff/symtab.$(O): rdoff/symtab.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h rdoff/hash.h & + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/hash.h rdoff/rdfutils.h & rdoff/symtab.h stdlib/snprintf.$(O): stdlib/snprintf.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h diff --git a/nasmlib/path.c b/nasmlib/path.c new file mode 100644 index 00000000..855440ea --- /dev/null +++ b/nasmlib/path.c @@ -0,0 +1,131 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2017 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. + * + * ----------------------------------------------------------------------- */ + +/* + * path.c - host operating system specific pathname manipulation functions + */ + +#include "compiler.h" +#include "nasmlib.h" +#include "error.h" + +#if defined(unix) || defined(__unix) || defined(__unix__) +# define separators "/" +# define cleandirend "/" +# define leaveonclean 1 +# define curdir "." +#elif defined(__MSDOS__) || defined(__WINDOWS__) || \ + defined(__OS2__) || defined(_WIN16) || defined(_WIN32) +# define separators "/\\:" +# define cleandirend "/\\" +# define leaveonclean 2 /* Leave \\ at the start alone */ +# define curdir "." +#elif defined(Macintosh) /* MacOS classic? */ +# define separators ":" +# define curdir ":" +# define cleandirend ":" +# define leaveonclean 0 +# define leave_leading 1 +#elif defined(__VMS) +/* + * VMS filenames may have ;version at the end. Assume we should count that + * as part of the filename anyway. + */ +# define separators ":]" +# define curdir "[]" +#else +/* No idea what to do here, do nothing. Feel free to add new ones. */ +# define curdir "" +#endif + +static inline bool ismatch(const char *charset, char ch) +{ + const char *p; + + for (p = charset; *p; p++) { + if (ch == *p) + return true; + } + + return false; +} + +static const char *first_filename_char(const char *path) +{ +#ifdef separators + const char *p = path + strlen(path); + + while (p > path) { + if (!ismatch(separators, p[-1])) + return p; + p--; + } + + return p; +#else + return path; +#endif +} + +/* Return the filename portion of a PATH as a new string */ +char *nasm_basename(const char *path) +{ + return nasm_strdup(first_filename_char(path)); +} + +/* Return the directory name portion of a PATH as a new string */ +char *nasm_dirname(const char *path) +{ + const char *p = first_filename_char(path); + const char *p0 = p; + (void)p0; /* Don't warn if unused */ + + if (p == path) + return nasm_strdup(curdir); + +#ifdef cleandirend + while (p > path+leaveonclean) { + if (ismatch(cleandirend, p[-1])) + break; + p--; + } +#endif + +#ifdef leave_leading + /* If the directory contained ONLY separators, leave as-is */ + if (p == path+leaveonclean) + p = p0; +#endif + + return nasm_strndup(path, p-path); +} From 11a07a7319676b55b9668fdfbf159580388d0318 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 23:01:00 -0700 Subject: [PATCH 16/20] nasmlib: add function to splice pathnames Add a function to splice a pathname consisting of a directory and a filename. It is worth noting that this function is limited to that particular use case: in particular, it does NOT currently support concatenating a filename which itself contains directory components to a non-null directory. Combining directory names is extremely system-dependent and probably needs more than just parameterized code in many cases, for example, on VMS combining "foo:[bar]" with "[baz]quux" should produce "foo:[bar.baz]quux" whereas combining "foo:[bar]" and baz:quux" is an outright error. Signed-off-by: H. Peter Anvin --- include/nasmlib.h | 9 ++++++++- nasmlib/path.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/nasmlib.h b/include/nasmlib.h index 0b2bcb17..672764c6 100644 --- a/include/nasmlib.h +++ b/include/nasmlib.h @@ -395,7 +395,14 @@ char *nasm_opt_val(char *p, char **opt, char **val); * * The buffer returned must be freed by the caller */ -char *nasm_realpath(const char *rel_path); +char * safe_alloc nasm_realpath(const char *rel_path); + +/* + * Path-splitting and merging functions + */ +char * safe_alloc nasm_dirname(const char *path); +char * safe_alloc nasm_basename(const char *path); +char * safe_alloc nasm_catfile(const char *dir, const char *path); const char * pure_func prefix_name(int); diff --git a/nasmlib/path.c b/nasmlib/path.c index 855440ea..72136546 100644 --- a/nasmlib/path.c +++ b/nasmlib/path.c @@ -42,17 +42,20 @@ #if defined(unix) || defined(__unix) || defined(__unix__) # define separators "/" # define cleandirend "/" +# define catsep '/' # define leaveonclean 1 # define curdir "." #elif defined(__MSDOS__) || defined(__WINDOWS__) || \ defined(__OS2__) || defined(_WIN16) || defined(_WIN32) # define separators "/\\:" # define cleandirend "/\\" +# define catsep '\\' # define leaveonclean 2 /* Leave \\ at the start alone */ # define curdir "." #elif defined(Macintosh) /* MacOS classic? */ # define separators ":" # define curdir ":" +# define catsep ":" # define cleandirend ":" # define leaveonclean 0 # define leave_leading 1 @@ -68,6 +71,10 @@ # define curdir "" #endif +/* + * This is an inline, because most compilers can greatly simplify this + * for a fixed string, like we have here. + */ static inline bool ismatch(const char *charset, char ch) { const char *p; @@ -129,3 +136,32 @@ char *nasm_dirname(const char *path) return nasm_strndup(path, p-path); } + +/* Concatenate a directory path and a filename */ +char *nasm_catfile(const char *dir, const char *file) +{ +#ifndef catsep + return nasm_strcat(dir, file); +#else + size_t dl = strlen(dir); + size_t fl = strlen(file); + char *p; + bool dosep = true; + + if (!dl || ismatch(separators, dir[dl-1])) { + /* No separator necessary */ + dosep = false; + } + + p = nasm_malloc(dl + fl + dosep + 1); + + memcpy(p, dir, dl); + p += dl; + if (dosep) + *p++ = catsep; + + memcpy(p, file, fl+1); + + return p; +#endif +} From d00d8c6ac396a84e85900cff7058f88180bf68fa Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 23:11:12 -0700 Subject: [PATCH 17/20] nasmlib: fix MacOS classic catsep definition Correct the definition for MacOS classic "catsep" in nasm_catfile(). Also put in a stern comment that this function doesn't handle filenames with path components. Signed-off-by: H. Peter Anvin --- nasmlib/path.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nasmlib/path.c b/nasmlib/path.c index 72136546..fd7ea132 100644 --- a/nasmlib/path.c +++ b/nasmlib/path.c @@ -55,7 +55,7 @@ #elif defined(Macintosh) /* MacOS classic? */ # define separators ":" # define curdir ":" -# define catsep ":" +# define catsep ':' # define cleandirend ":" # define leaveonclean 0 # define leave_leading 1 @@ -137,7 +137,11 @@ char *nasm_dirname(const char *path) return nasm_strndup(path, p-path); } -/* Concatenate a directory path and a filename */ +/* + * Concatenate a directory path and a filename. Note that this function + * currently does NOT handle the case where file itself contains + * directory components (except on Unix platforms, because it is trivial.) + */ char *nasm_catfile(const char *dir, const char *file) { #ifndef catsep From 40f0a7495aa1353d90c8fb68912b82c3af2ff01d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 23:20:54 -0700 Subject: [PATCH 18/20] SAA: add saa_wcstring() Add saa_wcstring() to write a C string (a string including final NUL) to an SAA, and return the number of bytes written. Signed-off-by: H. Peter Anvin --- include/saa.h | 1 + nasmlib/saa.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/saa.h b/include/saa.h index 8a8bd075..afd25a45 100644 --- a/include/saa.h +++ b/include/saa.h @@ -70,6 +70,7 @@ struct SAA *saa_init(size_t elem_len); /* 1 == byte */ void saa_free(struct SAA *); void *saa_wstruct(struct SAA *); /* return a structure of elem_len */ void saa_wbytes(struct SAA *, const void *, size_t); /* write arbitrary bytes */ +size_t saa_wcstring(struct SAA *s, const char *str); /* write a C string */ void saa_rewind(struct SAA *); /* for reading from beginning */ void *saa_rstruct(struct SAA *); /* return NULL on EOA */ const void *saa_rbytes(struct SAA *, size_t *); /* return 0 on EOA */ diff --git a/nasmlib/saa.c b/nasmlib/saa.c index a0350c10..c4af5aa0 100644 --- a/nasmlib/saa.c +++ b/nasmlib/saa.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2017 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -149,6 +149,19 @@ void saa_wbytes(struct SAA *s, const void *data, size_t len) } } +/* + * Writes a string, *including* the final null, to the specified SAA, + * and return the number of bytes written. + */ +size_t saa_wcstring(struct SAA *s, const char *str) +{ + size_t bytes = strlen(str) + 1; + + saa_wbytes(s, str, bytes); + + return bytes; +} + void saa_rewind(struct SAA *s) { s->rblk = s->blk_ptrs; From 6e11b2cc544572d5283e2c584ab95bcaf17997a7 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 23:37:11 -0700 Subject: [PATCH 19/20] saa, raa: saa_init() and raa_init() will never return NULL Like other NASM allocation functions, these will abort rather than ever return NULL. Signed-off-by: H. Peter Anvin --- include/raa.h | 2 +- include/saa.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/raa.h b/include/raa.h index 22c4537b..1ef5cc15 100644 --- a/include/raa.h +++ b/include/raa.h @@ -38,7 +38,7 @@ struct RAA; -struct RAA *raa_init(void); +struct RAA * never_null raa_init(void); void raa_free(struct RAA *); int64_t raa_read(struct RAA *, int32_t); struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value); diff --git a/include/saa.h b/include/saa.h index afd25a45..9d939ef5 100644 --- a/include/saa.h +++ b/include/saa.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2017 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -66,7 +66,7 @@ struct SAA { char **blk_ptrs; /* Pointer to pointer blocks */ }; -struct SAA *saa_init(size_t elem_len); /* 1 == byte */ +struct SAA * never_null saa_init(size_t elem_len); /* 1 == byte */ void saa_free(struct SAA *); void *saa_wstruct(struct SAA *); /* return a structure of elem_len */ void saa_wbytes(struct SAA *, const void *, size_t); /* write arbitrary bytes */ From 4b177bfb0373e7c8309be5841d9a13664b643d22 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 23 Apr 2017 23:46:41 -0700 Subject: [PATCH 20/20] outmacho: clean up list walks, use nasm_basename/nasm_dirname Use the new nasm_basename() and nasm_dirname() functions to split a pathname. Use nasm_wcstring() to write a C string to an SAA. Use list_for_each() to walk linked lists. Signed-off-by: H. Peter Anvin --- output/outmacho.c | 48 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 5c259e2f..d10c60c3 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -1797,9 +1797,9 @@ static void macho_dbg_generate(void) /* dw section walk to find high_addr and total_len */ { - struct dw_sect_list *p_sect = dw_head_sect; - uint32_t idx = 0; - for(; idx < dw_num_sects; idx++) { + struct dw_sect_list *p_sect; + + list_for_each(p_sect, dw_head_sect) { uint64_t offset = get_section_by_index(p_sect->section)->size; struct SAA *p_linep = p_sect->psaa; @@ -1811,16 +1811,14 @@ static void macho_dbg_generate(void) total_len += p_linep->datalen; high_addr += offset; - p_sect = p_sect->next; } } /* debug line */ { - struct file_list *p_file = dw_head_list; - struct dw_sect_list *p_sect = dw_head_sect; - size_t linep_off = 0; - uint32_t idx = 0, buf_size = 0; + struct file_list *p_file; + struct dw_sect_list *p_sect; + size_t linep_off, buf_size; struct SAA *p_lines = saa_init(1L); nasm_assert(p_lines != NULL); @@ -1846,12 +1844,11 @@ static void macho_dbg_generate(void) saa_write8(p_lines, 1); /* std opcode 12 length */ saa_write8(p_lines, 0); /* end of table */ - for(idx = 0; idx < dw_num_files; idx++) { - saa_wbytes(p_lines, p_file->file_name, (int32_t)(strlen(p_file->file_name) +1)); + list_for_each(p_file, dw_head_list) { + saa_wcstring(p_lines, p_file->file_name); saa_write8(p_lines, 0); /* directory */ saa_write8(p_lines, 0); /* time */ saa_write8(p_lines, 0); /* size */ - p_file = p_file->next; } saa_write8(p_lines, 0); /* end of table */ @@ -1868,7 +1865,7 @@ static void macho_dbg_generate(void) p_buf += linep_off; saa_free(p_lines); - for(idx = 0; idx < dw_num_sects; idx++) { + list_for_each(p_sect, dw_head_sect) { struct SAA *p_linep = p_sect->psaa; saa_len = p_linep->datalen; saa_rnbytes(p_linep, p_buf, saa_len); @@ -1884,7 +1881,6 @@ static void macho_dbg_generate(void) /* string section */ { struct file_list *p_file = dw_head_list; - uint32_t idx = 0; struct SAA *p_str = saa_init(1L); struct SAA *p_path_str = saa_init(1L); nasm_assert((p_str != NULL) && (p_path_str != NULL)); @@ -1897,21 +1893,21 @@ static void macho_dbg_generate(void) module_str_offset = path_str_offset = producer_str_offset + strlen(nasm_signature) + 1; - for(; idx < dw_num_files; idx++) { - size_t cur_file_strlen = strlen(p_file->file_name) + 1; + list_for_each(p_file, dw_head_list) { char *cur_path = nasm_realpath(p_file->file_name); - size_t cur_path_strlen = strlen(cur_path); + char *cur_file = nasm_basename(cur_path); + char *cur_dir = nasm_dirname(cur_path); - nasm_assert(cur_path_strlen > cur_file_strlen); - cur_path_strlen -= cur_file_strlen; - cur_path[cur_path_strlen] = '\0'; - saa_wbytes(p_str, p_file->file_name, cur_file_strlen); - saa_wbytes(p_path_str, cur_path, cur_path_strlen); - path_str_offset += cur_file_strlen; - p_file = p_file->next; + saa_wcstring(p_str, cur_file); + saa_wcstring(p_path_str, cur_dir); + + nasm_free(cur_path); + nasm_free(cur_file); + nasm_free(cur_dir); } saa_len = p_str->datalen; + path_str_offset += saa_len; p_buf = nasm_malloc(saa_len); saa_rnbytes(p_str, p_buf, saa_len); macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0); @@ -2045,16 +2041,14 @@ static void macho_dbg_linenum(const char *file_name, int32_t line_num, int32_t s if(!dw_cur_list || strcmp(file_name, dw_cur_list->file_name)) { if(dw_head_list) { - struct file_list *match = dw_head_list; - uint32_t idx = 0; + struct file_list *match; - for (; idx < dw_num_files; idx++ ) { + list_for_each(match, dw_head_list) { if(!(strcmp(file_name, match->file_name))) { dw_cur_list = match; need_new_list = false; break; } - match = match->next; } }