Commit graph

664 commits

Author SHA1 Message Date
Johann
47918f6920 remove unused coff_alignment()
Usage was removed in b6ba0a23f9
Fixes:
output/outcoff.c:302:28: warning: unused function 'coff_alignment' [-Wunused-function]
static inline unsigned int coff_alignment(uint32_t flags)
                           ^
2022-03-12 22:49:33 +09:00
Igor Glucksmann
27e17c913c output/coff: Possibility to define the associated comdat sections in any order
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:39 +03:00
Igor Glucksmann
ed2c609976 output/coff: Support for COMDAT sections
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:25 +03:00
Cyrill Gorcunov
39bb9d71a3 output/outelf: drop unused structure
The erel structure left from times when we've
been merging separate elf32/32x/64 files.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-09 00:59:38 +03:00
Marco Vanotti
f2a6eb4aac Add DW_AT_comp_dir to elf files.
This commit adds the compilation directory debug information for ELF files.
This feature helps debuggers locate the source file when debugging.
The feature is already present for Mach-O files.

Signed-off-by: Marco Vanotti <mvanotti@dc.uba.ar>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-08 23:59:09 +03:00
Cyrill Gorcunov
8c735c58d1 BR3392739: output/outbin: fix nil dereference for self following sections
In case if section follows itself we should yield
an error, otherwise we hit nil dereference because
there won't be any group of sections.

After all "follow" attribute is rather to group
sections other than self.



Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-02-21 01:05:28 +03:00
Cyrill Gorcunov
93c774d482 BR3392637: output/outieee: Fix nil dereference
The handling been broken in commit 98578071.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-11-04 13:08:06 +03:00
Cyrill Gorcunov
19ab41466b outmacho: macho_dbg_linenum -- fix memory leak
In 78f14ab1a6 the fix
is incomplete, we should move free procedure out of
the list_for_each traverse.

CID 1432930

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-05 00:20:05 +03:00
Cyrill Gorcunov
78f14ab1a6 outmacho.c: macho_dbg_linenum - fix memory leak
If new list is not needed then we should free memory
allocated by nasm_basename and nasm_dirname calls.

CID 1432930

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-04 23:45:04 +03:00
H. Peter Anvin (Intel)
cc64861a61 Merge tag 'nasm-2.15.05'
NASM 2.15.05

Resolved Conflicts:
	asm/preproc.c
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-31 12:23:36 -07:00
H. Peter Anvin (Intel)
bf79786e89 Add option to create reproducible output
We need the ability to produce consistent output for our own tests,
anyway, so make this a user-accessible feature. This was requested in
BR 3392635.

This obsoletes the NASM_TEST_RUN environment variable; simply use the
normal NASMENV environment variable instead.

The .obj tests in travis needed to be updated in order to remove the
rather pointless suffix " CONST" from the NASM signatures.

Reported-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-27 13:06:08 -07:00
H. Peter Anvin (Intel)
cc843efa38 Merge tag 'nasm-2.15.04'
NASM 2.15.04

Conflicts:
	asm/listing.h
	asm/pptok.pl
	asm/preproc.c
	version

This doesn't pass travis test 3392711, which is using an extremely odd
construct of %?? in the middle of an argument sequence for an smacro
while not being in a macro itself, and expecting it to expand to the
macro name. This seems to *really* confuse the master branch.

Resolve this later...
2020-08-25 16:16:09 -07:00
H. Peter Anvin (Intel)
1227a5d7fb Merge remote-tracking branch 'github/master'
Resolved Conflicts:
	asm/preproc.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-25 15:56:05 -07:00
H. Peter Anvin (Intel)
16ab7aed21 debug: feed single-line macro definitions and include hierachy to dfmt
At least DWARF can encode C-style macros. In doing so, it wants the
file include hierarchy, so give the debug format backend the option of
receiving that information from the preprocessor.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-25 15:52:05 -07:00
H. Peter Anvin (Intel)
abcbe0ea38 outdbg: add macro to emulate .bin format ORG directive
Just stub out "org" as a macro to be able to read source files that
are designed for the .bin format.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-25 15:50:11 -07:00
Cyrill Gorcunov
523b96dd6f output/outcoff.c: zap timestamp when running tests
When we're running tests we must not fail due to
time stamp difference in a header. Lets zap it if
test run is detected.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-08-25 19:18:50 +03:00
H. Peter Anvin
6236b39e06 outobj: change cutting -> truncating
I believe "truncating" is the more common terminology in this case, so
change to it for aestetic reasons only.

Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-18 12:34:33 -07:00
H. Peter Anvin
4a2c8c52c7 outobj: limit excessive length warning to 64 characters
The case where we warn for excessive length should presumably have
been %.nnns which means limit length to nnn characters, rather than
%nnns which means left-pad with spaces to nnn bytes if possible. Also
change the limit from 128 to 64, to make it more likely to not line
break.

Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-18 12:33:51 -07:00
Cyrill Gorcunov
f14552e5fb BR3392646: output/outobj.c: fix memory corruption in long object names
When we encode a name we put its length before it, the
storage is one byte width so the name can't be more
than UINT8_MAX (ie 255) bytes length.

