Gfortran makefile out -stack_size must be <= 512MB on Apple M1 Chip

I am trying to run a fortran makefile with the command

make -f release.makefile OUT=foo

but I get the error

ld: -stack_size must be <= 512MB

I did run the same code on my old Macbook Pro 2017 with the intel fortran compiler and it ran without any issues. However, using gfortran on the 2021 MacBook Pro now yields this problem. Is there anything I can do to get rid of this error? The code is a replication file obtained from an economic journal. I am new to fortran and am happy about any help I can get.
Thank you!

1 Like

Hi Josie, welcome to Discourse!

You can check the stack size using the command ulimit -s. The ld error is originating from the linker (a program which takes objects and libraries/archives and combines them into an executable), which apparently has a hard limit on the maximum allowable stack size.

It might be that the Intel build was using the flag -heap-arrays [size], or the stack size was simply larger on your old MacBook. The GNU Fortran compiler has a similar flag -fmax-stack-var-size=n where n should be a size in bytes. It seems like your Makefile might also be explicitly passing a value for the -stack_size. It would be easier to comment if we could see the Makefile (and potentially also code).

For an overview of what the stack and heap are, I have found this nice blog post: Memory in C – the stack, the heap, and static – The Craft of Coding