[Bug ipa/114290] GCC output incorrect output with -O2

2024-03-09 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114290

rvalue  changed:

   What|Removed |Added

 CC||i at rvalue dot moe

--- Comment #1 from rvalue  ---
I've done some bisect and found the problematic commit was
9f2cfe108f75de49a331ba27f01d509e2c8c1c70 and the problematic patch was
https://gcc.gnu.org/pipermail/gcc-patches/2019-June/524662.html

Tested on target x86_64-unknown-linux-gnu

[Bug target/110066] [13 Regression] [RISC-V] Segment fault if compiled with -static -pg

2023-09-04 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110066

--- Comment #26 from rvalue  ---
(In reply to CVS Commits from comment #22)
> The trunk branch has been updated by Andrew Pinski :
> 
> https://gcc.gnu.org/g:bbc1a102735c72e3c5a4dede8ab382813d12b058
> 
> commit r14-2733-gbbc1a102735c72e3c5a4dede8ab382813d12b058
> Author: Andrew Pinski 
> Date:   Sat Jul 22 08:52:42 2023 -0700
> 
> Fix PR 110066: crash with -pg -static on riscv
> 
> The problem -fasynchronous-unwind-tables is on by default for riscv linux
> We need turn it off for crt*.o because it would make __EH_FRAME_BEGIN__
> point
> to .eh_frame data from crtbeginT.o instead of the user-defined object
> during static linking.
> 
> This turns it off.
> 
> OK?
> 
> libgcc/ChangeLog:
> 
> * config.host (riscv*-*-linux*): Add t-crtstuff to tmake_file.
> (riscv*-*-freebsd*): Likewise.
> * config/riscv/t-crtstuff: New file.

Confirmed that the patch works for me.

[Bug target/110066] [RISC-V] Segment fault if compiled with -static -pg

2023-05-31 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110066

--- Comment #3 from rvalue  ---
(In reply to Andrew Pinski from comment #1)
> This also could be a glibc issue.

I tried gcc 12.2.1 and 13.1.1 with exactly the same glibc and binutils
environments, the 12.2.1 version works while 13.1.1 doesn't. So I decide to
report it here.

Further analysis found that the identifier __EH_FRAME_BEGIN__ is different from
the address of .eh_frame section by 0x10, which is unexpected. I suspect the
linker might fail but that didn't change between the two runs.

[Bug target/110066] New: [RISC-V] Segment fault if compiled with -static -pg

2023-05-31 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110066

Bug ID: 110066
   Summary: [RISC-V] Segment fault if compiled with -static -pg
   Product: gcc
   Version: 13.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: i at rvalue dot moe
  Target Milestone: ---

When compile the code with option -static and -pg, the compiled program will
fail with segfault before entering main().

Reproduce:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-unknown-linux-gnu/13.1.1/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-multilib --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.1.1 20230429 (GCC)
$ cat > test.c
int main(){}
$ gcc test.c -o test -static -pg
$ ./test
Segmentation fault (core dumped)

gdb backtrace:
#0 classify_object_over_fdes ()
#1 __register_frame_info ()
#2 frame_dummy ()
#3 __libc_start_main_impl ()
#4 _start ()

[Bug target/104338] RISC-V: Subword atomics result in library calls

2023-05-16 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104338

--- Comment #19 from rvalue  ---
(In reply to Aurelien Jarno from comment #18)
> I wonder if the following patch should also be backported, as it
> doesn't make sense to link with -latomic anymore with inline subword atomic
> operations

Agreed. It's now meaningless to keep this workaround for RISC-V as the problem
has been resolved.

[Bug driver/104707] GCC doesn't give default lib path to the linker when multilib is off

2023-04-03 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104707

rvalue  changed:

   What|Removed |Added

 CC||i at rvalue dot moe

--- Comment #8 from rvalue  ---
(In reply to Andrew Pinski from comment #7)
> > since all modern operating systems have a large enough parameter space (all 
> > of them have 262k at least).
> 
> Windows still does not 

I don't think this code will make anything better or worse in Windows since it
simply compares the path with "/lib/" and "/usr/lib/", which never exist in
Windows.

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-04-15 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #15 from rvalue  ---
Hi, Kito:

I've tried these patches and found that it doesn't work with isa-spec
20190608/20191213.

Release 11.2.0 with following patches applied: 9871d39f752b, f41871dfdbd9,
f049717d8d50, 330aff0a9f7b, fa21fcfb6758

Verbose output:

$ cat > test.c
int main(){
asm volatile("fence.i" ::: "memory");
}
$ gcc test.c -o test -v -march=rv64gc -misa-spec=20191213
Using built-in specs.
COLLECT_GCC=/usr/sbin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,fortran,go,lto,objc,obj-c++,d --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-linker-build-id --enable-lto
--disable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
--enable-link-serialization=1 gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-o' 'test' '-v' '-march=rv64gc' '-misa-spec=20191213'
'-mabi=lp64d' '-march=rv64imafdc'
 /usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/cc1 -quiet -v test.c -quiet
-dumpbase test.c -dumpbase-ext .c -march=rv64gc -misa-spec=20191213 -mabi=lp64d
-march=rv64imafdc -version -o /tmp/ccQTUxnc.s
GNU C17 (GCC) version 11.2.0 (riscv64-unknown-linux-gnu)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0-p13, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/../../../../riscv64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/include
 /usr/local/include
 /usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/include-fixed
 /usr/include
End of search list.
GNU C17 (GCC) version 11.2.0 (riscv64-unknown-linux-gnu)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0-p13, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7a7a4553dc5ab0b4f8fc26761070a0ed
COLLECT_GCC_OPTIONS='-o' 'test' '-v' '-march=rv64gc' '-misa-spec=20191213'
'-mabi=lp64d' '-march=rv64imafdc'
 as -v --traditional-format -fpic -march=rv64gc -march=rv64imafdc -mabi=lp64d
-misa-spec=20191213 -o /tmp/cc2my6Or.o /tmp/ccQTUxnc.s
GNU assembler version 2.38 (riscv64-unknown-linux-gnu) using BFD version (GNU
Binutils) 2.38
test.c: Assembler messages:
test.c:2: Error: unrecognized opcode `fence.i'

[Bug target/104338] RISC-V: Subword atomics result in library calls

2022-04-07 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104338

rvalue  changed:

   What|Removed |Added

 CC||i at rvalue dot moe

--- Comment #4 from rvalue  ---
In short term, maybe we can change the spec to link against libatomic by
default (implemented in
https://github.com/riscv-collab/riscv-gcc/commit/2c4857d0981501b7c50bbf228de9e287611f8ae5).
It will solve a lot of build errors if we revert the value of `LIB_SPEC`
instead of only link against libatomic when `-pthread` is present.

Detailed talk about this: https://github.com/riscv-collab/riscv-gcc/issues/337

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-03-30 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #9 from rvalue  ---
Hi Kito:

Thank you for your follow-up patch! Confirmed that these patches do work. The
test program compiles successfully with no `-misa-spec` flag or
`-misa-spec=2.2` flag.

But when I set `-misa-spec=20190608` or `-misa-spec=20191213`, it still fails.
I think the file mentioned in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853#c7 is still buggy. Is there
any future plan about this problem?

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-03-12 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #7 from rvalue  ---
Well, I've found something that could be problematic here:

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/riscv/arch-canonicalize;h=49a6204b9cb64cb0e375c6003c423bf115a0a8a6;hb=HEAD#l60

It's never updated in ISA spec version bumping.

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-03-12 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #6 from rvalue  ---
I've got some verbose output from gcc, and it seems that a duplicate `-march`
is passed to `as`

$ gcc -c test.c -march=rv64g --verbose
Using built-in specs.
COLLECT_GCC=/usr/sbin/gcc
Target: riscv64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,fortran,go,lto,objc,obj-c++,d --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-linker-build-id --enable-lto
--disable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
--with-build-config=bootstrap-lto --enable-link-serialization=1
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-c' '-march=rv64g' '-v' '-mabi=lp64d' '-march=rv64imafd'
 /usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/cc1 -quiet -v test.c -quiet
-dumpbase test.c -dumpbase-ext .c -march=rv64g -mabi=lp64d -march=rv64imafd
-version -o /tmp/ccCK3sIZ.s
GNU C17 (GCC) version 11.2.0 (riscv64-unknown-linux-gnu)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0-p13, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/../../../../riscv64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/include
 /usr/local/include
 /usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/include-fixed
 /usr/include
End of search list.
GNU C17 (GCC) version 11.2.0 (riscv64-unknown-linux-gnu)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0-p13, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 42e88359d8058cfa8524073dbb277472
COLLECT_GCC_OPTIONS='-c' '-march=rv64g' '-v' '-mabi=lp64d' '-march=rv64imafd'
 as -v --traditional-format -fpic -march=rv64g -march=rv64imafd -mabi=lp64d -o
test.o /tmp/ccCK3sIZ.s
GNU assembler version 2.38 (riscv64-unknown-linux-gnu) using BFD version (GNU
Binutils) 2.38
test.c: Assembler messages:
test.c:2: Error: unrecognized opcode `fence.i'

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-03-12 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #5 from rvalue  ---
(In reply to Kito Cheng from comment #4)
> Thanks your info, that cause by the default ISA spec version bump issue,
> binutils 2.38 and GCC 11.* using different default ISA spec cause this
> issue, I've push a patch to GCC 11 branch [1] for this issue, could you try
> this patch? thanks.
> 
> 
> See more detail for the full story about ISA spec:
> 
> https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/aE1ZeHHCYf4
> 
> [1]
> https://gcc.gnu.org/git/?p=gcc.git;a=commit;
> h=9871d39f752bc9c114ed694662a519d04896f491

I've tried this patch just now.
Unfortunately, the gcc rebuilt reports the same error as before.

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-03-08 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #3 from rvalue  ---
(In reply to Kito Cheng from comment #2)
> Do you mind give few more version info for binutils and configuration info
> for gcc?
> 
> You can obtain those info by following two commands:
> $ gcc -v
> $ as --version
> 
> Thanks

Sure.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.0/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,fortran,go,lto,objc,obj-c++,d --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-linker-build-id --enable-lto
--disable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
--with-build-config=bootstrap-lto --enable-link-serialization=1
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
$ as --version
GNU assembler (GNU Binutils) 2.38
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `riscv64-unknown-linux-gnu'.

[Bug target/104853] [RISC-V] -march=rv64g not including extension Zifencei

2022-03-08 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

--- Comment #1 from rvalue  ---
It do works with `-march=rv64g_zifencei`, but I don't think it's the right way
to work.

[Bug target/104853] New: [RISC-V] -march=rv64g not including extension Zifencei

2022-03-08 Thread i at rvalue dot moe via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104853

Bug ID: 104853
   Summary: [RISC-V] -march=rv64g not including extension Zifencei
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: i at rvalue dot moe
  Target Milestone: ---

I'm trying to compile some code including inline assembly instruction
`fence.i`. According to RISC-V ISA spec, G is defined as abbreviation for
IMAFDZicsrZifencei, which includes instruction `fence.i`. But I get assembler
message indicating that `fence.i` is unrecognized.

I report this to GCC instead of binutils because when I use `gcc -S` and then
use `as` manually, it works fine.

Also, it works fine before I upgrade to GCC 11.2.0

Minimum recurrence:

$ gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat > test.c
int main(){
asm volatile("fence.i" ::: "memory");
}
$ gcc -c test.c -march=rv64g
test.c: Assembler messages:
test.c:2: Error: unrecognized opcode `fence.i'

Manually use `as`:

$ gcc -S test.c -march=rv64g -o test.s
$ as -march=rv64g test.s -o test.o
$ objdump -d test.o

test.o: file format elf64-littleriscv


Disassembly of section .text:

 :
   0:   ff010113addisp,sp,-16
   4:   00813423sd  s0,8(sp)
   8:   01010413addis0,sp,16
   c:   100ffence.i
  10:   0793li  a5,0
  14:   00078513mv  a0,a5
  18:   00813403ld  s0,8(sp)
  1c:   01010113addisp,sp,16
  20:   8067ret