Merge pull request #2141 from bytecodealliance/pch/cranelift_faerie_deprecated
delete cranelift-faerie
This commit is contained in:
54
Cargo.lock
generated
54
Cargo.lock
generated
@@ -414,18 +414,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cranelift-faerie"
|
||||
version = "0.66.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cranelift-codegen",
|
||||
"cranelift-module",
|
||||
"faerie",
|
||||
"goblin",
|
||||
"target-lexicon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cranelift-filetests"
|
||||
version = "0.66.0"
|
||||
@@ -561,7 +549,6 @@ dependencies = [
|
||||
"cranelift",
|
||||
"cranelift-codegen",
|
||||
"cranelift-entity",
|
||||
"cranelift-faerie",
|
||||
"cranelift-filetests",
|
||||
"cranelift-frontend",
|
||||
"cranelift-interpreter",
|
||||
@@ -825,21 +812,6 @@ version = "0.0.0"
|
||||
name = "example-wasi-wasm"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "faerie"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfef65b0e94693295c5d2fe2506f0ee6f43465342d4b5331659936aee8b16084"
|
||||
dependencies = [
|
||||
"goblin",
|
||||
"indexmap",
|
||||
"log",
|
||||
"scroll",
|
||||
"string-interner",
|
||||
"target-lexicon",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fake-simd"
|
||||
version = "0.1.2"
|
||||
@@ -951,17 +923,6 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
|
||||
[[package]]
|
||||
name = "goblin"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3081214398d39e4bd7f2c1975f0488ed04614ffdd976c6fc7a0708278552c0da"
|
||||
dependencies = [
|
||||
"log",
|
||||
"plain",
|
||||
"scroll",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.6.3"
|
||||
@@ -1384,12 +1345,6 @@ dependencies = [
|
||||
name = "peepmatic-traits"
|
||||
version = "0.66.0"
|
||||
|
||||
[[package]]
|
||||
name = "plain"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.8"
|
||||
@@ -1962,15 +1917,6 @@ version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fbd8c65873d2e06991c33399d5e4bccba6ba04743fe99e9656afa0c64137d2c"
|
||||
|
||||
[[package]]
|
||||
name = "string-interner"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd710eadff449a1531351b0e43eb81ea404336fa2f56c777427ab0e32a4cf183"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
|
||||
@@ -25,7 +25,6 @@ cranelift-wasm = { path = "wasm", version = "0.66.0", optional = true }
|
||||
cranelift-native = { path = "native", version = "0.66.0" }
|
||||
cranelift-filetests = { path = "filetests", version = "0.66.0" }
|
||||
cranelift-module = { path = "module", version = "0.66.0" }
|
||||
cranelift-faerie = { path = "faerie", version = "0.66.0" }
|
||||
cranelift-object = { path = "object", version = "0.66.0" }
|
||||
cranelift-simplejit = { path = "simplejit", version = "0.66.0" }
|
||||
cranelift-preopt = { path = "preopt", version = "0.66.0" }
|
||||
|
||||
@@ -52,11 +52,6 @@
|
||||
emits native object files using the
|
||||
`object <https://github.com/gimli-rs/object>`_ library.
|
||||
|
||||
- [cranelift-faerie](https://docs.rs/cranelift-faerie)
|
||||
This crate provides a faerie-based backend for `cranelift-module`, which
|
||||
emits native object files using the
|
||||
`faerie <https://github.com/m4b/faerie>`_ library.
|
||||
|
||||
- [cranelift-simplejit](https://docs.rs/cranelift-simplejit)
|
||||
This crate provides a simple JIT backend for `cranelift-module`, which
|
||||
emits code and data into memory.
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
[package]
|
||||
name = "cranelift-faerie"
|
||||
version = "0.66.0"
|
||||
authors = ["The Cranelift Project Developers"]
|
||||
description = "Emit Cranelift output to native object files with Faerie"
|
||||
repository = "https://github.com/bytecodealliance/wasmtime"
|
||||
documentation = "https://docs.rs/cranelift-faerie"
|
||||
license = "Apache-2.0 WITH LLVM-exception"
|
||||
readme = "README.md"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
cranelift-module = { path = "../module", version = "0.66.0" }
|
||||
cranelift-codegen = { path = "../codegen", version = "0.66.0", default-features = false, features = ["std"] }
|
||||
faerie = "0.15.0"
|
||||
goblin = "0.1.0"
|
||||
anyhow = "1.0"
|
||||
target-lexicon = "0.10"
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "experimental" }
|
||||
@@ -1,220 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
--- LLVM Exceptions to the Apache 2.0 License ----
|
||||
|
||||
As an exception, if, as a result of your compiling your source code, portions
|
||||
of this Software are embedded into an Object form of such source code, you
|
||||
may redistribute such embedded portions in such Object form without complying
|
||||
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
||||
|
||||
In addition, if you combine or link compiled forms of this Software with
|
||||
software that is licensed under the GPLv2 ("Combined Software") and if a
|
||||
court of competent jurisdiction determines that the patent provision (Section
|
||||
3), the indemnity provision (Section 9) or other Section of the License
|
||||
conflicts with the conditions of the GPLv2, you may retroactively and
|
||||
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
||||
the License, but only in their entirety and only with respect to the Combined
|
||||
Software.
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
This crate contains a library that enables
|
||||
[Cranelift](https://crates.io/crates/cranelift)
|
||||
to emit native object (".o") files, using the
|
||||
[Faerie](https://crates.io/crates/faerie) library.
|
||||
|
||||
DEPRECATION NOTICE: the Cranelift developer team intends to stop maintaining
|
||||
the `cranelift-faerie` crate and remove it from the `wasmtime` git repository
|
||||
on or after August 3, 2020. We recommend users use its successor, the
|
||||
`cranelift-object` crate.
|
||||
@@ -1,482 +0,0 @@
|
||||
//! Defines `FaerieBackend`.
|
||||
|
||||
use crate::container;
|
||||
use anyhow::anyhow;
|
||||
use cranelift_codegen::binemit::{
|
||||
Addend, CodeOffset, NullStackMapSink, Reloc, RelocSink, StackMap, StackMapSink, TrapSink,
|
||||
};
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::{self, binemit, ir};
|
||||
use cranelift_module::{
|
||||
Backend, DataContext, DataDescription, DataId, FuncId, Init, Linkage, ModuleError,
|
||||
ModuleNamespace, ModuleResult,
|
||||
};
|
||||
use faerie;
|
||||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
use target_lexicon::Triple;
|
||||
|
||||
/// A builder for `FaerieBackend`.
|
||||
pub struct FaerieBuilder {
|
||||
isa: Box<dyn TargetIsa>,
|
||||
name: String,
|
||||
libcall_names: Box<dyn Fn(ir::LibCall) -> String>,
|
||||
}
|
||||
|
||||
impl FaerieBuilder {
|
||||
/// Create a new `FaerieBuilder` using the given Cranelift target, that
|
||||
/// can be passed to
|
||||
/// [`Module::new`](cranelift_module::Module::new)
|
||||
///
|
||||
/// Faerie output requires that TargetIsa have PIC (Position Independent Code) enabled.
|
||||
///
|
||||
/// The `libcall_names` function provides a way to translate `cranelift_codegen`'s `ir::LibCall`
|
||||
/// enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain
|
||||
/// floating point instructions, and for stack probes. If you don't know what to use for this
|
||||
/// argument, use `cranelift_module::default_libcall_names()`.
|
||||
#[deprecated(
|
||||
since = "0.65.0",
|
||||
note = "the Cranelift developer team intends to stop maintaining the `cranelift-faerie`
|
||||
crate and remove it from the `wasmtime` git repository on or after August 3, 2020. We
|
||||
recommend users use its successor, the `cranelift-object` crate."
|
||||
)]
|
||||
pub fn new(
|
||||
isa: Box<dyn TargetIsa>,
|
||||
name: String,
|
||||
libcall_names: Box<dyn Fn(ir::LibCall) -> String>,
|
||||
) -> ModuleResult<Self> {
|
||||
if !isa.flags().is_pic() {
|
||||
return Err(ModuleError::Backend(anyhow!(
|
||||
"faerie requires TargetIsa be PIC"
|
||||
)));
|
||||
}
|
||||
Ok(Self {
|
||||
isa,
|
||||
name,
|
||||
libcall_names,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A `FaerieBackend` implements `Backend` and emits ".o" files using the `faerie` library.
|
||||
///
|
||||
/// See the `FaerieBuilder` for a convenient way to construct `FaerieBackend` instances.
|
||||
pub struct FaerieBackend {
|
||||
isa: Box<dyn TargetIsa>,
|
||||
artifact: faerie::Artifact,
|
||||
libcall_names: Box<dyn Fn(ir::LibCall) -> String>,
|
||||
}
|
||||
|
||||
pub struct FaerieCompiledFunction {
|
||||
code_length: u32,
|
||||
}
|
||||
|
||||
impl FaerieCompiledFunction {
|
||||
pub fn code_length(&self) -> u32 {
|
||||
self.code_length
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FaerieCompiledData {}
|
||||
|
||||
impl Backend for FaerieBackend {
|
||||
type Builder = FaerieBuilder;
|
||||
|
||||
type CompiledFunction = FaerieCompiledFunction;
|
||||
type CompiledData = FaerieCompiledData;
|
||||
|
||||
// There's no need to return individual artifacts; we're writing them into
|
||||
// the output file instead.
|
||||
type FinalizedFunction = ();
|
||||
type FinalizedData = ();
|
||||
|
||||
/// The returned value here provides functions for emitting object files
|
||||
/// to memory and files.
|
||||
type Product = FaerieProduct;
|
||||
|
||||
/// Create a new `FaerieBackend` using the given Cranelift target.
|
||||
fn new(builder: FaerieBuilder) -> Self {
|
||||
Self {
|
||||
artifact: faerie::Artifact::new(builder.isa.triple().clone(), builder.name),
|
||||
isa: builder.isa,
|
||||
libcall_names: builder.libcall_names,
|
||||
}
|
||||
}
|
||||
|
||||
fn isa(&self) -> &dyn TargetIsa {
|
||||
&*self.isa
|
||||
}
|
||||
|
||||
fn declare_function(&mut self, _id: FuncId, name: &str, linkage: Linkage) {
|
||||
self.artifact
|
||||
.declare(name, translate_function_linkage(linkage))
|
||||
.expect("inconsistent declarations");
|
||||
}
|
||||
|
||||
fn declare_data(
|
||||
&mut self,
|
||||
_id: DataId,
|
||||
name: &str,
|
||||
linkage: Linkage,
|
||||
writable: bool,
|
||||
tls: bool,
|
||||
align: Option<u8>,
|
||||
) {
|
||||
assert!(!tls, "Faerie doesn't yet support TLS");
|
||||
self.artifact
|
||||
.declare(name, translate_data_linkage(linkage, writable, align))
|
||||
.expect("inconsistent declarations");
|
||||
}
|
||||
|
||||
fn define_function<TS>(
|
||||
&mut self,
|
||||
_id: FuncId,
|
||||
name: &str,
|
||||
ctx: &cranelift_codegen::Context,
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
total_size: u32,
|
||||
trap_sink: &mut TS,
|
||||
) -> ModuleResult<FaerieCompiledFunction>
|
||||
where
|
||||
TS: TrapSink,
|
||||
{
|
||||
let mut code: Vec<u8> = vec![0; total_size as usize];
|
||||
// TODO: Replace this with FaerieStackMapSink once it is implemented.
|
||||
let mut stack_map_sink = NullStackMapSink {};
|
||||
|
||||
// Non-lexical lifetimes would obviate the braces here.
|
||||
{
|
||||
let mut reloc_sink = FaerieRelocSink {
|
||||
triple: self.isa.triple().clone(),
|
||||
artifact: &mut self.artifact,
|
||||
name,
|
||||
namespace,
|
||||
libcall_names: &*self.libcall_names,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
ctx.emit_to_memory(
|
||||
&*self.isa,
|
||||
code.as_mut_ptr(),
|
||||
&mut reloc_sink,
|
||||
trap_sink,
|
||||
&mut stack_map_sink,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// because `define` will take ownership of code, this is our last chance
|
||||
let code_length = code.len() as u32;
|
||||
|
||||
self.artifact
|
||||
.define(name, code)
|
||||
.expect("inconsistent declaration");
|
||||
|
||||
Ok(FaerieCompiledFunction { code_length })
|
||||
}
|
||||
|
||||
fn define_function_bytes(
|
||||
&mut self,
|
||||
_id: FuncId,
|
||||
name: &str,
|
||||
bytes: &[u8],
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
) -> ModuleResult<FaerieCompiledFunction> {
|
||||
let code_length: u32 = match bytes.len().try_into() {
|
||||
Ok(code_length) => code_length,
|
||||
_ => Err(ModuleError::FunctionTooLarge(name.to_string()))?,
|
||||
};
|
||||
|
||||
self.artifact
|
||||
.define(name, bytes.to_vec())
|
||||
.expect("inconsistent declaration");
|
||||
|
||||
Ok(FaerieCompiledFunction { code_length })
|
||||
}
|
||||
|
||||
fn define_data(
|
||||
&mut self,
|
||||
_id: DataId,
|
||||
name: &str,
|
||||
_writable: bool,
|
||||
tls: bool,
|
||||
_align: Option<u8>,
|
||||
data_ctx: &DataContext,
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
) -> ModuleResult<FaerieCompiledData> {
|
||||
assert!(!tls, "Faerie doesn't yet support TLS");
|
||||
let &DataDescription {
|
||||
ref init,
|
||||
ref function_decls,
|
||||
ref data_decls,
|
||||
ref function_relocs,
|
||||
ref data_relocs,
|
||||
ref custom_segment_section,
|
||||
} = data_ctx.description();
|
||||
|
||||
if let Some((segment, section)) = custom_segment_section {
|
||||
return Err(cranelift_module::ModuleError::Backend(anyhow::anyhow!(
|
||||
"Custom section not supported by cranelift-faerie: `{}:{}`",
|
||||
segment,
|
||||
section
|
||||
)));
|
||||
}
|
||||
|
||||
for &(offset, id) in function_relocs {
|
||||
let to = &namespace.get_function_decl(&function_decls[id]).name;
|
||||
self.artifact
|
||||
.link(faerie::Link {
|
||||
from: name,
|
||||
to,
|
||||
at: u64::from(offset),
|
||||
})
|
||||
.map_err(|e| ModuleError::Backend(e.into()))?;
|
||||
}
|
||||
for &(offset, id, addend) in data_relocs {
|
||||
debug_assert_eq!(
|
||||
addend, 0,
|
||||
"faerie doesn't support addends in data section relocations yet"
|
||||
);
|
||||
let to = &namespace.get_data_decl(&data_decls[id]).name;
|
||||
self.artifact
|
||||
.link(faerie::Link {
|
||||
from: name,
|
||||
to,
|
||||
at: u64::from(offset),
|
||||
})
|
||||
.map_err(|e| ModuleError::Backend(e.into()))?;
|
||||
}
|
||||
|
||||
match *init {
|
||||
Init::Uninitialized => {
|
||||
panic!("data is not initialized yet");
|
||||
}
|
||||
Init::Zeros { size } => {
|
||||
self.artifact
|
||||
.define_zero_init(name, size)
|
||||
.expect("inconsistent declaration");
|
||||
}
|
||||
Init::Bytes { ref contents } => {
|
||||
self.artifact
|
||||
.define(name, contents.to_vec())
|
||||
.expect("inconsistent declaration");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(FaerieCompiledData {})
|
||||
}
|
||||
|
||||
fn write_data_funcaddr(
|
||||
&mut self,
|
||||
_data: &mut FaerieCompiledData,
|
||||
_offset: usize,
|
||||
_what: ir::FuncRef,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn write_data_dataaddr(
|
||||
&mut self,
|
||||
_data: &mut FaerieCompiledData,
|
||||
_offset: usize,
|
||||
_what: ir::GlobalValue,
|
||||
_usize: binemit::Addend,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn finalize_function(
|
||||
&mut self,
|
||||
_id: FuncId,
|
||||
_func: &FaerieCompiledFunction,
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
fn get_finalized_function(&self, _func: &FaerieCompiledFunction) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
fn finalize_data(
|
||||
&mut self,
|
||||
_id: DataId,
|
||||
_data: &FaerieCompiledData,
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
fn get_finalized_data(&self, _data: &FaerieCompiledData) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
fn publish(&mut self) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
fn finish(self, _namespace: &ModuleNamespace<Self>) -> FaerieProduct {
|
||||
FaerieProduct {
|
||||
artifact: self.artifact,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This is the output of `Module`'s
|
||||
/// [`finish`](../cranelift_module/struct.Module.html#method.finish) function.
|
||||
/// It provides functions for writing out the object file to memory or a file.
|
||||
#[derive(Debug)]
|
||||
pub struct FaerieProduct {
|
||||
/// Faerie artifact with all functions, data, and links from the module defined
|
||||
pub artifact: faerie::Artifact,
|
||||
}
|
||||
|
||||
impl FaerieProduct {
|
||||
/// Return the name of the output file. This is the name passed into `new`.
|
||||
pub fn name(&self) -> &str {
|
||||
&self.artifact.name
|
||||
}
|
||||
|
||||
/// Call `emit` on the faerie `Artifact`, producing bytes in memory.
|
||||
pub fn emit(&self) -> Result<Vec<u8>, faerie::ArtifactError> {
|
||||
self.artifact.emit()
|
||||
}
|
||||
|
||||
/// Call `write` on the faerie `Artifact`, writing to a file.
|
||||
pub fn write(&self, sink: File) -> Result<(), faerie::ArtifactError> {
|
||||
self.artifact.write(sink)
|
||||
}
|
||||
}
|
||||
|
||||
fn translate_function_linkage(linkage: Linkage) -> faerie::Decl {
|
||||
match linkage {
|
||||
Linkage::Import => faerie::Decl::function_import().into(),
|
||||
Linkage::Local => faerie::Decl::function().into(),
|
||||
Linkage::Preemptible => faerie::Decl::function().weak().into(),
|
||||
Linkage::Hidden => faerie::Decl::function().global().hidden().into(),
|
||||
Linkage::Export => faerie::Decl::function().global().into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn translate_data_linkage(linkage: Linkage, writable: bool, align: Option<u8>) -> faerie::Decl {
|
||||
let align = align.map(u64::from);
|
||||
match linkage {
|
||||
Linkage::Import => faerie::Decl::data_import().into(),
|
||||
Linkage::Local => faerie::Decl::data()
|
||||
.with_writable(writable)
|
||||
.with_align(align)
|
||||
.into(),
|
||||
Linkage::Preemptible => faerie::Decl::data()
|
||||
.weak()
|
||||
.with_writable(writable)
|
||||
.with_align(align)
|
||||
.into(),
|
||||
Linkage::Hidden => faerie::Decl::data()
|
||||
.global()
|
||||
.hidden()
|
||||
.with_writable(writable)
|
||||
.with_align(align)
|
||||
.into(),
|
||||
Linkage::Export => faerie::Decl::data()
|
||||
.global()
|
||||
.with_writable(writable)
|
||||
.with_align(align)
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
|
||||
struct FaerieRelocSink<'a> {
|
||||
triple: Triple,
|
||||
artifact: &'a mut faerie::Artifact,
|
||||
name: &'a str,
|
||||
namespace: &'a ModuleNamespace<'a, FaerieBackend>,
|
||||
libcall_names: &'a dyn Fn(ir::LibCall) -> String,
|
||||
}
|
||||
|
||||
impl<'a> RelocSink for FaerieRelocSink<'a> {
|
||||
fn reloc_block(&mut self, _offset: CodeOffset, _reloc: Reloc, _block_offset: CodeOffset) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: Reloc,
|
||||
name: &ir::ExternalName,
|
||||
addend: Addend,
|
||||
) {
|
||||
let ref_name: String = match *name {
|
||||
ir::ExternalName::User { .. } => {
|
||||
if self.namespace.is_function(name) {
|
||||
self.namespace.get_function_decl(name).name.clone()
|
||||
} else {
|
||||
self.namespace.get_data_decl(name).name.clone()
|
||||
}
|
||||
}
|
||||
ir::ExternalName::LibCall(ref libcall) => {
|
||||
let sym = (self.libcall_names)(*libcall);
|
||||
self.artifact
|
||||
.declare(sym.clone(), faerie::Decl::function_import())
|
||||
.expect("faerie declaration of libcall");
|
||||
sym
|
||||
}
|
||||
_ => panic!("invalid ExternalName {}", name),
|
||||
};
|
||||
let (raw_reloc, raw_addend) = container::raw_relocation(reloc, &self.triple);
|
||||
// TODO: Handle overflow.
|
||||
let final_addend = addend + raw_addend;
|
||||
let addend_i32 = final_addend as i32;
|
||||
debug_assert!(i64::from(addend_i32) == final_addend);
|
||||
self.artifact
|
||||
.link_with(
|
||||
faerie::Link {
|
||||
from: self.name,
|
||||
to: &ref_name,
|
||||
at: u64::from(offset),
|
||||
},
|
||||
faerie::Reloc::Raw {
|
||||
reloc: raw_reloc,
|
||||
addend: addend_i32,
|
||||
},
|
||||
)
|
||||
.expect("faerie relocation error");
|
||||
}
|
||||
|
||||
fn reloc_jt(&mut self, _offset: CodeOffset, reloc: Reloc, _jt: ir::JumpTable) {
|
||||
match reloc {
|
||||
Reloc::X86PCRelRodata4 => {
|
||||
// Not necessary to record this unless we are going to split apart code and its
|
||||
// jumptbl/rodata.
|
||||
}
|
||||
_ => {
|
||||
panic!("Unhandled reloc");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn reloc_constant(&mut self, _offset: CodeOffset, reloc: Reloc, _jt: ir::ConstantOffset) {
|
||||
match reloc {
|
||||
Reloc::X86PCRelRodata4 => {
|
||||
// Not necessary to record this unless we are going to split apart code and its
|
||||
// jumptbl/rodata.
|
||||
}
|
||||
_ => {
|
||||
panic!("Unhandled reloc");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct FaerieStackMapSink<'a> {
|
||||
artifact: &'a mut faerie::Artifact,
|
||||
namespace: &'a ModuleNamespace<'a, FaerieBackend>,
|
||||
}
|
||||
|
||||
/// Faerie is currently not used in SpiderMonkey. Methods are unimplemented.
|
||||
impl<'a> StackMapSink for FaerieStackMapSink<'a> {
|
||||
fn add_stack_map(&mut self, _: CodeOffset, _: StackMap) {
|
||||
unimplemented!("faerie support for stack maps");
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
//! Utilities for working with Faerie container formats.
|
||||
|
||||
use cranelift_codegen::binemit::Reloc;
|
||||
use target_lexicon::{Architecture, BinaryFormat, Triple};
|
||||
|
||||
/// An object file format.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum Format {
|
||||
/// The ELF object file format.
|
||||
ELF,
|
||||
/// The Mach-O object file format.
|
||||
MachO,
|
||||
}
|
||||
|
||||
/// Translate from a Cranelift `Reloc` to a raw object-file-format-specific
|
||||
/// relocation code and relocation-implied addend.
|
||||
pub fn raw_relocation(reloc: Reloc, triple: &Triple) -> (u32, i64) {
|
||||
match triple.binary_format {
|
||||
BinaryFormat::Elf => {
|
||||
use goblin::elf;
|
||||
(
|
||||
match triple.architecture {
|
||||
Architecture::X86_64 => {
|
||||
match reloc {
|
||||
Reloc::Abs4 => elf::reloc::R_X86_64_32,
|
||||
Reloc::Abs8 => elf::reloc::R_X86_64_64,
|
||||
Reloc::X86PCRel4 | Reloc::X86CallPCRel4 => elf::reloc::R_X86_64_PC32,
|
||||
// TODO: Get Cranelift to tell us when we can use
|
||||
// R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX.
|
||||
Reloc::X86CallPLTRel4 => elf::reloc::R_X86_64_PLT32,
|
||||
Reloc::X86GOTPCRel4 => elf::reloc::R_X86_64_GOTPCREL,
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("unsupported architecture: {}", triple),
|
||||
},
|
||||
// Most ELF relocations do not include an implicit addend.
|
||||
0,
|
||||
)
|
||||
}
|
||||
BinaryFormat::Macho => {
|
||||
use goblin::mach;
|
||||
match triple.architecture {
|
||||
Architecture::X86_64 => {
|
||||
match reloc {
|
||||
Reloc::Abs8 => (u32::from(mach::relocation::R_ABS), 0),
|
||||
// Mach-O doesn't need us to distinguish between PC-relative calls
|
||||
// and PLT calls, but it does need us to distinguish between calls
|
||||
// and non-calls. And, it includes the 4-byte addend implicitly.
|
||||
Reloc::X86PCRel4 => (u32::from(mach::relocation::X86_64_RELOC_SIGNED), 4),
|
||||
Reloc::X86CallPCRel4 | Reloc::X86CallPLTRel4 => {
|
||||
(u32::from(mach::relocation::X86_64_RELOC_BRANCH), 4)
|
||||
}
|
||||
Reloc::X86GOTPCRel4 => {
|
||||
(u32::from(mach::relocation::X86_64_RELOC_GOT_LOAD), 4)
|
||||
}
|
||||
_ => unimplemented!("unsupported mach-o reloc: {}", reloc),
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("unsupported architecture: {}", triple),
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("unsupported format"),
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
//! Top-level lib.rs for `cranelift_faerie`.
|
||||
//!
|
||||
//! Users of this module should not have to depend on faerie directly.
|
||||
|
||||
#![deny(
|
||||
missing_docs,
|
||||
trivial_numeric_casts,
|
||||
unused_extern_crates,
|
||||
unstable_features
|
||||
)]
|
||||
#![warn(unused_import_braces)]
|
||||
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
|
||||
#![cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
warn(
|
||||
clippy::float_arithmetic,
|
||||
clippy::mut_mut,
|
||||
clippy::nonminimal_bool,
|
||||
clippy::option_map_unwrap_or,
|
||||
clippy::option_map_unwrap_or_else,
|
||||
clippy::print_stdout,
|
||||
clippy::unicode_not_nfc,
|
||||
clippy::use_self
|
||||
)
|
||||
)]
|
||||
|
||||
mod backend;
|
||||
mod container;
|
||||
|
||||
pub use crate::backend::{FaerieBackend, FaerieBuilder, FaerieProduct};
|
||||
pub use crate::container::Format;
|
||||
|
||||
/// Version number of this crate.
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
@@ -15,9 +15,6 @@ following `Backend` implementations:
|
||||
code to memory for direct execution.
|
||||
- `ObjectBackend`, provided by [cranelift-object], which emits native
|
||||
object files.
|
||||
- `FaerieBackend`, provided by [cranelift-faerie], which emits native
|
||||
object files.
|
||||
|
||||
[cranelift-simplejit]: https://crates.io/crates/cranelift-simplejit
|
||||
[cranelift-object]: https://crates.io/crates/cranelift-object
|
||||
[cranelift-faerie]: https://crates.io/crates/cranelift-faerie
|
||||
|
||||
@@ -22,12 +22,9 @@ use std::string::String;
|
||||
/// the contents of a `Module` to memory which can be directly executed.
|
||||
/// - `ObjectBackend`, defined in [cranelift-object], which writes the
|
||||
/// contents of a `Module` out as a native object file.
|
||||
/// - `FaerieBackend`, defined in [cranelift-faerie], which writes the
|
||||
/// contents of a `Module` out as a native object file.
|
||||
///
|
||||
/// [cranelift-simplejit]: https://docs.rs/cranelift-simplejit/
|
||||
/// [cranelift-object]: https://docs.rs/cranelift-object/
|
||||
/// [cranelift-faerie]: https://docs.rs/cranelift-faerie/
|
||||
pub trait Backend
|
||||
where
|
||||
Self: marker::Sized,
|
||||
|
||||
@@ -34,7 +34,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[
|
||||
"cranelift-preopt",
|
||||
"cranelift-frontend",
|
||||
"cranelift-wasm",
|
||||
"cranelift-faerie",
|
||||
"cranelift-native",
|
||||
"cranelift-object",
|
||||
"cranelift-interpreter",
|
||||
|
||||
Reference in New Issue
Block a user