ld -z for 386
Piercarlo Grandi
pcg at rupert.cs.aber.ac.uk
Mon Oct 30 01:33:22 AEST 1989
Many will have realized that using option -z to ld(1) on System V 3.2 on
a 386 will not work, because the default ld script does not cater to
the -z case.
Here is an ld script that will allow you to use option -z (almost
always advisable...), as long as you specify iton the ld command line.
I have taken this out of the System V patches for G++ 1.35.0 I posted
some time ago:
--------------------------------cut here---------------------------------------
/*
This is a set of sysV 3.2 directives to assist with making the -z option
of ld(1) work. This options undefines a stretch of memory starting with
virtual address 0, thus helping to catch stray memory references
(tipically indirections thru the 0 pointer).
Unfortunately -z only redefines the memory map; this script must be also
used to ensure that the first section (.text) begins at the first valid
virtual memory map location and that it begins in the executable file at
a page boundary, so that demand loading is not misused.
On a sysV/386 pages are 0x1000 or 4096 bytes long.
*/
SECTIONS
{
/*
Ensure that text is the first section loaded
*/
.text BIND(0x00020000) /* -z starts virtual mem here */
BLOCK(0x00001000): /* Align text in file to page */
{
*(.init)
*(.text)
*(.fini)
}
/*
Ensure that data and bss begin at the next region boundary (0x400000)
and that it begins at an offset within the page that is the same as
the offset of the end of the text region (note that we *know* that
text begins on a page boundary here). This may waste some bytes in
the first page of the data+bss region, but allows it to overlap the
text region in the page table, thus saving a lot of page table space.
See the relevant article in Unix Papers (SAMS).
*/
GROUP BIND(NEXT(0x00400000) + SIZEOF(.text)%0x1000):
{
.data : { }
.bss : { }
}
}
--------------------------------cut here---------------------------------------
--
Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk at nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth | UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg at cs.aber.ac.uk
More information about the Comp.unix.i386
mailing list