compiling arm code in using android ndk tools

2,929 views
Skip to first unread message

hemanth kumar

unread,
Jan 12, 2012, 6:02:04 AM1/12/12
to android-ndk
hi all

Compiling ../Source/util_asm1.S
/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -O3 -D__GNU__ -
D__ARM_NEON__ -Wall -O3 -mfpu=neon -march=armv7-a -mtune=cortex-a8 -
mfloat-abi=softfp -fno-short-enums -fno-exceptions -fno-strict-
aliasing -I/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/
usr/include -mvectorize-with-neon-quad -Wall -static -I./../Include/ -
c ../Source/util_asm1.S -o ../Source/util_asm1.o
../Source/util_asm1.S: Assembler messages:
../Source/util_asm1.S:89: Error: bad instruction `ldrshne r7,[r1]'
../Source/util_asm1.S:232: Error: bad instruction `ldrshne r7,[r1]'
../Source/util_asm1.S:314: Error: bad instruction `ldrshne r0,[r1]'
make: *** [../Source/util_asm1.o] Error 1


i am facing problem in compiling LDRSHNE instruction in android ndk 7
tool
help me out in solving this problem
thanks
hemanth

David Turner

unread,
Jan 12, 2012, 6:26:34 AM1/12/12
to andro...@googlegroups.com
arm-linux-androideabi-gcc tries to build thumb code by default, and it looks like 'ldrshne' is a conditional version of the 'ldrsh' instruction, which is only supported by the 32-bit ARM instruction set.
Try adding -marm to your compiler CFLAGS. The best solution is probably to add an .arm assembler directive in your source code though.

Without more details about the source, it's hard to know what's happening here.

Hope this helps

- David

hemanth

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


Hemanth Kumar

unread,
Jan 12, 2012, 7:58:11 AM1/12/12
to andro...@googlegroups.com
hi thanks for suggestion
but still i am faceing same problem
i tried

Try adding -marm to your compiler CFLAGS. The best solution is
probably to add an .arm assembler directive in your source code

my soure is .c and .s files which are optimized for arm processor cortex a8
wether LDRSHNE will support by gcc assembler are not
if support how to compile this are my compile options

/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/lin
ux-x86/bin/arm-linux-androideabi-gcc -O3 -D__GNU__ -D__ARM_NEON__
-marm -Wall - O3 -mfpu=neon -march=armv7-a -mtune=cortex-a8
-mfloat-abi=softfp -fno-short-enu ms -fno-exceptions
-fno-strict-aliasing -I/home/mvanthi/android-ndk-r7/platforms


/android-9/arch-arm/usr/include -mvectorize-with-neon-quad -Wall
-static -I./../ Include/ -c ../Source/util_asm1.S -o
../Source/util_asm1.o


thanks
hemanth


--
Regards
Hemanthkumar T
PH:9620737573
Email:hema...@ncoretech.com

mic _

unread,
Jan 12, 2012, 8:34:27 AM1/12/12
to andro...@googlegroups.com
Did you try the other suggestion? (add a .arm directive inside the assembly files that contain ARM instructions).

/Michael

Hemanth Kumar

unread,
Jan 12, 2012, 9:26:12 AM1/12/12
to andro...@googlegroups.com
yes
i add .arm directive to my asm file.. same problem
thanks for replay

i have one more problem while liking

[mvanthi@dhcppc196 App]$ make -f Makefile_ndk
/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
-o ./h264dec ./../build/h264_api.o ../Lib/h264dec.a --entry=main
--dynamic-linker /system/bin/linker -nostdlib
-L/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib
-L/home/armds5/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/armv7-a
-lc -lm -rpath-link
/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib
../Lib/h264dec.a(image.o): In function `init_picture':
image.c:(.text+0x7b0): undefined reference to `__aeabi_uidivmod'
image.c:(.text+0x82c): undefined reference to `__aeabi_uidivmod'
../Lib/h264dec.a(macroblock.o): In function `decode_mb_IPCM':
macroblock.c:(.text+0x2c04): undefined reference to `__rev'
macroblock.c:(.text+0x2cc4): undefined reference to `__rev'
macroblock.c:(.text+0x2d40): undefined reference to `__rev'
macroblock.c:(.text+0x2dbc): undefined reference to `__rev'
macroblock.c:(.text+0x2e38): undefined reference to `__rev'
../Lib/h264dec.a(macroblock.o):macroblock.c:(.text+0x2eb4): more
undefined references to `__rev' follow
../Lib/h264dec.a(mbuffer.o): In function `h264d_init_dpb':
mbuffer.c:(.text+0xae0): undefined reference to `__aeabi_idiv'
../Lib/h264dec.a(mbuffer.o): In function `h264d_fill_frame_num_gap':
mbuffer.c:(.text+0x2c78): undefined reference to `__aeabi_uidivmod'
mbuffer.c:(.text+0x2d44): undefined reference to `__aeabi_idivmod'
../Lib/h264dec.a(output.o): In function `write_out_picture':
../Lib/h264dec.a(parset.o): In function `Flush_Buffer':
parset.c:(.text+0x9f8): undefined reference to `__rev'
../Lib/h264dec.a(parset.o): In function `esl_ue_v':
parset.c:(.text+0xa70): undefined reference to `__rev'
parset.c:(.text+0xad8): undefined reference to `__rev'
../Lib/h264dec.a(parset.o): In function `ReadHRDParameters':
parset.c:(.text+0xba4): undefined reference to `__rev'
parset.c:(.text+0xc6c): undefined reference to `__rev'
../Lib/h264dec.a(parset.o):parset.c:(.text+0xd18): more undefined
references to `__rev' follow
../Lib/h264dec.a(fmo.o): In function `FmoGenerateType1MapUnitMap':
fmo.c:(.text+0x100): undefined reference to `__aeabi_uidiv'
fmo.c:(.text+0x118): undefined reference to `__aeabi_uidivmod'
fmo.c:(.text+0x12c): undefined reference to `__aeabi_uidivmod'
../Lib/h264dec.a(fmo.o): In function `FmoGenerateType2MapUnitMap':
fmo.c:(.text+0x1b4): undefined reference to `__aeabi_uidiv'
fmo.c:(.text+0x1c4): undefined reference to `__aeabi_uidivmod'
fmo.c:(.text+0x1dc): undefined reference to `__aeabi_uidiv'
fmo.c:(.text+0x1ec): undefined reference to `__aeabi_uidivmod'
../Lib/h264dec.a(getbits.o): In function `H264_FlushBuf_Init':
getbits.c:(.text+0x4c): undefined reference to `__rev'
getbits.c:(.text+0x5c): undefined reference to `__rev'
getbits.c:(.text+0x74): undefined reference to `__rev'
../Lib/h264dec.a(header.o): In function `decode_poc':
header.c:(.text+0x2e0): undefined reference to `__aeabi_uidiv'
header.c:(.text+0x308): undefined reference to `__aeabi_uidivmod'
../Lib/h264dec.a(header.o): In function `esl_ue_v':
header.c:(.text+0x918): undefined reference to `__rev'
header.c:(.text+0x980): undefined reference to `__rev'
../Lib/h264dec.a(header.o): In function `FirstPartOfSliceHeader':
header.c:(.text+0xa44): undefined reference to `__rev'
header.c:(.text+0xb0c): undefined reference to `__rev'
header.c:(.text+0xbdc): undefined reference to `__rev'
../Lib/h264dec.a(header.o):header.c:(.text+0xc88): more undefined
references to `__rev' follow
../Lib/h264dec.a(header.o): In function `RestOfSliceHeader':
header.c:(.text+0x1f68): undefined reference to `__aeabi_idiv'
header.c:(.text+0x20f4): undefined reference to `__rev'
header.c:(.text+0x2200): undefined reference to `__rev'
header.c:(.text+0x2308): undefined reference to `__rev'
header.c:(.text+0x23f0): undefined reference to `__rev'
header.c:(.text+0x24b4): undefined reference to `__aeabi_idiv'
header.c:(.text+0x24c4): undefined reference to `__aeabi_idivmod'
header.c:(.text+0x25b0): undefined reference to `__rev'
header.c:(.text+0x2678): undefined reference to `__rev'
header.c:(.text+0x273c): undefined reference to `__rev'
header.c:(.text+0x288c): undefined reference to `__rev'
make: *** [TESTOUT] Error 1

