Peter Johnson [Thu, 14 Oct 2004 05:55:21 +0000 (05:55 -0000)]
* configure.ac: Add detection for libgen.h.
* yasm.c: Conditionally include libgen.h for dirname() definition.
* yasm-module.c: Conditionally include libgen.h for basename() definition.
Peter Johnson [Wed, 13 Oct 2004 03:55:04 +0000 (03:55 -0000)]
* x86id.re (x86_new_jmp): Fix evaluation order dependent call when creating
a FAR target expression. The create_branch() call could be called before
the expr_copy() call; the former can (and does) delete op->data.val. Move
the expr_copy() call to an earlier statement to force the correct
evaluation order.
Thanks to: HP TestDrive for providing the Itanium system that discovered
this bug.
Peter Johnson [Mon, 11 Oct 2004 04:30:08 +0000 (04:30 -0000)]
* elf.h: Update x86 and amd64 relocation types and associated comments.
* elf-x86-x86.c: Add 8-bit and 16-bit relocations (GNU extensions).
* tests/Makefile.inc: Rename elfreloc-err to elfreloc-ext, because relocs
tested in elfreloc-err are now legal due to above changes.
* elfreloc-ext.asm: Likewise.
* elfreloc-ext.errwarn: Likewise.
* elfreloc-ext.hex: New output file.
Michael Urman [Mon, 11 Oct 2004 03:47:28 +0000 (03:47 -0000)]
Enable machine specific handling of relocation section type, since amd64
should use .rela.* instead of .rel.* sections, of type SHT_RELA instead
of SHT_REL.
* elf.h, elf.c: update calls to backend, passing relocations further in.
* elf-machine.h, elf-x86-amd64.c, elf-x86-x86.c: add support for setting
relocation section name, type, and update amd64 to write RELA records.
Also when creating a relocation and writing a value to the file, have
it handled here to keep REL vs RELA distinctions hidden from elf.c.
* elf-rip.hex: update output to match new section type and data output.
Michael Urman [Mon, 11 Oct 2004 03:42:08 +0000 (03:42 -0000)]
Deconst yasm_expr_get_intnum's return, allowing inplace modifications to
be made. The specific instigator for this is the ability to modify the
value in a relocation stored in a .rela.section so that listings are
"correct".
Peter Johnson [Mon, 11 Oct 2004 00:23:10 +0000 (00:23 -0000)]
Add work around for static-build libtool binaries to find preloaded modules
without the presence of the associated ".la" file. This caused the Win32
nightly snapshots to be unusable (as they're static-built libtool).
At present, a search for a preloaded module occurs first, before the ".la"
is even looked for.
Noticed by: Oliver <mybox@ollysoft.de>
* libtool.m4: Define new config.h variable LIBTOOL_LIBEXT that is the
extension used for static libraries (e.g. ".a"). This is the extension used
for preloaded symbols.
* ltdl.c (lt_dlopenext): Add first search function to find filename.a prior
to other searches (.la and .so), so preloaded symbols are hit first.
Michael Urman [Sun, 10 Oct 2004 19:25:23 +0000 (19:25 -0000)]
Phase 2 of 2 cleanup to elf's internal structure.
Move and rename functions for cleanliness.
New files:
elf-machine.h - machine-specific interface, and helper macros
elf-x86-x86 - support specific standard ia32
elf-x86-amd64 - support specific to amd64
Modified files:
elf.c - update the machine structure traversal for external structures
Makefile.inc - support the new files
Michael Urman [Sun, 10 Oct 2004 18:40:31 +0000 (18:40 -0000)]
Phase 1 of a 2 phase cleanup to elf's internal structure.
Historically elf.c had a lot of switches for which machines it supports.
This replaces it with a structure of information and function pointers
which is selected in much the same way the switch value was before. Then
all such switches are replaced with calls through the current machine
handler structure.
Phase 2 will relocate each machine's support to its own file.
Peter Johnson [Fri, 8 Oct 2004 07:22:10 +0000 (07:22 -0000)]
Add relocation information to nasm list format by establishing a common
base structure for relocations and using it in all object formats.
* section.h (yasm_reloc): New base relocation type.
* section.c (yasm_section_add_reloc): New function to add a yasm_reloc to a
section.
(yasm_section_relocs_first, yasm_section_reloc_next): New functions to
access yasm_reloc list.
(yasm_reloc_get): New function to get base info from yasm_reloc.
* section.h: New prototypes for above section.c functions.
* section.c (yasm_section): Add relocs and destroy_reloc members.
(yasm_object_get_general): Initialize relocs and destroy_reloc.
(yasm_object_create_absolute): Likewise.
(yasm_section_destroy): Destroy any created relocs.
* xdf-objfmt.c (xdf_reloc): Base off of new yasm_reloc structure.
(xdf_objfmt_output_expr): Update after xdf_reloc changes.
(xdf_objfmt_output_section): Likewise.
(xdf_section_data_destroy): Likewise.
(xdf_section_data_print): Likewise.
* elf.h (elf_secthead): Remove unneeded list of relocs.
(elf_reloc_entry): Base off of new yasm_reloc structure.
* elf.c (elf_reloc_entry_destroy, elf_relocs_create)
(elf_reloc_destroy): Remove.
(elf_reloc_entry_create): Update after elf_reloc_entry changes.
(elf_secthead_append_reloc, elf_secthead_write_relocs_to_file): Take
additional pointer to yasm_section to access new relocations storage and
update for new elf_reloc_entry structure.
(elf_secthead_create): Update after elf_secthead changes.
(elf_secthead_destroy): Likewise.
(elf_secthead_print): Likewise.
* elf-objfmt.c (elf_objfmt_output_reloc, elf_objfmt_output_expr)
(elf_objfmt_output_section, elf_objfmt_output_secthead): Likewise.
* elf.h: Update prototypes for above elf.c changes.
* coff-objfmt.c (coff_reloc): Base off of new yasm_reloc structure.
(coff_objfmt_output_expr): Update after coff_reloc changes.
(coff_objfmt_output_section): Likewise.
(coff_section_data_destroy): Likewise.
(coff_section_data_print): Likewise.
* nasm-listfmt.c (sectreloc, bcreloc): New.
(nasm_listfmt_output_info): Add bcrelocs, next_reloc, next_reloc_addr.
(nasm_listfmt_output_expr): Record relocations in bcrelocs if next_reloc
and next_reloc_addr match the current expr parameters.
(nasm_listfmt_output): Initialize new members of nasm_listfmt_output_info,
and use bcrelocs data generated by nasm_listfmt_output_expr to add reloc
information to list output.
* x86bc.c (x86_bc_jmp_tobytes): Duplicate jmp_target before splitting
SEGOFF (:) pairs. This avoids a memory leak and doesn't destroy the
ability for the bytecode to be converted to bytes again (which is what
happens when listfmt is used).
* yasm.xml, yasm.1: Add documentation for new listfmt-related options
for yasm frontend: -L (--lformat) and -l (--list).
Peter Johnson [Sat, 2 Oct 2004 06:18:30 +0000 (06:18 -0000)]
First part of list file support. This should accurately output all file
bytes and offsets, but relocations are not yet indicated. Also, this
outputs post-preprocessed source, so no comments, etc, are visible in the
list file.
* listfmt.h: New header file describing listfmt module interface.
* coretype.h: Declare new yasm_listfmt typedef.
* libyasm.h: Include listfmt.h.
* libyasm/Makefile.inc (modinclude_HEADERS): Add listfmt.h.
* yasm-module.h (module_type): Add MODULE_LISTFMT for listfmts.
(load_listfmt_module, list_listfmts): New macros for listfmts.
* yasm-module.c (module_type_str): Add listfmt string for MODULE_LISTFMT.
(list_module_load): Add support for MODULE_LISTFMT.
* bytecode.h (yasm_bc_tobytes): Comment clarification on effect of calling
yasm_bc_tobytes twice on the same bytecode.
* linemgr.h: Replace support for associated data with support for bytecode
and source line information.
(yasm_linemap_get_data): Remove.
(yasm_linemap_get_source): Add.
(yasm_linemap_add_data): Remove.
(yasm_linemap_add_source): Add.
* linemgr.c (yasm_linemap, yasm_linemap_create, yasm_linemap_destroy)
(yasm_linemap_add_data, yasm_linemap_add_source, yasm_linemap_get_data)
(yasm_linemap_get_source): Likewise.
* nasm-token.re (fill): Save previous 2 lines instead of previous 1 line.
(destroy_line, print_line, line_assoc_data): Remove.
(save_line): Save line in structure instead of calling yasm_linemap_add_data.
* nasm-bison.y (input rule): Call yasm_linemap_add_source here.
* nasm-parser.h (yasm_parser_nasm): Add second line of storage and save_last
variable to toggle between the two lines.
* nasm-parser.c (nasm_parser_do_parse): Initialize save_last.
* modules/Makefile.inc: Include new modules/listfmts/Makefile.inc.
* modules/listfmts/Makefile.inc: New;
includes modules/listfmts/nasm/Makefile.inc.
* modules/listfmts/nasm/Makefile.inc: New build file for NASM-like listfmt.
* nasm-listfmt.c: New NASM-like listfmt.
* yasm.c: Enable use of listfmts, and default to NASM listfmt.
(list_filename, cur_listfmt, cur_listfmt_module): New listfmt variables.
(opt_listfmt_handler, opt_listfile_handler): New listfmt functions.
(options): Add --lformat (-L) and --list (-l) options.
(main): Load "nasm" listfmt as default if none selected.
Enable saving of input lines if list output file enabled.
Open and write to the list file.
(open_obj): Rename to open_file and make more generic.
(cleanup): Destroy listfmt and list filename if created.
Peter Johnson [Mon, 27 Sep 2004 04:15:12 +0000 (04:15 -0000)]
* expr.c (yasm_expr_extract_symrec): Add "relocate" parameter. Use it to
control whether the symbol is replaced with the symbol's value (old
behavior), or just replace it with 0 (new optional behavior). The old
behavior is enabled by setting relocate=1.
* expr.h (yasm_expr_extract_symrec): Likewise (and document new behavior).
* elf-objfmt.c (elf_objfmt_output_expr): Use new function (with relocate=1).
* coff-objfmt.c (coff_objfmt_output_expr): Likewise.
* expr.c (yasm_expr_extract_segment): Renamed to yasm_expr_extract_segoff, a
more approprate name given what operator it looks at.
* expr.h (yasm_expr_extract_segment): Likewise.
* x86bc.c (x86_bc_jmp_tobytes): Use new function name.
* expr.c (yasm_expr_extract_seg): New function to remove SEG unary operator.
* expr.h (yasm_expr_extract_seg): Likewise.
* expr.c (yasm_expr_extract_shr): New function to split SHR operator into
left and right halves.
* expr.h (yasm_expr_extract_shr): Likewise.
* xdf.h: New header file describing the newly added Extended Dynamic Object
Format (XDF). Note: GCC-only code.
* xdfdump.c: New utility that uses the format described in xdf.h to
completely dump an XDF file. Note: non-portable code (runs correctly on
little endian machines only).
Neither of these files are currently included in the distribution.
* xdf-objfmt.c: New YASM objfmt module to output XDF format object files.
* modules/objfmts/xdf/Makefile.inc: Add to build.
* modules/objfmts/Makefile.inc: Likewise.
The XDF object format is a blend between COFF and OMF. It is a very simple
object format intended for use by operating system loaders or similar types
of targets. It allows shifted relocations (useful for static interrupt or
page tables), both flat and segment-relative, and the use of the SEG, WRT,
and x86 JMP FAR notations.
Peter Johnson [Sat, 25 Sep 2004 06:38:57 +0000 (06:38 -0000)]
* util.h (BitCount): Change bit-counting algorithm; the old one miscounted
4096 (0x1000) as having 257 bits; almost certainly other values were broken
as well.
Peter Johnson [Mon, 13 Sep 2004 02:44:00 +0000 (02:44 -0000)]
* bc-int.h (yasm_bytecode): Add new pointer to array symrecs. This is a
NULL-terminated array of labels that point to this bytecode (as the bytecode
previous to the label). NULL if no labels point to this bytecode.
Michael Urman [Mon, 13 Sep 2004 00:01:03 +0000 (00:01 -0000)]
Add a final SO for any .text section. This is used to identify the end
of the final function.
FIXME: This creates a symbol (label .n_so) which currently has to be
added to the symtab. Peter thinks it should work fine outside the table,
so perhaps this is a bug in elf. Currently without being in the table
instead of identifying the end of the function, it identifies offset 0.
Peter Johnson [Sun, 12 Sep 2004 07:57:47 +0000 (07:57 -0000)]
* ins.h, scanner.h, dfa.h, code.c, re.h, parse.h, token.h, substr.h:
Remove use of "inline". This could cause breakage on non-gcc systems (as
these files do not use config.h because of cross-build reasons).
* yasm.dep, yasm.mak, yasm.dsp, yasm.dsw: Remove support for VC6 builds.
* libyasm.dsp, libyasm.mak, libyasm.dep: Likewise.
* modules.dsp, modules.mak, modules.dep: Likewise.
* yasm.suo: Remove unneeded user options file.
* vc: Update svn:ignore property to reflect removal of VC6 builds and user
options file.
* genmacro.vcproj: Generate genmacro tool.
* genmacro/run.bat: Use genmacro to generate nasm-macros.c.
* modules.vcproj: Point to the new location for nasm-macros.c.
* re2c.vcproj: Generate re2c tool.
* re2c/run.bat: Use re2c to generate re2c-generated .c files.
Peter Johnson [Tue, 7 Sep 2004 07:39:26 +0000 (07:39 -0000)]
* configure.ac: Remove check for groff, add check for xmlto.
* Makefile: Add support for building man pages from DocBook XML refentry's
using xmlto.
* frontends/yasm/yasm.xml: New. Source XML file for yasm(1) man page.
* frontends/yasm/yasm.1: Generated yasm(1) man page. We may want to remove
this at some point, but it would have impact on those keeping up with HEAD.
* frontends/yasm/Makefile.inc: Add new yasm(1) man page to distribution and
install.
* HACKING: Update required tools list. Rename "CVS" to "Subversion".
Remove "Generating ChangeLogs" section, as with Subversion this is not
necessary.
Peter Johnson [Fri, 3 Sep 2004 23:01:51 +0000 (23:01 -0000)]
* x86id.re (yasm_x86__parse_insn): Add checking of effective address size.
* x86arch.h (x86_new_insn_data): Add shortmov_op for shortmov post-action.
* x86bc.c (x86_insn): Likewise.
(yasm_x86__bc_create_insn): Copy shortmov_op to instruction.
(x86_bc_insn_resolve): Handle shortmov_op post-action.
* x86id.re (yasm_x86__parse_insn): Set shortmov_op post-action if desired.
* x86id.re (mov_insn): Through reorder and use of new shortmov_op
post-action, change generated code for mov on AMD64. On AMD64, the short
mov (opcode A0/A1/A2/A3), generated when moving to AL/AX/EAX/RAX from an
absolute address (no registers) has a 64-bit size in 64-bit mode. While an
address override can reduce it to 32-bits, automatically generating such an
override does not fit well with the model of not doing anything behind the
programmer's back. Instead, we now generate the 32-bit address size MOD/RM
form unless the address size is specifically set to 64 bits using [qword 0]
notation (this is the equivalent of the GNU AS movabs pseudo-instruction).
The short mov is still generated in 32-bit mode, whether obtained via BITS
setting or an a32 prefix in BITS 64 mode. (The a32 prefix handling
necessitated the new shortmov post-action.) Examples (pulled from new
mem64.asm):
Peter Johnson [Wed, 1 Sep 2004 07:10:14 +0000 (07:10 -0000)]
* configure.ac, Mkfiles/*/config.h: Stop using date command / CVS string,
switch to constant use of "HEAD" instead. This will be replaced by the SVN
tree revision for automated builds.
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).