动态加载的控制地址space布局

Controlling address space layout of dynamic loading

是否有可能(在Linux/OSX中)控制共享库的映射方式加载后内存? 是否可以 malloc 一个连续的内存区域,并将其传递给诸如“dlopen”之类的例程? 我不坚持将各个段(.text.bss 等)精确放置在 malloc'd 区域内,只是所有段都放置在 malloc'd 区域内。

Is it possible (in Linux / OSX) to control how shared libraries are mapped in memory after loading?

我对OSX了解不多,所以我只回答Linux部分。

不修改动态加载器不行,不行

Is it possible to malloc a contiguous region of memory, and pass that to a routine such as "dlopen"?

malloc 不会为您提供所需的页面对齐。 posix_memalign 会,但直接 mmap(..., MAP_FIXED, ...) 可能会更好。您要求实施此 feature request(还没有人完成)。