home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / drlink / Drlink_doc next >
Encoding:
Text File  |  1995-02-19  |  46.5 KB  |  1,064 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.27, 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.     -via <name>
  242.                According to the documentation on 'link', this
  243.                option allows the list of files to be included in
  244.                the link to be specified in file <name>. In fact,
  245.                the file can also contain link options and this is
  246.                how the option '-via' has been implemented in
  247.                Drlink. When this option is encountered, input is
  248.                switched to the file <name> and the list of files
  249.                and options taken from that file until end-of-file
  250.                is reached whereupon input reverts back to the
  251.                command line. The only option that is not valid in
  252.                a '-via' file is '-via'. This option can be used
  253.                as many times as is necessary on the command line.
  254.                The format of the filenames and options in the file
  255.                <name> is exactly the same as when specified on the
  256.                command line, except they can be spread over as
  257.                many lines in the file as necessary. Any 'newline'
  258.                characters in the file are treated as if they were
  259.                blanks.
  260.  
  261.     -workspace <size>
  262.                For a relocatable AIF image file, reserve <size>
  263.                bytes of memory after the image when relocating
  264.                it. <size> is rounded up to a whole number of
  265.                words. <size> is taken to be decimal by default
  266.                but can be prefixed by '&' or '0x' to give a
  267.                hexadecimal value. It can be postfixed by 'k' or
  268.                'm' to indicate the size is in kilobytes or
  269.                megabytes. The case of the 'k', 'm', 'x' or any of
  270.                the hex digits 'a' to 'f' is ignored.
  271.  
  272. All other 'link' options are recognised but are unsupported. They
  273. are: dbug, entry, overlay and xref.
  274.  
  275. The linker has the following extra options of its own:
  276.  
  277.     -acornmap  If option '-symbols' is used to print a symbol
  278.                listing, then it will be created in a format
  279.                similar to that produced by 'link'.
  280.  
  281.     -areamap <name>
  282.                This option causes the linker to write a map of the
  283.                areas in the executable image to file <name>. If
  284.                option '-nounused' is used as well, a list of areas
  285.                left out of the image file is produced as well. The
  286.                format of the list is exactly the same as that
  287.                produced by the '-map' option.
  288.  
  289.     -data <address>
  290.                '-data' allows the address of the start of the
  291.                read/write portion of the image file to be
  292.                specified. <address> is assumed to be a decimal
  293.                value by default but prefixing it with '&' or '0x'
  294.                means it will be taken to be in hexadecimal. It can
  295.                be postfixed by 'k' or 'm' to indicate the address
  296.                is in kilobytes or megabytes. The case of 'k', 'm',
  297.                'x' or any hex digits is ignored. The value of
  298.                <address> will be rounded up to the next word
  299.                boundary.
  300.  
  301.                This option can only be used when linking a binary
  302.                image file. Other image formats, for example, AIF,
  303.                make assumptions as to where the read/write part of
  304.                the image is to be found and therefore use of
  305.                '-data' is restricted to binary files only.
  306.  
  307.                The linker built-in symbol 'Image$$RW$$Base' is set
  308.                to the address of the start of the read/write
  309.                portion of the file, so the addresss of the data
  310.                can be found in a program by including a reference
  311.                to this symbol.
  312.  
  313.                Note that this option should only be used with the
  314.                greatest of care. It allows the address of the
  315.                start of the read/write portion of the image to be
  316.                given. The point of this is to allow data to be
  317.                placed at a specific address in memory. However, it
  318.                is also possible for executable code areas to go in
  319.                the read/write part of the image. If '-data' is
  320.                used, any such code will be treated as though it
  321.                will be at <address> at run time but due to the
  322.                format of the image file, when the program is run,
  323.                the code will not be placed at <address>. The same
  324.                is true for any pre-defined data. Therefore, if
  325.                this option is being used, the following points
  326.                should be observed:
  327.  
  328.                1.  Executable code should be placed in read-only
  329.                    code areas only.
  330.                2.  Constants should be placed in read-only data
  331.                    areas only.
  332.                3.  The initial values of any other items of data
  333.                    will be undefined.
  334.  
  335.     -debimage  If this option is specified and the image file to
  336.                be written contains debugging tables, the filetype
  337.                of the image file is set to 'DebImage' instead of
  338.                'Absolute'. If this option is not used, the
  339.                filetype of the image file is always set to
  340.                'Absolute'.
  341.  
  342.     -keepdebug <file list>
  343.                The purpose of this option is to allow debugging
  344.                information to be included selectively in the image
  345.                file. <file list> is a list of the object files and
  346.                library members where any compiler generated
  347.                debugging tables found are to be kept. Debugging
  348.                tables in any other files or members are ignored.
  349.                Any linker-generated low-level debugging tables
  350.                will only include entries for the files in <file
  351.                list>.
  352.  
  353.                The format of <file list> is a string of names of
  354.                files and library members separated by commas with
  355.                no other intervening characters or a string of
  356.                names enclosed in double quotes separated by one or
  357.                more blanks. The names should exactly match the
  358.                names of the files or library members to which they
  359.                refer, although the case of the names is ignored.
  360.                Wildcarded names are not permitted, although the
  361.                case where a name in <file list> matches a file
  362.                name in the list of files to link that resulted
  363.                from expanding a wildcarded name is allowed.
  364.  
  365.                Only one of the debugging options should be used at
  366.                a time. If both are found on the command line then
  367.                '-debug' takes precedence over '-keepdebug' and the
  368.                image file will contain all the debugging tables
  369.                the linker finds.
  370.  
  371.     -lib <library list>
  372.                <library list> is a list of libraries that Drlink
  373.                will search when attempting to resolve symbol
  374.                references. The list can take two forms. Either it
  375.                can supplied as a string of library names separated
  376.                by commas with no intervening blanks or any other
  377.                white space characters or the list can be enclosed
  378.                in double quotes with the names separated by one
  379.                or more blanks. Wildcarded library names are not
  380.                permitted.
  381.  
  382.                This option should not be needed in the normal
  383.                course of events. Drlink can tell the difference
  384.                between AOF files and libraries without having to
  385.                be told which is which but this is not the purpose
  386.                of the option. Its purpose is to reduce the
  387.                amount of memory used by the linker. The way the
  388.                Drlink works is to read *all* the files given on
  389.                the  command line into memory including any
  390.                libraries. Whilst this speeds up pulling members
  391.                out of the libraries, it can be quite expensive in
  392.                terms of memory. Libraries specified after '-lib'
  393.                will not be brought into memory and members will
  394.                be loaded from them as required.
  395.  
  396.     -nounused  This option is used to control whether unreferenced
  397.                areas in the image file will be left out. By
  398.                default, all areas are left in but if '-nounused'
  399.                is specified, the linker checks each area in the
  400.                executable image and leaves out any that it finds
  401.                are not referenced by any other areas.
  402.  
  403.                The purpose of this option is basically to strip
  404.                out any unused functions in a program. To achieve
  405.                this, it is necessary first to compile the program
  406.                with the '-zo' C (and DDE Pascal) compiler option.
  407.                This has the effect of spliting each function up
  408.                into its own self-contained 'area' in the object
  409.                code file. If '-nounused' is specified, the linker
  410.                examines all the areas and discards any that it
  411.                finds are not referenced from any other areas. In
  412.                fact, if the linker finds that, as a result of
  413.                throwing away an area, others that it referenced
  414.                now become unused, it will discard those other
  415.                areas as well. Unfortunately, it will not detect
  416.                cases where there are loops, that it, if area 'a'
  417.                calls only area 'b' and area 'b' calls only area
  418.                'a', it will not detect that it is safe to throw
  419.                away both areas. On the other hand, it can handle
  420.                the case where an otherwise unused area calls only
  421.                itself.
  422.  
  423.                Note that if the '-verbose' option is used, Drlink
  424.                will print a list of areas that have been left out
  425.                of the image file, along with the name of the first
  426.                symbol in the area if it can find one. This should
  427.                hopefully be the name of the function contained in
  428.                that area in an AOF file produced by the C
  429.                compiler.
  430.  
  431.                This option is not present in the C release 3
  432.                linker but it might be available in other AOF
  433.                linkers.
  434.  
  435.                WARNING: It should be remembered that the '-zo' C
  436.                compiler option is undocumented. In versions 3 and
  437.                4 of the compiler, it contains a serious bug that
  438.                affects the addresses of character strings in the
  439.                executable image. Under certain conditions, these
  440.                addresses are *wrong*. There is a workaround for
  441.                this, however. If '-zo' is used then '-fw' should
  442.                be used as well, that is, you should say, for
  443.                example: 'cc -zo -fw -c c.world'.
  444.  
  445.     -pagealign Pagealign instructs the linker to align the end of
  446.                the last read-only area in the image file on a page
  447.                boundary. The pagesize of the machine on which the
  448.                linker is being run is used in the calculations.
  449.  
  450.     -rescan    This tells the linker to scan libraries more than
  451.                once if necessary when searching for symbols.
  452.                'link' scans them only once so it is important to
  453.                specify libraries in the correct order. Drlink also
  454.                works like this unless '-rescan' is used, in which
  455.                case it will continue searching the libraries in
  456.                the order in which they were specified on the
  457.                command line until all symbols have been found or
  458.                all libraries have been checked for a particular
  459.                symbol.
  460.  
  461.                This option is not present in the C release 3
  462.                linker but it might be available in other AOF
  463.                linkers.
  464.  
  465.     -symbols <file>
  466.                Create a file listing all the relocatable symbols
  467.                in the image file. They are listed in address
  468.                order.
  469.  
  470.                If option '-acornmap' is used, the symbol listing
  471.                will be produced in a format similar to that of
  472.                'link' instead of using Drlink's format.
  473.  
  474.    -throwback  If this option is used and it is possible to use
  475.                'throwback' then all warning, error and fatal error
  476.                messages will be displayed in a 'throwback' window.
  477.                Note that only errors found after the option has
  478.                been encountered in the command line will be sent
  479.                to the 'throwback' window. Any found before that
  480.                point as well as any informational messages will
  481.                still be displayed at the command line in the
  482.                normal way. To display all errors in the
  483.                'throwback' window, this option should be the first
  484.                one supplied on the command line.
  485.  
  486.                Note that in order to use this facility, it is
  487.                necessary to have the 'DDEUtils' module loaded and
  488.                an editor that supports 'throwback', for example,
  489.                Dominic Symes' editor, !Zap.
  490.  
  491.                Note that the 'throwback' file name is set to that
  492.                of the image file to be created, and the effects of
  493.                clicking on one of the error messages shown in the
  494.                window is undefined. 'Throwback' is meant to be
  495.                used for source files, not object code!
  496.  
  497. Note that most options can be abbreviated to one or two letters.
  498. The minimum abbreviation for each option is:
  499.  
  500.     -acornmap    -aco
  501.     -aif         -ai
  502.     -aof         -ao
  503.     -areamap     -area
  504.     -base        -b
  505.     -bin         -bi
  506.     -case        -c
  507.     -data        -da
  508.     -debimage    -debi
  509.     -debug       -d
  510.     -edit        -e
  511.     -help        -h
  512.     -keepdebug   -keep
  513.     -lib         -lib
  514.     -map         -map
  515.     -module      -m
  516.     -nounused    -no
  517.     -output      -o
  518.     -pagealign   -pag
  519.     -relocatable -r
  520.     -rescan      -res
  521.     -rmf         -rm
  522.     -symbols     -s
  523.     -throwback   -th
  524.     -verbose     -v
  525.     -via         -via
  526.     -workspace   -w
  527.  
  528. Examples:
  529.  
  530.     drlink o.sieve c:o.stubs
  531.     drlink sieve.o c:stubs.o
  532.     drlink o.dhry1 o.dhry2 c:o.ansilib
  533.     drlink o.dhry1 o.dhry2 c:o.stubs -o dhry
  534.     drlink o.* -no -o PDC
  535.     drlink o.life c:o.risc_oslib c:o.stubs -map -v
  536.     drlink o.life -lib c:o.risc_oslib,c:o.ansilib
  537.     drlink o.life -lib "c:o.risc_oslib  c:o.ansilib"
  538.     drlink -throw o.balls64 p:o.plib c:o.risc_oslib P:O.Stubs
  539.     drlink o.balls64 -via pasclibs -map -v
  540.  
  541. The default options are to generate an AIF image file, to treat
  542. the case of symbols names as significant, not to include debugging
  543. information, to include all areas in the image file, not to
  544. produce an area map or symbol listing and to keep quiet about what
  545. the linker is doing.
  546.  
  547. In normal use, it should not really be necessary to use any of the
  548. linker options and running Drlink should just be a case of
  549. typing the command and the list of files and libraries to include
  550. in the linked image file, perhaps using the '-d' option to include
  551. debugging tables or '-o' to change the name of the linked image
  552. file. 
  553.  
  554.  
  555. Return Codes
  556. ~~~~~~~~~~~~
  557. If a link works, Drlink gives a return code of zero. If it fails,
  558. it posts a return code of twelve. A fatal error produces a return
  559. code of sixteen.
  560.  
  561.  
  562. Extended Command Line Support
  563. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  564. Drlink can make use of the extended command line facility that
  565. is provided by the 'DDEUtils' module. This allows the command line
  566. passed to Drlink to be of any length and not restricted to the
  567. normal limit of 255 characters. If the linker finds there is an
  568. extended command line available, it uses that in preference to the
  569. standard command line, which it completely ignores.
  570.  
  571. In order to use this facility, it is necessary to have the module
  572. 'DDEUtils' loaded and to use software that can set up extended
  573. command lines, for example, the version of 'amu' that comes with
  574. release 4 of the C compiler. 
  575.  
  576.  
  577. Link Edit Commands
  578. ~~~~~~~~~~~~~~~~~~
  579. This is a feature that allows symbols in the AOF files to be
  580. edited in various ways. Four operations are possible:
  581.  
  582. 1.  Rename a symbol in an AOF file.
  583. 2.  Change a symbol reference in an AOF file.
  584. 3.  Hide a symbol in an AOF file by making it 'local'.
  585. 4.  Reveal a symbol in an AOF file by making it 'global'.
  586.  
  587. The purpose of these commands is to resolve problems where
  588. different AOF files define symbols with the same name or to enable
  589. what would be unresolved symbol references to be replaced with
  590. references to defined symbols. Note that all that the commands do
  591. is act as a filter on the AOF files before they are passed to the
  592. main link routines and that if, for example, a symbol reference is
  593. changed, then there are no checks to make sure that the new symbol
  594. refers to the same sort of 'thing' as the old.
  595.  
  596. The commands are read from the file specified on the option
  597. '-edit'. Note that, unlike 'link', multiple 'link edit' files
  598. can be supplied. The general format of the commands is:
  599.  
  600.     <command> <filename> ( <one or two symbol names> )
  601.  
  602. <command> is one of the four commands described below and <filename>
  603. is the name of the AOF file or library member that will be
  604. affected by the command. Depending on the command, either one or
  605. two symbol names follows in brackets. The commands are free-form
  606. and can be spread over as many lines as necessary in the file.
  607. Several commands can be stacked on one line and there is no limit
  608. on the number of commands in a file.  At least one space should be
  609. left between the command and the filename but they are optional
  610. after that. The case of the link edit commands themselves is
  611. ignored as is that of any file names, but the case of symbol names
  612. is taken as significant, unless the option '-case' is specified on
  613. the command line as well in which case it is ignored. It is
  614. possible for several commands to refer to the same symbol, so
  615. that, for example, the name of a symbol could be changed in one
  616. file and references to it in another file could also be changed to
  617. that name as well. The order of the commands in the file is, in
  618. general, unimportant, but also refer to the note below. If, on the
  619. other hand, a symbol is to be renamed and its scope changed at the
  620. same time, then both edit commands should refer to the symbol by
  621. the symbol's old name.
  622.  
  623.  
  624. Rename a Symbol
  625. The format of the command is:
  626.  
  627.     rename <filename> ( <old name> , <new name> )
  628.  
  629. The effect of the command is to rename the symbol <old name>
  630. defined in file <filename> as <new name>. All references to the
  631. symbol should use <newname>.
  632.  
  633.  
  634. Change a Symbol Reference
  635. The format of this command is:
  636.  
  637.     change <filename> ( <old name> , <new name> )
  638.  
  639. It changes external references to symbol <old name> in file
  640. <filename> to <new name>.
  641.  
  642. Hide a Symbol
  643. This command's format is:
  644.  
  645.     hide <filename> ( <symbol name> )
  646.  
  647. If the symbol <symbol name> in file <filename> is marked as being
  648. visible to any file that references it, its scope is change to
  649. 'local' so that it can only be referenced in the file in which it
  650. was declared.
  651.  
  652. Reveal a Symbol
  653. This command has the format:
  654.  
  655.     reveal <filename> ( <symbol name> )
  656.  
  657. If the symbol <symbol name> in file <filename> is marked as a
  658. 'local' symbol, that is, can only be referenced in the file file
  659. in which it was declared, its scope is changed to 'global' so that
  660. any file can reference it.
  661.  
  662. Examples:
  663.  
  664.     hide o.sieve(main)
  665.  
  666.     rename o.miscprocs(isalnum,isalfanum)
  667.     change o.lexicals(isalnum,isalfanum)
  668.     change o.preproc(isalnum,isalfanum)
  669.  
  670. There are a couple of points to be aware of using the link edit
  671. commands.
  672.  
  673. Firstly, the commands are not executed in the order in which they
  674. are specified. All the commands for one file are performed
  675. together. They are also carried out in the order in which the
  676. files are specified on the command line. As the order in which
  677. library members will be read is not defined, the order in which
  678. link edit commands for these are executed is undefined as well.
  679.  
  680. There are times when the commands will appear not to work In a 'C'
  681. or DDE Pascal program, if a symbol reference, for example, a
  682. function call, is changed, references to that symbol within the
  683. AOF file will not be altered as the compiler will have resolved
  684. the references at compile time.
  685.  
  686.  
  687. A Brief Description of Drlink
  688. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  689. Drlink starts by reading the list of object files and libraries
  690. given on the command line into memory, except for any libraries
  691. given on the option '-lib'. Any 'link edit' commands are acted
  692. upon as the files are read. After this, Drlink attempts to resolve
  693. symbol references in each object file using, first, the symbols
  694. defined as being local to that file and then symbols defined as
  695. available to any file. If there are still any unresolved symbols,
  696. it then goes through each library trying to find them. The
  697. libraries are searched in the order they are specified on the
  698. command line, from left to right. This includes libraries
  699. specified on the '-lib' option. Each library is scanned only once,
  700. unless the option '-rescan' is used.  This means that any library
  701. members read can only refer to symbols that are already known or
  702. that can be found in that library or one that has yet to be
  703. searched. The order that libraries are specified on the command
  704. line is therefore very important. If, on the other hand, '-rescan'
  705. is specified, Drlink will keep searching the libraries until all
  706. the symbols have been found or until it determines that a symbol
  707. cannot be found in any library.
  708.  
  709. Assuming that all symbol references have been found, Drlink moves
  710. on to resolving addresses. Before it does that, however, if the
  711. '-nounused' option was specified, it attempts to determine the
  712. areas in the program that are not referenced from any other areas
  713. and removes any it finds from the program. Next, it determines the
  714. proper addresses of all the symbols and areas in the program and
  715. then goes through the program relocating and resolving addresses.
  716. If the '-debug' option is used, the low level debugging table is
  717. created at this point. The final step is to write the completed
  718. image file to disk.
  719.  
  720. Drlink has the ability to increase the amount of memory it is
  721. using if it is running in a task window or using the 'F12' CLI. It
  722. will acquire as much extra memory as it needs and return it once
  723. the link has completed. Drlink can be run in a wimpslot of only
  724. 96K bytes.
  725.  
  726.  
  727. Pre-defined Symbols
  728. ~~~~~~~~~~~~~~~~~~~
  729. There are a number of pre-defined symbols that can be referenced
  730. in object files. These are defined by the linker itself. The ones
  731. that Drlink supports are:
  732.  
  733. Image$$RO$$Base    The start address of the 'read-only' part of
  734.                    executable image when loaded into memory. This
  735.                    contains program code and constants.
  736.  
  737.  
  738. Image$$RO$$Limit   This is the address of the byte after the last
  739.                    byte of the 'read-only' part of a program when
  740.                    loaded into memory.
  741.  
  742. Image$$RW$$Base    This gives the address of the first byte of the
  743.                    'read/write' portion of a program when loaded
  744.                    into memory. This contains program code and
  745.                    data.
  746.  
  747. Image$$RW$$Limit   This defines the address of the byte after the
  748.                    last byte of the 'read/write' part of the
  749.                    program. The includes any zero-initialised data
  750.                    areas.
  751.  
  752. Image$$ZI$$Base    This symbol defines the start address of the
  753.                    'zero-initialised' part of the program when
  754.                    loaded into memory. This is simply an area of
  755.                    memory that is used by the program when it is
  756.                    run to hold data. It is not included in the
  757.                    image file on disk to prevent the image file
  758.                    becoming bloated with huge tracts of
  759.                    uninitialised data (except the Acorn C compiler
  760.                    does not make use of them and so the image
  761.                    file can become bloated with huge tracts of
  762.                    uninitialised data). If an AIF file is being
  763.                    produced (the standard Acorn executable image)
  764.                    then the zero-initialised data area is cleared
  765.                    to zeros when the program is run. This is not
  766.                    case if any other executable file formats are
  767.                    used, for example, '-bin'.
  768.  
  769. Image$$ZI$$Limit   This marks the address of the byte following
  770.                    the last byte of the 'zero-initialised' data
  771.                    part.
  772.  
  773.                    It should be noted that, with Drlink, the two
  774.                    symbols 'Image$$RW$$Limit' and 'Image$$ZILimit'
  775.                    are set to the same value.
  776.  
  777. The Acorn documentation says that the end of one part of the
  778. executable image should not be assumed to coincide with the start
  779. of the next, for example, it should not be assumed that the
  780. read/write part of the image starts the byte after the read-only
  781. part.
  782.  
  783. The six 'Image$$' symbols are defined in the 'link' documentation
  784. but there are a large number of other undocumented symbols, some
  785. of which are used by the libraries supplied with the C compiler
  786. (the C release 3 libraries, at least). Drlink implements a
  787. number of these but not the whole set, nor are the ones that are
  788. present guarenteed to remain there.
  789.  
  790. 'Area' Symbols
  791. Roughly speaking, the part of the AOF file that contains the
  792. actual code, data and debugging tables compiled from the original
  793. source file is broken down into a number of named 'areas', for
  794. example, the C compiler generates an area called 'C$$Code' for
  795. program code and one called 'C$$Data' for any data. These will be
  796. present in each AOF file included in the link and what Drlink
  797. (and 'link') does is to group all the areas with the same name
  798. together. What is not documented, though, is that each uniquely
  799. named area encountered by the linker results in creation of three
  800. symbols that can be can be (and are) referenced by any object
  801. file. These are the area name itself and a 'base' and 'limit' pair
  802. which point at the start address of the first area of that name
  803. when the program is loaded and the address of the byte after the
  804. last occurrence of that area, for example, the area 'C$$Code'
  805. would generate the symbols 'C$$Code', 'C$$Code$$Base' and
  806. 'C$$Code$$Limit'. The area 'C$$Debug' adds the symbols 'C$$Debug',
  807. 'C$$Debug$$Base' and 'C$$Debug$$Limit' to the linker's symbol
  808. table.
  809.  
  810. What was said in the preceding paragraph also applies to 'common'
  811. blocks. These are areas just like any other, but they are handled
  812. slightly differently in that all common block areas with the same
  813. name are overlaid on one another with the size of the common block
  814. being that of the largest instance of the common block. Just as
  815. with other areas, three symbols are created for each common block
  816. that can be used in programs: the common block name and a 'base'
  817. and 'limit' pair based on that name, for example, a common block
  818. called 'acorn' would add the symbols 'acorn', 'acorn$$Base' and
  819. 'acorn$$Limit' to the linker's tables.
  820.  
  821. If the '-zo' C compiler option is used, each function in the
  822. object code has its own uniquely-name area and this results in an
  823. explosion in the number of area symbols generated. Normally this
  824. would not be a problem except for the extra memory required to
  825. hold these symbols, but it results in the low-level debugging
  826. table created by the linker becoming flooded with what is, in the
  827. author's opinion, totally useless symbol information. Drlink's
  828. solution to this problem is not to include any symbols generated
  829. for areas apart from those for common blocks in the low-level
  830. debugging table.
  831.  
  832. There are other symbols that 'link' defines internally but these
  833. have not been seen in any AOF files yet and so they have not be
  834. included in Drlink.
  835.  
  836.  
  837. Differences Between Drlink and Link
  838. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  839. Drlink is based on the version of 'link' that comes with
  840. release 3 of the C compiler but there are a number of features of
  841. 'link' that are missing or that have been changed slightly. The
  842. idea is that Drlink will be used to link 'ordinary' programs and
  843. not any of the more exotic types that the Acorn linker can handle,
  844. for example, programs that use overlays.
  845.  
  846. First, the missing features:
  847.  
  848. 1)  Drlink does not support overlays (the '-overlay' option).
  849.  
  850. 2)  The entry address of the program cannot be specified (the
  851.     option '-entry').
  852.  
  853. 3)  The old debug option '-dbug' is not supported.
  854.  
  855. 4)  The option to print a list of cross references between areas
  856.     has not be included (option '-xref').
  857.  
  858. 5)  It does not support unnamed common blocks.
  859.  
  860. 6)  The 'link' documentation contains vague references to Un*x
  861.     'Aout' format files. Drlink does not handle these.
  862.  
  863. The known differences are:
  864.  
  865. 1)  The low level debugging tables do not have as many entries in
  866.     them as the ones generated by 'link'.  'link' includes entries
  867.     for symbols for every single area in the executable program
  868.     but Drlink leaves out all of these apart from the ones for
  869.     'common' blocks.
  870.  
  871. 2)  There are a number of undocumented built-in linker symbols
  872.     available in 'link' such as '_esdata' that Drlink does not
  873.     include.
  874.  
  875. 3)  The default program name created by the linker is '!Runimage'
  876.     and not 'aif'.
  877.  
  878. 4)  If the '-bin' option is used to create a binary file and the
  879.     entry point is not the first instruction in the program,
  880.     Drlink adds a branch to that address at the start of the
  881.     program.
  882.  
  883. 5)  The link edit commands are different to link's.
  884.  
  885. 6)  The partially-linked AOF files produced by Drlink are not the
  886.     same as those produced by link. They do not contain the zero-
  887.     length area 'Aout$$Common'. The relocations in the AOF file
  888.     are a mixture of type-1 and type-2 rather than being all
  889.     type-2.
  890.  
  891. 7)  '-base' behaves differently. With link, the filetype of a file
  892.     where '-base' is used is 'absolute'. Drlink makes such files
  893.     untyped and gives them load and execution addresses.
  894.  
  895. 8)  Strong symbol definitions are more fully supported.
  896.  
  897. The extensions to the Acorn release 3 link are:
  898.  
  899. 1)  If running under a task window or in the 'F12' CLI, Drlink can
  900.     extend its wimpslot.
  901.  
  902. 2)  It can removed unreferenced areas from the executable program.
  903.  
  904. 3)  Drlink supports extended command lines.
  905.  
  906. 4)  It can scan libraries more than once.
  907.  
  908. 5)  Debugging tables can be selectively included in the image
  909.     file.
  910.  
  911. 6)  Warning, error and fatal error messages can be displayed in a
  912.     'throwback' window.
  913.  
  914. 7)  The starting address of the read/write part of the image file
  915.     can be defined by means of a linker option.
  916.     
  917. 8)  A map of areas contained in the executable image file can be
  918.     written to a file.
  919.  
  920. 9)  It can produce a listing of symbols in the image file.
  921.  
  922. 10) It can align the end of the read-only portion of the image fle
  923.     on a page boundary.
  924.  
  925. In all other respects, Drlink should behave in exactly the same
  926. way as 'link', hopefully apart from some known bugs in 'link'.
  927. There are probably other subtle differences in the way the linkers
  928. behave but these are not known.
  929.  
  930.  
  931. Change Record
  932. ~~~~~~~~~~~~~
  933. Drlink 0.20 - First release version.
  934.  
  935. Drlink 0.21
  936. -  Added support for type-2 relocations.
  937. -  Fixed problem with paths with multiple directories in
  938.    filenames.
  939. -  Speeded up linker a bit.
  940.  
  941. Drlink 0.22
  942. -  Fixed bug where symbolic debug tables were left out of the
  943.    image file if '-nounused' was used.
  944. -  Changed way linker orders areas to more closely match that of
  945.    'link'.
  946. -  Added option '-keepdebug' to selectively include debugging
  947.    information from object files in image file.
  948. -  Allowed filenames supplied for options '-lib' and '-keepdebug'
  949.    to be enclosed in double quotes. This will, in fact, work on
  950.    any option.
  951.  
  952. Drlink 0.23
  953. -  Added 'link edit' commands (the '-edit' option).
  954. -  Added code to allow 'back-to-front' filenames.
  955. -  Now sets a return code of 12 if a link fails.
  956. -  Fixed bug in '-keepdebug' code where a buffer was overflowing
  957.    and overwriting anything that followed it, e.g. amu.
  958.  
  959. Drlink 0.24
  960. -  Made 'verbose' mode list the names of the external references
  961.    being satisfied and the files containing those references when
  962.    loading library members.
  963. -  Linker now prints a warning message about and lists files
  964.    specified on '-keepdebug' that were not loaded.
  965. -  A problem with extended command lines containing rubbish at the
  966.    end of the line has been fixed.
  967.  
  968. Drlink 0.25
  969. -  Fixed bug where the offset of the program entry point within
  970.    the entry point's area was being set to zero.
  971. -  Fixed bug in '-nounused' code where references to areas in
  972.    type-2 relocations were not being handled correctly.
  973. -  Fixed bug to do with filenames that include a path variable
  974.    that only showed up with RISCOS 2.
  975. -  Added the option to create partially-linked AOF files (option
  976.    '-aof').
  977. -  Added 'throwback' support (option '-throwback'). Warning, error
  978.    and fatal error messages can be displayed in a 'throwback'
  979.    window.
  980. -  Added warning to documentation concerning the use of the C
  981.    compiler option '-zo'.
  982.  
  983. Drlink 0.26
  984. -  Improved linker's performance in large links.
  985. -  Improved memory management.
  986. -  Added options '-base' and '-data' to allow the start addresses
  987.    of code and data part of the image file to be specified.
  988. -  Added option '-areamap' to allow map of areas in image file to
  989.    be written to a file.
  990. -  Added code to circumvent problem with the DDEUtils command
  991.    '*prefix' where the linker cannot find files where a path is
  992.    included as part of the filename, for example, 'C:O.Stubs',
  993.    after '*prefix' has been used.
  994.  
  995. Drlink 0.26a - Bug fix version
  996. -  Fixed bug introduced in 0.26 where -aof code stopped working.
  997. -  Programmed around problen affecting files from Objasm that
  998.    contain debug tables where the tables contain an invalid 'AL'
  999.    attribute.
  1000. -  RISCOS 2 filenames with paths finally sorted out I hope!
  1001. -  Recompiled with the latest and greatest version of the
  1002.    compiler.
  1003.  
  1004. Drlink 0.27
  1005. -  Fixed bug where unresolved references to weak external symbols
  1006.    were being included in the list of relocations at the end of
  1007.    relocatable modules.
  1008. -  Fixed bug in '-nounused' which could cause addressing
  1009.    exceptions if an AOF file contained type-2 relocations.
  1010. -  Fixed bug where type-2 relocations in an object file that is
  1011.    used as part of a partially-linked AOF file were sometimes
  1012.    being relocated incorrectly.
  1013. -  Added option '-acornmap' to allow printing of symbol listing in
  1014.    more-or-less the same format as that used by 'link'.
  1015. -  Added option '-pagealign' to allow end of read-only part of
  1016.    image to be aligned on a page boundary (useful for DDT).
  1017. -  Changed symbol listing so that the addresses of symbols in
  1018.    relocatable modules are expressed as an offset from the start
  1019.    of the module instead of an address.
  1020. -  Corrected handling of common blocks.
  1021. -  Added code to allow code and data areas to have the 'common
  1022.    definition' area attribute.
  1023. -  Changed handling of zero length areas. Previously Drlink
  1024.    ignored these completely.
  1025. -  The linker will now produce a list of unresolved weak external
  1026.    references if option '-verbose' is used instead of just
  1027.    mentioning the fact.
  1028. -  Corrected low level debug table and symbol listing code so that
  1029.    they no longer include symbols from areas omitted from the image
  1030.    file.
  1031. -  Added support for 'strong' symbol definitions.
  1032.  
  1033.  
  1034. Future Developments
  1035. ~~~~~~~~~~~~~~~~~~~
  1036. At the moment, the only items left on my 'wish list' for Drlink
  1037. are to make it run faster and improve the memory management. As
  1038. things stand, if you have enough memory to link a program then
  1039. fine, but if you don't, then tough. Any other suggestions people
  1040. have will be gratefully received.
  1041.  
  1042. If anyone has any suggestions or comments on Drlink, I can be
  1043. contacted on the Arcade Bulletin Board, user #418 'Davedan'.
  1044. Telephone numbers for Arcade are 0181-654-2212 and 0181-655-4412.
  1045. Alternative, I can be reached at:
  1046.  
  1047.     Davedan@arcade.demon.co.uk
  1048.  
  1049.  
  1050.  
  1051. Copyright
  1052. ~~~~~~~~~
  1053. The software and the documentation that goes with it is
  1054. Copyright © David Daniels 1993, 1994, 1995. All Rights Reserved.
  1055.  
  1056. Permission is hereby given for you to copy this program and freely
  1057. distribute it, subject to the following conditions:
  1058.  
  1059.  * No charge is made for the program (except nominal media costs).
  1060.  * No alterations are made to any of the files within this archive file.
  1061.  * All of the files within this archive are supplied, including this one.
  1062.  * No part of this program is included in a commercial product.
  1063.  
  1064.