Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cfstras/9f94a710c90d0161f23d to your computer and use it in GitHub Desktop.
Save cfstras/9f94a710c90d0161f23d to your computer and use it in GitHub Desktop.
Build static versions of binutils, for example ld, gprof, nm, strip, objdump, ar, strings; with mingw or on *nix
See the bash script below. :)
Tested on debian bookworm-slim (`docker pull debian:bookworm-slim`).
### Prerequisites
```bash
apt update
apt install -y build-essential wget bison
```
### Build
```bash
wget https://gist.githubusercontent.com/cfstras/9f94a710c90d0161f23d/raw/build.sh
chmod a+x build.sh
./build.sh
```
#!/bin/bash
set -euo pipefail
VERSION=2.41
[[ -s "binutils-$VERSION.tar.gz" ]] || wget "http://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.gz"
tar xzf "binutils-$VERSION.tar.gz"
cd "binutils-$VERSION"
./configure --disable-nls --prefix="$(pwd)/bin"
make configure-host
make LDFLAGS="-all-static"
make install
echo "output in binutils-$VERSION/bin/bin:"
ls bin/bin
@Ezbob
Copy link

Ezbob commented Jun 22, 2020

I was surprised that this works, but I just tried this with binutils 2.34 and it work like a charm too! Thanks!

@Ezbob
Copy link

Ezbob commented Jun 22, 2020

You can also use make install-strip to shrink the binary sizes when installing

@yakamoz423
Copy link

yakamoz423 commented Jul 12, 2023

Awesome! I build binutils-2.40 on MSYS2 (MinGW x86_64), by configuring with --enable-targets=all to obtain binutils-multiarch version, and it works too!

@polaco1782
Copy link

Thank you! It is exactly I was looking for, it did work flawlessly!

@cbpudding
Copy link

Still works with binutils 2.41. Thanks!

@rubyFeedback
Copy link

prdbg.c: In function 'tg_class_baseclass':
prdbg.c:2220:7: warning: 'free' called on a pointer to an unallocated object '18446744073709551610' [-Wfree-nonheap-object]
2220 | free (t);
| ^~~~~~~~
prdbg.c: In function 'pr_class_baseclass':
prdbg.c:1311:7: warning: 'free' called on a pointer to an unallocated object '18446744073709551610' [-Wfree-nonheap-object]
1311 | free (t);
| ^~~~~~~~
CC demanguse.o
CC rddbg.o
CC debug.o
CC stabs.o
CC rdcoff.o
CC elfcomm.o
make[4]: *** No rule to make target '../libctf/libctf.la', needed by 'objdump'. Stop.
make[4]: Leaving directory '/Depot/jjjj/binutils-28.03.2024/binutils'

I got some errors ... :(

@cfstras
Copy link
Author

cfstras commented Mar 29, 2024

@rubyFeedback Just tested this successfully on Debian bookworm -- what OS and compiler are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment