Commit Graph

80 Commits

Author SHA1 Message Date
Gabor Greif
2632848491 Relocation of DW_OP_{bra, skip} instructions (#2143)
The fundamental problem is that the target distance of jump-like operations may change in the DWARF expression translation process. Intervening DW_OP_deref will expand to about 10 bytes, for example.

So the jumps must be relocated. We approach this task by inserting artificial LandingPad markers (new CompiledExpressionParts constructors) into the parsed vector at actual Jump targets.

LandingPads are identified by JumpTargetMarker tokens which are generated on the fly.

Additionally we now parse the Jump instructions. These also get their corresponding JumpTargetMarker token.

We bail in two situations:

    frame_base is too complicated (i.e. itself contains Jump)
    some jump distance in the original expression is fishy.
2020-08-26 17:19:03 -05:00
Gabor Greif
ec87aee147 Revert #2137, the extra (seemingly leftover) DW_OP_deref is in fact essential (#2156)
* Revert "don't leave Deref bytecode for Code chunk (#2137)"

This reverts commit 30b9e69136.

* add explanation that DW_OP_deref is needed
2020-08-21 13:12:30 -05:00
Gabor Greif
6513e90914 use the obvious DW_OP_const4u for 0xffff_ffff (#2154)
No point in resorting to LEB128 encoding for such constants,
using the native `u32` is faster and more compact.

Adds `write_u32` method to facilitate this.
2020-08-21 08:16:09 -05:00
bjorn3
b5e24c8c67 Update object to 0.21.1 (#2144) 2020-08-19 15:14:26 -05:00
Gabor Greif
4cafb90186 use opcode directly, now that we support this (#2145)
fixing also two typos with `DW_OP_fbreg`
2020-08-19 12:30:01 -05:00
Gabor Greif
30b9e69136 don't leave Deref bytecode for Code chunk (#2137)
Re-enter loop after pushing `CompiledExpressionPart::Deref`, so that it
isn't recoded for `CompiledExpressionPart::Code` as well.
2020-08-18 10:54:34 -05:00
Gabor Greif
a796d65467 test_debug_parse_expressions: improve expression! macro (#2104)
Provide automatic translation to opcodes from DW_OP_* identifiers. They are looked up from gimli.
Since DW_OP_WASM_location is not contained in gimli yet, we take care of manually translating it.
2020-08-07 13:25:18 -05:00
Gabor Greif
9aebca11ad Don't GC DW_TAG_variant(_part), they are referenced (#2113)
by their respective parents.

See also #2105.
2020-08-07 13:23:47 -05:00
Gabor Greif
b5a6daedc4 DW_TAG_enumerator is owned by parent tag (#2107)
so mark it as such for GC to not accidentally lose it.

Fixes https://github.com/bytecodealliance/wasmtime/issues/2105
2020-08-06 14:19:43 -05:00
Alex Crichton
65eaca35dd Refactor where results of compilation are stored (#2086)
* Refactor where results of compilation are stored

This commit refactors the internals of compilation in Wasmtime to change
where results of individual function compilation are stored. Previously
compilation resulted in many maps being returned, and compilation
results generally held all these maps together. This commit instead
switches this to have all metadata stored in a `CompiledFunction`
instead of having a separate map for each item that can be stored.

The motivation for this is primarily to help out with future
module-linking-related PRs. What exactly "module level" is depends on
how we interpret modules and how many modules are in play, so it's a bit
easier for operations in wasmtime to work at the function level where
possible. This means that we don't have to pass around multiple
different maps and a function index, but instead just one map or just
one entry representing a compiled function.

Additionally this change updates where the parallelism of compilation
happens, pushing it into `wasmtime-jit` instead of `wasmtime-environ`.
This is another goal where `wasmtime-jit` will have more knowledge about
module-level pieces with module linking in play. User-facing-wise this
should be the same in terms of parallel compilation, though.

The ultimate goal of this refactoring is to make it easier for the
results of compilation to actually be a set of wasm modules. This means
we won't be able to have a map-per-metadata where the primary key is the
function index, because there will be many modules within one "object
file".

* Don't clear out fields, just don't store them

Persist a smaller set of fields in `CompilationArtifacts` instead of
trying to clear fields out and dynamically not accessing them.
2020-08-03 12:20:51 -05:00
Alex Crichton
026fb8d388 Don't re-parse wasm for debuginfo (#2085)
* Don't re-parse wasm for debuginfo

This commit updates debuginfo parsing to happen during the main
translation of the original wasm module. This avoid re-parsing the wasm
module twice (at least the section-level headers). Additionally this
ties debuginfo directly to a `ModuleTranslation` which makes it easier
to process debuginfo for nested modules in the upcoming module linking
proposal.

The changes here are summarized by taking the `read_debuginfo` function
and merging it with the main module translation that happens which is
driven by cranelift. Some new hooks were added to the module environment
trait to support this, but most of it was integrating with existing hooks.

* Fix tests in debug crate
2020-08-03 09:59:20 -05:00
Alex Crichton
63d5b91930 Wasmtime 0.19.0 and Cranelift 0.66.0 (#2027)
This commit updates Wasmtime's version to 0.19.0, Cranelift's version to
0.66.0, and updates the release notes as well.
2020-07-16 12:46:21 -05:00
Alex Crichton
1000f21338 Update wasmparser to 0.59.0 (#2013)
This commit is intended to update wasmparser to 0.59.0. This primarily
includes bytecodealliance/wasm-tools#40 which is a large update to how
parsing and validation works. The impact on Wasmtime is pretty small at
this time, but over time I'd like to refactor the internals here to lean
more heavily on that upstream wasmparser refactoring.

For now, though, the intention is to get on the train of wasmparser's
latest `main` branch to ensure we get bug fixes and such.

As part of this update a few other crates and such were updated. This is
primarily to handle the new encoding of `ref.is_null` where the type is
not part of the instruction encoding any more.
2020-07-13 16:22:41 -05:00
Yury Delendik
091373f9b8 Removes duplicate code in src/obj.rs, crates/obj and crates/jit/object.rs (#1993)
Changes:

 -  Moves object creation code from crates/jit/object.rs to the creates/obj (as ObjectBuilder)
 -   Removes legacy crates/obj/function.rs
 -  Removes write_debugsections
2020-07-08 12:14:19 -05:00
Yury Delendik
bef1b87be0 Write ELF image and instantiate code_memory from it (#1931)
- Create the ELF image from Compilation
- Create CodeMemory from the ELF image
- Link using ELF image
- Remove creation of GDB JIT images from crates/debug
- Move make_trampoline from compiler.rs
2020-07-07 12:51:24 -05:00
Gabor Greif
79f054f77f Correct the files' directory index when downgrading DWARF5 -> 4 (#1989)
* correct the files' directory index when downgrading DWARF5 -> 4
2020-07-07 11:20:32 -05:00
Yury Delendik
9900641674 Support reference types in the DWARF transform (#1986) 2020-07-07 09:43:03 -05:00
Till Schneidereit
f80c2abffb Update various crates' object and wast dependencies (#1908)
This somewhat cuts down on duplicate dependencies. `wast` is used in a much older version (`11.0.0`) by `witx`, and can be updated without issues there as well, but this at least gets us from 3 copies to 2.
2020-07-01 09:11:38 -05:00
Andrew Brown
4d57ae99e3 Upgrade wasmparser to 0.58.0 (#1942)
* Upgrade wasmparser to 0.58.0

* Enable more spec tests
2020-06-30 11:08:21 -05:00
bjorn3
9788b02dd5 Bump object to 0.19.0 (#1767)
* Bump object to 0.19.0
2020-06-12 15:37:04 -05:00
Dan Gohman
caa87048ab Wasmtime 0.18.0 and Cranelift 0.65.0. 2020-06-11 17:49:56 -07:00
Yury Delendik
70424037c3 Refactor debug library to use object:🧝:* (#1860)
* Add GDB test

* rm stray test resource

* use object:🧝:* structures

* install gdb on CI
2020-06-11 13:53:38 -05:00
Yury Delendik
e5b81bbc28 Migrating code to object (from faerie) (#1848)
* Using the "object" library everywhere in wasmtime.
* scroll_derive
2020-06-10 11:27:00 -05:00
Yury Delendik
4ebbcb82a9 Refactor CompiledModule to separate compile and linking stages (#1831)
* Refactor how relocs are stored and handled

* refactor CompiledModule::instantiate and link_module

* Refactor DWARF creation: split generation and serialization

* Separate DWARF data transform from instantiation

* rm LinkContext
2020-06-09 15:09:48 -05:00
Yury Delendik
6f37204f82 Upgrade gimli to 0.21 (#1819)
* Use gimli 0.21

* rm CFI w Expression

* Don't write .debug_frame twice
2020-06-04 14:34:05 -05:00
Dan Gohman
a76639c6fb Wasmtime 0.17.0 and Cranelift 0.64.0. (#1805) 2020-06-02 18:51:59 -07:00
Nick Fitzgerald
137e182750 Update wasmparser to 0.57.0 2020-06-01 14:53:10 -07:00
Nick Fitzgerald
1a4f3fb2df Update deps and tests for anyref --> externref
* Update to using `wasmparser` 0.55.0
* Update wasmprinter to 0.2.5
* Update `wat` to 1.0.18, and `wast` to 17.0.0
2020-05-14 12:47:37 -07:00
Alex Crichton
a7d90af19d Update wasmparser and wast dependencies (#1663)
Brings in updates to SIMD spec ops renumbering.
2020-05-05 16:13:14 -05:00
Yury Delendik
1873c0ae46 Fix value label ranges resolution (#1572)
There was a bug how value labels were resolved, which caused some DWARF expressions not be transformed, e.g. those are in the registers.

*    Implements FIXME in expression.rs
*    Move TargetIsa from CompiledExpression structure
*    Fix expression format for GDB
*    Add tests for parsing
*    Proper logic in ValueLabelRangesBuilder::process_label
*    Tests for ValueLabelRangesBuilder
*    Refactor build_with_locals to return Iterator instead of Vec<_>
*    Misc comments and magical numbers
2020-04-30 08:07:55 -05:00
Dan Gohman
864cf98c8d Update release notes, wasmtime 0.16, cranelift 0.63. 2020-04-29 17:30:25 -07:00
Gabor Greif
d9d69299bb A few typofixes (#1623)
* a few typofixes

* more tyops
2020-04-28 19:18:05 -05:00
Gabor Greif
a1f3f06878 The index in DW_OP_WASM_location is ULEB128 (#1611)
C.f. https://yurydelendik.github.io/webassembly-dwarf/#DWARF-expressions-and-location-descriptions
2020-04-28 10:56:34 -05:00
Gabor Greif
1639ed0e2e support a few DWARF-5 only features (#1410)
Support a few DWARF-5 only features:

* read .debug_addr
* read .debug_rnglists
* read .debug_loclists when present
* add dwarf-5 test
* read .debug_addr
* read .debug_rnglists
* read .debug_loclists when present
* support .debug_line_str and .debug_str_offsets

Co-authored-by: Yury Delendik <ydelendik@mozilla.com>
2020-04-27 17:27:22 -05:00
Peter Huene
f7e9f86ba9 Refactor unwind generation in Cranelift.
This commit makes the following changes to unwind information generation in
Cranelift:

* Remove frame layout change implementation in favor of processing the prologue
  and epilogue instructions when unwind information is requested.  This also
  means this work is no longer performed for Windows, which didn't utilize it.
  It also helps simplify the prologue and epilogue generation code.

* Remove the unwind sink implementation that required each unwind information
  to be represented in final form. For FDEs, this meant writing a
  complete frame table per function, which wastes 20 bytes or so for each
  function with duplicate CIEs.  This also enables Cranelift users to collect the
  unwind information and write it as a single frame table.

* For System V calling convention, the unwind information is no longer stored
  in code memory (it's only a requirement for Windows ABI to do so).  This allows
  for more compact code memory for modules with a lot of functions.

* Deletes some duplicate code relating to frame table generation.  Users can
  now simply use gimli to create a frame table from each function's unwind
  information.

Fixes #1181.
2020-04-16 11:15:32 -07:00
Yury Delendik
c5b6c57c34 Check .debug_str data that is not from DWARF (#1507)
* Check .debug_str data that is not from DWARF

* xplatform check
2020-04-14 15:21:42 -05:00
Yury Delendik
a88e26cc08 Utility methods for artificial debug types in the generated DWARF (#1482)
* add operator*
* add operator->
* add ptr() unwrap method
* comments/refactor
* macro_rules
* external symbols workaround
2020-04-10 11:00:10 -05:00
Andrew Brown
6fd0451bc3 Add TargetIsa::map_dwarf_register; fixes #1471
This exposes the functionality of `fde::map_reg` on the `TargetIsa` trait, avoiding compilation errors on architectures where register mapping is not yet supported. The change is conditially compiled under the `unwind` feature.
2020-04-09 09:45:20 -07:00
Dan Gohman
fde5ddf159 Fixes for 0.15 (#1449)
* Wasmtime 0.15.0 and Cranelift 0.62.0. (#1398)

* Bump more ad-hoc versions.

* Add build.rs to wasi-common's Cargo.toml.

* Update the env var name in more places.

* Remove a redundant echo.
2020-04-03 13:13:37 -07:00
Yury Delendik
e64668776a Propertly simulate DWARF information when imports present (#1452)
* Ignore complex LLVM10 expressions.

* Propery function name when imports are present
2020-03-31 18:33:35 -05:00
Andrew Brown
d3df275003 Remove duplication of map_reg; fixes #1245
Both cranelift-codegen and wasmtime-debug need to map Cranelift registers to Gimli registers. Previously both crates had an almost-identical `map_reg` implementation. This change:
 - removes the wasmtime-debug implementation
 - improves the cranelift-codegen implementation with custom errors
 - exposes map_reg in `cranelift_codegen::isa::fde::map_reg` and subsequently `wasmtime_environ::isa::fde::map_reg`
2020-03-31 15:42:02 -07:00
Dan Gohman
092538cc54 Test 0.14 (#1417)
* Bump Wasmtime to 0.14.0.

* Update the publish script for the wiggle crate wiggle.

* More fixes.

* Fix lightbeam depenency version.

* cargo update

* Cargo update wasi-tests too.

And add cargo update to the version-bump scripts.
2020-03-26 21:53:42 -07:00
Dan Gohman
6fa9be7767 Wasmtime 0.13.0 and Cranelift 0.61.0. (#1398)
This also updates the publishing scripts to work with newly added
and reorganized crates.
2020-03-26 13:19:02 -07:00
Yury Delendik
27bf044ca2 Fix debug asserts for dwarf transform (#1413)
* Fix debug asserts for dwarf transform

* feedback
2020-03-26 12:25:26 -05:00
Nick Fitzgerald
a8c5e7df95 Merge pull request #1402 from yurydelendik/enable-gdb
Enable GDB JIT debugging
2020-03-26 10:08:15 -07:00
Yury Delendik
f3bfa2aa23 Ignore DWARF expressions with wasm globals (#1405) 2020-03-25 16:03:38 -05:00
Yury Delendik
5c4ea5b03a Increase generated DWARF version to 4 2020-03-25 13:52:34 -05:00
Yury Delendik
021ebb3748 Refactor address_transform.rs to use less memory (#1260)
The crates/debug/src/transform/address_transform.rs is unoptimized in terms of data structures. This PR refactors this file to remove creation of intermediate in-heap structures, thus improves overall performance of the DWARF transformation.

* Reduce amount of memory allocated in translate_ranges_raw
* refactor translate_ranges
* Don't transform non-unit .debug_line
* type annotation for TransformRangeXXXIter's
* Fix empty generated wasm positions
2020-03-23 16:36:29 -05:00
Pat Hickey
2f6172732f wasmtime-cli, obj, debug: upgrade to faerie 0.15
eliminating the faerie 0.14 dep
2020-03-17 09:44:33 -07:00
Yury Delendik
f76b36f737 Write .debug_frame information (#53)
* Write .debug_frame information

* mv map_reg
2020-03-11 10:22:51 -05:00