Windows system OLLVM + NDK confusing build environment

Source: Internet
Author: User
Tags run python script

First, Environment construction:

System: win10_x64

NDK version: ndk-r12b (ndk-r12b subsequent versions also apply)

Cmake-3.9.1-win64-x64.msi is used to generate source code build files for different compilers, such as using VS to generate (. sln) vs configuration files, if using gcc (Makefile)

Mingw-w64-install.exe Windows-based GNU GCC compiler

python2.7 run Python script, do not use version 3.0 and above

Cmake,mingw,python (Baidu Network disk): https://pan.baidu.com/s/1v49gBKzF-2VAqMywvtnlUw password: hd7z

Add environment variable: C:\Python27

C:\Program Files (x86) \mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin

C:\Program Files\cmake\bin

environment variables According to the software specific installation path configuration

Second, compiling OLLVM

1, clear concept: LLVM and OLLVM

LLVM is the abbreviation for Lowlevel virtual machine and is a compiler framework. Apple's Xcode 4.0 was followed by the LLVM compiler.     LLVM was born in 2003.10 at the University of Illinois at Urbana-Champaign, founder Chrislattner, and is currently the head of Apple's developer tools Division.

OBFUSCATOR-LLVM (OLLVM) is a code obfuscation tool developed by the Northwestern University of Applied Sciences Security Laboratory for LLVM compiled components, which is fully open source to increase the difficulty of reverse engineering and ensure the security of the code.  

OBFUSCATOR-LLVM (OLLVM) integrates compilers and is compatible with all languages supported by LLVM (c,c++, Objective-c, Ada and Fortran) and platforms (x86, x86-64, PowerPC, PowerPC-64 , ARM, Thumb, SPARC, Alpha, CELLSPU, MIPS, MSP430, Systemz,and XCore).

2. Compiling instructions

      git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git      mkdir build      cd build      cmake -G “MinGW Makefiles” -DCMAKE_BUILD_TYPE=Release ../obfuscator/      mingw32-make -j7
 
网上很多资料上使用make命令,而不是mingw32-make命令,在我所安装的mingw并没有提供make命令,前面说明了我是在win10 64系统上通过mingw-w64-install.exe安装的。可能是系统不一样的原因。

CMake If you do not specify a parameter, the default is to select the current computer's existing compiler, if the installation of VS, will automatically find the VS compiler

If you intend to use vs compile

Cmake-dcmake_build_type=release. /obfuscator/

Generates a 32-bit dependent version

Cmake-g "Visual Studio Win64"-dcmake_build_type=release. /obfuscator/

The 15 and 2017 in Visual Studio Win64 are the corresponding relationship between the number of the platform toolset in VS and the VS version number, 14 corresponds to 2015,12 2013, and if you are compiling with VS, be careful to configure the VS version that you installed. the above method will generate a 64-bit version of the compilation environment, but in the test compile, 32-bit normal compilation through, 64 bit a lot of pits, so it is not recommended to use VS compilation.

When compiling with MinGW, you need to add parameters

Cmake-g "MinGW makefiles"-dcmake_build_type=release. /obfuscator/

3, the compilation process takes about 30 minutes or more, after compiling the build folder can see the bin and Lib two folders, which is required for subsequent use.

Iii. use of OLLVM in the NDK

1. The android-ndk-r12b\toolchains path will have a LLVM folder, copy a copy of the LLVM folder to the same path (that is, under the Android-ndk-r12b\toolchains path), and then rename the folder to ollvm-4.0

2. Delete the bin and Lib64 folder under the android-ndk-r12b\toolchains\ollvm-4.0\prebuilt\windows-x86_64 path, and the bin and Lib under the above build directory Two folder copy to path android-ndk-r12b\toolchains\ollvm-4.0\prebuilt\windows-x86_64;

3. Under Android-ndk-r12b\build\core\toolchains Path, create new directory arm-linux-androideabi-clang-ollvm4.0, copy directory Arm-linux-androideabi-clang file Config.mk and setup.mk to arm-linux-androideabi-clang-ollvm4.0, modify the Setup.mk file;

# # Override The toolchain prefix # ############################ original configuration ############################ #LLVM_T Oolchain_prebuilt_root: = $ (call GET-TOOLCHAIN-ROOT,LLVM) #LLVM_TOOLCHAIN_PREFIX: = $ (llvm_toolchain_prebuilt_root)/ bin/################################################################# ############################ Modified ########## ################### ollvm_name: = ollvm-4.0 Llvm_toolchain_prebuilt_root: = $ (Call get-toolchain-root,$ (OLLVM_NAME ) Llvm_toolchain_prefix: = $ (llvm_toolchain_prebuilt_root)/bin/#其他配置不做修改 ...

Config.mk saves the CPU schema for the compilation chain, so the above modifications can only compile Armeabi and armeabi-v7a schemas. If you need to compile other schemas, you need to make the appropriate modifications.
文件夹名也必须按照严格的格式,如 mips 的需要添加文件夹:mipsel-linux-android-clang-ollvm4.0,修改相应的 setup.mk 文件。


Iv. Use of OLLVM

Compiling the NDK with OLLVM requires corresponding modifications to the APPLICATION.MK and android.mk files.

Android.mk to add the confusing compilation parameters:

    LOCAL_CFLAGS += -mllvm -sub -mllvm -bcf -mllvm -fla

parameter-related documents can be seen on GitHub Wiki:https://github.com/obfuscator-llvm/obfuscator/wiki

Configuring Ndk_toolchain_version in Application.mk

    APP_ABI := x86 armeabi-v7a x86_64 arm64-v8a mips armeabi mips64    NDK_TOOLCHAIN_VERSION := clang-ollvm4.0
五、参考文献
  https://www.anquanke.com/post/id/86384
  http://blog.csdn.net/wangbaochu/article/details/45370543

Windows system OLLVM + NDK confusing build environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.