public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: gcc@gcc.gnu.org
Subject: Re: The macro STACK_BOUNDARY may overflow
Date: Sat, 25 Mar 2023 10:28:02 -0600	[thread overview]
Message-ID: <d6ef9207-7892-023f-7d11-bb84dff6cdca@gmail.com> (raw)
In-Reply-To: <20230324134850.teu6k2b4g33o4zsp@ws2202.lin.mbt.kalray.eu>



On 3/24/23 07:48, Paul Iannetta via Gcc wrote:
> Hi,
> 
> Currently, the macro STACK_BOUNDARY is defined as
> 
>    Macro: STACK_BOUNDARY
>       Define this macro to the minimum alignment enforced by hardware for
>       the stack pointer on this machine.  The definition is a C
>       expression for the desired alignment (measured in bits).  This
>       value is used as a default if 'PREFERRED_STACK_BOUNDARY' is not
>       defined.  On most machines, this should be the same as
>       'PARM_BOUNDARY'.
> 
> with no mentions about its type and bounds.  However, at some point, the value
> of this macro gets assigned to the field "regno_pointer_align" of "struct
> emit_status" which points to an "unsigned char", hence if STACK_BOUNDARY gets
> bigger than 255, it will overflow...  Thankfully, the backend which defines the
> highest value is microblaze with 128 < 255.
> 
> The assignment happens in "emit-rtl.c" through the REGNO_POINTER_ALIGN macro:
> 
> in function.h:
>    #define REGNO_POINTER_ALIGN(REGNO) (crtl->emit.regno_pointer_align[REGNO])
> in emit-rtl.cc:
>    REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
>    [...]
>    REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
> 
> Would it be possible to, either add an explicit bound to STACK_BOUNDARY in the
> manual, and/or use an "unsigned int *" rather than and "unsigned char *" for
> the field "regno_pointer_align".
Feel free to send a suitable patch to gcc-patches.  THe alignment data 
isn't held in the RTX structures, so it's not critical that it be kept 
as small as possible.  We don't want to waste space, so an unsigned 
short might be better.  A char was good for 30 years, so we don't need 
to go crazy here.

The alternative would be to change the representation to store the log2 
of the alignment.  That would be a much larger change and would trade 
off runtime for memory consumption.  I would have suggested this 
approach if the data were in the RTX structures amd space at a premium.

While I do see a trend in processor design to reduce/remove the 
misalignment penalties (thus eliminating the driver for increasing data 
alignment), that's been primarily in high end designs.

jeff


  reply	other threads:[~2023-03-25 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 13:48 Paul Iannetta
2023-03-25 16:28 ` Jeff Law [this message]
2024-01-12 10:15   ` Paul Iannetta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d6ef9207-7892-023f-7d11-bb84dff6cdca@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).