将源代码添加到elf文件 [英] Add source code to elf file

查看:241
本文介绍了将源代码添加到elf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将C ++源代码添加到相应的 elf 二进制文件中,我正在寻找实现此目的的最佳方法。 (我使用的是我的代码的多个版本,而不是每个版本都应该提交到svn中。)

I want to add my C++ source code to the corresponding elf binary file and I'm looking for the best way to do this. (I'm using several versions of my code and not every version should be committed into svn).

我可以仅添加源代码而不破坏 elf 文件使用bash的>> 运算符?
还是 objcopy --add-section 做到这一点的方法?

Can I just append the source code without destroying the elf file using bash's >> operator? Or is objcopy --add-section a way to do this?

还有一个更好的主意,就是从源代码文件中以 grep 递归所有 #include 行来确定所有源

By the way, is there a better idea that just grep'ing all #include lines recursively from the source code files to determine ALL source code files that are used?

推荐答案

如果使用的是gcc,则可以使用-M标志来获取带有所有包含文件的列表。它将被写入到-o指定的文件中,例如:

If you're using gcc you could use the -M flag to get a file with a list of all included files. It's written to the file specified with -o, like this:

gcc -M -c my_file.c -o list_of_included_files.txt

这篇关于将源代码添加到elf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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