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