Commit Graph

4098 Commits

Author SHA1 Message Date
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
3631bc29c1 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx:
  doc: Update changes
2018-10-21 15:45:36 +03:00
Cyrill Gorcunov
0e7f511151 doc: Update changes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-21 15:45:02 +03:00
Cyrill Gorcunov
eb82f99367 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx:
  preproc: Make the preprocessor use nasm_catfile for include
  path: nasm_catfile -- Fix incorrect return of filename only
2018-10-21 15:06:36 +03:00
night199uk
fdb1a1b151 preproc: Make the preprocessor use nasm_catfile for include
All include paths to nasm must already have a trailing separator
prefix which is uncommon among tools. Change to using nasm_catfile
which gives a more normal behaviour.

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

Signed-off-by: night199uk <night199uk@hermitcrabslab.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-19 01:00:11 +03:00
night199uk
e1bd3bc7b4 path: nasm_catfile -- Fix incorrect return of filename only
nasm_catfile returns an incorrect (already incremented) pointer.

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

Signed-off-by: night199uk <night199uk@hermitcrabslab.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-19 00:55:54 +03:00
Cyrill Gorcunov
1f620b8e84 test: nasm-t -- Add alonesym-obj testcase
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 23:40:50 +03:00
Cyrill Gorcunov
dcf3937e92 test: nasm-t -- Use new syntax for update
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 23:36:43 +03:00
Cyrill Gorcunov
6977b23cfb travis: Disable osx for a while
osx update takes too long, disable it for a while.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 21:40:14 +03:00
Cyrill Gorcunov
ab50bc3780 Add travis status into readme
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 21:40:14 +03:00
Cyrill Gorcunov
2e1bf723a9 test: travis -- Add some of converted tests
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 21:40:14 +03:00
Cyrill Gorcunov
5453388940 test: travis -- Add initial support
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 21:40:14 +03:00
Cyrill Gorcunov
88ef566099 README: Update link to license
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 21:38:35 +03:00
Cyrill Gorcunov
b5e00ec018 Convert README to md format
And update it a bit.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-17 21:38:28 +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
Cyrill Gorcunov
28b69e2a63 NASM 2.14rc16 2018-10-15 00:26:52 +03:00
Cyrill Gorcunov
1cbd48ad48 doc: Update changes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-14 21:09:30 +03:00
Cyrill Gorcunov
980dd658b5 preproc: expand_smacro -- Fix nil dereference on error path
When error happened earlier we might have a.mac already
handled and set to nil.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-14 19:25:32 +03:00
Cyrill Gorcunov
ceec0d8187 eval: Eliminate division by zero
When doing division we should detect if the value we're
divided by is not zero. Instead of is_unknown() helper
we should use is_just_unknown().

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

Reported-by: Jun <jxx13@psu.edu>
Reported-by: stuartly <situlingyun@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-14 01:49:43 +03:00
Cyrill Gorcunov
d94402d6f7 doc: Update changes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 23:03:24 +03:00
Cyrill Gorcunov
3c755dac88 opflags: Convert is_class and is_reg_class to helpers
So we can test for out of bound access and make
helpers safe to use.

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

Reported-by: Jun <jxx13@psu.edu>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 22:57:30 +03:00
Cyrill Gorcunov
67f2ca2b3f preproc: Fix out of range access in expand mmacro
On specially crafetd malformed input file the params
might be zapped (say due to invalid syntax) so we might
access out of bound having nil dereference in best case.

Note the later code in this helper uses tok_isnt_ helper
which already has similar check.

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

Reported-by: Jordan Zebor <j.zebor@f5.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 19:41:01 +03:00
Cyrill Gorcunov
a98a84b0d5 doc: Update changes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 18:15:36 +03:00
Cyrill Gorcunov
a28c40d546 parser: Fix sigsegv on certain equ instruction parsing
We should check for bounds when accessing nasm_reg_flags.
Seems this bug was for long time already.

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

Reported-by: Jordan Zebor <j.zebor@f5.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 18:10:30 +03:00
Cyrill Gorcunov
8e740c6773 labels: Make sure nil label is never passed
We already catched a case where we've missed
test for non nil label and in result got sigsegv,
lets rather panic next time.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 17:18:05 +03:00
Cyrill Gorcunov
e996d28c70 labels: Don't nil dereference if no label provided
An equ without label may cause nil dereference

 |	equ 0x100

Fixes 98578071b9

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 16:18:16 +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
Cyrill Gorcunov
0bdd7f1546 opflags: Style unification
No func change.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-01 01:09:43 +03:00
Cyrill Gorcunov
c713b5f994 preproc: parse_size -- Check for string provided
In case if the string is nil we will have sigsegv.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-29 14:31:26 +03:00
H. Peter Anvin
ab2c4dfff9 pspdf.pl: GhostScript font integration seems broken with -dSAFER
-dSAFER seems to break font integration on some systems.  Furthermore,
once given -dSAFER seems to not be possible to override, so instead of
calling via the ps2pdf script, call GhostScript explicitly with the
equivalent options, sans -dSAFER.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-09-24 18:02:22 -07:00
Cyrill Gorcunov
10c0f66570 doc: changes -- Add a few more bullets
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-23 23:30:44 +03:00
Cyrill Gorcunov
da3780dc22 Fix small typo in comment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 14:10:36 +03:00
Cyrill Gorcunov
69bb052e00 asm: Restore showing output for preproc mode in stdout
Before the commit 81b62b9f54
we've been always putting -E,-e results into stdout if no
output file provded. So bring this backward compatibility
back.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 13:46:45 +03:00
Chang S. Bae
17ffc1704b obj: Fix to initialize segment list
Recent labeling mechanism changes seem to bring the case,
where segment() procedure is called when the segment list
is empty. Now, it will simply check and initalize the
segment list.

Reported-by: Ozkan Sezer <sezeroz@gmail.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-09-15 23:04:30 +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
1fd4c45c96 doc: Fix macho section name for code
While today's manual lists "text" as the code section name,
"code" has been effectively named from d1da074.

Reported-by: <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-24 11:21:53 +03:00
Cyrill Gorcunov
55d09bbf6f disasm: Fix buffer overread in ndisasm
https://nvd.nist.gov/vuln/detail/CVE-2018-10254
https://sourceforge.net/p/nasm/bugs/561/

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-08-16 01:20:01 +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
Chang S. Bae
a578634b61 optimization: Introduce new flag to turn-off selectively
While configuring optimization in a level is conventional,
a certain optimization tends to conflict with some pragma.

For example, jump match conflicts with Mach-O's
"subsections-via-symbols" macro.

This configurability will workaround such conflicts.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-16 00:01:31 +03:00