public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "branislav.brzak at syrmia dot com" <gcc-bugzilla@gcc.gnu.org>
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 [thread overview]
Message-ID: <bug-110234-4@http.gcc.gnu.org/bugzilla/> (raw)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110234
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 repro:
.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=rv64imafd
-mno-riscv-attribute -mabi=lp64d -Tlink.ld -nostartfiles -mcmodel=medany
-Wl,--no-warn-rwx-segments -g -o le_test.elf test.s
riscv64-unknown-linux-gnu-gcc -ffreestanding -nostdlib -march=rv64imafd
-mno-riscv-attribute -mabi=lp64d -Tlink.ld -nostartfiles -mcmodel=medany
-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
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
Using built-in specs.
COLLECT_GCC=riscv64-unknown-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/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/configure
--target=riscv64-unknown-linux-gnu --prefix=/opt/riscv
--with-sysroot=/opt/riscv/sysroot --with-pkgversion=g2ee5e430018
--with-system-zlib --enable-shared --enable-tls
--enable-languages=c,c++,fortran --disable-libmudflap --disable-libssp
--disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootstrap
--src=.././gcc --disable-multilib --with-abi=lp64d --with-arch=rv64imafdc
--with-tune=rocket --with-isa-spec=20191213 'CFLAGS_FOR_TARGET=-O2
-mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-O2 -mcmodel=medlow'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (g2ee5e430018)
next reply other threads:[~2023-06-13 7:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 7:44 branislav.brzak at syrmia dot com [this message]
2023-06-13 7:45 ` [Bug c/110234] " branislav.brzak at syrmia dot com
2023-06-13 12:32 ` [Bug target/110234] " pinskia at gcc dot gnu.org
2023-06-13 13:34 ` xry111 at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-110234-4@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).