atosl 0.1.14

A partial replacement for Apple's atos tool for converting binary addresses to symbols.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
//
// written by everettjf
// email : everettjf@live.com
// created at 2022-01-01
//
use crate::demangle;
use anyhow::{anyhow, Context, Result};
use gimli::{DW_TAG_subprogram, DebugInfoOffset, Dwarf, EndianSlice, RunTimeEndian};
use object::macho;
use object::read::macho::{FatArch, FatHeader};
use object::{Object, ObjectSection, ObjectSegment};
use std::path::Path;
use std::{borrow, fs};

pub fn print_addresses(
    object_path: &Path,
    load_address: u64,
    addresses: &[u64],
    verbose: bool,
    file_offset_type: bool,
    arch_filter: Option<&str>,
    uuid_filter: Option<&str>,
) -> Result<(), anyhow::Error> {
    let file = fs::File::open(object_path)
        .with_context(|| format!("failed to open object file: {}", object_path.display()))?;
    let mmap = unsafe { memmap2::Mmap::map(&file)? };
    let object_filename = object_path
        .file_name()
        .ok_or_else(|| {
            anyhow!(
                "failed to get file name from path: {}",
                object_path.display()
            )
        })?
        .to_string_lossy()
        .to_string();

    let parsed_uuid_filter = uuid_filter.map(parse_uuid_string).transpose()?;
    let (object, selected_slice) =
        resolve_object_from_data(&mmap, arch_filter, parsed_uuid_filter, verbose)?;
    if verbose {
        if let Some(selected_slice) = selected_slice {
            println!("selected_slice: {selected_slice}");
        }
    }

    print_addresses_for_object(
        &object,
        &object_filename,
        load_address,
        addresses,
        verbose,
        file_offset_type,
    )
}

fn print_addresses_for_object(
    object: &object::File,
    object_filename: &str,
    load_address: u64,
    addresses: &[u64],
    verbose: bool,
    file_offset_type: bool,
) -> Result<(), anyhow::Error> {
    if is_object_dwarf(object) {
        if verbose {
            println!("resolver: dwarf");
        }
        dwarf_symbolize_addresses(
            object,
            object_filename,
            load_address,
            addresses,
            verbose,
            file_offset_type,
        )
    } else {
        if verbose {
            println!("resolver: symbol_table");
        }
        symbol_symbolize_addresses(
            object,
            object_filename,
            load_address,
            addresses,
            verbose,
            file_offset_type,
        )
    }
}

struct FatSlice<'data> {
    object: object::File<'data, &'data [u8]>,
    arch_name: String,
    uuid: Option<[u8; 16]>,
}

fn resolve_object_from_data<'data>(
    data: &'data [u8],
    arch_filter: Option<&str>,
    uuid_filter: Option<[u8; 16]>,
    verbose: bool,
) -> Result<(object::File<'data, &'data [u8]>, Option<String>), anyhow::Error> {
    let kind = object::FileKind::parse(data)?;
    match kind {
        object::FileKind::MachOFat32 => {
            let arches = FatHeader::parse_arch32(data)?;
            select_fat_slice(arches, data, arch_filter, uuid_filter, verbose)
        }
        object::FileKind::MachOFat64 => {
            let arches = FatHeader::parse_arch64(data)?;
            select_fat_slice(arches, data, arch_filter, uuid_filter, verbose)
        }
        _ => {
            let file = object::File::parse(data)?;
            validate_non_fat_filters(&file, arch_filter, uuid_filter)?;
            Ok((file, None))
        }
    }
}

fn validate_non_fat_filters(
    file: &object::File,
    arch_filter: Option<&str>,
    uuid_filter: Option<[u8; 16]>,
) -> Result<(), anyhow::Error> {
    if let Some(uuid_filter) = uuid_filter {
        let actual_uuid = file
            .mach_uuid()?
            .ok_or_else(|| anyhow!("--uuid was provided, but this file has no Mach-O UUID"))?;
        if actual_uuid != uuid_filter {
            return Err(anyhow!(
                "uuid mismatch: requested {}, actual {}",
                format_uuid(uuid_filter),
                format_uuid(actual_uuid)
            ));
        }
    }

    if let Some(arch_filter) = arch_filter {
        let architecture = file.architecture();
        let matches = architecture_matches_filter(architecture, arch_filter);
        if !matches {
            return Err(anyhow!(
                "architecture mismatch: requested '{}', actual '{:?}'",
                arch_filter,
                architecture
            ));
        }
    }
    Ok(())
}

