summaryrefslogtreecommitdiffstats
path: root/vendor/object/src/write
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/object/src/write')
-rw-r--r--vendor/object/src/write/coff.rs3
-rw-r--r--vendor/object/src/write/elf/object.rs60
-rw-r--r--vendor/object/src/write/macho.rs30
3 files changed, 90 insertions, 3 deletions
diff --git a/vendor/object/src/write/coff.rs b/vendor/object/src/write/coff.rs
index 6647b9611..c7489d3d6 100644
--- a/vendor/object/src/write/coff.rs
+++ b/vendor/object/src/write/coff.rs
@@ -117,8 +117,7 @@ impl<'a> Object<'a> {
}
let stub_size = self.architecture.address_size().unwrap().bytes();
- let mut name = b".rdata$.refptr.".to_vec();
- name.extend_from_slice(&self.symbols[symbol_id.0].name);
+ let name = b".rdata$.refptr".to_vec();
let section_id = self.add_section(Vec::new(), name, SectionKind::ReadOnlyData);
let section = self.section_mut(section_id);
section.set_data(vec![0; stub_size as usize], u64::from(stub_size));
diff --git a/vendor/object/src/write/elf/object.rs b/vendor/object/src/write/elf/object.rs
index 8c1fa4717..068ada6bd 100644
--- a/vendor/object/src/write/elf/object.rs
+++ b/vendor/object/src/write/elf/object.rs
@@ -67,6 +67,7 @@ impl<'a> Object<'a> {
fn elf_has_relocation_addend(&self) -> Result<bool> {
Ok(match self.architecture {
Architecture::Aarch64 => true,
+ Architecture::Aarch64_Ilp32 => true,
Architecture::Arm => false,
Architecture::Avr => true,
Architecture::Bpf => false,
@@ -83,7 +84,9 @@ impl<'a> Object<'a> {
Architecture::Riscv64 => true,
Architecture::Riscv32 => true,
Architecture::S390x => true,
+ Architecture::Sbf => false,
Architecture::Sparc64 => true,
+ Architecture::Xtensa => true,
_ => {
return Err(Error(format!(
"unimplemented architecture {:?}",
@@ -264,6 +267,7 @@ impl<'a> Object<'a> {
let e_type = elf::ET_REL;
let e_machine = match self.architecture {
Architecture::Aarch64 => elf::EM_AARCH64,
+ Architecture::Aarch64_Ilp32 => elf::EM_AARCH64,
Architecture::Arm => elf::EM_ARM,
Architecture::Avr => elf::EM_AVR,
Architecture::Bpf => elf::EM_BPF,
@@ -280,7 +284,9 @@ impl<'a> Object<'a> {
Architecture::Riscv32 => elf::EM_RISCV,
Architecture::Riscv64 => elf::EM_RISCV,
Architecture::S390x => elf::EM_S390,
+ Architecture::Sbf => elf::EM_SBF,
Architecture::Sparc64 => elf::EM_SPARCV9,
+ Architecture::Xtensa => elf::EM_XTENSA,
_ => {
return Err(Error(format!(
"unimplemented architecture {:?}",
@@ -450,6 +456,20 @@ impl<'a> Object<'a> {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
},
+ Architecture::Aarch64_Ilp32 => {
+ match (reloc.kind, reloc.encoding, reloc.size) {
+ (RelocationKind::Absolute, RelocationEncoding::Generic, 32) => {
+ elf::R_AARCH64_P32_ABS32
+ }
+ (RelocationKind::Elf(x), _, _) => x,
+ _ => {
+ return Err(Error(format!(
+ "unimplemented relocation {:?}",
+ reloc
+ )));
+ }
+ }
+ }
Architecture::Arm => match (reloc.kind, reloc.encoding, reloc.size) {
(RelocationKind::Absolute, _, 32) => elf::R_ARM_ABS32,
(RelocationKind::Elf(x), _, _) => x,
@@ -528,6 +548,25 @@ impl<'a> Object<'a> {
{
(RelocationKind::Absolute, _, 32) => elf::R_LARCH_32,
(RelocationKind::Absolute, _, 64) => elf::R_LARCH_64,
+ (RelocationKind::Relative, _, 32) => elf::R_LARCH_32_PCREL,
+ (RelocationKind::Relative, RelocationEncoding::LoongArchBranch, 16)
+ | (
+ RelocationKind::PltRelative,
+ RelocationEncoding::LoongArchBranch,
+ 16,
+ ) => elf::R_LARCH_B16,
+ (RelocationKind::Relative, RelocationEncoding::LoongArchBranch, 21)
+ | (
+ RelocationKind::PltRelative,
+ RelocationEncoding::LoongArchBranch,
+ 21,
+ ) => elf::R_LARCH_B21,
+ (RelocationKind::Relative, RelocationEncoding::LoongArchBranch, 26)
+ | (
+ RelocationKind::PltRelative,
+ RelocationEncoding::LoongArchBranch,
+ 26,
+ ) => elf::R_LARCH_B26,
(RelocationKind::Elf(x), _, _) => x,
_ => {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
@@ -574,6 +613,9 @@ impl<'a> Object<'a> {
match (reloc.kind, reloc.encoding, reloc.size) {
(RelocationKind::Absolute, _, 32) => elf::R_RISCV_32,
(RelocationKind::Absolute, _, 64) => elf::R_RISCV_64,
+ (RelocationKind::Relative, RelocationEncoding::Generic, 32) => {
+ elf::R_RISCV_32_PCREL
+ }
(RelocationKind::Elf(x), _, _) => x,
_ => {
return Err(Error(format!(
@@ -649,6 +691,14 @@ impl<'a> Object<'a> {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
},
+ Architecture::Sbf => match (reloc.kind, reloc.encoding, reloc.size) {
+ (RelocationKind::Absolute, _, 64) => elf::R_SBF_64_64,
+ (RelocationKind::Absolute, _, 32) => elf::R_SBF_64_32,
+ (RelocationKind::Elf(x), _, _) => x,
+ _ => {
+ return Err(Error(format!("unimplemented relocation {:?}", reloc)));
+ }
+ },
Architecture::Sparc64 => match (reloc.kind, reloc.encoding, reloc.size) {
// TODO: use R_SPARC_32/R_SPARC_64 if aligned.
(RelocationKind::Absolute, _, 32) => elf::R_SPARC_UA32,
@@ -658,6 +708,16 @@ impl<'a> Object<'a> {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
},
+ Architecture::Xtensa => match (reloc.kind, reloc.encoding, reloc.size) {
+ (RelocationKind::Absolute, _, 32) => elf::R_XTENSA_32,
+ (RelocationKind::Relative, RelocationEncoding::Generic, 32) => {
+ elf::R_XTENSA_32_PCREL
+ }
+ (RelocationKind::Elf(x), _, _) => x,
+ _ => {
+ return Err(Error(format!("unimplemented relocation {:?}", reloc)));
+ }
+ },
_ => {
if let RelocationKind::Elf(x) = reloc.kind {
x
diff --git a/vendor/object/src/write/macho.rs b/vendor/object/src/write/macho.rs
index f689dec51..8ef722fae 100644
--- a/vendor/object/src/write/macho.rs
+++ b/vendor/object/src/write/macho.rs
@@ -175,11 +175,17 @@ impl<'a> Object<'a> {
pub(crate) fn macho_fixup_relocation(&mut self, mut relocation: &mut Relocation) -> i64 {
let constant = match relocation.kind {
+ // AArch64Call relocations have special handling for the addend, so don't adjust it
+ RelocationKind::Relative if relocation.encoding == RelocationEncoding::AArch64Call => 0,
RelocationKind::Relative
| RelocationKind::GotRelative
| RelocationKind::PltRelative => relocation.addend + 4,
_ => relocation.addend,
};
+ // Aarch64 relocs of these sizes act as if they are double-word length
+ if self.architecture == Architecture::Aarch64 && matches!(relocation.size, 12 | 21 | 26) {
+ relocation.size = 32;
+ }
relocation.addend -= constant;
constant
}
@@ -326,6 +332,8 @@ impl<'a> Object<'a> {
Architecture::Aarch64 => (macho::CPU_TYPE_ARM64, macho::CPU_SUBTYPE_ARM64_ALL),
Architecture::I386 => (macho::CPU_TYPE_X86, macho::CPU_SUBTYPE_I386_ALL),
Architecture::X86_64 => (macho::CPU_TYPE_X86_64, macho::CPU_SUBTYPE_X86_64_ALL),
+ Architecture::PowerPc => (macho::CPU_TYPE_POWERPC, macho::CPU_SUBTYPE_POWERPC_ALL),
+ Architecture::PowerPc64 => (macho::CPU_TYPE_POWERPC64, macho::CPU_SUBTYPE_POWERPC_ALL),
_ => {
return Err(Error(format!(
"unimplemented architecture {:?}",
@@ -532,7 +540,7 @@ impl<'a> Object<'a> {
debug_assert_eq!(section_offsets[index].reloc_offset, buffer.len());
for reloc in &section.relocations {
let r_extern;
- let r_symbolnum;
+ let mut r_symbolnum;
let symbol = &self.symbols[reloc.symbol.0];
if symbol.kind == SymbolKind::Section {
r_symbolnum = section_offsets[symbol.section.id().unwrap().0].index as u32;
@@ -588,6 +596,26 @@ impl<'a> Object<'a> {
(RelocationKind::Absolute, RelocationEncoding::Generic, 0) => {
(false, macho::ARM64_RELOC_UNSIGNED)
}
+ (RelocationKind::Relative, RelocationEncoding::AArch64Call, 0) => {
+ (true, macho::ARM64_RELOC_BRANCH26)
+ }
+ // Non-zero addend, so we have to encode the addend separately
+ (RelocationKind::Relative, RelocationEncoding::AArch64Call, value) => {
+ // first emit the BR26 relocation
+ let reloc_info = macho::RelocationInfo {
+ r_address: reloc.offset as u32,
+ r_symbolnum,
+ r_pcrel: true,
+ r_length,
+ r_extern: true,
+ r_type: macho::ARM64_RELOC_BRANCH26,
+ };
+ buffer.write(&reloc_info.relocation(endian));
+
+ // set up a separate relocation for the addend
+ r_symbolnum = value as u32;
+ (false, macho::ARM64_RELOC_ADDEND)
+ }
(
RelocationKind::MachO { value, relative },
RelocationEncoding::Generic,