What is the .data.rel.ro used for?

waffleman picture waffleman · Aug 11, 2011 · Viewed 10.7k times · Source

I am using objdump to analyze a shared object's memory usage. Along with the .data and .rodata sections I see a .data.rel.ro section.

Anyone know what this used for?

Answer

waffleman picture waffleman · Aug 11, 2011

I found the answer here:

gcc, the GNU linker, and the glibc dynamic linker cooperate to implement an idea called read-only relocations, or relro. This permits the linker to designate a part of an executable or (more commonly) a shared library as being read-only after dynamic relocations have been applied.

This may be used for read-only global variables which are initialized to something which requires a relocation, such as the address of a function or a different global variable. Because the global variable requires a runtime initialization in the form of a dynamic relocation, it can not be placed in a read-only segment. However, because it is declared to be constant, and therefore may not be changed by the program, the dynamic linker can mark it as read-only after the dynamic relocation has been applied.