0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00

Merge branch 'evalmacro'

Resolved Conflicts:
	asm/preproc.c
	output/elf.h
	output/outelf.c
	output/outelf.h
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel)
2019-04-24 11:14:43 -07:00
17 changed files with 1378 additions and 957 deletions

View File

@@ -1,6 +1,6 @@
## -------------------------------------------------------------------------- ## --------------------------------------------------------------------------
## ##
## Copyright 1996-2016 The NASM Authors - All Rights Reserved ## Copyright 1996-2019 The NASM Authors - All Rights Reserved
## See the file AUTHORS included with the NASM distribution for ## See the file AUTHORS included with the NASM distribution for
## the specific copyright holders. ## the specific copyright holders.
## ##
@@ -70,8 +70,12 @@
%ideftok %ideftok
%if* %if*
%imacro %imacro
%irmacro
%include %include
%ipathsearch
%irmacro
%istrcat
%istrlen
%isubstr
%ixdefine %ixdefine
%line %line
%local %local

File diff suppressed because it is too large Load Diff

View File

@@ -215,6 +215,14 @@ static char *emit_utf8(char *q, int32_t v)
return q; return q;
} }
/*
* Quote a C string
*/
char *nasm_quote_cstr(const char *str)
{
return nasm_quote(str, strlen(str));
}
/* /*
* Do an *in-place* dequoting of the specified string, returning the * Do an *in-place* dequoting of the specified string, returning the
* resulting length (which may be containing embedded nulls.) * resulting length (which may be containing embedded nulls.)

View File

@@ -37,6 +37,7 @@
#include "compiler.h" #include "compiler.h"
char *nasm_quote(const char *str, size_t len); char *nasm_quote(const char *str, size_t len);
char *nasm_quote_cstr(const char *str);
size_t nasm_unquote(char *str, char **endptr); size_t nasm_unquote(char *str, char **endptr);
char *nasm_skip_string(char *str); char *nasm_skip_string(char *str);

View File

@@ -42,6 +42,11 @@ AS_IF([$pa_no_optimize],
[PA_ADD_CFLAGS([-O0]) [PA_ADD_CFLAGS([-O0])
PA_ADD_CFLAGS([-fno-omit-frame-pointer])]) PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
dnl Profiling
PA_ARG_ENABLED([profiling],
[compile with profiling (-pg option)],
[PA_ADD_CFLAGS([-pg])])
dnl Abort on panic dnl Abort on panic
PA_ARG_ENABLED([panic-abort], PA_ARG_ENABLED([panic-abort],
[call abort() on panic to trap in the debugger], [call abort() on panic to trap in the debugger],

View File

@@ -18,6 +18,14 @@ since 2007.
\b Suppress nuisance "\c{label changed during code generation}" messages \b Suppress nuisance "\c{label changed during code generation}" messages
after a real error. after a real error.
\b Add support for the \c{merge} and \c{strings} attributes on ELF
sections. See \k{elfsect}.
\b Add support for the \c{note}, \c{preinit_array}, \c{init_array},
and \c{fini_array} sections type in ELF. See \k{elfsect}.
\b Handle more than 32,633 sections in ELF.
\S{cl-2.14.02} Version 2.14.02 \S{cl-2.14.02} Version 2.14.02
\b Fix crash due to multiple errors or warnings during the code \b Fix crash due to multiple errors or warnings during the code

View File

@@ -122,15 +122,14 @@
\IR{- opunary} \c{-} operator, unary \IR{- opunary} \c{-} operator, unary
\IR{! opunary} \c{!} operator, unary \IR{! opunary} \c{!} operator, unary
\IR{alignment, in bin sections} alignment, in \c{bin} sections \IR{alignment, in bin sections} alignment, in \c{bin} sections
\IR{alignment, in elf sections} alignment, in \c{elf} sections \IR{alignment, in elf sections} alignment, in ELF sections
\IR{alignment, in win32 sections} alignment, in \c{win32} sections \IR{alignment, in win32 sections} alignment, in \c{win32} sections
\IR{alignment, of elf common variables} alignment, of \c{elf} common \IR{alignment, of elf common variables} alignment, of ELF common
variables variables
\IR{alignment, in obj sections} alignment, in \c{obj} sections \IR{alignment, in obj sections} alignment, in \c{obj} sections
\IR{a.out, bsd version} \c{a.out}, BSD version \IR{a.out, bsd version} \c{a.out}, BSD version
\IR{a.out, linux version} \c{a.out}, Linux version \IR{a.out, linux version} \c{a.out}, Linux version
\IR{autoconf} Autoconf \IR{bin} \c{bin} output format
\IR{bin} bin
\IR{bitwise and} bitwise AND \IR{bitwise and} bitwise AND
\IR{bitwise or} bitwise OR \IR{bitwise or} bitwise OR
\IR{bitwise xor} bitwise XOR \IR{bitwise xor} bitwise XOR
@@ -150,8 +149,8 @@ variables
\IR{codeview} CodeView debugging format \IR{codeview} CodeView debugging format
\IR{common object file format} Common Object File Format \IR{common object file format} Common Object File Format
\IR{common variables, alignment in elf} common variables, alignment \IR{common variables, alignment in elf} common variables, alignment
in \c{elf} in ELF
\IR{common, elf extensions to} \c{COMMON}, \c{elf} extensions to \IR{common, elf extensions to} \c{COMMON}, ELF extensions to
\IR{common, obj extensions to} \c{COMMON}, \c{obj} extensions to \IR{common, obj extensions to} \c{COMMON}, \c{obj} extensions to
\IR{declaring structure} declaring structures \IR{declaring structure} declaring structures
\IR{default-wrt mechanism} default-\c{WRT} mechanism \IR{default-wrt mechanism} default-\c{WRT} mechanism
@@ -165,7 +164,8 @@ in \c{elf}
\IA{effective address}{effective addresses} \IA{effective address}{effective addresses}
\IA{effective-address}{effective addresses} \IA{effective-address}{effective addresses}
\IR{elf} ELF \IR{elf} ELF
\IR{elf, 16-bit code and} ELF, 16-bit code and \IR{elf, 16-bit code} ELF, 16-bit code
\IR{elf, debug formats} ELF, debug formats
\IR{elf shared libraries} ELF, shared libraries \IR{elf shared libraries} ELF, shared libraries
\IR{elf32} \c{elf32} \IR{elf32} \c{elf32}
\IR{elf64} \c{elf64} \IR{elf64} \c{elf64}
@@ -181,7 +181,7 @@ in \c{elf}
\IR{functions, pascal calling convention} functions, Pascal calling \IR{functions, pascal calling convention} functions, Pascal calling
convention convention
\IR{global, aoutb extensions to} \c{GLOBAL}, \c{aoutb} extensions to \IR{global, aoutb extensions to} \c{GLOBAL}, \c{aoutb} extensions to
\IR{global, elf extensions to} \c{GLOBAL}, \c{elf} extensions to \IR{global, elf extensions to} \c{GLOBAL}, ELF extensions to
\IR{global, rdf extensions to} \c{GLOBAL}, \c{rdf} extensions to \IR{global, rdf extensions to} \c{GLOBAL}, \c{rdf} extensions to
\IR{got} GOT \IR{got} GOT
\IR{got relocations} \c{GOT} relocations \IR{got relocations} \c{GOT} relocations
@@ -238,16 +238,16 @@ convention
Object File Format Object File Format
\IR{relocations, pic-specific} relocations, PIC-specific \IR{relocations, pic-specific} relocations, PIC-specific
\IA{repeating}{repeating code} \IA{repeating}{repeating code}
\IR{section alignment, in elf} section alignment, in \c{elf} \IR{section alignment, in elf} section alignment, in ELF
\IR{section alignment, in bin} section alignment, in \c{bin} \IR{section alignment, in bin} section alignment, in \c{bin}
\IR{section alignment, in obj} section alignment, in \c{obj} \IR{section alignment, in obj} section alignment, in \c{obj}
\IR{section alignment, in win32} section alignment, in \c{win32} \IR{section alignment, in win32} section alignment, in \c{win32}
\IR{section, elf extensions to} \c{SECTION}, \c{elf} extensions to \IR{section, elf extensions to} \c{SECTION}, ELF extensions to
\IR{section, macho extensions to} \c{SECTION}, \c{macho} 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{section, win32 extensions to} \c{SECTION}, \c{win32} extensions to
\IR{segment alignment, in bin} segment alignment, in \c{bin} \IR{segment alignment, in bin} segment alignment, in \c{bin}
\IR{segment alignment, in obj} segment alignment, in \c{obj} \IR{segment alignment, in obj} segment alignment, in \c{obj}
\IR{segment, obj extensions to} \c{SEGMENT}, \c{elf} extensions to \IR{segment, obj extensions to} \c{SEGMENT}, ELF extensions to
\IR{segment names, borland pascal} segment names, Borland Pascal \IR{segment names, borland pascal} segment names, Borland Pascal
\IR{shift command} \c{shift} command \IR{shift command} \c{shift} command
\IA{sib}{sib byte} \IA{sib}{sib byte}
@@ -259,6 +259,8 @@ Object File Format
\IR{symbols, exporting from dlls} symbols, exporting from DLLs \IR{symbols, exporting from dlls} symbols, exporting from DLLs
\IR{symbols, importing from dlls} symbols, importing from DLLs \IR{symbols, importing from dlls} symbols, importing from DLLs
\IR{test subdirectory} \c{test} subdirectory \IR{test subdirectory} \c{test} subdirectory
\IR{thread local storage in elf} thread local storage, in ELF
\IR{thread local storage in mach-o} thread local storage, in \c{macho}
\IR{tlink} \c{TLINK} \IR{tlink} \c{TLINK}
\IR{underscore, in c symbols} underscore, in C symbols \IR{underscore, in c symbols} underscore, in C symbols
\IR{unicode} Unicode \IR{unicode} Unicode
@@ -295,16 +297,16 @@ Object File Format
The Netwide Assembler, NASM, is an 80x86 and x86-64 assembler designed The Netwide Assembler, NASM, is an 80x86 and x86-64 assembler designed
for portability and modularity. It supports a range of object file for portability and modularity. It supports a range of object file
formats, including Linux and \c{*BSD} \c{a.out}, \c{ELF}, \c{COFF}, formats, including Linux and *BSD \c{a.out}, ELF, Mach-O, 16-bit and
\c{Mach-O}, 16-bit and 32-bit \c{OBJ} (OMF) format, \c{Win32} and 32-bit \c{.obj} (OMF) format, COFF (including its Win32 and Win64
\c{Win64}. It will also output plain binary files, Intel hex and variants.) It can also output plain binary files, Intel hex and
Motorola S-Record formats. Its syntax is designed to be simple and Motorola S-Record formats. Its syntax is designed to be simple and
easy to understand, similar to the syntax in the Intel Software easy to understand, similar to the syntax in the Intel Software
Developer Manual with minimal complexity. It supports all currently Developer Manual with minimal complexity. It supports all currently
known x86 architectural extensions, and has strong support for macros. known x86 architectural extensions, and has strong support for macros.
NASM also comes with a set of utilities for handling the \c{RDOFF} NASM also comes with a set of utilities for handling its own RDOFF2
custom object-file format. object-file format.
\S{legal} \i{License} Conditions \S{legal} \i{License} Conditions
@@ -352,7 +354,7 @@ For example,
\c nasm -f elf myfile.asm \c nasm -f elf myfile.asm
will assemble \c{myfile.asm} into an \c{ELF} object file \c{myfile.o}. And will assemble \c{myfile.asm} into an ELF object file \c{myfile.o}. And
\c nasm -f bin myfile.asm -o myfile.com \c nasm -f bin myfile.asm -o myfile.com
@@ -374,7 +376,7 @@ The option \c{-hf} will also list the available output file formats,
and what they are. and what they are.
If you use Linux but aren't sure whether your system is \c{a.out} If you use Linux but aren't sure whether your system is \c{a.out}
or \c{ELF}, type or ELF, type
\c file nasm \c file nasm
@@ -4298,7 +4300,7 @@ operating in 16-bit mode, 32-bit mode or 64-bit mode. The syntax is
\c{BITS XX}, where XX is 16, 32 or 64. \c{BITS XX}, where XX is 16, 32 or 64.
In most cases, you should not need to use \c{BITS} explicitly. The In most cases, you should not need to use \c{BITS} explicitly. The
\c{aout}, \c{coff}, \c{elf}, \c{macho}, \c{win32} and \c{win64} \c{aout}, \c{coff}, \c{elf*}, \c{macho}, \c{win32} and \c{win64}
object formats, which are designed for use in 32-bit or 64-bit object formats, which are designed for use in 32-bit or 64-bit
operating systems, all cause NASM to select 32-bit or 64-bit mode, operating systems, all cause NASM to select 32-bit or 64-bit mode,
respectively, by default. The \c{obj} object format allows you respectively, by default. The \c{obj} object format allows you
@@ -4575,9 +4577,8 @@ refer to symbols which \e{are} defined in the same module as the
\c ; some code \c ; some code
\c{GLOBAL}, like \c{EXTERN}, allows object formats to define private \c{GLOBAL}, like \c{EXTERN}, allows object formats to define private
extensions by means of a colon. The \c{elf} object format, for extensions by means of a colon. The ELF object format, for example,
example, lets you specify whether global data items are functions or lets you specify whether global data items are functions or data:
data:
\c global hashlookup:function, hashtable:data \c global hashlookup:function, hashtable:data
@@ -4608,8 +4609,8 @@ at the same piece of memory.
Like \c{GLOBAL} and \c{EXTERN}, \c{COMMON} supports object-format Like \c{GLOBAL} and \c{EXTERN}, \c{COMMON} supports object-format
specific extensions. For example, the \c{obj} format allows common specific extensions. For example, the \c{obj} format allows common
variables to be NEAR or FAR, and the \c{elf} format allows you to variables to be NEAR or FAR, and the ELF format allows you to specify
specify the alignment requirements of a common variable: the alignment requirements of a common variable:
\c common commvar 4:near ; works in OBJ \c common commvar 4:near ; works in OBJ
\c common intarray 100:4 ; works in ELF: 4 byte aligned \c common intarray 100:4 ; works in ELF: 4 byte aligned
@@ -4681,7 +4682,7 @@ For example, when mangling local symbols via the generic namespace:
This is useful when the directive is needed to be output format This is useful when the directive is needed to be output format
agnostic. agnostic.
The example is also euquivalent to this, when the output format is \c{elf}: The example is also euquivalent to this, when the output format is ELF:
\c %pragma elf gprefix _ \c %pragma elf gprefix _
@@ -5833,8 +5834,8 @@ Format} Object Files
The \c{elf32}, \c{elf64} and \c{elfx32} output formats generate The \c{elf32}, \c{elf64} and \c{elfx32} output formats generate
\c{ELF32 and ELF64} (Executable and Linkable Format) object files, as \c{ELF32 and ELF64} (Executable and Linkable Format) object files, as
used by Linux as well as \i{Unix System V}, including \i{Solaris x86}, used by Linux as well as \i{Unix System V}, including \i{Solaris x86},
\i{UnixWare} and \i{SCO Unix}. \c{elf} provides a default output \i{UnixWare} and \i{SCO Unix}. ELF provides a default output
file-name extension of \c{.o}. \c{elf} is a synonym for \c{elf32}. file-name extension of \c{.o}. \c{elf} is a synonym for \c{elf32}.
The \c{elfx32} format is used for the \i{x32} ABI, which is a 32-bit The \c{elfx32} format is used for the \i{x32} ABI, which is a 32-bit
ABI with the CPU in 64-bit mode. ABI with the CPU in 64-bit mode.
@@ -5847,8 +5848,8 @@ target operating system (OSABI). This field can be set by using the
system. If this directive is not used, the default value will be "UNIX 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. System V ABI" (0) which will work on most systems which support ELF.
\S{elfsect} \c{elf} extensions to the \c{SECTION} Directive \S{elfsect} ELF extensions to the \c{SECTION} Directive
\I{SECTION, elf extensions to} \I{SECTION, ELF extensions to}
Like the \c{obj} format, \c{elf} allows you to specify additional Like the \c{obj} format, \c{elf} allows you to specify additional
information on the \c{SECTION} directive line, to control the type information on the \c{SECTION} directive line, to control the type
@@ -5873,13 +5874,52 @@ not.
\b \i\c{progbits} defines the section to be one with explicit contents \b \i\c{progbits} defines the section to be one with explicit contents
stored in the object file: an ordinary code or data section, for stored in the object file: an ordinary code or data section, for
example, \i\c{nobits} defines the section to be one with no explicit example.
\b \i\c{nobits} defines the section to be one with no explicit
contents given, such as a BSS section. contents given, such as a BSS section.
\b \c{align=}, used with a trailing number as in \c{obj}, gives the \b \i\c{note} indicates that this section contains ELF notes. The
content of ELF notes are specified using normal assembly instructions;
it is up to the programmer to ensure these are valid ELF notes.
\b \i\c{preinit_array} indicates that this section contains function
addresses to be called before any other initialization has happened.
\b \i\c{init_array} indicates that this section contains function
addresses to be called during initialization.
\b \i\c{fini_array} indicates that this section contains function
pointers to be called during termination.
\b \I{align, ELF attribute}\c{align=}, used with a trailing number as in \c{obj}, gives the
\I{section alignment, in elf}\I{alignment, in elf sections}alignment \I{section alignment, in elf}\I{alignment, in elf sections}alignment
requirements of the section. requirements of the section.
\b \c{byte}, \c{word}, \c{dword}, \c{qword}, \c{tword}, \c{oword},
\c{yword}, or \c{zword} with an optional \c{*}\i{multiplier} specify
the fundamental data item size for a section which contains either
fixed-sized data structures or strings; it also sets a default
alignment. This is generally used with the \c{strings} and \c{merge}
attributes (see below.) For example \c{byte*4} defines a unit size of
4 bytes, with a default alignment of 1; \c{dword} also defines a unit
size of 4 bytes, but with a default alignment of 4. The \c{align=}
attribute, if specified, overrides this default alignment.
\b \I{pointer, ELF attribute}\c{pointer} is equivalent to \c{dword}
for \c{elf32} or \c{elfx32}, and \c{qword} for \c{elf64}.
\b \I{strings, ELF attribute}\c{strings} indicate that this section
contains exclusively null-terminated strings. By default these are
assumed to be byte strings, but a size specifier can be used to
override that.
\b \i\c{merge} indicates that duplicate data elements in this section
should be merged with data elements from other object files. Data
elements can be either fixed-sized objects or null-terminatedstrings
(with the \c{strings} attribute.) A size specifier is required unless
\c{strings} is specified, in which case the size defaults to \c{byte}.
\b \i\c{tls} defines the section to be one which contains \b \i\c{tls} defines the section to be one which contains
thread local variables. thread local variables.
@@ -5889,24 +5929,28 @@ qualifiers are:
\I\c{.text} \I\c{.rodata} \I\c{.lrodata} \I\c{.data} \I\c{.ldata} \I\c{.text} \I\c{.rodata} \I\c{.lrodata} \I\c{.data} \I\c{.ldata}
\I\c{.bss} \I\c{.lbss} \I\c{.tdata} \I\c{.tbss} \I\c\{.comment} \I\c{.bss} \I\c{.lbss} \I\c{.tdata} \I\c{.tbss} \I\c\{.comment}
\c section .text progbits alloc exec nowrite align=16 \c section .text progbits alloc exec nowrite align=16
\c section .rodata progbits alloc noexec nowrite align=4 \c section .rodata progbits alloc noexec nowrite align=4
\c section .lrodata progbits alloc noexec nowrite align=4 \c section .lrodata progbits alloc noexec nowrite align=4
\c section .data progbits alloc noexec write align=4 \c section .data progbits alloc noexec write align=4
\c section .ldata progbits alloc noexec write align=4 \c section .ldata progbits alloc noexec write align=4
\c section .bss nobits alloc noexec write align=4 \c section .bss nobits alloc noexec write align=4
\c section .lbss nobits alloc noexec write align=4 \c section .lbss nobits alloc noexec write align=4
\c section .tdata progbits alloc noexec write align=4 tls \c section .tdata progbits alloc noexec write align=4 tls
\c section .tbss nobits alloc noexec write align=4 tls \c section .tbss nobits alloc noexec write align=4 tls
\c section .comment progbits noalloc noexec nowrite align=1 \c section .comment progbits noalloc noexec nowrite align=1
\c section other progbits alloc noexec nowrite align=1 \c section .preinit_array preinit_array alloc noexec nowrite pointer
\c section .init_array init_array alloc noexec nowrite pointer
\c section .fini_array fini_array alloc noexec nowrite pointer
\c section .note note noalloc noexec nowrite align=4
\c section other progbits alloc noexec nowrite align=1
(Any section name other than those in the above table (Any section name other than those in the above table
is treated by default like \c{other} in the above table. is treated by default like \c{other} in the above table.
Please note that section names are case sensitive.) Please note that section names are case sensitive.)
\S{elfwrt} \i{Position-Independent Code}\I{PIC}: \c{macho} Special \S{elfwrt} \i{Position-Independent Code}\I{PIC}: ELF Special
Symbols and \i\c{WRT} Symbols and \i\c{WRT}
Since \c{ELF} does not support segment-base references, the \c{WRT} Since \c{ELF} does not support segment-base references, the \c{WRT}
@@ -6044,7 +6088,7 @@ requires that it be aligned on a 4-byte boundary.
\S{elf16} 16-bit code and ELF \S{elf16} 16-bit code and ELF
\I{ELF, 16-bit code and} \I{ELF, 16-bit code}
The \c{ELF32} specification doesn't provide relocations for 8- and The \c{ELF32} specification doesn't provide relocations for 8- and
16-bit values, but the GNU \c{ld} linker adds these as an extension. 16-bit values, but the GNU \c{ld} linker adds these as an extension.
@@ -6054,7 +6098,7 @@ be linked as ELF using GNU \c{ld}. If NASM is used with the
these relocations is generated. these relocations is generated.
\S{elfdbg} Debug formats and ELF \S{elfdbg} Debug formats and ELF
\I{ELF, Debug formats and} \I{ELF, debug formats}
ELF provides debug information in \c{STABS} and \c{DWARF} formats. ELF provides debug information in \c{STABS} and \c{DWARF} formats.
Line number information is generated for all executable sections, but please Line number information is generated for all executable sections, but please
@@ -8142,7 +8186,7 @@ then the correct first instruction in the code section will not be
seen because the starting point skipped over it. This isn't really seen because the starting point skipped over it. This isn't really
ideal. ideal.
To avoid this, you can specify a `\i\c{synchronisation}' point, or indeed To avoid this, you can specify a `\i{synchronisation}' point, or indeed
as many synchronisation points as you like (although NDISASM can as many synchronisation points as you like (although NDISASM can
only handle 2147483647 sync points internally). The definition of a sync only handle 2147483647 sync points internally). The definition of a sync
point is this: NDISASM guarantees to hit sync points exactly during point is this: NDISASM guarantees to hit sync points exactly during

View File

@@ -49,12 +49,6 @@ STD: nasm
; here, not all of them are: the user-level form of a format-specific ; here, not all of them are: the user-level form of a format-specific
; directive should be defined in the module for that directive. ; directive should be defined in the module for that directive.
; These three need to be defined, though the actual definitions will
; be constantly updated during preprocessing.
%define __FILE__
%define __LINE__
%define __BITS__
%define __SECT__ ; it ought to be defined, even if as nothing %define __SECT__ ; it ought to be defined, even if as nothing
%imacro section 1+.nolist %imacro section 1+.nolist

View File

@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- * /* ----------------------------------------------------------------------- *
* *
* Copyright 1996-2017 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 * See the file AUTHORS included with the NASM distribution for
* the specific copyright holders. * the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following * copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided * disclaimer in the documentation and/or other materials provided
* with the distribution. * with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -262,9 +262,12 @@ void saa_fread(struct SAA *s, size_t posn, void *data, size_t len)
void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len) void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
{ {
size_t ix; size_t ix;
size_t padding = 0;
/* Seek beyond the end of the existing array not supported */ if (posn > s->datalen) {
nasm_assert(posn <= s->datalen); padding = posn - s->datalen;
posn = s->datalen;
}
if (likely(s->blk_len == SAA_BLKLEN)) { if (likely(s->blk_len == SAA_BLKLEN)) {
ix = posn >> SAA_BLKSHIFT; ix = posn >> SAA_BLKSHIFT;
@@ -281,6 +284,9 @@ void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len)
s->wblk--; s->wblk--;
} }
if (padding)
saa_wbytes(s, NULL, padding);
saa_wbytes(s, data, len); saa_wbytes(s, data, len);
} }

