首先,參考Linaro的patch最直接的最佳化方法就是使用-O3以及strict-aliasing來作最佳化如下 :
------------------------ core/combo/TARGET_linux-arm.mk ------------------------ index 9000b86..90719b9 100644 @@ -66,7 +66,7 @@ endif TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined -TARGET_arm_CFLAGS := -O2 \ +TARGET_arm_CFLAGS := -O3 \ -fomit-frame-pointer \ -fstrict-aliasing \下載Linaro-4.7之後,我們可以利用
$ export TARGET_TOOLS_PREFIX=[Linaro-4.7 path]/bin/arm-eabi-來讓AOSP切換toolchain編譯。
問題列表:
- error: template with C linkage
- 原因:錯誤使用 -isystem。例如在AOSP 的build/core/definitions.mk
- Ref.
解法 :- $(addprefix -isystem ,\ + $(addprefix -I ,\ $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ - $(filter-out $(PRIVATE_C_INCLUDES), \ + $(filter-out bionic/% $(PRIVATE_C_INCLUDES), \ $(PRIVATE_TARGET_PROJECT_INCLUDES) \ $(PRIVATE_TARGET_C_INCLUDES)))) \ + $(addprefix -isystem ,\ + $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ + $(filter bionic/%, \ + $(filter-out $(PRIVATE_C_INCLUDES), \ + $(PRIVATE_TARGET_PROJECT_INCLUDES) \ + $(PRIVATE_TARGET_C_INCLUDES))))) \
- unrecognized command line option '-mno-thumb'
- 原因: gcc-4.7似乎沒有-mno-thumb
- 解法:替換成-marm
- -Werror=strict-prototypes
- 原因: 在C的話,foo()代表允許無窮的參數,而foo(void)代表"沒有"參數。但是在C++這兩種是一樣的。
- 解法:
將foo()替換成foo(void)
- dereferencing type-punned pointer will break strict-aliasing rules (Werror=strict-aliasing)
- 遇到
error: ‘truncate’ was not declared in this scope error: ‘sleep’ was not declared in this scope error: ‘pipe’ was not declared in this scope error: there are no arguments to 'offsetof' that depend on a template parameter, so a declaration of 'offsetof' must be available
- 原因:因為很多標準的C++函式庫的header 都沒有 include unistd.h了。
- Ref.
解法 : 加入#include <unistd.h> - 遇到
error: redeclaration of ‘int i’ error: ‘int i’ previously declared here
- 原因: 重複使用變數,例如
void f(int); int main() { for (int i=0;;++i) { int i=5; f(i); } return 0; }
Ref. 解法: 不要重複使用"i" - unable to find string literal operator
- 原因: 參考Ref. 發生的情形例如
const char *p = "foobar"__TIME__;
解法:在macro和 字串中間加個空格