.comment раздел показывает 3 разных компилятора? - PullRequest
2 голосов
/ 17 июня 2019

Я получил внешний файл .so и запустил:

objdump -s --section .comment /opt/lib64/libexternal.so

Он напечатал:

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 2d342900 4743433a  at 4.4.7-4).GCC:
 0030 2028474e 55292036 2e322e31 20323031   (GNU) 6.2.1 201
 0040 36303931 36202852 65642048 61742036  60916 (Red Hat 6
 0050 2e322e31 2d332900 4743433a 2028474e  .2.1-3).GCC: (GN
 0060 55292034 2e382e35 20323031 35303632  U) 4.8.5 2015062
 0070 33202852 65642048 61742034 2e382e35  3 (Red Hat 4.8.5
 0080 2d342900                             -4).            

Есть идеи, почему в файле .so есть 3 разные версии gcc?Это также звучит как .so содержит объектные файлы, скомпилированные 3-мя различными компиляторами gcc?

Я только что провел небольшой эксперимент, в котором скомпилировал следующий код:

#include <iostream>

int main() {
    std::cout << "hello" << std::endl;
}

Скомпилировано с:

$ g++ -v -Wall test_comment_section.cpp -o test_comment_section -O3 -lrt -g3 -ggdb3
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.2.1-20180905/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'test_comment_section' '-O3' '-g3' '-ggdb3' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/cc1plus -quiet -v -dD -D_GNU_SOURCE test_comment_section.cpp -quiet -dumpbase test_comment_section.cpp -mtune=generic -march=x86-64 -auxbase test_comment_section -g3 -ggdb3 -O3 -Wall -version -o /tmp/cc5RMnqk.s
GNU C++14 (GCC) version 8.2.1 20180905 (Red Hat 8.2.1-3) (x86_64-redhat-linux)
    compiled by GNU C version 8.2.1 20180905 (Red Hat 8.2.1-3), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/include-fixed"
ignoring nonexistent directory "/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8
 /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux
 /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward
 /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/include
 /usr/local/include
 /opt/rh/devtoolset-8/root/usr/include
 /usr/include
End of search list.
GNU C++14 (GCC) version 8.2.1 20180905 (Red Hat 8.2.1-3) (x86_64-redhat-linux)
    compiled by GNU C version 8.2.1 20180905 (Red Hat 8.2.1-3), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9b29ab96dbb89418adcb25277f32b267
COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'test_comment_section' '-O3' '-g3' '-ggdb3' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/as -v --64 -o /tmp/ccdlEH9g.o /tmp/cc5RMnqk.s
GNU assembler version 2.30 (x86_64-redhat-linux) using BFD version version 2.30-47.el7
COMPILER_PATH=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/:/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/:/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/:/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/:/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/:/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'test_comment_section' '-O3' '-g3' '-ggdb3' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/collect2 -plugin /opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/liblto_plugin.so -plugin-opt=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/ccLbovWd.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test_comment_section /lib/../lib64/crt1.o /lib/../lib64/crti.o /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o -L/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8 -L/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../.. /tmp/ccdlEH9g.o -lrt -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/crtend.o /lib/../lib64/crtn.o
COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'test_comment_section' '-O3' '-g3' '-ggdb3' '-shared-libgcc' '-mtune=generic' '-march=x86-64'

А затем выкинул раздел .comment:

test_comment_section:     file format elf64-x86-64

Contents of section .comment:
 0000 4743433a 2028474e 55292034 2e382e35  GCC: (GNU) 4.8.5
 0010 20323031 35303632 33202852 65642048   20150623 (Red H
 0020 61742034 2e382e35 2d333629 00474343  at 4.8.5-36).GCC
 0030 3a202847 4e552920 382e322e 31203230  : (GNU) 8.2.1 20
 0040 31383039 30352028 52656420 48617420  180905 (Red Hat 
 0050 382e322e 312d3329 00                 8.2.1-3).       

Мысль?

1 Ответ

2 голосов
/ 18 июня 2019

Не путайте компиляцию и компоновку.Различные части библиотеки компилируются здесь с разными компиляторами.Затем они объединяются в одну библиотеку (.so), и .comment разделы входных файлов подвергаются процессу объединения.

Что касается вашего test_comment_section примера, см. .comment разделы всехфайлы, присутствующие в командной строке компоновщика (такие же, как у collect2), они отображаются в gcc -v вставленном вами результате.Имена связанных файлов:

/lib/../lib64/crt1.o
/lib/../lib64/crti.o
/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o
/tmp/ccdlEH9g.o # -- that's the assembler output for your file. If you want sane names, supply `-save-temps` to gcc.
/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/crtend.o
/lib/../lib64/crtn.o

Обратите внимание, что динамические библиотеки не имеют значения, поскольку они не связаны с вашего исполняемого файла, ваш исполняемый файл просто связаны с им.

...