disk: add -mno-unaligned-access to CFLAGS
PATCH 1/1 disk: add -mno-unaligned-access to CFLAGS
Many on-disk structures used in the directory are accessed in a non aligned manner. gcc => 4.7 (and gcc-4.6 from Linaro) switched to -munaligned-access on default causing exceptions on ARM. The easiest way to fix this is to force no-unaligned-access in this (non speed critical) directory.
--- disk/Makefile | 1 + 1 file changed, 1 insertion(+)
disk/Makefile +1 -0
@@ -24,6 +24,7 @@ include $(TOPDIR)/config.mk #CFLAGS += -DET_DEBUG -DDEBUG +CFLAGS += -mno-unaligned-access LIB = $(obj)libdisk.o
Signature · 1 line
1.7.9.5
PATCH 1/1 disk: add -mno-unaligned-access to CFLAGS
Hi Marc,
Quoted 16 lines · Marc Dietrich
Many on-disk structures used in the directory are accessed in a non aligned manner. gcc => 4.7 (and gcc-4.6 from Linaro) switched to -munaligned-access on default causing exceptions on ARM. The easiest way to fix this is to force no-unaligned-access in this (non speed critical) directory.
Signed-off-by Marc Dietrich <[email protected]>--- disk/Makefile | 1 + 1 file changed, 1 insertion(+)disk/Makefile +0
-0
disk/Makefile line 29
Quoted 6 lines
disk/Makefile +1
-0@@ -24,6 +24,7 @@ include $(TOPDIR)/config.mk #CFLAGS += -DET_DEBUG -DDEBUG +CFLAGS += -mno-unaligned-access LIB = $(obj)libdisk.o
Which fields, which structures, which files are affected by the unalignment issue?
Amicalement,
Signature · 1 line
Albert.
PATCH 1/1 disk: add -mno-unaligned-access to CFLAGS
Hi Albert,
Quoted 22 lines · On Thursday 28 March 2013 21:42:13 Albert ARIBAUD wrote:
Quoted 20 lines · Marc Dietrich
Many on-disk structures used in the directory are accessed in a non aligned manner. gcc => 4.7 (and gcc-4.6 from Linaro) switched to -munaligned-access on default causing exceptions on ARM. The easiest way to fix this is to force no-unaligned-access in this (non speed critical) directory.
Signed-off-by Marc Dietrich <[email protected]>---
disk/Makefile | 1 + 1 file changed, 1 insertion(+)disk/Makefile +0
-0@@ -24,6 +24,7 @@ include $(TOPDIR)/config.mk
Quoted 8 lines
Quoted 5 lines
disk/Makefile +1
-0#CFLAGS += -DET_DEBUG -DDEBUG +CFLAGS += -mno-unaligned-accessLIB = $(obj)libdisk.o
Which fields, which structures, which files are affected by the unalignment issue?
in my test case, it is the start sector of a partition (check include/part_efi.h). disk/part_efi.c reads the legacy mbr (to an aligned buffer) which has a partition structure on offset 440+4+2 (<- not aligned to 4 byte boundary) and inside this a 32 bit field start_sect (aligned to 4 byte boundary). Reading this field (and also the next, nr_sects) will cause an exception. Same is for part_dos, but there we still use le32_to_int which reads byte by byte. I didn't checked others.
Marc
PATCH 1/1 disk: add -mno-unaligned-access to CFLAGS
Hi Marc,
Quoted 34 lines · Marc Dietrich
Hi Albert,
Quoted 22 lines · On Thursday 28 March 2013 21:42:13 Albert ARIBAUD wrote:
Quoted 20 lines · Marc Dietrich
Many on-disk structures used in the directory are accessed in a non aligned manner. gcc => 4.7 (and gcc-4.6 from Linaro) switched to -munaligned-access on default causing exceptions on ARM. The easiest way to fix this is to force no-unaligned-access in this (non speed critical) directory.
Signed-off-by Marc Dietrich <[email protected]>---
disk/Makefile | 1 + 1 file changed, 1 insertion(+)disk/Makefile +0
-0@@ -24,6 +24,7 @@ include $(TOPDIR)/config.mkQuoted 8 lines
Quoted 5 lines
disk/Makefile +1
-0#CFLAGS += -DET_DEBUG -DDEBUG +CFLAGS += -mno-unaligned-accessLIB = $(obj)libdisk.o
Which fields, which structures, which files are affected by the unalignment issue?
Quoted 7 lines
in my test case, it is the start sector of a partition (check
include/part_efi.h).disk/part_efi.creads the legacy mbr (to an aligned buffer) which has a partition structure on offset 440+4+2 (<- not aligned to 4 byte boundary) and inside this a 32 bit fieldstart_sect(aligned to 4 byte boundary). Reading this field (and also the next,nr_sects) will cause an exception. Same is forpart_dos, but there we still usele32_to_intwhich reads byte by byte. I didn't checked others.
Thanks for clarifying.
Considering this is about a very small number of reads, I strongly prefer that these reads be done through the get_unaligned(&field) macro defined in e.g. arch/arm/include/asm/unaligned.h, even at the slightly added cost of decomposing the reads into 8-bit accesses.
Doing so solves the issue at hand while still allowing the rest of the code to detect cases where unalignment stems from error conditions, e.g. bad pointers or erroneous changes in structures, etc.
Quoted 1 line
Marc
Amicalement,
Signature · 1 line
Albert.
PATCH 1/1 disk: add -mno-unaligned-access to CFLAGS
Albert,
Quoted 14 lines · On Friday 29 March 2013 08:00:54 Albert ARIBAUD wrote:
Quoted 5 lines · Marc Dietrich
[ ... ]
Quoted 2 lines · On Thursday 28 March 2013 21:42:13 Albert ARIBAUD wrote:
Which fields, which structures, which files are affected by the unalignment issue?
Quoted 7 lines
in my test case, it is the start sector of a partition (check
include/part_efi.h).disk/part_efi.creads the legacy mbr (to an aligned buffer) which has a partition structure on offset 440+4+2 (<- not aligned to 4 byte boundary) and inside this a 32 bit fieldstart_sect(aligned to 4 byte boundary). Reading this field (and also the next,nr_sects) will cause an exception. Same is forpart_dos, but there we still usele32_to_intwhich reads byte by byte. I didn't checked others.
Quoted 6 lines
Thanks for clarifying.
Considering this is about a very small number of reads, I strongly prefer that these reads be done through the
get_unaligned(&field)macro defined in e.g.arch/arm/include/asm/unaligned.h, even at the slightly added cost of decomposing the reads into 8-bit accesses.
ok, this is what I was actually looking for :-) I've sent a new patch.
Marc