http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55517
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-28 13:00:27 UTC --- I think raising soft limit is a standard approach done in multiple places, even gcc itself does that, and is far better than just crashing. Unlike RLIMIT_STACK, it doesn't cause significant problems if you enlarge RLIMIT_AS during the runtime of a program as opposed to making sure it is big enough already at process start. You don't need to call getrlimit unconditionally, all you can do is upon mmap MAP_FAILED on these 3 large mmap calls you try to do getrlimit and if hard limit is bigger than what is needed and soft limit smaller, increase, setrlimit and retry the mmap.