Re: How to check what underlying commands are called by gcc?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 21, 2021 at 1:29 AM Peng Yu <pengyu.ut@xxxxxxxxx> wrote:
> I tried with hola.s below.
>
> https://cs.lmu.edu/~ray/notes/gasexamples/
>
> It seems that gcc -v -Wl,-v gives quite complex underlying commands.
> But most of the options are not useful.
>
> The minimal commands should be just the following (on Linux). Why are
> there so many irrelevant command line options passed down to ld?

If in addition to -v -Wl,-v you pass the compiler option -fno-lto, the
options pertaining to LTO (link-time optimization) will not appear.
So, you are left with the following parameters given to `/usr/bin/ld',
which is the static linker provided by the GNU Binutils project,
quoting your e-mail:

> --build-id

Not needed but may ease debugging [1].

> --eh-frame-hdr

Not needed [1] but required by some debugging standard [2].

> -m elf_x86_64
> --hash-style=gnu

Not needed because ld is built with some default [1].

> --as-needed

Not needed but may save some space [1].

> -dynamic-linker /lib64/ld-linux-x86-64.so.2

The dynamic linker, which is provided by the GNU C Library project.

> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
> /usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o

The C runtime, which is run to initialize the C library and then to
invoke the main function.  They are provided by the GNU C Library
project.

> -L/usr/lib/gcc/x86_64-linux-gnu/10
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib
> -L/lib/x86_64-linux-gnu
> -L/lib/../lib
> -L/usr/lib/x86_64-linux-gnu
> -L/usr/lib/../lib
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../..

Those are all paths where ld can additionally search for any library
mentioned down the line (e.g., -lgcc).  They are not needed if the
default search paths suffice [1].

> -v

Not needed [1].

> /tmp/mktemp/ccETAQ7Y.o

The object file to link.

> -lgcc

Not needed unless the object file needs something from libgcc.

> --push-state
> --as-needed
> -lgcc_s
> --pop-state

Not needed unless the object file needs something from libgcc_s.

> -lc

The C library.

> -lgcc

Either spurious repetition or repeated just in case libgcc_s needs
something from libgcc.

> --push-state
> --as-needed
> -lgcc_s
> --pop-state

Either spurious repetition or repeated just in case libgcc needs
something from libgcc_s.

> /usr/lib/gcc/x86_64-linux-gnu/10/crtend.o
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o

The C runtime, which is run to terminate the C library after returning
from the main function.  They are provided by the GNU C Library
project.

[1] https://sourceware.org/binutils/docs/ld/Options.html
[2] https://stackoverflow.com/a/26302715

> What
> do crt1.o, crti.o and crtn.o do in details? Thanks.

You should ask in the GNU C Library help mailing list [3].  Or, just
see the source code, for example, the comment at the start of [4],
which refers to [5].

[3] https://sourceware.org/mailman/listinfo/libc-help/
[4] https://sourceware.org/git/?p=glibc.git;a=blob;f=csu/Makefile;h=3054329cea4a276d5e2312e6b5d659192ff06423;hb=HEAD
[5] https://sourceware.org/git/?p=glibc.git;a=tree;f=elf;h=6063f27163949ad249e899fc1aa8c542c9a08ed3;hb=HEAD

> tmpfile=$(mktemp -u)
> as -o "$tmpfile" hola.s
> cmd=(
>         ld
>         -dynamic-linker /lib64/ld-linux-x86-64.so.2
>         /usr/lib/x86_64-linux-gnu/crt1.o
>         /usr/lib/x86_64-linux-gnu/crti.o
>         /usr/lib/x86_64-linux-gnu/crtn.o
>         -lc
>         "$tmpfile"
> )
> "${cmd[@]}"
>
>
> $ gcc -Wl,-v -v -no-pie hola.s
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
> OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
> OFFLOAD_TARGET_DEFAULT=1
> Target: x86_64-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Debian
> 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
> --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2
> --prefix=/usr --with-gcc-major-version-only --program-suffix=-10
> --program-prefix=x86_64-linux-gnu- --enable-shared
> --enable-linker-build-id --libexecdir=/usr/lib
> --without-included-gettext --enable-threads=posix --libdir=/usr/lib
> --enable-nls --enable-bootstrap --enable-clocale=gnu
> --enable-libstdcxx-debug --enable-libstdcxx-time=yes
> --with-default-libstdcxx-abi=new --enable-gnu-unique-object
> --disable-vtable-verify --enable-plugin --enable-default-pie
> --with-system-zlib --enable-libphobos-checking=release
> --with-target-system-zlib=auto --enable-objc-gc=auto
> --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
> --with-multilib-list=m32,m64,mx32 --enable-multilib
> --with-tune=generic
> --enable-offload-targets=nvptx-none=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-gcn/usr,hsa
> --without-cuda-driver --enable-checking=release
> --build=x86_64-linux-gnu --host=x86_64-linux-gnu
> --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean
> --enable-link-mutex
> Thread model: posix
> Supported LTO compression algorithms: zlib zstd
> gcc version 10.2.1 20210110 (Debian 10.2.1-6)
> COLLECT_GCC_OPTIONS='-v' '-no-pie' '-mtune=generic' '-march=x86-64'
>  as -v --64 -o /tmp/mktemp/ccETAQ7Y.o hola.s
> GNU assembler version 2.35.2 (x86_64-linux-gnu) using BFD version (GNU
> Binutils for Debian) 2.35.2
> COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/
> LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/
> COLLECT_GCC_OPTIONS='-v' '-no-pie' '-mtune=generic' '-march=x86-64'
>  /usr/lib/gcc/x86_64-linux-gnu/10/collect2 -plugin
> /usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so
> -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
> -plugin-opt=-fresolution=/tmp/mktemp/ccBVaooZ.res
> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s
> -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc
> -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m
> elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker
> /lib64/ld-linux-x86-64.so.2
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
> /usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o
> -L/usr/lib/gcc/x86_64-linux-gnu/10
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib
> -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu
> -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/10/../../.. -v
> /tmp/mktemp/ccETAQ7Y.o -lgcc --push-state --as-needed -lgcc_s
> --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state
> /usr/lib/gcc/x86_64-linux-gnu/10/crtend.o
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
> collect2 version 10.2.1 20210110
> /usr/bin/ld -plugin /usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so
> -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
> -plugin-opt=-fresolution=/tmp/mktemp/ccBVaooZ.res
> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s
> -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc
> -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m
> elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker
> /lib64/ld-linux-x86-64.so.2
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
> /usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o
> -L/usr/lib/gcc/x86_64-linux-gnu/10
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu
> -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib
> -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu
> -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/10/../../.. -v
> /tmp/mktemp/ccETAQ7Y.o -lgcc --push-state --as-needed -lgcc_s
> --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state
> /usr/lib/gcc/x86_64-linux-gnu/10/crtend.o
> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
> GNU ld (GNU Binutils for Debian) 2.35.2
> COLLECT_GCC_OPTIONS='-v' '-no-pie' '-mtune=generic' '-march=x86-64'
>
> --
> Regards,
> Peng

-- 
Best regards,
Tadeus




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux