On Fri, May 4, 2018 at 2:42 PM, Mathieu Malaterre <mathieu.malaterre@xxxxxxxxx> wrote: > On Fri, May 4, 2018 at 2:40 PM, Segher Boessenkool > <segher@xxxxxxxxxxxxxxxxxxx> wrote: >> On Fri, May 04, 2018 at 02:23:02PM +0200, Mathieu Malaterre wrote: >>> On Fri, May 4, 2018 at 2:16 PM, Segher Boessenkool >>> <segher@xxxxxxxxxxxxxxxxxxx> wrote: >>> > On Fri, May 04, 2018 at 01:45:35PM +0200, Mathieu Malaterre wrote: >>> >> $ gcc -static -ffreestanding -nostartfiles -s -o tiny tiny.c >>> >> $ ./tiny >>> >> Segmentation fault >>> >> >>> >> What do I need to pay attention to on ppc to build tiny executable >>> >> using the _start function ? >>> > >>> > You need to set up r13. This is powerpc64? (32-bit works fine for me, >>> > but you may be using a different ABI, you didn't tell. I'm on Linux). >>> >>> Nope, ppc32. >>> >>> $ objdump -f tiny >>> >>> tiny: file format elf32-powerpc >>> architecture: powerpc:common, flags 0x00000102: >>> EXEC_P, D_PAGED >>> start address 0x10000120 >>> >>> dmesg states: >>> >>> [ 1552.267961] tiny[2127]: unhandled signal 11 at ffff8fd0 nip >>> 10000180 lr 10000150 code 1 >> >> So >> >> $ gdb ./tiny >> (gdb) run >> (gdb) disas >> >> and look what line the "=>" mark is on. > > (gdb) r > Starting program: /tmp/tiny > > Program received signal SIGSEGV, Segmentation fault. > 0x10000180 in ?? () > (gdb) disas > No function contains program counter for selected frame. > (gdb) Tried again without -s command line option: Program received signal SIGSEGV, Segmentation fault. 0x10000180 in _exit () (gdb) disas Dump of assembler code for function _exit: 0x10000150 <+0>: stwu r1,-32(r1) 0x10000154 <+4>: stw r29,20(r1) 0x10000158 <+8>: lis r29,4098 0x1000015c <+12>: addi r29,r29,-12 0x10000160 <+16>: stw r30,24(r1) 0x10000164 <+20>: addis r29,r2,0 0x10000168 <+24>: stw r31,28(r1) 0x1000016c <+28>: li r30,49 0x10000170 <+32>: mr r31,r3 0x10000174 <+36>: addi r29,r29,-28672 0x10000178 <+40>: nop 0x1000017c <+44>: nop => 0x10000180 <+48>: lwz r9,-28720(r2) 0x10000184 <+52>: li r0,234 0x10000188 <+56>: mr r3,r31