英文:
Can't debug GOT table lazy resolution; entry already resolved before the first call
问题
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 <_print_string@got.plt>
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 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). 
英文:
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 <_print_string@got.plt>
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). 
答案1
得分: 1
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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论