Moreover if one provide a name more than RECORD_MAX then
we simply overwrite random memory.

Thus lets do as in other obj_check calls -- shrink the
size we gonna use. But unlike oter code lets yield a
warning as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-08-18 20:27:14 +03:00
H. Peter Anvin (Intel)
6dc8379d6a rdoff: disable broken backend, document deprecation
The RDOFF backend has been broken since at least NASM 2.14, throwing
an immediate assert. Since only one person appears to have even
noticed, and fixing it properly looks like it would take quite a bit
of work, disable this back end and document its deprecation.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-17 15:26:11 -07:00
H. Peter Anvin (Intel)
c9467688b4 Add [v]printf_func() attributes where appropriate
Add a new macro vprintf_func() for vprintf-style functions, and add
printf_func() and vprintf_func() attribute arguments whereever
meaningful.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-30 17:30:20 -07:00
H. Peter Anvin (Intel)
78df8828a0 output/codeview.c: use list_for_each_safe() to free a list
Using list_for_each() is by definition not safe when freeing the
members of the list, use list_for_each_free() instead.

Also, use nasm_new() and nasm_free() where appropriate.

This was discovered as a downstream bug from BR 3392707.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-30 17:06:24 -07:00
H. Peter Anvin (Intel)
b6ba0a23f9 BR 3392701: outcoff: remove weird padding code
It seems that the odd alignment-padding code was simply dead in older
versions of NASM. This means that the COFF backend behavior really was
the same as the other backends. Remove that stale code and revert to
previous/common behavior.

Reported-by: ig <glucksmann@avast.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-27 12:28:09 -07:00
H. Peter Anvin
d6b8c53b8c Merge tag 'nasm-2.15.03'
NASM 2.15.03

Resolved Conflicts:
	asm/preproc.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-17 17:58:38 -07:00
H. Peter Anvin (Intel)
64c7c763c2 Change dfmt->debug_macros to dfmt->debug_mmacros
... in preparation for adding dfmt->debug_smacros.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-14 12:05:03 -07:00
H. Peter Anvin (Intel)
baaa5ca441 outcoff: don't drop align= option alone on a section line
If the section/segment directive *only* contained an align= directive,
it would get lost. Fix that.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 18:14:09 -07:00
H. Peter Anvin (Intel)
72a555972f error: get rid of ERR_PASS1
ERR_PASS1 only remains in three places:

a. Unterminated %! string, an error
   - Should be signalled no matter which pass it is encountered in
b. Two cases of map file problems in outbin
   - The buffered warning system take care of that issue

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 01:10:30 -07:00
H. Peter Anvin (Intel)
c36cdf8a55 Merge remote-tracking branch 'github/debug-macros'
Resolved Conflicts:
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 21:16:49 -07:00
H. Peter Anvin (Intel)
79fd2b9645 data: replace data->sign with a flags field
Signed and unsigned are really two flags; might as well allow this
field to contain additional flags.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 20:58:10 -07:00
H. Peter Anvin (Intel)
50184c26c7 debug: collect macro information for the debug backend
Collect macro call/nesting information for the benefit of the debug
back end. So far, the only backend for which this is provided is the
debug back end, to show what information is present.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-08 09:28:44 -07:00
H. Peter Anvin (Intel)
cd87431424 BR 3392692: outcoff: allow user to reduce the default alignment
NASM would incorrectly only allow for the alignment to be increased,
even when overridden by the user. Allow the user to specify any
alignment value and have it override the partition type default.

The user can increade their own alignment value specification later,
of course, and the sectalign directive will present a floor for either
kind of specification.

