syscall: 0.432 runtime: 0.352 instruction: 0.215 qemu-user uses fixed stack size and ignores RLIMIT_STACK request, causing some guest programs to crash Description of problem: When compiling a source file, g++ segmentation faults in qemu-user riscv64. But it doesn't fail on real riscv64 boards. We discovered this problem while compiling nodejs-lts-hydrogen. The source file has been reduced to 5KB by cvise. Steps to reproduce: 1. Setup an Arch Linux riscv64 qemu-user container: https://github.com/felixonmars/archriscv-packages/wiki/Setup-Arch-Linux-RISC-V-Development-Environment 2. Start the container: `sudo systemd-nspawn -D ./archriscv -a -U` 3. Install gcc inside the container: `sudo pacman -Syu gcc` 4. Run the following command in the container: `g++ -S testcase.i -w -fpreprocessed -o /dev/null` [testcase.i](/uploads/d63b1867a458a240ef0d90c760d76bc7/testcase.i) 5. g++ segmentation faults: `g++: internal compiler error: Segmentation fault signal terminated program cc1plus` Additional information: Initially I thought this is a g++ bug. But I can't reproduce this bug on real riscv64 hardware. g++ version: g++ (GCC) 13.2.1 20230801 testcase.i: ```c++ namespace std { typedef long unsigned size_t; inline namespace __cxx11 {} } // namespace std typedef char uint8_t; namespace std { template class> struct __detector { using type = _Default; }; template class _Op> using __detected_or = __detector<_Default, void, _Op>; template class _Op> using __detected_or_t = typename __detected_or<_Default, _Op>::type; template class allocator; namespace __cxx11 { template > class basic_string; } typedef basic_string string; } // namespace std template class __new_allocator { public: typedef _Tp value_type; }; namespace std { template using __allocator_base = __new_allocator<_Tp>; template class allocator : public __allocator_base<_Tp> {}; template class initializer_list { typedef size_t size_type; typedef _E *iterator; iterator _M_array; size_type _M_len; }; struct __allocator_traits_base { template using __pointer = typename _Tp::const_pointer; }; template struct allocator_traits : __allocator_traits_base { typedef typename _Alloc::value_type value_type; using pointer = __detected_or_t; }; } // namespace std namespace __gnu_cxx { template struct __alloc_traits : std::allocator_traits<_Alloc> {}; } // namespace __gnu_cxx namespace std { namespace __cxx11 { template class basic_string { typedef __gnu_cxx::__alloc_traits<_Alloc> _Alloc_traits; public: typedef typename _Alloc_traits::pointer pointer; struct _Alloc_hider { _Alloc_hider(pointer, _Alloc); } _M_dataplus; pointer _M_local_data(); basic_string(_CharT *, _Alloc __a = _Alloc()) : _M_dataplus(_M_local_data(), __a) {} ~basic_string(); }; } // namespace __cxx11 } // namespace std namespace v8 { class StartupData {}; } // namespace v8 namespace std { template class vector { public: typedef _Tp value_type; vector(initializer_list); }; namespace builtins { struct CodeCacheInfo { string id; vector data; }; } // namespace builtins struct IsolateDataSerializeInfo {}; struct EnvSerializeInfo {}; struct SnapshotMetadata { enum { kDefault } type; string node_version; string node_arch; string v8_cache_version_tag; }; struct SnapshotData { enum { kNotOwned } data_ownership; SnapshotMetadata metadata; v8::StartupData v8_snapshot_blob_data; IsolateDataSerializeInfo isolate_data_info; EnvSerializeInfo env_info; vector code_cache; } snapshot_data{ SnapshotData::kNotOwned, SnapshotMetadata::kDefault, "", "", "", {}, {}, {}, {{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}}}; } // namespace std ```