public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/97143] New: aarch64-none-elf Code generated for array after another array within a global structure marked volatile is broken.
@ 2020-09-21 11:01 simon.willcocks at gmx dot de
  2020-09-21 14:44 ` [Bug target/97143] " simon.willcocks at gmx dot de
  2020-09-21 16:10 ` simon.willcocks at gmx dot de
  0 siblings, 2 replies; 3+ messages in thread
From: simon.willcocks at gmx dot de @ 2020-09-21 11:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97143

            Bug ID: 97143
           Summary: aarch64-none-elf Code generated for array after
                    another array within a global structure marked
                    volatile is broken.
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon.willcocks at gmx dot de
  Target Milestone: ---

Using built-in specs.
COLLECT_GCC=aarch64-none-elf-gcc
COLLECT_LTO_WRAPPER=/media/simon/b4ea8e46-fe87-4ddd-9e94-506c37005ac5/IsambardOS/IsambardOS/cross-compiler64-8.2/bin/../libexec/gcc/aarch64-none-elf/8.2.0/lto-wrapper
Target: aarch64-none-elf
Configured with: gcc-8.2.0/configure --prefix=/home/simon/cross-compiler64
--target=aarch64-none-elf --disable-libstdcxx --disable-threads
--disable-multilib --disable-nls --disable-libssp --disable-bootstrap
--enable-languages=c : (reconfigured) gcc-8.2.0/configure
--prefix=/home/simon/cross-compiler64 --target=aarch64-none-elf
--disable-libstdcxx --disable-threads --disable-multilib --disable-nls
--disable-libssp --disable-bootstrap --enable-languages=c CFLAGS='-g -O2'
Thread model: single
gcc version 8.2.0 (GCC) 

Remove array_not_at_start, or make the number of elements not a multiple of 4,
or remove the volatile keyword, and the problem disappears.

The generated code adds the number of elements in the first array to the index,
before multiplying the sum by 4 (x0, lsl #2), instead of just the index.

Taking the address of the array, then accessing the element works as expected.

aarch64-none-elf-gcc gcc-bug.c -c -Os (problem is idependent of optimisation
level)

Code:
extern struct {
    struct {
      unsigned int array_not_at_start[0x88];
      unsigned int Core_IRQ_Source[4];
    } QA7;
} volatile device_pages;

unsigned int this_function_is_broken( unsigned int i )
{
  return device_pages.QA7.Core_IRQ_Source[i];
}

unsigned int this_function_works( unsigned int i )
{
  unsigned int volatile *p = device_pages.QA7.Core_IRQ_Source;
  return p[i];
}

Annotated objdump:
0000000000000000 <this_function_is_broken>:
   0:   2a0003e0        mov     w0, w0
   4:   90000001        adrp    x1, 0 <device_pages>
                        4: R_AARCH64_ADR_PREL_PG_HI21   device_pages
   8:   91022000        add     x0, x0, #0x88               <<<< Elements in
1st array
   c:   91000021        add     x1, x1, #0x0
                        c: R_AARCH64_ADD_ABS_LO12_NC    device_pages
  10:   b8607820        ldr     w0, [x1, x0, lsl #2]        <<<< x1 + (index +
elements) * 4
  14:   d65f03c0        ret

0000000000000018 <this_function_works>:
  18:   d37e7c00        ubfiz   x0, x0, #2, #32
  1c:   90000001        adrp    x1, 0 <device_pages>
                        1c: R_AARCH64_ADR_PREL_PG_HI21  device_pages+0x220
  20:   91000021        add     x1, x1, #0x0
                        20: R_AARCH64_ADD_ABS_LO12_NC   device_pages+0x220
  24:   b8616800        ldr     w0, [x0, x1]
  28:   d65f03c0        ret

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/97143] aarch64-none-elf Code generated for array after another array within a global structure marked volatile is broken.
  2020-09-21 11:01 [Bug target/97143] New: aarch64-none-elf Code generated for array after another array within a global structure marked volatile is broken simon.willcocks at gmx dot de
@ 2020-09-21 14:44 ` simon.willcocks at gmx dot de
  2020-09-21 16:10 ` simon.willcocks at gmx dot de
  1 sibling, 0 replies; 3+ messages in thread
From: simon.willcocks at gmx dot de @ 2020-09-21 14:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97143

Simon Willcocks <simon.willcocks at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|aarch64-elf                 |aarch64-elf, arm-eabi

