views:

199

answers:

2

What is the difference between "shared library text" and "shared library data"? Also, what does it mean for shared library data to be "pre-relocated"? This question is in reference to a couple of AIX-specific features involving shared libraries.

+3  A: 

Ah, that's a tricky question.

Alright, so to answer it, you've got to know that an executable file has two* segments: a "text" section and a "data" section.

The "data" segment contains "stuff that won't get executed". For example, strings in the program (for example, the string "Command not found" would be in the data segment of the /bin/sh binary).

The "text" segment contains "stuff that will get executed" -- the machine instructions.

And, the "pre-relocated"... There is a fairly good explanation of why relocation is needed here: http://people.redhat.com/drepper/textrelocs.html and what is involved here: http://en.wikipedia.org/wiki/Relocation_(computer_science).

Does that help?

*: nitpicker note: it's got more than two, but that's not important right now

David Wolever
+1 - Just beat met to it, and great links too!
Eric Petroelje
Thanks! I like your "pre-relocated" description.
David Wolever
Awesome answer, thanks!
Andrew
+2  A: 

Memory is divided into 4 segments - code, data, stack & heap.

The "shared library text" is the code part of the shared library - the actual instructions that implement the functionality in the library.

The "shared library data" is the data part of the shared library - global variables, constants, static stuff, etc. that is allocated immediately when the library is loaded.

As for "pre-relocated" libraries, here's the concept. When a shared library is loaded, it is mapped into a shared address space. A "pre-relocated" library is built with a "hint" telling the OS where in that shared address space it should be loaded. For reasons beyond my understanding, that is supposed to improve performance.

Eric Petroelje
Nice description of pre-relocated.
David Wolever
That helps clarify tremendously, thanks.
Andrew
The pre-relocated library has all the addresses already computed for a specified "Hint" base loading offset. If the library can be loaded at that offset, there is no load-time patching to relocate the library. Otherwise, all use of hardcoded addresses have to be adjusted (or "fixed up") to match the load offset. If the library loads at the hinted address, this is a large performance improvement on the initial load time for the library.
Adisak