admin管理员组文章数量:1389496
I'm working on an educational project where I want to implement a position-independent executable (PIE) on a Cortex-M microcontroller, using the ARM GNU toolchain. The goal is to write a simple loader that can load such a binary at runtime and relocate it to any address in memory.
I compile my code with -fPIE
and link it with -pie
. As a result, the ELF file includes several sections that are relevant for relocation, such as .rel.dyn
, .got
, .got.plt
, and .dynamic
.
My current plan is not to parse the ELF directly, instead, my loader will load a raw binary image, which contains all the sections. For each of these sections, I have external information (such as offsets and sizes), so the loader knows where each section starts, how large it is, and how to map it into memory.
From what I understand so far:
- The
.rel.dyn
section contains relocation entries. In my builds, all the entries are of typeR_ARM_RELATIVE
(0x17), which, as far as I know, means that the loader just needs to add the base load address to the values at the specified offsets. - The
.got
section is also present and seems to be involved in relocations, but there are no relocation entries for.got.plt
. I'm not sure whether.got.plt
needs to be updated manually in this scenario. - There is also a
.dynamic
section, which I assume is used for dynamic linking. Since I'm not performing dynamic linking on Cortex-M, I'm wondering if it has any relevance to my loader, or if it can be ignored.
My objective is to understand how to implement a minimal loader for a PIE executable on Cortex-M:
- Which steps are necessary for the loader to relocate the binary properly.
- Which sections I need to process, and what operations are required to initialize them.
Any guidance or example code on how to build such a loader would be highly appreciated.
本文标签: gccwriting a loader for position independent executablesStack Overflow
版权声明:本文标题:gcc - writing a loader for position independent executables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744591926a2614542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论