how to solve this thing
i am strulling to solve this issue help me out
__rev has no builtin for gcc

thanks
hemanth

Thomas Martitz

unread,
Jan 12, 2012, 9:28:30 AM1/12/12
to andro...@googlegroups.com

Remove -nostdlib from the command line, or add -lgcc. You're missing
symbols provided by libgcc but you prevent them from being linked via
-nostdlib.

Best regards.

Hemanth Kumar

unread,
Jan 12, 2012, 9:46:20 AM1/12/12
to andro...@googlegroups.com
hi Thomas

i removed -nostdlib
and add -lgcc to mu command

now it showing error

[mvanthi@dhcppc196 App]$ make -f Makefile_ndk
/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
-o ./h264dec ./../build/h264_api.o ../Lib/h264dec.a --entry=main
--dynamic-linker /system/bin/linker

-L/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib
-L/home/armds5/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/armv7-a
-lc -lm -lgcc -rpath-link
/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib
/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld:
cannot find -lgcc


make: *** [TESTOUT] Error 1

this my tool path
where libgcc is present

[mvanthi@dhcppc196 ~]$ cd
android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/
[mvanthi@dhcppc196 4.4.3]$ cd armv7-a/
[mvanthi@dhcppc196 armv7-a]$ ls
crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o libgcc.a
libgcov.a thumb
[mvanthi@dhcppc196 armv7-a]$

