yasm/modules
Peter Johnson 23e53d41ce Fix #44 by adding support for WRT special symbols (e.g. [sym WRT ..plt] and
similar) to ELF.  They are used identically to NASM's ELF shared object
support.

Due to limited WRT support throughout libyasm, this caused a lot of rippling
changes.  A major cleanup needs to be performed later to clear some of this
hackiness up.

* elf-machine.h (func_accepts_size_t): Rename to func_accepts_reloc().
(func_map_reloc_info_to_type): Add parameter ssyms for array of special syms.
(elf_machine_ssym): New; for defining machine-specific special syms.
(elf_machine_handler): Change accepts_reloc_size to accepts_reloc.  Add new
ssyms and num_ssyms members.

* elf-x86-x86.c (ssym_index): New; this allows nice indexing of ssym arrays.
(elf_x86_x86_accepts_reloc): Rename of elf_x86_x86_accepts_reloc_size.  Add
support for various WRT ssyms.
(elf_x86_x86_map_reloc_info_to_type): Add support for various WRT ssyms.
(elf_x86_x86_ssyms): New array of supported special symbols.
(elf_machine_handler_x86_x86): Update for above changes/additions.
* elf-x86-amd64.c (ssym_index, elf_x86_amd64_accepts_reloc)
(elf_x86_amd64_map_reloc_info_to_type, elf_x86_amd64_ssyms)
(elf_machine_handler_x86_amd64): Likewise.

* elf.h (elf_reloc_entry): Add wrt member.
(elf_set_arch): Add symtab parameter.
(elf_is_wrt_sym_relative): New.
(elf_reloc_entry_create): Add wrt parameter.
* elf.c (elf_set_arch): Allocate special syms from machine level.
(elf_is_wrt_sym_relative): New; search special syms, and report whether a
WRT ssym should be symbol-relative or section-relative.
(elf_reloc_entry_create): Pass WRT and ssyms info down to machine level.

* elf-objfmt.c (yasm_objfmt_elf): Add dotdotsym (..sym) symrec member.
(elf_objfmt_create): Pass symtab to elf_set_arch().  Allocate ..sym symbol.
(elf_objfmt_output_reloc): Update for elf_reloc_entry_create() change.
(elf_objfmt_output_expr): Handle WRT ssym.  Make relocation symbol-relative
rather than section-relative if either WRT ..sym or WRT ssym that machine
level desires to be symbol-relative.

* symrec.c (yasm_symrec_get_label): Check for NULL sym->value.precbc; this
is now possible due to the user-accessible special symbols that ELF et al
create, which all have NULL precbc's.

* expr.c (yasm_expr_extract_symrec): Recurse into IDENT's to make more exprs
acceptable.

* coretype.h (yasm_output_reloc_func): Remove rel parameter as it shouldn't
be needed and complexifies writing of the reloc functions.
* stabs-dbgfmt.c (stabs_bc_stab_tobytes): Update output_reloc() call.
* elf-objfmt.c (elf_objfmt_output_reloc): Update to match.

* arch.h (yasm_arch_module): Add intnum_fixup_rel() function, change
intnum_tobytes() to not take rel parameter.  The rel functionality is being
separated because sometimes it's desirable not to put the data into the
written intnum (e.g. ELF RELA relocations).
(YASM_ARCH_VERSION): Bump due to above change.
(yasm_arch_intnum_fixup_rel): New wrapper.
(yasm_arch_intnum_tobytes): Update wrapper (removing rel).

* lc3bbc.c (yasm_lc3b__intnum_fixup_rel): New, with code from:
(yasm_lc3b__intnum_tobytes): Remove rel code.
* lc3barch.h (yasm_lc3b__intnum_fixup_rel): New.
(yasm_lc3b__intnum_tobytes): Update.
* lc3barch.c (yasm_lc3b_LTX_arch): Reference yasm_lc3b__intnum_fixup_rel().

* x86bc.c (yasm_x86__intnum_fixup_rel): New, with code from:
(yasm_x86__intnum_tobytes): Remove rel code.
* x86arch.h (yasm_x86__intnum_fixup_rel): New.
(yasm_x86__intnum_tobytes): Update.
* x86arch.c (yasm_x86_LTX_arch): Reference yasm_x86__intnum_fixup_rel().

* xdf-objfmt.c (xdf_objfmt_output_expr): Update to use intnum_fixup_rel() /
new intnum_tobytes().
* bin-objfmt.c (bin_objfmt_output_expr): Likewise.
* coff-objfmt.c (coff_objfmt_output_expr): Likewise.
* elf-objfmt.c (elf_objfmt_output_expr: Likewise.
* nasm-listfmt.c (nasm_listfmt_output_expr): Likewise.

* nasm-bison.y: Change precedence of WRT and : operators: instead of being
the strongest binders they are now the weakest.  This is needed to correctly
parse and be able to split WRT expressions.  WRT handling is still somewhat
of a hack throughout yasm; we'll fix this later.

* x86expr.c (x86_expr_checkea_distcheck_reg): Don't check for WRT here.
(x86_expr_checkea_getregusage): Add new wrt parameter.  Use it to handle
"WRT rip" separately from other operators.  Recurse if there's a WRT below
the WRT rip; this is to handle cases like ELF-AMD64's elfso64.asm.
(yasm_x86__expr_checkea): Split off top-level WRT's and feed through
separately to x86_expr_checkea_getregusage().

* x86bc.c (x86_bc_insn_tobytes): Ensure the SUB operation for PC-relative
displacements goes BELOW any WRT expression.
(x86_bc_jmp_tobytes): Likewise.

* elfso.asm, elfso.hex, elfso.errwarn: New 32-bit ELF shared object tests.
* modules/objfmts/elf/tests/Makefile.inc: Include in distribution.

* elfso64.asm, elfso64.hex, elfso64.errwarn: New 64-bit ELF shared object
tests.  This is not a good example, as the assembled code doesn't work, but
it at least tests the special symbols.
* modules/objfmts/elf/tests/amd64/Makefile.inc: Include in distribution.


svn path=/trunk/yasm/; revision=1168
2004-10-31 01:07:52 +00:00
..
arch Fix #44 by adding support for WRT special symbols (e.g. [sym WRT ..plt] and 2004-10-31 01:07:52 +00:00
dbgfmts Fix #44 by adding support for WRT special symbols (e.g. [sym WRT ..plt] and 2004-10-31 01:07:52 +00:00
listfmts Fix #44 by adding support for WRT special symbols (e.g. [sym WRT ..plt] and 2004-10-31 01:07:52 +00:00
objfmts Fix #44 by adding support for WRT special symbols (e.g. [sym WRT ..plt] and 2004-10-31 01:07:52 +00:00
optimizers * On most files: re-enable $IdPath$ as $Id$, and enable Id keyword expansion. 2004-09-04 01:24:57 +00:00
parsers Fix #44 by adding support for WRT special symbols (e.g. [sym WRT ..plt] and 2004-10-31 01:07:52 +00:00
preprocs * On most files: re-enable $IdPath$ as $Id$, and enable Id keyword expansion. 2004-09-04 01:24:57 +00:00
Makefile.inc First part of list file support. This should accurately output all file 2004-10-02 06:18:30 +00:00