Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • 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
@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