Bug 54983

Summary: ARM gcc creates invalid assembly: bad immediate value for 8-bit offset (1024)
Product: gcc Reporter: Bastian Hecht <hechtb>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P3    
Version: 4.6.3   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: Includes a .config to build the v3.7-rc1 kernel and the --save-temps file

Description Bastian Hecht 2012-10-19 10:38:30 UTC
Created attachment 28488 [details]
Includes a .config to build the v3.7-rc1 kernel and the --save-temps file

The bug appeared on new linux ARM kernel versions and I cite here a kernel maintainer responding to my patch submission:

"Hi, I used to be able to compile MTD stuff for mackerel board with the
defconfig attached, but now it fails with 3.7-rc1 with as error:

/tmp/cc2Nr7AN.s: Error: bad immediate value for 8-bit offset (1024)

It fails for dogc4.c, but if I disable DOCG4, it fails for other drivers
with a similar error.

I've tried (arm) gcc 4.6.3 and the latest Linaro 4.7 build."

In order to reproduce the bug, please get a repository of the kernel and checkout "v3.7-rc1" and use the attached .config. The bug happens when building the modules. I'm sorry but I see no way figuring out all the dependencies of a kernel build to supply a more compact way to test this. I used 

make -j16 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules

and get the error:

/tmp/ccwLMdCy.s: Assembler messages:
/tmp/ccwLMdCy.s: Error: bad immediate value for 8-bit offset (2048)
make[3]: *** [drivers/mtd/nand/docg4.o] Error 1

# arm-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabi/4.6/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.6.3 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include --with-headers=/usr/arm-linux-gnueabi/include --with-libs=/usr/arm-linux-gnueabi/lib
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Best,

 Bastian Hecht
Comment 1 Andrew Pinski 2012-10-19 11:01:13 UTC
I think there might be an issue with some of the inline-asm in asm/io.h:
static inline __attribute__((always_inline)) __attribute__((no_instrument_function)) void __raw_writew(u16 val, volatile void *addr)
{
 asm volatile("strh %1, %0"
       : "+Qo" (*(volatile u16 *)addr)
       : "r" (val));


Also what options are being passed to the gcc?
Comment 2 Bastian Hecht 2012-10-19 11:55:37 UTC
I'm afraid I don't have the knowledge to comment the inline assembly. The command line is:

arm-linux-gnueabi-gcc -Wp,-MD,drivers/mtd/nand/.docg4.o.d  -nostdinc
-isystem /usr/lib/gcc/arm-linux-gnueabi/4.6/include
-I$KERNEL_DIR/arch/arm/include -Iarch/arm/include/generated  -Iinclude
-I$KERNEL_DIR/arch/arm/include/uapi -Iarch/arm/include/generated/uapi
-I$KERNEL_DIR/include/uapi -Iinclude/generated/uapi -include
$KERNEL_DIR/include/linux/kconfig.h -D__KERNEL__ -mlittle-endian
-Iarch/arm/mach-shmobile/include -Wall -Wundef -Wstrict-prototypes
-Wno-trigraphs -fno-strict-aliasing -fno-common
-Werror-implicit-function-declaration -Wno-format-security
-fno-delete-null-pointer-checks -O2 -marm -fno-dwarf2-cfi-asm
-fno-omit-frame-pointer -mapcs -mno-sched-prolog -mabi=aapcs-linux
-mno-thumb-interwork -D__LINUX_ARM_ARCH__=7 -march=armv7-a
-msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector
-Wno-unused-but-set-variable -fno-omit-frame-pointer
-fno-optimize-sibling-calls -Wdeclaration-after-statement
-Wno-pointer-sign -fno-strict-overflow -fconserve-stack  -DMODULE
-D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(docg4)"
-D"KBUILD_MODNAME=KBUILD_STR(docg4)" --save-temps -c -o
drivers/mtd/nand/docg4.o drivers/mtd/nand/docg4.c
Comment 3 Richard Earnshaw 2012-10-19 16:54:41 UTC
The 'o' in "+Qo" is invalid for this instruction.  There is, unfortunately, no way to specify in inline assembly instructions the precise addressing range of strh.

I think your safest bet is to use "Q".
Comment 4 Bastian Hecht 2012-10-20 10:30:28 UTC
Ok I see. Thanks for taking a look at this! I'll check if this is some regression in the tree and either write a patch or post the issue on the ARM mailing list.