2

I have been working on a winit graphics application in Rust on MacOS. My default stack size based on the linker (ld) appears to be 8MB.

What I would like to know is:
1. How common is it for graphics applications etc. to have to increase the default stack size on their target systems? Should 8MB be reasonable?
2. I know on MacOS I can't run this as a child thread, I guess the windowing library doesn't support child thread event loops. If a larger stack size is reasonable, what is the best platform independent way of configuring it in Rust? The only way I have gotten the project to build is to call cargo rustc -- -C link-args=-Wl,-stack_size,0x100000000 after the dependencies have been built. If I create a .cargo/config file with the above option, dependencies like libc fail saying that setting stack size as a linker parameter only works for binaries.

My attempt at a .cargo/crate:

[build]
rustflags = ["-C", "link-args=-Wl,-stack_size,0x100000000"]

The resulting error:

   Compiling libc v0.2.68
error: linking with `cc` failed: exit code: 1
  |
...
  = note: ld: -stack_size option can only be used when linking a main executable
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
chub500
  • 712
  • 6
  • 18
  • For 1, don't linux/windows/macos stacks grow as needed up to some user configurable limit? – PiRocks Apr 10 '20 at 11:14
  • As far as I know in most systems the main stack size limit is set by the linker? – chub500 Apr 11 '20 at 13:58
  • So in linux there is this syscall: https://linux.die.net/man/2/setrlimit , and its command line analogue `ulimit -s`. – PiRocks Apr 11 '20 at 14:14
  • I still don't know the answer to this question, but I found why I was blowing the stack - allocating a Box<[u8; HUGE_NUM]> will allocate the array on stack for some reason before transferring it to heap. To solve this, I made a little crate called arr: https://crates.io/crates/arr – chub500 Apr 15 '20 at 20:12

0 Answers0