* makefile.dos, configdj.bat: New files from DJ

* cache.c: fopen with "b" is needed for DOS.
	* ieee.c: environ renamed to envi to stop an include file
	conflict.
	* opncls.c: more fopens with "b"
This commit is contained in:
Steve Chamberlain 1991-12-12 00:42:50 +00:00
parent c06ac69051
commit b645b63248
4 changed files with 282 additions and 146 deletions

View file

@ -1,3 +1,27 @@
Wed Dec 11 16:39:45 1991 Steve Chamberlain (sac at rtl.cygnus.com)
* makefile.dos, configdj.bat: New files from DJ
* cache.c: fopen with "b" is needed for DOS.
* ieee.c: environ renamed to envi to stop an include file
conflict.
* opncls.c: more fopens with "b"
Tue Dec 10 04:07:24 1991 K. Richard Pixley (rich at rtl.cygnus.com)
* Makefile.in: infodir belongs in datadir.
Sat Dec 7 16:39:23 1991 Steve Chamberlain (sac at rtl.cygnus.com)
* Makefile.in: fix where docdir lives
* aoutx.h, archive.c, archures.c, bfd.c, cache.c, coff-m88k.c,
coffcode.h, core.c, ctor.c, elf.c, format.c, ieee.c, init.c,
libbfd.c, libbfd.h, libcoff.h, opncls.c, reloc.c, section.c,
srec.c, syms.c, targets.c : all new documentation and lint
removal.
Sat Dec 7 07:22:09 1991 John Gilmore (gnu at cygnus.com) Sat Dec 7 07:22:09 1991 John Gilmore (gnu at cygnus.com)
* coffcode.h, srec.c: Lint. * coffcode.h, srec.c: Lint.

View file

