Skip to content

Commit

Permalink
write/elf: add SHT_RELR section header support
Browse files Browse the repository at this point in the history
This is still missing an encoder for the relocations.
  • Loading branch information
philipc committed Nov 29, 2024
1 parent 2997d5d commit 0d6d6e7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/write/elf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,30 @@ impl<'a> Writer<'a> {
});
}

/// Write the section header for a relative relocation section.
///
/// `offset` is the file offset of the relocations.
/// `size` is the size of the section in bytes.
pub fn write_relative_relocation_section_header(
&mut self,
name: StringId,
offset: usize,
size: usize,
) {
self.write_section_header(&SectionHeader {
name: Some(name),
sh_type: elf::SHT_RELA,
sh_flags: 0,
sh_addr: 0,
sh_offset: offset as u64,
sh_size: size as u64,
sh_link: 0,
sh_info: 0,
sh_addralign: self.elf_align as u64,
sh_entsize: self.class().relr_size() as u64,
});
}

/// Reserve a file range for a COMDAT section.
///
/// `count` is the number of sections in the COMDAT group.
Expand Down Expand Up @@ -2222,6 +2246,15 @@ impl Class {
}
}

/// Return the size of a relative relocation entry.
pub fn relr_size(self) -> usize {
if self.is_64 {
mem::size_of::<elf::Relr64<Endianness>>()
} else {
mem::size_of::<elf::Relr32<Endianness>>()
}
}

/// Return the size of a dynamic entry.
pub fn dyn_size(self) -> usize {
if self.is_64 {
Expand Down

0 comments on commit 0d6d6e7

Please sign in to comment.