From 36eda2b7694db78a68af97200af8ff2d79cfd0c9 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Fri, 29 Nov 2024 15:43:58 +1000 Subject: [PATCH] write/elf: add SHT_RELR section header support This is still missing an encoder for the relocations. --- src/write/elf/writer.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/write/elf/writer.rs b/src/write/elf/writer.rs index 756910a0..ca3ab59c 100644 --- a/src/write/elf/writer.rs +++ b/src/write/elf/writer.rs @@ -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. @@ -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::>() + } else { + mem::size_of::>() + } + } + /// Return the size of a dynamic entry. pub fn dyn_size(self) -> usize { if self.is_64 {