GCC ident strings

I just needed to get the GCC version a binary was build with, it’s included in the .comment section and there’re quite a few ways to obtain it:

  • objdump

$ objdump -s -j.comment $BINARY

main.o:     file format elf64-x86-64
Contents of section .comment:
0000 00474343 3a202855 62756e74 7520342e  .GCC: (Ubuntu 4.
0010 332e332d 35756275 6e747534 2920342e  3.3-5ubuntu4) 4.
0020 332e3300                             3.3.

  • strings

$ strings -a $BINARY | grep GCC

GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3

  • grep

$ grep -aoE 'GCC:[]a-zA-Z0-9:()., -[]+' $BINARY

GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3

The above examples all operate on a single main.o, that’s why there’s so little output.