








			 The Linux GCC HOWTOĶV0.1

		@: Daniel Barlow <dan@detached.demon.co.uk>

		 Ķ: ؾ(Frank J.S. Chen)<frank63@ms5.hinet.net>

			    v1.17, 28 February 1996



				   Abstract

     og󪺤e]AFpbLinuxUҥ(set up)GNU CsĶ(com
     piler)HΫإ(set
     up)ǥiHӶ}on骺{w(libraries);P,
     {XsĶ(compiling),s(linking),(running)P(debug
     ging),]|[(overview).ogg@,bOӦ۩Mitch
     D'SouzaҦGCC-FAQ,ӳogNFGCC-FAQ.t~@ӨӷNOELF-
     HOWTOF;iHo,Linux GCC-HOWTO֭nä[NELF-HOWTO,
     GCC̥DnF.
     oOĤ@}o檺(z|Ǹ;ORCSǧ@(arti
     fact)).Pĳ,ڳw.



~~~GCC HOWTOĶ V0.1 ɥR     Taipei, Taiwan, R.O.C.

  1.  oĶ嬰Linux document pro
      jects(LDP)½ĶpetC@.ثe}http://www.lin
      ux.org.tw/CLDP/.wUͿDJ@pe.

  2.  ڨèSӭvr½Ķ.FODĶqZiŪ,ڷ|yyդ@r,[oKL,άO²;o˰,iHɤ^嶡ykct,ByiHeqLê.

  3.  @rPM~J,|[Wr.

  4.  JĶx,߭`rJ,pbugs,shadow pass
      word,padding,hOd夣.YդUoǦrJAĶ㪺,Ф[.

  5.  夤YJ"[Ķ̵:**]"аO,hHB~.

  6.  ogĶ妳ĳPðݪ,emailfrank63@ms5.hinet.net.

  7.  WWW Home Page: http://wwwhome.fancy.com.tw/~frank/.

  8.  Ķ½Ķvwo^y@Daniel Barlow
      ͤPN;t,ؾͫOĶҦvQ,AiHN,HUشC''GoĶ,ߦɥRݭʤʪW,BiNĶ.

  9.  ½Ķ_l:11/7/97;I:11/19/97






The Linux GCC HOWTOĶV0.1						      1





The Linux GCC HOWTOĶV0.1						      2



1.  ͤW(Preliminaries)!

1.1  ELF vs. a.out


 "

 ثe,Linuxoiiܬ骺i.²@I,Linuxذɪ榡(for
mats)i,MAtάOX_Ӫ;Aiس.ŪFo󤧫,AN|DO@ؤF.



,nϧOO?椽ε{(utility)'file' (Ҧp,file
/bin/bash)NF.NELF榡{X,ܥXӪT|tELFr;pGOa.out榡,TN|㦳
Linux/i386rˤF.

ELFPa.out榡tB,|b򪺳`Q(ܼsx).ELFOs榡,@Ө,{׸.

1.2  @̪py(Administrata)

 "

 v(copyright informa
tion)PXkwWw(legalese),N\bo󪺧.~,......,٦@ǤoAܭn:NAۨSƷF,]nbUsenetW@ǧbʰݪD;٦,nѥHۤvC\O`p,Mo@ǤObugsbugsXӥH{,
iDOHAǵLN.̫;Zf}ɭ,A(,and picking your nose
while chewing gum)!  [Ķ̵:DoO@ꪺq? eh?
:-)t@إiO妳ʺ|rJ, O"and not picking your nose while chewing
gum."]

1.3  LPƪ(typography)

 pGA{bŪOPostscript,dviΪ̬Ohtml榡,AҬݨ쪺rܤƴN|uŪ¤r榡Hh@.SOO,ɮצW(file
names),RO(commands),ROX(command output)PKXӪlX(source
code),βγOrr˦(form).o˰,Yǻݭnjժܼ(vari
ables)HΨSSwGd(random things)Ө,NiHFjժĪGF.

Ūo󪺦P,A]|o@ӦΪ(usable)(index).YOdvi,
postscript,ުƦrNO`(sec
tion)s;pGOHTML,oǼƦr|ǱƦC,AiHηƹӳs(link
ing)۹諸;pGAݪO(plain)r, ƦrNuOƦr,
SOtN;ĳA֪@Ŭ!

کҥΪshellOBourne shell(OC shell),|Ҥl۵MOBourne
shellyk.pGAΪOC shell, ܼƳ]wyk|Uo:

     % setenv FOO bar

nOBourne shell, ڷ|oˤlg:

     $ FOO=bar; export FOO

pGܲŸ(prompt)ܪOrŸ#,ӤOrŸ
$,,ܦiOoөROuArootӤw.M!nOAդFoǽd,G˱oAtεoͨa,ڥiO@Id]|t!A߱n!:-)
[Ķ̵:o(ԫny)^_^.]








The Linux GCC HOWTOĶV0.1						      3



11/8/97Ķ.


2.  WoǪFF?

2.1  oyB

 oOLinux HOWTOtC@.,AiHbҦsLinux
HOWTO󪺺W쥦, p<URL:http://sun
site.unc.edu/pub/linux/docs/HOWTO/>.HTML榡(i|Os)iHq<URL:http://ftp.linux.org.uk/~bar
low/howto/gcc-howto.html>WU.

2.2  䥦

 "

gccObo檺lX(source distribu
tion)(UݴNF!),Ytex
tinfoP.infoɮ.nOAstv,Ϊ̬O@cdrom;M,ת@ߤ],AiHۤv⥦untar,MA۹줸@@/usr/infoؿU.pAPWz,
tsx-111 Wh@.L,ڷQ,SnѬO}O۳̷sa.



 libc󻡩بӷ.@جOGNU libc,H.info榡xs,Fst
dio~,lLinux libc۷ԺɺT.t@إiHbLinuxarchivemanpages2
WtΩIs(system call)(2`)Plibc(function)(3`)󻡩.

2.3  GCC

ѵG:

(a)AiHb<URL:ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/>W
Linux GCCot(distribution),BwsĶn(read-compiled)i(in
binary).ڦbgo,2.7.2(gcc-2.7.2.bin.tar.gz)O̷s.

(b)ۥѳn|(Free Software Foundation)ҵoGGCC̷slXiHqGNU
archives3
Wo.SnDoPWz@P~,LoӪTOثe̷s.Linux
GCC@Hh(maintainers)AiHܻPۦsĶoӳ̷s.config
ureROZ(script)|A۰ʫئn(set it all
up)ҦӰ.ĳAŤtsx-114
ݬ,w|ץ(patches)OA|QnΪ(apply).

