Add source code to elf file

I want to add C ++ source code to the corresponding elf binary, and I'm looking for a better way to do this. (I use several versions of my code, and not every version has to be transferred to svn).

Is it possible to simply add the source code without destroying the elf file using the bash >> operator? Or is it an objcopy --add-section way to do this?

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

+4
source share
2 answers

If you use gcc, you can use the -M flag to get a file listing all of the included files. It is written to the file specified with -o as follows:

 gcc -M -c my_file.c -o list_of_included_files.txt 
+1
source

You can get the preprocessor output from most C / C ++ compilers using the -E option on the command line, for example,

 g++ -E my_file.c -o my_file_preproc.c 

objcopy is an easy bet, but today I came across an ELF resource compiler and it may be useful for you. It allows you to embed everything you want into an ELF file, and even generate C / C ++ code so you can add it. That way, you can even create a library with which your code could link to it to print the source for the executable directly from the executable.

Which brings up another idea ... and not just include all the pre-processed source code, you could provide the executable with the option to print the equations used.

+2
source

Source: https://habr.com/ru/post/912937/


All Articles