简体   繁体   English

/ system / bin / linker中的Segfault,已为Android编译了二进制文件

[英]Segfault in /system/bin/linker with binary compiled for Android

I'm trying to build Kona for Android and have been running into some issues. 我正在尝试为Android构建Kona ,并且遇到了一些问题。 The patches I made to Kona are available here . 我为Kona制作的补丁可以在这里找到

For one thing, I'm trying to avoid using ndk-build and therefore have edited the makefile to support Android. 一方面,我试图避免使用ndk-build ,因此已经编辑了makefile以支持Android。 The details of that aren't particularly useful to this question (or fun), so I'll skip them. 对于该问题(或乐趣)而言,其细节并不是特别有用,因此我将跳过它们。

Basically, the source files are getting compiled like this: 基本上,源文件的编译如下:

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 off of what I saw ndk-build using. 我将这些标志基于ndk-build使用。 I then 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 the binary just segfaults: 现在,尝试运行二进制文件的segfaults:

ryan@DevPC-LX:~/stuff/kdroid$ adb shell
# k
[1] + Stopped (signal)        k
# 
[1]   Segmentation fault      k
# 

This is where is starts getting weird. 是开始变得怪异的地方。 If I try to use gdb, I get this: 如果我尝试使用gdb,则会得到以下信息:

ryan@DevPC-LX:~/stuff/kdroid$ adb shell
# gdbserver :5039 /system/bin/k
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
#0  0xb0004d36 in ?? ()
#1  0xb0005278 in ?? ()
#2  0xb0005278 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) 

ndk-stack gives me this: ndk-stack给了我这个:

********** 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

So...the linker seems to be crashing. 所以...链接器似乎崩溃了。 If I pull /system/bin/linker into the current directory, then I get this: 如果我将/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

Which is all very confusing. 这一切都很令人困惑。

I have absolutely no clue what the heck could be wrong at this point. 我绝对知道此时此刻到底有什么问题。 I mean, I feel like it's something wrong with my compiler commands, but I don't know what. 我的意思是,我感觉自己的编译器命令有问题,但是我不知道这是什么。

EDIT: It's definitely something wrong with my compiler commands. 编辑:我的编译器命令肯定有问题。 If I build this program: 如果我构建此程序:

int main() { return 0; }

with ndk-build and with the command-line flags I posted before, the version built without ndk-build segfaults. 使用ndk-build和我以前发布的命令行标志,该版本在没有ndk-build segfaults的情况下ndk-build

Figured it out! 弄清楚了! It was Clang! 是C! For some reason, it was causing the segfault. 由于某种原因,它导致了段错误。 I still have no clue why...but the problem is still mostly solved. 我仍然不知道为什么...但是问题仍然可以解决。

There is a separate version of Kona at https://github.com/tavmem/konaStk https://github.com/tavmem/konaStk有一个单独的Kona版本。

It provides stack reporting on the Kona execution process, printing out a mass of details concerning just about every step made by the Kona executable. 它提供有关Kona执行过程的堆栈报告,并打印出有关Kona可执行文件几乎每个步骤的大量细节。

I use it as a tool for debugging, and/or adding new features to Kona. 我将其用作调试工具和/或向Kona添加新功能。 It might help show where the Stop and the Segmentation Fault is occurring. 它可能有助于显示停止和分段故障发生的位置。

It might be easier to use if you try it out in your Linux environment first (to get a feel for it), then try it in the Android environment. 如果先在Linux环境中进行尝试(以体会一下),然后在Android环境中进行尝试,则使用起来可能会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM