- Add win64 as an alias for -f win32 -m amd64.

- Add elf32 as an alias for -f elf.
- Add elf64 as an alias for -f elf -m amd64.
Note the old command lines still work.

Add a testcase for win64 (includes masm -> yasm mapping, look at
win64-dataref.masm and win64-dataref.asm files respectively).

svn path=/trunk/yasm/; revision=1252
0.5.0rc2
Peter Johnson 19 years ago
parent 253056c994
commit f1d4bb2670
  1. 26
      frontends/yasm/yasm.c
  2. 2
      modules/objfmts/Makefile.inc
  3. 78
      modules/objfmts/coff/coff-objfmt.c
  4. 2
      modules/objfmts/elf/Makefile.inc
  5. 6
      modules/objfmts/elf/elf-machine.h
  6. 86
      modules/objfmts/elf/elf-objfmt.c
  7. 3
      modules/objfmts/elf/elf-x86-amd64.c
  8. 3
      modules/objfmts/elf/elf-x86-x86.c
  9. 11
      modules/objfmts/elf/elf.c
  10. 6
      modules/objfmts/elf/elf.h
  11. 9
      modules/objfmts/win64/Makefile.inc
  12. 5
      modules/objfmts/win64/tests/Makefile.inc
  13. 109
      modules/objfmts/win64/tests/win64-dataref.asm
  14. 0
      modules/objfmts/win64/tests/win64-dataref.errwarn
  15. 1649
      modules/objfmts/win64/tests/win64-dataref.hex
  16. 110
      modules/objfmts/win64/tests/win64-dataref.masm
  17. 4
      modules/objfmts/win64/tests/win64_test.sh

@ -432,8 +432,18 @@ main(int argc, char *argv[])
/* Set up architecture using the selected (or default) machine and
* selected (or default nasm) parser.
*/
if (!machine_name)
machine_name = yasm__xstrdup(cur_arch_module->default_machine_keyword);
if (!machine_name) {
/* If we're using x86 and the default objfmt bits is 64, default the
* machine to amd64. When we get more arches with multiple machines,
* we should do this in a more modular fashion.
*/
if (strcmp(cur_arch_module->keyword, "x86") == 0 &&
cur_objfmt_module->default_x86_mode_bits == 64)
machine_name = yasm__xstrdup("amd64");
else
machine_name =
yasm__xstrdup(cur_arch_module->default_machine_keyword);
}
cur_arch = cur_arch_module->create(machine_name,
cur_parser_module->keyword,
@ -538,6 +548,9 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
}
/* Get a fresh copy of objfmt_module as it may have changed. */
cur_objfmt_module = ((yasm_objfmt_base *)cur_objfmt)->module;
/* Add an initial "default" section to object */
def_sect = yasm_objfmt_add_default_section(cur_objfmt, object);
@ -593,13 +606,10 @@ main(int argc, char *argv[])
apply_preproc_builtins();
apply_preproc_saved_options();
/* Get initial x86 BITS setting from object format except for amd64 mode */
/* Get initial x86 BITS setting from object format */
if (strcmp(cur_arch_module->keyword, "x86") == 0) {
if (strcmp(machine_name, "amd64") == 0)
yasm_arch_set_var(cur_arch, "mode_bits", 64);
else
yasm_arch_set_var(cur_arch, "mode_bits",
cur_objfmt_module->default_x86_mode_bits);
yasm_arch_set_var(cur_arch, "mode_bits",
cur_objfmt_module->default_x86_mode_bits);
}
/* Parse! */

