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?
相关问题
- Error building gcc 4.8.3 from source: libstdc++.so
- What are the recommended GNU linker options to spe
- What is the right order of linker flags in gcc?
- Why doesn't g++ -Wconversion warn about conver
- Where to get compiled version of gccxml on windows
相关文章
- gcc/g++ gives me error “CreateProcess: No such fil
- Calls that precede a function's definition can
- How can I use gcc's -I command to add recursiv
- How do I know if std::map insert succeeded or fail
- How to specify gcc flags (CXXFLAGS) particularly f
- How to generate assembly code with gcc that can be
- Embedding a program's source code into its bin
- What is the purpose of “-Wa,option” in GCC? [close
It is normally stored in the comment section
returns GCC: (GNU) X.X.X
returns no output
It is not uncommon to strip the .comment (as well as .note) section out to reduce size via
Note: busybox strings specifies the -a option by default, which is needed for the .comment section
Edit: Contrary to Berendra Tusla's answer, it does not need to be compiled with any debugging flags for this method to work.
Binary example:
Object example:
Note the absence of any -g (debugging) flags and the presence of the -s flag which strips unneeded symbols. The GCC info is still available unless the .comment section is removed. If you need to keep this info intact, you may need to check your makefile (or applicable build script) to verify that -fno-ident is not in your $CFLAGS and the $STRIP command lacks -R .comment. -fno-ident prevents gcc from generating these symbols in the comment section to begin with.
You can use the elfinfo utility. This also supports detecting the compiler versions of Go and FPC, in addition to GCC.
Yet another two ways (maybe a bit simpler) that I've just read about here: https://unix.stackexchange.com/questions/719/can-we-get-compiler-information-from-an-elf-binary
and
To complete what others have said: it's not stored in the object (or exe) file, unless you compile with debugging information! (option
-g
). If you compile with debug info, you can get it back withreadelf
:See how it says
GNU C 4.4.3 20100108 (prerelease)
.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:
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.
This information is not stored in the compiled object.