Is there an option to output assembly from ndk-build?

1,632 views
Skip to first unread message

ccbitz

unread,
Mar 1, 2011, 5:12:00 PM3/1/11
to android-ndk
I'd like to take a look at the assembly produced by the tool chain
before it is converted to binary.

It is possible to add this line to the Android.mk file to get gcc to
output assembly in the .o files,
LOCAL_CFLAGS := -S
...but that will cause the linker to choke.

It also looks like I can add a tool to the chain that will be run
on .s files before they become .o files using this option:
LOCAL_FILTER_ASM := myasmfilter
...where in my case I'd have to write a small tool that would just
save the assembly on the side.

My question is, is there a more simple way to view the intermediate .s
files than this??

Thanks!

Carrot

unread,
Mar 2, 2011, 3:59:19 AM3/2/11
to android-ndk
try -save-temps.

David Turner

unread,
Mar 2, 2011, 6:12:36 AM3/2/11
to andro...@googlegroups.com, ccbitz
The typical way to do that is to run commands manually. For example, do the following:

1/ do a complete build
2/ touch <sourcefile>
3/ ndk-build V=1

This will dump the build command for <sourcefile> (followed by other build commands for linking, ignore these).

4/ copy and paste the build command, and change the parameters in it, i.e.:

* replace -o <objecfile> with -o <asmfile>
* replace -c with -S
* remove the -M options (-MMD -MF -MQ etc...) if any.

You can do the same thing to get the preprocessed output (use -E instead of -S)

Hope this helps.



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Colin Tracey

unread,
Mar 2, 2011, 5:57:09 PM3/2/11
to David Turner, andro...@googlegroups.com

Thanks for the tip!

So here's what I did, using your advice:

I created a shell script that runs the assembly command for each of the source files I'm interested in.  One line of it looks like this, for example (I'm using Cygwin):

/cygdrive/c/android/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -IC:/android/android-ndk-r5b/sources//android/cpufeatures -IC:/Android/projects/myproject/jni -DANDROID -DHAVE_NEON=1 -Wa,--noexecstack -O2 -DNDEBUG -g -IC:/android/android-ndk-r5b/platforms/android-8/arch-arm/usr/include -S  C:/Android/projects/myproject/jni/myfile.c -o C:/Android/projects/myproject/jni/asm/armeabi-v7a/mylibrary/myfile.s 

Now I just have to run this script after making changes to view the assembly.

It still seems a bit complicated though...  I was hoping for a simple flag for ndk-build that I might have overlooked.  A flag like this could be a useful feature for a future release.  To get the most out of NEON, I'm finding it essential to monitor the assembly.

Best,

-c

ccbitz

unread,
Mar 2, 2011, 6:01:08 PM3/2/11
to android-ndk
Oh, wow. Just noticed this reply...

This is exactly what I was looking for! Added -save-temps to
LOCAL_CFLAGS and I get all the intermediate files saved! Thanks!!

Yau-you Cheng

unread,
Jul 12, 2013, 12:43:26 AM7/12/13
to andro...@googlegroups.com
Thanks Carrot!

Write  LOCAL_CFLAGS +=-save-temps in *.mk file really helps!



Carrot於 2011年3月2日星期三UTC+8下午4時59分19秒寫道:
Reply all
Reply to author
Forward
0 new messages