GNU C Library

From Infinity Wiki
Revision as of 03:17, 2 December 2016 by Gary Benson (talk | contribs) (→‎td_thr_get_info fields)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The GNU C Library, also known as glibc, is the C library in the GNU system and in GNU/Linux systems, as well as many other systems that use Linux as the kernel. Its homepage is

Included with the GNU C Library are two libraries of note to Infinity developers:

Programs wishing to become multithreaded load and make calls into it. Software development tools wishing to understand multithreaded programs load and make calls into that. This works fine if the program being analyzed and the tool doing the analysis are built with the same ABI.

It grew from a need for GDB to be able to debug multithreaded applications without requiring libthread_db. In Infinity, the thread-debugging code is stored as platform-independent Infinity notes in; is not used at all.

The TL;DR of all this is that if you're developing Infinity you will very likely need to be making glibc test builds. You can find out how to do that at

Supported platforms

This table details how the various platforms glibc supports locate the current thread descriptor and what ELF binaries look like on those platforms. It's correct as of June 2016.

glibc platform name libthread_db wordsize THREAD_SELF type elf.h e_machine thread register prgregset_t offset
name DWARF number
aarch64 64 CTA EM_AARCH64
alpha 64 register EM_ALPHA unique 66 32 * 8
arm 32 CTA EM_ARM
hppa 32 register EM_PARISC cr27 not allocated 53 * 4
i386 32 RTA EM_386 gs 45 offsetof (struct user_regs_struct, xgs) == 10 * 4
i386 64 RTA EM_386 gs 45 26 * 8
ia64 64 register EM_IA_64 r13 13 13 * 8
m68k 32 CTA EM_68K
microblaze 32 CTA unknown
mips 32 CTA unknown
nios2 32 register EM_ALTERA_NIOS2 (113) r23 23 23 * 4
powerpc 32 register EM_PPC r13 13 PT_R13 * 4 (== 13 * 4)
powerpc 64 register EM_PPC64 r2 2 PT_R2 * 8 (== 2 * 8)
s390 32 register EM_S390 ar0 48 18 * 4
s390 64 register EM_S390 ar0 and ar1 48 and 49 18 * 8
sh 32 register EM_SH gbr 19 REG_GBR * 4 (== unknown)
sparc 32 register EM_SPARC{,V9,32PLUS} g7 7 10 * 4
sparc 64 register EM_SPARC{,V9,32PLUS} g7 7 (6 * 8) + (__WORDSIZE==64 ? 0 : 4)
tile 32 register EM_TILEGX tp 53 REG_TP * 4 (== unknown)
tile 64 register EM_TILEGX tp 53 REG_TP * 8 (== unknown)
x86_64 64 register (was CTA) EM_X86_64 fs.base 58 21*8 (but GDB does not fill it in currently)

td_thr_get_info fields

This table details the fields in the structure td_thr_get_info fills in. It's correct as of December 2016.

struct td_thrinfo field glibc thread_db.h comment glibc libthread_db fills it in libi8x libthread_db fills it in
name type
ti_ta_p td_thragent_t * Process handle Yes Yes
ti_user_flags unsigned int Unused No No
ti_tid thread_t Thread ID returned by pthread_create() Yes Yes
ti_tls char * Pointer to thread-local data Yes Yes (since Third Base)
ti_startfunc psaddr_t Start function passed to pthread_create() Yes (if not faked) Yes (since Third Base)
ti_stkbase psaddr_t Base of thread's stack No No
ti_stksize long int Size of thread's stack No No
ti_ro_area psaddr_t Unused No No
ti_ro_size int Unused No No
ti_state td_thr_state_e Thread state Yes Yes
ti_db_suspended unsigned char Nonzero if suspended by debugger No No
ti_type td_thr_type_e Type of the thread (system vs user thread) Yes (but constant, always TD_THR_USER) Yes (since Third Base)
ti_pc intptr_t Unused No No
ti_sp intptr_t Unused No No
ti_flags short int Unused No No
ti_pri int Thread priority Yes Yes (since Third Base)
ti_lid lwpid_t Kernel PID for this thread Yes Yes
ti_sigmask sigset_t Signal mask No No
ti_traceme unsigned char Nonzero if event reporting enabled Yes Yes (since Third Base)
ti_preemptflag unsigned char Unused No No
ti_pirecflag unsigned char Unused No No
ti_pending sigset_t Set of pending signals No No
ti_events td_thr_events_t Set of enabled events Yes (for non-faked, but sometimes fails) Yes (since Third Base)