pGQnsĶX@ǦΪFF(non-triv
ial)(Oo,٬OֲӺFFb!),U@p`ҽͪ]OAnƪ:

____________________

1. <URL:ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/>

2. <URL:ftp://sunsite.unc.edu/pub/Linux/docs/>

3. <URL:ftp://prep.ai.mit.edu/pub/gnu/>

4. <URL:ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/>







The Linux GCC HOWTOĶV0.1						      4



2.4  C{wPY

 "

boAӿ諸OM(i)AtάOELFάOa.out;(ii)AƱAt
ܦ@?pGAOqlibc 4@Ũlibc
5,򵹧A@Ө}ߪĳ,hݬELF-HOWTO.A@w|,bELF󪺭O?K!K!,Ntho@˪m.AiHbtsx-115
WAQn.

      libc-5.2.18.bin.tar.gz
	    --- ELF@ɵ{w(ELF shared library images),RA{w(static
	    libraries)PY(include files)(wCyPƾǵ{w).

      libc-5.2.18.tar.gz
	    ---libc-5.2.18.bin.tar.gzlX.oɮקAݭn,.bin.M(pack
	    age)tY(header
	    files).pGɧASݤM,oOnѨ˦ۤU,ʤsĶC{w;٬OνsĶnGi(bina
	    ries)NiHF.oاxZH,,ݧڪL:ΤHasĶnGiɤNѨMF.ubAQnNYSάOshadow
	    passwordpU,A~ݭnۤvӱʷnx.

      libc-4.7.5.bin.tar.gz
	    --- oɮתeOa.out@ɵ{w(shared library
	    images)PRA{w.oɮתγ~OFPezlibc
	    5M@s@a(coex
	    ist)ӳ]p,LDAQn~ϥΩΪ̵oia.out榡{,M,Oݭn.

2.5  pu (as, ld, ar, strings etc)




 "

ثe,Peҽͪ@,qtsx-116
W,NiHoǤu{.ثeObinutils-2.6.0.2.bin.tar.gz.

ݪ`NObinutilsuAΩELF榡,ثelibc]OELF;M,
ߺDa.outHpGELFlibcPa.outlibcpX(in conjunction
with)_Ӥ@_ϥ,
L̨OAnLƤF.i_{,C{woiHM(emphati
cally)}BڦVELF榡,DAuܦnz,ݭna.outFF(things),M,ja|y(encour
age)Ai},X[JUiתjy.

11/9/97Ķ


3.  GCCw(installation)Pҥ(setup)



____________________

5. <URL:ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/>

6. <URL:ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/>







The Linux GCC HOWTOĶV0.1						      5



3.1  GCC



 "

AiHbshellܲŸUJgcc
-v,ùWN|ܥXAثebϥΪGCC.ӳo]O@Ӭ۷iak,iHTwA{bҥΪOELFάOa.out.bڪtΤW,gcc
-vGO:

     $ gcc -v
     Reading specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
     gcc version 2.7.2

WTFX󭫭nƱ:

     i486.  oOX(indicates)AثebΪgccOF486LBz(proces
     sor)Ӽg-iAqO386Ϊ̬O586.o3طLBz(chips)ҽsĶӦ{X,OiHۮeϥΪ.tOBO486{XbYǦa観[Wpadding\,ҥHiHb486W]o.o386Ө,b{į(per
     formance)WèS򤣨}vT(detrimental
     effect),uLu(does)|{XܱoyyjF.

     box.   oiH@I]n;L]itҫ(OslackwareΪ̬Ode
     bian),Ϊ̮ڥ]O(ҥHo!㪺ؿW٬Oi486-linux).pAON,˦۰ʤإݩۤvgcc,AiHbإߪL{(build
     time)]wo@,HI(cosmetic effect).Nڰ@:-).

     linux. oOlinuxelf,Ϊ̬Olin
     uxaout.o@I|OHް_nxb,sO@ط|ھڧAҥΪӲ.


	  linux NELFYǸO2.7.0άOs;_h,NOa.outF.

	 linuxaout Na.out榡.linuxwq(defini
	  tion)qa.out󴫨ELF,lin
	  uxaoutN|,n@,F@ӥؼЪ(tar
	  get).],A|ݨ󪩥s2.7.0gcclinuxaout榡.



	 linuxelf
	  wgLɤF.q`O2.6.3gcc,ӳoӪ]iΨӲELFi(exe
	  cutables).n`NO,gcc
	  2.6.3bELF{Xɷ|bugs-pGAثeΪOoӪ,ĳA֪@.

     2.7.2 Ǹ.

ҥH,`_,ڦ2.7.2gcc,iHELF榡{X.No²,Ya!eh?

3.2  FF˦n᳣hF?

pGwgccɨSJӪݵۿù,Ϊ̧AOq@ӧ㪺otΤgccWXӦw˪,]\A|QD쩳oǪFF˦nObɮרt(file-
system)Ӧa.XӭIpU:

    /usr/lib/gcc-lib/target/version/ (Plؿ(sub-directo
     ries))jsĶ(compil








The Linux GCC HOWTOĶV0.1						      6



     ers)NObo઺.bo঳i檺{,ڦbsĶu@;t~,٦@ǯSw(ver
     sion-specific){wPY(include files).

     /usr/bin/gcc sĶXʵ{(driver)--NOAڦbROC(command
     line)W檺{.oӥؿiѦUتgccϥ,unAΤPsĶؿ(pWҭz)Ӧw˴NiHF.nDwO@,bshellܲŸUgcc
     -v.nOQjYӪ,Ngcc -V version.Ҧp:


	  # 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)/.  pGAˤFƺتؼЪ(multiple tar
     gets),Ҧpa.outPelf,Ϊ̬Y@تesĶ(cross-com
     piler);ݩDDyؼЪ(non-native target(s)){w,binu
     tils(as, ld)uPY(header
     files)iHbo.YϧAuwˤF@gcc,٬OiHbooǭ쥻NO̷ǳƪFF.pGObo,NӬOb/usr/(bin|lib|include)F.


     /lib/,/usr/lib P䥦ؿ,ODyt(native-sys
     tem){wؿ.\hε{|Ψ/lib/cpp
     ,]A]ݭn---@kW,Oq/usr/lib/gcc-lib/target/version/
     ؿ̫,NO˭ӲŸs(symlink)V.
     [Ķ̵:ҿnative,OثeAtάOHa.outelf榡D,Ϊ̤wgccO@ت.nativeNO'g','ꪺ'P'ѥͪ'......;A@CD-
     ROMYܧNLinuxw˧,LinuxX,AӤHS@p@~x,pGA[ˤ@Ǥ@˪ؼЪ,۵MN'g'P'~'(
     LFv),''P'~','ѥ'P'H'ϧO,Pɤ]tw(default)Nb.YA[WAӤH[P_Pߦn,ڷQΥDy(native)PDDy(non-
     native)½Ķٺ.]



3.3  Yɣz?Yɣz?

 "

Aۤvۦw˦b/usr/local/includeؿUY(header
files)ưb~,Linux٦t~3إDnY(header files):

     /usr/include/PlؿUY,jOH.J.LuoilibcM(libc
     binary package)ҴѪ.ڷ|u'j(most)'],
     O]Ai঳䥦ӷY(header
     files)(OcursesPdbm{w)\bo;רO,pGA{bΪO̷slibcotΪ(sª,wA䴩cursesdbmF.),FFhOHHQު!
     [Ķ̵:libc binary packageNHGiΦ(machine
     code)xsM,ëDlX(text),YnHĶX,h'libcGiɮM',m,Ghbi
     nary,HlibcMq.]













The Linux GCC HOWTOĶV0.1						      7



     b֤߭lXotΤ(kernel source distribution) ,/usr/include/linux
     P /usr/include/asm (Yoɮ: <linux/*.h> and
     <asm/*.h>)ӦŸs(symbolic links),isܥؿlinux/include/linux
     P
     linux/include/asm.pGAE[Ӫ,w˳oǪFF,NӥuOӽsĶ֤(ker
     nel)Ӥw.

     lXY(unpacking),iA]|o{,ݭnb֤ߪؿ(kernel direc
     tory)Umake configʧ@.ܦhɮ׳|̿<linux/auto
     conf.h>,iOoɮ׫oi]PӤsb.Yz֤ߪ,asmNuOۤv@ӲŸs,ȶȬObmake
     configɫإߥXӦӤw.  [Ķ̵:崣autoconf.hɬO'Many files depend on
     <linux/autoconf.h>,which otherwise may not exist,*'.Bother
     wiseήe(adj),'t@p','t@','P'N,Nήely}:
     (i). Many files depend on <linux/autoconf.h>.  (ii).<linux/autoconf.h> of
     other condition may not exist.
     PU@yۤ,BPbPpU.]

     ҥH,Abؿ/usr/src/linuxU,Ѷ}֤ߪ{X,NӵۤUܪa!


	  $ cd /usr/src/linux
	  $ su
	  # make config
	  [^UӪD.q`^oTän,DA~v_(go on and build)A֤.]
	  # cd /usr/include
	  # ln -s ../src/linux/include/linux .
	  # ln -s ../src/linux/include/asm .









     Ѧp<float.h>, <limits.h>,<varargs.h>, <stdarg.h> P<std
     def.h>ɮ,|HۤPsĶӲ,ݩAۤv'ӤH'ɮ,iHb
     /usr/lib/gcc-lib/i486-box-
     linux/2.7.2/include/P䥦(ۦP)ؿW٪a(places of that
     ilk).

     11/11/97Ķ

3.4  إߥesĶ(Building cross compilers)

3.4.1  NLinux@ؼЧ@~x(target platform)

 ]AwggcclX,q`Aun̴`INSTALLɤܫKi@ok.
make᭱Hconfigure --target=i486-linux --host=XXX on platform
XXX,NAܧF(do the
trick).n`NO,A|ݭnLinuxP֤ߪYɪ;ӥBA]ݭnإߥeĶ(cross
assembler)Pes(cross
linker),ӷO<URL:ftp://tsx-11.mit.edu/pub/linux/packages/GCC/>








The Linux GCC HOWTOĶV0.1						      8



3.4.2  Linuxӷ@~x(source platform),MSDOS@ؼЧ@~x

 Ugh.ܩ㪺,oӤjݭnΨ"emx"M(package)Ϊ̬O"go"M(exten
der).Цۦh<URL:ftp://sun
site.unc.edu/pub/Linux/devel/msdos>ݬ.ڨèSչLo,]]LkO(vouch)\(abil
ities).


4.  (Porting)PsĶ(Compiling){

4.1  gccۦwqŸ

 "

ungcc,[
-voӰѼ(switch),NXAҥΪogcc,۰AwqFŸ(sym
bols).Ҧp,ڪݰ_ӷ|o:

     $ 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__ -

YثeAbg{X,|Ψ@LinuxWS(Linux-specific fea
tures),⨺ǵLkӪ{X(non-portable bits),H󦡽sĶ(conditional
compilation)emROʬA(enclose in)_,iOӤDNO!

     #ifdef __linux__
     /* ... funky stuff ... */
     #endif /* linux */

__linux__YiFت;ݥJӤ@I,Olinux.Ⱥޫ̤]wq,,MOPOSIXз(not
POSIX compliant).

4.2  uWDU(invocation)

 gccsĶѼ(switches)Ogcc info page(bEmacs,UC-h
i,M'gcc'ﶵ).nOˤX,OACD-
ROMH,SoӪFFA,MNOA{bΪOª.oرpU,̦nkOʴLvarchive<URL:ftp://prep.ai.mit.edu/pub/gnu>άOmir
rorsxW,gcclɮק^a,si@f.

gcc manual page (gcc.1)
iHOwgLɤF.@AYۨSƷFnhݬݥ,N|iDAo,sAOLF.

4.2.1  X~(flags)


 "

 bROC(command line)Wgcc,unbѫ᭱[W-








The Linux GCC HOWTOĶV0.1						      9



Onﶵ,NgccĨĪAͥX̨Τƫ᪺X(output
code).o̪nO@ӥiiLp.Pgcc,nNqP䥿T(exact)\ĳ@;L,嫬dOq0(nC,ڤn̨Τ)ܤƨ2(̨Τƭnh@I),A3(̨ΤƭnAh@I,h@I).

gccb䤺|NoĶ@tC-f P-
mﶵ(options).gccɱaWX(flags)-vP-
Q,ANܲMݥXC@صŪ-OO(maps)쨺ǿﶵ(options).Ҧp,N-
O2,ڪgcciDڻ:

     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

nOAΪ̨ΤƵ(optimization level)AsĶү䴩(e.g.
-O6),򥦪ĪG,NAΧAsĶүണѪ̰Ū,O@˪G.b,oXhgcc{X,ΦbsĶɳOpBzoD,DncQ.YOiB̨ΤƤkXs,ӧA(ΧAusers)٬Oյ۳o˰,iN|o{,gcc|_A{(break
your code)F.


qgcc 2.7.02.7.2usersӪ`N,ϥή-
O2|@bugsb.V|O,jק(strength reduction)~MS(doesn't
work)!nOAwssĶgcc,O@ӭץ(patch)iH󥿳o~;M,@wnTwCsĶɳ|[W-
fno-strength-reduce!

11/12/97Ķ

4.2.1.1  өʪLBz(Processor-specific)

 @-mXLkǥѦUصŪ-Oӥ},MӫoOQΪ.o̥DnO-
