我说的 GCC 版本可不是指的「gcc –version」,而是指的上到 Linux 内核,下到 PHP 之类的软件,是用哪个版本的 GCC 编译的。
先看看如何判断 Linux 内核是用什么版本的 GCC 编译的?
shell> cat /proc/version ... (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) ...
再看看如何判断 PHP 之类的软件是用什么版本的 GCC 编译的?
shell> objdump -s --section .comment /usr/local/bin/php /usr/local/bin/php: file format elf64-x86-64 Contents of section .comment: 0000 4743433a 2028474e 55292034 2e342e37 GCC: (GNU) 4.4.7 0010 20323031 32303331 33202852 65642048 20120313 (Red H 0020 61742034 2e342e37 2d313129 00474343 at 4.4.7-11).GCC 0030 3a202847 4e552920 342e342e 37203230 : (GNU) 4.4.7 20 0040 31323033 31332028 52656420 48617420 120313 (Red Hat 0050 342e342e 372d3429 00 4.4.7-4).
或者
shell> readelf -p .comment /usr/local/bin/php String dump of section '.comment': [ 0] GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-11) [ 2d] GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-4)
知道这些有什么价值呢?因为视 GCC 版本的不同,可能会有各种各样的 BUG 或者性能问题,所以知晓如何判断 GCC 版本还是有意义的。比如我测试 tcp-recv-queue 的时候一直不成功,后来才发现它要求 Linux 内核必须用 GCC4.5+ 的版本编译才行。