From b645b63248888247d0d9757708b5ee4041ae3410 Mon Sep 17 00:00:00 2001 From: Steve Chamberlain Date: Thu, 12 Dec 1991 00:42:50 +0000 Subject: [PATCH] * 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" --- bfd/ChangeLog | 24 ++++++ bfd/cache.c | 177 ++++++++++++++++++++++++----------------- bfd/ieee.c | 14 ++-- bfd/opncls.c | 215 ++++++++++++++++++++++++++++++++++---------------- 4 files changed, 283 insertions(+), 147 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 17f233bf1ee..fe64b187b20 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -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) * coffcode.h, srec.c: Lint. diff --git a/bfd/cache.c b/bfd/cache.c index be85f2bdb5c..d0d3f231b19 100644 --- a/bfd/cache.c +++ b/bfd/cache.c @@ -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 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/*doc* -@section File Caching -The file caching mechanism is embedded within BFD and allows the application to open as many -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 -@code{BFD_CACHE_MAX_OPEN} files, and exports the name -@code{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. +/* +SECTION + File Caching + + The file caching mechanism is embedded within BFD and allows + the application to open as many 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 + <> maintains a least recently used list of + <> files, and exports the name + <> 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$ */ -#include + #include "bfd.h" +#include "sysdep.h" #include "libbfd.h" +/* +INTERNAL_FUNCTION + BFD_CACHE_MAX_OPEN macro -/*proto-internal* BFD_CACHE_MAX_OPEN -The maxiumum number of files which the cache will keep open at one -time. -*+ -#define BFD_CACHE_MAX_OPEN 10 -*- +DESCRIPTION + The maxiumum number of files which the cache will keep open at + one time. + +.#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 opened */ -/*proto-internal* bfd_last_cache -Zero, or a pointer to the topmost BFD on the chain. This is used by -the @code{bfd_cache_lookup} macro in @file{libbfd.h} to determine when -it can avoid a function call. -*+ -extern bfd *bfd_last_cache; -*- +/* +INTERNAL_FUNCTION + 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 <> macro in @file{libbfd.h} to + determine when it can avoid a function call. */ bfd *bfd_last_cache; -/*proto-internal* bfd_cache_lookup -Checks to see if the required BFD is the same as the last one looked -up. If so then it can use the iostream in the BFD with impunity, since -it can't have changed since the last lookup, otherwise it has to -perform the complicated lookup function -*+ -#define bfd_cache_lookup(x) \ - ((x)==bfd_last_cache? \ - (FILE*)(bfd_last_cache->iostream): \ - bfd_cache_lookup_worker(x)) - -*- - -*/ +/* + * INTERNAL_FUNCTION + * bfd_cache_lookup + * + * DESCRIPTION + * Checks to see if the required BFD is the same as the last one + * looked up. If so then it can use the iostream in the BFD with + * impunity, since it can't have changed since the last lookup, + * otherwise it has to perform the complicated lookup function + * + * .#define bfd_cache_lookup(x) \ + * . ((x)==bfd_last_cache? \ + * . (FILE*)(bfd_last_cache->iostream): \ + * . bfd_cache_lookup_worker(x)) + * + * + */ static void bfd_cache_delete(); @@ -144,11 +154,16 @@ DEFUN(insert,(x,y), } -/*proto-internal* -*i bfd_cache_init -Initialize a BFD by putting it on the cache LRU. -*; PROTO(void, bfd_cache_init, (bfd *)); -*-*/ +/* +INTERNAL_FUNCTION + bfd_cache_init + +SYNOPSIS + void bfd_cache_init (bfd *); + +DESCRIPTION + Initialize a BFD by putting it on the cache LRU. +*/ void DEFUN(bfd_cache_init,(abfd), @@ -158,11 +173,17 @@ DEFUN(bfd_cache_init,(abfd), } -/*proto-internal* -*i bfd_cache_close -Remove the BFD from the cache. If the attatched file is open, then close it too. -*; PROTO(void, bfd_cache_close, (bfd *)); -*-*/ +/* +INTERNAL_FUNCTION + bfd_cache_close + +DESCRIPTION + Remove the BFD from the cache. If the attached file is open, + then close it too. + +SYNOPSIS + void bfd_cache_close (bfd *); +*/ void DEFUN(bfd_cache_close,(abfd), bfd *abfd) @@ -174,15 +195,21 @@ DEFUN(bfd_cache_close,(abfd), } } -/*proto-internal* -*i bfd_open_file -Call the OS to open a file for this BFD. Returns the FILE * -(possibly null) that results from this operation. Sets up the -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. -*; PROTO(FILE *, bfd_open_file, (bfd *)); -*-*/ +/* +INTERNAL_FUNCTION + bfd_open_file + +DESCRIPTION + Call the OS to open a file for this BFD. Returns the FILE * + (possibly null) that results from this operation. Sets up the + 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 * DEFUN(bfd_open_file, (abfd), bfd *abfd) @@ -194,18 +221,18 @@ DEFUN(bfd_open_file, (abfd), switch (abfd->direction) { case read_direction: case no_direction: - abfd->iostream = (char *) fopen(abfd->filename, "r"); + abfd->iostream = (char *) fopen(abfd->filename, "rb"); break; case both_direction: case write_direction: if (abfd->opened_once == true) { - abfd->iostream = (char *) fopen(abfd->filename, "r+"); + abfd->iostream = (char *) fopen(abfd->filename, "r+b"); if (!abfd->iostream) { - abfd->iostream = (char *) fopen(abfd->filename, "w+"); + abfd->iostream = (char *) fopen(abfd->filename, "w+b"); } } else { /*open for creat */ - abfd->iostream = (char *) fopen(abfd->filename, "w"); + abfd->iostream = (char *) fopen(abfd->filename, "wb"); abfd->opened_once = true; } break; @@ -218,15 +245,21 @@ DEFUN(bfd_open_file, (abfd), return (FILE *)(abfd->iostream); } -/*proto-internal* -*i bfd_cache_lookup_worker -Called when the macro @code{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. -*; PROTO(FILE *, bfd_cache_lookup_worker, (bfd *)); +/* +INTERNAL_FUNCTION + bfd_cache_lookup_worker + +DESCRIPTION + Called when the macro <> 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 * DEFUN(bfd_cache_lookup_worker,(abfd), diff --git a/bfd/ieee.c b/bfd/ieee.c index b433027bc35..dd4478a6886 100644 --- a/bfd/ieee.c +++ b/bfd/ieee.c @@ -1104,7 +1104,7 @@ DEFUN(ieee_object_p,(abfd), processor = ieee->mb.processor = read_id(&(ieee->h)); if (strcmp(processor,"LIBRARY") == 0) goto fail; 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; } /* Determine the architecture and machine type of the object file. @@ -1189,10 +1189,11 @@ DEFUN(ieee_print_symbol,(ignore_abfd, afile, symbol, how), #endif BFD_FAIL(); break; + case bfd_print_symbol_nm: case bfd_print_symbol_all: { CONST char *section_name = symbol->section == (asection *)NULL ? - "*abs" : symbol->section->name; + (CONST char *)"*abs" : symbol->section->name; if (symbol->name[0] == ' ') { fprintf(file,"* empty table entry "); } @@ -2398,13 +2399,14 @@ DEFUN(ieee_write_debug_part, (abfd), output_bfd = abfd; if (chain == (bfd_chain_type *)NULL) { +#if 0 /* There is no debug info, so we'll fake some up */ CONST static char fake[] = { 0xf8, 0xa, 0, 5, 't', 't', 't', 't', 't', 0, 2, 3, '1','.','1',0x82, 1991>>8, 1991 & 0xff, 9, 20, 11, 07,50 }; ieee->w.r.debug_information_part = 0; -#if 0 + here; @@ -2619,7 +2621,7 @@ CONST static char exten[] = 0xf1, 0xce, 0x20, 0x00, 38 /* set object type relocateable to x */ }; -CONST static char environ[] = +CONST static char envi[] = { 0xf0, 0x21, 0x00, @@ -2693,8 +2695,8 @@ DEFUN(ieee_write_object_contents,(abfd), else ieee_write_byte(abfd, 0x2); /* Relocateable */ - ieee->w.r.environmental_record = bfd_tell(abfd); - bfd_write(environ, 1, sizeof(environ), abfd); + ieee->w.r.envimental_record = bfd_tell(abfd); + bfd_write(envi, 1, sizeof(envi), abfd); output_bfd = abfd; flush(); diff --git a/bfd/opncls.c b/bfd/opncls.c index 9e096f4d4a8..ade9476c5a1 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -79,19 +79,26 @@ bfd *obfd; 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. -*; PROTO(bfd*, bfd_openr, (CONST char *filename,CONST char*target)); -*-*/ +/* +FUNCTION + bfd_openr + +SYNOPSIS + bfd *bfd_openr(CONST char *filename, CONST char*target); + +DESCRIPTION + This function opens the file supplied (using <>) with the target + supplied, it returns a pointer to the created BFD. + + If NULL is returned then an error has occured. Possible errors + are <>, <> or <> error. +*/ bfd * 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 the file descriptor too, even though we didn't open it. */ -/*proto* -*i bfd_fdopenr -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. +/* +FUNCTION + bfd_fdopenr -Possible errors are no_memory, invalid_target and system_call error. -*; PROTO(bfd *, bfd_fdopenr, - (CONST char *filename, CONST char *target, int fd)); -*-*/ +SYNOPSIS + bfd *bfd_fdopenr(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 * DEFUN(bfd_fdopenr,(filename, target, fd), @@ -176,10 +189,10 @@ DEFUN(bfd_fdopenr,(filename, target, fd), } #ifdef FASCIST_FDOPEN - nbfd->iostream = (char *) fdopen (fd, "r"); + nbfd->iostream = (char *) fdopen (fd, "rb"); #else /* 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 if (nbfd->iostream == NULL) { (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. */ -/*proto* bfd_openw -Creates a BFD, associated with file @var{filename}, using the file -format @var{target}, and returns a pointer to it. +/* +FUNCTION + bfd_openw + +SYNOPSIS + bfd *bfd_openw(CONST char *filename, CONST char *target); -Possible errors are system_call_error, no_memory, invalid_target. -*; PROTO(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 * @@ -252,18 +272,28 @@ DEFUN(bfd_openw,(filename, target), 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. +/* + +FUNCTION + bfd_close + +SYNOPSIS + boolean bfd_close(bfd *); + +DESCRIPTION -All memory attached to the BFD's obstacks is released. + 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 + <> is called to mark it as such. -@code{true} is returned if all is ok, otherwise @code{false}. -*; PROTO(boolean, bfd_close,(bfd *)); + All memory attached to the BFD's obstacks is released. + +RETURNS + <> is returned if all is ok, otherwise <>. */ + boolean DEFUN(bfd_close,(abfd), bfd *abfd) @@ -292,26 +322,34 @@ DEFUN(bfd_close,(abfd), #define S_IXOTH 0001 /* Execute by others. */ #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) free(abfd); return true; } -/*proto* bfd_close_all_done -This function closes a BFD. It differs from @code{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. +/* +FUNCTION + bfd_close_all_done + +SYNOPSIS + boolean bfd_close_all_done(bfd *); + +DESCRIPTION + This function closes a BFD. It differs from <> + 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 @code{chmod} is called to mark -it as such. + If the created file is executable, then <> is called + to mark it as such. -All memory attached to the BFD's obstacks is released. + All memory attached to the BFD's obstacks is released. + +RETURNS + <> is returned if all is ok, otherwise <>. -@code{true} is returned if all is ok, otherwise @code{false}. -*; PROTO(boolean, bfd_close_all_done,(bfd *)); */ boolean @@ -336,19 +374,55 @@ DEFUN(bfd_close_all_done,(abfd), #define S_IXOTH 0001 /* Execute by others. */ #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) free(abfd); 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 + <>, 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 * @@ -370,9 +444,21 @@ DEFUN(bfd_create,(filename, template), return nbfd; } -/* Memory allocation */ +/* +INTERNAL_FUNCTION + bfd_alloc_by_size_t + +SYNOPSIS + PTR bfd_alloc_by_size_t(bfd *abfd, size_t wanted); -DEFUN(PTR bfd_alloc_by_size_t,(abfd, size), +DESCRIPTION + This function allocates a block of memory in the obstack + attatched to <> and returns a pointer to it. +*/ + + +PTR +DEFUN(bfd_alloc_by_size_t,(abfd, size), bfd *abfd AND size_t size) { @@ -419,21 +505,12 @@ DEFUN(PTR bfd_realloc,(abfd, old, size), 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; -} + + + + + + + + -- 2.30.2