TOC PREV NEXT INDEX DOC LIST MASTER INDEX



Patching Linker Guide

This utility is available only with Rational Apex Embedded for Rational Exec.


Using the Patching Linker

An application is initially linked using the normal Apex linking mechanism. After compiling modifications to your application, a patch of the original VOX executable can be made by adding the DIFF option to your linker description file and re-linking. This produces a new VOX executable that is linked so that differences between the two VOX files are minimized.

A diff utility, apex_pl_diff, can be used to generate an S-record file of the differences between the original and the new VOX executables. The patching utility, apex_pl_patch, can then be used on the original VOX file and the file of diffs to produce a patched VOX file that simulates on the host machine the patching that you do on your target. The comparison utility, apex_pl_compare, can now be used to compare the patched VOX file with the new VOX file produced by the patching linker.

Several new options have been added to the linker description file that help subsequent patches work more efficiently. On subsequent patching links, if a subprogram or data object has grown beyond its previous size, the patching linker may be forced to move the object. The PAD options allow the user to specify the amount of padding to be allocated on the initial link between subprogram or data objects. When insufficient space is available in the allocated pad areas, the patching linker creates new groups that contain moved subprograms or data.

The Binary Diff Program - apex_pl_diff

After running the linker in patch mode (using the DIFF old_vox_file option) a new VOX file new_vox_file is created. The binary diff tool, apex_pl_diff, is run as follows:

It finds the differences between the old and new program images and produces an annotated Motorola S-Record patch file. This file gives instructions about how to modify the most recently created program image to transform it into the new program image. Comments are included in the patch file to help identify the regions of code being patched. The -v option produces greater detail in the comments.

When following the preserve model (described in Preserved Patching Model2) it is useful to invoke apex_pl_diff with the -p option. This option tags the S-records that modify memory used in the original image with a # MODIFY comment, and those that simply initialize memory unused in the original image with a # NEW comment. Additionally suggested MOVE directives are generated in comments when modifications of a subprogram or data section exceed a move threshold of 10%. This move threshold can be modified to be n% by invoking apex_pl_diff with -p<n>.

The Binary Patch and Compare Programs - apex_pl_patch/apex_pl_compare

The patch file generated by apex_pl_diff may be applied to the previous VOX executable by using the binary patch program, apex_pl_patch:

This facility and the binary compare program, apex_pl_compare, are provided mainly as a way of testing the correctness of the patch file. It is left to you to find a way of applying the S-Record patch file in your application.

patched_vox_file is a generated VOX file that is virtually identical to new_vox_file that was produced by the patching linker. patched_vox_file can be executed on the target but symbolic debugging of it is severely limited; debugging the new_vox_file is preferred because it contains complete debugging information.

The binary comparison program, apex_pl_compare, can be used to compare patched_vox_file and new_vox_file and verify that application of the diff_file patch produces an image on the target that is identical to the new_vox_file. This gives us confidence that new_vox_file can be used as the basis of subsequent patching links.

apex_pl_compare only produces output if there is a difference between the two VOX executables.


Options and Features Added To the Syntax Of a Linker Description File

DIFF and PRESERVE Options

The DIFF option is used to put the linker into patch mode. It identifies a previously linked VOX executable to use as a guide when linking the current image. The goal of the patching link is to match up the external symbols of the new image as much as possible with the old image with the expectation that this results in fewer differences when generating a patch of the old VOX file.

The PRESERVE option tells the linker to follow the Preserved Patching model described in Preserved Patching Model.

For example,

Note: You can put a local linker description file, main_program.des, in the directory where you link your application and it overrides the global linker description file.

Move a Subprogram

The MOVE option can be used to force a subprogram to be moved even if it doesn't need to be moved. If an address is given with the MOVE option, the subprogram is moved to the given absolute address. Subprograms are moved only when doing a patching link as the MOVE option is ignored when doing a regular link.

