home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / f / fortran / GCCmain / !gcc / docs / !Intro next >
Encoding:
Text File  |  1996-11-25  |  20.4 KB  |  559 lines

  1. Introduction to GCC for RISC OS
  2. ===============================
  3.  
  4.  
  5. This is a short introduction to GCC. Information concerning a specific
  6. compiler can be found elsewhere. The documents supplied with each GCC
  7. compatible compiler do not provide an introduction to programming in that
  8. particular language, for that you will have to get a text book on the language.
  9.  
  10. GCC is a small program providing a simple and consistent front end to many
  11. compilers. Currently, the compilers supported are GNU C, GNU C++,
  12. GNU Objective-C, GNU Fortran, GNU GNAT Ada and GNU Pascal. As more compilers
  13. are released, GCC will support those too.
  14.  
  15. GCC is covered by the FSF General Public License (see the files docs.COPYING
  16. and docs.COPYINGLIB for details).
  17.  
  18. This port of GCC is © Copyright 1996 Nick Burrett
  19.  
  20. As with all GNU programs, THERE IS NO WARRANTY OF ANY SORT
  21.  
  22. The GCC distribution is a support archive providing the files common to all
  23. of the above compilers. This includes:
  24.   - an assembler (as)
  25.   - a linker front end (ld)
  26.   - the compiler front end (gcc)
  27.   - a C preprocessor (cpp)
  28.   - a runtime library (gcc.o.libgcc)
  29.   - gcc specific header files (gcc.h)
  30.   - this document and others (gcc.docs)
  31.  
  32. An Acorn Object Format linker is not provided but there exists a Public
  33. Domain linker called Drlink. Details on where to obtain this are detailed
  34. at the end of this document.
  35.  
  36. Thanks go to various people for the help and assistance that they have
  37. given me. Notably:
  38.  
  39. Peter Burwood for bug fixes, enhancements, testing, suggestions and more...
  40. Niklas RÖjemo, for the assembler 'as'
  41. Huw Rogers and Simon Callan, for UnixLib.
  42. Jochen Scharrlach for the RISC OS GCC FAQ.
  43. Cy Brooker for the DDEUtilsCy module.
  44.  
  45.  
  46. Installation
  47. ------------
  48.  
  49. To install GCC just copy the contents of this archive onto your hard disc.
  50. Running !gcc will setup Run$Path to automatically search for the compiler
  51. tools.
  52.  
  53. If you wish to separate the distribution, the files in !gcc.bin should be
  54. copied so that they are in your run path, while GCC$Path and GPP$Path should
  55. point to where the GCC and GPP directories are respectively.
  56.  
  57. Note, there is no linker or run-time library supplied, but Drlink and
  58. Unixlib 3.7a are useable with GCC and their location is given below.
  59.  
  60. GCC uses a linker front end, LD. This will search for both drlink and link
  61. on the current Run$Path and in that order.
  62.  
  63. To add GNU compilers to the GCC front end, simply merge the directories
  64. together on your hard disc i.e. by dragging the compiler's !gcc directory
  65. over the gcc front end's !gcc directory.
  66.  
  67. This completes installation, and GCC may be used simply by typing
  68. 'gcc' at the CLI prompt.
  69.  
  70.  
  71. Simple compilations
  72. -------------------
  73.  
  74. This assumes you have actually installed a compiler.
  75.  
  76. Source files are stored in the standard ASCII Text format and kept in a
  77. directory that is relevant for the language of your program. For example,
  78. C programs are stored in directory 'c' and C++ programs are stored in 'cc'.
  79.  
  80. GCC supports both RISC OS and UNIX format filenames.
  81.  
  82. For simple use, all that is needed is to set up a command line prompt and
  83. ensure there is enough free memory to run the compiler (details of memory
  84. requirements vary between compilers).
  85.  
  86. To compile a C program just type:
  87.  
  88.    gcc c.hello
  89.  
  90. This will compile, assemble and link the source 'c.hello' to produce an
  91. executable called '!RunImage', which can be run immediately.
  92.  
  93. Adding the switch '-o' to the command line, it's possible to specify a
  94. place to store the resultant file:
  95.  
  96.   gcc c.hello -o hello
  97.  
  98. This will comple, assemble and link the source 'c.hello' to produce an
  99. executable called 'hello', which can be run immediately.
  100.  
  101. It is possible to compile several sources at one go, mixing C sources in
  102. the same program, using a command line of:
  103.  
  104.    gcc c.file1 c.file2 c.file3 c.file4
  105.  
  106. Again, this will compile, assemble and link all the sources to produce the
  107. '!RunImage' executable.
  108.  
  109. To compile to the object form, use the -c switch. i.e.
  110.  
  111.         gcc -c c.file
  112.  
  113. will compile and assemble 'c.file' to 'o.file'.
  114.  
  115. Switches
  116. --------
  117.  
  118. This is a list of the simpler, standard switches for GCC. Full details can
  119. be obtained from the docs.gccuser manual. Please see below for the ARM
  120. specific switches since these have altered from the original gcc version.
  121.  
  122. The switches described below are useable with any GNU compiler.
  123.  
  124. -c              compile and assemble the source to the object file
  125. -S              compile the source to assembler code
  126. -E              preprocess the source file
  127. -o <file>       put the resulting output into <file>
  128. -O              apply some optimisations to the output
  129. -O2             apply full optimisation.
  130. -O3        full optimisation and inline small functions as well.
  131.  
  132. There are some additional ARM specific switches.
  133.  
  134.  -mapcs, -mapcs-frame
  135.    target for ARM Procedure Call Standard stack frames.
  136.  
  137.  -mpoke-function-name
  138.    place the name of the current function before the start of the function
  139.    to allow the post mortem debugger to print a readable backtrace.
  140.    Using it's opposite will reduce code size by about 3.5%.
  141.  
  142.  -mfpe
  143.    prevents instruction scheduling of floating point instructions since it
  144.    increases compile time and the benefits acheived make no difference through
  145.    the FPE.
  146.  
  147.  -mapcs-32
  148.    target the APCS-32 bit standard. Condition flags are assumed to be corrupted
  149.    by function calls in this mode.
  150.  
  151.  -mapcs-stack-check
  152.    provide explicit stack checking on entry to each function which allocates
  153.    temporary variables on the stack.
  154.  
  155.  -mapcs-strict
  156.    make the compiler conform strictly to the APCS even in the cases where
  157.    stack frames do not need to be set up.
  158.  
  159.  -mshort-load-bytes, -mno-short-load-words
  160.    if the MMU traps unaligned word accesses, shorts must be loaded
  161.    byte-at-a-time so this flag should be set.
  162.  
  163. RISC OS specific options
  164.  
  165.  -mthrowback
  166.    send errors to a text editor capable of receiving 'throwbacks'.
  167.    Error throwbacks will only occur when the DDEUtils module has previously
  168.    been loaded.
  169.  
  170.  -mstubs
  171.    compiles to target SharedCLibrary and tells the linker to link with
  172.    stubs instead of UnixLib.
  173.  
  174.  -munixlib
  175.    tell the linker to target UnixLib instead of the SharedCLibrary
  176.  
  177.  -mamu
  178.    Generate the file !Depend which contains a list of all the source
  179.    files that the produced object depend on. This is intended for use
  180.    with amu, which edit the makefile to include these after the
  181.    '# Dynamic Dependencies' line.
  182.  
  183.  
  184. At the time of release the use of -munique-areas is not guaranteed to work
  185. in all cases. -mapcs-strict is an option used for internal compiler
  186. debugging.
  187.  
  188.  
  189. LD
  190. --
  191.  
  192. LD is a front end to Link, which converts the LD as generated by gcc to the
  193. Acorn Image Format. LD only recognises a few options, the rest are passed
  194. directly through to Link. LD also attempts to convert Unix format names to
  195. RISC OS format. The options that LD recognises are:
  196.  
  197. -L <dir>
  198.   This specifies a directory/path that LD is to use when searching
  199.   for libraries. <dir> must be either a path (i.e gcc:, etc), or it
  200.   must be a valid Unix/RISC OS directory name, ending in either '/'
  201.   or '.'. Directories are searched in the order that they are
  202.   specified.
  203.  
  204. -l <file>
  205.   This specifies the name of a library file which LD will search the
  206.   library directories for. This may either be a complete filename (i.e
  207.   C:o.stubs) or just the leaf name, in which case, LD will search
  208.   though the specified library directories for the file o.lib<file>
  209.   and o.<file> if the former isn't found.
  210.  
  211. -o <file>
  212.   This specifies the object filename.
  213.  
  214. -M
  215.   Print a link map to stderr.
  216.  
  217. -Map <file>
  218.   Print a link map to <file>.
  219.  
  220. -t
  221.   Print the names of the input files as the linker processes them.
  222.  
  223. -via <file>
  224.   <file> contains a list of object files to be included in the link process.
  225.  
  226. -version
  227.   Print the version number of 'ld'.
  228.   
  229.  
  230. The sequence '-Lgcc: -LC: -lgcc -lstubs' will cause LD to look for the files
  231. gcc:o.gcc, c:o.gcc, gcc:o.stubs and c:o.stubs, taking the first gcc and
  232. stubs files that it finds.
  233.  
  234. Linker options can be passed from GCC to link using -Wl and -XLinker options.
  235.  
  236. The linker must be in the default Run$Path, as LD does not handle the -B
  237. command. Please note that it is best to define GCC$Linker in the !gcc.!run
  238. file to point to the linker you want to use. e.g.
  239.   Set GCC$Linker "link"
  240. will make LD use the program 'link' for linking.
  241.  
  242.  
  243. Predefines
  244. ----------
  245.  
  246. The following preprocessor constants are defined by GCC:
  247.    'arm', '__arm__', 'riscos', '__riscos__',
  248.    '__GNUC_MINOR__', '__GNUC_MAJOR__', '__JMP_BUF_SIZE'
  249.  
  250. To implement dynamic allocations within a function, it is necessary to add
  251. an extra field to jmpbuf. Fortunately the setjmp.h header files recognise
  252. __JMP_BUF_SIZE and can alter their jmpbuf array appropriately.
  253.  
  254.  
  255. Search paths
  256. ------------
  257.  
  258. The default search paths for GCC are as follows and searched in the
  259. specified order.
  260.    GCC$Path        GCC specific include files.
  261.    Unix$Path       Unixlib header files.
  262.  
  263.  
  264. <varargs.h>, <assert.h>, <stdarg.h>
  265. -----------------------------------
  266.  
  267. GCC supplies it's own versions of these header files since they are not
  268. compatible with the headers supplied with Acorn C and UnixLib.  However,
  269. this feature is invisible to the user.
  270.  
  271.  
  272. GCC and Compatibility
  273. ---------------------
  274.  
  275. As of release 1.0.7 and later, GCC is now compatible with StrongARM
  276. processors. Code produced by GCC will also be usable with StrongARM
  277. provided a version of UnixLib 3.7b or later is used.
  278.  
  279. Unfortunately, GCC has become unusable on any release of RISC OS prior to
  280. release 3.10 because the module CallASWI is now used.
  281.  
  282.  
  283. GCC and Virtual Memory
  284. ----------------------
  285.  
  286. GNU compilers use a lot of memory and nothing can be done about that. For
  287. the Risc PC, UnixLib has been modified to make use of dynamic areas. So
  288. users with small memory machines can use Clares' Virtualise to provide a
  289. working virtual memory envionment for them. See the section *Dynamic Areas*
  290. below.
  291.  
  292. Users of older machines, the Archimedes and A5000, can use the program
  293. !Virtual. Currently the version is 0.37 and there exists a few small problems
  294. with running gcc 2.7.2 compilers (or any UnixLib 3.7a and later programs)
  295. under this environment.
  296.  
  297. UnixLib 3.7a has been heavily modified and uses some unsupported SWI calls
  298. notably, XOS_RemoveTickerEvent, an XOS_Byte call and OS_PlatformFeatures.
  299. Until a later version of !Virtual is released, it is safe to answer 'Y' to
  300. all the questions related to Unknown SWIs.
  301.  
  302. Users of !Virtual can disregard the information contained within the
  303. specific compiler documentation concerning wimp slot size. Under the
  304. virtual memory environment, the wimp slot will need to be set to a size
  305. approximately 32K greater than the largest binary likely to be executed, the
  306. compiler. For example, if the size of cc1 is 700K, then setting the wimp slot
  307. to 732K should ensure that a successful compilation can be made
  308.  
  309. It should be noted that the greater amount of wimp slot that can be given
  310. to a virtual memory task, a smaller number of page swaps will be needed and
  311. a significant improvement in compile times should result.
  312.  
  313.  
  314. Dynamic areas
  315. -------------
  316.  
  317. Peter Burwood has modified UnixLib to use dynamic areas on the Risc PC and
  318. these modifications have been included in UnixLib 3.7a. This section applies
  319. to all GNU compilers supplied by either Nick Burrett, Peter Burwood or
  320. (hopefully) anyone else providing they have used UnixLib 3.7a or later. A
  321. description of using dynamic areas is included with UnixLib 3.7a and some
  322. of it is duplicated here:
  323.  
  324. UnixLib 3.7a has a facility to use Dynamic Areas, found in RISC OS 3.5
  325. and above, for the program's heap. The heap is another name for the
  326. malloc area. The advantages of using a dynamic area for the program's
  327. heap include :-
  328.  
  329.    * the WimpSlot of the program can be limited to the code and stack
  330.      requirements of the program. This helps alleviate the cost of RISC
  331.      OS task switching which slows down dramatically as the WimpSlot
  332.      grows in size.
  333.  
  334.    * Dynamic Areas provide a means of Virtual Memory when used with a
  335.      product such as Virtualise[1]. Virtual Memory allows programs to
  336.      use more data space than is available with just physical memory.
  337.  
  338. If any problems are encountered with the implementation or use of the
  339. dynamic area UnixLib heap then please contact Peter Burwood via e-mail at
  340. daheap@arcangel.dircon.co.uk. Please do not contact Peter with general
  341. UnixLib problems, but see the UnixLib ReadMe file for a contact address.
  342.  
  343. Basically, use
  344.  
  345.   *Set GCC_Heap ""
  346.  
  347. to enable dynamic areas for the compiler and
  348.  
  349.   *UnSet GCC_Heap
  350.  
  351. to disable dynamic areas for the compiler.
  352.  
  353. Before running a program set the wimpslot in the normal way, but it only
  354. needs to be large enough to hold the sum of the largest executables that
  355. can be run concurrently. e.g., with gcc, use the unsqueezed size of gcc
  356. plus cc1. When running from a command line amu remember to allow
  357. additional space for the amu executable and amu's workspace (though this
  358. is tricky to estimate!).
  359.  
  360. If other programs that form part of a compiler are run directly from the
  361. command line, e.g., gnatmake, then separate environment variables must
  362. be set to allow these programs to use dynamic areas for the program's
  363. heap. So, with gnatmake,
  364.  
  365.    *Set gnatmake_heap ""
  366.  
  367. As a user, you should not really need to worry about these details as the
  368. !gcc.!run file already contains the relevant lines. Please read the !run
  369. file if you are a Risc PC user, since some lines will need to be uncommented.
  370.  
  371. [1] Virtualise is a commercial product available from Clares. Peter Burwood
  372. has no connection with Clares or the Virtualise product other than being a
  373. user of Virtualise. If other similar products become available then UnixLib
  374. should work transparently since the UnixLib startup code does not use
  375. any Virtualise features.
  376.  
  377.  
  378. Troubleshooting
  379. ---------------
  380.  
  381. Here are describled some common problems users have with gcc and the GNU
  382. compilers. Possible solutions are provided for the known problems.
  383.  
  384. 1. The compiler fails to compile anything but no error message is reported.
  385.  
  386.   This is usually caused by a lack of memory. To see how far through
  387.   compilation a file has gone, try compiling with the '-v' flag. '-v' gives
  388.   verbose output and will show the programs gcc is executing.
  389.   
  390.   A lack of memory will be shown up by an almost instantaneous return from
  391.   any program executed. If this happens, try increasing the wimpslot,
  392.   using *wimpslot -min nnnK, where nnn is as follows:
  393.   
  394.   a) When not using dynamic areas i.e. when gcc_heap isn't set or you
  395.      don't have a RiscPC
  396.       2500 or more for GNU C
  397.       2600 or more for GNU Objective-C
  398.       3000 or more for GNU C++
  399.       6000 or more for GNAT Ada
  400.  
  401.   b) When using dynamic areas (RiscPC's only) and *set gcc_heap "" has been
  402.      performed.
  403.       1500 or more for GNU C
  404.       1500 or more for GNU Objective-C
  405.       1900 or more for GNU C++
  406.       3200 or more for GNAT Ada
  407.  
  408.   When the compiler runs out of memory during compilation, an error
  409.   'virtual memory exhausted' is usually reported.
  410.  
  411. 2. Abort on data transfer errors are displayed during compilation
  412.  
  413.   This is due to a lack of memory and will be rectified by increasing the
  414.   wimpslot to similar values as above.
  415.  
  416. Obtaining compilers
  417. -------------------
  418.  
  419. As said earlier, GCC is a compiler front end. Proper compilers can be
  420. obtained from the following places:
  421.  
  422. GNU C, Objective-C and C++:
  423.   ftp://micros.hensa.ac.uk/micros/arch/riscos/b/b013
  424.  
  425. GNU GNAT Ada:
  426.   ftp://micros.hensa.ac.uk/micros/arch/riscos/e/e095
  427.  
  428. GNU Fortran (G77):
  429.   ftp://micros.hensa.ac.uk/micros/arch/riscos/e/e167
  430.  
  431. GNU Pascal (GPC):
  432.   ftp://micros.hensa.ac.uk/micros/arch/riscos/e/e168
  433.  
  434.  
  435. Other compiler related utilities
  436. --------------------------------
  437.  
  438. Listed below is a small set of utilities you might find a useful
  439. complement to the GNU compilers.
  440.  
  441. Drlink (an AOF linker):
  442.   ftp://micros.hensa.ac.uk/micros/arch/riscos/b/b071/drlink.arc
  443.  
  444. UnixLib (a library emulating BSD, System V and POSIX functions):
  445.   ftp://micros.hensa.ac.uk/micros/arch/riscos/a/a042/unixlib.arc
  446.  
  447.  The latest snapshot of UnixLib may be obtained from:
  448.   http://www.callan.demon.co.uk/unixlib
  449.  
  450. Bison (a yacc parser):
  451.   ftp://ftp.demon.co.uk/pub/archimedes/gnu/bison124.spk
  452.  
  453. Diffutils (file difference and patch programs):
  454.   ftp://ftp.demon.co.uk/pub/archimedes/gnu/diffdist.spk
  455.  
  456. Flex (a lexical analyser: Unix Lex equivalent):
  457.   ftp://ftp.demon.co.uk/pub/archimedes/gnu/flex252.spk
  458.  
  459. Indent (C source code formatter):
  460.   ftp://ftp.demon.co.uk/pub/archimedes/gnu/indent.spk
  461.  
  462. Sed (batch stream editor):
  463.   ftp://ftp.demon.co.uk/pub/archimedes/gnu/sed.spk
  464.  
  465. !Virtual (virtual memory for early Archimedes, A5000 and before):
  466.   ftp://micros.hensa.ac.uk/micros/arch/riscos/a/a277/a277.arc
  467.  
  468.  
  469. Mirrors of hensa/micros
  470. -----------------------
  471.  
  472. Imperial College:
  473.  ftp://src.doc.ic.ac.uk/computing/systems/archimedes/collections/hensa/riscos/
  474.  
  475. Demon Internet Services
  476.  ftp://ftp.demon.co.uk/pub/mirrors/hensa/micros/arch/riscos/
  477.  
  478.  
  479. Porting compilers
  480. -----------------
  481.  
  482. The above compilers are all called front ends. They provide a mechanism
  483. for translating the relevant source code format (C, C++, Fortran etc.) into
  484. relevant information for the back-end. The back-end converts this information
  485. into a register transfer language and performs most of the optimisation
  486. techniques. This register transfer language is then applied to a processor
  487. back-end which will apply further optimisation (processor specific) and then
  488. output assembler instructions.  The compiler backend can support many
  489. different processors and operating systems, ARM and RISC OS are just two of
  490. them.
  491.  
  492. The job of actually porting new compilers has been made very easy due to the
  493. hard work of the compiler development teams. Nick Burrett wrote the RISC OS
  494. port of the ARM processor backend with a little help from Peter Burwood.
  495. Simon Callan and Huw Rodgers wrote UnixLib without which the job of porting
  496. the compiler would probably never have surfaced.
  497.  
  498. The actual ARM backend used to create the RISC OS port is, for the moment,
  499. unavailable on mainstream release in the GCC distribution. The alterations
  500. made to make the compilers actually work under RISC OS are very involved,
  501. and procedures are slowly underway to merge changes. Fortunately, the ARM
  502. backend for RISC OS is only going to be of interest to any future language
  503. compiler porters. If anybody wishes to port a new compiler then they should
  504. talk to Nick Burrett who will then send the changes through on request.
  505.  
  506. The main GCC compiler sources can be obtained from the sites listed described
  507. below. Sources are approximately 7.5Mb compressed, 27Mb uncompressed.
  508.  
  509.  
  510. Contacting Nick Burrett
  511. -----------------------
  512.  
  513. I can only be contacted by e-mail at nickb@digibank.demon.co.uk.
  514.  
  515. However, if there is no response from this address I can be contacted
  516. through Simon Callan: gcc@callan.demon.co.uk.
  517.  
  518.  
  519. Location of the main GCC sources
  520. --------------------------------
  521.  
  522.   Most GNU software is packed using the GNU `gzip' compression program.
  523.   Source code is available on most sites distributing GNU software.
  524.  
  525.   For information on how to order GNU software on tape, floppy or cd-rom, or
  526.   printed GNU manuals, check the file etc/ORDERS in the GNU Emacs
  527.   distribution, ftp the file /pub/gnu/GNUinfo/ORDERS on prep, or
  528.   e-mail a request to: gnu@prep.ai.mit.edu 
  529.  
  530.   By ordering your GNU software from the FSF, you help us continue to
  531.   develop more free software.  Media revenues are our primary source of
  532.   support.  Donations to FSF are deductible on US tax returns.
  533.  
  534.   thanx -gnu@prep.ai.mit.edu
  535.  
  536.         ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  537.   cair-archive.kaist.ac.kr:/pub/gnu, ftp.nectec.or.th:/pub/mirrors/gnu
  538.         AUSTRALIA: archie.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  539.         AFRICA: ftp.sun.ac.za:/pub/gnu
  540.         MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  541.         EUROPE: irisa.irisa.fr:/pub/gnu, ftp.univ-lyon1.fr:pub/gnu,
  542.   ftp.mcc.ac.uk, unix.hensa.ac.uk:/mirrors/uunet/systems/gnu,
  543.   src.doc.ic.ac.uk:/gnu, ftp.ieunet.ie:pub/gnu, ftp.eunet.ch,
  544.   nic.switch.ch:/mirror/gnu, ftp.informatik.rwth-aachen.de:/pub/gnu,
  545.   ftp.informatik.tu-muenchen.de, ftp.win.tue.nl:/pub/gnu, ftp.nl.net,
  546.   ftp.etsimo.uniovi.es:/pub/gnu ftp.funet.fi:/pub/gnu, ftp.denet.dk,
  547.   ftp.stacken.kth.se, isy.liu.se, ftp.luth.se:/pub/unix/gnu,
  548.   ftp.sunet.se:/pub/gnu, archive.eu.net
  549.         SOUTH AMERICA: ftp.inf.utfsm.cl:/pub/gnu, ftp.unicamp.br:/pub/gnu
  550.         WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  551.         USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
  552.   ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu,
  553.   f.ms.uky.edu:/pub3/gnu,
  554.   jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
  555.   uiarchive.cso.uiuc.edu:/pub/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  556.   col.hp.com:/mirrors/gnu, gatekeeper.dec.com:/pub/GNU,
  557.   ftp.uu.net:/systems/gnu
  558.  
  559.