From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E4219394D838; Tue, 13 Jun 2023 07:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4219394D838 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686642246; bh=v5iAuqimUVnrmItjpO4NFaySRtK+ydGDxfq08KK9uJU=; h=From:To:Subject:Date:From; b=jOu7WYH5709vBw7bzgUcJ8iwnAhJiUC2TUKQLwy5wnjMlHHIMzBvJ38y4pRqJPYWP +8Dv/B3gGgfa8ojl3f3RFpXqybYlEhskA957hYeRrlsoWt1Pa0p1Pp3ALaV2Tfc9bL gqnIg5wgr9AFTL+7HCot2k8mzB3QDR8YkbdpI5Vo= From: "branislav.brzak at syrmia dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110234] New: [RISCV] Improper endian encoding when using floats and doubles with -mbig-endian Date: Tue, 13 Jun 2023 07:44:05 +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.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: branislav.brzak at syrmia 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110234 Bug ID: 110234 Summary: [RISCV] Improper endian encoding when using floats and doubles with -mbig-endian Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: branislav.brzak at syrmia dot com Target Milestone: --- Problem description RISCV Gcc has a -mbig-endian flag that is supposed to flip endian on every available data type, except instructions stored in `.text`. However, there = is an issue with how floats and doubles are stored. With the following min rep= ro: .section .text .global _start _start: j _start .section .data float1: .float 1.1 That is compiled with the following makefile: all: riscv64-unknown-linux-gnu-gcc -ffreestanding -nostdlib -march=3Drv6= 4imafd -mno-riscv-attribute -mabi=3Dlp64d -Tlink.ld -nostartfiles -mcmodel=3Dmedany -Wl,--no-warn-rwx-segments -g -o le_test.elf test.s riscv64-unknown-linux-gnu-gcc -ffreestanding -nostdlib -march=3Drv6= 4imafd -mno-riscv-attribute -mabi=3Dlp64d -Tlink.ld -nostartfiles -mcmodel=3Dmedany -Wl,--no-warn-rwx-segments -mbig-endian -g -o be_test.elf test.s riscv64-unknown-elf-objdump -D le_test.elf > le_test.dump=20=20 riscv64-unknown-elf-objdump -D be_test.elf > be_test.dump riscv64-unknown-linux-gnu-objcopy -O binary le_test.elf le_test.bin riscv64-unknown-linux-gnu-objcopy -O binary be_test.elf be_test.bin xxd le_test.bin > le_test.hex xxd be_test.bin > be_test.hex diff: @diff le_test.hex be_test.hex Doing `make diff` on the resulting hex dumps gives: 1c1 < 00000000: 6f00 0000 0000 0000 cdcc 8c3f 0000 0000 o..........?.... --- > 00000000: 6f00 0000 0000 0000 cccd 3f8c 0000 0000 o.........?..... Upper one is the LE binary while the lower one is BE. Here we can see that compared to LE (that is properly encoded), BE's endian is flipped only on 2 byte boundaries. The correct BE sequence in this case would be 3f 8c cc cd 2 byte stores are also reflected in the elf file as well: GCC version info riscv64-unknown-linux-gnu-gcc -v=20=20=20=20=20=20=20 Using built-in specs. COLLECT_GCC=3Driscv64-unknown-linux-gnu-gcc COLLECT_LTO_WRAPPER=3D/opt/riscv/libexec/gcc/riscv64-unknown-linux-gnu/12.2= .0/lto-wrapper Target: riscv64-unknown-linux-gnu Configured with: /home/fix/tasks/riscvbe/new/riscv-gnu-toolchain/gcc/config= ure --target=3Driscv64-unknown-linux-gnu --prefix=3D/opt/riscv --with-sysroot=3D/opt/riscv/sysroot --with-pkgversion=3Dg2ee5e430018 --with-system-zlib --enable-shared --enable-tls --enable-languages=3Dc,c++,fortran --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootst= rap --src=3D.././gcc --disable-multilib --with-abi=3Dlp64d --with-arch=3Drv64im= afdc --with-tune=3Drocket --with-isa-spec=3D20191213 'CFLAGS_FOR_TARGET=3D-O2=20= =20=20 -mcmodel=3Dmedlow' 'CXXFLAGS_FOR_TARGET=3D-O2 -mcmodel=3Dmedlow' Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.2.0 (g2ee5e430018)=