I have a C++ program of mine that I've disassembled, and it seems like the assembly is using the instruction pointer to get at string literals. For example:
leaq 0x15468(%rip), %rsi ## literal pool for: "special"
and
leaq 0x15457(%rip), %rsi ## literal pool for: "ordinary"
Why does the compiler use the instruction pointer to get at string literals? This seems like it would result in a substantial headache for any human programmer, although it's probably not as hard for the compiler.
My question, though, is why? Is there some machine based or historical reason or did the compiler writers just decide to use %rip
arbitrarily?
Remember that string literals in C++ are constant and non-modifiable. One way to ensure that is to place them together with the code in the code-segment, which is loaded into memory pages marked as read-only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With