Recent

Author Topic: Lazarus on MacOS reporting stackoverflow  (Read 1362 times)

CorBee

  • New Member
  • *
  • Posts: 32
Lazarus on MacOS reporting stackoverflow
« on: November 11, 2022, 11:16:43 am »
Hi,

I am developing code using Lazarus that uses large dynamic memorybased arrays. These 2D arrays are sized using a standard setlength(name, dimension X, dimension Y)  command. When I compile and run this code for Linux/windows there are no errors even with all debug-options activated. When the same code is compiled on a Mac (11.6 MacOS) this leads to stackoverflow errors during the resizing of the arrays. My co-worker (who has a mac) has to change the stacksize (in the compiler settings) from the default 0 to >500Kb. Is this normal behaviour for lazarus ? Do people on a Mac have to declare the stacksize ?

cheers
Cor 

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Lazarus on MacOS reporting stackoverflow
« Reply #1 on: November 11, 2022, 11:21:54 am »
The default stack size on macOS is 8MB. I'm not sure where the default 0 comes from in your case.

That said, stack checking is not something that's used very often on modern operating systems, since most have a dynamically growing stack (and they will give a hardware exception if you try to grow it beyond the reserveed space). So it's possible there's an error in the stack checking functionality on macOS that's not known. Is this on an Intel or M1/M2 Mac?

CorBee

  • New Member
  • *
  • Posts: 32
Re: Lazarus on MacOS reporting stackoverflow
« Reply #2 on: November 11, 2022, 11:26:46 am »
Hi
Thanks for the fast answer. I have attached a screenshot from the project options. As you can see the compiler directive
for stacksize is normally set to 0. This is working on Linux/Windows.
My co-worker could only get the project working when he changed this setting.

Its according to me not an M1/M2 as he stated before.

cheers
Cor

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Lazarus on MacOS reporting stackoverflow
« Reply #3 on: November 11, 2022, 12:36:10 pm »
I don't think Lazarus does anything special when it's set to 0. If you click on "Show Options" at the bottom of that pane, I think you'll notice it won't actually list a -Cs0 option. Still, the default should indeed work.

CorBee

  • New Member
  • *
  • Posts: 32
Re: Lazarus on MacOS reporting stackoverflow
« Reply #4 on: November 11, 2022, 12:41:22 pm »
unfortunately it does not ... and its unclear why it throws out stackoverflow errors. The code that generates this is not very complex as stated before.

We will keep puzzling ...

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Lazarus on MacOS reporting stackoverflow
« Reply #5 on: November 11, 2022, 12:43:17 pm »
It's probably an error in the checking logic (or rather the setup). But as mentioned before: compiler-generated stack overflow checking is not very useful any more on modern operating systems (unless you want to limit your stack usage to a certain amount and have the program tell you if you exceed it).

CorBee

  • New Member
  • *
  • Posts: 32
Re: Lazarus on MacOS reporting stackoverflow
« Reply #6 on: November 11, 2022, 01:01:37 pm »
So its a matter of stopping the debugger to stop checking this ... I have not seen that in the options. Might need a new pair of glasses ? Anybody ?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Lazarus on MacOS reporting stackoverflow
« Reply #7 on: November 11, 2022, 01:16:03 pm »
In the "Debugging" subsection of the Project -> Compiler Options, deselect "Stack (-Ct)" (for the Debug configuration).

CorBee

  • New Member
  • *
  • Posts: 32
Re: Lazarus on MacOS reporting stackoverflow
« Reply #8 on: November 11, 2022, 01:26:05 pm »
You have found my glasses :) Thanks !! 8)

AL

  • Sr. Member
  • ****
  • Posts: 264
Re: Lazarus on MacOS reporting stackoverflow
« Reply #9 on: November 11, 2022, 03:35:29 pm »
I had a similar problem in MacOS Monterey.  See this thread:

https://forum.lazarus.freepascal.org/index.php/topic,61043.msg458143.html#msg458143

Turning the stack check off kind of solved the problem.
I am not sure that it was not caused by the new security implemented in Big Sur and Monterey.  You know signing, notarizing, hardening, etc.
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Lazarus on MacOS reporting stackoverflow
« Reply #10 on: November 11, 2022, 10:48:55 pm »
I'll just report my experience. I've never changed the stack allocation or stack check for release modes. I don't know what you mean by "large", but I regularly use dynamic arrays of significant size records over 20,000 or so. I have never run into stack overflow errors. 
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

CorBee

  • New Member
  • *
  • Posts: 32
Re: Lazarus on MacOS reporting stackoverflow
« Reply #11 on: November 12, 2022, 12:44:06 pm »
Hi,

I my case (which is solved) large means images of often >1000*1000 pixels that are split into several floating-point arrays for processing. So we are talking of large arrays. But without the stackcheck active things seem to be working

cheers
Cor

 

TinyPortal © 2005-2018