Linker 共享对象的FreeBSD运行时加载地址
在linux中,在文件dl machine.h中,下面有一个函数用于获取共享对象的运行时加载地址。这在FreeBSD中也会起作用吗?还是有不同的方法Linker 共享对象的FreeBSD运行时加载地址,linker,freebsd,elf,Linker,Freebsd,Elf,在linux中,在文件dl machine.h中,下面有一个函数用于获取共享对象的运行时加载地址。这在FreeBSD中也会起作用吗?还是有不同的方法 /* Return the run-time load address of the shared object. */ static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_load_address (void) { ElfW(Addr) addr; /* The
/* Return the run-time load address of the shared object. */
static inline ElfW(Addr) __attribute__ ((unused))
elf_machine_load_address (void)
{
ElfW(Addr) addr;
/* The easy way is just the same as on x86:
leaq _dl_start, %0
leaq _dl_start(%%rip), %1
subq %0, %1
but this does not work with binutils since we then have
a R_X86_64_32S relocation in a shared lib.
Instead we store the address of _dl_start in the data section
and compare it with the current value that we can get via
an RIP relative addressing mode. Note that this is the address
of _dl_start before any relocation performed at runtime. In case
the binary is prelinked the resulting "address" is actually a
load offset which is zero if the binary was loaded at the address
it is prelinked for. */
asm ("lea _dl_start(%%rip), %0\n\t"
"sub 1f(%%rip), %0\n\t"
".section\t.data.rel.ro\n"
"1:\t" ASM_ADDR " _dl_start\n\t"
".previous\n\t"
: "=r" (addr) : : "cc");
return addr;
}
FreeBSD上不存在文件
dl machine.h
(至少在10.1 amd64上不存在)
在FreeBSD上,就像在Linux上一样,您可以使用获取共享对象中符号的地址
主要区别在于FreeBSD还提供了dlfunc
来获取函数的地址,而无需编译器警告。您可以使用dladdr()
来获取共享对象的基址,该地址给定于对象的其他位置。如果您是从共享对象中的代码中调用函数,这非常简单