i am getting above error

i am new to ndk tools


thanks
hemanth

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

Thomas Martitz

unread,
Jan 12, 2012, 9:53:32 AM1/12/12
to andro...@googlegroups.com
Am 12.01.2012 15:46, schrieb Hemanth Kumar:
> hi Thomas
>
> i removed -nostdlib
> and add -lgcc to mu command
>
> now it showing error
>

You don't need -lgcc (and -lc) if you don't specify -nostdlib. Both are
standard libs and linked by default.

And clean up your library paths (you should only need --sysroot),

"-L/home/armds5/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib" surely isn't right.

Best regards.

Hemanth Kumar

unread,
Jan 13, 2012, 12:06:51 AM1/13/12
to andro...@googlegroups.com
hi all

/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld -o ./h264dec ./../build/h264_api.o ../Lib/h264dec.a  --entry=main --dynamic-linker /system/bin/linker -L/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib  -L/home/armds5/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib -lc  -lm  -rpath-link /home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib

../Lib/h264dec.a(image.o): In function `init_picture':
image.c:(.text+0x7b0): undefined reference to `__aeabi_uidivmod'
image.c:(.text+0x82c): undefined reference to `__aeabi_uidivmod'
../Lib/h264dec.a(macroblock.o): In function `decode_mb_IPCM':
macroblock.c:(.text+0x2c04): undefined reference to `__rev'
macroblock.c:(.text+0x2cc4): undefined reference to `__rev'
macroblock.c:(.text+0x2d40): undefined reference to `__rev'
macroblock.c:(.text+0x2dbc): undefined reference to `__rev'
macroblock.c:(.text+0x2e38): undefined reference to `__rev'
../Lib/h264dec.a(macroblock.o):macroblock.c:(.text+0x2eb4): more undefined references to `__rev' follow
../Lib/h264dec.a(mbuffer.o): In function `h264d_init_dpb':
mbuffer.c:(.text+0xae0): undefined reference to `__aeabi_idiv'
../Lib/h264dec.a(mbuffer.o): In function `h264d_fill_frame_num_gap':
mbuffer.c:(.text+0x2c78): undefined reference to `__aeabi_uidivmod'
mbuffer.c:(.text+0x2d44): undefined reference to `__aeabi_idivmod'
../Lib/h264dec.a(output.o): In function `write_out_picture':
output.c:(.text+0x650): undefined reference to `yuv420_to_yuv422'
how to remove this errors
/home/mvanthi/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld -o ./h264dec ./../build/h264_api.o ../Lib/h264dec.a  --entry=main --dynamic-linker /system/bin/linker -L/home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib  -L/home/armds5/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib -lc  -lm  -rpath-link /home/mvanthi/android-ndk-r7/platforms/android-9/arch-arm/usr/lib

this my linker command  help me out

thanks
hemanth

Oyin Oluwatimi

unread,
Jul 26, 2012, 5:26:08 AM7/26/12
to andro...@googlegroups.com
Hi Digit,

Is there any way to access native ARM (armv7a) constants, definitions, functions, registers, etc.  via the NDK  ?

I see in ~/WORKING_DIRECTORY/external/qemu/target-arm directory the file "cpu.h" which have the registers Im specifically interested in. I just saw sample code accessing the user level registers, but it was in assembly code. I want to be able use the c code, however.

Thanks in advance.

- David

To unsubscribe from this group, send email to android-ndk+unsubscribe@googlegroups.com.

David Given

unread,
Jul 26, 2012, 8:36:13 AM7/26/12
to andro...@googlegroups.com
Oyin Oluwatimi wrote:
[...]
> Is there any way to access native ARM (armv7a) constants, definitions,
> functions, registers, etc. via the NDK ?

I'm not quite sure what you mean here --- NDK code is, by definition,
running native machine code. So you are intrinsically doing all this
anyway. Can you expand?

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Parents let children ride bicycles on the street. But parents do not
│ allow children to hear vulgar words. Therefore we can deduce that
│ cursing is more dangerous than being hit by a car." --- Scott Adams

signature.asc

Oyin Oluwatimi

unread,
Jul 27, 2012, 1:38:19 AM7/27/12
to andro...@googlegroups.com
Excuse the confusion.

In that cpu.h file I mentioned, you can see definitions such as the struct

typedef struct CPUARMState {
    /* Regs for current mode.  */
    uint32_t regs[16];
    /* Frequently accessed CPSR bits are stored separately for efficiently.
       This contains all the other bits.  Use cpsr_{read,write} to access
       the whole CPSR.  */
    uint32_t uncached_cpsr;
    uint32_t spsr;

    /* These hold r8-r12.  */
    uint32_t usr_regs[5];
    uint32_t fiq_regs[5];

    /* cpsr flag cache for faster execution */
    uint32_t CF; /* 0 or 1 */
    uint32_t VF; /* V is the bit 31. All other bits are undefined */
    uint32_t NF; /* N is bit 31. All other bits are undefined.  */
    uint32_t ZF; /* Z set if zero.  */
    uint32_t QF; /* 0 or 1 */
    uint32_t GE; /* cpsr[19:16] */
    uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */
    uint32_t condexec_bits; /* IT bits.  cpsr[15:10,26:25]. 
.....  (it goes on).

Also in the file, are functions that utilize that struct definition.  What I am asking is if I'm able to use those declarations in my c library code. For example, simply printing the current value in the cpsr register. My professor's goal is to "extend the ndk with security extensions", in his words, and test it out on the android emulator (armeabi-v7a) that we acquired through the AOSP.  I Hope that cleared things up.

Damola

David Given

unread,
Jul 27, 2012, 6:19:21 AM7/27/12
to andro...@googlegroups.com
Oyin Oluwatimi wrote:
[...]
> Also in the file, are functions that utilize that struct definition.
> What I am asking is if I'm able to use those declarations in my c
> library code. For example, simply printing the current value in the cpsr
> register.

I still don't really know what you mean --- machine code doesn't need
special access to the CPU state, because it's running on the CPU. There
is no specific machine code instruction to access registers because all
instructions use registers!

This means that there's no struct like the one you describe containing
the CPU state, in much the same way that the sea doesn't need to keep
water in bottles.

That said, special registers like CPSR aren't usually accessible from C
because they're special, so you'll need to copy the value out into a
normal register and then tell gcc that this normal register is used to
store a C variable. There's special syntax to do this:

uint32 arm4_cpsrget()
{
uint32 r;

asm("mrs %[ps], cpsr" : [ps]"=r" (r));
return r;
}

(From here:
http://wiki.osdev.org/ARM_Overview#Specifying_CPSR_using_AS_.28binutils.2FGCC.29_Syntax)

That function will compile into something like:

arm4_cpsrget:
mrs r0, cpsr // copy CPSR into r0
bx lr // return value from functions are in r0
signature.asc

Oyin Oluwatimi

unread,
Jul 31, 2012, 12:57:13 AM7/31/12
to andro...@googlegroups.com
Your explanation really cleared things up for me. Thanks. 

I was able to copy the value with that instruction you gave me and print it out in an android app.

Now, I am trying to copy the system control register with 

asm("MRC p15, 0, %0, c1, c1, 2 " : "=r" (id));

However, it is not working. Reading the specification, it says it can only be accessed in privileged mode. I would think that just copying (not altering it) the special registers just like you said will be ok. Is this the problem? If not, how do I access it?

Damola

Oyin Oluwatimi

unread,
Jul 31, 2012, 1:23:52 AM7/31/12
to andro...@googlegroups.com
My goal is to add security extensions to the android emulator similar to ARM Trustzone or itself. Is it not possible because of the inability to access special registers via the ndk? I just read something online, but am I supposed to build a customized kernel (never done that) to utilize the special registers that manage system control flow (ex non secure world to secure world)?

Damola 

Ian Ni-Lewis

unread,
Jul 31, 2012, 12:42:38 PM7/31/12
to andro...@googlegroups.com
I'm no security expert, but yeah, if the Trustzone were configurable by user-mode apps then it wouldn't be much of a trusted zone, would it? ;-) 

The NDK is meant for creating Android apps, not for banging on system-level software or on the emulator. For that, use the standard Android Open Source Project toolchain.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/8aCDz-_gykQJ.

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.



--
Ian Ni-Lewis
Developer Advocate
Android Developer Relations


Oyin Oluwatimi

unread,
Jul 31, 2012, 11:10:36 PM7/31/12
to andro...@googlegroups.com
Yea I figured. Thanks. 

About the toolchain. I have the AOSP already, but I'm trying to understand the purpose toolchain now. Are you saying that, if I use the aosp toolchain I can access the special registers, and access them using the exact same code?  Could you just outline a short process to do so? 

Appreciate it!

Damola
To unsubscribe from this group, send email to android-ndk+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Ian Ni-Lewis

unread,
Aug 1, 2012, 2:27:14 AM8/1/12
to andro...@googlegroups.com
I don't have any special knowledge about how to access the control registers. My point is that the NDK is probably the wrong way to go about it, because the NDK is for user-mode code. You apparently want to use privileged registers, so your code needs to run in privileged mode. You can't build privileged-mode code with the NDK, but you can rebuild the entire OS with the AOSP toolchain. Therefore, by process of elimination, the AOSP toolchain is what you would need to use. I'm sorry that I can't be more helpful than that. I certainly can't provide a short snippet of how to run privileged-mode code, since modern operating systems take great care to ensure that privileged-mode code can't be trivially invoked by user-mode applications.

Perhaps it would help if you could explain more of what you eventually want your code to do? You mentioned "TrustZone," which is only somewhat helpful. TrustZone itself is a hypervisor-level feature that can't be effectively implemented in user software. However, from your description I suspect you might be trying to implement a fault isolation scheme. If so, might I suggest that you contact Dr. Brad Chen, who is Google's foremost expert in fault isolation? His team has successfully implemented fault isolation on ARM CPUs running ChromeOS.


To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/f6qrcZQekY4J.

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.
Reply all
Reply to author
Forward
0 new messages