
                         The Linux GCC HOWTOV0.2
                                       
: Daniel Barlow <dan@detached.demon.co.uk>
: ½ѫ(Frank J.S. Chen)<frank63@ms5.hinet.net>

   v1.17, 28 February 1996
     _________________________________________________________________
   
   ĲװGNU CͳʽݵķͬʱŹ۵˵ʽı롢ᡢ
   ִСĹԼٵ⡣дĲο̩Mitch
   D'SouzaռGCC-FAQһԴELF-HOWTO˷HOWTO˵
   GCC-FAQҼҪELF-HOWTOˡGCC-HOWTOһݹ
   еİ汾汾ţRCSĽκָ뽨ģ˶
   ܻӭ
     _________________________________________________________________
   
1. Զǣ

     * 1.1 ߵĻ
     * 1.2 뾲
     * 1.3 ߵ˽
     * 1.4 ӡˢŰ
       
2. Ķ

     * 2.1 GCC-HOWTOĶ
     * 2.2 GCCصĶ
     * 2.3 GCC 
     * 2.4 Cʽͷ
     * 2.5 йĹ (as, ld, ar, strings etc)
       
3. GCCİװGCC趨

     * 3.1 GCCİ汾
     * 3.2 װᶼĶȥ?
     * 3.3 ͷ˨?ͷ˨?
     * 3.4 (Building cross compilers)
       
4. ֲʽʽ

     * 4.1 gccжķ
     * 4.2 ˵
     * 4.3 ֲ
       
5. 

     * 5.1 Ԥƣlint
     * 5.2 
     * 5.3 
       
6. 

     * 6.1 ʽ vs̬ʽ
     * 6.2 ռУsin() ĸʽ
     * 6.3 X
     * 6.4 Լĳʽ
       
7. ̬

     * 7.1 
     * 7.2 ѶϢ
     * 7.3 ƶ̬
     * 7.4 Զ̬׫дʽ
       
8. 뷢չʿ

     * 8.1 Bug
     * 8.2 Эչ
       
9. 

     * 9.1 ˰
     * 9.2 
     * 9.3 ӭκεĻ
     * 9.4 Ϸɹ涨
       
10. 
     _________________________________________________________________
   
1. Զǣ

1.1 ߵĻ

     * ΪLinux document projects(LDP)ķƻϵ֮һĿǰ֮
       ַΪ [1]http://www.linux.org.tw/CLDP/ӭλӻԾͶһ
       
     * Ҳûȫԭַ롣ΪͨɶһԵ
       һݵ֣ףǾԭģĻֲӢļ
       ﷨ṹĲԣԹͨް
     * һЩؼרҵʻȣḽԭĵ֡
     * תѣΨԭĳֻbugsshadow passwordpadding
       image֮ģԭĲ䡣¶Щֻʵǵģ벻
       ָ̡
     * "[ע:**]"֮ǣΪ˶֮ע⡣
     * ƪκνʵģemailfrank63@ms5.hinet.net
     * WWW Home Page [2]http://linux.ntcic.edu.tw/~jsfrank/
     * ļ֮ȨȡӢ֮ԭDaniel Barlow ֮ͬ⣻
       ½ѫд˷ļеȨĿԸý
       ɢļΨ˽ڲ˵ԭⲻϣҲ
       ġ
     * v0.1൱ֲڣľ﷨ṹ̫ɢv0.2
       ĵϰһĲ׵ĵطeither
       ֣Ӣ˳eitherãָһHOWTOͳ
       ӦϰԣлϵĲ졣
     * м仰ûһǿֱҲ벻
       ֻñԭˣҪǸµģҡ
     * v0.1淭ʼΪ11/7/97ֹΪ11/19/97
     * v0.2ʼڣ5/13/98ֹΪ6/3/98
       
1.2 뾲

   ĿǰLinuxķչӿĽһ㽲Linuxִеĸʽ
   ãȡϵͳģLinuxӦһְɣĶ
   ļ԰ִе
   
   Ҫأִйóʽfile磬file /bin/bashͶˡ
   ELFĳʽԣөĻʾѶϢẬELFۣ˵a.outģ
   ѶϢڻ Linux/i386
   
   ELFa.outʽĲ֮½ۣܹ㷺รELFǱȽ
   ĸʽһԣܵĳ̶Ƚϼѡ
   
1.3 ߵ˽

   Ȩ˵Ϸɹ涨Ͱļβˡ֮⣬һһЩ
   òĻҪû¸ɣҲҪUsenet϶һЩʵ
   ⣻УҪΪԼCԵĹרŷһЩbugsbugs
   ۣⲻ͵춸߱㲻ѧڹүǰˣ˵
   ΪǵӢǵòʧġ
   
1.4 ӡˢŰ

   ڶPostscriptdvihtmlʽͱ仯ͻ
   ָֻʽ˶һЩرǵơժ¼
   ԭʼȣͳͳǴֻ͡ĻĳЩҪǿġ
   Щûй̶ġԣͿԴﵽǿЧˡ
   
   ļͬʱҲõһõdvi postscript֮
   İ汾־½(section)ıţHTMLĻЩֻ
   ˳УûȥԵݣ㿴Ǵְ
   Ļ, ־ֻ֣ûĺ⣻ϿΪ
   
   õshellBourne shellC shellٵȻBourne shell
   ﷨õC shellĻ趨﷨
   
% setenv FOO bar

   ҪBourne shellĻһд
   
$ FOO=bar; export FOO

   ʾʾǾַ#Ǯַ $Ļпֻ
   rootѡȻҪЩŪϵͳֱ䣬
   ҿһҲḺรףˣ:-)
   
   11/8/97. 5/13/98޶
   
2. Ķ

2.1 GCC-HOWTOĶ

   ļLinux HOWTOϵ֮һ仰˵дLinux HOWTO
   վҵķ٣
   [3]http://sunsite.unc.edu/pub/linux/docs/HOWTO/HTMLİ汾ܻǽ
   µİ汾Դ
   [4]http://ftp.linux.org.uk/~barlow/howto/gcc-howto.htmlץ
   
2.2 GCCصĶ

   ׼gcc˵ļ渽ڷеԭʼ(source distribution)ڣ¿
   ˣͷtextinfo.infoֵҪ·ʹ죬
   һƬcdromȻи߶ȵҲɣԼuntarȻٰ
   ӦλԪһһ/usr/infoĿ¼¡Ĳ
   [5]tsx-11վȥι۲ιۡ룬ûбҪǵµİ汾ɣ
   
   libcļ˵ԴһGNU libc.infoĸʽ棬stdio
   ֮⣬Linux libc˵൱꾡ȷһֿLinuxarchive
   [6]manpagesҵϵͳУsystem call2ڣlibcfunction
   3ڣļ˵
   
2.3 GCC

   ж:
   
   (a) [7]ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/վ
    ʽLinux GCCϵͳ(distribution)ѾõĿִе
   дļʱ2.7.2(gcc-2.7.2.bin.tar.gz)µİ汾
   
   (b)ᣨFree Software FoundationGCCԭʼ
   վ [8]GNU archivesȡáûбҪǵİ汾һ²У
   汾ȷĿǰµġLinux GCCά(maintainers)Ժ
   бµİ汾configure(script)Զ趨и
   顣пղ [9]tsx-11˵İ汾
   Ҫõġ
   
   ҪдһЩõ壨вûɶ;
   ·ĴܡһС̸ҲҪģ
   
