bfd.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,238 行 · 第 1/3 页

C
1,238
字号
_bfd_default_error_handler (const char *s, ...){  va_list p;  if (_bfd_error_program_name != NULL)    fprintf (stderr, "%s: ", _bfd_error_program_name);  else    fprintf (stderr, "BFD: ");  va_start (p, s);  vfprintf (stderr, s, p);  va_end (p);  fprintf (stderr, "\n");}#else /* ! defined (ANSI_PROTOTYPES) */static void _bfd_default_error_handler ();static void_bfd_default_error_handler (va_alist)     va_dcl{  va_list p;  const char *s;  if (_bfd_error_program_name != NULL)    fprintf (stderr, "%s: ", _bfd_error_program_name);  else    fprintf (stderr, "BFD: ");  va_start (p);  s = va_arg (p, const char *);  vfprintf (stderr, s, p);  va_end (p);  fprintf (stderr, "\n");}#endif /* ! defined (ANSI_PROTOTYPES) *//* This is a function pointer to the routine which should handle BFD   error messages.  It is called when a BFD routine encounters an   error for which it wants to print a message.  Going through a   function pointer permits a program linked against BFD to intercept   the messages and deal with them itself.  */bfd_error_handler_type _bfd_error_handler = _bfd_default_error_handler;/*FUNCTION	bfd_set_error_handlerSYNOPSIS	bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);DESCRIPTION	Set the BFD error handler function.  Returns the previous	function.*/bfd_error_handler_typebfd_set_error_handler (pnew)     bfd_error_handler_type pnew;{  bfd_error_handler_type pold;  pold = _bfd_error_handler;  _bfd_error_handler = pnew;  return pold;}/*FUNCTION	bfd_set_error_program_nameSYNOPSIS	void bfd_set_error_program_name (const char *);DESCRIPTION	Set the program name to use when printing a BFD error.  This	is printed before the error message followed by a colon and	space.  The string must not be changed after it is passed to	this function.*/voidbfd_set_error_program_name (name)     const char *name;{  _bfd_error_program_name = name;}/*FUNCTION	bfd_get_error_handlerSYNOPSIS	bfd_error_handler_type bfd_get_error_handler (void);DESCRIPTION	Return the BFD error handler function.*/bfd_error_handler_typebfd_get_error_handler (){  return _bfd_error_handler;}/*SECTION	Symbols*//*FUNCTION	bfd_get_reloc_upper_boundSYNOPSIS	long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);DESCRIPTION	Return the number of bytes required to store the	relocation information associated with section @var{sect}	attached to bfd @var{abfd}.  If an error occurs, return -1.*/longbfd_get_reloc_upper_bound (abfd, asect)     bfd *abfd;     sec_ptr asect;{  if (abfd->format != bfd_object) {    bfd_set_error (bfd_error_invalid_operation);    return -1;  }  return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect));}/*FUNCTION	bfd_canonicalize_relocSYNOPSIS	long bfd_canonicalize_reloc        	(bfd *abfd,		asection *sec,		arelent **loc,		asymbol	**syms);DESCRIPTION	Call the back end associated with the open BFD	@var{abfd} and translate the external form of the relocation	information attached to @var{sec} into the internal canonical	form.  Place the table into memory at @var{loc}, which has	been preallocated, usually by a call to	<<bfd_get_reloc_upper_bound>>.  Returns the number of relocs, or	-1 on error.	The @var{syms} table is also needed for horrible internal magic	reasons.*/longbfd_canonicalize_reloc (abfd, asect, location, symbols)     bfd *abfd;     sec_ptr asect;     arelent **location;     asymbol **symbols;{  if (abfd->format != bfd_object) {    bfd_set_error (bfd_error_invalid_operation);    return -1;  }  return BFD_SEND (abfd, _bfd_canonicalize_reloc,		   (abfd, asect, location, symbols));}/*FUNCTION	bfd_set_relocSYNOPSIS	void bfd_set_reloc	  (bfd *abfd, asection *sec, arelent **rel, unsigned int count)DESCRIPTION	Set the relocation pointer and count within	section @var{sec} to the values @var{rel} and @var{count}.	The argument @var{abfd} is ignored.*/voidbfd_set_reloc (ignore_abfd, asect, location, count)     bfd *ignore_abfd ATTRIBUTE_UNUSED;     sec_ptr asect;     arelent **location;     unsigned int count;{  asect->orelocation = location;  asect->reloc_count = count;}/*FUNCTION	bfd_set_file_flagsSYNOPSIS	boolean bfd_set_file_flags(bfd *abfd, flagword flags);DESCRIPTION	Set the flag word in the BFD @var{abfd} to the value @var{flags}.	Possible errors are:	o <<bfd_error_wrong_format>> - The target bfd was not of object format.	o <<bfd_error_invalid_operation>> - The target bfd was open for reading.	o <<bfd_error_invalid_operation>> -	The flag word contained a bit which was not applicable to the	type of file.  E.g., an attempt was made to set the <<D_PAGED>> bit	on a BFD format which does not support demand paging.*/booleanbfd_set_file_flags (abfd, flags)     bfd *abfd;     flagword flags;{  if (abfd->format != bfd_object) {    bfd_set_error (bfd_error_wrong_format);    return false;  }  if (bfd_read_p (abfd)) {    bfd_set_error (bfd_error_invalid_operation);    return false;  }  bfd_get_file_flags (abfd) = flags;  if ((flags & bfd_applicable_file_flags (abfd)) != flags) {    bfd_set_error (bfd_error_invalid_operation);    return false;  }return true;}voidbfd_assert (file, line)     const char *file;     int line;{  (*_bfd_error_handler) (_("bfd assertion fail %s:%d"), file, line);}/* A more or less friendly abort message.  In libbfd.h abort is   defined to call this function.  */#ifndef EXIT_FAILURE#define EXIT_FAILURE 1#endifvoid_bfd_abort (file, line, fn)     const char *file;     int line;     const char *fn;{  if (fn != NULL)    (*_bfd_error_handler)      (_("BFD internal error, aborting at %s line %d in %s\n"),       file, line, fn);  else    (*_bfd_error_handler)      (_("BFD internal error, aborting at %s line %d\n"),       file, line);  (*_bfd_error_handler) (_("Please report this bug.\n"));  xexit (EXIT_FAILURE);}/*FUNCTION	bfd_get_arch_sizeSYNOPSIS 	int bfd_get_arch_size (bfd *abfd);DESCRIPTION	Returns the architecture address size, in bits, as determined	by the object file's format.  For ELF, this information is	included in the header.RETURNS	Returns the arch size in bits if known, <<-1>> otherwise.*/intbfd_get_arch_size (abfd)     bfd *abfd;{  if (abfd->xvec->flavour == bfd_target_elf_flavour)    return (get_elf_backend_data (abfd))->s->arch_size;  bfd_set_error (bfd_error_wrong_format);  return -1;}/*FUNCTION	bfd_get_sign_extend_vmaSYNOPSIS 	int bfd_get_sign_extend_vma (bfd *abfd);DESCRIPTION	Indicates if the target architecture "naturally" sign extends	an address.  Some architectures implicitly sign extend address	values when they are converted to types larger than the size	of an address.  For instance, bfd_get_start_address() will	return an address sign extended to fill a bfd_vma when this is	the case.RETURNS	Returns <<1>> if the target architecture is known to sign	extend addresses, <<0>> if the target architecture is known to	not sign extend addresses, and <<-1>> otherwise.*/intbfd_get_sign_extend_vma (abfd)     bfd *abfd;{  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)    return (get_elf_backend_data (abfd)->sign_extend_vma);  bfd_set_error (bfd_error_wrong_format);  return -1;}/*FUNCTION	bfd_set_start_addressSYNOPSIS 	boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);DESCRIPTION	Make @var{vma} the entry point of output BFD @var{abfd}.RETURNS	Returns <<true>> on success, <<false>> otherwise.*/booleanbfd_set_start_address(abfd, vma)bfd *abfd;bfd_vma vma;{  abfd->start_address = vma;  return true;}/*FUNCTION	bfd_get_mtimeSYNOPSIS	long bfd_get_mtime(bfd *abfd);DESCRIPTION	Return the file modification time (as read from the file system, or	from the archive header for archive members).*/longbfd_get_mtime (abfd)     bfd *abfd;{  FILE *fp;  struct stat buf;  if (abfd->mtime_set)    return abfd->mtime;  fp = bfd_cache_lookup (abfd);  if (0 != fstat (fileno (fp), &buf))    return 0;  abfd->mtime = buf.st_mtime;		/* Save value in case anyone wants it */  return buf.st_mtime;}/*FUNCTION	bfd_get_sizeSYNOPSIS	long bfd_get_size(bfd *abfd);DESCRIPTION	Return the file size (as read from file system) for the file	associated with BFD @var{abfd}.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?