[英]Setting stack size with g++-9 has no effect
I'm building a test program with g++ 9.3.0 on Ubuntu 18.04 x64 using this linker command:我正在使用此 linker 命令在 Ubuntu 18.04 x64 上使用 g++ 9.3.0 构建一个测试程序:
/usr/bin/g++-9 -O3 -DNDEBUG -Wl,-z,stack-size=268435456 CMakeFiles/af.dir/main.cpp.o -o af
I'm testing increased stack requirements with this function:我正在使用此 function 测试增加的堆栈要求:
float f() {
float a[3'000'000];
return a[42];
}
and results indicate a standard 8MB stack regardless of the stack-size
linker option value.结果表明标准的 8MB 堆栈与
stack-size
linker 选项值无关。 What is the way to increase the stack size?增加堆栈大小的方法是什么?
EDIT编辑
The test is as follows:测试如下:
float a[3'000'000];
causes Segmentation fault (core dumped)
Segmentation fault (core dumped)
float a[2'000'000];
returns 0
as expected0
It seems that setting stack size with g++ 9.3.0 linker options on Ubuntu 18.04 x64 is not possible.似乎无法在 Ubuntu 18.04 x64 上使用 g++ 9.3.0 linker 选项设置堆栈大小。 As suggested in comments, I settled for a run-time option:
正如评论中所建议的,我选择了一个运行时选项:
#include <sys/resource.h>
#include <fmt/format.h>
int main() {
if (struct rlimit rl{1<<28, 1l<<33}; setrlimit(RLIMIT_STACK, &rl))
fmt::print("Can not set stack size! (errno = {})\n", errno);
else
fmt::print("Stack size: {}MiB up to {}GiB\n", rl.rlim_cur/(1<<20), rl.rlim_max/(1<<30));
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.