View File

@@ -148,23 +148,27 @@
#define PF_R 0x4 #define PF_R 0x4
/* Section header types */ /* Section header types */
#define SHT_NULL 0 #define SHT_NULL 0
#define SHT_PROGBITS 1 #define SHT_PROGBITS 1
#define SHT_SYMTAB 2 #define SHT_SYMTAB 2
#define SHT_STRTAB 3 #define SHT_STRTAB 3
#define SHT_RELA 4 #define SHT_RELA 4
#define SHT_HASH 5 #define SHT_HASH 5
#define SHT_DYNAMIC 6 #define SHT_DYNAMIC 6
#define SHT_NOTE 7 #define SHT_NOTE 7
#define SHT_NOBITS 8 #define SHT_NOBITS 8
#define SHT_REL 9 #define SHT_REL 9
#define SHT_SHLIB 10 #define SHT_SHLIB 10
#define SHT_DYNSYM 11 #define SHT_DYNSYM 11
#define SHT_NUM 12 #define SHT_INIT_ARRAY 14
#define SHT_LOPROC 0x70000000 #define SHT_FINI_ARRAY 15
#define SHT_HIPROC 0x7fffffff #define SHT_PREINIT_ARRAY 16
#define SHT_LOUSER 0x80000000 #define SHT_GROUP 17
#define SHT_HIUSER 0xffffffff #define SHT_SYMTAB_SHNDX 18
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff
/* Section header flags */ /* Section header flags */
#define SHF_WRITE (1 << 0) /* Writable */ #define SHF_WRITE (1 << 0) /* Writable */
@@ -179,13 +183,24 @@
#define SHF_TLS (1 << 10) /* Section hold thread-local data */ #define SHF_TLS (1 << 10) /* Section hold thread-local data */
/* Special section numbers */ /* Special section numbers */
#define SHN_UNDEF 0 #define SHN_UNDEF 0x0000
#define SHN_LORESERVE 0xff00 #define SHN_LORESERVE 0xff00
#define SHN_LOPROC 0xff00 #define SHN_LOPROC 0xff00
#define SHN_HIPROC 0xff1f #define SHN_HIPROC 0xff1f
#define SHN_ABS 0xfff1 #define SHN_ABS 0xfff1
#define SHN_COMMON 0xfff2 #define SHN_COMMON 0xfff2
#define SHN_HIRESERVE 0xffff #define SHN_XINDEX 0xffff
#define SHN_HIRESERVE 0xffff
/* Same, but signed/sign-extended */
#define XSHN_UNDEF ((int16_t)SHN_UNDEF)
#define XSHN_LORESERVE ((int16_t)SHN_LORESERVE)
#define XSHN_LOPROC ((int16_t)SHN_LOPROC)
#define XSHN_HIPROC ((int16_t)SHN_HIPROC)
#define XSHN_ABS ((int16_t)SHN_ABS)
#define XSHN_COMMON ((int16_t)SHN_COMMON)
#define XSHN_XINDEX ((int16_t)SHN_XINDEX)
#define XSHN_HIRESERVE ((int16_t)SHN_HIRESERVE)
/* Section align flag */ /* Section align flag */
#define SHA_ANY 1 /* No alignment constraint */ #define SHA_ANY 1 /* No alignment constraint */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- * /* ----------------------------------------------------------------------- *
* *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved * Copyright 1996-2019 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for * See the file AUTHORS included with the NASM distribution for
* the specific copyright holders. * the specific copyright holders.
* *
@@ -53,31 +53,14 @@
/* this stuff is needed for the dwarf/stabs debugging format */ /* this stuff is needed for the dwarf/stabs debugging format */
#define TY_DEBUGSYMLIN 0x40 /* internal call to debug_out */ #define TY_DEBUGSYMLIN 0x40 /* internal call to debug_out */
/* Known sections with nonstandard defaults */
struct elf_known_section {
const char *name; /* Name of section */
int type; /* Section type (SHT_) */
uint32_t flags; /* Section flags (SHF_) */
uint32_t align; /* Section alignment */
};
extern const struct elf_known_section elf_known_sections[];
/* /*
* Special ELF sections (after the real sections but before debugging ones) * Debugging ELF sections (section indicies starting with sec_debug)
*/
#define sec_shstrtab (nsects + 1)
#define sec_symtab (nsects + 2)
#define sec_strtab (nsects + 3)
#define sec_numspecial 3
/*
* Debugging ELF sections (last in the file)
*/ */
/* stabs */ /* stabs */
#define sec_stab (nsections-3) #define sec_stab (sec_debug + 0)
#define sec_stabstr (nsections-2) #define sec_stabstr (sec_debug + 1)
#define sec_rel_stab (nsections-1) #define sec_rel_stab (sec_debug + 2)
/* stabs symbol table format */ /* stabs symbol table format */
struct stabentry { struct stabentry {
@@ -89,16 +72,16 @@ struct stabentry {
}; };
/* dwarf */ /* dwarf */
#define sec_debug_aranges (nsections-10) #define sec_debug_aranges (sec_debug + 0)
#define sec_rela_debug_aranges (nsections-9) #define sec_rela_debug_aranges (sec_debug + 1)
#define sec_debug_pubnames (nsections-8) #define sec_debug_pubnames (sec_debug + 2)
#define sec_debug_info (nsections-7) #define sec_debug_info (sec_debug + 3)
#define sec_rela_debug_info (nsections-6) #define sec_rela_debug_info (sec_debug + 4)
#define sec_debug_abbrev (nsections-5) #define sec_debug_abbrev (sec_debug + 5)
#define sec_debug_line (nsections-4) #define sec_debug_line (sec_debug + 6)
#define sec_rela_debug_line (nsections-3) #define sec_rela_debug_line (sec_debug + 7)
#define sec_debug_frame (nsections-2) #define sec_debug_frame (sec_debug + 8)
#define sec_debug_loc (nsections-1) #define sec_debug_loc (sec_debug + 9)
extern uint8_t elf_osabi; extern uint8_t elf_osabi;
extern uint8_t elf_abiver; extern uint8_t elf_abiver;
@@ -137,14 +120,15 @@ struct elf_section {
uint64_t len; uint64_t len;
uint64_t size; uint64_t size;
uint64_t nrelocs; uint64_t nrelocs;
int32_t index; int32_t index; /* NASM index or NO_SEG if internal */
int type; /* SHT_PROGBITS or SHT_NOBITS */ int shndx; /* ELF index */
int type; /* SHT_* */
uint64_t align; /* alignment: power of two */ uint64_t align; /* alignment: power of two */
uint64_t flags; /* section flags */ uint64_t flags; /* section flags */
int64_t pass_last_seen; int64_t pass_last_seen;
uint64_t entsize; /* entry size */
char *name; char *name;
struct SAA *rel; struct SAA *rel;
uint64_t rellen;
struct elf_reloc *head; struct elf_reloc *head;
struct elf_reloc **tail; struct elf_reloc **tail;
struct rbtree *gsyms; /* global symbols in section */ struct rbtree *gsyms; /* global symbols in section */

4
test/evalmacro.asm Normal file
View File

@@ -0,0 +1,4 @@
%define tonum(=x) x
dd tonum(1+3)
dd tonum(5*7)

2
test/fewsecs.asm Normal file
View File

@@ -0,0 +1,2 @@
%assign NSECS 64
%include "manysecs.asm"

15
test/manysecs.asm Normal file
View File

@@ -0,0 +1,15 @@
%ifndef NSECS
%assign NSECS 16384
%endif
%assign NSECS ((NSECS+3) & ~3)
%assign n 0
%rep NSECS
%assign gcom (n & ~3) + 2
section .text %+ n progbits exec
start_ %+ n:
nop
jmp start_ %+ gcom
%assign n n+1
%endrep

3
test/moresecs.asm Normal file
View File

@@ -0,0 +1,3 @@
; Less than 65,279 data sections, but more total sections
%assign NSECS 37600
%include "manysecs.asm"

3
test/mostsecs.asm Normal file
View File

@@ -0,0 +1,3 @@
; More than 65,279 data sections
%assign NSECS 131072
%include "manysecs.asm"