gcc --version and g++ --version print the version of the compiler. .comment section: $ echo 'void f() {}' | gcc -xc -c -o f.obj -
$ readelf -p .comment f.obj
String dump of section '.comment':
[ 1] GCC: (Debian 10.2.1-6) 10.2.1 20210110
$ gcc --version | head -1
gcc (Debian 10.2.1-6) 10.2.1 20210110