https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123480
Bug ID: 123480
Summary: Compiler drivers built with host=riscv64-linux-gnu
exports libstdc++ symbols
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: driver
Assignee: unassigned at gcc dot gnu.org
Reporter: uwu at icenowy dot me
Target Milestone: ---
Compiler drivers built with host=riscv64-linux-gnu will contain symbols from
libstdc++ in their dynamic symbol list.
Because of target=riscv64-linux-gnu pulls in basic_ios related code, running a
native riscv64-to-riscv64 compiler with extra libstdc++.so.6 loaded will leads
to cross-libstdc++-instance call and crashing.
Running `LD_PRELOAD=libstdc++.so.6 gcc` on any RISC-V distro will lead to the
crash :
```
free(): invalid size
```
with backtrace of :
```
#0 0x0000003ff7b8ef10 in __pthread_kill_implementation (threadid=<optimized
out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x0000003ff7b8f002 in __pthread_kill_internal (threadid=<optimized out>,
signo=6) at pthread_kill.c:89
#2 0x0000003ff7b4f55c in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#3 0x0000003ff7b3d86e in __GI_abort () at abort.c:77
#4 0x0000003ff7b85196 in __libc_message_impl (fmt=fmt@entry=0x3ff7c51178
"%s\n") at ../sysdeps/posix/libc_fatal.c:138
#5 0x0000003ff7b97b6a in malloc_printerr (str=<optimized out>) at
malloc.c:5879
#6 0x0000003ff7b97b82 in malloc_printerr_tail (str=<optimized out>) at
malloc.c:5896
#7 0x00000000000d5bf6 in ?? ()
#8 0x00000000000d5dc8 in ?? ()
#9 0x000000000014113e in ?? ()
#10 0x00000000000faab0 in std::basic_ios<char, std::char_traits<char>
>::init(std::basic_streambuf<char, std::char_traits<char> >*) ()
#11 0x0000003ff7e2496a in std::basic_istream<char, std::char_traits<char>
>::basic_istream (this=<optimized out>, __in_chrg=1, __vtt_parm=0x0,
__sb=<optimized out>)
at
/var/cache/acbs/build/acbs.uizs9c1e/gcc-15.2.0/abbuild/riscv64-aosc-linux-gnu/libstdc++-v3/include/istream:99
#12 std::basic_istream<char, std::char_traits<char> >::basic_istream
(this=<optimized out>, __sb=<optimized out>)
at
/var/cache/acbs/build/acbs.uizs9c1e/gcc-15.2.0/abbuild/riscv64-aosc-linux-gnu/libstdc++-v3/include/istream:99
#13 std::ios_base::Init::Init (this=0x3ff7fcf6f0 <std::__ioinit>) at
/var/cache/acbs/build/acbs.uizs9c1e/gcc-15.2.0/libstdc++-v3/src/c++98/ios_init.cc:92
#14 std::ios_base::Init::Init (this=this@entry=0x3ff7fcf6f0 <std::__ioinit>) at
/var/cache/acbs/build/acbs.uizs9c1e/gcc-15.2.0/libstdc++-v3/src/c++98/ios_init.cc:78
#15 0x0000003ff7e07f28 in __static_initialization_and_destruction_0 () at
/var/cache/acbs/build/acbs.uizs9c1e/gcc-15.2.0/libstdc++-v3/src/c++98/globals_io.cc:80
#16 _GLOBAL__sub_I.00090_globals_io.cc(void) () at
/var/cache/acbs/build/acbs.uizs9c1e/gcc-15.2.0/libstdc++-v3/src/c++98/globals_io.cc:118
#17 0x0000003ff7fdd10a in call_init (l=<optimized out>, argc=1,
argv=0x3ffffff038, env=0x3ffffff048) at dl-init.c:74
#18 call_init (l=<optimized out>, argc=<optimized out>, argv=0x3ffffff038,
env=0x3ffffff048) at dl-init.c:26
#19 0x0000003ff7fdd1d6 in _dl_init (main_map=0x3ff7fff240, argc=1,
argv=0x3ffffff038, env=0x3ffffff048) at dl-init.c:121
#20 0x0000003ff7feac24 in _dl_start_user () from
/lib/ld-linux-riscv64-lp64d.so.1
```
(The debug symbol of /usr/bin/gcc is missing, but the address will show that
functions inside it is called)
This problem is found because https://github.com/rizsotto/bear preloads its
shared object to GCC.