fn select_fat_slice<'data, A: FatArch>(
    arches: &'data [A],
    data: &'data [u8],
    arch_filter: Option<&str>,
    uuid_filter: Option<[u8; 16]>,
    verbose: bool,
) -> Result<(object::File<'data, &'data [u8]>, Option<String>), anyhow::Error> {
    let mut slices = Vec::with_capacity(arches.len());
    for arch in arches {
        let cputype = arch.cputype();
        let cpusubtype = arch.cpusubtype();
        let arch_name = format_macho_arch_name(cputype, cpusubtype);
        let arch_data = arch.data(data)?;
        let object = object::File::parse(arch_data)?;
        let uuid = object.mach_uuid()?;
        slices.push(FatSlice {
            object,
            arch_name,
            uuid,
        });
    }

    if verbose {
        for slice in &slices {
            let uuid_str = slice
                .uuid
                .map(format_uuid)
                .unwrap_or_else(|| "-".to_string());
            println!("fat_slice: arch={} uuid={}", slice.arch_name, uuid_str);
        }
    }

    if slices.is_empty() {
        return Err(anyhow!("fat Mach-O has no slices"));
    }

    if arch_filter.is_none() && uuid_filter.is_none() {
        if slices.len() == 1 {
            let slice = slices.into_iter().next().expect("slice len checked");
            let selected = Some(format_selected_slice(&slice.arch_name, slice.uuid));
            return Ok((slice.object, selected));
        }
        return Err(anyhow!(
            "fat Mach-O contains multiple slices.\nUse -a/--arch or --uuid to select one.\nAvailable slices:\n{}",
            format_available_slices(&slices)
        ));
    }

    let available_slices = format_available_slices(&slices);
    let mut matches = slices
        .into_iter()
        .filter(|slice| {
            let arch_ok = arch_filter
                .map(|filter| macho_arch_matches_filter(&slice.arch_name, filter))
                .unwrap_or(true);
            let uuid_ok = uuid_filter
                .map(|uuid| slice.uuid == Some(uuid))
                .unwrap_or(true);
            arch_ok && uuid_ok
        })
        .collect::<Vec<_>>();

    match matches.len() {
        0 => Err(anyhow!(
            "no fat Mach-O slice matched arch={:?} uuid={:?}.\nAvailable slices:\n{}",
            arch_filter,
            uuid_filter.map(format_uuid),
            available_slices
        )),
        1 => {
            let slice = matches.pop().expect("slice len checked");
            let selected = Some(format_selected_slice(&slice.arch_name, slice.uuid));
            Ok((slice.object, selected))
        }
        _ => {
            let available = matches
                .iter()
                .map(|slice| format_selected_slice(&slice.arch_name, slice.uuid))
                .collect::<Vec<_>>()
                .join("\n");
            Err(anyhow!(
                "filters are ambiguous and matched multiple slices:\n{}",
                available
            ))
        }
    }
}

fn format_available_slices(slices: &[FatSlice]) -> String {
    slices
        .iter()
        .map(|slice| format_selected_slice(&slice.arch_name, slice.uuid))
        .collect::<Vec<_>>()
        .join("\n")
}

fn format_selected_slice(arch_name: &str, uuid: Option<[u8; 16]>) -> String {
    let uuid = uuid.map(format_uuid).unwrap_or_else(|| "-".to_string());
    format!("- arch={arch_name} uuid={uuid}")
}

fn parse_uuid_string(value: &str) -> Result<[u8; 16], anyhow::Error> {
    let hex = value
        .chars()
        .filter(|c| *c != '-')
        .collect::<String>()
        .to_ascii_lowercase();
    if hex.len() != 32 || !hex.chars().all(|c| c.is_ascii_hexdigit()) {
        return Err(anyhow!(
            "invalid uuid format: '{value}', expected 32 hex chars (with or without '-')"
        ));
    }

    let mut out = [0u8; 16];
    for (i, chunk) in hex.as_bytes().chunks(2).enumerate() {
        let byte_str = std::str::from_utf8(chunk)?;
        out[i] = u8::from_str_radix(byte_str, 16)?;
    }
    Ok(out)
}

fn format_uuid(uuid: [u8; 16]) -> String {
    let hex = uuid
        .iter()
        .map(|b| format!("{:02X}", b))
        .collect::<String>();
    format!(
        "{}-{}-{}-{}-{}",
        &hex[0..8],
        &hex[8..12],
        &hex[12..16],
        &hex[16..20],
        &hex[20..32]
    )
}

fn normalize_arch(value: &str) -> String {
    value
        .chars()
        .filter(|c| c.is_ascii_alphanumeric())
        .flat_map(char::to_lowercase)
        .collect::<String>()
}

fn architecture_matches_filter(architecture: object::Architecture, arch_filter: &str) -> bool {
    let filter = normalize_arch(arch_filter);
    match filter.as_str() {
        "arm" | "armv7" | "armv7s" | "armv7k" => architecture == object::Architecture::Arm,
        "arm64" | "arm64e" | "aarch64" => architecture == object::Architecture::Aarch64,
        "x8664" | "x64" | "amd64" | "x8664h" => architecture == object::Architecture::X86_64,
        "x86" | "i386" => architecture == object::Architecture::I386,
        _ => false,
    }
}

fn macho_arch_matches_filter(arch_name: &str, arch_filter: &str) -> bool {
    let actual = normalize_arch(arch_name);
    let filter = normalize_arch(arch_filter);
    if actual == filter {
        return true;
    }
    matches!(
        (actual.as_str(), filter.as_str()),
        ("arm64", "aarch64")
            | ("aarch64", "arm64")
            | ("x8664", "amd64")
            | ("x8664", "x64")
            | ("i386", "x86")
    )
}

fn format_macho_arch_name(cputype: u32, cpusubtype: u32) -> String {
    let cpusubtype = cpusubtype & !macho::CPU_SUBTYPE_MASK;
    match cputype {
        macho::CPU_TYPE_ARM64 => match cpusubtype {
            macho::CPU_SUBTYPE_ARM64E => "arm64e".to_string(),
            _ => "arm64".to_string(),
        },
        macho::CPU_TYPE_ARM => match cpusubtype {
            macho::CPU_SUBTYPE_ARM_V7 => "armv7".to_string(),
            macho::CPU_SUBTYPE_ARM_V7F => "armv7f".to_string(),
            macho::CPU_SUBTYPE_ARM_V7S => "armv7s".to_string(),
            macho::CPU_SUBTYPE_ARM_V7K => "armv7k".to_string(),
            macho::CPU_SUBTYPE_ARM_V8 => "armv8".to_string(),
            _ => "arm".to_string(),
        },
        macho::CPU_TYPE_X86_64 => match cpusubtype {
            macho::CPU_SUBTYPE_X86_64_H => "x86_64h".to_string(),
            _ => "x86_64".to_string(),
        },
        macho::CPU_TYPE_X86 => "i386".to_string(),
        _ => format!("cputype{}_subtype{}", cputype, cpusubtype),
    }
}

fn is_object_dwarf(object: &object::File) -> bool {
    object.section_by_name("__debug_line").is_some()
}

fn find_text_vmaddr(object: &object::File) -> Result<u64, anyhow::Error> {
    for segment in object.segments() {
        if let Some(name) = segment.name()? {
            if name == "__TEXT" {
                return Ok(segment.address());
            }
        }
    }
    Ok(0)
}

fn calculate_search_address(
    load_address: u64,
    address: u64,
    text_vmaddr: u64,
    file_offset_type: bool,
) -> Result<u64, anyhow::Error> {
    let base = address
        .checked_sub(load_address)
        .ok_or_else(|| anyhow!("address is smaller than load address"))?;

    if file_offset_type {
        Ok(base)
    } else {
        base.checked_add(text_vmaddr)
            .ok_or_else(|| anyhow!("address overflow while applying __TEXT vmaddr"))
    }
}

fn symbol_symbolize_addresses(
    object: &object::File,
    object_filename: &str,
    load_address: u64,
    addresses: &[u64],
    verbose: bool,
    file_offset_type: bool,
) -> Result<(), anyhow::Error> {
    let text_vmaddr = find_text_vmaddr(object)?;

    for &address in addresses {
        if verbose {
            println!("---------------------------------------------");
            println!("BEGIN ADDRESS {} | {:016x}", address, address);
        }

        let symbol_result = symbol_symbolize_address(
            object,
            object_filename,
            load_address,
            address,
            text_vmaddr,
            file_offset_type,
        );
        if verbose {
            println!("RESULT:")
        }
        match symbol_result {
            Ok(symbol) => println!("{}", symbol),
            Err(err) => println!("N/A - {}", err),
        };

        if verbose {
            println!("END ADDRESS {} | {:016x}", address, address);
        }
    }
    Ok(())
}

