Commit 99a0148a authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1587486 - Update object in the rust profiler. r=mstange

This removes a failure and old target-lexicon dependencies.

Differential Revision: https://phabricator.services.mozilla.com/D48718

--HG--
extra : moz-landing-system : lando
parent 1c67b00d
......@@ -2078,12 +2078,12 @@ dependencies = [
[[package]]
name = "object"
version = "0.13.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"goblin 0.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -2289,7 +2289,7 @@ version = "0.1.0"
dependencies = [
"goblin 0.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"object 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"object 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"thin-vec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -3054,16 +3054,6 @@ dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "target-lexicon"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "target-lexicon"
version = "0.8.1"
......@@ -3984,7 +3974,7 @@ dependencies = [
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d"
"checksum object 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d89ec45bc6b810c6ee998e22953fbf387a40fcbf5014dcbb9e5ba9a09a81ee15"
"checksum object 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81afbc5773e99efe9533d8a539dfac37e531dcd0f4eeb41584bae03ccf76d4c2"
"checksum opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51ecbcb821e1bd256d456fe858aaa7f380b63863eab2eb86eee1bd9f33dd6682"
"checksum ordered-float 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2f0015e9e8e28ee20c581cfbfe47c650cedeb9ed0721090e0b7ebb10b9cdbcc2"
"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13"
......@@ -4076,7 +4066,6 @@ dependencies = [
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203"
"checksum target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0ab4982b8945c35cc1c46a83a9094c414f6828a099ce5dcaa8ee2b04642dcb"
"checksum target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7975cb2c6f37d77b190bc5004a2bb015971464756fde9514651a525ada2a741a"
"checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2"
"checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209"
......
{"files":{"Cargo.lock":"440af8ab126af2257c67fdd2e1f0b144ed63f17a4a0a223211ec31ad1fda4d08","Cargo.toml":"3dd7528275c4d0eef0dd1b918dc6247c7e996383657355b43362f826f59b31fe","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0b74dfa0bcee5c420c6b7f67b4b2658f9ab8388c97b8e733975f2cecbdd668a6","README.md":"5c498b93ff10c038784c5b62c346858c0d53d9d6d1591841c5b6724b0abc9415","examples/nm.rs":"9885cb85700512d63e537b4b60bd2c840aa076721eae2059ba6ae3651be1282e","examples/objcopy.rs":"a05e1b87318be30b6dd67c061c59d77b97efde2af9d5191c9c97978c0410a5eb","examples/objdump.rs":"07a23a2f74b7e46d4cdcf4dab23357a39410b4c4db43179c17e059011e40d45c","src/common.rs":"143f42a0e085e82a022b85680d42322ac912eefc4ab2cb2bee687368fa8615a5","src/lib.rs":"7e559b0af48faca419086a743e3f99794e10a91e8619f8c6e26f113d1935fe14","src/read/any.rs":"12be08836fb2f66026b34434b47cfe275f82cf31b05039ef0545fc324a3b9bce","src/read/coff.rs":"f3a16d71ec8c5692f5435bf51a3ecda49dc727d5d93f5cdef67e7853e31e6dfa","src/read/elf.rs":"68939fc291b2f2c0b6d3d112fd7edf5eaed8b5987d6fda35a1a843843511d325","src/read/macho.rs":"ee575a49c194fdaa9132e1230266269dc4cb497b9a8f1fed635173bba492ead2","src/read/mod.rs":"efdb99a566a971bca815e1d1dd85b9e9800fbe4e3572cf54a7b0ff54111469c2","src/read/pe.rs":"423527bb5fb5b234057d51925f6ac3ea05603618c1d8c6165de2f9c819978d02","src/read/traits.rs":"c73dd0ca832fc74a9addb414ab5ffe430e6c076a0bd934b31e6608e04c61dc5e","src/read/wasm.rs":"5f6e1e24d53429ac9d80f87e7784183a4608d08b3f465df629c86c68f1af56d4","src/write/coff.rs":"9c9ebc226cb585a61e3c96085099b69de0b2b75877093f644b3caacf03b6d03d","src/write/elf.rs":"d6e7bb6db9b29de1c105dfa75c7e561c85e42a05c75c70cf7baffe25d3009d06","src/write/macho.rs":"1ca4e4d75e45badc4bf5b5dfc8a663d1060d85e6c6a94236ffe9db3c09531c5e","src/write/mod.rs":"248ccbc34aa0cdd84e3c413913f05fe1478a4837ad41e3448414289bb73b2671","src/write/string.rs":"a0640f9e0626ca4618a2ac88e17e0d14b053f880d60635ea932ca78b50a114f5","src/write/util.rs":"9629903d556036aa7d6031cffce1fd38c033453a28c0a30eb34fc77aded4a11d","tests/round_trip.rs":"a28b57931275c31b704aed5350da92e43abf4c09c5fb94360c9ab5db6a7c4a78"},"package":"d89ec45bc6b810c6ee998e22953fbf387a40fcbf5014dcbb9e5ba9a09a81ee15"}
\ No newline at end of file
{"files":{"Cargo.lock":"13d8a3b24f9bc7dc5cfcd74213f91d9c122ea1a790085b7d103af3f5c602de76","Cargo.toml":"24e6d432f81cc2b4f74e402c73853de7ba4d1e8f1bddc47966b1e19dc611f8b4","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0b74dfa0bcee5c420c6b7f67b4b2658f9ab8388c97b8e733975f2cecbdd668a6","README.md":"5c498b93ff10c038784c5b62c346858c0d53d9d6d1591841c5b6724b0abc9415","examples/nm.rs":"9885cb85700512d63e537b4b60bd2c840aa076721eae2059ba6ae3651be1282e","examples/objcopy.rs":"6b51b89bea2d9bd5d8651942a2a5c5637e4553b8beeda47221470f676f23ede0","examples/objdump.rs":"07a23a2f74b7e46d4cdcf4dab23357a39410b4c4db43179c17e059011e40d45c","src/common.rs":"143f42a0e085e82a022b85680d42322ac912eefc4ab2cb2bee687368fa8615a5","src/lib.rs":"7e559b0af48faca419086a743e3f99794e10a91e8619f8c6e26f113d1935fe14","src/read/any.rs":"12be08836fb2f66026b34434b47cfe275f82cf31b05039ef0545fc324a3b9bce","src/read/coff.rs":"f3a16d71ec8c5692f5435bf51a3ecda49dc727d5d93f5cdef67e7853e31e6dfa","src/read/elf.rs":"eef3db7f9a0adea79a488548e57270752c5bc79fef6b23beae054d2b29a6acb0","src/read/macho.rs":"236af20d251a618861fce9bd1efac21f239e0e59777b31b256c43085a4497247","src/read/mod.rs":"efdb99a566a971bca815e1d1dd85b9e9800fbe4e3572cf54a7b0ff54111469c2","src/read/pe.rs":"423527bb5fb5b234057d51925f6ac3ea05603618c1d8c6165de2f9c819978d02","src/read/traits.rs":"c73dd0ca832fc74a9addb414ab5ffe430e6c076a0bd934b31e6608e04c61dc5e","src/read/wasm.rs":"5f6e1e24d53429ac9d80f87e7784183a4608d08b3f465df629c86c68f1af56d4","src/write/coff.rs":"9c9ebc226cb585a61e3c96085099b69de0b2b75877093f644b3caacf03b6d03d","src/write/elf.rs":"00f89e6cb97172a0955dcb47911a31399afe3a6896683a6b937cd370645fc7c0","src/write/macho.rs":"c4344af113700ec944817500711f896f0e6600a5ef4c6d8430ff3a1af20d3f0d","src/write/mod.rs":"ef3037aaf61dab9f3ee1c065c1d78420964711527cfe05e829a0715b3d696efd","src/write/string.rs":"a0640f9e0626ca4618a2ac88e17e0d14b053f880d60635ea932ca78b50a114f5","src/write/util.rs":"9629903d556036aa7d6031cffce1fd38c033453a28c0a30eb34fc77aded4a11d","tests/round_trip.rs":"c385fe01e2c42a20a7eb723617ae3417f82b7d950b2425c821038635462ae073"},"package":"81afbc5773e99efe9533d8a539dfac37e531dcd0f4eeb41584bae03ccf76d4c2"}
\ No newline at end of file
......@@ -138,7 +138,7 @@ dependencies = [
[[package]]
name = "object"
version = "0.13.0"
version = "0.14.0"
dependencies = [
"crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -147,7 +147,7 @@ dependencies = [
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-wasm 0.40.0 (registry+https://github.com/rust-lang/crates.io-index)",
"scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -260,7 +260,7 @@ dependencies = [
[[package]]
name = "target-lexicon"
version = "0.4.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -330,7 +330,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
"checksum syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)" = "ec52cd796e5f01d0067225a5392e70084acc4c0013fa71d55166d38a8b307836"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
"checksum target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0ab4982b8945c35cc1c46a83a9094c414f6828a099ce5dcaa8ee2b04642dcb"
"checksum target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7975cb2c6f37d77b190bc5004a2bb015971464756fde9514651a525ada2a741a"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
......
......@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "object"
version = "0.13.0"
version = "0.14.0"
authors = ["Nick Fitzgerald <fitzgen@gmail.com>", "Philip Craig <philipjcraig@gmail.com>"]
exclude = ["/.coveralls.yml", "/.travis.yml"]
description = "A unified interface for parsing object file formats."
......@@ -50,7 +50,7 @@ version = "0.9"
default-features = false
[dependencies.target-lexicon]
version = "0.4"
version = "0.8"
[dependencies.uuid]
version = "0.7"
......
......@@ -37,6 +37,7 @@ fn main() {
};
let mut out_object = write::Object::new(in_object.format(), in_object.architecture());
out_object.mangling = write::Mangling::None;
let mut out_sections = HashMap::new();
for in_section in in_object.sections() {
......
......@@ -10,7 +10,7 @@ use goblin::{elf, strtab};
use scroll::ctx::TryFromCtx;
use scroll::{self, Pread};
use std::{iter, slice};
use target_lexicon::Architecture;
use target_lexicon::{Aarch64Architecture, Architecture, ArmArchitecture};
use crate::read::{
self, Object, ObjectSection, ObjectSegment, Relocation, RelocationEncoding, RelocationKind,
......@@ -89,8 +89,8 @@ where
fn architecture(&self) -> Architecture {
match self.elf.header.e_machine {
elf::header::EM_ARM => Architecture::Arm,
elf::header::EM_AARCH64 => Architecture::Aarch64,
elf::header::EM_ARM => Architecture::Arm(ArmArchitecture::Arm),
elf::header::EM_AARCH64 => Architecture::Aarch64(Aarch64Architecture::Aarch64),
elf::header::EM_386 => Architecture::I386,
elf::header::EM_X86_64 => Architecture::X86_64,
elf::header::EM_MIPS => Architecture::Mips,
......
......@@ -4,7 +4,7 @@ use goblin::container;
use goblin::mach;
use goblin::mach::load_command::CommandVariant;
use std::{fmt, iter, ops, slice};
use target_lexicon::Architecture;
use target_lexicon::{Aarch64Architecture, Architecture, ArmArchitecture};
use uuid::Uuid;
use crate::read::{
......@@ -77,8 +77,8 @@ where
fn architecture(&self) -> Architecture {
match self.macho.header.cputype {
mach::cputype::CPU_TYPE_ARM => Architecture::Arm,
mach::cputype::CPU_TYPE_ARM64 => Architecture::Aarch64,
mach::cputype::CPU_TYPE_ARM => Architecture::Arm(ArmArchitecture::Arm),
mach::cputype::CPU_TYPE_ARM64 => Architecture::Aarch64(Aarch64Architecture::Aarch64),
mach::cputype::CPU_TYPE_X86 => Architecture::I386,
mach::cputype::CPU_TYPE_X86_64 => Architecture::X86_64,
mach::cputype::CPU_TYPE_MIPS => Architecture::Mips,
......@@ -529,30 +529,30 @@ impl<'data, 'file> Iterator for MachORelocationIterator<'data, 'file> {
self.relocations.next()?.ok().map(|reloc| {
let mut encoding = RelocationEncoding::Generic;
let kind = match self.file.macho.header.cputype {
mach::cputype::CPU_TYPE_ARM => match reloc.r_type() {
mach::relocation::ARM_RELOC_VANILLA => RelocationKind::Absolute,
mach::cputype::CPU_TYPE_ARM => match (reloc.r_type(), reloc.r_pcrel()) {
(mach::relocation::ARM_RELOC_VANILLA, 0) => RelocationKind::Absolute,
_ => RelocationKind::Other(reloc.r_info),
},
mach::cputype::CPU_TYPE_ARM64 => match reloc.r_type() {
mach::relocation::ARM64_RELOC_UNSIGNED => RelocationKind::Absolute,
mach::cputype::CPU_TYPE_ARM64 => match (reloc.r_type(), reloc.r_pcrel()) {
(mach::relocation::ARM64_RELOC_UNSIGNED, 0) => RelocationKind::Absolute,
_ => RelocationKind::Other(reloc.r_info),
},
mach::cputype::CPU_TYPE_X86 => match reloc.r_type() {
mach::relocation::GENERIC_RELOC_VANILLA => RelocationKind::Absolute,
mach::cputype::CPU_TYPE_X86 => match (reloc.r_type(), reloc.r_pcrel()) {
(mach::relocation::GENERIC_RELOC_VANILLA, 0) => RelocationKind::Absolute,
_ => RelocationKind::Other(reloc.r_info),
},
mach::cputype::CPU_TYPE_X86_64 => match reloc.r_type() {
mach::relocation::X86_64_RELOC_UNSIGNED => RelocationKind::Absolute,
mach::relocation::X86_64_RELOC_SIGNED => {
mach::cputype::CPU_TYPE_X86_64 => match (reloc.r_type(), reloc.r_pcrel()) {
(mach::relocation::X86_64_RELOC_UNSIGNED, 0) => RelocationKind::Absolute,
(mach::relocation::X86_64_RELOC_SIGNED, 1) => {
encoding = RelocationEncoding::X86RipRelative;
RelocationKind::Relative
}
mach::relocation::X86_64_RELOC_BRANCH => {
(mach::relocation::X86_64_RELOC_BRANCH, 1) => {
encoding = RelocationEncoding::X86Branch;
RelocationKind::Relative
}
mach::relocation::X86_64_RELOC_GOT => RelocationKind::GotRelative,
mach::relocation::X86_64_RELOC_GOT_LOAD => {
(mach::relocation::X86_64_RELOC_GOT, 1) => RelocationKind::GotRelative,
(mach::relocation::X86_64_RELOC_GOT_LOAD, 1) => {
encoding = RelocationEncoding::X86RipRelativeMovq;
RelocationKind::GotRelative
}
......
......@@ -58,8 +58,8 @@ impl Object {
fn elf_has_relocation_addend(&self) -> Result<bool, String> {
Ok(match self.architecture {
Architecture::Arm => false,
Architecture::Aarch64 => false,
Architecture::Arm(_) => false,
Architecture::Aarch64(_) => false,
Architecture::I386 => false,
Architecture::X86_64 => true,
_ => {
......@@ -294,8 +294,8 @@ impl Object {
// Write file header.
let e_machine = match self.architecture {
Architecture::Arm => elf::EM_ARM,
Architecture::Aarch64 => elf::EM_AARCH64,
Architecture::Arm(_) => elf::EM_ARM,
Architecture::Aarch64(_) => elf::EM_AARCH64,
Architecture::I386 => elf::EM_386,
Architecture::X86_64 => elf::EM_X86_64,
_ => {
......
......@@ -182,8 +182,8 @@ impl Object {
// Write file header.
let (cputype, cpusubtype) = match self.architecture {
Architecture::Arm => (mach::CPU_TYPE_ARM, mach::CPU_SUBTYPE_ARM_ALL),
Architecture::Aarch64 => (mach::CPU_TYPE_ARM64, mach::CPU_SUBTYPE_ARM64_ALL),
Architecture::Arm(_) => (mach::CPU_TYPE_ARM, mach::CPU_SUBTYPE_ARM_ALL),
Architecture::Aarch64(_) => (mach::CPU_TYPE_ARM64, mach::CPU_SUBTYPE_ARM64_ALL),
Architecture::I386 => (mach::CPU_TYPE_I386, mach::CPU_SUBTYPE_I386_ALL),
Architecture::X86_64 => (mach::CPU_TYPE_X86_64, mach::CPU_SUBTYPE_X86_64_ALL),
_ => {
......@@ -400,6 +400,9 @@ impl Object {
(RelocationKind::Absolute, RelocationEncoding::Generic, 0) => {
(0, mach::X86_64_RELOC_UNSIGNED)
}
(RelocationKind::Relative, RelocationEncoding::Generic, -4) => {
(1, mach::X86_64_RELOC_SIGNED)
}
(RelocationKind::Relative, RelocationEncoding::X86RipRelative, -4) => {
(1, mach::X86_64_RELOC_SIGNED)
}
......@@ -409,14 +412,14 @@ impl Object {
(RelocationKind::PltRelative, RelocationEncoding::X86Branch, -4) => {
(1, mach::X86_64_RELOC_BRANCH)
}
(RelocationKind::GotRelative, RelocationEncoding::Generic, -4) => {
(1, mach::X86_64_RELOC_GOT)
}
(
RelocationKind::GotRelative,
RelocationEncoding::X86RipRelativeMovq,
-4,
) => (1, mach::X86_64_RELOC_GOT_LOAD),
(RelocationKind::GotRelative, RelocationEncoding::Generic, -4) => {
(1, mach::X86_64_RELOC_GOT)
}
_ => return Err(format!("unimplemented relocation {:?}", reloc)),
},
_ => {
......
......@@ -29,6 +29,8 @@ pub struct Object {
symbol_map: HashMap<Vec<u8>, SymbolId>,
stub_symbols: HashMap<SymbolId, SymbolId>,
subsection_via_symbols: bool,
/// The symbol name mangling scheme.
pub mangling: Mangling,
}
impl Object {
......@@ -43,6 +45,7 @@ impl Object {
symbol_map: HashMap::new(),
stub_symbols: HashMap::new(),
subsection_via_symbols: false,
mangling: Mangling::default(format, architecture),
}
}
......@@ -58,6 +61,18 @@ impl Object {
self.architecture
}
/// Return the current mangling setting.
#[inline]
pub fn mangling(&self) -> Mangling {
self.mangling
}
/// Return the current mangling setting.
#[inline]
pub fn set_mangling(&mut self, mangling: Mangling) {
self.mangling = mangling;
}
/// Return the name for a standard segment.
///
/// This will vary based on the file format.
......@@ -210,15 +225,20 @@ impl Object {
}
/// Add a new symbol and return its `SymbolId`.
pub fn add_symbol(&mut self, symbol: Symbol) -> SymbolId {
pub fn add_symbol(&mut self, mut symbol: Symbol) -> SymbolId {
// Defined symbols must have a scope.
debug_assert!(symbol.is_undefined() || symbol.scope != SymbolScope::Unknown);
if symbol.kind == SymbolKind::Section {
return self.section_symbol(symbol.section.unwrap());
}
let symbol_id = SymbolId(self.symbols.len());
if !symbol.name.is_empty() {
if !symbol.name.is_empty()
&& (symbol.kind == SymbolKind::Text || symbol.kind == SymbolKind::Data)
{
self.symbol_map.insert(symbol.name.clone(), symbol_id);
if let Some(prefix) = self.mangling.global_prefix() {
symbol.name.insert(0, prefix);
}
}
self.symbols.push(symbol);
symbol_id
......@@ -530,3 +550,36 @@ pub struct Relocation {
/// This may be in addition to an implicit addend stored at the place of the relocation.
pub addend: i64,
}
/// The symbol name mangling scheme.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mangling {
/// No symbol mangling.
None,
/// Windows COFF symbol mangling.
Coff,
/// ELF symbol mangling.
Elf,
/// Mach-O symbol mangling.
Macho,
}
impl Mangling {
/// Return the default symboling mangling for the given format and architecture.
pub fn default(format: BinaryFormat, _architecture: Architecture) -> Self {
match format {
BinaryFormat::Coff => Mangling::Coff,
BinaryFormat::Elf => Mangling::Elf,
BinaryFormat::Macho => Mangling::Macho,
_ => Mangling::None,
}
}
/// Return the prefix to use for global symbols.
pub fn global_prefix(self) -> Option<u8> {
match self {
Mangling::None | Mangling::Elf => None,
Mangling::Coff | Mangling::Macho => Some(b'_'),
}
}
}
......@@ -51,12 +51,14 @@ fn coff_x86_64() {
assert_eq!(text.kind(), SectionKind::Text);
assert_eq!(text.address(), 0);
assert_eq!(text.size(), 62);
assert_eq!(&text.data()[..30], &[1; 30]);
assert_eq!(&text.data()[32..62], &[1; 30]);
let mut symbols = object.symbols();
let (func1_symbol, symbol) = symbols.next().unwrap();
println!("{:?}", symbol);
assert_eq!(symbol.name(), Some("func1"));
assert_eq!(symbol.name(), Some("_func1"));
assert_eq!(symbol.address(), func1_offset);
assert_eq!(symbol.kind(), SymbolKind::Text);
assert_eq!(symbol.section_index(), Some(text_index));
......@@ -132,6 +134,8 @@ fn elf_x86_64() {
assert_eq!(text.kind(), SectionKind::Text);
assert_eq!(text.address(), 0);
assert_eq!(text.size(), 62);
assert_eq!(&text.data()[..30], &[1; 30]);
assert_eq!(&text.data()[32..62], &[1; 30]);
let mut symbols = object.symbols();
......@@ -201,6 +205,19 @@ fn macho_x86_64() {
},
)
.unwrap();
object
.add_relocation(
text,
write::Relocation {
offset: 16,
size: 32,
kind: RelocationKind::Relative,
encoding: RelocationEncoding::Generic,
symbol: func1_symbol,
addend: -4,
},
)
.unwrap();
let bytes = object.write().unwrap();
let object = read::File::parse(&bytes).unwrap();
......@@ -217,12 +234,14 @@ fn macho_x86_64() {
assert_eq!(text.kind(), SectionKind::Text);
assert_eq!(text.address(), 0);
assert_eq!(text.size(), 62);
assert_eq!(&text.data()[..30], &[1; 30]);
assert_eq!(&text.data()[32..62], &[1; 30]);
let mut symbols = object.symbols();
let (func1_symbol, symbol) = symbols.next().unwrap();
println!("{:?}", symbol);
assert_eq!(symbol.name(), Some("func1"));
assert_eq!(symbol.name(), Some("_func1"));
assert_eq!(symbol.address(), func1_offset);
assert_eq!(symbol.kind(), SymbolKind::Text);
assert_eq!(symbol.section_index(), Some(text_index));
......@@ -243,4 +262,16 @@ fn macho_x86_64() {
read::RelocationTarget::Symbol(func1_symbol)
);
assert_eq!(relocation.addend(), 0);
let (offset, relocation) = relocations.next().unwrap();
println!("{:?}", relocation);
assert_eq!(offset, 16);
assert_eq!(relocation.kind(), RelocationKind::Relative);
assert_eq!(relocation.encoding(), RelocationEncoding::X86RipRelative);
assert_eq!(relocation.size(), 32);
assert_eq!(
relocation.target(),
read::RelocationTarget::Symbol(func1_symbol)
);
assert_eq!(relocation.addend(), -4);
}
{"files":{"Cargo.toml":"615784e9f863ec4eeb00066ba899ab2fd8cf6619abcc35411f47ed29745b88ad","LICENSE":"268872b9816f90fd8e85db5a28d33f8150ebb8dd016653fb39ef1f94f2686bc5","README.md":"89f73d9404c960632bef4cfde9709862dbb510081180318e0be7bf12d18e9da7","build.rs":"800c0d76136d72e2894a7a3eb603ce02fc4da5d96c46b970edf6f909b999741e","examples/misc.rs":"49a579845450b7b020ed5c97dca142fc548725893cbc82f6f750ee0caab2beca","src/host.rs":"fb543df4f362e9119a58523563e453110f4e3a426f0995911d0ca386657cf1d9","src/lib.rs":"69b1b9e21c0b6e447fd53991a60e7ab20f814c2ab5faa7870e3423bf588c658f","src/parse_error.rs":"9f6897c0f0b5b666ce5e7ff1f3e3001964397d3e5f933884036b14f52b612363","src/targets.rs":"ebd909b42ad8fcec6486170076f3b6454365377b2e23dbed56cf007c761ff490","src/triple.rs":"aba17839dd6895927d3d75fd5b83698df8be6d3ea64d7c0235c62acf12645a33"},"package":"1b0ab4982b8945c35cc1c46a83a9094c414f6828a099ce5dcaa8ee2b04642dcb"}
\ No newline at end of file
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "target-lexicon"
version = "0.4.0"
authors = ["Dan Gohman <sunfish@mozilla.com>"]
description = "Targeting utilities for compilers and related tools"
documentation = "https://docs.rs/target-lexicon/"
readme = "README.md"
keywords = ["target", "host", "triple", "compiler", "jit"]
categories = ["no-std"]
license = "Apache-2.0 WITH LLVM-exception"
repository = "https://github.com/CraneStation/target-lexicon"
[dependencies.failure]
version = "0.1.3"
features = ["derive"]
default-features = false
[dependencies.failure_derive]
version = "0.1.3"
default-features = false
[build-dependencies.serde_json]
version = "1.0"
[features]
default = ["std"]
std = []
[badges.maintenance]
status = "passively-maintained"
[badges.travis-ci]
repository = "CraneStation/target-lexicon"
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