The simplest way is to extract the package source code somewhere: go to an appropriate directory, then run

apt source glibc

In gdb, add the corresponding directory to the source path by using the directory command.

You may also want the detached debug symbols; I don’t know whether Devuan provides debug symbol packages in general (dbgsym packages), but I see it ships libc6-dbg which has the same purpose:

sudo apt install libc6-dbg

Here’s an example gdb session:

$ gdb ls
...
(gdb) directory ~/Debian/glibc
Source directories searched: /home/steve/Debian/glibc:$cdir:$cwd
(gdb) break malloc
Breakpoint 1 at 0x46c8
(gdb) run
Starting program: /bin/ls 

Breakpoint 1, malloc (n=1441) at dl-minimal.c:50
50    if (alloc_end == 0)
Answer from Stephen Kitt on Stack Exchange
🌐
Ask Ubuntu
askubuntu.com › questions › 696139 › how-can-i-get-glibc-source-code
system installation - How can i get glibc source code ? - Ask Ubuntu
I want to compiler glibc and change some code ,but i don't know where can download the source code. question: ... A.B. – A.B. 2015-11-10 07:10:13 +00:00 Commented Nov 10, 2015 at 7:10 ... You will find packages and versions for various releases and architectures of Ubuntu.
🌐
Launchpad
code.launchpad.net › ubuntu › +source › glibc
glibc package : Ubuntu - Git - Launchpad Code
Code · Bugs · Blueprints · Translations · Answers · View Bazaar branches · Get this repository: git clone https://git.launchpad.net/ubuntu/+source/glibc · Members of git-ubuntu import can upload to this repository.
Discussions

debugging - How can I get glibc/libstdc++ sources and set them up for gdb to find? - Unix & Linux Stack Exchange
I'm debugging this program which raises an exception. This makes my debugger look for some source code, e.g. ../sysdeps/unix/sysv/linux/raise.c - and fail to find it. Now, I realize it's not necess... More on unix.stackexchange.com
🌐 unix.stackexchange.com
November 18, 2021
documentation - Where can I browse the sourcecode for libc online (like doxygen) - Stack Overflow
Sometimes I want to look up the implementations of functions in the stdlib, I've downloaded the sourcecode, but it's quite messy. Just greping is not really suitable because of the many hits. Does More on stackoverflow.com
🌐 stackoverflow.com
linux - Where is the source code for the GNU C library? - Stack Overflow
How do I go about finding the source code behind standard C functions (under Linux/Ubuntu 13)? Case in point, chdir(). I know I have to #include but then I encounter a bug, and I More on stackoverflow.com
🌐 stackoverflow.com
c - libc source location - for download or online viewing? - Stack Overflow
Info on the glibc repository: http://sourceware.org/glibc/wiki/GlibcGit · Clone it to get your own copy and search it however you like: ... I load it up in an IDE project (using whatever preferred IDE) and the code navigation works quite well to let me find what I'm interested in. Browse the ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Ubuntu
packages.ubuntu.com › focal › glibc-source
Ubuntu – Details of package glibc-source in focal
Download Source Package glibc: [glibc_2.31-0ubuntu9.17.dsc] [glibc_2.31.orig.tar.xz] [glibc_2.31-0ubuntu9.17.debian.tar.xz] Ubuntu Developers (Mail Archive) Please consider filing a bug or asking a question via Launchpad before contacting the maintainer directly.
🌐
Ubuntu
packages.ubuntu.com › glibc-source
Ubuntu – Package Search Results -- glibc-source
resolute (devel): GNU C Library: sources [universe] 2.42-2ubuntu2: all
Top answer
1 of 2
11

The simplest way is to extract the package source code somewhere: go to an appropriate directory, then run

apt source glibc

In gdb, add the corresponding directory to the source path by using the directory command.

You may also want the detached debug symbols; I don’t know whether Devuan provides debug symbol packages in general (dbgsym packages), but I see it ships libc6-dbg which has the same purpose:

sudo apt install libc6-dbg

Here’s an example gdb session:

$ gdb ls
...
(gdb) directory ~/Debian/glibc
Source directories searched: /home/steve/Debian/glibc:$cdir:$cwd
(gdb) break malloc
Breakpoint 1 at 0x46c8
(gdb) run
Starting program: /bin/ls 

Breakpoint 1, malloc (n=1441) at dl-minimal.c:50
50    if (alloc_end == 0)
2 of 2
1

Some further indications for Ubuntu 22.04 beyond what Stephen said.

