Sunday, 8 December 2013

Controlling an executable’s stack size

I needed to increase the default stack size (8 Mb on Mac OS X Mavericks) allocated to an executable.

You might have thought I could use the -d switch to gnatbind:

  -dnn[k|m] Default primary stack size = nn [kilo|mega] bytes
  -Dnn[k|m] Default secondary stack size = nn [kilo|mega] bytes

Unfortunately, this seemed to have no effect.

The Mac ld has the switch -stack_size:

   -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 lead-
     ing 0x. The size should be an even multiple of 4KB, that is
     the last three hexadecimal digits should be zero.

so to allocate a 16 Mb stack, use

   gnatmake foo.adb -largs -Wl,-stack_size,0x1000000

No comments:

Post a Comment