@ -6,6 +6,7 @@ EXTRA_DIST += modules/objfmts/elf/Makefile.inc
#!EXTRA_DIST += modules/objfmts/omf/Makefile.inc
EXTRA_DIST += modules/objfmts/coff/Makefile.inc
EXTRA_DIST += modules/objfmts/win32/Makefile.inc
EXTRA_DIST += modules/objfmts/win64/Makefile.inc
EXTRA_DIST += modules/objfmts/xdf/Makefile.inc
include modules/objfmts/dbg/Makefile.inc
@ -14,4 +15,5 @@ include modules/objfmts/elf/Makefile.inc
#!include modules/objfmts/omf/Makefile.inc
include modules/objfmts/coff/Makefile.inc
include modules/objfmts/win32/Makefile.inc
include modules/objfmts/win64/Makefile.inc
include modules/objfmts/xdf/Makefile.inc

@ -213,6 +213,7 @@ static const yasm_assoc_data_callback coff_symrec_data_cb = {
yasm_objfmt_module yasm_coff_LTX_objfmt;
yasm_objfmt_module yasm_win32_LTX_objfmt;
yasm_objfmt_module yasm_win64_LTX_objfmt;
static /*@dependent@*/ coff_symrec_data *
@ -252,16 +253,6 @@ coff_common_create(const char *in_filename, yasm_object *object, yasm_arch *a)
return NULL;
}
/* Support x86 and amd64 machines of x86 arch */
if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) {
objfmt_coff->machine = COFF_MACHINE_I386;
} else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) {
objfmt_coff->machine = COFF_MACHINE_AMD64;
} else {
yasm_xfree(objfmt_coff);
return NULL;
}
objfmt_coff->parse_scnum = 1; /* section numbering starts at 1 */
/* FIXME: misuse of NULL bytecode here; it works, but only barely. */
@ -279,7 +270,18 @@ coff_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
{
yasm_objfmt_coff *objfmt_coff =
coff_common_create(in_filename, object, a);
if (objfmt_coff) {
/* Support x86 and amd64 machines of x86 arch */
if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) {
objfmt_coff->machine = COFF_MACHINE_I386;
} else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) {
objfmt_coff->machine = COFF_MACHINE_AMD64;
} else {
yasm_xfree(objfmt_coff);
return NULL;
}
objfmt_coff->objfmt.module = &yasm_coff_LTX_objfmt;
objfmt_coff->win32 = 0;
}
@ -291,8 +293,43 @@ win32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
{
yasm_objfmt_coff *objfmt_coff =
coff_common_create(in_filename, object, a);
if (objfmt_coff) {
/* Support x86 and amd64 machines of x86 arch.
* (amd64 machine supported for backwards compatibility)
*/
if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) {
objfmt_coff->machine = COFF_MACHINE_I386;
objfmt_coff->objfmt.module = &yasm_win32_LTX_objfmt;
} else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) {
objfmt_coff->machine = COFF_MACHINE_AMD64;
objfmt_coff->objfmt.module = &yasm_win64_LTX_objfmt;
} else {
yasm_xfree(objfmt_coff);
return NULL;
}
objfmt_coff->win32 = 1;
}
return (yasm_objfmt *)objfmt_coff;
}
static yasm_objfmt *
win64_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
{
yasm_objfmt_coff *objfmt_coff =
coff_common_create(in_filename, object, a);
if (objfmt_coff) {
objfmt_coff->objfmt.module = &yasm_win32_LTX_objfmt;
/* Support amd64 machine of x86 arch */
if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) {
objfmt_coff->machine = COFF_MACHINE_AMD64;
} else {
yasm_xfree(objfmt_coff);
return NULL;
}
objfmt_coff->objfmt.module = &yasm_win64_LTX_objfmt;
objfmt_coff->win32 = 1;
}
return (yasm_objfmt *)objfmt_coff;
@ -1407,3 +1444,22 @@ yasm_objfmt_module yasm_win32_LTX_objfmt = {
coff_objfmt_common_declare,
win32_objfmt_directive
};
/* Define objfmt structure -- see objfmt.h for details */
yasm_objfmt_module yasm_win64_LTX_objfmt = {
"Win64",
"win64",
"obj",
".text",
64,
coff_objfmt_dbgfmt_keywords,
"null",
win64_objfmt_create,
coff_objfmt_output,
coff_objfmt_destroy,
coff_objfmt_section_switch,
coff_objfmt_extern_declare,
coff_objfmt_global_declare,
coff_objfmt_common_declare,
win32_objfmt_directive
};

