温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ollvm 编译器优化的bug

发布时间:2020-09-18 16:41:29 来源:网络 阅读:2035 作者:sunzeduo 栏目:移动开发

近来用ollvm来编译一些代码,主要是需要对so进行一些混淆的操作,发现了一个bug,记录如下:

代码段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;
    
}


上面的代码段就是完成一个创建线程的逻辑,如果线程创建失败,直接退出应用,这段代码不管用
android ndk默认的编译器或者是ollvm编译器,运行结果都是按照代码逻辑的。


但是如果代码段2,如下

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;这条语句
这个时候,两种编译器对于编译的结果就有差异了

android ndk默认编译器 编译出来的代码依然能够按照代码逻辑运行。
而 ollvm编译器编译出来的代码,ret优化成0了,虽然线程创建成功了,但是进程也执行 exit(1);
退出了


防止这类bad code的方法,在Android.mk加入下面这行。

LOCAL_CFLAGS +=  -Werror

加强检查类型,出现warning和error同样处理


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI