Unity3d IL2CPP 内存对齐错误
[TOC]
unity3d il2cpp安卓包运行异常,出现信号错误signal 7 (SIGBUS), code 1 (BUS_ADRALN)
。
03-26 10:49:24.270 20868 20887 E CRASH : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr ba77601a
03-26 10:49:24.270 20868 20887 E CRASH : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-26 10:49:24.270 20868 20887 E CRASH : Build type 'Release', Scripting Backend 'il2cpp', CPU 'armeabi-v7a'
03-26 10:49:24.270 20868 20887 E CRASH : Build fingerprint: 'Xiaomi/perseus/perseus:9/PKQ1.180729.001/V10.0.12.0.PEECNFH:user/release-keys'
03-26 10:49:24.270 20868 20887 E CRASH : Revision: '0'
03-26 10:49:24.270 20868 20887 E CRASH : pid: 20868, tid: 20887, name: UnityMain >>> com.abc.test <<<
03-26 10:49:24.270 20868 20887 E CRASH : r0 ba776010 r1 ba776000 r2 0000001a r3 00000012
03-26 10:49:24.270 20868 20887 E CRASH : r4 4b0ac5ca r5 ba77601a r6 6f746306 r7 b99e1114
03-26 10:49:24.270 20868 20887 E CRASH : r8 baf50f20 r9 00000009 sl 0000011d fp cc6fdd60
03-26 10:49:24.270 20868 20887 E CRASH : ip 0000011a sp cc6fdd48 lr b5f0747f pc c9e0a41c cpsr cc6fda58
03-26 10:49:24.270 20868 20887 E CRASH :
03-26 10:49:24.270 20868 20887 E CRASH : backtrace:
03-26 10:49:24.359 20868 20887 E CRASH : #00 pc 01ff041c /data/app/com.abc.test-MvkG0JyKHMrwrsDCO2D2Ig==/lib/arm/libil2cpp.so
03-26 10:49:24.359 20868 20887 E CRASH : #01 pc 01feff88 /data/app/com.abc.test-MvkG0JyKHMrwrsDCO2D2Ig==/lib/arm/libil2cpp.so
03-26 10:49:24.359 20868 20887 E CRASH : #02 pc 01ff05dc /data/app/com.abc.test-MvkG0JyKHMrwrsDCO2D2Ig==/lib/arm/libil2cpp.so
03-26 10:49:24.359 20868 20887 E CRASH : #03 pc 01f7b6c4 /data/app/com.abc.test-MvkG0JyKHMrwrsDCO2D2Ig==/lib/arm/libil2cpp.so
03-26 10:49:24.359 20868 20887 E CRASH : #04 pc 0072142c /data/app/com.abc.test-MvkG0JyKHMrwrsDCO2D2Ig==/lib/arm/libil2cpp.so
03-26 10:49:24.359 20868 20887 E CRASH :
03-26 10:49:24.359 20868 20887 E CRASH : memory near r0:
03-26 10:49:24.359 20868 20887 E CRASH : ba775ff0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.359 20868 20887 E CRASH : ba776000 c15bb748 00000000 00000000 00100000 H.[.............
03-26 10:49:24.359 20868 20887 E CRASH : ba776010 1d445957 0a000001 63060101 656b6f74 abc........ctoke
03-26 10:49:24.359 20868 20887 E CRASH : ba776020 00040c6e 00363838 74656e07 65646f4d n...886..netMode
03-26 10:49:24.359 20868 20887 E CRASH : ba776030 00000106 736f0200 7000030c 6e060063 ......os...pc..n
03-26 10:49:24.359 20868 20887 E CRASH : ba776040 65626d75 00010c72 77700300 00040c72 umber.....pwr...
03-26 10:49:24.359 20868 20887 E CRASH : ba776050 00363838 7070610a 73726556 0c6e6f69 886..appVersion.
03-26 10:49:24.360 20868 20887 E CRASH : ba776060 2e310006 00302e30 63636107 6f666e49 ..1.0.0..accInfo
03-26 10:49:24.360 20868 20887 E CRASH : ba776070 0000010c 736f6804 00050c74 656e6f6e .....host...none
03-26 10:49:24.360 20868 20887 E CRASH : ba776080 72610600 64496165 00000106 6f630400 ..areaId......co
03-26 10:49:24.360 20868 20887 E CRASH : ba776090 010c6564 640b0000 63697665 6f635365 de.....deviceSco
03-26 10:49:24.360 20868 20887 E CRASH : ba7760a0 00066572 08000000 69766564 64496563 re......deviceId
03-26 10:49:24.360 20868 20887 E CRASH : ba7760b0 0000010c 64696303 3000020c 68700900 .....cid...0..ph
03-26 10:49:24.360 20868 20887 E CRASH : ba7760c0 4d656e6f 0c65646f 0a000001 65527369 oneMode.....isRe
03-26 10:49:24.360 20868 20887 E CRASH : ba7760d0 74736967 00057265 0c777002 64640021 gister...pw.!.dd
03-26 10:49:24.360 20868 20887 E CRASH : ba7760e0 34306464 39626234 30616432 39393130 dd044bb92da00199
03-26 10:49:24.360 20868 20887 E CRASH :
03-26 10:49:24.360 20868 20887 E CRASH : memory near r1:
03-26 10:49:24.360 20868 20887 E CRASH : ba775fe0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.360 20868 20887 E CRASH : ba775ff0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.360 20868 20887 E CRASH : ba776000 c15bb748 00000000 00000000 00100000 H.[.............
03-26 10:49:24.360 20868 20887 E CRASH : ba776010 1d445957 0a000001 63060101 656b6f74 abc........ctoke
03-26 10:49:24.360 20868 20887 E CRASH : ba776020 00040c6e 00363838 74656e07 65646f4d n...886..netMode
03-26 10:49:24.360 20868 20887 E CRASH : ba776030 00000106 736f0200 7000030c 6e060063 ......os...pc..n
03-26 10:49:24.360 20868 20887 E CRASH : ba776040 65626d75 00010c72 77700300 00040c72 umber.....pwr...
03-26 10:49:24.360 20868 20887 E CRASH : ba776050 00363838 7070610a 73726556 0c6e6f69 886..appVersion.
03-26 10:49:24.360 20868 20887 E CRASH : ba776060 2e310006 00302e30 63636107 6f666e49 ..1.0.0..accInfo
03-26 10:49:24.360 20868 20887 E CRASH : ba776070 0000010c 736f6804 00050c74 656e6f6e .....host...none
03-26 10:49:24.361 20868 20887 E CRASH : ba776080 72610600 64496165 00000106 6f630400 ..areaId......co
03-26 10:49:24.361 20868 20887 E CRASH : ba776090 010c6564 640b0000 63697665 6f635365 de.....deviceSco
03-26 10:49:24.361 20868 20887 E CRASH : ba7760a0 00066572 08000000 69766564 64496563 re......deviceId
03-26 10:49:24.361 20868 20887 E CRASH : ba7760b0 0000010c 64696303 3000020c 68700900 .....cid...0..ph
03-26 10:49:24.361 20868 20887 E CRASH : ba7760c0 4d656e6f 0c65646f 0a000001 65527369 oneMode.....isRe
03-26 10:49:24.361 20868 20887 E CRASH : ba7760d0 74736967 00057265 0c777002 64640021 gister...pw.!.dd
03-26 10:49:24.361 20868 20887 E CRASH :
03-26 10:49:24.361 20868 20887 E CRASH : memory near r4:
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac5a8 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac5b8 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac5c8 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac5d8 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac5e8 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac5f8 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac608 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac618 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac628 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac638 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.361 20868 20887 E CRASH : 4b0ac648 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.362 20868 20887 E CRASH : 4b0ac658 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.362 20868 20887 E CRASH : 4b0ac668 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.362 20868 20887 E CRASH : 4b0ac678 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.362 20868 20887 E CRASH : 4b0ac688 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.362 20868 20887 E CRASH : 4b0ac698 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.362 20868 20887 E CRASH :
03-26 10:49:24.362 20868 20887 E CRASH : memory near r5:
03-26 10:49:24.362 20868 20887 E CRASH : ba775ff8 00000000 00000000 c15bb748 00000000 ........H.[.....
03-26 10:49:24.362 20868 20887 E CRASH : ba776008 00000000 00100000 1d445957 0a000001 ........abc.....
03-26 10:49:24.362 20868 20887 E CRASH : ba776018 63060101 656b6f74 00040c6e 00363838 ...ctoken...886.
03-26 10:49:24.362 20868 20887 E CRASH : ba776028 74656e07 65646f4d 00000106 736f0200 .netMode......os
03-26 10:49:24.362 20868 20887 E CRASH : ba776038 7000030c 6e060063 65626d75 00010c72 ...pc..number...
03-26 10:49:24.362 20868 20887 E CRASH : ba776048 77700300 00040c72 00363838 7070610a ..pwr...886..app
03-26 10:49:24.362 20868 20887 E CRASH : ba776058 73726556 0c6e6f69 2e310006 00302e30 Version...1.0.0.
03-26 10:49:24.362 20868 20887 E CRASH : ba776068 63636107 6f666e49 0000010c 736f6804 .accInfo.....hos
03-26 10:49:24.362 20868 20887 E CRASH : ba776078 00050c74 656e6f6e 72610600 64496165 t...none..areaId
03-26 10:49:24.362 20868 20887 E CRASH : ba776088 00000106 6f630400 010c6564 640b0000 ......code.....d
03-26 10:49:24.362 20868 20887 E CRASH : ba776098 63697665 6f635365 00066572 08000000 eviceScore......
03-26 10:49:24.362 20868 20887 E CRASH : ba7760a8 69766564 64496563 0000010c 64696303 deviceId.....cid
03-26 10:49:24.362 20868 20887 E CRASH : ba7760b8 3000020c 68700900 4d656e6f 0c65646f ...0..phoneMode.
03-26 10:49:24.363 20868 20887 E CRASH : ba7760c8 0a000001 65527369 74736967 00057265 ....isRegister..
03-26 10:49:24.363 20868 20887 E CRASH : ba7760d8 0c777002 64640021 34306464 39626234 .pw.!.dddd044bb9
03-26 10:49:24.363 20868 20887 E CRASH : ba7760e8 30616432 39393130 39353733 36363066 2da001993759f066
03-26 10:49:24.363 20868 20887 E CRASH :
03-26 10:49:24.363 20868 20887 E CRASH : memory near r6:
03-26 10:49:24.363 20868 20887 E CRASH : 6f7462e4 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f7462f4 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746304 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746314 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746324 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746334 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746344 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746354 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746364 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746374 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746384 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f746394 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f7463a4 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.363 20868 20887 E CRASH : 6f7463b4 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : 6f7463c4 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : 6f7463d4 ffffffff ffffffff ffffffff ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH :
03-26 10:49:24.364 20868 20887 E CRASH : memory near r7:
03-26 10:49:24.364 20868 20887 E CRASH : b99e10f4 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1104 0000000a 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1114 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1124 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1134 0000001d 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1144 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1154 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1164 00000013 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1174 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1184 00000000 00000000 00000000 ffffffff ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e1194 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e11a4 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e11b4 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e11c4 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e11d4 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.364 20868 20887 E CRASH : b99e11e4 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.364 20868 20887 E CRASH :
03-26 10:49:24.364 20868 20887 E CRASH : memory near r8:
03-26 10:49:24.365 20868 20887 E CRASH : baf50f00 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.365 20868 20887 E CRASH : baf50f10 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.365 20868 20887 E CRASH : baf50f20 c18e2400 00000000 00000001 bd0c2440 .$..........@$..
03-26 10:49:24.365 20868 20887 E CRASH : baf50f30 bd2b5eb0 bd2b5e88 e9548210 e9548540 .^+..^+...T.@.T.
03-26 10:49:24.365 20868 20887 E CRASH : baf50f40 bd03ce60 0000868d bac60ed8 bcae4480 `............D..
03-26 10:49:24.365 20868 20887 E CRASH : baf50f50 e9548240 00000005 00000003 bac60ed8 @.T.............
03-26 10:49:24.365 20868 20887 E CRASH : baf50f60 0000868d e9547fa0 ffffffff 00000000 ......T.........
03-26 10:49:24.365 20868 20887 E CRASH : baf50f70 00000000 bd0c2280 00000000 00000001 ....."..........
03-26 10:49:24.365 20868 20887 E CRASH : baf50f80 bd0c2740 baf25240 bac5fee0 bac5fea8 @'..@R..........
03-26 10:49:24.365 20868 20887 E CRASH : baf50f90 baf3ec30 00000000 247ea6cc b5f0747f 0.........~$.t..
03-26 10:49:24.365 20868 20887 E CRASH : baf50fa0 bd275060 baee2840 baee2828 00000000 `P'.@(..((......
03-26 10:49:24.365 20868 20887 E CRASH : baf50fb0 baf3aa50 baf25210 baf4bf80 00000000 P....R..........
03-26 10:49:24.365 20868 20887 E CRASH : baf50fc0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.365 20868 20887 E CRASH : baf50fd0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.365 20868 20887 E CRASH : baf50fe0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.365 20868 20887 E CRASH : baf50ff0 00000000 00000000 00000000 00000000 ................
03-26 10:49:24.365 20868 20887 E CRASH :
03-26 10:49:24.365 20868 20887 E CRASH : code around pc:
03-26 10:49:24.365 20868 20887 E CRASH : c9e0a3fc e1a03002 ea000013 e1a05000 e7b56002 .0.......P...`..
03-26 10:49:24.365 20868 20887 E CRASH : c9e0a40c e2822010 e5957004 e0264004 e027700e . ...p...@&..p'.
03-26 10:49:24.365 20868 20887 E CRASH : c9e0a41c e8850090 ea000009 e1a02000 e59d6000 ......... ...`..
03-26 10:49:24.365 20868 20887 E CRASH : c9e0a42c e7b27003 e59d5004 e5924004 e0266007 .p...P...@...`&.
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a43c e0257004 e1c260f0 e2832010 e2833008 .p%..`... ...0..
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a44c e152000c dafffff3 e153000c aa00000e ..R.......S.....
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a45c e0800003 e04c2003 e3a04000 e1a0300d ..... L..@...0..
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a46c e5d07000 e2522001 e7d46003 e0267007 .p... R..`...p&.
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a47c e4c07001 e2847001 e1a06fc7 e0876ea6 .p...p...o...n..
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a48c e3c66007 e0474006 1afffff4 e1a00001 .`...@G.........
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a49c e24bd010 e8bd88f0 e92d4df0 e28db018 ..K......M-.....
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a4ac e24dd008 e1a05000 e59f0220 e1a04003 ..M..P.. ....@..
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a4bc e1a06002 e08f0000 e1a07001 e5d00000 .`.......p......
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a4cc e3500000 1a000006 e59f0204 e79f0000 ..P.............
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a4dc e5900000 ebf1c6b5 e59f01f8 e3a01001 ................
03-26 10:49:24.366 20868 20887 E CRASH : c9e0a4ec e7cf1000 e3540000 0a000002 e6ef0077 ......T.....w...
03-26 10:49:24.366 20868 20887 E CRASH :
03-26 10:49:24.366 20868 20887 E CRASH : code around lr:
03-26 10:49:24.366 20868 20887 E CRASH : b5f0745c b5f1a120 c7527360 00000000 06001531 ...`sR.....1...
03-26 10:49:24.366 20868 20887 E CRASH : b5f0746c 00802096 0001ffff c81c2a38 c9c8f0e0 . ......8*......
03-26 10:49:24.366 20868 20887 E CRASH : b5f0747c c723d06c c18df5c0 ca68dd18 b5f19020 l.#.......h. ...
03-26 10:49:24.366 20868 20887 E CRASH : b5f0748c c7527394 00000000 06001532 00802096 .sR.....2.... ..
03-26 10:49:24.366 20868 20887 E CRASH : b5f0749c 0000ffff c81c2b40 c9cc8744 c723d081 ....@+..D.....#.
03-26 10:49:24.367 20868 20887 E CRASH : b5f074ac c18df5c0 ca68dd18 b5f1a130 c75273c8 ......h.0....sR.
03-26 10:49:24.367 20868 20887 E CRASH : b5f074bc 00000000 06001533 00802096 0001ffff ....3.... ......
03-26 10:49:24.367 20868 20887 E CRASH : b5f074cc c81c2c58 c9cc8744 c723d096 c18df5c0 X,..D.....#.....
03-26 10:49:24.367 20868 20887 E CRASH : b5f074dc ca68dd18 b5f1a140 c75273fc 00000000 ..h.@....sR.....
03-26 10:49:24.367 20868 20887 E CRASH : b5f074ec 06001534 00802096 0001ffff c81c2d70 4.... ......p-..
03-26 10:49:24.367 20868 20887 E CRASH : b5f074fc c9cc8744 c723d0aa c18df5c0 ca68dd18 D.....#.......h.
03-26 10:49:24.367 20868 20887 E CRASH : b5f0750c b5f1a150 c7527430 00000000 06001535 P...0tR.....5...
03-26 10:49:24.367 20868 20887 E CRASH : b5f0751c 00802096 0001ffff c81c2e88 c9cc86e0 . ..............
03-26 10:49:24.367 20868 20887 E CRASH : b5f0752c c723d0c0 c18df5c0 ca68dd18 b53393c0 ..#.......h...3.
03-26 10:49:24.367 20868 20887 E CRASH : b5f0753c c7527464 00000000 06001536 00802096 dtR.....6.... ..
03-26 10:49:24.367 20868 20887 E CRASH : b5f0754c 0002ffff c81c2fb0 c9cc8dd0 c723d0da ...../........#.
03-26 10:49:24.367 20868 20887 E MessageQueue: IdleHandler threw exception
异常代码出现在unity3d c#一处指针操作。为了更快的效率,我使用指针每8个字节进行一次异或运算,代码大概如下:
// do something here
fixed (byte* pData = data)
{
// do something here
while (i + UINT64_SIZE <= end)
{
i64lhs = (ulong*)(pData + i);
*i64lhs ^= key;
i += UINT64_SIZE;
}
// do something here
}
然而unity mono并不会该问题,il2cpp下的android、ios均会出现类似的信号错误signal 7 (SIGBUS), code 1 (BUS_ADRALN)
,实际情况是,i64lhs = (ulong*)(pData + i);
进行了未对齐的地址访问。
以下是一些作者对未对齐的地址访问的理解
某些架构上访问数据时有对齐的要求,比如只能从4字节边界上读取一个4字节的数据类型。IA-32架构没有硬性要求对齐,尽管未对齐的访问降低执行效率。另外一些架构,比如SPARC、m68k,要求对齐访问,否则向当前进程分发SIGBUS信号。1
Win32平台下的微软VC编译器在默认情况下采用如下的对齐规则: 任何基本数据类型T的对齐模数就是T的大小,即sizeof(T)。比如对于double类型(8字节),就要求该类型数据的地址总是8的倍数,而char类型数据(1字节)则可以从任何一个地址开始。Linux下的GCC奉行的是另外一套规则:任何2字节大小(包括单字节吗?)的数据类型(比如short)的对齐模数是2,而其它所有超过2字节的数据类型(比如long,double)都以4为对齐模数。2
根据C标准中的说明:“完整的对象类型需要满足对齐要求,这会限制该类型的对象可能分配的地址。对齐值是由具体实现所定义的一个整数值,表示给定对象所能分配的连续地址之间对应的字节数”。换句话说,这意味着我们必须满足如下条件: V % (alignof(uint64_t)) == 0 同样根据C标准,将指针从某种类型转化为另一种类型,而不遵守这个对齐规则时属于未定义的行为3
对于android x86和x86-64来说并不会有问题,因为intel架构支持非内存访问,但对arm来说是强制要求3。
但目前大多数android是arm架构,程序包含natie code务必注意该问题。
原文:
https://lizijie.github.io/2019/04/13/Unity3d-IL2CPP-%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E9%94%99%E8%AF%AF.html
作者github:
https://github.com/lizijie
</b>