Skip to content

Commit

Permalink
Add break-cfg test coverage for iOS
Browse files Browse the repository at this point in the history
Our refactor on avoiding shipping a `CompilerInvocation` instance
to favour host clang invocation for jit-compiling code was formerly
testing C++ code only. This additional test should confirm jitting
ASM works properly too when targeting iOS.
  • Loading branch information
antoniofrighetto committed Jan 8, 2024
1 parent 17b9442 commit 09cc7a6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/core/Jitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,13 @@ std::unique_ptr<MemoryBuffer> Jitter::jitAsm(const std::string& Asm, size_t Size
orc::LLJITBuilder Builder;
std::string TT = Triple_;
orc::JITTargetMachineBuilder JTMB{llvm::Triple(TT)};
// Note(romain): At this point, the code crashes on OSX/iOS.
// -> To be investigated
#if 0
JTMB.setRelocationModel(Reloc::Model::PIC_);
JTMB.setCodeModel(CodeModel::Large);
JTMB.setCodeGenOptLevel(CodeGenOpt::Level::None);

Builder
.setPlatformSetUp(orc::setUpInactivePlatform) // /!\Only for iOS???
.setJITTargetMachineBuilder(JTMB);
#endif

Builder
.setJITTargetMachineBuilder(std::move(JTMB));
Expand Down
56 changes: 56 additions & 0 deletions src/test/passes/break-cfg/basic-aarch64-ios.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// REQUIRES: aarch64-registered-target
// XFAIL: host-platform-linux

// RUN: clang -target arm64-apple-ios -fno-legacy-pass-manager -O1 -fno-verbose-asm -S %s -o - | FileCheck %s
// RUN: env OMVLL_CONFIG=%S/config_all.py clang -target arm64-apple-ios -fno-legacy-pass-manager -fpass-plugin=%libOMVLL -O1 -fno-verbose-asm -S %s -o - | FileCheck --check-prefix=BREAKCFG-IOS %s

// BREAKCFG-IOS-LABEL: _check_password.1:
// ; adr x1, #0x10
// ; ldr x0, [x1, #61]
// ; ldr x1, #16
// ; blr x1
// BREAKCFG-IOS: .byte 129
// BREAKCFG-IOS: .byte 0
// BREAKCFG-IOS: .byte 0
// BREAKCFG-IOS: .byte 16
// BREAKCFG-IOS: .byte 32
// BREAKCFG-IOS: .byte 208
// BREAKCFG-IOS: .byte 67
// BREAKCFG-IOS: .byte 248
// BREAKCFG-IOS: .byte 129
// BREAKCFG-IOS: .byte 0
// BREAKCFG-IOS: .byte 0
// BREAKCFG-IOS: .byte 88
// BREAKCFG-IOS: .byte 32
// BREAKCFG-IOS: .byte 0
// BREAKCFG-IOS: .byte 63
// BREAKCFG-IOS: .byte 214

// CHECK-LABEL: _check_password:
// BREAKCFG-IOS: Lloh0:
// BREAKCFG-IOS: adrp x8, _check_password.1@PAGE
// BREAKCFG-IOS: Lloh1:
// BREAKCFG-IOS: add x8, x8, _check_password.1@PAGEOFF
// BREAKCFG-IOS: str x8, [sp]
// BREAKCFG-IOS: add x8, x8, #32
// BREAKCFG-IOS: str x8, [sp, #8]
// BREAKCFG-IOS: ldr x8, [sp, #8]
// BREAKCFG-IOS: blr x8

int check_password(const char* passwd, unsigned len) {
if (len != 5) {
return 0;
}
if (passwd[0] == 'O') {
if (passwd[1] == 'M') {
if (passwd[2] == 'V') {
if (passwd[3] == 'L') {
if (passwd[4] == 'L') {
return 1;
}
}
}
}
}
return 0;
}
12 changes: 12 additions & 0 deletions src/test/passes/break-cfg/config_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import omvll
from functools import lru_cache

class MyConfig(omvll.ObfuscationConfig):
def __init__(self):
super().__init__()
def break_control_flow(self, mod: omvll.Module, func: omvll.Function):
return True

@lru_cache(maxsize=1)
def omvll_get_config() -> omvll.ObfuscationConfig:
return MyConfig()

0 comments on commit 09cc7a6

Please sign in to comment.