@ -18,34 +18,38 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/*doc* /*
@section File Caching SECTION
The file caching mechanism is embedded within BFD and allows the application to open as many File Caching
BFDs as it wants without regard to the underlying operating system's
file descriptor limit (often as low as 20 open files).
The module in @code{cache.c} maintains a least recently used list of The file caching mechanism is embedded within BFD and allows
@code{BFD_CACHE_MAX_OPEN} files, and exports the name the application to open as many BFDs as it wants without
@code{bfd_cache_lookup} which runs around and makes sure that the regard to the underlying operating system's file descriptor
required BFD is open. If not, then it chooses a file to close, closes limit (often as low as 20 open files). The module in
it and opens the one wanted, returning its file handle. <<cache.c>> maintains a least recently used list of
<<BFD_CACHE_MAX_OPEN>> files, and exports the name
<<bfd_cache_lookup>> which runs around and makes sure that
the required BFD is open. If not, then it chooses a file to
close, closes it and opens the one wanted, returning its file
handle.
*/ */
/* $Id$ */ /* $Id$ */
#include <sysdep.h>
#include "bfd.h" #include "bfd.h"
#include "sysdep.h"
#include "libbfd.h" #include "libbfd.h"
/*
INTERNAL_FUNCTION
BFD_CACHE_MAX_OPEN macro
/*proto-internal* BFD_CACHE_MAX_OPEN DESCRIPTION
The maxiumum number of files which the cache will keep open at one The maxiumum number of files which the cache will keep open at
time. one time.
*+
#define BFD_CACHE_MAX_OPEN 10 .#define BFD_CACHE_MAX_OPEN 10
*-
*/ */
@ -55,32 +59,38 @@ static int open_files;
static bfd *cache_sentinel; /* Chain of BFDs with active fds we've static bfd *cache_sentinel; /* Chain of BFDs with active fds we've
opened */ opened */
/*proto-internal* bfd_last_cache /*
Zero, or a pointer to the topmost BFD on the chain. This is used by INTERNAL_FUNCTION
the @code{bfd_cache_lookup} macro in @file{libbfd.h} to determine when bfd_last_cache
it can avoid a function call.
*+
extern bfd *bfd_last_cache;
*-
SYNOPSIS
extern bfd *bfd_last_cache;
DESCRIPTION
Zero, or a pointer to the topmost BFD on the chain. This is
used by the <<bfd_cache_lookup>> macro in @file{libbfd.h} to
determine when it can avoid a function call.
*/ */
bfd *bfd_last_cache; bfd *bfd_last_cache;
/*proto-internal* bfd_cache_lookup /*
Checks to see if the required BFD is the same as the last one looked * INTERNAL_FUNCTION
up. If so then it can use the iostream in the BFD with impunity, since * bfd_cache_lookup
it can't have changed since the last lookup, otherwise it has to *
perform the complicated lookup function * DESCRIPTION
*+ * Checks to see if the required BFD is the same as the last one
#define bfd_cache_lookup(x) \ * looked up. If so then it can use the iostream in the BFD with
((x)==bfd_last_cache? \ * impunity, since it can't have changed since the last lookup,
(FILE*)(bfd_last_cache->iostream): \ * otherwise it has to perform the complicated lookup function
bfd_cache_lookup_worker(x)) *
* .#define bfd_cache_lookup(x) \
*- * . ((x)==bfd_last_cache? \
* . (FILE*)(bfd_last_cache->iostream): \
*/ * . bfd_cache_lookup_worker(x))
*
*
*/
static void bfd_cache_delete(); static void bfd_cache_delete();
@ -144,11 +154,16 @@ DEFUN(insert,(x,y),
} }
/*proto-internal* /*
*i bfd_cache_init INTERNAL_FUNCTION
Initialize a BFD by putting it on the cache LRU. bfd_cache_init
*; PROTO(void, bfd_cache_init, (bfd *));
*-*/ SYNOPSIS
void bfd_cache_init (bfd *);
DESCRIPTION
Initialize a BFD by putting it on the cache LRU.
*/
void void
DEFUN(bfd_cache_init,(abfd), DEFUN(bfd_cache_init,(abfd),
@ -158,11 +173,17 @@ DEFUN(bfd_cache_init,(abfd),
} }
/*proto-internal* /*
*i bfd_cache_close INTERNAL_FUNCTION
Remove the BFD from the cache. If the attatched file is open, then close it too. bfd_cache_close
*; PROTO(void, bfd_cache_close, (bfd *));
*-*/ DESCRIPTION
Remove the BFD from the cache. If the attached file is open,
then close it too.
SYNOPSIS
void bfd_cache_close (bfd *);
*/
void void
DEFUN(bfd_cache_close,(abfd), DEFUN(bfd_cache_close,(abfd),
bfd *abfd) bfd *abfd)
@ -174,15 +195,21 @@ DEFUN(bfd_cache_close,(abfd),
} }
} }
/*proto-internal* /*
*i bfd_open_file INTERNAL_FUNCTION
Call the OS to open a file for this BFD. Returns the FILE * bfd_open_file
(possibly null) that results from this operation. Sets up the
BFD so that future accesses know the file is open. If the FILE * DESCRIPTION
returned is null, then there is won't have been put in the cache, so Call the OS to open a file for this BFD. Returns the FILE *
it won't have to be removed from it. (possibly null) that results from this operation. Sets up the
*; PROTO(FILE *, bfd_open_file, (bfd *)); BFD so that future accesses know the file is open. If the FILE
*-*/ * returned is null, then there is won't have been put in the
cache, so it won't have to be removed from it.
SYNOPSIS
FILE* bfd_open_file(bfd *);
*/
FILE * FILE *
DEFUN(bfd_open_file, (abfd), DEFUN(bfd_open_file, (abfd),
bfd *abfd) bfd *abfd)
@ -194,18 +221,18 @@ DEFUN(bfd_open_file, (abfd),
switch (abfd->direction) { switch (abfd->direction) {
case read_direction: case read_direction:
case no_direction: case no_direction:
abfd->iostream = (char *) fopen(abfd->filename, "r"); abfd->iostream = (char *) fopen(abfd->filename, "rb");
break; break;
case both_direction: case both_direction:
case write_direction: case write_direction:
if (abfd->opened_once == true) { if (abfd->opened_once == true) {
abfd->iostream = (char *) fopen(abfd->filename, "r+"); abfd->iostream = (char *) fopen(abfd->filename, "r+b");
if (!abfd->iostream) { if (!abfd->iostream) {
abfd->iostream = (char *) fopen(abfd->filename, "w+"); abfd->iostream = (char *) fopen(abfd->filename, "w+b");
} }
} else { } else {
/*open for creat */ /*open for creat */
abfd->iostream = (char *) fopen(abfd->filename, "w"); abfd->iostream = (char *) fopen(abfd->filename, "wb");
abfd->opened_once = true; abfd->opened_once = true;
} }
break; break;
@ -218,15 +245,21 @@ DEFUN(bfd_open_file, (abfd),
return (FILE *)(abfd->iostream); return (FILE *)(abfd->iostream);
} }
/*proto-internal* /*
*i bfd_cache_lookup_worker INTERNAL_FUNCTION
Called when the macro @code{bfd_cache_lookup} fails to find a quick bfd_cache_lookup_worker
answer. Finds a file descriptor for this BFD. If necessary, it open it.
If there are already more than BFD_CACHE_MAX_OPEN files open, it trys to close
one first, to avoid running out of file descriptors.
*; PROTO(FILE *, bfd_cache_lookup_worker, (bfd *));
*-*/ DESCRIPTION
Called when the macro <<bfd_cache_lookup>> fails to find a
quick answer. Finds a file descriptor for this BFD. If
necessary, it open it. If there are already more than
BFD_CACHE_MAX_OPEN files open, it trys to close one first, to
avoid running out of file descriptors.
SYNOPSIS
FILE *bfd_cache_lookup_worker(bfd *);
*/
FILE * FILE *
DEFUN(bfd_cache_lookup_worker,(abfd), DEFUN(bfd_cache_lookup_worker,(abfd),

View file

@ -1104,7 +1104,7 @@ DEFUN(ieee_object_p,(abfd),
processor = ieee->mb.processor = read_id(&(ieee->h)); processor = ieee->mb.processor = read_id(&(ieee->h));
if (strcmp(processor,"LIBRARY") == 0) goto fail; if (strcmp(processor,"LIBRARY") == 0) goto fail;
ieee->mb.module_name = read_id(&(ieee->h)); ieee->mb.module_name = read_id(&(ieee->h));
if (abfd->filename == (char *)NULL) { if (abfd->filename == (CONST char *)NULL) {
abfd->filename = ieee->mb.module_name; abfd->filename = ieee->mb.module_name;
} }
/* Determine the architecture and machine type of the object file. /* Determine the architecture and machine type of the object file.
@ -1189,10 +1189,11 @@ DEFUN(ieee_print_symbol,(ignore_abfd, afile, symbol, how),
#endif #endif
BFD_FAIL(); BFD_FAIL();
break; break;
case bfd_print_symbol_nm:
case bfd_print_symbol_all: case bfd_print_symbol_all:
{ {
CONST char *section_name = symbol->section == (asection *)NULL ? CONST char *section_name = symbol->section == (asection *)NULL ?
"*abs" : symbol->section->name; (CONST char *)"*abs" : symbol->section->name;
if (symbol->name[0] == ' ') { if (symbol->name[0] == ' ') {
fprintf(file,"* empty table entry "); fprintf(file,"* empty table entry ");
} }
@ -2398,13 +2399,14 @@ DEFUN(ieee_write_debug_part, (abfd),
output_bfd = abfd; output_bfd = abfd;
if (chain == (bfd_chain_type *)NULL) { if (chain == (bfd_chain_type *)NULL) {
#if 0
/* There is no debug info, so we'll fake some up */ /* There is no debug info, so we'll fake some up */
CONST static char fake[] = { CONST static char fake[] = {
0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3, 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3,
'1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 }; '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 };
ieee->w.r.debug_information_part = 0; ieee->w.r.debug_information_part = 0;
#if 0
here; here;
@ -2619,7 +2621,7 @@ CONST static char exten[] =
0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */ 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */
}; };
CONST static char environ[] = CONST static char envi[] =
{ {
0xf0, 0x21, 0x00, 0xf0, 0x21, 0x00,
@ -2693,8 +2695,8 @@ DEFUN(ieee_write_object_contents,(abfd),
else else
ieee_write_byte(abfd, 0x2); /* Relocateable */ ieee_write_byte(abfd, 0x2); /* Relocateable */
ieee->w.r.environmental_record = bfd_tell(abfd); ieee->w.r.envimental_record = bfd_tell(abfd);
bfd_write(environ, 1, sizeof(environ), abfd); bfd_write(envi, 1, sizeof(envi), abfd);
output_bfd = abfd; output_bfd = abfd;
flush(); flush();

View file

@ -79,19 +79,26 @@ bfd *obfd;
return nbfd; return nbfd;
} }
/*doc* /*
@section Opening and Closing BFDs SECTION
Opening and Closing BFDs
*/ */
/*proto*
*i bfd_openr
Opens the file supplied (using @code{fopen}) with the target supplied, it
returns a pointer to the created BFD.
If NULL is returned then an error has occured. /*
Possible errors are no_memory, invalid_target or system_call error. FUNCTION
*; PROTO(bfd*, bfd_openr, (CONST char *filename,CONST char*target)); bfd_openr
*-*/
SYNOPSIS
bfd *bfd_openr(CONST char *filename, CONST char*target);
DESCRIPTION
This function opens the file supplied (using <<fopen>>) with the target
supplied, it returns a pointer to the created BFD.
If NULL is returned then an error has occured. Possible errors
are <<no_memory>>, <<invalid_target>> or <<system_call>> error.
*/
bfd * bfd *
DEFUN(bfd_openr, (filename, target), DEFUN(bfd_openr, (filename, target),
@ -133,15 +140,21 @@ DEFUN(bfd_openr, (filename, target),
close it if anything goes wrong. Closing the stream means closing close it if anything goes wrong. Closing the stream means closing
the file descriptor too, even though we didn't open it. the file descriptor too, even though we didn't open it.
*/ */
/*proto* /*
*i bfd_fdopenr FUNCTION
bfd_fdopenr is to bfd_fopenr much like fdopen is to fopen. It opens a BFD on bfd_fdopenr
a file already described by the @var{fd} supplied.
Possible errors are no_memory, invalid_target and system_call error. SYNOPSIS
*; PROTO(bfd *, bfd_fdopenr, bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd);
(CONST char *filename, CONST char *target, int fd));
*-*/ DESCRIPTION
bfd_fdopenr is to bfd_fopenr much like fdopen is to fopen.
It opens a BFD on a file already described by the @var{fd}
supplied.
Possible errors are no_memory, invalid_target and system_call
error.
*/
bfd * bfd *
DEFUN(bfd_fdopenr,(filename, target, fd), DEFUN(bfd_fdopenr,(filename, target, fd),
@ -176,10 +189,10 @@ DEFUN(bfd_fdopenr,(filename, target, fd),
} }
#ifdef FASCIST_FDOPEN #ifdef FASCIST_FDOPEN
nbfd->iostream = (char *) fdopen (fd, "r"); nbfd->iostream = (char *) fdopen (fd, "rb");
#else #else
/* if the fd were open for read only, this still would not hurt: */ /* if the fd were open for read only, this still would not hurt: */
nbfd->iostream = (char *) fdopen (fd, "r+"); nbfd->iostream = (char *) fdopen (fd, "r+b");
#endif #endif
if (nbfd->iostream == NULL) { if (nbfd->iostream == NULL) {
(void) obstack_free (&nbfd->memory, (PTR)0); (void) obstack_free (&nbfd->memory, (PTR)0);
@ -211,12 +224,19 @@ DEFUN(bfd_fdopenr,(filename, target, fd),
See comment by bfd_fdopenr before you try to modify this function. */ See comment by bfd_fdopenr before you try to modify this function. */
/*proto* bfd_openw /*
Creates a BFD, associated with file @var{filename}, using the file FUNCTION
format @var{target}, and returns a pointer to it. bfd_openw
Possible errors are system_call_error, no_memory, invalid_target. SYNOPSIS
*; PROTO(bfd *, bfd_openw, (CONST char *filename, CONST char *target)); bfd *bfd_openw(CONST char *filename, CONST char *target);
DESCRIPTION
Creates a BFD, associated with file @var{filename}, using the
file format @var{target}, and returns a pointer to it.
Possible errors are system_call_error, no_memory,
invalid_target.
*/ */
bfd * bfd *
@ -252,18 +272,28 @@ DEFUN(bfd_openw,(filename, target),
return nbfd; return nbfd;
} }
/*proto* bfd_close /*
This function closes a BFD. If the BFD was open for writing, then
pending operations are completed and the file written out and closed.
If the created file is executable, then @code{chmod} is called to mark
it as such.
All memory attached to the BFD's obstacks is released. FUNCTION
bfd_close
@code{true} is returned if all is ok, otherwise @code{false}. SYNOPSIS
*; PROTO(boolean, bfd_close,(bfd *)); boolean bfd_close(bfd *);
DESCRIPTION
This function closes a BFD. If the BFD was open for writing,
then pending operations are completed and the file written out
and closed. If the created file is executable, then
<<chmod>> is called to mark it as such.
All memory attached to the BFD's obstacks is released.
RETURNS
<<true>> is returned if all is ok, otherwise <<false>>.
*/ */
boolean boolean
DEFUN(bfd_close,(abfd), DEFUN(bfd_close,(abfd),
bfd *abfd) bfd *abfd)
@ -292,26 +322,34 @@ DEFUN(bfd_close,(abfd),
#define S_IXOTH 0001 /* Execute by others. */ #define S_IXOTH 0001 /* Execute by others. */
#endif #endif
chmod(abfd->filename,buf.st_mode | S_IXUSR | S_IXGRP | S_IXOTH); chmod(abfd->filename, 0777 & (buf.st_mode | S_IXUSR | S_IXGRP | S_IXOTH));
} }
(void) obstack_free (&abfd->memory, (PTR)0); (void) obstack_free (&abfd->memory, (PTR)0);
(void) free(abfd); (void) free(abfd);
return true; return true;
} }
/*proto* bfd_close_all_done /*
This function closes a BFD. It differs from @code{bfd_close} since it FUNCTION
does not complete any pending operations. This routine would be used bfd_close_all_done
if the application had just used BFD for swapping and didn't want to
use any of the writing code.
If the created file is executable, then @code{chmod} is called to mark SYNOPSIS
it as such. boolean bfd_close_all_done(bfd *);
All memory attached to the BFD's obstacks is released. DESCRIPTION
This function closes a BFD. It differs from <<bfd_close>>
since it does not complete any pending operations. This
routine would be used if the application had just used BFD for
swapping and didn't want to use any of the writing code.
If the created file is executable, then <<chmod>> is called
to mark it as such.
All memory attached to the BFD's obstacks is released.
RETURNS
<<true>> is returned if all is ok, otherwise <<false>>.
@code{true} is returned if all is ok, otherwise @code{false}.
*; PROTO(boolean, bfd_close_all_done,(bfd *));
*/ */
boolean boolean
@ -336,19 +374,55 @@ DEFUN(bfd_close_all_done,(abfd),
#define S_IXOTH 0001 /* Execute by others. */ #define S_IXOTH 0001 /* Execute by others. */
#endif #endif
chmod(abfd->filename,buf.st_mode | S_IXUSR | S_IXGRP | S_IXOTH); chmod(abfd->filename, 0x777 &(buf.st_mode | S_IXUSR | S_IXGRP | S_IXOTH));
} }
(void) obstack_free (&abfd->memory, (PTR)0); (void) obstack_free (&abfd->memory, (PTR)0);
(void) free(abfd); (void) free(abfd);
return true; return true;
} }
/*proto* bfd_create
This routine creates a new BFD in the manner of @code{bfd_openw}, but without
opening a file. The new BFD takes the target from the target used by
@var{template}. The format is always set to @code{bfd_object}.
*; PROTO(bfd *, bfd_create, (CONST char *filename, bfd *template)); /*
FUNCTION
bfd_alloc_size
SYNOPSIS
bfd_size_type bfd_alloc_size(bfd *abfd);
DESCRIPTION
Return the number of bytes in the obstacks connected to the
supplied BFD.
*/
bfd_size_type
DEFUN(bfd_alloc_size,(abfd),
bfd *abfd)
{
struct _obstack_chunk *chunk = abfd->memory.chunk;
size_t size = 0;
while (chunk) {
size += chunk->limit - &(chunk->contents[0]);
chunk = chunk->prev;
}
return size;
}
/*
FUNCTION
bfd_create
SYNOPSIS
bfd *bfd_create(CONST char *filename, bfd *template);
DESCRIPTION
This routine creates a new BFD in the manner of
<<bfd_openw>>, but without opening a file. The new BFD
takes the target from the target used by @var{template}. The
format is always set to <<bfd_object>>.
*/ */
bfd * bfd *
@ -370,9 +444,21 @@ DEFUN(bfd_create,(filename, template),
return nbfd; return nbfd;
} }
/* Memory allocation */ /*
INTERNAL_FUNCTION
bfd_alloc_by_size_t
DEFUN(PTR bfd_alloc_by_size_t,(abfd, size), SYNOPSIS
PTR bfd_alloc_by_size_t(bfd *abfd, size_t wanted);
DESCRIPTION
This function allocates a block of memory in the obstack
attatched to <<abfd>> and returns a pointer to it.
*/
PTR
DEFUN(bfd_alloc_by_size_t,(abfd, size),
bfd *abfd AND bfd *abfd AND
size_t size) size_t size)
{ {
@ -419,21 +505,12 @@ DEFUN(PTR bfd_realloc,(abfd, old, size),
return res; return res;
} }
/*proto* bfd_alloc_size
Return the number of bytes in the obstacks connected to the supplied
BFD.
*; PROTO(bfd_size_type,bfd_alloc_size,(bfd *abfd));
*/
bfd_size_type
DEFUN( bfd_alloc_size,(abfd),
bfd *abfd)
{
struct _obstack_chunk *chunk = abfd->memory.chunk;
size_t size = 0;
while (chunk) {
size += chunk->limit - &(chunk->contents[0]);
chunk = chunk->prev;
}
return size;
}