public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114756] New: [14] RISC-V rv32imc miscompile with -fdata-sections
@ 2024-04-17 18:11 patrick at rivosinc dot com
  2024-04-17 19:30 ` [Bug target/114756] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: patrick at rivosinc dot com @ 2024-04-17 18:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114756
           Summary: [14] RISC-V rv32imc miscompile with -fdata-sections
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

Testcase:
#pragma pack(push)
#pragma pack(1)
struct a
{
        long long b;
        char c;
        long long d;
        int e;
        int f;
        long long g;
        char h;
};
#pragma pack(pop)
struct i
{
        unsigned c;
        unsigned d;
        unsigned h;
};
int j;
int k;
short l;
int m;
static struct a n = {0xBBCB58D824AE4D28};
static long long *s = &n.b;
struct a o = {1};
struct a p[32] = {{4}};
struct a aa = {6};
struct i ab[3] = {{108}};
int ac[8] = {4};
short ad;
short *ae[] = {&ad, &ad, &ad, &ad, &ad, &ad};
struct a q = {9};
int *r[24] = {&m};
struct a t = {4073709551615};
int *u[3] = {&j};
short v[64] = {6};
struct a x = {4073709551611};
struct a y = {4073709551607};
char z[60] = {4};
struct i af = {5};
struct i ag = {11};
short *ai[] = {&l, &l, &l, &l, &l};
int *aj[32] = {&k};
struct a ak = {4073709551615};
struct a al = {1};
struct a am = {12};
struct i an = {5};
struct a ao[216] = {{4073709551615}};
struct i ap = {3};
long long aq[] = {6, 0, 6, 6, 0, 6, 6};
struct a ar = {4};
struct a as[10] = {{13}};
struct a at = {4073709551615};
struct a au = {3};
struct a av = {6};
struct a aw = {7};
struct i ax = {4};
struct i ay = {4};
struct i az = {4};
struct i ba = {1};
struct a bb[8] = {{4073709551615}};
int main() { __builtin_printf("%llX\n", *s); }

Commands:
> /scratch/tc-testing/tc-apr-9/build-rv32gcv/bin/riscv64-unknown-linux-gnu-gcc -O1 -mabi=ilp32 -march=rv32imc -fdata-sections red.c -o user-config.out -fsigned-char -fno-strict-aliasing -static
> /scratch/tc-testing/tc-apr-15/build-rv64gcv/bin/qemu-riscv32 user-config.out
24AE4D28

without -fdata-sections
> /scratch/tc-testing/tc-apr-9/build-rv32gcv/bin/riscv64-unknown-linux-gnu-gcc -O1 -mabi=ilp32 -march=rv32imc red.c -o user-config.out -fsigned-char -fno-strict-aliasing -static
> /scratch/tc-testing/tc-apr-15/build-rv64gcv/bin/qemu-riscv32 user-config.out
BBCB58D824AE4D28

Found via fuzzer.

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

* [Bug target/114756] [14] RISC-V rv32imc miscompile with -fdata-sections
  2024-04-17 18:11 [Bug target/114756] New: [14] RISC-V rv32imc miscompile with -fdata-sections patrick at rivosinc dot com
@ 2024-04-17 19:30 ` pinskia at gcc dot gnu.org
  2024-04-17 19:31 ` pinskia at gcc dot gnu.org
  2024-04-17 19:35 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-17 19:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
        lui     a5,%hi(n)
        lw      a2,%lo(n)(a5)
        lw      a3,%lo(n+4)(a5)

vs:
        lui     a5,%hi(.LANCHOR0)
        addi    a5,a5,%lo(.LANCHOR0)
        lw      a2,0(a5)
        lw      a3,4(a5)

I have seen that issue before ...

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

* [Bug target/114756] [14] RISC-V rv32imc miscompile with -fdata-sections
  2024-04-17 18:11 [Bug target/114756] New: [14] RISC-V rv32imc miscompile with -fdata-sections patrick at rivosinc dot com
  2024-04-17 19:30 ` [Bug target/114756] " pinskia at gcc dot gnu.org
@ 2024-04-17 19:31 ` pinskia at gcc dot gnu.org
  2024-04-17 19:35 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-17 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 100604 ***

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

* [Bug target/114756] [14] RISC-V rv32imc miscompile with -fdata-sections
  2024-04-17 18:11 [Bug target/114756] New: [14] RISC-V rv32imc miscompile with -fdata-sections patrick at rivosinc dot com
  2024-04-17 19:30 ` [Bug target/114756] " pinskia at gcc dot gnu.org
  2024-04-17 19:31 ` pinskia at gcc dot gnu.org
@ 2024-04-17 19:35 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-17 19:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Basically what is happening is the linker relaxation code is turning it into
something which is wrong. But GCC's invalid use of %lo(n+4)(a5) with a
(invalid) corresponding %hi(n) is confusing the relaxation code really.

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

end of thread, other threads:[~2024-04-17 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 18:11 [Bug target/114756] New: [14] RISC-V rv32imc miscompile with -fdata-sections patrick at rivosinc dot com
2024-04-17 19:30 ` [Bug target/114756] " pinskia at gcc dot gnu.org
2024-04-17 19:31 ` pinskia at gcc dot gnu.org
2024-04-17 19:35 ` pinskia at gcc dot gnu.org

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).