Xref: utzoo comp.unix.wizards:22810 comp.unix.i386:6639 Path: utzoo!attcan!uunet!mcsun!ukc!dcl-cs!aber-cs!odin!pcg From: pcg@cs.aber.ac.uk (Piercarlo Grandi) Newsgroups: comp.unix.wizards,comp.unix.i386 Subject: Re: Implementing NULL trapping on AT&T SVR3.2(.2) Message-ID: Date: 9 Jul 90 11:48:16 GMT References: <412@minya.UUCP> <13291@smoke.BRL.MIL> <1990Jul5.174608.17336@eci386.uucp> <1990Jul6.115941.11096@cbnews.att.com> Sender: pcg@aber-cs.UUCP Organization: Coleg Prifysgol Cymru Lines: 146 In-reply-to: pcg@cs.aber.ac.uk's message of 7 Jul 90 16:25:36 GMT In article I, pcg@cs.aber.ac.uk (Piercarlo Grandi), write: In article <1990Jul5.174608.17336@eci386.uucp> clewis@eci386.UUCP (Chris Lewis) writes: On System V (I'm 386/ix 1.0.6), the memory layout of an executable By the way: take advantage of ISC's *generous* upgrade policy and get up to 2.x, which is vastly improved, or get (for probably much less than the upgrade cost) ESIX rev. D, which apparently has the Berkeley FFS, as well as RFS, TCP/IP, X11, etc... program is controlled by a default loader control file ("ifile"), ... 386 one uses the "defaults" built into "ld"'s binary, which I can't seem to be able to reconstruct from the 386/ix Guide entries for the loader. [ ... ] I had posted some months ago a full set of patches to g++ 1.36.x that contained this ifile, and the ifile itself separately. If any kind soul has saved, they might want to repost it (should go in the frequently asked questions writeup) or send it to Chris Lewis (my copy is on my home machine, i.e. not handy here). Well, given my infinite generosity I have myself brought over from home the ifile concerned, embellished it a bit, and here it is: -----------------------cut here----------------------------------- /* Copyright 1989,1990 Piercarlo Grandi. All rights reserved. This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You may have received a copy of the GNU General Public License along with this source; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* 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 still possible. On a sysV/386 pages are 0x1000 or 4K bytes long, and segments are 0x400000 or 4M bytes long. */ /* Just for curiosity, here are the directives that would set up the memory map appropriately (well, the stack is a bit bogus); if you use these, you can leave option -z out, but you get a limit on the number of supported shared libraries. Note that -z starts coede at 0x00020000; my manipulating three values you can change that. Note that the address of the shared libraries after the 1st are a bit speculative, as is the origin and length of the stack. The kernel and uarea ranges are ther eonly if you want to do funny things; they could be easily left out. If you want to use them, you have to use a noload section. */ /* MEMORY { code (RXI) : origin=0x00020000,length=0x003e0000 data (RWXI) : origin=0x00400000,length=0x00400000 stack (RWX) : origin=0x40000000,length=0x40000000 code1 (RX) : origin=0xa0000000,length=0x00400000 data1 (RX) : origin=0xa0400000,length=0x00400000 code2 (RX) : origin=0xa0800000,length=0x00400000 data2 (RX) : origin=0xa0c00000,length=0x00400000 code3 (RX) : origin=0xa1000000,length=0x00400000 data3 (RX) : origin=0xa1400000,length=0x00400000 code4 (RX) : origin=0xa1800000,length=0x00400000 data4 (RX) : origin=0xa1c00000,length=0x00400000 kernel (RX) : origin=0xd0010000,length=0x003f0000 uarea (R) : origin=0xe0000000,length=0x00020000 } */ SECTIONS { /* Ensure that text is the first section loaded. Note that we align the start of code to the first 4K bytes in the object file to make it possible to demand load it. We could have instead aligned it to the address immediately after the end of the COFF headers, but ld does not give us a primitive with the size of the COFF header. We therefore align code to a page boundary, and this incidentally leaves the first 4K bytes free to the COFF headers. They should never even approach that size, so it is a bit of disk space waste, but demand loading is important, and also peace of mind that they do not overwrite the beginning of the code section. */ .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 : { } } } -- Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk