Does gcc have any options to add version info in ELF binary file?

后端 未结 4 1311
走了就别回头了
走了就别回头了 2020-12-05 07:55

I mean whether gcc can insert some source code version infor into ELF binary as section or something similar. I do not want to change my source file, but add some info with

4条回答
  •  隐瞒了意图╮
    2020-12-05 08:08

    You can emit your version info into a text file, then turn that text file into an object file which you then statically link into your executable.

    The first step is simple but you have to write some code: a script or something to write your version info in any format you like as a plain text file. Then write a makefile rule to produce say version.o from version.txt, using objcopy. Now you'll have an object file with two useful symbols defined in it: the beginning and end of the textual version info. Add that generated object to your executable, and you'll be able to access the version two ways: by running strings on the binary, or by writing code in the application to print the version string (you'll need to declare the start and end symbols as variables in some header file).

提交回复
热议问题