I am trying to generate a patch that can be installed from the script.
arm-none-eabi-gcc -march=armv7-r -mthumb -fPIC -O1 -c pic.c
arm-none-eabi-objdump -dS pic.o
But the result is not good:
pic.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <disconnect4_my>:
0: e92d 43f8 stmdb sp!, {r3, r4, r5, r6, r7, r8, r9, lr}
4: 6884 ldr r4, [r0, #8]
6: f04f 7880 mov.w r8, #16777216 ; 0x1000000
a: 4f78 ldr r7, [pc, #480] ; (1ec <loc_fc2f12f0+0x4>)
c: 466a mov r2, sp
e: 4641 mov r1, r8
10: 68a6 ldr r6, [r4, #8]
12: 6838 ldr r0, [r7, #0]
14: f7ff effe blx 0 <sub_fc302180>
18: b108 cbz r0, 1e <loc_fc2f1400>
1a: 2501 movs r5, #1
1c: e000 b.n 20 <loc_fc2f1402>
0000001e <loc_fc2f1400>:
1e: 2500 movs r5, #0
00000020 <loc_fc2f1402>:
20: 2002 movs r0, #2
22: f7ff fffe bl 0 <sub_fc2efc32>
26: f7ff fffe bl 0 <sub_fc2efa86>
2a: f7ff fffe bl 0 <sub_fc2f46d4>
2e: 6838 ldr r0, [r7, #0]
30: 4641 mov r1, r8
32: f7ff effe blx 0 <sub_fc302300>
36: b16e cbz r6, 54 <loc_fc2f1436>
38: b1a5 cbz r5, 64 <loc_fc2f1446>
3a: 2001 movs r0, #1
3c: f7ff fffe bl 0 <sub_fc2efc32>
40: f7ff fffe bl 0 <sub_fc2f473a>
44: 2000 movs r0, #0
46: f7ff fffe bl 0 <sub_fc0f823c>
...
How to implement firmware subs for position-independent code?