Eric Botcazou <botca...@adacore.com> writes:
> Hi,
>
> this changes the stack checking method (that of -fstack-check) used on Linux
> from the traditional model (probe then move SP) to the model implemented for
> -fstack-clash-protection (probe while moving SP).  The rationale is that the
> latter is in widespread use on Linux and thus thought to be more robust.
>
> This entails doing a couple of things: defining STACK_CHECK_MOVING_SP to 1:
>
>  -- Macro: STACK_CHECK_MOVING_SP
>      An integer which is nonzero if GCC should move the stack pointer
>      page by page when doing probes.  This can be necessary on systems
>      where the stack pointer contains the bottom address of the memory
>      area accessible to the executing thread at any point in time.  In
>      this situation an alternate signal stack is required in order to be
>      able to recover from a stack overflow.  The default value of this
>      macro is zero

This part I followed :)

> and replacing tests on flag_stack_clash_protection by calls to a new wrapper 
> routine do_stack_clash_protection in the back-end [the implementation is the 
> same as the one present in the i386 back-end].  

But I'm not sure I understand this part.  It seems like it's using the
stack-clash mechanism and stack-clash thresholds for allocating static
parts of the frame while still using the stack-check mechanism for
dynamic alloctions.  Is that right?  If so, don't the two have different
assumptions about which part needs to be probed?  I wasn't sure why we
continued to use PROBE_INTERVAL for dynamic allocations but switched
to stack_clash_probe_interval for static ones (if I followed the code
correctly).

Thanks,
Richard

>
> -fstack-check is mainly used for Ada and AdaCore has been using this method 
> in 
> its Aarch64/Linux compilers for some time.
>
> Bootstrapped/regtested on Aarch64/Linux, OK for the mainline?
>
>
> 2024-10-01  Eric Botcazou  <ebotca...@adacore.com>
>
>       * config/aarch64/aarch64-linux.h (STACK_CHECK_MOVING_SP): Define to 1.
>       * config/aarch64/aarch64-protos.h (do_stack_clash_protection): Declare.
>       * config/aarch64/aarch64.h (STACK_DYNAMIC_OFFSET): Replace
>       flag_stack_clash_protection with call to do_stack_clash_protection.
>       * config/aarch64/aarch64.cc (aarch64_output_probe_stack_range): 
> Likewise.
>       (aarch64_output_probe_sve_stack_clash): Likewise.
>       (aarch64_layout_frame): Likewise.
>       (aarch64_get_separate_components): Likewise.
>       (aarch64_allocate_and_probe_stack_space): Likewise.
>       (aarch64_expand_prologue): Likewise.  And do not check the stack prior
>       to establishing the frame if STACK_CHECK_MOVING_SP is 1.
>       (aarch64_expand_epilogue): Likewise.
>       (do_stack_clash_protection): New predicate.

Reply via email to