Chinaunix首页 | 论坛 | 博客
  • 博客访问: 34110
  • 博文数量: 13
  • 博客积分: 92
  • 博客等级: 民兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-18 16:04
个人简介

飞飞有话说

文章分类
文章存档

2011年(13)

分类:

2011-09-27 13:31:22

原文地址:Glibc学习记要 作者:passion_2008

1、glibc对于编写应用程序来说那真是吃饭的家伙啊,除此之外glibc还提供了动态链接程序,C程序初始
调用入口等东西,这些东西对于深入理解基于ELF格式的动态链接是非常重要的。我们了解glibc有两个途径
一个是glibc提供的手册,另一个就是原代码。再也没有发现其他的可以供系统学习的资料了。
Glibc手册非常的长,1000多页根本没法全部看完,所以应该作为案头参考书或者“字典”来查询。如果想深入了解glibc的API的底层实现,只有reading the facking code了。
 
2、学习资料
glibc官方网站:  
原代码的下载地址: 
手册地址:   
 
3、有下面几种方法查询当前系统的glibc的版本号:
 1)ls -l /lib/libc*
 2)ldd --version //因为ldd是glibc自带的东西
 3)cat `gcc -print-file-name=libc.so` 
   cat /usr/lib/libc.so
一般来说glibc原始文件存放在/lib目录下,而在/usr/lib/目录下会有一个libc.so文件,这其实是一个ld脚本
用于在ld静态链接的时候用。
  
glibc默认安装的时候还会包括三个其他的包:
crypt:UFC-crypt 加密套件
linuxthreads: Posix 1003.1c "pthread" 介面的实作,NPTL。
locale data: 含制造使用 glibc 的 internationalization 功能所需 locale 资料档案的资料
以上三个库都可以在glibc相同的目录找到原文件和ld链接文件
Glibc 库提供了系统调用和 C 库的基本函数,所有动态连接的程序都要用到它,我们知道动态链接器
在初始化每个共享库后会跳转到__libc_start_main函数,由此函数最后来调用main函数,所以所有用到
动态链接库的程序都需要使用glibc,并且动态链接程序ld.so本身也是包含在glibc中的。
 
4、Glibc包的内容(摘自一篇LFS的文章)
包括的程序:
catchsegv, gencat, getconf, getent, iconv, iconvconfig, ldconfig, ldd, lddlibc4, locale, localedef, mtrace, nscd, nscd_nischeck, pcprofiledump, pt_chown, rpcgen, rpcinfo, sln, sprof, tzselect, xtrace, zdump, zic
 
包括的库:
ld.so, libBrokenLocale.[a,so], libSegFault.so, libanl.[a,so], libbsd-compat.a, libc.[a,so], libcrypt.[a,so], libdl.[a,so], libg.a, libieee.a, libm.[a,so], libmcheck.a, libmemusage.so, libnsl.a, libnss_compat.so, libnss_dns.so, libnss_files.so, libnss_hesiod.so, libnss_nis.so, libnss_nisplus.so, libpcprofile.so, libpthread.[a,so], libresolv.[a,so], librpcsvc.a, librt.[a,so], libthread_db.so, libutil.[a,so]
 
Glibc包括的程序:
catchsegv  当程序发生段故障的时候,用来建立一个堆栈跟踪
gencat   建立消息列表
getconf   针对文件系统的指定变量显示其系统设置值
getent   从系统管理数据库获取一个条目
iconv   字符集转换
iconvconfig  建立快速加载的 iconv 模块所使用的配置文件
ldconfig  配置动态链接库的实时绑定
ldd    列出每个程序或者命令需要的共享库
lddlibc4  帮助 ldd 操作目标文件
locale   告诉编译器为内建的操作启用或禁用 POSIX locales 支持[ Tells the compiler to enable or disable the use of POSIX locales for built-in operations ]
localedef  编译 locale 标准
mtrace   读取并解释一个内存跟踪文件然后以人类可读的格式显示一个摘要
nscd   为最常用的名称服务请求提供缓存的守护进程 [ A daemon that provides a cache for the most common name service requests ]
nscd_nischeck 检查在进行 NIS+ 查找时是否需要安全模式
pcprofiledump 转储 PC profiling 产生的信息
pt_chown  一个辅助程序,帮助 grantpt 设置子虚拟终端的属主、用户组、读写权限
rpcgen   产生实现远程过程调用(RPC)协议的 C 代码
rpcinfo   对 RPC 服务器产生一个 RPC 呼叫
sln    ln 程序使用静态连接编译的版本,在 ln 不起作用的时候,sln 仍然可以建立符号链接
sprof   读取并显示共享目标的特征描述数据
tzselect  对用户提出关于当前位置的问题并输出时区信息到标准输出
xtrace   通过打印当前执行的函数跟踪程序执行情况
zdump   显示时区
zic    时区编译器
 
