Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default to obfuscation #4

Open
wants to merge 1 commit into
base: swift-llvm-5.5
Choose a base branch
from

Conversation

alexcohn
Copy link

This is not a real Pull Request it has not been tested thoroughly enough, and may not be fit for everybody. I open it now as a way of discussion: what should be the right approach to resolve the limitation that was introduced by LLVM relatively recently.

This is the easiest way I found to work around -mllvm is not supported with -fembed-bitcode.

This didn't happen before, on llvm-9.0.1 (but that was not compatible with the modern Xcode).

I tried to simply remove the error check for mllvm from clang/lib/Driver/ToolChains/Clang.cpp, but this resulted in lots of suspicious warnings while compiling my iOS code, so I did not follow this path. Maybe, I did something wrong?

@ghost
Copy link

ghost commented Dec 19, 2021

@heroims please open the issue page

@heroims heroims self-requested a review December 19, 2021 13:52
@heroims heroims added good first issue Good for newcomers question Further information is requested wontfix This will not be worked on labels Dec 19, 2021
@androiddisk
Copy link

@alexcohn
你好,我按照您的修改,有以下报错。要怎样才能编译出 LLVMgold.so

Hello, according to your modification, I have the following error reports. How to compile llvmgold.so。

`

[armeabi-v7a] StaticLibrary : libkooapk.a
[armeabi-v7a] Compile++ thumb: utils <= missing.cpp
[armeabi-v7a] Compile++ thumb: utils <= new.cpp
[armeabi-v7a] Compile++ thumb: utils <= files.cpp
[armeabi-v7a] Compile++ thumb: utils <= misc.cpp
[armeabi-v7a] Compile++ thumb: utils <= selinux.cpp
[armeabi-v7a] Compile++ thumb: utils <= logging.cpp
[armeabi-v7a] Compile++ thumb: utils <= xwrap.cpp
[armeabi-v7a] Compile++ thumb: utils <= stream.cpp
[armeabi-v7a] StaticLibrary : libutils.a
[armeabi-v7a] Executable : binary
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /root/kooapk/llvm/obfuscator_9.0.1/build/bin/../lib/LLVMgold.so: could not load plugin library: /root/kooapk/llvm/obfuscator_9.0.1/build/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/binary/binary.o:1:3: invalid character
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/binary/binary.o:1:3: syntax error, unexpected $end
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/binary/binary.o: not an object or archive
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/resetprop/persist_properties.o:1:3: invalid character
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/resetprop/persist_properties.o:1:3: syntax error, unexpected $end
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/resetprop/persist_properties.o: not an object or archive
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/resetprop/resetprop.o:1:3: invalid character
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/resetprop/resetprop.o:1:3: syntax error, unexpected $end
/root/kooapk/cmdline-tools/ndk/ollvm/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi-v7a/objs/binary/resetprop/resetprop.o: not an object or archive
/root/kooapk/cmdline-tools/ndk/ollvm/platforms/android-16/arch-arm/usr/lib/../lib/crtbegin_dynamic.o:crtbegin.c:function _start_main: error: undefined reference to 'main'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/root/kooapk/cmdline-tools/ndk/ollvm/build/core/build-binary.mk:738: obj/local/armeabi-v7a/binary] Error 1
`

@alexcohn
Copy link
Author

alexcohn commented Jan 1, 2022

@androiddisk This build failure does not look related to the change in PassManagerBuilder.cpp.

hudjefa pushed a commit to hudjefa/obfuscator-llvm that referenced this pull request Feb 14, 2022
Andrei Matei reported a llvm11 core dump for his bpf program
   https://bugs.llvm.org/show_bug.cgi?id=48578
The core dump happens in LiveVariables analysis phase.
  heroims#4 0x00007fce54356bb0 __restore_rt
  heroims#5 0x00007fce4d51785e llvm::LiveVariables::HandleVirtRegUse(unsigned int,
      llvm::MachineBasicBlock*, llvm::MachineInstr&)
  heroims#6 0x00007fce4d519abe llvm::LiveVariables::runOnInstr(llvm::MachineInstr&,
      llvm::SmallVectorImpl<unsigned int>&)
  heroims#7 0x00007fce4d519ec6 llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int)
  heroims#8 0x00007fce4d51a4bf llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&)
The bug can be reproduced with llvm12 and latest trunk as well.

Futher analysis shows that there is a bug in BPF peephole
TRUNC elimination optimization, which tries to remove
unnecessary TRUNC operations (a <<= 32; a >>= 32).
Specifically, the compiler did wrong transformation for the
following patterns:
   %1 = LDW ...
   %2 = SLL_ri %1, 32
   %3 = SRL_ri %2, 32
   ... %3 ...
   %4 = SRA_ri %2, 32
   ... %4 ...

The current transformation did not check how many uses of %2
and did transformation like
   %1 = LDW ...
   ... %1 ...
   %4 = SRL_ri %2, 32
   ... %4 ...
and pseudo register %2 is used by not defined and
caused LiveVariables analysis core dump.

To fix the issue, when traversing back from SRL_ri to SLL_ri,
check to ensure SLL_ri has only one use. Otherwise, don't
do transformation.

Differential Revision: https://reviews.llvm.org/D97792

(cherry picked from commit 51cdb780db3b9b46c783efcec672c4da272e9992)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants