Commit graph

149 commits

Author SHA1 Message Date
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
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)
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)
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)
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
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
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
H. Peter Anvin (Intel)
32f7464076 outmacho.c: mark zeroing warning as WARN_ZEROING
The zeroing warning should, amazingly enough, have been WARN_ZEROING.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 19:37:49 -07:00
H. Peter Anvin (Intel)
873ceee29f Replace nasm_error(ERR_WARNING|...) with nasm_warn()
Remove a few remaining instances of nasm_error(ERR_WARNING).

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 19:18:36 -07:00
H. Peter Anvin
8960e1bc83 Remove #includes already provided by "compiler.h"
"compiler.h" already includes a bunch of common include files. There
is absolutely no reason to duplicate them in individual files, and in
fact it robs us of central control of how these files are used.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 12:45:44 -08:00
H. Peter Anvin
c2f3f26015 Replace <ctype.h> includes with "nctype.h"
For almost everything we should use "nctype.h". Right now we don't
have a nasm_toupper() to use <ctype.h> for things that need toupper().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 12:37:25 -08:00
H. Peter Anvin
2e53f27e9d Move <string.h> inclusion to compiler.h
There is absolutely no reason not to include <string.h> globally, and
with the inline function for mempcpy() we need it there anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-26 06:32:37 -08:00
H. Peter Anvin (Intel)
e55d03dd47 Clean up the handling of various passes
The use of pass0, pass1, pass2, and "pass" passed as an argument is
really confusing and already caused a severe bug in the 2.14.01
release cycle. Clean them up and be far more explicit about what
various passes mean.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-18 11:14:59 -08:00
H. Peter Anvin (Intel)
c3c6cea838 warnings: make WARN_* constant obligatory for warnings
Make it an error to have ERR_WARNING without a suppression level.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:44:35 -08:00
H. Peter Anvin (Intel)
ebb05a0e5f hashtbl: revamp the hash table interface, support binary keys
Add binary key support to the hash table interface. Clean up the
interface to contain less extraneous crud.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-11 13:18:49 -08:00
Cyrill Gorcunov
f6b1720a2d version: Make them dynamic for regression tests sake
When we are running regression tests we compare binary
forms and the strings better to be the constants to not
trigger false positives.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 16:59:32 +03:00
Cyrill Gorcunov
c7922f95af output: macho -- Rename sect_attribs to macho_known_section_attr
To unify with macho_known_section in namings.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-25 00:14:08 +03:00
Cyrill Gorcunov
458c04eca4 output: macho -- Use lookup_known_section helper
To make it similar to elf code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-25 00:13:54 +03:00
Cyrill Gorcunov
fbc92bdb66 output: macho -- Beautify known sections
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-24 22:49:03 +03:00
Cyrill Gorcunov
68de05ca79 output: macho -- Move constants into the header
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-24 22:31:07 +03:00
Cyrill Gorcunov
f7b44f6092 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx: (83 commits)
  NASM 2.14rc16
  doc: Update changes
  preproc: expand_smacro -- Fix nil dereference on error path
  eval: Eliminate division by zero
  doc: Update changes
  opflags: Convert is_class and is_reg_class to helpers
  preproc: Fix out of range access in expand mmacro
  doc: Update changes
  parser: Fix sigsegv on certain equ instruction parsing
  labels: Make sure nil label is never passed
  labels: Don't nil dereference if no label provided
  macho: Add warning message in macho_output()
  macho/reloc: Fix addr size sensitive conditions
  macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc()
  macho/reloc: Fixed offset adjustment in add_reloc()
  macho/reloc: Allow absolute relocation when forcing a symbol reference
  macho/reloc: Adjust SUB relocation information
  macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations
  macho/reloc: Simplified relocation for REL/BRANCH
  macho/sym: Record initial symbol number always
  ...

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-15 22:58:13 +03:00
Chang S. Bae
703e565849 macho: Add warning message in macho_output()
Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:13 +03:00
Chang S. Bae
7fcf32ba31 macho/reloc: Fix addr size sensitive conditions
TLVP relocation helps GOT that is 64-bit only.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:10 +03:00
Chang S. Bae
195e735a81 macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc()
Unlike the relative relocations, OUT_ADDRESS had ignored the adjustments
made by add_reloc(), and writes the offset of the target symbol in the
target section.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:05 +03:00
Chang S. Bae
f63d211bcf macho/reloc: Fixed offset adjustment in add_reloc()
If the target symbol is in the same file, add_reloc() emits an
internal reloc for the target section, and the offset written
is the offset in the target section.  If the target symbol is
external, its offset is zero (or an explicit addend), and
add_reloc() emits an external reloc for the symbol.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:01 +03:00
Chang S. Bae
960efc3ff2 macho/reloc: Allow absolute relocation when forcing a symbol reference
The (fake) section for absolute symbols is not in the linked list. So,
when the section is not found from the index, now it simply points to
the special section.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:57 +03:00
Chang S. Bae
625ea1ca47 macho/reloc: Adjust SUB relocation information
As SUB relocation getting deprecated, reset external reference seems to
be enough. Also, print a warning message for this.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:53 +03:00
Chang S. Bae
e859ece378 macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations
- Changed to search all symbols, instead of only global symbols.

- Will do immediate exits when unsupported use of WRT

- Fixed to mark (got)pcrel flag only for macho64 output. GOT is
supported only for 64-bit.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:49 +03:00
Chang S. Bae
4cbbb3940d macho/reloc: Simplified relocation for REL/BRANCH
It seems like the relocation for the relative reference
to absolute addresses only cares external reference info.
Instead of exiting, reset the external reference flag.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:45 +03:00
Chang S. Bae
bffd2b7def macho/sym: Record initial symbol number always
The special segment may need this information for future fix-ups.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:40 +03:00
Chang S. Bae
b10435f06e macho: Fix relocation type for relative direct branch
Previously, X86_64_RELOC_BRANCH is only set for external
relocations. Internal relocation also needs this type to be
set, instead of the default (X86_64_RELOC_SIGNED) or
anything.

Reported-by: <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-24 11:21:58 +03:00
Chang S. Bae
b8d153eb4d macho: Turn off jump-match optimization for subsections_via_symbols
The jump-match optimization tends to remove labels. When the
"subsections_via_symbols" pragma is declared, all the labels
should be emitted. Disabling the optimization (only) makes
the pragma effective.

It might be cleaner to extend the OFMT interface to support
callback function. In this case, the reconfiguration can be
done through the callback interface, rather than direct
access to the global variable.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-16 00:01:38 +03:00
H. Peter Anvin (Intel)
d644119ded subsections: don't lose the offset in the parent section
We don't want to lose the offset into the parent section when we
create a subsection, at least not for the MachO backend which is
currently the only user of subsections. Allow ofmt->herelabel() to set
a flag to copy the section offset from the previous section.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 20:20:21 -07:00
H. Peter Anvin
2c57d0a5ca RAA: make pointer vs integer RAAs type safe
Use pseudo-types to make it impossible to confuse RAAs made of
integers and RAAs made of pointers.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 17:11:54 -07:00
H. Peter Anvin
a5992a4c41 outmacho: don't use raa_read() for pointer values
If we write pointers, we have to read pointers.  This unbreaks
non-64-bit bigendian systems.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 16:00:48 -07:00
H. Peter Anvin
c51369067c errors: simplify nasm_fatal() and nasm_panic()
Nearly all instances of nasm_fatal() and nasm_panic() take a flags
argument of zero. Simplify the code by making nasm_fatal and
nasm_panic default to no flags, and add an alternate version if flags
really are desired. This also means that every call site doesn't have
to initialize a zero argument.

Furthermore, ERR_NOFILE is now often not necessary, as the error code
will no longer cause a null reference if there is no current
file. Therefore, we can remove many instances of ERR_NOFILE which only
deprives the user of information.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:20:17 -07:00
H. Peter Anvin
ed859f72a1 output: remove ABSOLUTE handling, OUT_RAWDATA asserts
ABSOLUTE handling can be done centrally, and shouldn't need to be in
every backend.  Simply drop the call to ofmt->output().

