From 4afa730c03c01aac26f8a41eb5cb19622b7afa14 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 10:55:00 -0800 Subject: outmacho: default section flags should depend on section name only The __TEXT segment in particular contains both code and data. The most consistent thing is to look only at the section name, and have the same behavior across sections. Signed-off-by: H. Peter Anvin --- output/outmacho.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 98a440d3..6179cc70 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -36,9 +36,6 @@ * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files */ -/* Most of this file is, like Mach-O itself, based on a.out. For more - * guidelines see outaout.c. */ - #include "compiler.h" #include @@ -710,10 +707,10 @@ static int32_t macho_section(char *name, int pass, int *bits) nasm_error(ERR_NONFATAL, "section name %s too long\n", section); } - if (!strcmp(segment, "__TEXT")) { + if (!strcmp(section, "__text")) { flags = S_REGULAR | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS; - } else if (!strcmp(segment, "__DATA") && !strcmp(section, "__bss")) { + } else if (!strcmp(section, "__bss")) { flags = S_ZEROFILL; } else { flags = S_REGULAR; -- cgit v1.2.1 From 5f0e601f9890e4dc85245c2f2b4178e051c97ea5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 11:48:12 -0800 Subject: doc/rdsrc.pl: escape braces in regular expression to support newer Perl Newer versions of Perl require literal braces in regular expressions to be escaped. Signed-off-by: H. Peter Anvin --- doc/rdsrc.pl | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/doc/rdsrc.pl b/doc/rdsrc.pl index de3a862f..21ec6e75 100644 --- a/doc/rdsrc.pl +++ b/doc/rdsrc.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl ## -------------------------------------------------------------------------- ## -## 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. ## @@ -249,8 +249,8 @@ sub got_para { while (/^\\c (([^\\]|\\[^c])*)(.*)$/) { $l = $1; $_ = $3; - $l =~ s/\\{/{/g; - $l =~ s/\\}/}/g; + $l =~ s/\\\{/\{/g; + $l =~ s/\\\}/}/g; $l =~ s/\\\\/\\/g; push @$pname, $l; } @@ -263,7 +263,7 @@ sub got_para { $snum = 0; $xref = "chapter-$cnum"; $pflags = "chap $cnum :$xref"; - die "badly formatted chapter heading: $_\n" if !/^\\C{([^}]*)}\s*(.*)$/; + die "badly formatted chapter heading: $_\n" if !/^\\C\{([^\}]*)\}\s*(.*)$/; $refs{$1} = "chapter $cnum"; $node = "Chapter $cnum"; &add_item($node, 1); @@ -280,7 +280,7 @@ sub got_para { $snum = 0; $xref = "appendix-$cnum"; $pflags = "appn $cnum :$xref"; - die "badly formatted appendix heading: $_\n" if !/^\\A{([^}]*)}\s*(.*)$/; + die "badly formatted appendix heading: $_\n" if !/^\\A\{([^\}]*)}\s*(.*)$/; $refs{$1} = "appendix $cnum"; $node = "Appendix $cnum"; &add_item($node, 1); @@ -294,7 +294,7 @@ sub got_para { $snum = 0; $xref = "section-$cnum.$hnum"; $pflags = "head $cnum.$hnum :$xref"; - die "badly formatted heading: $_\n" if !/^\\[HP]{([^}]*)}\s*(.*)$/; + die "badly formatted heading: $_\n" if !/^\\[HP]{([^\}]*)}\s*(.*)$/; $refs{$1} = "section $cnum.$hnum"; $node = "Section $cnum.$hnum"; &add_item($node, 2); @@ -307,7 +307,7 @@ sub got_para { $snum++; $xref = "section-$cnum.$hnum.$snum"; $pflags = "subh $cnum.$hnum.$snum :$xref"; - die "badly formatted subheading: $_\n" if !/^\\S{([^}]*)}\s*(.*)$/; + die "badly formatted subheading: $_\n" if !/^\\S\{([^\}]*)\}\s*(.*)$/; $refs{$1} = "section $cnum.$hnum.$snum"; $node = "Section $cnum.$hnum.$snum"; &add_item($node, 3); @@ -317,18 +317,18 @@ sub got_para { # the standard word-by-word code will happen next } elsif (/^\\IR/) { # An index-rewrite. - die "badly formatted index rewrite: $_\n" if !/^\\IR{([^}]*)}\s*(.*)$/; + die "badly formatted index rewrite: $_\n" if !/^\\IR\{([^\}]*)\}\s*(.*)$/; $irewrite = $1; $_ = $2; # the standard word-by-word code will happen next } elsif (/^\\IA/) { # An index-alias. - die "badly formatted index alias: $_\n" if !/^\\IA{([^}]*)}{([^}]*)}\s*$/; + die "badly formatted index alias: $_\n" if !/^\\IA\{([^\}]*)}\{([^\}]*)\}\s*$/; $idxalias{$1} = $2; return; # avoid word-by-word code } elsif (/^\\M/) { # Metadata - die "badly formed metadata: $_\n" if !/^\\M{([^}]*)}{([^}]*)}\s*$/; + die "badly formed metadata: $_\n" if !/^\\M\{([^\}]*)}\{([^\}]*)\}\s*$/; $metadata{$1} = $2; return; # avoid word-by-word code } elsif (/^\\b/) { @@ -374,11 +374,11 @@ sub got_para { $qindex = 1 if $1 eq "\\I"; $indexing = 1, s/^\\[iI]// if $1; s/^\\c//; - die "badly formatted \\c: \\c$_\n" if !/{(([^\\}]|\\.)*)}(.*)$/; + die "badly formatted \\c: \\c$_\n" if !/\{(([^\\}]|\\.)*)\}(.*)$/; $w = $1; $_ = $3; - $w =~ s/\\{/{/g; - $w =~ s/\\}/}/g; + $w =~ s/\\\{/\{/g; + $w =~ s/\\\}/\}/g; $w =~ s/\\-/-/g; $w =~ s/\\\\/\\/g; (push @$pname,"i"),$lastp = $#$pname if $indexing; @@ -391,11 +391,11 @@ sub got_para { $indexing = 1, $type = "\\i" if $1; $emph = 1, $type = "\\e" if $2; s/^(\\[iI])?(\\e?)//; - die "badly formatted $type: $type$_\n" if !/{(([^\\}]|\\.)*)}(.*)$/; + die "badly formatted $type: $type$_\n" if !/\{(([^\\}]|\\.)*)\}(.*)$/; $w = $1; $_ = $3; - $w =~ s/\\{/{/g; - $w =~ s/\\}/}/g; + $w =~ s/\\\{/\{/g; + $w =~ s/\\\}/\}/g; $w =~ s/\\-/-/g; $w =~ s/\\\\/\\/g; $t = $emph ? "es" : "n "; @@ -418,21 +418,21 @@ sub got_para { $t = "k "; $t = "kK" if /^\\K/; s/^\\[kK]//; - die "badly formatted \\k: \\c$_\n" if !/{([^}]*)}(.*)$/; + die "badly formatted \\k: \\k$_\n" if !/\{([^\}]*)\}(.*)$/; $_ = $2; push @$pname,"$t$1"; } elsif (/^\\W/) { s/^\\W//; die "badly formatted \\W: \\W$_\n" - if !/{([^}]*)}(\\i)?(\\c)?{(([^\\}]|\\.)*)}(.*)$/; + if !/\{([^\}]*)\}(\\i)?(\\c)?\{(([^\\}]|\\.)*)\}(.*)$/; $l = $1; $w = $4; $_ = $6; $t = "w "; $t = "wc" if $3 eq "\\c"; $indexing = 1 if $2; - $w =~ s/\\{/{/g; - $w =~ s/\\}/}/g; + $w =~ s/\\\{/\{/g; + $w =~ s/\\\}/\}/g; $w =~ s/\\-/-/g; $w =~ s/\\\\/\\/g; (push @$pname,"i"),$lastp = $#$pname if $indexing; @@ -443,8 +443,8 @@ sub got_para { die "painful death! $_\n" if !length $1; $w = $1; $_ = $3; - $w =~ s/\\{/{/g; - $w =~ s/\\}/}/g; + $w =~ s/\\\{/\{/g; + $w =~ s/\\\}/\}/g; $w =~ s/\\-/-/g; $w =~ s/\\\\/\\/g; if ($w eq "-") { -- cgit v1.2.1 From 277308f1f3cbd6dba09e560998f7dca7fa7aeaf3 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 11:49:33 -0800 Subject: doc: update documentation for a version 2.12 release Add documentation updates for version 2.12. Signed-off-by: H. Peter Anvin --- doc/changes.src | 20 ++++++++----- doc/nasmdoc.src | 89 ++++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 85 insertions(+), 24 deletions(-) diff --git a/doc/changes.src b/doc/changes.src index eab8439d..94ddb9c9 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -9,12 +9,15 @@ since 2007. \S{cl-2.12} Version 2.12 -\b Huge rework of \c{macho} backend (\k{Mach-O}), internal unification - of 32 and 64 bit formats and make NASM to handle section - alignment properly. +\b Major fixes to the \c{macho} backend (\k{machofmt}); earlier versions + would produce invalid symbols and relocations on a regular basis. + +\b Support for thread-local storage in Mach-O. + +\b Support for arbitrary sections in Mach-O. \b Fix wrong negative size treated as a big positive value passed into - backend causing nasm to crash. + backend causing NASM to crash. \b Fix handling of zero-extending unsigned relocations, we have been printing wrong message and forgot to assign segment with predefined value before @@ -25,16 +28,19 @@ since 2007. \b Portability fixes for building NASM with LLVM compiler. -\b Add support of Codeview (\c{cv8}) debug format for \c{win32} and \c{win64} - formats in the \c{COFF} backend (\k{coff}). +\b Add support of Codeview version 8 (\c{cv8}) debug format for + \c{win32} and \c{win64} formats in the \c{COFF} backend, + see \k{codeview}. \b Allow 64-bit outputs in 16/32-bit only backends. Unsigned 64-bit relocations are zero-extended from 32-bits with a warning - (suppressible via \c{}); signed 64-bit relocations are an arror. + (suppressible via \c{-w-zext-reloc}); signed 64-bit relocations are + an arror. \b Line numbers in list files now correspond to the lines in the source files, instead of simply being sequential. + \S{cl-2.11.09} Version 2.11.09 \b Fix potential stack overwrite in \c{macho32} backend. diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 00a1a14b..23a273b3 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -140,6 +140,7 @@ variables \IA{case-sensitive}{case sensitive} \IA{case-insensitive}{case sensitive} \IA{character constants}{character constant} +\IR{codeview} CodeView debugging format \IR{common object file format} Common Object File Format \IR{common variables, alignment in elf} common variables, alignment in \c{elf} @@ -187,7 +188,8 @@ convention \IR{logical or} logical OR \IR{logical xor} logical XOR \IR{mach object file format} Mach, object file format -\IR{mach-o} Mach-O +\IA{mach-o}{macho} +\IR{mach-o} Mach-O, object file format \IR{macho32} \c{macho32} \IR{macho64} \c{macho64} \IR{macos x} MacOS X @@ -232,6 +234,7 @@ Object File Format \IR{section alignment, in obj} section alignment, in \c{obj} \IR{section alignment, in win32} section alignment, in \c{win32} \IR{section, elf extensions to} \c{SECTION}, \c{elf} extensions to +\IR{section, macho extensions to} \c{SECTION}, \c{macho} extensions to \IR{section, win32 extensions to} \c{SECTION}, \c{win32} extensions to \IR{segment alignment, in bin} segment alignment, in \c{bin} \IR{segment alignment, in obj} segment alignment, in \c{obj} @@ -336,7 +339,7 @@ distribution archive, for the license conditions under which you may use NASM. NASM is now under the so-called 2-clause BSD license, also known as the simplified BSD license. -Copyright 1996-2011 the NASM Authors - All rights reserved. +Copyright 1996-2016 the NASM Authors - All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -4395,6 +4398,9 @@ output format defaults to 16-bit mode in anticipation of it being used most frequently to write DOS \c{.COM} programs, DOS \c{.SYS} device drivers and boot loader software. +The \c{BITS} directive can also be used to generate code for a +different mode than the standard one for the output format. + You do \e{not} need to specify \c{BITS 32} merely in order to use 32-bit instructions in a 16-bit DOS program; if you do, the assembler will generate incorrect code because it will be writing @@ -5428,6 +5434,14 @@ data for "safe exception handler table" causes no backward incompatibilities and "safeseh" modules generated by NASM 2.03 and later can still be linked by earlier versions or non-Microsoft linkers. +\S{codeview} Debugging formats for Windows +\I{Windows debugging formats} + +The \c{win32} and \c{win64} formats support the Microsoft CodeView +debugging format. Currently CodeView version 8 format is supported +(\i\c{cv8}), but newer versions of the CodeView debugger should be +able to handle this format as well. + \H{win64fmt} \i\c{win64}: Microsoft Win64 Object Files @@ -5695,12 +5709,58 @@ the \c{info} section type are not supported. \H{machofmt} \I{Mach-O}\i\c{macho32} and \i\c{macho64}: \i{Mach Object File Format} -The \c{macho32} and \c{macho64} output formts produces \c{Mach-O} +The \c{macho32} and \c{macho64} output formts produces Mach-O object files suitable for linking with the \i{MacOS X} linker. \i\c{macho} is a synonym for \c{macho32}. \c{macho} provides a default output file-name extension of \c{.o}. +\S{machosect} \c{macho} extensions to the \c{SECTION} Directive +\I{SECTION, macho extensions to} + +The \c{macho} output format specifies section names in the format +"\e{segment}\c{,}\e{section}". No spaces are allowed around the +comma. The following flags can also be specified: + +\b \c{data} - this section contains initialized data items + +\b \c{text} - this section contains code exclusively + +\b \c{mixed} - this section contains both code and data + +\b \c{bss} - this section is uninitialized and filled with zero + +\b \c{align=}\e{alignment} - specify section alignment + +The default is \c{data}, unless the section name is \c{__text} or +\c{__bss} in which case the default is \c{text} or \c{bss}, +respectively. + +For compatibility with other Unix platforms, the following standard +names are also supported: + +\c .text = __TEXT,__text text +\c .rodata = __DATA,__const data +\c .data = __DATA,__data data +\c .bss = __DATA,__bss bss + +If the \c{.rodata} section contains no relocations, it is instead put +into the \c{__TEXT,__const} section unless this section has already +been specified explicitly. However, it is probably better to specify +\c{__TEXT,__const} and \c{__DATA,__const} explicitly as appropriate. + +\S{machotls} \i{Thread Local Storage in Mach-O}\I{TLS}: \c{macho} special +symbols and \i\c{WRT} + +Mach-O defines the following special symbols that can be used on the +right-hand side of the \c{WRT} operator: + +\b \c{..tlvp} is used to specify access to thread-local storage. + +\b \c{..gotpcrel} is used to specify references to the Global Offset + Table. The GOT is supported in the \c{macho64} format only. + + \H{elffmt} \i\c{elf32}, \i\c{elf64}, \i\c{elfx32}: \I{ELF}\I{linux, elf}\i{Executable and Linkable Format} Object Files @@ -5715,13 +5775,14 @@ ABI with the CPU in 64-bit mode. \S{abisect} ELF specific directive \i\c{osabi} -The ELF header specifies the application binary interface for the target operating system (OSABI). -This field can be set by using the \c{osabi} directive with the numeric value (0-255) of the target - system. If this directive is not used, the default value will be "UNIX System V ABI" (0) which will work on - most systems which support ELF. +The ELF header specifies the application binary interface for the +target operating system (OSABI). This field can be set by using the +\c{osabi} directive with the numeric value (0-255) of the target +system. If this directive is not used, the default value will be "UNIX +System V ABI" (0) which will work on most systems which support ELF. -\S{elfsect} \c{elf} Extensions to the \c{SECTION} -Directive\I{SECTION, elf extensions to} +\S{elfsect} \c{elf} extensions to the \c{SECTION} Directive +\I{SECTION, elf extensions to} Like the \c{obj} format, \c{elf} allows you to specify additional information on the \c{SECTION} directive line, to control the type @@ -5779,15 +5840,9 @@ qualifiers are: Please note that section names are case sensitive.) -\S{elfwrt} \i{Position-Independent Code}\I{PIC}: \c{elf} Special +\S{elfwrt} \i{Position-Independent Code}\I{PIC}: \c{macho} Special Symbols and \i\c{WRT} -The \c{ELF} specification contains enough features to allow -position-independent code (PIC) to be written, which makes \i{ELF -shared libraries} very flexible. However, it also means NASM has to -be able to generate a variety of ELF specific relocation types in ELF -object files, if it is to be an assembler which can write PIC. - Since \c{ELF} does not support segment-base references, the \c{WRT} operator is not used for its normal purpose; therefore NASM's \c{elf} output format makes use of \c{WRT} for a different purpose, @@ -5836,7 +5891,7 @@ peculiarity of the dynamic linker. A fuller explanation of how to use these relocation types to write shared libraries entirely in NASM is given in \k{picdll}. -\S{elftls} \i{Thread Local Storage}\I{TLS}: \c{elf} Special +\S{elftls} \i{Thread Local Storage in ELF}\I{TLS}: \c{elf} Special Symbols and \i\c{WRT} \b In ELF32 mode, referring to an external or global symbol using -- cgit v1.2.1 From dea76e77793238bd35230413dfc962a1e7f03e00 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 11:50:42 -0800 Subject: NASM 2.12rc5 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 2382492e..38e6cc52 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12rc4 +2.12rc5 -- cgit v1.2.1 From b423c02ad2fa97310ea72968540e38e70d73c43e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 11:57:53 -0800 Subject: Platform compatibility improvements Windows: indicate that we support multibyte character sets in file names. Unix: support gigantic input and output files. Might be useful especially in the presence of the INCBIN directive. Signed-off-by: H. Peter Anvin --- compiler.h | 3 +++ configure.in | 1 + 2 files changed, 4 insertions(+) diff --git a/compiler.h b/compiler.h index e9022f86..4a68576c 100644 --- a/compiler.h +++ b/compiler.h @@ -48,6 +48,9 @@ # undef __STRICT_ANSI__ #endif +/* On Microsoft platforms we support multibyte character sets in filenames */ +#define _MBCS 1 + #ifdef HAVE_CONFIG_H # include "config.h" /* autoconf doesn't define these if they are redundant, but we want to diff --git a/configure.in b/configure.in index 023bd240..5164f4db 100644 --- a/configure.in +++ b/configure.in @@ -49,6 +49,7 @@ AC_PREFIX_PROGRAM(nasm) dnl Checks for programs. dnl Consider AC_USE_SYSTEM_EXTENSIONS if autoconf 2.61 is OK in the future AC_USE_SYSTEM_EXTENSIONS +AC_SYS_LARGEFILE AC_PROG_CC AC_PROG_LN_S AC_PROG_MAKE_SET -- cgit v1.2.1 From 44a609b203734f7b76ab4fbb80e6d17cb0884151 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 12:09:31 -0800 Subject: configure.in: add --enable-werror option Add an option to compile with -Werror, useful for development. Change --with-ccache to --enable-ccache to match guidelines. Signed-off-by: H. Peter Anvin --- configure.in | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/configure.in b/configure.in index 5164f4db..63192065 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf 2.61 or later to produce dnl a configure script. -AC_PREREQ(2.61) +AC_PREREQ(2.63) AC_INIT(config.h.in) AC_CONFIG_HEADERS(config.h) @@ -176,14 +176,17 @@ fi dnl dnl support cchace dnl -AC_ARG_WITH([ccache], - [AC_HELP_STRING([--with-ccache], - [Compile with ccache])], - [CC="ccache $CC"], - []) +AC_ARG_ENABLE([ccache], +[AC_HELP_STRING([--with-ccache], [compile with ccache])], +[CC="ccache $CC"], +[]) PA_ADD_CFLAGS([-pedantic]) -PA_ADD_CFLAGS([-Werror=implicit]) +AC_ARG_ENABLE([werror], +[AC_HELP_STRING([--enable-werror], +[compile with -Werror to error out on any warning])], +[PA_ADD_CFLAGS([-Werror])], +[PA_ADD_CFLAGS([-Werror=implicit]) PA_ADD_CFLAGS([-Werror=missing-braces]) PA_ADD_CFLAGS([-Werror=return-type]) PA_ADD_CFLAGS([-Werror=trigraphs]) @@ -192,7 +195,7 @@ PA_ADD_CFLAGS([-Werror=strict-prototypes]) PA_ADD_CFLAGS([-Werror=missing-prototypes]) PA_ADD_CFLAGS([-Werror=missing-declarations]) PA_ADD_CFLAGS([-Werror=comment]) -PA_ADD_CFLAGS([-Werror=vla]) +PA_ADD_CFLAGS([-Werror=vla])]) AC_OUTPUT_COMMANDS([mkdir -p output]) AC_OUTPUT(Makefile rdoff/Makefile doc/Makefile) -- cgit v1.2.1 From 114ba75f7bb6dbd935b8b72537544d8e8ec49716 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 18 Feb 2016 13:06:04 -0800 Subject: test/Makefile: add a rule for nasm itself If NASM needs to be rebuilt, build it in the proper directory. Signed-off-by: H. Peter Anvin --- test/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Makefile b/test/Makefile index 8b513590..a76044d4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,6 +5,9 @@ NASMOPT = -Ox -I../misc $(OPT) PERL = perl TESTS = $(wildcard *.asm) +$(NASM): + $(MAKE) -C .. + %.bin: %.asm $(NASM) $(NASM) $(NASMOPT) -f bin -o $@ -l $*.lst $< -- cgit v1.2.1