Michael Urman [Fri, 28 May 2004 13:19:48 +0000 (13:19 -0000)]
Fixed handling of absolute sections in the elf object format, including
preventing a segfault. The assumptions it had made for all sections
were wrong with absolute sections, so added just as much special casing
as necessary. I hope the output is correct as well - this way we should
at least get bugs if it's wrong.
Peter Johnson [Sun, 11 Apr 2004 23:25:17 +0000 (23:25 -0000)]
Add rudimentary, untested, AMD64 support.
The AMD64 MASM likes to generate REL32 relocations for everything; I've not
yet figured out how this works.
This code should work fine for files without relocation.
Bugzilla bug: 33
Reported by: Jeff Lawson <jlawson-yasm@bovine.net>
Peter Johnson [Sat, 27 Mar 2004 03:14:52 +0000 (03:14 -0000)]
Fix indexreg handling in x86_expr_checkea_getregusage() to correctly handle
a non-multiplier used after a multiplier (e.g. edi*8+eax). Previously,
this resulted in the eax overriding the edi as the indexreg, causing the
effective address not to be recognized.
Update the effaddr testcase to test this case and a few other similar ones.
Peter Johnson [Tue, 16 Mar 2004 08:26:19 +0000 (08:26 -0000)]
Fix push in 64-bit mode to take a 32-bit signed immediate rather than a
64-bit immediate. Actually, whether it's signed or unsigned seems to be
uncertain; AMD64 documentation shows it as signed, but Intel's new IA-32e
says it's unsigned! While we're here, the Imm8 version is signed, not
unsigned.
Bugzilla bug: 30
Reported by: Michael Ryan <michaelryan@mindspring.com>
Peter Johnson [Sat, 7 Feb 2004 22:28:40 +0000 (22:28 -0000)]
Make yasm dynamic module loader able to find modules even when run from a
different location. The new code uses dirname() to add the argv[0] path to
the LTDL module loader search path. Added new replacements for dirname and
basename functions from OpenBSD.
Bugzilla: Bug 24
Reported by: Simon Paulger <simonjpaulger@hotmail.com>
(Hopefully) finish cleanups begun in phase 1 (see phase 1 commit message),
making dbgfmt, objfmt, optimizer, and preproc module interfaces follow the
same thread-safe interface style as the phase 1 changes.
Also put in a large number of doxygen documentation cleanups.
Peter Johnson [Thu, 5 Feb 2004 08:25:20 +0000 (08:25 -0000)]
Correct ordering of legacy prefix and REX prefix for SSE/SSE2 instructions
in 64-bit (AMD64) mode. Intel says these bytes should not be treated as
prefixes, but AMD64 treats them as legacy prefixes, expecting them to come
before the REX byte.
For now, keep the three-byte max instruction length (although it's not truly
correct), as handling the other "3-byte" cases such as R/M spare with no EA
is probably more painful than it's worth to push down to later in the code
generation path.
Reported by: Henryk Richter <henryk.richter@comlab.uni-rostock.de>
Peter Johnson [Tue, 16 Dec 2003 07:45:04 +0000 (07:45 -0000)]
Add a workaround for the lack of per-objfmt macro support to fix the common
use of the ORG macro (several user comments about the lack of this) and the
initial value of the __SECT__ macro (used by ENDSTRUC among other macros).
Fortunately, for all current objfmts, __SECT__ is currently defined as
[section .text], so one common definition can be used for now.
FIXME: remove this workaround when a better solution has been implemented.
Peter Johnson [Tue, 16 Dec 2003 03:54:15 +0000 (03:54 -0000)]
Properly handle fatal errors (like missing include file) from the real
NASM parser by changing the libyasm yasm_fatal() interface to use va_list
instead of ... variable arguments. Add a yasm__fatal() function that takes
... and calls yasm_fatal().
Michael Urman [Tue, 4 Nov 2003 20:05:50 +0000 (20:05 -0000)]
Fix stabs to always use stab size 12, n_value size 4. Truncate 64bit
values into 32bits as necessary. This is the proper fix to "written
length does not match optimized length" in amd64+stabs.
Michael Urman [Tue, 4 Nov 2003 19:52:02 +0000 (19:52 -0000)]
"Fix" stabs to always output the same stab length in stabs_bc_stab_tobytes.
Previously only "symvalue" stabs did this, causing a mismatched output size
with amd64 and stabs. However since it appears the actual stabs spec always
uses 12 byte stabs, this fix is already obsolete and will be superceded
shortly.
Reported By: Jeff Lawson <jlawson-yasm@bovine.net>
Peter Johnson [Tue, 28 Oct 2003 18:58:55 +0000 (18:58 -0000)]
Hide details of yasm_arch_module structure, instead creating wrapper macro
"functions" that call down to the module level. Doesn't really change the
internal complexities, just makes it easier to read and write code that
uses it.
Peter Johnson [Fri, 24 Oct 2003 01:32:22 +0000 (01:32 -0000)]
Fix pshift instructions by fixing meaning of MOD_Gap0 to actually eat the
first parameter (before MOD_Op2Add). Before this change, MOD_Gap0 did not
eat a parameter until AFTER MOD_Op2Add.
Peter Johnson [Tue, 21 Oct 2003 03:04:56 +0000 (03:04 -0000)]
Fix reporting of redefinition errors by adding a set of error/warning
reporting functions that take a parameter for the line to be displayed in
addition to the the line used for sorting. This allows the "previously
defined" message to use the standard errwarn line resolution functions.
The resulting error messages look like gcc output.
Peter Johnson [Tue, 21 Oct 2003 01:36:19 +0000 (01:36 -0000)]
Fix a couple of MMX/SSE/SSE2 instructions: movntps, movntq, movss, and the
pcmp* family. The first three had some operand encoding problems, and pcmp*
was typoed as pacmp*.
Reported by: Edouard Gomez <ed.gomez@free.fr>
Peter Johnson [Sun, 19 Oct 2003 18:38:03 +0000 (18:38 -0000)]
Remove obsolete overflow check in EA displacements (causing error instead of
warning on size overflow).
Bugzilla Bug 18
Reported by Jeff Lawson <jlawson-yasm@bovine.net>
Peter Johnson [Fri, 3 Oct 2003 00:32:40 +0000 (00:32 -0000)]
Merge in NASM CVS changes up to 10/02/2003. Changes NOT merged:
- Removal of backslash() - why was this okay?
- Addition of pp_get_include_path_ptr() - we (will eventually) do this a
different way in yasm.
As yasm has evolved, various minor additions have been made to libyasm to
support the new features. These minor additions have accumulated, and
some contain significant redundancies. In addition, the core focus of
yasm has begun to move away from the front-end commandline program "yasm"
to focusing on libyasm, a collection of reusable routines for use in all
sorts of programs dealing with code at the assembly level, and the modules
that provide specific features for parsing such code.
This libyasm/module update focuses on cleaning up much of the cruft that
has accumulated in libyasm, standardizing function names, eliminating
redundancies, making many of the core objects more reusable for future
extensions, and starting to make libyasm and the modules thread-safe by
eliminating static variables.
Specific changes include:
- Making a symbol table data structure (no longer global). It follows a
factory model for creating symrecs.
- Label symbols now refer only to bytecodes; bytecodes have a pointer to
their containing section.
- Standardizing on *_create() and *_destroy() for allocation/deallocation.
- Adding a standardized callback mechanism for all data structures that
allow associated data. Allowed the removal of objfmt and
dbgfmt-specific data callbacks in their interfaces.
- Unmodularizing linemgr, but allowing multiple linemap instances (linemgr
is now renamed linemap).
- Remove references to lindex; all virtual lines (from linemap) are now
just "line"s.
- Eliminating the bytecode "type" enum, instead adding a standardized
callback mechanism for custom (and standard internal) bytecode types.
This will make it much easier to add new bytecodes, and eliminate the
possibility of type collisions. This also allowed the removal of the
of_data and df_data bytecodes, as objfmts and dbgfmts can now easily
implement their own bytecodes, and the cleanup of arch's bytecode usage.
- Remove the bytecodehead and sectionhead pseudo-containers, instead
making true containers: section now implements all the functions of
bytecodehead, and the new object data structure implements all the
functions of sectionhead.
- Add object data structure: it's a container that contains sections, a
symbol table, and a line mapping for a single object. Every former use
of sectionhead now takes an object.
- Make arch interface and all standard architectures thread-safe:
yasm_arch_module is the module interface; it contains a create()
function that returns a yasm_arch * to store local yasm_arch data; all
yasm_arch_module functions take the yasm_arch *.
- Make nasm parser thread-safe.
To be done in phase 2: making other module interfaces thread-safe. Note
that while the module interface may be thread-safe, not all modules may be
written in such a fashion (hopefully all the "standard" ones will be, but
this is yet to be determined).
Peter Johnson [Fri, 5 Sep 2003 00:39:15 +0000 (00:39 -0000)]
Fix support for o64. AMD64 isn't always 32-bit default operand size, so
add fields to bytecode and parsing insn_info to determine default operand
size in 64-bit mode.
Michael Urman [Fri, 15 Aug 2003 03:43:55 +0000 (03:43 -0000)]
STABS debugging information. This includes, naturally, several draft
changes to the dbgfmt interface, and other assorted updates, including:
* yasm.c now calls df->initialize() and df->generate()
* a dbgfmt bytecode type with associated handling
* yasm_output_reloc_func type for use particularly by dbgfmts
* df: initialize updated; generate, bc_dbgfmt_data_{output|delete|print} added
* null-dbgfmt structure brought in line with these additions
* elf-objfmt made aware of stabs sections, and what to do with them
The bad news:
* just enough stabs output to support line number information in GDB
* GDB identifies function labels off by 3 bytes in my test, but line
numbers remain correct, somehow. Unknown whether stabs-dbgfmt or GDB
at fault.
Peter Johnson [Sun, 3 Aug 2003 21:13:20 +0000 (21:13 -0000)]
Add support for the AMD64 syntax [symbol wrt rip]. This is distinct from
[rip+symbol] in that the latter adds the symbol offset to rip, whereas the
former is the same as [symbol] but uses rip-relative addressing. This is
a minor overload of the WRT operator, but reads well and shouldn't conflict
with the use of WRT against sections.
Doing this currently adds a bit of overhead to all effective addresses in
64-bit mode (a $ symbol reference). This is the cleanest approach I could
figure out; a time/space trade could be made later, such as prescanning for
RIP usage before allocating the symbol.
Michael Urman [Sun, 3 Aug 2003 01:13:14 +0000 (01:13 -0000)]
ELF objfmt size agnosticism:
* Replace ulongs secthead.size, secthead.align, reloc.addr with intnums
* Calculate relocation size with intnums
* Create macros YASM_WRITE_32I_L, YASM_WRITE_64I_L to write 32/64bit
intnums to buffer
This doesn't quite cover everything, particularly due to various calls
to yasm_intnum_get_uint for various bits of processing, but it's close!
Miscellany:
* Fix non-call to elf_reloc_delete()
* Remove unused secthead.addr, secthead_set_addr
* Create macro YASM_WRITE_64Z_L to write zero-extended 32bit value to
64bits of buffer
Michael Urman [Sat, 2 Aug 2003 21:50:42 +0000 (21:50 -0000)]
Move elf relocation valsize handling to the backend.
Add elf x86 test case to verify it works properly.
Unsure about elf x86-64 status (relocations segfault my objdump), but
it's no *worse* than last commit.
Michael Urman [Sat, 2 Aug 2003 20:32:42 +0000 (20:32 -0000)]
Continue adding AMD64 ELF support (without breaking x86!):
Move more machine-specific items to the backend (EHDR_SIZE) and make it
target machine-dependent there.
Theoretically everything except relocations may work, but since builds
of amd64 with bits=32 can segfault objdump, don't trust it.
Work to support relocations is next; perhaps then it can be tested.
Michael Urman [Sat, 2 Aug 2003 03:43:41 +0000 (03:43 -0000)]
Implement global constants in elf. Add test to ensure they work; modify
another test such that linked together they verify that
1. It links properly
2. The constant is loaded properly
3. The function is called properly
shown (probably not proved) by the program exiting with error level 0.
Peter Johnson [Fri, 1 Aug 2003 03:52:35 +0000 (03:52 -0000)]
Fix iretq, stosq, etc, which were properly setting the opersize but the REX
generation code wasn't seeing it because it wasn't looking at the modified
opersize.
Bug noticed by: Antoine Leca <antoine64leca@unknown> (x86-64 discuss ML)
Peter Johnson [Wed, 30 Jul 2003 04:36:29 +0000 (04:36 -0000)]
Add versioning to all loadable module interfaces. The version is checked by
module users to ensure the module interface they're using matches the
interface the module was compiled with. The #define YASM_module_VERSION
should be incremented on every functional change to the module interface.
Peter Johnson [Tue, 29 Jul 2003 03:19:12 +0000 (03:19 -0000)]
Add core pieces for "machine" subtype of "architecture". Needed to
differentiate e.g. AMD64 from x86. Doesn't prohibit anything in x86 yet,
but does standardize unsupported warnings across objfmts (most objfmts will
not support all machines and/or all architectures).
Peter Johnson [Sat, 26 Jul 2003 02:32:04 +0000 (02:32 -0000)]
Fixed some conversion warnings caused by intnum commit. Missed these due to
use of configure.ac's --enable-warnerror, which was set up to disable
conversion errors due to flex's warning-prone generated code. As we no
longer use flex, fix configure.ac to not disable conversion errors.
Peter Johnson [Fri, 25 Jul 2003 03:27:21 +0000 (03:27 -0000)]
Big output_expr(), intnum_tobytes(), and floatnum_tobytes() changes:
- Switch to bit-based output, including shift capability
- This means the standard intnum output functions can be used for non-byte
oriented archs like LC-3b (implemented)
- Default out of range (overflow) warnings for intnum (bugzilla bug 14)
- Change floating point overflow/underflow errors to warnings
To do (hooks but not implemented):
- Shifting floatnums into destination
- Floatnum destinations larger than floatnum value
- Big endian support for intnum and floatnum
Related simultaneous changes:
- Use bc instead of ep in objfmt output_expr() functions; while bc->line
should == (*ep)->line, in case they differ, we want to use the bc->line
so as not to confuse users.
- lc3b-mp22NC test was not properly offsetting the accessed variables, but
since the variable "sections" started at an aligned offset, the output
was actually correct. The new intnum warnings uncovered this issue, so
fix code to be correct (and not generate warnings).
Peter Johnson [Fri, 25 Jul 2003 02:17:30 +0000 (02:17 -0000)]
When changing a section start into a start-based expression, use the
expression line number instead of the start line number (which may be 0,
which isn't nearly as useful as the expression line number).
Michael Urman [Thu, 24 Jul 2003 04:38:37 +0000 (04:38 -0000)]
Replace preliminary elf header files with...
ELF objfmt implementation.
Assumed to be correct for the test cases, but only tested as far as feasible.
Currently only implements 32bit 386 little-endian, but is mostly abstracted
well enough to easily add more machines.
Peter Johnson [Sat, 19 Jul 2003 17:53:34 +0000 (17:53 -0000)]
Enhance return values for yasm_x86__expr_checkea() to fully represent the
three possible return states (okay, invalid, or indeterminate). Propagate
this return change into the yasm_x86__expr_checkea() call tree as necessary.
Peter Johnson [Sat, 19 Jul 2003 17:28:10 +0000 (17:28 -0000)]
Fix bad assumption in x86_expr_checkea_getregusage() that was causing bad code,
internal errors, and mis-optimization as seen in Bugzilla Bug 13.
Reported by: meor@softhome.net
Fix a few minor bugs (not heavily tested) due to use of opersize == 32 as a
comparison; this fails when opersize == 64 due to bits = 64, but the default
size is still 4 bytes, not 2.
There's still a couple cases here where we might end up with internal errors
due to a lack of variety in return values; I'll fix those in the next commit.