m386P-
m486,ΨӧiDgccӧ⥿bsĶ{X@M386άO486Ҽg.׬Oέ@بӽsĶ{X,iHbW,-m486sĶXӪX|j,iOӦb386W]]|CNOF.

ثe|L-mpentiumάO-m586X.Linusĳڭ,iH-m486 -malign-loops=2
-malign-jumps=2 -malign-functions=2,ӱǫΤƪ486{X(486 code optimiza
tions),ӳo˰nNiHקKalignment(Pentiumäݭn)Ljgapso.
Michael Meissner:

     ڪĤP(hunch)iD, -mno-strength-
     reduce(K!ڥiObͱjקbug,wgOt~@ӪתԳF.)@ˤ]iHbx86W,͸֪{X,oO]x86Ȧs(reg
     ister)ۤiiȴb(and GCC's method of grouping registers
     into spill registers vs. other registers doesn't help
     either).ǲΤW,jקG|ϱosĶQΥ[kȦs(additional
     registers)H[kB(addition)ӨNkB(multiplica
     tion).ӥB,ڤ]bh(suspect)-fcaller-
     saves,i]uOӺ|}(loss)]w.
















The Linux GCC HOWTOĶV0.1						     10



     ӧڪĤCPhAתiD, -fomit-frame-
     pointeri|,]iण|Y.qoIӬ,YN׵ۦt@ӼȦsiΨӳBzOt(allo
     ca
     tion)D.t譱,Yºqx86bഫ(encodes)O(instruc
     tion
     set)XkWӬ,KN׵۰|(stack)ҥΨ쪺OŶnframeҥΨ쪺٭nӪh;yܻ,Icache{XӨèSWqB.YOդUΤF-
     fomit-frame-
     pointer,P,]NOiDsĶbCIs(calls),Nץ|(stack
     pointer);M,Nframe,YIsƤh,h\|Ȯɰn(accu
     mulate)_.

o譱DD̫@qܤOӦ۩Linus:

     n`NO,pGAQnǫΪp榨G(optimal perfor
     mance),idUO۫Hڪ.Lצp,@wni.gccsĶ٦\hѼ(switches)i,䤤iN@س̯SOզX(set),iHĄΤƪG.

11/14/97Ķ

4.2.2  Internal compiler error: cc1 got fatal signal 11





 "

 Signal 11O SIGSEGV, Ϊ `segmentation violation'.q`oO
gccۤvҥΪзPxb_,ӥBٹյۼgJݩ󥦪O.ҥH,oiO@gccbug.

M,jӨ,gccO@gLYKեBiaרΪnΧ@.]ΤFjqƵcPHмƶq.²,YOn糧@̬DP̤@ARAMյ{(RAM
tester),gcciH@KZa.pALksƻsobug---As}lsĶ,~TèS@X{bP@Ӧa---XGiHTw,OAw饻D(CPU,O,DOάO֨O).dUn]AqiHqL}{Ǫ(power-
on checks),ΪWin
dowsiH]oܶ,Ϊ̨䥦,N^LYӤjvŶǻoOgcc@bug;AҰoǴհʧ@,q`SڤW,ӥBSȤ]OܦXz.t~,]n]sĶ֤߮,`Odb`make
zImage'q,Nnj|oOgccbug---M|b!`make zIm
age',ݭnsĶɮץiWL200ɮ;ڭ̥b@ӤpaӨN.

 pGAiHвͳobug,ӥB(̦nOo˰)iHg@ӵup{Ӯiܳobug,ANiH⥦bug(bug
report),MemailFSF,Ϊ̬Olinux-gcclC(linux-gcc mailing
list).AiHhѦgcc,ݬݦԲӪT,OL̩һݭn.

4.3  ӯO(Portability)

 ڳ,ӳ\hX,YYFF{b٨SӨLinuxWh,iH֩wO,@w@IȤ]S.:-)

!g@I.@Ө,lXuݭn@ǧק(minor changes),NiHJA(get
over)Linux 100%PPOSIXۮeS(compli
ance).pGAF󪺭ק,ӱNǦ^(passing
back)@,|Oܦس]ʪ|(worth
while).oˤNuݭnΨ'make',No@ӥi檺ɮפF.

4.3.1  BSDЬ]BSDisms^ ( bsd_ioctl, daemon P <sgtty.h>)

 sĶ{,iHtX-I/usr/include/bsdPs-lbsd{w.(Ҧp:bAMake
fileɤ,-I/usr/include/bsd[CFLAGS@;-lbsd[LD








The Linux GCC HOWTOĶV0.1						     11



FLAGS@).pGAuQnBSDAH欰(BSD type signal behav
ior),]Aݭn[W-D__USE_BSD_SIGNALF.O]AΤF-
I/usr/include/bsdPtAFY<signal.h>,makeN۰ʷ|⥦[JF.

4.3.2  ʦL]`Missing' signals^

(SIGBUS, SIGEMT, SIGIOT, SIGTRAP, SIGSYS etc)




 "

 LinuxPPOSIXOۮe.L,ǫHäOPOSIXwq---ISO/IEC 9945-1:1990
(IEEE Std 1003.1-1990), paragraph B.3.3.1.1 sez:

     "bPOSIX.1ٲFSIGBUS, SIGEMT, SIGIOT, SIGTRAP,
     PSIGSYSH,O]̪欰(behav
     ior)P@覡O(implementations depen
     dent),ӥB]LkiAO(adequately catego
     rized).T{@覡(conforming implementa
     tions),KiHͲX(deliver)oǫH,iHH󻡩(docu
     ment)̬Ob˪(circum
     stances)UͲXӪ,HΫXP̪oi󭭨(any restric
     tions concerning their delivery)".

pץI,²,]O̲ª(cheesy)kNOHSI
GUNUSEDswqoǫH.ӥTkOH󦡪sĶ#ifdefӳBzoǰD~:

     #ifdef SIGSYS
     /* ... non-posix SIGSYS code here .... */
     #endif

11/15/97Ķ

4.3.3  K & R

 gccOӻPANSIۮesĶ;_ǪO,ثejhƪ{XŦXANSIҩwз.pGARANSI,wANSIѪзǨӼgC{,GFbsĶXW[W-
traditional~,NS䥦iHhͪF.There is a certain amount of
finer-grained control over which varieties of brain damage to emu
late;Цۦd\gcc info page.

n`NO,ާAΤF-tradi
tionalӧܻy,ĪG]ȫ]bgccүd.Ҧp, -tradi
tional|}(turn on)-fwritable-strings,ϱor`(string con
stants)ܸưOŶ(data space)(q{XOŶ(text
space),oaONgJ).o˰|{XOŶLΤW[.

4.3.4  emBz(Preprocessor)ŸfWƭ쫬ŧi(prototypes)


 "

 ̱`DO,pҬҪ,Linux\h`ΪƳwq(macros)sbY(header








The Linux GCC HOWTOĶV0.1						     12



files),ɭYۦƭ쫬ŧiX{b{X,emBz|ڵiykR(parse)em@~.`atoi()Patol().

