From dbe4a2c9371073860513f393834dd7495724ac7b Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Mon, 15 Jun 2020 15:01:32 +1000 Subject: [PATCH] elf: allow unaligned compression headers Compressed sections are commonly emitted with the wrong alignment. This has been fixed in more recent versions of the major compilers, but for now let's support the invalid alignment even with the unaligned feature disabled, since performance here doesn't matter much. --- src/elf.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/elf.rs b/src/elf.rs index c05673df..28d7b110 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -7,7 +7,7 @@ #![allow(clippy::identity_op)] -use crate::endian::{Endian, I32, I64, U16, U32, U64}; +use crate::endian::{Endian, I32, I64, U16, U32, U64, U32Bytes, U64Bytes}; use crate::pod::Pod; /// The header at the start of every 32-bit ELF file. @@ -737,31 +737,37 @@ pub const SHF_MASKPROC: u32 = 0xf000_0000; /// Section compression header. /// /// Used when `SHF_COMPRESSED` is set. +/// +/// Note: this type currently allows for misaligned headers, but that may be +/// changed in a future version. #[derive(Debug, Default, Clone, Copy)] #[repr(C)] pub struct CompressionHeader32 { /// Compression format. One of the `ELFCOMPRESS_*` values. - pub ch_type: U32, + pub ch_type: U32Bytes, /// Uncompressed data size. - pub ch_size: U32, + pub ch_size: U32Bytes, /// Uncompressed data alignment. - pub ch_addralign: U32, + pub ch_addralign: U32Bytes, } /// Section compression header. /// /// Used when `SHF_COMPRESSED` is set. +/// +/// Note: this type currently allows for misaligned headers, but that may be +/// changed in a future version. #[derive(Debug, Default, Clone, Copy)] #[repr(C)] pub struct CompressionHeader64 { /// Compression format. One of the `ELFCOMPRESS_*` values. - pub ch_type: U32, + pub ch_type: U32Bytes, /// Reserved. - pub ch_reserved: U32, + pub ch_reserved: U32Bytes, /// Uncompressed data size. - pub ch_size: U64, + pub ch_size: U64Bytes, /// Uncompressed data alignment. - pub ch_addralign: U64, + pub ch_addralign: U64Bytes, } /// ZLIB/DEFLATE algorithm.