Linux kernel 2.6.39 + CodeSourcery 2011.03-41 = Alignment exception

Please note that if you are planning to move to new version of  CodeSourcery 2011.03-41 for ARM GNU/Linux there is an issue with alignment optimisation. I spent a couple of days trying to figure out why 2.6.39 kernel boots if it was compiled with old version of CodeSorcery and it hangs (actually produces unhandled alignment exceptions) after compilation using new CodeSourcery 2011.03. I’m not 100% sure, but it seems that guys from CodeSourcery added “Unaligned access support.” feature which is enabled by default and it leads to alignment exceptions: [ 0.000000] Linux version  2.6.39-rc7  (mgalemin@mgalemin-ThinkPad-R51e)  (gcc version 4.5.2 (Sourcery G++ Lite 2011.03-41)  ) #1 SMP Sun May 15 20:40:04 EST 2011
[ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c53c7f
[ 0.000000] CPU: VIPT nonaliasing data cache, VIPT aliasing instruction cache

[ 0.000000] Machine: OMAP3 Beagle Board
[ 0.000000] bootconsole [earlycon0] enabled
[ 0.000000] Reserving 12582912 bytes SDRAM for VRAM
[ 0.000000] Memory policy: ECC disabled, Data cache writeback
[ 0.000000] OMAP3630 ES1.0 (l2cache iva sgx neon isp 192mhz_clk )
[ 0.000000] SRAM: Mapped pa 0×40200000 to va 0xfe400000 size: 0×10000
[ 0.000000] Clocking rate (Crystal/Core/MPU): 26.0/332/600 MHz
[ 0.000000] Reprogramming SDRC clock to 332000000 Hz
[ 0.000000] PERCPU: Embedded 7 pages/cpu @c0f6e000 s8160 r8192 d12320 u32768

[ 0.000000] Unhandled fault: alignment exception (0×001) at 0xc0501a19
[ 0.000000] Internal error: : 1 [#1] SMP
[ 0.000000] last sysfs file:
[ 0.000000] Modules linked in:
[ 0.000000] CPU: 0 Not tainted (2.6.39-rc7 #1)
[ 0.000000] PC is at pcpu_dump_alloc_info+0xc/0×248
[ 0.000000] LR is at pcpu_setup_first_chunk+0×438/0x71c
[ 0.000000] pc : [<c010dd2c>] lr : [<c001f978>] psr: 200001d3
[ 0.000000] sp : c058fed8 ip : 00000001 fp : 00008000
[ 0.000000] r10: c0f75000 r9 : c0f75060 r8 : c0f75040
[ 0.000000] r7 : c05a467c r6 : c0f6e000 r5 : 00003020 r4 : c0f6b1e0
[ 0.000000] r3 : c0501a19 r2 : 00000002 r1 : c0f6b1e0 r0 : c0501ce0
[ 0.000000] Flags: nzCv IRQs off FIQs off Mode SVC_32 ISA ARM Segment kernel
[ 0.000000] Control: 10c5387f Table: 80004019 DAC: 00000017
[ 0.000000] Process swapper (pid: 0, stack limit = 0xc058e2f8)
[ 0.000000] Stack: (0xc058fed8 to 0xc0590000)

[ 0.000000] fec0: 00001000 c0047e88
[ 0.000000] fee0: 00000000 00000000 00000004 00000000 00000020 00000000 00000000 c0020ec0
[ 0.000000] ff00: 00000000 00000020 bfffffff 00000004 00003020 c0f6b1e0 00003020 c0f6e000
[ 0.000000] ff20: c05a467c c0f75040 c0f75060 c0f75000 00008000 c001f978 c0f6b1e0 00003020
[ 0.000000] ff40: c0f6e000 c05a3988 c0f75020 00000001 c0f6b1ec c0f6b1e0 c0f6c1e0 c0f6e000
[ 0.000000] ff60: c0f76000 c0f6b1f8 c0f6b1e0 c0f6b1ec 00000001 c00202a4 00002000 00003020
[ 0.000000] ff80: 00008000 00000000 000000ae c0f6b1e0 00001000 00007000 00008000 00001000
[ 0.000000] ffa0: 00000000 c060f760 c0034ac4 c0f6b120 c05a8144 80000000 413fc082 00000000
[ 0.000000] ffc0: 00000000 c0020360 c001f4a4 c001f49c c060f760 c0008888 10c53c7f 0000060a
[ 0.000000] ffe0: 80000100 c0034ac4 10c53c7d c05a38dc c0034ac0 8000803c 00000000 00000000

[ 0.000000] [<c010dd2c>] ( pcpu_dump_alloc_info +0xc/0×248) from [<c001f978>] (pcpu_setup_first_chunk+0×438/0x71c)
[ 0.000000] [<c001f978>] (pcpu_setup_first_chunk+0×438/0x71c) from [<c00202a4>] (pcpu_embed_first_chunk+0×648/0x6dc)
[ 0.000000] [<c00202a4>] (pcpu_embed_first_chunk+0×648/0x6dc) from [<c0020360>] (setup_per_cpu_areas+0×28/0xb0)
[ 0.000000] [<c0020360>] (setup_per_cpu_areas+0×28/0xb0) from [<c0008888>] (start_kernel+0xdc/0x2ec)
[ 0.000000] [<c0008888>] (start_kernel+0xdc/0x2ec) from [<8000803c>] (0x8000803c)
[ 0.000000] Code: c0b49838 e59f3220 e92d4ff0 e24dd03c (e5932000)
This particular fault situation can be fixed by fixing size of “empty_str” array in function “pcpu_dump_alloc_info” (file “mm/percpu.c”):

char empty_str[] = “——–”;

Should be replaced with:

char empty_str[16] = “——–”;

From  Getting Started Guide page 38:

Unaligned access support. The compiler now generates more efficient code for accessing packed data structures and for copying small blocks of unaligned data when targeting architectures that permit unaligned word/halfword accesses. This feature can be controlled by the -munaligned-access and -mno-unaligned-access options, and is enabled by default for ARMv6 processors and above, except for ARMv6-M.

So, as a workaround you can compile kernel with additionalEXTRA_CFLAGS=-mno-unaligned-access parameter, for example:

make CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=armEXTRA_CFLAGS=-mno-unaligned-access uImage 

from:http://blog.galemin.com/tag/codesourcery/

你可能感兴趣的:(Linux kernel 2.6.39 + CodeSourcery 2011.03-41 = Alignment exception)