@ -7,7 +7,7 @@ libyasm_a_SOURCES += modules/objfmts/elf/elf-machine.h
libyasm_a_SOURCES += modules/objfmts/elf/elf-x86-x86.c
libyasm_a_SOURCES += modules/objfmts/elf/elf-x86-amd64.c
YASM_MODULES += objfmt_elf
YASM_MODULES += objfmt_elf objfmt_elf32 objfmt_elf64
EXTRA_DIST += modules/objfmts/elf/tests/Makefile.inc

@ -74,7 +74,7 @@ typedef struct {
const int sym_rel; /* symbol or section-relative? */
} elf_machine_ssym;
typedef struct {
struct elf_machine_handler {
const char *arch;
const char *machine;
const char *reloc_section_prefix;
@ -94,6 +94,8 @@ typedef struct {
const elf_machine_ssym *ssyms; /* array of "special" syms */
const size_t num_ssyms; /* size of array */
} elf_machine_handler;
const int bits; /* usually 32 or 64 */
};
#endif /* ELF_MACHINE_H_INCLUDED */

@ -50,6 +50,7 @@
#include <libyasm.h>
#include "elf.h"
#include "elf-machine.h"
typedef struct yasm_objfmt_elf {
yasm_objfmt_base objfmt; /* base structure */
@ -80,6 +81,8 @@ typedef struct {
} append_local_sym_info;
yasm_objfmt_module yasm_elf_LTX_objfmt;
yasm_objfmt_module yasm_elf32_LTX_objfmt;
yasm_objfmt_module yasm_elf64_LTX_objfmt;
static elf_symtab_entry *
@ -146,20 +149,27 @@ elf_objfmt_append_local_sym(yasm_symrec *sym, /*@null@*/ void *d)
}
static yasm_objfmt *
elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
elf_objfmt_create_common(const char *in_filename, yasm_object *object,
yasm_arch *a, yasm_objfmt_module *module,
int bits_pref,
const elf_machine_handler **elf_march_out)
{
yasm_objfmt_elf *objfmt_elf = yasm_xmalloc(sizeof(yasm_objfmt_elf));
yasm_symrec *filesym;
elf_symtab_entry *entry;
const elf_machine_handler *elf_march;
objfmt_elf->objfmt.module = &yasm_elf_LTX_objfmt;
objfmt_elf->objfmt.module = module;
objfmt_elf->object = object;
objfmt_elf->symtab = yasm_object_get_symtab(object);
objfmt_elf->arch = a;
if (!elf_set_arch(a, objfmt_elf->symtab)) {
elf_march = elf_set_arch(a, objfmt_elf->symtab, bits_pref);
if (!elf_march) {
yasm_xfree(objfmt_elf);
return NULL;
}
if (elf_march_out)
*elf_march_out = elf_march;
objfmt_elf->shstrtab = elf_strtab_create();
objfmt_elf->strtab = elf_strtab_create();
@ -181,6 +191,40 @@ elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
return (yasm_objfmt *)objfmt_elf;
}
static yasm_objfmt *
elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
{
const elf_machine_handler *elf_march;
yasm_objfmt *objfmt;
yasm_objfmt_elf *objfmt_elf;
objfmt = elf_objfmt_create_common(in_filename, object, a,
&yasm_elf_LTX_objfmt, 0, &elf_march);
if (objfmt) {
objfmt_elf = (yasm_objfmt_elf *)objfmt;
/* Figure out which bitness of object format to use */
if (elf_march->bits == 32)
objfmt_elf->objfmt.module = &yasm_elf32_LTX_objfmt;
else if (elf_march->bits == 64)
objfmt_elf->objfmt.module = &yasm_elf64_LTX_objfmt;
}
return objfmt;
}
static yasm_objfmt *
elf32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
{
return elf_objfmt_create_common(in_filename, object, a,
&yasm_elf32_LTX_objfmt, 32, NULL);
}
static yasm_objfmt *
elf64_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a)
{
return elf_objfmt_create_common(in_filename, object, a,
&yasm_elf64_LTX_objfmt, 64, NULL);
}
static long
elf_objfmt_output_align(FILE *f, unsigned int align)
{
@ -980,3 +1024,39 @@ yasm_objfmt_module yasm_elf_LTX_objfmt = {
elf_objfmt_common_declare,
elf_objfmt_directive
};
yasm_objfmt_module yasm_elf32_LTX_objfmt = {
"ELF (32-bit)",
"elf32",
"o",
".text",
32,
elf_objfmt_dbgfmt_keywords,
"null",
elf32_objfmt_create,
elf_objfmt_output,
elf_objfmt_destroy,
elf_objfmt_section_switch,
elf_objfmt_extern_declare,
elf_objfmt_global_declare,
elf_objfmt_common_declare,
elf_objfmt_directive
};
yasm_objfmt_module yasm_elf64_LTX_objfmt = {
"ELF (64-bit)",
"elf64",
"o",
".text",
64,
elf_objfmt_dbgfmt_keywords,
"null",
elf64_objfmt_create,
elf_objfmt_output,
elf_objfmt_destroy,
elf_objfmt_section_switch,
elf_objfmt_extern_declare,
elf_objfmt_global_declare,
elf_objfmt_common_declare,
elf_objfmt_directive
};

@ -233,5 +233,6 @@ elf_machine_handler_x86_amd64 = {
elf_x86_amd64_write_reloc,
elf_x86_amd64_write_proghead,
elf_x86_amd64_ssyms,
sizeof(elf_x86_amd64_ssyms)/sizeof(elf_x86_amd64_ssyms[0])
sizeof(elf_x86_amd64_ssyms)/sizeof(elf_x86_amd64_ssyms[0]),
64
};

@ -223,5 +223,6 @@ elf_machine_handler_x86_x86 = {
elf_x86_x86_write_reloc,
elf_x86_x86_write_proghead,
elf_x86_x86_ssyms,
sizeof(elf_x86_x86_ssyms)/sizeof(elf_x86_x86_ssyms[0])
sizeof(elf_x86_x86_ssyms)/sizeof(elf_x86_x86_ssyms[0]),
32
};

@ -63,12 +63,12 @@ static const elf_machine_handler *elf_machine_handlers[] =
};
static const elf_machine_handler elf_null_machine = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0};
0, 0, 0};
static elf_machine_handler const *elf_march = &elf_null_machine;
static yasm_symrec **elf_ssyms;
int
elf_set_arch(yasm_arch *arch, yasm_symtab *symtab)
const elf_machine_handler *
elf_set_arch(yasm_arch *arch, yasm_symtab *symtab, int bits_pref)
{
const char *machine = yasm_arch_get_machine(arch);
int i;
@ -79,7 +79,8 @@ elf_set_arch(yasm_arch *arch, yasm_symtab *symtab)
{
if (yasm__strcasecmp(yasm_arch_keyword(arch), elf_march->arch)==0)
if (yasm__strcasecmp(machine, elf_march->machine)==0)
break;
if (bits_pref == 0 || bits_pref == elf_march->bits)
break;
}
if (elf_march && elf_march->num_ssyms > 0)
@ -96,7 +97,7 @@ elf_set_arch(yasm_arch *arch, yasm_symtab *symtab)
}
}
return elf_march != NULL;
return elf_march;
}
/* reloc functions */

