无法调试GOT表的延迟解析;在第一次调用之前已经解析了该条目。

huangapple go评论60阅读模式
英文:

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:

  1. I'm using gdb-dashboard, but disabling it didn't affect the issue.
  2. I tried compiling with -z norelro and checking whether LD_BIND_NOW was defined. LD_BIND_NOW was not defined, and -z norelro didn't have any effect (I checked that the option took effect by using checksec).
英文:

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:

  1. I'm using gdb-dashboard, but disabling it didn't affect the
    issue.
  2. I tried compiling with -z norelro and checking whether LD_BIND_NOW was defined. LD_BIND_NOW was not defined, and -z norelro didn't have any effect (I checked that the option took effect by using checksec).

答案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

huangapple
  • 本文由 发表于 2023年4月4日 14:32:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定