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