#2352 closed defect (fixed)

SPARC: Strange CPU_STACK_ALIGNMENT value

Reported by: Sebastian Huber Owned by: Daniel Hellstrom
Priority: normal Milestone: 4.11
Component: unspecified Version: 4.11
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description (last modified by Sebastian Huber)

We have

/**
 * CPU's worst alignment requirement for data types on a byte boundary.  This
 * alignment does not take into account the requirements for the stack.
 *
 * On the SPARC, this is required for double word loads and stores.
 */
#define CPU_ALIGNMENT      8

which is in line with the SPARC ABI.

We have

/**
 * This number corresponds to the byte alignment requirement for the
 * stack.  This alignment requirement may be stricter than that for the
 * data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
 * is strict enough for the stack, then this should be set to 0.
 *
 * NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
 *
 * The alignment restrictions for the SPARC are not that strict but this
 * should unsure that the stack is always sufficiently alignment that the
 * window overflow, underflow, and flush routines can use double word loads
 * and stores.
 */
#define CPU_STACK_ALIGNMENT        16

which makes not really sense since the compiler generates only 8 byte aligned frames, e.g. (200 % 16 == 8)

void f(char i)
{
	volatile char j[123];
	j[122] = i;
}
        .file   "test.c"
        .section        ".text"
        .align 4
        .global f
        .type   f, #function
        .proc   020
f:
        add     %sp, -200, %sp
        stb     %o0, [%sp+194]
        jmp     %o7+8
         add    %sp, 200, %sp
        .size   f, .-f
        .ident  "GCC: (GNU) 4.9.3 20150519 (prerelease)"

I suggest to change CPU_STACK_ALIGNMENT to

#define CPU_STACK_ALIGNMENT CPU_ALIGNMENT

Attachments (1)

0001-Use-CPU_ALIGNMENT-for-stack-alignment.patch (833 bytes) - added by Ralph Holmes on Dec 20, 2015 at 10:15:45 PM.

Download all attachments as: .zip

Change History (5)

comment:1 Changed on May 26, 2015 at 11:01:49 AM by Sebastian Huber

Description: modified (diff)

comment:2 Changed on May 26, 2015 at 11:13:46 AM by Sebastian Huber

Description: modified (diff)

comment:3 Changed on Dec 20, 2015 at 10:15:16 PM by Ralph Holmes

Changed as per suggestion; no regressions found. Adding patch.

comment:4 Changed on Jan 24, 2017 at 7:41:17 AM by Sebastian Huber <sebastian.huber@…>

Resolution: fixed
Status: newclosed

In 3d20f5fbb7602ec7e27859f6c3ee97708e826bc8/rtems:

Error: Processor CommitTicketReference failed
/data/trac/repo/rtems.git does not appear to be a Git repository.
Note: See TracTickets for help on using tickets.