\documentclass[letterpaper]{article}
\nonstopmode
\akai
\usepackage{linuxdoc-sgml}
\usepackage{qwertz}
\usepackage{url}
\usepackage[latin1]{inputenc}
\usepackage{t1enc}
\usepackage[english]{babel}
\usepackage{epsfig}
\usepackage{null}
\def\addbibtoc{
\addcontentsline{toc}{section}{\numberline{\mbox{}}\relax\bibname}
}%end-preamble
\setcounter{page}{1}
\title{The Linux GCC HOWTOÖÐÒë°æV0.2}
\author{×÷Õß: Daniel Barlow {\ttfamily $<$dan@detached.demon.co.uk$>$}\\ 
        ÒëÕß: ³Â½¨Ñ«(Frank J.S. Chen){\ttfamily $<$frank63@ms5.hinet.net$>$}}
\date{v1.17, 28 February 1996}
\abstract{±¾ÎÄ²ûÊö°²×°GNU C±àÒëÆ÷ºÍ³ÌÊ½¹ÝµÄ·½·¨£¬Í¬Ê±¸Å¹ÛµØËµÃ÷³ÌÊ½µÄ±àÒë¡¢Á¬½á¡¢Ö´ÐÐ¡¢³ý´íµÄ¹ý³ÌÒÔ¼°¿ÉÄÜÃæÁÙµÄÖî¶àÎÊÌâ¡£Ð´×÷µÄ²Î¿¼×ÊÁÏÌ©°ëÀ´×Ôì¶Mitch D'SouzaÏÈÉúËùÊÕ¼¯µÄGCC-FAQ£»¶øÁíÒ»¸öÀ´Ô´ÊÇELF-HOWTO¡£´Ë·ÝHOWTO¿ÉÒÔËµÒÑ´úÌæÁËGCC-FAQ£¬¶øÇÒ¼´½«ÒªÓÀ¾ÃÌæ´úELF-HOWTOÁË¡£´ËÄËGCC-HOWTOµÚÒ»·Ý¹«¿ª·¢ÐÐµÄ°æ±¾£¨²»ÐëÀí»á°æ±¾ÐòºÅ£»ÄÇÊÇRCSµÄ½Ü×÷£©£¬ÓÐÈÎºÎÖ¸ÕýÓë½¨ÒéµÄ£¬±¾ÈË¶¼ºÜ»¶Ó­¡£}


\begin{document}
\maketitle
\tableofcontents

\section{ÐÐÔ¶±Ø×ÔåÇ£¡}


\subsection{ÒëÕßµÄ»°}

\begin{itemize}
\item Õâ·ÝÒëÎÄÎªLinux document projects({\itshape LDP\/})ÖÐÎÄ·­Òë¼Æ»­ÏµÁÐÖ®Ò»¡£Ä¿Ç°Ö®ÍøÖ·Îª{\ttfamily \onlynameurl{http://www.linux.org.tw/CLDP/}}£¬»¶Ó­¸÷Î»ÍøÓÑÓ»Ô¾Í¶Èë´ËÒ»¼Æ»­¡£
\item ÎÒ²¢Ã»ÓÐÍêÈ«°´ÕÕÔ­ÎÄÖð×Ö·­Òë¡£ÎªÁËÁ¦ÇóÒëÎÄÍ¨³©¿É¶Á£¬ÎÒ»áÉÔÉÔµÄÖØ×éÒ»²¿·ÝµÄÎÄ×Ö£¬¼ÓÓÍÌí´×£¬»òÊÇ¾«¼òÔ­ÎÄ£»ÕâÑù×öµÄ»°£¬¿ÉÒÔÃÖ²¹ÖÐÓ¢ÎÄ¼äÓï·¨½á¹¹µÄ²îÒìÐÔ£¬ÇÒÓïÆø¿ÉÒÔ¹áÍ¨ÎÞ°­¡£
\item Ò»Ð©¹Ø¼ü×ÖÓë×¨Òµ´Ê»ãµÈ£¬»á¸½¼ÓÉÏÔ­ÎÄµ¥×Ö¡£
\item ÓöÓÐ×ªÒëÀ§ÄÑ£¬Î¨Ô­ÎÄ³£¼ûµÄ×Ö»ãÈç{\ttfamily bugs¡¢shadow password¡¢padding¡¢image}Ö®ÀàµÄ£¬Ôò±£ÁôÔ­ÎÄ²»±ä¡£Èô¸óÏÂ¶ÔÕâÐ©×Ö»ãÓÐÊÊµ±Òë´ÇµÄ£¬Çë²»ÁßÖ¸½Ì¡£
\item ÄÚÎÄÖÐÈôÓöÓÐ"{[}ÒëÕß×¢:**]"Ö®±ê¼Ç£¬ÔòÎª±¾ÈË¶îÍâÖ®×¢½â¡£
\item ¶ÔÕâÆªÒëÎÄÓÐÈÎºÎ½¨ÒéÓëÒÉÎÊµÄ£¬ÇëemailÖÁ{\itshape frank63@ms5.hinet.net\/}¡£
\item {\ttfamily WWW Home Page£º \onlynameurl{http://linux.ntcic.edu.tw/\~{}jsfrank/}}¡£
\item ´ËÖÐÒëÎÄ¼þÖ®·­ÒëÈ¨ÒÑÈ¡µÃÓ¢¼®Ö®Ô­×÷ÕßDaniel Barlow ÏÈÉúÖ®Í¬Òâ£»Áí£¬³Â½¨Ñ«ÏÈÉú±£ÓÐ´Ë·ÝÖÐÒë°æÎÄ¼þËùÓÐµÄÈ¨Àû£¬Äã¿ÉÒÔÈÎÒâµÄ¿½±´£¬ÒÔ¸÷ÖÖÃ½ÌåÉ¢²¼Õâ·ÝÖÐÒëÎÄ¼þ£¬Î¨´Ë½Ú²¹³äËµÃ÷ÐèÔ­·â²»¶¯¸½ÉÏ£¬ÇÒ²»¿ÉÈÎÒâ¸ü¶¯ÒëÎÄ¡£
\item v0.1°æµÄÒëÎÄÏàµ±´Ö²Ú£¬Á¬ÎÄ¾äµÄÓï·¨½á¹¹¶¼ÏÓÌ«¹ýì¶ËÉÉ¢£¬v0.2°æÕë¶ÔÖÐÎÄµÄÓÃ×ÖÏ°¹ßÀ´ÐÞÕý£¬²¢½«ÉÏÒ»°æÒëµÄ²»Í×µ±µÄµØ·½ÐÞÕý¹ýÀ´£¬ÀýÈçeitherÕâ¸ö×Ö£¬Ó¢¹úÈË³£°Ñeitherµ±Ãû´ÊÓÃ£¬Ö¸Á½ÕßÖÐÈÎÒâÒ»¸ö£»Õâ·ÝHOWTO¾Í³ä·Ý·´Ó¦³öÕâ¸öÓÃ×ÖÏ°ÐÔ£¬¸úÃÀÓïÓÐ»ù±¾ÉÏµÄ²îÒì¡£
\item ÎÄÖÐÓÐ¼¸¾ä»°Ã»ÓÐÒë³öÀ´£¬Ò»·½ÃæÊÇ¿´²»¶®£¬Áí·½ÃæÊÇÖ±ÒëÒ²Òë²»³öÀ´£¬ËùÒÔÖ»ºÃ±£ÁôÔ­ÎÄÁË£¬ÒªÊÇ¸óÏÂÓÐÐÂµÄÁìÎòµÄ£¬ÎÞÂÛÈçºÎÇë¸æËßÎÒ¡£
\item v0.1°æ·­ÒëÆðÊ¼ÈÕÆÚÎª£º11/7/97£»½ØÖ¹ÈÕÆÚÎª£º11/19/97¡£
\item v0.2°æÐÞÕýÆðÊ¼ÈÕÆÚ£º5/13/98£»½ØÖ¹ÈÕÆÚÎª£º6/3/98¡£
\end{itemize}





\subsection{¶¯Óë¾²\label{index.0} 
\label{index.1} }

Ä¿Ç°LinuxµÄ·¢Õ¹Õý²¨ÌÎÐÚÓ¿µÄ½øÐÐÖø¡£¼òµ¥Ò»µã½²£¬LinuxÓÐÁ½ÖÖÖ´ÐÐµµµÄ¸ñÊ½¿ÉÓÃ£¬È¡¾öì¶ÄãµÄÏµÍ³ÊÇÔõ÷áÕûºÏÆðÀ´µÄ£»ÄãµÄLinuxÓ¦¸ÃÊÇÆäÖÐÒ»ÖÖ°É£¡ÔÄ¶ÁÕâ·ÝÎÄ¼þ£¬¿ÉÒÔ°ïÖúÄã¡õÇåÖ´ÐÐµµµÄÀà±ð¡£

\label{index.2} 

ÒªÈçºÎÇø±ðÄØ£¿Ö´ÐÐ¹«ÓÃ³ÌÊ½¡®file¡¯£¨ÀýÈç£¬{\ttfamily file /bin/bash}£©¾Í¶ÔÁË¡£¾ÍELFµÄ³ÌÊ½¶øÑÔ£¬Ó©Ä»ÉÏÏÔÊ¾³öÀ´µÄÑ¶Ï¢»áº¬ÓÐELFµÄ×ÖÑÛ£»Èç¹ûËµÊÇa.outµÄ£¬Ñ¶Ï¢ÄÚ»áóéÓÐ {\ttfamily Linux/i386}µÄ×ÖÑù¡£

ELFÓëa.out¸ñÊ½µÄ²îÒìÖ®´¦»áÔÚááÐøµÄÕÂ½ÚÖÐÌÖÂÛ£¨ºÜ¹ã·ºà¸£¡£©¡£ELFÊÇ±È½ÏÐÂµÄ¸ñÊ½£¬Ò»°ã¶øÑÔ£¬½ÓÊÜµÄ³Ì¶È½Ï¼Ñ¡£




\subsection{×÷ÕßµÄË½Óï\label{index.3} }

 °æÈ¨ËµÃ÷ÓëºÏ·¨µÄÐÐåÉ¹æ¶¨£¬¾Í°ÚÔÚÕâ·ÝÎÄ¼þµÄ{\itshape Î²¶Ë\/}¡£³ý´ËÖ®Íâ£¬ÎÒ»¹ÓÐÒ»Ð©²»µÃ²»ÌáÐÑÄãµÄ»°Òª½²¡£¾ÍËãÄã¡õÖøÃ»ÊÂ¸É£¬Ò²²»ÒªÔÚUsenetÉÏ¶ªÒ»Ð©´ô¹ÏÎÊµÄÎÊÌâ£»»¹ÓÐ£¬²»ÒªÀÏÒÔÎª×Ô¼ºCÓïÑÔµÄ¹¦Á¦Éîºñ£¬×¨ÃÅ·¢±íÒ»Ð©²»ÊÇbugsµÄbugs³öÀ´¶ªÈËÏÖÑÛ£¬Õâ²»¾ÍµÈì¶¸æËß±ðÈËÄã²»Ñ§ÎÞÊõ£¬ÔÚ¹ØÀÏÒ¯ÃæÇ°Ë£´óµ¶ÁËÂð£¿ËùÒÔËµ×ÔÒÔÎªÊÇµÄÓ¢ÐÛÖ÷ÒåÊÇµÃ²»³¥Ê§µÄ¡£




\subsection{Ó¡Ë¢ÓëÅÅ°æ}

 Èç¹ûÄãÏÖÔÚ¶ÁµÄÊÇPostscript¡¢dvi»òÊÇhtml¸ñÊ½£¬ÄÇ÷áÄãËù¿´µ½µÄ×ÖÐÍ±ä»¯¾Í»á±ÈÖ»¶Á´¿ÎÄ×Ö¸ñÊ½µÄÈË¶àÒ»Ð©¡£ÌØ±ðÊÇµµ°¸Ãû³Æ¡¢ÃüÁî¡¢ÃüÁîµÄÊä³öÓëÕªÂ¼³öÀ´µÄÔ­Ê¼ÂëµÈ£¬Í³Í³¶¼ÊÇ{\ttfamily ´ò×Ö»ú}µÄ×ÖÐÍ¡£ÕâÑù×öµÄ»°£¬¶Ôì¶Ä³Ð©ÐèÒªÇ¿µ÷µÄ¡®±äÊý¡¯»¹ÓÐÄÇÐ©Ã»ÓÐ¹Ì¶¨½á¹ûµÄ¡õÀý¶øÑÔ£¬¾Í¿ÉÒÔ´ïµ½{\itshape Ç¿µ÷µÄÐ§¹û\/}ÁË¡£

¶ÁÕâ·ÝÎÄ¼þµÄÍ¬Ê±£¬ÄãÒ²»áµÃµ½Ò»Ì×ÂùÓÐÓÃµÄË÷Òý¡£¼ÙÈôÊÇdvi¡¢ postscriptÖ®ÀàµÄ°æ±¾£¬Ë÷ÒýµÄÊý×Ö¾ÍÊÇÕÂ½Ú(section)µÄ±àºÅ£»Èç¹ûÊÇHTMLµÄ»°£¬ÕâÐ©Êý×Ö»á°´Ë³ÐòÅÅÁÐ£¬Äã¿ÉÒÔÓÃ»¬Êó×ó¼üÈ¥Á¬½áÏà¶ÔµÄË÷ÒýÄÚÈÝ£»Èç¹ûÄã¿´µÄÊÇ´¿ÎÄ×Ö°æ±¾µÄ»°, Êý×Ö¾ÍÖ»ÊÇÊý×Ö£¬Ã»±ðµÄº¬Òâ£»½¨ÒéÄã¸Ï¿ìÉý¼¶ÎªÃîÁ¨£¡

ÎÒÓÃµÄshellÊÇBourne shell£¨²»ÊÇC shell£©£¬¾ÙµÄÀý×Ó×ÔÈ»ÊÇBourne shellµÄÓï·¨¡£Èç¹ûÄãÓÃµÄÊÇC shellµÄ»°£¬Éè¶¨»·¾³±äÊýµÄÓï·¨»áÏñÏÂÃæÕâÑù£º

\begin{tscreen}
\begin{verbatim}
% setenv FOO bar
\end{verbatim}
\end{tscreen}


ÒªÊÇÓÃBourne shellµÄ»°£¬ÎÒ»áÕâÑù×ÓÐ´£º

\begin{tscreen}
\begin{verbatim}
$ FOO=bar; export FOO
\end{verbatim}
\end{tscreen}


Èç¹ûÌáÊ¾·ûºÅÏÔÊ¾µÄÊÇ¾®×Ö·ûºÅ{\ttfamily \#}¶ø²»ÊÇÇ®×Ö·ûºÅ {\ttfamily \$}µÄ»°£¬ºÜÓÐ¿ÉÄÜÕâ¸öÃüÁîÊÇÖ»ÊÊÓÃì¶root¶øÒÑ¡£µ±È»À²£¬ÒªÊÇÄãÊÔÁËÕâÐ©¡õÀý£¬½á¹ûÅªµÃÄãµÄÏµÍ³·¢ÉúÔÖ±ä£¬ÎÒ¿ÉÊÇÒ»µãÔðÈÎÒ²²»»á¸ºµÄà¸£¡×£ºÃÔË£¡{\ttfamily :-)}

11/8/97Òë.
5/13/98ÐÞ¶©






\section{¶«¶«ÔÚÄÄ¶ù£¿}


\subsection{GCC-HOWTOÔÚÄÄ¶ù£¿}

 Õâ·ÝÎÄ¼þÊÇLinux HOWTOÏµÁÐÖ®Ò»£¬»»¾ä»°Ëµ£¬Äã¿ÉÒÔÔÚËùÓÐ´æ·ÅLinux HOWTOÎÄ¼þµÄÍøÕ¾ÉÏÃæÕÒµ½ËýµÄ·¼×Ù£¬ÀýÈç\nameurl{http://sunsite.unc.edu/pub/linux/docs/HOWTO/}{}¡£HTMLµÄ°æ±¾£¨¿ÉÄÜ»áÊÇ½ÏÐÂµÄ°æ±¾£©¿ÉÒÔ´Ó\nameurl{http://ftp.linux.org.uk/~barlow/howto/gcc-howto.html}{}ÉÏÃæ×¥ÏÂÀ´¡£




\subsection{GCCÏà¹ØµÄ×ÊÁÏÓÖÔÚÄÄ¶ù£¿\label{index.4} }

±ê×¼µÄgccËµÃ÷ÎÄ¼þÊÇËæ¸½ÔÚ·¢ÐÐµÄÔ­Ê¼Âë(source distribution)ÄÚ£¨ÍùÏÂ¿´¾ÍÓÐÁË£¡£©£¬ÀïÍ·ÓÐtextinfoÓë{\ttfamily .info}Á½ÖÖµµ°¸¡£ÒªÊÇÄãµÄÍøÂ·Á¬½ÓËÙÂÊ¹»¿ì£¬»òÊÇÓÐÒ»Æ¬cdrom£¬²»È»£¬ÓÐ¸ß¶ÈµÄÄÍÐÄÒ²³É£¬Äã¿ÉÒÔ×Ô¼º°ÑËüuntar£¬È»ááÔÙ°ÑÏà¶ÔÓ¦µÄÎ»ÔªÒ»Ò»¿½±´µ½{\ttfamily /usr/info}µÄÄ¿Â¼µ×ÏÂ¡£¼ÙÈçÄãµÄÌõ¼þÓëÉÏÊöµÄ²»·û£¬²»·Áµ½ \nameurl{ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/}{tsx-11}Õ¾ÉÏÈ¥²Î¹Û²Î¹Û¡£²»¹ý£¬ÎÒÏë£¬Ã»ÓÐ±ØÒªÀÏÊÇµë¼ÇÖø×îÐÂµÄ°æ±¾°É£¡

\label{index.5} 



 libcµÄÎÄ¼þËµÃ÷ÓÐÁ½ÖÖÀ´Ô´¡£Ò»ÖÖÊÇGNU libc£¬ÒÔ.infoµÄ¸ñÊ½´¢´æ£¬³ýÁËstdioÖ®Íâ£¬ÆäâÅLinux libcµÄËµÃ÷¶¼Ïàµ±µÄÏê¾¡¾«È·¡£ÁíÒ»ÖÖ¿ÉÒÔÔÚLinuxµÄarchive\nameurl{ftp://sunsite.unc.edu/pub/Linux/docs/}{manpages}ÉÏÕÒµ½ÏµÍ³ºô½Ð£¨system call£©£¨µÚ2½Ú£©Óëlibcº¯Êý£¨function£©£¨µÚ3½Ú£©µÄÎÄ¼þËµÃ÷¡£




\subsection{GCC \label{index.6} }

½â´ðÓÐ¶þ:

(a)Äã¿ÉÒÔÔÚ\nameurl{ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/}{}µÄÍøÕ¾ÉÏÕÒµ½
ÕýÊ½µÄLinux GCC·¢ÐÐÏµÍ³(distribution)£¬¶øÇÒÊÇÒÑ¾­±àÒëºÃµÄ¿ÉÖ´ÐÐµµ¡£µ±ÎÒÔÚÐ´Õâ·ÝÎÄ¼þÊ±£¬2.7.2({\ttfamily gcc-2.7.2.bin.tar.gz})ÊÇ×îÐÂµÄ°æ±¾¡£

(b)×ÔÓÉÈíÌå»ù½ð»á£¨Free Software Foundation£©Ëù·¢²¼µÄGCC×îÐÂÔ­Ê¼Âë¿ÉÒÔ´ÓÍøÕ¾\nameurl{ftp://prep.ai.mit.edu/pub/gnu/}{GNU archives}ÉÏÈ¡µÃ¡£Ã»ÓÐ±ØÒª·ÇµÃÓëÉÏÊöµÄ°æ±¾Ò»ÖÂ²ÅÐÐ£¬²»¹ýÕâ¸ö°æ±¾µÄÈ·ÊÇÄ¿Ç°×îÐÂµÄ¡£Linux GCCµÄÎ¬»¤ÍøÓÑ(maintainers)ÈÃÄã¿ÉÒÔºÜÇáËÉµÄ×ÔÐÐ±àÒëÕâ¸ö×îÐÂµÄ°æ±¾¡£{\ttfamily configure}ÃüÁî¸å(script)»á°ïÄã×Ô¶¯Éè¶¨ºÃËùÓÐ¸Ã×öµÄÊÂÇé¡£½¨ÒéÄãÓÐ¿Õ²»·Áµ½\nameurl{ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/}{tsx-11}¿´¿´£¬Ëµ²»¶¨»áÓÐÐÞÕýµÄ°æ±¾ÊÇÄã»áÏëÒªÓÃµÄ¡£

Èç¹ûÏëÒª±àÐ´³öÒ»Ð©ÓÐÓÃµÄÈíÌå£¨²»ÊÇÎÒÂÞËô£¬»¹ÊÇÓÐ²»ÉÙÃ»É¶ÓÃÍ¾µÄÈíÌåÔÚÍøÂ·ÉÏËÄ´¦Á÷´Ü¡££©£¬ÏÂÃæÕâÒ»Ð¡½ÚËùÌ¸µÄÒ²ÊÇÄãÐèÒªµÄ£º




\subsection{C³ÌÊ½¹ÝÓë±êÍ·µµ\label{index.7} }

¸ÃÑ¡ÄÄÒ»Ì×³ÌÊ½¹ÝÊÇÈ¡¾öì¶(i)ÄãµÄÏµÍ³ÊÇELFµÄ»òÊÇa.outµÄ£»(ii)ÄãÏ£ÍûÄãµÄÏµÍ³±ä³ÉÄÄÒ»ÖÖ£¿Èç¹ûÄãÊÇ´Ólibc 4Éý¼¶µ½libc 5£¬ÄÇ÷á¸øÄãÒ»¸öÁ¼ÐÄµÄ½¨Òé£¬ÏÈÈ¥¿´¿´ELF-HOWTOÔÙËµ¡£ÄãÒ»¶¨»áÎÊ£¬ÔÚELFÎÄ¼þµÄÄÄ¶ùÄØ£¿ºÙ£¡ºÙ£¡²»Æ«²»ÒÐ£¬¾Í²î²»¶à¸úÕâ·ÝÎÄ¼þÏàÍ¬µÄÎ»ÖÃ¡£ÍøÕ¾\nameurl{ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/}{tsx-11}ÉÏÃæ¿ÉÒÔÕÒµ½ÄãÏëÒªµÄ¡£

\begin{description}


\item[{\ttfamily libc-5.2.18.bin.tar.gz}] \mbox{}

--- ELF¹²Ïí³ÌÊ½¹Ý£¨ELF shared library images£©£¬¾²Ì¬³ÌÊ½¹Ý£¨static libraries£©Óë±êÍ·µµ£¨Õë¶ÔCÓïÑÔÓëÊýÑ§³ÌÊ½¹Ý£©¡£



\item[{\ttfamily libc-5.2.18.tar.gz}] \mbox{}

---libc-5.2.18.bin.tar.gzµÄÔ­Ê¼Âë¡£Õâ¸öµµ°¸ÄãÒ²ÐèÒª£¬ÒòÎª{\ttfamily .bin.}Ì×¼þ(package)º¬ÓÐ±ØÐèµÄ±êÍ·µµ¡£Èç¹û´ËÊ±ÄãÕýÓÌÔ¥²»¾ö£¬²»ÏþµÃÊÇÀÏÉíÇ××ÔÏÂº££¬¶¯ÊÖ±àÒëC³ÌÊ½¿â±È½ÏºÃ£»»¹ÊÇÖ±½ÓÓÃÈË¼Ò±àÒëºÃµÄ¶þ½øÎ»µµ(binaries)¾Í¿ÉÒÔÁË¡£ÓÐÕâÖÖÀ§ÈÅµÄÈË£¬À´£¬¿´ÎÒµÄ×ìÐÎ£ºÓÃÈË¼Ò±àÒëºÃµÄ¶þ½øÎ»µµ²»¾Í½â¾öÁËÂï£¡Ö»ÓÐÔÚÄãÏëÒªNYS»òÊÇshadow passwordµÄÇé¿öÏÂ£¬²ÅÐèÒª×Ô¼ºµÄÊÖÀ´ÍÆ¶¯Ò¡Àº¡£



\item[{\ttfamily libc-4.7.5.bin.tar.gz}] \mbox{}

--- Õâ¸öµµ°¸ÊÇa.outµÄ¹²Ïí³ÌÊ½¿â(shared library images)Óë¾²Ì¬³ÌÊ½¿â£¬ÓÃÍ¾ÊÇÎªÁËÓëÇ°ÊöµÄlibc 5Ì×¼þ¹²´æ¹²ÈÙ¶øÉè¼ÆµÄ£¬²»¹ý³ý·ÇÄãÏëÒª¼ÌÐøÊ¹ÓÃa.outµÄ³ÌÊ½»òÊÇ¼ÌÐø·¢Õ¹a.outµÄ³ÌÊ½£¬²»È»µÄ»°£¬ÊÇ²»ÐèÒªËüµÄ¡£



\end{description}





\subsection{ÓÐ¹ØÁªµÄ¹¤¾ß (as, ld, ar, strings etc)
\label{index.8} 
\label{index.9} 
\label{index.10} 
\label{index.11} }

µ½Ä¿Ç°ÎªÖ¹£¬ÓëÖ®Ç°ËùÌ¸µÄ¶¼Ò»Ñù£¬´ÓÍøÕ¾\nameurl{ftp://tsx-11.mit.edu:/pub/linux/packages/GCC/}{tsx-11}ÉÏ£¬¾Í¿ÉÒÔÕÒµ½ÕâÐ©¹¤¾ß³ÌÊ½¡£Ä¿Ç°µÄ°æ±¾ÊÇ{\ttfamily binutils-2.6.0.2.bin.tar.gz}¡£



ÐèÒª×¢ÒâµÄÊÇbinutilsÖ»ÊÊÓÃì¶ELF£¬¶øÇÒÄ¿Ç°libcµÄ°æ±¾Ò²¶¼ÊÇÊôì¶ELFµÄ£»µ±È»À²£¬Ï°¹ßa.outµÄÈËÈç¹ûÓÐ¸öELFµÄlibcÓëa.outµÄlibcÁªºÏÆðÀ´Ò»ÆðÊ¹ÓÃ£¬Õâ¶ÔËûÃÇÀ´½²ÊÇÔÙºÃ²»¹ýµÄÃÀÊÂÁË¡£²»¿É·ñÈÏµÄ£¬C³ÌÊ½¹ÝµÄ·¢Õ¹ÕýÒÔ¼á¾öµÄ½Å²½ÂõÏòELFµÄ¸ñÊ½£¬³ý·ÇÄãÕæµÄÓÐºÜºÃµÄÀíÓÉ£¬ÐèÒªa.outµÄ¶«¶«£¬²»È»°¡£¬´ó¼Ò¶¼»á¹ÄÀøÄãÓÂì¶Í»ÆÆ£¬³ÃÔç¼ÓÈëÈñ²»¿Éµ²µÄ´ó³±Á÷¡£

11/9/97Òë








\section{GCCµÄ°²×°ÓëGCCµÄÉè¶¨}


\subsection{GCCµÄ°æ±¾\label{index.12} 
\label{index.13} 
\label{index.14} }

ÔÚshellµÄÌáÊ¾·ûºÅÏÂ¼üÈë{\ttfamily gcc -v}£¬Ó©Ä»ÉÏ¾Í»áÏÔÊ¾³öÄãÄ¿Ç°ÕýÔÚÊ¹ÓÃµÄGCCµÄ°æ±¾¡£Í¬Ê±ÕâÒ²ÊÇÒ»¸öÏàµ±¿É¿¿µÄ·½·¨£¬¿ÉÒÔÈ·¶¨ÄãÏÖÔÚËùÓÃµÄÊÇELF»òÊÇa.out¡£ÔÚÎÒµÄÏµÍ³ÉÏ£¬Ö´ÐÐgcc -vµÄ½á¹ûÊÇ£º

\begin{tscreen}
\begin{verbatim}
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
gcc version 2.7.2
\end{verbatim}
\end{tscreen}




ÉÏÃæµÄÑ¶Ï¢Ö¸³öÁË¼¸¼þÖØÒªµÄÊÂÇé£º
\begin{itemize}
\item  {\ttfamily i486} ÕâÊÇÖ¸Ã÷ÄãÏÖÔÚÕýÔÚÓÃµÄgccÊÇÎªÁË486µÄÎ¢´¦ÀíÆ÷¶øÐ´µÄ---ÄãµÄµçÄÔ¿ÉÄÜÊÇ386»òÊÇ586¡£Õâ3ÖÖÎ¢´¦ÀíÆ÷µÄ¾§Æ¬Ëù±àÒë¶ø³ÉµÄ³ÌÊ½Âë£¬±Ë´Ë¼äÊÇ¿ÉÒÔÏàÈÝÊ¹ÓÃµÄ¡£²î±ðÖ®´¦ÊÇ486µÄ³ÌÊ½ÂëÔÚÄ³Ð©µØ·½ÓÐ¼ÓÉÏpaddingµÄ¹¦ÄÜ£¬ËùÒÔ¿ÉÒÔÔÚ486ÉÏÃæÅÜµÃ±È½Ï¿ì¡£Õâ¶Ô386µÄ»úÆ÷¶øÑÔ£¬Ö´ÐÐ³ÌÊ½µÄÐ§ÄÜ²¢²»»áÓÐÊ²÷á²»Á¼µÄÓ°Ïì£¬Ö»²»¹ýÕæµÄ»áÈÃ³ÌÊ½Âë±äµÃÉÔÉÔµÄ´óÁËÒ»Ð©¡£
\item  {\ttfamily box} Õâ¿ÉÒÔËµÒ»µãÒ²{\itshape ²»\/}ÖØÒª£»²»¹ýÒ²¿ÉÄÜÁíÓÐËùÖ¸£¨ÏñÊÇ{\ttfamily slackware}»òÕßÊÇ{\ttfamily debian}£©£¬»òÕß¸ù±¾Ê²÷áÒ²²»ÊÇ£¨ËùÒÔÂÞ£¡ÍêÕûµÄÄ¿Â¼Ãû³ÆÊÇ{\ttfamily i486-linux}£©¡£¼ÙÈçÄãÊÇÊµÎñÅÉµÄÙ®Ù®Õß£¬Ç××Ô¶¯ÊÖ½¨Á¢Êôì¶×Ô¼ºµÄgcc£¬ÄÇ÷áÄã¿ÉÒÔÔÚ½¨Á¢µÄ¹ý³ÌÖÐÉè¶¨ÕâÒ»Ïî£¬ÒÔ×°µãÃÅÃæ¡£¾ÍÏñÎÒ×öµÄÒ»Ñù{\ttfamily :-)}¡£
\item  {\ttfamily linux} ÆäÊµÕâÊÇÖ¸{\ttfamily linuxelf}»òÊÇ{\ttfamily linuxaout}¡£ÕâÒ»Ïî»áÁîÈËÒýÆð²»±ØÒªµÄÀ§»ó£¬¾¿¾¹ÊÇÖ¸ÄÄÒ»ÖÖ»á¸ù¾ÝÄãËùÓÃµÄ°æ±¾¶øÒì¡£

\begin{itemize}
\item  {\ttfamily linux} ÒâÖ¸ELFÈô°æ±¾ÐòºÅÊÇ2.7.0.£¨»òÊÇ¸üÐÂµÄ°æ±¾£©£»·ñÔòµÄ»°£¬¾ÍÊÇa.outµÄÁË¡£
\item {\ttfamily linuxaout} ÒâÖ¸a.outµÄ¸ñÊ½¡£µ±{\ttfamily linux}µÄ¶¨Òå´Óa.out¸ü»»µ½ELFÊ±£¬linuxaout¾Í»áË³Ë®ÍÆÖÛ£¬Ò¡ÉíÒ»±ä£¬³ÉÁËÒ»¸öÄ¿±êÎï¡£Òò´Ë£¬Äã²»»á¿´µ½ÈÎºÎ°æ±¾ÐÂì¶2.7.0.µÄgccÓÐlinuxaoutµÄ¡£

\label{index.15} 
\item {\ttfamily linuxelf} ÒÑ¾­¹ýÊ±ÁË¡£Í¨³£ÕâÊÇÖ¸2.6.3°æµÄgcc£¬¶øÇÒÕâ¸ö°æ±¾Ò²¿ÉÒÔÓÃÀ´²úÉúELFµÄ¿ÉÖ´ÐÐµµ¡£Òª×¢ÒâµÄÊÇ£¬gcc 2.6.3°æÔÚ²úÉúELF³ÌÊ½ÂëÊ±»áÓÐbugs£¬ËùÒÔÈç¹ûÄãÄ¿Ç°ÓÃµÄÇ¡ºÃÊÇÕâ¸ö°æ±¾£¬½¨ÒéÄã¸Ï¿ìÉý¼¶¡£
\end{itemize}
\item  {\ttfamily 2.7.2} °æ±¾µÄÐòºÅ¡£
\end{itemize}


ËùÒÔ£¬×Ü½áÆðÀ´£¬ÎÒÓÐ2.7.2°æµÄgcc£¬¿ÉÒÔ²úÉúELF¸ñÊ½µÄ³ÌÊ½Âë¡£¾ÍÕâ÷á¼òµ¥£¬¾ªÑÈ°É£¡eh£¿




\subsection{¶«¶«×°ºÃáá¶¼µ½ÄÄ¶ùÈ¥ÁË?}

Èç¹û°²×°gccÊ±Ã»ÓÐ×ÐÏ¸µÄ¿´ÖøÓ©Ä»£¬»òÕßÄãÊÇ´ÓÒ»¸öÍêÕûµÄ·¢ÐÐÏµÍ³Àï°Ñgccµ¥¶À×¥³öÀ´°²×°µÄ»°£¬ÄÇ÷áÒ²ÐíÄã»áÏëÖªµÀµ½µ×ÕâÐ©¶«¶«×°ºÃááÊÇ×¡ÔÚÕû¸öµµ°¸ÏµÍ³µÄÄÇÐ©µØ·½¡£¼¸¸öÖØµãÈçÏÂ£º

\begin{itemize}
\item {\ttfamily /usr/lib/gcc-lib/}{\itshape target\/}{\ttfamily /}{\itshape version\/}{\ttfamily /} £¨Óë×ÓÄ¿Â¼£©´ó²¿·ÝµÄ±àÒëÆ÷¾ÍÊÇ×¡ÔÚÕâ¸öµØ·½µÄ¡£ÔÚÕâ¶ùÓÐ¿ÉÖ´ÐÐµÄ³ÌÊ½£¬Êµ¼ÊÔÚ×ö±àÒëµÄ¹¤×÷£»ÁíÍâ£¬»¹ÓÐÒ»Ð©ÌØ¶¨°æ±¾µÄ³ÌÊ½¿âÓë±êÍ·µµµÈÒ²»á´¢´æÔÚ´Ë¡£
\item  {\ttfamily /usr/bin/gcc} Ö¸µÄÊÇ±àÒëÆ÷µÄÇý¶¯³ÌÊ½---Ò²¾ÍÊÇÄãÊµ¼ÊÔÚÃüÁîÁÐ(command line)ÉÏÖ´ÐÐµÄ³ÌÊ½¡£Õâ¸öÄ¿Â¼¿É¹©¸÷ÖÖ°æ±¾µÄgccÊ¹ÓÃ£¬Ö»ÒªÄãÓÃ²»Í¬µÄ±àÒëÆ÷Ä¿Â¼£¨ÈçÉÏËùÊö£©À´°²×°¾Í¿ÉÒÔÁË¡£ÒªÖªµÀÄÚ¶¨µÄ°æ±¾ÊÇÄÇÒ»¸ö£¬ÔÚshellÌáÊ¾·ûºÅÏÂ´ò{\ttfamily gcc -v}¡£ÒªÊÇÏëÇ¿ÆÈÖ´ÐÐÄ³¸ö°æ±¾£¬¾Í»»´ò{\ttfamily gcc -V }{\itshape version\/}¡£ÀýÈç£º

\begin{tscreen}
\begin{verbatim}
# 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
\end{verbatim}
\end{tscreen}

\item  {\ttfamily /usr/}{\itshape target\/}{\ttfamily /(bin$|$lib$|$include)/}
Èç¹ûÄã×°ÁËÊýÖÖµÄÄ¿±êÎï¼þ£¬ÀýÈça.outÓëelf£¬»òÊÇÄ³Ò»ÖÖµÄ½»²æ±àÒëÆ÷(cross-compiler)µÈµÈ£¬ÄÇÐ©Êôì¶·ÇÖ÷Á÷Ä¿±êÎï¼þ£¨non-native target(s)£©µÄ³ÌÊ½¿â£¬binutils£¨{\ttfamily as}¡¢{\ttfamily ld}µÈµÈ£©¹¤¾ßÓë±êÍ·µµµÈ¶¼¿ÉÒÔÔÚÕâ¶ùÕÒµ½¡£¼´Ê¹ÄãÖ»°²×°ÁËÒ»ÖÖgcc£¬»¹ÊÇ¿ÉÒÔÔÚÕâ¶ùÕÒµ½ÕâÐ©Ô­±¾¾ÍÊÇÌæËüÃÇ×¼±¸µÄ¶«¶«¡£Èç¹û²»ÊÇÔÚÕâ¶ù£¬ÄÇ÷á¾ÍÓ¦¸ÃÊÇÔÚ{\ttfamily /usr/(bin$|$lib$|$include)}ÁË¡£
 
\item  {\ttfamily /lib/}£¬{\ttfamily /usr/lib} ÓëÆäËüµÄÄ¿Â¼µÈ¶¼ÊÇÖ÷Á÷ÏµÍ³£¨native-system£©µÄ³ÌÊ½¹ÝÄ¿Â¼¡£Ðí¶àµÄÓ¦ÓÃ³ÌÊ½¶¼»áÓÃµ½{\ttfamily /lib/cpp}£¬Òò´ËÄãÒ²ÐèÒªËü---×÷·¨ÉÏ£¬²»ÊÇ´Ó{\ttfamily /usr/lib/gcc-lib/}{\itshape target\/}{\ttfamily /}{\itshape version\/}{\ttfamily / }Ä¿Â¼Àï¿½±´£¬¾ÍÊÇÅª¸ö·ûºÅÁ¬½á£¨symlink£©Ö¸ÏòÄÇ¶ù¡£
{[}ÒëÕß×¢:ËùÎ½µÄnative£¬ÊÇÖ¸Ä¿Ç°ÄãµÄÏµÍ³ÊÇÒÔa.out»òelfµÄ¸ñÊ½ÎªÖ÷£¬»òÕßÄÚ¶¨µÄgccÊÇÄÄÒ»ÖÖ°æ±¾µÈµÈ¡£nativeµÄÒâË¼ÊÇ¡®±¾ÍÁµÄ¡¯¡¢¡®±¾¹úµÄ¡¯Óë¡®ÌìÉúµÄ¡¯¡­¡­µÈµÈ£»µ±ÄãÄÃµ½Ò»Æ¬CD-ROMÖØÍ·ÖÁÎ²½«Linux°²×°Íê³É£¬ÈÃLinux³öÉú£¬³ÉÎªÄã¸öÈËÌØÉ«Å¨ºñµÄ×÷ÒµÆ½Ì¨áá£¬Èç¹ûÔÙ¼Ó×°Ò»Ð©²»Ò»ÑùµÄÄ¿±êÎï¼þ£¬×ÔÈ»¾ÍÓÐ¡®±¾ÍÁ¡¯Óë¡®ÍâÊ¡¡¯£¨ ÎÞ¹ØÕþÖÎ£©£¬¡®±¾¹ú¡¯Óë¡®Íâ¹ú¡¯¡¢¡®ÌìÉú¡¯Óë¡®ÈËÎª¡¯µÈµÈµÄÇø±ð£¬Í¬Ê±Ò²º¬ÓÐÄÚ¶¨£¨default£©µÄÒâË¼ÔÚ¡£¼ÙÈôÔÙ¸½¼ÓÉÏÄã¸öÈËµÄ¼ÛÖµ¹ÛÅÐ¶ÏºÍÏ²ºÃ£¬ÎÒÏëÓÃÖ÷Á÷£¨native£©Óë·ÇÖ÷Á÷£¨non-native£©À´·­ÒëÓ¦¸Ã»¹ËãÇ¡µ±¡£]

\label{index.16} 
\end{itemize}





\subsection{±êÍ·µµ¨Ë¨ß?±êÍ·µµ¨Ë¨ß?
\label{index.17} }

¼ÙÈç°ÑÄã×ÔÐÐ°²×°ÔÚ{\ttfamily /usr/local/include}Ä¿Â¼µ×ÏÂµÄ±êÍ·µµÅÅ³ýÔÚÍâµÄ»°£¬Linux»¹ÓÐÁíÍâ3ÖÖÖ÷ÒªµÄ±êÍ·µµ£º

\begin{itemize}
\item  {\ttfamily /usr/include/}ÓëÆä×ÓÄ¿Â¼µ×ÏÂµÄ±êÍ·µµ£¬´ó²¿·Ý¶¼ÊÇÓÉH.J.Lu·¢Õ¹µÄlibcÌ×¼þ(libc binary package)ËùÌá¹©µÄ¡£ÎÒ»áÖ»Ëµ¡®´ó²¿·Ý¡¯µÄÔ­Òò£¬ÊÇÒòÎªÄã¿ÉÄÜÓÐÆäËüÀ´Ô´µÄ±êÍ·µµ£¨ÏñÊÇ{\ttfamily curses}Óë{\ttfamily dbm}³ÌÊ½¿âµÈµÈ£©°ÚÔÚÕâ¶ù£»ÓÈÆäÊÇ£¬Èç¹ûÄãÏÖÔÚÓÃµÄÊÇ×îÐÂµÄlibc·¢ÐÐÏµÍ³µÄ»°£¨ÐÂ°æ±¾²»Ïñ¾É°æÄÇÑù£¬ÒÑ¾­²»ÔÙÖ§Ô®curses»òdbmÁË¡££©£¬ÄÇ¶«¶«Ö®¶àÊÇÈËÈËÎªÖ®Õ¦ÉàµÄ£¡
{[}ÒëÕß×¢:libc binary packageÒâÖ¸ÒÔ¶þ½øÎ»ÐÎÊ½(machine code)´¢´æÖ®Ì×¼þ£¬²¢·ÇÔ­Ê¼Âë£¨text£©£¬ÈôÒªÒÔÖÐÎÄÈ«³ÆÒë³ö£¬Ôò³É¡®libc¶þ½øÎ»µµÌ×¼þ¡¯£¬ËÆÓÐñúÑÀÖ®ÏÓ£¬¹ÊÂÔÈ¥binary£¬ÒÔlibcÌ×¼þÍ¨³Æ¡£]

\label{index.18} 
\label{index.19} 
\item  ÔÚºËÐÄÔ­Ê¼ÂëµÄ·¢ÐÐÏµÍ³ÄÚ(kernel source distribution) £¬{\ttfamily /usr/include/linux} Óë {\ttfamily /usr/include/asm} £¨ÀïÍ·ÓÐÕâÐ©µµ°¸£º{\ttfamily $<$linux/*.h$>$} Óë {\ttfamily $<$asm/*.h$>$}£©Ó¦¸ÃÓÐ·ûºÅÁ¬½á£¨symbolic links£©¿ÉÒÔÁ¬½áÖÁÄ¿Â¼{\ttfamily linux/include/linux} Óë {\ttfamily linux/include/asm}¡£Èç¹ûÄãÓÐºèðÀÖ®Ö¾µÄ»°£¬°²×°ÕâÐ©¶«¶«áá£¬¾Í²»Ó¦¸ÃÖ»ÊÇÄÃÀ´±àÒëºËÐÄ£¨kernel£©¶øÒÑ¡£

°ÑÔ­Ê¼Âë½âÑ¹Ëõ£¨unpacking£©áá£¬¿ÉÄÜÄãÒ²»á·¢ÏÖ£¬ÐèÒªÔÚºËÐÄµÄÄ¿Â¼£¨kernel directory£©µ×ÏÂ×ö{\ttfamily make config}µÄ¶¯×÷¡£ºÜ¶àµÄµµ°¸¶¼»áÒÀÀµ{\ttfamily $<$linux/autoconf.h$>$}µÄ°ïÃ¦£¬¿ÉÊÇÕâ¸öµµ°¸È´ÓÐ¿ÉÄÜÒò°æ±¾²»Í¬¶ø²»´æÔÚ¡£Èô¸ÉºËÐÄ°æ±¾Àï£¬{\ttfamily asm}¾ÍÖ»ÊÇËü×Ô¼ºµÄÒ»¸ö·ûºÅÁ¬½á£¬½ö½öÊÇÔÚ{\ttfamily make config}Ê±²Å½¨Á¢³öÀ´¶øÒÑ¡£
{[}ÒëÕß×¢:Ô­ÎÄÌá¼°autoconf.hÊ±ÊÇ¡®Many files depend on {\ttfamily $<$linux/autoconf.h$>$},which otherwise may not exist,*¡¯¡£´Ë´¦Ö®otherwiseÖ®´ÊÐÔÓ¦ÎªÐÎÈÝ´Ê(adj)£¬Ö¸¡®ÁíÒ»Çé¿ö¡¯¡¢¡®ÁíÒ»ÖÖ¡¯¡¢¡®²»Í¬µÄ¡¯Ö®Òâ£¬½«Ô­ÎÄÐÎÈÝ´Ê×Ó¾ä²ð¿ªÀ´Ó¦Îª£º(i) Many files depend on {\ttfamily $<$linux/autoconf.h$>$}.
(ii){\ttfamily $<$linux/autoconf.h$>$} {\itshape of other condition\/} may not exist.
ÓëÏÂÒ»¾ä»¥Ïà±È¶Ô£¬´Ë´¦Ó¦Í¬Ö¸ÔÚ²»Í¬°æ±¾Ö®Çé¿öÏÂ¡£]

ËùÒÔ£¬µ±ÄãÔÚÄ¿Â¼{\ttfamily /usr/src/linux}µ×ÏÂ£¬½â¿ªºËÐÄµÄ³ÌÊ½ÂëÊ±£¬¾ÍÕÕÖøÏÂÃæÖ¸Ê¾µÄ×ö°É£¡

\begin{tscreen}
\begin{verbatim}
$ cd /usr/src/linux
$ su
# make config
(»Ø´ð½ÓÏÂÀ´µÄÎÊÌâ¡£Í¨³£»Ø´ðµÃÕý²»ÕýÈ·²¢²»ÖØÒª£¬³ý·ÇÄã´òËã¼ÌÐø¡õÔìºËÐÄ¡£)
# cd /usr/include
# ln -s ../src/linux/include/linux .
# ln -s ../src/linux/include/asm .
\end{verbatim}
\end{tscreen}


\label{index.20} 
\label{index.21} 
\label{index.22} 
\label{index.23} 
\label{index.24} 
\item  ÖîÈç{\ttfamily $<$float.h$>$}¡¢{\ttfamily $<$limits.h$>$}¡¢{\ttfamily $<$varargs.h$>$}¡¢{\ttfamily $<$stdarg.h$>$} Óë{\ttfamily $<$stddef.h$>$}Ö®ÀàµÄµµ°¸£¬»áËæÖø²»Í¬µÄ±àÒëÆ÷°æ±¾¶øÒì£¬Êôì¶Äã¡®¸öÈËµÄ¡¯µµ°¸£¬¿ÉÒÔÔÚ {\ttfamily /usr/lib/gcc-lib/i486-box-linux/2.7.2/include/}ÓëÆäËüÏàÀàËÆ£¨ÏàÍ¬£©µÄÄ¿Â¼Ãû³ÆµÄµØ·½ÕÒµ½¡£

11/11/97Òë
5/14/98ÐÞÕý
\end{itemize}





\subsection{½¨Á¢½»²æ±àÒëÆ÷(Building cross compilers)}


\subsubsection{½«Linuxµ±×÷±êµÄ×÷ÒµÆ½Ì¨(target platform)}

 ¼ÙÉèÄãÒÑ¾­ÄÃµ½gccµÄÔ­Ê¼Âë£¬Í¨³£ÄãÖ»ÒªÒÀÑ­INSTALLµµµÄÖ¸Ê¾±ã¿ÉÍê³ÉÒ»ÇÐµÄÉè¶¨¡£ makeááÃæÔÙ½Ó{\ttfamily configure --target=i486-linux --host=XXX} on platform {\ttfamily XXX}£¬¾ÍÄÜ°ïÄã±ä°ÑÏ·ÁË¡£Òª×¢ÒâµÄÊÇ£¬Äã»áÐèÒªLinux»¹ÓÐºËÐÄµÄ±êÍ·µµ£»Í¬Ê±Ò²ÐèÒª½¨Á¢½»²æ×éÒëÆ÷(cross assembler)Óë½»²æÁ¬½áÆ÷(cross linker)£¬À´Ô´ÊÇ\nameurl{ftp://tsx-11.mit.edu/pub/linux/packages/GCC/}{}¡£




\subsubsection{Linuxµ±³ÉÔ­Ê¼×÷ÒµÆ½Ì¨(source platform)¶øMSDOS×÷Îª±êµÄ×÷ÒµÆ½Ì¨}

 Ugh¡£ºÜÃ÷ÏÔµÄ£¬Õâ¸ö´ó¸ÅÐèÒªÓÃµ½Ì×¼þ¡°emx¡±»òÊÇÑÓÉìÌ×¼þ¡°go¡±¡£Çë×ÔÐÐÈ¥\nameurl{ftp://sunsite.unc.edu/pub/Linux/devel/msdos}{}¿´¿´¡£ÎÒ²¢Ã»ÓÐ²âÊÔ¹ýÕâÐ©¸ö¶«Î÷£¬ËùÒÔÃ»ÓÐ°ì·¨±£Ö¤Ê²÷á¡£






\section{ÒÆÖ²³ÌÊ½Óë±àÒë³ÌÊ½}


\subsection{gcc×ÔÐÐ¶¨ÒåµÄ·ûºÅ\label{index.25} }

Ö»ÒªÖ´ÐÐgccÊ±£¬¸½¼Ó{\ttfamily  -v}Õâ¸ö²ÎÊý£¬¾ÍÄÜÕÒ³öÄãËùÓÃµÄÕâ°ægcc£¬×Ô¶¯°ïÄã¶¨ÒåÁËÊ²÷á·ûºÅ¡£ÀýÈç£¬ÎÒµÄ»úÆ÷¿´ÆðÀ´»áÏñÕâÑù£º

\begin{tscreen}
\begin{verbatim}
$ 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__ -
\end{verbatim}
\end{tscreen}


¼ÙÈôÄãÕýÔÚÐ´µÄ³ÌÊ½Âë»áÓÃµ½Ò»Ð©Linux¶ÀÓÐµÄÌØÐÔ£¬ÄÇ÷á°ÑÄÇÐ©ÎÞ·¨ÒÆÖ²µÄ³ÌÊ½Âë£¬ÒÔÌõ¼þÊ½±àÒëµÄÇ°ÖÃÃüÁî·âÀ¨ÆðÀ´£¬¿ÉÊÇ¸ö²»´íµÄÖ÷ÒâÄØ£¡ÈçÏÂËùÊ¾¡Ã

\begin{tscreen}
\begin{verbatim}
#ifdef __linux__
/* ... funky stuff ... */
#endif /* linux */
\end{verbatim}
\end{tscreen}


ÓÃ{\ttfamily \_\_linux\_\_}¾Í¿ÉÒÔ´ï³ÉÄ¿µÄ£»¿´×ÐÏ¸Ò»µã£¬{\itshape ²»ÊÇ\/}{\ttfamily linux}à¸¡£¾¡¹Ü{\ttfamily linux}Ò²ÓÐ¶¨Òå£¬±Ï¾¹£¬Õâ¸öÈÔÈ»²»ÊÇPOSIXµÄ±ê×¼¡£






\subsection{ÏßÉÏÇóÖúËµÃ÷}

 gcc±àÒëÆ÷²ÎÊýµÄËµÃ÷ÎÄ¼þÊÇgcc info page£¨ÔÚEmacsÄÚ£¬°´ÏÂ{\ttfamily C-h i}£¬È»ááÑ¡¡®gcc¡¯µÄÑ¡Ïî£©¡£ÒªÊÇÅª²»³öÀ´£¬²»ÊÇÂôÄãCD-ROMµÄÈËÃ»°ÑÕâ¸ö¶«¶«Ñ¹¸øÄã£¬²»È»¾ÍÊÇÄãÏÖÔÚÓÃµÄÊÇ¾É°æµÄ¡£Óöµ½ÕâÖÖÇé¿ö£¬×îºÃµÄ·½·¨ÊÇÒÆ¶¯×ðÍÎµ½archive\nameurl{ftp://prep.ai.mit.edu/pub/gnu}{}»òÊÇËüµÄmirrorsÕ¾Ì¨£¬È¥°ÑgccµÄÔ­Ê¼µµ°¸×¥»Ø¼Ò£¬ÖØÐÂÅëâ¿Ò»·¬¡£

gcc manual page£¨{\ttfamily gcc.1}£© ¿ÉÒÔËµÊÇÒÑ¾­¹ýÊ±ÁË£¬ÒªÊÇÄã³Ô±¥ÁË³ÅÖøÃ»ÊÂ¸ÉÓ²ÊÇÏë¿´£¬Ëü¾Í»á¸æËßÄãËµ±ðÎÞÁÄÁË¡£




\subsubsection{ÆìÕýÆ®Æ®~
\label{index.26} 
\label{index.27} }

 ÔÚÃüÁîÁÐÉÏÖ´ÐÐgccÊ±£¬Ö»ÒªÔÚËüµÄÆ¨¹ÉááÃæ¼ÓÉÏ{\ttfamily -O}{\itshape n\/}µÄÑ¡Ïî£¬¾ÍÄÜÈÃgcc¹Ô¹ÔµÄÌæÄãÉú³ö×î¼Ñ±àÂëµÄ»úÆ÷Âë¡£ÕâÀïµÄ{\itshape n\/}ÊÇÒ»¸ö¿ÉÓÐ¿ÉÎÞµÄÐ¡ÕûÊý£¬²»Í¬°æ±¾µÄgcc£¬{\itshape n\/}µÄÒâÒåÓëÆäÕýÈ·µÄ¹¦Ð§¶¼²»Ò»Ñù£¬²»¹ý£¬µäÐÍµÄ¡õÎ§ÊÇ´Ó0£¨²»Òª¼¦ÆÅ£¬ÎÒ²»Òª×î¼Ñ±àÂë¡££©±ä»¯µ½2£¨×î¼Ñ±àÂëÒª¶àÒ»µã¡££©£¬ÔÙÉý¼¶µ½3£¨×î¼Ñ±àÂëÒªÔÙ¶àÒ»µã£¬¶àÒ»µã£©¡£

gccÔÚÆäÄÚ²¿»á½«ÕâÐ©Êý×Ö×ªÒë³ÉÒ»ÏµÁÐµÄ{\ttfamily -f}Óë{\ttfamily -m}µÄÑ¡Ïî¡£Ö´ÐÐgccÊ±´øÉÏÆìºÅ{\ttfamily -v}Óë{\ttfamily -Q}£¬Äã¾ÍÄÜºÜÇå³þµÄ¿´³öÃ¿Ò»ÖÖµÈ¼¶µÄ{\ttfamily -O}ÊÇ¶ÔÓ¦µ½ÄÇÐ©Ñ¡Ïî¡£ºÃ±ÈËµ£¬¾Í{\ttfamily -O2}À´½²£¬ÎÒµÄgcc¸æËß»áÎÒËµ£º

\begin{tscreen}
\begin{verbatim}
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
\end{verbatim}
\end{tscreen}


ÒªÊÇÄãÓÃµÄ×î¼Ñ±àÂëµÈ¼¶¸ßì¶ÄãµÄ±àÒëÆ÷ËùÄÜÖ§Ô®µÄ£¨e.g. {\ttfamily -O6}£©£¬ÄÇ÷áËüµÄÐ§¹û¾Í¸úÄãÓÃÄãµÄ±àÒëÆ÷{\itshape ËùÄÜ\/}Ìá¹©µÄ×î¸ßµÈ¼¶µÄÐ§¹ûÊÇÒ»ÑùµÄ¡£ËµÊµÔÚµÄ£¬·¢ÐÐ³öÈ¥µÄgcc³ÌÊ½Âë£¬ÓÃÔÚ±àÒëÊ±¾¹ÊÇÈç´Ë´¦ÀíÕâµÈÎÊÌâ£¬ÕæµÄ²»ÊÇÊ²÷áºÃµÄ¹¹Ïë¡£ÈÕááÈôÊÇÓÐ¸ü½ø²½µÄ×î¼Ñ±àÂë·½·¨¾ßÌåÕûºÏµ½ÐÂµÄ°æ±¾Àï£¬¶øÄã£¨»òÊÇÄãµÄusers£©»¹ÊÇÊÔÖøÕâÑù×öµÄ»°£¬¿ÉÄÜ¾Í»á·¢ÏÖgcc»áÖÐ¶ÏÄãµÄ³ÌÊ½ÁË¡£

\label{index.28} 
´Ógcc 2.7.0Éý¼¶µ½2.7.2µÄusersÓ¦¸Ã×¢ÒâÒ»µã£¬Ê¹ÓÃ{\ttfamily -O2}Ê±»áÓÐÒ»¸öbug¡£¸üÔã¸âµÄÊÇ£¬Ç¿¶ÈÕÛ¼õ²ÎÊý(strength reduction)¾ÓÈ»Ã»ÓÐÓÃ£¡ÒªÊÇÄãÏ²»¶ÖØÐÂ±àÒëgccµÄ»°£¬ÊÇÓÐÄÇ÷áÒ»¸öÐÞÕýµÄ°æ±¾¿ÉÒÔ¸üÕýÕâÏî´íÎó£»²»È»µÄ»°£¬Ò»¶¨ÒªÈ·¶¨Ã¿´Î±àÒëÊ±¶¼ÓÐ¼ÓÉÏ{\ttfamily -fno-strength-reduce}à¸£¡

11/12/97Òë








\paragraph{ÓÐ¸öÐÔµÄÎ¢´¦ÀíÆ÷}

 ÓÐÒ»Ð©{\ttfamily -m}µÄÆìºÅÊ®·ÖÓÐÓÃ´¦£¬µ«ÊÇÈ´ÎÞ·¨½åÓÉ¸÷ÖÖµÈ¼¶µÄ{\ttfamily -O}´ò¿ªÀ´Ê¹ÓÃ¡£ÕâÖ®ÖÐ×îÖØÒªµÄÓÐÊÇ{\ttfamily -m386}ºÍ{\ttfamily -m486}ÕâÁ½ÖÖ£¬ÓÃÀ´¸æËßgcc¸Ã°ÑÕýÔÚ±àÒëµÄ³ÌÊ½ÂëÊÓ×÷×¨Îª386»òÊÇ486»úÆ÷ËùÐ´µÄ¡£²»ÂÛÊÇÓÃÄÄÒ»ÖÖ{\ttfamily -m}À´±àÒë³ÌÊ½Âë£¬¶¼¿ÉÒÔÔÚ±Ë´ËµÄ»úÆ÷ÉÏÖ´ÐÐ£¬-m486±àÒë³öÀ´µÄÂë»á±È½Ï´ó£¬²»¹ýÄÃÀ´ÔÚ386µÄ»úÆ÷ÉÏÅÜÒ²²»»á±È½ÏÂý¾ÍÊÇÁË¡£

Ä¿Ç°ÉÐÎÞ{\ttfamily -mpentium}»òÊÇ{\ttfamily -m586}µÄÆìºÅ¡£Linus½¨ÒéÎÒÃÇ¿ÉÒÔÓÃ{\ttfamily -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2}À´µÃµ½×î¼Ñ±àÂëµÄ486³ÌÊ½Âë£¬ÕâÑù×öÕýºÃ¾Í¿ÉÒÔ±ÜÃâalignment£¨Pentium²¢²»ÐèÒª£©ÓÐ¹ý´óµÄgaps·¢Éú¡£Michael MeissnerËµ£º

\begin{quotation}
ÎÒµÄµÚÁù¸Ð¸æËßÎÒ£¬{\ttfamily -mno-strength-reduce}£¨ºÙ£¡ÒªÏþµÃÎÒ¿É²»ÊÇÔÚÌ¸Ç¿¶ÈÕÛ¼õ²ÎÊýµÄbugÑ½£¬ÄÇÒÑ¾­ÊÇÁíÍâÒ»¸öÕùÂÛµÄÕ½³¡ÁË¡££©Ò»ÑùÒ²¿ÉÒÔÔÚx86µÄ»úÆ÷ÉÏ²úÉú½Ï¿ìµÄ³ÌÊ½Âë£¬ÕâÊÇÒòÎªx86µÄ»úÆ÷¶ÔÔÝ´æÆ÷ÓÐÖø²»¿ÉÄ¥ÃðµÄ¡õ¿ÊÔÚ£¬¶øÇÒGCC's method of grouping registers into spill registers vs. other registers doesn't help either¡£´«Í³ÉÏ£¬Ç¿¶ÈÕÛ¼õµÄ½á¹û»áÊ¹µÃ±àÒëÆ÷È¥ÀûÓÃ¼Ó·¨ÔÝ´æÆ÷ÒÔ¼Ó·¨ÔËËãÀ´È¡´ú³Ë·¨ÔËËã¡£ÊÂÊµÉÏ£¬ÎÒÔÚ»³ÒÉ{\ttfamily -fcaller-saves}¿ÉÄÜÒ²Ö»ÊÇ¸öÂ©¶´Ò²Ëµ²»¶¨¡£
\end{quotation}

\begin{quotation}
¶øÎÒµÄµÚÆß¸ÐÔòÔÙ¶ÈµÄ¸æËßÎÒËµ£¬{\ttfamily -fomit-frame-pointer}¿ÉÄÜ»áÒ²¿ÉÄÜ²»»áÓÐÈÎºÎµÄ×¬Í·¡£´ÓÕâµãÀ´¿´£¬¾ÍÊÇÒâÎ½ÖøÓÐÁíÒ»¸öÔÝ´æÆ÷¿ÉÒÔÓÃÀ´´¦Àí¼ÇÒäÌå·ÖÅäµÄÎÊÌâ¡£Áí·½Ãæ£¬Èô´¿´â´Óx86µÄ»úÆ÷ÔÚ×ª»»ËüµÄÖ¸Áî¼¯³ÉÎª»úÆ÷ÂëµÄ·½·¨ÉÏÀ´¿´£¬±ãÒâÎ½Öø¶ÑµþËùÓÃµ½µÄ¼ÇÒäÌå¿Õ¼äÒª±ÈframeËùÓÃµ½µÄ»¹ÒªÀ´µÃ¶à£»»»¾ä»°Ëµ£¬Icache¶Ô³ÌÊ½Âë¶øÑÔ²¢Ã»ÓÐÊµÖÊÉÏµÄ°ïÖú£¬ÈôÊÇ¸óÏÂÓÃÁË{\ttfamily -fomit-frame-pointer}µÄ»°£¬Í¬Ê±Ò²ÊÇ¸æËß±àÒëÆ÷ÔÚÃ¿´Îºô½Ðº¯ÊýÖ®áá£¬¾Í±ØÐëÐÞÕý¶ÑµþµÄÖ¸±ê£»È»¶ø£¬¾ÍframeÀ´½²£¬Èôºô½ÐµÄ´ÎÊý²»¶àµÄ»°£¬ÔòÔÊÐí¶ÑµþÔÝÊ±¶Ñ»ýÆðÀ´¡£
\end{quotation}


ÓÐ¹ØÕâ·½ÃæÖ÷ÌâµÄ×îááÒ»¶Î»°ÈÔÊÇÀ´×Ôì¶Linus£º

\begin{quotation}
Òª×¢ÒâµÄÊÇ£¬Èç¹ûÄãÏëÒªµÃµ½×î¼Ñ×´¿öµÄÖ´ÐÐÐ§ÄÜ£¬¿ÉÇ§Íò±ðÏàÐÅÎÒµÄ»°¡£ÎÞÂÛÈçºÎ£¬Ò»¶¨Òª½øÐÐ²âÊÔ¡£gcc±àÒëÆ÷»¹ÓÐÐí¶àµÄ²ÎÊý¿ÉÓÃ£¬ÆäÖÐ¿ÉÄÜ¾ÍÓÐÒ»ÖÖ×îÌØ±ðµÄ×éºÏ£¬¿ÉÒÔ¸øÄã×î¼Ñ±àÂëµÄ½á¹û¡£
\end{quotation}


11/14/97Òë
5/15/98ÐÞÕý






\subsubsection{{\ttfamily Internal compiler error: cc1 got fatal signal 11}
\label{index.29} 
\label{index.30} 
\label{index.31} 
\label{index.32} 
\label{index.33} }

 Signal 11ÊÇÖ¸ SIGSEGV£¬»òÕß ¡®segmentation violation¡¯¡£Í¨³£ÕâÊÇÖ¸
Ëµgcc¶Ô×Ô¼ºËùÓÃµÄÖ¸±ê¸Ðµ½À§»ó£¬¶øÇÒ»¹³¢ÊÔÖø°Ñ×ÊÁÏÐ´Èë²»Êôì¶ËüµÄ¼ÇÒäÌåÀï¡£ËùÒÔ£¬Õâ¿ÉÄÜÊÇÒ»¸ögccµÄbug¡£
È»¶ø£¬´óÌå¶øÑÔ£¬gccÊÇÒ»Ö§¾­¹ýÑÏÃÜ²âÊÔÇÒ¿É¿¿¶ÈÁ¼ºÃµÄÈíÌå¼Ñ×÷¡£ËüÒ²ÓÃÁË´óÁ¿¸´ÔÓµÄ×ÊÁÏ½á¹¹Óë¾ªÈËµÄÖ¸±êÊýÁ¿¡£¼òÑÔÖ®£¬ÈôÊÇÒªÆÀÑ¡±¾ÊÀ¼Í×îÌôÌèÓë×îÒ»Ë¿²»¡õµÄRAM²âÊÔ³ÌÊ½£¬gcc¾ø¶Ô¿ÉÒÔÒ»Õªºó¹Ú¡£¼ÙÈçÄã{\itshape ÎÞ·¨ÖØÐÂ¸´ÖÆÕâÖ»bug\/}---µ±ÄãÖØÐÂ¿ªÊ¼±àÒëÊ±£¬´íÎóµÄÑ¶Ï¢²¢Ã»ÓÐÒ»Ö±³öÏÖÔÚÍ¬Ò»¸öµØ·½---ÄÇ¼¸ºõ¿ÉÒÔÈ·¶¨,ÊÇÄãµÄÓ²Ìå±¾ÉíÓÐÎÊÌâ(CPU,¼ÇÒäÌå,Ö÷»ú°å»òÊÇ¿ìÈ¡¼ÇÒäÌå).{\bfseries Ç§Íò²»Òª}ÒòÎªÄãµÄµçÄÔ¿ÉÒÔÍ¨¹ý¿ª»ú³ÌÐòµÄ²âÊÔ¡¢»òÊÇWindows¿ÉÒÔÅÜµÃºÜË³¡¢»òÕßÆäËüÊ²÷áµÄ£¬¾Í»Ø¹ýÍ·À´´óËÁÐû´«ËµÕâÊÇgccµÄÒ»¸öbug£»ÄãËù×öµÄÕâÐ©²âÊÔ¶¯×÷£¬Í¨³£Ã»ÓÐÊ²÷áÊµ¼ÊÉÏµÄ¼ÛÖµ£¬ÕâÊÇºÜºÏÀíµÄ½áÂÛ¡£ÁíÍâ£¬Ò²²»ÒªÒòÎª±àÒëºËÐÄÊ±£¬×ÜÊÇÍ£ÁôÔÚ¡®{\ttfamily make zImage}¡¯µÄ½×¶Î£¬¾ÍÒª´óÂîÕâÊÇgccµÄbug---µ±È»Ëü»áÍ£ÔÚÄÇ¶ù°¡£¡×ö¡®{\ttfamily make zImage}¡¯Ê±£¬ÐèÒª±àÒëµÄµµ°¸¿ÉÄÜ¾Í³¬¹ý200µµ°¸£»ÎÒÃÇÕýÔÚÑÐÄâÒ»¸öÌæ´úµÄ·½°¸¡£



 Èç¹ûÄã¿ÉÒÔÖØ¸²²úÉúÕâ¸öbug£¬¶øÇÒ£¨×îºÃÊÇÕâÑùÀ²£¡£©¿ÉÒÔÐ´Ò»¸ö¶ÌÐ¡µÄ³ÌÊ½À´Õ¹Ê¾ÕâÖ»bugµÄ»°£¬Äã¾Í¿ÉÒÔ°ÑËü×ö³Ébug±¨¸æ£¬È»ááemail¸øFSF£¬»òÕßÊÇlinux-gccÍ¨ÐÅÂÛÌ³¡£Äã¿ÉÒÔÈ¥²Î¿¼gccµÄËµÃ÷ÎÄ¼þ£¬¿´¿´ÓÐÊ²÷áÏêÏ¸µÄ×ÊÑ¶,ÊÇËûÃÇËùÐèÒªµÄ¡£






\subsection{ÒÆÖ²ÄÜÁ¦}

 ¾Ý±¨£¬½üÈÕÀ´Ðí¶àÕýÃæµÄÏûÏ¢Ö¸³ö£¬ÈôÊÇÓÐÄ³¼þ¶«¶«µ½ÏÖÔÚ¶¼»¹Ã»ÒÆÖ²µ½LinuxÉÏÈ¥£¬ÄÇ÷á¿ÉÒÔ¿Ï¶¨µÄÊÇ£¬ËüÒ»¶¨Ò»µã¼ÛÖµÒ²Ã»ÓÐ¡£:-)

àÅ£¡Õý¾­Ò»µã¡£Ò»°ã¶øÑÔ£¬Ô­Ê¼ÂëÖ»ÐèÒª×öÒ»Ð©¾Ö²¿µÄÐÞ¸Ä£¬¾Í¿ÉÒÔ¿Ë·þLinux 100\%ÓëPOSIXÏàÈÝµÄÌØÖÊ¡£Èç¹ûÄã×öÁËÈÎºÎµÄÐÞ¸Ä£¬¶ø½«´Ë²¿·Ý´«»Ø¸øÔ­×÷Õß£¬»áÊÇºÜÓÐ½¨ÉèÐÔµÄ¾Ù¶¯¡£ÕâÑùÈÕáá¾ÍÖ»ÐèÒªÓÃµ½¡®make¡¯£¬¾ÍÄÜµÃµ½Ò»¸ö¿ÉÖ´ÐÐµÄµµ°¸ÁË¡£




\subsubsection{BSD½ÌÍ½ (ÓÐ {\ttfamily bsd\_ioctl}¡¢{\ttfamily daemon} Óë {\ttfamily $<$sgtty.h$>$})}

 ±àÒë³ÌÊ½Ê±£¬¿ÉÒÔÅäºÏ{\ttfamily -I/usr/include/bsd}ÓëÁ¬½á{\ttfamily -lbsd}µÄ³ÌÊ½¿â¡££¨ÀýÈç£ºÔÚÄãµÄMakefileµµÄÚ£¬°Ñ{\ttfamily -I/usr/include/bsd}¼Óµ½{\ttfamily CFLAGS}ÄÇÒ»ÐÐ£»°Ñ{\ttfamily -lbsd}¼Óµ½{\ttfamily LDFLAGS}ÄÇÒ»ÐÐ£©¡£Èç¹ûÄãÕæµÄÄÇ÷áÏëÒªBSDÐÍÌ¬µÄÐÅºÅÐÐÎª£¬Ò²{\itshape ²»\/}ÐèÒªÔÙ¼ÓÉÏ{\ttfamily -D\_\_USE\_BSD\_SIGNAL}ÁË¡£ÄÇÊÇÒòÎªµ±ÄãÓÃÁË{\ttfamily -I/usr/include/bsd}Óëº¬À¨ÁË±êÍ·µµ{\ttfamily $<$signal.h$>$}Ö®áá£¬makeÊ±¾Í»á×Ô¶¯¼ÓÈëÁË¡£




\subsubsection{Ê§ÂäµÄ·âÓ¡({\ttfamily SIGBUS}, {\ttfamily SIGEMT}, {\ttfamily SIGIOT}, {\ttfamily SIGTRAP}, {\ttfamily SIGSYS} etc)
\label{index.34} 
\label{index.35} 
\label{index.36} 
\label{index.37} 
\label{index.38} }

 LinuxÓëPOSIXÊÇÍêÈ«ÏàÈÝµÄ¡£²»¹ý£¬ÓÐÐ©ÐÅºÅ²¢²»ÊÇPOSIX¶¨ÒåµÄ---ISO/IEC 9945-1:1990 (IEEE Std 1003.1-1990), paragraph B.3.3.1.1 sez:

\begin{quotation}
¡°ÔÚPOSIX.1ÖÐÊ¡ÂÔÁËSIGBUS¡¢SIGEMT¡¢SIGIOT¡¢SIGTRAPÓëSIGSYSÐÅºÅ£¬ÄÇÊÇÒòÎªËüÃÇµÄÐÐÎªÓëÊµ×÷µÄ·½Ê½Ï¢Ï¢Ïà¹Ø£¬¶øÇÒÒ²ÎÞ·¨½øÐÐÊÊµ±µÄ·ÖÀà¡£È·ÈÏÊµ×÷·½Ê½áá£¬±ã¿ÉÒÔ·¢ËÍÕâÐ©ÐÅºÅ£¬¿ÉÊÇ±ØÐëÒÔÎÄ¼þËµÃ÷ËüÃÇÊÇÔÚÊ²÷áÑùµÄ»·¾³µ×ÏÂ·¢ËÍ³öÀ´µÄ£¬ÒÔ¼°Ö¸³öÈÎºÎÓëËüÃÇµÄ·¢Õ¹Ïà¹ØµÄÏÞÖÆ¡£¡±
\end{quotation}




ÏëÒªÐÞÕýÕâ¸öÎÊÌâ£¬×î¼òµ¥Ò²ÊÇ×î±¿µÄ·½·¨¾ÍÊÇÓÃ{\ttfamily SIGUNUSED}ÖØÐÂ¶¨ÒåÕâÐ©ÐÅºÅ¡£{\itshape ÕýÈ·µÄ\/}·½·¨Ó¦¸ÃÊÇÒÔÌõ¼þÊ½µÄ±àÒë{\ttfamily \#ifdef}À´´¦ÀíÕâÐ©ÎÊÌâ²Å¶Ô£º

\begin{tscreen}
\begin{verbatim}
#ifdef SIGSYS
/* ... non-posix SIGSYS code here .... */
#endif
\end{verbatim}
\end{tscreen}


11/15/97Òë
5/22/98ÐÞÕý




\subsubsection{K \& R \label{index.39} }

gccÊÇÒ»¸öÓëANSIÏàÈÝµÄ±àÒëÆ÷£»Ææ¹ÖµÄÊÇ£¬Ä¿Ç°´ó¶àÊýµÄ³ÌÊ½Âë¶¼²»·ûºÏANSIËù¶¨µÄ±ê×¼¡£Èç¹ûÄãÈÈ°®ANSI£¬Ï²»¶ÓÃANSIÌá¹©µÄ±ê×¼À´×«Ð´C³ÌÊ½£¬ËÆºõ³ýÁË¼ÓÉÏ{\ttfamily -traditional}µÄÆìºÅÖ®Íâ£¬¾ÍÃ»ÓÐÆäËüÊ²÷á¿ÉÒÔ¶àÌ¸µÄÁË¡£There is a certain amount of finer-grained control over which varieties of brain damage to emulate;Çë×ÔÐÐ²éÔÄgcc info page¡£

Òª×¢ÒâµÄÊÇ£¬¾¡¹ÜÄãÓÃÁË{\ttfamily -traditional}À´¸Ä±äÓïÑÔµÄÌØÐÔ£¬ËüµÄÐ§¹ûÒ²½ö¾ÖÏÞì¶gccËùÄÜ¹»½ÓÊÜµÄ¡õÎ§¡£ÀýÈç, {\ttfamily -traditional}»á´ò¿ª{\ttfamily -fwritable-strings}£¬Ê¹µÃ×Ö´®³£ÊýÒÆÖÁ×ÊÁÏ¼ÇÒäÌå¿Õ¼äÄÚ(´Ó³ÌÊ½Âë¼ÇÒäÌå¿Õ¼äÒÆ³öÀ´£¬Õâ¸öµØ·½ÊÇ²»ÄÜÈÎÒâÐ´ÈëµÄ)¡£ÕâÑù×ö»áÈÃ³ÌÊ½ÂëµÄ¼ÇÒäÌå¿Õ¼äÎÞÐÎÖÐÔö¼ÓµÄ¡£




\subsubsection{Ç°ÖÃ´¦ÀíÆ÷µÄ·ûºÅÃ®ÉÏº¯ÊýÔ­ÐÍÐû¸æ\label{index.40} 
\label{index.41} }

×î³£¼ûµÄÎÊÌâÊÇ£¬ÈçÖÚËù½ÔÖª£¬LinuxÖÐÓÐÐí¶à³£ÓÃµÄº¯Êý¶¼¶¨Òå³É¾Þ¼¯´æ·ÅÔÚ±êÍ·µµÄÚ£¬´ËÊ±ÈôÓÐÏàËÆµÄº¯ÊýÔ­ÐÍÐû¸æ³öÏÖÔÚ³ÌÊ½ÂëÄÚ£¬Ç°ÖÃ´¦ÀíÆ÷»á¾Ü¾ø½øÐÐÓï·¨·ÖÎöµÄÇ°ÖÃ×÷Òµ¡£³£¼ûµÄÓÐ{\ttfamily atoi()}Óë{\ttfamily atol()}¡£




\subsubsection{{\ttfamily sprintf()}
\label{index.42} }

ÔÚ´ó²¿·ÝµÄUnixÏµÍ³ÉÏ£¬{\ttfamily sprintf(string, fmt, ...)}´«»ØµÄÊÇ{\ttfamily string}µÄÖ¸±ê£¬È»¶ø£¬Õâ·½ÃæLinux£¨×ñÑ­ANSI£©´«»ØµÄÈ´ÊÇ·ÅÈëstringÄÚµÄ×ÖÔªÊýÄ¿.½øÐÐÒÆÖ²Ê±£¬ÓÈÆäÊÇÕë¶ÔSunOS£¬ÐèÓÐ¾¯¾õµÄÐÄ¡£




\subsubsection{{\ttfamily fcntl} ÓëÏà¹ØµÄº¯Êý£»{\ttfamily FD\_*}¼Ò×åµÄ¶¨Òåµ½µ×°ÚÔÚÄÄÀï?
\label{index.43} 
\label{index.44} 
\label{index.45} 
\label{index.46} 
\label{index.47} 
\label{index.48} 
\label{index.49} }

¾ÍÔÚ{\ttfamily $<$sys/time.h$>$}ÀïÍ·¡£ ÎªÁËÕæÕýµÄÔ­ÐÍÐû¸æ£¬µ±ÄãÓÃÁË{\ttfamily fcntl}£¬¿ÉÄÜÄãÒ²Ïëº¬À¨±êÍ·µµ{\ttfamily $<$unistd.h$>$}½øÀ´¡£

Ò»°ã¶øÑÔ£¬º¯ÊýµÄmanual page»áÔÚSYNOPSISÕÂ½ÚÄÚÁÐ³öÐèÒªµÄ{\ttfamily ±êÍ·µµ}¡£






\subsubsection{{\ttfamily select()}µÄ¼ÆÊ±---³ÌÊ½Ö´ÐÐÊ±»á´¦ì¶Ã¦Âµ-µÈ´ýµÄ×´Ì¬\label{index.50} }

ºÜ¾ÃºÜ¾ÃÒÔÇ°,£¬{\ttfamily select()}µÄ¼ÆÊ±²ÎÊýÖ»ÓÐÎ¨¶ÁµÄÐÔ¶øÒÑ¡£¼´Ê¹µ½ÁË×î½ü£¬manual pagesÈÔÈ»ÓÐÏÂÃæÕâ¶ÎµÄ¾¯¸æ£º

\begin{quotation}
select()Ó¦¸ÃÊÇ½åÓÉÐÞÕýÊ±¼äµÄÊýÖµ£¨Èç¹ûÓÐµÄ»°£©£¬ÔÙ´«»Ø×ÔÔ­Ê¼¼ÆÊ±¿ªÊ¼ááËùÊ£âÅµÄÊ±¼ä¡£Î´À´µÄ°æ±¾¿ÉÄÜ»áÊ¹ÕâÏî¹¦ÄÜÊµÏÖ¡£Òò´Ë£¬¾ÍÄ¿Ç°¶øÑÔ£¬ÈôÒÔÎªºô½Ðselect()Ö®áá£¬¼ÆÊ±Ö¸±êÈÔÈ»²»»á±»ÐÞÕý¹ý£¬¿ÉÊÇÒ»ÖÖ·Ç³£²»Ã÷ÖÇµÄÏë·¨à¸£¡
\end{quotation}


Î´À´¾ÍÔÚÎÒÃÇµÄÑÛÇ°ÁË£¡ÖÁÉÙ£¬ÔÚÕâ¶ùÄã¾ø¶Ô¿ÉÒÔ¿´µ½¡£º¯Êý{\ttfamily select()}´«»ØµÄ£¬ÊÇ¿Û³ýµÈ´ýÉÐÎ´µ½´ïµÄ×ÊÁÏËùºÄ·ÑµÄÊ±¼äáá£¬ÆäÊ£âÅµÄÊ±¼äÊýÖµ¡£Èç¹ûÔÚ¼ÆÊ±½áÊøÊ±£¬¶¼Ã»ÓÐ×ÊÁÏ´«ËÍ½øÀ´£¬¼ÆÊ±ÒýÊý±ã»áÉèÎª0£»Èç¹û½ÓÖø»¹ÓÐÈÎºÎµÄselect()£¬ÒÔÍ¬ÑùµÄ¼ÆÊ±structureÀ´ºô½Ð£¬ÄÇ÷áselect()±ã»áÁ¢¿Ì½áÊø¡£

ÈôÒªÐÞÕýÕâÏîÎÊÌâ£¬Ö»ÒªÃ¿´Îºô½Ð{\ttfamily select()}Ç°£¬¶¼°Ñ¼ÆÊ±ÊýÖµ·Åµ½¼ÆÊ± structureÄÚ£¬¾ÍÃ»ÓÐÎÊÌâÁË¡£°ÑÏÂÃæµÄ³ÌÊ½Âë£¬
\begin{tscreen}
\begin{verbatim}
      struct timeval timeout;
      timeout.tv_sec = 1; timeout.tv_usec = 0;
      while (some_condition)
            select(n,readfds,writefds,exceptfds,&timeout); 
\end{verbatim}
\end{tscreen}

¸Ä³É£¬
\begin{tscreen}
\begin{verbatim}
      struct timeval timeout;
      while (some_condition) {
            timeout.tv_sec = 1; timeout.tv_usec = 0;
            select(n,readfds,writefds,exceptfds,&timeout);
      }
\end{verbatim}
\end{tscreen}


Õâ¸öÎÊÌâ£¬ÔÚÓÐÐ©°æ±¾µÄMosaicÀïÊÇÏàµ±ÖøÃûµÄ£¬Ö»ÒªÒ»´ÎµÄµÈ´ý£¬Mosaic¾Í¹ÒÔÚÄÇÀïÁË¡£MosaicµÄÓ©Ä»ÓÒÉÏ½Ç£¬ÊÇ²»ÊÇÓÐ¸öÔ²Ô²µÄ¡¢»áÐý×ªµÄµØÇò¶¯»­¡£ÄÇ¿ÅÇò×ªµÃÓú¿ì£¬¾Í±íÊ¾×ÊÁÏ´ÓÍøÂ·ÉÏ´«ËÍ¹ýÀ´µÄËÙÂÊÓúÂý£¡




\subsubsection{²úÉúÖÐ¶ÏµÄÏµÍ³ºô½Ð\label{index.51} 
\label{index.52} }


\paragraph{ÌØáç£º}

µ±Ò»Ö§³ÌÊ½ÒÔCtrl-ZÖÐÖ¹¡¢È»ááÔÙÖØÐÂÖ´ÐÐÊ±¡õ»òÕßÊÇÆäËü¿ÉÒÔ²úÉúCtrl-CÖÐ¶ÏÐÅºÅµÄÇé¿ö£¬Èç×Ó³ÌÐòµÄÖÕ½áµÈ¡õÏµÍ³¾Í»á±§Ô¹Ëµ"interrupted system call"»òÊÇ"write: unknown error"£¬»òÕßÖîÈç´ËÀàµÄÑ¶Ï¢¡£




\paragraph{ÎÊÌâµã£º}

POSIXµÄÏµÍ³¼ì²éÐÅºÅµÄ´ÎÊý£¬±ÈÆðÒ»Ð©¾É°æµÄUnixÊÇÒª¶àÄÇ÷áÒ»µã¡£Èç¹ûÊÇLinux£¬¿ÉÄÜ¾Í»áÖ´ÐÐsignal handlersÁË¡õ

\begin{itemize}
\item  ·ÇÍ¬²½µØ(¼ÆÊ±Æ÷µÄµÎ´ðÉù)
\item  ÏµÍ³ºô½ÐµÄ´«»ØÖµ
\item  ÔÚÏÂÁÐÏµÍ³ºô½ÐµÄÖ´ÐÐÆÚ¼ä¡Ã
{\ttfamily select()}, {\ttfamily pause()}, {\ttfamily connect()},{\ttfamily accept()}, {\ttfamily read()} on terminals, sockets, pipes or files in {\ttfamily /proc}, {\ttfamily write()} on terminals, sockets, pipes or the line printer, {\ttfamily open()} on FIFOs, PTYs or serial lines,{\ttfamily ioctl()} on terminals, {\ttfamily fcntl()} with command {\ttfamily F\_SETLKW}, {\ttfamily wait4()}, {\ttfamily syslog()}, any TCP or NFS operations.  
\end{itemize}


¾ÍÆäËüµÄ×÷ÒµÏµÍ³¶øÑÔ£¬ÄãÐèÒªµÄ¿ÉÄÜ¾ÍÊÇÏÂÃæÕâÐ©ÏµÍ³ºô½ÐÁË£º
{\ttfamily creat()}, {\ttfamily close()}, {\ttfamily getmsg()}, {\ttfamily putmsg()},
{\ttfamily msgrcv()}, {\ttfamily msgsnd()}, {\ttfamily recv()}, {\ttfamily send()},
{\ttfamily wait()}, {\ttfamily waitpid()}, {\ttfamily wait3()}, {\ttfamily tcdrain()},
{\ttfamily sigpause()}, {\ttfamily semop()} to this list.



ÔÚÏµÍ³ºô½ÐÆÚ¼ä£¬ÈôÓÐÒ»ÐÅºÅ£¨ÄÇÖ§³ÌÊ½±¾ÉíÓ¦×¼±¸ºÃhandlerÒòÓ¦ÁË£©²úÉú£¬handler¾Í»á±»ºô½Ð¡£µ±handler½«¿ØÖÆÈ¨×ªÒÆ»ØÏµÍ³ºô½ÐÊ±£¬Ëü»áÕì²â³öËüÒÑ¾­²úÉúÖÐ¶Ï£¬¶øÇÒ´«»ØÖµ»áÁ¢¿ÌÉè¶¨³É-1£¬¶ø{\ttfamily errnoÉè¶¨³ÉEINTR}¡£³ÌÊ½²¢Ã»ÓÐÏëµ½»á·¢ÉúÕâÖÖÊÂ£¬ËùÒÔ¾Í¹ÒÁË¡£

ÓÐÁ½ÖÖÐÞÕýµÄ·½·¨¿ÉÒÔÑ¡Ôñ£º

(1) ¶ÔÃ¿¸öÄã×ÔÐÐ°²×°µÄsignal handler£¬¶¼ÐëÔÚsigactionµÄÆìºÅ¼ÓÉÏ{\ttfamily SA\_RESTART}¡£ÀýÈç£¬°ÑÏÂÁÐµÄ³ÌÊ½£¬

\begin{tscreen}
\begin{verbatim}
  signal (sig_nr, my_signal_handler);
\end{verbatim}
\end{tscreen}

¸Ä³É£¬
\begin{tscreen}
\begin{verbatim}
  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);
  }
\end{verbatim}
\end{tscreen}


Òª×¢ÒâµÄÊÇ£¬µ±Õâ²¿·ÝµÄ±ä¸ü´óÁ¿Ó¦ÓÃµ½ÏµÍ³ºô½ÐÖ®áá£¬ºô½Ð{\ttfamily read()}¡¢{\ttfamily write()}¡¢{\ttfamily ioctl()}¡¢ {\ttfamily select()}¡¢ {\ttfamily pause()} Óë {\ttfamily connect()}Ê±£¬ÄãÈÔÈ»µÃ×ÔÐÐ¼ì²é{\ttfamily EINTR}¡£ÈçÏÂËùÊ¾£º

(2) Äã×Ô¼ºµÃºÜÃ÷È·µØ¼ì²é{\ttfamily EINTR}£º

ÕâÀïÓÐÁ½¸öÕë¶Ô{\ttfamily read()}Óë{\ttfamily ioctl()}µÄÀý×Ó¡£



Ô­Ê¼µÄ³ÌÊ½Æ¬¶Î£¬Ê¹ÓÃ{\ttfamily read()}£º

\begin{tscreen}
\begin{verbatim}
int result;
while (len > 0) { 
  result = read(fd,buffer,len);
  if (result < 0) break;
  buffer += result; len -= result;
}
\end{verbatim}
\end{tscreen}

ÐÞ¸Ä³É,
\begin{tscreen}
\begin{verbatim}
int result;
while (len > 0) { 
  result = read(fd,buffer,len);
  if (result < 0) { if (errno != EINTR) break; }
  else { buffer += result; len -= result; }
}
\end{verbatim}
\end{tscreen}

Ô­Ê¼µÄ³ÌÊ½Æ¬¶Î£¬Ê¹ÓÃ{\ttfamily ioctl()}£º

\begin{tscreen}
\begin{verbatim}
int result;
result = ioctl(fd,cmd,addr);
\end{verbatim}
\end{tscreen}

ÐÞ¸Ä³É£¬
\begin{tscreen}
\begin{verbatim}
int result;
do { result = ioctl(fd,cmd,addr); }
while ((result == -1) && (errno == EINTR));
\end{verbatim}
\end{tscreen}


×¢ÒâÒ»µã£¬ÓÐÐ©°æ±¾µÄBSD Unix£¬ÆäÄÚ¶¨µÄÐÐÎªÊÇÖØÐÂÖ´ÐÐÏµÍ³ºô½Ð¡£ÈôÒªÈÃÏµÍ³ºô½ÐÖÐ¶Ï£¬µÃÊ¹ÓÃ {\ttfamily SV\_INTERRUPT}»ò{\ttfamily SA\_INTERRUPT}ÆìºÅ¡£






\subsubsection{¿ÉÒÔÐ´ÈëµÄ×Ö´®\label{index.53} 
\label{index.54} 
\label{index.55} 
\label{index.56} }

 gcc¶ÔÆäusers×Ü»³±§ÖøÀÖ¹ÛµÄÏë·¨£¬ÏàÐÅµ±ËûÃÇ´òËãÈÃÄ³¸ö×Ö´®µ±×÷³£ÊýÀ´ÓÃÊ±---ÄÇËü¾ÍÕæµÄÖ»ÊÇ×Ö´®³£Êý¶øÒÑ¡£Òò´Ë£¬ÕâÖÖ×Ö´®³£Êý»á´¢´æÔÚ³ÌÊ½ÂëµÄ¼ÇÒäÌåÇø¶ÎÄÚ¡£Õâ¿éÇøÓò¿ÉÒÔpageµ½´Åµú»úµÄimageÉÏ£¬±ÜÃâºÄµôswapµÄ¼ÇÒäÌå¿Õ¼ä£¬¶øÇÒÈÎºÎ³¢ÊÔÐ´ÈëµÄ¾Ù¶¯¶¼»áÔì³É·ÖÒ³µÄ´íÎó(segmentation fault)¡£Õâ¿ÉÊÇÒ»ÖÖÌØÉ«ÄØ£¡

¶ÔÀÏ¾ÉÒ»µãµÄ³ÌÊ½¶øÑÔ£¬Õâ¿ÉÄÜ»á²úÉúÒ»¸öÎÊÌâ¡£ÀýÈç£¬ºô½Ð{\ttfamily mktemp()}£¬´«µÝµÄÒýÊý(arguments)ÊÇ×Ö´®³£Êý¡£ {\ttfamily mktemp()}»á³¢ÊÔÖøÔÚ*ÊÊµ±µÄÎ»ÖÃ*ÖØÐÂÐ´ÈëËüµÄÒýÊý¡£

ÐÞÕýµÄ·½·¨²»Íâºõ(a)ÒÔ{\ttfamily -fwritable-strings}±àÒë£¬ÆÈÊ¹gcc½«´Ë³£ÊýÖÃ·ÅÔÚ×ÊÁÏ¼ÇÒäÌå¿Õ¼äÄÚ£»»òÕß(b)½«ÇÖ·¸µØÈ¨µÄ²¿·ÝÖØÐÂ¸ÄÐ´£¬ÅäÖÃÒ»¸ö²»Îª³£ÊýµÄ×Ö´®£¬ÔÚºô½ÐÇ°£¬ÏÈÒÔstrcpy()½«×ÊÁÏ¿½±´½øÈ¥¡£




\subsubsection{ÎªÊ²÷áºô½Ð{\ttfamily execl()}»áÊ§°Ü£¿\label{index.57} }

ÄÇÊÇÒòÎªÄãºô½ÐµÄ·½Ê½²»¶Ô¡£{\ttfamily execl}µÄµÚÒ»¸öÒýÊýÊÇÄãÏëÒªÖ´ÐÐµÄ³ÌÊ½Ãû.µÚ¶þ¸öÓë½ÓÐøµÄÒýÊý»á±ä³ÉÄãËùºô½ÐµÄ³ÌÊ½µÄ{\ttfamily argv}ÕóÁÐ¡£¼Ç×¡£º´«Í³ÉÏ£¬{\ttfamily argv[0]}ÊÇÖ»ÓÐµ±³ÌÊ½Ã»ÓÐ´øÖøÒýÊýÖ´ÐÐÊ±£¬²Å»áÓÐÉè¶¨Öµ¡£ËùÒÔÂÞ£¬ÄãÓ¦¸ÃÕâÑùÐ´£º

\begin{tscreen}
\begin{verbatim}
execl("/bin/ls","ls",NULL);
\end{verbatim}
\end{tscreen}

¶ø²»ÊÇÖ»ÓÐ£¬
\begin{tscreen}
\begin{verbatim}
execl("/bin/ls", NULL);
\end{verbatim}
\end{tscreen}




Ö´ÐÐ³ÌÊ½¶ø²»´øÈÎºÎÒýÊý£¬¿É½âÊÍ³ÉÊÇÒ»ÖÖÑûÇëº¯£¬Ä¿µÄÊÇ°Ñ´Ë³ÌÊ½µÄ¶¯Ì¬³ÌÊ½¿â¶ÀÁ¢µÄÌØÐÔÓ¡³öÀ´¡£ÖÁÉÙ£¬a.outÊÇÕâÑùµÄ¡£¾ÍELF¶øÑÔ¡£ÊÂÇé¾Í²»ÊÇÕâÑùÁË.



£¨Èç¹ûÄãÏëµÃÖª´Ë³ÌÊ½¿âµÄ×ÊÑ¶£¬ÓÐÒ»Ð©¸ü¼òµ¥µÄ½éÃæ¿ÉÓÃ£»²Î¿¼¶¯Ì¬ÔØÈëÄÇÒ»ÕÂ½Ú£¬»òÊÇ{\ttfamily ldd}µÄmanual page¡££©

11/16/97Òë
6/2/98ÐÞÕý






\section{³ý´íÓë¼à¹Ü}


\subsection{Ô¤·ÀÖØì¶ÖÎÁÆ£¨lint£©\label{index.58} }

 lint¶ÔLinux¶øÑÔ²¢Ã»ÓÐºÜ¹ã·ºµÄÓÃÍ¾£¬Ö÷ÒªÊÇÒòÎª´ó²¿·ÝµÄÈË¶¼ÄÜÂú×ãì¶gccËùÌá¹©µÄ¾¯¸æÑ¶Ï¢¡£¿ÉÄÜ×îÓÐÓÃµÄ¾ÍÊÇ{\ttfamily -Wall}²ÎÊýÁË---Õâ¸ö²ÎÊýµÄÓÃÍ¾ÊÇÒªÇógcc½«ËùÓÐµÄ¾¯¸æÑ¶Ï¢ÏÔÏÖ³öÀ´£»but probably has more mnemonic value if thought of as the thing you bang your head against.

ÍøÂ·ÉÏÓÐÒ»¸öÊµÓÃµÄpublic domain lint£¬Î»ì¶ \nameurl{ftp://larch.lcs.mit.edu/pub/Larch/lclint}{}¡£ÎÒ²¢²»ÖªµÀÕâ¸öÕ¾µ½µ×ÓÐ¶àºÃ¾ÍÊÇÁË¡£




\subsection{³ý´í\label{index.59} }


\subsubsection{ÎÒÒªÔõÑù×ö²ÅÄÜ½«³ý´í×ÊÑ¶·Åµ½Ò»Ö§³ÌÊ½ÀïÍ·£¿\label{index.60} 
\label{index.61} 
\label{index.62} }

 ÄãÐèÒªÌí¼Ó{\ttfamily -g}µÄ²ÎÊýÀ´±àÒëÓëÁ¬½á³ÌÊ½£¬¶øÇÒ²»¿ÉÒÔÓÃ{\ttfamily -fomit-frame-pointer}²ÎÊý¡£ÊÂÊµÉÏ£¬Äã²»ÐèÒªÖØÐÂ±àÒëËùÓÐµÄ³ÌÊ½£¬Ö»ÐèÖØÐÂ±àÒëÄ¿Ç°ÄãÕýÔÚ³ý´íµÄ²¿·Ý¼´¿É¡£



¾Ía.outµÄ×éÌ¬¶øÑÔ£¬¹²Ïí³ÌÊ½¿âÊÇÒÔ{\ttfamily -fomit-frame-pointer}±àÒë¶ø³É£¬Õâ¸öÊ±ºò£¬gdb¾Í±äµÃÓ¢ÐÛÎÞÓÃÎäÖ®µØÁË¡£Á¬½áÊ±¸ø¶¨{\ttfamily -g}µÄÑ¡Ïî£¬Ó¦¸Ã¾ÍÒþº¬Öø¾²Ì¬Á¬½áµÄÒâÒåÁË£»Õâ¾ÍÊÇÎªÊ²÷áÒª¼Ó-gµÄÔ­ÒòÁË¡£



Èç¹ûÁ¬½áÆ÷Á¬½áÊ§°Ü£¬¸æËßÄãÕÒ²»µ½libg.a£¬ÄÇ¾ÍÊÇÔÚ{\ttfamily /usr/lib/}µÄÄ¿Â¼µ×ÏÂ£¬ÉÙÁË{\ttfamily libg.a}¡£libg.aÊÇÒ»¸öCÓïÑÔºÜÌØ±ðµÄÕì´í³ÌÊ½¿â¡£Ò»°ãÔÚlibcµÄÌ×¼þÄÚ¾Í»áÌá¹©libg.a£»²»È»µÄ»°£¨ÐÂ°æÊÇÕâÑùµÄ£©£¬Äã¿ÉÄÜÐèÒªÄÃlibcµÄÔ­Ê¼Âë×Ô¼ºÉèÖÃÁË£¬²»¹ý£¬Êµ¼ÊÉÏÄãÓ¦¸Ã{\itshape ²»ÐèÒª\/}²Å¶Ô¡£²»¹ÜÊÇÊ²÷áÄ¿µÄ£¬´ó²¿·ÝµÄÇé¿öÏÂ£¬Ö»Ðè½«libg.aÁ¬½áµ½{\ttfamily /usr/lib/libc.a}£¬Äã¾ÍÄÜµÃµ½×ã¹»µÄ×ÊÑ¶ÁË¡£




\paragraph{ÄÇ£¬ÄÜ²»ÄÜ°Ñ³ý´í×ÊÑ¶¸øÄÃµô£¿\label{index.63} }

ºÜ¶àµÄGNUÈíÌåÔÚ±àÒëÁ¬½áÊ±£¬¶¼»áÉè¶¨{\ttfamily -g}µÄÑ¡Ïî£»ÕâÑù×ö»áÔì³ÉÖ´ÐÐµµ¹ý´óµÄÎÊÌâ£¨Í¨³£ÊÇ¾²Ì¬µÄÁ¬½á£©¡£Êµ¼ÊÉÏ£¬Õâ²¢²»ÊÇÒ»¸öºÜÈÈÃÅµÄÏë·¨¡£

Èç¹û³ÌÊ½±¾ÉíÓÐautoconf£¬²úÉúÁË{\ttfamily configure}ÃüÁî¸å£¬Í¨³£Äã¾Í¿ÉÒÔÓÃ{\ttfamily ./configure CFLAGS=}»òÊÇ{\ttfamily ./configure CFLAGS=-O2}À´¹Øµô³ý´í×ÊÑ¶¡£²»È»µÄ»°£¬ÄãµÃ¼ì²é¼ì²éMakefileÁË¡£µ±È»À²£¬¼ÙÈçÄãÓÃµÄÊÇELF£¬³ÌÊ½±ã»áÒÔ¶¯Ì¬µÄ·½Ê½À´Á¬½á£¬²»ÂÛÊÇ·ñÓÐ{\ttfamily -g}µÄÉè¶¨£»Òò´ËÄã¿ÉÒÔÆ½³£ÐÄ°Ñ-g{\ttfamily ÄÃµô}¡£






\subsubsection{ÊµÓÃµÄÈíÌå\label{index.64} }

¾ÝÁË½â£¬´ó²¿·ÝµÄÈË¶¼ÊÇÓÃ{\bfseries gdb}À´³ý´í¡£Äã¿ÉÒÔ´Ó\nameurl{ftp://prep.ai.mit.edu/pub/gnu}{GNU archive sites}ÄÃµ½Ô­Ê¼³ÌÊ½£»»òÕßÊÇµ½\nameurl{ftp://tsx-11.mit.edu/pub/linux/packages/GCC}{tsx-11}ÄÃ¿ÉÖ´ÐÐµµ¡£{\bfseries xxgdb}ÊÇÒ»¸öX½éÃæµÄ³ý´í³ÌÊ½£¬Ö²»ùì¶gdb£¨Ò²¾ÍÊÇËµÄãµÃÏÈ°²×°ºÃgdb£¬²ÅÄÜÔÙ×°xxgdb£©¡£xxgdbµÄÔ­Ê¼Âë¿ÉÒÔÔÚ\nameurl{ftp://ftp.x.org/contrib/xxgdb-1.08.tar.gz}{}ÕÒµ½¡£

ÁíÍâ£¬{\bfseries UPS}³ý´í³ÌÊ½ÒÑÓÉRick SladkeyÒÆÖ²³É¹¦¡£UPS¿ÉÒÔÔÚXµ×ÏÂ»îµÃºÜºÃ£¬²»ÏñxxgdbÄÇÑù---½ö½öÊÇgdbµÄXÇ°¶Ë½éÃæ£¨X front end£©¡£ÕâÖ§³ý´í³ÌÊ½ÓÐÒ»´ó¶ÑÓÅÁ¼µÄÌØµã£¬¶øÇÒÈç¹ûÄãµÃ»¨Ê±¼äÈ¥³ýÒ»Ö§ÆÆÀÃµÄ³ÌÊ½£¬½¨ÒéÄã¿¼ÂÇ¿¼ÂÇxxgdb¡£ÊÂÏÈ±àÒëºÃµÄLinux°æÓëÐÞÕý°æµÄÔ­Ê¼Âë¿ÉÒÔÔÚ\nameurl{ftp://sunsite.unc.edu/pub/Linux/devel/debuggers/}{}ÕÒµ½¡£¶ø×î³õµÄÔ­Ê¼³ÌÊ½Ôò·ÅÔÚ \nameurl{ftp://ftp.x.org/contrib/ups-2.45.2.tar.Z}{}¡£

Äã¿ÉÄÜ»á·¢ÏÖÁíÒ»¸öÓÃÀ´³ý´íµÄ¹¤¾ß{\bfseries strace}£¬Ò²ÊÇÏàµ±µÄÓÐÓÃ¡£Ëü¿ÉÒÔÏÔÊ¾³öÓÉ³ÌÐòËù²úÉúµÄÏµÍ³ºô½Ð£¬¶øÇÒ»¹ÓµÓÐÆäËüÖÚ¶à·±¸´µÄ¹¦ÄÜ£¬ÏñÊÇÈç¹ûÄãÊÖ±ßÃ»ÓÐÔ­Ê¼ÂëµÄ»°£¬strace¿ÉÒÔ°ïÄãÕÒ³öÓÐÄÇÐ©Â·¾¶Ãû³Æ£¨path-names£©ÒÑ±àÒë½øÖ´ÐÐµµÄÚ£» exacerbating race conditions in programs that you suspect contain them;»¹ÓÐ£¬strace¿ÉÄÃÀ´Ñ§Ï°³ÌÊ½ÊÇÔõ÷áÔÚµçÄÔÖÐÖ´ÐÐµÄ¡£×îÐÂµÄ°æ±¾£¨Ä¿Ç°ÊÇ3.0.8£©¿ÉÔÚÕÒµ½\nameurl{ftp://ftp.std.com/pub/jrs/}{}¡£






\subsubsection{±³¾°³ÌÊ½£¨³£×¤³ÌÊ½£©}

ÔçÆÚµäÐÍµÄ³£×¤³ÌÊ½(daemon programs)ÊÇÖ´ÐÐ{\ttfamily fork()}£¬È»ááÖÕÖ¹¸¸³ÌÐò¡£ÕâÑùµÄ×ö·¨Ê¹µÃ³ý´íµÄÊ±¼ä¼õ¶ÌÁË¡£



ÁË½âÕâµãµÄ×î¼òµ¥µÄ·½·¨¾ÍÊÇÌæ{\ttfamily fork()}ÉèÒ»¸öÖÐ¶Ïµã£¨breakpoint£©¡£µ±³ÌÊ½Í£Ö¹Ê±£¬Ç¿ÆÈfork()´«»Ø0¡£

\begin{tscreen}
\begin{verbatim}
(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       }
\end{verbatim}
\end{tscreen}





\subsubsection{ºËÐÄµµ°¸}

µ±Linux¿ª»úÊ±£¬Í¨³£×éÌ¬»áÉè¶¨³É²»Òª²úÉúºËÐÄµµ°¸¡£ÒªÊÇÄãÄÇ÷áÏ²»¶ËüÃÇµÄ»°£¬¿ÉÒÔÓÃshellµÄbuiltinÃüÁîÊ¹ÆäÖØÐÂÉúÐ§£º¾ÍC-shellÏàÈÝµÄshell£¨Èçtcsh£©¶øÑÔ£¬»áÊÇÏÂÃæÕâÑù£º
\begin{tscreen}
\begin{verbatim}
% limit core unlimited
\end{verbatim}
\end{tscreen}

¶øÀàËÆBourne shellµÄshell£¨sh, bash, zsh, pdksh£©ÔòÊ¹ÓÃÏÂÃæµÄÓï·¨£º
\begin{tscreen}
\begin{verbatim}
$ ulimit -c unlimited
\end{verbatim}
\end{tscreen}


Èç¹ûÄãÏëÒªÓÐ¸ö¶à²Å¶àÒÕµÄºËÐÄµµÃüÃû£¨core file naming£©£¨for
example, if you're trying to conduct a post-mortem using a debugger that's buggy itself£©£¬ÄÇ÷áÄã¿ÉÒÔ¶ÔÄãµÄºËÐÄ³ÌÊ½×öÒ»µãÐ¡Ð¡µÄ¸ü¶¯¡£ÕÒÒ»ÕÒ{\ttfamily fs/binfmt\_aout.c}Óë{\ttfamily fs/binfmt\_elf.c}µµÖÐÓëÏÂÁÐÏà·ûµÄ³ÌÊ½Æ¬¶Î(in newer kernels, you'll have to grep around a little in older ones)£º

\begin{tscreen}
\begin{verbatim}
        memcpy(corefile,"core.",5);
#if 0
        memcpy(corefile+5,current->comm,sizeof(current->comm));
#else
        corefile[4] = '\0';
#endif
\end{verbatim}
\end{tscreen}


½«{\ttfamily 0}»»³É{\ttfamily 1}.




\subsection{¼à¹Ü}

 ¼à¹Ü£¨Profiling£©ÊÇÓÃÀ´¼ìºËÒ»Ö§³ÌÊ½ÖÐÄÇÐ©²¿·ÝÊÇ×î³£ºô½Ð»òÊÇÖ´ÐÐµÄÊ±¼ä×î¾ÃµÄ·½·¨¡£Õâ¶Ô³ÌÊ½µÄ×î¼Ñ»¯ÓëÕÒ³öºÎÊ±Ê±¼äÊÇÀË·ÑµôµÄ¶øÑÔ£¬ÊÇÏàµ±ºÃµÄ·½Ê½¡£Äã±ØÐë¾ÍÄãËùÒªµÄÊ±³Ì×ÊÑ¶£¨timing information£©µÄÄ¿µÄµµ¼ÓÉÏ{\ttfamily -p}À´±àÒë£¬¶øÇÒÈç¹ûÒªÈÃÊä³öµÄµµ°¸ÓÐÒâÒå£¬ÄãÒ²»áÐèÒª{\ttfamily gprof}£¨À´×ÔbinutilsÌ×¼þµÄÃüÁî£©¡£²ÎÔÄ{\ttfamily gprof}µÄmanual page£¬¿ÉµÃÖªÆäÏ¸½Ú¡£

11/18/97Òë






\section{Á¬½á}

ÓÉì¶¾²Ì¬Óë¹²Ïí³ÌÊ½¿âÁ½Õß¼ä²»ÏàÈÝµÄ¸ñÊ½µÄ²îÒìÐÔÓë¶¯´Ê*link*¹ýÁ¿Ê¹ÓÃì¶Ö¸³Æ*±àÒëÍê³ÉááµÄÊÂÇé*Óë*µ±±àÒëºÃµÄ³ÌÊ½Ê¹ÓÃÊ±Ëù·¢ÉúµÄÊÂÇé*ÕâÁ½¼þÊÂÉÏÍ·£¬Ê¹µÃÕâÒ»ÕÂ½Ú±äµÃ¸´ÔÓÁËÐí¶à¡££¨ and, actually, the overloading of the word `load' in a comparable but opposite sense£©²»¹ý£¬ÔÙ¸´ÔÓÒ²¾ÍÊÇÕâÑùÁË£¬ËùÒÔ¸óÏÂ²»±Ø¹ýì¶µ£ÐÄ¡£



ÎªÁËÉÔÎ¢¼õÇá¶ÁÕßµÄÀ§»ó£¬ÎÒÃÇ³ÆÖ´ÐÐÆÚ¼äËù·¢ÉúµÄÊÂÎª*¶¯Ì¬ÔØÈë*£¬ÕâÒ»Ö÷Ìâ»áÔÚÏÂÒ»ÕÂ½ÚÖÐÌ¸µ½¡£ÄãÒ²»áÔÚ±ðµÄµØ·½¿´µ½ÎÒ°Ñ¶¯Ì¬ÔØÈëÃèÊö³É*¶¯Ì¬Á¬½á*£¬²»¹ý²»»áÊÇÔÚÕâÒ»ÕÂ½ÚÖÐ¡£»»¾ä»°Ëµ£¬ÕâÒ»ÕÂ½ÚËùÌ¸µÄ£¬È«²¿ÊÇÖ¸·¢ÉúÔÚ±àÒë½áÊøááµÄÁ¬½á¡£




\subsection{¹²Ïí³ÌÊ½¿â vs¾²Ì¬³ÌÊ½¿â}

½¨Á¢³ÌÊ½µÄ×îááÒ»¸ö²½Öè±ãÊÇÁ¬½á£»Ò²¾ÍÊÇ½«ËùÓÐ·ÖÉ¢µÄÐ¡³ÌÊ½×éºÏÆðÀ´£¬¿´¿´ÊÇ·ñÒÅÂ©ÁËÐ©Ê²÷á¡£ÏÔÈ»£¬ÓÐÒ»Ð©ÊÂÇéÊÇºÜ¶à³ÌÊ½¶¼»áÏë×öµÄ---ÀýÈç£¬¿ªÆôµµ°¸£¬½ÓÖøËùÓÐÓë¿ªµµÓÐ¹ØµÄÐ¡³ÌÊ½¾Í»á½«´¢´æ³ÌÊ½¿âµÄÏà¹Øµµ°¸Ìá¹©¸øÄãµÄ³ÌÊ½Ê¹ÓÃ¡£ÔÚÒ»°ãµÄLinuxÏµÍ³ÉÏ£¬ÕâÐ©Ð¡³ÌÊ½¿ÉÒÔÔÚ{\ttfamily /lib}Óë{\ttfamily /usr/lib/}Ä¿Â¼µ×ÏÂÕÒµ½¡£

\label{index.65} 
\label{index.66} 

µ±ÄãÓÃµÄÊÇ¾²Ì¬µÄ³ÌÊ½¿âÊ±£¬Á¬½áÆ÷»áÕÒ³ö³ÌÊ½ËùÐèµÄÄ£×é£¬È»ááÊµ¼Ê½«ËüÃÇ¿½±´µ½Ö´ÐÐµµÄÚ¡£È»¶ø£¬¶Ô¹²Ïí³ÌÊ½¿â¶øÑÔ£¬¾Í²»ÊÇÕâÑùÁË¡£¹²Ïí³ÌÊ½¿â»áÔÚÖ´ÐÐµµÄÚÁôÏÂÒ»¸ö¼ÇºÅ£¬Ö¸Ã÷*µ±³ÌÊ½Ö´ÐÐÊ±£¬Ê×ÏÈ±ØÐëÔØÈëÕâ¸ö³ÌÊ½¿â*¡£ÏÔÈ»£¬¹²Ïí³ÌÊ½¿âÊÇÊÔÍ¼Ê¹Ö´ÐÐµµ±äµÃ¸üÐ¡£¬µÈÍ¬ì¶Ê¹ÓÃ¸üÉÙµÄ¼ÇÒäÌåÓë´Åµú¿Õ¼ä¡£LinuxÄÚ¶¨µÄÐÐÎªÊÇÁ¬½á¹²Ïí³ÌÊ½¿â£¬Ö»ÒªLinuxÄÜÕÒµ½ÕâÐ©¹²Ïí³ÌÊ½¿âµÄ»°£¬¾ÍÃ»Ê²÷áÎÊÌâ£»²»È»,Linux¾Í»áÁ¬½á¾²Ì¬µÄÁË¡£Èç¹ûÄãÏëÒª¹²Ïí³ÌÊ½¿âµÄ»°£¬¼ì²éÕâÐ©³ÌÊ½¿â£¨{\ttfamily *.sa} for a.out, {\ttfamily *.so} for ELF£©ÊÇ·ñ×¡ÔÚËüÃÇ¸ÃÔÚµÄµØ·½£¬¶øÇÒÊÇ¿É¶ÁÈ¡µÄ¡£

ÔÚLinuxÉÏ£¬¾²Ì¬³ÌÊ½¿â»áÓÐÀàËÆ{\ttfamily libname.a}ÕâÑùµÄÃû³Æ£»¶ø¹²Ïí³ÌÊ½¿âÔò³ÆÎª{\ttfamily libname.so.x.y.z}£¬´Ë´¦µÄ{\ttfamily x.y.z}ÊÇÖ¸°æ±¾ÐòºÅµÄÑùÊ½¡£¹²Ïí³ÌÊ½¿âÍ¨³£¶¼»áÓÐÁ¬½á·ûºÅÖ¸Ïò¾²Ì¬³ÌÊ½¿â£¨ºÜÖØÒªµÄ£©ÓëÏà¹ØÁªµÄ{\ttfamily .sa}µµ°¸¡£±ê×¼µÄ³ÌÊ½¿â»á°üº¬¹²ÏíÓë¾²Ì¬³ÌÊ½¿âÁ½ÖÖ¸ñÊ½¡£

Äã¿ÉÒÔÓÃ{\ttfamily ldd}£¨List Dynamic Dependencies£©À´²é³öÄ³Ö§³ÌÊ½ÐèÒªÄÄÐ©¹²Ïí³ÌÊ½¿â¡£
\begin{tscreen}
\begin{verbatim}
$ ldd /usr/bin/lynx
        libncurses.so.1 => /usr/lib/libncurses.so.1.9.6
        libc.so.5 => /lib/libc.so.5.2.18
\end{verbatim}
\end{tscreen}


ÕâÊÇËµÔÚÎÒµÄÏµÍ³ÉÏ£¬WWWä¯ÀÀÆ÷*lynx*»áÒÀÀµ{\ttfamily libc.so.5} (the C library)Óë{\ttfamily libncurses.so.1}£¨ÖÕ¶Ë»úÓ©Ä»µÄ¿ØÖÆ£©µÄ´æÔÚ¡£ÈôÄ³Ö§³ÌÊ½È±·¦¶ÀÁ¢ÐÔ£¬ {\ttfamily ldd}¾Í»áËµ¡®{\ttfamily statically linked}¡¯»òÊÇ¡®{\ttfamily statically linked (ELF)}¡¯¡£




\subsection{ÖÕ¼«ÉóÅÐ£¨¡®{\ttfamily sin()} ÔÚÄÄ¸ö³ÌÊ½¿âÀï£¿¡¯£©\label{index.67} 
\label{index.68} 
\label{index.69} }

{\ttfamily nm }{\itshape ³ÌÊ½¿âÃû³Æ\/}Ó¦¸Ã»áÁÐ³ö´Ë{\itshape ³ÌÊ½¿âÃû³Æ\/}Ëù²Î¿¼µ½µÄËùÓÐ·ûºÅ¡£Õâ¸öÖ¸Áî¿ÉÒÔÓ¦ÓÃÔÚ¾²Ì¬Óë¹²Ïí³ÌÊ½¿âÉÏ¡£¼ÙÉèÄãÏëÖªµÀ{\ttfamily tcgetattr()}ÊÇÔÚÄÄ¶ù¶¨ÒåµÄ£ºÄã¿ÉÒÔÈç´Ë×ö£¬

\begin{tscreen}
\begin{verbatim}
$ nm libncurses.so.1 |grep tcget
         U tcgetattr
\end{verbatim}
\end{tscreen}


*{\ttfamily U}*Ö¸³ö*Î´¶¨Òå*---Ò²¾ÍÊÇËµncurses³ÌÊ½¿âÓÐÓÃµ½tegetattr()£¬µ«ÊÇ²¢Ã»ÓÐ¶¨ÒåËü¡£ÄãÒ²¿ÉÒÔÕâÑù×ö£¬

\begin{tscreen}
\begin{verbatim}
$ nm libc.so.5 | grep tcget
00010fe8 T __tcgetattr
00010fe8 W tcgetattr
00068718 T tcgetpgrp
\end{verbatim}
\end{tscreen}


*{\ttfamily W}*ËµÃ÷ÁË*ÈõÌ¬(weak)*£¬ÒâÖ¸·ûºÅËäÒÑ¶¨Òå£¬µ«¿ÉÓÉ²»Í¬³ÌÊ½¿âÖÐµÄÁíÒ»¶¨ÒåËùÌæ´ú¡£×î¼òµ¥µÄ*Õý³£*¶¨Òå£¨ÏñÊÇ{\ttfamily tcgetpgrp}£©ÊÇÓÉ*{\ttfamily T}*Ëù±êÊ¾£º

\label{index.70} 

±êÌâËùÌ¸µÄÎÊÌâ£¬×î¼òÃ÷µÄ´ð°¸±ãÊÇ{\ttfamily libm.(so$|$a)}ÁË¡£ËùÓÐ¶¨ÒåÔÚ{\ttfamily $<$math.h$>$}µÄº¯Êý¶¼±£ÁôÔÚmaths³ÌÊ½¿âÄÚ£»Òò´Ë£¬µ±ÄãÓÃµ½ÆäÖÐÈÎºÎÒ»¸öº¯ÊýÊ±£¬¶¼ÐèÒªÒÔ{\ttfamily -lm}µÄ²ÎÊýÁ¬½á´Ë³ÌÊ½¿â¡£






\subsection{Xµµ°¸£¿}

{\ttfamily ld: Output file requires shared library `libfoo.so.1`}



 ldÓëÆäÏàÀàËÆµÄÃüÁîÔÚËÑÑ°µµ°¸µÄ²ßÂÔÉÏ£¬»áÒÀ¾Ý°æ±¾µÄ²îÒì¶øÓÐËù²»Í¬£¬µ«ÊÇÎ¨Ò»Ò»¸öÄã¿ÉÒÔºÏÀí¼ÙÉèµÄÄÚ¶¨Ä¿Â¼±ãÊÇ{\ttfamily /usr/lib}ÁË¡£Èç¹ûÄãÏ£ÍûÉí´¦Ëü´¦µÄ³ÌÊ½¿âÒ²ÁÐÈëËÑÑ°µÄÐÐÁÐÖÐ£¬ÄÇ÷áÄã¾Í±ØÐëÒÔ{\ttfamily -L}Ñ¡Ïî¸æÖªgcc»òÊÇld¡£



ÒªÊÇÄã·¢ÏÖÒ»µãÐ§¹ûÒ²Ã»ÓÐ£¬¾Í¸Ï½ô²ì¿´¿´ÄÇµµ°¸ÊÇ²»ÊÇ»¹¹Ô¹ÔµÄÌÉÔÚÔ­µØ¡£¾Ía.out¶øÑÔ£¬ÒÔ{\ttfamily -lfoo}²ÎÊýÀ´Á¬½á£¬»áÇýÊ¹ldÈ¥Ñ°ÕÒ{\ttfamily libfoo.sa}£¨shared stubs£©£»Èç¹ûÃ»ÓÐ³É¹¦£¬¾Í»á»»³ÉÑ°ÕÒ{\ttfamily libfoo.a}£¨static£©¡£¾ÍELF¶øÑÔ£¬ ld»áÏÈÕÒ{\ttfamily libfoo.so}£¬È»ááÊÇ{\ttfamily libfoo.a}¡£{\ttfamily libfoo.so}Í¨³£ÊÇÒ»¸öÁ¬½á·ûºÅ£¬Á¬½áÖÁ{\ttfamily libfoo.so.x}¡£






\subsection{½¨Á¢Äã×Ô¼ºµÄ³ÌÊ½¿â}


\subsubsection{¿ØÖÆ°æ±¾}

ÓëÆäËüÈÎºÎµÄ³ÌÊ½Ò»Ñù£¬³ÌÊ½¿âÒ²ÓÐÐÞÕý²»ÍêµÄbugsµÄÎÊÌâ´æÔÚ¡£ËüÃÇÒ²¿ÉÄÜ²úÉú³öÒ»Ð©ÐÂµÄÌØµã£¬¸ü¸ÄÄ¿Ç°´æÔÚµÄÄ£×éµÄ¹¦Ð§£¬»òÊÇ½«¾ÉµÄÒÆ³ýµô¡£Õâ¶ÔÕýÔÚÊ¹ÓÃËüÃÇµÄ³ÌÊ½¶øÑÔ£¬¿ÉÄÜ»áÊÇÒ»¸ö´óÎÊÌâ¡£Èç¹ûÓÐÒ»Ö§³ÌÊ½ÊÇ¸ù¾ÝÄÇÐ©¾ÉµÄÌØµãÀ´Ö´ÐÐµÄ»°£¬ÄÇÔõ÷á°ì£¿

ËùÒÔ£¬ÎÒÃÇÒý½øÁË³ÌÊ½¿â°æ±¾±àºÅµÄ¹ÛÄî¡£ÎÒÃÇ½«³ÌÊ½¿â*´ÎÒª*Óë*Ö÷Òª*µÄ±ä¸ü·ÖÃÅ±ðÀà£¬Í¬Ê±¹æ¶¨*´ÎÒª*µÄ±ä¸üÊÇ²»ÔÊÐíÓÃµ½Õâ³ÌÊ½¿âµÄ¾É³ÌÊ½·¢ÉúÖÐ¶ÏµÄÏÖÏó¡£Äã¿ÉÒÔ´Ó³ÌÊ½¿âµÄµµÃû·Ö±æ³öËüµÄ°æ±¾£¨Êµ¼ÊÉÏ£¬ÑÏ¸ñÀ´½²£¬¶ÔELF¶øÑÔ½ö½öÊÇÒ»³¡Ìì´óµÄ»ÑÑÔ£»¼ÌÐø¶Á½«ÏÂÈ¥£¬±ã¿ÉÃ÷°×ÎªÊ²÷áÁË£©£º {\ttfamily libfoo.so.1.2}µÄÖ÷Òª°æ±¾ÊÇ1£¬´ÎÒª°æ±¾ÊÇ2¡£´ÎÒª°æ±¾µÄ±àºÅ¿ÉÄÜÕæÓÐÆäÊÂ£¬Ò²¿ÉÄÜÊ²÷á¶¼Ã»ÓÐ---libcÔÚÕâÒ»µãÉÏÓÃÁË*ÐÞÕý³Ì¶È*µÄ¹ÛÄî£¬¶ø¶©³öÁËÏñ{\ttfamily libc.so.5.2.18}ÕâÑùµÄ³ÌÊ½¿âÃû³Æ¡£´ÎÒª°æ±¾µÄ±àºÅÄÚÈôÊÇ·ÅÒ»Ð©×ÖÄ¸¡¢µ×Ïß¡¢»òÊÇÈÎºÎ¿ÉÒÔÁÐÓ¡µÄASCII×ÖÔª£¬Ò²ÊÇºÜºÏÀíµÄ¡£

ELFÓëa.out¸ñÊ½×îÖ÷ÒªµÄ²î±ðÖ®Ò»¾ÍÊÇÔÚÉèÖÃ¹²Ïí³ÌÊ½¿âÕâ¼þÊÂÉÏ£»ÎÒÃÇÏÈ¿´ELF£¬ÒòÎªËü±È½Ï¼òµ¥Ò»Ð©¡£




\subsubsection{ELF£¿Ëüµ½µ×ÊÇÊ²÷á¶«¶«¨Ë¨ß£¿\label{index.71} }

 ELF£¨Executable and Linking Format£©×î³õÊÇÓÉUSL£¨UNIX System 
Laboratories£©·¢Õ¹¶ø³ÉµÄ¶þ½øÎ»¸ñÊ½£¬Ä¿Ç°ÕýÓ¦ÓÃì¶SolarisÓëSystem V Release 4ÉÏ¡£ÓÉì¶ELFËùÔöÕÇµÄµ¯ÐÔÔ¶Ô¶³¬¹ýLinux¹ýÈ¥ËùÓÃµÄa.out¸ñÊ½£¬Òò´ËGCCÓëC³ÌÊ½¿âµÄ·¢Õ¹ÈËÊ¿ì¶1995Äê¾ö¶¨¸ÄÓÃELFÎªLinux±ê×¼µÄ¶þ½øÎ»¸ñÊ½¡£




\paragraph{Ôõ÷áÓÖÀ´ÁË£¿}

 ÕâÒ»½ÚÊÇÀ´×Ôì¶¡®/news-archives/comp.sys.sun.misc¡¯µÄÎÄ¼þ¡£

\begin{quotation}
ELF£¨¡°Executable Linking Format¡±£©ÊÇì¶SVR4ËùÒý½øµÄÐÂÊ½¸ÄÁ¼Ä¿µÄµµ¸ñÊ½¡£ELF±ÈÆðCOFF¿ÉÊÇ¶à³öÁË²»ÉÙµÄ¹¦ÄÜ¡£ÒÔELF¶øÑÔ£¬Ëü*ÊÇ*¿ÉÓÉÊ¹ÓÃÕß×ÔÐÐÑÓÉìµÄ¡£ELFÊÓÒ»Ä¿µÄµµÎª½ÚÇø£¨sections£©£¬Èç´®ÁÐ°ãµÄ×éºÏ£»¶øÇÒ´Ë´®ÁÐ¿ÉÎªÈÎÒâµÄ³¤¶È£¨¶ø²»ÊÇÒ»¹Ì¶¨´óÐ¡µÄÕóÁÐ£©¡£ÕâÐ©½ÚÇøÓëCOFFµÄ²»Ò»Ñù£¬²¢²»ÐèÒª¹Ì¶¨ÔÚÄ³¸öµØ·½£¬Ò²²»ÐèÒªÒÔÄ³ÖÖË³ÐòÅÅÁÐ¡£Èç¹ûÊ¹ÓÃÕßÏ£Íû²¹×½µ½ÐÂµÄ×ÊÁÏ£¬±ã¿ÉÒÔ¼ÓÈëÐÂµÄ½ÚÇøµ½Ä¿µÄµµÄÚ¡£ELFÒ²ÓÐÒ»¸ö¸üÇ¿¶øÓÐÁ¦µÄ³ý´í·¨Ê½£¬³ÆÎªDWARF£¨Debugging With Attribute Record Format£©¡õÄ¿Ç°Linux²¢²»ÍêÈ«Ö§Ô®¡£DWARF DIEs£¨Debugging Information Entries£©µÄÁ¬½á´®ÁÐ»áÔÚELFÄÚÐÎ³É .debugµÄ½ÚÇø¡£DWARF DIEsµÄÃ¿Ò»¸ö .debug½ÚÇø²¢·ÇÒ»Ð©ÉÙÁ¿ÇÒ¹Ì¶¨´óÐ¡µÄ×ÊÑ¶¼ÇÂ¼µÄ¼¯ºÏ£¬¶øÊÇÒ»ÈÎÒâ³¤¶ÈµÄ´®ÁÐ£¬ÓµÓÐ¸´ÔÓµÄÊôÐÔ£¬¶øÇÒ³ÌÊ½µÄ×ÊÁÏ»áÒÔÓÐ¡õÎ§ÏÞÖÆµÄÊ÷×´×ÊÁÏ½á¹¹Ð´³öÀ´¡£DIEsËùÄÜ²¹×½µ½µÄ´óÁ¿×ÊÑ¶ÊÇCOFFµÄ .debug½ÚÇøÎÞ·¨ÍûÆäÏî±³µÄ¡££¨ÏñÊÇC++µÄ¼Ì³ÐÍ¼¡££©
\end{quotation}


\begin{quotation}
ELFµµ°¸ÊÇ´ÓSVR4£¨Solaris 2.0 £¿£©ELF´æÈ¡³ÌÊ½¿â£¨ELF access library£©ÄÚ´æÈ¡µÄ¡£´Ë³ÌÊ½¿â¿ÉÌá¹©Ò»¼ò±ã¿ìËÙµÄ½éÃæÓèELF¡£Ê¹ÓÃELF´æÈ¡³ÌÊ½¿â×îÖ÷ÒªµÄ¶÷»ÝÖ®Ò»±ãÊÇ£¬Äã²»ÔÙÐèÒªÈ¥²ì¿´Ò»¸öELFµµµÄquaÁË¡£¾ÍUNIXµÄµµ°¸¶øÑÔ£¬ËüÊÇÒÔElf*µÄÐÍÊ½À´´æÈ¡£»ºô½Ðelf\_open()Ö®áá£¬´Ó´ËÊ±¿ªÊ¼£¬ÄãÖ»Ðèºô½Ðelf\_foobar()À´´¦Àíµµ°¸µÄÄ³Ò»²¿·Ý¼´¿É£¬²¢²»ÐèÒª°Ñµµ°¸Êµ¼ÊÔÚ´ÅµúÉÏµÄimage¸ãµÃÒ»ÍÅÂÒ¡£
\end{quotation}


ELFµÄÓÅÈ±µãÓëÉý¼¶ÖÁELFµÈ¼¶ËùÐè¾­ÀúµÄÖÖÖÖÍ´¿à£¬ÒÑÔÚELF-HOWTOÄÚÂÛ¼°£»ÎÒ²¢²»´òËãÔÚÕâ¶ùÍ¿½¬ºý¡£ELF HOWTOÓ¦¸ÃÓëÕâ·ÝÎÄ¼þÓÐÍ¬ÑùµÄÖ÷Ìâ²ÅÊÇ¡£




\paragraph{ELF¹²Ïí³ÌÊ½¿â}

ÈôÏëÈÃ{\ttfamily libfoo.so}³ÉÎª¹²Ïí³ÌÊ½¿â£¬»ù±¾µÄ²½Öè»áÏñÏÂÃæÕâÑù£º

\begin{tscreen}
\begin{verbatim}
$ 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
\end{verbatim}
\end{tscreen}


Õâ»á²úÉúÒ»¸öÃûÎª{\ttfamily libfoo.so.1.0}µÄ¹²Ïí³ÌÊ½¿â£¬ÒÔ¼°¸øÓèldÊÊµ±µÄÁ¬½á£¨{\ttfamily libfoo.so}£©»¹ÓÐÊ¹µÃ¶¯Ì¬ÔØÈë³ÌÊ½£¨dynamic loader£©ÄÜÕÒµ½Ëü£¨{\ttfamily libfoo.so.1}£©¡£ÎªÁË½øÐÐ²âÊÔ£¬ÎÒÃÇ½«Ä¿Ç°µÄÄ¿Â¼¼Óµ½{\ttfamily LD\_LIBRARY\_PATH}Àï¡£

\label{index.72} 

µ±Äã½ò½òÀÖµÀì¶³ÌÊ½¿âÖÆ×ö³É¹¦Ö®Ê±£¬±ðÍüÁË°ÑËüÒÆµ½Èç{\ttfamily /usr/local/lib}µÄÄ¿Â¼µ×ÏÂ£¬²¢ÇÒÖØÐÂÉè¶¨ÕýÈ·µÄÁ¬½áÂ·¾¶¡£{\ttfamily libfoo.so.1}Óë{\ttfamily libfoo.so.1.0}µÄÁ¬½á»áÓÉ{\ttfamily ldconfig}ÒÀÈÕÆÚ²»¶ÏµÄ¸üÐÂ£¬¾Í´ó²¿·ÝµÄÏµÍ³À´Ëµ£¬ldconfig»áÔÚ¿ª»ú¹ý³ÌÖÐÖ´ÐÐ¡£{\ttfamily libfoo.so}µÄÁ¬½á±ØÐëÓÉÊÖ¶¯·½Ê½¸üÐÂ¡£Èç¹ûÄã¶Ô³ÌÊ½¿âËùÓÐ×é³É·Ý×Ó£¨Èç±êÍ·µµµÈ£©µÄÉý¼¶£¬×ÜÊÇ±§³ÖÖøÒ»Ë¿²»¡õµÄÌ¬¶È£¬ÄÇ÷á×î¼òµ¥µÄ·½·¨¾ÍÊÇÈÃ{\ttfamily libfoo.so -{$>$} libfoo.so.1}£»Èç´ËÒ»À´£¬ldconfig±ã»áÌæÄãÍ¬Ê±±£Áô×îÐÂµÄÁ¬½á¡£ÒªÊÇÄãÃ»ÓÐÕâ÷á×ö£¬Äã×ÔÐÐÉè¶¨µÄ¶«¶«¾Í»áÔÚÊýÈÕááÔì³É{\itshape Ç§Ææ°Ù¹ÖµÄÎÊÌâ\/}³öÏÖ¡£µ½Ê±ºò£¬¿É±ðËµÎÒÃ»ÌáÐÑÄã°¡£¡

\begin{tscreen}
\begin{verbatim}
$ su
# cp libfoo.so.1.0 /usr/local/lib
# /sbin/ldconfig
# ( cd /usr/local/lib ; ln -s libfoo.so.1 libfoo.so )
\end{verbatim}
\end{tscreen}





\paragraph{°æ±¾±àºÅ¡¢sonameÓë·ûºÅÁ¬½á\label{index.73} 
\label{index.74} }

Ã¿Ò»¸ö³ÌÊ½¿â¶¼ÓÐÒ»¸ö{\itshape soname\/}¡£µ±Á¬½áÆ÷·¢ÏÖËüÕýÔÚËÑÑ°µÄ³ÌÊ½¿âÖÐÓÐÕâÑùµÄÒ»¸öÃû³Æ£¬Á¬½áÆ÷±ã»á½«sonameóéÈëÁ¬½áÖÐµÄ¶þ½øÎ»µµÄÚ£¬¶ø²»ÊÇËüÕýÔÚÔË×÷µÄÊµ¼ÊµÄµµÃû¡£ÔÚ³ÌÊ½Ö´ÐÐÆÚ¼ä£¬¶¯Ì¬ÔØÈë³ÌÊ½»áËÑÑ°ÓµÓÐsonameÕâÑùµÄµµÃûµÄµµ°¸£¬¶ø²»ÊÇ³ÌÊ½¿âµÄµµÃû¡£Òò´Ë£¬Ò»¸öÃûÎª{\ttfamily libfoo.so}µÄ³ÌÊ½¿â£¬¾Í¿ÉÒÔÓÐÒ»¸ö{\ttfamily libbar.so}µÄsonameÁË¡£¶øÇÒËùÓÐÁ¬½áµ½{\ttfamily libbar.so}µÄ³ÌÊ½£¬µ±³ÌÊ½¿ªÊ¼Ö´ÐÐÊ±£¬»áÑ°ÕÒµÄ±ãÊÇ{\ttfamily libbar.so}ÁË¡£



ÕâÌýÆðÀ´ºÃÏñÒ»µãÒâÒåÒ²Ã»ÓÐ£¬µ«ÊÇÕâÒ»µã£¬¶Ôì¶ÁË½âÊý¸ö²»Í¬°æ±¾µÄÍ¬Ò»¸ö³ÌÊ½¿âÊÇÈçºÎÔÚµ¥Ò»ÏµÍ³ÉÏ¹²´æµÄÔ­Òò£¬È´ÊÇ¹Ø¼üÖ®Ô¿¡£Linux³ÌÊ½¿â±ê×¼µÄÃüÃû·½Ê½£¬±ÈÈçËµÊÇ{\ttfamily libfoo.so.1.2}£¬¶øÇÒ¸øÕâ¸ö³ÌÊ½¿âÒ»¸ö{\ttfamily libfoo.so.1}µÄsoname¡£Èç¹û´Ë³ÌÊ½¿âÊÇ¼Óµ½±ê×¼³ÌÊ½¿âµÄÄ¿Â¼µ×ÏÂ£¨e.g. {\ttfamily /usr/lib}£©£¬{\ttfamily ldconfig}»á½¨Á¢·ûºÅÁ¬½á{\ttfamily libfoo.so.1 -{$>$} libfoo.so.1.2}£¬Ê¹ÆäÕýÈ·µÄimageÄÜì¶Ö´ÐÐÆÚ¼äÕÒµ½¡£ÄãÒ²ÐèÒªÁ¬½á{\ttfamily libfoo.so -{$>$} libfoo.so.1}£¬Ê¹ldÄÜì¶Á¬½áÆÚ¼äÕÒµ½ÕýÈ·µÄsoname¡£

ËùÒÔÂÞ£¬µ±ÄãÐÞÕý³ÌÊ½¿âÄÚµÄbugs£¬»òÊÇÌí¼ÓÁËÐÂµÄº¯Êý½øÈ¥£¨ÈÎºÎ²»»á¶ÔÏÖ´æµÄ³ÌÊ½Ôì³É²»ÀûµÄÓ°ÏìµÄ¸Ä±ä£©£¬Äã»áÖØ½¨´Ë³ÌÊ½¿â£¬±£ÁôÔ­±¾ÒÑÓÐµÄsoname£¬È»áá¸ü¸Ä³ÌÊ½¿âµµÃû¡£µ±Äã¶Ô³ÌÊ½¿âµÄ±ä¸ü»áÊ¹µÃÏÖÓÐµÄ³ÌÊ½ÖÐ¶Ï£¬ÄÇ÷áÄãÖ»ÐèÔö¼ÓsonameÖÐµÄ±àºÅ---´ËÀýÖÐ£¬³ÆÐÂ°æ±¾Îª{\ttfamily libfoo.so.2.0}£¬¶øsoname±ä³É{\ttfamily libfoo.so.2}¡£½ô½ÓÖø£¬ÔÙ½«{\ttfamily libfoo.so}µÄÁ¬½á×ªÏòÐÂµÄ°æ±¾£»ÖÁ´Ë£¬ÊÀ½çÓÖÔÙ¶È»Ö¸´ÁËºÍÆ½£¡

ÆäÊµÄã{\itshape ²»ÐëÒª\/}ÒÔ´ËÖÖ·½Ê½À´Ìæ³ÌÊ½¿âÃüÃû£¬²»¹ýÕâµÄÈ·ÊÇ¸öºÃµÄ´«Í³¡£ELF¸³ÓèÄãÔÚ³ÌÊ½¿âÃüÃûÉÏµÄµ¯ÐÔ£¬»áÊ¹µÃÈËÆø´­ºôºôµÄ¸ã²»Çå³þ×´¿ö£»ÓÐÕâÑùµÄµ¯ÐÔÔÚ£¬Ò²²¢²»±íÊ¾Äã¾ÍµÃÈ¥ÓÃËü¡£



ELF×Ü½á£º¼ÙÉè¾­ÓÉÄãî£ÖÇµÄ¹Û²ì·¢ÏÖÓÐ¸ö¹ßÀýËµ£º³ÌÊ½¿âÖ÷ÒªµÄÉý¼¶»áÆÆ»µÏàÈÝÐÔ£»¶ø´ÎÒªµÄÉý¼¶Ôò¿ÉÄÜ²»»á£»ÄÇ÷áÒÔÏÂÃæµÄ·½Ê½À´Á¬½á£¬ËùÓÐµÄÒ»ÇÐ¾Í¶¼»áÏà°²ÎÞÊÂÁË¡£

\begin{tscreen}
\begin{verbatim}
gcc -shared -Wl,-soname,libfoo.so.major -o libfoo.so.major.minor
\end{verbatim}
\end{tscreen}





\subsubsection{a.out---¾É¾ÉµÄ¸ñÊ½¡õ}

½¨Á¢¹²Ïí³ÌÊ½¿âµÄ±ãÀûÐÔÊÇÉý¼¶ÖÁELFµÄÖ÷ÒªÔ­ÒòÖ®Ò»¡£ÄÇÒ²ÊÇËµ,a.out¿ÉÄÜ»¹ÊÇÓÐÓÃ´¦ÔÚµÄ¡£ÉÏftpÕ¾È¥×¥\nameurl{ftp://tsx-11.mit.edu/pub/linux/packages/GCC/src/tools-2.17.tar.gz}{}£»½âÑ¹ËõááÄã»á·¢ÏÖÓÐ20Ò³µÄÎÄ¼þ¿ÉÒÔÂýÂýµÄ¶ÁÁ¨¡£ÎÒºÜ²»Ï²»¶×Ô¼ºµ³ÅÉµÄÆ«¼û±íÏÖµÃÄÇ÷áµÄÁÜÁ§¾¡ÖÂ£¬¿ÉÊÇ´ÓÉÏÏÂÎÄ¼ä£¬Ó¦¸ÃÒ²¿ÉÒÔºÜÇå³þµÄÐá³öÎÒ´ÓÀ´²»ÄÃÊ¯Í·ÔÒ×Ô¼ºµÄ½ÅµÄÆ¢Æø°É£¡:-)




\paragraph{ZMAGIC vs QMAGIC
\label{index.75} 
\label{index.76} }

QMAGICÊÇÒ»ÖÖÀàËÆ¾É¸ñÊ½µÄa.out£¨Òà³ÆÎªZMAGIC£©µÄ¿ÉÖ´ÐÐµµ
¸ñÊ½£¬ÕâÖÖ¸ñÊ½»áÊ¹µÃµÚÒ»¸ö·ÖÒ³ÎÞ·¨map¡£µ±0-4096µÄ¡õÎ§ÄÚÃ»ÓÐmapping´æÔÚÊ±£¬Ôò¿ÉÔÊÐíNULL dereference trapping¸ü¼ÓµÄÈÝÒ×¡£Ëù²úÉúµÄ±ß½çÐ§Ó¦ÊÇÄãµÄÖ´ÐÐµµ»á±È½ÏÐ¡£¨´óÔ¼ÉÙ1K×óÓÒ£©¡£

Ö»ÓÐ¼´½«×÷·ÏµÄÁ¬½áÆ÷ÓÐÖ§Ô®ZMAGIC£¬Ò»°ëÒÑÂñÈë¹×²ÄµÄÁ¬½áÆ÷ÓÐÖ§Ô®ÕâÁ½ÖÖ¸ñÊ½£»¶øÄ¿Ç°µÄ°æ±¾½öÖ§Ô®QMAGIC¶øÒÑ¡£ÊÂÊµÉÏ£¬Õâ²¢Ã»ÓÐ¶à´óµÄÓ°Ïì£¬ÄÇÊÇÒòÎªÄ¿Ç°µÄºËÐÄÁ½ÖÖ¸ñÊ½¶¼ÄÜÖ´ÐÐ¡£

*file*ÃüÁîÓ¦¸Ã¿ÉÒÔÈ·ÈÏ³ÌÊ½ÊÇ²»ÊÇQMAGICµÄ¸ñÊ½µÄ¡£




\paragraph{µµ°¸ÅäÖÃ}

Ò»a.out(DLL)µÄ¹²Ïí³ÌÊ½¿â°üº¬Á½¸öÕæÊµµÄµµ°¸ÓëÒ»¸öÁ¬½á·ûºÅ¡£¾Í*foo*Õâ¸öÓÃì¶Õû·ÝÎÄ¼þ×öÎª¡õÀýµÄ³ÌÊ½¿â¶øÑÔ£¬ÕâÐ©µµ°¸»áÊÇ{\ttfamily libfoo.sa}Óë{\ttfamily libfoo.so.1.2}£»Á¬½á·ûºÅ»áÊÇ{\ttfamily libfoo.so.1}£¬¶øÇÒ»áÖ¸Ïò{\ttfamily libfoo.so.1.2}¡£ÕâÐ©ÊÇ×öÊ²÷áÓÃµÄ£¿

ÔÚ±àÒëÊ±£¬{\ttfamily ld}»áÑ°ÕÒ{\ttfamily libfoo.sa}¡£ÕâÊÇ³ÌÊ½¿âµÄ*stub*µµ°¸¡£¶øÇÒº¬ÓÐËùÓÐÖ´ÐÐÆÚ¼äÁ¬½áËùÐèµÄexportedµÄ×ÊÁÏÓëÖ¸Ïòº¯ÊýµÄÖ¸±ê¡£

Ö´ÐÐÆÚ¼ä£¬¶¯Ì¬ÔØÈë³ÌÊ½»áÑ°ÕÒ{\ttfamily libfoo.so.1}¡£Õâ½ö½öÊÇÒ»¸ö·ûºÅÁ¬½á£¬¶ø²»ÊÇÕæÊµµÄµµ°¸¡£¹Ê³ÌÊ½¿â¿É¸üÐÂ³É½ÏÐÂµÄÇÒÒÑÐÞÕý´íÎóµÄ°æ±¾£¬¶ø²»»áËð»ÙÈÎºÎ´ËÊ±ÕýÔÚÊ¹ÓÃ´Ë³ÌÊ½¿âµÄÓ¦ÓÃ³ÌÊ½¡£ÔÚÐÂ°æ---±ÈÈçËµ{\ttfamily libfoo.so.1.3}---ÒÑÍêÕû³ÊÏÖÊ±£¬ldconfig»áÒÔÒ»¼«Î¢Ð¡µÄ²Ù×÷£¬½«Á¬½áÖ¸ÏòÐÂµÄ°æ±¾£¬Ê¹µÃÈÎºÎÔ­±¾Ê¹ÓÃ¾É°æµÄ³ÌÊ½²»»á¸Ðµ½Ë¿ºÁµÄ²»ÔÃ¡£

DLL³ÌÊ½¿â£¨ÎÒÖªµÀÕâÊÇÎÞÎ½µÄ·´¸²---ËùÒÔ¶ÔÎÒÌá³öËßËÏ°É£¡£©Í¨³£»á±ÈËüÃÇµÄ¾²Ì¬¸±±¾ÒªÀ´µÃ´ó¶à¡£ËüÃÇÊÇÒÔ*¶´£¨holes£©*µÄÐÎÊ½À´±£Áô¿Õ¼äÒÔ±ãÈÕááµÄÀ©³ä¡£ÕâÖÖ*¶´*¿ÉÒÔ²»Õ¼ÓÃÈÎºÎµÄ´Åµú¿Õ¼ä¡£Ò»¸ö¼òµ¥µÄ{\ttfamily cp}ºô½Ð£¬»òÊÇÊ¹ÓÃ{\ttfamily makehole}³ÌÊ½£¬¾Í¿ÉÒÔ´ïµ½ÕâÑùÐ§¹û¡£ÒòÎªËüÃÇµÄÎ»Ö·ÊÇ¹Ì¶¨ÔÚÍ¬Ò»Î»ÖÃÉÏ£¬ËùÒÔÔÚ½¨Á¢³ÌÊ½¿âáá£¬Äã¿ÉÒÔ°ÑËüÃÇÄÃµô¡£²»¹ý£¬{\bfseries Ç§Íò²»ÒªÊÔÖøÄÃµôELFµÄ³ÌÊ½¿â}¡£




\paragraph{``libc-lite''?}

libc-liteÊÇÇáÁ¿¼¶µÄlibc°æ±¾¡£¿ÉÓÃÀ´´æ·ÅÔÚ´ÅµúÆ¬ÉÏ£¬Ò²¿ÉÒÔÌæ´ó²¿·ÝµÍÎ¢µÄUNIXÈÎÎñÊÕÎ²¡£ËüÃ»ÓÐ°üº¬curses, dbm, termcapµÈµÈµÄ³ÌÊ½Âë¡£Èç¹ûÄãµÄ{\ttfamily /lib/libc.so.4}ÊÇÁ¬½áµ½Ò»¸öliteµÄlibc£¬ÄÇ÷á½¨ÒéÄãÒÔÍêÕûµÄ°æ±¾È¡´úËü¡£




\subsubsection{Á¬½á£º³£¼ûµÄÎÊÌâ}

°ÑÄãÁ¬½áÊ±ËùÔâÓöµÄÎÊÌâ¼Ä¸øÎÒ£¡ÎÒ¿ÉÄÜÊ²÷áÊÂÒ²²»»á×ö£¬µ«ÊÇÖ»ÒªÀÛ»ýÁË×ã¹»µÄÊýÁ¿£¬ÎÒ»á°ÑËüÃÇÐ´ÆðÀ´*¡£

\begin{description}


\item[ÄãÏë¹²Ïí£¬Æ«Æ«³ÌÊ½È´Á¬½á³É¾²Ì¬µÄ£¡] \mbox{}

\label{index.77} 
\label{index.78} 

¼ì²éÄãÌá¹©¸ø{\ttfamily ld}µÄÁ¬½áÊÇ·ñÕýÈ·£¬Ê¹ldÄÜÕÒµ½Ã¿Ò»¸ö¶ÔÓ¦µÄ¹²Ïí³ÌÊ½¿â£¬¾ÍELF¶øÑÔ£¬ÕâÊÇÖ¸Ò»¸ö·ûºÅÁ¬½á{\ttfamily libfoo.so}£¬Á¬½áÖÁimage£»¾Ía.out¶øÑÔ£¬¾ÍÊÇ{\ttfamily libfoo.sa}µµÁË¡£ºÜ¶àÈË½«ELF binutils 2.5Éý¼¶ÖÁ2.6Ö®áá£¬¾Í²úÉúÁËÕâ¸öÎÊÌâ---ÔçÆÚµÄ°æ±¾ËÑÑ°¹²Ïí³ÌÊ½¿âÊ±½ÏÓÐÖÇ»Û£¬ËùÒÔ²¢Ã»ÓÐ½«ËùÓÐµÄÁ¬½á½¨Á¢ÆðÀ´¡£ááÀ´£¬ÎªÁËÓëÆäËüµÄ¼Ü¹¹ÏàÈÝ£¬ÕâÏî³äÂúÖÇ»ÛµÄÐÐÎª±»ÈË¸øÉ¾³ýµôÁË£¬ÁíÍâ£¬ÕâÑùµÄ*ÖÇ»Û*ÅÐ¶Ï´íÎóµÄ»úÂÊÏàµ±¸ß£¬ËùÔì³ÉµÄÂé·³±ÈËüËù½â¾öµÄÎÊÌâ»¹¶à£¬ËùÒÔÁôÖøÒ²ÊÇº¦ÈË¾«£»²»Èç¹éÈ¥Ùâ£¡



\item[DLLµÄ¹¤¾ß³ÌÊ½¡®mkimage¡¯ÕÒ²»µ½libgcc£¿ ] \mbox{}

\label{index.79} 

×Ô{\ttfamily libc.so.4.5.x}Ö®áá£¬libgccÒÑ²»ÔÙÊÇ¹²ÏíµÄ¸ñÊ½¡£Òò´Ë£¬Äã±ØÐëÔÚ*{\ttfamily -lgcc}*³öÏÖÖ®´¦ÒÔ{\ttfamily `gcc -print-libgcc-file-name`}Ìæ´ú£¨ÍêÕûµÄµ¹µ¥ÒýºÅ£¨back-quotes£©£©¡£ÁíÍâ£¬É¾³ýËùÓÐ{\ttfamily /usr/lib/libgcc*}µÄµµ°¸¡£ÕâµãºÜÖØÒªÁ¨¡£



\item[ {\ttfamily \_\_NEEDS\_SHRLIB\_libc\_4 multiply defined} messages ] \mbox{}

ÊÇÍ¬ÑùµÄÎÊÌâËùÔì³ÉµÄÁíÒ»ÖÖ½á¹û¡£



\item[ ``Assertion failure'' message when rebuilding a DLL ?] \mbox{}

ÕâÒ»ÌõÉñÃØµÄÑ¶Ï¢×îÓÐ¿ÉÄÜµÄÔ­ÒòÊÇ£¬ÔÚÔ­Ê¼µÄ{\ttfamily jump.vars}µµ°¸ÄÚ£¬ÓÉì¶±£ÁôµÄ¿Õ¼äÌ«ÉÙ£¬ÒÔÖÂì¶Ôì³ÉÆäÖÐÒ»¸öjump table slotsÒçÂú¡£Äã¿ÉÒÔÖ´ÐÐ¹¤¾ß³ÌÊ½¡õÓÉ2.17.tar.gzÌ×¼þËùÌá¹©µÄ¡®{\ttfamily getsize}¡¯ÃüÁî£¬¶¨³öËùÓÐÏÓÒÉ·¸µÄ×Ù¼£¡£¿ÉÄÜÎ¨Ò»µÄ½â¾ö·½·¨ÊÇ£¬½â³ý´Ë³ÌÊ½¿âÖ÷ÒªµÄ°æ±¾±àºÅ£¬Ç¿ÆÈËü»Øµ½²»ÏàÈÝµÄÄê´ú¡£



\item[ {\ttfamily ld: output file needs shared library libc.so.4} ] \mbox{}

Í¨³£ÕâÊÇ·¢ÉúÔÚµ±ÄãÁ¬½áµÄ³ÌÊ½¿â²»ÊÇlibc£¨ÈçX³ÌÊ½¿â£©£¬¶øÇÒÔÚÃüÁîÁÐÓÃÁË{\ttfamily -g}µÄ²ÎÊý£¬È´Ã»ÓÐÒ»²¢Ê¹ÓÃ{\ttfamily -static}£¬Ëù·¢³öµÄ´íÎóÑ¶Ï¢¡£

¹²Ïí³ÌÊ½¿âµÄ{\ttfamily .sa} stubsÍ¨³£ÓÐÒ»¸öÎ´¶¨ÒåµÄ·ûºÅ{\ttfamily \_NEEDS\_SHRLIB\_libc\_4}£»ÕâÒ»µã¿É½åÓÉ{\ttfamily libc.sa} stubÀ´½â¾ö£¬È»¶ø£¬ÒÔ{\ttfamily -g}À´±àÒëÊ±£¬»áÊ¹µÃÁ¬½áÒÔ{\ttfamily libg.a}»ò{\ttfamily libc.a}À´½áÊø£»Òò´ËÕâ¸ö·ûºÅÒ»Ö±¾ÍÃ»ÓÐ½â¾ö£¬Ò²¾Í»áµ¼ÖÂÉÏÃæµÄ´íÎóÑ¶Ï¢ÁË¡£

×ÜÖ®£¬ÒÔ{\ttfamily -g}µÄÆìºÅ±àÒëÊ±±ðÍüÁË¼ÓÉÏ{\ttfamily -static}£¬²»È»¾Í±ðÓÃ{\ttfamily -g}À´Á¬½á¡£Í¨³££¬ÒÔ{\ttfamily -g}±àÒë¸÷¸ö¶ÀÁ¢µÄµµ°¸Ê±£¬Ëù»ñµÃµÄ³ý´í×ÊÑ¶ÒÑ¾­×ã¹»£¬Á¬½áÊ±¾Í¿ÉÒÔ{\itshape ²»ÐèÒª\/}ËüÁË¡£



\end{description}







\section{¶¯Ì¬ÔØÈë}

{\itshape ÕâÒ»ÕÂ½ÚÄ¿Ç°ÊÇ¼ò¶ÌÁËÒ»µã£»µ±ÎÒÂÓ¾¡ELF HOWTOÊ±£¬¾ÍÊÇÕâ²¿·ÝÔÙ¶ÈÀ©Õ¹µÄÊ±ºòÁË¡£\/}




\subsection{»ù±¾¸ÅÄî}

 LinuxÓÐ¹²Ïí³ÌÊ½¿â£¬Èç¹ûÖ®Ç°ÄãÒÑ×øÖø¶ÁÍêÉÏÒ»ÕÂ½Ú£¬Ïë±ØÏÖÔÚÒ»Ìýµ½ÏñÕâÑùµÄËµ´Ê£¬±ã»áÁ¢¿Ì¸Ðµ½Í·»è¡£ÓÐÒ»Ð©ÕÕ¹ßÀý¶øÑÔÊÇÔÚÁ¬½áÊ±ÆÚ±ã¸ÃÍê³ÉµÄ¹¤×÷£¬±ØÐëÑÓ³Ùµ½ÔØÈëÊ±ÆÚ²ÅÄÜÍê³É¡£


\subsection{´íÎóÑ¶Ï¢}

°ÑÄãÁ¬½áµÄ´íÎó¼Ä¸øÎÒ£¡ÎÒ²»»á×öÈÎºÎµÄÊÂ£¬²»¹ýÎÒ¿ÉÒÔ°ÑËüÃÇÐ´ÆðÀ´**

\begin{description}


\item[ {\ttfamily can't load library: /lib/libxxx.so, Incompatible version}] \mbox{}

£¨a. out only£© ÕâÊÇÖ¸ÄãÃ»ÓÐxxx³ÌÊ½¿âµÄÕýÈ·µÄÖ÷Òª°æ±¾¡£¿É±ðÒÔÎªËæËæ
±ã±ãÅª¸öÁ¬½áµ½ÄãÄ¿Ç°ÓµÓÐµÄ°æ±¾¾Í¿ÉÒÔÁË£¬Èç¹ûÐÒÔËµÄ»°£¬¾ÍÖ»»áÔì³ÉÄãµÄ³ÌÊ½·ÖÒ³´íÎó¶øÒÑ¡£È¥×¥ÐÂµÄ°æ±¾.ELFÀàËÆµÄÇé¿ö»áÔì³ÉÏñÏÂÃæÕâÑùµÄÑ¶Ï¢£º

\begin{tscreen}
\begin{verbatim}
ftp: can't load library 'libreadline.so.2'
\end{verbatim}
\end{tscreen}




\item[{\ttfamily warning using incompatible library version xxx}] \mbox{}

£¨a. out only£©ÄãµÄ³ÌÊ½¿âµÄ´ÎÒª°æ±¾±ÈÆðÕâÖ§³ÌÊ½ÓÃÀ´±àÒëµÄ»¹Òª¾É¡£³ÌÊ½ÒÀÈ»¿ÉÒÔÖ´ÐÐ¡£Ö»ÊÇ¿ÉÄÜÀ²£¡ÎÒÏë£¬Éý¸ö¼¶Ó¦¸ÃÃ»Ê²÷áÉËº¦°É£¡



\end{description}





\subsection{¿ØÖÆ¶¯Ì¬ÔØÈëÆ÷µÄÔË×÷\label{index.80} 
\label{index.81} }

ÓÐÒ»×é»·¾³±äÊý»áÈÃ¶¯Ì¬ÔØÈëÆ÷ÓÐËù·´Ó¦¡£´ó²¿·ÝµÄ»·¾³±äÊý¶Ô{\ttfamily ldd}µÄÓÃÍ¾Òª±ÈÆð¶ÔÒ»°ãusersµÄ»¹ÒªÀ´µÃ¸ü¶à¡£¶øÇÒ¿ÉÒÔºÜ·½±ãµÄÉè¶¨³ÉÓÉlddÅäºÏ¸÷ÖÖ²ÎÊýÀ´Ö´ÐÐ¡£ÕâÐ©±äÊý°üÀ¨£¬

\begin{itemize}
\item {\ttfamily LD\_BIND\_NOW} --- Õý³£À´½²£¬º¯ÊýÔÚºô½ÐÖ®Ç°ÊÇ²»»áÈÃ³ÌÊ½Ñ°ÕÒµÄ¡£Éè¶¨Õâ¸öÆìºÅ»áÊ¹µÃ³ÌÊ½¿âÒ»ÔØÈë£¬ËùÓÐµÄÑ°ÕÒ±ã»á·¢Éú£¬Í¬Ê±Ò²Ôì³ÉÆðÊ¼µÄÊ±¼ä½ÏÂý¡£µ±ÄãÏë²âÊÔ³ÌÊ½£¬È·¶¨ËùÓÐµÄÁ¬½á¶¼Ã»ÓÐÎÊÌâÊ±£¬ÕâÏîÆìºÅ¾Í±äµÃºÜÓÐÓÃ¡£
\item {\ttfamily LD\_PRELOAD}¿ÉÒÔÉè¶¨Ò»¸öµµ°¸£¬Ê¹Æä¾ßÓÐ*¸²¸Ç*º¯Êý¶¨ÒåµÄÄÜÁ¦¡£ÀýÈç£¬Èç¹ûÄãÒª²âÊÔ¼ÇÒäÌå·ÖÅäµÄ·½ÂÔ£¬¶øÇÒ»¹ÏëÖÃ»»*malloc*£¬ÄÇ÷áÄã¿ÉÒÔÐ´ºÃ×¼±¸Ìæ»»µÄ¸±³ÌÊ½£¬²¢°ÑËü±àÒë³É{\ttfamily mallolc.}£¬È»áá£º

\begin{tscreen}
\begin{verbatim}
$ LD_PRELOAD=malloc.o; export LD_PRELOAD
$ some_test_program
\end{verbatim}
\end{tscreen}


{\ttfamily LD\_ELF\_PRELOAD} Óë {\ttfamily LD\_AOUT\_PRELOAD} ºÜÀàËÆ£¬µ«ÊÇ½öÊÊÓÃì¶ÕýÈ·µÄ¶þ½øÎ»ÐÍÌ¬¡£Èç¹ûÉè¶¨ÁË
{\ttfamily LD\_}{\itshape something\/}{\ttfamily \_PRELOAD} Óë {\ttfamily LD\_PRELOAD} £¬±È½ÏÃ÷È·µÄÄÇÒ»¸ö»á±»ÓÃµ½¡£
\item  {\ttfamily LD\_LIBRARY\_PATH}ÊÇÒ»Á¬´®ÒÔ·ÖºÅ¸ôÀëµÄÄ¿Â¼Ãû³Æ£¬ÓÃÀ´ËÑÑ°¹²Ïí³ÌÊ½¿â¡£¶Ôld¶øÑÔ£¬²¢{\itshape Ã»ÓÐ\/}ÈÎºÎµÄÓ°Ïì£»ÕâÏîÖ»ÓÐÔÚÖ´ÐÐÆÚ¼ä²ÅÓÐÓ°Ïì¡£ÁíÍâ£¬¶ÔÖ´ÐÐsetuidÓësetgidµÄ³ÌÊ½¶øÑÔ£¬ÕâÒ»ÏîÊÇÎÞÐ§µÄ¡£¶ø{\ttfamily LD\_ELF\_LIBRARY\_PATH}Óë{\ttfamily LD\_AOUT\_LIBRARY\_PATH}ÕâÁ½ÖÖÆìºÅ¿É¸ù¾Ý¸÷±ðµÄ¶þ½øÎ»ÐÍÊ½·Ö±ðµ¼Ïò²»Í¬µÄËÑÑ°Â·¾¶¡£Ò»°ãÕý³£µÄÔË×÷ÏÂ£¬²»Ó¦¸Ã»áÓÃµ½{\ttfamily LD\_LIBRARY\_PATH}£»°ÑÐèÒªËÑÑ°µÄÄ¿Â¼¼Óµ½{\ttfamily /etc/ld.so.conf/}Àï£»È»ááÖØÐÂÖ´ÐÐldconfig¡£
\item  {\ttfamily LD\_NOWARN} ½öÊÊÓÃì¶a.out¡£Ò»µ©Éè¶¨ÁËÕâÒ»Ïî£¨{\ttfamily LD\_NOWARN=true; export LD\_NOWARN}£©£¬Ëü»á¸æËßÔØÈëÆ÷±ØÐë´¦Àífatal-warnings£¨ÏñÊÇ´ÎÒª°æ±¾²»ÏàÈÝµÈ£©µÄ¾¯¸æÑ¶Ï¢¡£
\item {\ttfamily LD\_WARN}½öÊÊÓÃì¶ELF¡£Éè¶¨ÕâÒ»ÏîÊ±£¬Ëü»á½«Í¨³£ÊÇÖÂÃüÑ¶Ï¢µÄ¡°Can*t find library¡±×ª»»³É¾¯¸æÑ¶Ï¢¡£¶ÔÕý³£µÄ²Ù×÷¶øÑÔ£¬Õâ²¢Ã»ÓÐ¶à´óµÄÓÃ´¦£¬¿ÉÊÇ¶Ôldd¾ÍºÜÖØÒªÁË¡£
\item {\ttfamily LD\_TRACE\_LOADED\_OBJECTS}½öÊÊÓÃì¶ELF¡£¶øÇÒ»áÊ¹µÃ³ÌÊ½ÒÔÎªËüÃÇÊÇÓÉ{\ttfamily ldd}ËùÖ´ÐÐµÄ£º

\begin{tscreen}
\begin{verbatim}
$ 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
\end{verbatim}
\end{tscreen}

\end{itemize}





\subsection{ÒÔ¶¯Ì¬ÔØÈë×«Ð´³ÌÊ½\label{index.82} 
\label{index.83} }

Èç¹ûÄãºÜÊìÏ¤Solaris 2.xËùÖ§Ô®µÄ¶¯Ì¬ÔØÈëµÄ¹¤×÷µÄ»°£¬Äã»á·¢ÏÖLinuxÔÚÕâµãÉÏÓëÆä·Ç³£µÄÏà½ü¡£ÕâÒ»²¿·ÝÔÚH.J.LuµÄELF³ÌÊ½Éè¼ÆÎÄ¼þÄÚÓë{\ttfamily dlopen(3)}µÄmanual page£¨¿ÉÒÔÔÚld.soµÄÌ×¼þÉÏÕÒµ½£©ÉÏÓÐ¹ã·ºµÄÌÖÂÛ¡£ÕâÀïÓÐ¸ö²»´íµÄ¼òµ¥¡õÀý£ºÒÔ{\ttfamily -ldl}Á¬½á¡£

\begin{tscreen}
\begin{verbatim}
#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");
  }

}
\end{verbatim}
\end{tscreen}







\section{Óë·¢Õ¹ÈËÊ¿ÁªÂç}


\subsection{Bug±¨±í\label{index.84} }

 {\bfseries °ÑÎÊÌâÐ´ÏÂÀ´}¡£ÕâÊÇÕë¶ÔLinuxµÄ£¬Òà»òÊÇgccÔÚÆäËüÏµÍ³ÉÏËù·¢ÉúµÄÎÊÌâ¡£ÓëkernelµÄ°æ±¾Ïà¹ØÂð£¿»òÕßÊÇ³ÌÊ½¿âµÄ°æ±¾£¿Èç¹û¸ÄÓÃ¾²Ì¬·½Ê½Á¬½á£¬ÎÊÌâÊÇ²»ÊÇ¾ÍÏûÊ§ÁË£¿Äã¿ÉÒÔ½ÚÂ¼Ò»{\bfseries Ð¡}¶Î³ÌÊ½À´Õ¹Ê¾ÕâÖ»bugÂð£¿

µ±Äã×öÁËÕâÐ©ÊÂÇéÖ®áá£¬Äã½«»áÖªµÀ³ÌÊ½ÄÚµÄbugsÊÇÊ²÷á¡£¾Ígcc¶øÑÔ£¬bug±¨±í³ÌÐòÊÇÒÔinfoµµÀ´ËµÃ÷µÄ¡£Èç¹ûÊÇld.so»òÊÇC¡¢maths³ÌÊ½¿â£¬½«email¼Äµ½{\ttfamily linux-gcc@vger.rutgers.edu}¡£Èç¹û¿ÉÄÜµÄ»°£¬°üº¬Ò»Ö§×Ô¼º×Ô×ãµÄÐ¡³ÌÊ½ÒÔÕ¹Ê¾Õâ¸öbug£¬¶øÇÒ¸½ÉÏËµÃ÷£¬ÃèÊöÄãÏëÒªÈÃÕâÖ§³ÌÊ½×öÐ©Ê²÷áÓëÊµ¼ÊÉÏËüÓÖ×öÁËÐ©Ê²÷á¡£




\subsection{Ð­Öú·¢Õ¹}

Èç¹ûÄãÏëÒª°ïÃ¦·¢Õ¹gcc»òÊÇC³ÌÊ½¿â£¬µÚÒ»¼þÊÂ¾ÍÊÇ¼ÓÈë{\ttfamily linux-gcc@vger.rutgers.edu}Í¨ÐÅÂÛÌ³¡£Èç¹ûÄãÖ»ÊÇÏë¿´¿´Í¨ÐÅÂÛÌ³ÔÚÌÖÂÛÐ©Ê²÷á£¬ÕâÀïÓÐÒ»¸öÂÛÌ³µÄarchives£¬Î»ì¶\nameurl{http://homer.ncm.com/linux-gcc/}{}¡£½ÓÏÂÀ´µÄÊÂ£¬¾Í¿´ÄãÏë×öÊ²÷áÁË¡£








\section{½áÓï}


\subsection{ÃûÈË°ñ}

\begin{quotation}
 
Only presidents, editors, and people with tapeworms have the right to
use the editorial ``we''.
\end{quotation}

(Mark Twain)



Õâ·ÝHOWTOÎÄ¼þ¼¸ºõÍêÈ«¸ùÖ²ì¶Mitchum DsouzaµÄGCC-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£¬Ã»ÓÐÁËËû£¬ÕâÕû¸öÔË¶¯¾Í±äµÃÒ»µãÒâÒåÒ²Ã»ÓÐÁË£¬ËùÒÔ²»¿ÉÄÜÈÃËû¹Âµ¥µÄ¡£:-)

Çë²»Òª¾õµÃÓÐÈÎºÎµÄÃ°·¸Ö®´¦£¬Èç¹ûÄúµÄÃû×ÖÃ»ÓÐ³öÏÖÔÚÕâ¶ù¡£Èç¹ûÄú¶ÔÕâ·ÝÎÄ¼þ£¨HOWTO»òÊÇFAQ£©Ôø¾­ÓÐ¹ý¹±Ï×µÄ»°£¬Çëemail¸øÎÒ£¬ÎÒ»á¸ÄÕý¹ýÀ´µÄ¡£






\subsection{·­Òë}

µ½Ä¿Ç°ÎªÖ¹£¬Õâ·ÝÎÄ¼þ»¹Ã»ÓÐÒÑÖªµÄ·­Òë°æ±¾³öÏÖ¡£Èç¹ûÄãÏ£ÍûÉúÒ»¸ö³öÀ´£¬Çë¾¡¹ÜÈ¥×ö£¬²»¹ýÒ»¶¨µÃ¸æËßÎÒÏà¹ØµÄÊÂÒË¡£ÎÒ½²µÄÓïÑÔ»áÊÇÄãÏëÒª·­µÄÓïÑÔ£¬ÄÇ»úÂÊ£¨ºÜÒÅº¶£©Ö»ÓÐºÃ¼¸°Ù·ÖÖ®Ò»£¬²»¹ý»¹ÊÇÏÈ°Ñ±¯ÉË°ÚÒ»ÅÔ°É£¬²»¹ÜÊÇÊ²÷áÑùÎÊÌâ£¬ÎÒ¶¼»áºÜÀÖÒâ°ïÃ¦µÄ¡£




\subsection{»¶Ó­ÈÎºÎµÄ»ØÀ¡}

¼ÄÐÅ¸øÎÒ\onlynameurl{dan@detached.demon.co.uk}¡£ÎÒµÄPGP public key (ID 5F263625) 
¿ÉÔÚÎÒµÄºæÅà¼¦\nameurl{http://ftp.linux.org.uk/~barlow/}{web pages}ÉÏÊ¹ÓÃ£¬Èç¹ûÄã¾õµÃÊÂÇéÓÐ±ØÒª±£ÃÜµÄ»°¡£




\subsection{ºÏ·¨µÄÐÐåÉ¹æ¶¨}

±¾ÎÄ²ÉÓÃ¹ýµÄÉÌ±ê·ÖÊôì¶¸ö±ðµÄ³ÖÓÐÕß¡£

Õâ·ÝHOWTOÎÄ¼þµÄ°æÈ¨Êôì¶Daniel Barlow {\ttfamily $<$dan@detached.demon.co.uk$>$}¡£
Äã¿ÉÒÔÈÎºÎÐÍÊ½µÄÃ½Ìå£¬°üÀ¨ÓÐÐÎµÄ¡¢µç×ÓµÄ·½Ê½ÖØ¸´Éú²ú¡¢´«²¼²¿·Ý»òÊÇÕû·ÝµÄGCC-HOWTO£¬Ö»ÒªÕâ·Ý°æÈ¨ÉùÃ÷±£´æÔÚËùÓÐµÄ¸´ÖÆÆ·ÖÐ¡£ÉÌÒµµÄ½»Ò×ÊÇÔÊÐíµÄ£¬¶øÇÒÎÒ¹ÄÀøÄãÕâ÷á×ö£¬²»¹ý£¬ÎÒºÜÏ£ÍûÄãÄÜÍ¨ÖªÎÒÓÐ¹ØµÄÏ¸½Ú¡£

²»ÂÛÄã×öÊ²÷á£¬ÏñÊÇ·­Òë¡¢À©³äÕâ·ÝÎÄ¼þ¡¢´ÓÕâ·ÝÎÄ¼þÑÜÉú³öÆäËûÏà¹ØµÄÎÄ¼þ»òÊÇÕûºÏÆäËûµÄLinux HOWTOÎÄ¼þµÈ£¬¶¼±ØÐë×ñÑ­Õâ·Ý°æÈ¨ÉùÃ÷¡£Ò²¾ÍÊÇËµ£¬Èç¹ûÄã²Î×ÃHOWTOÎÄ¼þÐ´³öÆäËûµÄËµÃ÷ÎÄ¼þ£¬ÄãÊÇ²»¿ÉÒÔ¶ÔÕâ·ÝÑÜÉú³öÀ´µÄÎÄ¼þ¼ÓÉÏ¶îÍâµÄÏÞÖÆ£¬Ó°ÏìÎÄ¼þµÄ·¢ÐÐÈ¨µÄ¡£µ±È»£¬ÓÐÐ©ÌØ±ðµÄÇé¿öÊÇ¿ÉÒÔÀýÍâµÄ£¬¹Øì¶Õâµã£¬ÇëÓëLinuxµÄÐ­µ÷ÈËÁ¬Âç£¬µç×ÓÓÊ¼þÐÅÏäµÄµØÖ·¾ÍÔÚááÍ·¡£

×Ü¶øÑÔÖ®£¬ÎÒÃÇÏ£ÍûËùÓÐµÄHOWTOÎÄ¼þÄÜ¹»Í¸¹ý¸÷ÖÖ²»Í¬µÄ¹ÜµÀ¾¡¿ÉÄÜµÄ´«²¥³öÈ¥£¬È»¶ø£¬Í¬ÑùÒ²¾ø¶ÔÏ£ÍûÕâ·Ý°æÈ¨ÉùÃ÷¿ÉÒÔ´æÁôÔÚÎÄ¼þÀïÍ·£¬ÆäËûÈÎºÎ·¢ÐÐHOWTOsÎÄ¼þµÄ¼Æ»­£¬ÎÒÃÇ¶¼ºÜÔ¸Òâ½Óµ½ÄãµÄÍ¨Öª¡£

Èç¹ûÓÐÈÎºÎÎÊÌâ£¬ÇëÓëLinux HOWTOµÄÐ­µ÷ÈËTim BynumÁ¬Ïµ£¬email addressÊÇ{\ttfamily 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
{\ttfamily $<$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 {\ttfamily linux-howto@sunsite.unc.edu} via email.

6/3/98ÔöÐÞ




\section{Ë÷Òý}

¿ªÍ·Èç¹û²»ÊÇÎÄÊý×ÖµÄ×ÖÔª£¬ÅÅÁÐ¾Í°´ÕÕASCIIÂëµÄË³Ðò¡£

\begin{itemize}
\item  {\ttfamily -fwritable-strings} \ref{index.39} {(39)} \ref{index.56} {(56)} 
\item  /lib/cpp \ref{index.16} {(16)} 
\item  a.out \ref{index.1} {(1)} 
\item  {\ttfamily ar} \ref{index.10} {(10)} 
\item  {\ttfamily as} \ref{index.8} {(8)} 
\item  $<$asm/*.h$>$ \ref{index.19} {(19)} 
\item  {\ttfamily atoi()} \ref{index.40} {(40)} 
\item  {\ttfamily atol()} \ref{index.41} {(41)} 
\item  binaries too big \ref{index.63} {(63)} \ref{index.65} {(65)} \ref{index.77} {(77)} 
\item  chewing gum \ref{index.3} {(3)} 
\item  {\ttfamily cos()} \ref{index.68} {(68)} 
\item  debugging \ref{index.59} {(59)} 
\item  {\ttfamily dlopen()} \ref{index.82} {(82)} 
\item  {\ttfamily dlsym()} \ref{index.83} {(83)} 
\item  documentation \ref{index.4} {(4)} 
\item  EINTR \ref{index.52} {(52)} 
\item  elf \ref{index.0} {(0)} \ref{index.71} {(71)} 
\item  {\ttfamily execl()} \ref{index.57} {(57)} 
\item  {\ttfamily fcntl} \ref{index.47} {(47)} 
\item  {\ttfamily FD\_CLR} \ref{index.44} {(44)} 
\item  {\ttfamily FD\_ISSET} \ref{index.45} {(45)} 
\item  {\ttfamily FD\_SET} \ref{index.43} {(43)} 
\item  {\ttfamily FD\_ZERO} \ref{index.46} {(46)} 
\item  {\ttfamily file} \ref{index.2} {(2)} 
\item  $<$float.h$>$ \ref{index.20} {(20)} 
\item  gcc \ref{index.6} {(6)} 
\item  {\ttfamily gcc -fomit-frame-pointer} \ref{index.61} {(61)} 
\item  {\ttfamily gcc -g} \ref{index.60} {(60)} 
\item  gcc -v \ref{index.14} {(14)} 
\item  gcc, bugs \ref{index.15} {(15)} \ref{index.28} {(28)} \ref{index.29} {(29)} \ref{index.84} {(84)} 
\item  gcc, flags \ref{index.13} {(13)} \ref{index.25} {(25)} \ref{index.26} {(26)} 
\item  gdb \ref{index.64} {(64)} 
\item  header files \ref{index.17} {(17)} 
\item  interrupted system calls \ref{index.51} {(51)} 
\item  {\ttfamily ld} \ref{index.9} {(9)} 
\item  {\ttfamily LD\_*} environment variables \ref{index.80} {(80)} 
\item  ldd \ref{index.81} {(81)} 
\item  libc \ref{index.7} {(7)} 
\item  {\ttfamily libg.a} \ref{index.62} {(62)} 
\item  libgcc \ref{index.79} {(79)} 
\item  $<$limits.h$>$ \ref{index.21} {(21)} 
\item  lint \ref{index.58} {(58)} 
\item  $<$linux/*.h$>$ \ref{index.18} {(18)} 
\item  manual pages \ref{index.5} {(5)} 
\item  {\ttfamily $<$math.h$>$} \ref{index.70} {(70)} 
\item  maths \ref{index.69} {(69)} 
\item  {\ttfamily mktemp()} \ref{index.55} {(55)} 
\item  optimisation \ref{index.27} {(27)} 
\item  QMAGIC \ref{index.76} {(76)} 
\item  segmentation fault \ref{index.30} {(30)} \ref{index.54} {(54)} 
\item  segmentation fault, in GCC \ref{index.33} {(33)} 
\item  select() \ref{index.50} {(50)} 
\item  {\ttfamily SIGBUS} \ref{index.34} {(34)} 
\item  {\ttfamily SIGEMT} \ref{index.35} {(35)} 
\item  {\ttfamily SIGIOT} \ref{index.36} {(36)} 
\item  SIGSEGV \ref{index.31} {(31)} \ref{index.53} {(53)} 
\item  SIGSEGV, in gcc \ref{index.32} {(32)} 
\item  {\ttfamily SIGSYS} \ref{index.38} {(38)} 
\item  {\ttfamily SIGTRAP} \ref{index.37} {(37)} 
\item  {\ttfamily sin()} \ref{index.67} {(67)} 
\item  soname \ref{index.73} {(73)} 
\item  {\ttfamily sprintf()} \ref{index.42} {(42)} 
\item  statically linked binaries, unexpected \ref{index.66} {(66)} \ref{index.78} {(78)} 
\item  $<$stdarg.h$>$ \ref{index.23} {(23)} 
\item  $<$stddef.h$>$ \ref{index.24} {(24)} 
\item  {\ttfamily strings} \ref{index.11} {(11)} 
\item  {\ttfamily $<$sys/time.h$>$} \ref{index.48} {(48)} 
\item  {\ttfamily $<$unistd.h$>$} \ref{index.49} {(49)} 
\item  $<$varargs.h$>$ \ref{index.22} {(22)} 
\item  version numbers \ref{index.12} {(12)} \ref{index.74} {(74)} 
\item  weird things \ref{index.72} {(72)} 
\item  ZMAGIC \ref{index.75} {(75)} 
\end{itemize}




\end{document}