Glibc包括的库:
ld.so   帮助动态链接库执行的辅助程序
libBrokenLocale 帮助应用程序(如Mozilla)处理破损的 locale
libSegFault  段故障信号处理器
libanl     异步名称查询库
libbsd-compat 为了在 linux 下执行一些 BSD 程序,libbsd-compat 提供了必要的可移植性
libc   主 C 库,集成了最常用函数
libcrypt  用于的加密库
libdl   动态连接接口库
libg   g++ 运行时库
libieee   IEEE 浮点运算库
libm   数学函数库
libmcheck  包括了启动(boot)时需要的代码
libmemusage  帮助 memusage 搜集程序运行时的内存占用信息
libnsl   提供网络服务的库
libnss   名称服务切换库,包含了解释主机名、用户名、组名、别名、服务、协议等等的函数
libpcprofile 包含用于跟踪某些特定源代码的 CPU 使用时间的 profiling 函数
libpthread  POSIX 线程库
libresolv  创建、发送、解释到互联网域名服务器的数据包
librpcsvc  提供 RPC 的其他杂项服务
librt   提供了大部分的 POSIX.1b 运行时扩展接口
libthread_db 对多线程程序的调试很有用
libutil   包含了在很多不同的 Unix 程序中使用的"标准"函数
 
5、以下摘取glibc手册overview章节
Chapter 3 [Virtual Memory Allocation And Paging], page 30, describes the GNU library’s
facilities for managing and using virtual and real memory, including dynamic
allocation of virtual memory. If you do not know in advance how much memory your
program needs, you can allocate it dynamically instead, and manipulate it via pointers.
Chapter 4 [Character Handling], page 64, contains information about character classi-
fication functions (such as isspace) and functions for performing case conversion.
Chapter 5 [String and Array Utilities], page 72, has descriptions of functions for manipulating
strings (null-terminated character arrays) and general byte arrays, including
operations such as copying and comparison.
Chapter 11 [Input/Output Overview], page 220, gives an overall look at the input and
output facilities in the library, and contains information about basic concepts such as
file names.
Chapter 12 [Input/Output on Streams], page 225, describes I/O operations involving
streams (or FILE * objects). These are the normal C library functions from ‘stdio.h’.
Chapter 13 [Low-Level Input/Output], page 295, contains information about I/O operations
on file descriptors. File descriptors are a lower-level mechanism specific to the
Unix family of operating systems.
Chapter 14 [File System Interface], page 342, has descriptions of operations on entire
files, such as functions for deleting and renaming them and for creating new directories.
This chapter also contains information about how you can access the attributes of a
file, such as its owner and file protection modes.
Chapter 15 [Pipes and FIFOs], page 383, contains information about simple interprocess
communication mechanisms. Pipes allow communication between two related
processes (such as between a parent and child), while FIFOs allow communication
between processes sharing a common file system on the same machine.
Chapter 16 [Sockets], page 388, describes a more complicated interprocess communication
mechanism that allows processes running on different machines to communicate
over a network. This chapter also contains information about Internet host addressing
and how to use the system network databases.
Chapter 17 [Low-Level Terminal Interface], page 433, describes how you can change
the attributes of a terminal device. If you want to disable echo of characters typed by
the user, for example, read this chapter.
Chapter 19 [Mathematics], page 466, contains information about the math library functions.
These include things like random-number generators and remainder functions on
integers as well as the usual trigonometric and exponential functions on floating-point
numbers.
Chapter 20 [Low-Level Arithmetic Functions], page 497, describes functions for simple
arithmetic, analysis of floating-point values, and reading numbers from strings.
Chapter 9 [Searching and Sorting], page 191, contains information about functions for
searching and sorting arrays. You can use these functions on any kind of array by
providing an appropriate comparison function.
Chapter 10 [Pattern Matching], page 200, presents functions for matching regular expressions
and shell file name patterns, and for expanding words as the shell does.
Chapter 21 [Date and Time], page 528, describes functions for measuring both calendar
time and CPU time, as well as functions for setting alarms and timers.
Chapter 6 [Character Set Handling], page 108, contains information about manipulating
characters and strings using character sets larger than will fit in the usual char data
type.
Chapter 7 [Locales and Internationalization], page 149, describes how selecting a particular
country or language affects the behavior of the library. For example, the locale
affects collation sequences for strings and how monetary values are formatted.
Chapter 23 [Non-Local Exits], page 581, contains descriptions of the setjmp and
longjmp functions. These functions provide a facility for goto-like jumps which can
jump from one function to another.
Chapter 24 [Signal Handling], page 590, tells you all about signals—what they are, how
to establish a handler that is called when a particular kind of signal is delivered, and
how to prevent signals from arriving during critical sections of your program.
Chapter 25 [The Basic Program/System Interface], page 634, tells how your programs
can access their command-line arguments and environment variables.
Chapter 26 [Processes], page 676, contains information about how to start new processes
and run programs.
Chapter 27 [Job Control], page 687, describes functions for manipulating process groups
and the controlling terminal. This material is probably only of interest if you are writing
a shell or other program which handles job control specially.
Chapter 28 [System Databases and Name Service Switch], page 706, describes the services
which are available for looking up names in the system databases, how to determine
which service is used for which database, and how these services are implemented
so that contributors can design their own services.
Section 29.13 [User Database], page 733, and Section 29.14 [Group Database], page 736,
tell you how to access the system user and group databases.
Chapter 30 [System Management], page 742, describes functions for controlling and
getting information about the hardware and software configuration your program is
executing under.
Chapter 31 [System Configuration Parameters], page 758, tells you how you can get
information about various operating system limits. Most of these parameters are provided
for compatibility with POSIX.
阅读(1468) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~