diff --git a/crates/linker/src/generate_dylib.rs b/crates/linker/src/generate_dylib.rs index 4197b8aa89..c8f8a63486 100644 --- a/crates/linker/src/generate_dylib.rs +++ b/crates/linker/src/generate_dylib.rs @@ -11,6 +11,9 @@ use roc_error_macros::internal_error; // an empty shared library, that we build on top of const DUMMY: &[u8] = include_bytes!("../dummy-elf64-x86-64.so"); +// index of the dynamic section +const DYMAMIC_SECTION: usize = 4; + pub fn generate(custom_names: &[String]) -> Result, Box> { let kind = match object::FileKind::parse(DUMMY) { Ok(file) => file, @@ -51,20 +54,20 @@ struct DynamicSymbol { } #[derive(Debug)] -struct MySection { +struct Section { in_index: usize, section: SectionHeader64, } struct Sections { - hash: MySection, - gnu_hash: MySection, - dynsym: MySection, - dynstr: MySection, - dynamic: MySection, - symtab: MySection, - strtab: MySection, - shstrtab: MySection, + hash: Section, + gnu_hash: Section, + dynsym: Section, + dynstr: Section, + dynamic: Section, + symtab: Section, + strtab: Section, + shstrtab: Section, } struct Addresses { @@ -76,7 +79,7 @@ struct Addresses { } impl Sections { - fn iter(&self) -> impl Iterator + '_ { + fn iter(&self) -> impl Iterator + '_ { [ &self.hash, &self.gnu_hash, @@ -186,7 +189,7 @@ impl Sections { // elf::SHT_DYNAMIC let in_section = §ions.dynamic.section; let offset = in_section.sh_offset(endian) as usize + extra_offset; - offsets[4] = round_up_to_alignment(offset, 8); // seems like this needs to be aligned?! + offsets[DYMAMIC_SECTION] = round_up_to_alignment(offset, 8); // seems like this needs to be aligned?! writer.reserve_until(offset); let dynamic_addr = in_section.sh_addr(endian); @@ -232,7 +235,7 @@ fn copy_file(in_data: &[u8], custom_names: &[String]) -> Result, Box Result, Box Result, Box Result, Box Result, Box 0 { - offsets[4] as _ + offsets[DYMAMIC_SECTION] as _ } else { 0 },