how does dynamic linker resolve references in run time?

let’s say I have a source file dll.c that use dlopen and dlsym functions to load a shared library called in run time.

dll.c has a reference to some_function(), and has the definition of some_function().

and let’s say the picture below is the executable object prog which is obtained by

linux> gcc -rdynamic -o prog dll.c -ldl

enter image description here

so .text section contains the reference of some_function() that needs to be resolved when the porgram load and start to call some_function()

My questions are:

Q1-it seems to me that the .text section(where some_function() belongs to) in RAM(executable is copied into memory) needs to be modified by the dynamic linker so that the reference of some_function() can be resolved, is my understanding correct?

Q2-If the dynamic linker needs to modify the .text section in RAM, how does it do it? from my understanding, .text section is read-only segment in RAM, how can a read-only segment be modified if it is called read-only?

Go to Source
Author: slowjams

Memory address problem in GNU Debugger

enter image description here

I’m new to gbd. I’ve wrote a simple program which will print hello world 10 times(I’ve listed the program in the screenshot). Then I’ve displayed the assembly language and set the break point to main and after running the program untill main, I’ve displayed the content of the rip register.

Now the confusion is, in the assembly code, the memory addresses are 0000…and then some number, but in the rip register the addresses are 55555…and then some number. For example in the line 4, containing mov instruction, the adderss is 0x000000000000113d and in the rip register the address is 0x55555555513d. I’m assuming those two addresses are same based on the common ending (13d), although not sure. But the previous digits are different. Why?

Go to Source
Author: Abhirup Bakshi