How to retrieve the GCC version used to compile a given ELF executable?

后端 未结 5 675
北恋
北恋 2020-11-27 10:28

I\'d like to retrieve the GCC version used to compile a given executable. I tried readelf but didn\'t get the information. Any thoughts?

5条回答
  •  猫巷女王i
    2020-11-27 11:11

    This information is not stored in the compiled object (c).

    Actually, for C code you're totally out of luck. However, for C++ code you may find some information from symbol versions. Some functions from C++ runtime libraries are version-specific, and are marked as such in object files. Try this:

    readelf -Wa file.exe | grep 'GCC[[:alnum:]_.]*' --only-match | sort | uniq | tail -n 1
    

    It won't show you the version of GCC used, however. What it shows is the version of symbols in runtime supplied to the compiler. Usually the runtime is that of a compiler shipment, and its version is not less than the one shown with the above command.

提交回复
热议问题