CHAPTER 5: LINKER

5.10 Linking

Linking rules

The linking process takes place in conformity with the following rules:

Absolute sections are mapped ahead of relocatable sections, according to the absolute addresses which were defined at the time of assembling. If an absolute section exceeds the available memory area, an error will occur.

The relocatable sections in the file of which the section start address was specified with an option (-rcode, -rdata, -rbss) are mapped from the specified address. Other relocatable sections are mapped from top of the relocatable CODE/DATA/BSS section.

Basically, the relocatable sections except those that are specified with the -rcode, -rdata or -rbss option are arranged successively in the order of processing. However, if a relocatable section cannot be mapped subsequent to the previous mapped section, for instance, there is unused area indicated by the ICE parameter file or an already mapped absolute section, the linker searches another area to map the section. If there is no available area, an error will occur. A section is not divided into two or more blocks when it is mapped.

After that, another section may be mapped in the vacant area if it is possible to map there.

Restrictions on linking

Note that all sections may not be mapped depending on each section size or address specifications even if the relocatable object size is within the available memory size.

Example of linking

A sample case where two relocatable object files, "test1.o" and "test2.o", are linked together under the following condition is described further below.

Memory configuration of the model

Code ROM:

0x0000 to 0x1fff

Data ROM:

0x8000 to 0x87ff

RAM:

0x0000 to 0x07ff

Display, I/O memory: 0xf000 to 0xffff

 

 

 

Relocatable object files

 

 

 

 

test1.o

 

 

test2.o

 

 

 

CODE1

(relocatable)

 

CODE3

(relocatable)

 

 

CODE2

(absolute 0x0100–)

(.org is used.)

CODE4

(relocatable)

(.org is used.)

 

DATA1

(relocatable)

 

DATA2

(absolute 0x8400–)

 

 

BSS1

(relocatable)

 

BSS3

(absolute 0xff00–)

 

 

BSS2

(absolute 0xf000–)

(.org is used.)

BSS4

(relocatable)

 

Fig. 5.10.1 Structure of sample relocatable files

Sample linker command file

-code 0x0000

;

Relocatable

CODE section start address

-rcode test2.o = 0x0110 ;

CODE section start address of test2.o

-data 0x8000

;

Relocatable

DATA section start address

-bss 0x0000

;

Relocatable

BSS section start address

-rbss test2.o = 0x0400 ;

BSS section

start address of test2.o

-o test.abs

;

Output file

name

test1.o

;

Input file 1

 

test2.o

;

Input file 2

 

 

 

 

 

When linking is executed with the commands defined above, the linker maps the sections of each module in the manner graphically presented in Figure 5.10.2.

100

EPSON

S5U1C63000A MANUAL

 

 

(S1C63 FAMILY ASSEMBLER PACKAGE)