【发布时间】:2013-09-25 09:45:22
【问题描述】:
我可以用 clang++ 指定堆栈大小吗?我找不到任何允许我这样做的编译器选项。我正在使用 OS X。
注意:这个问题专门针对 Clang,而不是 GCC 编译器。
【问题讨论】:
-
@Kiran:你会注意到这个问题指的是不同的编译器。
标签: macos ld compiler-options stack-size
我可以用 clang++ 指定堆栈大小吗?我找不到任何允许我这样做的编译器选项。我正在使用 OS X。
注意:这个问题专门针对 Clang,而不是 GCC 编译器。
【问题讨论】:
标签: macos ld compiler-options stack-size
链接器而不是编译器负责设置主线程的堆栈大小。 ld 的手册页包含以下内容:
-stack_size size
Specifies the maximum stack size for the main thread in a program. Without this
option a program has a 8MB stack. The argument size is a hexadecimal number with
an optional leading 0x. The size should be an even multiple of 4KB, that is the
last three hexadecimal digits should be zero.
例如,要指定一个 16MB 的堆栈,您可以执行以下操作:
mrowe@apollo:~$ cc -Wl,-stack_size -Wl,0x1000000 -o test test.m
mrowe@apollo:~$ otool -lV test | grep stack
stacksize 16777216
注意传递给cc 的参数上的-Wl, 前缀,以便将它们传递给链接器。
【讨论】: