2015-04-17 52 views
4

我試圖爲Android構建Kona,並且遇到了一些問題。我爲科納製作的補丁可用hereSegfault in/system/bin/linker爲Android編譯的二進制文件

首先,我試圖避免使用ndk-build,因此編輯了makefile以支持Android。這個問題的細節對這個問題(或者好玩)沒有特別的用處,所以我會跳過它們。

基本上,源文件編譯得到這樣的:

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 

我基於這些標誌斷我所看到ndk-build使用。然後我跑了以下內容:

[email protected]:~/stuff/kdroid$ adb remount 
remount succeeded 
[email protected]:~/stuff/kdroid$ adb push ./k /system/bin/k 
3201 KB/s (724928 bytes in 0.221s) 
[email protected]:~/stuff/kdroid$ 

現在,試圖運行的二進制剛剛出現segfaults:

[email protected]:~/stuff/kdroid$ adb shell 
# k 
[1] + Stopped (signal)  k 
# 
[1] Segmentation fault  k 
# 

是被開始變得怪異在哪裏。如果我嘗試使用gdb的,我得到這個:

[email protected]:~/stuff/kdroid$ adb shell 
# gdbserver :5039 /system/bin/k 
Process /system/bin/k created; pid = 297 
Listening on port 5039 

在另一個shell窗口:

[email protected]:~/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 
#0 0xb0004d36 in ??() 
#1 0xb0005278 in ??() 
#2 0xb0005278 in ??() 
Backtrace stopped: previous frame identical to this frame (corrupt stack?) 
(gdb) 

NDK堆給了我這樣的:

********** 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 #00 pc b0004d36 /system/bin/linker: Unable to open symbol file k/linker. Error (20): Not a directory 

所以......鏈接似乎正在崩潰。如果我拉/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 

這是所有非常混亂。

我絕對有沒有線索在這一點上可能是錯誤的。我的意思是,我覺得我的編譯器命令有問題,但我不知道是什麼。

編輯:這是絕對我的編譯器命令有問題。如果我建立這個程序:

int main() { return 0; } 

ndk-build並用命令行標誌我以前發佈,該版本內置無ndk-build段錯誤。

+1

您是否遵循了生成獨立工具鏈的過程,或者您是否只是將它連接起來?如何使用只有一個或兩個動態庫函數的非常簡單的可執行程序,使用ndk和你的方式傳統構建它,並將輸出對象與ndk readelf,objdump,nm進行比較,如果它歸結爲它,hexdump。 –

回答

1

想通了!這是鏗鏘!出於某種原因,它導致了段錯誤。我仍然不知道爲什麼......但問題仍然基本解決。

+0

那麼你究竟做了什麼來解決這個問題? :) –

+0

@JanSommer切換到GCC。 – refi64

0

有科納在https://github.com/tavmem/konaStk

一個單獨的版本,它提供堆棧科納執行過程報告,打印出的關於只是由科納可執行取得的每一步細節的質量。

我將它用作調試和/或向Kona添加新功能的工具。它可能有助於顯示Stop和Segmentation Fault發生的位置。

如果您首先在Linux環境中嘗試(感受它),然後在Android環境中嘗試它,它可能會更容易使用。

+0

我知道這件事,但二進制文件在啓動之前崩潰了。它甚至沒有達到「主要」。 – refi64

相關問題