简体   繁体   English

合并 2 个或更多 ELF 文件的最简单方法

[英]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.

相关问题 将ELF可执行文件拆分为嵌入式系统中的两个文件 - Splitting an ELF executable into two files in an embedded system ELF文件中的程序标题和节标题 - program headers and section headers in ELF files elf 文件中各节的虚拟地址和物理地址 - virtual and physical addresses of sections in elf files 有没有一种方法可以从ELF中提取符号,然后使用LD将另一个文件与前一个ELF中定义的符号链接在一起? - Is there a way to extract the symbols from a ELF, and use LD to link another file together with the symbols defined in the previous ELF? 从多少个可重定位文件中构建一个 Elf 执行文件? - from how many Relocatable files an Elf execution file Built from? 生成 elf 文件时 linker 脚本文件如何工作 - How linker script files work when generate elf file 自定义 ELF 文件中未定义的引用,但符号在文件符号表中定义 - Undefined reference in a custom ELF file, but the symbol is defined in the files symbol table ELF:链接:为什么我在.so文件中获得未定义的引用 - ELF: linking: Why do I get undefined references in .so files ARM链接器ELF。 需要一种获取信息的方法 - ARM linker ELF. Need a way to derive information 将 xo65 对象文件与 ELF 对象和 LLVM IR 文件链接起来 - Linking xo65 object files with ELF objects and LLVM IR files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM