Segmentation fault on RPi 3 B (2018-11-13-raspbian-stretch)
umarcor opened this issue · 3 comments
I downloaded Raspbian Stretch with desktop from raspberrypi.org/downloads/raspbian, flashed a SD card, powered the RPi, and after the initial setup I installed the dependencies for MAMBO:
$ sudo apt install libelf-dev ruby gcc
I then cloned MAMBO and built it:
$ git clone --recurse-submodules https://github.com/beehive-lab/mambo.git
$ cd mambo
$ make
MAMBO: detected architecture "arm"
PIE: detected architecture "arm"
make --no-print-directory ARCH=arm pie
ruby generate_decoder.rb arm > pie-arm-decoder.c
ruby generate_decoder.rb arm header > pie-arm-decoder.h
cc -c -Os -Wall -g -std=c99 pie-arm-decoder.c -o pie-arm-decoder.o
ruby generate_encoder.rb arm > pie-arm-encoder.c
ruby generate_encoder.rb arm header > pie-arm-encoder.h
cc -c -Os -Wall -g -std=c99 pie-arm-encoder.c -o pie-arm-encoder.o
ruby generate_field-decoder.rb arm > pie-arm-field-decoder.c
ruby generate_field-decoder.rb arm header > pie-arm-field-decoder.h
cc -c -Os -Wall -g -std=c99 pie-arm-field-decoder.c -o pie-arm-field-decoder.o
make --no-print-directory ARCH=thumb pie
ruby generate_decoder.rb thumb > pie-thumb-decoder.c
ruby generate_decoder.rb thumb header > pie-thumb-decoder.h
cc -c -Os -Wall -g -std=c99 pie-thumb-decoder.c -o pie-thumb-decoder.o
ruby generate_encoder.rb thumb > pie-thumb-encoder.c
ruby generate_encoder.rb thumb header > pie-thumb-encoder.h
cc -c -Os -Wall -g -std=c99 pie-thumb-encoder.c -o pie-thumb-encoder.o
ruby generate_field-decoder.rb thumb > pie-thumb-field-decoder.c
ruby generate_field-decoder.rb thumb header > pie-thumb-field-decoder.h
cc -c -Os -Wall -g -std=c99 pie-thumb-field-decoder.c -o pie-thumb-field-decoder.o
ruby api/generate_emit_wrapper.rb pie/pie-arm-encoder.c header > api/emit_arm.h
ruby api/generate_emit_wrapper.rb pie/pie-thumb-encoder.c header > api/emit_thumb.h
cc -D_GNU_SOURCE -g -std=gnu99 -O2 -mfpu=neon -c -o elf_loader/elf_loader.o elf_loader/elf_loader.c
ruby api/generate_emit_wrapper.rb pie/pie-arm-encoder.c > api/emit_arm.c
ruby api/generate_emit_wrapper.rb pie/pie-thumb-encoder.c > api/emit_thumb.c
cc -D_GNU_SOURCE -g -std=gnu99 -O2 -mfpu=neon -static -ldl -Wl,-Ttext-segment=0xa8000000 -DDBM_LINK_UNCOND_IMM -DDBM_INLINE_UNCOND_IMM -DDBM_LINK_COND_IMM -DDBM_LINK_CBZ -DDBM_LINK_TBZ -DDBM_TB_DIRECT -DLINK_BX_ALT -DDBM_INLINE_HASH -DDBM_TRACES -I/usr/include/libelf -o dbm dispatcher.S common.c dbm.c traces.c syscalls.c dispatcher.c signals.c util.S api/helpers.c api/plugin_support.c api/branch_decoder_support.c api/load_store.c elf_loader/elf_loader.o scanner_thumb.c scanner_arm.c api/emit_arm.c api/emit_thumb.c pie/pie-arm-encoder.o pie/pie-arm-decoder.o pie/pie-arm-field-decoder.o pie/pie-thumb-encoder.o pie/pie-thumb-decoder.o pie/pie-thumb-field-decoder.o -lelf -lpthread
dispatcher.S: Assembler messages:
dispatcher.S:202: Error: cannot honor width suffix -- `str LR,[SP,#16]'
dispatcher.S:208: Error: selected processor does not support `subw R2,R2,#1' in Thumb mode
dispatcher.S:210: Error: selected processor does not support `cbz R2,create_trace_trampoline' in Thumb mode
dispatcher.S:211: Error: cannot honor width suffix -- `pop {R0-R2,LR}'
dispatcher.S:212: Error: cannot honor width suffix -- `ldr PC,[SP],#8'
dispatcher.S:450: Error: selected processor does not support `cbz R0,gotocc' in Thumb mode
dispatcher.S:454: Error: cannot honor width suffix -- `ldr PC,[SP],#8'
dispatcher.S:459: Error: cannot honor width suffix -- `push {r3-r6,r9,r12,lr}'
dispatcher.S:461: Error: selected processor does not support `vpush {d16-d31}' in Thumb mode
dispatcher.S:462: Error: selected processor does not support `vpush {d0-d7}' in Thumb mode
dispatcher.S:464: Error: selected processor does not support `mrs r5,CPSR' in Thumb mode
dispatcher.S:465: Error: selected processor does not support `vmrs r6,FPSCR' in Thumb mode
dispatcher.S:467: Error: cannot honor width suffix -- `ldr R9,=deliver_signals'
dispatcher.S:471: Error: cannot honor width suffix -- `bic R2,r4,#0x7'
dispatcher.S:476: Error: selected processor does not support `msr CPSR,r5' in Thumb mode
dispatcher.S:477: Error: selected processor does not support `vmsr FPSCR,r6' in Thumb mode
dispatcher.S:479: Error: selected processor does not support `vpop {d0-d7}' in Thumb mode
dispatcher.S:480: Error: selected processor does not support `vpop {d16-d31}' in Thumb mode
dispatcher.S:481: Error: cannot honor width suffix -- `pop {r3-r6,r9,r12,lr}'
dispatcher.S:493: Error: selected processor does not support `cbz R0,abort_self_signal' in Thumb mode
dispatcher.S:499: Error: cannot honor width suffix -- `mov R7,#268'
dispatcher.S:507: Error: cannot honor width suffix -- `ldr PC,[SP],#8'
dispatcher.S:448: Error: invalid offset, target not word aligned (0x0000017E)
dispatcher.S:448: Error: invalid offset, value too big (0x00000026)
/tmp/ccln0oo4.s: Assembler messages:
/tmp/ccln0oo4.s:105: Error: selected processor does not support `dmb SY' in ARM mode
/tmp/ccln0oo4.s:659: Error: selected processor does not support `dmb SY' in ARM mode
util.S: Assembler messages:
util.S:62: Error: cannot honor width suffix -- `pop {R0-R12,R14}'
util.S:94: Error: cannot honor width suffix -- `push {R4-R12,LR}'
util.S:114: Error: cannot honor width suffix -- `pop {R4-R12,PC}'
util.S:139: Error: cannot honor width suffix -- `ldm R12,{R3-R6}'
util.S:165: Error: cannot honor width suffix -- `push {r0-r3,r9,r12,lr}'
util.S:167: Error: selected processor does not support `cbz R0,sigret' in Thumb mode
util.S:169: Error: cannot honor width suffix -- `pop {r0-r3,r9,r12,lr}'
util.S:173: Error: cannot honor width suffix -- `mov R7,#173'
util.S:222: Error: selected processor does not support `ldrexd R4,R5,[R0]' in Thumb mode
util.S:224: Error: cannot honor width suffix -- `adc R5,R3'
util.S:225: Error: selected processor does not support `strexd R1,R4,R5,[R0]' in Thumb mode
util.S:251: Error: selected processor does not support `ldrex R2,[R0]' in Thumb mode
util.S:252: Error: cannot honor width suffix -- `add R2,R1'
util.S:253: Error: selected processor does not support `strex R3,R2,[R0]' in Thumb mode
util.S:276: Error: selected processor does not support `ldrex R2,[R0]' in Thumb mode
util.S:279: Error: cannot honor width suffix -- `sub R2,R2,R1'
util.S:280: Error: selected processor does not support `strex R3,R2,[R0]' in Thumb mode
util.S:286: Error: selected processor does not support `clrex' in Thumb mode
util.S:287: Error: cannot honor width suffix -- `mov R0,#-1'
util.S:314: Error: cannot honor width suffix -- `push {R5-R7,R9,R12,LR}'
util.S:315: Error: selected processor does not support `vpush {d16-d31}' in Thumb mode
util.S:316: Error: selected processor does not support `vpush {d0-d7}' in Thumb mode
util.S:319: Error: cannot honor width suffix -- `bic R6,R7,#7'
util.S:322: Error: selected processor does not support `mrs R5,CPSR' in Thumb mode
util.S:323: Error: selected processor does not support `vmrs R6,FPSCR' in Thumb mode
util.S:329: Error: selected processor does not support `msr CPSR,R5' in Thumb mode
util.S:330: Error: selected processor does not support `vmsr FPSCR,R6' in Thumb mode
util.S:332: Error: selected processor does not support `vpop {d0-d7}' in Thumb mode
util.S:333: Error: selected processor does not support `vpop {d16-d31}' in Thumb mode
util.S:334: Error: cannot honor width suffix -- `pop {R5-R7,R9,R12,PC}'
makefile:64: recipe for target 'dbm' failed
make[1]: *** [dbm] Error 1
makefile:54: recipe for target 'all' failed
make: *** [all] Error 2
@GuillermoCallaghan suggested me to edit the makefile and replace #CFLAGS+=-mcpu=native
with CFLAGS+=-mcpu=cortex-a53
. Certainly, it is built succesfully:
$ make clean all
rm -f dbm elf_loader/elf_loader.o
MAMBO: detected architecture "arm"
PIE: detected architecture "arm"
make --no-print-directory ARCH=arm pie
make[3]: Nothing to be done for 'pie'.
make --no-print-directory ARCH=thumb pie
make[3]: Nothing to be done for 'pie'.
cc -D_GNU_SOURCE -g -std=gnu99 -O2 -mcpu=cortex-a53 -mfpu=neon -c -o elf_loader/elf_loader.o elf_loader/elf_loader.c
cc -D_GNU_SOURCE -g -std=gnu99 -O2 -mcpu=cortex-a53 -mfpu=neon -static -ldl -Wl,-Ttext-segment=0xa8000000 -DDBM_LINK_UNCOND_IMM -DDBM_INLINE_UNCOND_IMM -DDBM_LINK_COND_IMM -DDBM_LINK_CBZ -DDBM_LINK_TBZ -DDBM_TB_DIRECT -DLINK_BX_ALT -DDBM_INLINE_HASH -DDBM_TRACES -I/usr/include/libelf -o dbm dispatcher.S common.c dbm.c traces.c syscalls.c dispatcher.c signals.c util.S api/helpers.c api/plugin_support.c api/branch_decoder_support.c api/load_store.c elf_loader/elf_loader.o scanner_thumb.c scanner_arm.c api/emit_arm.c api/emit_thumb.c pie/pie-arm-encoder.o pie/pie-arm-decoder.o pie/pie-arm-field-decoder.o pie/pie-thumb-encoder.o pie/pie-thumb-decoder.o pie/pie-thumb-field-decoder.o -lelf -lpthread
But the execution produces a Segmentation fault
. It does neither start with gdb
:
$ ./dbm /bin/ls
Segmentation fault
$ gdb --args ./dbm /bin/ls
GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./dbm...done.
(gdb) r
Starting program: /home/pi/mambo/dbm /bin/ls
During startup program terminated with signal SIGSEGV, Segmentation fault.
(gdb) q
$ gdb ./dbm
GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./dbm...done.
(gdb) r
Starting program: /home/pi/mambo/dbm
During startup program terminated with signal SIGSEGV, Segmentation fault.
(gdb) q
Raspbian is one of the few distributions using by default an AArch32 kernel built with CONFIG_VMSPLIT_2G
instead of CONFIG_VMSPLIT_3G
. Change the linking address in the makefile
from -Ttext-segment=0xa8000000
to somewhere below 2G and it should work.
It's an armv6 userspace though, so it's not officially supported.