Skip to content

Commit

Permalink
elf: allow unaligned compression headers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
philipc committed Jun 15, 2020
1 parent 2ad5088 commit dbe4a2c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<E: Endian> {
/// Compression format. One of the `ELFCOMPRESS_*` values.
pub ch_type: U32<E>,
pub ch_type: U32Bytes<E>,
/// Uncompressed data size.
pub ch_size: U32<E>,
pub ch_size: U32Bytes<E>,
/// Uncompressed data alignment.
pub ch_addralign: U32<E>,
pub ch_addralign: U32Bytes<E>,
}

/// 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<E: Endian> {
/// Compression format. One of the `ELFCOMPRESS_*` values.
pub ch_type: U32<E>,
pub ch_type: U32Bytes<E>,
/// Reserved.
pub ch_reserved: U32<E>,
pub ch_reserved: U32Bytes<E>,
/// Uncompressed data size.
pub ch_size: U64<E>,
pub ch_size: U64Bytes<E>,
/// Uncompressed data alignment.
pub ch_addralign: U64<E>,
pub ch_addralign: U64Bytes<E>,
}

/// ZLIB/DEFLATE algorithm.
Expand Down

0 comments on commit dbe4a2c

Please sign in to comment.