The location counter and OVERLAY command in linker script

Tao Zhang zhangtao@cc.gatech.edu
Fri Jul 23 02:50:00 GMT 2004


Hi, all

I am trying to write a linker script to overlay some code.
I got into some problems and need help badly..

Below is a piece of code in linker script performing overlay.

OVERLAY         :
{
	.ovly0 { bar1.o(.text) }
	.ovly1 { bar2.o(.text) }
	.ovly2 { bar3.o(.text) }
} :text
.leftover         :
{
	*(.text .stub .text.* .gnu.linkonce.t.*)
	/* .gnu.warning sections are handled specially by elf32.em.  */
	*(.gnu.warning)
} : text

It is not working and I got some error message like:

section .leftover [0000000000007e00 -> 000000000000914f]
overlaps section .ovly1 [0000000000007d00 -> 0000000000007eff]

Through some experiments, I think the problem is due to the linker
doesn't update the location couter properly for OVERLAY command.
According to the manual, "At the end of the overlay, the value of .
is set to the start address of the overlay plus the size of the
largest section." I don't understand why the location counter is
plused by the size of largest section rather than the size of
all the sections in OVERLAY. I think this location counter is recording
the
output section location, and all the sections in the OVERLAY command
should present physically in the program binary, right? So why not plus
the size of all the sections?  If this location couter is recording the
location in virtual memory space, then plusing the size of largest section
is reasonable, but it looks not the case.

I changed the script to the following:

	_temp = .;
	OVERLAY         :
	{
		.ovly0 { bar1.o(.text) }
		.ovly1 { bar2.o(.text) }
		.ovly2 { bar3.o(.text) }
	} :text
	. = _temp;
	. += SIZEOF(.ovly0);
	. += SIZEOF(.ovly1);
	. += SIZEOF(.ovly2);

After linking, the dump from objdump -h is :

[skip...]
  3 .ovly0        00000100  00007c00  00007c00  00007c00  2**6
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .ovly1        00000200  00007c00  00007d00  00007d00  2**6
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  5 .ovly2        00000080  00007c00  00007f00  00007f00  2**6
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  6 .leftover     00001350  00007f80  00007f80  00007f80  2**6
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

This is what I want, so the above hack works for me. But I believe
it is not supposed to work in that way. So could anybody clarify my
confusion on location counter and show me how to do this decently?

Thanks so much!

Tao




			-Tao Zhang (zhangtao@cc.gatech.edu)



More information about the Binutils mailing list