Questo contenuto non è disponibile nella lingua selezionata.
Chapter 4. binutils
binutils is a collection of various binary tools, such as the GNU linker, GNU assembler, and other utilities that allow you to inspect and manipulate object files and binaries. See Table 4.1, “Tools Included in binutils for Red Hat Developer Toolset” for a complete list of binary tools that are distributed with the Red Hat Developer Toolset version of binutils.
Red Hat Developer Toolset is distributed with binutils 2.36.1. This version is more recent than the version included in Red Hat Enterprise Linux and the previous release of Red Hat Developer Toolset and provides bug fixes and enhancements.
Name | Description |
---|---|
| Translates addresses into file names and line numbers. |
| Creates, modifies, and extracts files from archives. |
| The GNU assembler. |
| Decodes mangled C++ symbols. |
| Combines DWARF object files into a single DWARF package file. |
| Examines and edits ELF files. |
| Display profiling information. |
| The GNU linker. |
| An alternative to the GNU linker. |
| Another alternative to the GNU linker. |
| Lists symbols from object files. |
| Copies and translates object files. |
| Displays information from object files. |
| Generates an index to the contents of an archive to make access to this archive faster. |
| Displays information about ELF files. |
| Lists section sizes of object or archive files. |
| Displays printable character sequences in files. |
| Discards all symbols from object files. |
4.1. Installing binutils
In Red Hat Developer Toolset, binutils are provided by the devtoolset-12-binutils package and are automatically installed with devtoolset-12-toolchain as described in Section 1.5, “Installing Red Hat Developer Toolset”.
4.2. Using the GNU Assembler
To produce an object file from an assembly language program, run the as
tool as follows:
$ scl enable devtoolset-12 'as option ... -o object_file source_file'
This creates an object file named object_file in the current working directory.
Note that you can execute any command using the scl
utility, causing it to be run with the Red Hat Developer Toolset binaries used in preference to the Red Hat Enterprise Linux system equivalent. This allows you to run a shell session with Red Hat Developer Toolset as
as default:
$ scl enable devtoolset-12 'bash'
To verify the version of as
you are using at any point:
$ which as
Red Hat Developer Toolset’s as
executable path will begin with /opt
. Alternatively, you can use the following command to confirm that the version number matches that for Red Hat Developer Toolset as
:
$ as -v
4.3. Using the GNU Linker
To create an executable binary file or a library from object files, run the ld
tool as follows:
$ scl enable devtoolset-12 'ld option ... -o output_file object_file ...'
This creates a binary file named output_file in the current working directory. If the -o
option is omitted, the compiler creates a file named a.out
by default.
Note that you can execute any command using the scl
utility, causing it to be run with the Red Hat Developer Toolset binaries used in preference to the Red Hat Enterprise Linux system equivalent. This allows you to run a shell session with Red Hat Developer Toolset ld
as default:
$ scl enable devtoolset-12 'bash'
To verify the version of ld
you are using at any point:
$ which ld
Red Hat Developer Toolset’s ld
executable path will begin with /opt
. Alternatively, you can use the following command to confirm that the version number matches that for Red Hat Developer Toolset ld
:
$ ld -v
4.4. Using Other Binary Tools
The binutils provide many binary tools other than a linker and an assembler. For a complete list of these tools, see Table 4.1, “Tools Included in binutils for Red Hat Developer Toolset”.
To execute any of the tools that are a part of binutils:
$ scl enable devtoolset-12 'tool option ... file_name'
See Table 4.1, “Tools Included in binutils for Red Hat Developer Toolset” for a list of tools that are distributed with binutils. For example, to use the objdump
tool to inspect an object file:
$ scl enable devtoolset-12 'objdump option ... object_file'
Note that you can execute any command using the scl
utility, causing it to be run with the Red Hat Developer Toolset binaries used in preference to the Red Hat Enterprise Linux system equivalent. This allows you to run a shell session with Red Hat Developer Toolset binary tools as default:
$ scl enable devtoolset-12 'bash'
To verify the version of binutils you are using at any point:
$ which objdump
Red Hat Developer Toolset’s objdump
executable path will begin with /opt
. Alternatively, you can use the following command to confirm that the version number matches that for Red Hat Developer Toolset objdump
:
$ objdump -v
4.5. Specifics of binutils in Red Hat Developer Toolset
Static linking of libraries
Certain more recent library features are statically linked into applications built with Red Hat Developer Toolset to support execution on multiple versions of Red Hat Enterprise Linux. This creates an additional minor security risk as standard Red Hat Enterprise Linux errata do not change this code. If the need arises for developers to rebuild their applications due to this risk, Red Hat will communicate this using a security erratum.
Because of this additional security risk, developers are strongly advised not to statically link their entire application for the same reasons.
Specify libraries after object files when linking
In Red Hat Developer Toolset, libraries are linked using linker scripts which might specify some symbols through static archives. This is required to ensure compatibility with multiple versions of Red Hat Enterprise Linux. However, the linker scripts use the names of the respective shared object files. As a consequence, the linker uses different symbol handling rules than expected, and does not recognize symbols required by object files when the option adding the library is specified before options specifying the object files:
$ scl enable devtoolset-12 'ld -lsomelib objfile.o'
Using a library from the Red Hat Developer Toolset in this manner results in the linker error message undefined reference to symbol
. To prevent this problem, follow the standard linking practice, and specify the option adding the library after the options specifying the object files:
$ scl enable devtoolset-12 'ld objfile.o -lsomelib'
Note that this recommendation also applies when using the base Red Hat Enterprise Linux version of binutils.
4.6. Additional Resources
For more information about binutils, see the resources listed below.
Installed Documentation
as(1), ld(1), addr2line(1), ar(1), c++filt(1), dwp(1), elfedit(1), gprof(1), nm(1), objcopy(1), objdump(1), ranlib(1), readelf(1), size(1), strings(1), strip(1), — Manual pages for various binutils tools provide more information about their respective usage. To display a manual page for the version included in Red Hat Developer Toolset:
$
scl enable devtoolset-12 'man tool'
Online Documentation
- Documentation for binutils — The binutils documentation provides an in-depth description of the binary tools and their usage.
See Also
- Chapter 1, Red Hat Developer Toolset — An overview of Red Hat Developer Toolset and more information on how to install it on your system.
- Chapter 5, elfutils — Information on how to use elfutils, a collection of binary tools to inspect and manipulate ELF files.
- Chapter 2, GNU Compiler Collection (GCC) — Information on how to compile programs written in C, C++, and Fortran.