From e76b84335ee1d67bd2a12aa879500b5dd2a88c0f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 17 Apr 2020 19:57:45 +0800 Subject: [PATCH] libdyld: accept ARM ELF header --- libdyld/src/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libdyld/src/lib.rs b/libdyld/src/lib.rs index ae2e3382..82280d84 100644 --- a/libdyld/src/lib.rs +++ b/libdyld/src/lib.rs @@ -202,14 +202,26 @@ impl<'a> Library<'a> { let ehdr = read_unaligned::(data, 0) .map_err(|()| "cannot read ELF header")?; - const IDENT: [u8; EI_NIDENT] = [ + const IDENT_OPENRISC: [u8; EI_NIDENT] = [ ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ELFOSABI_NONE, /* ABI version */ 0, /* padding */ 0, 0, 0, 0, 0, 0, 0 ]; + const IDENT_ARM: [u8; EI_NIDENT] = [ + ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, + ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ELFOSABI_NONE, + /* ABI version */ 0, /* padding */ 0, 0, 0, 0, 0, 0, 0 + ]; - if ehdr.e_ident != IDENT || ehdr.e_type != ET_DYN || ehdr.e_machine != EM_OPENRISC { - return Err("not a shared library for a supported architecture")? + if ehdr.e_type != ET_DYN { + return Err("not a shared library")? + } + + if !((ehdr.e_ident == IDENT_OPENRISC && ehdr.e_machine == EM_OPENRISC) + || ((ehdr.e_ident == IDENT_ARM && ehdr.e_machine == EM_ARM))) { + println!("e_type={}", ehdr.e_type); + println!("e_machine={}", ehdr.e_machine); + return Err("not for a supported architecture")? } let mut dyn_off = None;