--- Comment #1 from Simon Willcocks <simon.willcocks at gmx dot de> ---
The same bug is present in 8.4 aarch64-elf AND arm-none-eabi 6.3.1

$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/6.3.1/lto-wrapper
Target: arm-none-eabi
Configured with: ../src/configure --build=x86_64-linux-gnu --prefix=/usr
--includedir='/usr/lib/include' --mandir='/usr/lib/share/man'
--infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var
--disable-silent-rules --libdir='/usr/lib/lib/x86_64-linux-gnu'
--libexecdir='/usr/lib/lib/x86_64-linux-gnu' --disable-maintainer-mode
--disable-dependency-tracking --mandir=/usr/share/man
--enable-languages=c,c++,lto --enable-multilib --disable-decimal-float
--disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath
--disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared
--disable-threads --disable-tls --build=x86_64-linux-gnu --target=arm-none-eabi
--with-system-zlib --with-gnu-as --with-gnu-ld
--with-pkgversion=15:6.3.1+svn253039-1build1 --without-included-gettext
--prefix=/usr/lib --infodir=/usr/share/doc/gcc-arm-none-eabi/info
--htmldir=/usr/share/doc/gcc-arm-none-eabi/html
--pdfdir=/usr/share/doc/gcc-arm-none-eabi/pdf --bindir=/usr/bin
--libexecdir=/usr/lib --libdir=/usr/lib --disable-libstdc++-v3
--host=x86_64-linux-gnu --with-headers=no --without-newlib
--with-multilib-list=rmprofile CFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2'
CXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' FCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' FFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' GCJFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -Wl,-z,relro'
OBJCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' OBJCXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-arm-none-eabi-iopiMw/gcc-arm-none-eabi-6.3.1+svn253039=.
-fstack-protector-strong' INHIBIT_LIBC_CFLAGS=-DUSE_TM_CLONE_REGISTRY=0
AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as
LD_FOR_TARGET=arm-none-eabi-ld NM_FOR_TARGET=arm-none-eabi-nm
OBJDUMP_FOR_TARGET=arm-none-eabi-objdump RANLIB_FOR_TARGET=arm-none-eabi-ranlib
READELF_FOR_TARGET=arm-none-eabi-readelf STRIP_FOR_TARGET=arm-none-eabi-strip
Thread model: single
gcc version 6.3.1 20170620 (15:6.3.1+svn253039-1build1) 


00000000 <this_function_is_broken>:
   0:   e59f3008        ldr     r3, [pc, #8]    ; 10
<this_function_is_broken+0x10>
   4:   e2800088        add     r0, r0, #136    ; 0x88
   8:   e7930100        ldr     r0, [r3, r0, lsl #2]
   c:   e12fff1e        bx      lr
                        c: R_ARM_V4BX   *ABS*
  10:   00000000        andeq   r0, r0, r0
                        10: R_ARM_ABS32 device_pages

00000014 <this_function_works>:
  14:   e59f3004        ldr     r3, [pc, #4]    ; 20 <this_function_works+0xc>
  18:   e7930100        ldr     r0, [r3, r0, lsl #2]
  1c:   e12fff1e        bx      lr
                        1c: R_ARM_V4BX  *ABS*
  20:   00000220        andeq   r0, r0, r0, lsr #4
                        20: R_ARM_ABS32 device_pages

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/97143] aarch64-none-elf Code generated for array after another array within a global structure marked volatile is broken.
  2020-09-21 11:01 [Bug target/97143] New: aarch64-none-elf Code generated for array after another array within a global structure marked volatile is broken simon.willcocks at gmx dot de
  2020-09-21 14:44 ` [Bug target/97143] " simon.willcocks at gmx dot de
@ 2020-09-21 16:10 ` simon.willcocks at gmx dot de
  1 sibling, 0 replies; 3+ messages in thread
From: simon.willcocks at gmx dot de @ 2020-09-21 16:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97143

Simon Willcocks <simon.willcocks at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Simon Willcocks <simon.willcocks at gmx dot de> ---
Checking the x86 code, as well, I realise that I was wrong, it's not a bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-21 16:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 11:01 [Bug target/97143] New: aarch64-none-elf Code generated for array after another array within a global structure marked volatile is broken simon.willcocks at gmx dot de
2020-09-21 14:44 ` [Bug target/97143] " simon.willcocks at gmx dot de
2020-09-21 16:10 ` simon.willcocks at gmx dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).