Tutorials, Guides, Tips, and Tricks from Everyday Experiences

Today I was asked to compile a program for one of the SBCs that I work with. The difficulty was in trying to choose the correct cross-compiling toolchain. Since there were several different toolchains each with a different version of gcc and glibc, I wanted to know what other utilities like ‘ls’ were compiled with so I had a good idea of which toolchain to use. I found several different methods of finding a suitable toolchain.

A good place to start is on the target system itself, and if it has ldd and gcc installed, then it’s as easy as using:

ldd --version
gcc --version

Another not-so-obvious method to find all information including gcc and glibc versions is simply using (may not work on all systems):

/lib/libc.so.6

If the above doesn’t work, there is yet another solution and that is to actually compile this short program and run it so that it spits out the glibc version used:

It may not be as common, but if a binary has not yet been stripped of it’s comments and extras you can use objdump and objcopy to view information about that file. For example, the following command will use objcopy to spit out the section named .comment within the /bin/ls binary to the /tmp/foobar file. The strings command will then spit out readable text from which you can derive the glibc and/or gcc version that was used to compile the binary. Again, keep in mind that this may not work for every binary. Use the objdump command to see which other fields are available.

objcopy -j .comment /bin/ls /tmp/foobar; strings /tmp/foobar

If you have any more methods for extracting this sort of information out of an already-compiled binary, I’d love to hear about it in the comments.

Related

Feel free to
donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in: