[英]Easiest way to merge 2 or more ELF files
I'm working on some embedded code for a class project that currently (per requirements) creates a number of srec files and merges them.我正在为 class 项目开发一些嵌入式代码,该项目当前(根据要求)创建了许多 srec 文件并将它们合并。 I'd like to be able to load this code into QEMU, but it is generally only happy with ELF files.
我希望能够将此代码加载到 QEMU 中,但它通常只对 ELF 文件感到满意。 What is the esiest way to merge the original ELF files instead of the srecs.
合并原始 ELF 文件而不是 srecs 的最简单方法是什么? Also acceptable, a method to convert the srec back into an ELF and have the resulting file be loadable (objcopy seems to produce fairly broken files doing this (no architecture amoung others). The tools must be capable of working with m68k binaries, but the host system is plain x86.
也可以接受,一种将 srec 转换回 ELF 并使生成的文件可加载的方法(objcopy 似乎会产生相当损坏的文件(没有其他架构)。这些工具必须能够处理 m68k 二进制文件,但是主机系统是普通的 x86。
Please look at ELFIO library .请查看ELFIO 库。 It contains WriteObj and Writer examples.
它包含 WriteObj 和 Writer 示例。 By using the library, you will be able to create ELF binary files on different host platforms.
通过使用该库,您将能够在不同的主机平台上创建 ELF 二进制文件。
Easy... let's assume: a.c and b.c简单...让我们假设:a.c 和 b.c
gcc a.c -c -o a.o
gcc b.c -c -o b.o
ld -r a.o b.oc -o c.o
c.o now containes both ao and bo as a relocatable ELF file. c.o 现在包含 ao 和 bo 作为可重定位的 ELF 文件。
--Ivan ——伊万
Use your linker perhaps?也许使用您的 linker?
An srec file contains only the linked/located loadable binary, an elf file contains additional meta-data that is lost in the generation of the binary, so reversing back to elf may not be possible, especially if the elf needs to be relocatable. srec 文件仅包含链接/定位的可加载二进制文件,elf 文件包含在生成二进制文件时丢失的附加元数据,因此可能无法返回到 elf,尤其是当 elf 需要可重定位时。
I found the easiest solution to my original problem was actually to add SREC loading to qemu.我发现我最初的问题最简单的解决方案实际上是将 SREC 加载添加到 qemu。 I am already modifying the source to add board support, so SREC support isn't much additional work.
我已经在修改源代码以添加板支持,因此 SREC 支持并没有太多额外的工作。 I found some code on github from someone who had already done so and used it as a basis for my work.
我在 github 上找到了一些已经这样做的人的代码,并将其用作我工作的基础。
https://github.com/MegabytePhreak/qemu-mcf5307/commit/d3bceb911893b37b2524d6e804bac96691d4d33c https://github.com/MegabytePhreak/qemu-mcf5307/commit/d3bceb911893b37b2524d6e804bac96691d4d33c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.