4.3.5  sprintf()

 "

 bjUnixtΤW, sprintf(string, fmt,
...)Ǧ^Ostring,M,o譱Linux(`ANSI)Ǧ^oOJstringrƥ.i沾Ӯ,רOwSunOS,ݦĵı.

4.3.6  fcntl P; FD_*aڪwq쩳¦b?







 "

Nb <sys/time.h>Y. Fu쫬ŧi,AΤFfc
ntl,iA]QtAY<unistd.h>i.

@Ө,ƪmanual page|bSYNOPSIS`CXݭnY.

4.3.7  select() p(time-out)---{ɷ|B󦣸L-ݪA(busy-wait
ing).

 "

 ܤ[ܤ[He, select()pɰѼ(time-out parameter)uŪݩ(read-
only)Ӥw.YϨF̪,manual pagesMUoqĵi:

     select()ӲzӬOǥѾAץɶƭ,AǦ^ۭlp(origi
     nal time-
     out)}lҳѾlɶ.Ӫi|ϳo\{.],NثeӨ,YwbIsse
     lect(),pɫ(time-out
     pointer)M|HץL,iO@ثD`Qk!

ӴNbڭ̪eF!ܤ,boAiHݨ. se
lect()Ǧ^,Oݩ|FƩүӶOɶ,Ѿlɶ.pGbpɵ,Sƶǰei,pɤ޼(time-
out argument)K|]0;pG٦select(),HP˪time-out struc
tureөIs,select()K|ߨ赲.

YnץoD,unCIsselect()e,pɼƭ(time-out value)time-
out structure,NSDF.U{X,

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


令,









The Linux GCC HOWTOĶV0.1						     13



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

oӰD,bǪMosaic̬O۷ۦW,u@,MosaicNF.MosaicùkW,OOӶꪺ,|઺ayʵe.yoU,NܸƱqWǰeLӪtvUC!

4.3.8  ͤ_tΩIs(Interrupted system calls)


 "

4.3.8.1  x(Symptom):

@{HCtrl-Z(stop),MAs(restart)--Ϊ̬O䥦iHCtrl-
C_(interruption)Hp,pl{(child process)׵(termina
tion)--tδN|軡"interrupted system call"άO"write: unknown
error",Ϊ̽ѦpT.

4.3.8.2  DI:

POSIXtˬdH,_@ªUnixOnh@I.pGOLinux,iN|sig
nal handlersF--

     DPBa(asynchronously)(pɾwn)

     tΩIsǦ^(on return from any system call)

     bUCtΩIs: 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(), sys
     log(), any TCP or NFS operations.

N䥦@~tΦӨ,AݭniNOUoǨtΩIs(system calls)F: creat(),
close(), getmsg(), putmsg(), msgrcv(), msgsnd(), recv(), send(), wait(), wait
pid(), wait3(), tcdrain(), sigpause(), semop() to this list.

btΩIs,Y@H({ǳƦnhandler]F),han
dlerN|QIs.han
dlerNvಾ^tΩIs,|Xwgͤ_,ӥBǦ^ȷ|ߨ]w-1,errno]wEINTR.{èSQ|oͳoب,ҥHN|bot
tles outF.

حץkiH:

(1) CӧAۦw(install)signal handler,bsigac
tionX[WSA_RESTART.Ҧp,UC{,

       signal (sig_nr, my_signal_handler);


令,









The Linux GCC HOWTOĶV0.1						     14



       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);
       }

n`NO,oܧjqΨtΩIs,Isread(), write(),ioctl(),
select(), pause() P connect(),AMoۦˬd(check for)EINTR.pUҥ.

(2) AۤvoܩTa(explicitly)ˬdEINTR:

o̦Ӱwread()Pioctl()Ҥl.

l{q,ϥ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; }
     }


l{q,ϥioctl().

     int result;
     result = ioctl(fd,cmd,addr);


ק令,

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

`N@I,ǪBSD Unix,䤺w欰(default
behaviour)OstΩIs.YntΩIs_,oϥ SV_INTERRUPTSA_INTER
RUPTX.








The Linux GCC HOWTOĶV0.1						     15



4.3.9  iHgJr(Writable strings)




 "

 gccusers`hۼ[Qk(optimistic
view),۫HL̥YӦr@`ƨӥή---NuuOr`ƦӤw.],oئr`Ʒ|xsb{XOϬq(in
the code area of the pro
gram).oϰiHpageϺоimageW,קKӱswapOŶ,ӥBռgJ|ʳ|y~(seg
mentation fault).oiO@دSO!

¤@I{Ө, oi|ͤ@ӰD.Ҧp,Ismktemp(),ǻ޼(argu
ments)Or`. mktemp()|յۦb*Am(in place)*sgJ޼.

ץk~G(a)H-fwritable-
stringssĶ,gccN`ƸmbưOŶ(data
space).Ϊ(b)NIǦav(offending
parts)sg,tm@Ӥ`ƪr(non-constant string),bIse,Hstr
cpy()Nƫih.

4.3.10	Isexecl()|?

 "

 O]AIs覡.execlĤ@Ӥ޼ƬOAQn檺{W.ĤGӻP򪺤޼Ʒ|ܦAҩIs{argv}C(array).O:ǲΤW,argv[0]Ou{Saۤ޼ư,~|]w.ҥHo,Aӳo˼g:

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


ӤOu,

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

 {Ӥa޼(with no arguments),i(construe)O@ܽШ(invi
tation),تO⦹{ʺA{wW(dynamic library dependen
cies)SʦLX(print out).ܤ,a.outOo˪.NELFӨ,ƱNOoˤF.

(pGAQo{wT,@ǧ²檺i;ѦҰʺAJ(dynamic load
ing)@`,άOlddmanual page.)

11/16/97Ķ


5.  Debugging and Profiling

5.1  Preventative maintenance (lint)

 "

 lintLinuxӨèSܼsxγ~,DnO]jHມgccҴѪĵiT(warn
ings).i̦ΪNO-
WallѼƤF---oӰѼƪγ~OnDgccNҦĵiT{X.but probably has








The Linux GCC HOWTOĶV0.1						     16



more mnemonic value if thought of as the thing you bang your head against.

W@ӹΪpublic domain lint,
<URL:ftp://larch.lcs.mit.edu/pub/Larch/lclint>.ڨäDoӯ쩳hnNOF.

5.2  (Debugging)

 "

5.2.1  ڭn˰~NT@{Y?



 "

 AݭnK[-gѼƨӽsĶPs{,ӥBiH-fomit-frame-
pointerѼ.ƹW,AݭnssĶҦ{,uݭssĶثeAbYi.

 Na.out榡(configurations)Ө,@ɵ{w(shared libraries)OH-fomit-
frame-pointersĶӦ,oӮɭ,gdbNܱo^LΪZaF.sɵw-
gﶵ,ӴNtRAs(static linking)F;oNOn[-g]F.

 pGs(linker)s,iDA䤣libg.a,NOb/usr/lib/ؿU,֤Flibg.a.libg.aOSCy{w(spe
cial debugging-enabled C
library).@blibcM󤺴N|libg.a;M(sOo˪),AiݭnlibclXۤvإߤF.L,ڤWAӤݭn~.ެOت,jpU,uݱNlibg.as/usr/lib/libc.a,ANo쨬TF.

5.2.1.1  ,णⰣT?

 "

 ܦhGNUnbsĶs,|]w-
gﶵ,ӳo˰|yɹLjD(q`ORA).ڤW,oäO@ӫܼQk.

 pG{autoconf,ͤFconfigureROZ,q`ANiH./configure
CFLAGS=άO./configure CFLAGS=-O2T.M,AoˬdˬdMake
fileF.M,pAΪOELF,{K|HʺA覡s(dynamically
linked),׬O_-g]w;]AiH`ߧ-g(strip).

5.2.2  Ϊn(Available software)

 "

 A,@Hϥgdb.AiHqGNU archive sites7 l{;Ϊ̬Otsx-118
i.xxgdbO@X{(debug
ger),Ӱgdb(]NOAow˦ngdb,~Axxgdb).xxgdblXiHb<URL:ftp://ftp.x.org/con
trib/xxgdb-1.08.tar.gz>.

t~,UPS{wRick Slad
keyӦ\.UPSiHbXUoܦn,xxgdb---ȶȬOgdbXeݤ(X front

____________________

7. <URL:ftp://prep.ai.mit.edu/pub/gnu>

8. <URL:ftp://tsx-11.mit.edu/pub/linux/packages/GCC>







The Linux GCC HOWTOĶV0.1						     17



end).o䰣{@ju}SI,and if you spend any time debugging stuff,
you probably should check it out.esĶ(precom
piled)nLinuxPץ(patches)lXiHb<URL:ftp://sun
site.unc.edu/pub/Linux/devel/debuggers/>.ӳ̪쪺l{hb
<URL:ftp://ftp.x.org/contrib/ups-2.45.2.tar.Z>.

Ai|o{t@ӥΨӰustrace,]O۷.iHܥXѵ{(pro
cess)ҲͪtΩIs,ӥBپ֦䥦hcƪ\(multiplic
ity),OpGASlX,straceiHAX(figure
out)Ǹ|(path-names)wsĶi(binaries); exacerbating race condi
tions in programs that you suspect contain
them;٦,straceiӾǲߵ{Obq檺.̷s(ثeO3.0.8)ib<URL:ftp://ftp.std.com/pub/jrs/>.

5.2.3  I{(Background (daemon) programs)

 嫬`n{(daemon programs)Ofork(),Mפ(terminate){(par
ent).o˪kϱoɶuF.

 A(get around)oI²檺kNOfork()]@break
point.{,jfork()Ǧ^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	     }

5.2.4  ֤ɮ(Core files)

 Linux},q`պA(configura
tion)|]wn֤ͮɮ.nOAw̪,iHshellbuiltinROϨ䭫sͮ:NC-
shellۮeshell(ptcsh)Ө,|OUo:

     % limit core unlimited








The Linux GCC HOWTOĶV0.1						     18



Bourne shellshell(sh,bash,zsh,pdksh)hϥΤUyk:

     $ ulimit -c unlimited

pGAQnӦh~h(versatility)֤ɩRW(core file naming)(for example,
if you're trying to conduct a post-mortem using a debugger that's buggy itself)
,AiHA֤ߵ{(ker
nel)@Ipp(mod).@fs/binfmt_aout.cPfs/binfmt_elf.cɤPUC۲Ū{q(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

N01.

5.3  ǺV(Profiling)

 ProfilingOΨˮ֤@{ǳ(which
bits)O̱`IsάO檺ɶ̤[k.o{̨ΤƻPXɮɶOOӨ,O۷n覡.ANAҭnɵ{T(tim
ing information)تɮ(object files)[W-
pӽsĶ,ӥBpGnXɮ(output files)Nq(make
sense),A]|ݭngprof(ӦbinutilsM󪺩RO).Ѿ\gprofmanual
page,ioӸ`.

11/18/97Ķ


6.  s(Linking)

 ѩRA(static)P@(shared){w̶ۮe榡(incompatible binary
formats)t(distinction)Pʵ*link*Lqϥ(overload
ing)*sĶ᪺Ʊ*P*sĶL{ϥή(invoke)ҵoͪƱ*oƤWY,ϱoo@`ܱoF\h.(
and, actually, the overloading of the word `load' in a comparable but opposite
sense)L,A]NOoˤF,ҥHդUL.

 FyLŪ̪xb,ڭٰ̺(runtime)ҵoͪƬ*ʺAJ(dynamic
load
ing)*,o@DD|bU@`ͨ.A]|bOaݨڧʺAJyz*ʺAs(dynamic
link
ing)*,L|Obo@`.yܻ,o@`ҽͪ,OoͦbsĶ᪺s(link
ing).

6.1  @ɵ{w vsRA{w

 إߵ{̫@ӨBJKOs;]NONҦp{(pieces)զX_,ݬݬO_|FǤ.ܩ㪺,@ǨƱOܦh{|Q---Ҧp,}ɮ(open
files),۩ҦP}ɦp{(pieces)N|H{wɮ׫AѵA{.bqLinuxtΤW,oǤp{iHb/libP/usr/lib/ؿU.












The Linux GCC HOWTOĶV0.1						     19



AΪO@RA{w,s|X{һݪҲ(bits),M(physi
cally)N̫ɤ.M,@ɵ{wӨ,NOoˤF.@ɵ{w|bɤdU@ӲŸ(note),*{,Joӵ{w*.ܩ㪺,@ɵ{wOչϨϰܱop;]PϥΧ֪OPϺЪŶ.Linuxw欰Os@ɵ{w,unLinuxoǦ@ɵ{w,NSD;M,LinuxN|sRAF.pGAQn@ɵ{w,ˬdoǵ{w(*.sa
for a.out, *.so for ELF)O_b̸Ӧba,ӥBOiŪ.

bLinuxW,RA{w|libname.ao˪W;Ӧ@ɵ{whٰlib
name.so.x.y.z,Bx.y.zOǸ˦.@ɵ{wq`|sŸVRA{w(ܭn)P(on
a.out configura
tions)p.saɮ.зǪ{w|]t@ɻPRA{wخ榡.

AiHldd (List Dynamic Dependencies)ӬdXY{ݭnǦ@ɵ{w.

     $ ldd /usr/bin/lynx
	     libncurses.so.1 => /usr/lib/libncurses.so.1.9.6
	     libc.so.5 => /lib/libc.so.5.2.18

oObڪtΤW,WWWs(browser)*lynx*|̿libc.so.5 (the C
library)Plibncurses.so.1(׺ݾù)sb(pres
ence).YY{ʥFWߩ(dependencies), lddN|`statically
linked'άO`statically linked (ELF)'.

6.2  Interrogating libraries (`which library is sin() in?')



 "

  nm {wW ӷ|CX{wW٩ҰѦҨ쪺ҦŸ(sym
bols).oӫOiHΦbRAP@ɵ{wW.]AQDtcge
tattr()Obwq:AiHp

     $ nm libncurses.so.1 |grep tcget
	      U tcgetattr

*U*F*wq(undefined)*---]NOncurses{wΨtege
tattr(),OèSwq.A]iHo˰,

     $ nm libc.so.5 | grep tcget
     00010fe8 T __tcgetattr
     00010fe8 W tcgetattr
     00068718 T tcgetpgrp

*W*F*z(weak)*,NŸwwq,iѤP{wt@wqҨN(over
ridden).ӳ̪(straightforward)*`(normal)*wq(Otcgetp
grp)O*T*ҼХ.



DҽͪD,²׫KOlibm.(so|a)F.Ҧwqb<math.h>ƳOdbmaths{w;],AΨ䤤@ӨƮ,ݭnH-
lmѼƳs{w.

6.3  Xɮ???

ld: Output file requires shared library `libfoo.so.1`









The Linux GCC HOWTOĶV0.1						     20



 ldPRObjMɮת(strat
egy)W,|̾ڪtӦҤP,Oߤ@@ӧAiHXz]wؿKO/usr/libF.pGAƱ樭BB{w]CJjMC,ANH-
LﶵigccάOld.

 nOAo{@IĪG]S,Nݬݨɮ׬OO٨ĨĪba.Na.outӨ,H-
lfooѼƨӳs,|XldhMlibfoo.sa (shared
stubs);pGS\,N|Mlibfoo.a (static).NELFӨ, ld|lib
foo.so,MOlibfoo.a.libfoo.soq`O@ӲŸs,slibfoo.so.x.

6.4  إߧAۤv{w(Building your own libraries)

6.4.1  (Version control)

 P䥦󪺵{@,{w]ץbugsDsb.̤]iಣͥX@ǷsSI,ثesbҲժ\,άONª.o勵bϥΥ̪{Ө,i|O@ӤjD.pG@{OھڨªSIӰ檺,?

ҥH,ڭ̤޶i(introduce)F{ws(version
ing)[.ڭ̱N{w*n(minor)*P*Dn(major)*ܧO(catego
rize),Pɧڭ̳Ww*n*ܧO\Ψo{wµ{oͤ_{H(break).AiHq{wɦWX(ڤW,Y,ELFӨȶȬO@Ѥj;~ŪNUh,KiլF):
lib
foo.so.1.2DnO1,nO2.nsiu,]iर򳣨S---libcbo@IWΤF*ץ{(patch-
level)*[,ӵXFWٹlibc.so.5.2.18o˪{w.nsYO@Ǧr,u,άOiHCLASCIIr,]OܦXz.

ELFPa.out榡̥DntO@NObإߦ@ɵ{wW.ڭ̥ELF,]²@.

6.4.2  ELF? 쩳OFFz?

 "

  ELF (Executable and Linking Format) ̪OUSL(UNIX System Laborato
ries)ҵoiGi榡(binary format),ӥثeΩSolarisPSystem V Release
4W.ѩELFҼWu(flexibil
ity)WLLinuxLhҥΪa.out榡,]GCCPC{woiHhh~(1995)MwELFLinuxзǪGi榡.

6.4.2.1  SӤF?

 o@`OӦ۩'/news-archives/comp.sys.sun.misc'.

     ELF("Executable Linking For
     mat")OSVR4Ҥ޶is}تɮ榡.ELF_COFFiOhXF֪\.HELFӨ,*O*iѨϥΪ̦ۦ橵(user-
     extensible).ELF@تɬ`(sec
     tions)pC몺զX,ӥBCiN(arbitrar
     ily)(ӤO@Twjp}C).oǸ`ϻPCOFF@,äݭnTwbYӦa,]ݭnHYضǱƦC.pGusersƱɮs,L̫KiH[Js`Ϩتɤ.ELF]@ӧjӦO榡,٬DWARF(Debug
     ging With Attribute Record Format)-ثeLinuxä䴩.DWARF
     DIEs(Debugging Information
     Entries)sC|bELFΦ.debug`.DWARF
     DIEsC@.debug`ϨëD@Ǥֶq(small)BTwjp(fixed-
     size)TO(information records)X(collec
     tion),ӬO@NתC,֦ݩ,ӥB{Ʒ|Hd򬰮ھڪ𪬸Ƶc(scope-
     based
     tree)gX.DIEsүɮ쪺jqTOCOFF.debug`ϵLk䶵I.(OC++~ӹ).












The Linux GCC HOWTOĶV0.1						     21



     ELFɮ׬OqSVR4(Solaris 2.0 ?)ELFs{w(ELF access
     library)s.{wiѤ@²KֳtELF.ϥELFs{w̥Dnf@KO,AAݭnhݤ@ELFɪquaF.NUNIXɮצӨ,OHElf*Ӧs;Iself_open(),qɶ}l,AuݩIself_foo
     bar()ӳBzɮתY@(compo
     nents)Yi,äݭnɮ׹ڦbϺФWimagedo@ζ.

ELFuIP@ŦELFũһݸgغصhW(contortions),wbELF-
HOWTOפ;ڨäbo߽k.ELF HOW
TOӻPoۦPBP˪DD~O.

6.4.2.2  ELF@ɵ{w

 YQإlibfoo.so@ɵ{w,򥻪BJ|Uo:

     $ 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

o|ͤ@ӦWlibfoo.so.1.0@ɵ{w,HεldAs(lib
foo.so)٦ϱoʺAJ{(dynamic loader)쥦(lib
foo.so.1).Fi,ڭ̱Nثeؿ[LD_LIBRARY_PATH.



AzzֹD{ws\,
OѤF⥦p/usr/local/libؿU,åBsإߥTs|. lib
foo.so.1Plibfoo.so.1.0s|ldcon
fig̤_s;NjtΨӻ,ldconfig|b}{Ǥ. lib
foo.sosѤʤ覡s.pGA{wҦզl(pYɵ)@,`Oۤ@AA(scrupu
lous),²檺kNOlibfoo.so -> libfoo.so.1;p@,ldcon
figK|APɫOd̷ss.nOASo,Aۦ]wFFN|bƤyd_ʩǪ˥X{.ɭ,iOڨSA!

     $ su
     # cp libfoo.so.1.0 /usr/local/lib
     # /sbin/ldconfig
     # ( cd /usr/local/lib ; ln -s libfoo.so.1 libfoo.so )

6.4.2.3  s, sonamePŸs


 "

 C@ӵ{w@son
ame.so{bjM{wo˪@ӦW,sK|Nson
ameJ(embed)sGiɤ,
ӤObB@ڪɦW.b{,ʺAJ{|jM֦son
ameo˪ɦWɮ,ӤO{wɦW.],@ӦWlib
foo.so{w,NiH@libbar.sosonameF.ӥBҦslib
bar.so{,{}l,|M䪺KOlibbar.soF.

oť_Ӧn@INq]S,Oo@I,AѼƭӤPP@ӵ{wOpb@tΤW@s(coex
ist)],oO䤧_.Linux{wзǪRW覡,pOlib
foo.so.1.2,ӥBoӵ{w@libfoo.so.1son








The Linux GCC HOWTOĶV0.1						     22



ame.pG{wO[зǵ{wؿU(e.g. /usr/lib),ldcon
fig|إ߲Ÿslibfoo.so.1 -> libfoo.so.1.2,Ϩ䥿Timage(run-
time).A]ݭnslibfoo.so -> libfoo.so.1,lds(link-
time)쥿Tsoname.

 ҥHo,Aץ{wbugs,άOK[Fsƶih(󤣷|{s{yQ(adversely)vT),A|ئ{w,Od쥻wson
ame,M{wɦW.ӷA{wܧ|ϱo{{(bina
ries)_(break),AuݼW[sonames---Ҥ,ٷslib
foo.so.2.0,sonameܦlibfoo.so.2.򱵵,ANlib
foo.sosVs;ܦ,@ɤSA׫_FM!

AnHؤ覡Ӵ{wRW,LoTOӦnǲ(conven
tion).ELFҽᤩAb{wRWWu,|ϱoHݩIIdMp;o˪uʦb,]äܧANohΥ.

ELF`:]gѧAʹ[o{ӺDһ:{wDn@ŷ|}a(break)ۮe(com
patibil
ity);Ӧn@ūhiण|;HU覡ӳs,Ҧ@N|ۦwLƤF.

     gcc -shared -Wl,-soname,libfoo.so.major -o libfoo.so.major.minor

6.4.3  a.out---ª榡~

 إߦ@ɵ{wKQ(ease)O@ŦELFDn]@.]O,a.outi٬OγBb.Wftph<URL:ftp://tsx-11.mit.edu/pub/linux/pack
ages/GCC/src/tools-2.17.tar.gz>;YA|o{20iHCCŪ.ګܤwۤvҬ(par
ti
san){o򪺲OɭP,iOqWU嶡,Ӥ]iHܲMXڱqӤY{ۤv}ʮa!:-)

6.4.3.1  ZMAGIC vs QMAGIC


 "

  QMAGICO@®榡a.out(٬ZMAGIC)i
榡,oخ榡|ϱoĤ@ӤLkmap.0-4096d򤺨Smap
pingsb,hi\NULL dereference trapping[e.Ҳͪɮ(side
effect)OAɷ|p(jO1Kk).

uYN@os䴩ZMAGIC,@bwIJçs䴩oخ榡;ӥثeȤ䴩QMAGICӤw.ƹW,oèShjvT,O]ثe֤ߨخ榡.

*file*ROӥiHT{{OOQMAGIC榡.

6.4.3.2  ɮװtm(File Placement)

 @a.out(DLL)@ɵ{w]tӯuꪺɮ׻P@ӲŸs.N*foo*oӥΩ󰵬dҪ{wӨ,oɮ׷|Olib
foo.saPlibfoo.so.1.2;Ÿs|Olibfoo.so.1,ӥB|Vlib
foo.so.1.2.oǬOΪ?

bsĶ, ld|Mlib
foo.sa.oO{w*stub*ɮ,ӥBtҦsһݪexportedƻPVƪ.

,ʺAJ{|Mlib
foo.so.1.oȶȬO@ӲŸs,ӤOuꪺɮ,G{wissBwץ~,Ӥ|l󦹮ɥbϥΦ{wε{.bs---plib
foo.so.1.3---we{,ldcon
fig|H@Lpާ@,NsVs,ϱo쥻ϥª{|P쵷@.








The Linux GCC HOWTOĶV0.1						     23



DLL{w(ڪDoOLת(tautol
ogy)---ҥHڴXiDa!)q`|񥦭̪RAƥ(static counter
parts)nӱojhF.̬OH*}(holes)*ΦӫOdŶHK᪺XR.o*}*iHΥ󪺺ϺЪŶ.@²檺cpIs,άOϥmake
hole{,NiHFoˮĪG(achieve).]̪}OTwbP@mW,ҥHbإߵ{w,AiH⥦̮.dUnյ۹ܨELF{w.

6.4.3.3  ``libc-lite''?

  libc-liteOq(light-weight)libc.iΨӦsbϺФW,P
jCL(menial)UNIXȦ(suffice).S]tcurses, dbm, term
cap{X.pGA/lib/libc.so.4Os@litelibc,ĳAH㪺N.

6.4.4  s:`D

 AsɩҾDJDH!ڥiरƤ]|,OunֿnFƶq,
ڷ|⥦̼g_*.

      AQ@,{osRA!



	    ˬdAѵldsO_T,ldC@ӹ@ɵ{w.NELFӨ,oO@ӲŸslib
	    foo.so,simage;Na.outӨ,NOlibfoo.saɤF.ܦhHNELF binu
	    tils
	    2.5@Ŧ2.6,NͤFoӰD---jM@ɵ{wɸz,ҥHèSNҦsإ߰_.,FP䥦[cۮe,oRz欰QHRF,t~,o˪*z*P_~v۷,ҳy·Ф񥦩ҸѨMD٦h,ҥHdۤ]O`H,pkh!

      The DLL tool `mkimage' fails to find libgcc, or


	    qlibc.so.4.5.x,libgccwAO@ɪ榡.],Ab*-lgcc*X{BH`gcc
	    -print-libgcc-file-name`N(㪺˳޸(back-
	    quotes)).t~,RҦ/usr/lib/libgcc*ɮ.oIܭn.

      __NEEDS_SHRLIB_libc_4 multiply defined messages
	    OP˪Dҳyt@صG.

      ``Assertion failure'' message when rebuilding a DLL ?
	    o@(cryp
	    tic)Ți઺]O,bljump.varsɮפ,ѩOdŶӤ,
	    HPy䤤@jump table slots(over
	    flow).AiHtools-2.17.tar.gzMҴѪ`get
	    size'RO,wXҦå(cul
	    prit(s))ܸ.iߤ@ѨMkO,Ѱ(bump){wDns,j^줣ۮe~N(be
	    backward incompatible).

      ld: output file needs shared library libc.so.4
	    q`oOoͦbAs{wOlibc(pX{w),ӥBbROCΤF-
	    gѼ,oS@֨ϥ-static,ҵoX~T.

	    @ɵ{w.sa
	    stubsq`@ӥwqŸ_NEEDS_SHRLIB_libc_4;ӳo@Iiǥlibc.sa
	    stubӸѨM.M,H-
	    gӽsĶ,|ϱosHlibg.alibc.aӵ;]oӲŸ@NSѨM,]N|ɭPW~TF.

	    `,H-gXsĶɧOѤF[W-static,MNO-gӳs.q`,H-








The Linux GCC HOWTOĶV0.1						     24



	    gsĶUӿWߪɮ׮,oTwg,sɴNiHݭnF.


7.  ʺAJ(Dynamic Loading)

  o@`ثeO²uF@I;ڱELF HOWTO,NOoAXiɭԤF.

7.1  򥻷

 Linux@ɵ{w,pGeAwŪW@`,Q{b@ť칳o˪,K|ߨPY.@ǷӺDҦӨObsɴKӧu@(match
ing-names-to-places),Jɴ(load-time)~৹.

7.2  ~T(Error messages)

  As~H!ڤ|󪺨,LڥiH⥦̼g_**

      can't load library: /lib/libxxx.so, Incompatible version
	    (a. out only) oOASxxx{wTDn.iOHHH
	    KK˭ӳsAثe֦NiHF,pGB,
	    Nu|yA{~Ӥw.hs.ELFp|yUo˪T:

		 ftp: can't load library 'libreadline.so.2'

      warning using incompatible library version xxx
	    (a. out
	    only)A{wn_o{ΨӽsĶ٭n.{̵MiH.uOi!ڷQ,@ӯӨSˮ`a!

7.3  ʺAJB@


 "

 @ܼƷ|ʺAJҤ.jܼƹlddγ~n_@users٭nӱoh.ӥBiHܤK]wlddtXUذѼƨӰ.oܼƥ]A

     LD_BIND_NOW --- `,ƦbIseO|{M(looked
     up).]woӺX|ϱo{w@J,ҦM(lookups)K|o,Pɤ]y_lɶ(startup
     time)C.AQյ{,TwҦsSD,oXNܱoܦ.

     LD_PRELOAD iH]w@ɮ,Ϩ㦳*л\*(overrid
     ing)ƩwqO.Ҧp,pGAnհOt貤(strate
     gies),ӥBٷQm*malloc*,AiHgnǳƴƵ{(rou
     tine),ç⥦sĶmallolc.,M:

	  $ LD_PRELOAD=malloc.o; export LD_PRELOAD
	  $ some_test_program



     LD_ELF_PRELOAD P LD_AOUT_PRELOAD
     ,OȾAΩ󥿽TGi쫬A.pG]wF LD_something_PRELOAD P
     LD_PRELOAD ,T@ӷ|QΨ.

     LD_LIBRARY_PATH
     O@sHjؿW,ΨӷjM@ɵ{w.ldӨ,èS󪺼vT;oub~vT.t~,se








The Linux GCC HOWTOĶV0.1						     25



     tuidPset
     gid{Ө,o@OLĪ.LD_ELF_LIBRARY_PATHPLD_AOUT_LIBRARY_PATHoغXiھڦUOGi쫬OɦVPjM|.@륿`B@U,ӷ|ΨLD_LIBRARY_PATH;ݭnjMؿ[/etc/ld.so.conf/;M᭫sld
     config.

     LD_NOWARN ȾAΩa.out.@]wFo@(LD_NOWARN=true; export
     LD_NOWARN),|iDJBzfatal-warn
     ings(Onۮe)ĵiT.

     LD_WARN ȾAΩELF.]wo@,|Nq`OPRT"Can*t find
     library"ഫĵiT.勵`ާ@Ө,oèShjγB,iOlddNܭnF.

     LD_TRACE_LOADED_OBJECTS
     ȾAΩELF.ӥB|ϱo{H̬OlddҰ檺:


	  $ 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  HʺAJg{


 "

 pGAܼxSolaris
2.xҤ䴩ʺAJu@,A|o{LinuxboIWPD`۪.o@bH.J.LuELF{]p󤺻Pdlopen(3)man
ual
page(iHbld.soMW)Wsxt\(cover).o̦Ӥ²d:H-
ldls.

     #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.  PoiHhp

8.1  Bug

 "








The Linux GCC HOWTOĶV0.1						     26



 DgU.oOwLinux,άOgccb䥦tΤWҵoͪD.Pker
nel?Ϊ̬O{w?pGRA覡s,DOONF?AiH`@pq{Ӯiܳobug?

AFoǨƱ,AN|D{bugsO.NgccӨ,bug{ǬOHin
foɨӻ.pGOld.soάOC,maths{w,NemailHlinux-gcc@vger.rut
gers.edu.pGi઺,]t@ۤvۨp{Hiܳobug,ӥBW,yzAQno{ǤPڤWSFǤ.

8.2  Uoi

 pGAQnoigccάOC{w,Ĥ@ƫKO[Jlinux-gcc@vger.rut
gers.edulC(mailing list).pGAuOQݬmailing
listbQרǤ,o̦@ӪCarchives,<URL:http://homer.ncm.com/linux-
gcc/>.UӪ,NݧAQF.


9.  y

9.1  WH]


     Only presidents, editors, and people with tapeworms have the right to
     use the editorial ``we''.


(Mark Twain)

  oHOWTOXGڴөMitchum DsouzaGCC-FAQ; 󤺤jT(not to
mention a reasonable amount of the text)OӦ۩GCC-FAQ.
oHOWTOΨ쪺Ĥ@H٥NW,iڭ̨H䤤@;q`,nOH"٨SչLo;pGNF(toast)Aw/t/t,iOǧ!",o˪ܾAΩڭǨW.

o󦳰^mWHhpUҦC(HWrASCIIX): Andrew Tefft, Axel
Boldt, Bill Metzenthen, Bruce Evans, Bruno Haible, Daniel Barlow, Daniel Quin
lan, 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, M٦Linux Tor
valds,SFL,oӹBʴN|ܱo@INq]SF,ҥHiLt檺.:-)

Фnıo󪺫_ǤB,pGzWrSX{bo,ӱzo(HOWTOάOFAQ)SgL^m,email,ڷ|勵LӪ.

9.2  ½Ķ

 ثe,o٨Sw½ĶX{.pGAƱͤ@ӥX,оޥh,L@woiDڬƩy.y|OAQn½y,v(ܿ)unXʤ@,L٬Oo\@ǧa!ެO覡,ڳ|ַܼN.

9.3  w󪺦^X(Feedback)

HHdan@detached.demon.co.uk.ڪPGP public key (ID 5F263625)
ibڪMweb pages9 Wϥ, pGAıoƱnOK.

9.4  XkwWw

 All trademarks used in this document are acknowledged as being owned by their

____________________

9. <URL:http://ftp.linux.org.uk/~barlow/>







The Linux GCC HOWTOĶV0.1						     27



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. Com
mercial 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 doc
uments, and would like to be notified of any plans to redistribute the HOWTOs.

If you have questions, please contact Greg Hankins, the Linux HOWTO coordina
tor, at gregh@sunsite.unc.edu via email.


10.  

 HDƦr(non-alphabeti
cal)r_lJfB(entries),OHASCIIXǱƦC.

     -fwritable-strings 39 (section .39-hn .tm "GETHN:index.39 not defined" ,
     page .39-pn .tm "GETPN:index.39 not defined" ) 56 (section .56-hn .tm
     "GETHN:index.56 not defined" , page .56-pn .tm "GETPN:index.56 not
     defined" )

     /lib/cpp 16 (section .16-hn .tm "GETHN:index.16 not defined" , page
     .16-pn .tm "GETPN:index.16 not defined" )

     a.out 1 (section .1-hn .tm "GETHN:index.1 not defined" , page .1-pn .tm
     "GETPN:index.1 not defined" )

     ar 10 (section .10-hn .tm "GETHN:index.10 not defined" , page .10-pn .tm
     "GETPN:index.10 not defined" )

     as 8 (section .8-hn .tm "GETHN:index.8 not defined" , page .8-pn .tm
     "GETPN:index.8 not defined" )

     <asm/*.h> 19 (section .19-hn .tm "GETHN:index.19 not defined" , page
     .19-pn .tm "GETPN:index.19 not defined" )

     atoi() 40 (section .40-hn .tm "GETHN:index.40 not defined" , page .40-pn
     .tm "GETPN:index.40 not defined" )

     atol() 41 (section .41-hn .tm "GETHN:index.41 not defined" , page .41-pn
     .tm "GETPN:index.41 not defined" )









The Linux GCC HOWTOĶV0.1						     28



     binaries too big 63 (section .63-hn .tm "GETHN:index.63 not defined" ,
     page .63-pn .tm "GETPN:index.63 not defined" ) 65 (section .65-hn .tm
     "GETHN:index.65 not defined" , page .65-pn .tm "GETPN:index.65 not
     defined" ) 77 (section .77-hn .tm "GETHN:index.77 not defined" , page
     .77-pn .tm "GETPN:index.77 not defined" )

     chewing gum 3 (section .3-hn .tm "GETHN:index.3 not defined" , page .3-pn
     .tm "GETPN:index.3 not defined" )

     cos() 68 (section .68-hn .tm "GETHN:index.68 not defined" , page .68-pn
     .tm "GETPN:index.68 not defined" )

     debugging 59 (section .59-hn .tm "GETHN:index.59 not defined" , page
     .59-pn .tm "GETPN:index.59 not defined" )

     dlopen() 82 (section .82-hn .tm "GETHN:index.82 not defined" , page
     .82-pn .tm "GETPN:index.82 not defined" )

     dlsym() 83 (section .83-hn .tm "GETHN:index.83 not defined" , page .83-pn
     .tm "GETPN:index.83 not defined" )

     documentation 4 (section .4-hn .tm "GETHN:index.4 not defined" , page
     .4-pn .tm "GETPN:index.4 not defined" )

     EINTR 52 (section .52-hn .tm "GETHN:index.52 not defined" , page .52-pn
     .tm "GETPN:index.52 not defined" )

     elf 0 (section .0-hn .tm "GETHN:index.0 not defined" , page .0-pn .tm
     "GETPN:index.0 not defined" ) 71 (section .71-hn .tm "GETHN:index.71 not
     defined" , page .71-pn .tm "GETPN:index.71 not defined" )

     execl() 57 (section .57-hn .tm "GETHN:index.57 not defined" , page .57-pn
     .tm "GETPN:index.57 not defined" )

     fcntl 47 (section .47-hn .tm "GETHN:index.47 not defined" , page .47-pn
     .tm "GETPN:index.47 not defined" )

     FD_CLR 44 (section .44-hn .tm "GETHN:index.44 not defined" , page .44-pn
     .tm "GETPN:index.44 not defined" )

     FD_ISSET 45 (section .45-hn .tm "GETHN:index.45 not defined" , page
     .45-pn .tm "GETPN:index.45 not defined" )

     FD_SET 43 (section .43-hn .tm "GETHN:index.43 not defined" , page .43-pn
     .tm "GETPN:index.43 not defined" )

     FD_ZERO 46 (section .46-hn .tm "GETHN:index.46 not defined" , page .46-pn
     .tm "GETPN:index.46 not defined" )

     file 2 (section .2-hn .tm "GETHN:index.2 not defined" , page .2-pn .tm
     "GETPN:index.2 not defined" )

     <float.h> 20 (section .20-hn .tm "GETHN:index.20 not defined" , page
     .20-pn .tm "GETPN:index.20 not defined" )








The Linux GCC HOWTOĶV0.1						     29



     gcc 6 (section .6-hn .tm "GETHN:index.6 not defined" , page .6-pn .tm
     "GETPN:index.6 not defined" )

     gcc -fomit-frame-pointer 61 (section .61-hn .tm "GETHN:index.61 not
     defined" , page .61-pn .tm "GETPN:index.61 not defined" )

     gcc -g 60 (section .60-hn .tm "GETHN:index.60 not defined" , page .60-pn
     .tm "GETPN:index.60 not defined" )

     gcc -v 14 (section .14-hn .tm "GETHN:index.14 not defined" , page .14-pn
     .tm "GETPN:index.14 not defined" )

     gcc, bugs 15 (section .15-hn .tm "GETHN:index.15 not defined" , page
     .15-pn .tm "GETPN:index.15 not defined" ) 28 (section .28-hn .tm
     "GETHN:index.28 not defined" , page .28-pn .tm "GETPN:index.28 not
     defined" ) 29 (section .29-hn .tm "GETHN:index.29 not defined" , page
     .29-pn .tm "GETPN:index.29 not defined" ) 84 (section .84-hn .tm
     "GETHN:index.84 not defined" , page .84-pn .tm "GETPN:index.84 not
     defined" )

     gcc, flags 13 (section .13-hn .tm "GETHN:index.13 not defined" , page
     .13-pn .tm "GETPN:index.13 not defined" ) 25 (section .25-hn .tm
     "GETHN:index.25 not defined" , page .25-pn .tm "GETPN:index.25 not
     defined" ) 26 (section .26-hn .tm "GETHN:index.26 not defined" , page
     .26-pn .tm "GETPN:index.26 not defined" )

     gdb 64 (section .64-hn .tm "GETHN:index.64 not defined" , page .64-pn .tm
     "GETPN:index.64 not defined" )

     header files 17 (section .17-hn .tm "GETHN:index.17 not defined" , page
     .17-pn .tm "GETPN:index.17 not defined" )

     interrupted system calls 51 (section .51-hn .tm "GETHN:index.51 not
     defined" , page .51-pn .tm "GETPN:index.51 not defined" )

     ld 9 (section .9-hn .tm "GETHN:index.9 not defined" , page .9-pn .tm
     "GETPN:index.9 not defined" )

     LD_* environment variables 80 (section .80-hn .tm "GETHN:index.80 not
     defined" , page .80-pn .tm "GETPN:index.80 not defined" )

     ldd 81 (section .81-hn .tm "GETHN:index.81 not defined" , page .81-pn .tm
     "GETPN:index.81 not defined" )

     libc 7 (section .7-hn .tm "GETHN:index.7 not defined" , page .7-pn .tm
     "GETPN:index.7 not defined" )

     libg.a 62 (section .62-hn .tm "GETHN:index.62 not defined" , page .62-pn
     .tm "GETPN:index.62 not defined" )

     libgcc 79 (section .79-hn .tm "GETHN:index.79 not defined" , page .79-pn
     .tm "GETPN:index.79 not defined" )










The Linux GCC HOWTOĶV0.1						     30



     <limits.h> 21 (section .21-hn .tm "GETHN:index.21 not defined" , page
     .21-pn .tm "GETPN:index.21 not defined" )

     lint 58 (section .58-hn .tm "GETHN:index.58 not defined" , page .58-pn
     .tm "GETPN:index.58 not defined" )

     <linux/*.h> 18 (section .18-hn .tm "GETHN:index.18 not defined" , page
     .18-pn .tm "GETPN:index.18 not defined" )

     manual pages 5 (section .5-hn .tm "GETHN:index.5 not defined" , page
     .5-pn .tm "GETPN:index.5 not defined" )

     <math.h> 70 (section .70-hn .tm "GETHN:index.70 not defined" , page
     .70-pn .tm "GETPN:index.70 not defined" )

     maths 69 (section .69-hn .tm "GETHN:index.69 not defined" , page .69-pn
     .tm "GETPN:index.69 not defined" )

     mktemp() 55 (section .55-hn .tm "GETHN:index.55 not defined" , page
     .55-pn .tm "GETPN:index.55 not defined" )

     optimisation 27 (section .27-hn .tm "GETHN:index.27 not defined" , page
     .27-pn .tm "GETPN:index.27 not defined" )

     QMAGIC 76 (section .76-hn .tm "GETHN:index.76 not defined" , page .76-pn
     .tm "GETPN:index.76 not defined" )

     segmentation fault 30 (section .30-hn .tm "GETHN:index.30 not defined" ,
     page .30-pn .tm "GETPN:index.30 not defined" ) 54 (section .54-hn .tm
     "GETHN:index.54 not defined" , page .54-pn .tm "GETPN:index.54 not
     defined" )

     segmentation fault, in GCC 33 (section .33-hn .tm "GETHN:index.33 not
     defined" , page .33-pn .tm "GETPN:index.33 not defined" )

     select() 50 (section .50-hn .tm "GETHN:index.50 not defined" , page
     .50-pn .tm "GETPN:index.50 not defined" )

     SIGBUS 34 (section .34-hn .tm "GETHN:index.34 not defined" , page .34-pn
     .tm "GETPN:index.34 not defined" )

     SIGEMT 35 (section .35-hn .tm "GETHN:index.35 not defined" , page .35-pn
     .tm "GETPN:index.35 not defined" )

     SIGIOT 36 (section .36-hn .tm "GETHN:index.36 not defined" , page .36-pn
     .tm "GETPN:index.36 not defined" )

     SIGSEGV 31 (section .31-hn .tm "GETHN:index.31 not defined" , page .31-pn
     .tm "GETPN:index.31 not defined" ) 53 (section .53-hn .tm "GETHN:index.53
     not defined" , page .53-pn .tm "GETPN:index.53 not defined" )

     SIGSEGV, in gcc 32 (section .32-hn .tm "GETHN:index.32 not defined" ,
     page .32-pn .tm "GETPN:index.32 not defined" )









The Linux GCC HOWTOĶV0.1						     31



     SIGSYS 38 (section .38-hn .tm "GETHN:index.38 not defined" , page .38-pn
     .tm "GETPN:index.38 not defined" )

     SIGTRAP 37 (section .37-hn .tm "GETHN:index.37 not defined" , page .37-pn
     .tm "GETPN:index.37 not defined" )

     sin() 67 (section .67-hn .tm "GETHN:index.67 not defined" , page .67-pn
     .tm "GETPN:index.67 not defined" )

     soname 73 (section .73-hn .tm "GETHN:index.73 not defined" , page .73-pn
     .tm "GETPN:index.73 not defined" )

     sprintf() 42 (section .42-hn .tm "GETHN:index.42 not defined" , page
     .42-pn .tm "GETPN:index.42 not defined" )

     statically linked binaries, unexpected 66 (section .66-hn .tm
     "GETHN:index.66 not defined" , page .66-pn .tm "GETPN:index.66 not
     defined" ) 78 (section .78-hn .tm "GETHN:index.78 not defined" , page
     .78-pn .tm "GETPN:index.78 not defined" )

     <stdarg.h> 23 (section .23-hn .tm "GETHN:index.23 not defined" , page
     .23-pn .tm "GETPN:index.23 not defined" )

     <stddef.h> 24 (section .24-hn .tm "GETHN:index.24 not defined" , page
     .24-pn .tm "GETPN:index.24 not defined" )

     strings 11 (section .11-hn .tm "GETHN:index.11 not defined" , page .11-pn
     .tm "GETPN:index.11 not defined" )

     <sys/time.h> 48 (section .48-hn .tm "GETHN:index.48 not defined" , page
     .48-pn .tm "GETPN:index.48 not defined" )

     <unistd.h> 49 (section .49-hn .tm "GETHN:index.49 not defined" , page
     .49-pn .tm "GETPN:index.49 not defined" )

     <varargs.h> 22 (section .22-hn .tm "GETHN:index.22 not defined" , page
     .22-pn .tm "GETPN:index.22 not defined" )

     version numbers 12 (section .12-hn .tm "GETHN:index.12 not defined" ,
     page .12-pn .tm "GETPN:index.12 not defined" ) 74 (section .74-hn .tm
     "GETHN:index.74 not defined" , page .74-pn .tm "GETPN:index.74 not
     defined" )

     weird things 72 (section .72-hn .tm "GETHN:index.72 not defined" , page
     .72-pn .tm "GETPN:index.72 not defined" )

     ZMAGIC 75 (section .75-hn .tm "GETHN:index.75 not defined" , page .75-pn
     .tm "GETPN:index.75 not defined" )














The Linux GCC HOWTOĶV0.1						     32





































































				   CONTENTS



1.  ͤW(Preliminaries)! ................................................ 2
    1.1 ELF vs. a.out ....................................................... 2
    1.2 @̪py(Administrata) ............................................ 2
    1.3 LPƪ(typography) .............................................. 2

2.  WoǪFF? ......................................................... 3
    2.1 oyB .................................................... 3
    2.2 䥦 .................................................. 3
    2.3 GCC   ............................................................... 3
    2.4 C{wPY ..................................................... 4
    2.5 pu (as, ld, ar, strings etc) .............................. 4

3.  GCCw(installation)Pҥ(setup) .................................... 4
    3.1 GCC ........................................................... 5
    3.2 FF˦n᳣hF? ............................................. 5
    3.3 Yɣz?Yɣz? .............................................. 6
    3.4 إߥesĶ(Building cross compilers) ............................ 7

4.  (Porting)PsĶ(Compiling){ ...................................... 8
    4.1 gccۦwqŸ ................................................... 8
    4.2 uWDU(invocation) ............................................ 8
    4.3 ӯO(Portability) .............................................. 10

5.  Debugging and Profiling ................................................ 15
    5.1 Preventative maintenance (lint) .................................... 15
    5.2 (Debugging) .................................................... 16
    5.3 ǺV(Profiling) ................................................ 18

6.  s(Linking) .......................................................... 18
    6.1 @ɵ{w vsRA{w ............................................ 18
    6.2 Interrogating libraries (`which library is sin() in?') ............. 19
    6.3 Xɮ??? ........................................................... 19
    6.4 إߧAۤv{w(Building your own libraries) .................... 20

7.  ʺAJ(Dynamic Loading) .............................................. 24
    7.1 򥻷 ........................................................... 24
    7.2 ~T(Error messages) ........................................... 24
    7.3 ʺAJB@ ............................................... 24
    7.4 HʺAJg{ ................................................. 25

8.  PoiHhp ......................................................... 25
    8.1 Bug ............................................................ 25
    8.2 Uoi ........................................................... 26

9.  y ................................................................... 26
    9.1 WH] ............................................................. 26
    9.2 ½Ķ ............................................................... 26
    9.3 w󪺦^X(Feedback) ........................................... 26
    9.4 XkwWw ..................................................... 26



				       i









10.  ................................................................... 27























































				       ii


