我想在我的代码中看到一个函数的地址,所以我写了一个这样的 hello world:
#include <stdio.h>
void myfn() {
printf("I am myfn1\n");
printf("I am myfn2\n");
printf("I am myfn3\n");
printf("I am myfn4\n");
printf("I am myfn5\n");
}
typedef void (*MYFN)();
int main() {
MYFN fn = (MYFN)myfn;
printf("addr of fn: 0x%08X\n", (unsigned int)fn);
fn();
printf("just for %s\n", "test");
return 0;
}
结果是:
# ./test
addr of fn: 0x00008461
I am myfn1
I am myfn2
I am myfn3
I am myfn4
I am myfn5
just for test
那么,myfn 的地址是0x00008461吗?
然后我使用 objdump 转储它:
84ae: f7ff efb8 blx 8420 <printf@plt>
84b2: f7ff ffd5 bl 8460 <printf@plt+0x40>
84b6: 4807 ldr r0, [pc, #28] ; (84d4 <printf@plt+0xb4>)
84b8: 4907 ldr r1, [pc, #28] ; (84d8 <printf@plt+0xb8>)
84ba: 4478 add r0, pc
84bc: 4479 add r1, pc
84be: f7ff efb0 blx 8420 <printf@plt>
从那, myfn 的地址是0x8460?附近:
8460: 480a ldr r0, [pc, #40] ; (848c <printf@plt+0x6c>)
8462: b510 push {r4, lr}
8464: 4478 add r0, pc
8466: f7ff efd6 blx 8414 <puts@plt>
846a: 4809 ldr r0, [pc, #36] ; (8490 <printf@plt+0x70>)
846c: 4478 add r0, pc
846e: f7ff efd2 blx 8414 <puts@plt>
8472: 4808 ldr r0, [pc, #32] ; (8494 <printf@plt+0x74>)
8474: 4478 add r0, pc
8476: f7ff efce blx 8414 <puts@plt>
847a: 4807 ldr r0, [pc, #28] ; (8498 <printf@plt+0x78>)
847c: 4478 add r0, pc
847e: f7ff efca blx 8414 <puts@plt>
8482: 4806 ldr r0, [pc, #24] ; (849c <printf@plt+0x7c>)
我想知道真实地址是0x8460还是0x8461还是0x8462?请帮我...