here take glibc-2.23 as an example, after downloading the source
1
2
3
4
5
6
7
8
9
10
11
cd ~/src/glibc
mkdir glibc-2.23-{build,out}cd glibc-2.23-build
# -Wno-error will override -Werror which will make compilation fail on warnings# -O3, if you specify CFLAGS, you must give it -Ox (glibc cannot be compiled without optimization: https://gnu.org/software/libc/manual/html_mono/libc.html#toc-Installing-the-GNU-C-Library)# -g will generate embed debug information../glibc-2.23/configure --prefix=~/src/glibc/glibc-2.23-out CFLAGS="-Wno-error -O3 -g"# this is important# make # compile with single thread, slow: took me about 14 minutesmake -j`nproc`# faster: took me under 2 minutes# make -j$((`nproc`+1)) # https://unix.stackexchange.com/questions/208568/how-to-determine-the-maximum-number-to-pass-to-make-j-optionmake install # install to what you have configured in the `--prefix` (so mine will be installed to ~/src/glibc/glibc-2.23-out)
use mgcc to compile programs
mgcc
mgcc is just a shell wrapper that wraps the gcc command, you can compile programs same way as you would in gcc. you can also specify --glibc_install with the installation path of some version of glibc to switch between different glibc’s: mgcc --glibc_install ~/src/glibc/glibc-2.32-out -g -o main main.c
tell gdb where to look for source code: dir ~/src/glibc/glibc-2.23/malloc
1
2
3
4
gdb main
# ...pwndbg> dir ~/src/glibc/glibc-2.23/malloc/
# ...
completion
if you are using zsh and oh-my-zsh (you should), you can add a line: compdef mgcc=gcc to your ~/.zshrc file this will allow mgcc to use gcc’s completion
run others’ program with your libc
CLI
1
2
3
LD_PRELOAD=./libc.so ./program
# or https://pullp.github.io/2020/11/06/11-glibc-basics/#2-2-run-with-specific-glibcLD_PRELOAD=./libc.so ./ld.so ./program