fn symbol_symbolize_address(
    object: &object::File,
    object_filename: &str,
    load_address: u64,
    address: u64,
    text_vmaddr: u64,
    file_offset_type: bool,
) -> Result<String, anyhow::Error> {
    let search_address =
        calculate_search_address(load_address, address, text_vmaddr, file_offset_type)?;

    let symbols = object.symbol_map();
    let found_symbol = symbols.get(search_address);

    if let Some(found_symbol) = found_symbol {
        // expect format
        // main (in BinaryName)
        let offset = search_address - found_symbol.address();
        let demangled_name = demangle::demangle_symbol(found_symbol.name());
        let symbolize_result = format!("{} (in {}) + {}", demangled_name, object_filename, offset);
        return Ok(symbolize_result);
    }

    Err(anyhow!("failed search symbol"))
}

fn dwarf_symbolize_addresses(
    object: &object::File,
    object_filename: &str,
    load_address: u64,
    addresses: &[u64],
    verbose: bool,
    file_offset_type: bool,
) -> Result<(), anyhow::Error> {
    let endian = if object.is_little_endian() {
        gimli::RunTimeEndian::Little
    } else {
        gimli::RunTimeEndian::Big
    };
    let dwarf_cow = gimli::Dwarf::load(|section_id| -> Result<borrow::Cow<[u8]>, gimli::Error> {
        // println!("section id = {}", section_id.name());
        match object.section_by_name(section_id.name()) {
            Some(ref section) => Ok(section
                .uncompressed_data()
                .unwrap_or(borrow::Cow::Borrowed(&[][..]))),
            None => Ok(borrow::Cow::Borrowed(&[][..])),
        }
    })?;
    let dwarf = dwarf_cow.borrow(|section| gimli::EndianSlice::new(section.as_ref(), endian));

    let text_vmaddr = find_text_vmaddr(object)?;

    for &address in addresses {
        if verbose {
            println!("---------------------------------------------");
            println!("BEGIN ADDRESS {} | {:016x}", address, address);
        }

        let symbol_result = dwarf_symbolize_address(
            &dwarf,
            object_filename,
            load_address,
            address,
            text_vmaddr,
            verbose,
            file_offset_type,
        );
        if verbose {
            println!("RESULT:")
        }
        match symbol_result {
            Ok(symbol) => println!("{}", symbol),
            Err(_) => {
                // downgrade to symbol table search
                let symbol_result = symbol_symbolize_address(
                    object,
                    object_filename,
                    load_address,
                    address,
                    text_vmaddr,
                    file_offset_type,
                );
                match symbol_result {
                    Ok(symbol) => println!("{}", symbol),
                    Err(err) => println!("N/A - {}", err),
                };
            }
        };

        if verbose {
            println!("END ADDRESS {} | {:016x}", address, address);
        }
    }
    Ok(())
}

