2

I've been contemplating on writing a dlopen(), dlsym(), dlclose(), dlerror(), like library for one of my embedded projects where not even a C library exists (for which I already wrote my own C/C++ libraries for which can be found here www.libcaprice.com). But what's bugging me is implementing this dynamic library loader. I've taken a look at the paper: http://www.sco.com/developers/devspecs/gabi41.pdf But I can't seem to wrap my head around relocation and how you initialize the GOT.

At first I figured it should be easy to fopen() a library, and walk over the ELF header, validate it's a correct dynamic library, then search for some symbols when dlsym() is used. The problem with this is the library itself needs to be initialized, or more specifically the GOT. There also needs to be some relocation done to ensure that things are within certian bounds and allignment.

I've taken a look at some user-space implementations of this functionality, and they seem to be rather long, complex, and undocumented. So my question really is: are there any stand-alone opensource implementations of dydl that are licensed under a permissive licene, MIT or public domain perferably. Otherwise if there are none, and I will have to implement my own, can someone point me in the right direction of where I could start?

Please don't link the Application V Binary Interface Specification as I've already read the parts about dynamic linking and loading, and none seem to explain the concept of relocation in an understandable way.

4

1 回答 1

0

有一本书名为“链接器和加载器”,以及工具接口标准可执行链接格式的最新剪辑,它可能会让您更接近实现动态加载器所需的内容。这本书可能已经绝版,但可以在下面免费获得:

http://www.iecc.com/linker/

另一方面,如果您正在寻找 glibc 实现,它主要保存在 glibc 源目录中的 dlfcn 目录中。一个可能有趣的起点是 dlfcn/dlopen.c

于 2012-03-02T17:16:51.727 回答