home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / drlink_1 / Drlink_doc < prev   
Text File  |  1998-03-08  |  52KB  |  1,177 lines

  1.                      The 'Drlink' AOF Linker
  2.                      ~~~~~~~~~~~~~~~~~~~~~~~
  3.  
  4. Disclaimer
  5. ~~~~~~~~~~
  6. The 'Drlink' linker is provided 'as is' and people using it do so
  7. entirely at their own risk. No liability whatsoever will be
  8. accepted for any loss or damage arising from the use of this
  9. software.
  10.  
  11.  
  12. Introduction
  13. ~~~~~~~~~~~~
  14. Drlink is a linker that is intended to be a partial substitute for
  15. the Acorn linker, 'link'. It is aimed at people with compilers
  16. that generate object files in Acorn's AOF format but who do not
  17. have a copy of 'link', for example, people who want to use the DDE
  18. Pascal compiler or TLA or perhaps their own homebrew compilers.
  19. Drlink accepts object files in Acorn's AOF format and libraries in
  20. Acorn's ALF format and links them to produce an executable image
  21. in either Acorn's AIF format or a plain binary image. It can also
  22. be used to link relocatable modules or to create partially-linked
  23. AOF files. Drlink is modelled very closely on the version of
  24. 'link' that comes with release 3 of Acorn's C compiler but it is
  25. not really a complete replacement for it as it does not have the
  26. same range of facilities. What is there, it is hoped, should be
  27. adequate in most cases. Drlink is designed to link 'ordinary'
  28. programs and cannot do some of the fancy things link can, such as
  29. create image files that use overlays. Of course, some of these
  30. features could be added at a later date but the current version of
  31. Drlink, 0.34, does not support them. On the other hand, it does
  32. contain some features found on later releases of 'link' such as
  33. the ability to increase the size of the wimpslot if necessary when
  34. running in a task window and support for extended command lines.
  35. Other features include the ability to scan libraries more than
  36. once when resolving symbols and, assuming the right compiler
  37. options have been used when compiling programs, being able to
  38. leave out unused functions from executable images. Hopefully
  39. features like these will make the linker attractive to people who
  40. use link as well.
  41.  
  42.  
  43. Thanks...
  44. ~~~~~~~~~
  45. I would like to thank the many people on Arcade who have tested
  46. Drlink for me over the months and who made many helpful and useful
  47. suggestions. Drlink would never have reached the state it has
  48. today without their generous assistance.
  49.  
  50.  
  51. Using Drlink
  52. ~~~~~~~~~~~~
  53. Drlink is a command line-based program and has the same command
  54. syntax as 'link'. It can be used in the same environments as
  55. 'link', for example, with amu. If it is renamed as 'link', then
  56. it can be dynamically invoked from either the Acorn C or DDE
  57. Pascal compilers as well. It accepts the same options as 'link',
  58. although a number of them are unsupported and will be flagged as
  59. errors. Drlink also supports extended command lines. (Further
  60. information on this can be found in the section 'Extended Command
  61. Line Support' below.)
  62.  
  63. The command syntax is:
  64.  
  65.     drlink <list of files> <options>
  66.  
  67. where:
  68.  
  69. <list of files> is the list of object files and libraries to be
  70.                 included in the linked program.
  71.  
  72. <options>       is the options to be used when linking the
  73.                 program.
  74.  
  75. Options and object file names can be freely intermixed. The linker
  76. processes all the options before moving on to the link itself.
  77.  
  78. Filenames
  79. Each filename in the list of object files should be fully
  80. qualified, that is, Drlink makes no assumptions as to where the
  81. object files are to be found. Wildcards are permitted, in which
  82. case Drlink loads all the files that match the wildcard. If the
  83. directory containing the object files is called 'o', then Drlink
  84. will also accept 'back-to-front' filenames, for example, 'sieve.o'
  85. instead of 'o.sieve'. If a path is used as part of a filename, for
  86. example, 'C:', the way Drlink treats the filename depends on
  87. whether it contains wildcards or not. If it does not, then every
  88. directory on the path will be searched to find the file until
  89. either the file is found or the end of the list is reached. On the
  90. other hand, if the filename contains wildcards, only the first
  91. directory listed on the path will be checked. (This is how link
  92. behaves.) Examples:
  93.  
  94.     o.sieve
  95.     o.dhry1 o.dhry2 c:o.stubs
  96.     o.dhry* c:o.ansilib
  97.     dhry*.o c:ansilib.o
  98.     o.* c:o.*
  99.     O.world scsi::Arc.$.programs.!Pascal.O.Plib C:O.stubs
  100.  
  101. Drlink ignores the case of object file and library names.
  102.  
  103. Options
  104. As noted above, Drlink recognises the same options as 'link',
  105. even if it does flag a number as unsupported, plus has a number of
  106. its own. Options take the form of a '-' followed by the option
  107. name. Some options are followed by an argument. One or more blanks
  108. should be left between the option name and the argument. The case
  109. of the option and any argument is ignored. Options that are
  110. supported are:
  111.  
  112.     -aif       Create an AIF image file.
  113.  
  114.                This is the standard format for programs running
  115.                under RISCOS where a small header is attached to
  116.                the start of the program containing various bits
  117.                and pieces of information. It is the default option
  118.                used for the image type when no type is explicitly
  119.                given unless the '-base' option is used when '-bin'
  120.                is the default value.
  121.  
  122.     -aof       Create a partially-linked AOF file.
  123.  
  124.                The image file created takes the form of an AOF
  125.                file where as many references as possible between
  126.                the object files included in the link are resolved
  127.                and then the object files are merged together to
  128.                form another object file in AOF format that can be
  129.                used in a future link.
  130.  
  131.                There are a couple of points to watch out for here:
  132.                a) To include debug information in the AOF file,
  133.                   either '-debug' or '-keepdebug' must be used.
  134.                b) All local symbol names are lost, so they will
  135.                   not appear in the low-level debug tables if
  136.                   these are generated in the final image.
  137.  
  138.     -base <address>
  139.                This option allows the initial load address of the
  140.                read-only part of the image file to be specified.
  141.                The read-only part normally contains code.
  142.                <address> is taken to be decimal by default but if
  143.                prefixed by '&' or '0x' it will be treated as a
  144.                hexadecimal value. It can be postfixed by 'k' or
  145.                'm' to indicate the address is in kilobytes or
  146.                megabytes. The case of the 'k', 'm', 'x' or any of
  147.                the hex digits 'a' to 'f' is ignored. The value of
  148.                <address> is rounded up to the next word boundary
  149.                if it is not already so aligned.
  150.                
  151.                The initial load address can only be specified for
  152.                a binary image file.
  153.                
  154.                Image files created when this option is used do not
  155.                have a filetype but have 'load' and 'excute'
  156.                addresses instead. The load address is set to
  157.                whatever was specified on '-base' and the 'execute'
  158.                address to the program's entry point address. The
  159.                files themselves contain plain binary images as
  160.                created by the option '-bin'. This behaviour is
  161.                different to that of 'link'. 
  162.                
  163.     -bin       Create a plain binary image file.
  164.  
  165.                A binary image file does not have the header that
  166.                AIF files have on them and consist of nothing but
  167.                the linked program. This has two consequences.
  168.                Firstly, and most importantly, zero-initialised
  169.                data areas will not be cleared to zeros when the
  170.                program starts running as the routine to do this is
  171.                part of the AIF header. Secondly, if debugging
  172.                tables are included in the executable image, there
  173.                is nothing to indicate where they are.
  174.  
  175.                Note that when the option '-base' is used and the
  176.                image file type is not given, '-bin' is assumed to
  177.                be the image type.
  178.  
  179.     -case      Ignore the case of symbols when trying to resolve
  180.                symbol references. If this option is omitted, then
  181.                the case of the letters in symbol names is treated
  182.                as significant.
  183.  
  184.     -debug     Include debugging information in the image file. If
  185.                this option is omitted, any debugging tables
  186.                generated by the compiler that produced the AOF
  187.                file will be left out of the final image file. If
  188.                it is specified then any debugging tables found
  189.                will be included, along with some low-level tables
  190.                the linker itself creates. In the case where the
  191.                AOF files to be linked do not contain debugging
  192.                tables, only the linker's low-level tables will be
  193.                included.
  194.  
  195.                There is a second debug option, '-keepdebug', that
  196.                can be used to selectively include debugging
  197.                tables. Only one of '-keepdebug' or '-debug' should
  198.                be used. If both options are used, '-debug' takes
  199.                precedence.
  200.  
  201.                Note that if this option and '-bin' is used then
  202.                the debugging tables will still be included
  203.                although they will not really be of much use as
  204.                debuggers such as 'asd' would not be able to find
  205.                them. On the other hand, a routine in the program
  206.                might be able to locate them and for this reason
  207.                they are still included in the image file.
  208.  
  209.     -edit <name>
  210.                Gives the name of a file from which 'link edit'
  211.                commands are to be taken. For more information,
  212.                refer to the section 'Link Edit Commands' below.
  213.  
  214.     -help      Print a summary of Drlink options.
  215.  
  216.     -map       Print a list of areas (read-only code, data,
  217.                debugging tables, etc) in the image file giving
  218.                their addresses, sizes and types and the name of
  219.                the original AOF files that contained the areas.
  220.  
  221.     -module    Create a relocatable module in RMF format.
  222.  
  223.     -output <name>
  224.                Write the executable image file to file <name>. If
  225.                this option is omitted, the program is written to
  226.                the file '!Runimage' in the current directory.
  227.  
  228.     -relocatable
  229.                Create a reloctable AIF image file.
  230.  
  231.     -rmf       Create a reloctable module in RMF format.
  232.  
  233.     -verbose   Print messages as the link progresses saying how
  234.                far it has got. Some extra warning messages are
  235.                also produced if the linker finds aspects of the
  236.                link that look a bit iffy, for example, it will
  237.                print warning messages about unresolved 'weak'
  238.                external references. Normally, the linker keeps
  239.                quiet about such things.
  240.  
  241.                Note that '-quiet' takes precedence over
  242.                '-verbose'. If both options are specified,
  243.                '-verbose' is ignored.
  244.  
  245.     -via <name>
  246.                According to the documentation on 'link', this
  247.                option allows the list of files to be included in
  248.                the link to be specified in file <name>. In fact,
  249.                the file can also contain link options and this is
  250.                how the option '-via' has been implemented in
  251.                Drlink. When this option is encountered, input is
  252.                switched to the file <name> and the list of files
  253.                and options taken from that file until end-of-file
  254.                is reached whereupon input reverts back to the
  255.                command line. The only option that is not valid in
  256.                a '-via' file is '-via'. This option can be used
  257.                as many times as is necessary on the command line.
  258.                The format of the filenames and options in the file
  259.                <name> is exactly the same as when specified on the
  260.                command line, except they can be spread over as
  261.                many lines in the file as necessary. Any 'newline'
  262.                characters in the file are treated as if they were
  263.                blanks.
  264.  
  265.     -workspace <size>
  266.                For a relocatable AIF image file, reserve <size>
  267.                bytes of memory after the image when relocating
  268.                it. <size> is rounded up to a whole number of
  269.                words. <size> is taken to be decimal by default
  270.                but can be prefixed by '&' or '0x' to give a
  271.                hexadecimal value. It can be postfixed by 'k' or
  272.                'm' to indicate the size is in kilobytes or
  273.                megabytes. The case of the 'k', 'm', 'x' or any of
  274.                the hex digits 'a' to 'f' is ignored.
  275.  
  276. All other 'link' options are recognised but are unsupported. They
  277. are: dbug, entry, overlay and xref.
  278.  
  279. The linker has the following extra options of its own:
  280.  
  281.     -acornmap  If option '-symbols' is used to print a symbol
  282.                listing, then it will be created in a format
  283.                similar to that produced by 'link'.
  284.  
  285.     -areamap <name>
  286.                This option causes the linker to write a map of the
  287.                areas in the executable image to file <name>. If
  288.                option '-nounused' is used as well, a list of areas
  289.                left out of the image file is produced as well. The
  290.                format of the list is exactly the same as that
  291.                produced by the '-map' option.
  292.  
  293.     -data <address>
  294.                '-data' allows the address of the start of the
  295.                read/write portion of the image file to be
  296.                specified. <address> is assumed to be a decimal
  297.                value by default but prefixing it with '&' or '0x'
  298.                means it will be taken to be in hexadecimal. It can
  299.                be postfixed by 'k' or 'm' to indicate the address
  300.                is in kilobytes or megabytes. The case of 'k', 'm',
  301.                'x' or any hex digits is ignored. The value of
  302.                <address> will be rounded up to the next word
  303.                boundary.
  304.  
  305.                This option can only be used when linking a binary
  306.                image file. Other image formats, for example, AIF,
  307.                make assumptions as to where the read/write part of
  308.                the image is to be found and therefore use of
  309.                '-data' is restricted to binary files only.
  310.  
  311.                The linker built-in symbol 'Image$$RW$$Base' is set
  312.                to the address of the start of the read/write
  313.                portion of the file, so the addresss of the data
  314.                can be found in a program by including a reference
  315.                to this symbol.
  316.  
  317.                Note that this option should only be used with the
  318.                greatest of care. It allows the address of the
  319.                start of the read/write portion of the image to be
  320.                given. The point of this is to allow data to be
  321.                placed at a specific address in memory. However, it
  322.                is also possible for executable code areas to go in
  323.                the read/write part of the image. If '-data' is
  324.                used, any such code will be treated as though it
  325.                will be at <address> at run time but due to the
  326.                format of the image file, when the program is run,
  327.                the code will not be placed at <address>. The same
  328.                is true for any pre-defined data. Therefore, if
  329.                this option is being used, the following points
  330.                should be observed:
  331.  
  332.                1.  Executable code should be placed in read-only
  333.                    code areas only.
  334.                2.  Constants should be placed in read-only data
  335.                    areas only.
  336.                3.  The initial values of any other items of data
  337.                    will be undefined.
  338.  
  339.     -debimage  If this option is specified and the image file to
  340.                be written contains debugging tables, the filetype
  341.                of the image file is set to 'DebImage' instead of
  342.                'Absolute'. If this option is not used, the
  343.                filetype of the image file is always set to
  344.                'Absolute'.
  345.  
  346.     -gcc       This option is used in conjunction with '-nounused'
  347.                to tell the linker to ignore special areas created
  348.                by GCC when weeding out areas that are not
  349.                referenced in the image file. It has no other
  350.                effect. The default is to omit all unreferenced
  351.                areas.
  352.  
  353.     -keepdebug <file list>
  354.                The purpose of this option is to allow debugging
  355.                information to be included selectively in the image
  356.                file. <file list> is a list of the object files and
  357.                library members where any compiler generated
  358.                debugging tables found are to be kept. Debugging
  359.                tables in any other files or members are ignored.
  360.                Any linker-generated low-level debugging tables
  361.                will only include entries for the files in <file
  362.                list>.
  363.  
  364.                The format of <file list> is a string of names of
  365.                files and library members separated by commas with
  366.                no other intervening characters or a string of
  367.                names enclosed in double quotes separated by one or
  368.                more blanks. The names should exactly match the
  369.                names of the files or library members to which they
  370.                refer, although the case of the names is ignored.
  371.                Wildcarded names are not permitted, although the
  372.                case where a name in <file list> matches a file
  373.                name in the list of files to link that resulted
  374.                from expanding a wildcarded name is allowed.
  375.  
  376.                Only one of the debugging options should be used at
  377.                a time. If both are found on the command line then
  378.                '-debug' takes precedence over '-keepdebug' and the
  379.                image file will contain all the debugging tables
  380.                the linker finds.
  381.  
  382.     -leaveweak This instructs the linker to leave weak externals
  383.                unresolved if satisfying them would cause library
  384.                members to be loaded. This is the way the AOF
  385.                version 3 documentation says the linker should
  386.                behave, and is the opposite to the AOF 2 docs. By
  387.                default, Drlink will attempt to resolve weak
  388.                externals. This options makes it behave as per AOF 3.
  389.  
  390.     -lib <library list>
  391.                <library list> is a list of libraries that Drlink
  392.                will search when attempting to resolve symbol
  393.                references. The list can take two forms. Either it
  394.                can supplied as a string of library names separated
  395.                by commas with no intervening blanks or any other
  396.                white space characters or the list can be enclosed
  397.                in double quotes with the names separated by one
  398.                or more blanks. Wildcarded library names are not
  399.                permitted.
  400.  
  401.                This option should not be needed in the normal
  402.                course of events. Drlink can tell the difference
  403.                between AOF files and libraries without having to
  404.                be told which is which but this is not the purpose
  405.                of the option. Its purpose is to reduce the
  406.                amount of memory used by the linker. The way the
  407.                Drlink works is to read *all* the files given on
  408.                the  command line into memory including any
  409.                libraries. Whilst this speeds up pulling members
  410.                out of the libraries, it can be quite expensive in
  411.                terms of memory. Libraries specified after '-lib'
  412.                will not be brought into memory and members will
  413.                be loaded from them as required.
  414.  
  415.                Note that any 'old style' libraries listed after
  416.                '-lib' will be loaded immediately, that is, they
  417.                will not be added to the list of libraries to be
  418.                searched later.
  419.  
  420.     -nounused  This option is used to control whether unreferenced
  421.                areas in the image file will be left out. By
  422.                default, all areas are left in but if '-nounused'
  423.                is specified, the linker checks each area in the
  424.                executable image and leaves out any that it finds
  425.                are not referenced by any other areas.
  426.  
  427.                The purpose of this option is basically to strip
  428.                out any unused functions in a program. To achieve
  429.                this, it is necessary first to compile the program
  430.                with the '-zo' C (and DDE Pascal) compiler option.
  431.                This has the effect of spliting each function up
  432.                into its own self-contained 'area' in the object
  433.                code file. If '-nounused' is specified, the linker
  434.                examines all the areas and discards any that it
  435.                finds are not referenced from any other areas. In
  436.                fact, if the linker finds that, as a result of
  437.                throwing away an area, others that it referenced
  438.                now become unused, it will discard those other
  439.                areas as well. Unfortunately, it will not detect
  440.                cases where there are loops, that it, if area 'a'
  441.                calls only area 'b' and area 'b' calls only area
  442.                'a', it will not detect that it is safe to throw
  443.                away both areas. On the other hand, it can handle
  444.                the case where an otherwise unused area calls only
  445.                itself.
  446.  
  447.                Note that if the '-verbose' option is used, Drlink
  448.                will print a list of areas that have been left out
  449.                of the image file, along with the name of the first
  450.                symbol in the area if it can find one. This should
  451.                hopefully be the name of the function contained in
  452.                that area in an AOF file produced by the C
  453.                compiler.
  454.  
  455.                This option is not present in the C release 3
  456.                linker but it might be available in other AOF
  457.                linkers.
  458.  
  459.                WARNING: It should be remembered that the '-zo' C
  460.                compiler option is undocumented. In versions 3 and
  461.                4 of the compiler, it contains a serious bug that
  462.                affects the addresses of character strings in the
  463.                executable image. Under certain conditions, these
  464.                addresses are *wrong*. There is a workaround for
  465.                this, however. If '-zo' is used then '-fw' should
  466.                be used as well, that is, you should say, for
  467.                example: 'cc -zo -fw -c c.world'.
  468.  
  469.     -pagealign Pagealign instructs the linker to align the end of
  470.                the last read-only area in the image file on a page
  471.                boundary. The pagesize of the machine on which the
  472.                linker is being run is used in the calculations.
  473.  
  474.     -quiet     This instructs the linker not to print the
  475.                'Drlink AOF Linker ...' message when it starts
  476.                up. Nothing will be printed except for error
  477.                messages. This option overrides '-verbose' if
  478.                both are specified.
  479.  
  480.     -rescan    This tells the linker to scan libraries more than
  481.                once if necessary when searching for symbols.
  482.                'link' scans them only once so it is important to
  483.                specify libraries in the correct order. Drlink also
  484.                works like this unless '-rescan' is used, in which
  485.                case it will continue searching the libraries in
  486.                the order in which they were specified on the
  487.                command line until all symbols have been found or
  488.                all libraries have been checked for a particular
  489.                symbol.
  490.  
  491.                This option is not present in the C release 3
  492.                linker but it might be available in other AOF
  493.                linkers.
  494.  
  495.     -revmap    This option is used in conjunction with '-symbols'
  496.                and instructs the linker to list the symbols with
  497.                one symbol per line in the order <address> <name>.
  498.  
  499.     -symbols <file>
  500.                Create a file listing all the relocatable symbols
  501.                in the image file. They are listed in address
  502.                order.
  503.  
  504.                If option '-acornmap' is used, the symbol listing
  505.                will be produced in a format similar to that of
  506.                'link' instead of using Drlink's format, that is,
  507.                one symbol per line in the order <name> <address>.
  508.  
  509.                If option '-revmap' is used then the symbol listing
  510.                is produced with one symbol per line in
  511.                <address> <name> order.
  512.  
  513.    -throwback  If this option is used and it is possible to use
  514.                'throwback' then all warning, error and fatal error
  515.                messages will be displayed in a 'throwback' window.
  516.                Note that only errors found after the option has
  517.                been encountered in the command line will be sent
  518.                to the 'throwback' window. Any found before that
  519.                point as well as any informational messages will
  520.                still be displayed at the command line in the
  521.                normal way. To display all errors in the
  522.                'throwback' window, this option should be the first
  523.                one supplied on the command line.
  524.  
  525.                Note that in order to use this facility, it is
  526.                necessary to have the 'DDEUtils' module loaded and
  527.                an editor that supports 'throwback', for example,
  528.                Dominic Symes' editor, !Zap.
  529.  
  530.                Note that the 'throwback' file name is set to that
  531.                of the image file to be created, and the effects of
  532.                clicking on one of the error messages shown in the
  533.                window is undefined. 'Throwback' is meant to be
  534.                used for source files, not object code!
  535.  
  536. Note that most options can be abbreviated to one or two letters.
  537. The minimum abbreviation for each option is:
  538.  
  539.     -acornmap    -aco
  540.     -aif         -ai
  541.     -aof         -ao
  542.     -areamap     -area
  543.     -base        -b
  544.     -bin         -bi
  545.     -case        -c
  546.     -data        -da
  547.     -debimage    -debi
  548.     -debug       -d
  549.     -edit        -e
  550.     -gcc         -gcc
  551.     -help        -h
  552.     -keepdebug   -keep
  553.     -leaveweak   -leave
  554.     -lib         -lib
  555.     -map         -map
  556.     -module      -m
  557.     -nounused    -no
  558.     -output      -o
  559.     -pagealign   -pag
  560.     -quiet       -qui
  561.     -relocatable -r
  562.     -rescan      -res
  563.     -revmap      -rev
  564.     -rmf         -rm
  565.     -symbols     -s
  566.     -throwback   -th
  567.     -verbose     -v
  568.     -via         -via
  569.     -workspace   -w
  570.  
  571. Examples:
  572.  
  573.     drlink o.sieve c:o.stubs
  574.     drlink sieve.o c:stubs.o
  575.     drlink o.dhry1 o.dhry2 c:o.ansilib
  576.     drlink o.dhry1 o.dhry2 c:o.stubs -o dhry
  577.     drlink o.* -no -o PDC
  578.     drlink o.life c:o.risc_oslib c:o.stubs -map -v
  579.     drlink o.life -lib c:o.risc_oslib,c:o.ansilib
  580.     drlink o.life -lib "c:o.risc_oslib  c:o.ansilib"
  581.     drlink -throw o.balls64 p:o.plib c:o.risc_oslib P:O.Stubs
  582.     drlink o.balls64 -via pasclibs -map -v
  583.  
  584. The default options are to generate an AIF image file, to treat
  585. the case of symbols names as significant, not to include debugging
  586. information, to include all areas in the image file, not to
  587. produce an area map or symbol listing and to keep quiet about what
  588. the linker is doing.
  589.  
  590. In normal use, it should not really be necessary to use any of the
  591. linker options and running Drlink should just be a case of
  592. typing the command and the list of files and libraries to include
  593. in the linked image file, perhaps using the '-d' option to include
  594. debugging tables or '-o' to change the name of the linked image
  595. file. 
  596.  
  597.  
  598. Return Codes
  599. ~~~~~~~~~~~~
  600. If a link works, Drlink gives a return code of zero. If it fails,
  601. it posts a return code of twelve. A fatal error produces a return
  602. code of sixteen.
  603.  
  604.  
  605. Extended Command Line Support
  606. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  607. Drlink can make use of the extended command line facility that
  608. is provided by the 'DDEUtils' module. This allows the command line
  609. passed to Drlink to be of any length and not restricted to the
  610. normal limit of 255 characters. If the linker finds there is an
  611. extended command line available, it uses that in preference to the
  612. standard command line, which it completely ignores.
  613.  
  614. In order to use this facility, it is necessary to have the module
  615. 'DDEUtils' loaded and to use software that can set up extended
  616. command lines, for example, the version of 'amu' that comes with
  617. release 4 of the C compiler. 
  618.  
  619.  
  620. Link Edit Commands
  621. ~~~~~~~~~~~~~~~~~~
  622. This is a feature that allows symbols in the AOF files to be
  623. edited in various ways. Four operations are possible:
  624.  
  625. 1.  Rename a symbol in an AOF file.
  626. 2.  Change a symbol reference in an AOF file.
  627. 3.  Hide a symbol in an AOF file by making it 'local'.
  628. 4.  Reveal a symbol in an AOF file by making it 'global'.
  629.  
  630. The purpose of these commands is to resolve problems where
  631. different AOF files define symbols with the same name or to enable
  632. what would be unresolved symbol references to be replaced with
  633. references to defined symbols. Note that all that the commands do
  634. is act as a filter on the AOF files before they are passed to the
  635. main link routines and that if, for example, a symbol reference is
  636. changed, then there are no checks to make sure that the new symbol
  637. refers to the same sort of 'thing' as the old.
  638.  
  639. The commands are read from the file specified on the option
  640. '-edit'. Note that, unlike 'link', multiple 'link edit' files
  641. can be supplied. The general format of the commands is:
  642.  
  643.     <command> <filename> ( <one or two symbol names> )
  644.  
  645. <command> is one of the four commands described below and <filename>
  646. is the name of the AOF file or library member that will be
  647. affected by the command. Depending on the command, either one or
  648. two symbol names follows in brackets. The commands are free-form
  649. and can be spread over as many lines as necessary in the file.
  650. Several commands can be stacked on one line and there is no limit
  651. on the number of commands in a file.  At least one space should be
  652. left between the command and the filename but they are optional
  653. after that. The case of the link edit commands themselves is
  654. ignored as is that of any file names, but the case of symbol names
  655. is taken as significant, unless the option '-case' is specified on
  656. the command line as well in which case it is ignored. It is
  657. possible for several commands to refer to the same symbol, so
  658. that, for example, the name of a symbol could be changed in one
  659. file and references to it in another file could also be changed to
  660. that name as well. The order of the commands in the file is, in
  661. general, unimportant, but also refer to the note below. If, on the
  662. other hand, a symbol is to be renamed and its scope changed at the
  663. same time, then both edit commands should refer to the symbol by
  664. the symbol's old name.
  665.  
  666.  
  667. Rename a Symbol
  668. The format of the command is:
  669.  
  670.     rename <filename> ( <old name> , <new name> )
  671.  
  672. The effect of the command is to rename the symbol <old name>
  673. defined in file <filename> as <new name>. All references to the
  674. symbol should use <newname>.
  675.  
  676.  
  677. Change a Symbol Reference
  678. The format of this command is:
  679.  
  680.     change <filename> ( <old name> , <new name> )
  681.  
  682. It changes external references to symbol <old name> in file
  683. <filename> to <new name>.
  684.  
  685. Hide a Symbol
  686. This command's format is:
  687.  
  688.     hide <filename> ( <symbol name> )
  689.  
  690. If the symbol <symbol name> in file <filename> is marked as being
  691. visible to any file that references it, its scope is change to
  692. 'local' so that it can only be referenced in the file in which it
  693. was declared.
  694.  
  695. Reveal a Symbol
  696. This command has the format:
  697.  
  698.     reveal <filename> ( <symbol name> )
  699.  
  700. If the symbol <symbol name> in file <filename> is marked as a
  701. 'local' symbol, that is, can only be referenced in the file file
  702. in which it was declared, its scope is changed to 'global' so that
  703. any file can reference it.
  704.  
  705. Examples:
  706.  
  707.     hide o.sieve(main)
  708.  
  709.     rename o.miscprocs(isalnum,isalfanum)
  710.     change o.lexicals(isalnum,isalfanum)
  711.     change o.preproc(isalnum,isalfanum)
  712.  
  713. There are a couple of points to be aware of using the link edit
  714. commands.
  715.  
  716. Firstly, the commands are not executed in the order in which they
  717. are specified. All the commands for one file are performed
  718. together. They are also carried out in the order in which the
  719. files are specified on the command line. As the order in which
  720. library members will be read is not defined, the order in which
  721. link edit commands for these are executed is undefined as well.
  722.  
  723. There are times when the commands will appear not to work. In a
  724. 'C' or DDE Pascal program, if a symbol reference, for example, a
  725. function call, is changed, references to that symbol within the
  726. AOF file will not be altered as the compiler will have resolved
  727. the references at compile time.
  728.  
  729.  
  730. A Brief Description of Drlink
  731. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  732. Drlink starts by reading the list of object files and libraries
  733. given on the command line into memory, except for any libraries
  734. given on the option '-lib'. Any 'link edit' commands are acted
  735. upon as the files are read. After this, Drlink attempts to resolve
  736. symbol references in each object file using, first, the symbols
  737. defined as being local to that file and then symbols defined as
  738. available to any file. If there are still any unresolved symbols,
  739. it then goes through each library trying to find them. The
  740. libraries are searched in the order they are specified on the
  741. command line, from left to right. This includes libraries
  742. specified on the '-lib' option. Each library is scanned only once,
  743. unless the option '-rescan' is used.  This means that any library
  744. members read can only refer to symbols that are already known or
  745. that can be found in that library or one that has yet to be
  746. searched. The order that libraries are specified on the command
  747. line is therefore very important. If, on the other hand, '-rescan'
  748. is specified, Drlink will keep searching the libraries until all
  749. the symbols have been found or until it determines that a symbol
  750. cannot be found in any library.
  751.  
  752. Assuming that all symbol references have been found, Drlink moves
  753. on to resolving addresses. Before it does that, however, if the
  754. '-nounused' option was specified, it attempts to determine the
  755. areas in the program that are not referenced from any other areas
  756. and removes any it finds from the program. Next, it determines the
  757. proper addresses of all the symbols and areas in the program and
  758. then goes through the program relocating and resolving addresses.
  759. If the '-debug' option is used, the low level debugging table is
  760. created at this point. The final step is to write the completed
  761. image file to disk.
  762.  
  763. Drlink has the ability to increase the amount of memory it is
  764. using if it is running in a task window or using the 'F12' CLI. It
  765. will acquire as much extra memory as it needs and return it once
  766. the link has completed. Drlink can be run in a wimpslot of only
  767. 96K bytes.
  768.  
  769.  
  770. Pre-defined Symbols
  771. ~~~~~~~~~~~~~~~~~~~
  772. There are a number of pre-defined symbols that can be referenced
  773. in object files. These are defined by the linker itself. The ones
  774. that Drlink supports are:
  775.  
  776. Image$$RO$$Base    The start address of the 'read-only' part of
  777.                    executable image when loaded into memory. This
  778.                    contains program code and constants.
  779.  
  780.  
  781. Image$$RO$$Limit   This is the address of the byte after the last
  782.                    byte of the 'read-only' part of a program when
  783.                    loaded into memory.
  784.  
  785. Image$$RW$$Base    This gives the address of the first byte of the
  786.                    'read/write' portion of a program when loaded
  787.                    into memory. This contains program code and
  788.                    data.
  789.  
  790. Image$$RW$$Limit   This defines the address of the byte after the
  791.                    last byte of the 'read/write' part of the
  792.                    program. The includes any zero-initialised data
  793.                    areas.
  794.  
  795. Image$$ZI$$Base    This symbol defines the start address of the
  796.                    'zero-initialised' part of the program when
  797.                    loaded into memory. This is simply an area of
  798.                    memory that is used by the program when it is
  799.                    run to hold data. It is not included in the
  800.                    image file on disk to prevent the image file
  801.                    becoming bloated with huge tracts of
  802.                    uninitialised data (except the Acorn C compiler
  803.                    does not make use of them and so the image
  804.                    file can become bloated with huge tracts of
  805.                    uninitialised data). If an AIF file is being
  806.                    produced (the standard Acorn executable image)
  807.                    then the zero-initialised data area is cleared
  808.                    to zeros when the program is run. This is not
  809.                    case if any other executable file formats are
  810.                    used, for example, '-bin'.
  811.  
  812. Image$$ZI$$Limit   This marks the address of the byte following
  813.                    the last byte of the 'zero-initialised' data
  814.                    part.
  815.  
  816.                    It should be noted that, with Drlink, the two
  817.                    symbols 'Image$$RW$$Limit' and 'Image$$ZILimit'
  818.                    are set to the same value.
  819.  
  820. The Acorn documentation says that the end of one part of the
  821. executable image should not be assumed to coincide with the start
  822. of the next, for example, it should not be assumed that the
  823. read/write part of the image starts the byte after the read-only
  824. part.
  825.  
  826. The six 'Image$$' symbols are defined in the 'link' documentation
  827. but there are a large number of other undocumented symbols, some
  828. of which are used by the libraries supplied with the C compiler
  829. (the C release 3 libraries, at least). Drlink implements a
  830. number of these but not the whole set, nor are the ones that are
  831. present guarenteed to remain there.
  832.  
  833. 'Area' Symbols
  834. Roughly speaking, the part of the AOF file that contains the
  835. actual code, data and debugging tables compiled from the original
  836. source file is broken down into a number of named 'areas', for
  837. example, the C compiler generates an area called 'C$$Code' for
  838. program code and one called 'C$$Data' for any data. These will be
  839. present in each AOF file included in the link and what Drlink
  840. (and 'link') does is to group all the areas with the same name
  841. together. What is not documented, though, is that each uniquely
  842. named area encountered by the linker results in creation of three
  843. symbols that can be can be (and are) referenced by any object
  844. file. These are the area name itself and a 'base' and 'limit' pair
  845. which point at the start address of the first area of that name
  846. when the program is loaded and the address of the byte after the
  847. last occurrence of that area, for example, the area 'C$$Code'
  848. would generate the symbols 'C$$Code', 'C$$Code$$Base' and
  849. 'C$$Code$$Limit'. The area 'C$$Debug' adds the symbols 'C$$Debug',
  850. 'C$$Debug$$Base' and 'C$$Debug$$Limit' to the linker's symbol
  851. table.
  852.  
  853. What was said in the preceding paragraph also applies to 'common'
  854. blocks. These are areas just like any other, but they are handled
  855. slightly differently in that all common block areas with the same
  856. name are overlaid on one another with the size of the common block
  857. being that of the largest instance of the common block. Just as
  858. with other areas, three symbols are created for each common block
  859. that can be used in programs: the common block name and a 'base'
  860. and 'limit' pair based on that name, for example, a common block
  861. called 'acorn' would add the symbols 'acorn', 'acorn$$Base' and
  862. 'acorn$$Limit' to the linker's tables.
  863.  
  864. If the '-zo' C compiler option is used, each function in the
  865. object code has its own uniquely-name area and this results in an
  866. explosion in the number of area symbols generated. Normally this
  867. would not be a problem except for the extra memory required to
  868. hold these symbols, but it results in the low-level debugging
  869. table created by the linker becoming flooded with what is, in the
  870. author's opinion, totally useless symbol information. Drlink's
  871. solution to this problem is not to include any symbols generated
  872. for areas apart from those for common blocks in the low-level
  873. debugging table.
  874.  
  875. There are other symbols that 'link' defines internally but these
  876. have not been seen in any AOF files yet and so they have not be
  877. included in Drlink.
  878.  
  879.  
  880. Differences Between Drlink and Link
  881. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  882. Drlink is based on the version of 'link' that comes with
  883. release 3 of the C compiler but there are a number of features of
  884. 'link' that are missing or that have been changed slightly. The
  885. idea is that Drlink will be used to link 'ordinary' programs and
  886. not any of the more exotic types that the Acorn linker can handle,
  887. for example, programs that use overlays.
  888.  
  889. First, the missing features:
  890.  
  891. 1)  Drlink does not support overlays (the '-overlay' option).
  892.  
  893. 2)  The entry address of the program cannot be specified (the
  894.     option '-entry').
  895.  
  896. 3)  The old debug option '-dbug' is not supported.
  897.  
  898. 4)  The option to print a list of cross references between areas
  899.     has not be included (option '-xref').
  900.  
  901. 5)  It does not support unnamed common blocks.
  902.  
  903. 6)  The 'link' documentation contains vague references to Un*x
  904.     'Aout' format files. Drlink does not handle these.
  905.  
  906. The known differences are:
  907.  
  908. 1)  The low level debugging tables do not have as many entries in
  909.     them as the ones generated by 'link'. 'link' includes entries
  910.     for symbols for every single area in the executable program
  911.     but Drlink leaves out all of these apart from the ones for
  912.     'common' blocks.
  913.  
  914. 2)  There are a number of undocumented built-in linker symbols
  915.     available in 'link' such as '_esdata' that Drlink does not
  916.     include.
  917.  
  918. 3)  The default program name created by the linker is '!Runimage'
  919.     and not 'aif'.
  920.  
  921. 4)  If the '-bin' option is used to create a binary file and the
  922.     entry point is not the first instruction in the program,
  923.     Drlink adds a branch to that address at the start of the
  924.     program.
  925.  
  926. 5)  The link edit commands are different to link's.
  927.  
  928. 6)  The partially-linked AOF files produced by Drlink are not the
  929.     same as those produced by link. They do not contain the zero-
  930.     length area 'Aout$$Common'. The relocations in the AOF file
  931.     are a mixture of type-1 and type-2 rather than being all
  932.     type-2.
  933.  
  934. 7)  '-base' behaves differently. With link, the filetype of a file
  935.     where '-base' is used is 'absolute'. Drlink makes such files
  936.     untyped and gives them load and execution addresses.
  937.  
  938. 8)  Strong symbol definitions are more fully supported.
  939.  
  940. The extensions to the Acorn release 3 link are:
  941.  
  942. 1)  If running under a task window or in the 'F12' CLI, Drlink can
  943.     extend its wimpslot.
  944.  
  945. 2)  It can removed unreferenced areas from the executable program.
  946.  
  947. 3)  Drlink supports extended command lines.
  948.  
  949. 4)  It can scan libraries more than once.
  950.  
  951. 5)  Debugging tables can be selectively included in the image
  952.     file.
  953.  
  954. 6)  Warning, error and fatal error messages can be displayed in a
  955.     'throwback' window.
  956.  
  957. 7)  The starting address of the read/write part of the image file
  958.     can be defined by means of a linker option.
  959.     
  960. 8)  A map of areas contained in the executable image file can be
  961.     written to a file.
  962.  
  963. 9)  It can produce a listing of symbols in the image file.
  964.  
  965. 10) It can align the end of the read-only portion of the image fle
  966.     on a page boundary.
  967.  
  968. 11) It partially supports AOF version 3 (enough to link C and C++
  969.     programs) and generates AIF version 3 headers on image files.
  970.  
  971. In all other respects, Drlink should behave in exactly the same
  972. way as 'link', hopefully apart from some known bugs in 'link'.
  973. There are probably other subtle differences in the way the linkers
  974. behave but these are not known.
  975.  
  976.  
  977. Change Record
  978. ~~~~~~~~~~~~~
  979. Drlink 0.20 - First release version.
  980.  
  981. Drlink 0.21
  982. -  Added support for type-2 relocations.
  983. -  Fixed problem with paths with multiple directories in
  984.    filenames.
  985. -  Speeded up linker a bit.
  986.  
  987. Drlink 0.22
  988. -  Fixed bug where symbolic debug tables were left out of the
  989.    image file if '-nounused' was used.
  990. -  Changed way linker orders areas to more closely match that of
  991.    'link'.
  992. -  Added option '-keepdebug' to selectively include debugging
  993.    information from object files in image file.
  994. -  Allowed filenames supplied for options '-lib' and '-keepdebug'
  995.    to be enclosed in double quotes. This will, in fact, work on
  996.    any option.
  997.  
  998. Drlink 0.23
  999. -  Added 'link edit' commands (the '-edit' option).
  1000. -  Added code to allow 'back-to-front' filenames.
  1001. -  Now sets a return code of 12 if a link fails.
  1002. -  Fixed bug in '-keepdebug' code where a buffer was overflowing
  1003.    and overwriting anything that followed it, e.g. amu.
  1004.  
  1005. Drlink 0.24
  1006. -  Made 'verbose' mode list the names of the external references
  1007.    being satisfied and the files containing those references when
  1008.    loading library members.
  1009. -  Linker now prints a warning message about and lists files
  1010.    specified on '-keepdebug' that were not loaded.
  1011. -  A problem with extended command lines containing rubbish at the
  1012.    end of the line has been fixed.
  1013.  
  1014. Drlink 0.25
  1015. -  Fixed bug where the offset of the program entry point within
  1016.    the entry point's area was being set to zero.
  1017. -  Fixed bug in '-nounused' code where references to areas in
  1018.    type-2 relocations were not being handled correctly.
  1019. -  Fixed bug to do with filenames that include a path variable
  1020.    that only showed up with RISCOS 2.
  1021. -  Added the option to create partially-linked AOF files (option
  1022.    '-aof').
  1023. -  Added 'throwback' support (option '-throwback'). Warning, error
  1024.    and fatal error messages can be displayed in a 'throwback'
  1025.    window.
  1026. -  Added warning to documentation concerning the use of the C
  1027.    compiler option '-zo'.
  1028.  
  1029. Drlink 0.26
  1030. -  Improved linker's performance in large links.
  1031. -  Improved memory management.
  1032. -  Added options '-base' and '-data' to allow the start addresses
  1033.    of code and data part of the image file to be specified.
  1034. -  Added option '-areamap' to allow map of areas in image file to
  1035.    be written to a file.
  1036. -  Added code to circumvent problem with the DDEUtils command
  1037.    '*prefix' where the linker cannot find files where a path is
  1038.    included as part of the filename, for example, 'C:O.Stubs',
  1039.    after '*prefix' has been used.
  1040.  
  1041. Drlink 0.26a - Bug fix version
  1042. -  Fixed bug introduced in 0.26 where -aof code stopped working.
  1043. -  Programmed around problen affecting files from Objasm that
  1044.    contain debug tables where the tables contain an invalid 'AL'
  1045.    attribute.
  1046. -  RISCOS 2 filenames with paths finally sorted out I hope!
  1047. -  Recompiled with the latest and greatest version of the
  1048.    compiler.
  1049.  
  1050. Drlink 0.27
  1051. -  Fixed bug where unresolved references to weak external symbols
  1052.    were being included in the list of relocations at the end of
  1053.    relocatable modules.
  1054. -  Fixed bug in '-nounused' which could cause addressing
  1055.    exceptions if an AOF file contained type-2 relocations.
  1056. -  Fixed bug where type-2 relocations in an object file that is
  1057.    used as part of a partially-linked AOF file were sometimes
  1058.    being relocated incorrectly.
  1059. -  Added option '-acornmap' to allow printing of symbol listing in
  1060.    more-or-less the same format as that used by 'link'.
  1061. -  Added option '-pagealign' to allow end of read-only part of
  1062.    image to be aligned on a page boundary (useful for DDT).
  1063. -  Changed symbol listing so that the addresses of symbols in
  1064.    relocatable modules are expressed as an offset from the start
  1065.    of the module instead of an address.
  1066. -  Corrected handling of common blocks.
  1067. -  Added code to allow code and data areas to have the 'common
  1068.    definition' area attribute.
  1069. -  Changed handling of zero length areas. Previously Drlink
  1070.    ignored these completely.
  1071. -  The linker will now produce a list of unresolved weak external
  1072.    references if option '-verbose' is used instead of just
  1073.    mentioning the fact.
  1074. -  Corrected low level debug table and symbol listing code so that
  1075.    they no longer include symbols from areas omitted from the image
  1076.    file.
  1077. -  Added support for 'strong' symbol definitions.
  1078. -  Added some AOF V3 support.
  1079.  
  1080. Drlink 0.28
  1081. -  Added option '-leaveweak' to stop linker resolving weak external
  1082.    references from libraries (so that it behaves as per AOF 3 docs).
  1083. -  Changed headers on image file to AIF v3 headers.
  1084. -  Added option -C++ to instruct linker to carry out C++-specific
  1085.    operations concerned with constructors and destructors. The
  1086.    linker does not yet expand C++ mangled names into their full
  1087.    versions.
  1088. -  Added support for 'old style' libraries so that FORTRAN 77
  1089.    programs can be linked.
  1090. -  Fixed bug where relocation info for type-2 relocations was
  1091.    missed out in relocatable AIF files and relocatable modules.
  1092. -  Improved memory management when linker is running out of memory.
  1093.  
  1094. Drlink 0.29
  1095. -  Added symbols 'Image$$CodeBase', 'Image$$CodeLimit',
  1096.    'Image$$DataBase' and 'Image$$DataLimit' required by FORTRAN 77
  1097.    programs. These will only be included if 'old style' libraries
  1098.    are read.
  1099.  
  1100. Drlink 0.30
  1101. -  Made code StrongARM compatible.
  1102. -  Added support for 'based' areas.
  1103. -  Added support for areas not aligned on a word boundary.
  1104. -  Added option '-quiet' which stops linker from printing the
  1105.    'Drlink AOF Linker' message.
  1106. -  Added support for the relocation of instruction sequences.
  1107. -  Fixed bug affecting symbols which had the 'common reference'
  1108.    attribute set.
  1109. -  Fixed two bugs in partially-linked AOF file support which
  1110.    stopped partially-linked files working with C release 5.
  1111. -  Fixed bug causing addressing exception when option '-symbol'
  1112.    was used when creating a partially-linked AOF file.
  1113. -  Fixed bug in C++ code where areas containing constructors
  1114.    and destructors could be deleted if option '-nounused' was
  1115.    used.
  1116. -  Added code to handle 'strong symbol' case that was missed out
  1117.    when strong symbol support was added.
  1118.  
  1119. Drlink 0.31
  1120. -  Fixed bug in library search code.
  1121. -  Added option '-revmap'.
  1122.  
  1123. Drlink 0.32
  1124. -  Fixed problem where very long symbol names (300 characters!)
  1125.    caused the linker to fail in various places.
  1126.  
  1127. Drlink 0.33
  1128. -  Fixed problem in code that produces area maps where area names
  1129.    longer than about 200 characters were causing the linker to
  1130.    die.
  1131. -  Added option '-gcc' to stop linker removing GCC-specific areas
  1132.    from the image file when '-nounused' is used.
  1133. -  Increased the maximum length filename that the linker will
  1134.    handle to 500 characters.
  1135.  
  1136. Drlink 0.34
  1137. -  Linker can now be compiled to run under RiscBSD and Linux (but
  1138.    it still links only AOF files).
  1139.  
  1140.   
  1141. Future Developments
  1142. ~~~~~~~~~~~~~~~~~~~
  1143. At the moment, the items on my 'wish list' for Drlink are, in no
  1144. particular order:
  1145.  
  1146. 1)  Add full support for AOF V3.
  1147. 2)  Improve the C++ support by printing de-mangled C++ function
  1148.     and variable names.
  1149. 3)  Make it run faster.
  1150. 4)  Improve the memory management.
  1151.  
  1152. Any other suggestions people have will be gratefully received.
  1153.  
  1154. If anyone has any suggestions or comments on Drlink, I can be
  1155. contacted on the Arcade Bulletin Board, user #418 'Davedan'.
  1156. Telephone numbers for Arcade are 0181-654-2212 and 0181-655-4412.
  1157. Alternative, I can be reached at:
  1158.  
  1159.     Davedan@arcade.demon.co.uk
  1160.  
  1161.  
  1162.  
  1163. Copyright
  1164. ~~~~~~~~~
  1165. The software and the documentation that goes with it is
  1166. Copyright © David Daniels 1993, 1994, 1995, 1996, 1997, 1998. All
  1167. Rights Reserved.
  1168.  
  1169. Permission is hereby given for you to copy this program and freely
  1170. distribute it, subject to the following conditions:
  1171.  
  1172.  * No charge is made for the program (except nominal media costs).
  1173.  * No alterations are made to any of the files within this archive file.
  1174.  * All of the files within this archive are supplied, including this one.
  1175.  * No part of this program is included in a commercial product.
  1176.  
  1177.