Skip to content

Commit 5237c49

Browse files
committed
Updated readme
1 parent e605709 commit 5237c49

File tree

1 file changed

+60
-43
lines changed

1 file changed

+60
-43
lines changed

‎README.md‎

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,38 @@
1-
## Build Scripts and Toolchain Helpers
1+
## Build Scripts and Toolchain Helpers, also known as "how do I build a statically linked gdbserver"
22

3-
"For when you don't quite need crosstool-ng or buildroot- you just need to build a few binaries, and you have a root to work from"
3+
First things first, I apologize for the poor documentation but I did not intend to write any. Hopefully it's better than nothing
44

5-
* ```activate-openwrt-toolchain.env``` - place file in prebuilt OpenWRT toolchain root, source it for productivity, etc.
6-
* ```activate-musl-toolchain.env``` - place file in musl-cross-make toolchain root, source it for productivity, etc.
7-
* ```gdbserver-7.12-static-build.sh``` - shell script to build a static gdb-7.12 gdbserver using a cross-compile toolchain
5+
### What this repository is NOT
86

9-
### First - if you just want to grab a statically linked gdbserver for a specific MIPS(EL) or ARM platform ...
7+
This repository is not a toolchain or a toolchain builder
108

11-
Check out https://github.com/mzpqnxow/arm-mips-tools as it contains a substantial collection of gdbserver binaries that have been well tested on many different architectures of varying ABIs, byte-orders and CPU architectures. Why build when you can borrow or steal, right? They aren't backdoored :)
9+
### What this repository *kind of* is
1210

13-
### Second - If you just want to build a *native* gdb-7.12 gdbserver statically on your host machine
11+
A HOWTO on building a statically linked gdbserver without much hacking
1412

15-
You don't need any of this. These scripts just simplify doing it with different toolchains. If you're doing it natively it can be summarized pretty quickly.
13+
### What this repository IS when fully utilized
1614

17-
#### Find static libraries you will need to link gdbserver with
15+
This repository is for when you don't need something as heavy as crosstool-ng or buildroot. You just need to cross-compile and statically link a few binaries, for example gdbserver, and you have musl/uClibc/glibc toolchain to work from already built. This focuses on gdb-7.12, but you can use these scripts in one form or another when building just about anything, though you will need to modify them from time to time to suit your needs. While they function out of the box for my needs, it is best you think of them as living documentation / reference material for a simpleish task that can be confusing for first-timers, and slow for veterans
1816

19-
You will need to make sure you have libstdc++.a and libgcc_eh.a on your system. If you don't know what you're doing, you can just use find. Try using the following:
17+
* `activate-openwrt-toolchain.env` - place file in prebuilt OpenWRT toolchain root, source it for productivity, etc.
18+
* `activate-musl-toolchain.env` - place file in musl-cross-make toolchain root, source it for productivity, etc.
19+
* `gdbserver-7.12-static-build.sh` - shell script to build a static gdb-7.12 gdbserver using a cross-compile toolchain. Should be executed from gdb-7.12-/gdb/gdbserver/
2020

21-
```
22-
$ find /l* /u* -name libgcc_eh.a
23-
$ find /l* /u* -name libstdc++.a
24-
```
25-
26-
#### Perform the build
21+
### ATTENTION!
2722

28-
```
29-
$ wget https://ftp.gnu.org/gnu/gdb/gdb-7.12.tar.xz
30-
$ tar -xvf gdb-7.12.tar.xz
31-
$ cd gdb-7.12/gdb/gdbserver
32-
$ sed -i -e 's/srv_linux_thread_db=yes//' configure.srv
33-
$ ./configure --prefix=/opt/gdbserver-7.12-static CXXFLAGS='fPIC -static'
34-
$ make -j gdbserver GDBSERVER_LIBS="/path/to/libstdc++.a /path/to/libgcc_eh.a"
35-
```
23+
***If you just want to download a statically linked gdbserver for a specific MIPS(EL) or ARM platform, check the src/ directory***
3624

37-
#### FIN
25+
Just look in the in the *prebuilt* directory. I attempted to compile builds as portable as possible (i.e. emulating FP in software) and got a lot out of use of them, so you should find them somewhat reliable on Linux based embedded devices
3826

39-
You will have a statically compiled GDB 7.12 gdbserver for your native OS. Read on for the cross-compile stuff, which is a little more involved but still pretty simple
27+
### If you want to build things other than gdbserver
4028

