ollvm 編譯器最佳化的bug

來源:互聯網
上載者:User

標籤:android   編譯器   create   error   return   

近來用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同樣處理


ollvm 編譯器最佳化的bug

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.