https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125582
Bug ID: 125582
Summary: gcc: mips: internal compiler error: Segmentation fault
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: yangshiji66 at outlook dot com
Target Milestone: ---
I am trying to add GCC16.1 support for OpenWrt[1]. I have noticed some third
party packages build failed on the MIPS platforms. The following code can be
used to trigger the error.
test.c:
```
int getrandom(void *, unsigned, unsigned);
static int get_getrandom_seed(int *seed)
{
int ret;
do {
ret = getrandom(seed, sizeof(*seed), 0x0001);
} while (ret == -1);
return ret;
}
int main()
{
int seed = 1;
return get_getrandom_seed(&seed);
}
```
command:
```
/home/db/owrt/staging_dir/toolchain-mipsel_24kc_gcc-16.1.0_musl/bin/mipsel-openwrt-linux-musl-gcc
\
-O2 -fPIC -mips16 -minterlink-mips16 -c test.c -o test.c.o
```
error:
```
/home/db/owrt/staging_dir/toolchain-mipsel_24kc_gcc-16.1.0_musl/bin/mipsel-openwrt-linux-musl-gcc
-O2 -fPIC -mips16 -minterlink-mips16 -c test.c -o test.c.o
mipsel-openwrt-linux-musl-gcc: warning: environment variable 'STAGING_DIR' not
defined
during RTL pass: expand
In function 'get_getrandom_seed',
inlined from 'main' at test.c:18:9:
test.c:8:23: internal compiler error: Segmentation fault
8 | ret = getrandom(seed, sizeof(*seed), 0x0001);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x19ac90b diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x19a5fad internal_error(char const*, ...)
???:0
0xd434df crash_signal(int)
???:0
0x8e7b4b add_insn_after(rtx_insn*, rtx_insn*, basic_block_def*) [clone .part.0]
???:0
0x8e8377 emit_pattern_after_noloc(rtx_def*, rtx_insn*, basic_block_def*,
rtx_insn* (*)(rtx_def*))
???:0
0x1111810 mips_pic_base_register(rtx_def*)
???:0
0x11118e7 mips_got_load(rtx_def*, rtx_def*, mips_symbol_type)
???:0
0x1111ab9 mips_load_call_address(mips_call_type, rtx_def*, rtx_def*)
???:0
0x111cd3e mips_expand_call(mips_call_type, rtx_def*, rtx_def*, rtx_def*,
rtx_def*, bool)
???:0
0x16d9e31 gen_call_value(rtx_def*, rtx_def*, rtx_def*, rtx_def*)
???:0
0x10f4ff8 target_gen_call_value(rtx_def*, rtx_def*, rtx_def*, rtx_def*,
rtx_def*)
???:0
0x7ef00a emit_call_1(rtx_def*, tree_node*, tree_node*, tree_node*, poly_int<1u,
long>, poly_int<1u, long>, poly_int<1u, long>, rtx_def*, rtx_def*, int,
rtx_def*, int, cumulative_args_t) [clone .isra.0]
???:0
0x7f66ee expand_call(tree_node*, rtx_def*, int)
???:0
0x91ad65 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
???:0
0x926485 store_expr(tree_node*, rtx_def*, int, bool, bool)
???:0
0x928475 expand_assignment(tree_node*, tree_node*, bool)
???:0
0x808fe8 expand_gimple_stmt(gimple*)
???:0
0x80f7e7 expand_gimple_basic_block(basic_block_def*, rtx_insn*)
???:0
0x811d67 (anonymous namespace)::pass_expand::execute(function*)
???:0
```
[1] https://github.com/openwrt/openwrt/pull/23194
P.S.
a) Disabling -mips16 -minterlink-mips16 can workaround it.
b) Only happened on GCC 16.