加载时ELF重 [英] load-time ELF relocation

查看:186
本文介绍了加载时ELF重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写Linux下一个简单的用户空间ELF装载机(为什么吗?有趣的)。我此刻的加载程序是非常简单,旨在加载包含与位置无关的code只有静态链接的ELF文件。

I am writing a simple user-space ELF loader under Linux (why? for 'fun'). My loader at the moment is quite simple and is designed to load only statically-linked ELF files containing position-independent code.

通常,当一个节目由内核的ELF加载器加载,它被装入其自己的地址空间。这样,数据段和code段可以在如在ELF段指定的正确的虚拟地址被加载

Normally, when a program is loaded by the kernel's ELF loader, it is loaded into its own address space. As such, the data segment and code segment can be loaded at the correct virtual address as specified in the ELF segments.

在我的情况,但是,我通过 MMAP ,并要求从内核地址可能会或可能不会得到在ELF段要求的地址。这不是为code段中的问题,因为它是与位置无关。然而,如果数据段没有在预期的地址加载,code将不能够正确地引用存储在数据段的任何

In my case, however, I am requesting addresses from the kernel via mmap, and may or may not get the addresses requested in the ELF segments. This is not a problem for the code segment since it is position independent. However, if the data segment is not loaded at the expected address, code will not be able to properly reference anything stored in the data segment.

事实上,我的装载机似乎做工精细用一个简单的集可执行文件不包含任何数据。但只要我添加了一个数据段和引用它,可执行无法正确或段错误运行。

Indeed, my loader appears to work fine with a simple assembly executable that does not contain any data. But as soon as I add a data segment and reference it, the executable fails to run correctly or SEGFAULTs.

如何,如果可能的话,我可以修正内容数据段的任何引用指向正确的位置?是否有存储在(静态)ELF文件用于此目的的拆迁款?

How, if possible, can I fixup any references to the data segment to point to the correct place? Is there a relocation section stored in the (static) ELF file for this purpose?

推荐答案

如果您修改.GOT部分提供的绝对地址(全局偏移表)你的程序应该工作。一定要修改的绝对地址计算,以应付的.text和。数据之间的新的距离,恐怕你需要弄清楚在这个信息来源,为您的架构。

If you modify the absolute addresses available in the .got section, (global offset table) your program should work. Make sure to modify the absolute address calculation to cater for the new distance between .text and .data, I'm afraid you need to figure out where this information comes from, for your architecture.

看到这个:全局偏移表(特定于处理器)

祝你好运。

这篇关于加载时ELF重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