我写了一个简单的位置无关代码的测试程序,包含两个C文件,source如下:
文件一:test.c
int aaa = 0x2b2b2b;
//const char bbb = '2';
extern int useless_fun();
void entry_pt()
{
aaa = 0xacacac;
aaa = useless_fun();
//
bbb++;
}
文件夹二:test1.c
int var_c = 0x1010101;
int useless_fun()
{
int bbb = var_c;
bbb++;
bbb--;
return bbb;
}
然后分别编译两个文件,用如下指令:
armcc -c -O1 -g- -apcs /rwpi/ropi -cpu ARM7EJ-S test1.c
armcc -c -O1 -g- -apcs /rwpi/ropi -cpu ARM7EJ-S test.c
链接用:
armlink -info totals -rwpi -ropi -nodebug test.o test1.o
生成的axf映象文件打开之后部分汇编代码如下:
entry_pt [0xe92d4010] stmfd r13!,{r4,r14}
00008004 [0xe59f4018] ldr r4,0x00008024 ; = #0x00000004
00008008 [0xe59f0010] ldr r0,0x00008020 ; = #0x00acacac
0000800c [0xe0844009] add r4,r4,r9
00008010 [0xe5840000] str r0,[r4,#0]
00008014 [0xeb000003] bl useless_fun
00008018 [0xe5840000] str r0,[r4,#0]
0000801c [0xe8bd8010] ldmfd r13!,{r4,pc}
00008020 [0x00acacac] dcd 0x00acacac ....
00008024 [0x00000004] dcd 0x00000004 ....
useless_fun [0xe59f0010] ldr r0,0x00008040 ; = #0x00000008
0000802c [0xe0800009] add r0,r0,r9
00008030 [0xe5900000] ldr r0,[r0,#0]
00008034 [0xe2800001] add r0,r0,#1
00008038 [0xe2400001] sub r0,r0,#1
0000803c [0xe12fff1e] bx r14
请问如果是位置无关的代码怎么会出现0x00008024这种绝对地址呢?动态加载的时候这些绝对地址是怎么变成实际的物理地址呢?
00008004 [0xe59f4018] ldr r4,0x00008024 ; = #0x00000004
00008008 [0xe59f0010] ldr r0,0x00008020 ; = #0x00acacac
排版有点乱,不知道说明白没 |