Friday, 19 August 2011

Which version of the GCC compiled my program?

Here's a quick one-liner to find out which version of GCC was used to compile some code:

readelf -p .comment a.out

String dump of section '.comment':
  [     0]  GCC: (Ubuntu/Linaro 4.6.1-7ubuntu1) 4.6.1
  [    2a]  GCC: (Ubuntu/Linaro 4.6.1-6ubuntu6) 4.6.1


  1. most apps and libs on a running system do not have the sections that contain that info from what I saw so far

  2. Well, it is also very useful for checking the compiler used to compile kernel modules..

    readelf -p .comment /lib/modules/2.6.38-10-generic/kernel/drivers/acpi/video.ko