I have a small program using a dynamic library and I want to follow the GOT resolution. I reach the following lines when calling _print_string. Now, The first line should be first set to the next one push $0x0 to solve the actual address of _print_string. But when executing line by line, the correct address for _print_string is already stored in the GOT. I ran gdb, put a breakpoint at _print_string@plt and executed the run command. The library I'm using is a shared one (not static).
0x0000555555555030 ? jmp *0x2f8a(%rip) # 0x555555557fc0 <[email protected]>
0x0000555555555036 ? push $0x0
0x000055555555503b ? jmp 0x555555555020
EDIT:
Here is the initial code for the main function (my program is written in at&t assembly x86-64 architecture). I only pasted the code until the function call.
.global main
.type main function
main:
push %rbp
mov %rsp, %rbp
push %rdi # argc (%rbp - 8)
push %rsi # argv (%rbp - 16)
push $0 # index (i) (%rbp - 24)
leaq nargsmsg(%rip), %rdi
call _print_string
EDIT2:
A small example where I the GOT entry for puts is already solved
.global main
.type main function
.text
main:
push %rbp
mov %rsp, %rbp
leaq string(%rip), %rdi
call puts
mov $0, %rax
leave
ret
.data
string: .asciz "Hello world\n"
EDIT3:
- I'm using gdb-dashboard, but disabling it didn't affect the issue.
- I tried compiling with
-z norelroand checking whetherLD_BIND_NOWwas defined.LD_BIND_NOWwas not defined, and-z norelrodidn't have any effect (I checked that the option took effect by usingchecksec).
My issue was that address resolution for dynamic libraries was being done when loading the executable (instead of using lazy linking).
To avoid it, I added these flags when compiling my executable:
-z lazy -z norelro