Commit Graph

51 Commits

Author SHA1 Message Date
bjorn3
82f3ad4f1a Add comment why thiserror is not used 2021-05-04 13:51:28 +02:00
bjorn3
147cda3b99 Remove thiserror dependency from cranelift_module 2021-05-04 13:42:48 +02:00
bjorn3
cc89111463 Support declaring anonymous functions and data objects 2021-03-21 18:00:26 +01:00
Will Robson
38926fb1fc cranelift-module: Add support for passing a StackMapSink when defining functions
Fixes #2738

This follows the convention set by the existing method of passing a
TrapSink by adding another argument for a StackMapSink.
2021-03-19 00:02:15 +00:00
bjorn3
a710fc4425 Make Module object safe 2021-02-22 16:00:37 +01:00
bjorn3
86d3dc9510 Add prepare_for_function_redefine 2020-11-12 19:39:44 +01:00
bjorn3
844a52e96a Don't unnecessarily take &self for some ModuleDeclarations methods 2020-11-11 11:43:09 +01:00
bjorn3
856f799ade Make some things more consistent between define_function and define_function_bytes 2020-11-11 11:38:28 +01:00
Alex Crichton
8af2dbfbac Allow offloading compilation in cranelift-object (#2371)
This commit is a slight refactoring of the `Module` trait and backend in
`cranelift-object`. The goal is to enable parallelization of compilation
when using `cranelift-object`. Currently this is difficult because
`ObjectModule::define_function` requires `&mut self`. This instead
soups up the `define_function_bytes` interface to handle relocations so
compilation can happen externally before defining it in a `Module`. This
also means that `define_function` is now a convenience wrapper around
`define_function_bytes`.
2020-11-06 09:56:44 -06:00
bjorn3
7a2a4bc903 Add some debug derives 2020-10-12 11:45:01 +02:00
Pat Hickey
13c6bdd9ba cranelift-module: add iterator methods to ModuleDeclarations
The predecessor interface made it possible to iterate across all
function and data declarations. This is still useful and easy enough to
provide.
2020-10-07 20:06:58 -07:00
bjorn3
b061694491 Rustfmt and update docs 2020-10-01 09:53:23 +02:00
bjorn3
d84ca235d2 Remove Backend trait and turn Module into a trait 2020-09-30 19:52:57 +02:00
bjorn3
84c6ec3214 Move alignment config from declare_data to define_data 2020-09-30 19:23:23 +02:00
bjorn3
b44c5bb2be Move ModuleDeclarations to backends 2020-09-30 18:33:29 +02:00
bjorn3
7a6e909efe Move a bit more logic out of Module 2020-09-30 17:31:08 +02:00
bjorn3
c2ffcdc6d0 Move logic out of more Module methods 2020-09-30 17:12:33 +02:00
bjorn3
80f4ecf9b5 Move almost all logic out of Module 2020-09-30 16:50:24 +02:00
bjorn3
588a4be0b3 Store Compiled* in the backend instead of Module 2020-09-30 16:18:57 +02:00
bjorn3
405b9e2875 Remove finalize_* from the Backend trait
Instead let the `finish` method perform finalization
2020-09-30 14:20:39 +02:00
bjorn3
59f95083b1 Remove write_data_funcaddr and write_data_dataaddr
They are unimplemented by all backends
2020-09-30 13:59:26 +02:00
bjorn3
7608749647 Merge finalize_definitions into finish 2020-09-30 13:58:13 +02:00
bjorn3
4483c3740a Remove get_finalized_* 2020-09-30 13:53:01 +02:00
bjorn3
7dcfb1b47b Move some error checking out of the define_* functions 2020-09-30 12:40:26 +02:00
bjorn3
b1187b5507 Merge ModuleNamespace and ModuleContents 2020-09-30 12:29:22 +02:00
Nathan Froyd
dcabb55776 change Module::define_function to take TrapSink instances
Experience with the `define_function` API has shown that returning
borrowed slices of `TrapSite` is not ideal: the returned slice
represents a borrow on the entire `Module`, which makes calling back
into methods taking `&mut self` a bit tricky.

To eliminate the problem, let's require the callers of `define_function`
to provide `TrapSink` instances.  This style of API enables them to
control when and how traps are collected, and makes the `object` and
`faerie` backends simpler/more efficient by not having to worry about
trap collection.
2020-03-24 13:36:01 -04:00
Pat Hickey
8bbf07c758 Merge pull request #1327 from bjorn3/linkage_hidden
Add support for hidden visibility
2020-03-17 11:34:41 -07:00
bjorn3
b4562c62e3 Add support for hidden visibility 2020-03-17 17:51:12 +01:00
Pat Hickey
fdfda89d59 cranelift-module: make backend error an anyhow::Error
This allows us to retain richer information from backend errors.
We already have `anyhow` as a dep in several places in the wasmtime
tree, and in cranelift-faerie. faerie is the only user of this
variant.

Existing code that puts a String into the Backend error can trivially
adapt their code to emit an anyhow::Error.
2020-03-17 09:44:33 -07:00
Nathan Froyd
2bb3096342 change interfaces to use slices instead of Vec 2020-03-05 10:19:01 -05:00
Nathan Froyd
0f49a830c9 cranelift-module: expose trap information when defining functions
The current interface of `cranelift-module` requires consumers who want
to be informed about traps to discover that information through
`Module::Product`, which is backend-specific.  Since it's advantageous
to manipulate this information in a backend-agnostic way, this patch
changes `Module::define_function{,_bytes}` to return information about
the traps contained in the function being defined.
2020-03-03 11:37:15 -05:00
bjorn3
0a1bb3ba6c Add TLS support for ELF and MachO (#1174)
* Add TLS support
* Add binemit and legalize tests
* Spill all caller-saved registers when necessary
2020-02-25 17:50:04 -08:00
Nathan Froyd
09c6c5db44 add a "raw" function definition interface to cranelift-module (#1400)
* move trap site definitions into cranelift-module

`cranelift-faerie` and `cranelift-object` already have identical
definitions of structures to represent trap sites.  We might as well
merge them ahead of work to define functions via a raw slice of bytes
with associated traps, which will need some kind of common structure for
representing traps anyway.

* cranelift-module: add `define_function_bytes` interface

This interface is useful when the client needs to precisely specify the
ordering of bytes in a particular function.

* add comment about saving files for `perf`
2020-02-21 15:14:37 -08:00
Philip Craig
51229c3f58 cranelift-module: document that finalize methods may not be relevant 2020-02-10 11:42:11 +01:00
Philip Craig
3c15f8f129 cranelift-object: move relocation processing to finish
This removes the need to call `finalize_definitions` for cranelift-object.
`finalize_definitions` is only intended for backends that produce
finalized functions and data objects, which cranelift-object does not.
2020-02-10 11:42:11 +01:00
Joshua Nelson
fcb0593796 [module] Finalize definitions for the end-user
Closes https://github.com/bytecodealliance/cranelift/issues/1288 by
calling `module.finalize_definitions` whenever `module.finish` is
called.
2019-12-16 12:44:25 +01:00
Josh Triplett
d6b3ca28b4 Add and use a From impl from CodegenError to ModuleError
This will also improve reporting of the chain of errors.
2019-10-30 17:15:09 -07:00
Josh Triplett
7e725cf880 Migrate from failure to thiserror
The failure crate invents its own traits that don't use
std::error::Error (because failure predates certain features added to
Error); this prevents using ? on an error from failure in a function
using Error. The thiserror crate integrates with the standard Error
trait instead.
2019-10-30 17:15:09 -07:00
Josh Triplett
fcf0ad1d5d Log function definition unconditionally
Don't log inside the `.map_err` call, which resulted in only logging
function definitions on codegen errors.
2019-10-30 15:55:26 +01:00
Joshua Nelson
e045a6df27 implement Debug for Linkage
this would have been useful while debugging something in my own project
2019-10-28 11:43:15 +01:00
Peter Huene
9f506692c2 Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
2019-10-24 17:20:12 -07:00
Philip Craig
3293ca6b69 Add cranelift-object 2019-09-09 21:54:20 -07:00
Joshua Nelson
1eb6cd93b2 Fix documentation typo
function -> data object
2019-08-23 15:52:49 +02:00
Benjamin Bouvier
d7d48d5cc6 Add the dyn keyword before trait objects; 2019-06-24 11:42:26 +02:00
Lars T Hansen
420850adf0 Record information about sections of emitted code+data.
The result of the emitter is a vector of bytes holding machine code,
jump tables, and (in the future) other read-only data.  Some clients,
notably Firefox's Wasm compiler, needs to separate the machine code
from the data in order to insert more code directly after the code
generated by Cranelift.

To make such separation possible, we record more information about the
emitted bytes: the sizes of each of the sections of code, jump tables,
and read-only data, as well as the locations within the code that
reference (PC-relatively) the jump tables and read-only data.
2019-05-31 08:39:57 +02:00
bjorn3
abf0048972 Merge data alignment 2019-04-30 14:06:34 +02:00
bjorn3
556d5d45e9 Rustfmt 2019-04-30 14:06:34 +02:00
bjorn3
cb6268118c Make it possible to define data alignment 2019-04-30 14:06:34 +02:00
iximeow
45013a1d2b Expose function definitions and populate FaerieCompiledFunction with function lengths 2019-04-24 14:54:29 -07:00
bjorn3
615499bae8 Remove define_function_peek_compiled 2019-02-15 17:22:26 +01:00