To get debug symbols and source, some setup is needed as in:

# Get debug symbols.
printf "deb http://ddebs.ubuntu.com %s main restricted universe multiverse\n" $(lsb_release -cs){,-updates,-security,-proposed} | \
 sudo tee -a /etc/apt/sources.list.d/ddebs.list
sudo apt install ubuntu-dbgsym-keyring
sudo apt update
sudo apt install coreutils-dbgsym

# Get source as per: https://askubuntu.com/questions/496549/error-you-must-put-some-source-uris-in-your-sources-list
# Produces directory "coreutils-8.32"
sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /'
/etc/apt/sources.list sudo apt-get update
apt source coreutils

Then, to get GDB to actually find the sources, you might need to either cd into the downloaded source, or play with stuff like:

set substitute-path . glibc-2.35

as mentioned at: https://askubuntu.com/questions/487222/how-to-install-debug-symbols-for-installed-packages/1434174#1434174

🌐
GitHub
github.com › bminor › glibc
GitHub - bminor/glibc: Unofficial mirror of sourceware glibc repository. · GitHub
Unofficial mirror of sourceware glibc repository. Contribute to bminor/glibc development by creating an account on GitHub.
Starred by 1.9K users
Forked by 469 users
Languages   C 71.0% | Assembly 12.4% | C++ 7.2% | Pawn 6.0% | Makefile 1.1% | Python 1.0%
🌐
Ubuntu
launchpad.net › ubuntu › bionic › +package › glibc-source
glibc-source : Bionic (18.04) : Ubuntu - Launchpad
This package contains the sources and patches which are needed to build glibc. ... © 2004 Canonical Ltd. • Terms of use • Data privacy • Contact Launchpad Support • Blog • Careers • System status • 99c00f5 (Get the code!)
Find elsewhere
🌐
Ubuntu
packages.ubuntu.com › xenial › glibc-source
Ubuntu – Error
two or more packages specified (glibc-source xenial) Content Copyright © 2025 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
🌐
Ubuntu
launchpad.net › ubuntu › +source › glibc
glibc package in Ubuntu
glibc-doc: GNU C Library: Documentation glibc-source: GNU C Library: sources libc-bin: GNU C Library: Binaries libc-bin-dbgsym: debug symbols for libc-bin libc-dev-bin: GNU C Library: Development binaries libc-dev-
🌐
GNU
gnu.org › software › libc › sources.html
The GNU C Library (glibc) Documentation
You can contact the developer community by emailing the developer list libc-alpha@sourceware.org. The GNU C Library can be found on the main GNU ftp server (download glibc via HTTPS, download glibc via HTTP or download glibc via FTP), and its mirrors; please use a mirror if possible.
🌐
Gentoo Forums
forums.gentoo.org › board index › assistance › portage & programming
how to find glibc sorce code - Gentoo Forums
October 27, 2019 - The downloaded sources of the installed packages are kept in the DISTDIR directory, defined in make.conf. There is a good chance that it is /usr/portage/distfiles. The C library code is in the glibc archive.
🌐
Ubuntu
packages.ubuntu.com › source › focal › glibc
Ubuntu – Details of source package glibc in focal
September 1, 2022 - two or more packages specified (glibc focal) Content Copyright © 2026 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
🌐
GitHub
github.com › vinsonlee › ubuntu-glibc
GitHub - vinsonlee/ubuntu-glibc
The GNU C Library supports these configurations for using Linux kernels: aarch64*-*-linux-gnu alpha*-*-linux-gnu arm-*-linux-gnueabi hppa-*-linux-gnu Not currently functional without patches. i[4567]86-*-linux-gnu x86_64-*-linux-gnu Can build either x86_64 or x32 ia64-*-linux-gnu m68k-*-linux-gnu microblaze*-*-linux-gnu mips-*-linux-gnu mips64-*-linux-gnu powerpc-*-linux-gnu Hardware or software floating point, BE only. powerpc64*-*-linux-gnu Big-endian and little-endian. s390-*-linux-gnu s390x-*-linux-gnu sh[34]-*-linux-gnu sparc*-*-linux-gnu sparc64*-*-linux-gnu tilegx-*-linux-gnu tilepro-*-linux-gnu If you are interested in doing a port, please contact the glibc maintainers; see http://www.gnu.org/software/libc/ for more information.
Author   vinsonlee
Top answer
1 of 4
27

Most linuxes use a libc version named glibc.

