]> git.sur5r.net Git - cc65/blobdiff - doc/ld65.sgml
ld65.sgml: document '--allow-multiple-definition' switch
[cc65] / doc / ld65.sgml
index 329f975e18abbd9524e1e1247cac89282ed5f58d..36489b0c60e286b86eff8d91d5095c5a58a54f61 100644 (file)
@@ -3,7 +3,6 @@
 <article>
 <title>ld65 Users Guide
 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
-<date>2014-04-20
 
 <abstract>
 The ld65 linker combines object files into an executable file. ld65 is highly
@@ -25,21 +24,21 @@ It complements the features that are built into the ca65 macroassembler:
 
 <itemize>
 
-<item> Accept any number of segments to form an executable module.
+<item>  Accept any number of segments to form an executable module.
 
-<item> Resolve arbitrary expressions stored in the object files.
+<item>  Resolve arbitrary expressions stored in the object files.
 
-<item> In case of errors, use the meta information stored in the object files
-       to produce helpful error messages. In case of undefined symbols,
-       expression range errors, or symbol type mismatches, ld65 is able to
-       tell you the exact location in the original assembler source, where
-       the symbol was referenced.
+<item>  In case of errors, use the meta information stored in the object files
+        to produce helpful error messages. In case of undefined symbols,
+        expression range errors, or symbol type mismatches, ld65 is able to
+        tell you the exact location in the original assembler source, where
+        the symbol was referenced.
 
-<item> Flexible output. The output of ld65 is highly configurable by a config
-       file. Some more-common platforms are supported by default configurations
-       that may be activated by naming the target system. The output
-       generation was designed with different output formats in mind, so
-       adding other formats shouldn't be a great problem.
+<item>  Flexible output. The output of ld65 is highly configurable by a config
+        file. Some more-common platforms are supported by default configurations
+        that may be activated by naming the target system. The output
+        generation was designed with different output formats in mind, so
+        adding other formats shouldn't be a great problem.
 
 </itemize>
 
@@ -67,28 +66,29 @@ Short options:
   -m name               Create a map file
   -o name               Name the default output file
   -t sys                Set the target system
-  -u sym                Force an import of symbol `sym'
+  -u sym                Force an import of symbol 'sym'
   -v                    Verbose mode
   -vm                   Verbose map file
 
 Long options:
-  --cfg-path path       Specify a config file search path
-  --config name         Use linker config file
-  --dbgfile name        Generate debug information
-  --define sym=val      Define a symbol
-  --end-group           End a library group
-  --force-import sym    Force an import of symbol `sym'
-  --help                Help (this text)
-  --lib file            Link this library
-  --lib-path path       Specify a library search path
-  --mapfile name        Create a map file
-  --module-id id        Specify a module id
-  --obj file            Link this object file
-  --obj-path path       Specify an object file search path
-  --start-addr addr     Set the default start address
-  --start-group         Start a library group
-  --target sys          Set the target system
-  --version             Print the linker version
+  --allow-multiple-definition   Allow multiple definitions
+  --cfg-path path               Specify a config file search path
+  --config name                 Use linker config file
+  --dbgfile name                Generate debug information
+  --define sym=val              Define a symbol
+  --end-group                   End a library group
+  --force-import sym            Force an import of symbol 'sym'
+  --help                        Help (this text)
+  --lib file                    Link this library
+  --lib-path path               Specify a library search path
+  --mapfile name                Create a map file
+  --module-id id                Specify a module id
+  --obj file                    Link this object file
+  --obj-path path               Specify an object file search path
+  --start-addr addr             Set the default start address
+  --start-group                 Start a library group
+  --target sys                  Set the target system
+  --version                     Print the linker version
 ---------------------------------------------------------------------------
 </verb></tscreen>
 
@@ -99,6 +99,14 @@ Here is a description of all of the command-line options:
 
 <descrip>
 
