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

后端 未结 4 1312
走了就别回头了
走了就别回头了 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:12

    Even if you don't have access to your source anymore, you can link the object with this option:

    gcc -Wl,--defsym,VERSION_1_2_3=0 prog.o -o prog
    

    You can check it with hexdump -C prog | less and look for VERSION


    Add this to your makefile and be sure to always know when a program was compiled:

    BUILD = $(shell date +"%Y%m%d_%H%M%S")
    LDLIBS = -Wl,--defsym,BUILD_$(BUILD)=0
    

提交回复
热议问题