Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my disassembled C++ code use the instruction pointer and an offset to get string literals?

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?

like image 278
Dovahkiin Avatar asked May 31 '17 15:05

Dovahkiin


1 Answers

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.

like image 150
Some programmer dude Avatar answered Sep 18 '22 13:09

Some programmer dude