home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / FAQ / GCC_FAQ < prev    next >
Encoding:
Text File  |  1996-09-02  |  72.9 KB  |  1,863 lines

  1. -------Linux GCC FAQ 11th March 1995 (with preliminary ELF additions)-------
  2.  
  3. 0) Where can I get the latest version of this FAQ ?
  4. 1) How do I tell what version of GCC I am using ?
  5. 2) Where is the latest distribution of GCC, as, ld, ar,  etc.. ?
  6. 3) Where can I find the newest shared libraries libc.so and libm.so ?
  7. 4) What other shared libraries are available for Linux ?
  8. 5) How do I build a shared DLL library for Linux ?
  9. 6) Why do I get the message "PLT__oct__FUii" when I execute a certain binary ?
  10. 7) How do I build a cross compiler on platform XXX to produce code for Linux ?
  11. 8) What symbols are automatically defined by Linux's GCC ?
  12. 9) How do I get over BSD'isms (especially signals, sigvec etc..) when compiling code ?
  13. 10) Where are SIGBUS, SIGEMT, SIGIOT, SIGTRAP, SIGSYS  etc ?
  14. 11) What is libhard and libsoft ?
  15. 12) What does the message "can't load library: /lib/libxxx.so, Incompatible version" mean ?
  16. 13) Why are my binaries so huge and how do I reduce them ?
  17. 14) What does the -N flag do, and when should I use it ?
  18. 15) How do I get debugging information into a program ?
  19. 16) What debuggers are available for Linux ?
  20. 17) How do I debug a daemon program ?
  21. 18) What is profiling and how do I profile a program ?
  22. 19) Is there a way to tell if a binary is linked  statically or to a shared library ?
  23. 20) Does Linux have support for LD_LIBRARY_PATH ?
  24. 21) My program wants /lib/cpp ! Where can I get it from ?
  25. 22) Where are <float.h>, <limits.h>, <varargs.h>, <stdarg.h> and <stddef.h> ?
  26. 23) My program wants to include <linux/foo.h> but cannot find it, where is it ?
  27. 24) Do we have the function foo() in our libraries ?
  28. 25) How do I port program XXX to Linux ?
  29. 26) I think I have found a bug in gcc/library foo, what do I do now ?
  30. 27) Why are shared libraries so large in comparison to their static counterparts ?
  31. 28) What are .sa file I see in /usr/lib ?
  32. 29) Where can I get Objective C for Linux ?
  33. 30) What does the message "Internal compiler error: cc1 got fatal signal 11,4" mean ?
  34. 31) What is a libc-lite ?
  35. 32) Do Linux libraries have SHADOW Password support, and how do I switch it on/off ?
  36. 33) Can't find math.h routines ! My program compiles but cannot find log(), sin(), etc.., HELP !!
  37. 34) Is there a manual for GCC? If so, where do I get it, and how do I print it out ?
  38. 35) I get the message "Undefined symbol _bsd_ioctl". Where is this anyhow ?
  39. 36) If I upgrade versions, can I get rid of the old stuff from /usr/lib/gcc-lib/i[34]86-linux/<old-version> ?
  40. 37) [HELP] where is libipc.a ? Needed for dosemu 0.49..
  41. 38) XXX won't compile: _daemon undefined, help !!
  42. 39) [HELP] ar and libraries. Linking fails although symbol appears in library.
  43. 40) HELP! newbie gets warning message "libc.so.4: incompat. minor ver no."
  44. 41) Where can I find `lint' to check my c programs before compilation ?
  45. 42) My program needs sgtty.h where is it ?
  46. 43) How do I stop or start core files being produced by SIGSEGV's ?
  47. 44) What does the message "can't load dynamic linker `/lib/ld.so'" mean ?
  48. 45) What is the difference between -O2 and -O6 optimizations ?
  49. 46) How can I check an unknown binary to see if it is a trojan horse ?
  50. 47) Where are the sources to the C library - how do I rebuild it ?
  51. 48) Where are the definitions of FD_* stuff ?
  52. 49) When linking with option -g I get undefined ___fpu_control and ___setfpucw ?
  53. 50) Where can I get the tools to internationalize my library/application ?
  54. 51) The DLL tool `mkimage' fails to find libgcc. Help!!!
  55. 52) How do I get rid of "__NEEDS_SHRLIB_libc_4 multiply defined" messages ?
  56. 53) What is this QMAGIC thing everyone is talking about ?
  57. 54) How do I generate a QMAGIC executable/library ?
  58. 55) Is it possible to turn the "warning using incompatible library version xxx" messages off ?
  59. 56) Are GNU's glibc 1.08 texinfo manual pages relevant to Linux's libc?
  60. 57) Can I sell my application if it was compiled within linux ??
  61. 58) Why do I get an "Assertion failure" message when rebuilding a DLL ??
  62. 59) Can I build DOS executables under linux ?
  63. 60) Is -fpic - i.e PIC (position independent code) supported on linux. ?
  64. 61) What is this ELF thing anyway ?
  65. 62) How do I build an ELF libc ?
  66. 63) Why does the execl() call fail on linux and just print out libc.so.4 messages ?
  67. 64) Can I preload objects with a.out binaries (a.la Sun LD_PRELOAD) ?
  68. 65) With the new gcc I cannot seem to generate ZMAGIC binaries ?
  69. 66) perl-5.00 needs dlopen() and friends. Where are they anyway ?
  70. 67) Where can I get more info about ELF ?
  71.  
  72. ==============================================================================
  73.  
  74. 0) Where can I get the latest version of this FAQ ?
  75.  
  76. Ans:    The latest versions are posted to comp.os.linux.announce periodically,
  77.     and archived at most popular Linux sites, e.g.
  78.  
  79.         sunsite.unc.edu:/pub/Linux/docs/faqs
  80.  
  81.     Other GCC, C, C++, g++, Objective-C, FAQ's may be found at
  82.  
  83.         rtfm.mit.edu:pub/usenet/news.answers
  84.  
  85. -------------------------------------------------------------------------------
  86.  
  87. 1) How do I tell what version of GCC I am using ?
  88.  
  89. Ans:    Execute the command
  90.         gcc -v
  91.     to find out what version you are using. At the time of writing the
  92.     above command produces on my machine
  93.         Reading specs from /usr/lib/gcc-lib/i386-linux/2.6.2/specs
  94.         gcc version 2.6.2
  95.     You would be well advised to upgrade to a version similar to this or
  96.     above.
  97.  
  98.     P.S. If you get the output
  99.         Reading specs from /usr/lib/gcc-lib/i486-linux/2.6.2/specs
  100.         gcc version 2.6.2
  101.     you are running a gcc compiled for a 486.
  102.  
  103. -------------------------------------------------------------------------------
  104.  
  105. 2) Where is the latest distribution of GCC, as, ld, ar,  etc.. ?
  106.  
  107. Ans:    The Official place for GCC distributions is tsx-11.mit.edu in
  108.     /pub/linux/packages/GCC. All others sites mirror this.
  109.     The latest versions of all GCC stuff will be found here.
  110.  
  111.     At the time of writing, the latest GCC is version for Linux is
  112.     2.6.2 and available from
  113.         tsx-11.mit.edu:/pub/linux/packages/GCC/gcc-2.6.2-p1.tar.gz
  114.  
  115.     However this does not mean that this is the latest available
  116.     version of GCC from the GNU foundation. This is just the latest
  117.     *distribution*.
  118.  
  119.     The Linux GCC maintainer(s) have made it easy for you to compile the
  120.     latest version available yourself. The configure script with GCC
  121.     sources should set it all up for you.
  122.  
  123.     You will also need the latest include (header) files if you wish to
  124.     compile stuff. At the time of writing the latest includes can be
  125.     obtained from 
  126.  
  127.         tsx-11.mit.edu:/pub/linux/packages/GCC/inc-4.6.27.tar.gz
  128.  
  129.     The latest `as', `ld', `ar' etc may be found in the package
  130.  
  131.         tsx-11.mit.edu:/pub/linux/packages/GCC/binutils-2.5.2.6.bin.tar.gz
  132.  
  133. -------------------------------------------------------------------------------
  134.  
  135. 3) Where can I find the newest shared libraries libc.so and libm.so ?
  136.  
  137. Ans:    See question (4) below. You need the file image-4.6.27.tar.gz.
  138.     Only 486 images are provided (they work also on 386's - but the
  139.     image size is slightly larger). You will need to recompile the shared
  140.     libraries if you want 386 libaries. See question (47) on where to
  141.     obtain the source code to the linux C library.
  142.  
  143. -------------------------------------------------------------------------------
  144.  
  145. 4) What other shared libraries are available for Linux ?
  146.  
  147. Ans:    Ok here is a list I have been compiling. Any additions/changes
  148.     graciously received.
  149.  
  150.     The locations given below were where they were last seen (or
  151.     reportedly seen). They may have been moved by archive maintainers.
  152.  
  153.     P.S. For a more obvious description of the libraries below,
  154.     their maintainers and their registered start/end address please
  155.     read the `doc/table_description' file in the tools-2.16.tar.gz package.
  156.     See the following question (5) on where to obtain this from.
  157.  
  158. Here are the locations of currently registered DLL libraries for Linux.
  159. ======================================================================
  160.  
  161. libc.so        tsx-11.mit.edu:/pub/linux/packages/GCC/image-4.6.27.tar.gz
  162. libm.so            included in above tar.gz file.
  163.  
  164. libX11.so    tsx-11.mit.edu:pub/linux/packages/X11/XFree86-2.1/XF86-2.1-lib.tar.gz
  165. libXt.so        included in above tar.gz file.
  166. libXaw.so        included in above tar.gz file.
  167.  
  168. librl.so    sunsite.unc.edu:/pub/Linux/libs/librl-2.0.3.tar.gz
  169. libgr.so    sunsite.unc.edu:/pub/Linux/libs/graphics/libgr-1.3.tar.gz
  170. libf2c.so    sunsite.unc.edu:/pub/Linux/devel/fortran/libf2c-0.10.tar.gz
  171. libF77.so        use libf2c.so shown above instead.
  172. libI77.so        use libf2c.so shown above instead.
  173.  
  174. libXpm.so    sunsite.unc.edu:/pub/Linux/libs/X/libXpm-3.4c.tar.gz
  175.  
  176. libnsl.so    ftp.lysator.liu.se:/pub/NYS/nys-0.27.1.tar.gz (frequent updates)
  177.  
  178. libolgx.so    sunsite.unc.edu:/pub/Linux/libs/xview3L5.1.tar.gz
  179. libxview.so        included in above tar.gz file.
  180. libsspkg.so        included in above tar.gz file.
  181. libUIT.so        included in above tar.gz file.
  182.  
  183. libPEX.so    tsx-11.mit.edu:pub/linux/packages/X11/XFree86-2.1/XF86-2.1-pex.tar.gz
  184.  
  185. libtcl.so    sunsite.unc.edu:/pub/Linux/devel/tcl/
  186. libtk.so        various related tcl/tk stuff included in above tar.gz files.
  187.  
  188. libWc.so        Unknown
  189. libXp.so        Unknown
  190.  
  191. libIV.so    sunsite.unc.edu:/pub/Linux/libs/X/iv3.1dist.tar.gz
  192. libUnidraw.so        included in above .tgz files.
  193.  
  194. libXm.so    The Motif library is *not* free. See note below.
  195.  
  196. libsrgp.so    sunsite.unc.edu:/pub/Linux/X11/devel/suit.tpz
  197. libsuit.so        included in above tpz file.  (reported not shared)
  198.  
  199. libOI.so    tsx-11.mit.edu:/pub/linux/packages/OI/oi40.tar
  200. libOIrg.so        included in above tar file.
  201.  
  202. libld.so    tsx-11.mit.edu:/pub/linux/packages/GCC/ld.so-1.5.2.tar.gz
  203.               (required for libc 4.4.4 and above.)
  204.  
  205. libarma.so    ftp.atnf.csiro.au:/pub/karma
  206. libkarmaX11.so        see above site
  207. libkarmaXt.so        see above site
  208. libkarmagraphics.so    see above site
  209. libkarmawidgets.so    see above site
  210. libkarmaxview.so    see above site
  211.  
  212. libwxwin.so    sunsite.unc.edu:/pub/Linux/X11/devel/wxWin_linux.tgz
  213.  
  214. libandrew.so    sunsite.unc.edu:/pub/Linux/X11/andrew/andrew61.prog.tar.gz
  215.  
  216. libUil.so        Commercial library.
  217.  
  218. libBLT.so    sunsite.unc.edu:/pub/Linux/devel/tcl/blt1.7l1-bin.tar.gz
  219.  
  220. libvga.so    sunsite.unc.edu:/pub/Linux/libs/graphics/svgalib112.tgz
  221.  
  222. libitcl.so    sunsite.unc.edu:/pub/Linux/devel/tcl/itcl1.5l1-bin.tar.z
  223.  
  224. ------------
  225. Note 1:-
  226.  
  227. Drop in DLL libraries for Xaw to get a 3d effect (libXaw3d-0.6) and a Mac(TM)
  228. like scroll bar on Xaw clients are available respectively at
  229.  
  230.     sunsite.unc.edu:/pub/Linux/libs/X/Xaw3d-0.6B.3.1.1.bin.tar.gz
  231. and
  232.     sunsite.unc.edu:/pub/Linux/libs/X/libXaw.Scrollbar.taz
  233.  
  234.  
  235. Note 2:-
  236.  
  237. For motif libs you have to pay bucks !! Read an extract that follows...
  238. ------------
  239.  
  240. Metro Link, Inc. is pleased to announce the availability of OSF/Motif 1.2.2 
  241. for Linux at $199 for a complete runtime and development system. 
  242.  
  243. Requirements:
  244.     Linux 0.99pl4 or greater (currently 0.99pl12 O.K.)
  245.     XFree86 1.2 or greater (1.3 O.K.)
  246.     libc 4.3.3 or greater (libc 4.4 is O.K.)
  247.  
  248. What is included:
  249.  
  250. Runtime:
  251.     1) Motif Window Manager (mwm)
  252.     2) Shared motif library (libXm.so.1.2.2)
  253.     3) Motif demos both from OSF and from the net
  254.  
  255. Development:
  256.     1) Shared+Static Motif library
  257.     2) Static Mrm and Uil libraries
  258.     3) UIL compiler
  259.     4) Motif header files 
  260.     5) Manual pages for Motif function calls
  261.     6) Imakefile support
  262.     7) Source to OSF/Motif demos
  263.  
  264. And your choice of any one of the X-window books published by O'Reilly & 
  265. Associates, Inc.
  266.  
  267. You can order OSF/Motif 1.2.2 for Linux by calling Metro Link,Inc. at 
  268. (305) 970-7353 (voice) or (305) 970-7351 (fax) or by mailing us at 
  269. sales@metrolink.com.
  270.  
  271.  
  272. ==============================================================================
  273.   Metro Link Incorporated.  2213 W. McNab Rd. Pompano Beach,  Florida  33069
  274.  X11.5 and OSF/Motif for QNX, SVR3, SVR4.[012], SCO, Linux, UnixWare, LynxOS, 
  275.                   AT&T, Venix, ISC, Solaris, Pyramid, SunOS
  276.  Voice: +1.305.970.7353    Fax: +1.305.970.7351  Email: mahesh@metrolink.com
  277.             WATCH your: Word Action Thought Character Heart
  278. ==============================================================================
  279.  
  280. -------------------------------------------------------------------------------
  281.  
  282. 5) How do I build a shared DLL library for Linux ?
  283.  
  284. Ans:    You need to get the file
  285.  
  286.         tsx-11.mit.edu:/pub/linux/packages/GCC/src/tools-2.16.tar.gz
  287.  
  288.     from tsx-11.mit.edu, and install it. Read the README.tr in the doc
  289.     subdirectory thoroughly - a lot of effort has been put into this to
  290.     make it readable and possible for everyone to be able to build a
  291.     shared DLL.
  292.  
  293.     If you find the README.tr more up to date than the README.ps, you
  294.     will have to recreate it if you want a pretty Postscript version,
  295.     but you *must* have groff installed. A `make README.ps' in the doc
  296.     subdirectory should suffice.
  297.  
  298.     ** Note: the version numbers may have changed.
  299.  
  300. -------------------------------------------------------------------------------
  301.  
  302. 6) Why do I get the message "PLT__oct__FUii" when I execute a certain binary ?
  303.  
  304. Ans:     More likely than not you have a old version of the libraries, libc.so
  305.     and/or you compiled a program using a incorrect version of `ld'.
  306.     The solution is to get the new version of binutils package from
  307.  
  308.         tsx-11.mit.edu:/pub/linux/packages/GCC/binutils-2.5.2.6.bin.tar.gz
  309.  
  310. -------------------------------------------------------------------------------
  311.  
  312. 7) How do I build a cross compiler on platform XXX to produce code for Linux ?
  313.  
  314. Ans:    Assuming you have obtained the source code to gcc, usually you can
  315.     just follow the instructions given in the INSTALL file for GCC.
  316.     A `configure --target=i386-linux-linux --host=XXX' on platform XXX
  317.     followed by a `make' should do the trick.
  318.     Note that you will need the linux includes, the kernel includes,
  319.     and also to build cross assembler, and cross linker from the sources
  320.     in /pub/linux/packages/GCC/src at tsx-11.mit.edu
  321.  
  322.     Here is an example of building a cross compiler on a Sparc (Sun) to
  323.     produce code for a linux machine. This is the easy way, using linux
  324.     libraries compiled by HLU that you already are using on your linux
  325.     machine. For some of this I STRONGLY advise you to get GNU's make
  326.     (gmake) to use for some of the compilations (binutils and gas will
  327.     fail using the included Makefiles.linux with Sun's make)
  328.  
  329.     7.1) Lets assume you already have a working gcc version 2.4.5 on the
  330.          Sun in /usr/local/bin with all standard install paths - i.e the
  331.          compilers are in /usr/local/lib/gcc-lib.
  332.  
  333.          First make the linux specific directories (you may need to make
  334.          the intermediate directories too) up to
  335.  
  336.         % mkdir -p /usr/local/lib/gcc-lib/i386-linux-linux/bin
  337.         % mkdir -p /usr/local/lib/gcc-lib/i386-linux-linux/2.4.5/include
  338.         % mkdir    /usr/local/lib/gcc-lib/i386-linux-linux/include
  339.  
  340.        7.2) Start by setting some environment variables so you don't have to
  341.         type long pathnames. Set this in your .login or .cshrc also as you
  342.         will need to use l-ar, l-ranlib for cross compiling DLL's etc..
  343.         For the moment you can do the following
  344.  
  345.         In csh:
  346.            % setenv LBINS /usr/local/lib/gcc-lib/i386-linux-linux/bin/
  347.         In sh:
  348.            % LBINS=/usr/local/lib/gcc-lib/i386-linux-linux/bin/
  349.            % export LBINS
  350.  
  351.         Put *ALL* linux specific header files with all the contents of the
  352.         subdirectories linux, asm, gnu, sys etc.. in ${LBINS}../include
  353.         Make SURE of this. See questions (2) and (23) on where to get
  354.         these from. You will have to do this each time a new kernel is
  355.         released.
  356.  
  357.         On my linux machine sitting next to my sun I can say
  358.  
  359.         % rcp -r linux_machine:/usr/include ${LBINS}../
  360.  
  361.         Otherwise you will need to get the includes and kernel sources, see
  362.         questions (2), to achieve this. Also you will want the gnu specific
  363.         files like limits.h, varargs.h, stdargs.h  etc... Again from my
  364.         linux machine I can say
  365.  
  366.         % rcp -r \
  367.             linux_machine:/usr/lib/gcc-lib/i386-linux/2.4.5/include \
  368.             ${LBINS}../2.4.5
  369.  
  370.        You may have to change the i386 or 2.4.5 depending on your machine
  371.        and version of gcc.
  372.         
  373.     7.3) Now you have to extract and compile the cross assembler and
  374.          linker:
  375.  
  376.          Get the following files
  377.  
  378.          tsx-11.mit.edu:/pub/linux/packages/GCC/src/binutils-1.9l.4.tar.gz
  379.          tsx-11.mit.edu:/pub/linux/packages/GCC/src/gas-1.38.1l.2.tar.gz
  380.  
  381.          and extract them somewhere.
  382.  
  383.     7.3.1)  In the binutils dir binutils-1.9l.3:
  384.         Edit Makefile.linux and change the line that has the bindir
  385.         definition to have
  386.  
  387.                 bindir=${LBINS}
  388.  
  389.         and the appropriate block for your machine ("sun4" in this
  390.         case) line to
  391.  
  392.             HOST_ROOT=${LBINS}..
  393.  
  394.         For 0.99pl12 (and above probably) you will have to copy
  395.         a.out.h and page.h to a directory and include it in the 
  396.         MISCFLAGS. So in the current binutils dir, do this
  397.  
  398.             % mkdir linux
  399.             % cp ${LBINS}../include/linux/a.out.h linux
  400.             % cp ${LBINS}../include/linux/page.h linux
  401.  
  402.         and then edit the Makefile.linux and add -I. to the
  403.         appropriate MISCFLAGS line.
  404.  
  405.         Then do
  406.             % make -f Makefile.linux archpfx= install
  407.  
  408.         To be able to do l-ar, l-ranlib for the linux ar, ranlib
  409.         utilities, do the following (I put the l-blah into my
  410.         private ${HOME}/bin directory)
  411.             % sh -c 'for i in ${LBINS}*; do \
  412.                       ln -s $i ${HOME}/bin/l-`basename $i`; done'
  413.  
  414.     7.3.2)    *******FOR gas-1.38.1l.1*******
  415.  
  416.         In the the assembler directory gas-1.38.1l.1:
  417.         Edit the makefile.linux file and change the appropriate lines
  418.         to read the following
  419.             
  420.             LINUX_INCDIR=
  421.  
  422.             HEADERS=-DA_OUT_H=\"${LBINS}../include/linux/a.out.h\"
  423.  
  424.         Then type (lots of warnings will appear)
  425.  
  426.             % make -f makefile.linux
  427.  
  428.         Copy the cross assembler binary manually
  429.  
  430.             % cp a386 ${LBINS}as
  431.  
  432.  
  433.         *******FOR gas-2.2 (and above)*******
  434.  
  435.         In the the assembler directory do
  436.  
  437.             % ./configure --host=sun4 --target=i386-linux-linux
  438.             % make CC=gcc CFLAGS=-O2 LDFLAGS=-s
  439.  
  440.     7.3.3)    Finally make the two links
  441.  
  442.             % ln -s ${LBINS}as ${LBINS}../2.4.5/as
  443.             % ln -s ${LBINS}ld ${LBINS}../2.4.5/ld
  444.  
  445.       7.4) Now in the GCC source directory you extracted on your Sun do the
  446.        following.
  447.  
  448.         % ./configure --host=sun4 --target=i386-linux-linux
  449.         % make    CC=/usr/local/bin/gcc CFLAGS="-O2 -s" \
  450.             tooldir=${LBINS}.. LANGUAGES="c c++ objc"
  451.  
  452.        This may end with an error when building the library
  453.        libgcc.a, ignore it. All you want are the cross compiler
  454.        binaries in this instance.
  455.  
  456.       7.5) After that finishes, copy the binaries to the proper places...
  457.  
  458.         % cp cc1 cc1plus cpp cc1obj ${LBINS}../2.4.5
  459.  
  460.        Copy the front end to the compiler to the bin directory and make
  461.        a easy link somewhere (maybe your ~/bin)
  462.  
  463.         % cp xgcc ${LBINS}gcc
  464.         % ln -s ${LBINS}gcc ${HOME}/bin/gcc-linux
  465.  
  466.       7.6) Get all your libs from your linux machine
  467.  
  468.         % rcp linux_machine:/usr/lib/lib\*a ${LBINS}../2.4.5
  469.         % rcp linux_machine:/usr/X386/lib\*a ${LBINS}../2.4.5
  470.         % rcp linux_machine:/usr/lib/crt0.o ${LBINS}../2.4.5
  471.  
  472.       7.7) That's it. Try compiling something. Lots of well written packages
  473.        will let you do the following (assuming you have the path to your
  474.        ${HOME}/bin set)
  475.  
  476.         % make CC="gcc-linux -O6 -s" RANLIB=l-ranlib AR="l-ar"
  477.  
  478.       7.8) If you want to cross compile shared DLL's then you must also get
  479.  
  480.         tsx-11.mit.edu:/pub/linux/packages/GCC/src/tools-2.16.tar.gz
  481.  
  482.        Use the Makefile.cross in the tools subdirectory to compile a
  483.        cross version. Change the definition at the top of the
  484.        Makefile.cross to look like
  485.  
  486.         CROSSBINDIR=${LBINS}
  487.         CROSSINCDIR=${LBINS}../include
  488.         
  489.        Finally change the BINDIR definition. I set it to ${LBINS}../dll/bin
  490.        This will also create a ${LBINS}../dll/jump for you. Then a
  491.  
  492.         % make -f Makefile.cross install
  493.  
  494.        should do the business.
  495.  
  496. -------------------------------------------------------------------------------
  497.  
  498. 8) What symbols are automatically defined by Linux's GCC ?
  499.  
  500. Ans:    Symbols defined are `linux', `__unix__', `__i386__', `__linux__',
  501.     `__unix', `__i386', `__linux'.
  502.     You can get a correct list by using the flag -v to gcc whilst
  503.     compilation.
  504.  
  505.     P.s. One should note that even though the compiler automatically
  506.     defines "linux" in a program, this is *not* POSIX compliant. Instead
  507.     __linux__ should be used in programs that need operating-system
  508.     specific compilation, since __linux__ *is* POSIX compliant.
  509.  
  510.     This means you can wrap your linux specific code around (for example)
  511.  
  512.     #ifdef __linux__
  513.     ...[linux specific code here]...
  514.     #endif /* ifdef linux */
  515.  
  516.     without adding anything extra to the Makefile defines etc..
  517.  
  518.     You can also add your own defines to the file
  519.         /usr/lib/gcc-lib/i486-linux/2.6.2/specs
  520.  
  521. -------------------------------------------------------------------------------
  522.  
  523. 9) How do I get over BSD'isms (especially signals, sigvec etc..) when compiling code ?
  524.  
  525. Ans:    You can compile your program with -I/usr/include/bsd and link it
  526.     with -lbsd (i.e. Add -I/usr/include/bsd to CFLAGS and -lbsd to
  527.     the LDFLAGS line in your Makefile). There is *no* need to add
  528.     -D__USE_BSD_SIGNAL any more if you want BSD type signal behavior,
  529.     as this is added automatically when you do the -I/usr/include/bsd
  530.  
  531. -------------------------------------------------------------------------------
  532.  
  533. 10) Where are SIGBUS, SIGEMT, SIGIOT, SIGTRAP, SIGSYS  etc ?
  534.  
  535. Ans:    Linux is 100% POSIX compliant and these signals are not POSIX
  536.     signals. As an easy way out you could redefine them to SIGUNUSED.
  537.     See the definitions in /usr/include/bsd/signal.h 
  538.  
  539.     However you should note that the lack of these signals *is* compliant
  540.     with POSIX. Instead of #define'ing to them to SIGUNUSED, new programs
  541.     should instead say:
  542.  
  543.     #ifdef SIGSYS
  544.     ....[non-posix sigsys code here]....
  545.     #endif
  546.  
  547.     for code that requires the use of SIGSYS (similarly for SIGBUS).
  548.  
  549.     Here is a snippet from ISO/IEC 9945-1:1990 (IEEE Std 1003.1-1990),
  550.     paragraph B.3.3.1.1: 
  551.  
  552.     "The signals SIGBUS, SIGEMT, SIGIOT, SIGTRAP, and SIGSYS were
  553.     omitted from POSIX.1 because their behavior is implementation
  554.     dependent and could not be adequately categorized.  Conforming
  555.     implementations may deliver these signals, but must document the
  556.     circumstances under which they are delivered and note any
  557.     restrictions concerning their delivery."
  558.  
  559. -------------------------------------------------------------------------------
  560.  
  561. 11) What is libhard and libsoft ?
  562.  
  563. Ans:    These are the libraries for the math emulation routines - the hard
  564.     if you had hardware to do math (i.e. a 387), or soft if emulation of
  565.     math routines was done in software.
  566.  
  567.     You do *not* need these libraries if you are using a current version
  568.     of Linux, as math emulation is now done at kernel level - (i.e if
  569.     you enabled it when you did a `make config' at kernel build time).
  570.     Otherwise your 387 will do the work. You may safely remove them if
  571.     your link /lib/libm.so.4 points to a libm.so.4.x.y
  572.  
  573. -------------------------------------------------------------------------------
  574.  
  575. 12) What does the message "can't load library: /lib/libxxx.so, Incompatible version" mean ?
  576.  
  577. Ans:    As shared libraries evolve it is necessary to have some sort of
  578.     version numbering such that a program may be able to determine
  579.     whether its execution will cause it to crash. This will happen for
  580.     example if a function call has changed radically or doesn't exist.
  581.  
  582.     Say we have a library - libc.so.4.3.3
  583.                                    T    T T T
  584.                                   /    /  |  \
  585.                                  /    /   |   \
  586.                                 /    /    |    \
  587.                      Library name   /     |     \
  588.                                    /      |      \
  589.                     Major version no.     |      Patch level.
  590.                                           |
  591.                                   Minor version no.
  592.  
  593.     If the Major version no. changes, then you will only be allowed to
  594.     execute a program if the Major version number of the current library
  595.     you are running matches that with which the program was linked with.
  596.     This means if your program is compiled when you had libc.so.4.3.3
  597.     you will not be able to execute it if you get a more recent version of
  598.     the DLL library, say libc.so.5.1.2. I.e it is no use attempting to
  599.     create a link from libc.so.5.1.2 to libc.so.4 if your program requires
  600.     libc.so.4.
  601.  
  602.     The Minor version no. is as name suggests, an indication that a
  603.     minor change has undergone in the shared DLL library, maybe just a
  604.     new addition of a function, and shows that backward compatibility
  605.     is still retained. If you attempt to use a library whose minor
  606.     version number is smaller than what the binary was originally
  607.     compiled with then a warning to this effect will ensue, but normal
  608.     execution should still be possible.
  609.  
  610.     The Patch level no. may be left out totally from the numbering
  611.     convention. It is usually used just for a typo or small bug
  612.     fix in the library code.
  613.  
  614.     So getting back to the question, it usually means that you are
  615.     trying to run a binary and you don't have the correct library(ies)
  616.     installed on your system. To rectify the situation get the latest
  617.     libs - See questions (3), (19).
  618.  
  619. -------------------------------------------------------------------------------
  620.  
  621. 13) Why are my binaries so huge and how do I reduce them ?
  622.  
  623. Ans:    If you want smaller binaries there are a number of things you can do.
  624.  
  625.     * Optimize the code - Use the -O2 flag when compiling,
  626.     * Strip the resultant binary - Use the -s flag at the ld stage.
  627.     * Make the binary impure - Use the -N flag at the ld stage.
  628.     * Make the binary QMAGIC - Use the -qmagic flag at the ld stage -
  629.         See question (53) for building QMAGIC executables.
  630.  
  631.     A combination of any/all of these may be used. If you want to
  632.     strip a binary, but don't have the source handy to use the
  633.     "-s" flag with ld. You can also use the "strip" command. See
  634.     "man strip" for more information.
  635.  
  636.     The linker `ld' will choose by default to link your program to
  637.     the shared libraries. However if it doesn't find the relevant
  638.     stubs (i.e. the .sa files, see question (28)) *OR* if the
  639.     these files are unreadable by the user then it will attempt to
  640.     link static (i.e. to the .a files). This may be a reason why
  641.     your binaries are so huge. The search path it looks for these
  642.     .sa and .a libraries are /usr/lib, then /lib and then /. This
  643.     means you may intersperse the stubs and DLL shared libs
  644.     anywhere in these directories. More flexibility will soon be
  645.     available - See also question (20).
  646.  
  647.     Also many of the FSF authors believe that we want to debug their
  648.     programs, and leave the -g option in their Makefiles. The result is
  649.     that large amounts of debugging symbols are left in and the program
  650.     is linked statically. Check the Makefile carefully to make sure -g
  651.     has been removed from either the CFLAGS and/or the LDFLAGS if you are
  652.     compiling software and you are satisfied with it's operation.
  653.  
  654.     Note with newer `ld' executables QMAGIC is the default for the
  655.     a.out format.
  656.  
  657. -------------------------------------------------------------------------------
  658.  
  659. 14) What does the -N flag do, and when should I use it ?
  660.  
  661. Ans:    A demand paged binary can be swapped.  If you use the -N option you
  662.     get an impure executable file which does not have its various
  663.     segments padded out to page boundaries. Linux can optimize the
  664.     swapping of sharable (clean) pages by simply "forgetting" them -
  665.     because it can always reload them directly from the file.
  666.     Otherwise, it has to physically write them into the swap partition or
  667.     swap file - which needs some time and uses up disk space.
  668.  
  669.     This is usually irrelevant for very small programs, which is why they
  670.     are often compiled with -N.  Large programs (eg. gcc or emacs), or
  671.     programs which are likely to have multiple instances (like the shell
  672.     or xterm), should be compiled without -N so that their code pages can
  673.     be shared cleanly. If you start to run out of memory, the kernel can
  674.     start to delete unused code pages from demand page executables as
  675.     they can always be reloaded later.  This is impossible for impure
  676.     executables.
  677.  
  678.     So, if your program is likely to use significant amounts of memory,
  679.     then don't use -N or the kernel's memory management will be
  680.     obstructed.
  681.  
  682.     Clearly `one-off' programs can all be compiled using this flag -
  683.     i.e. anything which doesn't stay for long periods of time in memory,
  684.     say for example hostname, fsck, mkfs, w, etc.. Do *not* use the -N
  685.     flag on daemons, which by nature are meant to be resident in memory.
  686.  
  687. -------------------------------------------------------------------------------
  688.  
  689. 15) How do I get debugging information into a program ?
  690.  
  691. Ans:    You need to compile your program (i.e. all objects) and also link it
  692.     with the -g flag on - in other words compile *everything* with -g.
  693.     Debugging still works with -g on for some files only (the ones, which
  694.     are buggy).  More important than using the -g flag is to *not* use
  695.     the -fomit-frame-pointer flag, as it cheats `gdb' severely.
  696.     Unfortunately, the shared libs are usually compiled with 
  697.     -fomit-frame-pointer for performance.
  698.  
  699.     Therefore, it is wise to give the -g or the -static flag to the
  700.     linker, to link with the non-shared libs, when debugging.  If you
  701.     fail to do so, you are usually unable to do a backtrace, when you
  702.     are caught with a segmentation violation in a system routine.
  703.  
  704.     If you end up at the linker stage with a message like
  705.         Can't find libg.a
  706.     then you need to get it from the file
  707.         tsx-11.mit.edu: /pub/linux/packages/GCC/extra-4.6.27.tar.gz
  708.  
  709.     However enough debugging information may be gleaned by simply doing
  710.         % cd /usr/lib; ln -s libc.a libg.a
  711.     on your linux machine. However, you will not be able to debug any
  712.     of the library calls unless you use the full libg.a (~2.7Mb).
  713.  
  714.     Make sure *NOT* to strip the binary if you want to perform debugging.
  715.  
  716. -------------------------------------------------------------------------------
  717.  
  718. 16) What debuggers are available for Linux ?
  719.  
  720. Ans:    Well of course, the best debugger available ever is `gdb'. Look for
  721.     it at your favorite site. Eg:
  722.         prep.ai.mit.edu:/pub/gnu/gdb-4.13.tar.gz
  723.  
  724.     A Linux precompiled version may be found at:
  725.         sunsite.unc.edu:/pub/Linux/devel/debuggers/gdb-4.12-bin.tar.gz
  726.     or
  727.         sunsite.unc.edu:/pub/Linux/Incoming/librl-2.0.3.tar.gz
  728.  
  729.     An X debugger based on this, (i.e. you need gdb installed first), is
  730.     also available. The source may be found at
  731.         ftp.x.org:/contrib/xxgdb-1.08.tar.gz
  732.  
  733.     Also, the UPS debugger has been ported by Rick Sladkey. It runs
  734.     under X as well, but unlike xxgdb, it is not merely an X front end
  735.     for a text based debugger. It has quite a number of nice features,
  736.     and if you spend any time debugging stuff, you probably should
  737.     check it out. The Linux precompiled version and patches for the stock
  738.     UPS sources can be found at:
  739.         sunsite.unc.edu:/pub/Linux/devel/debuggers/ups-2.45.2-linux-0.1.tar.gz
  740.  
  741.     You will need to get the full sources from your nearest X archive or
  742.         ftp.x.org:/contrib/ups-2.45.2.tar.Z
  743.     if you wish to rebuild it yourself
  744.  
  745. -------------------------------------------------------------------------------
  746.  
  747. 17) How do I debug a daemon program ?
  748.  
  749. Ans:    Simply put, you have to get the daemon program not to fork before
  750.     you can debug it. 
  751.  
  752.     However using the debugger `gdb' you can attach to the daemon even
  753.     *after* it has forked. You do this by telling gdb the process id no.
  754.     that you want to debug. Use the `attach' command to do this. GDB's
  755.     integrated online help is useful here.
  756.  
  757.     Also if you are not in possession of the source, and the binary is
  758.     stripped you can obtain the program `strace', attach it to the
  759.     daemon process id and examine the output produced. This can be useful
  760.     if you know what you are looking for. Look in
  761.  
  762.         sunsite.unc.edu:/pub/Linux/devel/strace/strace-3.0.tar.gz
  763.  
  764. -------------------------------------------------------------------------------
  765.  
  766. 18) What is profiling and how do I profile a program ?
  767.  
  768. Ans:    Profiling is a way to examine where and which functions time is being
  769.     spent on, the number of calls made to a certain function and total
  770.     execution times. It is a good way to optimize code and look at where
  771.     time is being unnecessarily wasted.
  772.     To enable profiling all objects and linking must be compiled with
  773.     the -p flag. See question (15) on where to get the libraries
  774.     necessary for profiling.
  775.  
  776.     To actually get a graph profile you need also the program `gprof'.
  777.     You will find it included in the binutils package.
  778.     Again, find it at your favorite Linux archive site. Eg:
  779.         tsx-11.mit.edu:/pub/linux/packages/GCC/binutils-2.5.2.6.bin.tar.gz
  780.  
  781.  
  782. -------------------------------------------------------------------------------
  783.  
  784. 19) Is there a way to tell if a binary is linked statically or to a shared library ?
  785.  
  786. Ans:    Yes.
  787.     Use the utility `ldd'. This gives you information on what libraries
  788.     are required. If no output is generated when you run `ldd' on a
  789.     program then it indicates the program was linked statically.
  790.  
  791.     Eg (1): the command (on my linux system)
  792.         % ldd /bin/init
  793.     gives no output meaning init was linked statically. And a good thing
  794.     too it was linked statically :-) (NOTE: For programs linked with
  795.     libc.so.4.5.19 and above, the message "statically linked" will be
  796.     output in this case). For statically linked ELF executables you will
  797.     get the message "statically linked (ELF)".
  798.  
  799.     Eg (2): the command (on my linux system)
  800.         % ldd /usr/bin/gs
  801.     i.e. the ghostscript interpreter gives the following output.
  802.             libm.so.4       => /lib/libm.so.4.4 (4.0)
  803.             libX11.so.3     => /lib/libX11.so.3.0 (DLL Jump 3.0pl0)
  804.             libc.so.4       => /lib/libc.so.4.4 (DLL Jump 4.3)
  805.     This tells me that the program `gs' was dynamically linked and
  806.     requires three shared libraries. The numbers in brackets tell me
  807.     that only one library, (libX11), matches the current version of the
  808.     library I have when the program was compiled. When `gs' was compiled
  809.     the math library, (libm), I had was version 4.0 and not a DLL
  810.     library, but it will happily run with my 4.4 DLL shared version.
  811.     Similarly my current c library, (libc), is a version greater that
  812.     when I compiled `gs'. For dynamically linked ELF executables you will
  813.         get a messages like (paths may be different)
  814.  
  815.         Linux ELF dynamic linker: gs: file loaded: /usr/X386/lib/libX11.so.4
  816.         Linux ELF dynamic linker: gs: file loaded: /usr/lib/libm.so.4
  817.         Linux ELF dynamic linker: gs: file loaded: /usr/lib/libc.so.4
  818.  
  819.     Note: For ELF executables you MUST be using a `ldd' or `ldconfig'
  820.     from the ld.so package (See question (4)) version 1.5.0 or greater
  821.     for this to work.
  822.  
  823. -------------------------------------------------------------------------------
  824.  
  825. 20) Does Linux have support for LD_LIBRARY_PATH ?
  826.  
  827. Ans:    Yes and No, depending on the version of libc your binary was originally
  828.     compiled with.
  829.  
  830.       *    Initially LD_LIBRARY_PATH was supported with libraries > than 4.3.3.
  831.  
  832.     I.e. the __load.o routine in your stub (/usr/lib/libc.sa) was
  833.     replaced to cater for this. With binaries compiled using libc version
  834.     less than 4.4.4, linux's dynamic linker contains the loader as a
  835.     static object in the form of __load.o which appears in the libc.sa
  836.     stub and automatically gets linked into every binary you build.
  837.     This means that changes to __load.o take a very long time to
  838.     propagate and appear in every single binary.
  839.  
  840.     So to answer the question: Yes, it is supported if anything is
  841.     compiled using library versions greater that 4.3.3, (libc.so.4.3.4
  842.     and above), but the upshot is that you will not notice it unless you
  843.     recompile *all* your binaries.
  844.  
  845.       *    With libc version 4.4.4 and above, the dynamic loader was in fact made
  846.     dynamic and loads and unloads itself after searching and locating
  847.     the required libraries. The upshot of this is that binaries are
  848.     smaller and any changes to the dynamic loader/linker are isolated
  849.     from libc. You will need to read the manpages to ld.so and ldconfig
  850.     from the ld.so package. See question (4) under libld.so.
  851.  
  852.     Linux's LD_LIBRARY_PATH is very security concious, and do NOT expect
  853.     it to work the way Sun-OS do it or the way you'd like it to. 
  854.  
  855.     Primarily the difference with Sun-OS's LD_LIBRARY_PATH use is the
  856.     fact that during compilation (linking) stage, the LD_LIBRARY_PATH is
  857.     parsed to find valid libraries to link to and these are *recorded*
  858.     within the incomplete binary produced. Hence at runtime the binary
  859.     knows where to look for the shared libraries before it looks up
  860.     LD_LIBRARY_PATH, (and often it never parses LD_LIBRARY_PATH at all,
  861.     as it finds the shared libraries first in the recorded path), thus
  862.     reducing overhead. Linux on the other hand does NOT record this
  863.     information, but instead searches at runtime (execution) for
  864.     libraries it needs to link to.
  865.  
  866.     When a binary is executed on Linux it first searches /usr/lib, then
  867.     /lib and then / for a library to runtime link to if you do *not*
  868.     have any LD_LIBRARY_PATH. This can be referred to as the "trusted
  869.     search path". 
  870.  
  871.     Note that / is not really a search path, but was put in for
  872.     backward compatibility as some users were building shared DLL's
  873.     using names like "/lib/libfoo.so" so uselib() would now do
  874.  
  875.         (1) uselib("/usr/lib//lib/libfoo.so.x")  ---- fails 
  876.         (2) uselib("/lib//lib/libfoo.so.x")      ---- fails again
  877.         (3) uselib("//lib/libfoo.so.x")          ---- succeeds.!!
  878.  
  879.     So don't actually put your DLL's in / :-)
  880.  
  881.     Now if you *do* have a LD_LIBRARY_PATH and you are root, (user with
  882.     uid 0), then LD_LIBRARY_PATH is searched followed by the trusted
  883.     search path.
  884.  
  885.     If on the other hand you are a normal user, (uid != 0), and the
  886.     binary to be executed is a suid executable, then the libc.so.x and
  887.     necessary libraries are force loaded from somewhere in the trusted
  888.     search path. The LD_LIBRARY_PATH is ignored, (in fact reset totally).
  889.     This stops a normal user from emulating his own, for example, setuid()
  890.     calls from a libc library (s)he created.
  891.  
  892.     Finally if you are a normal user and the binary to be executed is a
  893.     "normal" binary, then LD_LIBRARY_PATH is searched first for the
  894.     libraries required.
  895.  
  896.     If the library is NOT found in the user's LD_LIBRARY_PATH then the
  897.     search path is set to the "trusted search path" and the search
  898.     carries on. This gets over the problems of incorrect/silly
  899.     LD_LIBRARY_PATH settings and still allows these kind of nubile users
  900.     to execute binaries. 
  901.  
  902. -------------------------------------------------------------------------------
  903.  
  904. 21) My program wants /lib/cpp ! Where can I get it from ?
  905.  
  906. Ans:    cpp appears in /usr/lib/gcc-lib/i486-linux/2.6.2
  907.     (the gcc version numbers may have changed when you read this)
  908.  
  909.     You need to do the following
  910.         % cd /lib; ln -sf /usr/lib/gcc-lib/i486-linux/2.6.2/cpp
  911.  
  912.     ** Change the 2.6.2 to whatever version of GCC your are using.
  913.         ** Change the i486 to i386 if using the 386 compiler
  914.  
  915.     A possible alternative is this:
  916.  
  917.         % cat > /lib/cpp
  918.         #!/bin/sh
  919.         exec cc -E "$@"
  920.         Ctrl-D[EOF]
  921.         % chmod 755 /lib/cpp
  922.  
  923.     This way /lib/cpp won't stop working when you switch to a newer gcc
  924.     version and delete the old one. However the former command (i.e the
  925.     link) will read from stdin, while the latter will complain about a
  926.     missing filename argument (unless you explicitly specify - as stdin).
  927.     Any program that uses /lib/cpp as a filter without any arguments
  928.     will therefore fail. For example "xrdb" won't work (the error is
  929.     silently ignored).
  930.  
  931.     Because of these differences, it is advisable to remember to update
  932.     the link instead.
  933.  
  934. -------------------------------------------------------------------------------
  935.  
  936. 22) Where are <float.h>, <limits.h>, <varargs.h>, <stdarg.h> and <stddef.h> ?
  937.  
  938. Ans:    These files depend on the version of your compiler. Therefore they are 
  939.     hidden in a compiler directory.
  940.         /usr/lib/gcc-lib/i486-linux/2.6.2/include
  941.  
  942.     ** Change the 2.6.2 to whatever version of GCC your are using.
  943.     ** Change the i486 to i386 if using the 386 compiler
  944.  
  945. -------------------------------------------------------------------------------
  946.  
  947. 23) My program wants to include <linux/foo.h> but cannot find it, where is it ?
  948.  
  949. Ans:    As some of the includes are kernel version dependent, they are thus
  950.     kept along with the kernel releases. You need to get the latest
  951.     kernel sources, unpack them and then make appropriate links.
  952.  
  953.     If say you unpacked the kernel source in /usr/src such that you have
  954.     a /usr/src/linux directory, then you should do the following:
  955.         % cd /usr/include
  956.         % ln -sf /usr/src/linux/include/linux
  957.         % ln -sf /usr/src/linux/include/asm
  958.  
  959.  
  960.     The MCC release does not initially have these links, and hence
  961.     one can install a new kernel source tree, and still be using
  962.     the old include files. Watch out for this.
  963.  
  964. -------------------------------------------------------------------------------
  965.  
  966. 24) Do we have the function foo() in our libraries ?
  967.  
  968. Ans:    An easy way to check out whether a function is supported in a
  969.     certain library is to do the following, say you are unsure
  970.     whether flock() is supported ...
  971.         % nm /usr/lib/libc.a | grep flock
  972.  
  973.     If you get something like
  974.         00000000 T flock
  975.     flock() is defined in libc.a/libc.sa.
  976.  
  977.     If you only get lines like
  978.         00000000 U flock
  979.     it only indicates a reference to flock(). The `U' means that flock is
  980.     defined elsewhere and you need to include the library where it is
  981.     defined such that the reference can be resolved.
  982.  
  983. -------------------------------------------------------------------------------
  984.  
  985. 25) How do I port program XXX to Linux ?
  986.  
  987. Ans:    Gone are the days when one had to `port' a program to Linux.
  988.     These days if something hasn't been ported to Linux then it is not
  989.     worth having :-)
  990.  
  991.     Seriously though, in general only minor changes are needed to the
  992.     sources to get over Linux's 100% POSIX compliance. It is also
  993.     worthwhile passing back any changes to authors of the code such that
  994.     in the future only `make' need be called to provide a working
  995.     executable.
  996.  
  997.     One of the most frequent problems is that some common functions are
  998.     defined as macros in Linux's header files and the preprocessor will
  999.     refuse to parse similar prototype definitions in the code. Common
  1000.     ones are  atoi() and atol().
  1001.  
  1002.     There is another common problem: "sprintf(string, fmt, ...)" returns
  1003.     a pointer to string on most unixes, while linux returns the number
  1004.     of characters, which were put into the string.
  1005.  
  1006.     Other problems tend to arise from the fact, that GCC is an ANSI
  1007.     compiler. Most important changes are for the preprocessor.  Adding
  1008.     the option:
  1009.  
  1010.         -traditional
  1011.  
  1012.     is often the only (but poor) solution.
  1013.  
  1014.     +---------------------------------------------------------------+
  1015.     | Some other worthy comments are noted below from Bruno Haible: |
  1016.     +---------------------------------------------------------------+
  1017.  
  1018.     This is an attempt to describe some of the problems that may arise
  1019.     when porting Unix software to Linux.
  1020.  
  1021.     We assume the software is written in C.
  1022.  
  1023.     Linux (i.e. its system calls and C library functions) is as closely
  1024.     POSIX compliant as possible. This makes this list very short.
  1025.  
  1026.  
  1027.     Problem 1: The select() timeout
  1028.     -------------------------------
  1029.  
  1030.     Symptom:
  1031.     A program that should only poll for input becomes a CPU hog.
  1032.  
  1033.     Problem:
  1034.     The select() system call. The timeout parameter was classically used
  1035.     read-only by the system. Some manual page already noted three years
  1036.     ago:
  1037.  
  1038.            select() should probably return the  time  remaining  from
  1039.            the  original timeout, if any, by modifying the time value
  1040.            in place.  This may be implemented in future  versions  of
  1041.            the system.  Thus, it is unwise to assume that the timeout
  1042.            pointer will be unmodified by the select() call.
  1043.  
  1044.     If you do not take this advice seriously you get a zero timeout
  1045.     written back to your timeout structure, which means that future
  1046.     calls to select() using the same timeout structure will immediately
  1047.     return.
  1048.  
  1049.     Fix:
  1050.     Put the timeout value into that structure every time you call select().
  1051.     Change code like
  1052.  
  1053.            struct timeval timeout;
  1054.            timeout.tv_sec = 1; timeout.tv_usec = 0;
  1055.            while (some_condition)
  1056.              { select(n,readfds,writefds,exceptfds,&timeout); }
  1057.  
  1058.     to
  1059.  
  1060.            struct timeval timeout;
  1061.            while (some_condition)
  1062.              { timeout.tv_sec = 1; timeout.tv_usec = 0;
  1063.                select(n,readfds,writefds,exceptfds,&timeout);
  1064.              }
  1065.  
  1066.  
  1067.     Problem 2: Interrupted system calls
  1068.     -----------------------------------
  1069.  
  1070.     Symptom:
  1071.     When a program is stopped using Ctrl-Z and then restarted - or in
  1072.     other situations that generate signals: Ctrl-C interruption,
  1073.     termination of a child process etc. - it complains about
  1074.     "interrupted system call" or "write: unknown error" or things like
  1075.     that.
  1076.  
  1077.     Problem:
  1078.     The system call the program was executing has been interrupted to
  1079.     process the signal, and then it returned -1 and set errno = EINTR.
  1080.     The program then was likely to draw bad conclusions from that.
  1081.  
  1082.     Explanation:
  1083.     Your program has signal handlers installed (using signal(),
  1084.     sigaction() or sigvec()). The signal occurred, and your signal
  1085.     handler was invoked. In other Unix systems, this usually happens
  1086.     asynchronously or in a few slow system calls:
  1087.  
  1088.       When a signal is caught during the execution of system calls such
  1089.       as read(2), write(2), open(2) or ioctl(2) on a slow device (such
  1090.       as a terminal, but not a file), during a pause(2) system call or a
  1091.       wait(2) system call that does not return immediately because a
  1092.       previously stopped or zombie process already exists, the
  1093.       signal-catching function is executed and the interrupted system
  1094.       call then returns a -1 to the calling process with errno set to
  1095.       EINTR.
  1096.  
  1097.     Linux (following POSIX) checks for signals and may execute
  1098.     signal handlers
  1099.         * asynchronously (at a timer tick),
  1100.         * on return from *any* system call,
  1101.         * during the execution of the following system calls:
  1102.           select(),
  1103.           pause(),
  1104.           connect(), accept(),
  1105.           read() on terminals or sockets or pipes or /proc files,
  1106.           write() on terminals or sockets or pipes or line printer,
  1107.           open() on FIFOs or PTYs or serial lines,
  1108.           ioctl() on terminals,
  1109.           fcntl() with command F_SETLKW,
  1110.           wait4(),
  1111.           syslog(),
  1112.           any TCP or NFS operations.
  1113.       [For other operating systems you may have to include the system calls
  1114.        creat(), close(), getmsg(), putmsg(), msgrcv(), msgsnd(), recv(),
  1115.        send(), wait(), waitpid(), wait3(), tcdrain(), sigpause(),
  1116.        semop() to this list.]
  1117.  
  1118.     In the last two cases and assuming the program's signal handler
  1119.     returns, the system call returns -1 and sets errno to EINTR.
  1120.  
  1121.     If the SA_RESTART flag is set for the corresponding signal, however,
  1122.     in most cases the system call is automatically restarted (continued)
  1123.     after execution of the signal handler, and your program won't see
  1124.     any EINTR.
  1125.  
  1126.     You may ask why this is not the default behaviour. This is because
  1127.     returning and setting EINTR is more powerful: it gives your program
  1128.     the opportunity to immediately react on every signal it receives.
  1129.     System calls are no longer "dark tunnels".
  1130.  
  1131.     Note that in some versions of BSD Unix the default behaviour is to
  1132.     restart system calls. To get system calls interrupted you have to
  1133.     use the SV_INTERRUPT or SA_INTERRUPT flag.
  1134.  
  1135.     You may choose between two fixes.
  1136.  
  1137.     Fix 1:
  1138.     For every signal handler that you install, add SA_RESTART to the
  1139.     sigaction flags. For example, change
  1140.  
  1141.             signal (sig_nr, my_signal_handler);
  1142.  
  1143.     to
  1144.  
  1145.              signal (sig_nr, my_signal_handler);
  1146.              { struct sigaction sa;
  1147.                sigaction (sig_nr, (struct sigaction *)0, &sa);
  1148.              #ifdef SA_RESTART
  1149.                sa.sa_flags |= SA_RESTART;
  1150.              #endif
  1151.              #ifdef SA_INTERRUPT
  1152.                sa.sa_flags &= ~ SA_INTERRUPT;
  1153.              #endif
  1154.                sigaction (sig_nr, &sa, (struct sigaction *)0);
  1155.              }
  1156.  
  1157.     Note that while this applies to most system calls, you must still check
  1158.     for EINTR on read(), write(), ioctl(), select(), pause(), connect().
  1159.     Here are two examples for read() and ioctl(),
  1160.  
  1161.     Original piece of code using read()
  1162.  
  1163.              int result;
  1164.              while (len > 0)
  1165.                { result = read(fd,buffer,len);
  1166.                  if (result < 0) break;
  1167.                  buffer += result; len -= result;
  1168.                }
  1169.     becomes
  1170.  
  1171.              int result;
  1172.              while (len > 0)
  1173.                { result = read(fd,buffer,len);
  1174.                  if (result < 0) { if (errno != EINTR) break; }
  1175.                  else { buffer += result; len -= result; }
  1176.                }
  1177.  
  1178.     and;
  1179.  
  1180.     Original piece of code using ioctl()
  1181.  
  1182.              int result;
  1183.              result = ioctl(fd,cmd,addr);
  1184.  
  1185.     becomes
  1186.  
  1187.              int result;
  1188.              do { result = ioctl(fd,cmd,addr); }
  1189.                 while ((result == -1) && (errno == EINTR));
  1190.  
  1191. -------------------------------------------------------------------------------
  1192.  
  1193. 26) I think I have found a bug in gcc/library foo, what do I do now ?
  1194.  
  1195. Ans:    Have you really ?
  1196.     Well first try and narrow the code down to a few lines and see if
  1197.     the program still fails/doesn't work as expected.
  1198.  
  1199.     Does the same behavior occur both with a static and shared version ?
  1200.     (i.e. is it a problem with the DLL libs, or the static libs)
  1201.  
  1202.     Have you access to another platform running gcc ? In other words is
  1203.     the problem a GCC one as opposed to a Linux/GCC one ? If so you may
  1204.     want to post to one or more of the relevant USENET newsgroups
  1205.  
  1206.         gnu.gcc.bug, gnu.gcc.help, gnu.g++.help,
  1207.         comp.lang.c, or comp.lang.c++.
  1208.  
  1209.     Is the problem in the math emulator ? If so you could email
  1210.     Bill Metzenthen (apm233m@vaxc.cc.monash.edu.au) the writer of the
  1211.     emulator code.
  1212.  
  1213.     Finally you could try emailing linux-bugs@sunsite.unc.edu, myself
  1214.     (mitch@Dubai.Sun.COM) or even HLU.
  1215.  
  1216. -------------------------------------------------------------------------------
  1217.  
  1218. 27) Why are shared libraries so large in comparison to their static counterparts ?
  1219.  
  1220. Ans:    Shared libraries reserve space for future expansion in the form of
  1221.     `holes' which can be made to take no disk space. A simple `cp' call
  1222.     or using the program `makehole' will achieve this.
  1223.     With a.out DLL's you can also strip them after building as the
  1224.     address's are in fixed locations. Do not attempt to strip ELF
  1225.     libraries.
  1226.  
  1227. -------------------------------------------------------------------------------
  1228.  
  1229. 28) What are .sa file I see in /usr/lib ?
  1230.  
  1231. Ans:    The .sa files are the stubs to the shared DLL libraries and contain
  1232.     all exported data from a certain library, and pointers to functions
  1233.     required for run time linking. See also question (13).
  1234.  
  1235.     An ELF library does not have a corresponding stub as all the exported
  1236.     data is in the shared object.
  1237.  
  1238. -------------------------------------------------------------------------------
  1239.  
  1240. 29) Where can I get Objective C for Linux ?
  1241.  
  1242. Ans:    Objective C is in releases of gcc for Linux versions gcc-2.4.0 and
  1243.     above. This is not currently fully tested at the moment. The latest
  1244.     version may be obtained from
  1245.         tsx-11.mit.edu:/pub/linux/packages/GCC/gcc-2.6.2-p2.tar.gz
  1246.  
  1247. -------------------------------------------------------------------------------
  1248.  
  1249. 30) What does the message "Internal compiler error: cc1 got fatal signal 11,4" mean ?
  1250.  
  1251. Ans:    Gcc is probably the biggest memory hog you're likely to run on your
  1252.     machine and it will surely eat up a lot of your RAM. Usually a fatal
  1253.     signal 11 will mean some sort of parity errors in your RAM or other
  1254.     hardware faults. I had this once when `cc1' got corrupted due to a
  1255.     race condition and bad blocks on my hard disk. There have also been
  1256.     reports that overheating chips, (not french fries), can also produce
  1257.     such errors. And watch for poor IDE controller/drive combos that
  1258.     are being run faster than the standard 8MHz AT bus clock. These
  1259.     can give the same errors by causing corruption of the swap space.
  1260.  
  1261.     Usually, a signal 11 (segmentation violation) means that a process
  1262.     tried to access memory out of its process space, or tried to write
  1263.     into a read-only location.  Sometimes, this signal is caused by
  1264.     software bugs, not by hardware faults (or your system would hang
  1265.     repeatedly, because the same thing happened to the kernel).  With
  1266.     gcc 2.3.3, some people could reproduce a lot of "signal 11"'s.
  1267.  
  1268.     A "fatal signal 4" has been reported to be generated due to lack of
  1269.     memory (happened on a 4MB system).
  1270.  
  1271.     Also it can mean a failure in one of the `ld' or `as' stages. Try
  1272.     recompiling whatever with a -v flag to gcc and see if it is failing
  1273.     in one of the cc1, cpp, as or ld stages possibly.
  1274.  
  1275. -------------------------------------------------------------------------------
  1276.  
  1277. 31) What is a libc-lite ?
  1278.  
  1279. Ans:    A libc-lite is a light-weight version of the libc library built
  1280.     such that it will fit on a floppy and suffice for all of the most
  1281.     menial of UNIX tasks. It does *not* include curses, dbm, termcap etc
  1282.     code. If your /lib/libc.so.4 is linked to a lite lib, you are advised
  1283.     to replace it with a full version. See question (3) on where it is
  1284.     available from.
  1285.  
  1286. -------------------------------------------------------------------------------
  1287.  
  1288. 32) Do Linux libraries have SHADOW Password support, and how do I switch it on/off ?
  1289.  
  1290. Ans:    Yes.
  1291.     You need to compile programs with the defines SHADOW_PWD in place,
  1292.     and link it with the shadow library - available separately in:
  1293.         sunsite.unc.edu:/pub/Linux/system/Admin/shadow-3.3.1.tar.gz
  1294.     This means adding -DSHADOW_PWD to the CFLAGS line in the Makefile, and
  1295.     -lshadow in the LDFLAGS line.
  1296.  
  1297.     You may also have to change the source a bit, as the "crypt()" in
  1298.     the shadow support is implemented as a macro and not a function.
  1299.     Hence any "extern int crypt()" may trip it up.
  1300.  
  1301.     This means that there is NO WAY of switching shadow password'ing
  1302.     on/off without having to compile *all* necessary binaries which use
  1303.     the getpwent(), setpwent() etc routines.
  1304.  
  1305.     NOTE: At some point in the future the shadow routines may be
  1306.     integrated into the standard C library.
  1307.  
  1308. -------------------------------------------------------------------------------
  1309.  
  1310. 33) Can't find math.h routines ! My program compiles but cannot find log(), sin(), etc.., HELP !!
  1311.  
  1312. Ans:    When you compile a program using certain functions, you *must* also
  1313.     link the program to the appropriate library. This means for math
  1314.     functions you have to include libm.a at the linker stage, i.e. add
  1315.     -lm to the LDFLAGS, for curses functions add -lcurses, for dbm
  1316.     functions add -ldbm etc...
  1317.  
  1318.     Always put the -lm flag after the objects. So this is no good:
  1319.         % gcc -lm -o math_prog math_prog.c
  1320.     as the math functions will not be resolved. Instead do:
  1321.         % gcc -o math_prog math_prog.c -lm
  1322.  
  1323. -------------------------------------------------------------------------------
  1324.  
  1325. 34) Is there a manual for GCC? If so, where do I get it, and how do I print it out ?
  1326.  
  1327. Ans:    There is a file on sunsite in the GCC directory
  1328.         sunsite.unc.edu:/pub/Linux/GCC/gcc-man.tar.z
  1329.  
  1330.     This file contains the man pages cccp.1, cpp.1, g++.1 and gcc.1.
  1331.  
  1332.     If you want a full printed manual for GCC, then you will have
  1333.     to get the full source from your local ftp site that carries GCC
  1334.     and other FSF goodies. You will require TeX to make the manual from
  1335.     the GCC source distribution. 
  1336.   
  1337.     If it is the library function calls you are looking for, then you
  1338.     need to get the full source for glibc. This will be on the same
  1339.     ftp archive that you found the sources for GCC. Again, you will
  1340.     need TeX to generate the manual. Be warned that this manual is
  1341.     about 900 pages long. Save a tree and keep it online as a dvi file.
  1342.  
  1343.     Both of the above packages also come with "info" files, that can be
  1344.     viewed using Gnu info, xinfo, or emacs. "info" files are a hyper-
  1345.     text based information system.
  1346.  
  1347.  
  1348. -------------------------------------------------------------------------------
  1349.  
  1350. 35) I get the message "Undefined symbol _bsd_ioctl". Where is this anyhow ?
  1351.  
  1352. Ans:    You forgot to include the bsd library /usr/lib/libbsd.a into your
  1353.     program at the linking stage.
  1354.  
  1355.     Solution: Add -lbsd to the Makefile LDFLAGS line. (or add it
  1356.     manually if it doesn't have a LDFLAGS line)
  1357.  
  1358. -------------------------------------------------------------------------------
  1359.  
  1360. 36) If I upgrade versions, can I get rid of the old stuff from /usr/lib/gcc-lib/i[34]86-linux/<old-version> ?
  1361.  
  1362. Ans:    Well unless you are testing gcc releases it is fairly safe to get
  1363.     rid of any older versions in that directory. You can compile with
  1364.     older versions of gcc using "gcc -V <old-version>
  1365.  
  1366. -------------------------------------------------------------------------------
  1367.  
  1368. 37) [HELP] where is libipc.a ? Needed for dosemu 0.49..
  1369.  
  1370. Ans:    The Inter Process Communication (IPC) functions are included as
  1371.     standard in libc as of libc.so.4.4.1. This means if you have
  1372.     libc.so.4.4.1 and above, you do not need -lipc and can remove this
  1373.     line from the Makefile. If you do not have libc.so.4.4.1 and its
  1374.     related stub libc.sa then you need to upgrade you libraries.
  1375.  
  1376. -------------------------------------------------------------------------------
  1377.  
  1378. 38) XXX won't compile: _daemon undefined, help!!
  1379.  
  1380. Ans:    daemon() is in libbsd.a. Just add -lbsd to your Makefile LDFLAGS line.
  1381.  
  1382. -------------------------------------------------------------------------------
  1383.  
  1384. 39) [HELP] ar and libraries. Linking fails although symbol appears in library.
  1385.  
  1386. Ans:    There is a known bug in `ar' where sometimes `ranlib' does not
  1387.     generate a correct table. This can be worked around with the
  1388.     commands
  1389.  
  1390.         % ar -dv libfoo.a __.SYMDEF
  1391.         % ranlib libfoo.a
  1392.  
  1393. -------------------------------------------------------------------------------
  1394.  
  1395. 40) HELP! newbie gets warning message "libc.so.4: incompat. minor ver no."
  1396.  
  1397. Ans:    You need a shared library upgrade. See questions (12), (3) and
  1398.         (55) for more details.
  1399.  
  1400. -------------------------------------------------------------------------------
  1401.  
  1402. 41) Where can I find `lint' to check my c programs before compilation ?
  1403.  
  1404. Ans:    There is no `lint' or the likes for checking programs. Instead use the
  1405.     plethora of gcc options for checking your programs. Read the manual
  1406.     pages for the variety options.
  1407.  
  1408.     The most useful
  1409.  
  1410.         % gcc -Wall foo.c
  1411.  
  1412.     will warn you of most of the possible problems that might occur.
  1413.  
  1414.     Alternatively a PD lint is available from
  1415.  
  1416.         larch.lcs.mit.edu:/pub/Larch/lclint
  1417.  
  1418. -------------------------------------------------------------------------------
  1419.  
  1420. 42) My program needs sgtty.h where is it ?
  1421.  
  1422. Ans:    It is in /usr/include/bsd directory. So just add the line
  1423.  
  1424.         -I/usr/include/bsd
  1425.  
  1426.     to your CFLAGS line in the Makefile when compiling.
  1427.  
  1428. -------------------------------------------------------------------------------
  1429.  
  1430. 43) How do I stop or start core files being produced on SIGSEGV's ?
  1431.  
  1432. Ans:    This is not really a GCC question, but more a shell one. Anyhow
  1433.     to stop core files being produced totally:
  1434.  
  1435.         In C-shell `csh' (tcsh)
  1436.             % limit core 0
  1437.         In Bourne shell `sh' (bash)
  1438.             % ulimit -c 0
  1439.  
  1440.     To start corefiles when you receive signal 11 (SEGV):
  1441.  
  1442.         In C-shell `csh' (tcsh)
  1443.             % limit core unlimited
  1444.         In Bourne shell `sh' (bash)
  1445.             % ulimit -c unlimited
  1446.  
  1447. -------------------------------------------------------------------------------
  1448.  
  1449. 44) What does the message "can't load dynamic linker `/lib/ld.so'" mean ?
  1450.  
  1451. Ans:    This means you haven't installed the dynamic linker/loader. See
  1452.     question (4) under libld.so on where to obtain this from.
  1453.  
  1454. -------------------------------------------------------------------------------
  1455.  
  1456. 45) What is the difference between -O2 and -O6 optimizations ?
  1457.  
  1458. Ans:    Nothing at present. If you look at the source code for
  1459.     GCC (eww! yuck!) with an i386/i486 host/target, you will see 
  1460.     that -Ox for x>=2 does the same thing. In fact it is a bad
  1461.     thing to use x>2 in your Makefiles, because if GCC implements
  1462.     -O3 on Intel targets in the future, it may be an optimization
  1463.     that breaks your code.
  1464.  
  1465. -------------------------------------------------------------------------------
  1466.  
  1467. 46) How can I check an unknown binary to see if it is a trojan horse ?
  1468.  
  1469. Ans:    First, if you are worried that it is going to hose your machine,
  1470.     *don't* run it. (At least not as root!) Try and find the source
  1471.     and recompile it. Other than that, you might be able to get some
  1472.     information on it by typing "strings <filename> | less". If you
  1473.     are game enough to run it, you can use `strace' to see if it
  1474.     is doing anything nasty. See question (17) on its whereabouts.
  1475.  
  1476. -------------------------------------------------------------------------------
  1477.  
  1478. 47) Where are the sources to the C library - how do I rebuild it ?
  1479.  
  1480. Ans:    Look in
  1481.         tsx-11.mit.edu:/pub/linux/pagkages/GCC/libc-4.6.27.tar.gz
  1482.  
  1483.     If you want shared libraries you will also need the dll tools package.
  1484.     See question (5) on where to obtain this from.
  1485.  
  1486.     To rebuild, unpack the sources, make sure you have the corresponding
  1487.     include files for that version of the C library, and then under
  1488.     libc-linux directory do the following
  1489.  
  1490.         % ./configure
  1491.  
  1492.     Answer all the questions at this point. If you are building on a 
  1493.     native linux machine (i.e not cross-compiling) you can just type
  1494.     <return> at this point (i.e. accept the default values). Then type
  1495.  
  1496.         % make
  1497.  
  1498.     NOTE: If you are cross-compiling, it is probably a wise idea to keep
  1499.     a copy of the configure generated file `config.in' for future use.
  1500.     You can just copy the old version into the libc-linux directory and
  1501.     type `make'.
  1502.  
  1503. -------------------------------------------------------------------------------
  1504.  
  1505. 48) Where are the definitions of FD_* stuff ?
  1506.  
  1507. Ans:    Just include <sys/time.h> and these macros will be included.
  1508.  
  1509. -------------------------------------------------------------------------------
  1510.  
  1511. 49) When linking with option -g I get undefined ___fpu_control and ___setfpucw ?
  1512.  
  1513.     /usr/lib/crt0.o Undefined symbol ___fpu_control reference from text segment.
  1514.      /usr/lib/crt0.o Undefined symbol ___setfpucw reference from text segment.
  1515.  
  1516.     what's wrong?
  1517.  
  1518. Ans:     You have updated your crt0.o libc.sa and libc.a from a recent copy
  1519.     of the linux libc, but you have still an old libg.a around.
  1520.  
  1521.     If you really want to get a static binary (this is implied by -g)
  1522.     with a debug library, you should get and install libg.a.
  1523.     See question (15) on the whereabouts of this.
  1524.  
  1525. -------------------------------------------------------------------------------
  1526.  
  1527. 50) Where can I get the tools to internationalize my library/application ?
  1528.  
  1529. Ans:    Get the file
  1530.         sunsite.unc.edu:/pub/Linux/utils/nls/cat-pack.tar.gz
  1531.     and follow the instructions there.
  1532.  
  1533.     User contributed catalogs in various languages may be found in
  1534.         sunsite.unc.edu:/pub/Linux/utils/nls/catalogs
  1535.     and placed in the Incoming directory under there.
  1536.  
  1537.     NOTE: Internationalization tools and functions are only available in
  1538.         libraries greater than version 4.4.4 (i.e. libc.so.4.5.x and 
  1539.         above)
  1540.  
  1541.     NOTE: In this context `Internationalization' is used loosely and as of
  1542.         linux pl14 supports only Latin-1/ISO-8859-1 (european) and
  1543.         KOI-8 (russian) locales.
  1544.  
  1545. -------------------------------------------------------------------------------
  1546.  
  1547. 51) The DLL tool `mkimage' fails to find libgcc. Help!!!
  1548.  
  1549. Ans:    As of libc.so.4.5.x and above, libgcc is no longer shared. Hence you
  1550.     must replace occurrences of `-lgcc' on the mkimage line with
  1551.  
  1552.         `gcc -print-libgcc-file-name`
  1553.  
  1554.     or for short
  1555.  
  1556.         `gcc --print-libgcc`
  1557.     
  1558.     With the backquotes intact.
  1559.  
  1560. -------------------------------------------------------------------------------
  1561.  
  1562. 52) How do I get rid of "__NEEDS_SHRLIB_libc_4 multiply defined" messages ?
  1563.  
  1564. Ans:    As of libc.so.4.5.x and above, libgcc is no longer shared. Thus you
  1565.     MUST delete all /usr/lib/libgcc* files.
  1566.  
  1567.         % rm -f /usr/lib/libgcc*
  1568.  
  1569. -------------------------------------------------------------------------------
  1570.  
  1571. 53) What is this QMAGIC thing everyone is talking about ?
  1572.  
  1573. Ans:    QMAGIC is an executable format just like your standard a.out (which
  1574.     are ZMAGIC) binaries, but which leaves the first page unmapped. This
  1575.     allows for easier NULL dereference trapping as no mapping exists in
  1576.     then range 0-4096. As a side effect your binaries are nominally
  1577.     smaller as well (~1K).
  1578.  
  1579.     Your `file' command will be able to identify a QMAGIC binary if the
  1580.     proper entry has been added to your /etc/magic file. I have
  1581.     distributed suitable entries to most channels.
  1582.  
  1583. -------------------------------------------------------------------------------
  1584.  
  1585. 54) How do I generate a QMAGIC executable/library ?
  1586.  
  1587. Ans:    You need the latest `ld' binary or patches to the source to be able
  1588.     to generate QMAGIC executables. This will be distributed in the
  1589.     `binutils-2.5.2.6.bin.tar.gz' file - See question (2).
  1590.  
  1591.     To build a QMAGIC executable:
  1592.  
  1593.       Add one of the following to your LDFLAGS line in the Makefile
  1594.         LDFLAGS = -Wl,-qmagic
  1595.       or
  1596.         LDFLAGS = -Xlinker -qmagic
  1597.  
  1598.     To build a QMAGIC library:
  1599.  
  1600.       Supported with the `mkimage' tool from the tools-2.16.tar.gz package
  1601.       onwards you may use the "-qmagic" flag to the linker on the
  1602.       "mkimage" command line.
  1603.  
  1604.     Note that with newer versions of `ld', QMAGIC is the default a.out
  1605.     format. ZMAGIC executables are no longer supported (although they
  1606.     will succesfully run).
  1607.  
  1608. -------------------------------------------------------------------------------
  1609.  
  1610. 55) Is it possible to turn the "warning using incompatible library version xxx" messages off ?
  1611.  
  1612. Ans:    Yes.
  1613.     If you have ld.so version 1.4 and above you may set the environment
  1614.     variable LD_NOWARN to suppress warning messages. Note: fatal mesages
  1615.     are still output.
  1616.  
  1617.     In csh (tcsh):
  1618.         setenv LD_NOWARN
  1619.     In sh (bash):
  1620.         export LD_NOWARN=true
  1621.  
  1622. -------------------------------------------------------------------------------
  1623.  
  1624. 56) Are GNU's glibc 1.08 texinfo manual pages relevant to Linux's libc?
  1625.  
  1626. Ans:    Yes, except for the stdio internals.
  1627.  
  1628. -------------------------------------------------------------------------------
  1629.  
  1630. 57) Can I sell my application if it was compiled within linux ??
  1631.  
  1632.     (a) It is legal to sell your applications.  You may take as much
  1633.         money as you want.
  1634.  
  1635.     (b) Simply using a GNU tool to develop your application does not
  1636.         affect your copyright to your applications.  This includes
  1637.         using g++ and gcc.
  1638.  
  1639.     (c) However, your copyright is affected if you include code from
  1640.         other GNU applications into yours.  In this case, you have
  1641.         to put the resulting ("derived") work under the GNU copyleft.
  1642.         That means, that you have to release source code upon request,
  1643.         and that your customer(s) may distribute (and/or sell!) copies
  1644.         of your source code and/or binary.
  1645.  
  1646.     (d) 99% of all C programs written are linked against the C
  1647.         library.  Linking means, that you include GNU code into
  1648.         your program.  However, the C library is released under
  1649.         special terms (GNU Library Public License, GLPL), which
  1650.         allows linking as an exception to what is said in c).
  1651.  
  1652.         You can link with the C library at will, but you have to
  1653.         provide your program in a form, that the user can update
  1654.         the library.  In case of shared linking, this is not a
  1655.         problem, but if you want (or must) link with static
  1656.         libraries, you must provide your program in a form, which
  1657.         has not yet been linked with the static library (say, link
  1658.         all your .o-files into one big .o using "ld".  Take a look
  1659.         at the kernel sources to see how it works).
  1660.  
  1661.     (e) What is said at point a) is always true: you may sell your
  1662.         application, whether or not it has to be distributed under
  1663.         the GNU copyleft, for as much money as you want.
  1664.  
  1665. -------------------------------------------------------------------------------
  1666.  
  1667. 58) Why do I get an "Assertion failure" message when rebuilding a DLL ??
  1668.  
  1669. Ans:    This cryptic message most probably means that one of your jump
  1670.     table slots has overflowed because too little space has been
  1671.     reserved in the original jump.vars file.
  1672.  
  1673.     You can locate the culprit(s) by running the `getsize' command
  1674.     provided in the tools-2.16.tar.gz package. See question (5) on where
  1675.     to obtain this from.
  1676.  
  1677.     The only solution in this case may be to bump up the major version
  1678.     number of the library forcing it to be backward incompatible.
  1679.  
  1680. -------------------------------------------------------------------------------
  1681.  
  1682. 59) Can I build DOS executables under linux ?
  1683.  
  1684. Ans:    Get a life !!
  1685.     Anyway I have been told that it is somewhat possible by using the
  1686.     "emx" package or the "go" extender.
  1687.  
  1688.     Please look in
  1689.  
  1690.         sunsite.unc.edu:/pub/Linux/devel/msdos
  1691.  
  1692.     I have not tested this and cannot vouch for its abilities.
  1693.  
  1694. -------------------------------------------------------------------------------
  1695.  
  1696. 60) Is -fpic - i.e PIC (position independent code) supported on linux. ?
  1697.  
  1698. Ans:    Yes but only with ELF executables. a.out PIC is not supported.
  1699.     This is currently in the testing stage, but works very well.
  1700.  
  1701. -------------------------------------------------------------------------------
  1702.  
  1703. 61) What is this ELF thing anyway ?
  1704.  
  1705. Ans: This section is from the document '/news-archives/comp.sys.sun.misc'.
  1706.  
  1707.     ELF ("Extensible Linking Format) is the "new, improved" object file
  1708.     format introduced in SVR4. ELF is much more powerful than straight 
  1709.     COFF, in that it *is* user-extensible. ELF views an object-file as
  1710.     an arbitarily long list of sections (rather than an array of fixed
  1711.     size entities), these sections, unlike in COFF, do not HAVE to be in
  1712.     a certain place and do not HAVE to come in any specific order etc.
  1713.     Users can add new sections to object-files if they wish to
  1714.     capture new data. ELF also has a far more powerful debugging format
  1715.     called DWARF (Debugging With Attribute Record Format) - not currently
  1716.     fully supported on linux (but work is underway). A linked list
  1717.     of DWARF DIEs (or Debugging Information Entries) forms the .debug
  1718.     section in ELF. Instead of being a collection of small, fixed-size
  1719.     information records, DWARF DIEs each contain an arbitrarily long
  1720.     list of complex attributes and are written out as a scope-based tree
  1721.     of program data. DIEs can capture a large amount of information that
  1722.     the COFF .debug section simply couldn't (like C++ inheritance graphs
  1723.     etc.).
  1724.  
  1725.     ELF files are accessed via the SVR4 (Solaris 2.0 ?) ELF access
  1726.     library, which provides an easy and fast interface to the more gory
  1727.     parts of ELF. One of the major boons in using the ELF access library
  1728.     is that you will never need to look at an ELF file qua. UNIX file, it
  1729.     is accessed as an Elf *, after an elf_open() call and from then on,
  1730.     you perform elf_foobar() calls on its components instead of messing
  1731.     about with its actual on-disk image (something many COFFers did with
  1732.     impunity). ELF is now supported by GNU gdb-4.12 (and above) on linux
  1733.     and many other tools and is definitely something to look forward to
  1734.     in linux. You may compile gdb with
  1735.         ./configure i386-sysv-linuxelf
  1736.  
  1737.     You may find more doccumentation (postscript) on version 1.1 of
  1738.     ELF from
  1739.  
  1740.         tsx-11.mit.edu:/pub/linux/packages/GCC/ELF.doc.tar.gz
  1741.  
  1742. -------------------------------------------------------------------------------
  1743.  
  1744. 62) How do I build an ELF libc ?
  1745.  
  1746. Ans:    Get the libc sources (See question (47) on where to obtain it) and
  1747.     then you simply need to do
  1748.  
  1749.         % make ELF=true
  1750.  
  1751.     after running
  1752.  
  1753.         % ./configure
  1754.  
  1755.     This is assuming you have installed the ELF gcc/ld/as etc.. as
  1756.     indicated in question (60) above.
  1757.  
  1758.     NOTE: This is only supported for libc versions 4.6.x
  1759.  
  1760. -------------------------------------------------------------------------------
  1761.  
  1762. 63) Why does the execl() call fail on linux and just print out libc.so.4 messages ?
  1763.  
  1764. Ans:    The execl() call does NOT fail on linux. It basically means your
  1765.     application does not strictly conform to POSIX.1. You have just not
  1766.     read the manpage correctly and are not providing execl() with the
  1767.     right parameters. Here is a quote from the manpage:
  1768.  
  1769.          Two interfaces are available.   execl()  is  useful  when  a
  1770.          known  file  with known arguments is being called; the argu-
  1771.          ments to execl() are the character strings constituting  the
  1772.          file and the arguments; the first argument is conventionally
  1773.          the same as the file name (or its last component).  A  (char
  1774.          *)0  argument  must end the argument list.  The cast to type
  1775.          char * insures portability.
  1776.  
  1777.     So your execl() should provide a *minimum* of two arguments like
  1778.  
  1779.         execl("/bin/ls","ls",NULL);
  1780.  
  1781.     instead of just
  1782.  
  1783.         execl("/bin/ls", NULL);
  1784.  
  1785.     The single argument execl() command is reserved for the use of
  1786.     identifying the executable dependencies (i.e. its shared libraries)
  1787.     or whether it is static.
  1788.  
  1789. -------------------------------------------------------------------------------
  1790.  
  1791. 64) Can I preload objects with a.out binaries (a.la Sun LD_PRELOAD) ?
  1792.  
  1793. Ans:    Yes but only if you are using ld.so version 1.5.2 or above. See 
  1794.     question (4) under libld.so on where to obtain this from.
  1795.  
  1796. -------------------------------------------------------------------------------
  1797.  
  1798. 65) With the new gcc I cannot seem to generate ZMAGIC binaries ?
  1799.  
  1800. Ans:    Well it's not really gcc but the new binutils which do not support
  1801.     the creation of ZMAGIC binaries. Support will continue unhindered
  1802.     for the execution of these binaries so old programs will still
  1803.     be able to work.
  1804.  
  1805. -------------------------------------------------------------------------------
  1806.  
  1807. 66) perl-5.00 needs dlopen() and friends. Where are they anyway ?
  1808.  
  1809. Ans:    dlopen() and friends are only supported in the ELF executable format.
  1810.     ELF compiler and utilities will be available shortly. They are
  1811.     undergoing final testing now (Dec `94). Perl-5.00 has been succesfully
  1812.     built using ELF format with complete dynamic loading facilities.
  1813.  
  1814. -------------------------------------------------------------------------------
  1815.  
  1816. 67) Where can I get more info about ELF ?
  1817.  
  1818. Ans:    Daniel Barlow has put up a URL describing some more detail about ELF.
  1819.     Set your URL to the location
  1820.  
  1821.         http://sable.ox.ac.uk/~jo95004/elf.html
  1822.  
  1823.  
  1824. ===============================================================================
  1825.  
  1826.                        Acknowledgements: (in no order)
  1827.  
  1828.                                   H.J.Lu
  1829.                                Dirk Hohndel
  1830.                                 David Engel
  1831.                               Eric Youngdale
  1832.                              Bill Metzenthen
  1833.                                 Rik Faith
  1834.                               Steven S. Dick
  1835.                                Bruno Haible
  1836.                                Andrew Tefft
  1837.                                 Kai Petzke
  1838.                               Tuomas J Lukka
  1839.                              Fergus Henderson
  1840.                               Paul Gortmaker
  1841.                                Olaf Flebbe
  1842.                              Jens Schweikhardt
  1843.                                Bruce Evans
  1844.                                Axel Boldt
  1845.  
  1846.                               and of course
  1847.  
  1848.                               Linus Torvalds
  1849.  
  1850. ===============================================================================
  1851.  
  1852. N.B. Please do not feel offended if your name has not appeared here and you
  1853. have contributed however significantly/insignificantly. It is entirely my
  1854. fault. Email me and I will rectify it.
  1855.  
  1856. ===============================================================================
  1857.  
  1858. Please help in making this FAQ the definitive answer repository of Linux GCC
  1859. queries by e-mailing questions, (and answers if you have them), corrections
  1860. and additions to me
  1861.  
  1862.                     Mitchum DSouza <mitch@Dubai.Sun.COM>
  1863.