From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id A5356386F80C for ; Mon, 11 May 2020 02:32:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A5356386F80C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 04B2VtuZ017083 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 10 May 2020 22:32:00 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 04B2VtuZ017083 Received: from [10.0.0.193] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 35F191E5F9 for ; Sun, 10 May 2020 22:31:55 -0400 (EDT) To: newlib@sourceware.org From: Simon Marchi Subject: Stack pointer is 0 in a bare metal AArch64 program Message-ID: <1eabaa19-fb43-e45d-1b16-12edcdf4aa3e@polymtl.ca> Date: Sun, 10 May 2020 22:31:54 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 11 May 2020 02:31:55 +0000 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 May 2020 02:32:03 -0000 Hi, Following this thread: https://sourceware.org/pipermail/gdb/2020-May/048516.html I've been trying to build a bare metal AArch64 program and run it in the binutils-gdb simulator. The program is just an empty main function, and it is compiled with: $ aarch64-none-elf-gcc test.c -specs=nosys.specs -g3 -O0 When I try to run it, I get: $ ./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]! memory: write of 0 (8 bytes) to fffffffffffffff0 core: 8 byte write to unmapped address 0xfffffff0 at 0x0 program stopped with signal 11 (Segmentation fault). I understand that these instructions try to set up the stack pointer, reading its initial value from 0x4001b8. This value happens to be 0, not a good value for a stack pointer. I'm guessing that these instructions come from crt0.S, from newlib/libgloss: https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/aarch64/crt0.S;h=f831be12e6a17e67908dba3e6ffbe5de4e3b58a0;hb=HEAD#l141 With the steps I've done, is it expected that the stack pointer is 0? Is there something I'm missing to make it have some value that makes more sense? Simon