Ollvm Compiler Optimization bug

Source: Internet
Author: User

Recently, we have used ollvm to compile some code. We need to perform some obfuscation operations on so, and found a bug, which is recorded as follows:

Code segment 1

jint begin_antidebug(){    pthread_t antidebugtid;    int ret = 0;    ret = pthread_create(&antidebugtid, NULL, antidebug_listen_thread, NULL);    if(ret!=0)    {        LOGANTI("Create pthread error!\n");        exit (1);    }    return 0;    }


The above code snippet completes the logic of creating a thread. If the thread fails to be created, the Code directly exits the application.
The android ndk default compiler or ollvm compiler runs according to the code logic.


However, if code segment 2 is as follows:

jint begin_antidebug(){    pthread_t antidebugtid;    int ret = 0;    ret = pthread_create(&antidebugtid, NULL, antidebug_listen_thread, NULL);    if(ret!=0)    {        LOGANTI("Create pthread error!\n");        exit (1);    }    }

This code is compared with the above Code, with a return 0 missing; this statement
At this time, the compilation results of the two compilers are different.

The Code Compiled by the android ndk compiler by default can still run according to the code logic.
The Code Compiled by the ollvm compiler is optimized to 0 by ret. Although the thread is successfully created, the process also executes exit (1 );
Exited


To prevent this type of bad code, add the following line to Android. mk.

Local_cflags + =-werror

Strengthen the check type, and handle the same issue as warning and error.


Ollvm Compiler Optimization bug

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.