fn dwarf_symbolize_address(
    dwarf: &Dwarf<EndianSlice<RunTimeEndian>>,
    object_filename: &str,
    load_address: u64,
    address: u64,
    text_vmaddr: u64,
    verbose: bool,
    file_offset_type: bool,
) -> Result<String, anyhow::Error> {
    let search_address =
        calculate_search_address(load_address, address, text_vmaddr, file_offset_type)?;

    // aranges
    let mut debug_info_offset: Option<DebugInfoOffset> = None;
    let mut arange_headers = dwarf.debug_aranges.headers();
    while let Some(header) = arange_headers.next()? {
        let mut found_address = false;
        let mut arange_entries = header.entries();
        while let Some(entry) = arange_entries.next()? {
            // println!("- | entry: address=0x{:016x} length=0x{:016x} segment=0x{:016x}", entry.address(), entry.length(), entry.segment().unwrap_or(0));
            let begin = entry.address();
            let end = entry.address() + entry.length();
            if search_address >= begin && search_address < end {
                found_address = true;
                break;
            }
        }

        if found_address {
            debug_info_offset = Some(header.debug_info_offset());
            break;
        }
    }

    let debug_info_offset = match debug_info_offset {
        Some(offset) => offset,
        None => return Err(anyhow!("can not find arange")),
    };

    // get debug info
    // catch header
    let debug_info_header = dwarf.debug_info.header_from_offset(debug_info_offset)?;

    if verbose {
        println!("got debug info header 0x{:016x}", debug_info_offset.0);
    };

    let debug_info_unit = dwarf.unit(debug_info_header)?;
    let mut debug_info_entries = debug_info_unit.entries();

    let mut found_symbol_name: Option<String> = None;
    while debug_info_entries.next_entry()?.is_some() {
        if let Some(entry) = debug_info_entries.current() {
            if entry.tag() == DW_TAG_subprogram {
                let mut low_pc: Option<u64> = None;
                let mut high_pc: Option<u64> = None;
                if let Ok(Some(gimli::AttributeValue::Addr(lowpc_val))) =
                    entry.attr_value(gimli::DW_AT_low_pc)
                {
                    low_pc = Some(lowpc_val);
                    let high_pc_value = entry.attr_value(gimli::DW_AT_high_pc);

                    if verbose {
                        println!("high pc value : {:?}", high_pc_value);
                    }

                    if let Ok(Some(high_pc_data)) = high_pc_value {
                        if let gimli::AttributeValue::Addr(addr) = high_pc_data {
                            high_pc = Some(addr);
                        } else if let gimli::AttributeValue::Udata(size) = high_pc_data {
                            high_pc = Some(lowpc_val + size);
                        }
                    }
                }

                if verbose {
                    println!("low pc = {:?}, high pc = {:?}", low_pc, high_pc)
                }

                if let (Some(low_pc), Some(high_pc)) = (low_pc, high_pc) {
                    if search_address >= low_pc && search_address < high_pc {
                        if let Ok(Some(name)) = entry.attr_value(gimli::DW_AT_name) {
                            if let Ok(symbol_name) = dwarf.attr_string(&debug_info_unit, name) {
                                found_symbol_name = Some(symbol_name.to_string_lossy().to_string());
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    if verbose {
        println!("found_symbol_name = {:?}", found_symbol_name);
    };

    let mut found_file_name: Option<String> = None;
    let mut found_line: Option<u64> = None;
    if let Some(program) = debug_info_unit.line_program.clone() {
        let mut rows = program.rows();
        let mut last_file_name: Option<String> = None;
        let mut last_line: Option<u64> = None;
        while let Some((header, row)) = rows.next_row()? {
            if row.end_sequence() {
                if search_address < row.address() {
                    // got last filename and line
                    found_file_name = last_file_name.clone();
                    found_line = last_line;
                    if let Some(line_no) = found_line {
                        if line_no > 0 {
                            break;
                        }
                    }
                }
                continue;
            }
            if let Some(file) = row.file(header) {
                let filename = dwarf
                    .attr_string(&debug_info_unit, file.path_name())?
                    .to_string_lossy();
                last_file_name = Some(filename.into_owned());
            }
            let line = match row.line() {
                Some(line) => line.get(),
                None => 0,
            };

            if search_address < row.address() {
                // got last filename and line
                found_file_name = last_file_name.clone();
                found_line = last_line;
                if let Some(line_no) = found_line {
                    if line_no > 0 {
                        break;
                    }
                }
            }
            last_line = Some(line);
        }
    }

    if verbose {
        println!(
            "found_file_name = {:?} found_line = {:?}",
            found_file_name, found_line
        );
    };

    if let (Some(symbol_name), Some(file_name), Some(line)) =
        (found_symbol_name, found_file_name, found_line)
    {
        // expect format
        // main (in BinaryName) (main.m:100)

        let demangled_name = demangle::demangle_symbol(&symbol_name);
        let symbolize_result = format!(
            "{} (in {}) ({}:{})",
            demangled_name, object_filename, file_name, line
        );
        return Ok(symbolize_result);
    }
    Err(anyhow!("failed search symbol"))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parse_uuid_accepts_hyphenated_and_plain() {
        let a = parse_uuid_string("29118F18-9DFC-36A8-9028-A19B13996D5E").unwrap();
        let b = parse_uuid_string("29118f189dfc36a89028a19b13996d5e").unwrap();
        assert_eq!(a, b);
        assert_eq!(format_uuid(a), "29118F18-9DFC-36A8-9028-A19B13996D5E");
    }

    #[test]
    fn parse_uuid_rejects_invalid() {
        assert!(parse_uuid_string("not-a-uuid").is_err());
        assert!(parse_uuid_string("1234").is_err());
    }

    #[test]
    fn macho_arch_aliases_match() {
        assert!(macho_arch_matches_filter("arm64", "aarch64"));
        assert!(macho_arch_matches_filter("x86_64", "amd64"));
        assert!(macho_arch_matches_filter("i386", "x86"));
    }
}