2.4 Cʽͷ

   ѡһ׳ʽȡ(i)ϵͳELFĻa.outģ(ii)ϣϵ
   ͳһ֣Ǵlibc 4libc 5һĵĽ飬
   ȥELF-HOWTO˵һʣELFļĶأ٣٣ƫУ
   Ͳļͬλáվ [10]tsx-11ҵҪġ
   
   libc-5.2.18.bin.tar.gz
          --- ELFʽݣELF shared library images̬ʽ
          static librariesͷCѧʽݣ
          
   libc-5.2.18.tar.gz
          ---libc-5.2.18.bin.tar.gzԭʼ롣ҲҪΪ.bin.
          (package)бıͷʱԥ
          ºֱCʽȽϺãֱ˼ұõĶλ
          (binaries)ͿˡŵˣҵΣ˼ұ
          õĶλͽֻҪNYSshadow password
          £ҪԼƶҡ
          
   libc-4.7.5.bin.tar.gz
          --- a.outĹʽ(shared library images)뾲̬ʽ
          ⣬;Ϊǰlibc 5׼湲ٶƵģҪ
          ʹa.outĳʽǼչa.outĳʽȻĻǲҪ
          ġ
          
2.5 йĹ (as, ld, ar, strings etc)

   ĿǰΪֹ֮ǰ̸Ķһվ [11]tsx-11ϣͿҵЩ
   ʽĿǰİ汾binutils-2.6.0.2.bin.tar.gz
   
   ҪעbinutilsֻELFĿǰlibcİ汾ҲELFģ
   Ȼϰa.outиELFlibca.outlibcһʹã
   ٺòˡɷϵģCʽݵķչԼĽŲ
   ELFĸʽкܺõɣҪa.outĶȻҶ
   ͻƣ񲻿ɵĴ
   
   11/9/97
   
3. GCCİװGCC趨

3.1 GCCİ汾

   shellʾ¼gcc -vөĻϾͻʾĿǰʹõGCCİ
   ͬʱҲһ൱ɿķȷõELFa.out
   ҵϵͳϣִgcc -vĽǣ
   
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
gcc version 2.7.2

   ѶϢָ˼Ҫ飺
     * i486 ָõgccΪ486΢д---ĵ
       3865863΢ľƬɵĳʽ룬˴˼ǿ
       ʹõġ֮486ĳʽĳЩطмpaddingĹܣ
       Կ486ܵñȽϿ졣386ĻԣִгʽЧܲ
       ʲ᲻Ӱ죬ֻĻóʽԵĴһЩ
     * box ˵һҲҪҲָslackware
       debian߸ʲҲǣޣĿ¼i486-linux
       ʵɵٮٮߣԶֽԼgcc
       Ĺ趨һװ档һ:-)
     * linux ʵָlinuxelflinuxaoutһ𲻱Ҫ
       ָһֻõİ汾졣
          + linux ָELF汾2.7.0.Ǹµİ汾Ļ
            a.outˡ
          + linuxaout ָa.outĸʽlinuxĶa.outELFʱ
            linuxaoutͻ˳ˮۣҡһ䣬һĿˣ㲻
            ῴκΰ汾2.7.0.gcclinuxaoutġ
          + linuxelf Ѿʱˡָͨ2.6.3gcc汾Ҳ
            ELFĿִеҪעǣgcc 2.6.3ڲELFʽ
            ʱbugsĿǰõǡ汾Ͽ
            
     * 2.7.2 汾š
       
   ԣܽ2.7.2gccԲELFʽĳʽ롣򵥣
   Ȱɣeh
   
3.2 װᶼĶȥ?

   װgccʱûϸĿөĻǴһķϵͳgcc
   ץװĻҲ֪Щװסϵ
   ͳЩطص£
   
     * /usr/lib/gcc-lib/target/version/ Ŀ¼󲿷ݵıס
       طġпִеĳʽʵĹ⣬һ
       Щض汾ĳʽͷҲᴢڴˡ
     * /usr/bin/gcc ָǱʽ---Ҳʵ(command
       line)ִеĳʽĿ¼ɹְ汾gccʹãֻҪòͬı
       Ŀ¼װͿˡҪ֪ڶİ汾һ
       shellʾ´gcc -vҪǿִĳ汾ͻgcc -V
       version磺
       
# gcc -v
Reading specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
gcc version 2.7.2
# gcc -V 2.6.3 -v
Reading specs from /usr/lib/gcc-lib/i486-box-linux/2.6.3/specs
gcc driver version 2.7.2 executing gcc version 2.6.3

     * /usr/target/(bin|lib|include)/ װֵĿa.out
       elfĳһֵĽ(cross-compiler)ȵȣЩ춷Ŀ
       non-native target(s)ĳʽ⣬binutilsasldȵȣ
       ͷȶҵʹֻװһgccǿ
       Щԭ׼ĶӦ
       /usr/(bin|lib|include)ˡ
     * /lib//usr/lib Ŀ¼ȶϵͳnative-systemĳʽ
       Ŀ¼Ӧóʽõ/lib/cppҲҪ---ϣ
       /usr/lib/gcc-lib/target/version/ Ŀ¼�Ū
       symlinkָǶ [ע:νnativeָĿǰϵͳ
       a.outelfĸʽΪڶgccһְ汾ȵȡnative˼
       ǡġġ롮ġȵȣõһƬCD-ROM
       ͷβLinuxװɣLinuxΪɫŨҵƽ̨
       ټװһЩһĿȻС롮ʡ ޹
       Σ롮롮ΪȵȵͬʱҲ
       ڶdefault˼ڡٸ˵ļֵжϺϲã
       nativenon-nativeӦûǡ]
       
3.3 ͷ˨?ͷ˨?

   аװ/usr/local/includeĿ¼µıͷųĻ
   Linux3Ҫıͷ
   
     * /usr/include/Ŀ¼µıͷ󲿷ݶH.J.Luչlibc
       (libc binary package)ṩġһֻ˵󲿷ݡԭΪ
       Դıͷcursesdbmʽȵȣ
       õµlibcϵͳĻ°汾ɰѾ
       ֧ԮcursesdbmˡǶ֮Ϊ֮զģ [
       ע:libc binary packageָԶλʽ(machine code)֮׼
       ԭʼ루textҪȫɡlibcλ׼
       ֮ӣȥbinarylibc׼ͨơ]
     * ںԭʼķϵͳ(kernel source distribution)
       /usr/include/linux  /usr/include/asm ͷЩ
       <linux/*.h>  <asm/*.h>Ӧзᣨsymbolic links
       Ŀ¼linux/include/linux  linux/include/asmк֮־
       ĻװЩᣬͲӦֻģkernelѡ ԭ
       ʼѹunpackingᣬҲ֣ᷢҪںĵĿ¼
       kernel directorymake configĶܶĵ
       <linux/autoconf.h>İæȴп汾ͬ
       ɺİ汾asmֻԼһᣬmake
       configʱŽѡ [ע:ԭἰautoconf.hʱǡMany
       files depend on <linux/autoconf.h>,which otherwise may not exist,*
       ˴֮otherwise֮ӦΪݴ(adj)ָһһ
       ͬġ֮⣬ԭݴӾӦΪ(i) Many files
       depend on <linux/autoconf.h>. (ii)<linux/autoconf.h> of other
       condition may not exist. һ以ȶԣ˴Ӧָͬڲͬ汾֮
       ¡] ԣĿ¼/usr/src/linux£⿪ĵĳʽʱ
       ָʾɣ
       
$ cd /usr/src/linux
$ su
# make config
(ش⡣ͨشȷҪġ)
# cd /usr/include
# ln -s ../src/linux/include/linux .
# ln -s ../src/linux/include/asm .

     * <float.h><limits.h><varargs.h><stdarg.h> <stddef.h>֮
       ĵͬı汾죬㡮˵ġ
       /usr/lib/gcc-lib/i486-box-linux/2.7.2/include/ƣͬ
       Ŀ¼Ƶĵطҵ 11/11/97 5/14/98
       
3.4 (Building cross compilers)

  Linuxҵƽ̨(target platform)
  
   Ѿõgccԭʼ룬ֻͨҪѭINSTALLָʾһе
   趨 makeٽconfigure --target=i486-linux --host=XXX on
   platform XXXܰϷˡҪעǣҪLinuxкĵıͷ
   ͬʱҲҪ(cross assembler)뽻(cross
   linker)Դ [12]ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
   
  Linuxԭʼҵƽ̨(source platform)MSDOSΪҵƽ̨
  
   UghԵģҪõ׼emx׼goȥ
   [13]ftp://sunsite.unc.edu/pub/Linux/devel/msdosҲûвԹЩ
   ûа취֤ʲᡣ
   
4. ֲʽʽ

4.1 gccжķ

   ֻҪִgccʱ -vҳõgccԶ㶨
   ʲš磬ҵĻ
   
$ echo 'main(){printf("hello world\n");}' | gcc -E -v -
Reading specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
gcc version 2.7.2
 /usr/lib/gcc-lib/i486-box-linux/2.7.2/cpp -lang-c -v -undef
-D__GNUC__=2 -D__GNUC_MINOR__=7 -D__ELF__ -Dunix -Di386 -Dlinux
-D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__i386
-D__linux -Asystem(unix) -Asystem(posix) -Acpu(i386)
-Amachine(i386) -D__i486__ -

   дĳʽõһЩLinuxеԣЩ޷ֲĳʽ
   룬ʽǰǸأʾ
   
#ifdef __linux__
/* ... funky stuff ... */
#endif /* linux */

   __linux__ͿԴĿģϸһ㣬linuxมlinuxҲж壬
   ϾȻPOSIXı׼
   