+  <tag><tt>--allow-multiple-definition</tt></tag>
+
+  Normally when a global symbol is defined multiple times, ld65 will
+  issue an error and not create the output file. This option lets it
+  silently ignore this fact and continue. The first definition of a
+  symbol will be used.
+
+
   <label id="option--start-group">
   <tag><tt>-(, --start-group</tt></tag>
 
@@ -156,6 +164,7 @@ Here is a description of all of the command-line options:
   <item>module
   <item>apple2
   <item>apple2enh
+  <item>atari2600
   <item>atari
   <item>atarixl
   <item>atmos
@@ -174,6 +183,7 @@ Here is a description of all of the command-line options:
   <item>sim6502
   <item>sim65c02
   <item>supervision
+  <item>telestrat
   <item>vic20
   </itemize>
 
@@ -246,10 +256,11 @@ Here is a description of all of the command-line options:
   <tag><tt>-Ln</tt></tag>
 
   This option allows you to create a file that contains all global labels and
-  may be loaded into the VICE emulator using the <tt/ll/ (load label) command. You
+  may be loaded into the VICE emulator using the <tt/ll/ (load label) command
+  or into the Oricutron emulator using the <tt/sl/ (symbols load) command. You
   may use this to debug your code with VICE. Note: Older versions had some
   bugs in the label code. If you have problems, please get the latest <url
-  url="http://vice-emu.sourceforge.net/" name="VICE"> version.
+  url="http://vice-emu.sourceforge.net" name="VICE"> version.
 
 
   <label id="option-S">
@@ -485,7 +496,7 @@ There are of course more attributes for a memory section than just start and
 size. Start and size are mandatory attributes, that means, each memory area
 defined <em/must/ have these attributes given (the linker will check that). I
 will cover other attributes later. As you may have noticed, I've used a
-comment in the example above. Comments start with a hash mark (`#'), the
+comment in the example above. Comments start with a hash mark ('#'), the
 remainder of the line is ignored if this character is found.
 
 
@@ -510,13 +521,15 @@ What we are doing here is telling the linker, that all segments go into the
 the linker will first write the <tt/CODE/ segment, then the <tt/RODATA/
 segment, then the <tt/DATA/ segment - but it will not write the <tt/BSS/
 segment. Why? Here enters the segment type: For each segment specified, you may also
-specify a segment attribute. There are four possible segment attributes:
+specify a segment attribute. There are five possible segment attributes:
 
 <tscreen><verb>
-        ro      means readonly
-        rw      means read/write
-        bss     means that this is an uninitialized segment
-        zp      a zeropage segment
+        ro          means readonly
+        rw          means read/write
+        bss         means that this is an uninitialized segment
+        zp          a zeropage segment
+        overwrite   a segment that overwrites (parts of) another one
+
 </verb></tscreen>
 
 So, because we specified that the segment with the name BSS is of type bss,
@@ -568,7 +581,7 @@ default behaviour is OK for our purposes, I did not use the attribute in the
 example above. Let's have a look at it now.
 
 The "file" attribute (the keyword may also be written as "FILE" if you like
-that better) takes a string enclosed in double quotes (`&dquot;') that specifies the
+that better) takes a string enclosed in double quotes ('&dquot;') that specifies the
 file, where the data is written. You may specify the same file several times,
 in that case the data for all memory areas having this file name is written
 into this file, in the order of the memory areas defined in the <tt/MEMORY/
@@ -616,6 +629,55 @@ the command line, with "-1.bin" and "-2.bin" appended respectively. Because
 '%' is used as an escape char, the sequence "%%" has to be used if a single
 percent sign is required.
 
+<sect1>OVERWRITE segments<p>
+
+There are situations when you may wish to overwrite some part (or parts) of a
+segment with another one. Perhaps you are modifying an OS ROM that has its
+public subroutines at fixed, well-known addresses, and you want to prevent them
+from shifting to other locations in memory if your changed code takes less
+space. Or you are updating a block of code available in binary-only form with
+fixes that are scattered in various places. Generally, whenever you want to
+minimize disturbance to an existing code brought on by your updates, OVERWRITE
+segments are worth considering.
+
+Here is an example:
+
+<tscreen><verb>
+MEMORY {
+    RAM: file = "", start = $6000, size = $2000, type=rw;
+    ROM: file = %O, start = $8000, size = $8000, type=ro;
+}
+</verb></tscreen>
+
+Nothing unusual so far, just two memory blocks - one RAM, one ROM. Now let's
+look at the segment configuration:
+
+<tscreen><verb>
+SEGMENTS {
+    RAM:       load = RAM, type = bss;
+    ORIGINAL:  load = ROM, type = ro;
+    FASTCOPY:  load = ROM, start=$9000, type = overwrite;
+    JMPPATCH1: load = ROM, start=$f7e8, type = overwrite;
+    DEBUG:     load = ROM, start=$8000, type = overwrite;
+    VERSION:   load = ROM, start=$e5b7, type = overwrite;
+}
+</verb></tscreen>
+
+Segment named ORIGINAL contains the original code, disassembled or provided in
+a binary form (i.e. using <tt/.INCBIN/ directive; see the <tt/ca65/ assembler
+document).  Subsequent four segments will be relocated to addresses specified
+by their "start" attributes ("offset" can also be used) and then will overwrite
+whatever was at these locations in the ORIGINAL segment. In the end, resulting
+binary output file will thus contain original data with the exception of four
+sequences starting at $9000, $f7e8, $8000 and $e5b7, which will sport code from
+their respective segments. How long these sequences will be depends on the
+lengths of corresponding segments - they can even overlap, so think what you're
+doing.
+
+Finally, note that OVERWRITE segments should be the final segments loaded to a
+particular memory area, and that they need at least one of "start" or "offset"
+attributes specified.
+
 <sect1>LOAD and RUN addresses (ROMable code)<p>
 
 Let us look now at a more complex example. Say, you've successfully tested
@@ -755,8 +817,7 @@ segment.
 <sect1>Other SEGMENT attributes<p>
 
 Segments may be aligned to some memory boundary. Specify "<tt/align = num/" to
-request this feature. Num must be a power of two. To align all segments on a
-page boundary, use
+request this feature. To align all segments on a page boundary, use
 
 <tscreen><verb>
         SEGMENTS {
@@ -841,7 +902,7 @@ look like this:
         }
 </verb></tscreen>
 
-The only other available output format is the o65 format specified by Andre
+There are two other available formats, one is the o65 format specified by Andre
 Fachat (see the <url url="http://www.6502.org/users/andre/o65/fileformat.html"
 name="6502 binary relocation format specification">). It is defined like this:
 
@@ -851,7 +912,20 @@ name="6502 binary relocation format specification">). It is defined like this:
         }
 </verb></tscreen>
 
