According to my understanding, for the .rodata, the compiler can simply put it "next" to the .text section, because it shares the same page permissions, so wherever the binary is loaded, an instruction can find the global vars in the .rodata through RIP-relative adressing But what about the data and bss since they are located at random distances to the .text section ?
1 Answer
AFAIK in the current ELF PIE implementations all sections/segments are assumed to be at a fixed offset from the load base, so RIP relative addressing continues to work.
In theory it is possible to place the r/w data area at a different offset but it would require major changes in the compiler and dynamic linker behavior. Also, the file format doesn’t really foresee this possibility.
From the major OSes I think currently only macOS does this (for the Mach-O format).