Jiangtao Zhang
Jiangtao Zhang

Reputation: 89

how to reserve a particular range of virtual memory from a linux process

i86-32 bits system: Is there a way to reserve a particular range of virtual address space in a process memory map to stop ld.so (dynamic linker) from loading any shared objects into that range?

I want to use at least 2 1G virtual memory to map the two 1G huge pages, however, ld.so load the shared library in the middle, so I can't map the 1G huge pages.

Compiler can't do this job. linker scripts can't as well. ld.so is loaded into the executable by the loader, then ld.so loads other shared libraries. however, ld.so itself even in the middle of the mapped space.

entry point of ld.so and libc.so are at a higher address, which can't be changed for our application. Entry point address: 0x46c38810

Thanks, Jiangtao

Upvotes: 2

Views: 1065

Answers (2)

Jiangtao Zhang
Jiangtao Zhang

Reputation: 89

The entry point address in the shared libs are edited by the prelink. prelink is to avoid conflicts of load address of shared libraries, to optimize and speed-up run-time loader. By default it's on in our system.

prelink is a program that modifies ELF shared libraries and ELF dynamically linked binaries and assigns a unique virtual address space slot to each libs. In such a way that the time needed for the dynamic linker to perform relocations at startup significantly decreases. Due to fewer relocations, the run-time memory consumption decreases as well.

/usr/sbin/prelink -avmR prelinks all binaries found in directories specified in /etc/prelink.conf and all their dependent libraries, assigning libraries unique virtual address space slots

By disabling the prelink, the entry point is not in the middle of the lib. so we can get another 1G memory mmaped.

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213526

ld.so is loaded into the executable by the loader,

No: ld.so is the loader, and it is loaded into the process by the kernel.

You do have a few choices:

  • the easiest solution is link the binary fully-statically. Note that on Linux such binary could still dlopen other shared libraries, although this is not a well-supported or well-tested thing to do.
  • harder solution is to build your own patched ld.so, and make your application use that ld.so (using -Wl,--dynamic-linker=... flag).
  • if you don't want to do that, rtldi may help (it will run before ld.so).

Upvotes: 2

Related Questions