Lightning talk notes on binutils
Fangrui Song
i@maskray.me
Wed Jan 20 07:42:41 GMT 2021
Greetings, I will give a lightning talk in a small meetup on some GNU
toolchain projects and I am writing notes:)
Here is that I have now. Happy to see more points from you experts:)
## binutils
* Repository: <https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git>
* Mailing list: <https://sourceware.org/pipermail/binutils>
* Bugzilla: <https://sourceware.org/bugzilla/>
* Main tools: as (`gas/`, GNU assembler), ld (`ld/`, GNU ld), gold (`gold/`, GNU gold)
As of 2021-01, it has no wiki.
Target `all` builds targets `all-host` and `all-target`.
When running configure, by default most top-level directories `binutils gas gdb gdbserver ld libctf` are all enabled.
You can disable some components via `--disable-*`. `--enable-gold` is needed to enable gold.
```sh
mkdir Debug; cd Debug
../configure --target=x86_64-linux-gnu --prefix=/tmp/opt --disable-gdb --disable-gdbserver
```
For cross compiling, make sure your have `$target-{gcc,as,ld}`.
For many tools (binutils, gdb, ld), `--enable-targets=all` will build every supported architectures and binary formats.
However, one gas build can only support one architecture. ld has a default emulation and needs `-m` to support other architectures
(``aarch64 architecture of input file `a.o' is incompatible with i386:x86-64 output``).
Many tests are generic and can be run on many targets, but a `--enable-targets=all` build only tests its default target.
```sh
# binutils (binutils/*)
make -C Debug all-binutils
# gas (gas/as-new)
make -C Debug all-gas
# ld (ld/ld-new)
make -C Debug all-ld
# Build all enabled tools.
make -C Debug all
```
Build with Clang:
```sh
mkdir -p out/clang-debug; cd out/clang-debug
../../configure CC=~/Stable/bin/clang CXX=~/Stable/bin/clang++ CFLAGS='-O0 -g' CXXFLAGS='-O0 -g'
```
### Test
GNU Test Framework DejaGnu is based on Expect, which is in turn based on Tcl.
To run tests:
```sh
make -C Debug check-binutils
# Find the result in (summary) Debug/binutils/binutils.sum and (details) Debug/binutils/binutils.log
make -C Debug check-gas
# Find the result in (summary) Debug/gas/testsuite/gas.sum and (details) Debug/gas/testsuite/gas.log
make -C Debug check-ld
# Test all enabled tools.
make -C Debug check-all
```
For ld, tests are listed in `.exp` files under `ld/testsuite`.
A single test normally consists of a `.d` file and several associated `.s` files.
To run the tests in `ld/testsuite/ld-shared/shared.exp`:
```sh
make -C Debug check-ld RUNTESTFLAGS=ld-shared/shared.exp
```
## gdb
gdb resides in the binutils-gdb repository.
configure enables gdb and gdbserver by default. You just need to make sure `--disable-gdb --disable-gdbserver` is not on the configure line.
Run gdb under the build directory:
```sh
gdb/gdb -data-directory gdb/data-directory
```
To run the tests in `gdb/testsuite/gdb.dwarf2/dw2-abs-hi-pc.exp`:
```sh
make check-gdb RUNTESTFLAGS=gdb.dwarf2/dw2-abs-hi-pc.exp
# cd $build/gdb/testsuite/outputs/gdb.dwarf2/dw2-abs-hi-pc
```
More information about the Binutils
mailing list