manuel-serrano / bigloo

a practical Scheme compiler
http://www-sop.inria.fr/indes/fp/Bigloo
Other
133 stars 20 forks source link

Why is BGL_STACKOVERFLOW_SIZE_THRESHOLD a constant? #112

Closed svenha closed 2 weeks ago

svenha commented 6 months ago

The value of BGL_STACKOVERFLOW_SIZE_THRESHOLD is 8192, a typical value for the stack size limit. I have to use larger stack size limits and hence (without much understanding and consideration) disabled the rlimit feature (getrlimitfull inconfigure) some years ago.

But would not it be better to use a variable BGL_STACKOVERFLOW_SIZE_THRESHOLD which is set from the limit at the start of the bigloo program?

manuel-serrano commented 3 weeks ago

Hi Sven,

It would not be difficult to use an environment variable as you suggest but first, I would like to be sure I understand the problem you are trying to solve.

BGL_STACKOVERFLOW_SIZE_THRESHOLD is only used when trapping a SIGSEGV signal for detecting stack overflows and for being able to trigger the corresponding error object.

If I understand your message correctly, this procedure was not working as expected in your case. Could you tell me exactly when you faced the problem and what would have been a possible fix? Thanks in advance.

svenha commented 3 weeks ago

Hi @manuel-serrano The problem was that the detection of overflow did not work for some cases. I have to use stack limits between 800000 to 1600000 for some programs (yes, they contain non-tailrecursive functions and making them tailrecursive is not worth it). I wanted to experiment with higher BGL_STACKOVERFLOW_SIZE_THRESHOLD values to make the detection more reliable (and avoid the SIGSEGV without any information). Or is this the wrong direction for my problem?

svenha commented 3 weeks ago

Maybe related. On the same machine with same GCC, I get values 0 and 1 for ./autoconf/stackdown (as reported by configure) for different bigloo versions. What does this mean?

manuel-serrano commented 3 weeks ago

This is super weird... Which bigloo versions did you try? The test autoconf/stackdown has not changed for years! I have no idea what could be the reason for this phenomenon...

svenha commented 3 weeks ago

Which is the expected value for stackdown on a Linux machine with gcc-10 or similar?

manuel-serrano commented 2 weeks ago

On three of my machines (x86_64 Linux Debian) STACK_GROWS_DOWN is always 1. What surprises me is that if it was badly computed, then call/cc could not work. I would have noticed that as it is automatically tested after each bootstrap.

manuel-serrano commented 2 weeks ago

Hi Sven,

What about this version for the autoconf/stackdown script?

#include <stdio.h> 

void (*f)();

void direction(long new_addr, void (*g)()) {
   static long *old_addr;
   static int flag = 0;

   if (!flag) {
     old_addr = &new_addr;
     flag++;
     g(2, (void (*)())&printf);
   } else if (flag == 1) {
     flag++;
     (old_addr > &new_addr) ? puts("1") : puts("0");
   } else {
     flag++;
     g(3,  (void (*)())&puts);;
   }
}

int main(int argc, char *argv[]) {
   f = argc > 10 ? (void (*)())&puts : &direction;
   f(1, f);
}

Is it reliable on x86_32 platforms?

Thanks in advance for your tests.

svenha commented 2 weeks ago

Hi Manuel. The new version reliably returns 1 for -mx32. Tested with -O1 and -O2 for gcc-9 to gcc-13, clang-13 to clang-16.

manuel-serrano commented 2 weeks ago

Excellent! Let's consider this issue as closed now. Thanks again for your help.