@@ -9,11 +9,13 @@ use std::path::{Path, PathBuf};
99use std:: process:: { Command , Stdio } ;
1010use std:: { env, fs} ;
1111
12+ use object:: elf:: SectionHeader32 ;
1213use object:: read:: archive:: ArchiveFile ;
14+ use object:: read:: elf:: SectionHeader ;
1315use object:: {
14- Architecture , BinaryFormat , Bytes , Endianness , File as ObjFile , Object , ObjectSection ,
15- ObjectSymbol , Result as ObjResult , SectionFlags , SectionKind , Symbol , SymbolKind , SymbolScope ,
16- elf,
16+ Architecture , BinaryFormat , Bytes , Endianness , File as ObjFile , LittleEndian , Object ,
17+ ObjectSection , ObjectSymbol , Result as ObjResult , SectionFlags , SectionKind , Symbol ,
18+ SymbolKind , SymbolScope , U32 , U32Bytes , elf,
1719} ;
1820use serde_json:: Value ;
1921
@@ -55,26 +57,34 @@ fn main() {
5557
5658 let mut target = None ;
5759 let mut verify_no_exe = true ;
60+ let mut positional = Vec :: new ( ) ;
5861
5962 for arg in args_iter. by_ref ( ) {
63+ dbg ! ( & arg) ;
6064 match arg. as_str ( ) {
6165 "--no-std" => verify_no_exe = false ,
6266 "--" => break ,
6367 f if f. starts_with ( "-" ) => invalid_usage ( & format ! ( "unrecognized flag `{f}`" ) ) ,
6468 _ if mode == Mode :: BuildAndCheck => target = Some ( arg) ,
65- _ => break ,
69+ _ => {
70+ positional. push ( arg) ;
71+ break ;
72+ }
6673 }
6774 }
6875
69- let positional = args_iter . collect :: < Vec < _ > > ( ) ;
76+ positional. extend ( args_iter ) ;
7077
7178 match mode {
7279 Mode :: BuildAndCheck => {
7380 let target = target. unwrap_or_else ( || host_target ( ) ) ;
7481 let paths = exec_cargo_with_args ( & target, positional. as_slice ( ) ) ;
7582 check_paths ( & paths, verify_no_exe) ;
7683 }
77- Mode :: CheckOnly => check_paths ( & positional, verify_no_exe) ,
84+ Mode :: CheckOnly => {
85+ assert ! ( !positional. is_empty( ) ) ;
86+ check_paths ( & positional, verify_no_exe) ;
87+ }
7888 } ;
7989}
8090
@@ -91,11 +101,11 @@ fn check_paths<P: AsRef<Path>>(paths: &[P], verify_no_exe: bool) {
91101
92102 // verify_no_duplicates(&archive);
93103 // verify_core_symbols(&archive);
94- if verify_no_exe {
95- // We don't really have a good way of knowing whether or not an elf file is for a
96- // no-kernel environment, in which case note.GNU-stack doesn't get emitted.
97- verify_no_exec_stack ( & archive) ;
98- }
104+ // if verify_no_exe {
105+ // We don't really have a good way of knowing whether or not an elf file is for a
106+ // no-kernel environment, in which case note.GNU-stack doesn't get emitted.
107+ verify_no_exec_stack ( & archive) ;
108+ // }
99109 }
100110}
101111
@@ -359,16 +369,29 @@ fn obj_requires_exe_stack(obj: &ObjFile) -> bool {
359369 return false ;
360370 }
361371
372+ let secs = match obj {
373+ ObjFile :: Elf32 ( elf_file) => elf_file. sections ( ) ,
374+ ObjFile :: Elf64 ( elf_file) => panic ! ( ) ,
375+ // ObjFile::Elf64(elf_file) => elf_file.sections(),
376+ _ => return false ,
377+ } ;
378+
362379 let mut return_immediate = None ;
363380 let mut has_exe_sections = false ;
364381 for sec in obj. sections ( ) {
382+ dbg ! ( sec. name( ) ) ;
365383 let SectionFlags :: Elf { sh_flags } = sec. flags ( ) else {
366384 unreachable ! ( "only elf files are being checked" ) ;
367385 } ;
368386
369387 if sec. kind ( ) == SectionKind :: Elf ( elf:: SHT_ARM_ATTRIBUTES ) {
388+ let end = obj. endianness ( ) ;
370389 let data = sec. data ( ) . unwrap ( ) ;
371- parse_arm_thing ( data) ;
390+ let ObjFile :: Elf32 ( elf) = obj else { panic ! ( ) } ;
391+ let elf_sec = elf. section_by_index ( sec. index ( ) ) . unwrap ( ) ;
392+ let elf_hdr = elf_sec. elf_section_header ( ) ;
393+
394+ parse_arm_thing ( data, elf_hdr, end) ;
372395 }
373396
374397 let is_exe = ( sh_flags & elf:: SHF_EXECINSTR as u64 ) != 0 ;
@@ -405,13 +428,44 @@ fn platform_default_exe_stack_required(arch: Architecture, end: Endianness) -> b
405428 }
406429}
407430
408- fn parse_arm_thing ( data : & [ u8 ] ) {
409- eprintln ! ( "data: {data:x?}" ) ;
431+ /* this portion apache-2.0 with llvm exception */
432+ fn parse_arm_thing ( data : & [ u8 ] , elf_hdr : & SectionHeader32 < Endianness > , end : Endianness ) {
433+ let attrs = elf_hdr. attributes ( end, data) . unwrap ( ) ;
434+ dbg ! ( attrs) ;
435+
436+ eprintln ! ( "data d: {data:?}" ) ;
437+ eprintln ! ( "data x: {data:x?}" ) ;
410438 eprintln ! ( "data string: {:?}" , String :: from_utf8_lossy( data) ) ;
411- eprintln ! ( "data: {:x?}" , & data[ 16 ..] ) ;
439+ // eprintln!("data: {:x?}", &data[16..]);
412440 // let mut rest = &data[16..];
413441 let mut b = Bytes ( data) ;
414- b. skip ( 16 ) . unwrap ( ) ;
442+ let _fmt_version = b. read :: < u8 > ( ) . unwrap ( ) ;
443+ let _sec_length = b. read :: < U32 < LittleEndian > > ( ) . unwrap ( ) ;
444+
445+ // loop {
446+ let s = b. read_string ( ) . unwrap ( ) ;
447+ eprintln ! ( "abi {}" , String :: from_utf8_lossy( s) ) ;
448+
449+ let _tag = b. read_uleb128 ( ) . unwrap ( ) ;
450+ let _size = b. read :: < U32 < LittleEndian > > ( ) . unwrap ( ) ;
451+
452+ while !b. is_empty ( ) {
453+ let tag = b. read_uleb128 ( ) . unwrap ( ) ;
454+ match tag {
455+ 67 => eprintln ! (
456+ "conf: {}" ,
457+ String :: from_utf8_lossy( b. read_string( ) . unwrap( ) )
458+ ) ,
459+ // 77 =>
460+ 7 => {
461+ // CPU_arch_profile
462+ let value = b. read_uleb128 ( ) . unwrap ( ) ;
463+ }
464+ _ => eprintln ! ( "tag {tag} value {}" , b. read:: <u8 >( ) . unwrap( ) ) ,
465+ }
466+ }
467+
468+ // }
415469
416470 // while !rest.is_empty() {}
417471}
0 commit comments