coff-bfd.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* BFD COFF interfaces used outside of BFD.
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. Written by Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "coff/internal.h"
  21. #include "libcoff.h"
  22. /* Return the COFF syment for a symbol. */
  23. bool
  24. bfd_coff_get_syment (bfd *abfd,
  25. asymbol *symbol,
  26. struct internal_syment *psyment)
  27. {
  28. coff_symbol_type *csym;
  29. csym = coff_symbol_from (symbol);
  30. if (csym == NULL || csym->native == NULL
  31. || ! csym->native->is_sym)
  32. {
  33. bfd_set_error (bfd_error_invalid_operation);
  34. return false;
  35. }
  36. *psyment = csym->native->u.syment;
  37. if (csym->native->fix_value)
  38. psyment->n_value =
  39. ((psyment->n_value - (bfd_hostptr_t) obj_raw_syments (abfd))
  40. / sizeof (combined_entry_type));
  41. /* FIXME: We should handle fix_line here. */
  42. return true;
  43. }
  44. /* Return the COFF auxent for a symbol. */
  45. bool
  46. bfd_coff_get_auxent (bfd *abfd,
  47. asymbol *symbol,
  48. int indx,
  49. union internal_auxent *pauxent)
  50. {
  51. coff_symbol_type *csym;
  52. combined_entry_type *ent;
  53. csym = coff_symbol_from (symbol);
  54. if (csym == NULL
  55. || csym->native == NULL
  56. || ! csym->native->is_sym
  57. || indx >= csym->native->u.syment.n_numaux)
  58. {
  59. bfd_set_error (bfd_error_invalid_operation);
  60. return false;
  61. }
  62. ent = csym->native + indx + 1;
  63. BFD_ASSERT (! ent->is_sym);
  64. *pauxent = ent->u.auxent;
  65. if (ent->fix_tag)
  66. pauxent->x_sym.x_tagndx.l =
  67. ((combined_entry_type *) pauxent->x_sym.x_tagndx.p
  68. - obj_raw_syments (abfd));
  69. if (ent->fix_end)
  70. pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l =
  71. ((combined_entry_type *) pauxent->x_sym.x_fcnary.x_fcn.x_endndx.p
  72. - obj_raw_syments (abfd));
  73. if (ent->fix_scnlen)
  74. pauxent->x_csect.x_scnlen.l =
  75. ((combined_entry_type *) pauxent->x_csect.x_scnlen.p
  76. - obj_raw_syments (abfd));
  77. return true;
  78. }