4.2 ˵

   gcc˵ļgcc info pageEmacsڣC-h iȻѡ
   gccѡҪŪCD-ROMûѹ㣬
   ȻõǾɰġõķƶεarchive
   [14]ftp://prep.ai.mit.edu/pub/gnumirrorsվ̨ȥgccԭʼ
   ץؼңһ
   
   gcc manual pagegcc.1 ˵ѾʱˣҪԱ˳û¸Ӳ
   뿴ͻ˵ˡ
   
  ƮƮ
  
   ִgccʱֻҪƨ-OnѡgccԹԵ
   ѱĻ롣nһп޵Сͬ汾gcc
   nȷĹЧһ͵ġΧǴ0ҪţҲ
   Ҫѱ롣仯2ѱҪһ㡣3ѱҪٶ
   һ㣬һ㣩
   
   gccڲὫЩתһϵе-f-mѡִgccʱ-v
   -QܺĿÿһֵȼ-OǶӦЩѡñ˵-O2
   ҵgcc߻˵
   
enabled: -fdefer-pop -fcse-follow-jumps -fcse-skip-blocks
-fexpensive-optimizations
         -fthread-jumps -fpeephole -fforce-mem -ffunction-cse -finline
         -fcaller-saves -fpcc-struct-return -frerun-cse-after-loop
         -fcommon -fgnu-linker -m80387 -mhard-float -mno-soft-float
         -mno-386 -m486 -mieee-fp -mfp-ret-in-387

   Ҫõѱȼı֧Ԯģe.g. -O6Ч
   ͸ıṩߵȼЧһġ˵ʵڵģг
   ȥgccʽ룬ڱʱ˴⣬ĲʲõĹ롣
   иѱ뷽ϵµİ汾㣨users
   Ļܾͻᷢgccжĳʽˡ
   
   gcc 2.7.02.7.2usersӦעһ㣬ʹ-O2ʱһbug
   ǣǿۼ(strength reduction)ȻûãҪϲ±
   gccĻһİ汾Ը󣻲ȻĻһҪȷ
   ÿαʱм-fno-strength-reduceร
   
   11/12/97
   
  иԵ΢
  
   һЩ-mʮôȴ޷ɸֵȼ-Oʹá֮
   Ҫ-m386-m486֣gccðڱĳʽר
   Ϊ386486дġһ-mʽ룬ڱ˴˵Ļ
   ִУ-m486Ƚϴ󣬲386ĻҲȽ
   ˡ
   
   Ŀǰ-mpentium-m586šLinusǿ-m486
   -malign-loops=2 -malign-jumps=2 -malign-functions=2õѱ486
   ʽ룬þͿԱalignmentPentiumҪйgaps
   Michael Meissner˵
   
     ҵĵиң-mno-strength-reduce٣Ҫҿɲ̸ǿ
     bugѽѾһ۵սˡһҲx86Ļ
     ϲϿĳʽ룬Ϊx86Ļݴĥġڣ
     GCC's method of grouping registers into spill registers vs.
     other registers doesn't help eitherͳϣǿۼĽʹñ
     ȥüӷݴԼӷȡ˷㡣ʵϣڻ
     -fcaller-savesҲֻǸ©Ҳ˵
     
     ҵĵ߸ٶȵĸ˵-fomit-frame-pointerܻҲܲ
     κε׬ͷνһݴ
     ⡣棬x86ĻתָΪķ
     νѵõļռҪframeõĻҪöࣻ
     仰˵IcacheԳʽԲûʵϵİǸ
     -fomit-frame-pointerĻͬʱҲǸ߱ÿκк֮ᣬ
     ѵָꣻȻframeеĴĻ
     ѵʱѻ
     
   йⷽһλLinus
   
     ҪעǣҪõ״ִЧܣǧҵĻ
     ΣһҪвԡgccĲãпܾһ
     رϣԸѱĽ
     
   11/14/97 5/15/98
   
  Internal compiler error: cc1 got fatal signal 11
  
   Signal 11ָ SIGSEGV segmentation violationָͨ
   ˵gccԼõָе󣬶һд벻ļ
   ԣһgccbug Ȼԣgccһ֧ܲ
   ɿõҲ˴ӵϽṹ뾪˵ָ
   ֮Ҫѡһ˿RAMԳʽgccԿһժ
   ڡ޷¸ֻbug---¿ʼʱѶϢûһ
   ֱͬһط---Ǽȷ,Ӳ屾(CPU,,
   ǿȡ).ǧҪΪĵԿͨĲԡ
   Windowsܵú˳ʲģͻعͷ˵gccһ
   bugЩԶͨûʲʵϵļֵǺܺĽ
   ⣬ҲҪΪʱͣڡmake zImageĽ׶ΣҪ
   gccbug---ȻͣǶmake zImageʱҪĵ
   ܾͳ200һķ
   
   ظbugңдһСĳʽ
   չʾֻbugĻͿ԰bug棬ȻemailFSF
   linux-gcc̳ͨȥοgcc˵ļʲϸѶ,
   Ҫġ
   
4.3 ֲ

   ݱϢָĳڶûֲLinux
   ȥԿ϶ǣһһֵҲûС:-)
   
   ţһ㡣һԣԭʼֻҪһЩֲ޸ģͿԿ˷Linux
   100%POSIXݵʡκε޸ģ˲ݴظԭߣ
   ǺнԵľٶֻҪõmakeܵõһִе
   ˡ
   
  BSDͽ ( bsd_ioctldaemon  <sgtty.h>)
  
   ʽʱ-I/usr/include/bsd-lbsdĳʽ⡣磺
   Makefileڣ-I/usr/include/bsdӵCFLAGSһУ-lbsd
   LDFLAGSһУҪBSD̬źΪҲҪټ
   -D__USE_BSD_SIGNALˡΪ-I/usr/include/bsd뺬˱ͷ
   <signal.h>֮ᣬmakeʱͻԶˡ
   
  ʧķӡ(SIGBUS, SIGEMT, SIGIOT, SIGTRAP, SIGSYS etc)
  
   LinuxPOSIXȫݵġЩźŲPOSIX---ISO/IEC
   9945-1:1990 (IEEE Std 1003.1-1990), paragraph B.3.3.1.1 sez:
   
     POSIX.1ʡSIGBUSSIGEMTSIGIOTSIGTRAPSIGSYSźţ
     ΪǵΪʵķʽϢϢأҲ޷ʵķࡣȷʵ
     ʽᣬԷЩźţǱļ˵ʲĻ
     ·ͳģԼָκǵķչصơ
     
   Ҫ⣬ҲķSIGUNUSED¶Щźš
   ȷķӦʽı#ifdefЩŶԣ
   
