How to embed version information into shared library and binary?

前端 未结 4 496
难免孤独
难免孤独 2020-12-17 21:06

On Linux, is there a way to embed version information into an ELF binary? I would like to embed this info at compile time so it can then be extract it using a script later.

4条回答
  •  旧时难觅i
    2020-12-17 21:32

    If you declare a variable called program_version or similar you can find out at which address the variable is stored at and then proceed to extract its value. E.g.

    objdump -t --demangle /tmp/libtest.so | grep program_version
    0000000000600a24 g     O .data  0000000000000004              program_version
    

    tells me that program_version resides at address 0000000000600a24 and is of size 4. Then just read the value at that address in the file.

    Or you could just write a simple program that links the library in questions and prints the version, defined either as an exported variable or a function.

提交回复
热议问题