相关疑难解决方法(0)

x86_64:是否可以"在线替代"PLT/GOT参考?

我不确定这个问题的主题是什么,但是我们走了......

为了强制代码的关键部分的代码局部性/紧凑性,我正在寻找一种方法在调用时R_X86_64_JUMP_SLOT直接通过"跳槽"(ELF 重定位)在外部(动态加载)库中调用函数site - 链接器通常放入PLT/GOT的内容,但是在调用站点上有这些内联.

如果我模仿这样的调用:

#include <stdio.h>
int main(int argc, char **argv)
{
        asm ("push $1f\n\t"
             "jmp *0f\n\t"
             "0: .quad %P0\n"
             "1:\n\t"
             : : "i"(printf), "D"("Hello, World!\n"));
        return 0;
}
Run Code Online (Sandbox Code Playgroud) 为了得到一个64位字的空间,电话本身是有效的(拜托,没有评论这是幸运的巧合,因为这打破了某些ABI规则 - 所有这些都不是这个问题的主题......并且,对于我的情况,可以工作围绕/以其他方式解决,我试图保持这个例子简短).

它创建以下程序集:

0000000000000000 <main>:
   0:   bf 00 00 00 00          mov    $0x0,%edi
                        1: R_X86_64_32  .rodata.str1.1
   5:   68 00 00 00 00          pushq  $0x0
                        6: R_X86_64_32  .text+0x19
   a:   ff 24 25 00 00 00 00    jmpq   *0x0
                        d: R_X86_64_32S .text+0x11
        ...
                        11: R_X86_64_64 printf
  19:   31 …

assembly gcc x86-64 elf ld

6
推荐指数
1
解决办法
1613
查看次数

.plt .plt.got 有什么不同?

.plt: 在 REplt[n]可用段中,蹦床在0 之外运行,.got.plt 解析器链接在plt[0]

.got .got.plt : 在可读写段中,只需寻址

我从这篇文章中了解到:https : //eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/

问题

实际的 Linux shell 命令给了我不同的答案

$readelf -l /bin/bash
Run Code Online (Sandbox Code Playgroud)

读取精灵 -l 结果

got.plt 消失了,02 段中的 .plt.got 是什么?

我倾倒了两个部分(plt,plt.got)并得到了这个程序集

.plt 是我了解到的 plt: .plt 是我了解到的 plt

.plt.got ,这是做什么用的? .plt.got ,这是做什么用的

对不起,倾销不好,它是由

objcopy -O binary --only-section=.plt.got /bin/bash ./pltgot
objcopy -O binary --only-section=.plt /bin/bash ./plt
Run Code Online (Sandbox Code Playgroud)

问题

  1. .plt 和 .plt.got 有什么区别
  2. 为什么会发生这种差异?

assembly x86-64 matplotlib elf dynamic-linking

5
推荐指数
2
解决办法
1780
查看次数

标签 统计

assembly ×2

elf ×2

x86-64 ×2

dynamic-linking ×1

gcc ×1

ld ×1

matplotlib ×1