#ifdef SIGSYS
/* ... non-posix SIGSYS code here .... */
#endif

   11/15/97 5/22/98
   
  K & R
  
   gccһANSIݵıֵǣĿǰĳʽ붼ANSI
   ı׼ȰANSIϲANSIṩı׼׫дCʽƺ˼
   -traditional֮⣬ûʲԶ̸ˡThere is a
   certain amount of finer-grained control over which varieties of brain
   damage to emulate;вgcc info page
   
   Ҫעǣ-traditionalıԵԣЧҲ
   gccܹܵġΧ, -traditional-fwritable-stringsʹ
   ִϼռ(ӳʽռƳطǲ
   д)óʽļռӵġ
   
  ǰôķîϺԭ
  
   ǣ֪Linuxೣõĺɾ޼ڱ
   ͷڣʱƵĺԭڳʽڣǰôܾ
   ﷨ǰҵatoi()atol()
   
  sprintf()
  
   ڴ󲿷ݵUnixϵͳϣsprintf(string, fmt, ...)صstringָ꣬Ȼ
   ⷽLinuxѭANSIصȴǷstringڵԪĿ.ֲʱ
   SunOSоġ
   
  fcntl صĺFD_*Ķ嵽װ?
  
   <sys/time.h>ͷ Ϊԭ棬fcntlҲ뺬
   ͷ<unistd.h>
   
   һԣmanual pageSYNOPSIS½гҪıͷ
   
  select()ļʱ---ʽִʱᴦæµ-ȴ״̬
  
   ܾúܾǰ,select()ļʱֻΨԶѡʹ
   manual pagesȻεľ棺
   
     select()ӦǽʱֵеĻٴԭʼʱʼ
     ʣŵʱ䡣δİ汾ܻʹʵ֡ˣĿǰԣ
     Ϊselect()֮ᣬʱָȻᱻһַǳǵ
     뷨ร
     
   δǵǰˣ٣ԿԿselect()صģ
   ǿ۳ȴδķѵʱᣬʣŵʱֵڼʱ
   ʱûϴͽʱΪ0κ
   select()ͬļʱstructureУselect()̽
   
   Ҫ⣬ֻҪÿκselect()ǰѼʱֵŵʱ
   structureڣûˡĳʽ룬
   
      struct timeval timeout;
      timeout.tv_sec = 1; timeout.tv_usec = 0;
      while (some_condition)
            select(n,readfds,writefds,exceptfds,&timeout);

   ĳɣ
   
      struct timeval timeout;
      while (some_condition) {
            timeout.tv_sec = 1; timeout.tv_usec = 0;
            select(n,readfds,writefds,exceptfds,&timeout);
      }

   ⣬Щ汾Mosaic൱ģֻҪһεĵȴMosaic͹
   ˡMosaicөĻϽǣǲиԲԲġתĵ򶯻ǿ
   ת죬ͱʾϴ·ϴ͹
   
  жϵϵͳ
  
  磺
  
   һ֧ʽCtrl-ZֹȻִʱԲCtrl-Cж
   źŵӳսȡϵͳͻᱧԹ˵"interrupted system call"
   "write: unknown error"ѶϢ
   
  㣺
  
   POSIXϵͳźŵĴһЩɰUnixҪһ㡣
   Linuxܾͻִsignal handlersˡ
   
     * ͬ(ʱĵδ)
     * ϵͳеĴֵ
     * ϵͳеִڼ select(), pause(), connect(),accept(),
       read() on terminals, sockets, pipes or files in /proc, write() on
       terminals, sockets, pipes or the line printer, open() on FIFOs,
       PTYs or serial lines,ioctl() on terminals, fcntl() with command
       F_SETLKW, wait4(), syslog(), any TCP or NFS operations.
       
   ҵϵͳԣҪĿܾЩϵͳˣ creat(),
   close(), getmsg(), putmsg(), msgrcv(), msgsnd(), recv(), send(),
   wait(), waitpid(), wait3(), tcdrain(), sigpause(), semop() to this
   list.
   
   ϵͳڼ䣬һźţ֧ʽӦ׼handlerӦˣ
   handlerͻᱻСhandlerȨתƻϵͳʱ
   жϣҴֵ趨-1errno趨EINTRʽû
   ᷢ£Ծ͹ˡ
   
   ķѡ
   
   (1) ÿаװsignal handlersigactionż
   SA_RESTART磬еĳʽ
   
  signal (sig_nr, my_signal_handler);

   ĳɣ
   
  signal (sig_nr, my_signal_handler);
  { struct sigaction sa;
    sigaction (sig_nr, (struct sigaction *)0, &sa);
#ifdef SA_RESTART
    sa.sa_flags |= SA_RESTART;
#endif
#ifdef SA_INTERRUPT
    sa.sa_flags &= ~ SA_INTERRUPT;
#endif
    sigaction (sig_nr, &sa, (struct sigaction *)0);
  }

   ҪעǣⲿݵıӦõϵͳ֮ᣬread()write()
   ioctl() select() pause()  connect()ʱȻмEINTR
   ʾ
   
   (2) ԼúȷؼEINTR
   
   read()ioctl()ӡ
   
   ԭʼĳʽƬΣʹread()
   
int result;
while (len > 0) {
  result = read(fd,buffer,len);
  if (result < 0) break;
  buffer += result; len -= result;
}

   ޸ĳ,
   
int result;
while (len > 0) {
  result = read(fd,buffer,len);
  if (result < 0) { if (errno != EINTR) break; }
  else { buffer += result; len -= result; }
}

   ԭʼĳʽƬΣʹioctl()
   
int result;
result = ioctl(fd,cmd,addr);

   ޸ĳɣ
   
int result;
do { result = ioctl(fd,cmd,addr); }
while ((result == -1) && (errno == EINTR));

   עһ㣬Щ汾BSD UnixڶΪִϵͳСҪϵ
   ͳжϣʹ SV_INTERRUPTSA_INTERRUPTš
   
  дִ
  
   gccusersֹܻ۵뷨ŵǴĳִ
   ʱ---ִֻѡˣִᴢڳʽļ
   ڡpageŵimageϣĵswapļռ䣬
   κγдľٶɷҳĴ(segmentation fault)һ
   ɫأ
   
   Ͼһĳʽԣܻһ⡣磬mktemp()ݵ
   (arguments)ִ mktemp()᳢*ʵλ*д
   
   
   ķ(a)-fwritable-strings룬ʹgcc˳÷
   ռڣ(b)ַȨĲ¸дһΪִ
   ںǰstrcpy()Ͽȥ
   
  Ϊʲexecl()ʧܣ
  
   ΪеķʽԡexeclĵһҪִеĳʽ.ڶ
   еĳʽargvСסͳϣargv[0]ֻ
   ʽûдִʱŻ趨ֵޣӦд
   
execl("/bin/ls","ls",NULL);

   ֻУ
   
execl("/bin/ls", NULL);

   ִгʽκɽͳһ뺯ĿǰѴ˳ʽĶ̬ʽ
   ӡ٣a.outġELFԡͲ.
   
   ֪˳ʽѶһЩ򵥵Ľãο̬һ
   ½ڣlddmanual page
   
   11/16/97 6/2/98
   
5. 

5.1 Ԥƣlint

   lintLinuxԲûкܹ㷺;ҪΪ󲿷ݵ˶gcc
   ṩľѶϢõľ-Wall---;Ҫgcc
   еľѶϢֳbut probably has more mnemonic value if
   thought of as the thing you bang your head against.
   
   ·һʵõpublic domain lintλ
   [15]ftp://larch.lcs.mit.edu/pub/Larch/lclintҲ֪վж
   þˡ
   
