Commit graph

99 commits

Author SHA1 Message Date
Biswapriyo Nath
e69fba2db0
Fix missing yasm_xfree function declaration (#224)
This fixes the following compiler error in macOS in CI.

libyasm/tests/bitvect_test.c:112:5: error: implicit declaration of
function 'yasm_xfree' [-Werror,-Wimplicit-function-declaration]
2023-05-14 11:03:04 -07:00
Duncan Ogilvie
8b6c7b237c
Fix allocator mismatch (#107) 2023-05-12 21:19:37 -07:00
Peter Johnson
94ab1135a3 Remove $Id$ and RCSID() usage.
These are useless now that we're using git.
2011-08-19 10:43:16 -07:00
Peter Johnson
bd8401d538 expr_simplify_identity: Pass int_term via pointer.
This allows signaling to the caller (expr_level_op) that the int_term
was destroyed.  Without this, the new expr-simplify-identity testcase
has a use-after-free.

[#232 state:resolved]
2011-07-10 23:44:18 -07:00
Peter Johnson
e15ad1b94b Fix #188: Times forward references would result in bad code generation.
svn path=/trunk/yasm/; revision=2233
2009-10-31 21:45:55 +00:00
Peter Johnson
dd7c64f68a Fix #178: Don't "distribute" shift right op.
This breaks horribly for things like (sym+511)>>9 in -f bin, as the result is
zero instead of something more useful.

Also don't check RHS for symbols; these will fall out later in the assembly
process if they cannot be simplified.

svn path=/trunk/yasm/; revision=2220
2009-07-24 19:01:35 +00:00
Peter Johnson
457170f54e Fix expr simplification bug.
If an expression of the form INT+(a+b)+INT was simplified, constant folding
would combine the ints, but then the level stage (to make INT+a+b) would
start reading from the second (deleted due to folding) INT rather than the
new end of the expression.

Reported by: Samuel Thibault (on yasm-devel@)

svn path=/trunk/yasm/; revision=2123
2008-09-30 03:56:37 +00:00
Peter Johnson
aba2a018cb Support masking of relocatable values with an AND of the full value width to
avoid warnings.  This is primarily useful in bin object format output.
  db label        ; if label is >255, warns.
  db label & 0xff ; okay, no warning.
Masks other than full-sized 1s are still not supported:
  db label & 0x7f ; too complex error

svn path=/trunk/yasm/; revision=2034
2008-02-08 18:59:46 +00:00
Peter Johnson
02075ed7ca Fix #123: Be explicit that errors are such by printing "error:" at beginning
of error messages.

svn path=/trunk/yasm/; revision=2019
2007-12-04 06:19:07 +00:00
Peter Johnson
f938cbd21d Fix #124: Fully simplify out sym-sym in values (e.g. a symbol minus itself).
This could particularly cause false errors if sym is external.

svn path=/trunk/yasm/; revision=2018
2007-12-04 05:58:54 +00:00
Peter Johnson
358acf4597 Commit tests missed in [1979] commit.
svn path=/trunk/yasm/; revision=1981
2007-09-21 18:04:47 +00:00
Peter Johnson
bd7c26d2a6 Fix #115: 1<<0 resulted in 0 instead of 1 (broken in [1900]).
svn path=/trunk/yasm/; revision=1979
2007-09-21 17:48:17 +00:00
Peter Johnson
69fc913eec Clean up a number of obsolete autoconf-detected standard C things.
svn path=/trunk/yasm/; revision=1892
2007-07-13 20:56:28 +00:00
Peter Johnson
3122ac66be Fix #107: Float input "1.000000" hit an edge case in the code that caused
the rounding increment at the end of float conversion to wrap the mantissa
from all 1's to 0, resulting in an incorrect result.

svn path=/trunk/yasm/; revision=1836
2007-05-11 02:19:36 +00:00
Peter Johnson
469e54fa4a Update all copyright dates.
svn path=/trunk/yasm/; revision=1827
2007-04-22 05:09:49 +00:00
Peter Johnson
00473ca981 Bite the bullet and convert tabs to spaces. Previously yasm's source has
been using a mix of tabs and 4 spaces to indent; this looks horrible if
tab size is ever not 8.  While I debated converting to tab-only indentation
that would have been a far higher impact to the source.

svn path=/trunk/yasm/; revision=1825
2007-04-22 03:32:46 +00:00
Peter Johnson
3b44e937b2 Follow the lead of GAS and change the prefix order to SEG, ADDR, DATA,
LOCKREP.  According to mailing list traffic, Intel prefers this order
(apparently for SIMD?) and AMD doesn't care.

GAS commit by: H.J. Lu <hongjiu.lu@intel.com>

svn path=/trunk/yasm/; revision=1807
2007-03-02 07:09:28 +00:00
Peter Johnson
5603155758 Fix #98. Fix implemented by merging any reserve multiple into the main
bytecode multiple.

strucsize.asm tests both creation and instantiation of a nested structure.
[1751] and [1752] fix bugs found during the testing of the instantiation
portion of this testcase.

A side effect of this change is that some errors are found in different
phases, and the error messages are slightly different.  Split
reserve-error.asm testcase into two parts to still get full coverage.

svn path=/trunk/yasm/; revision=1753
2007-02-04 00:41:42 +00:00
Peter Johnson
95e57a41e4 Fix handling of times 0 <...>.
svn path=/trunk/yasm/; revision=1750
2007-02-03 23:52:44 +00:00
Peter Johnson
159f377293 file.c (yasm_unescape_cstring): New function to unescape a string following
C-style escaping conventions.  Will update GAS parser to use this.

svn path=/trunk/yasm/; revision=1696
2006-11-21 08:55:43 +00:00
Peter Johnson
fd04b1aef6 Don't mix EQU expansion with other expr leveling; we could get confused
with certain combinations.
(2nd half of #83)

This also hides some internals of yasm_expr_level_tree.

svn path=/trunk/yasm/; revision=1655
2006-10-18 05:36:51 +00:00
Peter Johnson
f072502ad1 Fix crash case in data bytecode handling (raw followed by non-raw value).
Reported by: Danny Reeves <danny_reeves@hotmail.com>

svn path=/trunk/yasm/; revision=1646
2006-10-12 03:10:14 +00:00
Peter Johnson
9b2aaa97bd Fix #77 by performing symrec-symrec -> subst placeholder transformation
recursively in yasm_expr__bc_dist_subst(); before this we would only do
one level, which fails on simple structures like the old NASM align approach
of "($$-$) & value" (as the $$-$ is one level down in the expression).

svn path=/trunk/yasm/; revision=1635
2006-09-30 05:13:41 +00:00
Peter Johnson
6aaa48cce1 Make out_test.sh smart about 0-byte errwarn output and don't require a
golden errwarn file in this case.  This allows us to remove around 150
0-byte .errwarn test files.

svn path=/trunk/yasm/; revision=1617
2006-09-16 05:43:41 +00:00
Peter Johnson
2f6bca29f2 * section.c (yasm_object_optimize): Set active flag to indicate it's already
on QB.  We use this flag other places, but forgot to set it here.  This
could cause an infinite loop in (rare) situations.

Reported by: Brian Gladman <brg@gladman.plus.com>
(also committed the code he sent that hits this bug as a testcase)

svn path=/trunk/yasm/; revision=1613
2006-09-16 01:36:58 +00:00
Peter Johnson
f8afbd50a8 Merge [1547]-[1593] (inclusive) from trunk.
svn path=/branches/new-optimizer/; revision=1597
2006-08-10 02:31:37 +00:00
Peter Johnson
9ed00ec87e Check for more complex circular references.
svn path=/branches/new-optimizer/; revision=1590
2006-06-24 06:56:49 +00:00
Peter Johnson
c2de3a1667 Start implementing support for multiples.
svn path=/branches/new-optimizer/; revision=1585
2006-06-19 06:18:11 +00:00
Peter Johnson
5b85508ae8 Make imm8 expansion work.
This was broken because I had precbc and precbc2 purposes swapped in the
optimizer.

svn path=/branches/new-optimizer/; revision=1584
2006-06-19 03:54:20 +00:00
Peter Johnson
9bbfdd47f7 Support align. Made a few other minor cleanups while doing so.
svn path=/branches/new-optimizer/; revision=1583
2006-06-18 21:29:26 +00:00
Peter Johnson
53d9be8757 Reimplement optimizer pass 1b and fix x86 so that jumps handle one pass of
expansion.

svn path=/branches/new-optimizer/; revision=1566
2006-06-10 20:34:32 +00:00
Peter Johnson
406461adb2 * bc-data.c (yasm_bc_create_data): Fix crash on empty string (e.g. db '').
svn path=/trunk/yasm/; revision=1547
2006-06-01 05:50:27 +00:00
Peter Johnson
4c33af41ec Revamp error/warning handling, using a model similar to Python's internal
exception handling.  There are now two layers an error or warning goes
through before it hits the user: first an error is logged via
yasm_error_set() (or yasm_warn_set() for a warning).  Only one error may
be set, whereas multiple warnings can be set (yasm_warn_set maintains a
linked list).  Then, calling yasm_errwarn_propagate() propagates any error
and/or warning(s) to an errwarns structure and associates the
errors/warnings with a line number at that time; this call also clears the
pending errors/warnings and allows new ones to be set.  The propagate
function can safely be called when there are no pending error/warnings.

In addition, there are some helper errwarn functions that allow clearing of
an error/warning without propagating, getting it separately, etc.

Still yet to be done: changing most/all uses of yasm_internal_error() into
yasm_error_set(YASM_ERROR_ASSERTION).

The main advantage this change has is making libyasm functions feel much
more library like, and separating the user code line numbers from the inner
function error handling (e.g. intnum create functions only needed the line
number to trigger errors; this is no longer required).

The set/propagate/etc functions use global data structures to avoid passing
around a pointer to every function.  This would need to be made thread-local
data in a threaded app.  Errwarns containers (that keep associated line
numbers) are no longer global, so multiple source streams can be processed
separately with no conflict (at least if there's only a single thread of
execution).

svn path=/trunk/yasm/; revision=1521
2006-05-04 07:55:32 +00:00
Peter Johnson
110cc94e27 * expr.c (expr_simplify_identity): Fix crash when there are greater than 2
terms in an expr, only 1 of them is an intnum, and it can get removed.

* expr-wide-ident.asm: Test for this case.

Reported by: Brian Gladman

svn path=/trunk/yasm/; revision=1438
2006-03-28 09:35:44 +00:00
Peter Johnson
1b5b5fd342 * combpath_test.c: Add a couple of tests with drive letters in the mix.
svn path=/trunk/yasm/; revision=1437
2006-03-28 09:09:15 +00:00
Peter Johnson
3268c5e367 Finally fix brokenness that was NASM imported preprocessor include path
handling.  The new way of doing things follows C compiler standard path
searching rules in terms of relative and absolute paths in relation to
source location and the current working directory.  There's probably some
latent bugs in this as I've not tested it on Windows yet.

This should make CodeView actually usable with included files.

* file.c (yasm__abspath_win, yasm__abspath_unix): Convert a relative path
into an absolute path.  Code moved from:
* cv-symline.c (cv_make_pathname): Here (deleted).
(cv_dbgfmt_add_file): Use yasm__abspath() instead.
* file.h (yasm__abspath_win, yasm__abspath_unix): Prototype.
(yasm__abspath): Macro pointing to right version.

* file.c (yasm__combpath_win, yasm__combpath_unix): Combine two possibly
relative paths (also handles absolute paths).
* file.h (yasm__combpath_win, yasm__combpath_unix): Prototype.
(yasm__combpath): Macro pointing to right version.

* file.c (yasm__fopen_include): Where the new include search magic happens,
using yasm__combpath heavily.
* file.h (yasm__fopen_include): Prototype.

* nasm-preproc.c: Update to use yasm__fopen_include().
* nasmlib.c (nasm_src_get_fname): Helper.
* nasmlib.h (nasm_src_get_fname): Helper prototype.
* nasm-preproc.c (nasm_preproc_add_dep): Don't free pointer, we need it.

* splitpath_test.c: Update.
* combpath_test.c: New test for yasm__combpath_*.

* Mkfiles: Update config.h for yasm__abspath and yasm__combpath.

svn path=/trunk/yasm/; revision=1436
2006-03-28 09:05:53 +00:00
Peter Johnson
f8541ca249 * splitpath_test.c: Include file.h not splitpath.c to match [1433].
svn path=/trunk/yasm/; revision=1434
2006-03-28 02:26:19 +00:00
Peter Johnson
9fa87cdae1 Massive cleanup of relocation and WRT handling. Closes #49 and lays the
groundwork for further features and possible cleanups.

Note: this commit changes the way in which relocations in the
COFF/Win32/Win64 target can be forced to reference a different symbol than
is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get
the reloc to point at trap.end but reference the trap symbol, after this
commit "trap.end wrt trap" is the way to say this.  This also reads a lot
more clearly and is not ambiguous.  This should really only affect people
who write .pdata sections for Win64.  See the
objfmts/win64/tests/win64-dataref.asm testcase for an example of usage.

This cleanup adds a new data structure, yasm_value, which is used for all
expressions that can be potentially relocatable.  This data structure
splits the absolute portion of the expression away from the relative
portion and any modifications to the relative portion (SEG, WRT,
PC-relative, etc).  A large amount of code in the new value module breaks
a general expression into its absolute and relative parts
(yasm_value_finalize_expr) and provides a common set of code for writing
out non-relocated values (yasm_value_output_basic).

All bytecode handling in both libyasm and the architecture modules was
rewritten to use yasm_values when appropriate (e.g. data values,
immediates, and effective addresses).  The yasm_output_expr_func is now
yasm_output_value_func and all users and implementors (mainly in object
formats) have been updated to handle yasm_values.

Simultaneously with this change, yasm_effaddr and yasm_immval full
structure definitions have been moved from bc-int.h to bytecode.h.
The data hiding provided by bc-int.h was relatively minimal and probably
overkill.  Also, great simplifications have been made to x86 effective
address expression handling.

svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
Peter Johnson
135d4727dd More gracefully handle absolute section refernce expansion, and allow for
correct detection of absolute section reference loops (fixing a crash case).
This is also needed for an ongoing rewrite of reloc/value handling.

* expr.c (expr_xform_bc_dist): Remove transformation of absolute section
references; move in changed form into...
(yasm_expr__level_tree): Here.  The new code doesn't immediately calculate
the distance from the start of the absolute section to the referenced symbol;
rather it generates an expression for this quantity.  As this actually adds
new absolute section refs to the tree, we can't expand with YASM_EXPR_SYMs,
otherwise we would expand multiple times.  Thus we need a new
YASM_EXPR_SYMEXP type that thus does not get expanded.  Unfortunately this
ripples changes a bit because everywhere *else* we look for YASM_EXPR_SYM,
we now need to look for YASM_EXPR_SYMEXP as well...
(expr_xform_bc_dist): Here.
(yasm_expr__copy_except): Here.
(yasm_expr_extract_symrec): Here.
(yasm_expr_get_symrec): Here.
(yasm_expr_print): Here.
* bin-objfmt.c (bin_objfmt_expr_xform): And here.
* expr-int.h (yasm_expr__type): Define new YASM_EXPR_SYMEXP.

* section.h (yasm_section_abs_get_sym): To implement above, we need to get
a symbol referencing the first bytecode in the absolute section.  To avoid
creating redundant symrecs, one is generated for us now.  This function
lets us get it in yasm_expr__level_tree().
* section.c (yasm_section_abs_get_sym): Implement.
(yasm_section): Add necessary SECTION_ABSOLUTE data.
(yasm_section_create_absolute): Create the symrec here.

* absloop-err.asm: New test for absolute section reference loops.

svn path=/trunk/yasm/; revision=1417
2006-03-14 08:52:41 +00:00
Peter Johnson
faee015579 Remove some unused variables/functions.
* dwarf2-info.c (dwarf2_info_head_*): Remove.

* dwarf2-line.c (dwarf2_spp_bc_tobytes): Remove unused variable.
* dwarf2-dbgfmt.c (dwarf2_dbgfmt_generate, dwarf2_head_bc_tobytes): Likewise.
* leb128_test.c (run_input_test): Likewise.

svn path=/trunk/yasm/; revision=1387
2006-02-14 03:32:52 +00:00
Peter Johnson
2e18bad174 * intnum.c (yasm_intnum_create_leb128): Create an intnum from a LEB128
encoded value.
* intnum.h (yasm_intnum_create_leb128): Prototype.
* leb128_test.c: Test above.

svn path=/trunk/yasm/; revision=1386
2006-02-12 23:12:10 +00:00
Peter Johnson
cea67a24b2 * splitpath_test.c: Add no-filename cases.
svn path=/trunk/yasm/; revision=1347
2006-01-29 01:24:19 +00:00
Peter Johnson
000ba73a81 Add functions to split a path into a directory and base filename.
* splitpath.c (yasm__splitpath_unix, yasm__splitpath_win): New.
* coretype.h: Prototype above and alias yasm__splitpath.
* splitpath_test.c: New test for above.

svn path=/trunk/yasm/; revision=1345
2006-01-29 01:17:49 +00:00
Peter Johnson
5074259998 * symrec.c (symrec_define): Don't error if a symbol is declared common and
then defined, and warn instead of error if a symbol is declared global and
then defined.

* externdef.asm: Test for the warning.

svn path=/trunk/yasm/; revision=1308
2005-11-03 04:38:21 +00:00
Peter Johnson
7f72306ed5 Make negative times value an error case.
* bytecode.c (yasm_bc_resolve, yasm_bc_tobytes): Look for negative multiple.

* timesover-err.asm: New testcase for this.

Reported by: Stefan <SMarF@gmx.de>

svn path=/trunk/yasm/; revision=1296
2005-10-30 06:15:15 +00:00
Peter Johnson
1ddc1272d2 Add support for LEB128 encoded integers (both signed and unsigned). This
is needed for the GAS .uleb128 and .sleb128 directives.

* intnum.c (yasm_intnum_sign): New signedness discovery function.
* intnum.h (yasm_intnum_sign): Prototype.

* intnum.c (yasm_intnum_get_leb128, yasm_intnum_size_leb128): New.
* intnum.h (yasm_intnum_get_leb128, yasm_intnum_size_leb128): Prototype.
* leb128_test.c: New test for intnum-level LEB128 functions.

* bytecode.c (bytecode_leb128): New bytecode and supporting functions.
(yasm_bc_create_leb128): New creation function.
* bytecode.h (yasm_bc_create_leb128): Prototype.

* gas-token.re: Recognize .uleb128 and .sleb128.
* gas-bison.y: Ditto.
(gas_define_leb128): New.
* leb128.asm: New test for GAS .uleb128 and .sleb128 directives.

svn path=/trunk/yasm/; revision=1287
2005-10-17 07:43:16 +00:00
Peter Johnson
ca17d58f87 Fix distcheck build breakage by including stamp-h1 instead of trying to
include source (which breaks when different build/source paths are used).

svn path=/trunk/yasm/; revision=1221
2005-08-30 06:56:12 +00:00
Peter Johnson
ca1f865343 * bytecode.c (bc_incbin_tobytes): Fix fread call so that return value check
works (was broken for >1 byte files).
(yasm_bc_tobytes): Fix handling of bytecodes that are larger than provided
buffer.

Patch by: Stephen Polkowski <stephen@centtech.com>

svn path=/trunk/yasm/; revision=1219
2005-08-27 02:05:36 +00:00
Michael Urman
68340f7ba7 Modify the output for 'make check' to be much less verbose, and thus
much easier to see the bad news when necessary. Thanks go to Peter for
updates to the C tests. Kudos to him having us send most of our tests
through a single shell script!

svn path=/trunk/yasm/; revision=1203
2005-03-16 05:26:35 +00:00
Peter Johnson
882738b234 Greatly simplify build system by removing libtool and integrating formerly
dynamically loaded modules into the now-static libyasm.  I now anticipate
that there would be very few users of the dynamic loading features, and it
yielded a lot of instability and build headaches for very little benefit.
The new build should now be much more cross-platform and faster (there was
a lot of overhead in finding and loading modules).

 * libtool.m4, ltdl.m4: Delete.
 * m4/Makefile.am: Rename to m4/Makefile.inc and remove references to above.
   Change to use subdirectory (flat) build rather than recursive build.
 * Makefile.am: Include m4/Makefile.inc rather than having it in SUBDIRS.
 * libltdl: Delete.

 * frontends/yasm/yasm-module.c: Delete.
 * basename.c, dirname.c: Delete (no longer needed by yasm-module.c).
 * genmodule.c, module.in: Generator and template for new module.c included
   in libyasm that replaces the old yasm-module.c (module.in is a modified
   rename of yasm-module.c).
 * module.h: Modified rename of old yasm-module.h.
 * libyasm.h: Include libyasm/module.h.
 * libyasm/Makefile.inc: Build generator and include module.c in libyasm.
 * yasm.c: Use new libyasm module interface.

 * (many) Makefile.inc: Remove libtool libraries, build all modules into
   libyasm library.

 * configure.ac: Remove libtool/libltdl references.

 * Mkfiles/vc/yasm-module.c: Remove.  Still need to fix some of the other
   Mkfiles/ build files for these changes.


svn path=/trunk/yasm/; revision=1183
2004-12-01 07:49:18 +00:00