The following options in a patching link force BZERO to be moved, __SUBP2 to be moved to the specified address, and the generated exception tables __EXCEPTION_TABLE to be moved.

Subprogram Move Efficiency

The Patching Linker efficiently moves subprograms or data objects. The cost of moving an object is its new size plus the size of all of the references made to the object. If an object has grown beyond its previous allocation it may be more efficient to move the next contiguous object to make room for expansion of the first.

Exclude Sections of Memory

You can specify memory that should not be used when linking. The MEMORY directive must follow the OBJECTS directive.

The following defines sections of memory that cannot be used for code or data:

The linker in either regular or patching mode lays out the image to avoid these memory locations. In patching mode, objects previously located in these memory locations are moved.

Control the Padding Between Subprograms

On the initial link of the program, padding can be inserted between text sections (subprograms) or data sections with global padding options or with a padding specification on a particular group's FOR clause. The padding specification can be either be an absolute pad size or a percentage of the corresponding group or section.

Default Global Padding Options

A global padding option can be used to specify padding for all groups of a specified type (Text, Const, Data, Bss). The global padding option is used also when new groups are created for moved subsections.

To pad each subprogram by 50%, and pad all data subsections by 50 bytes:

Pad a Specific Group

Padding can be specified in a group's For clause. This padding specification overrides any global padding option and applies only to the specified group.

Pad a Specific Subprogram

To identify an individual subprogram and indicate a specific amount of padding to include after that subprogram:

Pad Implicit Tables

As new groups are generated by the patching linker the internal tables GROUP_TABLE and DATA_INIT_TABLE (for new data imaged groups) may be forced to move. To reduce the likelihood of this happening, you may explicitly pad these tables on the initial link with special padding options.

The compacted exception tables, __EXCEPTION_TABLE, change as new text groups are created or new exception handlers are created. The exception tables consist of three subtables. If left unpadded, a change to the first cascades into changes throughout the following tables. The special pad option can be specified to reduce the likelihood of having to patch most of the exception tables or move the entire thing.

Separation of Default Sections into Distinct Groups

If you can determine that certain parts of the program are less likely to change than others, these sections may need less padding. For example, any parts of the program from the predefined Ada views runtime archives cannot be changed by the user and should require no padding. To allow segregating objects from different program libraries into different groups, it is possible to prefix a default section specification to identify all sections that reside in some subdirectory of the given pathname. For example:

Preserved Patching Model

One model of using the patching linker that is supported is to always move subprograms or data subsections to new unused memory leaving vacated memory with its former contents. This allows you to fall back to the previous state with a minimum of patching effort. Please note that this requires fairly careful bookkeeping and some additional support that you provide.

To use the linker in preserve mode, use the PRESERVE option.

Annotated Output

The Patching Linker describes the functions that move and why they move in the map file. When invoked with the -v option, the executable diff tool also describes what functions changed:

The output of the diff tool is a change file in ASCII. At the top are comments that identify the file, the date, the original image name, and the linked (new) image name. For example,

This is followed by various comment lines to help apex_pl_patch identify structural changes between the old image and the new one. For example,

These header sections are followed by a sequence of diff comments for each S-record to help decipher the address range being modified. For example,

In debug mode, the change file is expressed symbolically using the table from the image file.

The apex_pl_diff utility produces either Motorola S-records.


Ada Restrictions

The LINK_BLOCK group is special. The Apex Embedded runtime kernel uses this group to initialize the users program. The elements within this group cannot move. The origin cannot be changed without rebuilding the kernel and specifying the new LINK_BLOCK address.


Summary of Changes to the Linker Description File


Example Of a Complete Linker Description File


Rational Software Corporation 
http://www.rational.com
support@rational.com
techpubs@rational.com
Copyright © 1993-2002, Rational Software Corporation. All rights reserved.
TOC PREV NEXT INDEX DOC LIST MASTER INDEX TECHNOTES APEX TIPS