summaryrefslogtreecommitdiffstats
path: root/vendor/object/src/write
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/object/src/write
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/object/src/write')
-rw-r--r--vendor/object/src/write/elf/object.rs12
-rw-r--r--vendor/object/src/write/macho.rs30
2 files changed, 21 insertions, 21 deletions
diff --git a/vendor/object/src/write/elf/object.rs b/vendor/object/src/write/elf/object.rs
index 8b9eadaf8..acc820c9e 100644
--- a/vendor/object/src/write/elf/object.rs
+++ b/vendor/object/src/write/elf/object.rs
@@ -126,6 +126,7 @@ impl<'a> Object<'a> {
Architecture::Arm => false,
Architecture::Avr => true,
Architecture::Bpf => false,
+ Architecture::Csky => true,
Architecture::I386 => false,
Architecture::X86_64 => true,
Architecture::X86_64_X32 => true,
@@ -329,6 +330,7 @@ impl<'a> Object<'a> {
Architecture::Arm => elf::EM_ARM,
Architecture::Avr => elf::EM_AVR,
Architecture::Bpf => elf::EM_BPF,
+ Architecture::Csky => elf::EM_CSKY,
Architecture::I386 => elf::EM_386,
Architecture::X86_64 => elf::EM_X86_64,
Architecture::X86_64_X32 => elf::EM_X86_64,
@@ -548,6 +550,16 @@ impl<'a> Object<'a> {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
},
+ Architecture::Csky => match (reloc.kind, reloc.encoding, reloc.size) {
+ (RelocationKind::Absolute, _, 32) => elf::R_CKCORE_ADDR32,
+ (RelocationKind::Relative, RelocationEncoding::Generic, 32) => {
+ elf::R_CKCORE_PCREL32
+ }
+ (RelocationKind::Elf(x), _, _) => x,
+ _ => {
+ return Err(Error(format!("unimplemented relocation {:?}", reloc)));
+ }
+ },
Architecture::I386 => match (reloc.kind, reloc.size) {
(RelocationKind::Absolute, 32) => elf::R_386_32,
(RelocationKind::Relative, 32) => elf::R_386_PC32,
diff --git a/vendor/object/src/write/macho.rs b/vendor/object/src/write/macho.rs
index 0e082b69d..e3ce55bb4 100644
--- a/vendor/object/src/write/macho.rs
+++ b/vendor/object/src/write/macho.rs
@@ -303,39 +303,29 @@ impl<'a> Object<'a> {
let sizeofcmds = offset - command_offset;
// Calculate size of section data.
- let mut segment_file_offset = None;
+ // Section data can immediately follow the load commands without any alignment padding.
+ let segment_file_offset = offset;
let mut section_offsets = vec![SectionOffsets::default(); self.sections.len()];
let mut address = 0;
for (index, section) in self.sections.iter().enumerate() {
section_offsets[index].index = 1 + index;
if !section.is_bss() {
- let len = section.data.len();
- if len != 0 {
- offset = align(offset, section.align as usize);
- section_offsets[index].offset = offset;
- if segment_file_offset.is_none() {
- segment_file_offset = Some(offset);
- }
- offset += len;
- } else {
- section_offsets[index].offset = offset;
- }
address = align_u64(address, section.align);
section_offsets[index].address = address;
+ section_offsets[index].offset = segment_file_offset + address as usize;
address += section.size;
}
}
+ let segment_file_size = address as usize;
+ offset += address as usize;
for (index, section) in self.sections.iter().enumerate() {
- if section.kind.is_bss() {
- assert!(section.data.is_empty());
+ if section.is_bss() {
+ debug_assert!(section.data.is_empty());
address = align_u64(address, section.align);
section_offsets[index].address = address;
address += section.size;
}
}
- let segment_file_offset = segment_file_offset.unwrap_or(offset);
- let segment_file_size = offset - segment_file_offset;
- debug_assert!(segment_file_size as u64 <= address);
// Count symbols and add symbol strings to strtab.
let mut strtab = StringTable::default();
@@ -537,10 +527,8 @@ impl<'a> Object<'a> {
// Write section data.
for (index, section) in self.sections.iter().enumerate() {
- let len = section.data.len();
- if len != 0 {
- write_align(buffer, section.align as usize);
- debug_assert_eq!(section_offsets[index].offset, buffer.len());
+ if !section.is_bss() {
+ buffer.resize(section_offsets[index].offset);
buffer.write_bytes(&section.data);
}
}