Skip to content

Commit ac70160

Browse files
committed
Strip unnecessary info from expected assembly output
1 parent ec943d4 commit ac70160

File tree

8 files changed

+22
-53
lines changed

8 files changed

+22
-53
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.build_version macos, 11, 0
32
.globl _handle
43
.p2align 2
54
_handle:
6-
.cfi_startproc
75
b _objc_msgSend
8-
.cfi_endproc
96

107
.subsections_via_symbols
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.build_version iossimulator, 14, 0
32
.globl _handle
43
.p2align 2
54
_handle:
6-
.cfi_startproc
75
b _objc_msgSend
8-
.cfi_endproc
96

10-
; Stripped __LLVM line
11-
; Stripped __LLVM line
12-
; Stripped __LLVM line
13-
; Stripped __LLVM line
7+
; Stripped __LLVM section
148

15-
; Stripped __LLVM line
16-
; Stripped __LLVM line
17-
; Stripped __LLVM line
18-
; Stripped __LLVM line
9+
; Stripped __LLVM section
1910

2011
.subsections_via_symbols
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.ios_version_min 7, 0
32
.globl _handle
43
.p2align 2
54
_handle:
6-
.cfi_startproc
75
b _objc_msgSend
8-
.cfi_endproc
96

10-
; Stripped __LLVM line
11-
; Stripped __LLVM line
12-
; Stripped __LLVM line
13-
; Stripped __LLVM line
7+
; Stripped __LLVM section
148

15-
; Stripped __LLVM line
16-
; Stripped __LLVM line
17-
; Stripped __LLVM line
18-
; Stripped __LLVM line
9+
; Stripped __LLVM section
1910

2011
.subsections_via_symbols
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.ios_version_min 7, 0
32
.intel_syntax noprefix
43
.globl _handle
54
.p2align 4, 0x90
65
_handle:
7-
.cfi_startproc
86
push ebp
9-
.cfi_def_cfa_offset 8
10-
.cfi_offset ebp, -8
117
mov ebp, esp
12-
.cfi_def_cfa_register ebp
138
pop ebp
149
jmp _objc_msgSend
15-
.cfi_endproc
1610

1711
.subsections_via_symbols
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.macosx_version_min 10, 7
32
.intel_syntax noprefix
43
.globl _handle
54
.p2align 4, 0x90
65
_handle:
7-
.cfi_startproc
86
push ebp
9-
.cfi_def_cfa_offset 8
10-
.cfi_offset ebp, -8
117
mov ebp, esp
12-
.cfi_def_cfa_register ebp
138
pop ebp
149
jmp _objc_msgSend
15-
.cfi_endproc
1610

1711
.subsections_via_symbols
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.macosx_version_min 10, 7
32
.intel_syntax noprefix
43
.globl _handle
54
.p2align 4, 0x90
65
_handle:
7-
.cfi_startproc
86
push rbp
9-
.cfi_def_cfa_offset 16
10-
.cfi_offset rbp, -16
117
mov rbp, rsp
12-
.cfi_def_cfa_register rbp
138
pop rbp
149
jmp _objc_msgSend
15-
.cfi_endproc
1610

1711
.subsections_via_symbols
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
.section __TEXT,__text,regular,pure_instructions
2-
.ios_version_min 7, 0
32
.intel_syntax noprefix
43
.globl _handle
54
.p2align 4, 0x90
65
_handle:
7-
.cfi_startproc
86
push rbp
9-
.cfi_def_cfa_offset 16
10-
.cfi_offset rbp, -16
117
mov rbp, rsp
12-
.cfi_def_cfa_register rbp
138
pop rbp
149
jmp _objc_msgSend
15-
.cfi_endproc
1610

1711
.subsections_via_symbols

tests/src/bin/test_assembly.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ use std::io;
1111
use std::path::Path;
1212
use std::process::{Command, Stdio};
1313

14+
fn strip_lines(data: &str, starts_with: &str) -> String {
15+
data.lines()
16+
.filter(|line| !line.trim_start().starts_with(starts_with))
17+
.collect::<Vec<_>>()
18+
.join("\n")
19+
}
20+
1421
fn strip_section(data: &str, section: &str) -> String {
1522
let mut res = String::with_capacity(data.len());
1623
let mut in_removed_section = false;
@@ -20,14 +27,17 @@ fn strip_section(data: &str, section: &str) -> String {
2027
in_removed_section = false;
2128
}
2229
if line.trim().starts_with(".section") {
23-
in_removed_section = line.contains(section);
30+
if line.contains(section) {
31+
in_removed_section = true;
32+
write!(res, "; Stripped {section} section\n").unwrap();
33+
} else {
34+
in_removed_section = false;
35+
}
2436
}
2537
if !in_removed_section {
2638
res.push_str(line);
27-
} else {
28-
write!(res, "; Stripped {section} line").unwrap();
39+
res.push('\n');
2940
}
30-
res.push('\n');
3141
}
3242
res
3343
}
@@ -41,6 +51,10 @@ fn read_assembly<P: AsRef<Path>>(path: P) -> io::Result<String> {
4151
.to_str()
4252
.unwrap();
4353
let s = s.replace(workspace_dir, "$WORKSPACE");
54+
let s = strip_lines(&s, ".cfi_");
55+
let s = strip_lines(&s, ".macosx_version_");
56+
let s = strip_lines(&s, ".ios_version_");
57+
let s = strip_lines(&s, ".build_version");
4458
// We remove the __LLVM,__bitcode and __LLVM,__cmdline sections because
4559
// they're uninteresting for out use-case.
4660
//

0 commit comments

Comments
 (0)