Commit graph

681 commits

Author SHA1 Message Date
H. Peter Anvin
21c977e717 output/legacy: when converting OUT_SEGMENT, clear the offset
Legacy backends like obj/omf may depend on the offset being zero if
not in use.

Reported-by: Bernd Boeckmann <bernd-freedos@boeckmann.io>
Reported-by: Vladimir Chebotarev <vladimir.chebotarev@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-10-16 17:19:45 -07:00
H. Peter Anvin
cab5b75145 output: when converting OUT_SEGMENT to legacy, don't lose the addend
When converting an OUT_SEGMENT relocation to legacy, the addend is
still significant, as it would represent an explicit addend to the
segment number.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392783
Reported-by: David Fifield <david@bamsoftware.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-12-07 10:51:33 -08:00
H. Peter Anvin
c8af731120 outieee: fix segfault on empty input
Fix the IEEE backend crashing if the input file is empty.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-12-07 10:24:14 -08:00
H. Peter Anvin
93548c2de2 rdoff: kill it off
RDOFF has been deprecated as it has unfixable problems, and has been
announced that it will be killed off in NASM 2.16.

This deletes it once and for all.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 16:49:13 -08:00
H. Peter Anvin
ed70640526 Merge remote-tracking branch 'johannkoenig/master' 2022-11-07 12:54:22 -08:00
H. Peter Anvin
b18e870d90 Merge remote-tracking branch 'ElyesH/typos' 2022-11-07 12:39:44 -08:00
H. Peter Anvin
3516258783 Merge remote-tracking branch 'ElyesH/comments' 2022-11-07 12:39:34 -08:00
H. Peter Anvin
665a9820f5 Merge remote-tracking branch 'vszakats/outcoff-file-repro' 2022-11-07 12:35:34 -08:00
H. Peter Anvin
0582a32300 Merge remote-tracking branch 'rygorous/master' 2022-11-07 12:31:54 -08:00
H. Peter Anvin
13e338af8b Merge remote-tracking branch 'iglosiggio/fix-DW_AT_high_pc-relocation' 2022-11-07 12:23:36 -08:00
H. Peter Anvin
7351302477 output/elf: remove efmt->rela_size
There are no use cases for of RELA on i386, and the intent has always been
that efmt->rel_size would be the size of the desired relocation
section type. Rename it from rel_size to relsize to make it more
obvious that it matches efmt->reltype rather than SHT_REL, and delete
efmt->rela_size to keep it from being misused again.

This should avoid a repeat of:

    https://bugzilla.nasm.us/show_bug.cgi?id=3392807

fixed in adf7507e29.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 09:54:33 -08:00
Ignacio Losiggio
eb5d3b7c6a
output/outelf: Fix relocation for DW_AT_high_pc
The information for DW_AT_high_pc was not correctly generated. Instead
of having a relocation whose value was `.text + highaddr` we wrote
`highaddr` to the output file location and added a relocation for
`.text + 0`.

This change writes `0` to the file and creates the correct relocation.
The previous behaviour wasn't noticed before because GNU ld had the
opposite issue: it added the target contents with the symbol value and
the entry addend. These two bugs coexisted in peace until GNU ld fixed
their broken interpretation of the spec on
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=17c6c3b99156fe82c1e637e1a5fd9f163ac788c8

This will fix broken debug information for binaries generated with lld
and newer ld versions.

`elf32` relocations are left untouched because the current behaviour
(emitting RELA relocations) is broken, see: https://github.com/netwide-assembler/nasm/pull/37

More information:
- https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html#chapter7-2
- https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/bfd-in2.h;h=4ab7e2d69347fc8d707094c18b29e1b32ecfcd69;hb=HEAD#l2063

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392798

Signed-off-by: Ignacio Losiggio <iglosiggio@dc.uba.ar>
2022-09-01 14:32:02 -03:00
H.J. Lu
adf7507e29 Use REL relocation in DWARF sections for i386
i386 should use REL relocation in DWARF sections with addend stored at
the relocation offset.  This fixes

https://bugzilla.nasm.us/show_bug.cgi?id=3392807

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2022-09-01 09:04:47 -07:00
Fabian Giesen
04f981e0e6 output/elf: Don't set data symbol type/size in ABS sections
I'm dealing with a FreeBSD-derived embedded target that ends up
showing such symbols (which is mainly NASM struct definitions)
in backtraces after calling NULL function pointers, since these
symbols _are_ technically covering bytes around address zero.

Needless to say, this is extremely confusing and generates
nonsensical bug reports. (Essentially, random unrelated crashes
get cross-referenced to a random ASM struct, whatever the linker
picked for address 0).

These symbols are already a bit strange to begin with (they're
purely an artifact of how NASM happens to implement structs),
leaving their sizes at 0 seems reasonable.

Signed-off-by: Fabian Giesen <fabian.giesen@epicgames.com>
2022-08-30 14:26:54 -07:00
Viktor Szakats
e1423b0573
omit input filename from COFF output when --reproducible
Before this patch, COFF output always contained the first 18 bytes of the
input filename. This breaks reproducibility and may also leak sensitive
data to objects (esp. with input filenames with absolute paths.)

This patch makes this output respect the --reproducible option, and omits
the input filename from the COFF output, when set.
2022-07-12 06:07:53 +00:00
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
Elyes HAOUAS
1dfbfa408d Fix some comments
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2022-01-09 18:27:53 +01:00
Elyes HAOUAS
cdf7ad02c2 Fix some typos
while on it, remove unneeded white spaces.

Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2022-01-09 17:34:35 +01: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