I am trying to create Kona for Android and am facing some problems. The patches I made for Kona are available here .
Firstly, I try to avoid using it ndk-buildand therefore edited the makefile to support Android. The details of this are not particularly useful for this question (or fun), so I will skip them.
Basically, the source files are compiled as follows:
arm-linux-androideabi-clang -g -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -mtune=xscale -msoft-float -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -c -o src/ks.o src/ks.c
...
arm-linux-androideabi-clang -g -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -mtune=xscale -msoft-float -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 src/0.o src/c.o src/getline.o src/getline_android.o src/mt.o src/p.o src/r.o src/k.o src/kc.o src/kx.o src/kg.o src/km.o src/kn.o src/ko.o src/ks.o src/v.o src/va.o src/vc.o src/vd.o src/vf.o src/vg.o src/vq.o src/main.o -o k -Wl,--gc-sections -Wl,-z,nocopyreloc -lgcc -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -mthumb -lc -lm -ldl
I based these flags on what I saw ndk-build. Then I ran the following:
ryan@DevPC-LX:~/stuff/kdroid$ adb remount
remount succeeded
ryan@DevPC-LX:~/stuff/kdroid$ adb push ./k /system/bin/k
3201 KB/s (724928 bytes in 0.221s)
ryan@DevPC-LX:~/stuff/kdroid$
Now, trying to run binary is just segfaults:
ryan@DevPC-LX:~/stuff/kdroid$ adb shell
[1] + Stopped (signal) k
[1] Segmentation fault k
This is where the strange begins. If I try to use gdb, I get the following:
ryan@DevPC-LX:~/stuff/kdroid$ adb shell
Process /system/bin/k created; pid = 297
Listening on port 5039
In another shell window:
ryan@DevPC-LX:~/stuff/kdroid$ arm-linux-androideabi-gdb
GNU gdb (GDB) 7.6
Copyright (C) 2013 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 "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
/home/ryan/.gdbinit:1: Error in sourced command file:
No symbol table is loaded. Use the "file" command.
(gdb) symbol-file k
Reading symbols from /media/ryan/stuff/kdroid/k...done.
(gdb) target remote :5039
Remote debugging using :5039
0xb0001000 in ?? ()
(gdb) continue
Continuing.
Cannot access memory at address 0x0
Program received signal SIGSEGV, Segmentation fault.
0xb0004d36 in ?? ()
(gdb) bt
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)
ndk-stack gives me the following:
********** Crash dump: **********
Build fingerprint: 'generic/sdk/generic:2.3.3/GRI34/101070:eng/test-keys'
pid: 297, tid: 297 >>> /system/bin/k <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0003cabc
Stack frame
... , , . /system/bin/linker , :
********** Crash dump: **********
Build fingerprint: 'generic/sdk/generic:2.3.3/GRI34/101070:eng/test-keys'
pid: 291, tid: 291 >>> k <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0003cabc
Stack frame #00 pc b0004d36 /system/bin/linker: Routine BFD: ./linker: warning: sh_link not set for section `.ARM.exidx'
??
??:0
Crash dump is completed
.
, , , . , , - , .
EDIT: - . :
int main() { return 0; }
ndk-build , , ndk-build segfaults.