Search notes:

gcc --version

gcc --version and g++ --version print the version of the compiler.

Writing compiler information into .comment section

GCC (as well as Clang) write the compiler's version into an object file's .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

See also

GCC options

Index