41-
### Use ```activate-openwrt-toolchain.env``` with a pre-built OpenWrt Toolchain
29+
Some open source projects have no build system, and many have very strange custom build systems that don't use the "standard" `./configure && make && make install` style build system . You can check out [embedded-toolkt](https://github.com/mzpqnxow/embedded-toolkit) and look in the [src](https://github.com/mzpqnxow/embedded-toolkit/tree/master/src) directory for examples of using these scripts before building various tools such as *gawk*, *gdbserver*, *tcpdump*, *libpcap*, *lsof*, *etc* which have some unique build systems, especially lsof- wtf?
4230

43-
Browse to https://downloads.openwrt.org/snapshots/trunk/ to find your toolchain
31+
## OpenWrt: Use `source activate-openwrt-toolchain.env` with a pre-built OpenWrt Toolchain
4432

45-
To use this script, assume you have a directory called /toolchains/ and that this is where you will keep the toolchains, one subdirectory per toolchain. You're a maniac- you're hoarding toolchains and probably up to no good.
33+
To use `activate-openwrt-toolchain.env` with a pre-built OpenWrt Toolchain you can dollow these simple steps. First browse to [https://downloads.openwrt.org/snapshots/trunk/](https://downloads.openwrt.org/snapshots/trunk/) to find your toolchain
4634

47-
To get a new toolchain up in such a way to use active-openwrt-toolchain, grab a file like OpenWrt-Toolchain-brcm63xx-generic_gcc-5.3.0_musl-1.1.16.Linux-x86_64.tar.bz2
35+
To use this script, assume you have a directory called /toolchains/ and that this is where you will keep the toolchains, one subdirectory per toolchain. You're a maniac- you're hoarding toolchains and probably up to no good. To get a new toolchain up in such a way to use active-openwrt-toolchain, grab a file like [OpenWrt-Toolchain-brcm63xx-generic_gcc-5.3.0_musl-1.1.16.Linux-x86_64.tar.bz2](https://downloads.openwrt.org/snapshots/trunk/brcm63xx/generic/OpenWrt-Toolchain-brcm63xx-generic_gcc-5.3.0_musl-1.1.16.Linux-x86_64.tar.bz2)
4836

4937

5038
```
@@ -59,14 +47,14 @@ $ cp ~/gdb-7.12-crossbuilder/activate-openwrt-toolchain.env /openwrt-toolchains/
5947
$ source /openwrt-toolchains/$TOOLCHAIN/activate
6048
```
6149

62-
### Use ```activate-musl-toolchain.env``` with an installed toolchain built by musl-cross-make
50+
## MUSL via [musl-cross-make](https://github.com/richfelker/musl-cross-make/): Use `source activate-musl-toolchain.env` with an installed toolchain built by musl-cross-make
6351

64-
Using musl-cross-make is a nice experience- I recommend you try it. If you do, all you need to do is edit config.mak, use make -j and make install. That's it. You're done. The activate-musl-toolchain file is for you to place in the root of the installed toolchain to use as a convenience to "activate" the toolchain in your environment.
52+
Using musl-cross-make is a nice experience- I recommend you try it. If you do, all you need to do is edit config.mak, use make -j and make install. That's it. You're done. The activate-musl-toolchain file is for you to place in the root of the installed toolchain to use as a convenience to "activate" the toolchain in your environment for use with *weird* build systems, or for software with no build system at all.
6553

6654
```
6755
$ export TOOLCHAIN_DEST=/musl-cross-make-toolchains/toolchain-mips_mips32_musl/
6856
$ cd ~/
69-
git clone https://github.com/richfelker/musl-cross-make
57+
$ git clone https://github.com/richfelker/musl-cross-make
7058
$ cd musl-cross-make
7159
$ vi config.mak
7260
... assume you're installing to $TOOLCHAIN_DEST ...
@@ -85,14 +73,13 @@ $ file gdbserver
8573
gdbserver: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
8674
```
8775

88-
### Capabilities provided
76+
### Capabilities provided by the shell source scripts
8977

90-
See the end of each .env file. You will see variables exported. Those variables can now be accessed in your shell while building software. Tools like gcc, ar, ld, g++, etc. will also now be in your path and there will be a ```cross_configure``` alias in the shell to simplify using software packages that utilize ./configure build systems
78+
See the end of each .env file. You will see variables exported. Those variables can now be accessed in your shell while building software. Tools like gcc, ar, ld, g++, etc. will also now be in your path and there will be a `cross_configure` alias in the shell to simplify using software packages that utilize ./configure build systems
9179

9280
#### Sample environment variables after activating an OpenWrt toolchain
9381

94-
```
95-
DL_STATIC=/opt/openwrt/armel-gnu-eabi5-sysv/lib/libdl.a
82+
```DL_STATIC=/opt/openwrt/armel-gnu-eabi5-sysv/lib/libdl.a
9683
C_STATIC=/opt/openwrt/armel-gnu-eabi5-sysv/lib/libc.a
9784
STDCXX_STATIC=/opt/openwrt/armel-gnu-eabi5-sysv/lib/libstdc++.a
9885
UTIL_STATIC=/opt/openwrt/armel-gnu-eabi5-sysv/lib/libutil.a
@@ -102,16 +89,46 @@ STAGING_DIR=/opt/openwrt/armel-gnu-eabi5-sysv
10289
TOOLCHAIN_ROOT=/opt/openwrt/armel-gnu-eabi5-sysv
10390
TOOLCHAIN_BIN=/opt/openwrt/armel-gnu-eabi5-sysv/bin
10491
TOOLCHAIN_TARGET=arm-openwrt-linux-muslgnueabi
105-
SYSTEM_ROOT=/opt/openwrt/armel-gnu-eabi5-sysv
106-
```
92+
SYSTEM_ROOT=/opt/openwrt/armel-gnu-eabi5-sysv```
10793
10894
#### Sample alias
10995
96+
```alias cross_configure='./configure --host=arm-openwrt-linux-muslgnueabi --prefix=/opt/openwrt/armel-gnu-eabi5-sysv'```
97+
98+
### Doing a plain old build of gdbserver for the same host and target (i.e. no special toolchain)
99+
100+
*This is not something you should really ever be doing- you will almost always be using a non-native toolchain. However, I wanted to include an example of how it can be cleanly done in a standard build environment. It assumes glibc, which is not really a good target for building non-trivial statically executables, but whatever...*
101+
102+
#### Find static libraries you will need to link gdbserver with
103+
104+
You will need to make sure you have libstdc++.a and libgcc_eh.a on your system. If you don't know what you're doing, you can just use find. Try using the following:
105+
110106
```
111-
alias cross_configure='./configure --host=arm-openwrt-linux-muslgnueabi --prefix=/opt/openwrt/armel-gnu-eabi5-sysv'
107+
$ find /l* /u* -name libgcc_eh.a
108+
... choose the appropriate one if you have a multilib system ..
109+
$ export LIBGCC=/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a
110+
$ find /l* /u* -name libstdc++.a
111+
... choose the appropriate one if you have a multilib system ..
112+
$ export LIBCXX=/usr/lib/gcc/x86_64-linux-gnu/4.9/libstdc++.a
113+
$ export CC=gcc-4.9
114+
... set this if you have multiple versions of gcc on your system ...
112115
```
113116
117+
#### Perform the build
118+
119+
```
120+
$ wget https://ftp.gnu.org/gnu/gdb/gdb-7.12.tar.xz
121+
$ tar -xvf gdb-7.12.tar.xz
122+
$ cd gdb-7.12/gdb/gdbserver
123+
$ sed -i -e 's/srv_linux_thread_db=yes//' configure.srv
124+
$ ./configure --prefix=/opt/gdbserver-7.12-static CXXFLAGS='-fPIC -static'
125+
$ make -j gdbserver GDBSERVER_LIBS="$LIBGCC $LIBCXX"
126+
```
127+
128+
You should now have a statically compiled GDB 7.12 gdbserver for your native OS. Read on for the cross-compile stuff, which is a little more involved but still pretty simple. You really should use uClibc or musl for your libc, not glibc, because getgrgid() and getpwuid() both load shared libraries. This could cause a problem if you intend to run the gdbserver executable on another machine with a different version of glibc- which more or less defeats the purpose of static linking.
129+
114130
## License
115131
116-
# This software is released under the terms of GPLv2 by copyright@mzpqnxow.com
117-
# Please see LICENSE or LICENSE.md for more information on GPLv2
132+
* The shell scripts and source files here are is released under the terms of GPLv2 by copyright@mzpqnxow.com
133+
* Please see LICENSE or LICENSE.md for more information on GPLv2
134+
* Third party software is included with license information intact

0 commit comments

Comments
 (0)