From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9E5D2385275B; Tue, 14 Jun 2022 19:21:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E5D2385275B From: "gjimenez at teldat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105981] New: Wrong code generated when compiling for arm cortex-a72 in AARCH32 with -mbig-endian Date: Tue, 14 Jun 2022 19:21:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gjimenez at teldat dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jun 2022 19:21:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105981 Bug ID: 105981 Summary: Wrong code generated when compiling for arm cortex-a72 in AARCH32 with -mbig-endian Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gjimenez at teldat dot com Target Milestone: --- Created attachment 53137 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53137&action=3Dedit files with the source and results for cortex-a72 and cortex-a53 When compiling a file("test.c") with a simple function like this: void test(char *buf) { __builtin_strcpy(buf, "abcd1234"); } With this: ../x-tools/armeb-none-eabi/bin/armeb-none-eabi-gcc -c -Wall -Wextra -O3 -mbig-endian -ffreestanding -fbuiltin -nostdinc -save-temps -mcpu=3Dcortex-= a72 test.c -o test.a72 The code generated is: .LC0: .ascii "abcd1234\000" .text .align 2 .global test .syntax unified .arm .type test, %function test: @ args =3D 0, pretend =3D 0, frame =3D 0 @ frame_needed =3D 0, uses_anonymous_args =3D 0 @ link register save eliminated. movw r3, #:lower16:.LC0 movt r3, #:upper16:.LC0 strd r4, [sp, #-8]! ldrd r4, [r3] ldrb r3, [r3, #8] @ zero_extendqisi2 str r5, [r0] @ unaligned str r4, [r0, #4] @ unaligned ldrd r4, [sp] add sp, sp, #8 strb r3, [r0, #8] bx lr String read: In "ldrd r4, [r3]" It reads the string "abcd1234" into r4 and r5. (I am skipping the null string terminator. It is written ok). Buffer fill: Then, it writes r5 into the start of the buffer "str r5, [r0]" And then r4 in the offset 4 of the buffer "str r4, [r0, #4]". The result is that we get the buffer with the string 32bits-swapped "1234ab= cd". *** WRONG RESULT *** But, if we compile the same file with -mcpu=3Dcortex-a53 it works fine: .LC0: .ascii "abcd1234\000" .text .align 2 .global test .syntax unified .arm .type test, %function test: @ args =3D 0, pretend =3D 0, frame =3D 0 @ frame_needed =3D 0, uses_anonymous_args =3D 0 @ link register save eliminated. movw r3, #:lower16:.LC0 movt r3, #:upper16:.LC0 mov r2, r0 ldmia r3!, {r0, r1} str r0, [r2] @ unaligned str r1, [r2, #4] @ unaligned ldrb r3, [r3] @ zero_extendqisi2 strb r3, [r2, #8] bx lr String read: ldmia r3!, {r0, r1} Buffer fill: str r0, [r2] @ unaligned str r1, [r2, #4] @ unaligned *** CORRECT ORDER *** The gcc release: git log -1 commit 1ea978e3066ac565a1ec28a96a4d61eaf38e2726 (HEAD, tag: releases/gcc-12.1.0) Author: Jakub Jelinek Date: Fri May 6 07:07:53 2022 +0000 Update ChangeLog and version files for release git remote -v origin git://gcc.gnu.org/git/gcc.git (fetch) origin git://gcc.gnu.org/git/gcc.git (push) The output when I add the "-v" option: ../x-tools/armeb-none-eabi/bin/armeb-none-eabi-gcc -v -c -Wall -Wextra -O3 -mbig-endian -ffreestanding -fbuiltin -nostdinc -save-temps -mcpu=3Dcortex-= a72 test.c -o test.a72 Using built-in specs. COLLECT_GCC=3D../x-tools/armeb-none-eabi/bin/armeb-none-eabi-gcc Target: armeb-none-eabi Configured with: /home/gjimenez/gcc/crosstool-ng/.build/armeb-none-eabi/src/gcc/configure --build=3Dx86_64-build_pc-linux-gnu --host=3Dx86_64-build_pc-linux-gnu --target=3Darmeb-none-eabi --prefix=3D/home/gjimenez/x-tools/armeb-none-eabi --exec_prefix=3D/home/gjimenez/x-tools/armeb-none-eabi --with-local-prefix=3D/home/gjimenez/x-tools/armeb-none-eabi/armeb-none-eabi --with-headers=3D/home/gjimenez/x-tools/armeb-none-eabi/armeb-none-eabi/inc= lude --with-newlib --enable-threads=3Dno --disable-shared --with-pkgversion=3D'crosstool-NG 1.25.0.36_a3e3d73' --enable-__cxa_atexit --disable-libgomp --disable-libmudflap --disable-libmpx --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libstdcxx-ver= bose --with-gmp=3D/home/gjimenez/gcc/crosstool-ng/.build/armeb-none-eabi/buildto= ols --with-mpfr=3D/home/gjimenez/gcc/crosstool-ng/.build/armeb-none-eabi/buildt= ools --with-mpc=3D/home/gjimenez/gcc/crosstool-ng/.build/armeb-none-eabi/buildto= ols --with-isl=3D/home/gjimenez/gcc/crosstool-ng/.build/armeb-none-eabi/buildto= ols --disable-lto --enable-target-optspace --disable-nls --enable-multiarch --with-multilib-list=3D'rmprofile aprofile' --enable-languages=3Dc,c++ Thread model: single Supported LTO compression algorithms: zlib gcc version 12.1.0 (crosstool-NG 1.25.0.36_a3e3d73) COLLECT_GCC_OPTIONS=3D'-v' '-c' '-Wall' '-Wextra' '-O3' '-mbig-endian' '-ffreestanding' '-fbuiltin' '-nostdinc' '-save-temps' '-mcpu=3Dcortex-a72'= '-o' 'test.a72' '-mfloat-abi=3Dsoft' '-marm' '-mlibarch=3Darmv8-a+crc' '-march=3Darmv8-a+crc' /home/gjimenez/x-tools/armeb-none-eabi/libexec/gcc/armeb-none-eabi/12.1.0/= cc1 -E -quiet -nostdinc -v -imultilib thumb/v8-a/nofp -D__USES_INITFINI__ test.c -mbig-endian -mcpu=3Dcortex-a72 -mfloat-abi=3Dsoft -marm -mlibarch=3Darmv8-= a+crc -march=3Darmv8-a+crc -Wall -Wextra -ffreestanding -fbuiltin -O3 -fpch-prepr= ocess -o test.i #include "..." search starts here: #include <...> search starts here: End of search list. COLLECT_GCC_OPTIONS=3D'-v' '-c' '-Wall' '-Wextra' '-O3' '-mbig-endian' '-ffreestanding' '-fbuiltin' '-nostdinc' '-save-temps' '-mcpu=3Dcortex-a72'= '-o' 'test.a72' '-mfloat-abi=3Dsoft' '-marm' '-mlibarch=3Darmv8-a+crc' '-march=3Darmv8-a+crc' /home/gjimenez/x-tools/armeb-none-eabi/libexec/gcc/armeb-none-eabi/12.1.0/= cc1 -fpreprocessed test.i -quiet -dumpbase test.c -dumpbase-ext .c -mbig-endian -mcpu=3Dcortex-a72 -mfloat-abi=3Dsoft -marm -mlibarch=3Darmv8-a+crc -march=3Darmv8-a+crc -O3 -Wall -Wextra -version -ffreestanding -fbuiltin -o test.s GNU C17 (crosstool-NG 1.25.0.36_a3e3d73) version 12.1.0 (armeb-none-eabi) compiled by GNU C version 9.4.0, GMP version 6.2.1, MPFR version 4.= 1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 GNU C17 (crosstool-NG 1.25.0.36_a3e3d73) version 12.1.0 (armeb-none-eabi) compiled by GNU C version 9.4.0, GMP version 6.2.1, MPFR version 4.= 1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 Compiler executable checksum: 3261fde4c69fe46364115246804cccd4 COLLECT_GCC_OPTIONS=3D'-v' '-c' '-Wall' '-Wextra' '-O3' '-mbig-endian' '-ffreestanding' '-fbuiltin' '-nostdinc' '-save-temps' '-mcpu=3Dcortex-a72'= '-o' 'test.a72' '-mfloat-abi=3Dsoft' '-marm' '-mlibarch=3Darmv8-a+crc' '-march=3Darmv8-a+crc' /home/gjimenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-eabi/12.1.0/../..= /../../armeb-none-eabi/bin/as -EB -march=3Darmv8-a+crc -mfloat-abi=3Dsoft -meabi=3D5 -o test.a72 test.s COMPILER_PATH=3D/home/gjimenez/x-tools/armeb-none-eabi/libexec/gcc/armeb-no= ne-eabi/12.1.0/:/home/gjimenez/x-tools/armeb-none-eabi/libexec/gcc/armeb-no= ne-eabi/12.1.0/:/home/gjimenez/x-tools/armeb-none-eabi/libexec/gcc/armeb-no= ne-eabi/:/home/gjimenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-eabi/12.= 1.0/:/home/gjimenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-eabi/:/home/= gjimenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-eabi/12.1.0/../../../..= /armeb-none-eabi/bin/ LIBRARY_PATH=3D/home/gjimenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-ea= bi/12.1.0/thumb/v8-a/nofp/:/home/gjimenez/x-tools/armeb-none-eabi/lib/gcc/a= rmeb-none-eabi/12.1.0/../../../../armeb-none-eabi/lib/thumb/v8-a/nofp/:/hom= e/gjimenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-eabi/12.1.0/:/home/gj= imenez/x-tools/armeb-none-eabi/lib/gcc/armeb-none-eabi/12.1.0/../../../../a= rmeb-none-eabi/lib/ COLLECT_GCC_OPTIONS=3D'-v' '-c' '-Wall' '-Wextra' '-O3' '-mbig-endian' '-ffreestanding' '-fbuiltin' '-nostdinc' '-save-temps' '-mcpu=3Dcortex-a72'= '-o' 'test.a72' '-mfloat-abi=3Dsoft' '-marm' '-mlibarch=3Darmv8-a+crc' '-march=3Darmv8-a+crc' '-dumpdir' 'test.'=