Many backends have an assert for OUT_RAWDATA not having a target
segment; this doesn't make any sense as output/legacy.c will not allow
that to happen.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-15 00:03:53 -07:00
H. Peter Anvin
0125c446dd output: centralize the null definition of ofmt->segbase
Only two output formats (obj and ieee) actually need ofmt->segbase, so
move the common dummy definion into nullout.c.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 22:41:00 -07:00
H. Peter Anvin
b91b63d164 outmacho: don't do encoding magic in the segment index
Encoding magic (in this case, subsection number) by bitfields in the
segment index has several problems:

1. It limits the number of *external symbols* as well as
   segments/subsections.
2. It is inefficient for the assembler (creates a very large RAA).

This is also a really good opportunity for removing linear lookups in
the MachO backend. We now use an RAA to do look up segment by index,
and a hash table to look up segment by name. Subsections are simply
handled by allocating a new index using seg_alloc() but still point it
to the same section structure in the index RAA.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 17:14:36 -07:00
H. Peter Anvin
29695c85fb labels: add a subsection field available for backend use
Allow the subsection to store a subsection value directly in the
label, rather than having to do strange encoding hacks.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 17:04:32 -07:00
H. Peter Anvin
69f0551f6f macho: Turn off OFMT_KEEP_ADDR
OFMT_KEEP_ADDR seems to not work properly. Now when we have proper
subsections, there is no need for that anymore.

This reverts commit 69ed82447a.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:14:16 -07:00
H. Peter Anvin
98578071b9 Cleanup of label renaming infrastructure, add subsection support
In order to support Mach-O better, add support for subsections, as
used by Mach-O "subsections_via_symbols". We also want to add
infrastructure to support this by downcalling to the backend to
indicate if a new subsection is needed.

Currently this supports a maximum of 2^14 subsections per section for
Mach-O; this can be addressed by adding a level of indirection (or
cleaning up the handling of sections so we have an actual data
structure.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:06:25 -07:00
H. Peter Anvin
892c4818ce Add support for backend-defined subsections and label hacks
MachO has this odd thing called "subsections via symbols", by which a
symbol can magically start what effectively is a new section. To
support this, add support for a calldown into the backend when a new
symbol is defined *at the current output location*, and allow it to
switch the current segment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:48:18 -07:00
H. Peter Anvin
1ce81e10ef Revert "output: macho -- Check the actual size of 64-bit absolute address"
This reverts commit 69ed82447a.
2018-05-08 12:46:55 -07:00
Chang S. Bae
427d8e3e57 output: macho -- Avoid conversion of addresses to RAWDATA
Without relocation, the linker may do erroneous dead strip.
For the relocation, the conversion of addresses to RAWDATA
should be avoided for Mach-O.

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

Reported-by: Andrew Fish <afish@apple.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-05-05 23:44:33 +03:00
Chang S. Bae
69ed82447a output: macho -- Check the actual size of 64-bit absolute address
Even though the size is set to 64-bit, actual value can be
in 32-bit range. In that case, the use of such absolute
address is prevented.

The side effect of 58d2ab17 is resolved.

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

Reported-by: Richard Russell <rtrussell@gmail.com>
Reported-by: Michael Petch <mpetch@capp-sysware.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-05-05 23:43:57 +03:00
Matthieu Darbois
9adfd34b03 output: macho -- Add support for N_PEXT in macho output
This allows to mark global symbols as private external.
Similar to visibility hidden in ELF output.

Signed-off-by: Matthieu Darbois <mayeut@users.noreply.github.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 17:41:54 +03:00
Cyrill Gorcunov
51b453b097 output: elf,ieee,macho,obj -- Fix mofule name for commit 81b62b9f54
These modules need a reference to input filename.
For example elf put into symbol table

 | SYMBOL TABLE:
 | 0000000000000000 l    df *ABS*	0000000000000000 sha-64.asm

Otherwise this  become empty string.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 15:50:35 +03:00