Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Library:GNU C Library

From ReverseEngineering.wiki
Library
Developer Free Software Foundation / GNU project (since 1987)
Platforms Linux and GNU Hurd on x86, x86-64, AArch64, ARM, MIPS, PowerPC, RISC-V, s390, LoongArch and others
Versions 2.x; 2.34 (August 2021) merged libpthread/libdl into libc and changed the startup code
License LGPL-2.1-or-later (some files GPL with exceptions)
Website https://www.gnu.org/software/libc/
On this wiki Facts · Code · Notes · Topics

The C standard library and dynamic loader of most Linux distributions (libc.so.6, ld-linux*.so), LGPL-2.1+. Every dynamically linked glibc program imports __libc_start_main from libc.so.6 with a versioned symbol and starts with the _start stub from glibc's crt1.o, whose bytes identify glibc, the architecture and whether glibc was older or newer than 2.34.

Identification

  • PT_INTERP of the program: /lib64/ld-linux-x86-64.so.2 (x86-64), /lib/ld-linux.so.2 (i386), /lib/ld-linux-aarch64.so.1, /lib/ld-linux-armhf.so.3, /lib/ld.so.1 or /lib64/ld.so.1 (MIPS), and DT_NEEDED libc.so.6 (Format:ELF (Executable and Linkable Format)#Dynamic section).
  • Symbol versions in .gnu.version_r: every import names a GLIBC_2.x version, the lowest being the architecture's baseline: GLIBC_2.0 on i386 and MIPS, GLIBC_2.2.5 on x86-64, GLIBC_2.17 on AArch64. A program linked against glibc 2.34 or later imports __libc_start_main@GLIBC_2.34, so the highest version present is a lower bound for the build system's glibc.
  • The entry point is _start from sysdeps/<arch>/start.S (linked from crt1.o/Scrt1.o): byte signatures are facts of this page; export_symbols with subject Library:GNU C Library gives a Ghidra/IDA script that names it.
  • Statically linked programs contain strings such as GNU C Library (<distro>) stable release version 2.35. and FATAL: kernel too old (Unverified here: not present in the pyelftools samples used, which are all dynamically linked).

Startup code

_start clears the frame pointer, takes argc/argv from the stack and the dynamic loader's rtld_fini from a register (rdx on x86-64, edx on i386, x0 on AArch64), aligns the stack and calls __libc_start_main(main, argc, argv, init, fini, rtld_fini, stack_end). Until glibc 2.33 init and fini were __libc_csu_init and __libc_csu_fini, linked into every program from libc_nonshared.a; glibc 2.34 (bug 23323, "CSU startup hardening") removed them and passes NULL, so the bytes after the common x86-64 prefix tell the generation:

Bytes after 31 ED 49 89 D1 5E 48 89 E2 48 83 E4 F0 50 54 Meaning Samples (pyelftools corpus)
49 C7 C0 imm32 (mov r8, __libc_csu_fini) then 48 C7 C1 glibc < 2.34, non-PIE SUSE GCC 4.3.4, Red Hat GCC 4.4.7, Ubuntu 16.04 GCC 5.4, Ubuntu 18.04 GCC 7.4
4C 8D 05 rel32 (lea r8, [rip+...]) glibc < 2.34, PIE Debian 10 GCC 8.3, Debian 11 GCC 10.2, Ubuntu 18.04 GCC 7.4 PIE
45 31 C0 31 C9 (xor r8d, r8d; xor ecx, ecx) glibc 2.34 or later Ubuntu 22.04 GCC 11.x, Ubuntu 24.04 GCC 13.3, GCC 12.1, LLD 14

The main function is the first argument: mov rdi, imm32 / lea rdi, [rip+...] (old) or mov rdi, [rip+main@GOTPCREL] (2.34+) right before the call, which is the quickest way to find main in a stripped binary. A leading F3 0F 1E FA (endbr64) appears when the distribution builds with CET (-fcf-protection), 5F 24 03 D5 (bti c) on AArch64 with branch protection.

Code & repositories

  • https://github.com/bminor/glibc @ 04e750e75b73957cf1c791535a3f4319534a52fc · license: LGPL-2.1
    Read-only GitHub mirror of the GNU C Library git repository (sourceware.org/git/glibc.git). The startup code that every glibc program carries is in sysdeps/<arch>/start.S; NEWS lists the user-visible changes and fixed bugs per release.
    Tested on: Sparse checkout at this commit (2026-01-20, 2.42.9000); start.S for x86_64, i386, aarch64 and mips read and compared with the entry-point bytes of the pyelftools test executables. · checked 2026-10-17; archived; last activity 2026-01-21

Pitfalls

  • __libc_csu_init in an old binary is linked into the program, not libc: do not mistake it for user code (it walks __init_array_start..__init_array_end).
  • Android (Bionic), musl and uClibc programs have different startup code; Android ARM samples start 0D 00 A0 E1 FF FF FF EA or 00 B0 A0 E3 00 E0 A0 E3 0D 00 A0 E1 instead.

Evidence & references

  • glibc source, GitHub mirror bminor/glibc at 04e750e75b73 (2026-01-20, development version 2.42.9000): sysdeps/x86_64/start.S, sysdeps/i386/start.S, sysdeps/aarch64/start.S, sysdeps/mips/start.S; NEWS (2.34 section, bug 23323).
  • Entry-point bytes and version needs read with Code:ELF (Executable and Linkable Format)/elfinfo (Python) and a small script from the executables of pyelftools' test corpus (commit 5a04389).