-The necessary o65 attributes are defined in a special section labeled
+The other format available is the Atari (xex) segmented file format, this is
+the standard format used by Atari DOS 2.0 and upward file managers in the Atari
+8-bit computers, and it is defined like this:
+
+<tscreen><verb>
+        FILES {
+            %O: format = atari;
+        }
+</verb></tscreen>
+
+In the Atari segmented file format, the linker will write each <tt/MEMORY/ area
+as a new segment, including a header with the start and end address.
+
+The necessary o65 or Atari attributes are defined in a special section labeled
 <ref id="FORMAT" name="FORMAT">.
 
 
@@ -872,6 +946,30 @@ has several attributes that may be defined here.
     }
 </verb></tscreen>
 
+The Atari file format has two attributes:
+
+<descrip>
+
+  <tag><tt>RUNAD = symbol</tt></tag>
+
+  Specify a symbol as the run address of the binary, the loader will call this
+  address after all the file is loaded in memory. If the attribute is omitted,
+  no run address is included in the file.
+
+  <tag><tt>INITAD = memory_area : symbol</tt></tag>
+
+  Specify a symbol as the initialization address for the given memory area.
+  The binary loader will call this address just after the memory area is loaded
+  into memory, before continuing loading the rest of the file.
+
+</descrip>
+
+
+<tscreen><verb>
+    FORMATS {
+        atari: runad = _start;
+    }
+</verb></tscreen>
 
 
 <sect1>The FEATURES section<label id="FEATURES"><p>
@@ -1032,11 +1130,11 @@ The builtin config files do contain segments that have a special meaning for
 the compiler and the libraries that come with it. If you replace the builtin
 config files, you will need the following information.
 
-<sect1>INIT<p>
+<sect1>ONCE<p>
 
-The INIT segment is used for initialization code that may be reused once
+The ONCE segment is used for initialization code run only once before
 execution reaches main() - provided that the program runs in RAM. You
-may for example add the INIT segment to the heap in really memory
+may for example add the ONCE segment to the heap in really memory
 constrained systems.
 
 <sect1>LOWCODE<p>
@@ -1073,14 +1171,14 @@ including commercial applications, and to alter it and redistribute it
 freely, subject to the following restrictions:
 
 <enum>
-<item>         The origin of this software must not be misrepresented; you must not
-               claim that you wrote the original software. If you use this software
-               in a product, an acknowledgment in the product documentation would be
-       appreciated but is not required.
-<item> Altered source versions must be plainly marked as such, and must not
-       be misrepresented as being the original software.
-<item> This notice may not be removed or altered from any source
-       distribution.
+<item>  The origin of this software must not be misrepresented; you must not
+        claim that you wrote the original software. If you use this software
+        in a product, an acknowledgment in the product documentation would be
+        appreciated but is not required.
+<item>  Altered source versions must be plainly marked as such, and must not
+        be misrepresented as being the original software.
+<item>  This notice may not be removed or altered from any source
+        distribution.
 </enum>