aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-06-26 11:34:50 -0700
committerPeter Johnson <peter@tortall.net>2012-08-30 23:47:41 -0700
commit510c8dd7e6b28413350652b4b0284a1ae52ed96f (patch)
tree00c72ccb691070c3e358ba1ffe5a1b5c9cd5c4d3
parent9728322335cba96500861ef766b1546d096e5600 (diff)
downloadyasm-510c8dd7e6b28413350652b4b0284a1ae52ed96f.tar.gz
Add support for x32
X32 is a 32-bit psABI for x86-64 with 32-bit pointer size. More info can be found at: https://sites.google.com/site/x32abi/
-rw-r--r--Mkfiles/Makefile.dj2
-rw-r--r--Mkfiles/Makefile.flat2
-rw-r--r--frontends/yasm/yasm.c12
-rw-r--r--modules/arch/x86/x86arch.c28
-rw-r--r--modules/arch/x86/x86arch.h1
-rw-r--r--modules/arch/yasm_arch.xml4
-rw-r--r--modules/objfmts/elf/CMakeLists.txt2
-rw-r--r--modules/objfmts/elf/Makefile.inc3
-rw-r--r--modules/objfmts/elf/elf-objfmt.c30
-rw-r--r--modules/objfmts/elf/elf-x86-x32.c251
-rw-r--r--modules/objfmts/elf/elf.c10
-rw-r--r--modules/objfmts/elf/tests/Makefile.inc4
-rw-r--r--modules/objfmts/elf/tests/gasx32/Makefile.inc11
-rw-r--r--modules/objfmts/elf/tests/gasx32/crosssect.asm18
-rw-r--r--modules/objfmts/elf/tests/gasx32/crosssect.hex568
-rw-r--r--modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.asm27
-rw-r--r--modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.hex848
-rw-r--r--modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.asm37
-rw-r--r--modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.hex1016
-rw-r--r--modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.asm10
-rw-r--r--modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.hex592
-rwxr-xr-xmodules/objfmts/elf/tests/gasx32/elf_gasx32_test.sh3
-rw-r--r--modules/objfmts/elf/tests/x32/Makefile.inc11
-rw-r--r--modules/objfmts/elf/tests/x32/elf-rip.asm7
-rw-r--r--modules/objfmts/elf/tests/x32/elf-rip.hex496
-rwxr-xr-xmodules/objfmts/elf/tests/x32/elf_x32_test.sh3
-rw-r--r--modules/objfmts/elf/tests/x32/elfsox32.asm90
-rw-r--r--modules/objfmts/elf/tests/x32/elfsox32.hex1176
-rw-r--r--modules/objfmts/elf/tests/x32/gotpcrel.asm6
-rw-r--r--modules/objfmts/elf/tests/x32/gotpcrel.hex496
-rw-r--r--modules/objfmts/elf/tests/x32/multiplefixup.asm8
-rw-r--r--modules/objfmts/elf/tests/x32/multiplefixup.hex680
-rw-r--r--modules/objfmts/yasm_objfmts.xml11
33 files changed, 6440 insertions, 23 deletions
diff --git a/Mkfiles/Makefile.dj b/Mkfiles/Makefile.dj
index 8881b544..34773036 100644
--- a/Mkfiles/Makefile.dj
+++ b/Mkfiles/Makefile.dj
@@ -97,7 +97,7 @@ MODULES_OBJFMTS_OBJS= \
YASM_MODULES+=objfmt_dbg
YASM_MODULES+=objfmt_bin objfmt_dosexe
YASM_MODULES+=objfmt_coff objfmt_win32 objfmt_win64 objfmt_x64
-YASM_MODULES+=objfmt_elf objfmt_elf32 objfmt_elf64
+YASM_MODULES+=objfmt_elf objfmt_elf32 objfmt_elf64 objfmt_elfx32
YASM_MODULES+=objfmt_macho objfmt_macho32 objfmt_macho64
YASM_MODULES+=objfmt_rdf
YASM_MODULES+=objfmt_xdf
diff --git a/Mkfiles/Makefile.flat b/Mkfiles/Makefile.flat
index 011fbe51..e4d5b219 100644
--- a/Mkfiles/Makefile.flat
+++ b/Mkfiles/Makefile.flat
@@ -100,7 +100,7 @@ MODULES_OBJFMTS_OBJS= \
YASM_MODULES+=objfmt_dbg
YASM_MODULES+=objfmt_bin objfmt_dosexe
YASM_MODULES+=objfmt_coff objfmt_win32 objfmt_win64 objfmt_x64
-YASM_MODULES+=objfmt_elf objfmt_elf32 objfmt_elf64
+YASM_MODULES+=objfmt_elf objfmt_elf32 objfmt_elf64 objfmt_elfx32
YASM_MODULES+=objfmt_macho objfmt_macho32 objfmt_macho64
YASM_MODULES+=objfmt_rdf
YASM_MODULES+=objfmt_xdf
diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c
index ddd044bb..f070a168 100644
--- a/frontends/yasm/yasm.c
+++ b/frontends/yasm/yasm.c
@@ -355,6 +355,7 @@ do_assemble(void)
yasm_linemap *linemap;
yasm_errwarns *errwarns = yasm_errwarns_create();
int i, matched;
+ const char *machine;
/* Initialize line map */
linemap = yasm_linemap_create();
@@ -391,7 +392,16 @@ do_assemble(void)
yasm__xstrdup(cur_arch_module->default_machine_keyword);
}
- cur_arch = yasm_arch_create(cur_arch_module, machine_name,
+ /* If we're using amd64 and the default objfmt is elfx32, change the
+ * machine to "x32".
+ */
+ if (strcmp(machine_name, "amd64") == 0 &&
+ strcmp(cur_objfmt_module->keyword, "elfx32") == 0)
+ machine = "x32";
+ else
+ machine = machine_name;
+
+ cur_arch = yasm_arch_create(cur_arch_module, machine,
cur_parser_module->keyword, &arch_error);
if (!cur_arch) {
switch (arch_error) {
diff --git a/modules/arch/x86/x86arch.c b/modules/arch/x86/x86arch.c
index 833e94cd..bac11774 100644
--- a/modules/arch/x86/x86arch.c
+++ b/modules/arch/x86/x86arch.c
@@ -39,14 +39,20 @@ x86_create(const char *machine, const char *parser,
/*@out@*/ yasm_arch_create_error *error)
{
yasm_arch_x86 *arch_x86;
- unsigned int amd64_machine;
+ unsigned int amd64_machine, address_size;
*error = YASM_ARCH_CREATE_OK;
- if (yasm__strcasecmp(machine, "x86") == 0)
+ if (yasm__strcasecmp(machine, "x86") == 0) {
amd64_machine = 0;
- else if (yasm__strcasecmp(machine, "amd64") == 0)
+ address_size = 32;
+ } else if (yasm__strcasecmp(machine, "amd64") == 0) {
amd64_machine = 1;
+ address_size = 64;
+ } else if (yasm__strcasecmp(machine, "x32") == 0) {
+ amd64_machine = 1;
+ address_size = 32;
+ }
else {
*error = YASM_ARCH_CREATE_BAD_MACHINE;
return NULL;
@@ -65,6 +71,7 @@ x86_create(const char *machine, const char *parser,
arch_x86->amd64_machine = amd64_machine;
arch_x86->mode_bits = 0;
+ arch_x86->address_size = address_size;
arch_x86->force_strict = 0;
arch_x86->default_rel = 0;
arch_x86->gas_intel_mode = 0;
@@ -101,9 +108,12 @@ static const char *
x86_get_machine(const yasm_arch *arch)
{
const yasm_arch_x86 *arch_x86 = (const yasm_arch_x86 *)arch;
- if (arch_x86->amd64_machine)
- return "amd64";
- else
+ if (arch_x86->amd64_machine) {
+ if (arch_x86->address_size == 32)
+ return "x32";
+ else
+ return "amd64";
+ } else
return "x86";
}
@@ -113,10 +123,7 @@ x86_get_address_size(const yasm_arch *arch)
const yasm_arch_x86 *arch_x86 = (const yasm_arch_x86 *)arch;
if (arch_x86->mode_bits != 0)
return arch_x86->mode_bits;
- if (arch_x86->amd64_machine)
- return 64;
- else
- return 32;
+ return arch_x86->address_size;
}
static int
@@ -583,6 +590,7 @@ x86_segreg_print(yasm_arch *arch, uintptr_t segreg, FILE *f)
static const yasm_arch_machine x86_machines[] = {
{ "IA-32 and derivatives", "x86" },
{ "AMD64", "amd64" },
+ { "X32", "x32" },
{ NULL, NULL }
};
diff --git a/modules/arch/x86/x86arch.h b/modules/arch/x86/x86arch.h
index 5c3a6cf5..14b2b2e3 100644
--- a/modules/arch/x86/x86arch.h
+++ b/modules/arch/x86/x86arch.h
@@ -105,6 +105,7 @@ typedef struct yasm_arch_x86 {
unsigned int amd64_machine;
enum x86_parser_type parser;
unsigned int mode_bits;
+ unsigned int address_size;
unsigned int force_strict;
unsigned int default_rel;
unsigned int gas_intel_mode;
diff --git a/modules/arch/yasm_arch.xml b/modules/arch/yasm_arch.xml
index a5e53ef6..a35510c0 100644
--- a/modules/arch/yasm_arch.xml
+++ b/modules/arch/yasm_arch.xml
@@ -132,7 +132,9 @@
assembled will be run in 64-bit mode. To specify an AMD64 object
file, use <option>-m amd64</option> on the Yasm command line, or
explicitly target a 64-bit object format such as <option>-f
- win64</option> or <option>-f elf64</option>.</para>
+ win64</option> or <option>-f elf64</option>. <option>-f
+ elfx32</option> can be used to select 32-bit ELF object format
+ for AMD64 processors.</para>
<refsect3>
<title>Register Changes</title>
diff --git a/modules/objfmts/elf/CMakeLists.txt b/modules/objfmts/elf/CMakeLists.txt
index c06b81d8..444e9a8b 100644
--- a/modules/objfmts/elf/CMakeLists.txt
+++ b/modules/objfmts/elf/CMakeLists.txt
@@ -3,6 +3,8 @@ YASM_ADD_MODULE(objfmt_elf
objfmts/elf/elf-objfmt.c
objfmts/elf/elf-x86-x86.c
objfmts/elf/elf-x86-amd64.c
+ objfmts/elf/elf-x86-x32.c
)
list(APPEND YASM_MODULES objfmt_elf32)
list(APPEND YASM_MODULES objfmt_elf64)
+list(APPEND YASM_MODULES objfmt_elfx32)
diff --git a/modules/objfmts/elf/Makefile.inc b/modules/objfmts/elf/Makefile.inc
index 659f867e..54657657 100644
--- a/modules/objfmts/elf/Makefile.inc
+++ b/modules/objfmts/elf/Makefile.inc
@@ -4,8 +4,9 @@ libyasm_a_SOURCES += modules/objfmts/elf/elf-objfmt.c
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
+libyasm_a_SOURCES += modules/objfmts/elf/elf-x86-x32.c
-YASM_MODULES += objfmt_elf objfmt_elf32 objfmt_elf64
+YASM_MODULES += objfmt_elf objfmt_elf32 objfmt_elf64 objfmt_elfx32
EXTRA_DIST += modules/objfmts/elf/tests/Makefile.inc
diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c
index 1cf725f0..0c3a1426 100644
--- a/modules/objfmts/elf/elf-objfmt.c
+++ b/modules/objfmts/elf/elf-objfmt.c
@@ -80,6 +80,7 @@ typedef struct {
yasm_objfmt_module yasm_elf_LTX_objfmt;
yasm_objfmt_module yasm_elf32_LTX_objfmt;
yasm_objfmt_module yasm_elf64_LTX_objfmt;
+yasm_objfmt_module yasm_elfx32_LTX_objfmt;
static elf_symtab_entry *
@@ -397,7 +398,9 @@ elf_objfmt_create(yasm_object *object)
if (objfmt) {
objfmt_elf = (yasm_objfmt_elf *)objfmt;
/* Figure out which bitness of object format to use */
- if (elf_march->bits == 32)
+ if (strcmp (elf_march->machine, "x32") == 0)
+ objfmt_elf->objfmt.module = &yasm_elfx32_LTX_objfmt;
+ else 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;
@@ -417,6 +420,12 @@ elf64_objfmt_create(yasm_object *object)
return elf_objfmt_create_common(object, &yasm_elf64_LTX_objfmt, 64, NULL);
}
+static yasm_objfmt *
+elfx32_objfmt_create(yasm_object *object)
+{
+ return elf_objfmt_create_common(object, &yasm_elfx32_LTX_objfmt, 32, NULL);
+}
+
static long
elf_objfmt_output_align(FILE *f, unsigned int align)
{
@@ -1363,3 +1372,22 @@ yasm_objfmt_module yasm_elf64_LTX_objfmt = {
elf_objfmt_section_switch,
elf_objfmt_get_special_sym
};
+
+yasm_objfmt_module yasm_elfx32_LTX_objfmt = {
+ "ELF (x32)",
+ "elfx32",
+ "o",
+ 64,
+ 0,
+ elf_objfmt_dbgfmt_keywords,
+ "null",
+ elf_objfmt_directives,
+ elf_objfmt_stdmacs,
+ elfx32_objfmt_create,
+ elf_objfmt_output,
+ elf_objfmt_destroy,
+ elf_objfmt_add_default_section,
+ elf_objfmt_init_new_section,
+ elf_objfmt_section_switch,
+ elf_objfmt_get_special_sym
+};
diff --git a/modules/objfmts/elf/elf-x86-x32.c b/modules/objfmts/elf/elf-x86-x32.c
new file mode 100644
index 00000000..40a25a12
--- /dev/null
+++ b/modules/objfmts/elf/elf-x86-x32.c
@@ -0,0 +1,251 @@
+/*
+ * ELF object format helpers - x86:x32
+ *
+ * Copyright (C) 2012 Michael Urman and H.J. Lu
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <util.h>
+
+#include <libyasm.h>
+#define YASM_OBJFMT_ELF_INTERNAL
+#include "elf.h"
+#include "elf-machine.h"
+
+static elf_machine_ssym elf_x86_x32_ssyms[] = {
+ {"plt", ELF_SSYM_SYM_RELATIVE, R_X86_64_PLT32, 32},
+ {"gotpcrel", ELF_SSYM_SYM_RELATIVE, R_X86_64_GOTPCREL, 32},
+ {"tlsgd", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_TLSGD, 32},
+ {"tlsld", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_TLSLD, 32},
+ {"gottpoff", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_GOTTPOFF, 32},
+ {"tpoff", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_TPOFF32, 32},
+ {"dtpoff", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_DTPOFF32, 32},
+ {"got", ELF_SSYM_SYM_RELATIVE, R_X86_64_GOT32, 32},
+ {"tlsdesc", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_GOTPC32_TLSDESC, 32},
+ {"tlscall", ELF_SSYM_SYM_RELATIVE|ELF_SSYM_THREAD_LOCAL,
+ R_X86_64_TLSDESC_CALL, 32}
+};
+
+static int
+elf_x86_x32_accepts_reloc(size_t val, yasm_symrec *wrt)
+{
+ if (wrt) {
+ const elf_machine_ssym *ssym = (elf_machine_ssym *)
+ yasm_symrec_get_data(wrt, &elf_ssym_symrec_data);
+ if (!ssym || val != ssym->size)
+ return 0;
+ return 1;
+ }
+ return (val&(val-1)) ? 0 : ((val & (8|16|32)) != 0);
+}
+
+static void
+elf_x86_x32_write_symtab_entry(unsigned char *bufp,
+ elf_symtab_entry *entry,
+ yasm_intnum *value_intn,
+ yasm_intnum *size_intn)
+{
+ YASM_WRITE_32_L(bufp, entry->name ? entry->name->index : 0);
+ YASM_WRITE_32I_L(bufp, value_intn);
+ YASM_WRITE_32I_L(bufp, size_intn);
+
+ YASM_WRITE_8(bufp, ELF32_ST_INFO(entry->bind, entry->type));
+ YASM_WRITE_8(bufp, ELF32_ST_OTHER(entry->vis));
+ if (entry->sect) {
+ elf_secthead *shead =
+ yasm_section_get_data(entry->sect, &elf_section_data);
+ if (!shead)
+ yasm_internal_error(N_("symbol references section without data"));
+ YASM_WRITE_16_L(bufp, shead->index);
+ } else {
+ YASM_WRITE_16_L(bufp, entry->index);
+ }
+}
+
+static void
+elf_x86_x32_write_secthead(unsigned char *bufp, elf_secthead *shead)
+{
+ YASM_WRITE_32_L(bufp, shead->name ? shead->name->index : 0);
+ YASM_WRITE_32_L(bufp, shead->type);
+ YASM_WRITE_32_L(bufp, shead->flags);
+ YASM_WRITE_32_L(bufp, 0); /* vmem address */
+ YASM_WRITE_32_L(bufp, shead->offset);
+ YASM_WRITE_32I_L(bufp, shead->size);
+
+ YASM_WRITE_32_L(bufp, shead->link);
+ YASM_WRITE_32_L(bufp, shead->info);
+
+ YASM_WRITE_32_L(bufp, shead->align);
+ YASM_WRITE_32_L(bufp, shead->entsize);
+}
+
+static void
+elf_x86_x32_write_secthead_rel(unsigned char *bufp,
+ elf_secthead *shead,
+ elf_section_index symtab_idx,
+ elf_section_index sindex)
+{
+ yasm_intnum *nreloc;
+ yasm_intnum *relocsize;
+
+ YASM_WRITE_32_L(bufp, shead->rel_name ? shead->rel_name->index : 0);
+ YASM_WRITE_32_L(bufp, SHT_RELA);
+ YASM_WRITE_32_L(bufp, 0);
+ YASM_WRITE_32_L(bufp, 0);
+ YASM_WRITE_32_L(bufp, shead->rel_offset);
+
+ nreloc = yasm_intnum_create_uint(shead->nreloc);
+ relocsize = yasm_intnum_create_uint(RELOC32A_SIZE);
+ yasm_intnum_calc(relocsize, YASM_EXPR_MUL, nreloc);
+ YASM_WRITE_32I_L(bufp, relocsize); /* size */
+ yasm_intnum_destroy(nreloc);
+ yasm_intnum_destroy(relocsize);
+
+ YASM_WRITE_32_L(bufp, symtab_idx); /* link: symtab index */
+ YASM_WRITE_32_L(bufp, shead->index); /* info: relocated's index */
+ YASM_WRITE_32_L(bufp, RELOC32_ALIGN); /* align */
+ YASM_WRITE_32_L(bufp, RELOC32A_SIZE); /* entity size */
+}
+
+static void
+elf_x86_x32_handle_reloc_addend(yasm_intnum *intn,
+ elf_reloc_entry *reloc,
+ unsigned long offset)
+{
+ /* .rela: copy value out as addend, replace original with 0 */
+ reloc->addend = yasm_intnum_copy(intn);
+ yasm_intnum_zero(intn);
+}
+
+static unsigned int
+elf_x86_x32_map_reloc_info_to_type(elf_reloc_entry *reloc)
+{
+ if (reloc->wrt) {
+ const elf_machine_ssym *ssym = (elf_machine_ssym *)
+ yasm_symrec_get_data(reloc->wrt, &elf_ssym_symrec_data);
+ if (!ssym || reloc->valsize != ssym->size)
+ yasm_internal_error(N_("Unsupported WRT"));
+
+ /* Force TLS type; this is required by the linker. */
+ if (ssym->sym_rel & ELF_SSYM_THREAD_LOCAL) {
+ elf_symtab_entry *esym;
+
+ esym = yasm_symrec_get_data(reloc->reloc.sym, &elf_symrec_data);
+ if (esym)
+ esym->type = STT_TLS;
+ }
+ /* Map PC-relative GOT to appropriate relocation */
+ if (reloc->rtype_rel && ssym->reloc == R_X86_64_GOT32)
+ return (unsigned char) R_X86_64_GOTPCREL;
+ return (unsigned char) ssym->reloc;
+ } else if (reloc->is_GOT_sym && reloc->valsize == 32) {
+ return (unsigned char) R_X86_64_GOTPC32;
+ } else if (reloc->is_GOT_sym && reloc->valsize == 64) {
+ yasm_internal_error(N_("Unsupported relocation size"));
+ } else if (reloc->rtype_rel) {
+ switch (reloc->valsize) {
+ case 8: return (unsigned char) R_X86_64_PC8;
+ case 16: return (unsigned char) R_X86_64_PC16;
+ case 32: return (unsigned char) R_X86_64_PC32;
+ default: yasm_internal_error(N_("Unsupported relocation size"));
+ }
+ } else {
+ switch (reloc->valsize) {
+ case 8: return (unsigned char) R_X86_64_8;
+ case 16: return (unsigned char) R_X86_64_16;
+ case 32: return (unsigned char) R_X86_64_32;
+ case 64: return (unsigned char) R_X86_64_64;
+ default: yasm_internal_error(N_("Unsupported relocation size"));
+ }
+ }
+ return 0;
+}
+
+static void
+elf_x86_x32_write_reloc(unsigned char *bufp, elf_reloc_entry *reloc,
+ unsigned int r_type, unsigned int r_sym)
+{
+ YASM_WRITE_32I_L(bufp, reloc->reloc.addr);
+ YASM_WRITE_32_L(bufp, ELF32_R_INFO((unsigned long)r_sym, (unsigned char)r_type));
+ if (reloc->addend)
+ YASM_WRITE_32I_L(bufp, reloc->addend);
+ else {
+ YASM_WRITE_32_L(bufp, 0);
+ }
+}
+
+static void
+elf_x86_x32_write_proghead(unsigned char **bufpp,
+ elf_offset secthead_addr,
+ unsigned long secthead_count,
+ elf_section_index shstrtab_index)
+{
+ unsigned char *bufp = *bufpp;
+ unsigned char *buf = bufp-4;
+ YASM_WRITE_8(bufp, ELFCLASS32); /* elf class */
+ YASM_WRITE_8(bufp, ELFDATA2LSB); /* data encoding :: MSB? */
+ YASM_WRITE_8(bufp, EV_CURRENT); /* elf version */
+ YASM_WRITE_8(bufp, ELFOSABI_SYSV); /* os/abi */
+ YASM_WRITE_8(bufp, 0); /* SYSV v3 ABI=0 */
+ while (bufp-buf < EI_NIDENT) /* e_ident padding */
+ YASM_WRITE_8(bufp, 0);
+
+ YASM_WRITE_16_L(bufp, ET_REL); /* e_type - object file */
+ YASM_WRITE_16_L(bufp, EM_X86_64); /* e_machine - or others */
+ YASM_WRITE_32_L(bufp, EV_CURRENT); /* elf version */
+ YASM_WRITE_32_L(bufp, 0); /* e_entry */
+ YASM_WRITE_32_L(bufp, 0); /* e_phoff */
+ YASM_WRITE_32_L(bufp, secthead_addr); /* e_shoff secthead off */
+
+ YASM_WRITE_32_L(bufp, 0); /* e_flags */
+ YASM_WRITE_16_L(bufp, EHDR32_SIZE); /* e_ehsize */
+ YASM_WRITE_16_L(bufp, 0); /* e_phentsize */
+ YASM_WRITE_16_L(bufp, 0); /* e_phnum */
+ YASM_WRITE_16_L(bufp, SHDR32_SIZE); /* e_shentsize */
+ YASM_WRITE_16_L(bufp, secthead_count); /* e_shnum */
+ YASM_WRITE_16_L(bufp, shstrtab_index); /* e_shstrndx */
+ *bufpp = bufp;
+}
+
+const elf_machine_handler
+elf_machine_handler_x86_x32 = {
+ "x86", "x32", ".rela",
+ SYMTAB32_SIZE, SYMTAB32_ALIGN, RELOC32A_SIZE, SHDR32_SIZE, EHDR32_SIZE,
+ elf_x86_x32_accepts_reloc,
+ elf_x86_x32_write_symtab_entry,
+ elf_x86_x32_write_secthead,
+ elf_x86_x32_write_secthead_rel,
+ elf_x86_x32_handle_reloc_addend,
+ elf_x86_x32_map_reloc_info_to_type,
+ elf_x86_x32_write_reloc,
+ elf_x86_x32_write_proghead,
+ elf_x86_x32_ssyms,
+ sizeof(elf_x86_x32_ssyms)/sizeof(elf_x86_x32_ssyms[0]),
+ 32
+};
diff --git a/modules/objfmts/elf/elf.c b/modules/objfmts/elf/elf.c
index 7adf7ea9..addec913 100644
--- a/modules/objfmts/elf/elf.c
+++ b/modules/objfmts/elf/elf.c
@@ -56,12 +56,14 @@ const yasm_assoc_data_callback elf_ssym_symrec_data = {
extern elf_machine_handler
elf_machine_handler_x86_x86,
- elf_machine_handler_x86_amd64;
+ elf_machine_handler_x86_amd64,
+ elf_machine_handler_x86_x32;
static const elf_machine_handler *elf_machine_handlers[] =
{
&elf_machine_handler_x86_x86,
&elf_machine_handler_x86_amd64,
+ &elf_machine_handler_x86_x32,
NULL
};
static const elf_machine_handler elf_null_machine = {0, 0, 0, 0, 0, 0, 0, 0,
@@ -81,9 +83,13 @@ elf_set_arch(yasm_arch *arch, yasm_symtab *symtab, int bits_pref)
elf_march = elf_machine_handlers[++i])
{
if (yasm__strcasecmp(yasm_arch_keyword(arch), elf_march->arch)==0)
- if (yasm__strcasecmp(machine, elf_march->machine)==0)
+ if (yasm__strcasecmp(machine, elf_march->machine)==0) {
if (bits_pref == 0 || bits_pref == elf_march->bits)
break;
+ } else if (bits_pref == elf_march->bits
+ && yasm__strcasecmp(machine, "amd64") == 0
+ && yasm__strcasecmp(elf_march->machine, "x32") == 0)
+ break;
}
if (elf_march && elf_march->num_ssyms > 0)
diff --git a/modules/objfmts/elf/tests/Makefile.inc b/modules/objfmts/elf/tests/Makefile.inc
index e6d421c0..0980329c 100644
--- a/modules/objfmts/elf/tests/Makefile.inc
+++ b/modules/objfmts/elf/tests/Makefile.inc
@@ -47,9 +47,13 @@ EXTRA_DIST += modules/objfmts/elf/tests/nasm-forceident.asm
EXTRA_DIST += modules/objfmts/elf/tests/nasm-forceident.hex
EXTRA_DIST += modules/objfmts/elf/tests/amd64/Makefile.inc
+EXTRA_DIST += modules/objfmts/elf/tests/x32/Makefile.inc
EXTRA_DIST += modules/objfmts/elf/tests/gas32/Makefile.inc
EXTRA_DIST += modules/objfmts/elf/tests/gas64/Makefile.inc
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/Makefile.inc
include modules/objfmts/elf/tests/amd64/Makefile.inc
+include modules/objfmts/elf/tests/x32/Makefile.inc
include modules/objfmts/elf/tests/gas32/Makefile.inc
include modules/objfmts/elf/tests/gas64/Makefile.inc
+include modules/objfmts/elf/tests/gasx32/Makefile.inc
diff --git a/modules/objfmts/elf/tests/gasx32/Makefile.inc b/modules/objfmts/elf/tests/gasx32/Makefile.inc
new file mode 100644
index 00000000..6bba8bd6
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/Makefile.inc
@@ -0,0 +1,11 @@
+TESTS += modules/objfmts/elf/tests/gasx32/elf_gasx32_test.sh
+
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_test.sh
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/crosssect.asm
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/crosssect.hex
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.asm
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.hex
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.asm
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.hex
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.asm
+EXTRA_DIST += modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.hex
diff --git a/modules/objfmts/elf/tests/gasx32/crosssect.asm b/modules/objfmts/elf/tests/gasx32/crosssect.asm
new file mode 100644
index 00000000..41999791
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/crosssect.asm
@@ -0,0 +1,18 @@
+.section .rodata
+ .align 4
+_sys_srt:
+ .long 0
+
+.text
+ .align 4,0x90
+ .long _sys_srt-.
+ .long _sys_srt-_sys_info
+ #.long _sys_info-_sys_srt
+ #.long -(_sys_srt-_sys_info)
+ .long _sys_info-.
+ .long .-_sys_info
+ .long (_sys_srt-.)+(.-_sys_info) # GAS cannot handle this but we can
+ .long 0
+ .long 65558
+_sys_info:
+ .long 0
diff --git a/modules/objfmts/elf/tests/gasx32/crosssect.hex b/modules/objfmts/elf/tests/gasx32/crosssect.hex
new file mode 100644
index 00000000..35893c4e
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/crosssect.hex
@@ -0,0 +1,568 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+20
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+07
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+14
+00
+00
+00
+f0
+ff
+ff
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+16
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+02
+04
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+02
+04
+00
+00
+e8
+ff
+ff
+ff
+10
+00
+00
+00
+02
+04
+00
+00
+f4
+ff
+ff
+ff
+00
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+2e
+72
+6f
+64
+61
+74
+61
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+2d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+1c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+2a
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+88
+00
+00
+00
+34
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+1a
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+bc
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+22
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c0
+00
+00
+00
+60
+00
+00
+00
+02
+00
+00
+00
+06
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+20
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+0f
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+60
+00
+00
+00
+24
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+07
+00
+00
+00
+01
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+84
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.asm b/modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.asm
new file mode 100644
index 00000000..60a893b3
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.asm
@@ -0,0 +1,27 @@
+.globl bar
+.globl foo
+
+.section .bar
+bar:
+.4byte foo-.
+.4byte baz-.
+call foo
+call baz
+foo:
+
+.section .data
+baz:
+.4byte foo-.
+#.4byte .-foo # illegal
+.4byte baz-.
+.4byte .-baz
+.4byte foo+4-. # with constant
+.4byte .-baz+foo+4-. # both local and cross-segment (legal)
+#.4byte baz+foo+4-.-. # ditto, slightly different - GAS gets confused on this
+#.4byte (bar-.)+(foo-.) # illegal (too many cross-segment)
+.4byte baz-.+baz-. # two from same segment
+
+.section .text
+movl $5, foo-.
+movl $(foo-.), %eax
+call foo
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.hex b/modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.hex
new file mode 100644
index 00000000..45cb217f
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_curpos.hex
@@ -0,0 +1,848 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c0
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+0a
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c7
+04
+25
+00
+00
+00
+00
+05
+00
+00
+00
+b8
+00
+00
+00
+00
+e8
+00
+00
+00
+00
+00
+00
+00
+03
+00
+00
+00
+02
+07
+00
+00
+03
+00
+00
+00
+0c
+00
+00
+00
+02
+07
+00
+00
+01
+00
+00
+00
+11
+00
+00
+00
+02
+07
+00
+00
+fc
+ff
+ff
+ff
+12
+00
+00
+00
+00
+00
+00
+00
+e8
+05
+00
+00
+00
+e8
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+02
+02
+00
+00
+00
+00
+00
+00
+0e
+00
+00
+00
+02
+02
+00
+00
+fc
+ff
+ff
+ff
+00
+00
+00
+00
+fc
+ff
+ff
+ff
+08
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+d8
+ff
+ff
+ff
+00
+00
+00
+00
+02
+07
+00
+00
+00
+00
+00
+00
+0c
+00
+00
+00
+02
+07
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+02
+07
+00
+00
+14
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+2e
+62
+61
+72
+00
+2e
+64
+61
+74
+61
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+72
+65
+6c
+61
+2e
+62
+61
+72
+00
+2e
+72
+65
+6c
+61
+2e
+64
+61
+74
+61
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+2d
+00
+62
+61
+72
+00
+66
+6f
+6f
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+08
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+08
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+06
+00
+07
+00
+00
+00
+12
+00
+00
+00
+00
+00
+00
+00
+10
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+42
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+e4
+00
+00
+00
+4c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+32
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+30
+01
+00
+00
+0b
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+3a
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+3c
+01
+00
+00
+80
+00
+00
+00
+02
+00
+00
+00
+06
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+15
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+12
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+58
+00
+00
+00
+24
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+07
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+7c
+00
+00
+00
+12
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+1d
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+90
+00
+00
+00
+18
+00
+00
+00
+03
+00
+00
+00
+06
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+0c
+00
+00
+00
+01
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+a8
+00
+00
+00
+18
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+27
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c0
+00
+00
+00
+24
+00
+00
+00
+03
+00
+00
+00
+08
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.asm b/modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.asm
new file mode 100644
index 00000000..e015ce4b
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.asm
@@ -0,0 +1,37 @@
+.comm _ZEROVAR, 32, 16
+.comm _VAR, 16, 16
+.data
+.org 0
+_ZEROVAR:
+.org 0xa0
+.globl _VAR
+.type _VAR, @object
+.size _VAR, 16
+_VAR:
+.4byte 0
+.4byte 0
+.4byte 0
+.4byte 0
+.org 0xc0
+_VAR2:
+.org 0xe0
+.globl _VAR3
+_VAR3:
+
+.text
+movq $0, %rax
+movq _VAR, %rax
+movq %rax, _VAR(%rip)
+movq _VAR+8(%rip), %rcx
+movlpd _VAR(%rip), %xmm1
+
+movq _VAR2, %rax
+movq %rax, _VAR2(%rip)
+movq _VAR2+8(%rip), %rcx
+movlpd _VAR2(%rip), %xmm1
+
+movq _VAR3, %rax
+movq %rax, _VAR3(%rip)
+movq _VAR3+8(%rip), %rcx
+movlpd _VAR3(%rip), %xmm1
+
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.hex b/modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.hex
new file mode 100644
index 00000000..1b46fa18
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_reloc.hex
@@ -0,0 +1,1016 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+e0
+02
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+07
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+48
+c7
+c0
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+89
+05
+00
+00
+00
+00
+48
+8b
+0d
+00
+00
+00
+00
+66
+0f
+12
+0d
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+89
+05
+00
+00
+00
+00
+48
+8b
+0d
+00
+00
+00
+00
+66
+0f
+12
+0d
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+89
+05
+00
+00
+00
+00
+48
+8b
+0d
+00
+00
+00
+00
+66
+0f
+12
+0d
+00
+00
+00
+00
+00
+00
+00
+0b
+00
+00
+00
+0a
+06
+00
+00
+00
+00
+00
+00
+12
+00
+00
+00
+02
+06
+00
+00
+fc
+ff
+ff
+ff
+19
+00
+00
+00
+02
+06
+00
+00
+04
+00
+00
+00
+21
+00
+00
+00
+02
+06
+00
+00
+fc
+ff
+ff
+ff
+29
+00
+00
+00
+0a
+03
+00
+00
+c0
+00
+00
+00
+30
+00
+00
+00
+02
+03
+00
+00
+bc
+00
+00
+00
+37
+00
+00
+00
+02
+03
+00
+00
+c4
+00
+00
+00
+3f
+00
+00
+00
+02
+03
+00
+00
+bc
+00
+00
+00
+47
+00
+00
+00
+0a
+07
+00
+00
+00
+00
+00
+00
+4e
+00
+00
+00
+02
+07
+00
+00
+fc
+ff
+ff
+ff
+55
+00
+00
+00
+02
+07
+00
+00
+04
+00
+00
+00
+5d
+00
+00
+00
+02
+07
+00
+00
+fc
+ff
+ff
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+2e
+64
+61
+74
+61
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+00
+00
+2d
+00
+5f
+56
+41
+52
+00
+5f
+5a
+45
+52
+4f
+56
+41
+52
+00
+5f
+56
+41
+52
+33
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+c0
+00
+00
+00
+00
+00
+00
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+08
+00
+00
+00
+00
+00
+00
+00
+20
+00
+00
+00
+10
+00
+06
+00
+03
+00
+00
+00
+a0
+00
+00
+00
+10
+00
+00
+00
+11
+00
+06
+00
+11
+00
+00
+00
+e0
+00
+00
+00
+00
+00
+00
+00
+10
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+28
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+14
+02
+00
+00
+32
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+18
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+48
+02
+00
+00
+17
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+20
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+60
+02
+00
+00
+80
+00
+00
+00
+02
+00
+00
+00
+05
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+61
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+0d
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+a4
+00
+00
+00
+90
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+07
+00
+00
+00
+01
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+34
+01
+00
+00
+e0
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.asm b/modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.asm
new file mode 100644
index 00000000..b7203f62
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.asm
@@ -0,0 +1,10 @@
+.text
+foo:
+movl %eax, foo@PLT
+movl %eax, foo@GOTPCREL
+movl %eax, bar@TLSGD
+movl %eax, bar@TLSLD
+movl %eax, bar@GOTTPOFF
+movl %eax, bar@TPOFF
+movl %eax, bar@DTPOFF
+movl %eax, foo@GOT
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.hex b/modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.hex
new file mode 100644
index 00000000..cac39900
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_ssym.hex
@@ -0,0 +1,592 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+60
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+06
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+89
+04
+25
+00
+00
+00
+00
+03
+00
+00
+00
+04
+02
+00
+00
+00
+00
+00
+00
+0a
+00
+00
+00
+09
+02
+00
+00
+00
+00
+00
+00
+11
+00
+00
+00
+13
+04
+00
+00
+00
+00
+00
+00
+18
+00
+00
+00
+14
+04
+00
+00
+00
+00
+00
+00
+1f
+00
+00
+00
+16
+04
+00
+00
+00
+00
+00
+00
+26
+00
+00
+00
+17
+04
+00
+00
+00
+00
+00
+00
+2d
+00
+00
+00
+15
+04
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+03
+02
+00
+00
+00
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+2d
+00
+62
+61
+72
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+16
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+22
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+d8
+00
+00
+00
+2c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+12
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+01
+00
+00
+07
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+1a
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+0c
+01
+00
+00
+50
+00
+00
+00
+02
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+38
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+07
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+78
+00
+00
+00
+60
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/gasx32/elf_gasx32_test.sh b/modules/objfmts/elf/tests/gasx32/elf_gasx32_test.sh
new file mode 100755
index 00000000..f5372cb5
--- /dev/null
+++ b/modules/objfmts/elf/tests/gasx32/elf_gasx32_test.sh
@@ -0,0 +1,3 @@
+#! /bin/sh
+${srcdir}/out_test.sh elf_gasx32_test modules/objfmts/elf/tests/gasx32 "GAS elf-x32 objfmt" "-f elfx32 -p gas" ".o"
+exit $?
diff --git a/modules/objfmts/elf/tests/x32/Makefile.inc b/modules/objfmts/elf/tests/x32/Makefile.inc
new file mode 100644
index 00000000..d62ba3ea
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/Makefile.inc
@@ -0,0 +1,11 @@
+TESTS += modules/objfmts/elf/tests/x32/elf_x32_test.sh
+
+EXTRA_DIST += modules/objfmts/elf/tests/x32/elf_x32_test.sh
+EXTRA_DIST += modules/objfmts/elf/tests/x32/elf-rip.asm
+EXTRA_DIST += modules/objfmts/elf/tests/x32/elf-rip.hex
+EXTRA_DIST += modules/objfmts/elf/tests/x32/elfso32.asm
+EXTRA_DIST += modules/objfmts/elf/tests/x32/elfso32.hex
+EXTRA_DIST += modules/objfmts/elf/tests/x32/gotpcrel.asm
+EXTRA_DIST += modules/objfmts/elf/tests/x32/gotpcrel.hex
+EXTRA_DIST += modules/objfmts/elf/tests/x32/multiplefixup.asm
+EXTRA_DIST += modules/objfmts/elf/tests/x32/multiplefixup.hex
diff --git a/modules/objfmts/elf/tests/x32/elf-rip.asm b/modules/objfmts/elf/tests/x32/elf-rip.asm
new file mode 100644
index 00000000..5f10f096
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/elf-rip.asm
@@ -0,0 +1,7 @@
+[bits 64]
+[extern sym]
+mov eax, [rip]
+mov eax, [rip+2]
+mov eax, [rip+sym]
+mov eax, [sym wrt rip]
+call sym
diff --git a/modules/objfmts/elf/tests/x32/elf-rip.hex b/modules/objfmts/elf/tests/x32/elf-rip.hex
new file mode 100644
index 00000000..be5da687
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/elf-rip.hex
@@ -0,0 +1,496 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+06
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+8b
+05
+00
+00
+00
+00
+8b
+05
+02
+00
+00
+00
+8b
+05
+00
+00
+00
+00
+8b
+05
+00
+00
+00
+00
+e8
+00
+00
+00
+00
+00
+00
+00
+0e
+00
+00
+00
+0a
+03
+00
+00
+00
+00
+00
+00
+14
+00
+00
+00
+02
+03
+00
+00
+fc
+ff
+ff
+ff
+19
+00
+00
+00
+02
+03
+00
+00
+fc
+ff
+ff
+ff
+00
+2e
+74
+65
+78
+74
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+2d
+00
+73
+79
+6d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+22
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+84
+00
+00
+00
+2c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+12
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+b0
+00
+00
+00
+07
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+1a
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+b8
+00
+00
+00
+40
+00
+00
+00
+02
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+1d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+07
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+60
+00
+00
+00
+24
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/x32/elf_x32_test.sh b/modules/objfmts/elf/tests/x32/elf_x32_test.sh
new file mode 100755
index 00000000..39618166
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/elf_x32_test.sh
@@ -0,0 +1,3 @@
+#! /bin/sh
+${srcdir}/out_test.sh elf_x32_test modules/objfmts/elf/tests/x32 "elf-x32 objfmt" "-f elf -m x32" ".o"
+exit $?
diff --git a/modules/objfmts/elf/tests/x32/elfsox32.asm b/modules/objfmts/elf/tests/x32/elfsox32.asm
new file mode 100644
index 00000000..931c7ffe
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/elfsox32.asm
@@ -0,0 +1,90 @@
+; This code is UNTESTED, and almost certainly DOES NOT WORK!
+; Do NOT use this as an example of how to write AMD64 shared libraries!
+; This code is simply to test the AMD64 ELF WRT relocations.
+
+; This file should test the following:
+; [1] Define and export a global text-section symbol
+; [2] Define and export a global data-section symbol
+; [3] Define and export a global BSS-section symbol
+; [4] Define a non-global text-section symbol
+; [5] Define a non-global data-section symbol
+; [6] Define a non-global BSS-section symbol
+; [7] Define a COMMON symbol
+; [8] Define a NASM local label
+; [9] Reference a NASM local label
+; [10] Import an external symbol
+; [11] Make a PC-relative call to an external symbol
+; [12] Reference a text-section symbol in the text section
+; [13] Reference a data-section symbol in the text section
+; [14] Reference a BSS-section symbol in the text section
+; [15] Reference a text-section symbol in the data section
+; [16] Reference a data-section symbol in the data section
+; [17] Reference a BSS-section symbol in the data section
+
+ [BITS 64]
+ [GLOBAL lrotate:function] ; [1]
+ [GLOBAL greet:function] ; [1]
+ [GLOBAL asmstr:data asmstr.end-asmstr] ; [2]
+ [GLOBAL textptr:data 4] ; [2]
+ [GLOBAL selfptr:data 4] ; [2]
+ [GLOBAL integer:data 4] ; [3]
+ [EXTERN printf] ; [10]
+ [COMMON commvar 4:4] ; [7]
+ [EXTERN _GLOBAL_OFFSET_TABLE_]
+
+ [SECTION .text]
+
+; prototype: long lrotate(long x, int num);
+lrotate: ; [1]
+ push rbp
+ mov rbp,rsp
+ mov rax,[rbp+8]
+ mov rcx,[rbp+12]
+.label rol rax,1 ; [4] [8]
+ loop .label ; [9] [12]
+ mov rsp,rbp
+ pop rbp
+ ret
+
+; prototype: void greet(void);
+greet push rbx ; we'll use RBX for GOT, so save it
+ mov rbx,[integer wrt ..gotpcrel wrt rip]
+ mov rax,[rbx] ; [14]
+ inc rax
+ mov rbx,[_GLOBAL_OFFSET_TABLE_ wrt ..gotpcrel wrt rip]
+ mov [rbx+localint wrt ..got],eax ; [14]
+ mov rax,[rbx+commvar wrt ..got]
+ push qword [rax]
+ mov rax,[rbx+localptr wrt ..got] ; [13]
+ push qword [rax]
+ mov rax,[rbx+integer wrt ..got] ; [1] [14]
+ push qword [rax]
+ lea rax,[rbx+printfstr wrt ..got]
+ push rax ; [13]
+ call printf wrt ..plt ; [11]
+ add rsp,16
+ pop rbx
+ ret
+
+ [SECTION .data]
+
+; a string
+asmstr db 'hello, world', 0 ; [2]
+.end
+
+; a string for Printf
+printfstr db "integer==%d, localint==%d, commvar=%d"
+ db 10, 0
+
+; some pointers
+localptr dd localint ; [5] [17]
+textptr dd greet wrt ..sym ; [15]
+selfptr dd selfptr wrt ..sym ; [16]
+
+ [SECTION .bss]
+
+; an integer
+integer resd 1 ; [3]
+
+; a local integer
+localint resd 1 ; [6]
diff --git a/modules/objfmts/elf/tests/x32/elfsox32.hex b/modules/objfmts/elf/tests/x32/elfsox32.hex
new file mode 100644
index 00000000..d423b2de
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/elfsox32.hex
@@ -0,0 +1,1176 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+30
+03
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+09
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+55
+48
+89
+e5
+48
+8b
+45
+08
+48
+8b
+4d
+0c
+48
+d1
+c0
+e2
+fb
+48
+89
+ec
+5d
+c3
+53
+48
+8b
+1d
+00
+00
+00
+00
+48
+8b
+03
+48
+ff
+c0
+48
+8b
+1d
+00
+00
+00
+00
+89
+83
+00
+00
+00
+00
+48
+8b
+83
+00
+00
+00
+00
+ff
+30
+48
+8b
+83
+00
+00
+00
+00
+ff
+30
+48
+8b
+83
+00
+00
+00
+00
+ff
+30
+48
+8d
+83
+00
+00
+00
+00
+50
+e8
+00
+00
+00
+00
+48
+83
+c4
+10
+5b
+c3
+00
+1a
+00
+00
+00
+09
+0f
+00
+00
+fc
+ff
+ff
+ff
+27
+00
+00
+00
+09
+12
+00
+00
+fc
+ff
+ff
+ff
+2d
+00
+00
+00
+03
+06
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+03
+11
+00
+00
+00
+00
+00
+00
+3d
+00
+00
+00
+03
+05
+00
+00
+00
+00
+00
+00
+46
+00
+00
+00
+03
+0f
+00
+00
+00
+00
+00
+00
+4f
+00
+00
+00
+03
+04
+00
+00
+00
+00
+00
+00
+55
+00
+00
+00
+04
+10
+00
+00
+fc
+ff
+ff
+ff
+68
+65
+6c
+6c
+6f
+2c
+20
+77
+6f
+72
+6c
+64
+00
+69
+6e
+74
+65
+67
+65
+72
+3d
+3d
+25
+64
+2c
+20
+6c
+6f
+63
+61
+6c
+69
+6e
+74
+3d
+3d
+25
+64
+2c
+20
+63
+6f
+6d
+6d
+76
+61
+72
+3d
+25
+64
+0a
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+0a
+02
+00
+00
+04
+00
+00
+00
+38
+00
+00
+00
+0a
+0b
+00
+00
+00
+00
+00
+00
+3c
+00
+00
+00
+0a
+0e
+00
+00
+00
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+2e
+64
+61
+74
+61
+00
+2e
+62
+73
+73
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+72
+65
+6c
+61
+2e
+64
+61
+74
+61
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+00
+00
+2d
+00
+6c
+72
+6f
+74
+61
+74
+65
+00
+67
+72
+65
+65
+74
+00
+61
+73
+6d
+73
+74
+72
+00
+74
+65
+78
+74
+70
+74
+72
+00
+73
+65
+6c
+66
+70
+74
+72
+00
+69
+6e
+74
+65
+67
+65
+72
+00
+70
+72
+69
+6e
+74
+66
+00
+63
+6f
+6d
+6d
+76
+61
+72
+00
+5f
+47
+4c
+4f
+42
+41
+4c
+5f
+4f
+46
+46
+53
+45
+54
+5f
+54
+41
+42
+4c
+45
+5f
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+08
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+06
+00
+00
+00
+00
+00
+0d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+06
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+00
+00
+00
+00
+06
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+08
+00
+00
+00
+00
+00
+0c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+0d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+12
+00
+04
+00
+0b
+00
+00
+00
+16
+00
+00
+00
+00
+00
+00
+00
+12
+00
+04
+00
+11
+00
+00
+00
+00
+00
+00
+00
+0d
+00
+00
+00
+11
+00
+06
+00
+18
+00
+00
+00
+38
+00
+00
+00
+04
+00
+00
+00
+11
+00
+06
+00
+20
+00
+00
+00
+3c
+00
+00
+00
+04
+00
+00
+00
+11
+00
+06
+00
+28
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+11
+00
+08
+00
+30
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+37
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+10
+00
+f2
+ff
+3f
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+38
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+64
+01
+00
+00
+42
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+28
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+a8
+01
+00
+00
+55
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+30
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+02
+00
+00
+30
+01
+00
+00
+02
+00
+00
+00
+0a
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+5f
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+12
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+a0
+00
+00
+00
+60
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+07
+00
+00
+00
+01
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+40
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+1d
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+40
+01
+00
+00
+24
+00
+00
+00
+03
+00
+00
+00
+06
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+0d
+00
+00
+00
+08
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+08
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/x32/gotpcrel.asm b/modules/objfmts/elf/tests/x32/gotpcrel.asm
new file mode 100644
index 00000000..c3d12383
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/gotpcrel.asm
@@ -0,0 +1,6 @@
+var:
+mov rax, [var wrt ..got]
+mov rax, [var wrt ..gotpcrel] ; should be error/warning?
+mov rax, [rel var wrt ..got] ; automatic promotion to GOTPCREL
+mov rax, [rel var wrt ..gotpcrel]
+
diff --git a/modules/objfmts/elf/tests/x32/gotpcrel.hex b/modules/objfmts/elf/tests/x32/gotpcrel.hex
new file mode 100644
index 00000000..695cf7d6
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/gotpcrel.hex
@@ -0,0 +1,496 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+06
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+8b
+05
+00
+00
+00
+00
+48
+8b
+05
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+03
+02
+00
+00
+00
+00
+00
+00
+0c
+00
+00
+00
+09
+02
+00
+00
+00
+00
+00
+00
+13
+00
+00
+00
+09
+02
+00
+00
+fc
+ff
+ff
+ff
+1a
+00
+00
+00
+09
+02
+00
+00
+fc
+ff
+ff
+ff
+00
+2e
+74
+65
+78
+74
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+2d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+22
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+90
+00
+00
+00
+2c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+12
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+bc
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+1a
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c0
+00
+00
+00
+40
+00
+00
+00
+02
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+1e
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+07
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+60
+00
+00
+00
+30
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
diff --git a/modules/objfmts/elf/tests/x32/multiplefixup.asm b/modules/objfmts/elf/tests/x32/multiplefixup.asm
new file mode 100644
index 00000000..ec253cbb
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/multiplefixup.asm
@@ -0,0 +1,8 @@
+[section .data]
+foobar:
+ dq 42
+[section .text]
+foo:
+ times 4 mov rax, [rel foobar]
+ times 4 mov rax, [foobar]
+ times 4 jmp foo
diff --git a/modules/objfmts/elf/tests/x32/multiplefixup.hex b/modules/objfmts/elf/tests/x32/multiplefixup.hex
new file mode 100644
index 00000000..a1874282
--- /dev/null
+++ b/modules/objfmts/elf/tests/x32/multiplefixup.hex
@@ -0,0 +1,680 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+3e
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+90
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+07
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+48
+8b
+05
+00
+00
+00
+00
+48
+8b
+05
+00
+00
+00
+00
+48
+8b
+05
+00
+00
+00
+00
+48
+8b
+05
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+48
+8b
+04
+25
+00
+00
+00
+00
+eb
+c2
+eb
+c0
+eb
+be
+eb
+bc
+03
+00
+00
+00
+02
+04
+00
+00
+fc
+ff
+ff
+ff
+0a
+00
+00
+00
+02
+04
+00
+00
+fc
+ff
+ff
+ff
+11
+00
+00
+00
+02
+04
+00
+00
+fc
+ff
+ff
+ff
+18
+00
+00
+00
+02
+04
+00
+00
+fc
+ff
+ff
+ff
+20
+00
+00
+00
+0a
+04
+00
+00
+00
+00
+00
+00
+28
+00
+00
+00
+0a
+04
+00
+00
+00
+00
+00
+00
+30
+00
+00
+00
+0a
+04
+00
+00
+00
+00
+00
+00
+38
+00
+00
+00
+0a
+04
+00
+00
+00
+00
+00
+00
+2a
+00
+00
+00
+00
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+2e
+64
+61
+74
+61
+00
+2e
+72
+65
+6c
+61
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+00
+00
+2d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+06
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+28
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+ec
+00
+00
+00
+32
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+18
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+20
+01
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+20
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+24
+01
+00
+00
+60
+00
+00
+00
+02
+00
+00
+00
+06
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+44
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00
+0d
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+84
+00
+00
+00
+60
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+04
+00
+00
+00
+0c
+00
+00
+00
+07
+00
+00
+00
+01
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+e4
+00
+00
+00
+08
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+00
+00
+00
+00
diff --git a/modules/objfmts/yasm_objfmts.xml b/modules/objfmts/yasm_objfmts.xml
index 13811a07..f4c9a75b 100644
--- a/modules/objfmts/yasm_objfmts.xml
+++ b/modules/objfmts/yasm_objfmts.xml
@@ -96,11 +96,12 @@
<refsect1>
<title>elf</title>
- <para>The ELF object format really comes in two flavors:
- <quote>elf32</quote> (for 32-bit targets) and <quote>elf64</quote>
- (for 64-bit targets). ELF is a standard object format in common
- use on modern Unix and compatible systems (e.g. Linux, FreeBSD).
- ELF has complex support for relocatable and shared objects.</para>
+ <para>The ELF object format really comes in three flavors:
+ <quote>elf32</quote> (for 32-bit targets), <quote>elf64</quote>
+ (for 64-bit targets and <quote>elfx32</quote> (for x32 targets).
+ ELF is a standard object format in common use on modern Unix and
+ compatible systems (e.g. Linux, FreeBSD). ELF has complex support
+ for relocatable and shared objects.</para>
</refsect1>
<refsect1>