@ -36,6 +36,8 @@ typedef struct elf_strtab_head elf_strtab_head;
typedef struct elf_symtab_entry elf_symtab_entry;
typedef struct elf_symtab_head elf_symtab_head;
typedef struct elf_machine_handler elf_machine_handler;
typedef unsigned long elf_address;
typedef unsigned long elf_offset;
typedef unsigned long elf_size;
@ -399,7 +401,9 @@ extern const yasm_assoc_data_callback elf_section_data;
extern const yasm_assoc_data_callback elf_symrec_data;
int elf_set_arch(struct yasm_arch *arch, yasm_symtab *symtab);
const elf_machine_handler *elf_set_arch(struct yasm_arch *arch,
yasm_symtab *symtab,
int bits_pref);
/* reloc functions */
int elf_is_wrt_sym_relative(yasm_symrec *wrt);

@ -0,0 +1,9 @@
# $Id$
# Assume objfmt_coff is included
YASM_MODULES += objfmt_win64
EXTRA_DIST += modules/objfmts/win64/tests/Makefile.inc
include modules/objfmts/win64/tests/Makefile.inc

@ -0,0 +1,5 @@
# $Id$
TESTS += modules/objfmts/win64/tests/win64_test.sh
EXTRA_DIST += modules/objfmts/win32/tests/win64_test.sh

@ -0,0 +1,109 @@
BITS 64
global x86ident
global __savident
extern foobar ; :proc
extern foobar2 ; :abs
extern foobar3 ; :qword
extern foobar4 ; :byte
[SECTION .data]
__savident dd 0
savidentptr dd __savident
savidentptr2 dq __savident
x86identptr dd x86ident
x86identptr2 dq x86ident
foobarptr dd foobar
foobarptr2 dq foobar
foobar2ptr dd foobar2
foobar2ptr2 dq foobar2
foobar3ptr dd foobar3
foobar3ptr2 dq foobar3
xptr dd x
xptr2 dq x
[SECTION .bss]
x resq 1
[SECTION .text]
x86ident:
; with :proc
mov ebx, foobar ; WTF ML64.. this had []
mov rcx, foobar
lea rdx, [foobar wrt rip]
mov rax, [foobar+rcx]
mov rax, foobar
mov rbx, foobar
movzx rax, byte [foobar wrt rip]
movzx rax, byte [foobar+rax]
; with :abs
;mov ebx,[foobar2]
;mov rcx,offset foobar2
;lea rdx, foobar2
;mov rax, qword ptr foobar2[rcx]
;mov rax, foobar2
;mov rbx, foobar2
;movzx rax, byte ptr foobar2
;movzx rax, byte ptr foobar2[rax]
; with :qword
mov ebx, [foobar3 wrt rip]
mov rcx, foobar3
lea rdx, [foobar3 wrt rip]
mov rax, [foobar3+rcx]
mov rax, [foobar3 wrt rip]
mov rbx, [foobar3 wrt rip]
movzx rax, byte [foobar3 wrt rip]
movzx rax, byte [foobar3+rax]
; local var (dword)
mov ebx,[__savident wrt rip]
mov rcx, __savident
lea rdx, [__savident wrt rip]
mov rax, [__savident+rcx]
mov rax, [__savident wrt rip]
mov rbx, [__savident wrt rip]
movzx rax, byte [__savident wrt rip]
movzx rax, byte [__savident+rax]
; local var (qword)
mov ebx, [savidentptr2 wrt rip]
mov rcx, savidentptr2
lea rdx, [savidentptr2 wrt rip]
mov rax, [savidentptr2+rcx]
mov rax, [savidentptr2 wrt rip]
mov rbx, [savidentptr2 wrt rip]
movzx rax, byte [savidentptr2 wrt rip]
movzx rax, byte [savidentptr2+rax]
call foobar
ret
trap: sub rsp, 256
int3
add rsp, 256
.end
[SECTION .pdata]
dd trap
dd trap.end
dd $xdatasym
[SECTION .xdata]
$xdatasym:
db 1, 7, 2, 0, 7, 1, 0x20, 0
[SECTION _FOO]
foo_foobar3ptr dd foobar3
foo_foobar3ptr2 dq foobar3
mov ebx, [foobar3 wrt rip]
mov rcx, foobar3
lea rdx, [foobar3 wrt rip]
mov rax, [foobar3+rcx]
mov rax, [foobar3 wrt rip]
mov rbx, [foobar3 wrt rip]
movzx rax, byte [foobar3 wrt rip]
movzx rax, byte [foobar3+rax]