The LXR (online cross-reference system) for glibc is e.g. here http://koala.cs.pub.ro/lxr/glibc/ for 2.9 version (link is broken). I must say that something may be not lxr'ed because some sources are generated in the build process, for example - as i can remember - wrappers around a system calls.

Pthreads are in nptl/ folder. Right link to libc sources is http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.bz2 (or change 2.14 to your version)

Update: After closing of koala's lxr, there are:

  1. Metager with glibc: http://code.metager.de/source/xref/gnu/glibc/ (Served with Sun's OpenGrok, which was originally used to generate online x-ref for Solaris/OpenSolaris)

  2. Google code search (I know that it was closed; but I also know it's other version which is up): http://code.google.com/codesearch and try to search something glibc-specific

UPD (march 2013) They killed codesearch again:

404. That’s an error.

The requested URL /codesearch was not found on this server. That’s all we know.

UPD 2017

  1. Metager with glibc: http://code.metager.de/source/xref/gnu/glibc/

  2. There is online git by glibc authors: https://sourceware.org/git/?p=glibc.git (tree is browserable at https://sourceware.org/git/?p=glibc.git;a=tree)

  3. Glibc git is mirrored to github (which has some searching functions) https://github.com/bminor/glibc Buildroot 2018.05 notably uses this mirror.

  4. There is search like google's codesearch in all debian packages: https://codesearch.debian.net/. It can search in glibc sources by "package:glibc request" request and also have file browser: http://sources.debian.net/src/glibc/

2 of 4
15

Info on the glibc repository: http://sourceware.org/glibc/wiki/GlibcGit

Clone it to get your own copy and search it however you like:

git clone git://sourceware.org/git/glibc.git

I load it up in an IDE project (using whatever preferred IDE) and the code navigation works quite well to let me find what I'm interested in.

Browse the source online http://sourceware.org/git/?p=glibc.git

🌐
LinuxVox
linuxvox.com › blog › install-glibc-ubuntu
Installing glibc on Ubuntu: A Comprehensive Guide — linuxvox.com
# Download the glibc source code wget http://ftp.gnu.org/gnu/glibc/glibc-2.34.tar.gz # Extract the source code tar -xzf glibc-2.34.tar.gz # Create a build directory mkdir glibc-build cd glibc-build # Configure the build ../glibc-2.34/configure ...
Top answer
1 of 1
1

How can I navigate glibc and find the actual implementation for lib functions?

Type the function in the search bar at https://code.woboq.org/userspace/glibc or at https://github.com/bminor/glibc . Navigate the results manually until you find the definition.

If you want to index the project locally, use cscope, ctags, GLOBAL tags or clangd to index the project and then use that tools specific interface to search for the definition.

As an example, try looking up the definition of hidden_def in glibc

Type hidden_def glibc into google. My first hit is woboq.org https://code.woboq.org/userspace/glibc/include/libc-symbols.h.html#550 .

I use firefox. I type ctrl+f and type hidden_def. Type Enter until I find # define hidden_def at https://code.woboq.org/userspace/glibc/include/libc-symbols.h.html#550 .

Then select __hidden_ver1 and type ctrl+c ctrl+f and ctrl+v and search for it. In the web browser. I type enter until I find https://code.woboq.org/userspace/glibc/include/libc-symbols.h.html#540 . __hidden_ver2 is just below on line 542.

For most cases all you need is a browser, google, coboq.org and github.org.

It's a macro taking you to hidden_def1

There are no such macros as you mentioned, at least at the version hosted at woboq.org.

How does anyone follow it?

While IDE is a powerful help, each project is unique and requires different settings, that take time to figure out. Mostly browsing the source code is grep (or faster alternatives, like ag, very useful for big projects like glibc) and going through the result list.

Not only system dependent things, like setjmp

Developers are (shoudl be :) sane people - in most cases a function named setjmp will be in a file named setjmp.c. or setjmp.S. Or in the same directory as setjmp.h. Or inside directory named stdlib or setjmp.

Type setjmp in github search bar. https://github.com/bminor/glibc/search?q=setjmp You see there are multiple definitions for each architecture powerpc s390 etc. But files are all named setjmp. Go back. Type "Go to file" on https://github.com/bminor/glibc . Search for a file named x86/setjmp. There are 3 implementations, the most standard one seems to be https://github.com/bminor/glibc/blob/master/sysdeps/x86_64/setjmp.S .

even portable functions like fprintf

As above, saerch for file named fprintf . You quickly find https://github.com/bminor/glibc/blob/master/stdio-common/fprintf.c .