5.2 

  ҪܽѶŵһ֧ʽͷ
  
   Ҫ-gĲʽҲ-fomit-frame-pointer
   ʵϣ㲻Ҫ±еĳʽֻ±ĿǰڳĲ
   ݼɡ
   
   a.out̬ԣʽ-fomit-frame-pointerɣʱ
   gdbͱӢ֮ˡʱ-gѡӦþ̬
   ˣΪʲҪ-gԭˡ
   
   ʧܣҲlibg.aǾ/usr/lib/Ŀ¼£
   libg.alibg.aһCԺرʽ⡣һlibc׼ھͻ
   libg.aȻĻ°ģҪlibcԭʼԼ
   ʵӦòҪŶԡʲĿģ󲿷ݵ£ֻ
   libg.aᵽ/usr/lib/libc.aܵõ㹻Ѷˡ
   
  ǣܲܰѳѶõ
  
   ܶGNUڱʱ趨-gѡִе
   ⣨ͨǾ̬ᣩʵϣⲢһŵ뷨
   
   ʽautoconfconfigure壬ͨͿ
   ./configure CFLAGS=./configure CFLAGS=-O2صѶȻĻ
   üMakefileˡȻõELFʽԶ̬ķʽ
   ᣬǷ-g趨ƽİ-gõ
   
  ʵõ
  
   ˽⣬󲿷ݵ˶gdbԴ [16]GNU archive sitesõԭ
   ʼʽǵ [17]tsx-11ÿִеxxgdbһXĳʽֲ
   gdbҲ˵Ȱװgdbװxxgdbxxgdbԭʼ
   [18]ftp://ftp.x.org/contrib/xxgdb-1.08.tar.gzҵ
   
   ⣬UPSʽRick SladkeyֲɹUPSX»úܺã
   xxgdb---gdbXǰ˽棨X front end֧ʽһ
   ص㣬ûʱȥһ֧õĳʽ㿼ǿxxgdb
   ȱõLinuxԭʼ
   [19]ftp://sunsite.unc.edu/pub/Linux/devel/debuggers/ҵԭʼ
   ʽ [20]ftp://ftp.x.org/contrib/ups-2.45.2.tar.Z
   
   ܻᷢһĹstraceҲ൱áʾ
   ϵͳУһӵڶ෱Ĺܣֱû
   ԭʼĻstrace԰ҳЩ·ƣpath-namesѱִ
   ڣ exacerbating race conditions in programs that you suspect
   contain them;Уstraceѧϰʽڵִеġµİ汾
   Ŀǰ3.0.8ҵ [21]ftp://ftp.std.com/pub/jrs/
   
  ʽפʽ
  
   ڵ͵ĳפʽ(daemon programs)ִfork()Ȼֹ
   ʹóʱˡ
   
   ˽򵥵ķfork()һжϵ㣨breakpointʽͣ
   ֹʱǿfork()0
   
(gdb) list
1       #include <stdio.h>
2
3       main()
4       {
5         if(fork()==0) printf("child\n");
6         else printf("parent\n");
7       }
(gdb) break fork
Breakpoint 1 at 0x80003b8
(gdb) run
Starting program: /home/dan/src/hello/./fork
Breakpoint 1 at 0x400177c4

Breakpoint 1, 0x400177c4 in fork ()
(gdb) return 0
Make selected stack frame return now? (y or n) y
#0  0x80004a8 in main ()
    at fork.c:5
5         if(fork()==0) printf("child\n");
(gdb) next
Single stepping until exit from function fork,
which has no line number information.
child
7       }

  ĵ
  
   Linuxʱ̬ͨ趨ɲҪĵҪϲǵĻ
   shellbuiltinʹЧC-shellݵshelltcsh
   ԣ
   
% limit core unlimited

   Bourne shellshellsh, bash, zsh, pdkshʹ﷨
   
