实战 WSL2.0 arm 交叉工具链 — 踩坑交叉编译不兼容问题
环境
- 交叉编译器: 在
VMware UBUNTU 18.04 x64及WSL 2.0 UBUNTU 20.04 x64(非 docker 环境) 中安装的都是arm-linux-gnueabihf-4.9.4-2017.01-linaro这款编译器,从官网下载的安装包gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz - 目标终端: 内核及文件系统,是平台组 VMware UBUNTU 18.04 x64 平台下
gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz交叉编译的
问题描述
- 绝大多数情况下,目标终端看起来正常,然而,总有少量的机器表现莫名其妙地异常
- 在偶尔出现问题的终端中,起初没有发现有什么异常,仔细分析之后发现有低概率“CPU貌似卡顿”的现象
- 模拟测试时,发现 WSL 2.0 (非 docker 环境) 中发布的安装包,以 root 用户远程升级之后的用户名和组居然不是 root 帐户
- 加入进程内存、CPU运行状态跟踪监控代码,某些出现问题的终端每运行1小时会耗尽内存
问题解决
- 从代码分析上找不到原因的情况下,试着从 root 帐户的问题入手,试着看看是不是平台的问题。从
VMware UBUNTU 18.04 x64平台编译打包,居然发现 root 帐户问题神奇消失 - 从
VMware UBUNTU 18.04 x64交叉编译和打包发布,疑似的“CPU卡顿”问题消失
问题溯源
删除临时文件,纯净交叉编译项目中的守护进程,然后
arm-linux-gnueabihf-readelf导出VMware UBUNTU 18.04 x64及WSL 2.0 UBUNTU 20.04 x64编译的目标文件信息,发现些微差别VMware UBUNTU 18.04 x64平台Unwind table index '.ARM.exidx' at offset 0x12fc contains 8 entries: 0x10e68: 0x1 [cantunwind] 0x10f48: @0x112cc // 仅 VMware UBUNTU 18.04 x64 Compact model index: 1 0x97 vsp = r7 0x0d vsp = vsp + 56 0x84 0x08 pop {r7, r14} 0xb0 finish 0xb0 finish 0x10fb4: 0x80978008 // 仅 VMware UBUNTU 18.04 x64 Compact model index: 0 0x97 vsp = r7 0x80 0x08 pop {r7} 0x10fcc: @0x112d8 Compact model index: 1 0x97 vsp = r7 0x03 vsp = vsp + 16 0x84 0x08 pop {r7, r14} 0xb0 finish 0xb0 finish 0x10ff8: @0x112e4 Compact model index: 1 0x97 vsp = r7 0x0a vsp = vsp + 44 0x84 0x09 pop {r4, r7, r14} 0xb0 finish 0xb0 finish 0x1116c: @0x112f0 // 仅 VMware UBUNTU 18.04 x64 Compact model index: 1 0x97 vsp = r7 0x01 vsp = vsp + 8 0x84 0x08 pop {r7, r14} 0xb0 finish 0xb0 finish 0x111b4: 0x80978408 // 仅 VMware UBUNTU 18.04 x64 Compact model index: 0 0x97 vsp = r7 0x84 0x08 pop {r7, r14} 0x111c4: 0x1 [cantunwind] Symbol table '.dynsym' contains 54 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 0001133c 0 NOTYPE LOCAL DEFAULT 17 __exidx_end 2: 000112fc 0 NOTYPE LOCAL DEFAULT 16 __exidx_start 3: 00021528 4 OBJECT GLOBAL DEFAULT 25 g_sys_res_ctor 4: 00000000 0 FUNC GLOBAL DEFAULT UND sync@GLIBC_2.4 (2) 5: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_atexit@CXXABI_ARM_1.3.3 (3) 6: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon25GetAndCaching 7: 00021524 0 NOTYPE GLOBAL DEFAULT 24 _edata 8: 00021518 0 NOTYPE WEAK DEFAULT 24 data_start 9: 00011210 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used 10: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon11GetInstanceEv 11: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN10LogManager9LogPrintf 12: 00010ff9 370 FUNC GLOBAL DEFAULT 13 main 13: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_setschedpoli@GLIBC_2.4 (4) 14: 00021530 0 NOTYPE GLOBAL DEFAULT 25 __end__ 15: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon16CreateAllProc 16: 00011208 0 FUNC GLOBAL DEFAULT 14 _fini 17: 00021530 0 NOTYPE GLOBAL DEFAULT 25 __bss_end__ 18: 00000000 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.4 (2) 19: 00021530 0 NOTYPE GLOBAL DEFAULT 25 _bss_end__ 20: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_getschedpoli@GLIBC_2.4 (4) 21: 00000000 0 FUNC GLOBAL DEFAULT UND system@GLIBC_2.4 (4) 22: 00010e69 0 FUNC GLOBAL DEFAULT 13 _start 23: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN10SysResCtor5Sem_PE17T 24: 00000000 0 FUNC GLOBAL DEFAULT UND _Z11DebugPrintfPKcz 25: 00010d10 0 FUNC GLOBAL DEFAULT 11 _init 26: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 27: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_destroy@GLIBC_2.4 (4) 28: 00010fcd 42 FUNC GLOBAL DEFAULT 13 _Z20MonitorProcessThreadP 29: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon11IsNoMemeoryEv 30: 00021524 0 NOTYPE GLOBAL DEFAULT 25 __bss_start__ 31: 00021518 0 NOTYPE GLOBAL DEFAULT 24 __data_start 32: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_init@GLIBC_2.4 (4) 33: 00021530 0 NOTYPE GLOBAL DEFAULT 25 _end 34: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon11InitAppStatEv 35: 00021524 0 NOTYPE GLOBAL DEFAULT 25 __bss_start 36: 00000000 0 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (5) 37: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon8WatchDogEv 38: 00000000 0 FUNC GLOBAL DEFAULT UND usleep@GLIBC_2.4 (2) 39: 000111c5 64 FUNC GLOBAL DEFAULT 13 __libc_csu_init 40: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr1@GCC_3.5 (6) 41: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_create@GLIBC_2.4 (4) 42: 00010fb5 24 FUNC GLOBAL DEFAULT 13 _Z18VersionCodeDeclarev 43: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon14MonitorProces 44: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 45: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_setschedpara@GLIBC_2.4 (4) 46: 00010f49 108 FUNC GLOBAL DEFAULT 13 SetThreadSchedPolicyRR 47: 00011205 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini 48: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr0@GCC_3.5 (6) // 仅 VMware UBUNTU 18.04 x64 49: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.4 (2) 50: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 51: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 52: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN10SysResCtor11GetInsta 53: 00010e5c 0 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4 (5) Histogram for bucket list length (total of 37 buckets): Length Number % of total Coverage 0 6 ( 16.2%) 1 15 ( 40.5%) 28.3% 2 11 ( 29.7%) 69.8% 3 4 ( 10.8%) 92.5% 4 1 ( 2.7%) 100.0%WSL 2.0 UBUNTU 20.04 x64平台Unwind table index '.ARM.exidx' at offset 0x12d8 contains 4 entries: 0x10e5c: 0x1 [cantunwind] 0x10fc0: @0x112c0 Compact model index: 1 0x97 vsp = r7 0x03 vsp = vsp + 16 0x84 0x08 pop {r7, r14} 0xb0 finish 0xb0 finish 0x10fec: @0x112cc Compact model index: 1 0x97 vsp = r7 0x0a vsp = vsp + 44 0x84 0x09 pop {r4, r7, r14} 0xb0 finish 0xb0 finish 0x11160: 0x1 [cantunwind] Symbol table '.dynsym' contains 53 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 000112f8 0 NOTYPE LOCAL DEFAULT 17 __exidx_end 2: 000112d8 0 NOTYPE LOCAL DEFAULT 16 __exidx_start 3: 000214e4 4 OBJECT GLOBAL DEFAULT 25 g_sys_res_ctor 4: 00000000 0 FUNC GLOBAL DEFAULT UND sync@GLIBC_2.4 (2) 5: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_atexit@CXXABI_ARM_1.3.3 (3) 6: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon25GetAndCaching 7: 000214e0 0 NOTYPE GLOBAL DEFAULT 24 _edata 8: 000214d4 0 NOTYPE WEAK DEFAULT 24 data_start 9: 00011204 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used 10: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon11GetInstanceEv 11: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN10LogManager9LogPrintf 12: 00010fed 370 FUNC GLOBAL DEFAULT 13 main 13: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_setschedpoli@GLIBC_2.4 (4) 14: 000214ec 0 NOTYPE GLOBAL DEFAULT 25 __end__ 15: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon16CreateAllProc 16: 000111fc 0 FUNC GLOBAL DEFAULT 14 _fini 17: 000214ec 0 NOTYPE GLOBAL DEFAULT 25 __bss_end__ 18: 00000000 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.4 (2) 19: 000214ec 0 NOTYPE GLOBAL DEFAULT 25 _bss_end__ 20: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_getschedpoli@GLIBC_2.4 (4) 21: 00000000 0 FUNC GLOBAL DEFAULT UND system@GLIBC_2.4 (4) 22: 00010e5d 0 FUNC GLOBAL DEFAULT 13 _start 23: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN10SysResCtor5Sem_PE17T 24: 00000000 0 FUNC GLOBAL DEFAULT UND _Z11DebugPrintfPKcz 25: 00010d04 0 FUNC GLOBAL DEFAULT 11 _init 26: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 27: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_destroy@GLIBC_2.4 (4) 28: 00010fc1 42 FUNC GLOBAL DEFAULT 13 _Z20MonitorProcessThreadP 29: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon11IsNoMemeoryEv 30: 000214e0 0 NOTYPE GLOBAL DEFAULT 25 __bss_start__ 31: 000214d4 0 NOTYPE GLOBAL DEFAULT 24 __data_start 32: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_init@GLIBC_2.4 (4) 33: 000214ec 0 NOTYPE GLOBAL DEFAULT 25 _end 34: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon11InitAppStatEv 35: 000214e0 0 NOTYPE GLOBAL DEFAULT 25 __bss_start 36: 00000000 0 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (5) 37: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon8WatchDogEv 38: 00000000 0 FUNC GLOBAL DEFAULT UND usleep@GLIBC_2.4 (2) 39: 000111b9 64 FUNC GLOBAL DEFAULT 13 __libc_csu_init 40: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr1@GCC_3.5 (6) 41: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_create@GLIBC_2.4 (4) 42: 00010fa9 24 FUNC GLOBAL DEFAULT 13 _Z18VersionCodeDeclarev 43: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN6Daemon14MonitorProces 44: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 45: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_setschedpara@GLIBC_2.4 (4) 46: 00010f3d 108 FUNC GLOBAL DEFAULT 13 SetThreadSchedPolicyRR 47: 000111f9 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini 48: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.4 (2) 49: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 50: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 51: 00000000 0 FUNC GLOBAL DEFAULT UND _ZN10SysResCtor11GetInsta 52: 00010e50 0 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4 (5) Histogram for bucket list length (total of 37 buckets): Length Number % of total Coverage 0 6 ( 16.2%) 1 16 ( 43.2%) 30.8% 2 10 ( 27.0%) 69.2% 3 4 ( 10.8%) 92.3% 4 1 ( 2.7%) 100.0%反汇编,除了偏移地址的差异,文件比较器下也看不出目标文件有什么不同
更进一步测试
- 比较
VMware UBUNTU 18.04 x64及WSL 2.0 Docker UBUNTU 18.04 x64平台下,arm-linux-gnueabihf-4.9.4-2017.01-linaro交叉编译的目标文件,反汇编、arm-linux-gnueabihf-readelf目标文件信息,除了地址偏移,其他完全相同
小结
WSL 2.0 UBUNTU xx.xx环境快速好用,然而特殊情况下,交叉编译会导致某些问题,猜测可能与 MS 对 Linux 平台的兼容改造有关。- 建议发布生产环境下的目标文件,尽量使用 VMware Linux 等已验证的系统平台
版权声明:本文为hylaking原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。