Stack pointer is 0 in a bare metal AArch64 program
Christophe Lyon
christophe.lyon@linaro.org
Mon May 11 12:49:55 GMT 2020
Hi,
On Mon, 11 May 2020 at 14:47, Joel Sherrill <joel@rtems.org> wrote:
>
> On Sun, May 10, 2020 at 11:04 PM Orlando Arias via Newlib <
> newlib@sourceware.org> wrote:
>
> > Greetings,
> >
> > On 5/10/20 10:31 PM, Simon Marchi via Newlib wrote:
> > > $ ./sim/aarch64/run --trace=on --trace-disasm=on ./sim/aarch64/a.out
> > > memory: ERROR: executable is too big: ffffffffffffffff
> > > insn: pc = 400168 instr = 58000281
> > > disasm: ldr x1, 0x00000000004001b8
> > > memory: read of 0 (8 bytes) from 4001b8
> > > insn: pc = 40016c instr = 927cec20
> > > disasm: and x0, x1, #0xfffffffffffffff0
> > > insn: pc = 400170 instr = 9100001f
> > > disasm: mov sp, x0
> > > insn: pc = 400174 instr = d280001d
> > > disasm: mov x29, #0x0 // #0
> > > insn: pc = 400178 instr = a9bf77fd
> > > disasm: stp x29, x29, [sp, #-16]!
> >
> > Within libgloss for Aarch64, the stack is initialized using a weak
> > symbol with the value of 0:
> >
> > .macro GEN_DWORD name
> > #if defined(__ILP32__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> > .word \name
> > .word 0
> > #elif defined(__ILP32__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> > .word 0
> > .word \name
> > #else
> > .dword \name
> > #endif
> > .endm
> >
> > .Lstack:
> > GEN_DWORD __stack
> > .weak __stack
> >
> >
> > If the linker script you are utilizing does not define __stack, then the
> > weak symbol is used.
> >
> > As an aside, this behavior in libgloss has always annoyed me. When
> > working with Cortex-M cores [both ARMv7-M and ARMv8-M], msp is
> > initialized using the value stored in address 0 of the memory map by the
> > hardware. Yes, the application is free to change it afterwards, but it
> > just seems redundant to me.
> >
>
> Then why isn't a linker script provided which provides this? This behavior
> is in sharp contrast with other CPU-elf targets with libgloss support. They
> can produce executables out of the box with no requirements like this.
>
I think this is also related to:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66203
> --joel
> RTEMS
>
>
>
> >
> > Cheers,
> > Orlando.
> >
> >
More information about the Newlib
mailing list