Reported-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-06 21:46:43 -07:00
Cyrill Gorcunov
d390490089 outlib: Make ol_add_sym_to being static
Otherwise getting building problem

 > output/outlib.c:197:6: error: no previous prototype for ‘ol_add_sym_to’ [-Werror=missing-prototypes]
 >   197 | void ol_add_sym_to(struct ol_symlist *syml, struct ol_symhead *head,
 >       |      ^~~~~~~~~~~~~

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-07-03 11:01:40 +03:00
H. Peter Anvin (Intel)
1b50fec496 outlib: fix infinite recursion due to incorrect wrapping
recursion: see recursion.

A wrapper function needs to call the function being wrapped, not
itself.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-02 20:48:43 -07:00
H. Peter Anvin (Intel)
2770fc7ac6 outlib: add infrastructure for common section and symbol handling
Pretty much all the backends have to do the same gymnastics to handle
symbols and sections. In the future, this should be done by the
assembly core, but in order to prepare the ground and get the
performance benefits as soon as possible, implement a library of
functions which can manage symbols and sections and their respective
hashes, trees, and tables.

This infrastructure is not yet used by any backend, that porting work
has to come next.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-27 22:11:27 -07:00
H. Peter Anvin (Intel)
29a61b7987 DWARF: consistent version information; drop .debug_loc section
Fix the version information for various sections and generalize their
implementation. Drop issuing an empty .debug_pubnames section; like
other sections DWARF parsers seem to be unhappy about a section with
null content.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-26 16:14:55 -07:00
H. Peter Anvin (Intel)
eb571a3ac3 dwarf: don't emit a dummy .debug_loc section
It seems DWARF parsers get really snippy about a section which only
contains an end token. Instead, leave unused sections empty. Already
did that with .debug_frame, do it with .debug_loc too.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-26 15:22:26 -07:00
H. Peter Anvin (Intel)
241697306c BR 3392650: Codeview truncates symbol table length to 16 bits
If the source code is large, it is very reasonable for the symbol
table length to exceed 2^16 bits. Use uint32_t to keep track of
lengths, even where not necessary... there is no real reason to use
uint16_t anywhere.

Reported-by: <michael@mehlich.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-26 14:10:54 -07:00
H. Peter Anvin (Intel)
45978bb8bc BR 3392651: fix the .debug$T section in Codeview output format
The cv8 output format would generate an invalid .debug$T section,
containing repeated invalid records, none of which are actually used
(which is probably the only reason it actually worked.)

Just in case, generate a *single* type record for void func(void);

Furthermore, the argument list record should come before the procedure
type record (forward references are at least normatively prohibited.)

Reported-by: Alexandre Ganea <alexandre.ganea@ubisoft.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-25 13:57:44 -07:00
H. Peter Anvin (Intel)
a6ea1152bc BR 3392657: dwarf: leave .debug_frame empty
Until such time that we have a CFI code generator, leave .debug_frame
empty.

Reported-by: Philip Craig <philipjcraig@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-14 23:16:50 -07:00
H. Peter Anvin
a3cbaafd52 outobj: fix harmless but still incorrect use of uninitialized variable
Fix use of uninitialized variable. This most likely is just an
issue while running at debug level >= 3, but it's still wrong.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-01 16:11:47 -07:00
Chang S. Bae
74b2731f2c outelf: Fix the section index for the debug output
The section information delivered to the debug output has an index of the
section table. The index should be different from the total number of
sections at the moment, the returned value from add_sectname(). So, fix the
value.

Fixes: b2004511dd ("ELF: handle more than 32,633 sections")

Reported-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392654
Reported-by: <mae.bdf@outlook.com>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392661
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-22 00:05:56 +00:00
H. Peter Anvin
fb2a2d6697 outcoff: add semi-generic pragma namespaces
Recognize the semi-generic pragma namespaces "coff" and "win" for
the win32 and win64 backends.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-30 13:30:15 -07:00
H. Peter Anvin
82c5cb1704 outelf: use "symbols" not "variables" in error messages
Many symbols are variables, but others are labels, etc. Use the common
term "symbol".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-12 17:48:16 -07:00
H. Peter Anvin
e47f4b7ad5 elf: fix "object" symbol keyword
The "object" symbol keyword would incorrectly generate STT_NOTYPE
instead of STT_OBJECT. Add test for weak object references; they are
different from plain weak references in that they are guaranteed to
resolve to zero if the symbol is not found.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 17:45:11 -07:00
H. Peter Anvin
7ad25b2e18 Change LBL_NONE to LBL_none
NASM convention is to use all-upper-case for "real" information, and
mixed-case (upper case common prefix, lower case description) for
meta-information. This is a highly useful distinction.

Thus "LBL_NONE" implies an actual label of type "NONE", as opposed to
no label at all.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 20:26:23 -04:00
H. Peter Anvin
90b1ccff86 Drop unnecessary EXTERN symbols
Currently, NASM always issues as an unknown symbol any symbol declared
EXTERN. This is highly undesirable when using common header files,
as it might cause the linker to pull in a bunch of unnecessary
modules, depending on how smart the linker is.

Add a new REQUIRED directive which behaves like the old EXTERN, for
the use cases which might still need this behavior.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 20:21:03 -04:00
H. Peter Anvin
495fda6341 elf: support weak global and extern references
A global or extern definition can now contain the keyword "weak" (or
"strong", although that is the default) to create a weak symbol or a
weak external reference, respectively.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 14:27:50 -04:00
H. Peter Anvin
d235408c65 preproc: standard macros now C-safe, %aliases off, fix %? recursion
Enough users expect the namespace starting with underscore to be safe
for symbols. Change our private namespace from __foo__ to
__?foo?__. Use %defalias to provide backwards compatiblity (by using
%defalias instead of %define, we handle the case properly where the
user changes the value.)

Add a preprocessor directive:

%aliases off

... to disable all smacro aliases and thereby making the namespace
clean.

Finally, fix infinite recursion when seeing %? or %?? due to
paste_tokens(). If we don't paste anything, the expansion is done.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-27 16:42:41 -07:00
H. Peter Anvin
14b16442ce outelf: change debug format default to dwarf
DWARF is by far the predominant format on ELF platforms these
days. Catch up with the times.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:30:29 -07:00
H. Peter Anvin
9084beb1bb Clean up backend format names
The backend format names were rather redundant and not always
helpful. Do some cleanup.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:28:17 -07:00