Skip to content

Instantly share code, notes, and snippets.

@chandlerc
Created October 16, 2022 02:48
Show Gist options
  • Save chandlerc/bf1bbc202b7878ba230198a1e7da974d to your computer and use it in GitHub Desktop.
Save chandlerc/bf1bbc202b7878ba230198a1e7da974d to your computer and use it in GitHub Desktop.
> llc -fast-isel -function-sections -data-sections --relocation-model=pic reduced.test.ll -o - | tee /dev/stderr | clang -fpie -fdata-sections -ffunction-sections -O1 -o reduced.test -x assembler -; and otool -t -v reduced.test
reduced.test:
(__TEXT,__text) section
_my_function:
0000000100003e88 stp x29, x30, [sp, #-0x10]!
0000000100003e8c adrp x8, 517 ; 0x100208000
0000000100003e90 add x9, x8, #0xe0
0000000100003e94 str x0, [x9]
0000000100003e98 tbnz w1, #0x0, 0x100003ea8
0000000100003e9c ldr x0, [x8, #0xe0]
0000000100003ea0 bl _my_function2
0000000100003ea4 brk #0x1
0000000100003ea8 bl ___asan_report_load8
0000000100003eac brk #0x1
_my_function2:
0000000100003eb0 stp x29, x30, [sp, #-0x10]!
0000000100003eb4 mov x0, xzr
0000000100003eb8 bl 0x100003ef0 ; symbol stub for: __exit
0000000100003ebc ldp x29, x30, [sp], #0x10
0000000100003ec0 ret
___asan_report_load8:
0000000100003ec4 stp x29, x30, [sp, #-0x10]!
0000000100003ec8 bl 0x100003efc ; symbol stub for: _abort
0000000100003ecc ldp x29, x30, [sp], #0x10
0000000100003ed0 ret
_main:
0000000100003ed4 stp x29, x30, [sp, #-0x10]!
0000000100003ed8 adr x0, #0x4128
0000000100003edc nop
0000000100003ee0 and w1, wzr, #0x1
0000000100003ee4 bl _my_function
0000000100003ee8 ldp x29, x30, [sp], #0x10
0000000100003eec ret
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-macosx12.0.0"
@big_padding1 = global { [2 x [1024 x [1024 x i8] ] ], [7 x [32 x i8] ] } zeroinitializer
@my_global = global { ptr, [24 x i8] } zeroinitializer
@big_padding2 = global { [2 x [1024 x [1024 x i8] ] ], [13 x [32 x i8] ] } zeroinitializer
define void @my_function(ptr %0, i1 %1) personality ptr null {
store ptr %0, ptr @my_global, align 8
br label %3
3: ; preds = %2
br i1 %1, label %4, label %5
4: ; preds = %3
call void @__asan_report_load8()
unreachable
5: ; preds = %3
br label %6
6: ; preds = %5
%7 = load ptr, ptr @my_global, align 8
br label %8
8: ; preds = %6
call void @my_function2(ptr %7)
br label %9
9: ; preds = %8
%10 = call ptr null(ptr null)
ret void
}
declare void @_exit(i64)
define void @my_function2(ptr) {
call void @_exit(i64 0)
ret void
}
declare void @abort()
define void @__asan_report_load8() {
call void @abort()
ret void
}
define void @main() {
call void @my_function(ptr @big_padding1, i1 false)
ret void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment