昌黎建设局网站,wordpress vue react,阳江做网站多少钱,网页制作与网站建设pdf背景android模擬器運行於virtualbox中#xff0c;而virtualbox運行於x86架構的pc端#xff0c;所以android及其Linux內核都編譯成x86架構。當virtualbox的vt未開啟的情況下android系統會出現各種問題#xff0c;如arm庫游戲不能運行#xff0c;桌面平凡掛死重啟。通過查看日…背景android模擬器運行於virtualbox中而virtualbox運行於x86架構的pc端所以android及其Linux內核都編譯成x86架構。當virtualbox的vt未開啟的情況下android系統會出現各種問題如arm庫游戲不能運行桌面平凡掛死重啟。通過查看日志都奔潰在了#00 pc 000183c6 /system/lib/libc.so (__get_thread6)這個點。關於此點的日志分析過程請查看本人的另一篇文章的分析: Linux系統調用__get_thread獲取TLS失敗導致應用程序奔潰.問題在android內核為3.10時選擇CONFIG_CC_STACKPROTECTORy(開啟內核棧保護功能)在x86架構下能正常編譯解決vt下桌面重復掛死、arm庫游戲不能玩的問題。但是如果升級android內核為3.18內核開啟棧保護功能時交叉編譯x86架構下的linux內核就會出現編譯錯誤。具體看如下開啟內核配置和出錯日志開啟3.18棧保護的內核配置選項如下 -41,7 41,6 CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOCyCONFIG_HAVE_INTEL_TXTyCONFIG_X86_32_SMPyCONFIG_X86_HTy-CONFIG_X86_32_LAZY_GSyCONFIG_ARCH_HWEIGHT_CFLAGS-fcall-saved-ecx -fcall-saved-edxCONFIG_ARCH_SUPPORTS_UPROBESyCONFIG_FIX_EARLYCON_MEMy -249,10 248,10 CONFIG_HAVE_CMPXCHG_DOUBLEyCONFIG_ARCH_WANT_IPC_PARSE_VERSIONyCONFIG_HAVE_ARCH_SECCOMP_FILTERyCONFIG_HAVE_CC_STACKPROTECTORy-# CONFIG_CC_STACKPROTECTOR is not set-CONFIG_CC_STACKPROTECTOR_NONEyCONFIG_CC_STACKPROTECTORy# CONFIG_CC_STACKPROTECTOR_NONE is not set# CONFIG_CC_STACKPROTECTOR_REGULAR is not set-# CONFIG_CC_STACKPROTECTOR_STRONG is not setCONFIG_CC_STACKPROTECTOR_STRONGyCONFIG_HAVE_ARCH_WITHIN_STACK_FRAMESyCONFIG_HAVE_IRQ_TIME_ACCOUNTINGyCONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGEy開啟3.18內核棧保護配置后內核編譯x86架構錯誤如下CHK include/generated/compile.hUPD include/generated/compile.hCC init/version.oLD init/built-in.oandroid-4.4.4/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-ld: init/built-in.o: in function do_one_initcall:init_task.c(.text0x7f): error: undefined reference to __stack_chk_guardandroid-4.4.4/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-ld: init/built-in.o: in function do_one_initcall:init_task.c(.text0x1c6): error: undefined reference to __stack_chk_guardandroid-4.4.4/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-ld: init/built-in.o: in function name_to_dev_t:init_task.c(.text0x261): error: undefined reference to __stack_chk_guardandroid-4.4.4/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-ld: init/built-in.o: in function name_to_dev_t:init_task.c(.text0x517): error: undefined reference to __stack_chk_guardmake: *** [vmlinux] Error 1arch/x86/Makefile:116: stack-protector enabled but compiler support broken分析解決上述error: undefined reference to __stack_chk_guard錯誤通過各種google也沒有找到正解有的說是gcc需要4.9及以上然而用交叉編譯工具4.9也不行。還查看了android源碼關於stack protector的相關修復都沒有啥卵用。最后通過查看__stack_chk_guard字段發現x86架構沒有定義此字段而sh,arm,mips等架構確定義了。在窮途末路時只能自己動手依葫蘆畫瓢期待有所進展。如下patch為本人添加不僅能解決編譯錯誤還確實解決了vt未開啟時virtualbox下運行android鏡像出現的各種問題。Linux編譯x86架構時__stack_chk_guard未定義錯誤的修復patchdiff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.hindex 6a99859..3e2d812 100644--- a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h -41,6 41,10 #include #include #if (defined(CONFIG_CC_STACKPROTECTOR) !defined(CONFIG_SMP))extern unsigned long __stack_chk_guard;#endif/** 24 byte read-only segment initializer for stack canary. Linker* cant handle the address bit shifting. Address will be set in -79,6 83,10 static __always_inline void boot_init_stack_canary(void)#elsethis_cpu_write(stack_canary.canary, canary);#endif#if (defined(CONFIG_CC_STACKPROTECTOR) !defined(CONFIG_SMP)) __stack_chk_guard current-stack_canary;#endif}static inline void setup_stack_canary_segment(int cpu)diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.cindex 4eb204c..5ad8ab2 100644--- a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c -29,6 29,12 #include #include #if (defined(CONFIG_CC_STACKPROTECTOR) !defined(CONFIG_SMP)) unsigned long __stack_chk_guard __read_mostly;/* 配置打開SMP時會出現此__stack_chk_guard變量重復定義問題所有只能在無SMP下生效 *///static DEFINE_PER_CPU(unsigned long,__stack_chk_guard) __read_mostly;EXPORT_SYMBOL(__stack_chk_guard);#endif/** per-CPU TSS segments. Threads are completely soft on Linux,* no more per-task TSSs. The TSS size is kept cacheline-aligneddiff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.cindex 8f3ebfe..f027d25 100644--- a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c -39,6 39,11 #include #include #include #if (defined(CONFIG_CC_STACKPROTECTOR) !defined(CONFIG_SMP))#include #endif#include #include #include -249,6 254,11 __switch_to(struct task_struct *prev_p, struct task_struct *next_p)*next next_p-thread;int cpu smp_processor_id();struct tss_struct *tss per_cpu(init_tss, cpu); #if (defined(CONFIG_CC_STACKPROTECTOR) !defined(CONFIG_SMP)) __stack_chk_guard next_p-stack_canary; #endiffpu_switch_t fpu;/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */為啥內核能正常選擇打開棧保護功能但卻無法編譯通過呢后面想了想可能有如下原因一是godlfish內核主要對移動手機設備使用的內核手機一般使用的是arm芯片對於x86架構官方關注的也許並不多。二是默認此棧保護功能是關閉的只有對運行穩定性有特殊需求的產品如航天太空類高穩定產品才需要考慮打開打開后會稍微降低性能。此patch應該是可以作為官網的patch來提交修復福澤大眾的但本人從來沒有提交過限於水平有限暫且記錄以備后忘。感謝2017 …… ,卷起褲管跑擼起袖子干