aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorPip Cet <pipcet@gmail.com>2017-03-30 10:57:21 +0100
committerNick Clifton <nickc@redhat.com>2017-03-30 10:57:21 +0100
commitf96bd6c2d7a3801fabbf9d834f7a29b752aa7532 (patch)
tree6c4ee43355083f19052f09a0fb5bbc4e47c4a08a /bfd
parent662659a1a582af14aa45a458005e2a4df514b6d7 (diff)
downloadgdb-f96bd6c2d7a3801fabbf9d834f7a29b752aa7532.zip
gdb-f96bd6c2d7a3801fabbf9d834f7a29b752aa7532.tar.gz
gdb-f96bd6c2d7a3801fabbf9d834f7a29b752aa7532.tar.bz2
Add support for the WebAssembly file format and the wasm32 ELF conversion to gas and the binutils.
binutils * readelf.c: Add support for wasm32 ELF format WebAssembly files. (guess_is_rela): Likewise. (dump_relocations): Likewise. (is_32bit_abs_reloc): Likewise. (is_none_reloc_): Likewise. * NEWS: Mention the new support. * testsuite/lib/binutils-common.exp (is_elf_format): Mark wasm32 as ELF target. (supports_gnu_unique): Mark wasm32 as supporting STB_GNU_UNIQUE. * testsuite/binutils-all/nm.exp: Mark wasm32 as requiring .size annotations. * testsuite/binutils-all/wasm32: New directory. * testsuite/binutils-all/wasm32/create-wasm.d: New file. * testsuite/binutils-all/wasm32/create-wasm.s: Likewise. * testsuite/binutils-all/wasm32/custom-section.d: Likewise. * testsuite/binutils-all/wasm32/custom-section.s: Likewise. * testsuite/binutils-all/wasm32/invalid-wasm-1.d: Likewise. * testsuite/binutils-all/wasm32/invalid-wasm-1.s: Likewise. * testsuite/binutils-all/wasm32/long-sections.d: Likewise. * testsuite/binutils-all/wasm32/long-sections.s: Likewise. * testsuite/binutils-all/wasm32/parse-wasm.d: Likewise. * testsuite/binutils-all/wasm32/parse-wasm.s: Likewise. * testsuite/binutils-all/wasm32/parse-wasm-2.d: Likewise. * testsuite/binutils-all/wasm32/parse-wasm-2.s: Likewise. * testsuite/binutils-all/wasm32/prepared-section.d: Likewise. * testsuite/binutils-all/wasm32/prepared-section.s: Likewise. * testsuite/binutils-all/wasm32/wasm32.exp: New file, run tests. gas * config/tc-wasm32.h: New file: Add WebAssembly assembler target. * config/tc-wasm32.c: New file: Add WebAssembly assembler target. * Makefile.am: Add WebAssembly assembler target. * configure.tgt: Add WebAssembly assembler target. * doc/c-wasm32.texi: New file: Start documenting WebAssembly assembler. * doc/all.texi: Define WASM32. * doc/as.texinfo: Add WebAssembly entries. * NEWS: Mention the new support. * Makefile.in: Regenerate. * po/gas.pot: Regenerate. * po/POTFILES.in: Regenerate. * testsuite/gas/wasm32: New directory. * testsuite/gas/wasm32/allinsn.d: New file. * testsuite/gas/wasm32/allinsn.s: New file. * testsuite/gas/wasm32/illegal.l: New file. * testsuite/gas/wasm32/illegal.s: New file. * testsuite/gas/wasm32/illegal-2.l: New file. * testsuite/gas/wasm32/illegal-2.s: New file. * testsuite/gas/wasm32/illegal-3.l: New file. * testsuite/gas/wasm32/illegal-3.s: New file. * testsuite/gas/wasm32/illegal-4.l: New file. * testsuite/gas/wasm32/illegal-4.s: New file. * testsuite/gas/wasm32/illegal-5.l: New file. * testsuite/gas/wasm32/illegal-5.s: New file. * testsuite/gas/wasm32/illegal-6.l: New file. * testsuite/gas/wasm32/illegal-6.s: New file. * testsuite/gas/wasm32/illegal-7.l: New file. * testsuite/gas/wasm32/illegal-7.s: New file. * testsuite/gas/wasm32/illegal-8.l: New file. * testsuite/gas/wasm32/illegal-8.s: New file. * testsuite/gas/wasm32/illegal-9.l: New file. * testsuite/gas/wasm32/illegal-9.s: New file. * testsuite/gas/wasm32/illegal-10.l: New file. * testsuite/gas/wasm32/illegal-10.s: New file. * testsuite/gas/wasm32/illegal-11.l: New file. * testsuite/gas/wasm32/illegal-11.s: New file. * testsuite/gas/wasm32/illegal-12.l: New file. * testsuite/gas/wasm32/illegal-12.s: New file. * testsuite/gas/wasm32/illegal-13.l: New file. * testsuite/gas/wasm32/illegal-13.s: New file. * testsuite/gas/wasm32/illegal-14.l: New file. * testsuite/gas/wasm32/illegal-14.s: New file. * testsuite/gas/wasm32/illegal-15.l: New file. * testsuite/gas/wasm32/illegal-15.s: New file. * testsuite/gas/wasm32/illegal-16.l: New file. * testsuite/gas/wasm32/illegal-16.s: New file. * testsuite/gas/wasm32/illegal-17.l: New file. * testsuite/gas/wasm32/illegal-17.s: New file. * testsuite/gas/wasm32/illegal-18.l: New file. * testsuite/gas/wasm32/illegal-18.s: New file. * testsuite/gas/wasm32/illegal-19.l: New file. * testsuite/gas/wasm32/illegal-19.s: New file. * testsuite/gas/wasm32/illegal-20.l: New file. * testsuite/gas/wasm32/illegal-20.s: New file. * testsuite/gas/wasm32/illegal-21.l: New file. * testsuite/gas/wasm32/illegal-21.s: New file. * testsuite/gas/wasm32/illegal-22.l: New file. * testsuite/gas/wasm32/illegal-22.s: New file. * testsuite/gas/wasm32/illegal-24.l: New file. * testsuite/gas/wasm32/illegal-24.s: New file. * testsuite/gas/wasm32/illegal-25.l: New file. * testsuite/gas/wasm32/illegal-25.s: New file. * testsuite/gas/wasm32/reloc.d: New file. * testsuite/gas/wasm32/reloc.s: New file. * testsuite/gas/wasm32/wasm32.exp: New tests for WebAssembly architecture. opcodes * configure.ac: Add (empty) bfd_wasm32_arch target. * configure: Regenerate * po/opcodes.pot: Regenerate. include * opcode/wasm.h: New file to support wasm32 architecture. * elf/wasm32.h: Add R_WASM32_32 relocation. bfd * elf32-wasm32.c: Add relocation code, two relocs. * reloc.c: Add wasm32 relocations. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. * bfd/po/bfd.pot: Regenerate.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog8
-rw-r--r--bfd/bfd-in2.h12
-rw-r--r--bfd/elf32-wasm32.c107
-rw-r--r--bfd/libbfd.h10
-rw-r--r--bfd/po/bfd.pot57
-rw-r--r--bfd/reloc.c23
6 files changed, 187 insertions, 30 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 42ffd4d..bb851c7 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2017-03-30 Pip Cet <pipcet@gmail.com>
+
+ * elf32-wasm32.c: Add relocation code, two relocs.
+ * reloc.c: Add wasm32 relocations.
+ * libbfd.h: Regenerate.
+ * bfd-in2.h: Regenerate.
+ * bfd/po/bfd.pot: Regenerate.
+
2017-03-29 Nick Clifton <nickc@redhat.com>
PR binutils/18025
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index adfcefd..fbd379f 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -6464,6 +6464,18 @@ assembler and not (currently) written to any object files. */
BFD_RELOC_VISIUM_HI16_PCREL,
BFD_RELOC_VISIUM_LO16_PCREL,
BFD_RELOC_VISIUM_IM16_PCREL,
+
+/* WebAssembly relocations. */
+ BFD_RELOC_WASM32_LEB128,
+ BFD_RELOC_WASM32_LEB128_GOT,
+ BFD_RELOC_WASM32_LEB128_GOT_CODE,
+ BFD_RELOC_WASM32_LEB128_PLT,
+ BFD_RELOC_WASM32_PLT_INDEX,
+ BFD_RELOC_WASM32_ABS32_CODE,
+ BFD_RELOC_WASM32_COPY,
+ BFD_RELOC_WASM32_CODE_POINTER,
+ BFD_RELOC_WASM32_INDEX,
+ BFD_RELOC_WASM32_PLT_SIG,
BFD_RELOC_UNUSED };
typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
diff --git a/bfd/elf32-wasm32.c b/bfd/elf32-wasm32.c
index 9b38272..6d2e04ec 100644
--- a/bfd/elf32-wasm32.c
+++ b/bfd/elf32-wasm32.c
@@ -23,8 +23,108 @@
#include "libbfd.h"
#include "elf-bfd.h"
#include "bfd_stdint.h"
+#include "libiberty.h"
#include "elf/wasm32.h"
+static reloc_howto_type elf32_wasm32_howto_table[] =
+{
+ HOWTO (R_WASM32_NONE, /* type */
+ 0, /* rightshift */
+ 3, /* size (0 = byte, 1 = short, 2 = long) */
+ 0, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont,/* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_WASM32_NONE", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ /* 32 bit absolute */
+ HOWTO (R_WASM32_32, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield,/* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_WASM32_32", /* name */
+ FALSE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+};
+
+/* Look up the relocation CODE. */
+
+static reloc_howto_type *
+elf32_wasm32_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+ bfd_reloc_code_real_type code)
+{
+ switch (code)
+ {
+ case BFD_RELOC_NONE:
+ return &elf32_wasm32_howto_table[R_WASM32_NONE];
+ case BFD_RELOC_32:
+ return &elf32_wasm32_howto_table[R_WASM32_32];
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+/* Look up the relocation R_NAME. */
+
+static reloc_howto_type *
+elf32_wasm32_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+ const char *r_name)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE (elf32_wasm32_howto_table); i++)
+ if (elf32_wasm32_howto_table[i].name != NULL
+ && strcasecmp (elf32_wasm32_howto_table[i].name, r_name) == 0)
+ return &elf32_wasm32_howto_table[i];
+
+ return NULL;
+}
+
+/* Look up the relocation R_TYPE. */
+
+static reloc_howto_type *
+elf32_wasm32_rtype_to_howto (bfd *abfd, unsigned r_type)
+{
+ unsigned int i = r_type;
+
+ if (i >= ARRAY_SIZE (elf32_wasm32_howto_table))
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%B: invalid relocation type %d"),
+ abfd, (int) r_type);
+ i = R_WASM32_NONE;
+ }
+
+ if (elf32_wasm32_howto_table[i].type != r_type)
+ return NULL;
+
+ return &elf32_wasm32_howto_table[i];
+}
+
+/* Translate the ELF-internal relocation RELA into CACHE_PTR. */
+
+static void
+elf32_wasm32_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
+ arelent *cache_ptr,
+ Elf_Internal_Rela *dst)
+{
+ unsigned int r_type = ELF32_R_TYPE (dst->r_info);
+ cache_ptr->howto = elf32_wasm32_rtype_to_howto (abfd, r_type);
+}
+
#define ELF_ARCH bfd_arch_wasm32
#define ELF_TARGET_ID EM_WEBASSEMBLY
#define ELF_MACHINE_CODE EM_WEBASSEMBLY
@@ -40,8 +140,11 @@
/* For testing. */
#define elf_backend_want_dynrelro 1
-#define bfd_elf32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
-#define bfd_elf32_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
+#define elf_info_to_howto elf32_wasm32_info_to_howto_rela
+#define elf_info_to_howto_rel NULL
+
+#define bfd_elf32_bfd_reloc_type_lookup elf32_wasm32_reloc_type_lookup
+#define bfd_elf32_bfd_reloc_name_lookup elf32_wasm32_reloc_name_lookup
#define ELF_DYNAMIC_INTERPRETER "/sbin/elf-dynamic-interpreter.so"
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 1b6ca52..8bac650 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -3166,6 +3166,16 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
"BFD_RELOC_VISIUM_HI16_PCREL",
"BFD_RELOC_VISIUM_LO16_PCREL",
"BFD_RELOC_VISIUM_IM16_PCREL",
+ "BFD_RELOC_WASM32_LEB128",
+ "BFD_RELOC_WASM32_LEB128_GOT",
+ "BFD_RELOC_WASM32_LEB128_GOT_CODE",
+ "BFD_RELOC_WASM32_LEB128_PLT",
+ "BFD_RELOC_WASM32_PLT_INDEX",
+ "BFD_RELOC_WASM32_ABS32_CODE",
+ "BFD_RELOC_WASM32_COPY",
+ "BFD_RELOC_WASM32_CODE_POINTER",
+ "BFD_RELOC_WASM32_INDEX",
+ "BFD_RELOC_WASM32_PLT_SIG",
"@@overflow: BFD_RELOC_UNUSED@@",
};
#endif
diff --git a/bfd/po/bfd.pot b/bfd/po/bfd.pot
index 70249f8..2b2bec5 100644
--- a/bfd/po/bfd.pot
+++ b/bfd/po/bfd.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: bug-binutils@gnu.org\n"
-"POT-Creation-Date: 2017-03-27 11:46+0100\n"
+"POT-Creation-Date: 2017-03-29 17:07+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -206,7 +206,7 @@ msgid "Warning: Writing section `%s' at huge (ie negative) file offset 0x%lx."
msgstr ""
#: bout.c:1142 elf-m10300.c:2651 elf32-avr.c:2452 elf32-frv.c:5633
-#: elf64-ia64-vms.c:353 elfxx-sparc.c:2876 reloc.c:7981 reloc16.c:156
+#: elf64-ia64-vms.c:353 elfxx-sparc.c:2876 reloc.c:8004 reloc16.c:156
#: elf32-ia64.c:351 elf64-ia64.c:351
msgid "%P%F: --relax and -r may not be used together\n"
msgstr ""
@@ -617,16 +617,16 @@ msgstr ""
msgid "<corrupt info> %s"
msgstr ""
-#: coffgen.c:2638 elflink.c:13940 linker.c:2931
+#: coffgen.c:2666 elflink.c:13940 linker.c:2931
msgid "%F%P: already_linked_table: %E\n"
msgstr ""
-#: coffgen.c:2965 elflink.c:12981
+#: coffgen.c:2993 elflink.c:12981
#, c-format
msgid "Removing unused section '%s' in file '%B'"
msgstr ""
-#: coffgen.c:3041 elflink.c:13219
+#: coffgen.c:3069 elflink.c:13219
msgid "Warning: gc-sections option ignored"
msgstr ""
@@ -736,26 +736,26 @@ msgstr ""
msgid "Dwarf Error: Unable to read alt ref %u."
msgstr ""
-#: dwarf2.c:2600 dwarf2.c:2745 dwarf2.c:3063
+#: dwarf2.c:2600 dwarf2.c:2750 dwarf2.c:3071
#, c-format
msgid "Dwarf Error: Could not find abbrev number %u."
msgstr ""
-#: dwarf2.c:3015
+#: dwarf2.c:3023
#, c-format
msgid ""
"Dwarf Error: found dwarf version '%u', this reader only handles version 2, 3 "
"and 4 information."
msgstr ""
-#: dwarf2.c:3026
+#: dwarf2.c:3034
#, c-format
msgid ""
"Dwarf Error: found address size '%u', this reader can not handle sizes "
"greater than '%u'."
msgstr ""
-#: dwarf2.c:3129
+#: dwarf2.c:3137
msgid ""
"Dwarf Error: DW_AT_comp_dir attribute encountered with a non-string form."
msgstr ""
@@ -1680,7 +1680,7 @@ msgstr ""
#. Ignore init flag - it may not be set, despite the flags field containing valid data.
#. Ignore init flag - it may not be set, despite the flags field
#. containing valid data.
-#: elf32-arm.c:14101 elf32-bfin.c:4919 elf32-cris.c:4084 elf32-m68hc1x.c:1413
+#: elf32-arm.c:14101 elf32-bfin.c:4919 elf32-cris.c:4089 elf32-m68hc1x.c:1413
#: elf32-m68k.c:1200 elf32-score.c:4009 elf32-score7.c:3818 elf32-vax.c:536
#: elf32-xgate.c:669 elfxx-mips.c:15782
#: /work/sources/binutils/current/bfd/elfnn-aarch64.c:6695
@@ -2072,14 +2072,14 @@ msgid ""
"-mno-small-tls)"
msgstr ""
-#: elf32-cris.c:3231
+#: elf32-cris.c:3233
#, c-format
msgid ""
"%B, section %A:\n"
" v10/v32 compatible object %s must not contain a PIC relocation"
msgstr ""
-#: elf32-cris.c:3285
+#: elf32-cris.c:3287
#, c-format
msgid ""
"%B, section %A:\n"
@@ -2087,52 +2087,52 @@ msgid ""
"recompile with -fPIC"
msgstr ""
-#: elf32-cris.c:3500
+#: elf32-cris.c:3505
#, c-format
msgid ""
"%B, section %A:\n"
" relocation %s should not be used in a shared object; recompile with -fPIC"
msgstr ""
-#: elf32-cris.c:3924
+#: elf32-cris.c:3929
#, c-format
msgid ""
"%B, section `%A', to symbol `%s':\n"
" relocation %s should not be used in a shared object; recompile with -fPIC"
msgstr ""
-#: elf32-cris.c:4036
+#: elf32-cris.c:4041
msgid "Unexpected machine number"
msgstr ""
-#: elf32-cris.c:4087
+#: elf32-cris.c:4092
#, c-format
msgid " [symbols have a _ prefix]"
msgstr ""
-#: elf32-cris.c:4090
+#: elf32-cris.c:4095
#, c-format
msgid " [v10 and v32]"
msgstr ""
-#: elf32-cris.c:4093
+#: elf32-cris.c:4098
#, c-format
msgid " [v32]"
msgstr ""
-#: elf32-cris.c:4137
+#: elf32-cris.c:4142
msgid "%B: uses _-prefixed symbols, but writing file with non-prefixed symbols"
msgstr ""
-#: elf32-cris.c:4138
+#: elf32-cris.c:4143
msgid "%B: uses non-prefixed symbols, but writing file with _-prefixed symbols"
msgstr ""
-#: elf32-cris.c:4157
+#: elf32-cris.c:4162
msgid "%B contains CRIS v32 code, incompatible with previous objects"
msgstr ""
-#: elf32-cris.c:4159
+#: elf32-cris.c:4164
msgid "%B contains non-CRIS-v32 code, incompatible with previous objects"
msgstr ""
@@ -2356,7 +2356,8 @@ msgstr ""
#. Unknown relocation.
#: elf32-i386.c:387 elf32-m68k.c:352 elf32-ppc.c:2074 elf32-s390.c:346
-#: elf32-tic6x.c:2674 elf64-ppc.c:2515 elf64-s390.c:372 elf64-x86-64.c:289
+#: elf32-tic6x.c:2674 elf32-wasm32.c:106 elf64-ppc.c:2515 elf64-s390.c:372
+#: elf64-x86-64.c:289
#, c-format
msgid "%B: invalid relocation type %d"
msgstr ""
@@ -2947,7 +2948,7 @@ msgstr ""
msgid "%B: Unmatched OMIT_FP in %A."
msgstr ""
-#: elf32-nds32.c:13026 reloc.c:8192
+#: elf32-nds32.c:13026 reloc.c:8215
#, c-format
msgid "%X%P: %B(%A): relocation \"%R\" goes out of range\n"
msgstr ""
@@ -5841,21 +5842,21 @@ msgstr ""
msgid "Partition[%d] length = 0x%.8lx (%ld)\n"
msgstr ""
-#: reloc.c:8028
+#: reloc.c:8051
msgid "INPUT_SECTION_FLAGS are not supported.\n"
msgstr ""
-#: reloc.c:8126
+#: reloc.c:8149
#, c-format
msgid "%X%P: %B(%A): error: relocation for offset %V has no value\n"
msgstr ""
-#: reloc.c:8202
+#: reloc.c:8225
#, c-format
msgid "%X%P: %B(%A): relocation \"%R\" is not supported\n"
msgstr ""
-#: reloc.c:8211
+#: reloc.c:8234
#, c-format
msgid "%X%P: %B(%A): relocation \"%R\" returns an unrecognized value %x\n"
msgstr ""
diff --git a/bfd/reloc.c b/bfd/reloc.c
index d4229a4..2791458 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -7853,6 +7853,29 @@ ENUMX
ENUMDOC
Visium Relocations.
+ENUM
+ BFD_RELOC_WASM32_LEB128
+ENUMX
+ BFD_RELOC_WASM32_LEB128_GOT
+ENUMX
+ BFD_RELOC_WASM32_LEB128_GOT_CODE
+ENUMX
+ BFD_RELOC_WASM32_LEB128_PLT
+ENUMX
+ BFD_RELOC_WASM32_PLT_INDEX
+ENUMX
+ BFD_RELOC_WASM32_ABS32_CODE
+ENUMX
+ BFD_RELOC_WASM32_COPY
+ENUMX
+ BFD_RELOC_WASM32_CODE_POINTER
+ENUMX
+ BFD_RELOC_WASM32_INDEX
+ENUMX
+ BFD_RELOC_WASM32_PLT_SIG
+ENUMDOC
+ WebAssembly relocations.
+
ENDSENUM
BFD_RELOC_UNUSED
CODE_FRAGMENT