@@ -9,11 +9,13 @@ use std::path::{Path, PathBuf};
9
9
use std:: process:: { Command , Stdio } ;
10
10
use std:: { env, fs} ;
11
11
12
+ use object:: elf:: SectionHeader32 ;
12
13
use object:: read:: archive:: ArchiveFile ;
14
+ use object:: read:: elf:: SectionHeader ;
13
15
use 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,
17
19
} ;
18
20
use serde_json:: Value ;
19
21
@@ -55,26 +57,34 @@ fn main() {
55
57
56
58
let mut target = None ;
57
59
let mut verify_no_exe = true ;
60
+ let mut positional = Vec :: new ( ) ;
58
61
59
62
for arg in args_iter. by_ref ( ) {
63
+ dbg ! ( & arg) ;
60
64
match arg. as_str ( ) {
61
65
"--no-std" => verify_no_exe = false ,
62
66
"--" => break ,
63
67
f if f. starts_with ( "-" ) => invalid_usage ( & format ! ( "unrecognized flag `{f}`" ) ) ,
64
68
_ if mode == Mode :: BuildAndCheck => target = Some ( arg) ,
65
- _ => break ,
69
+ _ => {
70
+ positional. push ( arg) ;
71
+ break ;
72
+ }
66
73
}
67
74
}
68
75
69
- let positional = args_iter . collect :: < Vec < _ > > ( ) ;
76
+ positional. extend ( args_iter ) ;
70
77
71
78
match mode {
72
79
Mode :: BuildAndCheck => {
73
80
let target = target. unwrap_or_else ( || host_target ( ) ) ;
74
81
let paths = exec_cargo_with_args ( & target, positional. as_slice ( ) ) ;
75
82
check_paths ( & paths, verify_no_exe) ;
76
83
}
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
+ }
78
88
} ;
79
89
}
80
90
@@ -91,11 +101,11 @@ fn check_paths<P: AsRef<Path>>(paths: &[P], verify_no_exe: bool) {
91
101
92
102
// verify_no_duplicates(&archive);
93
103
// 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
+ // }
99
109
}
100
110
}
101
111
@@ -359,16 +369,29 @@ fn obj_requires_exe_stack(obj: &ObjFile) -> bool {
359
369
return false ;
360
370
}
361
371
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
+
362
379
let mut return_immediate = None ;
363
380
let mut has_exe_sections = false ;
364
381
for sec in obj. sections ( ) {
382
+ dbg ! ( sec. name( ) ) ;
365
383
let SectionFlags :: Elf { sh_flags } = sec. flags ( ) else {
366
384
unreachable ! ( "only elf files are being checked" ) ;
367
385
} ;
368
386
369
387
if sec. kind ( ) == SectionKind :: Elf ( elf:: SHT_ARM_ATTRIBUTES ) {
388
+ let end = obj. endianness ( ) ;
370
389
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) ;
372
395
}
373
396
374
397
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
405
428
}
406
429
}
407
430
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?}" ) ;
410
438
eprintln ! ( "data string: {:?}" , String :: from_utf8_lossy( data) ) ;
411
- eprintln ! ( "data: {:x?}" , & data[ 16 ..] ) ;
439
+ // eprintln!("data: {:x?}", &data[16..]);
412
440
// let mut rest = &data[16..];
413
441
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
+ // }
415
469
416
470
// while !rest.is_empty() {}
417
471
}
0 commit comments