Easiest way to merge 2 or more ELF files

穿精又带淫゛_ 提交于 2019-12-10 18:26:42

问题


I'm working on some embedded code for a class project that currently (per requirements) creates a number of srec files and merges them. I'd like to be able to load this code into QEMU, but it is generally only happy with ELF files. What is the esiest way to merge the original ELF files instead of the 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.


回答1:


Please look at ELFIO library. It contains WriteObj and Writer examples. By using the library, you will be able to create ELF binary files on different host platforms.




回答2:


Use your linker perhaps?

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.




回答3:


I found the easiest solution to my original problem was actually to add SREC loading to qemu. I am already modifying the source to add board support, so SREC support isn't much additional work. I found some code on github from someone who had already done so and used it as a basis for my work.

https://github.com/MegabytePhreak/qemu-mcf5307/commit/d3bceb911893b37b2524d6e804bac96691d4d33c




回答4:


Easy... let's assume : a.c and 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 a.o and b.o as a relocatable ELF file.

--Ivan



来源:https://stackoverflow.com/questions/6209832/easiest-way-to-merge-2-or-more-elf-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!