• Aucun résultat trouvé

The Linker

Dans le document for the Lisa'" (Page 136-148)

; cause error

Chapter 7 The Linker

7.1 TIle Linker ... 7-1 The Linker is a program that combines object files to create an

executable file.

7.2 lJslr.g ttle Linker ... 7-2 The Linker combines object files to prodUce executable programs.

Inputs to the Linker are object files, command files, or options.

7.3 TIle Linker ~tions ... 7-2 The Linker options control how a link Is performed. A Itst of the

current option settings is displayed when you enter a "?" to the options prompt.

7.4 I-bw 00 I Uri< a Main Progmn? ... 7-4 A main program is linked by giving the Linker the object file from a Pascal program" along with all assembly language routines, complIed units, and libraries that the program uses.

75 RegJlar CI1d Intrinsic Lklits .•...•....•..•...

7-4-Regular and intrinsic units are both Pascal units" separately complled.

A .regula.r unjt is linked wi th a main program and becomes part of the

executable file. An intrinsic unit Is shared among all programs that

use it" both on disk and in memory.

7.6 1l1e Linker Listing ... 7-5 The Linker listing provides a summary Of the linking process and

resources used. cptionally ... you can request lIsts of all symbols used 7.7 ResolvtrlQ ExtelTlal I\IarneS .•..••••..••••••.•..••••.••••••.•••••••.•.•.••••••••..•••.••.•••. 7-6

Extemai names are symbolic references to separately compiled modules.

The Linker maps them to actual addresses.

7.8 I'1odule Irlclusioo ... , ... , .. 7-6 The Linker only InclUdes modUles that are actually referenced.

7.9 ~tation ... 7-7

segmentjnga program allows portions of it to be swapped out of memory when not in use. Segmentat10n Is controlled by a combinat1on of compiler commands, Linker options, and the Changeseg utility.

The Linker

7.1 The Lin<er

The Linker combines object files. Its input consists of coornands and object files. Its output consists of Object files, link-map information, and error messages. The output of the Pascal compiler must be linked with IOSPASLIB.CBJ before it can be executed. Other object files, including

intrinsic unit libraries, and object fUes produced by the Assembler, can also be linked into the output Db ject file.

When a program is compiled into an Object file, it contains the following sorts of things:

• (l)ject code, in the form of relocatable machine language, that expresses the algorithm of the program.

• Symbolic (named) references to all locations that were not known at compile time. These include externally compiled routines (units and intrinsic units) and the Pascal library support routines (IOSPASLlB.CBJ).

• Other information to be used by the Linker.

The purpose of the Linker is to resolve all the symbolic references (link references to definitions), and output an object file that can be executed. The Linker also sorts the code modules into named segments. These segments are swapped into memory at run time by the ~rating System.

The Linker does its work in two phases. In the first phase, it reads all the

input files, and finds all symbolic references and their corresponding definitions. Errors such as duplicate and missing references are detected during phase

one.

In the second phase, the Linker copies code from the input files into the output files in executable formal

If the Linker can't find something that is addressed symbolically, this is an error. M error message will be printed, indicating the missing module. This process of finding the real addresses that correspond to the symbolic addresses is called resolving the extemaJ refeJ1!Jl7CB.t

The Linker expects to find the file INTRINSIC.LIB. INTRINSIC.L1B is a directory of Ubraries and intrinsic units, and includes information for the use of the Linker. INTRINSIC.L1B defines all the intrinsic units supplied with the Workshop

system.

To create an executable fUe, the Linker must have the following inputs:

• The object file from a main Pascal program.

• IOSP ASLIB.C6J to provide the standard Pascal procedures and fl.llCtions.

7-1

Workshop User's Guide TI7e Linker

Workshop User's Gujde The Ljnker

options are entered is unimportant, because they have no effect until the link begins. The last value entered for an option is the value used when the link is performed.

Q:ltions are represented by a single character. A to+" in front of the character makes that option take effect. A "_to sets the Linker so that option will not happen. In addition to being set on or off, some options have additional parameters. Numeric parameters can be in either decimal or hexadecimal.

Hexadecimal numbers are indicated with a leading "$". The current setting of all options can be displayed by entering a "?" in response to the request for an input file or an option.

The Linker options are as follows:

+A Alphabetical listing of symbols. The default is -A +0 Debug information. The default is -D.

-H num -H sets the initial disk space allocated to the program's stack.

The default is to automatically include space for the program variables and the value specified in the +S option.

+L Location ordered listing of symbols. The default is -La The location is the segment name plus offset.

+M fromName toName

+M maps all occurrences of the segment fromName to the segment toName. This allows you to map several small segments into a single larger segment You can thereby postpone

segmentation decisions until link time by using many segment names in the source code.

f'IJTE

Because options have an effect only when the link begins, it is not possible to map a segment name to several different names using this option. Also, you camot use this option to map segments to or from the blank segment.

+S num +S sets the starting dynamic stacksize to 'num'. The default is 10000.

+ T num + T sets the maximum allowed location of the top of the stack to 'nurn'. The default is 128K.

+ W + W tells the Linker to get intrinsic unit information from a file other than INTRINSIC.LIB.

? Prints the options available and their current values.

7-3

WO.rf<s/Jop User's Guide TI1e Linker regular units and assembly language routines. My intrinsic units used

must be defined in INTRINSIC.LIB. chapter for information on Linker options. Press [RETURN] after each option entered. When you have entered all the options, press [RETURN] to extension; it is supplied automatically.

The linking process begins when you press [RETURN] after entering the output

· WorksIJqJ Llsef's Guide The Ljnkef

In addition to being shared on the disk, an intrinsic unit is also shared in memory.

The current implementation has no provisIon for users to create new intrinsic LIlits. All intrinsic units are supplied by Apple Computer.

7 5.1 ~ 00 I Lin< with a R~ar U1lt?

A regular unit is a separately compiled segment of code. It Is written in Pascal, and compiled like a regular program. See the PBScol Refemnce

M8nl/al fOf tIJe LjS8 for information on how to write a LI1it. See Chapter 5 in this manual for information on compiling the unit.

After you have created a unit, the routines in it can be accessed from any other program or regular unit you write. The Linker combines a main program with all units it uses. The result is an executable object file containing all the needed routines.

To use regular units with a main program, follow the procedure in Section 7.4.

~ input, you must give the Linker:

• The object file of the main program.

• The object files of all mits used by the main program.

• IOSPASLIB.OOJ, and IOSFPLIB.OOJ (if any floating point variables are USed~

The Linker combInes all these object files into an executable object fUe. It also does a dead code analysis to eliminate any routines that are not used, to redUce the sIze of the object f11e.

7.6 The lin<er Listing

A listing is produced each time a program is linked. This listing can be sent to a file, or displayed on the console (the default~ The +A option gives you

an

alphabetical list of the symbols (procedure names) used in the link. The +L option gives you a list of the names in order of their location. The listing is produced in stages,

as

follows:

1. The input files are reacJ, and a summary of the resources used is prInted.

2. . The linking process begins. Information about the si2e of each segnent is printed.

Errors are reported

as

they

are

found, and you are told whether or

not

the output is executable.

If you requested optional listings, they are also printed. M example of a Linker listing with no options requested is shown in Figure 7-1. Linker listings are mainly used for debugging at the machine code level. See O'lapter 8 for more information on the Debugger.

7-5

Workshop User's Gujde TI7e Ljr1ker 7.7 Resolving External Nanes

M external name is a symboliC entry point into an object module. All such

Wo/1(StJop User's Guide TI7e Linker

7.9 Segnentatloo

Segmenting a program makes it possible for portions of t.re program that are not being used to be swapped out to disk, thUs making better use of memory.

The way a program is segmented affects its performance.

Segmentation is controlled by three things:

• The $S Compiler command and the .SEG Assembler opUon, which assign segment names to source code modules.

• The +M Linker option, which enables you to remap compiler segment names into new segment names.

• The Changeseg utility, which enables changing the segment names prior to linking. See Chapter 10 for Information on Change5eg.

7-7

NOTES

Chapter 8

Dans le document for the Lisa'" (Page 136-148)