Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the compiler version appear in my ELF executable?

Tags:

c

linux

gcc

elf

I've recently compiled a simple hello world C program under Debian Linux using gcc:

gcc -mtune=native -march=native -m32 -s -Wunused -O2 -o hello hello.c

The file size was 2980 bytes. I opened it in a hex editor and i saw the following lines:

GCC: (Debian 4.4.5-8) 4.4.5 GCC: (Debian 4.4.5-10) 4.4.5 .shstrtab .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .text .fini .rodata .eh_frame .ctors .dtors .jcr .dynamic .got .got.plt data.data .bss .comment

Are they really needed? No way to reduce executable size?

like image 547
dan.dev.01 Avatar asked Jun 07 '11 09:06

dan.dev.01


People also ask

What is ELF in compiler?

In computing, the Executable and Linkable Format (ELF, formerly named Extensible Linking Format), is a common standard file format for executable files, object code, shared libraries, and core dumps.

How do I know which gcc version I have?

gcc --version will tell you the version of the gcc executable in your path. rpm -q libstdc++-devel will tell you the version of the package that owns the C++ standard library headers.

How can I tell which compiler I have in Linux?

If you want to check if the GNU GCC Compilers are install on your system, you can try to check the version of GCC compiler on Linux, or you can use which command to locate gcc or g++ commands . devops@devops-osetc:~$ gcc --version gcc (Ubuntu 5.4.

How do I know what version of gcc is binary?

comment section from the binary to find the version string. Use objdump and add --section to specify section name. For example, if your compiled a program named foo in the source dir, you can run the following commands to get GCC's version info: $ objdump -s --section .


1 Answers

use -Qn to avoid that.

aa$ touch hello.c
aa$ gcc -c hello.c 
aa$ objdump -s hello.o 

hello.o:     file format elf32-i386

Contents of section .comment:
 0000 00474343 3a202844 65626961 6e20342e  .GCC: (Debian 4.
 0010 372e322d 35292034 2e372e32 00        7.2-5) 4.7.2.   
aa$ gcc -Qn -c hello.c 
aa$ objdump -s hello.o 

hello.o:     file format elf32-i386

aa$ gcc -v 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.7/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5) 
aa$ 
like image 152
swigger Avatar answered Sep 23 '22 04:09

swigger