-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android NDK build #851
Comments
Thanks for using uftrace. Unfortunately it doesn't support Android for now. I'm not familiar with the build system and there's some piece of code needs update to be built on non-glibc systems. And I don't know why you mentioned |
Oh, I am sorry. Termux build was failing because of missing posix_spawn implementation in this file: https://github.com/namhyung/uftrace/blob/master/tests/s-posix_spawn.c . |
Can I ask you to fix uftrace in Termux? I tried to cross-compile uftrace but everything I get is
|
No need to be sorry. The |
Also I need to notice a bit different structure of bionic binary, e.g. Unwind_Resume() function is placed in libgcc_real.a in NDK and compiled statically to the binary. |
I think you need to skip /dev/* files when you are scanning process maps files. |
I have a gdb log, but I do not understan what I see.
|
The error occures in linker_init_post_relocation, but it is not because of dlopen/execve/etc hooks, and not because of wrong mcount name. I can not trace a segfault. Can you please help me? |
Sorry for the late reply. I don't know what's the exact reason of the segfault, but |
Looks like Ubuntu arm segfaults too. 0.9 works fine, but the latest segfaults. |
Do you mean the packaged version or latest master? |
Latest master |
Hi @twaik. Thanks for the work. If |
I am sorry, but I did not test. @xeffyr did. |
I see. Thanks anyway. |
Latest commit on master seems work fine.
The segfault was on tag v0.9.3 and happened only when traced program compiled with
I can do a git bisect, but since on latest master this issue is not reproducible I think no point to do it. Regarding issue on Android ARM, I can't reproduce segfault but I'm getting a bit different problem when traced program built with
This doesn't happen when program is compiled with |
@xeffyr I agree you don't need to bisect if latest master works well. Could you please run |
Disassembly of
Complete at: https://pastebin.com/ViTLxcXJ |
Thanks for doing that. I found that your clang generate incompatible binary pattern than we expect from gcc. Please see the comments in |
Could you please test the completed untested patch? diff --git a/arch/arm/mcount.S b/arch/arm/mcount.S
index bbfc597..eb28831 100644
--- a/arch/arm/mcount.S
+++ b/arch/arm/mcount.S
@@ -60,6 +60,26 @@ GLOBAL(__gnu_mcount_nc)
bx ip
END(__gnu_mcount_nc)
+/* for clang */
+GLOBAL(mcount)
+ push {r0-r3, lr}
+ ands r3, lr, #1 /* check lr for ARM/THUMB detection */
+ add r0, fp, #4 /* r0 points to pushed LR */
+ bne 1f
+ ldr r1, [fp] /* fp (=r11) might point to return address on ARM */
+ ldr r2, [r0]
+ cmp r1, r2
+ moveq r0, lr
+1:
+ mov r1, lr /* child ip */
+ mov r2, sp /* mcount_args */
+
+ bl mcount_entry
+
+ pop {r0-r3, lr}
+ bx lr
+END(mcount)
+
ENTRY(mcount_return)
push {r0-r3, lr, pc} /* ensure 8-byte alignment */ |
@namhyung After applying this patch, it works.
|
Was proposed in namhyung/uftrace#851.
That's great! @namhyung Is there any reason to make |
You can add |
@honggyukim there's a difference how @xeffyr good to see it works, thanks for the testing! @twaik it's not a problem of building uftrace. It cares the target binary which could be built by gcc or clang. So the marco guard won't work IMO. |
I mean you can change mcount asm code correspond the target compiler. Patched mcount code for clang or original __gnu_mcount_nc code for gcc. |
Are you saying that it should do it runtime? We cannot (or might not) know which compiler was used for the target binary when running it with uftrace. |
So the patch effectiveness depends on the target binary compiler? |
If |
It was reported that clang generates different code pattern for calling mcount(). Unlike gcc uses __gnu_mcount_nc() for compatibility it just use the old mcount() name and saves fp and lr registers before calling it. It seems to be the case in Android NDK build (or termux?) Fixed: namhyung#851 Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Was proposed in namhyung/uftrace#851.
Hi. Can you please make uftrace to be able to be built with Android NDK? NDK has no mcount support, but there is a need to write function execution time trace log. I think there is no need to interpret results on the target device, it can be done on PC using
uftrace replay
. NDK misses posix_spawn implementation until Android 9, so you can get it here.The text was updated successfully, but these errors were encountered: