From: "Tim Van Holder" To: Subject: RE: Where does gcc -o foo make foo.exe Date: Sun, 14 Jan 2001 13:03:08 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id HAA11689 Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > ??? BFD may be _reading_ the stub, but I'm guessing that it's the > application (ld, in this case) which tells it from what file to read it. > Otherwise, that would mean that GO32STUB etc. are also pushed to the BFD > level, which I don't think is true. I just checked the current weekly snapshot; only coff-stgo32.c references $GO32STUB. There's a function create_go32_stub that adds a stub to the given bfd. It checks $GO32STUB and $STUB for a file to takze the stub from, otherwise it uses the built-in one. I've included the source of this function below. == coff-stgo32.c snippet static void create_go32_stub (abfd) bfd *abfd; { /* Do it only once */ if (bfd_coff_go32stub (abfd) == NULL) { char *stub; struct stat st; int f; unsigned char header[10]; char magic[8]; unsigned long coff_start, exe_start; /* Check at first the environment variable $(GO32STUB) */ stub = getenv ("GO32STUB"); /* Now check the environment variable $(STUB) */ if (stub == NULL) stub = getenv ("STUB"); if (stub == NULL) goto stub_end; if (stat (stub, &st) != 0) goto stub_end; #ifdef O_BINARY f = open (stub, O_RDONLY | O_BINARY); #else f = open (stub, O_RDONLY); #endif if (f < 0) goto stub_end; if (read (f, &header, sizeof (header)) < 0) { close (f); goto stub_end; } if (_H (0) != 0x5a4d) /* it is not an exe file */ { close (f); goto stub_end; } /* Compute the size of the stub (it is every thing up to the beginning of the coff image) */ coff_start = (long) _H (2) * 512L; if (_H (1)) coff_start += (long) _H (1) - 512L; /* Currently there is only a fixed stub size of 2048 bytes supported */ if (coff_start != 2048) { close (f); goto stub_end; } exe_start = _H (4) * 16; if ((unsigned long) lseek (f, exe_start, SEEK_SET) != exe_start) { close (f); goto stub_end; } if (read (f, &magic, 8) != 8) { close (f); goto stub_end; } if (memcmp (magic, "go32stub", 8) != 0) { close (f); goto stub_end; } /* Now we found a correct stub (hopefully) */ bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, coff_start); if (bfd_coff_go32stub (abfd) == NULL) { close (f); return; } lseek (f, 0L, SEEK_SET); if ((unsigned long) read (f, bfd_coff_go32stub (abfd), coff_start) != coff_start) { bfd_release (abfd, bfd_coff_go32stub (abfd)); bfd_coff_go32stub (abfd) = NULL; } close (f); } stub_end: /* There was something wrong above, so use now the standard builtin stub */ if (bfd_coff_go32stub (abfd) == NULL) { bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, STUBSIZE); if (bfd_coff_go32stub (abfd) == NULL) { return; } memcpy (bfd_coff_go32stub (abfd), stub_bytes, STUBSIZE); } } == end of snippet