Bug 115153 - [14/15 Regression] Error: bad immediate value for 8-bit offset - armv7ve
Summary: [14/15 Regression] Error: bad immediate value for 8-bit offset - armv7ve
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 14.1.0
: P3 normal
Target Milestone: 14.2
Assignee: Wilco
URL:
Keywords: assemble-failure, build
Depends on:
Blocks:
 
Reported: 2024-05-19 00:12 UTC by rudi
Modified: 2024-08-05 23:14 UTC (History)
6 users (show)

See Also:
Host:
Target: armv7ve-libreelec-linux-gnueabihf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-05-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rudi 2024-05-19 00:12:13 UTC
When compiling libsanitizer or kodi with a target of armv7ve an assembly failure occurs, this failure does not occur the armv7a target (nor on 64bit targets)

Below is the snippet of the failure

/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/.x86_64-linux-gnu/./gcc/xgcc -shared-libgcc -B/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/.x86_64-linux-gnu/./gcc -nostdinc++ -L/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/.x86_64-linux-gnu/armv7ve-libreelec-linux-gnueabihf/libstdc++-v3/src -L/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/.x86_64-linux-gnu/armv7ve-libreelec-linux-gnueabihf/libstdc++-v3/src/.libs -L/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/.x86_64-linux-gnu/armv7ve-libreelec-linux-gnueabihf/libstdc++-v3/libsupc++/.libs -B/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/armv7ve-libreelec-linux-gnueabihf/bin/ -B/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/armv7ve-libreelec-linux-gnueabihf/lib/ -isystem /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/armv7ve-libreelec-linux-gnueabihf/include -isystem /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/armv7ve-libreelec-linux-gnueabihf/sys-include    -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DASAN_HAS_EXCEPTIONS=1 -DASAN_NEEDS_SEGV=1 -DCAN_SANITIZE_UB=0 -DASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION=0 -DHAVE_AS_SYM_ASSIGN=1  -I. -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/libsanitizer/asan -I..  -I /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/libsanitizer/include -I /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/libsanitizer  -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros -fno-ipa-icf -I../../libstdc++-v3/include     -I../../libstdc++-v3/include/armv7ve-libreelec-linux-gnueabihf     -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/libsanitizer/../libstdc++-v3/libsupc++ -std=gnu++14  -g -O2 -D_GNU_SOURCE -MT asan_preinit.o -MD -MP -MF .deps/asan_preinit.Tpo -c -o asan_preinit.o /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/libsanitizer/asan/asan_preinit.cpp
mv -f .deps/asan_descriptions.Tpo .deps/asan_descriptions.Plo
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/libsanitizer/asan/asan_thread.h:192:8: warning: ISO C++ forbids flexible array member 'start_data_' [-Wpedantic]
  192 |   char start_data_[];
      |        ^~~~~~~~~~~
mv -f .deps/asan_interceptors_vfork.Tpo .deps/asan_interceptors_vfork.Plo
mv -f .deps/asan_suppressions.Tpo .deps/asan_suppressions.Plo
mv -f .deps/asan_preinit.Tpo .deps/asan_preinit.Po
cp asan_preinit.o libasan_preinit.o
mv -f .deps/asan_errors.Tpo .deps/asan_errors.Plo
/tmp/ccorxrMD.s: Assembler messages:
/tmp/ccorxrMD.s:523: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:682: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:1122: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:1460: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:2140: Error: bad immediate value for 8-bit offset (568)
/tmp/ccorxrMD.s:2293: Error: bad immediate value for 8-bit offset (568)
/tmp/ccorxrMD.s:2550: Error: bad immediate value for 8-bit offset (568)
/tmp/ccorxrMD.s:2726: Error: bad immediate value for 8-bit offset (568)
/tmp/ccorxrMD.s:2888: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:3077: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:3352: Error: bad immediate value for 8-bit offset (272)
/tmp/ccorxrMD.s:3493: Error: bad immediate value for 8-bit offset (272)
make[4]: *** [Makefile:661: asan_stats.lo] Error 1
Comment 1 Andrew Pinski 2024-05-19 00:15:42 UTC
What is your exact configure command line?
Comment 2 Andrew Pinski 2024-05-19 00:16:44 UTC
Also can you attach the preprocessed source? and add -v to gcc command line to provide the exact command line which is causing the error?
Comment 3 rudi 2024-05-19 00:21:34 UTC
(In reply to Andrew Pinski from comment #1)
> What is your exact configure command line?

Executing (host): /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/gcc-14.1.0/configure --host=x86_64-linux-gnu --build=x86_64-linux-gnu --prefix=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain --bindir=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/bin --sbindir=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/sbin --sysconfdir=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/etc --libexecdir=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/lib --localstatedir=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/var --disable-static --enable-shared --target=armv7ve-libreelec-linux-gnueabihf --with-sysroot=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/armv7ve-libreelec-linux-gnueabihf/sysroot --with-gmp=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain --with-mpfr=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain --with-mpc=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain --with-zstd=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain --with-gnu-as --with-gnu-ld --enable-plugin --enable-lto --enable-gold --enable-ld=default --with-linker-hash-style=gnu --disable-multilib --disable-nls --enable-checking=release --without-ppl --without-cloog --disable-libada --disable-libmudflap --disable-libitm --disable-libquadmath --disable-libgomp --disable-libmpx --disable-libssp --enable-__cxa_atexit --enable-languages=c,c++ --enable-libatomic --enable-decimal-float --enable-tls --enable-shared --disable-static --enable-long-long --enable-threads=posix --disable-libstdcxx-pch --enable-libstdcxx-time --enable-clocale=gnu --with-abi=aapcs-linux --with-arch=armv7ve --with-float=hard --with-fpu=neon-vfpv4
Comment 4 rudi 2024-05-19 00:36:48 UTC
We have also see the same failure building kodi (vpeter4 did the investigation) 
The difference between gcc13 and 14 is

gcc-13, ok
	add	r0, r0, #384
	ldrd	r2, r3, [r0]

gcc-14, not ok
	dmb	ish
	ldrd	r2, r3, [r0, #384]

The kodi issue is at - https://github.com/xbmc/xbmc/issues/25221
Comment 5 rudi 2024-05-19 00:40:03 UTC
(In reply to rudi from comment #4)
> We have also see the same failure building kodi (vpeter4 did the
> investigation) 
> The difference between gcc13 and 14 is
> 
> gcc-13, ok
> 	add	r0, r0, #384
> 	ldrd	r2, r3, [r0]
> 
> gcc-14, not ok
> 	dmb	ish
> 	ldrd	r2, r3, [r0, #384]
> 
> The kodi issue is at - https://github.com/xbmc/xbmc/issues/25221

This was when we built a working gcc (we compiled it without libsanitizer)
Comment 6 Andrew Pinski 2024-05-19 00:45:31 UTC
I suspect r14-4365-g0731889c026bfe is the cause.

```
 (define_insn "arm_atomic_loaddi2_ldrd"
   [(set (match_operand:DI 0 "register_operand" "=r")
        (unspec_volatile:DI
-         [(match_operand:DI 1 "arm_sync_memory_operand" "Q")]
+         [(match_operand:DI 1 "memory_operand" "m")]
            VUNSPEC_LDRD_ATOMIC))]
   "ARM_DOUBLEWORD_ALIGN && TARGET_HAVE_LPAE"
-  "ldrd%?\t%0, %H0, %C1"
-  [(set_attr "predicable" "yes")])
+  "ldrd\t%0, %H0, %1"
+)
```

Most likely that should have been `ldrd_strd_offset_operand/Do` . There might be other places in that patch which made the same mistake too.
Comment 7 rudi 2024-05-19 01:08:32 UTC
(In reply to Andrew Pinski from comment #6)
> I suspect r14-4365-g0731889c026bfe is the cause.
> 
> ```
>  (define_insn "arm_atomic_loaddi2_ldrd"
>    [(set (match_operand:DI 0 "register_operand" "=r")
>         (unspec_volatile:DI
> -         [(match_operand:DI 1 "arm_sync_memory_operand" "Q")]
> +         [(match_operand:DI 1 "memory_operand" "m")]
>             VUNSPEC_LDRD_ATOMIC))]
>    "ARM_DOUBLEWORD_ALIGN && TARGET_HAVE_LPAE"
> -  "ldrd%?\t%0, %H0, %C1"
> -  [(set_attr "predicable" "yes")])
> +  "ldrd\t%0, %H0, %1"
> +)
> ```
> 
> Most likely that should have been `ldrd_strd_offset_operand/Do` . There
> might be other places in that patch which made the same mistake too.

I can confirm that reverting https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=0731889c026bfe;hp=bada3c27d855430af736de51439ce275cffda754 allows for the successful compile of both libsanitizer and kodi.
Comment 8 Wilco 2024-05-20 12:03:43 UTC
Confirmed. Small example:

long long f(long long *p)
{
   return __atomic_load_n (p+32, __ATOMIC_RELAXED);
}

It only fails on ARM and if the offset is between 256 and 1024. This is a latent bug: arm_legitimate_index_p has an explicit check that disallows anything over 256, but an earlier check for VALID_NEON_DREG_MODE oddly enough allows DImode and a larger range. Moving the Neon check after LDRD check fixes this.

Note using ldrd_strd_offset_operand/Do should also work, but the existing code for 'm' is supposed to handle this correctly.
Comment 9 GCC Commits 2024-07-05 17:02:26 UTC
The master branch has been updated by Wilco Dijkstra <wilco@gcc.gnu.org>:

https://gcc.gnu.org/g:44e5ecfd261afe72aa04eba4bf1a9ec782579cab

commit r15-1865-g44e5ecfd261afe72aa04eba4bf1a9ec782579cab
Author: Wilco Dijkstra <wilco.dijkstra@arm.com>
Date:   Fri Jul 5 17:31:25 2024 +0100

    Arm: Fix ldrd offset range [PR115153]
    
    The valid offset range of LDRD in arm_legitimate_index_p is increased to
    -1024..1020 if NEON is enabled since VALID_NEON_DREG_MODE includes DImode.
    Fix this by moving the LDRD check earlier.
    
    gcc:
            PR target/115153
            * config/arm/arm.cc (arm_legitimate_index_p): Move LDRD case before
            NEON.
            (thumb2_legitimate_index_p): Update comments.
            (output_move_neon): Use DFmode for vldr/vstr and non-checking
            adjust_address.
    
    gcc/testsuite:
            PR target/115153
            * gcc.target/arm/pr115153.c: Add new test.
            * lib/target-supports.exp: Add arm_arch_v7ve_neon target support.
Comment 10 GCC Commits 2024-07-09 11:40:12 UTC
The releases/gcc-14 branch has been updated by Wilco Dijkstra <wilco@gcc.gnu.org>:

https://gcc.gnu.org/g:83332e3f808b146ca06dbc6a91d15bd3e5650658

commit r14-10398-g83332e3f808b146ca06dbc6a91d15bd3e5650658
Author: Wilco Dijkstra <wilco.dijkstra@arm.com>
Date:   Fri Jul 5 17:31:25 2024 +0100

    Arm: Fix ldrd offset range [PR115153]
    
    The valid offset range of LDRD in arm_legitimate_index_p is increased to
    -1024..1020 if NEON is enabled since VALID_NEON_DREG_MODE includes DImode.
    Fix this by moving the LDRD check earlier.
    
    gcc:
            PR target/115153
            * config/arm/arm.cc (arm_legitimate_index_p): Move LDRD case before
            NEON.
            (thumb2_legitimate_index_p): Update comments.
            (output_move_neon): Use DFmode for vldr/vstr and non-checking
            adjust_address.
    
    gcc/testsuite:
            PR target/115153
            * gcc.target/arm/pr115153.c: Add new test.
            * lib/target-supports.exp: Add arm_arch_v7ve_neon target support.
    
    (cherry picked from commit 44e5ecfd261afe72aa04eba4bf1a9ec782579cab)
Comment 11 Wilco 2024-07-09 11:58:10 UTC
Fixed on trunk and GCC14.