Is there a way to embed version info such as a git commit hash in an ELF executable such that it can be retrieved from core dumps generated from it?
Asked
Active
Viewed 287 times
1 Answers
1
See this question to get the git hash.
Then, change your build procedure (e.g. your Makefile
) to include it. For instance, generate a one line C file with
git log --pretty=format:'const char program_git_hash[] = "%H";' \
-n 1 > _prog_hash.c
then link your program with _prog_hash.c
and remove that file after linking.
You could add timestamping information with e.g.
date +'const char program_timestamp="%c";%n' >> _prog_hash.c
Then you could use gdb
or strings
on the binary executable to find it.
You may want to declare extern const char program_git_hash[];
in some header file, and perhaps display it (e.g. when passing the --version
option to your program)

Community
- 1
- 1

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
-
I found that running "strings
" and then searching for my git commit hash from the output solved the problem after following the above steps. – Kevin Feb 06 '14 at 16:55