相关疑难解决方法(0)

GDB 在 PLT 部分显示错误的跳转地址

我编写了以下示例来了解 PLT/GOT 部分。

共享库libshar代码:

shared.h

int sum(int a, int b);
Run Code Online (Sandbox Code Playgroud)

shared.c

#include "shared.h"

int sum(int a, int b){
    return a + b;
}
Run Code Online (Sandbox Code Playgroud)

可执行bin_shared代码:

#include <stdio.h>
#include "shared.h"

int main(void){
    printf("Starting the programm... \n");
    int s = sum(1, 2); //<=== I expected the dynamic linker would be called here
    int s2 = sum(2, 3);
    printf("s = %d, s2 = %d\n", s, s2);
}
Run Code Online (Sandbox Code Playgroud)

因此,我编译了共享库并将其与可执行文件链接,并编写了以下 gdb 脚本来进入动态链接器代码。我预计它会在第一次调用时执行sum

set pagination off

file build/bin_shared
b main
commands …
Run Code Online (Sandbox Code Playgroud)

c linux assembly gdb shared-libraries

4
推荐指数
1
解决办法
807
查看次数

标签 统计

assembly ×1

c ×1

gdb ×1

linux ×1

shared-libraries ×1