I have a source file, converted it to assembly and added 2 instructions and generated the final elf. When I load this final elf, symbols doesnt match the source due to assembly instructions addition.
Is there a way to align them ? am using ARM cortex-M4 and cortex-M0. I have tried to edit #line in assembly file to make sure lines match with source code but that doesn't give a good alignment. Any ideas?
Hello,
please give us the concrete source code and dis-assembly code of the elf?
Best regards,
Yasuhiko Koumoto.
Source file: test3.c
Modified assembly is test3_qcm.S
Output : final.elf
commands I am using to generate the output
REM C:\Apps\ARMCT5.05\106\bin\armcc.exe --thumb --cpu Cortex-M4 -DT_ARM -D__ARMEL__ -D__RVCT__ --apcs /noswst/interwork --littleend --force_new_nothrow -g --dwarf2 -Otime -O1 -c -S -o test3.S test3.c
REM modify the file
C:\Apps\ARMCT5.05\106\bin\armasm.exe --cpu Cortex-M4 --apcs /noswst/interwork -g --dwarf2 test3_qcm.S -o test3.o
C:\Apps\ARMCT5.05\106\bin\armlink.exe --elf --map --info sizes,totals --list test3.map --symbols --symdefs test3.sym test3.o -o final.elf
test3.c
---------
Modified assembly test3_qcm.S
-----------------------------
; generated by Component: ARM Compiler 5.05 update 1 (build 106) Tool: armcc [4d0efa]
; commandline armcc [--thumb --dwarf2 --debug -c -S -otest3.S --cpu=Cortex-M4 --apcs=/noswst/interwork -O1 -Otime --sitelicense -DT_ARM -D__ARMEL__ -D__RVCT__ --force_new_nothrow test3.c]
THUMB
REQUIRE8
PRESERVE8
AREA ||.text||, CODE, READONLY, ALIGN=2
REQUIRE _printf_percent
REQUIRE _printf_d
REQUIRE _printf_int_dec
foo2 PROC
PUSH {R0}
POP {R0}
#line 5 "test3.c"
ADR r0,|L0.60|
B.W __2printf
#line 9 "test3.c"
ENDP
foo1 PROC
#line 12 "test3.c"
ADR r0,|L0.68|
#line 16 "test3.c"
cubed PROC
#line 17 "test3.c"
MUL r1,r0,r0
MULS r0,r1,r0
BX lr
#line 20 "test3.c"
main PROC
#line 24 "test3.c"
PUSH {r4,lr}
MOVS r3,#3
MOV r0,r3
BL cubed
MOV r2,r0
MOV r1,r3
ADR r0,|L0.76|
BL __2printf
ADR r0,|L0.92|
BL foo1
BL foo2
MOVS r0,#0
POP {r4,pc}
#line 29 "test3.c"
DCW 0x0000
|L0.60|
DCB "In foo2",0
|L0.68|
DCB "In foo1",0
|L0.76|
DCB "%d cubed = %d\n",0
DCB 0
|L0.92|
DCB "Hello world",0
AREA ||.arm_vfe_header||, DATA, READONLY, NOALLOC, ALIGN=2
DCD 0x00000000
__ARM_use_no_argv EQU 0
EXPORT __ARM_use_no_argv
EXPORT foo2 [CODE]
EXPORT foo1 [CODE]
EXPORT cubed [CODE]
EXPORT main [CODE]
IMPORT ||Lib$$Request$$armlib|| [CODE,WEAK]
IMPORT __2printf [CODE]
IMPORT _printf_percent [CODE]
IMPORT _printf_d [CODE]
IMPORT _printf_int_dec [CODE]
ATTR FILESCOPE
ATTR SETVALUE Tag_ABI_PCS_wchar_t,2
ATTR SETVALUE Tag_ABI_enum_size,1
ATTR SETVALUE Tag_ABI_optimization_goals,1
ATTR SETSTRING Tag_conformance,"2.06"
ATTR SETVALUE AV,18,1
ASSERT {ENDIAN} = "little"
ASSERT {INTER} = {TRUE}
ASSERT {ROPI} = {FALSE}
ASSERT {RWPI} = {FALSE}
ASSERT {IEEE_FULL} = {FALSE}
ASSERT {IEEE_PART} = {FALSE}
ASSERT {IEEE_JAVA} = {FALSE}
END
Orginal test3.S generated with armcc -S
-----------------------------------------------
Alignment seen on T32:
-----------------------------------
Alignment seen on T32, Tried to highlight the source code
______addr/line|code_____|label____|mnemonic________________|comment______________________________________________________|
|...
|
| REQUIRE _printf_percent
| REQUIRE _printf_d
| REQUIRE _printf_int_dec
|foo2 PROC
| ; PATCH TOOL - START
16| PUSH {R0}
ST:00008098|B401 foo2: push {r0}
17| POP {R0}
ST:0000809A|BC01 pop {r0}
|#include<stdio.h>
|void foo2() ------------------ this is what I inserted
5|{
____ST:0000809C|A011________________add_____r0,pc,#0x44
6| printf("In foo2");
ST:0000809E|F000 bl_h 0x809E
ST:000080A0|B837 undef 0xB837
|}
|void foo1() ------------------ this is what came by default
12|{
ST:000080A2|B401 foo1: push {r0}
13| printf("In foo1");
ST:000080A4|BC01 pop {r0}
|void foo1()------------------ this is what I inserted
ST:000080A6|A011 add r0,pc,#0x44
ST:000080A8|F000 bl_h 0x80A8
ST:000080AA|B832 undef 0xB832
I think you should put extra "#line" before the new instruction such as PUSH or POP.
The "#line" will reset the line number to the parameter of it.
Tried adding extra #line before inserted instructions but doesn't help.
View all questions in Embedded forum