$ ulimit -c unlimited

   ҪиŶյĺĵcore file namingfor example,
   if you're trying to conduct a post-mortem using a debugger that's
   buggy itselfԶĺĳʽһССĸһ
   fs/binfmt_aout.cfs/binfmt_elf.cĳʽƬ(in newer
   kernels, you'll have to grep around a little in older ones)
   
        memcpy(corefile,"core.",5);
#if 0
        memcpy(corefile+5,current->comm,sizeof(current->comm));
#else
        corefile[4] = '\0';
#endif

   01.
   
5.3 

   ܣProfilingһ֧ʽЩлִеʱ
   õķԳʽѻҳʱʱ˷ѵĶԣ൱õķʽ
   ҪʱѶtiming informationĿĵ-p룬
   Ҫĵ壬ҲҪgprofbinutils׼
   gprofmanual pageɵ֪ϸڡ
   
   11/18/97
   
6. 

   춾̬빲ʽ߼䲻ݵĸʽĲ붯*link*ʹָ
   ***õĳʽʹʱ*ͷ
   ʹһ½ڱøࡣ and, actually, the overloading of the
   word `load' in a comparable but opposite senseٸҲ
   ˣԸ²ع춵ġ
   
   Ϊ΢ߵǳִڼΪ*̬*һ
   һ½̸ҲڱĵطҰѶ̬*̬*
   һ½С仰˵һ½̸ģȫָڱ
   ᡣ
   
6.1 ʽ vs̬ʽ

   ʽһ᣻ҲǽзɢСʽ
   Ƿ©ЩʲᡣȻһЩǺܶʽ---磬
   뿪йصСʽͻὫʽصṩĳʽʹ
   áһLinuxϵͳϣЩСʽ/lib/usr/lib/Ŀ¼ҵ
   
   õǾ̬ĳʽʱҳʽģ飬Ȼʵʽǿ
   ִеڡȻԹʽԣͲˡʽִ
   һǺţָ*ʽִʱȱʽ*Ȼ
   ʽͼʹִеøСͬʹøٵļŵռ
   LinuxڶΪṲʽ⣬ֻҪLinuxҵЩʽĻ
   ûʲ⣻Ȼ,Linuxͻᾲ̬ˡҪʽĻ
   Щʽ⣨*.sa for a.out, *.so for ELFǷסǸڵĵط
   ǿɶȡġ
   
   Linuxϣ̬ʽlibname.aƣʽ
   Ϊlibname.so.x.y.z˴x.y.zָ汾ŵʽʽͨ
   ָ̬ʽ⣨Ҫģ.sa׼ĳʽ
   뾲̬ʽָʽ
   
   lddList Dynamic Dependenciesĳ֧ʽҪЩʽ
   ⡣
   
$ ldd /usr/bin/lynx
        libncurses.so.1 => /usr/lib/libncurses.so.1.9.6
        libc.so.5 => /lib/libc.so.5.2.18

   ˵ҵϵͳϣWWW*lynx*libc.so.5 (the C library)
   libncurses.so.1ն˻өĻĿƣĴڡĳ֧ʽȱԣ
   lddͻ˵statically linkedǡstatically linked (ELF)
   
6.2 ռУsin() ĸʽ

   nm ʽӦûг˳ʽοзšָӦ
   ھ̬빲ʽϡ֪tcgetattr()Ķģ
   
   
$ nm libncurses.so.1 |grep tcget
         U tcgetattr

   *U*ָ*δ*---Ҳ˵ncursesʽõtegetattr()ǲûж
   Ҳ
   
$ nm libc.so.5 | grep tcget
00010fe8 T __tcgetattr
00010fe8 W tcgetattr
00068718 T tcgetpgrp

   *W*˵*̬(weak)*ָѶ壬ɲͬʽеһ
   򵥵**壨tcgetpgrp*T*ʾ
   
   ̸⣬Ĵ𰸱libm.(so|a)ˡж<math.h>ĺ
   mathsʽڣˣõκһʱҪ-lm
   ˳ʽ⡣
   
6.3 X

   ld: Output file requires shared library `libfoo.so.1`
   
   ldƵѰĲϣݰ汾Ĳͬ
   ΨһһԺڶĿ¼/usr/libˡϣĳ
   ʽҲѰУͱ-Lѡ֪gccld
   
   Ҫ㷢һЧҲûУ͸Ͻ쿴ǵǲǻԹԵԭء
   a.outԣ-lfooᣬʹldȥѰlibfoo.sashared stubs
   ûгɹͻỻѰlibfoo.astaticELFԣ ld
   libfoo.soȻlibfoo.alibfoo.soͨһţ
   libfoo.so.x
   
6.4 Լĳʽ

  ư汾
  
   κεĳʽһʽҲbugsڡҲܲ
   һЩµص㣬ĿǰڵģĹЧǽɵƳ
   ʹǵĳʽԣܻһ⡣һ֧ʽǸЩɵ
   ִеĻ죿
   
   ԣ˳ʽ汾ŵĹǽʽ*Ҫ**Ҫ*ı
   ű࣬ͬʱ涨*Ҫ*ıǲõʽľɳʽжϵ
   Դӳʽĵֱİ汾ʵϣϸELFԽ
   һĻԣȥΪʲˣ libfoo.so.1.2
   Ҫ汾1Ҫ汾2Ҫ汾ıſ£Ҳʲᶼû
   ---libcһ*̶*Ĺlibc.so.5.2.18
   ʽơҪ汾ıǷһЩĸߡκοӡ
   ASCIIԪҲǺܺġ
   
   ELFa.outʽҪĲ֮һùʽϣ
   ELFΪȽϼһЩ
   
  ELFʲᶫ˨ߣ
  
   ELFExecutable and Linking FormatUSLUNIX System
   LaboratoriesչɵĶλʽĿǰӦSolarisSystem V
   Release 4ϡELFǵĵԶԶLinuxȥõa.outʽ
   GCCCʽķչʿ1995ELFΪLinux׼Ķλʽ
   
  ˣ
  
   һ춡/news-archives/comp.sys.sun.miscļ
   
     ELFExecutable Linking FormatSVR4ʽĿĵ
     ʽELFCOFFǶ˲ٵĹܡELFԣ**ʹ
     ġELFһĿĵΪsections紮аϣҴ˴
     Ϊĳȣһ̶СУЩCOFFĲһ
     Ҫ̶ĳطҲҪĳ˳Сʹϣ׽
     ϣԼµĽĿĵڡELFҲһǿĳ
     ʽΪDWARFDebugging With Attribute Record FormatĿǰLinux
     ȫ֧ԮDWARF DIEsDebugging Information Entriesᴮл
     ELFγ .debugĽDWARF DIEsÿһ .debugһЩ
     ҹ̶СѶ¼ļϣһⳤȵĴУӵиӵԣ
     ҳʽϻСΧƵ״ϽṹдDIEsܲ׽Ĵ
     ѶCOFF .debug޷ġC++ļ̳ͼ
     
     ELFǴSVR4Solaris 2.0 ELFȡʽ⣨ELF access library
     ڴȡġ˳ʽṩһٵĽELFʹELFȡʽ
     ҪĶ֮һǣ㲻Ҫȥ쿴һELFquaˡUNIXĵ
     Elf*ʽȡelf_open()֮ᣬӴʱʼֻ
     elf_foobar()ĳһݼɣҪѵʵڴŵ
     imageһҡ
     
   ELFȱELFȼ辭ʹ࣬ELF-HOWTOۼҲ
   ͿELF HOWTOӦļͬǡ
   
  ELFʽ
  
   libfoo.soΪʽ⣬Ĳ
   
$ gcc -fPIC -c *.c
$ gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o
$ ln -s libfoo.so.1.0 libfoo.so.1
$ ln -s libfoo.so.1 libfoo.so
$ LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH ; export LD_LIBRARY_PATH

   һΪlibfoo.so.1.0Ĺʽ⣬Լldʵ
   libfoo.soʹö̬ʽdynamic loaderҵ
   libfoo.so.1Ϊ˽вԣǽĿǰĿ¼ӵLD_LIBRARY_PATH
   
   ֵ춳ʽɹ֮ʱ˰Ƶ/usr/local/libĿ¼
   £趨ȷ·libfoo.so.1libfoo.so.1.0
   ldconfigڲϵĸ£ʹ󲿷ݵϵͳ˵ldconfigڿ
   ִСlibfoo.soֶʽ¡Գʽɷӣ
   ͷȣǱһ˿̬ȣ򵥵ķ
   libfoo.so -> libfoo.so.1һldconfigͬʱµ
   ᡣҪû趨Ķͻǧٹֵ
   ֡ʱ򣬿ɱ˵û㰡
   
$ su
# cp libfoo.so.1.0 /usr/local/lib
# /sbin/ldconfig
# ( cd /usr/local/lib ; ln -s libfoo.so.1 libfoo.so )

  汾šsoname
  
   ÿһʽⶼһsonameѰĳʽһ
   ƣὫsonameеĶλڣʵ
   ʵĵڳʽִڼ䣬̬ʽѰӵsonameĵĵ
   ǳʽĵˣһΪlibfoo.soĳʽ⣬Ϳһ
   libbar.sosonameˡᵽlibbar.soĳʽʽʼִʱ
   Ѱҵılibbar.soˡ
   
   һҲûУһ㣬˽ͬ汾ͬһ
   ʽڵһϵͳϹԭȴǹؼ֮ԿLinuxʽ׼
   ʽ˵libfoo.so.1.2Ҹʽһlibfoo.so.1soname
   ˳ʽǼӵ׼ʽĿ¼£e.g. /usr/libldconfigὨ
   libfoo.so.1 -> libfoo.so.1.2ʹȷimageִڼҵ
   ҲҪlibfoo.so -> libfoo.so.1ʹldڼҵȷsoname
   
   ޣʽڵbugsµĺȥκβִ
   ĳʽɲӰĸı䣩ؽ˳ʽ⣬ԭеsoname
   Ȼĳʽ⵵Գʽıʹеĳʽжϣֻ
   sonameеı---У°汾Ϊlibfoo.so.2.0soname
   libfoo.so.2ٽlibfoo.soתµİ汾ˣ
   Ȼָ˺ƽ
   
   ʵ㲻ҪԴַʽʽȷǸõĴͳELF
   ڳʽϵĵԣʹĸ㲻״ĵڣ
   Ҳʾ͵ȥ
   
   ELFܽ᣺辭ǵĹ۲췢и˵ʽҪƻ
   ԣҪܲ᣻ķʽᣬеһоͶ
   ˡ
   
gcc -shared -Wl,-soname,libfoo.so.major -o libfoo.so.major.minor

  a.out---ɾɵĸʽ
  
   ʽıELFҪԭ֮һҲ˵,a.outܻ
   ôڵġftpվȥץ
   [22]ftp://tsx-11.mit.edu/pub/linux/packages/GCC/src/tools-2.17.tar.gz
   ѹᷢ20ҳļĶҺܲϲԼɵƫ
   ֵ£Ǵļ䣬ӦҲԺҴʯ
   ͷԼĽŵƢɣ:-)
   
  ZMAGIC vs QMAGIC
  
   QMAGICһƾɸʽa.outΪZMAGICĿִе ʽָʽ
   ʹõһҳ޷map0-4096ġΧûmappingʱ
   NULL dereference trappingӵסı߽ЧӦִе
   СԼ1Kң
   
   ֻмϵ֧ԮZMAGICһײĵ֧Ԯָ
   ʽĿǰİ汾֧ԮQMAGICѡʵϣⲢûжӰ죬Ϊ
   ĿǰĺָʽִС
   
   *file*ӦÿȷϳʽǲQMAGICĸʽġ
   
  
  
   һa.out(DLL)Ĺʽʵĵһš*foo*
   ļΪĳʽԣЩlibfoo.salibfoo.so.1.2
   Żlibfoo.so.1һָlibfoo.so.1.2Щʲõģ
   
   ڱʱldѰlibfoo.saǳʽ*stub*Һִ
   exportedָָꡣ
   
   ִڼ䣬̬ʽѰlibfoo.so.1һᣬ
   ʵĵʳʽɸ³ɽµİ汾κδʱ
   ʹô˳ʽӦóʽ°---˵libfoo.so.1.3---ʱ
   ldconfigһ΢СĲָµİ汾ʹκԭʹþɰ
   ĳʽе˿Ĳá
   
   DLLʽ⣨֪νķ---Զϰɣͨǵ
   ̬Ҫôࡣ*holes*ʽռԱ
   **ԲռκεĴŵռ䡣һ򵥵cpУʹmakehole
   ʽͿԴﵽЧΪǵλַǹ̶ͬһλϣڽ
   ʽᣬ԰õǧҪõELFĳʽ⡣
   
  ``libc-lite''?
  
   libc-litelibc汾ڴŵƬϣҲ󲿷ݵ΢
   UNIXβûаcurses, dbm, termcapȵȵĳʽ롣
   /lib/libc.so.4ᵽһlitelibcὨİ汾ȡ
   
  ᣺
  
   ʱĸңҿʲҲֻҪۻ㹻
   һд*
   
   빲ƫƫʽȴɾ̬ģ
          ṩldǷȷʹldҵÿһӦĹʽ⣬
          ELFԣָһlibfoo.soimagea.out
          libfoo.saˡܶ˽ELF binutils 2.52.6֮ᣬͲ
          ---ڵİ汾ѰʽʱǻۣԲûн
          еὨΪļܹݣǻ۵
          Ϊ˸ɾˣ⣬*ǻ*жϴĻ൱ߣ
          鷳⻹࣬ҲǺ˾ȥ⣡
          
   DLLĹ߳ʽmkimageҲlibgcc 
          libc.so.4.5.x֮ᣬlibgccѲǹĸʽˣ
          *-lgcc*֮`gcc -print-libgcc-file-name`ĵ
          ţback-quotes⣬ɾ/usr/lib/libgcc*ĵ
          Ҫ
          
   __NEEDS_SHRLIB_libc_4 multiply defined messages 
          ͬɵһֽ
          
   ``Assertion failure'' message when rebuilding a DLL ?
          һصѶϢпܵԭǣԭʼjump.varsڣ
          Ŀռ̫٣һjump table slotsִ
          й߳ʽ2.17.tar.gz׼ṩġgetsize
          ɷټΨһĽǣ˳ʽҪİ汾ţǿ
          صݵ
          
   ld: output file needs shared library libc.so.4 
          ͨǷڵĳʽⲻlibcXʽ⣩
          -gĲȴûһʹ-staticĴѶϢ
          
          ʽ.sa stubsͨһδķ_NEEDS_SHRLIB_libc_4
          һɽlibc.sa stubȻ-gʱʹ
          libg.alibc.aһֱûнҲͻᵼ
          ĴѶϢˡ
          
          ֮-gűʱ˼-staticȻͱ-gᡣͨ
          -gĵʱõĳѶѾ㹻ʱ
          ԲҪˡ
          
7. ̬

   һ½ĿǰǼһ㣻ӾELF HOWTOʱⲿٶչʱ
   ˡ
   
7.1 

   Linuxйʽ⣬֮ǰһ½ڣһ
   ˵ʣ̸еͷ衣һЩչʱڱɵĹ
   ӳٵʱڲɡ
   
7.2 ѶϢ

   ĴĸңҲκε£ҿ԰д**
   
   can't load library: /lib/libxxx.so, Incompatible version
          a. out only ָûxxxʽȷҪ汾ɱΪ
           ŪᵽĿǰӵеİ汾Ϳˣ˵Ļֻ
          ĳʽҳѡȥץµİ汾.ELFƵ
          ѶϢ
          
ftp: can't load library 'libreadline.so.2'

   warning using incompatible library version xxx
          a. out onlyĳʽĴҪ汾֧ʽĻҪ
          ʽȻִСֻǿ룬Ӧûʲ˺ɣ
          
7.3 ƶ̬

   һ黷ö̬Ӧ󲿷ݵĻldd;Ҫ
   һusersĻҪøࡣҿԺܷ趨lddϸֲִ
   СЩ
   
     * LD_BIND_NOW --- ں֮ǰǲóʽѰҵġ趨
       Żʹóʽһ룬еѰұᷢͬʱҲʼʱ
       Գʽȷеᶼûʱžͱú
       á
     * LD_PRELOAD趨һʹ**磬
       ҪԼķԣһû*malloc*д׼
       滻ĸʽmallolc.Ȼ᣺
       
$ LD_PRELOAD=malloc.o; export LD_PRELOAD
$ some_test_program

       LD_ELF_PRELOAD  LD_AOUT_PRELOAD ƣǽȷĶλ
       ̬趨 LD_something_PRELOAD  LD_PRELOAD Ƚȷ
       һᱻõ
     * LD_LIBRARY_PATHһԷֺŸĿ¼ƣѰʽ⡣
       ldԣûκεӰ죻ִֻڼӰ졣⣬ִ
       setuidsetgidĳʽԣһЧġLD_ELF_LIBRARY_PATH
       LD_AOUT_LIBRARY_PATHſɸݸĶλʽֱͬ
       Ѱ·һ£ӦûõLD_LIBRARY_PATHҪ
       ѰĿ¼ӵ/etc/ld.so.conf/Ȼִldconfig
     * LD_NOWARN a.outһ趨һLD_NOWARN=true; export
       LD_NOWARN봦fatal-warningsǴҪ汾
       ݵȣľѶϢ
     * LD_WARNELF趨һʱὫͨѶϢġCan*t
       find libraryתɾѶϢĲԣⲢûжô
       ǶlddͺҪˡ
     * LD_TRACE_LOADED_OBJECTSELFһʹóʽΪldd
       ִеģ
       
$ LD_TRACE_LOADED_OBJECTS=true /usr/bin/lynx
        libncurses.so.1 => /usr/lib/libncurses.so.1.9.6
        libc.so.5 => /lib/libc.so.5.2.18

7.4 Զ̬׫дʽ

   ϤSolaris 2.x֧ԮĶ̬ĹĻᷢLinux
   ǳһH.J.LuELFʽļdlopen(3)
   manual pageld.so׼ҵй㷺ۡи
   򵥡-ldlᡣ
   
#include <dlfcn.h>
#include <stdio.h>

main()
{
  void *libc;
  void (*printf_call)();

  if(libc=dlopen("/lib/libc.so.5",RTLD_LAZY))
  {
    printf_call=dlsym(libc,"printf");
    (*printf_call)("hello, world\n");
  }

}

8. 뷢չʿ

8.1 Bug

   дLinuxģgccϵͳ⡣
   kernelİ汾𣿻ǳʽİ汾þ̬ʽᣬ
   ǾʧˣԽ¼һСγʽչʾֻbug
   
   Щ֮ᣬ㽫֪ʽڵbugsʲᡣgccԣbug
   info˵ġld.soCmathsʽ⣬email
   linux-gcc@vger.rutgers.eduܵĻһ֧ԼСʽ
   չʾbugҸ˵Ҫ֧ʽЩʲʵ
   Щʲᡣ
   
8.2 Эչ

   ҪæչgccCʽ⣬һ¾Ǽ
   linux-gcc@vger.rutgers.eduֻ̳ͨ뿴̳ͨЩ
   ʲᣬһ̳archivesλ
   [23]http://homer.ncm.com/linux-gcc/£Ϳʲˡ
   
9. 

9.1 ˰

     Only presidents, editors, and people with tapeworms have the right
     to use the editorial ``we''.
     
   (Mark Twain)
   
   HOWTOļȫֲMitchum DsouzaGCC-FAQ ļд󲿷ݵѶ
   ֱGCC-FAQļõĵһ˳ƴʣΪһ
   ˵Ҫһ˵һûвԹЩӲ
   ϵͳǸɢģɱ˵û㰡"Ļ
   ϡ
   
   ļй׵ʿУASCII˳г Andrew
   Tefft, Axel Boldt, Bill Metzenthen, Bruce Evans, Bruno Haible, Daniel
   Barlow, Daniel Quinlan, David Engel, Dirk Hohndel, Eric Youngdale,
   Fergus Henderson, H.J. Lu, Jens Schweikhardt, Kai Petzke, Michael
   Meissner, Mitchum DSouza, Olaf Flebbe, Paul Gortmaker, Rik Faith,
   Steven S. Dick, Tuomas J Lukka, ȻLinux Torvaldsû
   ˶ͱһҲûˣԲµġ:-)
   
   벻Ҫκεð֮ûг
   HOWTOFAQй׵Ļemailңһġ
   
9.2 

   ĿǰΪֹļû֪ķ汾֡ϣһ
   ȥһøصˡҽԻҪԣ
   ʣźֻкüٷ֮һȰѱ˰һ԰ɣʲ
   ⣬Ҷæġ
   
9.3 ӭκεĻ

   Ÿ [24]dan@detached.demon.co.ukҵPGP public key (ID
   5F263625) ҵĺ༦ [25]web pagesʹãбҪ
   Ļ
   
9.4 Ϸɹ涨

   Ĳù̱춸ĳߡ
   
   HOWTOļİȨDaniel Barlow <dan@detached.demon.co.uk> 
   κʽý壬εġӵķʽظݻ
   GCC-HOWTOֻҪݰȨеĸƷСҵĽģ
   ҹҺϣ֪ͨйصϸڡ
   
   ʲᣬǷ롢ļļصļ
   Linux HOWTOļȣѭݰȨҲ˵
   HOWTOļд˵ļǲԶļ϶
   ƣӰļķȨġȻЩرǿģ
   LinuxЭ磬ʼĵַͷ
   
   ֮ܶϣеHOWTOļܹ͸ֲͬĹܵܵĴȥ
   ȻͬҲϣݰȨԴļͷκη
   HOWTOsļļƻǶԸӵ֪ͨ
   
   κ⣬Linux HOWTOЭTim Bynumϵemail address
   gregh@sunsite.unc.edu
   
   ԭת£ All trademarks used in this document are acknowledged
   as being owned by their respective owners.
   
   This document is copyright (C) 1996 Daniel Barlow
   <dan@detached.demon.co.uk> It may be reproduced and distributed in
   whole or in part, in any medium physical or electronic, as long as
   this copyright notice is retained on all copies. Commercial
   redistribution is allowed and encouraged; however, the author would
   like to be notified of any such distributions.
   
   All translations, derivative works, or aggregate works incorporating
   any Linux HOWTO documents must be covered under this copyright notice.
   That is, you may not produce a derivative work from a HOWTO and impose
   additional restrictions on its distribution. Exceptions to these rules
   may be granted under certain conditions; please contact the Linux
   HOWTO coordinator at the address given below.
   
   In short, we wish to promote dissemination of this information through
   as many channels as possible. However, we do wish to retain copyright
   on the HOWTO documents, and would like to be notified of any plans to
   redistribute the HOWTOs.
   
   If you have questions, please contact Tim Bynum, the Linux HOWTO
   coordinator, at linux-howto@sunsite.unc.edu via email.
   
   6/3/98
   
10. 

   ͷֵԪоͰASCII˳
   
     * -fwritable-strings [26]39 [27]56
     * /lib/cpp [28]16
     * a.out [29]1
     * ar [30]10
     * as [31]8
     * <asm/*.h> [32]19
     * atoi() [33]40
     * atol() [34]41
     * binaries too big [35]63 [36]65 [37]77
     * chewing gum [38]3
     * cos() [39]68
     * debugging [40]59
     * dlopen() [41]82
     * dlsym() [42]83
     * documentation [43]4
     * EINTR [44]52
     * elf [45]0 [46]71
     * execl() [47]57
     * fcntl [48]47
     * FD_CLR [49]44
     * FD_ISSET [50]45
     * FD_SET [51]43
     * FD_ZERO [52]46
     * file [53]2
     * <float.h> [54]20
     * gcc [55]6
     * gcc -fomit-frame-pointer [56]61
     * gcc -g [57]60
     * gcc -v [58]14
     * gcc, bugs [59]15 [60]28 [61]29 [62]84
     * gcc, flags [63]13 [64]25 [65]26
     * gdb [66]64
     * header files [67]17
     * interrupted system calls [68]51
     * ld [69]9
     * LD_* environment variables [70]80
     * ldd [71]81
     * libc [72]7
     * libg.a [73]62
     * libgcc [74]79
     * <limits.h> [75]21
     * lint [76]58
     * <linux/*.h> [77]18
     * manual pages [78]5
     * <math.h> [79]70
     * maths [80]69
     * mktemp() [81]55
     * optimisation [82]27
     * QMAGIC [83]76
     * segmentation fault [84]30 [85]54
     * segmentation fault, in GCC [86]33
     * select() [87]50
     * SIGBUS [88]34
     * SIGEMT [89]35
     * SIGIOT [90]36
     * SIGSEGV [91]31 [92]53
     * SIGSEGV, in gcc [93]32
     * SIGSYS [94]38
     * SIGTRAP [95]37
     * sin() [96]67
     * soname [97]73
     * sprintf() [98]42
     * statically linked binaries, unexpected [99]66 [100]78
     * <stdarg.h> [101]23
     * <stddef.h> [102]24
     * strings [103]11
     * <sys/time.h> [104]48
     * <unistd.h> [105]49
     * <varargs.h> [106]22
     * version numbers [107]12 [108]74
     * weird things [109]72
     * ZMAGIC [110]75

References

   1. http://www.linux.org.tw/CLDP/
   2. http://linux.ntcic.edu.tw/~jsfrank/
   3. http://sunsite.unc.edu/pub/linux/docs/HOWTO/
   4. http://ftp.linux.org.uk/~barlow/howto/gcc-howto.html
   5. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
   6. ftp://sunsite.unc.edu/pub/Linux/docs/
   7. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
   8. ftp://prep.ai.mit.edu/pub/gnu/
   9. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
  10. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
  11. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
  12. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/
  13. ftp://sunsite.unc.edu/pub/Linux/devel/msdos
  14. ftp://prep.ai.mit.edu/pub/gnu
  15. ftp://larch.lcs.mit.edu/pub/Larch/lclint
  16. ftp://prep.ai.mit.edu/pub/gnu
  17. ftp://tsx-11.mit.edu/pub/linux/packages/GCC
  18. ftp://ftp.x.org/contrib/xxgdb-1.08.tar.gz
  19. ftp://sunsite.unc.edu/pub/Linux/devel/debuggers/
  20. ftp://ftp.x.org/contrib/ups-2.45.2.tar.Z
  21. ftp://ftp.std.com/pub/jrs/
  22. ftp://tsx-11.mit.edu/pub/linux/packages/GCC/src/tools-2.17.tar.gz
  23. http://homer.ncm.com/linux-gcc/
  24. mailto:dan@detached.demon.co.uk
  25. http://ftp.linux.org.uk/~barlow/
  26. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.39
  27. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.56
  28. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.16
  29. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.1
  30. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.10
  31. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.8
  32. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.19
  33. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.40
  34. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.41
  35. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.63
  36. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.65
  37. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.77
  38. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.3
  39. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.68
  40. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.59
  41. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.82
  42. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.83
  43. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.4
  44. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.52
  45. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.0
  46. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.71
  47. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.57
  48. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.47
  49. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.44
  50. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.45
  51. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.43
  52. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.46
  53. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.2
  54. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.20
  55. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.6
  56. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.61
  57. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.60
  58. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.14
  59. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.15
  60. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.28
  61. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.29
  62. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.84
  63. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.13
  64. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.25
  65. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.26
  66. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.64
  67. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.17
  68. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.51
  69. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.9
  70. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.80
  71. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.81
  72. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.7
  73. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.62
  74. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.79
  75. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.21
  76. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.58
  77. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.18
  78. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.5
  79. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.70
  80. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.69
  81. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.55
  82. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.27
  83. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.76
  84. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.30
  85. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.54
  86. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.33
  87. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.50
  88. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.34
  89. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.35
  90. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.36
  91. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.31
  92. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.53
  93. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.32
  94. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.38
  95. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.37
  96. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.67
  97. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.73
  98. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.42
  99. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.66
 100. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.78
 101. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.23
 102. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.24
 103. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.11
 104. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.48
 105. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.49
 106. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.22
 107. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.12
 108. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.74
 109. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.72
 110. file://localhost/tmp/zh-sgmltools.9205/GCC-HOWTO.txt.html#index.75