File diff suppressed because it is too large Load Diff

@ -0,0 +1,110 @@
public x86ident
public __savident
extrn foobar : proc
extrn foobar2 : abs
extrn foobar3 : qword
extrn foobar4 : byte
_DATA SEGMENT
__savident dd 0
savidentptr dd __savident
savidentptr2 dq __savident
x86identptr dd x86ident
x86identptr2 dq x86ident
foobarptr dd foobar
foobarptr2 dq foobar
foobar2ptr dd foobar2
foobar2ptr2 dq foobar2
foobar3ptr dd foobar3
foobar3ptr2 dq foobar3
xptr dd x
xptr2 dq x
;dataptr dd offset _DATA
;dataptr2 dq offset _DATA
;codeptr dd offset _TEXT
;codeptr2 dq offset _TEXT
_DATA ENDS
_BSS SEGMENT
x dq ?
_BSS ENDS
_TEXT SEGMENT
x86ident:
; with :proc
mov ebx,[foobar]
mov rcx,offset foobar
lea rdx, foobar
mov rax, qword ptr foobar[rcx]
mov rax, foobar
mov rbx, foobar
movzx rax, byte ptr foobar
movzx rax, byte ptr foobar[rax]
; with :abs
;mov ebx,[foobar2]
;mov rcx,offset foobar2
;lea rdx, foobar2
;mov rax, qword ptr foobar2[rcx]
;mov rax, foobar2
;mov rbx, foobar2
;movzx rax, byte ptr foobar2
;movzx rax, byte ptr foobar2[rax]
; with :qword
mov ebx, dword ptr [foobar3]
mov rcx,offset foobar3
lea rdx, foobar3
mov rax, qword ptr foobar3[rcx]
mov rax, foobar3
mov rbx, foobar3
movzx rax, byte ptr foobar3
movzx rax, byte ptr foobar3[rax]
; local var (dword)
mov ebx,[__savident]
mov rcx,offset __savident
lea rdx, __savident
mov rax, qword ptr __savident[rcx]
mov rax, qword ptr __savident
mov rbx, qword ptr __savident
movzx rax, byte ptr __savident
movzx rax, byte ptr __savident[rax]
; local var (qword)
mov ebx, dword ptr [savidentptr2]
mov rcx,offset savidentptr2
lea rdx, savidentptr2
mov rax, savidentptr2[rcx]
mov rax, savidentptr2
mov rbx, savidentptr2
movzx rax, byte ptr savidentptr2
movzx rax, byte ptr savidentptr2[rax]
call foobar
ret
trap proc public frame
sub rsp, 256
.allocstack 256
.endprolog
int 3
add rsp, 256
trap endp
_TEXT ENDS
_FOO SEGMENT
foo_foobar3ptr dd foobar3
foo_foobar3ptr2 dq foobar3
mov ebx, dword ptr [foobar3]
mov rcx,offset foobar3
lea rdx, foobar3
mov rax, qword ptr foobar3[rcx]
mov rax, foobar3
mov rbx, foobar3
movzx rax, byte ptr foobar3
movzx rax, byte ptr foobar3[rax]
_FOO ENDS
END

@ -0,0 +1,4 @@
#! /bin/sh
# $Id$
${srcdir}/out_test.sh win64_test modules/objfmts/win64/tests "win64 objfmt" "-f win64" ".obj"
exit $?
Loading…
Cancel
Save