@@ -13,6 +13,7 @@ use std::process::{Command, Stdio, exit};
1313use std:: sync:: LazyLock ;
1414use std:: { env, fmt, fs} ;
1515
16+ use object:: elf:: { ProgramFlags , ProgramType } ;
1617use object:: read:: archive:: ArchiveFile ;
1718use object:: read:: pe:: ImageOptionalHeader ;
1819use object:: {
@@ -697,10 +698,10 @@ fn elf_os<Elf: read::elf::FileHeader>(f: &read::elf::ElfFile<Elf>) -> Os {
697698/// Get the OS from a mach file, or `Unknown` if not specified.
698699fn mach_os < Mach : read:: macho:: MachHeader > ( f : & read:: macho:: MachOFile < Mach > ) -> Os {
699700 // Note that this only returns something on `.rmeta` objects, not `.o`s.
700- let Ok ( Some ( build ) ) = f. build_version ( ) else {
701+ let Ok ( Some ( ( build_cmd , build_tool ) ) ) = f. build_version ( ) else {
701702 return Os :: Unknown ;
702703 } ;
703- let platform = build . platform . get ( f. endian ( ) ) ;
704+ let platform = build_cmd . platform . get ( f. endian ( ) ) ;
704705
705706 match platform {
706707 macho:: PLATFORM_UNKNOWN => Os :: Unknown ,
@@ -709,7 +710,7 @@ fn mach_os<Mach: read::macho::MachHeader>(f: &read::macho::MachOFile<Mach>) -> O
709710 macho:: PLATFORM_TVOS | macho:: PLATFORM_TVOSSIMULATOR => Os :: TvOs ,
710711 macho:: PLATFORM_VISIONOS | macho:: PLATFORM_VISIONOSSIMULATOR => Os :: VisionOs ,
711712 macho:: PLATFORM_WATCHOS | macho:: PLATFORM_WATCHOSSIMULATOR => Os :: WatchOs ,
712- _ => panic ! ( "unrecognized Mach-O platform {platform} ({build :?})" ) ,
713+ _ => panic ! ( "unrecognized Mach-O platform {platform} ({build_cmd:?} {build_tool :?})" ) ,
713714 }
714715}
715716
@@ -808,7 +809,8 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
808809 // Check for PT_GNU_STACK marked executable
809810 let mut is_obj_exe = false ;
810811 let mut found_gnu_stack = false ;
811- let mut check_ph = |p_type : U32 < Endianness > , p_flags : U32 < Endianness > | {
812+ let mut check_ph = |p_type : U32 < Endianness , ProgramType > ,
813+ p_flags : U32 < Endianness , ProgramFlags > | {
812814 let ty = p_type. get ( end) ;
813815 let flags = p_flags. get ( end) ;
814816
@@ -821,7 +823,7 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
821823 if ty == elf:: PT_GNU_STACK {
822824 assert ! ( !found_gnu_stack, "multiple PT_GNU_STACK sections" ) ;
823825 found_gnu_stack = true ;
824- if flags & elf:: PF_X != 0 {
826+ if flags. contains ( elf:: PF_X ) {
825827 return Err ( ExeStack :: ExePtGnuStack ) ;
826828 }
827829 }
@@ -852,11 +854,15 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
852854 let mut gnu_stack_exe = None ;
853855 let mut has_exe_sections = false ;
854856 for sec in obj. sections ( ) {
855- let SectionFlags :: Elf { sh_flags } = sec. flags ( ) else {
857+ let SectionFlags :: Elf {
858+ sh_type : _,
859+ sh_flags,
860+ } = sec. flags ( )
861+ else {
856862 unreachable ! ( "only elf files are being checked" ) ;
857863 } ;
858864
859- let is_sec_exe = sh_flags & u64 :: from ( elf:: SHF_EXECINSTR ) != 0 ;
865+ let is_sec_exe = sh_flags. contains ( elf:: SHF_EXECINSTR ) ;
860866
861867 // If the magic section is present, its exe bit tells us whether or not the object
862868 // file requires an executable stack.
@@ -891,7 +897,7 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
891897 match obj. architecture ( ) {
892898 // PPC64 doesn't set `.note.GNU-stack` since GNU nested functions don't need a trampoline,
893899 // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21098>. This only applies to ELFv1.
894- Architecture :: PowerPc64 if e_flags & elf:: EF_PPC64_ABI != 2 => Ok ( ( ) ) ,
900+ Architecture :: PowerPc64 if e_flags. 0 & elf:: EF_PPC64_ABI != 2 => Ok ( ( ) ) ,
895901
896902 _ => Err ( ExeStack :: MissingGnuStackSec ) ,
897903 }
0 commit comments