If possible, set the stack rlimit to at least 8MiB on cc1 startup, and work
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 17 Aug 2016 01:05:07 +0000 (01:05 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 17 Aug 2016 01:05:07 +0000 (01:05 +0000)
commit194b6a3b1b1a99cc3c12c466a04320f271ebd8aa
treee499be87ae52ddc0ec1bb369b37b6951a207bf28
parent6331dc171c9f91876c28acf0a2396af1b2e9bd2f
If possible, set the stack rlimit to at least 8MiB on cc1 startup, and work
around a Linux kernel bug where the actual amount of available stack may be a
*lot* lower than the rlimit.

GCC also sets a higher stack rlimit on startup, but it goes all the way to
64MiB. We can increase this limit if it proves necessary.

The kernel bug is as follows: Linux kernels prior to version 4.1 may choose to
map the process's heap as little as 128MiB before the process's stack for a PIE
binary, even in a 64-bit virtual address space. This means that allocating more
than 128MiB before you reach the process's stack high water mark can lead to
crashes, even if you don't recurse particularly deeply.

We work around the kernel bug by touching a page deep within the stack (after
ensuring that we know how big it is), to preallocate virtual address space for
the stack so that the kernel doesn't allow the brk() area to wander into it,
when building clang as a Linux PIE binary.

llvm-svn: 278882
clang/tools/driver/cc1_main.cpp