Anti-AIClone

Log date · Mon

Does LLVM obfuscation protect your code?

Published on · Updated

LLVM obfuscation changes code representation, not exposed behavior. Compare a compiler baseline and test the protection layer separately.

What does LLVM obfuscation protect?

LLVM obfuscation can change a program’s internal representation and increase the work needed to understand it, but it does not remove the behavior the program exposes. We built a baseline with our own pricing function: its static instruction count fell from 23 at -O0 to 9 at -O2. With LTO it stayed at 9, while the symbol changed from global to local. All three programs produced identical output for eight inputs.

This is why an evaluation needs both artifact and behavior checks. A different code shape does not mean a different business rule; a complicated listing is not, by itself, evidence of effective protection. We first reproduce the baseline, then examine passes, integration points and acceptance criteria.

Results at a glance
QuestionFinding
What did optimization change?The function fell from 23 to 9 static instructions.
What changed with LTO?Still 9 instructions here; _quote became local.
Did outputs change?Outputs for eight inputs were byte-identical.
Does this measure obfuscation?No; this is a normal compiler baseline.

Sample, tools and scope

We wrote a tiered pricing function: 90 per unit from 20 units, 80 from 100, and 100 otherwise. The noinline attribute keeps a separate function to inspect; it is not a recommended production setting. The inputs include zero and values on both sides of each threshold.

The sample function.
__attribute__((noinline)) int quote(int units) {
    int rate = units >= 100 ? 80 : units >= 20 ? 90 : 100;
    return units * rate;
}

We ran all three executables locally on macOS 27.2 arm64 with Apple clang 21.0.0 and the system otool, nm and cmp. No obfuscation pass was installed, so the discussion of obfuscation below comes from documentation and was not executed; this experiment did not measure reverse-engineering time or performance.

Compare the compiled function first

Clang describes -O0 as no optimization and -O2 as enabling most optimizations. These are compiler settings, not obfuscation switches. [1] We built the same source with each setting and inspected _quote in the final executable.

Build and inspection commands.
clang -O0 sample.c -o O0
clang -O2 sample.c -o O2
clang -O2 -flto sample.c -o lto
otool -tvV O0
otool -tvV O2
otool -tvV lto
nm O0
nm O2
nm lto

We counted addressed instruction lines between the _quote label and the next function label in otool’s output. This is neither the program’s total instruction count nor the number executed at runtime. The -O0 version stores and reloads intermediate values on the stack; the -O2 version selects the tier with conditional-select instructions. Counts depend on architecture, compiler, flags and function boundaries, and cannot be converted directly into performance or security scores.

Output from our run; T denotes a global text symbol and t a local text symbol.
== O0 instruction count ==
23
== O0 quote symbol ==
00000001000004b0 T _quote

== O2 instruction count ==
9
== O2 quote symbol ==
0000000100000460 T _quote

== lto instruction count ==
9
== lto quote symbol ==
0000000100000460 t _quote

With LTO the name remains in the symbol table, but its visibility changes. LLVM documents link-time use of linker information for intermodule optimization, including removing unused symbols. [4] Our sample has one source file, so it does not predict the exact changes in a multi-module application.

Then compare behavior

Each program ran the same fixed inputs, and we compared their complete output files with cmp. One output is shown below; the comparisons confirm the other two are byte-identical. The results at 20 and 100 matter particularly because those inputs select different price tiers.

Identical output in all three builds, copied here from O0.
0 -> 0
1 -> 100
19 -> 1900
20 -> 1800
21 -> 1890
99 -> 8910
100 -> 8000
101 -> 8080
Results of the cmp comparisons.
== output comparisons ==
O0 vs O2: identical
O0 vs lto: identical

Eight examples are not a proof of equivalence for every integer, and they do not cover overflow, concurrency, error handling or device differences in a real app. These small values do not trigger signed integer overflow. For release acceptance, add boundary, error, randomized and real business cases, with independent expected results rather than only comparing two versions that could both be wrong.

An external user can also observe inputs and outputs. Even if the internals become harder to read, sufficiently informative queries can reveal part of a rule. Include query volume, input range and server-side permissions in the threat model instead of judging protection only by whether the disassembly got longer.

Where an LLVM pass fits

LLVM describes passes as compiler components that analyze or transform an intermediate representation; plugins can add passes to an optimization pipeline. [2] A particular obfuscator needs its supported compiler and integration method. First establish that the target module actually enters that pipeline, then inspect the final linked artifact. Seeing an option in a build log alone does not establish that every intended function was transformed.

For example, the Obfuscator-LLVM project describes control-flow flattening as arranging basic blocks inside a loop, with a state variable and switch selecting the next step. [3] That is an illustration from that project’s documentation, not a guarantee of LLVM’s default optimizer or a result of our test. Different tools, versions, pass ordering and later optimizations can produce different artifacts; do not call our -O2 result flattening.

Integration also requires concrete answers: are dependencies available as source, IR or already compiled machine code? Does the transformation run before or during linking? Can LTO, inlining or symbol handling change the final result? Associate compiler version, configuration, build logs and final artifacts so that a functional or performance regression after an upgrade can be traced.

Recommendations for selection and acceptance

The table gives engineering recommendations, not protection effects measured in this experiment. Identify the asset and the interface visible to an adversary first, then compare each candidate using the same release configuration.

Recommendations by case
CaseRecommendation
Protecting proprietary logicConfirm the module enters the supported pipeline; retain an untransformed baseline.
Only a compiled third-party library is availableCheck input requirements; do not assume an IR pass accepts machine code.
An interface may reveal rulesTest boundaries and query cost; move sensitive decisions to a controlled service where feasible.
Preparing a transformed releaseEnable layers incrementally; validate functionality, performance, crash symbolication and rollback.

Fix the toolchain, architecture, inputs and build flags, then add one transformation at a time. Check that the release artifact contains the intended code and compare the same functional tests, startup time, critical-path latency and size. For security value, commission an authorized independent assessment with tasks, time limits, success criteria and evidence defined in advance. The time taken in one review is not a universal attack cost.

Keep the debug symbols and configuration corresponding to each release with restricted access, and rehearse crash diagnosis, updates and rollback. If performance or compatibility exceeds budget, be able to disable an individual transformation and validate again. Key management remains a separate design problem: do not put a shared privileged secret in a client merely because its code is transformed.

Run this on your own app

Choose a macOS build you are authorized to examine and save baseline and candidate artifacts in an isolated directory. Substitute your executable paths below. Symbols may be inlined, renamed or stripped, so no match does not mean the code is absent. Use the relevant toolchain and format on other platforms.

macOS inspection template; replace the paths and use your project’s test command.
otool -tvV path/to/baseline > baseline.asm
otool -tvV path/to/candidate > candidate.asm
nm path/to/baseline > baseline.symbols
nm path/to/candidate > candidate.symbols
# Run your own test suite against each build and compare the results.

Do not just count instructions across the entire file. Identify the target function and its boundaries, then check that the transformation survives into the final artifact. Compare results for the same inputs against independent expectations, and retain failing cases, tool versions and build configuration. Finally repeat performance and compatibility tests on target devices and verify the diagnostic and rollback process.

Your checklist

  • Confirm the target module enters the supported compilation pipeline.
  • Keep the toolchain details and an untransformed release baseline.
  • Compare final artifacts, functionality and performance one layer at a time.
  • Test observable behavior using boundary cases and independent expectations.
  • Retain controlled symbol files and rehearse rollback.

Primary sources

All sources and reproduction status ↗