Incorrect code generation when referencing linker symbols?
Given this C code:
extern char *__bss_start__;
extern char *__bss_end__;
int main(int argc, char **argv)
{
unsigned long len = &__bss_end__ - &__bss_start__;
}
why does arm-none-eabi-gcc generate the ASRS instruction following the SUBS?
> arm-none-eabi-gcc test.c --specs=nosys.specs -mthumb
000081bc <main>:
81bc: b580 push {r7, lr}
81be: b084 sub sp, #16
81c0: af00 add r7, sp, #0
81c2: 6078 str r0, [r7, #4]
81c4: 6039 str r1, [r7, #0]
81c6: 4a05 ldr r2, [pc, #20] ; (81dc <main+0x20>)
81c8: 4b05 ldr r3, [pc, #20] ; (81e0 <main+0x24>)
81ca: 1ad3 subs r3, r2, r3
81cc: 109b asrs r3, r3, #2
81ce: 60fb str r3, [r7, #12]
81d0: 1c18 adds r0, r3, #0
81d2: 46bd mov sp, r7
81d4: b004 add sp, #16
81d6: bc80 pop {r7}
81d8: bc02 pop {r1}
81da: 4708 bx r1
81dc: 00010998 .word 0x00010998
81e0: 0001097c .word 0x0001097c
This gives a result 1/4 of the actual size.
Thanks,
Stu
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Stuart Juengst for more information if necessary.