llvm-gcc assembler: LDR syntax

烂漫一生 提交于 2019-11-28 14:12:09
Pavan Manjunath

Try changing

ldr r7, =maskTable

to

ldr r7, maskTable

and remove

.data

section. It seems to be a bug/missing capability of gcc < 4.6 to deal with .data section

There are two things you can try:

  1. Change ldr r7, =maskTable into adr r7, maskTable.
  2. Store the address of the table under a separate label and load it manually like follows:

.globl func_name

func_name:
     push   {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr}

//[Some stripped code]

     add    r6, r6, sl, lsl #2
     sub    ip, ip, sl
     ldr    r7, maskTable_adr           // Here it crashes
     add    sl, sl, #4  @ 0x4

// Some stripped code here

     mov    r0, #0  @ 0x0 // return 0
     pop    {r4, r5, r6, r7, r8, r9, sl, fp, ip, pc}

     .word  0x00000000

.data
.align 5
maskTable_adr:
    .word   maskTable

maskTable:

    .word  0x00000000, 0x00000000, 0x00000000, 0x00000000
    .word  0x0000FFFF, 0x00000000, 0x00000000, 0x00000000
    .word  0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000

I don't know the answer myself, but if it was me, I'd look at some compiled C code, and see how the compiler does it. Make sure that the compiler isn't in PIC mode, or something, or it'll do something more complicated and unnecessary.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!