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